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 enum { 17 MSG_OPTIONS_AUTO_NUM_LOCK = 'oanl', 18 MSG_OPTIONS_AUDIO_FEEDBACK = 'oafb', 19 MSG_OPTIONS_KEYPAD_MODE_COMPACT = 'okmc', 20 MSG_OPTIONS_KEYPAD_MODE_BASIC = 'okmb', 21 MSG_OPTIONS_KEYPAD_MODE_SCIENTIFIC = 'okms', 22 MSG_UNFLASH_KEY = 'uflk' 23 }; 24 25 static const float kMinimumWidthBasic = 130.0f; 26 static const float kMaximumWidthBasic = 400.0f; 27 static const float kMinimumHeightBasic = 130.0f; 28 static const float kMaximumHeightBasic = 400.0f; 29 30 class BString; 31 class BMenuItem; 32 class BPopUpMenu; 33 class CalcOptions; 34 class CalcOptionsWindow; 35 class ExpressionTextView; 36 37 _EXPORT 38 class CalcView : public BView { 39 public: 40 41 static CalcView* Instantiate(BMessage* archive); 42 43 44 CalcView(BRect frame, 45 rgb_color rgbBaseColor, 46 BMessage* settings); 47 48 CalcView(BMessage* archive); 49 50 virtual ~CalcView(); 51 52 virtual void AttachedToWindow(); 53 virtual void MessageReceived(BMessage* message); 54 virtual void Draw(BRect updateRect); 55 virtual void MouseDown(BPoint point); 56 virtual void MouseUp(BPoint point); 57 virtual void KeyDown(const char* bytes, int32 numBytes); 58 virtual void MakeFocus(bool focused = true); 59 virtual void ResizeTo(float width, float height); 60 virtual void FrameResized(float width, float height); 61 62 // Present about box for view (replicant). 63 virtual void AboutRequested(); 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 keypad mode 94 void SetKeypadMode(uint8 mode); 95 96 private: 97 void _ParseCalcDesc(const char* keypadDescription); 98 99 void _PressKey(int key); 100 void _PressKey(const char* label); 101 int32 _KeyForLabel(const char* label) const; 102 void _FlashKey(int32 key, uint32 flashFlags); 103 void _AudioFeedback(bool inBackGround); 104 105 void _Colorize(); 106 107 void _CreatePopUpMenu(); 108 109 BRect _ExpressionRect() const; 110 BRect _KeypadRect() const; 111 112 void _MarkKeypadItems(uint8 mode); 113 114 void _FetchAppIcon(BBitmap* into); 115 116 status_t _LoadSettings(BMessage* archive); 117 118 // grid dimensions 119 int16 fColumns; 120 int16 fRows; 121 122 // color scheme 123 rgb_color fBaseColor; 124 rgb_color fLightColor; 125 rgb_color fDarkColor; 126 rgb_color fButtonTextColor; 127 rgb_color fExpressionBGColor; 128 rgb_color fExpressionTextColor; 129 130 // view dimensions 131 float fWidth; 132 float fHeight; 133 134 // keypad grid 135 struct CalcKey; 136 137 char* fKeypadDescription; 138 CalcKey* fKeypad; 139 140 // icon 141 BBitmap* fCalcIcon; 142 143 // expression 144 ExpressionTextView* fExpressionTextView; 145 146 // pop-up context menu. 147 BPopUpMenu* fPopUpMenu; 148 BMenuItem* fAutoNumlockItem; 149 BMenuItem* fAudioFeedbackItem; 150 BMenuItem* fKeypadModeCompactItem; 151 BMenuItem* fKeypadModeBasicItem; 152 BMenuItem* fKeypadModeScientificItem; 153 154 // calculator options. 155 CalcOptions* fOptions; 156 }; 157 158 #endif // _CALC_VIEW_H 159