* load settings before building the window: the behavior is then similar with the replicant version.

* change window limits when keypad option is off
* style cleanup


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29293 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Jérôme Duval
2009-02-22 22:45:41 +00:00
parent 1c053f1771
commit bc3229d648
6 changed files with 45 additions and 56 deletions
+7 -12
View File
@@ -44,11 +44,11 @@ CalcApplication::~CalcApplication()
void void
CalcApplication::ReadyToRun() CalcApplication::ReadyToRun()
{ {
BRect frame(0, 0, kDefaultWindowWidth - 1, kDefaultWindowHeight - 1); BMessage settings;
fCalcWindow = new CalcWindow(frame); _LoadSettings(settings);
if (!_LoadSettings()) BRect frame(0, 0, kDefaultWindowWidth - 1, kDefaultWindowHeight - 1);
fCalcWindow->SetFrame(frame, true); fCalcWindow = new CalcWindow(frame, &settings);
// reveal window // reveal window
fCalcWindow->Show(); fCalcWindow->Show();
@@ -76,25 +76,20 @@ CalcApplication::QuitRequested()
// #pragma mark - // #pragma mark -
bool void
CalcApplication::_LoadSettings() CalcApplication::_LoadSettings(BMessage &archive)
{ {
// locate preferences file // locate preferences file
BFile prefsFile; BFile prefsFile;
if (_InitSettingsFile(&prefsFile, false) < B_OK) { if (_InitSettingsFile(&prefsFile, false) < B_OK) {
printf("no preference file found.\n"); printf("no preference file found.\n");
return false; return;
} }
// unflatten settings data // unflatten settings data
BMessage archive;
if (archive.Unflatten(&prefsFile) < B_OK) { if (archive.Unflatten(&prefsFile) < B_OK) {
printf("error unflattening settings.\n"); printf("error unflattening settings.\n");
return false;
} }
// apply settings
return fCalcWindow->LoadSettings(&archive);
} }
+1 -1
View File
@@ -28,7 +28,7 @@ class CalcApplication : public BApplication {
virtual bool QuitRequested(); virtual bool QuitRequested();
private: private:
bool _LoadSettings(); void _LoadSettings(BMessage &settings);
void _SaveSettings(); void _SaveSettings();
status_t _InitSettingsFile(BFile* file, bool write); status_t _InitSettingsFile(BFile* file, bool write);
+22 -16
View File
@@ -74,7 +74,7 @@ CalcView *CalcView::Instantiate(BMessage *archive)
} }
CalcView::CalcView(BRect frame, rgb_color rgbBaseColor) CalcView::CalcView(BRect frame, rgb_color rgbBaseColor, BMessage *settings)
: BView(frame, "DeskCalc", B_FOLLOW_ALL_SIDES, : BView(frame, "DeskCalc", B_FOLLOW_ALL_SIDES,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS), B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
fColums(5), fColums(5),
@@ -108,6 +108,8 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this); fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
AddChild(fExpressionTextView); AddChild(fExpressionTextView);
_LoadSettings(settings);
// tell the app server not to erase our b/g // tell the app server not to erase our b/g
SetViewColor(B_TRANSPARENT_32_BIT); SetViewColor(B_TRANSPARENT_32_BIT);
@@ -116,7 +118,7 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
// colorize based on base color. // colorize based on base color.
_Colorize(); _Colorize();
// create pop-up menu system // create pop-up menu system
_CreatePopUpMenu(); _CreatePopUpMenu();
@@ -158,7 +160,7 @@ CalcView::CalcView(BMessage* archive)
AddChild(fExpressionTextView); AddChild(fExpressionTextView);
// read data from archive // read data from archive
LoadSettings(archive); _LoadSettings(archive);
// create pop-up menu system // create pop-up menu system
_CreatePopUpMenu(); _CreatePopUpMenu();
@@ -184,14 +186,13 @@ CalcView::AttachedToWindow()
FrameResized(frame.Width(), frame.Height()); FrameResized(frame.Width(), frame.Height());
fPopUpMenu->SetTargetForItems(this); fPopUpMenu->SetTargetForItems(this);
_ShowKeypad(fOptions->show_keypad);
} }
void void
CalcView::MessageReceived(BMessage* message) CalcView::MessageReceived(BMessage* message)
{ {
//message->PrintToStream();
// check if message was dropped // check if message was dropped
if (message->WasDropped()) { if (message->WasDropped()) {
// pass message on to paste // pass message on to paste
@@ -412,7 +413,8 @@ CalcView::MouseDown(BPoint point)
// display popup menu if not primary mouse button // display popup menu if not primary mouse button
if ((B_PRIMARY_MOUSE_BUTTON & buttons) == 0) { if ((B_PRIMARY_MOUSE_BUTTON & buttons) == 0) {
BMenuItem* selected; BMenuItem* selected;
if ((selected = fPopUpMenu->Go(ConvertToScreen(point))) != NULL) if ((selected = fPopUpMenu->Go(ConvertToScreen(point))) != NULL
&& selected->Message() != NULL)
MessageReceived(selected->Message()); MessageReceived(selected->Message());
return; return;
} }
@@ -654,7 +656,7 @@ CalcView::Paste(BMessage *message)
status_t status_t
CalcView::LoadSettings(BMessage* archive) CalcView::_LoadSettings(BMessage* archive)
{ {
if (!archive) if (!archive)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -697,7 +699,6 @@ CalcView::LoadSettings(BMessage* archive)
// load options // load options
fOptions->LoadSettings(archive); fOptions->LoadSettings(archive);
fShowKeypad = fOptions->show_keypad;
// load display text // load display text
const char* display; const char* display;
@@ -727,13 +728,13 @@ CalcView::SaveSettings(BMessage* archive) const
status_t ret = archive ? B_OK : B_BAD_VALUE; status_t ret = archive ? B_OK : B_BAD_VALUE;
// record grid dimensions // record grid dimensions
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt16("cols", fColums); ret = archive->AddInt16("cols", fColums);
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddInt16("rows", fRows); ret = archive->AddInt16("rows", fRows);
// record color scheme // record color scheme
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddData("rgbBaseColor", B_RGB_COLOR_TYPE, ret = archive->AddData("rgbBaseColor", B_RGB_COLOR_TYPE,
&fBaseColor, sizeof(rgb_color)); &fBaseColor, sizeof(rgb_color));
if (ret == B_OK) if (ret == B_OK)
@@ -953,7 +954,7 @@ CalcView::_CreatePopUpMenu()
// construct items // construct items
fAutoNumlockItem = new BMenuItem("Enable Num Lock on start up", fAutoNumlockItem = new BMenuItem("Enable Num Lock on start up",
new BMessage(K_OPTIONS_AUTO_NUM_LOCK)); new BMessage(K_OPTIONS_AUTO_NUM_LOCK));
fAudioFeedbackItem = new BMenuItem("Audio Feedback" B_UTF8_ELLIPSIS, fAudioFeedbackItem = new BMenuItem("Audio Feedback",
new BMessage(K_OPTIONS_AUDIO_FEEDBACK)); new BMessage(K_OPTIONS_AUDIO_FEEDBACK));
fShowKeypadItem = new BMenuItem("Show Keypad", fShowKeypadItem = new BMenuItem("Show Keypad",
new BMessage(K_OPTIONS_SHOW_KEYPAD)); new BMessage(K_OPTIONS_SHOW_KEYPAD));
@@ -1007,15 +1008,20 @@ CalcView::_ShowKeypad(bool show)
return; return;
fShowKeypad = show; fShowKeypad = show;
if (fShowKeypadItem && fShowKeypadItem->IsMarked() ^ fShowKeypad)
fShowKeypadItem->SetMarked(fShowKeypad);
float height = fShowKeypad ? fHeight / K_DISPLAY_YPROP float height = fShowKeypad ? fHeight / K_DISPLAY_YPROP
: fHeight * K_DISPLAY_YPROP; : fHeight * K_DISPLAY_YPROP;
BWindow* window = Window(); BWindow* window = Window();
if (window->Bounds() == Frame()) if (window) {
window->ResizeTo(fWidth, height); if (window->Bounds() == Frame()) {
else window->ResizeTo(fWidth, height);
ResizeTo(fWidth, height); window->SetSizeLimits(100.0, 400.0, fShowKeypad ? 100.0 : 20.0, 400.0);
} else
ResizeTo(fWidth, height);
}
} }
+5 -3
View File
@@ -28,7 +28,8 @@ class CalcView : public BView {
CalcView(BRect frame, CalcView(BRect frame,
rgb_color rgbBaseColor); rgb_color rgbBaseColor,
BMessage *settings);
CalcView(BMessage* archive); CalcView(BMessage* archive);
@@ -57,8 +58,7 @@ class CalcView : public BView {
// Paste contents of system clipboard to view. // Paste contents of system clipboard to view.
void Paste(BMessage *message); void Paste(BMessage *message);
// Load/Save current settings // Save current settings
status_t LoadSettings(BMessage* archive);
status_t SaveSettings(BMessage* archive) const; status_t SaveSettings(BMessage* archive) const;
void Evaluate(); void Evaluate();
@@ -87,6 +87,8 @@ class CalcView : public BView {
void _ShowKeypad(bool show); void _ShowKeypad(bool show);
void _FetchAppIcon(BBitmap* into); void _FetchAppIcon(BBitmap* into);
status_t _LoadSettings(BMessage* archive);
// grid dimensions // grid dimensions
int16 fColums; int16 fColums;
int16 fRows; int16 fRows;
+9 -22
View File
@@ -24,7 +24,7 @@
static const char* kWindowTitle = "DeskCalc"; static const char* kWindowTitle = "DeskCalc";
CalcWindow::CalcWindow(BRect frame) CalcWindow::CalcWindow(BRect frame, BMessage *settings)
: BWindow(frame, kWindowTitle, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) : BWindow(frame, kWindowTitle, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{ {
// create calculator view with calculator description and // create calculator view with calculator description and
@@ -32,8 +32,10 @@ CalcWindow::CalcWindow(BRect frame)
BScreen screen(this); BScreen screen(this);
rgb_color baseColor = screen.DesktopColor(); rgb_color baseColor = screen.DesktopColor();
SetSizeLimits(100.0, 400.0, 100.0, 400.0);
frame.OffsetTo(B_ORIGIN); frame.OffsetTo(B_ORIGIN);
fCalcView = new CalcView(frame, baseColor); fCalcView = new CalcView(frame, baseColor, settings);
// create replicant dragger // create replicant dragger
frame.top = frame.bottom - 7.0f; frame.top = frame.bottom - 7.0f;
@@ -45,7 +47,11 @@ CalcWindow::CalcWindow(BRect frame)
AddChild(fCalcView); AddChild(fCalcView);
fCalcView->AddChild(dragger); fCalcView->AddChild(dragger);
SetSizeLimits(100.0, 400.0, 100.0, 400.0); BRect rect;
if (settings->FindRect("window frame", &rect) == B_OK)
SetFrame(rect);
else
SetFrame(frame, true);
} }
@@ -78,25 +84,6 @@ CalcWindow::QuitRequested()
} }
bool
CalcWindow::LoadSettings(BMessage* archive)
{
status_t ret = fCalcView->LoadSettings(archive);
if (ret < B_OK)
return false;
BRect frame;
ret = archive->FindRect("window frame", &frame);
if (ret < B_OK)
return false;
SetFrame(frame);
return true;
}
status_t status_t
CalcWindow::SaveSettings(BMessage* archive) const CalcWindow::SaveSettings(BMessage* archive) const
{ {
+1 -2
View File
@@ -18,13 +18,12 @@ class CalcView;
class CalcWindow : public BWindow { class CalcWindow : public BWindow {
public: public:
CalcWindow(BRect frame); CalcWindow(BRect frame, BMessage *settings);
virtual ~CalcWindow(); virtual ~CalcWindow();
virtual void Show(); virtual void Show();
virtual bool QuitRequested(); virtual bool QuitRequested();
bool LoadSettings(BMessage* archive);
status_t SaveSettings(BMessage* archive) const; status_t SaveSettings(BMessage* archive) const;
void SetFrame(BRect frame, void SetFrame(BRect frame,