Implemented basic settings window skeleton.

git-svn-id: http://svn.haiku-os.org/webpositive/webkit/trunk@277 94f232f2-1747-11df-bad5-a5bfde151594
This commit is contained in:
stippi
2012-07-03 15:33:10 +02:00
committed by Alexandre Deckner
parent c6662bd928
commit d0417c565a
6 changed files with 245 additions and 20 deletions
+44 -19
View File
@@ -32,6 +32,7 @@
#include "BrowserWindow.h" #include "BrowserWindow.h"
#include "BrowsingHistory.h" #include "BrowsingHistory.h"
#include "DownloadWindow.h" #include "DownloadWindow.h"
#include "SettingsWindow.h"
#include "WebPage.h" #include "WebPage.h"
#include "WebSettings.h" #include "WebSettings.h"
#include "WebView.h" #include "WebView.h"
@@ -52,12 +53,14 @@ const char* kApplicationName = "WebPositive";
static const uint32 PRELOAD_BROWSING_HISTORY = 'plbh'; static const uint32 PRELOAD_BROWSING_HISTORY = 'plbh';
BrowserApp::BrowserApp() BrowserApp::BrowserApp()
: BApplication(kApplicationSignature) :
, fWindowCount(0) BApplication(kApplicationSignature),
, fLastWindowFrame(100, 100, 700, 750) fWindowCount(0),
, fLaunchRefsMessage(0) fLastWindowFrame(100, 100, 700, 750),
, fInitialized(false) fLaunchRefsMessage(0),
, fDownloadWindow(0) fInitialized(false),
fDownloadWindow(NULL),
fSettingsWindow(NULL)
{ {
} }
@@ -111,17 +114,26 @@ BrowserApp::ReadyToRun()
BFile settingsFile; BFile settingsFile;
BRect windowFrameFromSettings = fLastWindowFrame; BRect windowFrameFromSettings = fLastWindowFrame;
BRect downloadWindowFrame(100, 100, 300, 250); BRect downloadWindowFrame(100, 100, 300, 250);
BRect settingsWindowFrame;
bool showDownloads = false; bool showDownloads = false;
if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) { if (_OpenSettingsFile(settingsFile, B_READ_ONLY)) {
BMessage settingsArchive; BMessage settingsArchive;
settingsArchive.Unflatten(&settingsFile); settingsArchive.Unflatten(&settingsFile);
settingsArchive.FindRect("window frame", &windowFrameFromSettings); BRect rect;
settingsArchive.FindRect("downloads window frame", &downloadWindowFrame); if (settingsArchive.FindRect("window frame", &rect) == B_OK)
settingsArchive.FindBool("show downloads", &showDownloads); 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; fLastWindowFrame = windowFrameFromSettings;
fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads); fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads);
fSettingsWindow = new SettingsWindow(settingsWindowFrame);
fInitialized = true; fInitialized = true;
@@ -176,17 +188,12 @@ BrowserApp::MessageReceived(BMessage* message)
PostMessage(B_QUIT_REQUESTED); PostMessage(B_QUIT_REQUESTED);
break; break;
case SHOW_DOWNLOAD_WINDOW: { case SHOW_DOWNLOAD_WINDOW:
BAutolock _(fDownloadWindow); _ShowWindow(message, fDownloadWindow);
uint32 workspaces; break;
if (message->FindUInt32("workspaces", &workspaces) == B_OK) case SHOW_SETTINGS_WINDOW:
fDownloadWindow->SetWorkspaces(workspaces); _ShowWindow(message, fSettingsWindow);
if (fDownloadWindow->IsHidden())
fDownloadWindow->Show();
else
fDownloadWindow->Activate();
break; break;
}
default: default:
BApplication::MessageReceived(message); BApplication::MessageReceived(message);
@@ -251,6 +258,10 @@ BrowserApp::QuitRequested()
settingsArchive.AddBool("show downloads", !fDownloadWindow->IsHidden()); settingsArchive.AddBool("show downloads", !fDownloadWindow->IsHidden());
fDownloadWindow->Unlock(); fDownloadWindow->Unlock();
} }
if (fSettingsWindow->Lock()) {
settingsArchive.AddRect("settings window frame", fSettingsWindow->Frame());
fSettingsWindow->Unlock();
}
settingsArchive.Flatten(&settingsFile); 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 - // #pragma mark -
+4
View File
@@ -35,6 +35,7 @@
class BFile; class BFile;
class DownloadWindow; class DownloadWindow;
class BrowserWindow; class BrowserWindow;
class SettingsWindow;
class BrowserApp : public BApplication { class BrowserApp : public BApplication {
@@ -55,6 +56,8 @@ private:
void _CreateNewWindow(const BString& url); void _CreateNewWindow(const BString& url);
void _CreateNewTab(BrowserWindow* window, void _CreateNewTab(BrowserWindow* window,
const BString& url, bool select); const BString& url, bool select);
void _ShowWindow(const BMessage* message,
BWindow* window);
private: private:
int fWindowCount; int fWindowCount;
@@ -63,6 +66,7 @@ private:
bool fInitialized; bool fInitialized;
DownloadWindow* fDownloadWindow; DownloadWindow* fDownloadWindow;
SettingsWindow* fSettingsWindow;
}; };
+2
View File
@@ -187,6 +187,7 @@ BrowserWindow::BrowserWindow(BRect frame, const BMessenger& downloadListener,
menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W')); menu->AddItem(new BMenuItem("Close tab", new BMessage(CLOSE_TAB), 'W'));
menu->AddSeparatorItem(); menu->AddSeparatorItem();
menu->AddItem(new BMenuItem("Show downloads", new BMessage(SHOW_DOWNLOAD_WINDOW), 'J')); 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(); menu->AddSeparatorItem();
BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q');
menu->AddItem(quitItem); menu->AddItem(quitItem);
@@ -473,6 +474,7 @@ BrowserWindow::MessageReceived(BMessage* message)
break; break;
case SHOW_DOWNLOAD_WINDOW: case SHOW_DOWNLOAD_WINDOW:
case SHOW_SETTINGS_WINDOW:
message->AddUInt32("workspaces", Workspaces()); message->AddUInt32("workspaces", Workspaces());
be_app->PostMessage(message); be_app->PostMessage(message);
break; break;
+2 -1
View File
@@ -56,7 +56,8 @@ enum {
NEW_TAB = 'ntab', NEW_TAB = 'ntab',
WINDOW_OPENED = 'wndo', WINDOW_OPENED = 'wndo',
WINDOW_CLOSED = 'wndc', WINDOW_CLOSED = 'wndc',
SHOW_DOWNLOAD_WINDOW = 'sdwd' SHOW_DOWNLOAD_WINDOW = 'sdwd',
SHOW_SETTINGS_WINDOW = 'sswd'
}; };
#define INTEGRATE_MENU_INTO_TAB_BAR 0 #define INTEGRATE_MENU_INTO_TAB_BAR 0
+138
View File
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
*
* 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 <Button.h>
#include <ControlLook.h>
#include <GridLayoutBuilder.h>
#include <GroupLayout.h>
#include <GroupLayoutBuilder.h>
#include <MenuItem.h>
#include <ScrollView.h>
#include <SeparatorView.h>
#include <SpaceLayoutItem.h>
#include <stdio.h>
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()
{
}
+55
View File
@@ -0,0 +1,55 @@
/*
* Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
*
* 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 <Window.h>
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