Fork for IVI: mesa fixing
[profile/ivi/uifw.git] / src / ui / controls / FUiCtrl_SplitPanelPresenter.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_SplitPanelPresenter.cpp
20  * @brief               This is the header file for the _SplitPanelPresenter class.
21  *
22  * This header file contains the declarations of the %_SplitPanelPresenter class.
23  */
24
25 #include <FBaseErrorDefine.h>
26 #include <FGrpCanvas.h>
27 #include <FUiCtrlSplitPanelTypes.h>
28 #include <FBaseSysLog.h>
29 #include <FGrp_BitmapImpl.h>
30 #include "FUi_ResourceManager.h"
31 #include "FUi_UiTouchEvent.h"
32 #include "FUiCtrl_SplitPanelPresenter.h"
33 #include "FUiCtrl_SplitPanel.h"
34 #include "FUiCtrl_SplitPanelImpl.h"
35
36 using namespace Tizen::Ui;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui::Animations;
39
40 namespace Tizen { namespace Ui { namespace Controls
41 {
42
43 _SplitPanelPresenter::_SplitPanelPresenter(void)
44         : __pSplitPanel(null)
45         , __pSplitPanelModel(null)
46         , __dividerMaximumPosition(0)
47         , __dividerMinimumPosition(0)
48         , __splitPanelDividerPressed(false)
49         , __setFirstDividerPositionChangeEvent(true)
50         , __dividerRectangle(0,0,0,0)
51         , __dividerThumbRectangle(0,0,0,0)
52         , __pDividerPressedBackgroundBitmap(null)
53         , __pDividerBackgroundBitmap(null)
54         , __pDividerBackgroundEffectBitmap(null)
55         , __pDividerThumbBitmap(null)
56         , __transactionIdMaximize(0)
57         , __transactionIdRestore(0)
58         , __controlAnimatorAnimationInterpolator(ANIMATION_INTERPOLATOR_LINEAR)
59         , __visualElementAnimationInterpolator(L"Linear")
60 {
61         GET_COLOR_CONFIG(SPLITPANEL::DIVIDER_BG_NORMAL, __dividerBackgroundColor);
62         GET_COLOR_CONFIG(SPLITPANEL::DIVIDER_BG_PRESSED, __dividerPressedBackgroundColor);
63 }
64
65 _SplitPanelPresenter::~_SplitPanelPresenter(void)
66 {
67         delete __pSplitPanelModel;
68         __pSplitPanelModel = null;
69
70         delete __pDividerPressedBackgroundBitmap;
71         __pDividerPressedBackgroundBitmap = null;
72
73         delete __pDividerBackgroundBitmap;
74         __pDividerBackgroundBitmap = null;
75
76         delete __pDividerThumbBitmap;
77         __pDividerThumbBitmap = null;
78
79         delete __pDividerBackgroundEffectBitmap;
80         __pDividerBackgroundEffectBitmap = null;
81 }
82
83 result
84 _SplitPanelPresenter::Construct(const _SplitPanel& splitPanel, SplitPanelDividerStyle splitPanelDividerStyle, SplitPanelDividerDirection splitPanelDividerDirection)
85 {
86         result r = E_SUCCESS;
87
88         _SplitPanelModel* pModel = new (std::nothrow) _SplitPanelModel;
89         SysTryReturnResult(NID_UI_CTRL, pModel, E_OUT_OF_MEMORY, "Memory allocation failed.");
90
91         r = SetModel(*pModel);
92         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to set the model.");
93
94         r = pModel->Construct();
95         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. Failed to construct _SplitPanelModel instance.");
96
97         __pSplitPanel = const_cast <_SplitPanel*>(&splitPanel);
98         SysTryCatch(NID_UI_CTRL, __pSplitPanel != null, , E_SYSTEM, "[E_SYSTEM] A system error has occurred. _SplitPanel instance is null.");
99
100         __pSplitPanelModel->SetDividerStyle(splitPanelDividerStyle);
101
102         r = LoadBitmap(splitPanelDividerDirection);
103         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to load bitmap.", GetErrorMessage(r));
104
105         AdjustDividerRectangle();
106
107         __controlAnimatorAnimationInterpolator = ANIMATION_INTERPOLATOR_EASE_IN;
108         __visualElementAnimationInterpolator = L"EaseIn";
109
110         return E_SUCCESS;
111
112 CATCH:
113         delete pModel;
114         pModel = null;
115
116         return r;
117 }
118
119 bool
120 _SplitPanelPresenter::CheckDividerTouchRegion(int positionX, int positionY)
121 {
122         int dividerPosition = __pSplitPanel->GetDividerPosition();
123
124         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
125         {
126                 Bitmap* pThumbBitmap = __pDividerThumbBitmap;
127                 if ((positionX >= dividerPosition)
128                         && (positionX <= dividerPosition + pThumbBitmap->GetWidth()))
129                 {
130                         return true;
131                 }
132         }
133         else
134         {
135                 Bitmap* pThumbBitmap = __pDividerThumbBitmap;
136                 if ((positionY >= dividerPosition)
137                         && (positionY <= dividerPosition + pThumbBitmap->GetHeight()))
138                 {
139                         return true;
140                 }
141         }
142
143         return false;
144 }
145
146 bool
147 _SplitPanelPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
148 {
149         Point point = touchinfo.GetCurrentPosition();
150
151         if (CheckDividerTouchRegion(point.x, point.y) == true)
152         {
153                 __splitPanelDividerPressed = true;
154         }
155
156         Draw();
157
158         return E_SUCCESS;
159 }
160
161 bool
162 _SplitPanelPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
163 {
164         if (__splitPanelDividerPressed == true)
165         {
166                 __splitPanelDividerPressed = false;
167                 Draw();
168         }
169
170         return E_SUCCESS;
171 }
172
173 bool
174 _SplitPanelPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
175 {
176         if (__pSplitPanel != &source || __splitPanelDividerPressed == false )
177         {
178                 return false;
179         }
180
181         if (__pSplitPanelModel->GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_FIXED)
182         {
183                 return false;
184         }
185
186         Point point = touchinfo.GetCurrentPosition();
187
188         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
189         {
190                 // Min, Max Position Check.
191                 if ((__pSplitPanel->GetMinimumDividerPosition() > point.x)
192                         || (__pSplitPanel->GetMaximumDividerPosition() < point.x))
193                 {
194                         return false;
195                 }
196
197                 Bitmap* pThumbBitmap = __pDividerThumbBitmap;
198
199                 if (point.x <= __pSplitPanel->GetBounds().width - pThumbBitmap->GetWidth())
200                 {
201                         __pSplitPanel->SetDividerPosition(point.x);
202                 }
203         }
204         else
205         {
206                 // Min, Max Position Check.
207                 if ((__pSplitPanel->GetMinimumDividerPosition() > point.y)
208                         || (__pSplitPanel->GetMaximumDividerPosition() < point.y))
209                 {
210                         return false;
211                 }
212
213                 Bitmap* pThumbBitmap = __pDividerThumbBitmap;
214
215                 if (point.y <= __pSplitPanel->GetBounds().height - pThumbBitmap->GetHeight())
216                 {
217                         __pSplitPanel->SetDividerPosition(point.y);
218                 }
219         }
220
221         __pSplitPanel->SendSplitPanelEvent(_SPLIT_PANEL_EVENT_DIVIDER_POSITION_CHANGE);
222
223         Draw();
224
225         return true;
226 }
227
228 bool
229 _SplitPanelPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
230 {
231         if (__splitPanelDividerPressed == true)
232         {
233                 __splitPanelDividerPressed = false;
234                 Draw();
235         }
236
237         return E_SUCCESS;
238 }
239
240 bool
241 _SplitPanelPresenter::OnTapGestureDetected(_TouchTapGestureDetector& gesture)
242 {
243         if (__pSplitPanelModel->GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_FIXED)
244         {
245                 return false;
246         }
247
248         __pSplitPanel->SendSplitPanelEvent(_SPLIT_PANEL_EVENT_DIVIDER_DOUBLE_PRESSED);
249
250         return true;
251 }
252
253 bool
254 _SplitPanelPresenter::OnTapGestureCanceled(_TouchTapGestureDetector& gesture)
255 {
256         return false;
257 }
258
259 result
260 _SplitPanelPresenter::SetDividerStyle(SplitPanelDividerStyle splitPanelDividerStyle)
261 {
262         __pSplitPanelModel->SetDividerStyle(splitPanelDividerStyle);
263
264         return E_SUCCESS;
265 }
266
267 SplitPanelDividerStyle
268 _SplitPanelPresenter::GetDividerStyle(void) const
269 {
270         return __pSplitPanelModel->GetDividerStyle();
271 }
272
273 Rectangle
274 _SplitPanelPresenter::GetDividerRectangle(void) const
275 {
276         return __dividerRectangle;
277 }
278
279 result
280 _SplitPanelPresenter::MaximizePane(SplitPanelPaneOrder paneOrder)
281 {
282         result r = E_SUCCESS;
283
284         if (IsPaneMaximized(paneOrder))
285         {
286                 return E_SUCCESS;
287         }
288         else if (GetAnimationStatus() == ANIMATOR_STATUS_PLAYING)
289         {
290                 AnimationTransaction::Stop(__transactionIdMaximize);
291                 AnimationTransaction::Stop(__transactionIdRestore);
292         }
293
294         RecalcSplitPanel();
295
296         ChangePaneOrder(paneOrder);
297
298         AnimationTransaction::Begin(__transactionIdMaximize);
299
300         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
301         {
302                 if (paneOrder == SPLIT_PANEL_PANE_ORDER_FIRST)
303                 {
304                         r = AnimateDivider(_SPLIT_PANEL_ANIMATION_RIGHT);
305                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
306
307                         r = AnimatePane(_SPLIT_PANEL_ANIMATION_RIGHT);
308                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
309                 }
310                 else
311                 {
312                         r = AnimateDivider(_SPLIT_PANEL_ANIMATION_LEFT);
313                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
314
315                         r = AnimatePane(_SPLIT_PANEL_ANIMATION_LEFT);
316                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
317                 }
318         }
319         else
320         {
321                 if (paneOrder == SPLIT_PANEL_PANE_ORDER_FIRST)
322                 {
323                         r = AnimateDivider(_SPLIT_PANEL_ANIMATION_BOTTOM);
324                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
325
326                         r = AnimatePane(_SPLIT_PANEL_ANIMATION_BOTTOM);
327                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
328                 }
329                 else
330                 {
331                         r = AnimateDivider(_SPLIT_PANEL_ANIMATION_TOP);
332                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
333
334                         r = AnimatePane(_SPLIT_PANEL_ANIMATION_TOP);
335                         SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
336                 }
337         }
338
339         AnimationTransaction::Commit();
340
341         __pSplitPanelModel->SetPaneMaximumState(true);
342         __pSplitPanelModel->SetMaximizedPaneOrder(paneOrder);
343
344         return E_SUCCESS;
345
346 CATCH:
347         AnimationTransaction::Discard();
348
349         return r;
350 }
351
352 bool
353 _SplitPanelPresenter::IsPaneMaximized(SplitPanelPaneOrder paneOrder) const
354 {
355         if ((__pSplitPanelModel->GetPaneMaximumState() == true)
356                 && (__pSplitPanelModel->GetMaximizedPaneOrder() == paneOrder))
357         {
358                 return true;
359         }
360
361         return false;
362 }
363
364 result
365 _SplitPanelPresenter::RestorePane(void)
366 {
367         result r = E_SUCCESS;
368
369         if (__pSplitPanelModel->GetPaneMaximumState() == false)
370         {
371                 return E_SUCCESS;
372         }
373         else if (GetAnimationStatus() == ANIMATOR_STATUS_PLAYING)
374         {
375                 AnimationTransaction::Stop(__transactionIdMaximize);
376                 AnimationTransaction::Stop(__transactionIdRestore);
377         }
378
379         RecalcSplitPanel();
380
381         AnimationTransaction::Begin(__transactionIdRestore);
382
383         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
384         {
385                 r = AnimateDivider(_SPLIT_PANEL_ANIMATION_RESTORE_VERTICAL);
386                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
387
388                 r = AnimatePane(_SPLIT_PANEL_ANIMATION_RESTORE_VERTICAL);
389                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
390         }
391         else
392         {
393                 r = AnimateDivider(_SPLIT_PANEL_ANIMATION_RESTORE_HORIZONTAL);
394                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
395
396                 r = AnimatePane(_SPLIT_PANEL_ANIMATION_RESTORE_HORIZONTAL);
397                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Propagating.", GetErrorMessage(r));
398         }
399
400         AnimationTransaction::Commit();
401
402         __pSplitPanelModel->SetPaneMaximumState(false);
403
404         return E_SUCCESS;
405
406 CATCH:
407         AnimationTransaction::Discard();
408
409         return r;
410 }
411
412 result
413 _SplitPanelPresenter::Draw(void)
414 {
415         if (__pSplitPanelModel->GetPaneMaximumState() == false && GetAnimationStatus() == ANIMATOR_STATUS_STOPPED)
416         {
417                 //adjust divider rectangle
418                 AdjustDividerRectangle();
419
420                 Canvas* pCanvas = __pSplitPanel->GetDividerVisualElement()->GetCanvasN();
421                 SysTryReturnResult(NID_UI_CTRL, pCanvas != null, GetLastResult(), "Propagating.");
422
423                 pCanvas->Clear();
424
425                 //resize pane
426                 SetPaneBounds();
427
428                 Rectangle dividerBounds = __dividerRectangle;
429                 dividerBounds.x = 0;
430                 dividerBounds.y = 0;
431
432                 if (__splitPanelDividerPressed == true)
433                 {
434                         pCanvas->DrawNinePatchedBitmap(dividerBounds, *__pDividerPressedBackgroundBitmap);
435                 }
436                 else
437                 {
438                         pCanvas->DrawNinePatchedBitmap(dividerBounds, *__pDividerBackgroundBitmap);
439                 }
440
441                 //draw divider
442                 pCanvas->DrawNinePatchedBitmap(dividerBounds, *__pDividerBackgroundEffectBitmap);
443
444                 //draw divider thumb
445                 if (__pSplitPanelModel->GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_MOVABLE)
446                 {
447                         Rectangle dividerThumbBounds = __dividerThumbRectangle;
448                         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
449                         {
450                                 dividerThumbBounds.x = 0;
451                         }
452                         else
453                         {
454                                 dividerThumbBounds.y = 0;
455                         }
456
457                         pCanvas->DrawBitmap(dividerThumbBounds, *__pDividerThumbBitmap);
458                 }
459
460                 delete pCanvas;
461         }
462
463         return E_SUCCESS;
464 }
465
466 result
467 _SplitPanelPresenter::LoadBitmap(SplitPanelDividerDirection splitPanelDividerDirection)
468 {
469         result r = E_SUCCESS;
470         Bitmap *pDividerBackgroundBitmap = null;
471
472         // Modified - Changeable Color / Resource ( Fixed Style )
473         r = GET_BITMAP_CONFIG_N(SPLITPANEL::DIVIDER_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, pDividerBackgroundBitmap);
474         SysTryReturnResult(NID_UI_CTRL, (r == E_SUCCESS), r, "Failed to load bitmap.");
475
476         if (splitPanelDividerDirection == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
477         {
478                 r = GET_BITMAP_CONFIG_N(SPLITPANEL::VERTICAL_DIVIDER_BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pDividerBackgroundEffectBitmap);
479                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Failed to load bitmap.", GetErrorMessage(r));
480                 r = GET_BITMAP_CONFIG_N(SPLITPANEL::VERTICAL_DIVIDER_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pDividerThumbBitmap);
481                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Failed to load bitmap.", GetErrorMessage(r));
482         }
483         else
484         {
485                 r = GET_BITMAP_CONFIG_N(SPLITPANEL::HORIZONTAL_DIVIDER_BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pDividerBackgroundEffectBitmap);
486                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Failed to load bitmap.", GetErrorMessage(r));
487                 r = GET_BITMAP_CONFIG_N(SPLITPANEL::HORIZONTAL_DIVIDER_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pDividerThumbBitmap);
488                 SysTryCatch(NID_UI_CTRL, (r == E_SUCCESS), , r, "[%s] Failed to load bitmap.", GetErrorMessage(r));
489         }
490
491         __pDividerPressedBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pDividerBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __dividerPressedBackgroundColor);
492         r = GetLastResult();
493         SysTryCatch(NID_UI_CTRL, (__pDividerPressedBackgroundBitmap != null), , r, "[%s] Failed to get replacement color bitmap.", GetErrorMessage(r));
494
495         __pDividerBackgroundBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pDividerBackgroundBitmap, Color::GetColor(COLOR_ID_MAGENTA), __dividerBackgroundColor);
496         r = GetLastResult();
497         SysTryCatch(NID_UI_CTRL, (__pDividerBackgroundBitmap != null), , r, "[%s] Failed to get replacement color bitmap.", GetErrorMessage(r));
498
499         delete pDividerBackgroundBitmap;
500
501         return r;
502
503 CATCH:
504         delete pDividerBackgroundBitmap;
505         delete __pDividerBackgroundEffectBitmap;
506         delete __pDividerPressedBackgroundBitmap;
507         delete __pDividerThumbBitmap;
508
509         return r;
510 }
511
512 void
513 _SplitPanelPresenter::RecalcSplitPanel(void)
514 {
515         //adjust divider rectangle
516         AdjustDividerRectangle();
517
518         //resize pane
519         SetPaneBounds();
520
521         return;
522 }
523
524 void
525 _SplitPanelPresenter::OnChangeLayout(_ControlOrientation orientation)
526 {
527         AnimationTransaction::Stop(__transactionIdMaximize);
528         AnimationTransaction::Stop(__transactionIdRestore);
529
530         return;
531 }
532
533 void
534 _SplitPanelPresenter::OnBoundsChanged(void)
535 {
536         RecalcSplitPanel();
537         return;
538 }
539
540 result
541 _SplitPanelPresenter::SetModel(const _SplitPanelModel& splitPanelModel)
542 {
543         __pSplitPanelModel = const_cast<_SplitPanelModel*>(&splitPanelModel);
544
545         return E_SUCCESS;
546 }
547
548 result
549 _SplitPanelPresenter::SetPaneBounds(void)
550 {
551         result r = E_SUCCESS;
552         Rectangle firstPaneBounds(0, 0, 0, 0);
553         Rectangle secondPaneBounds(0, 0, 0, 0);
554
555         Rectangle clientBounds = __pSplitPanel->GetBounds();
556
557         _Control* pFirstPane = __pSplitPanel->GetPane(SPLIT_PANEL_PANE_ORDER_FIRST);
558
559         _Control* pSecondPane = __pSplitPanel->GetPane(SPLIT_PANEL_PANE_ORDER_SECOND);
560
561         clientBounds.x = clientBounds.y = 0;
562
563         if (IsPaneMaximized(SPLIT_PANEL_PANE_ORDER_FIRST))
564         {
565                 firstPaneBounds = clientBounds;
566
567                 if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
568                 {
569                         secondPaneBounds = Rectangle(clientBounds.width + __dividerRectangle.width, 0, clientBounds.width - __dividerRectangle.x - __dividerRectangle.width,clientBounds.height);
570                 }
571                 else
572                 {
573                         secondPaneBounds = Rectangle(0, clientBounds.height + __dividerRectangle.height, clientBounds.width, clientBounds.height - __dividerRectangle.y - __dividerRectangle.height);
574                 }
575         }
576         else if (IsPaneMaximized(SPLIT_PANEL_PANE_ORDER_SECOND))
577         {
578                 secondPaneBounds = clientBounds;
579
580                 if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
581                 {
582                         firstPaneBounds = Rectangle(clientBounds.x -__dividerRectangle.x - __dividerRectangle.width, 0, __dividerRectangle.x, clientBounds.height);
583                 }
584                 else
585                 {
586                         firstPaneBounds = Rectangle(0, clientBounds.y -__dividerRectangle.y - __dividerRectangle.height, clientBounds.width, __dividerRectangle.y);
587                 }
588         }
589         else
590         {
591                 if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
592                 {
593                         firstPaneBounds = Rectangle(0, 0, __dividerRectangle.x, clientBounds.height);
594                         secondPaneBounds = Rectangle(__dividerRectangle.x + __dividerRectangle.width, 0, clientBounds.width - __dividerRectangle.x - __dividerRectangle.width,clientBounds.height);
595                 }
596                 else
597                 {
598                         firstPaneBounds  = Rectangle(0, 0, clientBounds.width, __dividerRectangle.y);
599                         secondPaneBounds = Rectangle(0, __dividerRectangle.y + __dividerRectangle.height, clientBounds.width, clientBounds.height - __dividerRectangle.y - __dividerRectangle.height);
600                 }
601         }
602
603         bool movable = true;
604         bool resizable = true;
605
606         //set Pane bounds
607         if (pFirstPane != null)
608         {
609                 movable = pFirstPane->IsMovable();
610                 resizable = pFirstPane->IsResizable();
611
612                 pFirstPane->SetMovable(true);
613                 pFirstPane->SetResizable(true);
614
615                 r = pFirstPane->SetBounds(firstPaneBounds);
616                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
617
618                 pFirstPane->SetMovable(movable);
619                 pFirstPane->SetResizable(resizable);
620         }
621
622         if (pSecondPane != null)
623         {
624                 movable = pSecondPane->IsMovable();
625                 resizable = pSecondPane->IsResizable();
626
627                 pSecondPane->SetMovable(true);
628                 pSecondPane->SetResizable(true);
629
630                 r = pSecondPane->SetBounds(secondPaneBounds);
631                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
632
633                 pSecondPane->SetMovable(movable);
634                 pSecondPane->SetResizable(resizable);
635         }
636
637         if ((pFirstPane != null) && (pSecondPane != null))
638         {
639                 if (__setFirstDividerPositionChangeEvent == true)
640                 {
641                         __setFirstDividerPositionChangeEvent = false;
642                         __pSplitPanel->SendSplitPanelEvent(_SPLIT_PANEL_EVENT_DIVIDER_POSITION_CHANGE);
643                 }
644         }
645
646         return r;
647 }
648
649 void
650 _SplitPanelPresenter::AdjustDividerRectangle(void)
651 {
652         int dividerPosition = __pSplitPanel->GetDividerPosition();
653         // Check - Divider Postion. ( Screen Size Over / Maximum Divider Position )
654
655         Rectangle clientBounds = __pSplitPanel->GetBounds();
656         int width = 0;
657         int height = 0;
658
659         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
660
661         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
662         {
663                 Bitmap* pThumbBitmap = __pDividerThumbBitmap;
664
665                 if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_MOVABLE)
666                 {
667                         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, width);
668                 }
669                 else
670                 {
671                         GET_SHAPE_CONFIG(SPLITPANEL::FIXED_DIVIDER_THICKNESS, orientation, width);
672                 }
673
674                 height = clientBounds.height;
675
676                 if (height > 0)
677                 {
678                         __dividerRectangle = Rectangle(dividerPosition, 0, width, height);
679                         __dividerThumbRectangle = Rectangle(dividerPosition, ((height - pThumbBitmap->GetHeight()) / 2), pThumbBitmap->GetWidth(), pThumbBitmap->GetHeight());
680                 }
681         }
682         else
683         {
684                 Bitmap* pThumbBitmap = __pDividerThumbBitmap;
685
686                 width = clientBounds.width;
687
688                 if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_MOVABLE)
689                 {
690                         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, height);
691                 }
692                 else
693                 {
694                         GET_SHAPE_CONFIG(SPLITPANEL::FIXED_DIVIDER_THICKNESS, orientation, height);
695                 }
696
697                 if (width > 0)
698                 {
699                         __dividerRectangle = Rectangle(0, dividerPosition, width, height);
700                         __dividerThumbRectangle = Rectangle(((width - pThumbBitmap->GetWidth()) / 2), dividerPosition, pThumbBitmap->GetWidth(), pThumbBitmap->GetHeight());
701                 }
702         }
703
704         __pSplitPanel->SetDividerVisualElementBounds(__dividerRectangle);
705 }
706
707 void
708 _SplitPanelPresenter::ChangePaneOrder(SplitPanelPaneOrder paneOrder)
709 {
710         result r = E_SUCCESS;
711
712         if (paneOrder == SPLIT_PANEL_PANE_ORDER_FIRST)
713         {
714                 _Control* pFirstPane = __pSplitPanel->GetPane(SPLIT_PANEL_PANE_ORDER_FIRST);
715                 SysTryReturnVoidResult(NID_UI_CTRL, pFirstPane != null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
716
717                 r = __pSplitPanel->DetachChild(*pFirstPane);
718                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
719
720                 r = __pSplitPanel->AttachChild(*pFirstPane);
721                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
722         }
723         else
724         {
725                 _Control* pSecondPane = __pSplitPanel->GetPane(SPLIT_PANEL_PANE_ORDER_SECOND);
726                 SysTryReturnVoidResult(NID_UI_CTRL, pSecondPane != null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(r));
727
728                 r = __pSplitPanel->DetachChild(*pSecondPane);
729                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
730
731                 r = __pSplitPanel->AttachChild(*pSecondPane);
732                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
733         }
734
735         return;
736 }
737
738 result
739 _SplitPanelPresenter::AnimateDivider(int destination)
740 {
741         result r = E_SUCCESS;
742
743         FloatRectangle dividerBoundsStartF(0.0f, 0.0f, 0.0f, 0.0f);
744         FloatRectangle dividerBoundsEndF(0.0f, 0.0f, 0.0f, 0.0f);
745
746         Control* pFirstPanelControl = GetPaneControl(SPLIT_PANEL_PANE_ORDER_FIRST);
747         r = GetLastResult();
748         SysTryReturnResult(NID_UI_CTRL, pFirstPanelControl != null, r, "Propagating.");
749
750         VisualElement* pVisualElementDivider = __pSplitPanel->GetDividerVisualElement();
751         r = GetLastResult();
752         SysTryReturnResult(NID_UI_CTRL, pVisualElementDivider != null, r, "Propagating.");
753
754         pVisualElementDivider->RemoveAllAnimations();
755         r = GetLastResult();
756         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
757
758         FloatRectangle dividerBoundsF = pVisualElementDivider->GetBounds();
759         Rectangle clientBounds = __pSplitPanel->GetBounds();
760         Rectangle firstPaneBounds =  pFirstPanelControl->GetBounds();
761
762         const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName(__visualElementAnimationInterpolator);
763         r = GetLastResult();
764         SysTryReturnResult(NID_UI_CTRL, pTimingFunction != null, r, "Propagating.");
765
766         VisualElementPropertyAnimation* pAnimationDivider = new (std::nothrow) VisualElementPropertyAnimation();
767         SysTryReturnResult(NID_UI_CTRL, pAnimationDivider != null, E_OUT_OF_MEMORY, " Memory allocation failed.")
768
769         r = pAnimationDivider->SetPropertyName(L"bounds");
770         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Propagating.");
771
772         r = pAnimationDivider->SetDuration(ANIMATION_DURATION);
773         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Propagating.");
774
775         pAnimationDivider->SetTimingFunction(pTimingFunction);
776         r = GetLastResult();
777         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Propagating.");
778
779         dividerBoundsF = pVisualElementDivider->GetBounds();
780         dividerBoundsStartF = dividerBoundsF;
781
782         clientBounds.x = clientBounds.y = 0;
783
784         switch (destination)
785         {
786         case _SPLIT_PANEL_ANIMATION_RIGHT:
787                 {
788                         dividerBoundsStartF.x = firstPaneBounds.x + firstPaneBounds.width;
789
790                         dividerBoundsEndF = dividerBoundsF;
791                         dividerBoundsEndF.x = (float)clientBounds.width;
792                 }
793                 break;
794         case _SPLIT_PANEL_ANIMATION_LEFT:
795                 {
796                         dividerBoundsStartF.x = firstPaneBounds.x + firstPaneBounds.width;
797
798                         dividerBoundsEndF = dividerBoundsF;
799                         dividerBoundsEndF.x = (float)clientBounds.x - dividerBoundsF.width;
800                 }
801                 break;
802         case _SPLIT_PANEL_ANIMATION_TOP:
803                 {
804                         dividerBoundsStartF.y = firstPaneBounds.y + firstPaneBounds.height;
805
806                         dividerBoundsEndF = dividerBoundsF;
807                         dividerBoundsEndF.y = (float)clientBounds.y - dividerBoundsF.height;
808                 }
809                 break;
810         case _SPLIT_PANEL_ANIMATION_BOTTOM:
811                 {
812                         dividerBoundsStartF.y = firstPaneBounds.y + firstPaneBounds.height;
813
814                         dividerBoundsEndF = dividerBoundsF;
815                         dividerBoundsEndF.y = (float)clientBounds.height;
816                 }
817                 break;
818         case _SPLIT_PANEL_ANIMATION_RESTORE_HORIZONTAL:
819                 {
820                         dividerBoundsF = FloatRectangle((float)__dividerRectangle.x, (float)__dividerRectangle.y,
821                                                                                         (float)__dividerRectangle.width, (float)__dividerRectangle.height);
822
823                         dividerBoundsStartF = dividerBoundsF;
824                         dividerBoundsEndF = dividerBoundsF;
825
826                         if (__pSplitPanelModel->GetMaximizedPaneOrder() == SPLIT_PANEL_PANE_ORDER_FIRST)
827                         {
828                                 dividerBoundsStartF.y = (float)clientBounds.height;
829                         }
830                         else
831                         {
832                                 dividerBoundsStartF.y = (float)clientBounds.y - dividerBoundsF.height;
833                         }
834                 }
835                 break;
836         case _SPLIT_PANEL_ANIMATION_RESTORE_VERTICAL:
837                 {
838                         dividerBoundsF = FloatRectangle((float)__dividerRectangle.x, (float)__dividerRectangle.y,
839                                                                                         (float)__dividerRectangle.width, (float)__dividerRectangle.height);
840
841                         dividerBoundsStartF = dividerBoundsF;
842                         dividerBoundsEndF = dividerBoundsF;
843
844                         if (__pSplitPanelModel->GetMaximizedPaneOrder() == SPLIT_PANEL_PANE_ORDER_FIRST)
845                         {
846                                 dividerBoundsStartF.x = (float)clientBounds.width;
847                         }
848                         else
849                         {
850                                 dividerBoundsStartF.x = (float)clientBounds.x - dividerBoundsF.width;
851                         }
852                 }
853                 break;
854         }
855
856         r = pAnimationDivider->SetStartValue(dividerBoundsStartF);
857         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Propagating.");
858
859         r = pAnimationDivider->SetEndValue(dividerBoundsEndF);
860         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Propagating.");
861
862         pVisualElementDivider->AddAnimation(L"Bounds", *pAnimationDivider);
863         r = GetLastResult();
864         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "Propagating.");
865
866 CATCH:
867
868         delete pAnimationDivider;
869         return r;
870
871 }
872
873 result
874 _SplitPanelPresenter::AnimatePane(int destination)
875 {
876         result r = E_SUCCESS;
877
878         Control* pFirstPanelControl = GetPaneControl(SPLIT_PANEL_PANE_ORDER_FIRST);
879         r = GetLastResult();
880         SysTryReturnResult(NID_UI_CTRL, pFirstPanelControl != null, r, "Propagating.");
881
882         Control* pSecondPanelControl = GetPaneControl(SPLIT_PANEL_PANE_ORDER_SECOND);
883         r = GetLastResult();
884         SysTryReturnResult(NID_UI_CTRL, pSecondPanelControl != null, r, "Propagating.");
885
886         ControlAnimator* pControlAnimatorFirstPane = pFirstPanelControl->GetControlAnimator();
887         r = GetLastResult();
888         SysTryReturnResult(NID_UI_CTRL, pControlAnimatorFirstPane != null, r, "Propagating.");
889
890         ControlAnimator* pControlAnimatorSecondPane = pSecondPanelControl->GetControlAnimator();
891         r = GetLastResult();
892         SysTryReturnResult(NID_UI_CTRL, pControlAnimatorSecondPane != null, r, "Propagating.");
893
894         Rectangle clientBounds = __pSplitPanel->GetBounds();
895         Rectangle firstPaneBounds = pFirstPanelControl->GetBounds();
896         Rectangle secondPaneBounds = pSecondPanelControl->GetBounds();
897
898         FloatAnimation animationHidePane(ANIMATION_ALPHA_SHOW, ANIMATION_ALPHA_HIDE, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
899         FloatAnimation animationShowPane(ANIMATION_ALPHA_HIDE, ANIMATION_ALPHA_SHOW, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
900
901         clientBounds.x = clientBounds.y = 0;
902
903         switch (destination)
904         {
905         case _SPLIT_PANEL_ANIMATION_RIGHT:
906                 {
907                         Rectangle secondPaneEndBounds = secondPaneBounds;
908                         secondPaneEndBounds.x = clientBounds.x + clientBounds.width + __dividerRectangle.width;
909
910                         RectangleAnimation animationMaximizeFirstPane = RectangleAnimation(firstPaneBounds, clientBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
911                         RectangleAnimation animationMinimizeSecondPane = RectangleAnimation(secondPaneBounds, secondPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
912
913                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMaximizeFirstPane);
914                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
915
916                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationMaximizeFirstPane);
917                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
918
919                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMinimizeSecondPane);
920                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
921
922                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationHidePane);
923                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
924
925                         if (pFirstPanelControl->GetShowState() == false)
926                         {
927                                 r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
928                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
929                         }
930                 }
931                 break;
932         case _SPLIT_PANEL_ANIMATION_LEFT:
933                 {
934                         Rectangle firstPaneEndBounds = firstPaneBounds;
935                         firstPaneEndBounds.x = clientBounds.x - firstPaneBounds.width - __dividerRectangle.width;
936
937                         RectangleAnimation animationMaximizeSecondPane = RectangleAnimation(secondPaneBounds, clientBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
938                         RectangleAnimation animationMinimizeFirstPane = RectangleAnimation(firstPaneBounds, firstPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
939
940                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMaximizeSecondPane);
941                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
942
943                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationMaximizeSecondPane);
944                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
945
946                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMinimizeFirstPane);
947                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
948
949                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationHidePane);
950                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
951
952                         if (pSecondPanelControl->GetShowState() == false)
953                         {
954                                 r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
955                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
956                         }
957                 }
958                 break;
959         case _SPLIT_PANEL_ANIMATION_TOP:
960                 {
961                         Rectangle firstPaneEndBounds = firstPaneBounds;
962                         firstPaneEndBounds.y = clientBounds.y - firstPaneBounds.height - __dividerRectangle.height;
963
964                         RectangleAnimation animationMaximizeSecondPane = RectangleAnimation(secondPaneBounds, clientBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
965                         RectangleAnimation animationMinimizeFirstPane = RectangleAnimation(firstPaneBounds, firstPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
966
967                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMaximizeSecondPane);
968                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
969
970                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationMaximizeSecondPane);
971                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
972
973                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMinimizeFirstPane);
974                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
975
976                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationHidePane);
977                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
978
979                         if (pSecondPanelControl->GetShowState() == false)
980                         {
981                                 r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
982                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
983                         }
984                 }
985                 break;
986         case _SPLIT_PANEL_ANIMATION_BOTTOM:
987                 {
988                         Rectangle secondPaneEndBounds = secondPaneBounds;
989                         secondPaneEndBounds.y = clientBounds.y + clientBounds.height + __dividerRectangle.height;
990
991                         RectangleAnimation animationMaximizeFirstPane = RectangleAnimation(firstPaneBounds, clientBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
992                         RectangleAnimation animationMinimizeSecondPane = RectangleAnimation(secondPaneBounds, secondPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
993
994                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMaximizeFirstPane);
995                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
996
997                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationMaximizeFirstPane);
998                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
999
1000                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationMinimizeSecondPane);
1001                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1002
1003                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationHidePane);
1004                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1005
1006                         if (pFirstPanelControl->GetShowState() == false)
1007                         {
1008                                 r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
1009                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1010                         }
1011                 }
1012                 break;
1013         case _SPLIT_PANEL_ANIMATION_RESTORE_HORIZONTAL:
1014                 {
1015                         Rectangle firstPaneEndBounds = GetRestorePaneBounds(SPLIT_PANEL_PANE_ORDER_FIRST);
1016                         Rectangle secondPaneEndBounds = GetRestorePaneBounds(SPLIT_PANEL_PANE_ORDER_SECOND);
1017
1018                         RectangleAnimation animationRestoreFirstPane = RectangleAnimation(firstPaneBounds, firstPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
1019                         RectangleAnimation animationRestoreSecondPane = RectangleAnimation(secondPaneBounds, secondPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
1020
1021                         // Restore Pane 1
1022                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationRestoreFirstPane);
1023                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1024
1025                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationRestoreFirstPane);
1026                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1027
1028                         // Restore Pane 2
1029                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationRestoreSecondPane);
1030                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1031
1032                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationRestoreSecondPane);
1033                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1034
1035                         if (__pSplitPanelModel->GetMaximizedPaneOrder() == SPLIT_PANEL_PANE_ORDER_FIRST)
1036                         {
1037                                 r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
1038                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1039                         }
1040                         else
1041                         {
1042                                 r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
1043                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1044                         }
1045                 }
1046                 break;
1047         case _SPLIT_PANEL_ANIMATION_RESTORE_VERTICAL:
1048                 {
1049                         Rectangle firstPaneEndBounds = GetRestorePaneBounds(SPLIT_PANEL_PANE_ORDER_FIRST);
1050                         Rectangle secondPaneEndBounds = GetRestorePaneBounds(SPLIT_PANEL_PANE_ORDER_SECOND);
1051
1052                         RectangleAnimation animationRestoreFirstPane = RectangleAnimation(firstPaneBounds, firstPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
1053                         RectangleAnimation animationRestoreSecondPane = RectangleAnimation(secondPaneBounds, secondPaneEndBounds, ANIMATION_DURATION, __controlAnimatorAnimationInterpolator);
1054
1055                         // Restore Pane 1
1056                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationRestoreFirstPane);
1057                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1058
1059                         r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationRestoreFirstPane);
1060                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1061
1062                         // Restore Pane 2
1063                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_SIZE, animationRestoreSecondPane);
1064                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1065
1066                         r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_POSITION, animationRestoreSecondPane);
1067                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1068
1069                         if (__pSplitPanelModel->GetMaximizedPaneOrder() == SPLIT_PANEL_PANE_ORDER_FIRST)
1070                         {
1071                                 r = pControlAnimatorSecondPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
1072                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1073                         }
1074                         else
1075                         {
1076                                 r = pControlAnimatorFirstPane->StartUserAnimation(ANIMATION_TARGET_ALPHA, animationShowPane);
1077                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
1078                         }
1079                 }
1080                 break;
1081         }
1082
1083         return E_SUCCESS;
1084 }
1085
1086 Control*
1087 _SplitPanelPresenter::GetPaneControl(SplitPanelPaneOrder paneOrder)
1088 {
1089         _ControlImpl* pControlImpl = static_cast<_ControlImpl*>(__pSplitPanel->GetUserData());
1090         SysTryReturn(NID_UI_CTRL, pControlImpl != null, null, E_SYSTEM, "[E_SYSTEM] A system error has occurred. _ControlImpl is null.");
1091
1092         _SplitPanelImpl* pSplitPanelImpl = dynamic_cast<_SplitPanelImpl*>(pControlImpl);
1093         SysTryReturn(NID_UI_CTRL, pSplitPanelImpl != null, null, E_SYSTEM, "[E_SYSTEM]A system error has occurred. _SplitPanelImpl is null.");
1094
1095         SplitPanel& splitPanelPublic = pSplitPanelImpl->GetPublic();
1096
1097         Control* pControl = splitPanelPublic.GetPane(paneOrder);
1098         SysTryReturn(NID_UI_CTRL, pControl != null, null, E_SYSTEM, "[%s] Propagating.", GetErrorMessage(GetLastResult()));
1099
1100         return pControl;
1101 }
1102
1103 AnimatorStatus
1104 _SplitPanelPresenter::GetAnimationStatus(void)
1105 {
1106         result r = E_SUCCESS;
1107
1108         Control* pFirstPanelControl = GetPaneControl(SPLIT_PANEL_PANE_ORDER_FIRST);
1109         r = GetLastResult();
1110         SysTryReturn(NID_UI_CTRL, pFirstPanelControl != null, ANIMATOR_STATUS_STOPPED, r, "[%s] Propagating.", GetErrorMessage(r));
1111
1112         Control* pSecondPanelControl = GetPaneControl(SPLIT_PANEL_PANE_ORDER_SECOND);
1113         r = GetLastResult();
1114         SysTryReturn(NID_UI_CTRL, pSecondPanelControl != null, ANIMATOR_STATUS_STOPPED, r, "[%s] Propagating.", GetErrorMessage(r));
1115
1116         ControlAnimator* pControlAnimatorFirstPane = pFirstPanelControl->GetControlAnimator();
1117         r = GetLastResult();
1118         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, ANIMATOR_STATUS_STOPPED, r, "[%s] Propagating.", GetErrorMessage(r));
1119
1120         ControlAnimator* pControlAnimatorSecondPane = pSecondPanelControl->GetControlAnimator();
1121         r = GetLastResult();
1122         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, ANIMATOR_STATUS_STOPPED, r, "[%s] Propagating.", GetErrorMessage(r));
1123
1124         if (pControlAnimatorFirstPane->GetStatus() == ANIMATOR_STATUS_STOPPED && pControlAnimatorSecondPane->GetStatus() == ANIMATOR_STATUS_STOPPED)
1125         {
1126                 return ANIMATOR_STATUS_STOPPED;
1127         }
1128
1129         return ANIMATOR_STATUS_PLAYING;
1130 }
1131
1132 Rectangle
1133 _SplitPanelPresenter::GetRestorePaneBounds(SplitPanelPaneOrder paneOrder)
1134 {
1135         int width = 0;
1136         int height = 0;
1137
1138         Rectangle firstPaneBounds(0, 0, 0, 0);
1139         Rectangle secondPaneBounds(0, 0, 0, 0);
1140
1141         int dividerPosition = __pSplitPanel->GetDividerPosition();
1142
1143         Rectangle clientBounds = __pSplitPanel->GetBounds();
1144
1145         _ControlOrientation orientation = _ControlManager::GetInstance()->GetOrientation();
1146
1147         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
1148         {
1149                 if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_MOVABLE)
1150                 {
1151                         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, width);
1152                 }
1153                 else
1154                 {
1155                         GET_SHAPE_CONFIG(SPLITPANEL::FIXED_DIVIDER_THICKNESS, orientation, width);
1156                 }
1157
1158                 height = clientBounds.height;
1159
1160                 if (height > 0)
1161                 {
1162                         __dividerRectangle = Rectangle(dividerPosition, 0, width, height);
1163                 }
1164         }
1165         else
1166         {
1167                 width = clientBounds.width;
1168
1169                 if (GetDividerStyle() == SPLIT_PANEL_DIVIDER_STYLE_MOVABLE)
1170                 {
1171                         GET_SHAPE_CONFIG(SPLITPANEL::MOVABLE_DIVIDER_THICKNESS, orientation, height);
1172                 }
1173                 else
1174                 {
1175                         GET_SHAPE_CONFIG(SPLITPANEL::FIXED_DIVIDER_THICKNESS, orientation, height);
1176                 }
1177
1178                 if (width > 0)
1179                 {
1180                         __dividerRectangle = Rectangle(0, dividerPosition, width, height);
1181                 }
1182         }
1183
1184         if (__pSplitPanel->GetDividerDirection() == SPLIT_PANEL_DIVIDER_DIRECTION_VERTICAL)
1185         {
1186                 firstPaneBounds = Rectangle(0, 0, __dividerRectangle.x, clientBounds.height);
1187                 secondPaneBounds = Rectangle(__dividerRectangle.x + __dividerRectangle.width, 0, clientBounds.width - __dividerRectangle.x - __dividerRectangle.width,clientBounds.height);
1188         }
1189         else
1190         {
1191                 firstPaneBounds  = Rectangle(0, 0, clientBounds.width, __dividerRectangle.y);
1192                 secondPaneBounds = Rectangle(0, __dividerRectangle.y + __dividerRectangle.height, clientBounds.width, clientBounds.height - __dividerRectangle.y - __dividerRectangle.height);
1193         }
1194
1195         if (paneOrder == SPLIT_PANEL_PANE_ORDER_FIRST)
1196         {
1197                 return firstPaneBounds;
1198         }
1199
1200         return secondPaneBounds;
1201 }
1202
1203 }}} // Tizen::Ui::Controls