xref: /haiku/src/apps/deskcalc/CalcView.h (revision 6c4a44e36ba846c54467103f884d65dfa13e7fcb)
1 /*
2  * Copyright 2006 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  *		John Scipione <jscipione@gmail.com>
9  *		Timothy Wayper <timmy@wunderbear.com>
10  */
11 #ifndef _CALC_VIEW_H
12 #define _CALC_VIEW_H
13 
14 
15 #include <View.h>
16 
17 
18 enum {
19 	MSG_OPTIONS_AUTO_NUM_LOCK				= 'oanl',
20 	MSG_OPTIONS_AUDIO_FEEDBACK				= 'oafb',
21 	MSG_OPTIONS_ANGLE_MODE_RADIAN			= 'oamr',
22 	MSG_OPTIONS_ANGLE_MODE_DEGREE			= 'oamd',
23 	MSG_OPTIONS_KEYPAD_MODE_COMPACT			= 'okmc',
24 	MSG_OPTIONS_KEYPAD_MODE_BASIC			= 'okmb',
25 	MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC		= 'okms',
26 	MSG_UNFLASH_KEY							= 'uflk'
27 };
28 
29 static const float kMinimumWidthBasic		= 130.0f;
30 static const float kMaximumWidthBasic		= 400.0f;
31 static const float kMinimumHeightBasic		= 130.0f;
32 static const float kMaximumHeightBasic		= 400.0f;
33 
34 class BString;
35 class BMenuItem;
36 class BPopUpMenu;
37 class CalcOptions;
38 class CalcOptionsWindow;
39 class ExpressionTextView;
40 
41 _EXPORT
42 class CalcView : public BView {
43  public:
44 
45 	static	CalcView*			Instantiate(BMessage* archive);
46 
47 
48 								CalcView(BRect frame,
49 									rgb_color rgbBaseColor,
50 									BMessage* settings);
51 
52 								CalcView(BMessage* archive);
53 
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				ResizeTo(float width, float height);
64 	virtual	void				FrameResized(float width, float height);
65 
66 			// Present about box for view (replicant).
67 	virtual	void				AboutRequested();
68 
69 			// Archive this view.
70 	virtual	status_t			Archive(BMessage* archive, bool deep) const;
71 
72 			// Cut contents of view to system clipboard.
73 			void				Cut();
74 
75 			// Copy contents of view to system clipboard.
76 			void				Copy();
77 
78 			// Paste contents of system clipboard to view.
79 			void				Paste(BMessage* message);
80 
81 			// Save current settings
82 			status_t			SaveSettings(BMessage* archive) const;
83 
84 			// Evaluate the expression
85 			void				Evaluate();
86 
87 			// Flash the key on the keypad
88 			void				FlashKey(const char* bytes, int32 numBytes);
89 
90 			// Toggle whether or not the Num Lock key starts on
91 			void				ToggleAutoNumlock(void);
92 
93 			// Toggle whether or not to provide audio feedback
94 			// (option currently disabled)
95 			void				ToggleAudioFeedback(void);
96 
97 			// Set the angle mode to degrees or radians
98 			void				SetDegreeMode(bool degrees);
99 
100 			// Set the keypad mode
101 			void				SetKeypadMode(uint8 mode);
102 
103  private:
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 
123 			status_t			_LoadSettings(BMessage* archive);
124 
125 			// grid dimensions
126 			int16				fColumns;
127 			int16				fRows;
128 
129 			// color scheme
130 			rgb_color			fBaseColor;
131 			rgb_color			fLightColor;
132 			rgb_color			fDarkColor;
133 			rgb_color			fButtonTextColor;
134 			rgb_color			fExpressionBGColor;
135 			rgb_color			fExpressionTextColor;
136 
137 			// view dimensions
138 			float				fWidth;
139 			float				fHeight;
140 
141 			// keypad grid
142 			struct CalcKey;
143 
144 			char*				fKeypadDescription;
145 			CalcKey*			fKeypad;
146 
147 			// icon
148 			BBitmap*			fCalcIcon;
149 
150 			// expression
151 			ExpressionTextView*	fExpressionTextView;
152 
153 			// pop-up context menu.
154 			BPopUpMenu*			fPopUpMenu;
155 			BMenuItem*			fAutoNumlockItem;
156 			BMenuItem*			fAudioFeedbackItem;
157 
158 			BMenuItem*			fAngleModeRadianItem;
159 			BMenuItem*			fAngleModeDegreeItem;
160 
161 			BMenuItem*			fKeypadModeCompactItem;
162 			BMenuItem*			fKeypadModeBasicItem;
163 			BMenuItem*			fKeypadModeScientificItem;
164 
165 			// calculator options.
166 			CalcOptions*		fOptions;
167 };
168 
169 #endif // _CALC_VIEW_H
170