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 33 CalcView(BMessage* archive); 34 35 virtual ~CalcView(); 36 37 virtual void AttachedToWindow(); 38 virtual void MessageReceived(BMessage* message); 39 virtual void Draw(BRect updateRect); 40 virtual void MouseDown(BPoint point); 41 virtual void KeyDown(const char* bytes, int32 numBytes); 42 virtual void MakeFocus(bool focused = true); 43 virtual void FrameResized(float width, float height); 44 45 // Present about box for view (replicant). 46 virtual void AboutRequested(); 47 48 // Archive this view. 49 virtual status_t Archive(BMessage* archive, bool deep) const; 50 51 // Cut contents of view to system clipboard. 52 void Cut(); 53 54 // Copy contents of view to system clipboard. 55 void Copy(); 56 57 // Paste contents of system clipboard to view. 58 void Paste(BMessage *message); 59 60 // Load/Save current settings 61 status_t LoadSettings(BMessage* archive); 62 status_t SaveSettings(BMessage* archive) const; 63 64 void Evaluate(); 65 66 void FlashKey(const char* bytes, int32 numBytes); 67 68 void AddExpressionToHistory(const char* expression); 69 void PreviousExpression(); 70 void NextExpression(); 71 72 private: 73 void _ParseCalcDesc(const char* keypadDescription); 74 75 void _PressKey(int key); 76 void _PressKey(const char* label); 77 int32 _KeyForLabel(const char* label) const; 78 void _FlashKey(int32 key); 79 80 void _Colorize(); 81 82 void _CreatePopUpMenu(); 83 84 BRect _ExpressionRect() const; 85 BRect _KeypadRect() const; 86 87 void _ShowKeypad(bool show); 88 void _FetchAppIcon(BBitmap* into); 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 BMenuItem* fAboutItem; 120 BMenuItem* fOptionsItem; 121 BPopUpMenu* fPopUpMenu; 122 123 // calculator options. 124 CalcOptions* fOptions; 125 CalcOptionsWindow* fOptionsWindow; 126 BRect fOptionsWindowFrame; 127 bool fShowKeypad; 128 }; 129 130 #endif // _CALC_VIEW_H 131