dd482feca6ff8d91904d7ff2f93aa856d7a8c8d3
[apps/native/sample/BasicApp.git] / project / src / ButtonPanel.cpp
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.1 (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://floralicense.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 <FBase.h>
20
21 #include "ButtonPanel.h"
22
23 using namespace Tizen::Base;
24 using namespace Tizen::Ui::Controls;
25 using namespace Tizen::Graphics;
26
27 ButtonPanel::ButtonPanel(void)
28         : __pLabel(null)
29 {
30 }
31
32 ButtonPanel::~ButtonPanel(void)
33 {
34 }
35
36 result
37 ButtonPanel::Initialize(const Tizen::Graphics::Rectangle& rect)
38 {
39         return Panel::Construct(rect);
40 }
41
42 result
43 ButtonPanel::OnInitializing(void)
44 {
45         // Create a Label
46         __pLabel = new (std::nothrow) Label();
47         __pLabel->Construct(Rectangle(45, 190, 600, 80), L"Button");
48         __pLabel->SetName(L"Label1");
49         __pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
50         __pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
51         result r = AddControl(__pLabel);
52
53         // Create a Button
54         Button *pButton = new (std::nothrow) Button();
55         pButton->Construct(Rectangle(20, 290, 680, 160));
56         pButton->SetText(L"Change Text");
57         pButton->SetActionId(ID_BUTTON);
58         pButton->AddActionEventListener(*this);
59         r = AddControl(pButton);
60
61         return r;
62 }
63
64 void
65 ButtonPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
66 {
67         switch(actionId)
68         {
69         case ID_BUTTON:
70                 {
71                         __pLabel->SetText(L"Button is clicked!");
72                         AppLog("Button is pressed! \n");
73                 }
74                 break;
75         }
76         Invalidate(true);
77 }
78