xref: /haiku/src/apps/deskcalc/CalcView.h (revision 385ee03ba83b7a40d315e17b03031b3ca37820c0)
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.
5  *
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
11  */
12 #ifndef _CALC_VIEW_H
13 #define _CALC_VIEW_H
14 
15 
16 #include <View.h>
17 
18 
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'
28 };
29 
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;
34 
35 class BString;
36 class BMenuItem;
37 class BMessage;
38 class BMessageRunner;
39 class BPopUpMenu;
40 class CalcOptions;
41 class CalcOptionsWindow;
42 class ExpressionTextView;
43 
44 _EXPORT
45 class CalcView : public BView {
46  public:
47 
48 	static	CalcView*			Instantiate(BMessage* archive);
49 
50 
51 								CalcView(BRect frame,
52 									rgb_color rgbBaseColor,
53 									BMessage* settings);
54 								CalcView(BMessage* archive);
55 	virtual						~CalcView();
56 
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);
65 
66 			// Archive this view.
67 	virtual	status_t			Archive(BMessage* archive, bool deep) const;
68 
69 			// Cut contents of view to system clipboard.
70 			void				Cut();
71 
72 			// Copy contents of view to system clipboard.
73 			void				Copy();
74 
75 			// Paste contents of system clipboard to view.
76 			void				Paste(BMessage* message);
77 
78 			// Save current settings
79 			status_t			SaveSettings(BMessage* archive) const;
80 
81 			// Evaluate the expression
82 			void				Evaluate();
83 
84 			// Flash the key on the keypad
85 			void				FlashKey(const char* bytes, int32 numBytes);
86 
87 			// Toggle whether or not the Num Lock key starts on
88 			void				ToggleAutoNumlock(void);
89 
90 			// Toggle whether or not to provide audio feedback
91 			// (option currently disabled)
92 			void				ToggleAudioFeedback(void);
93 
94 			// Set the angle mode to degrees or radians
95 			void				SetDegreeMode(bool degrees);
96 
97 			// Set the keypad mode
98 			void				SetKeypadMode(uint8 mode);
99 
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);
105 
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);
111 
112 			void				_Colorize();
113 
114 			void				_CreatePopUpMenu(bool addKeypadModeMenuItems);
115 
116 			BRect				_ExpressionRect() const;
117 			BRect				_KeypadRect() const;
118 
119 			void				_MarkKeypadItems(uint8 mode);
120 
121 			void				_FetchAppIcon(BBitmap* into);
122 			bool				_IsEmbedded();
123 
124 			void				_SetEnabled(bool enable);
125 
126 			// grid dimensions
127 			int16				fColumns;
128 			int16				fRows;
129 
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;
137 
138 			bool				fHasCustomBaseColor;
139 
140 			// view dimensions
141 			float				fWidth;
142 			float				fHeight;
143 
144 			// keypad grid
145 			struct CalcKey;
146 
147 			char*				fKeypadDescription;
148 			CalcKey*			fKeypad;
149 
150 			// icon
151 			BBitmap*			fCalcIcon;
152 
153 			// expression
154 			ExpressionTextView*	fExpressionTextView;
155 
156 			// pop-up context menu.
157 			BPopUpMenu*			fPopUpMenu;
158 			BMenuItem*			fAutoNumlockItem;
159 			BMenuItem*			fAudioFeedbackItem;
160 
161 			BMenuItem*			fAngleModeRadianItem;
162 			BMenuItem*			fAngleModeDegreeItem;
163 
164 			BMenuItem*			fKeypadModeCompactItem;
165 			BMenuItem*			fKeypadModeBasicItem;
166 			BMenuItem*			fKeypadModeScientificItem;
167 
168 			// calculator options.
169 			CalcOptions*		fOptions;
170 
171 			thread_id			fEvaluateThread;
172 			BMessageRunner*		fEvaluateMessageRunner;
173 			sem_id				fEvaluateSemaphore;
174 			bool				fEnabled;
175 };
176 
177 #endif // _CALC_VIEW_H
178