Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / MetalDetector / MetalDetector / project / src / MainForm.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 <new>
19 #include "MainForm.h"
20 #include "FormMgr.h"
21
22 using namespace Osp::Base;
23 using namespace Osp::Ui;
24 using namespace Osp::Ui::Controls;
25 using namespace Osp::App;
26 using namespace Osp::Graphics;
27
28 MainForm::MainForm(void)
29 {
30 }
31
32 MainForm::~MainForm(void)
33 {
34 }
35
36 bool
37 MainForm::Initialize(void)
38 {
39         Form::Construct(FORM_STYLE_NORMAL|FORM_STYLE_HEADER|FORM_STYLE_INDICATOR);
40         SetName(L"MainForm");
41
42         // Set Header
43         Header* pHeader = this->GetHeader();
44         pHeader->SetTitleText(L"Metal Detector");
45
46         this->SetBackgroundColor(Color::GetColor(COLOR_ID_BLACK));
47
48         return true;
49 }
50
51 result
52 MainForm::OnInitializing(void)
53 {
54         result r = E_SUCCESS;
55
56         // Create a Button
57         Button *pBtnStart = new (std::nothrow) Button();
58         TryReturn(pBtnStart != null, E_FAILURE, "[Fail]Button Create");
59
60         Rectangle clientAreaBound = GetClientAreaBounds();
61         int buttonX = static_cast<int>(clientAreaBound.width * 0.33); // 1/3 Down
62         int buttonY = static_cast<int>(clientAreaBound.height * 0.75); // 3/4
63         int buttonWidth = static_cast<int>(clientAreaBound.width * 0.34); // 1/3 Up
64         int buttonHeight = static_cast<int>(clientAreaBound.height * 0.14); // 1/7
65
66         pBtnStart->Construct(Rectangle(buttonX, buttonY, buttonWidth, buttonHeight));
67         pBtnStart->SetText(L"Start");
68         pBtnStart->SetActionId(IDC_BTN_START);
69         pBtnStart->AddActionEventListener(*this);
70         AddControl(*pBtnStart);
71
72         return r;
73 }
74
75 result
76 MainForm::OnTerminating(void)
77 {
78         return E_SUCCESS;
79 }
80
81 void
82 MainForm::OnActionPerformed(const Osp::Ui::Control& source, int actionId)
83 {
84         // Get the frame pointer
85         Frame *pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
86
87         switch(actionId)
88         {
89         case IDC_BTN_START:
90                 {
91                         FormMgr* pFormMgr = static_cast<FormMgr *>(pFrame->GetControl("FormMgr"));
92
93                         if(pFormMgr != null)
94                         {
95                                 pFormMgr->SendUserEvent(FormMgr::REQUEST_DETECTFORM, null);
96                         }
97                 }
98                 break;
99         default:
100                 break;
101         }
102 }