* 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

View File

@ -44,11 +44,11 @@ CalcApplication::~CalcApplication()
void
CalcApplication::ReadyToRun()
{
BRect frame(0, 0, kDefaultWindowWidth - 1, kDefaultWindowHeight - 1);
fCalcWindow = new CalcWindow(frame);
BMessage settings;
_LoadSettings(settings);
if (!_LoadSettings())
fCalcWindow->SetFrame(frame, true);
BRect frame(0, 0, kDefaultWindowWidth - 1, kDefaultWindowHeight - 1);
fCalcWindow = new CalcWindow(frame, &settings);
// reveal window
fCalcWindow->Show();
@ -76,25 +76,20 @@ CalcApplication::QuitRequested()
// #pragma mark -
bool
CalcApplication::_LoadSettings()
void
CalcApplication::_LoadSettings(BMessage &archive)
{
// locate preferences file
BFile prefsFile;
if (_InitSettingsFile(&prefsFile, false) < B_OK) {
printf("no preference file found.\n");
return false;
return;
}
// unflatten settings data
BMessage archive;
if (archive.Unflatten(&prefsFile) < B_OK) {
printf("error unflattening settings.\n");
return false;
}
// apply settings
return fCalcWindow->LoadSettings(&archive);
}

View File

@ -28,7 +28,7 @@ class CalcApplication : public BApplication {
virtual bool QuitRequested();
private:
bool _LoadSettings();
void _LoadSettings(BMessage &settings);
void _SaveSettings();
status_t _InitSettingsFile(BFile* file, bool write);

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,
B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE | B_FRAME_EVENTS),
fColums(5),
@ -108,6 +108,8 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
fExpressionTextView = new ExpressionTextView(_ExpressionRect(), this);
AddChild(fExpressionTextView);
_LoadSettings(settings);
// tell the app server not to erase our b/g
SetViewColor(B_TRANSPARENT_32_BIT);
@ -116,7 +118,7 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
// colorize based on base color.
_Colorize();
// create pop-up menu system
_CreatePopUpMenu();
@ -158,7 +160,7 @@ CalcView::CalcView(BMessage* archive)
AddChild(fExpressionTextView);
// read data from archive
LoadSettings(archive);
_LoadSettings(archive);
// create pop-up menu system
_CreatePopUpMenu();
@ -184,14 +186,13 @@ CalcView::AttachedToWindow()
FrameResized(frame.Width(), frame.Height());
fPopUpMenu->SetTargetForItems(this);
_ShowKeypad(fOptions->show_keypad);
}
void
CalcView::MessageReceived(BMessage* message)
{
//message->PrintToStream();
// check if message was dropped
if (message->WasDropped()) {
// pass message on to paste
@ -412,7 +413,8 @@ CalcView::MouseDown(BPoint point)
// display popup menu if not primary mouse button
if ((B_PRIMARY_MOUSE_BUTTON & buttons) == 0) {
BMenuItem* selected;
if ((selected = fPopUpMenu->Go(ConvertToScreen(point))) != NULL)
if ((selected = fPopUpMenu->Go(ConvertToScreen(point))) != NULL
&& selected->Message() != NULL)
MessageReceived(selected->Message());
return;
}
@ -654,7 +656,7 @@ CalcView::Paste(BMessage *message)
status_t
CalcView::LoadSettings(BMessage* archive)
CalcView::_LoadSettings(BMessage* archive)
{
if (!archive)
return B_BAD_VALUE;
@ -697,7 +699,6 @@ CalcView::LoadSettings(BMessage* archive)
// load options
fOptions->LoadSettings(archive);
fShowKeypad = fOptions->show_keypad;
// load display text
const char* display;
@ -727,13 +728,13 @@ CalcView::SaveSettings(BMessage* archive) const
status_t ret = archive ? B_OK : B_BAD_VALUE;
// record grid dimensions
if (ret == B_OK)
if (ret == B_OK)
ret = archive->AddInt16("cols", fColums);
if (ret == B_OK)
if (ret == B_OK)
ret = archive->AddInt16("rows", fRows);
// record color scheme
if (ret == B_OK)
if (ret == B_OK)
ret = archive->AddData("rgbBaseColor", B_RGB_COLOR_TYPE,
&fBaseColor, sizeof(rgb_color));
if (ret == B_OK)
@ -953,7 +954,7 @@ CalcView::_CreatePopUpMenu()
// construct items
fAutoNumlockItem = new BMenuItem("Enable Num Lock on start up",
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));
fShowKeypadItem = new BMenuItem("Show Keypad",
new BMessage(K_OPTIONS_SHOW_KEYPAD));
@ -1007,15 +1008,20 @@ CalcView::_ShowKeypad(bool show)
return;
fShowKeypad = show;
if (fShowKeypadItem && fShowKeypadItem->IsMarked() ^ fShowKeypad)
fShowKeypadItem->SetMarked(fShowKeypad);
float height = fShowKeypad ? fHeight / K_DISPLAY_YPROP
: fHeight * K_DISPLAY_YPROP;
BWindow* window = Window();
if (window->Bounds() == Frame())
window->ResizeTo(fWidth, height);
else
ResizeTo(fWidth, height);
if (window) {
if (window->Bounds() == Frame()) {
window->ResizeTo(fWidth, height);
window->SetSizeLimits(100.0, 400.0, fShowKeypad ? 100.0 : 20.0, 400.0);
} else
ResizeTo(fWidth, height);
}
}

View File

@ -28,7 +28,8 @@ class CalcView : public BView {
CalcView(BRect frame,
rgb_color rgbBaseColor);
rgb_color rgbBaseColor,
BMessage *settings);
CalcView(BMessage* archive);
@ -57,8 +58,7 @@ class CalcView : public BView {
// Paste contents of system clipboard to view.
void Paste(BMessage *message);
// Load/Save current settings
status_t LoadSettings(BMessage* archive);
// Save current settings
status_t SaveSettings(BMessage* archive) const;
void Evaluate();
@ -87,6 +87,8 @@ class CalcView : public BView {
void _ShowKeypad(bool show);
void _FetchAppIcon(BBitmap* into);
status_t _LoadSettings(BMessage* archive);
// grid dimensions
int16 fColums;
int16 fRows;

View File

@ -24,7 +24,7 @@
static const char* kWindowTitle = "DeskCalc";
CalcWindow::CalcWindow(BRect frame)
CalcWindow::CalcWindow(BRect frame, BMessage *settings)
: BWindow(frame, kWindowTitle, B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
{
// create calculator view with calculator description and
@ -32,8 +32,10 @@ CalcWindow::CalcWindow(BRect frame)
BScreen screen(this);
rgb_color baseColor = screen.DesktopColor();
SetSizeLimits(100.0, 400.0, 100.0, 400.0);
frame.OffsetTo(B_ORIGIN);
fCalcView = new CalcView(frame, baseColor);
fCalcView = new CalcView(frame, baseColor, settings);
// create replicant dragger
frame.top = frame.bottom - 7.0f;
@ -45,7 +47,11 @@ CalcWindow::CalcWindow(BRect frame)
AddChild(fCalcView);
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
CalcWindow::SaveSettings(BMessage* archive) const
{

View File

@ -18,13 +18,12 @@ class CalcView;
class CalcWindow : public BWindow {
public:
CalcWindow(BRect frame);
CalcWindow(BRect frame, BMessage *settings);
virtual ~CalcWindow();
virtual void Show();
virtual bool QuitRequested();
bool LoadSettings(BMessage* archive);
status_t SaveSettings(BMessage* archive) const;
void SetFrame(BRect frame,