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