From d0417c565a1a418ece0406d288dcd2e971b5d447 Mon Sep 17 00:00:00 2001 From: stippi Date: Wed, 3 Mar 2010 10:57:46 +0000 Subject: [PATCH] Implemented basic settings window skeleton. git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@277 94f232f2-1747-11df-bad5-a5bfde151594 --- src/apps/webpositive/BrowserApp.cpp | 63 +++++++---- src/apps/webpositive/BrowserApp.h | 4 + src/apps/webpositive/BrowserWindow.cpp | 2 + src/apps/webpositive/BrowserWindow.h | 3 +- src/apps/webpositive/SettingsWindow.cpp | 138 ++++++++++++++++++++++++ src/apps/webpositive/SettingsWindow.h | 55 ++++++++++ 6 files changed, 245 insertions(+), 20 deletions(-) create mode 100644 src/apps/webpositive/SettingsWindow.cpp create mode 100644 src/apps/webpositive/SettingsWindow.h diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index df6b01832e..81fcce7b28 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -32,6 +32,7 @@ #include "BrowserWindow.h" #include "BrowsingHistory.h" #include "DownloadWindow.h" +#include "SettingsWindow.h" #include "WebPage.h" #include "WebSettings.h" #include "WebView.h" @@ -52,12 +53,14 @@ const char* kApplicationName = "WebPositive"; static const uint32 PRELOAD_BROWSING_HISTORY = 'plbh'; BrowserApp::BrowserApp() - : BApplication(kApplicationSignature) - , fWindowCount(0) - , fLastWindowFrame(100, 100, 700, 750) - , fLaunchRefsMessage(0) - , fInitialized(false) - , fDownloadWindow(0) + : + BApplication(kApplicationSignature), + fWindowCount(0), + fLastWindowFrame(100, 100, 700, 750), + fLaunchRefsMessage(0), + fInitialized(false), + fDownloadWindow(NULL), + fSettingsWindow(NULL) { } @@ -111,17 +114,26 @@ BrowserApp::ReadyToRun() BFile settingsFile; BRect windowFrameFromSettings = fLastWindowFrame; BRect downloadWindowFrame(100, 100, 300, 250); + BRect settingsWindowFrame; bool showDownloads = false; if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) { BMessage settingsArchive; settingsArchive.Unflatten(&settingsFile); - settingsArchive.FindRect("window frame", &windowFrameFromSettings); - settingsArchive.FindRect("downloads window frame", &downloadWindowFrame); - settingsArchive.FindBool("show downloads", &showDownloads); + BRect rect; + if (settingsArchive.FindRect("window frame", &rect) == B_OK) + windowFrameFromSettings = rect; + if (settingsArchive.FindRect("downloads window frame", &rect) == B_OK) + downloadWindowFrame = rect; + if (settingsArchive.FindRect("settings window frame", &rect) == B_OK) + settingsWindowFrame = rect; + bool flag; + if (settingsArchive.FindBool("show downloads", &flag) == B_OK) + showDownloads = flag; } fLastWindowFrame = windowFrameFromSettings; fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads); + fSettingsWindow = new SettingsWindow(settingsWindowFrame); fInitialized = true; @@ -176,17 +188,12 @@ BrowserApp::MessageReceived(BMessage* message) PostMessage(B_QUIT_REQUESTED); break; - case SHOW_DOWNLOAD_WINDOW: { - BAutolock _(fDownloadWindow); - uint32 workspaces; - if (message->FindUInt32("workspaces", &workspaces) == B_OK) - fDownloadWindow->SetWorkspaces(workspaces); - if (fDownloadWindow->IsHidden()) - fDownloadWindow->Show(); - else - fDownloadWindow->Activate(); + case SHOW_DOWNLOAD_WINDOW: + _ShowWindow(message, fDownloadWindow); + break; + case SHOW_SETTINGS_WINDOW: + _ShowWindow(message, fSettingsWindow); break; - } default: BApplication::MessageReceived(message); @@ -251,6 +258,10 @@ BrowserApp::QuitRequested() settingsArchive.AddBool("show downloads", !fDownloadWindow->IsHidden()); fDownloadWindow->Unlock(); } + if (fSettingsWindow->Lock()) { + settingsArchive.AddRect("settings window frame", fSettingsWindow->Frame()); + fSettingsWindow->Unlock(); + } settingsArchive.Flatten(&settingsFile); } @@ -324,6 +335,20 @@ BrowserApp::_CreateNewTab(BrowserWindow* window, const BString& url, } +void +BrowserApp::_ShowWindow(const BMessage* message, BWindow* window) +{ + BAutolock _(window); + uint32 workspaces; + if (message->FindUInt32("workspaces", &workspaces) == B_OK) + window->SetWorkspaces(workspaces); + if (window->IsHidden()) + window->Show(); + else + window->Activate(); +} + + // #pragma mark - diff --git a/src/apps/webpositive/BrowserApp.h b/src/apps/webpositive/BrowserApp.h index 17ae54735a..6b5402ba9a 100644 --- a/src/apps/webpositive/BrowserApp.h +++ b/src/apps/webpositive/BrowserApp.h @@ -35,6 +35,7 @@ class BFile; class DownloadWindow; class BrowserWindow; +class SettingsWindow; class BrowserApp : public BApplication { @@ -55,6 +56,8 @@ private: void _CreateNewWindow(const BString& url); void _CreateNewTab(BrowserWindow* window, const BString& url, bool select); + void _ShowWindow(const BMessage* message, + BWindow* window); private: int fWindowCount; @@ -63,6 +66,7 @@ private: bool fInitialized; DownloadWindow* fDownloadWindow; + SettingsWindow* fSettingsWindow; }; diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp index c29896f34f..fc01924a22 100644 --- a/src/apps/webpositive/BrowserWindow.cpp +++ b/src/apps/webpositive/BrowserWindow.cpp @@ -187,6 +187,7 @@ BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener, menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Show downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'J')); + menu->AddItem(new BMenuItem("Show settings", new BMessage(SHOW_SETTINGS_WINDOW))); menu->AddSeparatorItem(); BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); menu->AddItem(quitItem); @@ -473,6 +474,7 @@ BrowserWindow::MessageReceived(BMessage* message) break; case SHOW_DOWNLOAD_WINDOW: + case SHOW_SETTINGS_WINDOW: message->AddUInt32("workspaces", Workspaces()); be_app->PostMessage(message); break; diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h index a296727c41..0fafb1ec2e 100644 --- a/src/apps/webpositive/BrowserWindow.h +++ b/src/apps/webpositive/BrowserWindow.h @@ -56,7 +56,8 @@ enum { NEW_TAB = 'ntab', WINDOW_OPENED = 'wndo', WINDOW_CLOSED = 'wndc', - SHOW_DOWNLOAD_WINDOW = 'sdwd' + SHOW_DOWNLOAD_WINDOW = 'sdwd', + SHOW_SETTINGS_WINDOW = 'sswd' }; #define INTEGRATE_MENU_INTO_TAB_BAR 0 diff --git a/src/apps/webpositive/SettingsWindow.cpp b/src/apps/webpositive/SettingsWindow.cpp new file mode 100644 index 0000000000..77364539fe --- /dev/null +++ b/src/apps/webpositive/SettingsWindow.cpp @@ -0,0 +1,138 @@ +/* + * Copyright (C) 2010 Stephan Aßmus + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include "SettingsWindow.h" + +#include "BrowserApp.h" +#include "WebSettings.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +enum { + MSG_OK = 'aply', + MSG_CANCEL = 'cncl', + MSG_REVERT = 'rvrt', +}; + + +SettingsWindow::SettingsWindow(BRect frame) + : + BWindow(frame, "Settings", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, + B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE) +{ + SetLayout(new BGroupLayout(B_VERTICAL)); + + fOkButton = new BButton("OK", new BMessage(MSG_OK)); + fCancelButton = new BButton("Cancel", new BMessage(MSG_CANCEL)); + fRevertButton = new BButton("Revert", new BMessage(MSG_REVERT)); + + float spacing = be_control_look->DefaultItemSpacing(); + + AddChild(BGroupLayoutBuilder(B_VERTICAL) + .Add(BGridLayoutBuilder(spacing, spacing) + ) + .Add(new BSeparatorView(B_HORIZONTAL, B_PLAIN_BORDER)) + .Add(BGroupLayoutBuilder(B_HORIZONTAL, spacing) + .Add(fRevertButton) + .AddGlue() + .Add(fCancelButton) + .Add(fOkButton) + .SetInsets(spacing, spacing, spacing, spacing) + ) + ); + + fOkButton->MakeDefault(true); + + if (!frame.IsValid()) + CenterOnScreen(); + + // Start hidden + Hide(); + Show(); +} + + +SettingsWindow::~SettingsWindow() +{ +} + + +void +SettingsWindow::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_OK: + _ApplySettings(); + PostMessage(B_QUIT_REQUESTED); + break; + case MSG_CANCEL: + _RevertSettings(); + PostMessage(B_QUIT_REQUESTED); + break; + case MSG_REVERT: + _RevertSettings(); + break; + default: + BWindow::MessageReceived(message); + break; + } +} + + +bool +SettingsWindow::QuitRequested() +{ + if (!IsHidden()) + Hide(); + return false; +} + + +// #pragma mark - private + + +void +SettingsWindow::_ApplySettings() +{ +} + + +void +SettingsWindow::_RevertSettings() +{ +} + + diff --git a/src/apps/webpositive/SettingsWindow.h b/src/apps/webpositive/SettingsWindow.h new file mode 100644 index 0000000000..22ff3f7c10 --- /dev/null +++ b/src/apps/webpositive/SettingsWindow.h @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2010 Stephan Aßmus + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef SETTINGS_WINDOW_H +#define SETTINGS_WINDOW_H + +#include + +class BButton; + + +class SettingsWindow : public BWindow { +public: + SettingsWindow(BRect frame); + virtual ~SettingsWindow(); + + virtual void MessageReceived(BMessage* message); + virtual bool QuitRequested(); + +private: + void _ApplySettings(); + void _RevertSettings(); + +private: + BButton* fOkButton; + BButton* fCancelButton; + BButton* fRevertButton; +}; + + +#endif // SETTINGS_WINDOW_H +