Tizen 2.1 base
[framework/osp/uifw.git] / src / ui / controls / FUiCtrl_SplitPanel.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  * @file                FUiCtrl_SplitPanel.cpp
19  * @brief               This is the implementation file for the _SplitPanel class.
20  */
21
22 #include <FBaseErrorDefine.h>
23 #include <FBaseString.h>
24 #include <FBaseSysLog.h>
25 #include <FGrp_BitmapImpl.h>
26 #include "FUi_ResourceManager.h"
27 #include "FUi_UiTouchEvent.h"
28 #include "FUi_TouchTapGestureDetector.h"
29 #include "FUi_AccessibilityContainer.h"
30 #include "FUi_AccessibilityElement.h"
31 #include "FUiCtrl_SplitPanel.h"
32 #include "FUiCtrl_SplitPanelPresenter.h"
33
34 using namespace Tizen::Ui;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui::Animations;
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Runtime;
39
40 namespace Tizen { namespace Ui { namespace Controls
41 {
42
43 _SplitPanel::_SplitPanel()
44         : __pSplitPanelPresenter(null)
45         , __pTapGesture(null)
46         , __pFirstPane(null)
47         , __pSecondPane(null)
48         , __splitPanelDividerDirection(SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
49         , __pSplitPanelEvent(null)
50         , __dividerTapCount(0)
51         , __pAccessibilityElement(null)
52         , __pDividerVisualElement(null)
53         , __isDividerPositionInitialized(false)
54         , __isDividerMaximumPositionInitialized(false)
55         , __isDividerMinimumPositionInitialized(false)
56         , __isFirstTimeOrientationChanged(true)
57 {
58         for (int i=0; i < _SPLIT_PANEL_DIVIDER_STATE; i++)
59         {
60                 __dividerPosition[i] = 0;
61                 __minimumDividerPosition[i] = 0;
62                 __maximumDividerPosition[i] = 0;
63         }
64 }
65
66 _SplitPanel*
67 _SplitPanel::CreateSplitPanelN(const Rectangle& rect, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
68 {
69         result r = E_SUCCESS;
70
71         _SplitPanel* pSplitPanel = new (std::nothrow) _SplitPanel;
72         SysTryReturn(NID_UI_CTRL, pSplitPanel, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
73
74         r = pSplitPanel->Construct(splitPanelDividerStyle, splitPanelDividerDirection);
75         if (r != E_SUCCESS)
76         {
77                 delete pSplitPanel;
78                 pSplitPanel = null;
79                 return null;
80         }
81         pSplitPanel->AcquireHandle();
82         pSplitPanel->SetDividerDirection(splitPanelDividerDirection);
83
84         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
85
86         int dividerThickness = 0;
87         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, dividerThickness);
88
89         pSplitPanel->__maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = rect.width - dividerThickness;
90         pSplitPanel->__maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = rect.width - dividerThickness;
91         pSplitPanel->__maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = rect.height - dividerThickness;
92         pSplitPanel->__maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = rect.width - dividerThickness;
93
94         pSplitPanel->__dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = rect.width / 2;
95         pSplitPanel->__dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = rect.width / 2;
96         pSplitPanel->__dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] =  rect.height / 2;
97         pSplitPanel->__dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = rect.height / 2;
98
99         pSplitPanel->__pTapGesture = new (std::nothrow) _TouchTapGestureDetector;
100         SysTryCatch(NID_UI_CTRL, pSplitPanel->__pTapGesture, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
101
102         pSplitPanel->AddGestureDetector(*(pSplitPanel->__pTapGesture));
103         r = pSplitPanel->__pTapGesture->AddGestureListener(*pSplitPanel);
104         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
105
106         pSplitPanel->SetBackgroundColor(Color(0,0,0,0));
107
108         if (likely(_AccessibilityManager::IsActivated()) && pSplitPanel->GetAccessibilityContainer())
109         {
110                 pSplitPanel->GetAccessibilityContainer()->Activate(true);
111         }
112
113         return pSplitPanel;
114
115 CATCH:
116         if (pSplitPanel->__pTapGesture != null)
117         {
118                 pSplitPanel->__pTapGesture->RemoveGestureListener(*pSplitPanel);
119                 pSplitPanel->RemoveGestureDetector(*pSplitPanel->__pTapGesture);
120
121                 delete pSplitPanel->__pTapGesture;
122                 pSplitPanel->__pTapGesture = null;
123         }
124
125         delete pSplitPanel;
126         return null;
127 }
128
129 result
130 _SplitPanel::Construct(SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
131 {
132         result r = E_SUCCESS;
133
134         __pDividerVisualElement = new (std::nothrow) VisualElement();
135         SysTryReturnResult(NID_UI_CTRL, __pDividerVisualElement, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
136         r = __pDividerVisualElement->Construct();
137         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct divider visual element.", GetErrorMessage(r));
138
139         __pDividerVisualElement->SetShowState(true);
140         __pDividerVisualElement->SetImplicitAnimationEnabled(false);
141         __pDividerVisualElement->SetClipChildrenEnabled(false);
142
143         r = GetVisualElement()->AttachChild(*__pDividerVisualElement);
144         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach divider visual element.", GetErrorMessage(r));
145
146         __pSplitPanelPresenter = new (std::nothrow) _SplitPanelPresenter;
147         SysTryCatch(NID_UI_CTRL, __pSplitPanelPresenter != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
148
149         r = __pSplitPanelPresenter->Construct(*this, splitPanelDividerStyle, splitPanelDividerDirection);
150         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct presenter.", GetErrorMessage(r));
151
152         return r;
153
154 CATCH:
155         if (__pDividerVisualElement)
156         {
157                 __pDividerVisualElement->Destroy();
158                 __pDividerVisualElement = null;
159         }
160
161         delete __pSplitPanelPresenter;
162         __pSplitPanelPresenter = null;
163
164         return r;
165 }
166
167 _SplitPanel::~_SplitPanel(void)
168 {
169         if (__pSplitPanelPresenter)
170         {
171                 delete __pSplitPanelPresenter;
172                 __pSplitPanelPresenter = null;
173         }
174
175         if (__pSplitPanelEvent)
176         {
177                 delete __pSplitPanelEvent;
178                 __pSplitPanelEvent = null;
179         }
180
181         if (__pTapGesture)
182         {
183                 __pTapGesture->RemoveGestureListener(*this);
184                 RemoveGestureDetector(*__pTapGesture);
185
186                 delete __pTapGesture;
187                 __pTapGesture = null;
188         }
189
190         if (__pAccessibilityElement)
191         {
192                 __pAccessibilityElement->Activate(false);
193                 __pAccessibilityElement = null;
194         }
195
196         if (__pDividerVisualElement)
197         {
198                 __pDividerVisualElement->Destroy();
199                 __pDividerVisualElement = null;
200         }
201
202         ClearLastResult();
203 }
204
205 result
206 _SplitPanel::SetPresenter(const _SplitPanelPresenter& splitPanelPresenter)
207 {
208         __pSplitPanelPresenter = const_cast<_SplitPanelPresenter*>(&splitPanelPresenter);
209         return E_SUCCESS;
210 }
211
212 result
213 _SplitPanel::AddSplitPanelEventListener(const _ISplitPanelEventListener& listener)
214 {
215         result r = E_SUCCESS;
216
217         if (__pSplitPanelEvent == null)
218         {
219                 __pSplitPanelEvent = _SplitPanelEvent::CreateInstanceN(*this);
220                 r = GetLastResult();
221                 SysTryReturn(NID_UI_CTRL, __pSplitPanelEvent, r, r, "[%s] Propagating.", GetErrorMessage(r))
222
223                 __pSplitPanelEvent->AddListener(listener);
224         }
225
226         return r;
227 }
228
229 result
230 _SplitPanel::RemoveSplitPanelEventListener(const _ISplitPanelEventListener& listener)
231 {
232         SysTryReturn(NID_UI_CTRL, __pSplitPanelEvent, E_SYSTEM, E_SYSTEM,
233                                 "[E_SYSTEM] System error occurred.")
234
235         __pSplitPanelEvent->RemoveListener(listener);
236
237         return E_SUCCESS;
238 }
239
240 void
241 _SplitPanel::OnDraw(void)
242 {
243         __pSplitPanelPresenter->Draw();
244
245         return;
246 }
247
248 void
249 _SplitPanel::OnChangeLayout(_ControlOrientation orientation)
250 {
251         if (__isFirstTimeOrientationChanged)
252         {
253                 Rectangle bounds = GetBounds();
254
255                 int dividerThickness = 0;
256                 GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, dividerThickness);
257
258                 if (!__isDividerMaximumPositionInitialized)
259                 {
260                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
261                         {
262                                 __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = bounds.width - dividerThickness;
263                                 __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = bounds.width - dividerThickness;
264                         }
265                         else
266                         {
267                                 __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = bounds.width - dividerThickness;
268                                 __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = bounds.width - dividerThickness;
269                         }
270                 }
271
272                 if (!__isDividerPositionInitialized)
273                 {
274                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
275                         {
276                                 __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = bounds.width / 2;
277                                 __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] =  bounds.height / 2;
278                         }
279                         else
280                         {
281                                 __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = bounds.width / 2;
282                                 __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = bounds.height / 2;
283                         }
284                 }
285
286                 __isFirstTimeOrientationChanged = false;
287         }
288
289         __pSplitPanelPresenter->OnChangeLayout(orientation);
290
291         return;
292 }
293
294 void
295 _SplitPanel::OnBoundsChanged(void)
296 {
297         Rectangle bounds = GetBounds();
298
299         int dividerThickness = 0;
300
301         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
302
303         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, dividerThickness);
304
305         if (GetMaximumDividerPosition() > (bounds.width - dividerThickness))
306         {
307                 SetMaximumDividerPosition(bounds.width - dividerThickness);
308         }
309
310         __pSplitPanelPresenter->OnBoundsChanged();
311
312         return;
313 }
314
315 bool
316 _SplitPanel::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
317 {
318         if (&source != this)
319         {
320                 return false;
321         }
322         return __pSplitPanelPresenter->OnTouchPressed(source, touchinfo);
323 }
324
325 bool
326 _SplitPanel::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
327 {
328         if (&source != this)
329         {
330                 return false;
331         }
332         return __pSplitPanelPresenter->OnTouchReleased(source, touchinfo);
333 }
334
335 bool
336 _SplitPanel::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
337 {
338         if (&source != this)
339         {
340                 return false;
341         }
342         return __pSplitPanelPresenter->OnTouchMoved(source, touchinfo);
343 }
344
345 bool
346 _SplitPanel::OnTouchCanceled(const _Control & source, const _TouchInfo & touchinfo)
347 {
348         return __pSplitPanelPresenter->OnTouchCanceled(source, touchinfo);
349 }
350
351 bool
352 _SplitPanel::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
353 {
354         if (__pSplitPanelPresenter == null)
355         {
356                 return true;
357         }
358
359         return __pSplitPanelPresenter->OnTapGestureDetected(gesture);
360 }
361
362 bool
363 _SplitPanel::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
364 {
365         return __pSplitPanelPresenter->OnTapGestureCanceled(gesture);
366 }
367
368 result
369 _SplitPanel::SetPane(_Control* pControl, SplitPanelPaneOrder paneOrder)
370 {
371         result r = E_SUCCESS;
372
373         SysTryReturn(NID_UI_CTRL, __pSplitPanelPresenter != null, E_SYSTEM, E_SYSTEM,
374                                 "[E_SYSTEM] A system error occurred.");
375
376         if (paneOrder == SPLIT_PANEL_PANE_ORDER_FIRST)
377         {
378                 __pFirstPane = pControl;
379         }
380         else
381         {
382                 __pSecondPane = pControl;
383         }
384
385         r = AttachChild(*pControl);
386         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
387
388         return E_SUCCESS;
389 }
390
391 _Control*
392 _SplitPanel::GetPane(SplitPanelPaneOrder paneOrder) const
393 {
394         SysTryReturn(NID_UI_CTRL, __pSplitPanelPresenter != null, null, E_SYSTEM,
395                                 "[E_SYSTEM] System error occurred.");
396
397         if (paneOrder == SPLIT_PANEL_PANE_ORDER_FIRST)
398         {
399                 return const_cast <_Control*>(__pFirstPane);
400         }
401         else
402         {
403                 return const_cast <_Control*>(__pSecondPane);
404         }
405 }
406
407 result
408 _SplitPanel::SetDividerStyle(SplitPanelDividerStyle splitPanelDividerStyle)
409 {
410         SysTryReturn(NID_UI_CTRL, __pSplitPanelPresenter != null, E_SYSTEM, E_SYSTEM,
411                                 "[E_SYSTEM] System error occurred.");
412
413         __pSplitPanelPresenter->SetDividerStyle(splitPanelDividerStyle);
414
415         return E_SUCCESS;
416 }
417
418 SplitPanelDividerStyle
419 _SplitPanel::GetDividerStyle(void) const
420 {
421         return __pSplitPanelPresenter->GetDividerStyle();
422 }
423
424 result
425 _SplitPanel::SetDividerPosition(int position)
426 {
427         const int width = GetBounds().width;
428
429         if ((0 > position) || (width < position))
430         {
431                 return E_OUT_OF_RANGE;
432         }
433
434         if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_MOVABLE)
435         {
436                 if ((GetMinimumDividerPosition() > position) || (GetMaximumDividerPosition() < position))
437                 {
438                         return E_OUT_OF_RANGE;
439                 }
440         }
441
442         if (!__isDividerPositionInitialized)
443         {
444                 if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
445                 {
446                         __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
447                         __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
448                 }
449                 else
450                 {
451                         __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
452                         __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
453                 }
454
455                 __isDividerPositionInitialized = true;
456         }
457         else
458         {
459                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
460
461                 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
462                 {
463                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
464                         {
465                                 __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
466                         }
467                         else
468                         {
469                                 __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
470                         }
471                 }
472                 else
473                 {
474                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
475                         {
476                                 __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
477                         }
478                         else
479                         {
480                                 __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
481                         }
482                 }
483         }
484
485         __pSplitPanelPresenter->RecalcSplitPanel();
486
487         return E_SUCCESS;
488 }
489
490 int
491 _SplitPanel::GetDividerPosition(void) const
492 {
493         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
494
495         if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
496         {
497                 if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
498                 {
499                         return __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE];
500                 }
501                 else
502                 {
503                         return __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE];
504                 }
505         }
506         else
507         {
508                 if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
509                 {
510                         return __dividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT];
511                 }
512                 else
513                 {
514                         return __dividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT];
515                 }
516         }
517 }
518
519 result
520 _SplitPanel::SetMaximumDividerPosition(int position)
521 {
522         if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_FIXED)
523         {
524                 SysLog(NID_UI_CTRL, "[E_SYSTEM] System error occurred. This functionality is not supported for divider style fixed");
525                 return E_SUCCESS;
526         }
527
528         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
529
530         const int width = GetBounds().width;
531         int margin = 0;
532         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER, orientation, margin);
533
534         if ((0 > position) || ((width - margin) < position) || (position < GetMinimumDividerPosition()))
535         {
536                 return E_OUT_OF_RANGE;
537         }
538
539         if (!__isDividerMaximumPositionInitialized)
540         {
541                 if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
542                 {
543                         __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
544                         __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
545                 }
546                 else
547                 {
548                         __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
549                         __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
550                 }
551
552                 __isDividerMaximumPositionInitialized = true;
553         }
554         else
555         {
556                 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
557                 {
558                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
559                         {
560                                 __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
561                         }
562                         else
563                         {
564                                 __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
565                         }
566                 }
567                 else
568                 {
569                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
570                         {
571                                 __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
572                         }
573                         else
574                         {
575                                 __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
576                         }
577                 }
578         }
579
580         if (GetDividerPosition() > position)
581         {
582                 SetDividerPosition(position);
583         }
584
585         return E_SUCCESS;
586 }
587
588 int
589 _SplitPanel::GetMaximumDividerPosition(void) const
590 {
591         if (GetDividerStyle() != SPLIT_PANEL_DIVIDER_STYLE_FIXED)
592         {
593                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
594
595                 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
596                 {
597                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
598                         {
599                                 return __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE];
600                         }
601                         else
602                         {
603                                 return __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE];
604                         }
605                 }
606                 else
607                 {
608                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
609                         {
610                                 return __maximumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT];
611                         }
612                         else
613                         {
614                                 return __maximumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT];
615                         }
616                 }
617
618         }
619
620         return GetBounds().width;
621 }
622
623 result
624 _SplitPanel::SetMinimumDividerPosition(int position)
625 {
626         if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_FIXED)
627         {
628                 SysLog(NID_UI_CTRL, "[E_SYSTEM] System error occurred. This functionality is not supported for divider style fixed");
629                 return E_SUCCESS;
630         }
631
632         const int width = GetBounds().width;
633
634         if ((0 > position) || (width < position) || (position > GetMaximumDividerPosition()))
635         {
636                 return E_OUT_OF_RANGE;
637         }
638
639         if (!__isDividerMinimumPositionInitialized)
640         {
641                 if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
642                 {
643                         __minimumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
644                         __minimumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
645                 }
646                 else
647                 {
648                         __minimumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
649                         __minimumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
650                 }
651
652                 __isDividerMinimumPositionInitialized = true;
653         }
654         else
655         {
656                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
657
658                 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
659                 {
660                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
661                         {
662                                 __minimumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
663                         }
664                         else
665                         {
666                                 __minimumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE] = position;
667                         }
668                 }
669                 else
670                 {
671                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
672                         {
673                                 __minimumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
674                         }
675                         else
676                         {
677                                 __minimumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT] = position;
678                         }
679                 }
680         }
681
682         if (GetDividerPosition() < position)
683         {
684                 SetDividerPosition(position);
685         }
686
687         return E_SUCCESS;
688 }
689
690 int
691 _SplitPanel::GetMinimumDividerPosition(void) const
692 {
693         if (GetDividerStyle() != SPLIT_PANEL_DIVIDER_STYLE_FIXED)
694         {
695                 _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
696
697                 if (orientation == _CONTROL_ORIENTATION_LANDSCAPE)
698                 {
699                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
700                         {
701                                 return __minimumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_LANDSCAPE];
702                         }
703                         else
704                         {
705                                 return __minimumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_LANDSCAPE];
706                         }
707                 }
708                 else
709                 {
710                         if (GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
711                         {
712                                 return __minimumDividerPosition[_SPLIT_PANEL_VERTICAL_DIVIDER_ORIENTATION_PORTRAIT];
713                         }
714                         else
715                         {
716                                 return __minimumDividerPosition[_SPLIT_PANEL_HORIZONTAL_DIVIDER_ORIENTATION_PORTRAIT];
717                         }
718                 }
719
720         }
721
722         return 0;
723 }
724
725 void
726 _SplitPanel::SetDividerDirection(SplitPanelDividerDirection dividerDirection)
727 {
728         __splitPanelDividerDirection = dividerDirection;
729
730         return;
731 }
732
733 SplitPanelDividerDirection
734 _SplitPanel::GetDividerDirection(void) const
735 {
736         SetLastResult(E_SUCCESS);
737
738         return __splitPanelDividerDirection;
739 }
740
741 result
742 _SplitPanel::MaximizePane(SplitPanelPaneOrder paneOrder)
743 {
744         SysTryReturn(NID_UI_CTRL, __pSplitPanelPresenter != null, E_SYSTEM, E_SYSTEM,
745                                 "[E_SYSTEM] System error occurred.");
746
747         __pSplitPanelPresenter->MaximizePane(paneOrder);
748
749         return E_SUCCESS;
750 }
751
752 bool
753 _SplitPanel::IsPaneMaximized(SplitPanelPaneOrder paneOrder) const
754 {
755         SysTryReturn(NID_UI_CTRL, __pSplitPanelPresenter != null, false, E_SYSTEM,
756                                 "[E_SYSTEM] System error occurred.");
757
758         return __pSplitPanelPresenter->IsPaneMaximized(paneOrder);
759 }
760
761 result
762 _SplitPanel::RestorePane(void)
763 {
764         SysTryReturn(NID_UI_CTRL, __pSplitPanelPresenter != null, E_SYSTEM, E_SYSTEM,
765                                 "[E_SYSTEM] System error occurred.");
766
767         __pSplitPanelPresenter->RestorePane();
768
769         return E_SUCCESS;
770 }
771
772 result
773 _SplitPanel::SendSplitPanelEvent(_SplitPanelEventStatus status)
774 {
775         result r = E_SUCCESS;
776
777         if (__pSplitPanelEvent)
778         {
779                 IEventArg* pEventArg = _SplitPanelEvent::CreateSplitPanelEventArgN(status);
780                 r = GetLastResult();
781                 SysTryReturn(NID_UI_CTRL, pEventArg, r, r, "[%s] Propagating.", GetErrorMessage(r));
782
783                 __pSplitPanelEvent->Fire(*pEventArg);
784         }
785
786         return r;
787 }
788
789 void
790 _SplitPanel::SetTapCount(int count)
791 {
792         __dividerTapCount = count;
793
794         return;
795 }
796
797 int
798 _SplitPanel::GetTapCount(void) const
799 {
800         return __dividerTapCount;
801 }
802
803 result
804 _SplitPanel::OnAttachedToMainTree(void)
805 {
806         if (likely(!(_AccessibilityManager::IsActivated())))
807         {
808                 return E_SUCCESS;
809         }
810
811         _AccessibilityContainer* pContainer = GetAccessibilityContainer();
812
813         if (pContainer)
814         {
815                 if (__pDividerVisualElement)
816                 {
817                         Rectangle dividerRect = __pSplitPanelPresenter->GetDividerRectangle();
818                         String hintText = L"";
819
820                         if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_FIXED)
821                         {
822                                 hintText = String(L"Drag scroll Fixed");
823                         }
824                         else
825                         {
826                                 hintText = String(L"Drag scroll, double tap and move to adjust split area");
827                         }
828
829                         __pAccessibilityElement = new _AccessibilityElement(true);
830                         SysTryReturn(NID_UI_CTRL, __pAccessibilityElement, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
831
832                         __pAccessibilityElement->SetBounds(dividerRect);
833                         __pAccessibilityElement->SetTrait(ACCESSIBILITY_TRAITS_NONE);
834                         __pAccessibilityElement->SetHint(hintText);
835                         __pAccessibilityElement->SetLabel(L"");
836                         __pAccessibilityElement->SetName(L"SplitPanelDivider");
837
838                         pContainer->AddElement(*__pAccessibilityElement);
839                         pContainer->AddListener(*this);
840                 }
841         }
842
843         return E_SUCCESS;
844 }
845
846 VisualElement*
847 _SplitPanel::GetDividerVisualElement(void)
848 {
849         return __pDividerVisualElement;
850 }
851
852 void
853 _SplitPanel::SetDividerVisualElementBounds(Rectangle& bounds)
854 {
855         if (__pDividerVisualElement)
856         {
857                 __pDividerVisualElement->SetBounds(FloatRectangle(bounds.x, bounds.y, bounds.width, bounds.height));
858
859                 if (likely(_AccessibilityManager::IsActivated()) && __pAccessibilityElement)
860                 {
861                         __pAccessibilityElement->SetBounds(bounds);
862                 }
863         }
864
865         return;
866 }
867
868 bool
869 _SplitPanel::OnAccessibilityValueIncreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
870 {
871         SetDividerPosition(GetDividerPosition() + 5);
872
873         Invalidate();
874         return true;
875 }
876
877 bool
878 _SplitPanel::OnAccessibilityValueDecreased(const _AccessibilityContainer& control, const _AccessibilityElement& element)
879 {
880
881         SetDividerPosition(GetDividerPosition() - 5);
882
883         Invalidate();
884         return true;
885 }
886
887 }}} // Tizen::Ui::Controls
888