Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / SimplePedometer / SimplePedometer / project / src / StartForm.cpp
1 //
2 // Tizen C++ SDK
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
18 #include "StartForm.h"
19 #include "PedometerForm.h"
20
21 using namespace Osp::Graphics;
22 using namespace Osp::Ui::Controls;
23
24 StartForm::StartForm(void)
25         :__pButtonGo(null)
26         , __pLabelDescription(null)
27         , __pFormPedometer(null)
28 {
29 }
30
31 StartForm::~StartForm(void)
32 {
33 }
34
35 bool
36 StartForm::Initialize(void)
37 {
38         // Construct an XML form
39         Construct(L"IDF_STARTFORM");
40
41         return true;
42 }
43
44 result
45 StartForm::OnInitializing(void)
46 {
47         SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
48
49         // Get a button via resource ID
50         __pButtonGo = static_cast<Button*>(GetControl(L"IDC_BUTTON_GO"));
51         TryReturn(__pButtonGo != null, E_FAILURE, "GoButton creation failed.");
52
53         __pLabelDescription = static_cast<Label*>(GetControl(L"IDC_LABEL_DESCRIPTION"));
54         TryReturn(__pLabelDescription != null, E_FAILURE, "DescriptionLabel creation failed.");
55
56         __pButtonGo->SetActionId(ID_BUTTON_GO);
57         __pButtonGo->AddActionEventListener(*this);
58
59         Rectangle clientAreaBound = GetClientAreaBounds();
60         int fontSize = clientAreaBound.width * 0.06;
61         __pLabelDescription->SetTextConfig(fontSize, LABEL_TEXT_STYLE_NORMAL);
62         __pLabelDescription->SetTextColor(Color::GetColor(COLOR_ID_WHITE));
63
64         __pFormPedometer = null;
65
66         return E_SUCCESS;
67 }
68
69 result
70 StartForm::OnTerminating(void)
71 {
72         return E_SUCCESS;
73 }
74
75 void
76 StartForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
77 {
78         switch(actionId)
79         {
80         case ID_BUTTON_GO:
81                 {
82                         __pFormPedometer = new (std::nothrow) PedometerForm();
83                         TryReturnVoid(__pFormPedometer != null, "PedometerForm creation failed");
84                         static_cast<PedometerForm*>(__pFormPedometer)->Initialize();
85
86                         // Add the form to the frame
87                         Frame* pFrame = Osp::App::Application::GetInstance()->GetAppFrame()->GetFrame();
88                         if (pFrame == null)
89                         {
90                                 AppLogException("Frame getting failed");
91                                 delete __pFormPedometer;
92                                 __pFormPedometer = null;
93                                 return;
94                         }
95                         pFrame->AddControl(*__pFormPedometer);
96
97                         // Set the current form
98                         pFrame->SetCurrentForm(*__pFormPedometer);
99                         __pFormPedometer->Draw();
100                 }
101                 break;
102         default:
103                 break;
104         }
105         this->RequestRedraw(true);
106 }