2 * Copyright 2006-2012 Haiku, Inc. All Rights Reserved.
3 * Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
4 * Distributed under the terms of the MIT License.
7 * Stephan Aßmus, superstippi@gmx.de
8 * John Scipione, jscipione@gmail.com
9 * Timothy Wayper, timmy@wunderbear.com
13 #include "CalcWindow.h"
19 #include <Application.h>
24 #include "CalcApplication.h"
25 #include "CalcOptions.h"
29 #undef B_TRANSLATION_CONTEXT
30 #define B_TRANSLATION_CONTEXT "Window"
33 CalcWindow::CalcWindow(BRect frame
, BMessage
* settings
)
35 BWindow(frame
, kAppName
, B_TITLED_WINDOW
, B_ASYNCHRONOUS_CONTROLS
36 | B_NOT_ANCHORED_ON_ACTIVATE
)
38 // create calculator view with calculator description and
39 // desktop background color
41 rgb_color baseColor
= screen
.DesktopColor();
43 // Size Limits are defined in CalcView.h
44 SetSizeLimits(kMinimumWidthBasic
, kMaximumWidthBasic
,
45 kMinimumHeightBasic
, kMaximumHeightBasic
);
47 frame
.OffsetTo(B_ORIGIN
);
48 fCalcView
= new CalcView(Frame(), baseColor
, settings
);
50 // create replicant dragger
51 BRect
replicantFrame(frame
);
52 replicantFrame
.top
= replicantFrame
.bottom
- 7.0f
;
53 replicantFrame
.left
= replicantFrame
.right
- 7.0f
;
54 BDragger
* dragger
= new BDragger(replicantFrame
, fCalcView
,
55 B_FOLLOW_RIGHT
| B_FOLLOW_BOTTOM
);
59 fCalcView
->AddChild(dragger
);
62 if (settings
->FindRect("window frame", &rect
) == B_OK
)
65 SetFrame(frame
, true);
67 // Add shortcut keys to menu options
68 AddShortcut('0', B_COMMAND_KEY
,
69 new BMessage(MSG_OPTIONS_KEYPAD_MODE_COMPACT
));
70 AddShortcut('1', B_COMMAND_KEY
,
71 new BMessage(MSG_OPTIONS_KEYPAD_MODE_BASIC
));
72 AddShortcut('2', B_COMMAND_KEY
,
73 new BMessage(MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC
));
77 CalcWindow::~CalcWindow()
83 CalcWindow::MessageReceived(BMessage
* message
)
85 switch (message
->what
) {
86 case MSG_OPTIONS_AUTO_NUM_LOCK
:
87 fCalcView
->ToggleAutoNumlock();
90 case MSG_OPTIONS_AUDIO_FEEDBACK
:
91 fCalcView
->ToggleAudioFeedback();
94 case MSG_OPTIONS_ANGLE_MODE_RADIAN
:
95 fCalcView
->SetDegreeMode(false);
98 case MSG_OPTIONS_ANGLE_MODE_DEGREE
:
99 fCalcView
->SetDegreeMode(true);
102 case MSG_OPTIONS_KEYPAD_MODE_COMPACT
:
103 fCalcView
->SetKeypadMode(KEYPAD_MODE_COMPACT
);
106 case MSG_OPTIONS_KEYPAD_MODE_BASIC
:
107 fCalcView
->SetKeypadMode(KEYPAD_MODE_BASIC
);
110 case MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC
:
111 fCalcView
->SetKeypadMode(KEYPAD_MODE_SCIENTIFIC
);
115 BWindow::MessageReceived(message
);
124 // NOTE: done here because the CalcView
125 // turns on numlock if the options say so...
126 // so we want to call MakeFocus() after
127 // the options have been read for sure...
128 fCalcView
->MakeFocus();
134 CalcWindow::QuitRequested()
136 be_app
->PostMessage(B_QUIT_REQUESTED
);
139 // NOTE: don't quit, since the app needs us
140 // for saving settings yet...
146 CalcWindow::SaveSettings(BMessage
* archive
) const
148 status_t ret
= archive
->AddRect("window frame", Frame());
152 return fCalcView
->SaveSettings(archive
);
157 CalcWindow::SetFrame(BRect frame
, bool forceCenter
)
159 // make sure window frame is on screen (center, if not)
160 BScreen
screen(this);
161 BRect screenFrame
= screen
.Frame();
162 if (forceCenter
|| !screenFrame
.Contains(frame
)) {
163 float left
= (screenFrame
.Width() - frame
.Width()) / 2.0;
164 float top
= (screenFrame
.Height() - frame
.Height()) / 2.0;
165 left
+= screenFrame
.left
;
166 top
+= screenFrame
.top
;
167 frame
.OffsetTo(left
, top
);
170 MoveTo(frame
.left
, frame
.top
);
171 ResizeTo(frame
.Width(), frame
.Height());