-
-
Notifications
You must be signed in to change notification settings - Fork 338
/
CalcView.h
166 lines (125 loc) · 4.13 KB
/
CalcView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
* Copyright 2006-2013, Haiku, Inc. All rights reserved.
* Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Stephan Aßmus, superstippi@gmx.de
* Philippe Saint-Pierre, stpere@gmail.com
* John Scipione, jscipione@gmail.com
* Timothy Wayper, timmy@wunderbear.com
*/
#ifndef _CALC_VIEW_H
#define _CALC_VIEW_H
#include <View.h>
enum {
MSG_OPTIONS_AUTO_NUM_LOCK = 'oanl',
MSG_OPTIONS_AUDIO_FEEDBACK = 'oafb',
MSG_OPTIONS_ANGLE_MODE_RADIAN = 'oamr',
MSG_OPTIONS_ANGLE_MODE_DEGREE = 'oamd',
MSG_OPTIONS_KEYPAD_MODE_COMPACT = 'okmc',
MSG_OPTIONS_KEYPAD_MODE_BASIC = 'okmb',
MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC = 'okms',
MSG_UNFLASH_KEY = 'uflk'
};
static const float kMinimumWidthBasic = 130.0f;
static const float kMaximumWidthBasic = 400.0f;
static const float kMinimumHeightBasic = 130.0f;
static const float kMaximumHeightBasic = 400.0f;
class BString;
class BMenuItem;
class BMessage;
class BPopUpMenu;
class CalcOptions;
class CalcOptionsWindow;
class ExpressionTextView;
_EXPORT
class CalcView : public BView {
public:
static CalcView* Instantiate(BMessage* archive);
CalcView(BRect frame,
rgb_color rgbBaseColor,
BMessage* settings);
CalcView(BMessage* archive);
virtual ~CalcView();
virtual void AttachedToWindow();
virtual void MessageReceived(BMessage* message);
virtual void Draw(BRect updateRect);
virtual void MouseDown(BPoint point);
virtual void MouseUp(BPoint point);
virtual void KeyDown(const char* bytes, int32 numBytes);
virtual void MakeFocus(bool focused = true);
virtual void FrameResized(float width, float height);
// Archive this view.
virtual status_t Archive(BMessage* archive, bool deep) const;
// Cut contents of view to system clipboard.
void Cut();
// Copy contents of view to system clipboard.
void Copy();
// Paste contents of system clipboard to view.
void Paste(BMessage* message);
// Save current settings
status_t SaveSettings(BMessage* archive) const;
// Evaluate the expression
void Evaluate();
// Flash the key on the keypad
void FlashKey(const char* bytes, int32 numBytes);
// Toggle whether or not the Num Lock key starts on
void ToggleAutoNumlock(void);
// Toggle whether or not to provide audio feedback
// (option currently disabled)
void ToggleAudioFeedback(void);
// Set the angle mode to degrees or radians
void SetDegreeMode(bool degrees);
// Set the keypad mode
void SetKeypadMode(uint8 mode);
private:
void _Init(BMessage* settings);
status_t _LoadSettings(BMessage* archive);
void _ParseCalcDesc(const char* keypadDescription);
void _PressKey(int key);
void _PressKey(const char* label);
int32 _KeyForLabel(const char* label) const;
void _FlashKey(int32 key, uint32 flashFlags);
void _AudioFeedback(bool inBackGround);
void _Colorize();
void _CreatePopUpMenu(bool addKeypadModeMenuItems);
BRect _ExpressionRect() const;
BRect _KeypadRect() const;
void _MarkKeypadItems(uint8 mode);
void _FetchAppIcon(BBitmap* into);
bool _IsEmbedded();
// grid dimensions
int16 fColumns;
int16 fRows;
// color scheme
rgb_color fBaseColor;
rgb_color fLightColor;
rgb_color fDarkColor;
rgb_color fButtonTextColor;
rgb_color fExpressionBGColor;
rgb_color fExpressionTextColor;
// view dimensions
float fWidth;
float fHeight;
// keypad grid
struct CalcKey;
char* fKeypadDescription;
CalcKey* fKeypad;
// icon
BBitmap* fCalcIcon;
// expression
ExpressionTextView* fExpressionTextView;
// pop-up context menu.
BPopUpMenu* fPopUpMenu;
BMenuItem* fAutoNumlockItem;
BMenuItem* fAudioFeedbackItem;
BMenuItem* fAngleModeRadianItem;
BMenuItem* fAngleModeDegreeItem;
BMenuItem* fKeypadModeCompactItem;
BMenuItem* fKeypadModeBasicItem;
BMenuItem* fKeypadModeScientificItem;
// calculator options.
CalcOptions* fOptions;
};
#endif // _CALC_VIEW_H