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 pImagePanel->Initialize(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
67 AddOrientationEventListener(*pImagePanel);
68 AddControl(*pImagePanel);
69 __pPanel[2] = pImagePanel;
73 MainForm::OnInitializing(void)
77 Rectangle clientRect = GetClientAreaBounds();
78 Rectangle rect(0, 0, clientRect.width, clientRect.height);
81 Header* pHeader = GetHeader();
84 pHeader->SetStyle(HEADER_STYLE_TAB);
86 HeaderItem headerItem1;
87 headerItem1.Construct(ID_HEADER_ITEM1);
88 headerItem1.SetText(L"BUTTON");
89 pHeader->AddItem(headerItem1);
91 HeaderItem headerItem2;
92 headerItem2.Construct(ID_HEADER_ITEM2);
93 headerItem2.SetText(L"ORIENTATION");
94 pHeader->AddItem(headerItem2);
96 HeaderItem headerItem3;
97 headerItem3.Construct(ID_HEADER_ITEM3);
98 headerItem3.SetText(L"IMAGE");
99 pHeader->AddItem(headerItem3);
101 pHeader->AddActionEventListener(*this);
105 Footer * pFooter = GetFooter();
108 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
109 pFooter->SetBackButton();
110 SetFormBackEventListener(this);
113 // Create the Button panel
114 ButtonPanel* pButtonPanel = new (std::nothrow) ButtonPanel();
115 pButtonPanel->Initialize(rect);
116 AddControl(*pButtonPanel);
117 __pPanel[0] = pButtonPanel;
119 // Orientation panel was created with UI Builder,
120 // so only its button events must be defined here
121 __pPanel[1] = static_cast<Panel *>(GetControl(L"IDC_ORIENTATIONPANEL"));
122 if (__pPanel[1] != null)
124 __pButtonOrientation = static_cast<Button *>(GetControl(L"IDC_BUTTON_ORIENTATION", true));
126 if (__pButtonOrientation != null)
128 __pButtonOrientation->SetActionId(ID_ORIENTATION);
129 __pButtonOrientation->AddActionEventListener(*this);
133 // Set the current panel as selected in the header and display it on the form
136 pHeader->SetItemSelected(__panelId);
140 if (__pPanel[2] == null)
144 SetOrientation(ORIENTATION_AUTOMATIC);
147 if (__pPanel[0] != null)
149 __pPanel[0]->SetShowState(false);
151 if (__pPanel[1] != null)
153 __pPanel[1]->SetShowState(false);
156 __pPanel[__panelId]->SetShowState(true);
164 MainForm::OnTerminating(void)
166 AppRegistry *appRegistry = Application::GetInstance()->GetAppRegistry();
167 String panelIDkey(L"AppLastPanelId");
168 String panelNamekey(L"AppLastPanelName");
170 Header* pHeader = GetHeader();
171 result r = appRegistry->Set(panelIDkey,pHeader->GetSelectedItemIndex());
178 panel.Format(50, L"Panel%d", pHeader->GetSelectedItemIndex());
179 r = appRegistry->Set(panelNamekey, panel);
185 r = appRegistry->Save();
188 //failed to save data to registry.
195 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
199 case ID_HEADER_ITEM1:
201 if (__pPanel[0] != null)
203 __pPanel[0]->SetShowState(true);
205 if (__pPanel[1] != null)
207 __pPanel[1]->SetShowState(false);
209 if (__pPanel[2] != null)
211 __pPanel[2]->SetShowState(false);
213 SetOrientation(ORIENTATION_PORTRAIT);
217 case ID_HEADER_ITEM2:
219 if (__pPanel[0] != null)
221 __pPanel[0]->SetShowState(false);
223 if (__pPanel[1] != null)
225 __pPanel[1]->SetShowState(true);
227 if (__pPanel[2] != null)
229 __pPanel[2]->SetShowState(false);
231 SetOrientation(__status);
235 case ID_HEADER_ITEM3:
237 if (__pPanel[2] == null)
241 if (__pPanel[0] != null)
243 __pPanel[0]->SetShowState(false);
245 if (__pPanel[1] != null)
247 __pPanel[1]->SetShowState(false);
249 if (__pPanel[2] != null)
251 __pPanel[2]->SetShowState(true);
253 SetOrientation(ORIENTATION_AUTOMATIC);
259 if (__pPanel[1]->GetShowState())
261 OrientationStatus status = GetOrientationStatus();
262 if (status == ORIENTATION_STATUS_PORTRAIT)
264 __status = ORIENTATION_LANDSCAPE;
266 else if (status == ORIENTATION_STATUS_LANDSCAPE)
268 __status = ORIENTATION_PORTRAIT;
270 SetOrientation(__status);
283 MainForm::OnFormBackRequested(Form& source)
285 UiApp* pApp = UiApp::GetInstance();