3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://floralicense.org/license/
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.
21 #include "ButtonPanel.h"
22 #include "ImagePanel.h"
25 using namespace Tizen::App;
26 using namespace Tizen::Base;
27 using namespace Tizen::Ui;
28 using namespace Tizen::Ui::Controls;
29 using namespace Tizen::Graphics;
31 MainForm::MainForm(void)
32 : __pButtonOrientation(null)
33 , __status(ORIENTATION_PORTRAIT)
38 MainForm::~MainForm(void)
43 MainForm::Initialize(int panelId)
45 result r = Form::Construct(L"IDF_MAINFORM");
47 if (panelId >= 0 && panelId <= 2)
60 MainForm::OnInitializing(void)
64 Rectangle clientRect = GetClientAreaBounds();
65 Rectangle rect(0, 0, clientRect.width, clientRect.height);
68 Header* pHeader = GetHeader();
71 pHeader->SetStyle(HEADER_STYLE_TAB);
73 HeaderItem headerItem1;
74 headerItem1.Construct(ID_HEADER_ITEM1);
75 headerItem1.SetText(L"BUTTON");
76 pHeader->AddItem(headerItem1);
78 HeaderItem headerItem2;
79 headerItem2.Construct(ID_HEADER_ITEM2);
80 headerItem2.SetText(L"ORIENTATION");
81 pHeader->AddItem(headerItem2);
83 HeaderItem headerItem3;
84 headerItem3.Construct(ID_HEADER_ITEM3);
85 headerItem3.SetText(L"IMAGE");
86 pHeader->AddItem(headerItem3);
88 pHeader->AddActionEventListener(*this);
92 Footer * pFooter = GetFooter();
95 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
96 pFooter->SetBackButton();
97 SetFormBackEventListener(this);
100 // Create the Button panel
101 ButtonPanel* pButtonPanel = new (std::nothrow) ButtonPanel();
102 pButtonPanel->Initialize(rect);
103 AddControl(*pButtonPanel);
104 __pPanel[0] = pButtonPanel;
106 // Orientation panel was created with UI Builder,
107 // so only its button events must be defined here
108 __pPanel[1] = static_cast<Panel *>(GetControl(L"IDC_ORIENTATIONPANEL"));
109 if (__pPanel[1] != null)
111 __pButtonOrientation = static_cast<Button *>(GetControl(L"IDC_BUTTON_ORIENTATION", true));
113 if (__pButtonOrientation != null)
115 __pButtonOrientation->SetActionId(ID_ORIENTATION);
116 __pButtonOrientation->AddActionEventListener(*this);
121 ImagePanel* pImagePanel = new (std::nothrow) ImagePanel();
122 pImagePanel->Initialize(rect);
123 AddOrientationEventListener(*pImagePanel);
124 AddControl(*pImagePanel);
125 __pPanel[2] = pImagePanel;
127 // Set the current panel as selected in the header and display it on the form
130 pHeader->SetItemSelected(__panelId);
134 SetOrientation(ORIENTATION_AUTOMATIC);
137 __pPanel[0]->SetShowState(false);
138 __pPanel[1]->SetShowState(false);
139 __pPanel[2]->SetShowState(false);
140 __pPanel[__panelId]->SetShowState(true);
148 MainForm::OnTerminating(void)
150 AppRegistry *appRegistry = Application::GetInstance()->GetAppRegistry();
151 String panelIDkey(L"AppLastPanelId");
152 String panelNamekey(L"AppLastPanelName");
154 Header* pHeader = GetHeader();
155 result r = appRegistry->Set(panelIDkey,pHeader->GetSelectedItemIndex());
162 panel.Format(50, L"Panel%d", pHeader->GetSelectedItemIndex());
163 r = appRegistry->Set(panelNamekey, panel);
169 r = appRegistry->Save();
172 //failed to save data to registry.
179 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
183 case ID_HEADER_ITEM1:
185 __pPanel[0]->SetShowState(true);
186 __pPanel[1]->SetShowState(false);
187 __pPanel[2]->SetShowState(false);
188 SetOrientation(ORIENTATION_PORTRAIT);
192 case ID_HEADER_ITEM2:
194 __pPanel[0]->SetShowState(false);
195 __pPanel[1]->SetShowState(true);
196 __pPanel[2]->SetShowState(false);
197 SetOrientation(__status);
201 case ID_HEADER_ITEM3:
203 __pPanel[0]->SetShowState(false);
204 __pPanel[1]->SetShowState(false);
205 __pPanel[2]->SetShowState(true);
206 SetOrientation(ORIENTATION_AUTOMATIC);
212 if (__pPanel[1]->GetShowState())
214 OrientationStatus status = GetOrientationStatus();
215 if (status == ORIENTATION_STATUS_PORTRAIT)
217 __status = ORIENTATION_LANDSCAPE;
219 else if (status == ORIENTATION_STATUS_LANDSCAPE)
221 __status = ORIENTATION_PORTRAIT;
223 SetOrientation(__status);
236 MainForm::OnFormBackRequested(Form& source)
238 UiApp* pApp = UiApp::GetInstance();