Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / cpp / Sample / Tizen C++ / UiControls / UiControls / project / src / ButtonForm.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.tizenopensource.org/license
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 #include "ButtonForm.h"\r
18 \r
19 using namespace Osp::Ui;\r
20 using namespace Osp::Ui::Controls;\r
21 using namespace Osp::Graphics;\r
22 \r
23 ButtonForm::ButtonForm(void):\r
24 __pLabelButton(null)\r
25 {\r
26 }\r
27 \r
28 ButtonForm::~ButtonForm(void)\r
29 {\r
30 }\r
31 \r
32 bool\r
33 ButtonForm::Initialize(void)\r
34 {\r
35         Construct(L"IDF_FORM_BUTTON");\r
36         SetFooter();\r
37         return true;\r
38 }\r
39 \r
40 result\r
41 ButtonForm::OnInitializing(void)\r
42 {\r
43         BaseForm::OnInitializing();\r
44         result r = E_SUCCESS;\r
45 \r
46         Header* pHeader = GetHeader();\r
47         pHeader->SetTitleText(L"Button");\r
48 \r
49         __pLabelButton = static_cast<Label *>(GetControl(L"IDF_LABEL_BUTTON"));\r
50         Rectangle rc;\r
51         rc = GetClientAreaBounds();\r
52         __pLabelButton->SetPosition(30, rc.height-60);\r
53         Button* pButtonOn = static_cast<Button *>(GetControl(L"IDF_BUTTON_ON"));\r
54         Button* pButtonOff = static_cast<Button *>(GetControl(L"IDF_BUTTON_OFF"));\r
55 \r
56         __pLabelButton->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);\r
57         __pLabelButton->SetTextHorizontalAlignment(ALIGNMENT_LEFT);\r
58 \r
59         pButtonOn->SetActionId(ID_BUTTON_ON);\r
60         pButtonOff->SetActionId(ID_BUTTON_OFF);\r
61         pButtonOn->AddActionEventListener(*this);\r
62         pButtonOff->AddActionEventListener(*this);\r
63 \r
64         return r;\r
65 }\r
66 \r
67 void\r
68 ButtonForm::OnActionPerformed(const Control& source, int actionId)\r
69 {\r
70         switch (actionId)\r
71         {\r
72         case ID_BUTTON_ON:\r
73                 __pLabelButton->SetText(L"Button ON Clicked!");\r
74                 break;\r
75 \r
76         case ID_BUTTON_OFF:\r
77                 __pLabelButton->SetText(L"Button OFF Clicked!");\r
78                 break;\r
79         default:\r
80                 break;\r
81         }\r
82 \r
83         __pLabelButton->Draw();\r
84 }\r