BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / deskcalc / CalcView.h
blobbf126917d194e68e8ed25b90cd4359eb8ab1fd26
1 /*
2 * Copyright 2006-2013, Haiku, Inc. All rights reserved.
3 * Copyright 1997, 1998 R3 Software Ltd. All Rights Reserved.
4 * Distributed under the terms of the MIT License.
6 * Authors:
7 * Stephan Aßmus, superstippi@gmx.de
8 * Philippe Saint-Pierre, stpere@gmail.com
9 * John Scipione, jscipione@gmail.com
10 * Timothy Wayper, timmy@wunderbear.com
12 #ifndef _CALC_VIEW_H
13 #define _CALC_VIEW_H
16 #include <View.h>
19 enum {
20 MSG_OPTIONS_AUTO_NUM_LOCK = 'oanl',
21 MSG_OPTIONS_AUDIO_FEEDBACK = 'oafb',
22 MSG_OPTIONS_ANGLE_MODE_RADIAN = 'oamr',
23 MSG_OPTIONS_ANGLE_MODE_DEGREE = 'oamd',
24 MSG_OPTIONS_KEYPAD_MODE_COMPACT = 'okmc',
25 MSG_OPTIONS_KEYPAD_MODE_BASIC = 'okmb',
26 MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC = 'okms',
27 MSG_UNFLASH_KEY = 'uflk'
30 static const float kMinimumWidthBasic = 130.0f;
31 static const float kMaximumWidthBasic = 400.0f;
32 static const float kMinimumHeightBasic = 130.0f;
33 static const float kMaximumHeightBasic = 400.0f;
35 class BString;
36 class BMenuItem;
37 class BMessage;
38 class BMessageRunner;
39 class BPopUpMenu;
40 class CalcOptions;
41 class CalcOptionsWindow;
42 class ExpressionTextView;
44 _EXPORT
45 class CalcView : public BView {
46 public:
48 static CalcView* Instantiate(BMessage* archive);
51 CalcView(BRect frame,
52 rgb_color rgbBaseColor,
53 BMessage* settings);
54 CalcView(BMessage* archive);
55 virtual ~CalcView();
57 virtual void AttachedToWindow();
58 virtual void MessageReceived(BMessage* message);
59 virtual void Draw(BRect updateRect);
60 virtual void MouseDown(BPoint point);
61 virtual void MouseUp(BPoint point);
62 virtual void KeyDown(const char* bytes, int32 numBytes);
63 virtual void MakeFocus(bool focused = true);
64 virtual void FrameResized(float width, float height);
66 // Archive this view.
67 virtual status_t Archive(BMessage* archive, bool deep) const;
69 // Cut contents of view to system clipboard.
70 void Cut();
72 // Copy contents of view to system clipboard.
73 void Copy();
75 // Paste contents of system clipboard to view.
76 void Paste(BMessage* message);
78 // Save current settings
79 status_t SaveSettings(BMessage* archive) const;
81 // Evaluate the expression
82 void Evaluate();
84 // Flash the key on the keypad
85 void FlashKey(const char* bytes, int32 numBytes);
87 // Toggle whether or not the Num Lock key starts on
88 void ToggleAutoNumlock(void);
90 // Toggle whether or not to provide audio feedback
91 // (option currently disabled)
92 void ToggleAudioFeedback(void);
94 // Set the angle mode to degrees or radians
95 void SetDegreeMode(bool degrees);
97 // Set the keypad mode
98 void SetKeypadMode(uint8 mode);
100 private:
101 static status_t _EvaluateThread(void* data);
102 void _Init(BMessage* settings);
103 status_t _LoadSettings(BMessage* archive);
104 void _ParseCalcDesc(const char* keypadDescription);
106 void _PressKey(int key);
107 void _PressKey(const char* label);
108 int32 _KeyForLabel(const char* label) const;
109 void _FlashKey(int32 key, uint32 flashFlags);
110 void _AudioFeedback(bool inBackGround);
112 void _Colorize();
114 void _CreatePopUpMenu(bool addKeypadModeMenuItems);
116 BRect _ExpressionRect() const;
117 BRect _KeypadRect() const;
119 void _MarkKeypadItems(uint8 mode);
121 void _FetchAppIcon(BBitmap* into);
122 bool _IsEmbedded();
124 void _SetEnabled(bool enable);
126 // grid dimensions
127 int16 fColumns;
128 int16 fRows;
130 // color scheme
131 rgb_color fBaseColor;
132 rgb_color fLightColor;
133 rgb_color fDarkColor;
134 rgb_color fButtonTextColor;
135 rgb_color fExpressionBGColor;
136 rgb_color fExpressionTextColor;
138 bool fHasCustomBaseColor;
140 // view dimensions
141 float fWidth;
142 float fHeight;
144 // keypad grid
145 struct CalcKey;
147 char* fKeypadDescription;
148 CalcKey* fKeypad;
150 // icon
151 BBitmap* fCalcIcon;
153 // expression
154 ExpressionTextView* fExpressionTextView;
156 // pop-up context menu.
157 BPopUpMenu* fPopUpMenu;
158 BMenuItem* fAutoNumlockItem;
159 BMenuItem* fAudioFeedbackItem;
161 BMenuItem* fAngleModeRadianItem;
162 BMenuItem* fAngleModeDegreeItem;
164 BMenuItem* fKeypadModeCompactItem;
165 BMenuItem* fKeypadModeBasicItem;
166 BMenuItem* fKeypadModeScientificItem;
168 // calculator options.
169 CalcOptions* fOptions;
171 thread_id fEvaluateThread;
172 BMessageRunner* fEvaluateMessageRunner;
173 sem_id fEvaluateSemaphore;
174 bool fEnabled;
177 #endif // _CALC_VIEW_H