1 /* 2 * Copyright 2006-2013, 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 * Philippe Saint-Pierre, stpere@gmail.com 9 * John Scipione, jscipione@gmail.com 10 * Timothy Wayper, timmy@wunderbear.com 11 */ 12 #ifndef _CALC_VIEW_H 13 #define _CALC_VIEW_H 14 15 16 #include <View.h> 17 18 19 enum { 20 MSG_OPTIONS_AUTO_NUM_LOCK = 'oanl', 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 BMessageRunner; 38 class BPopUpMenu; 39 struct CalcOptions; 40 class CalcOptionsWindow; 41 class ExpressionTextView; 42 43 class _EXPORT 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 FrameResized(float width, float height); 63 64 // Archive this view. 65 virtual status_t Archive(BMessage* archive, bool deep) const; 66 67 // Cut contents of view to system clipboard. 68 void Cut(); 69 70 // Copy contents of view to system clipboard. 71 void Copy(); 72 73 // Paste contents of system clipboard to view. 74 void Paste(BMessage* message); 75 76 // Save current settings 77 status_t SaveSettings(BMessage* archive) const; 78 79 // Evaluate the expression 80 void Evaluate(); 81 82 // Flash the key on the keypad 83 void FlashKey(const char* bytes, int32 numBytes); 84 85 // Toggle whether or not the Num Lock key starts on 86 void ToggleAutoNumlock(void); 87 88 // Set the angle mode to degrees or radians 89 void SetDegreeMode(bool degrees); 90 91 // Set the keypad mode 92 void SetKeypadMode(uint8 mode); 93 94 private: 95 static status_t _EvaluateThread(void* data); 96 void _Init(BMessage* settings); 97 status_t _LoadSettings(BMessage* archive); 98 void _ParseCalcDesc(const char** keypadDescription); 99 100 void _PressKey(int key); 101 void _PressKey(const char* label); 102 int32 _KeyForLabel(const char* label) const; 103 void _FlashKey(int32 key, uint32 flashFlags); 104 105 void _Colorize(); 106 107 void _CreatePopUpMenu(bool addKeypadModeMenuItems); 108 109 BRect _ExpressionRect() const; 110 BRect _KeypadRect() const; 111 112 void _MarkKeypadItems(uint8 mode); 113 114 void _FetchAppIcon(BBitmap* into); 115 bool _IsEmbedded(); 116 117 void _SetEnabled(bool enable); 118 119 // grid dimensions 120 int16 fColumns; 121 int16 fRows; 122 123 // color scheme 124 rgb_color fBaseColor; 125 rgb_color fButtonTextColor; 126 127 bool fHasCustomBaseColor; 128 129 // view dimensions 130 float fWidth; 131 float fHeight; 132 133 // keypad grid 134 struct CalcKey; 135 136 const char** fKeypadDescription; 137 CalcKey* fKeypad; 138 139 // icon 140 BBitmap* fCalcIcon; 141 142 // expression 143 ExpressionTextView* fExpressionTextView; 144 145 // pop-up context menu. 146 BPopUpMenu* fPopUpMenu; 147 BMenuItem* fAutoNumlockItem; 148 149 BMenuItem* fAngleModeRadianItem; 150 BMenuItem* fAngleModeDegreeItem; 151 152 BMenuItem* fKeypadModeCompactItem; 153 BMenuItem* fKeypadModeBasicItem; 154 BMenuItem* fKeypadModeScientificItem; 155 156 // calculator options. 157 CalcOptions* fOptions; 158 159 thread_id fEvaluateThread; 160 BMessageRunner* fEvaluateMessageRunner; 161 sem_id fEvaluateSemaphore; 162 bool fEnabled; 163 }; 164 165 #endif // _CALC_VIEW_H 166