remembers option window position and avoids opening another instance of it, options window is not resizable anymore
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@17742 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
b962260488
commit
e61b54a291
@ -25,9 +25,14 @@ CalcOptions::CalcOptions()
|
||||
}
|
||||
|
||||
|
||||
CalcOptionsWindow::CalcOptionsWindow(BRect frame, CalcOptions *options)
|
||||
: BWindow(frame, "Options", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS),
|
||||
fOptions(options)
|
||||
CalcOptionsWindow::CalcOptionsWindow(BRect frame, CalcOptions *options,
|
||||
BMessage* quitMessage,
|
||||
BHandler* target)
|
||||
: BWindow(frame, "Options", B_TITLED_WINDOW,
|
||||
B_ASYNCHRONOUS_CONTROLS | B_NOT_RESIZABLE),
|
||||
fOptions(options),
|
||||
fQuitMessage(quitMessage),
|
||||
fTarget(target)
|
||||
{
|
||||
// TODO: revisit when Ingo has created his layout framework...
|
||||
frame.OffsetTo(B_ORIGIN);
|
||||
@ -82,14 +87,27 @@ CalcOptionsWindow::CalcOptionsWindow(BRect frame, CalcOptions *options)
|
||||
|
||||
|
||||
CalcOptionsWindow::~CalcOptionsWindow()
|
||||
{
|
||||
delete fQuitMessage;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
CalcOptionsWindow::QuitRequested()
|
||||
{
|
||||
// auto num-lock
|
||||
fOptions->auto_num_lock = fAutoNumLockCheckBox->Value() == B_CONTROL_ON;
|
||||
|
||||
// audio feedback
|
||||
fOptions->audio_feedback = fAudioFeedbackCheckBox->Value() == B_CONTROL_ON;
|
||||
|
||||
// notify target of our demise
|
||||
if (fQuitMessage && fTarget && fTarget->Looper()) {
|
||||
fQuitMessage->AddRect("window frame", Frame());
|
||||
fTarget->Looper()->PostMessage(fQuitMessage, fTarget);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -26,12 +26,18 @@ class BButton;
|
||||
class CalcOptionsWindow : public BWindow {
|
||||
public:
|
||||
CalcOptionsWindow(BRect frame,
|
||||
CalcOptions* options);
|
||||
CalcOptions* options,
|
||||
BMessage* quitMessage,
|
||||
BHandler* target);
|
||||
|
||||
virtual ~CalcOptionsWindow();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
CalcOptions* fOptions;
|
||||
BMessage* fQuitMessage;
|
||||
BHandler* fTarget;
|
||||
|
||||
BCheckBox* fAutoNumLockCheckBox;
|
||||
BCheckBox* fAudioFeedbackCheckBox;
|
||||
|
@ -35,7 +35,8 @@ const float K_FONT_YPROP = 0.6f;
|
||||
const float K_DISPLAY_YPROP = 0.2;
|
||||
|
||||
enum {
|
||||
K_OPTIONS_REQUESTED = 'opts'
|
||||
K_OPTIONS_REQUESTED = 'opts',
|
||||
K_OPTIONS_GONE = 'opgn',
|
||||
};
|
||||
|
||||
// default calculator key pad layout
|
||||
@ -86,7 +87,8 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
|
||||
fPopUpMenu(NULL),
|
||||
|
||||
fOptions(new CalcOptions()),
|
||||
fOptionsWindow(NULL)
|
||||
fOptionsWindow(NULL),
|
||||
fOptionsWindowFrame(30.0, 50.0, 230.0, 200.0)
|
||||
{
|
||||
// tell the app server not to erase our b/g
|
||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||
@ -120,7 +122,8 @@ CalcView::CalcView(BMessage* archive)
|
||||
fPopUpMenu(NULL),
|
||||
|
||||
fOptions(new CalcOptions()),
|
||||
fOptionsWindow(NULL)
|
||||
fOptionsWindow(NULL),
|
||||
fOptionsWindowFrame(30.0, 50.0, 230.0, 200.0)
|
||||
{
|
||||
// read data from archive
|
||||
LoadSettings(archive);
|
||||
@ -187,11 +190,29 @@ CalcView::MessageReceived(BMessage* message)
|
||||
|
||||
// calculator options window requested
|
||||
case K_OPTIONS_REQUESTED: {
|
||||
BRect frame(30.0f, 50.0f, 230.0, 200.0);
|
||||
fOptionsWindow = new CalcOptionsWindow(frame, fOptions);
|
||||
if (fOptionsWindow != NULL) {
|
||||
// TODO: remove race condition and activate
|
||||
// fOptionsWindow->Activate();
|
||||
break;
|
||||
}
|
||||
|
||||
fOptionsWindow = new CalcOptionsWindow(fOptionsWindowFrame,
|
||||
fOptions,
|
||||
new BMessage(K_OPTIONS_GONE),
|
||||
this);
|
||||
fOptionsWindow->Show();
|
||||
break;
|
||||
}
|
||||
|
||||
// calculator options window has quit
|
||||
case K_OPTIONS_GONE: {
|
||||
fOptionsWindow = NULL;
|
||||
|
||||
BRect frame;
|
||||
if (message->FindRect("window frame", &frame) == B_OK)
|
||||
fOptionsWindowFrame = frame;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
@ -284,7 +305,7 @@ CalcView::Draw(BRect updateRect)
|
||||
SetLowColor(fBaseColor);
|
||||
SetDrawingMode(B_OP_COPY);
|
||||
SetFontSize(((fHeight - sizeDisp)/(float)fRows) * K_FONT_YPROP);
|
||||
float baselineOffset = ((fHeight - sizeDisp)/(float)fRows)
|
||||
float baselineOffset = ((fHeight - sizeDisp) / (float)fRows)
|
||||
* (1.0 - K_FONT_YPROP) * 0.5;
|
||||
CalcKey *key = fKeypad;
|
||||
for (int row = 0; row < fRows; row++) {
|
||||
@ -601,7 +622,12 @@ CalcView::LoadSettings(BMessage* archive)
|
||||
} else {
|
||||
puts("Missing options from CalcView archive.\n");
|
||||
}
|
||||
|
||||
|
||||
// load option window frame
|
||||
BRect frame;
|
||||
if (archive->FindRect("option window frame", &frame) == B_OK)
|
||||
fOptionsWindowFrame = frame;
|
||||
|
||||
// load display text
|
||||
const char* display;
|
||||
if (archive->FindString("displayText", &display) < B_OK) {
|
||||
@ -645,6 +671,10 @@ CalcView::SaveSettings(BMessage* archive) const
|
||||
ret = archive->AddData("options", B_RAW_TYPE,
|
||||
fOptions, sizeof(CalcOptions));
|
||||
|
||||
// record option window frame
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddRect("option window frame", fOptionsWindowFrame);
|
||||
|
||||
// record display text
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddString("displayText", fExpression.String());
|
||||
|
@ -104,6 +104,7 @@ class CalcView : public BView {
|
||||
// calculator options.
|
||||
CalcOptions* fOptions;
|
||||
CalcOptionsWindow* fOptionsWindow;
|
||||
BRect fOptionsWindowFrame;
|
||||
};
|
||||
|
||||
#endif // _CALC_VIEW_H
|
||||
|
Loading…
Reference in New Issue
Block a user