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