Changed indicator bg color.
[platform/framework/native/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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0/
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 <FBase_LocalizedNumParser.h>
27 #include <FUiCtrlPanel.h>
28 #include <FUiCtrlScrollPanel.h>
29 #include <FUiCtrlForm.h>
30 #include "FUiCtrl_SplitPanelImpl.h"
31 #include "FUiCtrl_SplitPanel.h"
32 #include "FUi_UiBuilder.h"
33 #include "FUi_CoordinateSystemUtils.h"
34
35 using namespace Tizen::Base;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Base::Runtime;
39 using namespace Tizen::App;
40
41 namespace Tizen { namespace Ui { namespace Controls
42 {
43
44 _SplitPanelImpl*
45 _SplitPanelImpl::GetInstance(SplitPanel& pSplitPanel)
46 {
47         return static_cast<_SplitPanelImpl*> (pSplitPanel._pControlImpl);
48 }
49
50 const _SplitPanelImpl*
51 _SplitPanelImpl::GetInstance(const SplitPanel& pSplitPanel)
52 {
53         return static_cast<const _SplitPanelImpl*> (pSplitPanel._pControlImpl);
54 }
55
56 _SplitPanelImpl::_SplitPanelImpl(SplitPanel* pPublic, _SplitPanel* pCore)
57         : _ControlImpl(pPublic, pCore)
58         , __pSplitPanel(pCore)
59         , __pPublicSplitPanelEvent(null)
60 {
61         ClearLastResult();
62 }
63
64 _SplitPanelImpl::~_SplitPanelImpl(void)
65 {
66         __pSplitPanel->RemoveSplitPanelEventListener(*this);
67
68         if(__pPublicSplitPanelEvent)
69         {
70                 delete __pPublicSplitPanelEvent;
71                 __pPublicSplitPanelEvent = null;
72         }
73
74         ClearLastResult();
75 }
76
77 _SplitPanelImpl*
78 _SplitPanelImpl::CreateSplitPanelImplN(SplitPanel* pControl, const Rectangle& rect, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
79 {
80         ClearLastResult();
81         result r = E_SUCCESS;
82
83         FloatRectangle rectF = _CoordinateSystemUtils::ConvertToFloat(rect);
84
85         _SplitPanel* pCore = _SplitPanel::CreateSplitPanelN(rectF, splitPanelDividerStyle, splitPanelDividerDirection);
86         SysTryReturn(NID_UI_CTRL, pCore != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
87
88         _SplitPanelImpl* pImpl = new (std::nothrow) _SplitPanelImpl(pControl, pCore);
89         r = _ControlImpl::CheckConstruction(pCore, pImpl);
90         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
91
92         return pImpl;
93 }
94
95 _SplitPanelImpl*
96 _SplitPanelImpl::CreateSplitPanelImplFN(SplitPanel* pControl, const FloatRectangle& rect, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
97 {
98         ClearLastResult();
99         result r = E_SUCCESS;
100
101         _SplitPanel* pCore = _SplitPanel::CreateSplitPanelN(rect, splitPanelDividerStyle, splitPanelDividerDirection);
102         SysTryReturn(NID_UI_CTRL, pCore != null, null, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
103
104         _SplitPanelImpl* pImpl = new (std::nothrow) _SplitPanelImpl(pControl, pCore);
105         r = _ControlImpl::CheckConstruction(pCore, pImpl);
106         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Propagating.", GetErrorMessage(r));
107
108         return pImpl;
109 }
110
111 result
112 _SplitPanelImpl::Initialize(const Rectangle& rect)
113 {
114         ClearLastResult();
115         result r = E_SUCCESS;
116
117         FloatRectangle rectF = _CoordinateSystemUtils::ConvertToFloat(rect);
118
119         r = SetBounds(rectF);
120         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
121
122         __pPublicSplitPanelEvent = _PublicSplitPanelEvent::CreateInstanceN(GetPublic());
123         SysTryReturn(NID_UI_CTRL, __pPublicSplitPanelEvent, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
124
125         r = GetCore().AddSplitPanelEventListener(*this);
126         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
127
128         return r;
129 }
130
131 result
132 _SplitPanelImpl::InitializeF(const FloatRectangle& rect)
133 {
134         ClearLastResult();
135         result r = E_SUCCESS;
136
137         r = SetBounds(rect);
138         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
139
140         __pPublicSplitPanelEvent = _PublicSplitPanelEvent::CreateInstanceN(GetPublic());
141         SysTryReturn(NID_UI_CTRL, __pPublicSplitPanelEvent, GetLastResult(), GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
142
143         r = GetCore().AddSplitPanelEventListener(*this);
144         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
145
146         return r;
147 }
148
149 const char*
150 _SplitPanelImpl::GetPublicClassName(void) const
151 {
152         return "Tizen::Ui::Controls::SplitPanel";
153 }
154
155 const SplitPanel&
156 _SplitPanelImpl::GetPublic(void) const
157 {
158         return static_cast <const SplitPanel&>(_ControlImpl::GetPublic());
159 }
160
161 SplitPanel&
162 _SplitPanelImpl::GetPublic(void)
163 {
164         return static_cast <SplitPanel&>(_ControlImpl::GetPublic());
165 }
166
167 const _SplitPanel&
168 _SplitPanelImpl::GetCore(void) const
169 {
170         return static_cast <const _SplitPanel&>(_ControlImpl::GetCore());
171 }
172
173 _SplitPanel&
174 _SplitPanelImpl::GetCore(void)
175 {
176         return static_cast <_SplitPanel&>(_ControlImpl::GetCore());
177 }
178
179 void
180 _SplitPanelImpl::OnDividerPositionChanged(_SplitPanel& source, int position)
181 {
182         ClearLastResult();
183
184         if (__pPublicSplitPanelEvent != null)
185         {
186                 IEventArg* pEventArg = _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SPLIT_PANEL_EVENT_DIVIDER_POSITION_CHANGE);
187                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
188                 __pPublicSplitPanelEvent->Fire(*pEventArg);
189         }
190 }
191
192 void
193 _SplitPanelImpl::OnDividerDoublePressed(_SplitPanel& source)
194 {
195         ClearLastResult();
196
197         if (__pPublicSplitPanelEvent != null)
198         {
199                 IEventArg* pEventArg = _PublicSplitPanelEvent::CreateSplitPanelEventArgN(SPLIT_PANEL_EVENT_DIVIDER_DOUBLE_PRESSED);
200                 SysTryReturnVoidResult(NID_UI_CTRL, pEventArg, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
201                 __pPublicSplitPanelEvent->Fire(*pEventArg);
202         }
203 }
204
205 result
206 _SplitPanelImpl::AddSplitPanelEventListener(ISplitPanelEventListener& listener)
207 {
208         return __pPublicSplitPanelEvent->AddListener(listener);
209 }
210
211 result
212 _SplitPanelImpl::AddSplitPanelEventListener(ISplitPanelEventListenerF& listener)
213 {
214         return __pPublicSplitPanelEvent->AddListener(listener);
215 }
216
217 result
218 _SplitPanelImpl::RemoveSplitPanelEventListener(ISplitPanelEventListener& listener)
219 {
220         return __pPublicSplitPanelEvent->RemoveListener(listener);
221 }
222
223 result
224 _SplitPanelImpl::RemoveSplitPanelEventListener(ISplitPanelEventListenerF& listener)
225 {
226         return __pPublicSplitPanelEvent->RemoveListener(listener);
227 }
228
229 result
230 _SplitPanelImpl::SetPane(_ControlImpl* pControl, SplitPanelPaneOrder paneOrder)
231 {
232         result r = E_SUCCESS;
233
234         if (pControl == null)
235         {
236                 r = GetCore().SetPane(null, paneOrder);
237         }
238         else
239         {
240                 r = GetCore().SetPane(&(pControl->GetCore()), paneOrder);
241         }
242
243         SetLastResultReturn(r);
244 }
245
246 _ControlImpl*
247 _SplitPanelImpl::GetPane(SplitPanelPaneOrder paneOrder) const
248 {
249         _Control* pControl = GetCore().GetPane(paneOrder);
250         if (pControl == null)
251         {
252                 return null;
253         }
254
255         return static_cast<_ControlImpl*>(pControl->GetUserData());
256 }
257
258 result
259 _SplitPanelImpl::SetDividerPosition(int position)
260 {
261         float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
262         result r = GetCore().SetDividerPosition(floatPosition);
263         SetLastResultReturn(r);
264 }
265
266 result
267 _SplitPanelImpl::SetDividerPosition(float position)
268 {
269         result r = GetCore().SetDividerPosition(position);
270         SetLastResultReturn(r);
271 }
272
273 int
274 _SplitPanelImpl::GetDividerPosition(void) const
275 {
276         ClearLastResult();
277         int position = _CoordinateSystemUtils::ConvertToInteger(GetCore().GetDividerPosition());
278         return position;
279 }
280
281 float
282 _SplitPanelImpl::GetDividerPositionF(void) const
283 {
284         ClearLastResult();
285         return GetCore().GetDividerPosition();
286 }
287
288 result
289 _SplitPanelImpl::SetMaximumDividerPosition(int position)
290 {
291         float floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
292         result r = GetCore().SetMaximumDividerPosition(floatPosition);
293         SetLastResultReturn(r);
294 }
295
296 result
297 _SplitPanelImpl::SetMaximumDividerPosition(float position)
298 {
299         result r = GetCore().SetMaximumDividerPosition(position);
300         SetLastResultReturn(r);
301 }
302
303 int
304 _SplitPanelImpl::GetMaximumDividerPosition(void) const
305 {
306         ClearLastResult();
307         int maxPosition = _CoordinateSystemUtils::ConvertToInteger(GetCore().GetMaximumDividerPosition());
308         return maxPosition;
309 }
310
311 float
312 _SplitPanelImpl::GetMaximumDividerPositionF(void) const
313 {
314         ClearLastResult();
315         return GetCore().GetMaximumDividerPosition();
316 }
317
318 result
319 _SplitPanelImpl::SetMinimumDividerPosition(int position)
320 {
321         int floatPosition = _CoordinateSystemUtils::ConvertToFloat(position);
322         result r = GetCore().SetMinimumDividerPosition(floatPosition);
323         SetLastResultReturn(r);
324 }
325
326 result
327 _SplitPanelImpl::SetMinimumDividerPosition(float position)
328 {
329         result r = GetCore().SetMinimumDividerPosition(position);
330         SetLastResultReturn(r);
331 }
332
333 int
334 _SplitPanelImpl::GetMinimumDividerPosition(void) const
335 {
336         ClearLastResult();
337         int minPosition = _CoordinateSystemUtils::ConvertToInteger(GetCore().GetMinimumDividerPosition());
338         return minPosition;
339 }
340
341 float
342 _SplitPanelImpl::GetMinimumDividerPositionF(void) const
343 {
344         ClearLastResult();
345         return GetCore().GetMinimumDividerPosition();
346 }
347
348 result
349 _SplitPanelImpl::MaximizePane(SplitPanelPaneOrder paneOrder)
350 {
351         result r = GetCore().MaximizePane(paneOrder);
352         SetLastResultReturn(r);
353 }
354
355 bool
356 _SplitPanelImpl::IsPaneMaximized(SplitPanelPaneOrder paneOrder) const
357 {
358         ClearLastResult();
359         return GetCore().IsPaneMaximized(paneOrder);
360 }
361
362 result
363 _SplitPanelImpl::RestorePane(void)
364 {
365         result r = GetCore().RestorePane();
366         SetLastResultReturn(r);
367 }
368
369 class _SplitPanelMaker
370         : public _UiBuilderControlMaker
371 {
372 public:
373         _SplitPanelMaker(_UiBuilder* uibuilder)
374                 : _UiBuilderControlMaker(uibuilder)
375         {
376                 __pTransform = uibuilder->GetTransformer();
377         };
378         virtual ~_SplitPanelMaker(void){};
379         static _UiBuilderControlMaker*
380         GetInstance(_UiBuilder* uibuilder)
381         {
382                 _SplitPanelMaker* pSplitPanelMaker = new (std::nothrow) _SplitPanelMaker(uibuilder);
383
384                 return pSplitPanelMaker;
385         };
386
387 protected:
388         virtual Control*
389         Make(_UiBuilderControl* pControl)
390         {
391                 result r = E_SYSTEM;
392                 _UiBuilderControlLayout* pControlProperty = null;
393                 SplitPanel* pSplitPanel = null;
394                 Tizen::Graphics::FloatRectangle rect;
395                 Tizen::Base::String elementString;
396                 Tizen::Base::String xmlLink;
397                 float minDividerPosition = 0.0f;
398                 float maxDividerPosition = 0.0f;
399                 float dividerPosition = 0.0f;
400                 float originalValue = 0.0f;
401
402                 SplitPanelDividerStyle splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_MOVABLE;
403                 SplitPanelDividerDirection splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL;
404
405                 GetProperty(pControl, &pControlProperty);
406
407                 if (pControlProperty == null)
408                 {
409                         return null;
410                 }
411
412                 pSplitPanel = new (std::nothrow) SplitPanel();
413                 SysTryReturn(NID_UI_CTRL, pSplitPanel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
414
415                 rect = pControlProperty->GetRectF();
416
417                 // Set Style
418                 if (pControl->GetElement("dividerStyle", elementString) || pControl->GetElement("DividerStyle", elementString))
419                 {
420                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_STYLE_FIXED", false))
421                         {
422                                 splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_FIXED;
423                         }
424                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_STYLE_MOVABLE", false))
425                         {
426                                 splitPanelDividerStyle = SPLIT_PANEL_DIVIDER_STYLE_MOVABLE;
427                         }
428                 }
429
430                 if (pControl->GetElement("dividerDirection", elementString) || pControl->GetElement("DividerDirection", elementString))
431                 {
432                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL", false))
433                         {
434                                 splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL;
435                         }
436                         if (elementString.Equals(L"SPLIT_PANEL_DIVIDER_DIRECTION_HORIZONTAL", false))
437                         {
438                                 splitPanelDividerDirection = SPLIT_PANEL_DIVIDER_DIRECTION_HORIZONTAL;
439                         }
440                 }
441
442                 // Construct
443                 r = pSplitPanel->Construct(rect, splitPanelDividerStyle, splitPanelDividerDirection);
444
445                 if (r != E_SUCCESS)
446                 {
447                         SysLog(NID_UI_CTRL, "Failed to create SplitPanel.");
448                         delete pSplitPanel;
449                         pSplitPanel = null;
450
451                         return null;
452                 }
453
454                 if (pControl->GetElement("minDividerPosition", elementString))
455                 {
456                         minDividerPosition = _LocalizedNumParser::ToDouble(elementString, "C");
457
458                         if (__pTransform != null)
459                         {
460                                 originalValue = minDividerPosition;
461                                 minDividerPosition = __pTransform->Transform(originalValue);
462                         }
463
464                         pSplitPanel->SetMinimumDividerPosition(minDividerPosition);
465                 }
466
467                 if (pControl->GetElement("maxDividerPosition", elementString))
468                 {
469                         maxDividerPosition = _LocalizedNumParser::ToDouble(elementString, "C");
470
471                         if (__pTransform != null)
472                         {
473                                 originalValue = maxDividerPosition;
474                                 maxDividerPosition = __pTransform->Transform(originalValue);
475                         }
476
477                         pSplitPanel->SetMaximumDividerPosition(maxDividerPosition);
478                 }
479
480                 if (pControl->GetElement("dividerPosition", elementString))
481                 {
482                         dividerPosition = _LocalizedNumParser::ToDouble(elementString, "C");
483
484                         if (__pTransform != null)
485                         {
486                                 originalValue = dividerPosition;
487                                 dividerPosition = __pTransform->Transform(originalValue);
488                         }
489
490                         pSplitPanel->SetDividerPosition(dividerPosition);
491                 }
492
493                 //Set pane
494                 if (pControl->GetElement("firstPane", elementString))
495                 {
496                         if (pControl->GetElement("firstPaneXmlLink", xmlLink))
497                         {
498                                 if (elementString.Equals(L"panel", false))
499                                 {
500                                         Panel* pFirstPanel = new (std::nothrow) Panel();
501                                         pFirstPanel->Construct(xmlLink);
502                                         pSplitPanel->SetPane(pFirstPanel, SPLIT_PANEL_PANE_ORDER_FIRST);
503                                 }
504                                 else if (elementString.Equals(L"form", false))
505                                 {
506                                         Form* pFirstForm = new (std::nothrow) Form();
507                                         pFirstForm->Construct(xmlLink);
508                                         pSplitPanel->SetPane(pFirstForm, SPLIT_PANEL_PANE_ORDER_FIRST);
509                                 }
510                                 else if (elementString.Equals(L"scrollpanel", false))
511                                 {
512                                         ScrollPanel* pFirstScrollPanel = new (std::nothrow) ScrollPanel();
513                                         pFirstScrollPanel->Construct(xmlLink);
514                                         pSplitPanel->SetPane(pFirstScrollPanel, SPLIT_PANEL_PANE_ORDER_FIRST);
515                                 }
516                         }
517                 }
518
519                 if (pControl->GetElement("secondPane", elementString))
520                 {
521                         if (pControl->GetElement("secondPaneXmlLink", xmlLink))
522                         {
523                                 if (elementString.Equals(L"panel", false))
524                                 {
525                                         Panel* pFirstPanel = new (std::nothrow) Panel();
526                                         pFirstPanel->Construct(xmlLink);
527                                         pSplitPanel->SetPane(pFirstPanel, SPLIT_PANEL_PANE_ORDER_SECOND);
528                                 }
529                                 else if (elementString.Equals(L"form", false))
530                                 {
531                                         Form* pFirstForm = new (std::nothrow) Form();
532                                         pFirstForm->Construct(xmlLink);
533                                         pSplitPanel->SetPane(pFirstForm, SPLIT_PANEL_PANE_ORDER_SECOND);
534                                 }
535                                 else if (elementString.Equals(L"scrollpanel", false))
536                                 {
537                                         ScrollPanel* pFirstScrollPanel = new (std::nothrow) ScrollPanel();
538                                         pFirstScrollPanel->Construct(xmlLink);
539                                         pSplitPanel->SetPane(pFirstScrollPanel, SPLIT_PANEL_PANE_ORDER_SECOND);
540                                 }
541                         }
542                 }
543
544                 return pSplitPanel;
545         }
546 private:
547         _ICoordinateSystemTransformer* __pTransform;
548 }; // _SplitPanelMaker
549
550 _SplitPanelRegister::_SplitPanelRegister(void)
551 {
552         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
553         pUiBuilderControlTableManager->RegisterControl(L"SplitPanel", _SplitPanelMaker::GetInstance);
554 }
555 _SplitPanelRegister::~_SplitPanelRegister(void)
556 {
557         _UiBuilderControlTableManager* pUiBuilderControlTableManager = _UiBuilderControlTableManager::GetInstance();
558         pUiBuilderControlTableManager->UnregisterControl(L"SplitPanel");
559 }
560 static _SplitPanelRegister SplitPanelRegisterToUIbuilder;
561 }}} // Tizen::Ui::Controls
562