3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
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 "AppResourceId.h"
22 #include "ButtonPanel.h"
23 #include "ImagePanel.h"
26 using namespace Tizen::App;
27 using namespace Tizen::Base;
28 using namespace Tizen::Ui;
29 using namespace Tizen::Ui::Controls;
30 using namespace Tizen::Graphics;
32 MainForm::MainForm(void)
33 : __pButtonOrientation(null)
34 , __status(ORIENTATION_PORTRAIT)
42 MainForm::~MainForm(void)
47 MainForm::Initialize(int panelId)
49 result r = Form::Construct(IDF_MAINFORM);
51 if (panelId >= 0 && panelId <= 2)
64 MainForm::CreateImagePanel(void)
66 ImagePanel* pImagePanel = new (std::nothrow) ImagePanel();
67 result r = pImagePanel->Initialize(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height));
68 AddOrientationEventListener(*pImagePanel);
69 r = AddControl(pImagePanel);
70 __pPanel[2] = pImagePanel;
76 MainForm::OnInitializing(void)
80 Rectangle clientRect = GetClientAreaBounds();
81 Rectangle rect(0, 0, clientRect.width, clientRect.height);
84 Header* pHeader = GetHeader();
87 pHeader->SetStyle(HEADER_STYLE_TAB);
89 HeaderItem headerItem1;
90 headerItem1.Construct(ID_HEADER_ITEM1);
91 headerItem1.SetText(L"BUTTON");
92 pHeader->AddItem(headerItem1);
94 HeaderItem headerItem2;
95 headerItem2.Construct(ID_HEADER_ITEM2);
96 headerItem2.SetText(L"ORIENTATION");
97 pHeader->AddItem(headerItem2);
99 HeaderItem headerItem3;
100 headerItem3.Construct(ID_HEADER_ITEM3);
101 headerItem3.SetText(L"IMAGE");
102 pHeader->AddItem(headerItem3);
104 pHeader->AddActionEventListener(*this);
108 Footer * pFooter = GetFooter();
111 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON);
112 pFooter->SetBackButton();
113 SetFormBackEventListener(this);
116 // Create the Button panel
117 ButtonPanel* pButtonPanel = new (std::nothrow) ButtonPanel();
118 pButtonPanel->Initialize(rect);
119 AddControl(pButtonPanel);
120 __pPanel[0] = pButtonPanel;
122 // Orientation panel was created with UI Builder,
123 // so only its button events must be defined here
124 __pPanel[1] = static_cast<Panel *>(GetControl(IDC_ORIENTATIONPANEL));
125 if (__pPanel[1] != null)
127 __pButtonOrientation = static_cast<Button *>(GetControl(IDC_BUTTON_ORIENTATION, true));
129 if (__pButtonOrientation != null)
131 __pButtonOrientation->SetActionId(ID_ORIENTATION);
132 __pButtonOrientation->AddActionEventListener(*this);
136 // Set the current panel as selected in the header and display it on the form
139 pHeader->SetItemSelected(__panelId);
143 if (__pPanel[2] == null)
147 SetOrientation(ORIENTATION_AUTOMATIC);
150 if (__pPanel[0] != null)
152 __pPanel[0]->SetShowState(false);
154 if (__pPanel[1] != null)
156 __pPanel[1]->SetShowState(false);
159 __pPanel[__panelId]->SetShowState(true);
167 MainForm::OnTerminating(void)
169 AppRegistry *appRegistry = Application::GetInstance()->GetAppRegistry();
170 String panelIDkey(L"AppLastPanelId");
171 String panelNamekey(L"AppLastPanelName");
173 Header* pHeader = GetHeader();
174 result r = appRegistry->Set(panelIDkey,pHeader->GetSelectedItemIndex());
181 panel.Format(50, L"Panel%d", pHeader->GetSelectedItemIndex());
182 r = appRegistry->Set(panelNamekey, panel);
188 r = appRegistry->Save();
191 //failed to save data to registry.
198 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
202 case ID_HEADER_ITEM1:
204 if (__pPanel[0] != null)
206 __pPanel[0]->SetShowState(true);
208 if (__pPanel[1] != null)
210 __pPanel[1]->SetShowState(false);
212 if (__pPanel[2] != null)
214 __pPanel[2]->SetShowState(false);
216 SetOrientation(ORIENTATION_PORTRAIT);
220 case ID_HEADER_ITEM2:
222 if (__pPanel[0] != null)
224 __pPanel[0]->SetShowState(false);
226 if (__pPanel[1] != null)
228 __pPanel[1]->SetShowState(true);
230 if (__pPanel[2] != null)
232 __pPanel[2]->SetShowState(false);
234 SetOrientation(__status);
238 case ID_HEADER_ITEM3:
240 if (__pPanel[2] == null)
244 if (__pPanel[0] != null)
246 __pPanel[0]->SetShowState(false);
248 if (__pPanel[1] != null)
250 __pPanel[1]->SetShowState(false);
252 if (__pPanel[2] != null)
254 __pPanel[2]->SetShowState(true);
256 SetOrientation(ORIENTATION_AUTOMATIC);
262 if (__pPanel[1]->GetShowState())
264 OrientationStatus status = GetOrientationStatus();
265 if (status == ORIENTATION_STATUS_PORTRAIT)
267 __status = ORIENTATION_LANDSCAPE;
269 else if (status == ORIENTATION_STATUS_LANDSCAPE)
271 __status = ORIENTATION_PORTRAIT;
273 SetOrientation(__status);
286 MainForm::OnFormBackRequested(Form& source)
288 UiApp* pApp = UiApp::GetInstance();