2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include "AppResourceId.h"
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(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);
106 SetFormBackEventListener(this);
108 // Create the Button panel
109 ButtonPanel* pButtonPanel = new (std::nothrow) ButtonPanel();
110 pButtonPanel->Initialize(rect);
111 AddControl(pButtonPanel);
112 __pPanel[0] = pButtonPanel;
114 // Orientation panel was created with UI Builder,
115 // so only its button events must be defined here
116 __pPanel[1] = static_cast<Panel *>(GetControl(IDC_ORIENTATIONPANEL));
117 if (__pPanel[1] != null)
119 __pButtonOrientation = static_cast<Button *>(GetControl(IDC_BUTTON_ORIENTATION, true));
121 if (__pButtonOrientation != null)
123 __pButtonOrientation->SetActionId(ID_ORIENTATION);
124 __pButtonOrientation->AddActionEventListener(*this);
128 // Set the current panel as selected in the header and display it on the form
131 pHeader->SetItemSelected(__panelId);
135 if (__pPanel[2] == null)
139 SetOrientation(ORIENTATION_AUTOMATIC);
142 if (__pPanel[0] != null)
144 __pPanel[0]->SetShowState(false);
146 if (__pPanel[1] != null)
148 __pPanel[1]->SetShowState(false);
151 __pPanel[__panelId]->SetShowState(true);
159 MainForm::OnTerminating(void)
161 AppRegistry *appRegistry = Application::GetInstance()->GetAppRegistry();
162 String panelIDkey(L"AppLastPanelId");
163 String panelNamekey(L"AppLastPanelName");
165 Header* pHeader = GetHeader();
166 result r = appRegistry->Set(panelIDkey,pHeader->GetSelectedItemIndex());
173 panel.Format(50, L"Panel%d", pHeader->GetSelectedItemIndex());
174 r = appRegistry->Set(panelNamekey, panel);
180 r = appRegistry->Save();
183 //failed to save data to registry.
190 MainForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
194 case ID_HEADER_ITEM1:
196 if (__pPanel[0] != null)
198 __pPanel[0]->SetShowState(true);
200 if (__pPanel[1] != null)
202 __pPanel[1]->SetShowState(false);
204 if (__pPanel[2] != null)
206 __pPanel[2]->SetShowState(false);
208 SetOrientation(ORIENTATION_PORTRAIT);
212 case ID_HEADER_ITEM2:
214 if (__pPanel[0] != null)
216 __pPanel[0]->SetShowState(false);
218 if (__pPanel[1] != null)
220 __pPanel[1]->SetShowState(true);
222 if (__pPanel[2] != null)
224 __pPanel[2]->SetShowState(false);
226 SetOrientation(__status);
230 case ID_HEADER_ITEM3:
232 if (__pPanel[2] == null)
236 if (__pPanel[0] != null)
238 __pPanel[0]->SetShowState(false);
240 if (__pPanel[1] != null)
242 __pPanel[1]->SetShowState(false);
244 if (__pPanel[2] != null)
246 __pPanel[2]->SetShowState(true);
248 SetOrientation(ORIENTATION_AUTOMATIC);
254 if (__pPanel[1]->GetShowState())
256 OrientationStatus status = GetOrientationStatus();
257 if (status == ORIENTATION_STATUS_PORTRAIT)
259 __status = ORIENTATION_LANDSCAPE;
261 else if (status == ORIENTATION_STATUS_LANDSCAPE)
263 __status = ORIENTATION_PORTRAIT;
265 SetOrientation(__status);
278 MainForm::OnFormBackRequested(Form& source)
280 UiApp* pApp = UiApp::GetInstance();