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:
Stephan Aßmus
2006-06-06 16:43:42 +00:00
parent b962260488
commit e61b54a291
4 changed files with 68 additions and 13 deletions
+23 -5
View File
@@ -25,9 +25,14 @@ CalcOptions::CalcOptions()
} }
CalcOptionsWindow::CalcOptionsWindow(BRect frame, CalcOptions *options) CalcOptionsWindow::CalcOptionsWindow(BRect frame, CalcOptions *options,
: BWindow(frame, "Options", B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS), BMessage* quitMessage,
fOptions(options) 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... // TODO: revisit when Ingo has created his layout framework...
frame.OffsetTo(B_ORIGIN); frame.OffsetTo(B_ORIGIN);
@@ -82,14 +87,27 @@ CalcOptionsWindow::CalcOptionsWindow(BRect frame, CalcOptions *options)
CalcOptionsWindow::~CalcOptionsWindow() CalcOptionsWindow::~CalcOptionsWindow()
{
delete fQuitMessage;
}
bool
CalcOptionsWindow::QuitRequested()
{ {
// auto num-lock // auto num-lock
fOptions->auto_num_lock = fAutoNumLockCheckBox->Value() == B_CONTROL_ON; fOptions->auto_num_lock = fAutoNumLockCheckBox->Value() == B_CONTROL_ON;
// audio feedback // audio feedback
fOptions->audio_feedback = fAudioFeedbackCheckBox->Value() == B_CONTROL_ON; 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;
} }
+7 -1
View File
@@ -26,12 +26,18 @@ class BButton;
class CalcOptionsWindow : public BWindow { class CalcOptionsWindow : public BWindow {
public: public:
CalcOptionsWindow(BRect frame, CalcOptionsWindow(BRect frame,
CalcOptions* options); CalcOptions* options,
BMessage* quitMessage,
BHandler* target);
virtual ~CalcOptionsWindow(); virtual ~CalcOptionsWindow();
virtual bool QuitRequested();
private: private:
CalcOptions* fOptions; CalcOptions* fOptions;
BMessage* fQuitMessage;
BHandler* fTarget;
BCheckBox* fAutoNumLockCheckBox; BCheckBox* fAutoNumLockCheckBox;
BCheckBox* fAudioFeedbackCheckBox; BCheckBox* fAudioFeedbackCheckBox;
+37 -7
View File
@@ -35,7 +35,8 @@ const float K_FONT_YPROP = 0.6f;
const float K_DISPLAY_YPROP = 0.2; const float K_DISPLAY_YPROP = 0.2;
enum { enum {
K_OPTIONS_REQUESTED = 'opts' K_OPTIONS_REQUESTED = 'opts',
K_OPTIONS_GONE = 'opgn',
}; };
// default calculator key pad layout // default calculator key pad layout
@@ -86,7 +87,8 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
fPopUpMenu(NULL), fPopUpMenu(NULL),
fOptions(new CalcOptions()), 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 // tell the app server not to erase our b/g
SetViewColor(B_TRANSPARENT_32_BIT); SetViewColor(B_TRANSPARENT_32_BIT);
@@ -120,7 +122,8 @@ CalcView::CalcView(BMessage* archive)
fPopUpMenu(NULL), fPopUpMenu(NULL),
fOptions(new CalcOptions()), fOptions(new CalcOptions()),
fOptionsWindow(NULL) fOptionsWindow(NULL),
fOptionsWindowFrame(30.0, 50.0, 230.0, 200.0)
{ {
// read data from archive // read data from archive
LoadSettings(archive); LoadSettings(archive);
@@ -187,11 +190,29 @@ CalcView::MessageReceived(BMessage* message)
// calculator options window requested // calculator options window requested
case K_OPTIONS_REQUESTED: { case K_OPTIONS_REQUESTED: {
BRect frame(30.0f, 50.0f, 230.0, 200.0); if (fOptionsWindow != NULL) {
fOptionsWindow = new CalcOptionsWindow(frame, fOptions); // TODO: remove race condition and activate
// fOptionsWindow->Activate();
break;
}
fOptionsWindow = new CalcOptionsWindow(fOptionsWindowFrame,
fOptions,
new BMessage(K_OPTIONS_GONE),
this);
fOptionsWindow->Show(); fOptionsWindow->Show();
break; 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: default:
BView::MessageReceived(message); BView::MessageReceived(message);
@@ -284,7 +305,7 @@ CalcView::Draw(BRect updateRect)
SetLowColor(fBaseColor); SetLowColor(fBaseColor);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
SetFontSize(((fHeight - sizeDisp)/(float)fRows) * K_FONT_YPROP); 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; * (1.0 - K_FONT_YPROP) * 0.5;
CalcKey *key = fKeypad; CalcKey *key = fKeypad;
for (int row = 0; row < fRows; row++) { for (int row = 0; row < fRows; row++) {
@@ -601,7 +622,12 @@ CalcView::LoadSettings(BMessage* archive)
} else { } else {
puts("Missing options from CalcView archive.\n"); 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 // load display text
const char* display; const char* display;
if (archive->FindString("displayText", &display) < B_OK) { if (archive->FindString("displayText", &display) < B_OK) {
@@ -645,6 +671,10 @@ CalcView::SaveSettings(BMessage* archive) const
ret = archive->AddData("options", B_RAW_TYPE, ret = archive->AddData("options", B_RAW_TYPE,
fOptions, sizeof(CalcOptions)); fOptions, sizeof(CalcOptions));
// record option window frame
if (ret == B_OK)
ret = archive->AddRect("option window frame", fOptionsWindowFrame);
// record display text // record display text
if (ret == B_OK) if (ret == B_OK)
ret = archive->AddString("displayText", fExpression.String()); ret = archive->AddString("displayText", fExpression.String());
+1
View File
@@ -104,6 +104,7 @@ class CalcView : public BView {
// calculator options. // calculator options.
CalcOptions* fOptions; CalcOptions* fOptions;
CalcOptionsWindow* fOptionsWindow; CalcOptionsWindow* fOptionsWindow;
BRect fOptionsWindowFrame;
}; };
#endif // _CALC_VIEW_H #endif // _CALC_VIEW_H