xref: /haiku/src/apps/deskcalc/CalcView.h (revision 239222b2369c39dc52df52b0a7cdd6cc0a91bc92)
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  *		Timothy Wayper <timmy@wunderbear.com>
8  *		Stephan Aßmus <superstippi@gmx.de>
9  */
10 
11 #ifndef _CALC_VIEW_H
12 #define _CALC_VIEW_H
13 
14 #include <View.h>
15 
16 class BString;
17 class BMenuItem;
18 class BPopUpMenu;
19 class CalcOptions;
20 class CalcOptionsWindow;
21 class ExpressionTextView;
22 
23 _EXPORT
24 class CalcView : public BView {
25  public:
26 
27 	static	CalcView*			Instantiate(BMessage* archive);
28 
29 
30 								CalcView(BRect frame,
31 										rgb_color rgbBaseColor,
32 										BMessage *settings);
33 
34 								CalcView(BMessage* archive);
35 
36 	virtual						~CalcView();
37 
38 	virtual	void				AttachedToWindow();
39 	virtual	void				MessageReceived(BMessage* message);
40 	virtual	void				Draw(BRect updateRect);
41 	virtual	void				MouseDown(BPoint point);
42 	virtual	void				MouseUp(BPoint point);
43 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
44 	virtual	void				MakeFocus(bool focused = true);
45 	virtual	void				FrameResized(float width, float height);
46 
47 			// Present about box for view (replicant).
48 	virtual	void				AboutRequested();
49 
50 			// Archive this view.
51 	virtual	status_t			Archive(BMessage* archive, bool deep) const;
52 
53 			// Cut contents of view to system clipboard.
54 			void				Cut();
55 
56 			// Copy contents of view to system clipboard.
57 			void				Copy();
58 
59 			// Paste contents of system clipboard to view.
60 			void				Paste(BMessage *message);
61 
62 			// Save current settings
63 			status_t			SaveSettings(BMessage* archive) const;
64 
65 			void				Evaluate();
66 
67 			void				FlashKey(const char* bytes, int32 numBytes);
68 
69  private:
70 			void				_ParseCalcDesc(const char* keypadDescription);
71 
72 			void				_PressKey(int key);
73 			void				_PressKey(const char* label);
74 			int32				_KeyForLabel(const char* label) const;
75 			void				_FlashKey(int32 key, uint32 flashFlags);
76 			void				_AudioFeedback(bool inBackGround);
77 
78 			void				_Colorize();
79 
80 			void				_CreatePopUpMenu();
81 
82 			BRect				_ExpressionRect() const;
83 			BRect				_KeypadRect() const;
84 
85 			void				_ShowKeypad(bool show);
86 			void				_FetchAppIcon(BBitmap* into);
87 
88 			status_t			_LoadSettings(BMessage* archive);
89 
90 			// grid dimensions
91 			int16				fColums;
92 			int16				fRows;
93 
94 			// color scheme
95 			rgb_color			fBaseColor;
96 			rgb_color			fLightColor;
97 			rgb_color			fDarkColor;
98 			rgb_color			fButtonTextColor;
99 			rgb_color			fExpressionBGColor;
100 			rgb_color			fExpressionTextColor;
101 
102 			// view dimensions
103 			float				fWidth;
104 			float				fHeight;
105 
106 			// keypad grid
107 			struct CalcKey;
108 
109 			char*				fKeypadDescription;
110 			CalcKey*			fKeypad;
111 
112 			// icon
113 			BBitmap*			fCalcIcon;
114 
115 			// expression
116 			ExpressionTextView*	fExpressionTextView;
117 
118 			// pop-up context menu.
119 			BPopUpMenu*			fPopUpMenu;
120 			BMenuItem*			fAutoNumlockItem;
121 			BMenuItem*			fAudioFeedbackItem;
122 			BMenuItem*			fShowKeypadItem;
123 			BMenuItem*			fAboutItem;
124 
125 			// calculator options.
126 			CalcOptions*		fOptions;
127 			bool				fShowKeypad;
128 };
129 
130 #endif // _CALC_VIEW_H
131