Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SplitPanelImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /**
19  * @file                        FUiCtrl_SplitPanelImpl.cpp
20  * @brief               This is the implementation file for the _SplitPanelImpl class.
21  */
22
23 #include <FBaseInternalTypes.h>
24 #include <FApp_AppInfo.h>
25 #include <FBaseSysLog.h>
26 #include <FUiCtrlPanel.h>
27 #include <FUiCtrlScrollPanel.h>
28 #include <FUiCtrlForm.h>
29 #include "FUiCtrl_SplitPanelImpl.h"
30 #include "FUiCtrl_SplitPanel.h"
31 #include "FUi_UiBuilder.h"
32
33 using namespace Tizen::Base;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::App;
38
39 namespace Tizen { namespace Ui { namespace Controls
40 {
41
42 _SplitPanelImpl*
43 _SplitPanelImpl::GetInstance(SplitPanel& pSplitPanel)
44 {
45         return static_cast<_SplitPanelImpl*> (pSplitPanel._pControlImpl);
46 }
47
48 const _SplitPanelImpl*
49 _SplitPanelImpl::GetInstance(const SplitPanel& pSplitPanel)
50 {
51         return static_cast<const _SplitPanelImpl*> (pSplitPanel._pControlImpl);
52 }
53
54 _SplitPanelImpl::_SplitPanelImpl(SplitPanel* pPublic, _SplitPanel* pCore)
55         : _ControlImpl(pPublic, pCore)
56         , __pSplitPanel(pCore)
57         , __pPublicSplitPanelEvent(null)
58 {
59         ClearLastResult();
60 }
61
62 _SplitPanelImpl::~_SplitPanelImpl(void)
63 {
64         __pSplitPanel->RemoveSplitPanelEventListener(*this);
65
66         if(__pPublicSplitPanelEvent)
67         {
68                 delete __pPublicSplitPanelEvent;
69                 __pPublicSplitPanelEvent = null;
70         }
71
72         ClearLastResult();
73 }
74
75 _SplitPanelImpl*
76 _SplitPanelImpl::CreateSplitPanelImplN(SplitPanel* pControl, const Rectangle& rect, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
77 {
78         ClearLastResult();
79         result r = E_SUCCESS;
80
81         _SplitPanel* pCore = _SplitPanel::CreateSplitPanelN(rect, splitPanelDividerStyle, splitPanelDividerDirection);
82         SysTryReturn(NID_UI_CTRL, pCore != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
83
84         _SplitPanelImpl* pImpl = new (std::nothrow) _SplitPanelImpl(pControl, pCore);
85         r = _ControlImpl::CheckConstruction(pCore, pImpl);
86         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
87
88         return pImpl;
89 }
90
91 result
92 _SplitPanelImpl::Initialize(const Rectangle& rect)
93 {
94         ClearLastResult();
95         result r = E_SUCCESS;
96
97         r = SetBounds(rect);
98         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
99
100         __pPublicSplitPanelEvent = _PublicSplitPanelEvent::CreateInstanceN(GetPublic());
101         SysTryReturn(NID_UI_CTRL, __pPublicSplitPanelEvent, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
102
103         r = GetCore().AddSplitPanelEventListener(*this);
104         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
105
106         return r;
107 }
108
109 const char*
110 _SplitPanelImpl::GetPublicClassName(void) const
111 {
112         return "Tizen::Ui::Controls::SplitPanel";
113 }
114
115 const SplitPanel&
116 _SplitPanelImpl::GetPublic(void) const
117 {
118         return static_cast <const SplitPanel&>(_ControlImpl::GetPublic());
119 }
120
121 SplitPanel&
122 _SplitPanelImpl::GetPublic(void)
123 {
124         return static_cast <SplitPanel&>(_ControlImpl::GetPublic());
125 }
126
127 const _SplitPanel&
128 _SplitPanelImpl::GetCore(void) const
129 {
130         return static_cast <const _SplitPanel&>(_ControlImpl::GetCore());
131 }
132
133 _SplitPanel&
134 _SplitPanelImpl::GetCore(void)
135 {
136         return static_cast <_SplitPanel&>(_ControlImpl::GetCore());
137 }
138
139 void
140 _SplitPanelImpl::OnDividerPositionChanged(_SplitPanel& source, int position)
141 {
142         ClearLastResult();
143
144         if (__pPublicSplitPanelEvent != null)
145         {
146                 IEventArg* pEventArg = _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SPLIT_PANEL_EVENT_DIVIDER_POSITION_CHANGE);
147                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
148                 __pPublicSplitPanelEvent->Fire(*pEventArg);
149         }
150 }
151
152 void
153 _SplitPanelImpl::OnDividerDoublePressed(_SplitPanel& source)
154 {
155         ClearLastResult();
156
157         if (__pPublicSplitPanelEvent != null)
158         {
159                 IEventArg* pEventArg = _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SPLIT_PANEL_EVENT_DIVIDER_DOUBLE_PRESSED);
160                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
161                 __pPublicSplitPanelEvent->Fire(*pEventArg);
162         }
163 }
164
165 result
166 _SplitPanelImpl::AddSplitPanelEventListener(ISplitPanelEventListener& listener)
167 {
168         return __pPublicSplitPanelEvent->AddListener(listener);
169 }
170
171 result
172 _SplitPanelImpl::RemoveSplitPanelEventListener(ISplitPanelEventListener& listener)
173 {
174         return __pPublicSplitPanelEvent->RemoveListener(listener);
175 }
176
177 result
178 _SplitPanelImpl::SetPane(_ControlImpl* pControl, SplitPanelPaneOrder paneOrder)
179 {
180         result r = E_SUCCESS;
181
182         if (pControl == null)
183         {
184                 r = GetCore().SetPane(null, paneOrder);
185         }
186         else
187         {
188                 r = GetCore().SetPane(&(pControl->GetCore()), paneOrder);
189         }
190
191         SetLastResultReturn(r);
192 }
193
194 _ControlImpl*
195 _SplitPanelImpl::GetPane(SplitPanelPaneOrder paneOrder) const
196 {
197         _Control* pControl = GetCore().GetPane(paneOrder);
198         if (pControl == null)
199         {
200                 return null;
201         }
202
203         return static_cast<_ControlImpl*>(pControl->GetUserData());
204 }
205
206 result
207 _SplitPanelImpl::SetDividerPosition(int position)
208 {
209         result r = GetCore().SetDividerPosition(position);
210         SetLastResultReturn(r);
211 }
212
213 int
214 _SplitPanelImpl::GetDividerPosition(void) const
215 {
216         ClearLastResult();
217         return GetCore().GetDividerPosition();
218 }
219
220 result
221 _SplitPanelImpl::SetMaximumDividerPosition(int position)
222 {
223         result r = GetCore().SetMaximumDividerPosition(position);
224         SetLastResultReturn(r);
225 }
226
227 int
228 _SplitPanelImpl::GetMaximumDividerPosition(void) const
229 {
230         ClearLastResult();
231         return GetCore().GetMaximumDividerPosition();
232 }
233
234 result
235 _SplitPanelImpl::SetMinimumDividerPosition(int position)
236 {
237         result r = GetCore().SetMinimumDividerPosition(position);
238         SetLastResultReturn(r);
239 }
240
241 int
242 _SplitPanelImpl::GetMinimumDividerPosition(void) const
243 {
244         ClearLastResult();
245         return GetCore().GetMinimumDividerPosition();
246 }
247
248 result
249 _SplitPanelImpl::MaximizePane(SplitPanelPaneOrder paneOrder)
250 {
251         result r = GetCore().MaximizePane(paneOrder);
252         SetLastResultReturn(r);
253 }
254
255 bool
256 _SplitPanelImpl::IsPaneMaximized(SplitPanelPaneOrder paneOrder) const
257 {
258         ClearLastResult();
259         return GetCore().IsPaneMaximized(paneOrder);
260 }
261
262 result
263 _SplitPanelImpl::RestorePane(void)
264 {
265         result r = GetCore().RestorePane();
266         SetLastResultReturn(r);
267 }
268
269 class _SplitPanelMaker
270         : public _UiBuilderControlMaker
271 {
272 public:
273         _SplitPanelMaker(_UiBuilder* uibuilder)
274                 : _UiBuilderControlMaker(uibuilder){};
275         virtual ~_SplitPanelMaker(void){};
276         static _UiBuilderControlMaker*
277         GetInstance(_UiBuilder* uibuilder)
278         {
279                 _SplitPanelMaker* pSplitPanelMaker = new (std::nothrow) _SplitPanelMaker(uibuilder);
280
281                 return pSplitPanelMaker;
282         };
283
284 protected:
285         virtual Control*
286         Make(_UiBuilderControl* pControl)
287         {
288                 result r = E_SYSTEM;
289                 _UiBuilderControlLayout* pControlProperty = null;
290                 SplitPanel* pSplitPanel = null;
291                 Tizen::Graphics::Rectangle rect;
292                 Tizen::Base::String elementString;
293                 Tizen::Base::String xmlLink;
294                 int minDividerPosition = 0;
295                 int maxDividerPosition = 0;
296                 int dividerPosition = 0;
297
298                 SplitPanelDividerStyle splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_MOVABLE;
299                 SplitPanelDividerDirection splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL;
300
301                 GetProperty(pControl, &pControlProperty);
302
303                 if (pControlProperty == null)
304                 {
305                         return null;
306                 }
307
308                 pSplitPanel = new (std::nothrow) SplitPanel();
309                 SysTryReturn(NID_UI_CTRL, pSplitPanel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
310
311                 rect = pControlProperty->GetRect();
312
313                 // Set Style
314                 if (pControl->GetElement("dividerStyle", elementString) || pControl->GetElement("DividerStyle", elementString))
315                 {
316                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_STYLE_FIXED", false))
317                         {
318                                 splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_FIXED;
319                         }
320                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_STYLE_MOVABLE", false))
321                         {
322                                 splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_MOVABLE;
323                         }
324                 }
325
326                 if (pControl->GetElement("dividerDirection", elementString) || pControl->GetElement("DividerDirection", elementString))
327                 {
328                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL", false))
329                         {
330                                 splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL;
331                         }
332                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_DIRECTION_HORIZONTAL", false))
333                         {
334                                 splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_HORIZONTAL;
335                         }
336                 }
337
338                 // Construct
339                 r = pSplitPanel->Construct(rect, splitPanelDividerStyle, splitPanelDividerDirection);
340
341                 if (r != E_SUCCESS)
342                 {
343                         SysLog(NID_UI_CTRL, "Failed to create SplitPanel.");
344                         delete pSplitPanel;
345                         pSplitPanel = null;
346
347                         return null;
348                 }
349
350                 if (pControl->GetElement("minDividerPosition", elementString))
351                 {
352                         Base::Integer::Parse(elementString, minDividerPosition);
353                         pSplitPanel->SetMinimumDividerPosition(minDividerPosition);
354                 }
355
356                 if (pControl->GetElement("maxDividerPosition", elementString))
357                 {
358                         Base::Integer::Parse(elementString, maxDividerPosition);
359                         pSplitPanel->SetMaximumDividerPosition(maxDividerPosition);
360                 }
361
362                 if (pControl->GetElement("dividerPosition", elementString))
363                 {
364                         Base::Integer::Parse(elementString, dividerPosition);
365                         pSplitPanel->SetDividerPosition(dividerPosition);
366                 }
367
368                 //Set pane
369                 if (pControl->GetElement("firstPane", elementString))
370                 {
371                         if (pControl->GetElement("firstPaneXmlLink", xmlLink))
372                         {
373                                 if (elementString.Equals(L"panel", false))
374                                 {
375                                         Panel* pFirstPanel = new (std::nothrow) Panel();
376                                         pFirstPanel->Construct(xmlLink);
377                                         pSplitPanel->SetPane(pFirstPanel, SPLIT_PANEL_PANE_ORDER_FIRST);
378                                 }
379                                 else if (elementString.Equals(L"form", false))
380                                 {
381                                         Form* pFirstForm = new (std::nothrow) Form();
382                                         pFirstForm->Construct(xmlLink);
383                                         pSplitPanel->SetPane(pFirstForm, SPLIT_PANEL_PANE_ORDER_FIRST);
384                                 }
385                                 else if (elementString.Equals(L"scrollpanel", false))
386                                 {
387                                         ScrollPanel* pFirstScrollPanel = new (std::nothrow) ScrollPanel();
388                                         pFirstScrollPanel->Construct(xmlLink);
389                                         pSplitPanel->SetPane(pFirstScrollPanel, SPLIT_PANEL_PANE_ORDER_FIRST);
390                                 }
391                         }
392                 }
393
394                 if (pControl->GetElement("secondPane", elementString))
395                 {
396                         if (pControl->GetElement("secondPaneXmlLink", xmlLink))
397                         {
398                                 if (elementString.Equals(L"panel", false))
399                                 {
400                                         Panel* pFirstPanel = new (std::nothrow) Panel();
401                                         pFirstPanel->Construct(xmlLink);
402                                         pSplitPanel->SetPane(pFirstPanel, SPLIT_PANEL_PANE_ORDER_SECOND);
403                                 }
404                                 else if (elementString.Equals(L"form", false))
405                                 {
406                                         Form* pFirstForm = new (std::nothrow) Form();
407                                         pFirstForm->Construct(xmlLink);
408                                         pSplitPanel->SetPane(pFirstForm, SPLIT_PANEL_PANE_ORDER_SECOND);
409                                 }
410                                 else if (elementString.Equals(L"scrollpanel", false))
411                                 {
412                                         ScrollPanel* pFirstScrollPanel = new (std::nothrow) ScrollPanel();
413                                         pFirstScrollPanel->Construct(xmlLink);
414                                         pSplitPanel->SetPane(pFirstScrollPanel, SPLIT_PANEL_PANE_ORDER_SECOND);
415                                 }
416                         }
417                 }
418
419                 return pSplitPanel;
420         }
421 }; // _SplitPanelMaker
422
423 _SplitPanelRegister::_SplitPanelRegister(void)
424 {
425         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
426         pUiBuilderControlTableManager->RegisterControl(L"SplitPanel", _SplitPanelMaker::GetInstance);
427 }
428 _SplitPanelRegister::~_SplitPanelRegister(void)
429 {
430         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
431         pUiBuilderControlTableManager->UnregisterControl(L"SplitPanel");
432 }
433 static _SplitPanelRegister SplitPanelRegisterToUIbuilder;
434 }}} // Tizen::Ui::Controls
435