Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / Calculator / Calculator / project / inc / CalculatorForm.h
1 //\r
2 // Open Service Platform (or Tizen C++ SDK)\r
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.\r
4 //\r
5 // Licensed under the Flora License, Version 1.0 (the License);\r
6 // you may not use this file except in compliance with the License.\r
7 // You may obtain a copy of the License at\r
8 //\r
9 //     http://www.tizenopensource.org/license\r
10 //\r
11 // Unless required by applicable law or agreed to in writing, software\r
12 // distributed under the License is distributed on an AS IS BASIS,\r
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14 // See the License for the specific language governing permissions and\r
15 // limitations under the License.\r
16 //\r
17 \r
18 #include "Calculator.h"\r
19 \r
20 #include "FUiRelativeLayout.h"\r
21 #include "FUiGridLayout.h"\r
22 \r
23 \r
24 class CalculatorForm :\r
25         public Osp::Ui::Controls::Form,\r
26         public Osp::Ui::IActionEventListener\r
27 {\r
28 protected:\r
29                 Osp::Ui::Controls::Panel*  __pGridPanel;\r
30 \r
31 public:\r
32         static const int ID_BTN_DOT             = 104;\r
33         static const int ID_BTN_BACK            = 105;\r
34         static const int ID_BTN_EQUAL           = 106;\r
35 \r
36         static const int ID_BTN_CLEAR           = 107;\r
37 \r
38         static const int ID_BTN_PLUS            = 109;\r
39         static const int ID_BTN_MINUS           = 110;\r
40 \r
41         static const int ID_BTN_MULTIPLY        = 111;\r
42         static const int ID_BTN_DIVIDE          = 112;\r
43         static const int ID_BTN_SIGN            = 113;\r
44         static const int ID_BTN_UNKNOWNOP       = 114;\r
45         static const int ID_BUTTON_OK_POPUP = 115;\r
46 \r
47 public:\r
48         CalculatorForm(void);\r
49         ~CalculatorForm(void);\r
50 \r
51 public:\r
52         result Construct();\r
53 \r
54         virtual result OnInitializing(void);\r
55         virtual result OnTerminating(void);\r
56         virtual result OnDraw(void);\r
57         virtual void OnActionPerformed(const Osp::Ui::Control& source, int actionId);\r
58 \r
59 private:\r
60         void CreateButtons(void);\r
61 \r
62 private:\r
63 \r
64         Osp::Ui::Controls::Label*       __pLabelPrint;\r
65         Osp::Ui::RelativeLayout*        __pRelLayout;\r
66         Osp::Ui::GridLayout*            __pGridLayout;\r
67         Osp::Ui::Controls::Popup* __pPopup;\r
68 \r
69 \r
70         class CalculatorModel\r
71         {\r
72                 public:\r
73                         CalculatorModel(void);\r
74                         bool HandleNumKeys(int numKey);\r
75                         void HandleOperatorKeys(int key);\r
76                         void HandleEqualKey(void);\r
77                         void HandleBackKey(void);\r
78                         void HandleClearKey(void);\r
79 \r
80                         const Osp::Base::String& GetResult() const;\r
81                         bool UpdateOperand(int key);\r
82                         void Calculate(void);\r
83 \r
84                 private:\r
85                         enum CALCULATE_MODE {\r
86                                 MODE_OPERAND1,\r
87                                 MODE_OPERATOR,\r
88                                 MODE_OPERAND2,\r
89                                 MODE_RESULT,\r
90                                 MODE_INVALID,\r
91                         };\r
92 \r
93                         CALCULATE_MODE          __calcMode; // Calculator mode\r
94                         int                                     __operator;     // operator\r
95                         Osp::Base::String       __operand1;     // result\r
96                         Osp::Base::String       __operand2;     // operand\r
97                         Osp::Base::String       __errString;\r
98 \r
99                         static const int        MAX_PRINTABLE_CHARS = 8;\r
100                         static const int        MAX_PRINTABLE_VALUE = 99999999;\r
101         } __Calculator;\r
102 };\r