xref: /haiku/src/apps/deskcalc/CalcView.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
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 BAboutWindow;
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				ResizeTo(float width, float height);
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 			void				_Init(BMessage* settings);
102 			status_t			_LoadSettings(BMessage* archive);
103 			void				_ParseCalcDesc(const char* keypadDescription);
104 
105 			void				_PressKey(int key);
106 			void				_PressKey(const char* label);
107 			int32				_KeyForLabel(const char* label) const;
108 			void				_FlashKey(int32 key, uint32 flashFlags);
109 			void				_AudioFeedback(bool inBackGround);
110 
111 			void				_Colorize();
112 
113 			void				_CreatePopUpMenu(bool addKeypadModeMenuItems);
114 
115 			BRect				_ExpressionRect() const;
116 			BRect				_KeypadRect() const;
117 
118 			void				_MarkKeypadItems(uint8 mode);
119 
120 			void				_FetchAppIcon(BBitmap* into);
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 			// about window for replicant
166 			BAboutWindow*		fAboutWindow;
167 };
168 
169 #endif // _CALC_VIEW_H
170