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)
41 MainForm::~MainForm(void)
46 MainForm::Initialize(int panelId)
48 result r = Form::Construct(L"IDF_MAINFORM");
50 if (panelId >= 0 && panelId <= 2)
63 MainForm::CreateImagePanel(void)
65 ImagePanel* pImagePanel = new (std::nothrow) ImagePanel();
66 result r = pImagePanel->Initialize(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
67 AddOrientationEventListener(*pImagePanel);
68 r = AddControl(pImagePanel);
69 __pPanel[2] = pImagePanel;
75 MainForm::OnInitializing(void)
79 Rectangle clientRect = GetClientAreaBounds();
80 Rectangle rect(0, 0, clientRect.width, clientRect.height);
83 Header* pHeader = GetHeader();
86 pHeader->SetStyle(HEADER_STYLE_TAB);
88 HeaderItem headerItem1;
89 headerItem1.Construct(ID_HEADER_ITEM1);
90 headerItem1.SetText(L"BUTTON");
91 pHeader->AddItem(headerItem1);
93 HeaderItem headerItem2;
94 headerItem2.Construct(ID_HEADER_ITEM2);
95 headerItem2.SetText(L"ORIENTATION");
96 pHeader->AddItem(headerItem2);
98 HeaderItem headerItem3;
99 headerItem3.Construct(ID_HEADER_ITEM3);
100 headerItem3.SetText(L"IMAGE");
101 pHeader->AddItem(headerItem3);
103 pHeader->AddActionEventListener(*this);
107 Footer * pFooter = GetFooter();
110 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
111 pFooter->SetBackButton();
112 SetFormBackEventListener(this);
115 // Create the Button panel
116 ButtonPanel* pButtonPanel = new (std::nothrow) ButtonPanel();
117 pButtonPanel->Initialize(rect);
118 AddControl(pButtonPanel);
119 __pPanel[0] = pButtonPanel;
121 // Orientation panel was created with UI Builder,
122 // so only its button events must be defined here
123 __pPanel[1] = static_cast<Panel *>(GetControl(L"IDC_ORIENTATIONPANEL"));
124 if (__pPanel[1] != null)
126 __pButtonOrientation = static_cast<Button *>(GetControl(L"IDC_BUTTON_ORIENTATION", true));
128 if (__pButtonOrientation != null)
130 __pButtonOrientation->SetActionId(ID_ORIENTATION);
131 __pButtonOrientation->AddActionEventListener(*this);
135 // Set the current panel as selected in the header and display it on the form
138 pHeader->SetItemSelected(__panelId);
142 if (__pPanel[2] == null)
146 SetOrientation(ORIENTATION_AUTOMATIC);
149 if (__pPanel[0] != null)
151 __pPanel[0]->SetShowState(false);
153 if (__pPanel[1] != null)
155 __pPanel[1]->SetShowState(false);
158 __pPanel[__panelId]->SetShowState(true);
166 MainForm::OnTerminating(void)
168 AppRegistry *appRegistry = Application::GetInstance()->GetAppRegistry();
169 String panelIDkey(L"AppLastPanelId");
170 String panelNamekey(L"AppLastPanelName");
172 Header* pHeader = GetHeader();
173 result r = appRegistry->Set(panelIDkey,pHeader->GetSelectedItemIndex());
180 panel.Format(50, L"Panel%d", pHeader->GetSelectedItemIndex());
181 r = appRegistry->Set(panelNamekey, panel);
187 r = appRegistry->Save();
190 //failed to save data to registry.
197 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
201 case ID_HEADER_ITEM1:
203 if (__pPanel[0] != null)
205 __pPanel[0]->SetShowState(true);
207 if (__pPanel[1] != null)
209 __pPanel[1]->SetShowState(false);
211 if (__pPanel[2] != null)
213 __pPanel[2]->SetShowState(false);
215 SetOrientation(ORIENTATION_PORTRAIT);
219 case ID_HEADER_ITEM2:
221 if (__pPanel[0] != null)
223 __pPanel[0]->SetShowState(false);
225 if (__pPanel[1] != null)
227 __pPanel[1]->SetShowState(true);
229 if (__pPanel[2] != null)
231 __pPanel[2]->SetShowState(false);
233 SetOrientation(__status);
237 case ID_HEADER_ITEM3:
239 if (__pPanel[2] == null)
243 if (__pPanel[0] != null)
245 __pPanel[0]->SetShowState(false);
247 if (__pPanel[1] != null)
249 __pPanel[1]->SetShowState(false);
251 if (__pPanel[2] != null)
253 __pPanel[2]->SetShowState(true);
255 SetOrientation(ORIENTATION_AUTOMATIC);
261 if (__pPanel[1]->GetShowState())
263 OrientationStatus status = GetOrientationStatus();
264 if (status == ORIENTATION_STATUS_PORTRAIT)
266 __status = ORIENTATION_LANDSCAPE;
268 else if (status == ORIENTATION_STATUS_LANDSCAPE)
270 __status = ORIENTATION_PORTRAIT;
272 SetOrientation(__status);
285 MainForm::OnFormBackRequested(Form& source)
287 UiApp* pApp = UiApp::GetInstance();