Got rid of the options window and implemented them directly
in the context menu. Since there are only so few options, this is much more convenient. (Fixes part of #3236.) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28902 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2006-2009 Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Timothy Wayper <[email protected]>
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
#include "CalcOptions.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Message.h>
|
||||
|
||||
|
||||
CalcOptions::CalcOptions()
|
||||
: auto_num_lock(false),
|
||||
audio_feedback(false),
|
||||
show_keypad(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CalcOptions::LoadSettings(const BMessage* archive)
|
||||
{
|
||||
bool option;
|
||||
|
||||
if (archive->FindBool("auto num lock", &option) == B_OK)
|
||||
auto_num_lock = option;
|
||||
|
||||
if (archive->FindBool("audio feedback", &option) == B_OK)
|
||||
audio_feedback = option;
|
||||
|
||||
if (archive->FindBool("show keypad", &option) == B_OK)
|
||||
show_keypad = option;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CalcOptions::SaveSettings(BMessage* archive) const
|
||||
{
|
||||
status_t ret = archive->AddBool("auto num lock", auto_num_lock);
|
||||
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddBool("audio feedback", audio_feedback);
|
||||
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddBool("show keypad", show_keypad);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2006-2009 Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Timothy Wayper <[email protected]>
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef CALC_OPTIONS_H
|
||||
#define CALC_OPTIONS_H
|
||||
|
||||
#include <SupportDefs.h>
|
||||
|
||||
class BMessage;
|
||||
|
||||
struct CalcOptions {
|
||||
bool auto_num_lock; // automatically activate numlock
|
||||
bool audio_feedback; // provide audio feedback
|
||||
bool show_keypad; // show or hide the buttons
|
||||
|
||||
CalcOptions();
|
||||
|
||||
void LoadSettings(const BMessage* archive);
|
||||
status_t SaveSettings(BMessage* archive) const;
|
||||
};
|
||||
|
||||
#endif // CALC_OPTIONS_H
|
||||
@@ -1,166 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Timothy Wayper <[email protected]>
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
#include "CalcOptionsWindow.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <CheckBox.h>
|
||||
|
||||
|
||||
CalcOptions::CalcOptions()
|
||||
: auto_num_lock(false),
|
||||
audio_feedback(false),
|
||||
show_keypad(true)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
CalcOptions::LoadSettings(const BMessage* archive)
|
||||
{
|
||||
bool option;
|
||||
|
||||
if (archive->FindBool("auto num lock", &option) == B_OK)
|
||||
auto_num_lock = option;
|
||||
|
||||
if (archive->FindBool("audio feedback", &option) == B_OK)
|
||||
audio_feedback = option;
|
||||
|
||||
if (archive->FindBool("show keypad", &option) == B_OK)
|
||||
show_keypad = option;
|
||||
}
|
||||
|
||||
|
||||
status_t
|
||||
CalcOptions::SaveSettings(BMessage* archive) const
|
||||
{
|
||||
status_t ret = archive->AddBool("auto num lock", auto_num_lock);
|
||||
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddBool("audio feedback", audio_feedback);
|
||||
|
||||
if (ret == B_OK)
|
||||
ret = archive->AddBool("show keypad", show_keypad);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
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);
|
||||
BBox* bg = new BBox(frame, "bg", B_FOLLOW_ALL);
|
||||
bg->SetBorder(B_PLAIN_BORDER);
|
||||
AddChild(bg);
|
||||
|
||||
frame.InsetBy(5.0f, 5.0f);
|
||||
|
||||
// create interface components
|
||||
float y = 16.0f, vw, vh;
|
||||
|
||||
// auto numlock
|
||||
BRect viewframe(4.0f, y, frame.right, y + 16.0f);
|
||||
fAutoNumLockCheckBox = new BCheckBox(viewframe,
|
||||
"autoNumLockCheckBox", "Auto Num Lock", NULL);
|
||||
if (fOptions->auto_num_lock) {
|
||||
fAutoNumLockCheckBox->SetValue(B_CONTROL_ON);
|
||||
}
|
||||
bg->AddChild(fAutoNumLockCheckBox);
|
||||
fAutoNumLockCheckBox->ResizeToPreferred();
|
||||
y += fAutoNumLockCheckBox->Frame().Height();
|
||||
|
||||
// audio feedback
|
||||
viewframe.Set(4.0f, y, frame.right, y + 16.0f);
|
||||
fAudioFeedbackCheckBox = new BCheckBox(viewframe,
|
||||
"audioFeedbackCheckBox", "Audio Feedback", NULL);
|
||||
if (fOptions->audio_feedback) {
|
||||
fAudioFeedbackCheckBox->SetValue(B_CONTROL_ON);
|
||||
}
|
||||
bg->AddChild(fAudioFeedbackCheckBox);
|
||||
fAudioFeedbackCheckBox->ResizeToPreferred();
|
||||
y += fAudioFeedbackCheckBox->Frame().Height();
|
||||
|
||||
// show keypad
|
||||
viewframe.Set(4.0f, y, frame.right, y + 16.0f);
|
||||
fShowKeypadCheckBox = new BCheckBox(viewframe,
|
||||
"showKeypadCheckBox", "Show Keypad", NULL);
|
||||
if (fOptions->show_keypad) {
|
||||
fShowKeypadCheckBox->SetValue(B_CONTROL_ON);
|
||||
}
|
||||
bg->AddChild(fShowKeypadCheckBox);
|
||||
fShowKeypadCheckBox->ResizeToPreferred();
|
||||
y += fShowKeypadCheckBox->Frame().Height();
|
||||
|
||||
// create buttons
|
||||
viewframe.Set(0.0f, 0.0f, 40.0f, 40.0f);
|
||||
fOkButton = new BButton(viewframe, "okButton", "OK",
|
||||
new BMessage(B_QUIT_REQUESTED));
|
||||
fOkButton->GetPreferredSize(&vw, &vh);
|
||||
fOkButton->ResizeTo(vw, vh);
|
||||
fOkButton->MoveTo(frame.right - vw - 8.0f,
|
||||
frame.bottom - vh - 8.0f);
|
||||
bg->AddChild(fOkButton);
|
||||
|
||||
fOkButton->MakeDefault(true);
|
||||
|
||||
float cw, ch;
|
||||
fCancelButton = new BButton(viewframe, "cancelButton", "Cancel",
|
||||
new BMessage(B_QUIT_REQUESTED));
|
||||
fCancelButton->GetPreferredSize(&cw, &ch);
|
||||
fCancelButton->ResizeTo(cw, ch);
|
||||
fCancelButton->MoveTo(frame.right - vw - 16.0f - cw,
|
||||
frame.bottom - ch - 8.0f);
|
||||
bg->AddChild(fCancelButton);
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
|
||||
// show keypad
|
||||
fOptions->show_keypad = fShowKeypadCheckBox->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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright 2006 Haiku, Inc. All Rights Reserved.
|
||||
* Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Timothy Wayper <[email protected]>
|
||||
* Stephan Aßmus <[email protected]>
|
||||
*/
|
||||
|
||||
#ifndef _CALC_OPTIONS_WINDOW_H
|
||||
#define _CALC_OPTIONS_WINDOW_H
|
||||
|
||||
#include <Window.h>
|
||||
|
||||
struct CalcOptions {
|
||||
bool auto_num_lock; // automatically activate numlock
|
||||
bool audio_feedback; // provide audio feedback
|
||||
bool show_keypad; // show or hide the buttons
|
||||
|
||||
CalcOptions();
|
||||
|
||||
void LoadSettings(const BMessage* archive);
|
||||
status_t SaveSettings(BMessage* archive) const;
|
||||
};
|
||||
|
||||
class BCheckBox;
|
||||
class BButton;
|
||||
|
||||
class CalcOptionsWindow : public BWindow {
|
||||
public:
|
||||
CalcOptionsWindow(BRect frame,
|
||||
CalcOptions* options,
|
||||
BMessage* quitMessage,
|
||||
BHandler* target);
|
||||
|
||||
virtual ~CalcOptionsWindow();
|
||||
|
||||
virtual bool QuitRequested();
|
||||
|
||||
private:
|
||||
CalcOptions* fOptions;
|
||||
BMessage* fQuitMessage;
|
||||
BHandler* fTarget;
|
||||
|
||||
BCheckBox* fAutoNumLockCheckBox;
|
||||
BCheckBox* fAudioFeedbackCheckBox;
|
||||
BCheckBox* fShowKeypadCheckBox;
|
||||
|
||||
BButton* fOkButton;
|
||||
BButton* fCancelButton;
|
||||
};
|
||||
|
||||
#endif // _CALC_OPTIONS_WINDOW_H
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <Roster.h>
|
||||
|
||||
#include "CalcApplication.h"
|
||||
#include "CalcOptionsWindow.h"
|
||||
#include "CalcOptions.h"
|
||||
#include "ExpressionParser.h"
|
||||
#include "ExpressionTextView.h"
|
||||
|
||||
@@ -42,8 +42,9 @@ const float K_FONT_YPROP = 0.6f;
|
||||
const float K_DISPLAY_YPROP = 0.2f;
|
||||
|
||||
enum {
|
||||
K_OPTIONS_REQUESTED = 'opts',
|
||||
K_OPTIONS_GONE = 'opgn',
|
||||
K_OPTIONS_AUTO_NUM_LOCK = 'opan',
|
||||
K_OPTIONS_AUDIO_FEEDBACK = 'opaf',
|
||||
K_OPTIONS_SHOW_KEYPAD = 'opsk'
|
||||
};
|
||||
|
||||
// default calculator key pad layout
|
||||
@@ -93,13 +94,13 @@ CalcView::CalcView(BRect frame, rgb_color rgbBaseColor)
|
||||
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
|
||||
#endif
|
||||
|
||||
fAboutItem(NULL),
|
||||
fOptionsItem(NULL),
|
||||
fPopUpMenu(NULL),
|
||||
fAutoNumlockItem(NULL),
|
||||
fAudioFeedbackItem(NULL),
|
||||
fShowKeypadItem(NULL),
|
||||
fAboutItem(NULL),
|
||||
|
||||
fOptions(new CalcOptions()),
|
||||
fOptionsWindow(NULL),
|
||||
fOptionsWindowFrame(30.0, 50.0, 230.0, 200.0),
|
||||
fShowKeypad(true)
|
||||
{
|
||||
// create expression text view
|
||||
@@ -142,13 +143,13 @@ CalcView::CalcView(BMessage* archive)
|
||||
fCalcIcon(new BBitmap(BRect(0, 0, 15, 15), 0, B_CMAP8)),
|
||||
#endif
|
||||
|
||||
fAboutItem(NULL),
|
||||
fOptionsItem(NULL),
|
||||
fPopUpMenu(NULL),
|
||||
fAutoNumlockItem(NULL),
|
||||
fAudioFeedbackItem(NULL),
|
||||
fShowKeypadItem(NULL),
|
||||
fAboutItem(NULL),
|
||||
|
||||
fOptions(new CalcOptions()),
|
||||
fOptionsWindow(NULL),
|
||||
fOptionsWindowFrame(30.0, 50.0, 230.0, 200.0),
|
||||
fShowKeypad(true)
|
||||
{
|
||||
// create expression text view
|
||||
@@ -180,6 +181,8 @@ CalcView::AttachedToWindow()
|
||||
|
||||
BRect frame(Frame());
|
||||
FrameResized(frame.Width(), frame.Height());
|
||||
|
||||
fPopUpMenu->SetTargetForItems(this);
|
||||
}
|
||||
|
||||
|
||||
@@ -224,34 +227,22 @@ CalcView::MessageReceived(BMessage* message)
|
||||
case B_ABOUT_REQUESTED:
|
||||
AboutRequested();
|
||||
break;
|
||||
|
||||
// calculator options window requested
|
||||
case K_OPTIONS_REQUESTED: {
|
||||
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();
|
||||
case K_OPTIONS_AUTO_NUM_LOCK:
|
||||
fOptions->auto_num_lock = !fOptions->auto_num_lock;
|
||||
fAutoNumlockItem->SetMarked(fOptions->auto_num_lock);
|
||||
break;
|
||||
}
|
||||
|
||||
// calculator options window has quit
|
||||
case K_OPTIONS_GONE: {
|
||||
fOptionsWindow = NULL;
|
||||
|
||||
BRect frame;
|
||||
if (message->FindRect("window frame", &frame) == B_OK)
|
||||
fOptionsWindowFrame = frame;
|
||||
case K_OPTIONS_AUDIO_FEEDBACK:
|
||||
fOptions->audio_feedback = !fOptions->audio_feedback;
|
||||
fAudioFeedbackItem->SetMarked(fOptions->audio_feedback);
|
||||
break;
|
||||
|
||||
case K_OPTIONS_SHOW_KEYPAD:
|
||||
fOptions->show_keypad = !fOptions->show_keypad;
|
||||
fShowKeypadItem->SetMarked(fOptions->show_keypad);
|
||||
_ShowKeypad(fOptions->show_keypad);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
@@ -550,7 +541,7 @@ CalcView::AboutRequested()
|
||||
"DeskCalc v2.1.0\n\n"
|
||||
"written by Timothy Wayper,\nStephan Aßmus and Ingo Weinhold\n\n"
|
||||
B_UTF8_COPYRIGHT"1997, 1998 R3 Software Ltd.\n"
|
||||
B_UTF8_COPYRIGHT"2006 Haiku, Inc.\n\n"
|
||||
B_UTF8_COPYRIGHT"2006-2009 Haiku, Inc.\n\n"
|
||||
"All Rights Reserved.", "Cool");
|
||||
alert->Go(NULL);
|
||||
}
|
||||
@@ -701,11 +692,6 @@ CalcView::LoadSettings(BMessage* archive)
|
||||
fOptions->LoadSettings(archive);
|
||||
fShowKeypad = fOptions->show_keypad;
|
||||
|
||||
// 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) {
|
||||
@@ -751,10 +737,6 @@ CalcView::SaveSettings(BMessage* archive) const
|
||||
if (ret == B_OK)
|
||||
ret = fOptions->SaveSettings(archive);
|
||||
|
||||
// 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", fExpressionTextView->Text());
|
||||
@@ -962,15 +944,28 @@ void
|
||||
CalcView::_CreatePopUpMenu()
|
||||
{
|
||||
// construct items
|
||||
fAboutItem = new BMenuItem("About DeskCalc" B_UTF8_ELLIPSIS,
|
||||
fAutoNumlockItem = new BMenuItem("Enable Num Lock on start up",
|
||||
new BMessage(K_OPTIONS_AUTO_NUM_LOCK));
|
||||
fAudioFeedbackItem = new BMenuItem("Audio Feedback" B_UTF8_ELLIPSIS,
|
||||
new BMessage(K_OPTIONS_AUDIO_FEEDBACK));
|
||||
fShowKeypadItem = new BMenuItem("Show Keypad",
|
||||
new BMessage(K_OPTIONS_SHOW_KEYPAD));
|
||||
fAboutItem = new BMenuItem("About DeskCalc",
|
||||
new BMessage(B_ABOUT_REQUESTED));
|
||||
fOptionsItem = new BMenuItem("Options" B_UTF8_ELLIPSIS,
|
||||
new BMessage(K_OPTIONS_REQUESTED));
|
||||
|
||||
// apply current settings
|
||||
fAutoNumlockItem->SetMarked(fOptions->auto_num_lock);
|
||||
fAudioFeedbackItem->SetMarked(fOptions->audio_feedback);
|
||||
fShowKeypadItem->SetMarked(fOptions->show_keypad);
|
||||
|
||||
// construct menu
|
||||
fPopUpMenu = new BPopUpMenu("pop-up", false, false);
|
||||
|
||||
fPopUpMenu->AddItem(fAutoNumlockItem);
|
||||
fPopUpMenu->AddItem(fAudioFeedbackItem);
|
||||
fPopUpMenu->AddItem(fShowKeypadItem);
|
||||
fPopUpMenu->AddSeparatorItem();
|
||||
fPopUpMenu->AddItem(fAboutItem);
|
||||
fPopUpMenu->AddItem(fOptionsItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -116,14 +116,14 @@ class CalcView : public BView {
|
||||
ExpressionTextView* fExpressionTextView;
|
||||
|
||||
// pop-up context menu.
|
||||
BMenuItem* fAboutItem;
|
||||
BMenuItem* fOptionsItem;
|
||||
BPopUpMenu* fPopUpMenu;
|
||||
BMenuItem* fAutoNumlockItem;
|
||||
BMenuItem* fAudioFeedbackItem;
|
||||
BMenuItem* fShowKeypadItem;
|
||||
BMenuItem* fAboutItem;
|
||||
|
||||
// calculator options.
|
||||
CalcOptions* fOptions;
|
||||
CalcOptionsWindow* fOptionsWindow;
|
||||
BRect fOptionsWindowFrame;
|
||||
bool fShowKeypad;
|
||||
};
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src apps deskcalc mapm_4.9.5 ] ;
|
||||
|
||||
Application DeskCalc :
|
||||
CalcApplication.cpp
|
||||
CalcOptionsWindow.cpp
|
||||
CalcOptions.cpp
|
||||
CalcView.cpp
|
||||
CalcWindow.cpp
|
||||
DeskCalc.cpp
|
||||
|
||||
Reference in New Issue
Block a user