xref: /haiku/src/apps/deskcalc/CalcView.h (revision 4a3268e14fff4dd5a456d824b48ce6503368e4c1)
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 BPopUpMenu;
39 class CalcOptions;
40 class CalcOptionsWindow;
41 class ExpressionTextView;
42 
43 _EXPORT
44 class CalcView : public BView {
45  public:
46 
47 	static	CalcView*			Instantiate(BMessage* archive);
48 
49 
50 								CalcView(BRect frame,
51 									rgb_color rgbBaseColor,
52 									BMessage* settings);
53 								CalcView(BMessage* archive);
54 	virtual						~CalcView();
55 
56 	virtual	void				AttachedToWindow();
57 	virtual	void				MessageReceived(BMessage* message);
58 	virtual	void				Draw(BRect updateRect);
59 	virtual	void				MouseDown(BPoint point);
60 	virtual	void				MouseUp(BPoint point);
61 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
62 	virtual	void				MakeFocus(bool focused = true);
63 	virtual	void				FrameResized(float width, float height);
64 
65 			// Archive this view.
66 	virtual	status_t			Archive(BMessage* archive, bool deep) const;
67 
68 			// Cut contents of view to system clipboard.
69 			void				Cut();
70 
71 			// Copy contents of view to system clipboard.
72 			void				Copy();
73 
74 			// Paste contents of system clipboard to view.
75 			void				Paste(BMessage* message);
76 
77 			// Save current settings
78 			status_t			SaveSettings(BMessage* archive) const;
79 
80 			// Evaluate the expression
81 			void				Evaluate();
82 
83 			// Flash the key on the keypad
84 			void				FlashKey(const char* bytes, int32 numBytes);
85 
86 			// Toggle whether or not the Num Lock key starts on
87 			void				ToggleAutoNumlock(void);
88 
89 			// Toggle whether or not to provide audio feedback
90 			// (option currently disabled)
91 			void				ToggleAudioFeedback(void);
92 
93 			// Set the angle mode to degrees or radians
94 			void				SetDegreeMode(bool degrees);
95 
96 			// Set the keypad mode
97 			void				SetKeypadMode(uint8 mode);
98 
99  private:
100 			void				_Init(BMessage* settings);
101 			status_t			_LoadSettings(BMessage* archive);
102 			void				_ParseCalcDesc(const char* keypadDescription);
103 
104 			void				_PressKey(int key);
105 			void				_PressKey(const char* label);
106 			int32				_KeyForLabel(const char* label) const;
107 			void				_FlashKey(int32 key, uint32 flashFlags);
108 			void				_AudioFeedback(bool inBackGround);
109 
110 			void				_Colorize();
111 
112 			void				_CreatePopUpMenu(bool addKeypadModeMenuItems);
113 
114 			BRect				_ExpressionRect() const;
115 			BRect				_KeypadRect() const;
116 
117 			void				_MarkKeypadItems(uint8 mode);
118 
119 			void				_FetchAppIcon(BBitmap* into);
120 			bool				_IsEmbedded();
121 
122 			// grid dimensions
123 			int16				fColumns;
124 			int16				fRows;
125 
126 			// color scheme
127 			rgb_color			fBaseColor;
128 			rgb_color			fLightColor;
129 			rgb_color			fDarkColor;
130 			rgb_color			fButtonTextColor;
131 			rgb_color			fExpressionBGColor;
132 			rgb_color			fExpressionTextColor;
133 
134 			// view dimensions
135 			float				fWidth;
136 			float				fHeight;
137 
138 			// keypad grid
139 			struct CalcKey;
140 
141 			char*				fKeypadDescription;
142 			CalcKey*			fKeypad;
143 
144 			// icon
145 			BBitmap*			fCalcIcon;
146 
147 			// expression
148 			ExpressionTextView*	fExpressionTextView;
149 
150 			// pop-up context menu.
151 			BPopUpMenu*			fPopUpMenu;
152 			BMenuItem*			fAutoNumlockItem;
153 			BMenuItem*			fAudioFeedbackItem;
154 
155 			BMenuItem*			fAngleModeRadianItem;
156 			BMenuItem*			fAngleModeDegreeItem;
157 
158 			BMenuItem*			fKeypadModeCompactItem;
159 			BMenuItem*			fKeypadModeBasicItem;
160 			BMenuItem*			fKeypadModeScientificItem;
161 
162 			// calculator options.
163 			CalcOptions*		fOptions;
164 };
165 
166 #endif // _CALC_VIEW_H
167