xref: /haiku/src/apps/deskcalc/CalcView.h (revision e5d65858f2361fe0552495b61620c84dcee6bc00)
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 BMessage;
37 class BPopUpMenu;
38 class CalcOptions;
39 class CalcOptionsWindow;
40 class ExpressionTextView;
41 
42 _EXPORT
43 class CalcView : public BView {
44  public:
45 
46 	static	CalcView*			Instantiate(BMessage* archive);
47 
48 
49 								CalcView(BRect frame,
50 									rgb_color rgbBaseColor,
51 									BMessage* settings);
52 								CalcView(BMessage* archive);
53 	virtual						~CalcView();
54 
55 	virtual	void				AttachedToWindow();
56 	virtual	void				MessageReceived(BMessage* message);
57 	virtual	void				Draw(BRect updateRect);
58 	virtual	void				MouseDown(BPoint point);
59 	virtual	void				MouseUp(BPoint point);
60 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
61 	virtual	void				MakeFocus(bool focused = true);
62 	virtual	void				ResizeTo(float width, float height);
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 
121 			// grid dimensions
122 			int16				fColumns;
123 			int16				fRows;
124 
125 			// color scheme
126 			rgb_color			fBaseColor;
127 			rgb_color			fLightColor;
128 			rgb_color			fDarkColor;
129 			rgb_color			fButtonTextColor;
130 			rgb_color			fExpressionBGColor;
131 			rgb_color			fExpressionTextColor;
132 
133 			// view dimensions
134 			float				fWidth;
135 			float				fHeight;
136 
137 			// keypad grid
138 			struct CalcKey;
139 
140 			char*				fKeypadDescription;
141 			CalcKey*			fKeypad;
142 
143 			// icon
144 			BBitmap*			fCalcIcon;
145 
146 			// expression
147 			ExpressionTextView*	fExpressionTextView;
148 
149 			// pop-up context menu.
150 			BPopUpMenu*			fPopUpMenu;
151 			BMenuItem*			fAutoNumlockItem;
152 			BMenuItem*			fAudioFeedbackItem;
153 
154 			BMenuItem*			fAngleModeRadianItem;
155 			BMenuItem*			fAngleModeDegreeItem;
156 
157 			BMenuItem*			fKeypadModeCompactItem;
158 			BMenuItem*			fKeypadModeBasicItem;
159 			BMenuItem*			fKeypadModeScientificItem;
160 
161 			// calculator options.
162 			CalcOptions*		fOptions;
163 };
164 
165 #endif // _CALC_VIEW_H
166