2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0/
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.
19 * @file FUiCtrl_ScrollPresenter.cpp
20 * @brief This is the implementation file for the %_ScrollPresenter class.
23 #include <FBaseErrors.h>
24 #include <FBaseSysLog.h>
25 #include <FGrpColor.h>
26 #include <FGrpRectangle.h>
27 #include <FGrpCanvas.h>
28 #include <FGrp_BitmapImpl.h>
29 #include <FUiAnimVisualElementAnimation.h>
30 #include <FUiAnimVisualElementAnimationProvider.h>
31 #include "FUi_ResourceManager.h"
32 #include "FUi_UiTouchEvent.h"
34 #include "FUiAnim_TransformMatrix3Df.h"
35 #include "FUiAnim_VisualElement.h"
36 #include "FUiCtrl_ScrollPresenter.h"
37 #include "FUiCtrl_UiScrollEvent.h"
38 #include "FUiCtrl_UiScrollEventArg.h"
40 using namespace Tizen::Base;
41 using namespace Tizen::Base::Collection;
42 using namespace Tizen::Graphics;
43 using namespace Tizen::Ui;
44 using namespace Tizen::Ui::Animations;
48 const float SCROLL_OPACITY_ON = 1.0f;
49 const float SCROLL_OPACITY_DARK_DIM =0.6f;
50 const float SCROLL_OPACITY_LIGHT_DIM = 0.3f;
51 const float SCROLL_OPACITY_OFF = 0.0f;
52 const float SCROLLING_EFFECT_MAX_POSITION = 100.0f;
53 const float SCROLLING_EFFECT_MIN_SCALE_RATE = 0.95f;
56 namespace Tizen { namespace Ui { namespace Controls
60 #define MAX(a, b) ((a) > (b) ? (a) : (b))
61 #define MIN(a, b) ((a) < (b) ? (a) : (b))
64 _ScrollPresenter::_ScrollPresenter(void)
67 , __scrollDirection(SCROLL_DIRECTION_VERTICAL)
68 , __enableFadeEffect(false)
69 , __enableJumpToTop(false)
70 , __enableHandler(false)
71 , __enableScrollingEffect(false)
72 , __enableOverScrollingEffect(false)
73 , __isContextMenuScroll(false)
74 , __parentUsingViewport(true)
77 , __scrollPositionCurr(0.0f)
80 , __scrollVisibility(false)
81 , __scrollingEffectVisibility(false)
82 , __parentBouncingRate(0.0f)
83 , __fadeEffectDuration_ms(5000)
84 , __needUpdateThumb(false)
85 , __needUpdateJumpTopTop(false)
86 , __needUpdateHandler(false)
87 , __needUpdateScrollingEffect(false)
88 , __handlerTouched(false)
89 , __handlerTouchedPosition(0.0f)
90 , __jumpToTopPressed(false)
91 , __pScrollEvent(null)
94 , __pJumpToTopVe(null)
96 , __pFrontScrollingEffectVe(null)
97 , __pReerScrollingEffectVe(null)
98 , __thumbColor(0x00000000)
99 , __jumpToTopColor(0x00000000)
100 , __jumpToTopColorPressed(0x00000000)
101 , __buttonColor(0x00000000)
102 , __buttonColorPressed(0x00000000)
103 , __pThumbBitmap(null)
104 , __pThumbEffectBitmap(null)
105 , __pJumpToTopBitmap(null)
106 , __pJumpToTopPressBitmap(null)
107 , __pJumpToTopEfBitmap(null)
108 , __pButtonBitmap(null)
109 , __pButtonEfBitmap(null)
110 , __pButtonPressBitmap(null)
111 , __pButtonPressEfBitmap(null)
112 , __pHandlerBitmap(null)
113 , __pFrontScrollingEffectBitmap(null)
114 , __pReerScrollingEffectBitmap(null)
115 , __thumbSizeMin(0.0f, 0.0f)
116 , __thumbMargin(0.0f)
117 , __jumpToTopSize(0.0f, 0.0f)
118 , __jumpToTopMarginRight(0.0f)
119 , __jumpToTopMarginTop(0.0f)
120 , __handlerSizeMin(0.0f, 0.0f)
121 , __handlerMarginLeft(0.0f)
122 , __handlerMarginRight(0.0f)
123 , __handlerMarginTop(0.0f)
124 , __handlerMarginBottom(0.0f)
125 , __scrollingEffectWidthLeft(0.0f)
126 , __scrollingEffectWidthRight(0.0f)
127 , __scrollingEffectHeightTop(0.0f)
128 , __scrollingEffectHeightBottom(0.0f)
129 , __beforeBouncingMatrixHash()
133 _ScrollPresenter::~_ScrollPresenter(void)
135 delete __pScrollEvent;
136 __pScrollEvent = null;
138 __beforeBouncingMatrixHash.RemoveAll(true);
140 if (__pThumbVe != null)
142 __pThumbVe->Destroy();
146 if (__pJumpToTopVe != null)
148 __pJumpToTopVe->Destroy();
149 __pJumpToTopVe = null;
152 if (__pHandlerVe != null)
154 __pHandlerVe->Destroy();
158 if (__pFrontScrollingEffectVe != null)
160 __pFrontScrollingEffectVe->RemoveAllAnimations();
161 __pFrontScrollingEffectVe->Destroy();
162 __pFrontScrollingEffectVe = null;
165 if (__pReerScrollingEffectVe != null)
167 __pReerScrollingEffectVe->RemoveAllAnimations();
168 __pReerScrollingEffectVe->Destroy();
169 __pReerScrollingEffectVe = null;
172 if (__pCtrlVe != null)
174 __pCtrlVe->RemoveAllAnimations();
175 __pCtrlVe->SetAnimationProvider(null);
176 __pCtrlVe->Destroy();
180 ReleaseBitmapResources();
184 _ScrollPresenter::CreateScrollPresenterN(_Control& parentCtrl,
186 _ScrollDirection scrollDirection,
187 bool enableFadeEffect,
188 bool enableJumpToTop,
193 float scrollPosition)
195 SysTryReturn(NID_UI_CTRL, ((scrollRange >= viewRange) && (scrollRange != 0)), null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments");
196 SysTryReturn(NID_UI_CTRL, scrollPosition >= 0, null, E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments");
198 _ScrollPresenter* pPresenter = new (std::nothrow) _ScrollPresenter();
199 SysTryReturn(NID_UI_CTRL, pPresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
201 result r = pPresenter->Construct(parentCtrl,
212 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
214 SetLastResult(E_SUCCESS);
224 _ScrollPresenter::SetScrollDirection(_ScrollDirection scrollDirection)
226 if (__scrollDirection == scrollDirection)
231 // load color/shape configuration and bitmap resources
232 result r = LoadResources(scrollDirection, _CONTROL_ORIENTATION_PORTRAIT);
233 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to load resources.");
236 __scrollDirection = scrollDirection;
238 // reset the bounds of scroll control
239 FloatRectangle bounds = GetParentCtrl().GetBoundsF();
240 bounds.SetPosition(0.0f, 0.0f);
241 r = GetControl().SetBounds(bounds);
242 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _Scroll.");
244 // relayout scroll children.
245 r = RelayoutScrollChildren(__scrollDirection);
246 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to relayout scroll chilren");
252 _ScrollPresenter::GetScrollDirection(void) const
254 return __scrollDirection;
258 _ScrollPresenter::SetScrollRange(float viewRange, float scrollRange)
260 SysTryReturn(NID_UI_CTRL, ((scrollRange >= viewRange) && (scrollRange != 0)), E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Invalid arguments");
262 if (__viewRange == viewRange && __scrollRange == scrollRange)
267 __viewRange = viewRange;
268 __scrollRange = scrollRange;
270 result r = RelayoutScrollChildren(__scrollDirection);
271 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to relayout scroll chilren");
277 _ScrollPresenter::GetScrollRange(float* pViewRange, float* pScrollRange) const
279 SysTryReturnVoidResult(NID_UI_CTRL,
280 !((pViewRange == null) && (pScrollRange == null)),
281 E_INVALID_ARG,"[E_INVALID_ARG] Input parameter is invalid.");
283 *pViewRange = __viewRange;
284 *pScrollRange = __scrollRange;
290 _ScrollPresenter::SetScrollPosition(float scrollPosition)
292 result r = E_SUCCESS;
294 if (scrollPosition != __scrollPositionCurr)
297 if (!__enableScrollingEffect)
299 if (scrollPosition < 0.0f)
301 scrollPosition = 0.0f;
303 else if (scrollPosition > (__scrollRange - __viewRange))
305 scrollPosition = (__scrollRange - __viewRange);
308 __scrollPositionCurr = scrollPosition;
310 if (__enableJumpToTop)
312 if ((_FloatCompare(__scrollPositionCurr, 0.0f) || __scrollPositionCurr < 0.0f) && (__pJumpToTopVe->GetOpacity() > 0.0f))
314 __pCtrlVe->SetImplicitAnimationEnabled(true);
315 __pJumpToTopVe->SetImplicitAnimationEnabled(true);
317 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_OFF);
319 __pJumpToTopVe->SetImplicitAnimationEnabled(false);
320 __pCtrlVe->SetImplicitAnimationEnabled(false);
322 else if ((__scrollPositionCurr > 0.0f) && (__pJumpToTopVe->GetOpacity() < 1.0f))
324 __pCtrlVe->SetImplicitAnimationEnabled(true);
325 __pJumpToTopVe->SetImplicitAnimationEnabled(true);
327 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_ON);
329 __pJumpToTopVe->SetImplicitAnimationEnabled(false);
330 __pCtrlVe->SetImplicitAnimationEnabled(false);
332 // else keep up current visibility.
338 FloatPoint handlerPosition = CalculateHandlerPosition(__scrollDirection);
339 FloatRectangle handlerBounds(handlerPosition.x, handlerPosition.y, __pHandlerVe->GetBounds().width, __pHandlerVe->GetBounds().height);
340 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
342 if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
344 if (handlerPosition.x < 0.0f)
346 handlerBounds.x = 0.0f;
348 else if (handlerPosition.x > scrollCtrlBounds.width - handlerBounds.width)
350 handlerBounds.x =scrollCtrlBounds.width - handlerBounds.width;
355 if (handlerPosition.y < 0.0f)
357 handlerBounds.y = 0.0f;
359 else if (handlerPosition.y > scrollCtrlBounds.height - handlerBounds.height)
361 handlerBounds.y = scrollCtrlBounds.height - handlerBounds.height;
365 __pHandlerVe->SetBounds(handlerBounds);
369 FloatPoint thumbPosition = CalculateThumbPosition(__scrollDirection);
370 FloatRectangle thumbBounds(thumbPosition.x, thumbPosition.y, __pThumbVe->GetBounds().width, __pThumbVe->GetBounds().height);
371 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
373 if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
375 if (thumbPosition.x < 0.0f)
377 thumbBounds.x = 0.0f;
379 else if (thumbPosition.x > scrollCtrlBounds.width - thumbBounds.width)
381 thumbBounds.x = scrollCtrlBounds.width - thumbBounds.width;
386 if (thumbPosition.y < 0.0f)
388 thumbBounds.y = 0.0f;
390 else if (thumbPosition.y > scrollCtrlBounds.height - thumbBounds.height)
392 thumbBounds.y = scrollCtrlBounds.height - thumbBounds.height;
396 __pThumbVe->SetBounds(thumbBounds);
399 r = SetScrollingEffect();
400 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Propagating.");
407 _ScrollPresenter::GetScrollPosition(void) const
409 return __scrollPositionCurr;
413 _ScrollPresenter::SetContextMenuScrollType(bool isContextMenu)
415 result r = E_SUCCESS;
416 if (__isContextMenuScroll == isContextMenu)
421 if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
426 __isContextMenuScroll = isContextMenu;
427 __enableJumpToTop = false;
428 __enableHandler = false;
429 __enableScrollingEffect = false;
430 __enableOverScrollingEffect = false;
432 delete __pThumbBitmap;
433 __pThumbBitmap = null;
435 _ControlOrientation orientation = _CONTROL_ORIENTATION_PORTRAIT;
438 r = GET_BITMAP_CONFIG_N(SCROLL::CONTEXTTHUMB_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
439 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
441 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
442 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
444 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
445 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
447 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MARGIN, orientation, __thumbMargin);
448 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
452 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_VERTICAL_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
453 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
455 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
456 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
458 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
459 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
461 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MARGIN, orientation, __thumbMargin);
462 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
465 __pThumbVe->SetBounds(CalculateThumbBounds(__scrollDirection));
466 __needUpdateThumb = true;
467 (GetControl().GetVisualElement())->InvalidateRectangle(null);
472 delete __pThumbBitmap;
473 __pThumbBitmap = null;
479 _ScrollPresenter::EnableFadeEffect(bool enable)
481 __enableFadeEffect = enable;
487 _ScrollPresenter::IsEnabledFadeEffect(void) const
489 return __enableFadeEffect;
493 _ScrollPresenter::IsOnFadeEffect(void) const
495 return (__fadeIn || __fadeOut);
499 _ScrollPresenter::EnableScrollingEffect(bool enable)
501 __enableScrollingEffect = enable;
505 _ScrollPresenter::IsEnabledScrollingEffect(void) const
507 return __enableScrollingEffect;
511 _ScrollPresenter::EnableOverScrollingEffect(bool enable)
513 __enableOverScrollingEffect = enable;
517 _ScrollPresenter::IsEnabledOverScrollingEffect(void) const
519 return __enableOverScrollingEffect;
523 _ScrollPresenter::SetParentUsingViewport(bool useViewPort)
525 __parentUsingViewport = useViewPort;
529 _ScrollPresenter::IsParentUsingViewport(void) const
531 return __parentUsingViewport;
535 _ScrollPresenter::SetScrollVisibility(bool visibility)
537 if (GetScrollVisibility() == visibility)
539 // keep up current visibility.
543 if (__jumpToTopPressed && visibility == false)
545 // ignore visibility off
549 __pCtrlVe->RemoveAllAnimations();
552 if (__enableFadeEffect)
557 __pCtrlVe->SetImplicitAnimationEnabled(true);
560 __pCtrlVe->SetOpacity(SCROLL_OPACITY_ON);
562 if (__enableFadeEffect)
564 __pCtrlVe->SetImplicitAnimationEnabled(false);
574 if (__enableFadeEffect)
579 __pCtrlVe->SetImplicitAnimationEnabled(true);
582 __pCtrlVe->SetOpacity(SCROLL_OPACITY_OFF);
584 if (__enableFadeEffect)
586 __pCtrlVe->SetImplicitAnimationEnabled(false);
595 __scrollVisibility = visibility;
601 _ScrollPresenter::GetScrollVisibility(void) const
603 if (__enableFadeEffect)
605 if (__scrollVisibility)
610 else if (__pCtrlVe->GetOpacity() > SCROLL_OPACITY_OFF)
619 _ScrollPresenter::CancelFadeEffect(void)
624 __scrollVisibility = false;
625 __pCtrlVe->SetOpacity(SCROLL_OPACITY_OFF);
630 __scrollVisibility = true;
631 __pCtrlVe->SetOpacity(SCROLL_OPACITY_ON);
638 _ScrollPresenter::EnableJumpToTop(bool enable)
640 result r = E_SUCCESS;
642 if (__enableJumpToTop != enable)
646 if (__enableFadeEffect)
648 __pCtrlVe->SetImplicitAnimationEnabled(true);
651 r = AttachScrollChild(&__pJumpToTopVe, CalculateJumpToTopBounds(__scrollDirection), true);
652 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to attach the __pJumpToTopVe to _Scroll");
654 if (!(_FloatCompare(__scrollPositionCurr, 0.0f)))
656 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_ON);
660 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_OFF);
663 if (__enableFadeEffect)
665 __pCtrlVe->SetImplicitAnimationEnabled(false);
670 DetachScrollChild(&__pJumpToTopVe, true);
673 __enableJumpToTop = enable;
681 _ScrollPresenter::IsEnabledJumpToTop(void) const
683 return __enableJumpToTop;
687 _ScrollPresenter::EnableHandler(bool enable)
689 result r = E_SUCCESS;
691 if (__enableHandler != enable)
693 if (__enableFadeEffect)
695 __pCtrlVe->SetImplicitAnimationEnabled(true);
700 r = AttachScrollChild(&__pHandlerVe, CalculateHandlerBounds(__scrollDirection), true);
701 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to attach the __pHandlerVe to _Scroll");
703 DetachScrollChild(&__pThumbVe, true);
707 r = AttachScrollChild(&__pThumbVe, CalculateThumbBounds(__scrollDirection), true);
708 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to attach the __pThumbVe to _Scroll");
710 DetachScrollChild(&__pHandlerVe, true);
712 __enableHandler = enable;
714 if (__enableFadeEffect)
716 __pCtrlVe->SetImplicitAnimationEnabled(false);
724 _ScrollPresenter::IsEnabledHandler(void) const
726 return __enableHandler;
730 _ScrollPresenter::SetScrollingEffectVisibility(bool visibility)
732 if (!__enableScrollingEffect)
737 if (__scrollingEffectVisibility == visibility)
739 // keep up current visibility.
743 if (__pFrontScrollingEffectVe == null || __pReerScrollingEffectVe == null)
748 __pFrontScrollingEffectVe->RemoveAllAnimations();
749 __pReerScrollingEffectVe->RemoveAllAnimations();
753 if (__enableFadeEffect)
755 __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(true);
756 __pReerScrollingEffectVe->SetImplicitAnimationEnabled(true);
759 SetScrollingEffectOpacity(SCROLL_OPACITY_DARK_DIM);
761 if (__enableFadeEffect)
763 __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(false);
764 __pReerScrollingEffectVe->SetImplicitAnimationEnabled(false);
769 if (__enableFadeEffect)
771 __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(true);
772 __pReerScrollingEffectVe->SetImplicitAnimationEnabled(true);
775 SetScrollingEffectOpacity(SCROLL_OPACITY_OFF);
777 if (__enableFadeEffect)
779 __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(false);
780 __pReerScrollingEffectVe->SetImplicitAnimationEnabled(false);
784 __scrollingEffectVisibility = visibility;
790 _ScrollPresenter::SetScrollingEffectOpacity(float opacity)
792 __pFrontScrollingEffectVe->SetOpacity(opacity);
793 __pReerScrollingEffectVe->SetOpacity(opacity);
797 _ScrollPresenter::SetScrollingEffectOpacity(_VisualElement& Ve, bool isActive, float ratio)
799 float baseOpacity = (isActive) ? SCROLL_OPACITY_ON : SCROLL_OPACITY_LIGHT_DIM;
800 Ve.SetOpacity(SCROLL_OPACITY_DARK_DIM + ((baseOpacity - SCROLL_OPACITY_DARK_DIM) * ratio));
804 _ScrollPresenter::IsScrollVisible(void) const
806 return (__fadeIn || __fadeOut || __scrollVisibility);
810 _ScrollPresenter::AddScrollEventListener(const Controls::_IScrollEventListener& listener)
812 if (__pScrollEvent == null)
814 __pScrollEvent = new (std::nothrow) _UiScrollEvent();
815 SysTryReturnVoidResult(NID_UI_CTRL, __pScrollEvent, E_OUT_OF_MEMORY,
816 "[E_OUT_OF_MEMORY] Memory allocation failed.");
817 __pScrollEvent->Construct(GetControl());
820 __pScrollEvent->AddListener(listener);
826 _ScrollPresenter::RemoveScrollEventListener(const Controls::_IScrollEventListener& listener)
829 SysTryReturnVoidResult(NID_UI_CTRL, __pScrollEvent, E_SYSTEM, "[E_SYSTEM] __pScrollEvent must not be null.");
831 __pScrollEvent->RemoveListener(listener);
837 _ScrollPresenter::OnParentBoundsChanged(void)
839 FloatRectangle bounds = GetParentCtrl().GetBoundsF();
840 bounds.SetPosition(0.0f, 0.0f);
841 GetControl().SetBounds(bounds);
843 RelayoutScrollChildren(__scrollDirection);
848 _ScrollPresenter::OnDraw(void)
853 DrawScrollingEffect();
859 _ScrollPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
863 ret |= OnTouchPressedHandler(source, touchinfo);
864 ret |= OnTouchPressedJumpToTop(source, touchinfo);
870 _ScrollPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
874 ret |= OnTouchReleasedHandler(source, touchinfo);
875 ret |= OnTouchReleasedJumpToTop(source, touchinfo);
881 _ScrollPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
885 ret |= OnTouchMovedHandler(source, touchinfo);
886 ret |= OnTouchMovedJumpToTop(source, touchinfo);
892 _ScrollPresenter::OnTouchMoveHandled(const _Control& source)
894 if (__jumpToTopPressed)
896 __needUpdateJumpTopTop = true;
897 __jumpToTopPressed = false;
898 (GetControl().GetVisualElement())->InvalidateRectangle(null);
903 _ScrollPresenter::HitTest(const FloatPoint& point)
905 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
907 if (__enableJumpToTop && IsScrollVisible())
909 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
910 jumpToTopBounds.x += ctrlBounds.x;
911 jumpToTopBounds.y += ctrlBounds.y;
912 if (jumpToTopBounds.Contains(point))
914 return HIT_TEST_MATCH;
920 FloatRectangle handlerBounds = __pHandlerVe->GetBounds();
921 handlerBounds.x += ctrlBounds.x;
922 handlerBounds.y += ctrlBounds.y;
923 if (handlerBounds.Contains(point))
925 return HIT_TEST_MATCH;
929 return HIT_TEST_NOWHERE;
932 VisualElementAnimation*
933 _ScrollPresenter::CreateAnimationForProperty(VisualElement& target, const String& property)
935 VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
936 SysTryReturn(NID_UI_CTRL, pAnimation, null, GetLastResult(), "[%s] Failed to create a VisualElementAnimation.", GetErrorMessage(GetLastResult()));
938 pAnimation->SetVisualElementAnimationStatusEventListener(this);
939 SetLastResult(E_SUCCESS);
945 _ScrollPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
951 _ScrollPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
957 _ScrollPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
959 if (__pCtrlVe == (static_cast <_VisualElement*>(&target)))
969 _ScrollPresenter::Construct(_Control& parentCtrl,
971 _ScrollDirection scrollDirection,
972 bool enableFadeEffect,
973 bool enableJumpToTop,
978 float scrollPosition)
980 result r = E_SUCCESS;
982 // load color/shape configuration and bitmap resources
983 r = LoadResources(scrollDirection, _CONTROL_ORIENTATION_PORTRAIT);
984 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to load resources.");
987 SetParentCtrl(parentCtrl);
988 SetControl(scrollCtrl);
989 __scrollDirection = scrollDirection;
990 __enableFadeEffect = enableFadeEffect;
991 __enableJumpToTop = enableJumpToTop;
992 __enableHandler = enableHandler;
993 __viewRange = viewRange;
994 __scrollRange = scrollRange;
995 __scrollPositionCurr = scrollPosition;
997 _VisualElement* pVe = null;
999 // initialize the scroll control
1000 FloatRectangle bounds = GetParentCtrl().GetBoundsF();
1001 bounds.SetPosition(0.0f, 0.0f);
1002 GetControl().SetBounds(bounds);
1003 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the bounds of _Scroll.", GetErrorMessage(r));
1005 scrollCtrl.SetBackgroundColor(Color(0, 0, 0, 0));
1007 // initialize visual elements
1008 pVe = scrollCtrl.GetVisualElement();
1009 SysTryCatch(NID_UI_CTRL, pVe, , GetLastResult(), "[%s] Failed to get VisualElement of the _Scroll.", GetErrorMessage(GetLastResult()));
1011 __pCtrlVe = new (std::nothrow) _VisualElement();
1012 SysTryReturnResult(NID_UI_CTRL, __pCtrlVe != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
1014 r = __pCtrlVe->Construct();
1015 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct Visual Element.", GetErrorMessage(r));
1017 r = __pCtrlVe->SetSurfaceOpaque(false);
1018 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1020 __pCtrlVe->SetImplicitAnimationEnabled(false);
1022 r = pVe->AttachChild(*__pCtrlVe);
1023 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
1025 __pCtrlVe->SetBounds(CalculateScrollCtrlBounds(scrollDirection));
1026 __pCtrlVe->SetAnimationProvider(this);
1027 __pCtrlVe->SetShowState(true);
1031 __pCtrlVe->SetOpacity(SCROLL_OPACITY_ON);
1035 __pCtrlVe->SetOpacity(SCROLL_OPACITY_OFF);
1038 // initialize jumpToTopVe
1039 if (enableJumpToTop)
1041 r = AttachScrollChild(&__pJumpToTopVe, CalculateJumpToTopBounds(scrollDirection), true);
1042 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the __pJumpToTopVe to _Scroll.", GetErrorMessage(r));
1044 if ((scrollDirection != SCROLL_DIRECTION_VERTICAL) || (_FloatCompare(scrollPosition, 0.0f)))
1046 __pJumpToTopVe->SetOpacity(SCROLL_OPACITY_OFF);
1049 __needUpdateJumpTopTop = true;
1052 // initialize thumbVe and handlerVe
1055 r = AttachScrollChild(&__pHandlerVe, CalculateHandlerBounds(scrollDirection), true);
1056 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the __pHandlerVe to _Scroll.", GetErrorMessage(r));
1058 DetachScrollChild(&__pThumbVe, true);
1060 __needUpdateHandler = true;
1064 r = AttachScrollChild(&__pThumbVe, CalculateThumbBounds(scrollDirection), true);
1065 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the __pThumbVe to _Scroll.", GetErrorMessage(r));
1067 DetachScrollChild(&__pHandlerVe, true);
1069 __needUpdateThumb = true;
1072 // initialize scrolling effect front VE
1073 __pFrontScrollingEffectVe = new (std::nothrow) _VisualElement();
1074 SysTryCatch(NID_UI_CTRL, __pFrontScrollingEffectVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1076 r = __pFrontScrollingEffectVe->Construct();
1077 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct pFrontScrollingEffectVe.", GetErrorMessage(r));
1079 r = __pFrontScrollingEffectVe->SetSurfaceOpaque(false);
1080 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1082 __pFrontScrollingEffectVe->SetImplicitAnimationEnabled(false);
1084 r = pVe->AttachChild(*__pFrontScrollingEffectVe);
1085 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
1087 __pFrontScrollingEffectVe->SetBounds(CalculateScrollingEffectFrontBounds(scrollDirection));
1088 __pFrontScrollingEffectVe->SetShowState(true);
1089 __pFrontScrollingEffectVe->SetOpacity(SCROLL_OPACITY_OFF);
1091 // initialize scrolling effect reer VE
1092 __pReerScrollingEffectVe = new (std::nothrow) _VisualElement();
1093 SysTryCatch(NID_UI_CTRL, __pReerScrollingEffectVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1095 r = __pReerScrollingEffectVe->Construct();
1096 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct pReerScrollingEffectVe.", GetErrorMessage(r));
1098 r = __pReerScrollingEffectVe->SetSurfaceOpaque(false);
1099 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1101 __pReerScrollingEffectVe->SetImplicitAnimationEnabled(false);
1103 r = pVe->AttachChild(*__pReerScrollingEffectVe);
1104 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the control VisualElement.", GetErrorMessage(r));
1106 __pReerScrollingEffectVe->SetBounds(CalculateScrollCtrlBounds(scrollDirection));
1107 __pReerScrollingEffectVe->SetShowState(true);
1108 __pReerScrollingEffectVe->SetOpacity(SCROLL_OPACITY_OFF);
1110 __needUpdateScrollingEffect = true;
1112 __scrollVisibility = visibility;
1114 r = __beforeBouncingMatrixHash.Construct();
1115 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1121 __pParentCtrl = null;
1122 __pScrollCtrl = null;
1123 __scrollDirection = SCROLL_DIRECTION_VERTICAL;
1124 __enableFadeEffect = false;
1125 __enableJumpToTop = false;
1126 __enableHandler = false;
1127 __enableScrollingEffect = false;
1128 __enableOverScrollingEffect = false;
1129 __isContextMenuScroll = false;
1132 __scrollRange = 0.0f;
1134 __scrollPositionCurr = 0.0f;
1135 __needUpdateThumb = false;
1136 __needUpdateJumpTopTop = false;
1137 __needUpdateHandler = false;
1138 __needUpdateScrollingEffect = false;
1139 __jumpToTopPressed = false;
1141 __thumbColor = 0x00000000;
1142 __jumpToTopColor = 0x00000000;
1143 __jumpToTopColorPressed = 0x00000000;
1144 __buttonColor= 0x00000000;
1145 __buttonColorPressed = 0x00000000;
1147 ReleaseBitmapResources();
1149 __thumbSizeMin.SetSize(0.0f, 0.0f);
1150 __thumbMargin = 0.0f;
1151 __jumpToTopSize.SetSize(0.0f, 0.0f);
1152 __jumpToTopMarginRight = 0.0f;
1153 __jumpToTopMarginTop = 0.0f;
1154 __handlerSizeMin.SetSize(0.0f, 0.0f);
1155 __handlerMarginLeft = 0.0f;
1156 __handlerMarginRight = 0.0f;
1157 __handlerMarginTop = 0.0f;
1158 __handlerMarginBottom = 0.0f;
1159 __scrollingEffectWidthLeft = 0.0f;
1160 __scrollingEffectWidthRight = 0.0f;
1161 __scrollingEffectHeightTop = 0.0f;
1162 __scrollingEffectHeightBottom = 0.0f;
1164 if (__pThumbVe != null)
1166 __pThumbVe->Destroy();
1170 if (__pJumpToTopVe != null)
1172 __pJumpToTopVe->Destroy();
1173 __pJumpToTopVe = null;
1176 if (__pHandlerVe != null)
1178 __pHandlerVe->Destroy();
1179 __pHandlerVe = null;
1182 if (__pFrontScrollingEffectVe != null)
1184 __pFrontScrollingEffectVe->RemoveAllAnimations();
1185 __pFrontScrollingEffectVe->Destroy();
1186 __pFrontScrollingEffectVe = null;
1189 if (__pReerScrollingEffectVe != null)
1191 __pReerScrollingEffectVe->RemoveAllAnimations();
1192 __pReerScrollingEffectVe->Destroy();
1193 __pReerScrollingEffectVe = null;
1196 if (__pCtrlVe != null)
1198 __pCtrlVe->RemoveAllAnimations();
1199 __pCtrlVe->SetAnimationProvider(null);
1200 __pCtrlVe->Destroy();
1208 _ScrollPresenter::LoadResources(_ScrollDirection scrollDirection, _ControlOrientation orientation)
1210 result r = E_SUCCESS;
1212 r = LoadColorConfig();
1213 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get resource.", GetErrorMessage(r));
1215 r = LoadBitmapResources(scrollDirection);
1216 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get resource.", GetErrorMessage(r));
1218 r = LoadShapeConfig(scrollDirection, orientation);
1219 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to get resource.", GetErrorMessage(r));
1224 __thumbColor = 0x00000000;
1225 __jumpToTopColor = 0x00000000;
1226 __jumpToTopColorPressed = 0x00000000;
1227 __buttonColor= 0x00000000;
1228 __buttonColorPressed = 0x00000000;
1230 ReleaseBitmapResources();
1232 __thumbSizeMin.SetSize(0, 0);
1234 __jumpToTopSize.SetSize(0, 0);
1235 __jumpToTopMarginRight = 0;
1236 __jumpToTopMarginTop = 0;
1237 __handlerSizeMin.SetSize(0, 0);
1238 __handlerMarginLeft = 0;
1239 __handlerMarginRight = 0;
1240 __handlerMarginTop = 0;
1241 __handlerMarginBottom = 0;
1242 __scrollingEffectWidthLeft = 0;
1243 __scrollingEffectWidthRight = 0;
1244 __scrollingEffectHeightTop = 0;
1245 __scrollingEffectHeightBottom = 0;
1252 _ScrollPresenter::LoadColorConfig(void)
1254 result r = E_SUCCESS;
1256 // load color configuration
1257 r = GET_COLOR_CONFIG(SCROLL::THUMB_BG_NORMAL, __thumbColor);
1258 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1260 r = GET_COLOR_CONFIG(SCROLL::JUMP_TO_TOP_NORMAL, __jumpToTopColor);
1261 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1263 r = GET_COLOR_CONFIG(SCROLL::JUMP_TO_TOP_PRESSED, __jumpToTopColorPressed);
1264 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1266 r = GET_COLOR_CONFIG(SCROLL::BUTTON_BG_NORMAL, __buttonColor);
1267 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1269 r = GET_COLOR_CONFIG(SCROLL::BUTTON_BG_PRESSED, __buttonColorPressed);
1270 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1275 __thumbColor = 0x00000000;
1276 __jumpToTopColor = 0x00000000;
1277 __jumpToTopColorPressed = 0x00000000;
1278 __buttonColor= 0x00000000;
1279 __buttonColorPressed = 0x00000000;
1286 _ScrollPresenter::LoadBitmapResources(_ScrollDirection scrollDirection)
1288 result r = E_SUCCESS;
1290 // release allocated resources.
1291 ReleaseBitmapResources();
1293 // load bitmap resources
1294 r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonBitmap);
1295 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1297 r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_NORMAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonEfBitmap);
1298 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1300 r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonPressBitmap);
1301 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1303 r = GET_BITMAP_CONFIG_N(SCROLL::BUTTON_BG_PRESSED_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pButtonPressEfBitmap);
1304 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1306 if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1308 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_HORIZONTAL_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
1309 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1311 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_HORIZONTAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbEffectBitmap);
1312 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1314 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_LEFT_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopBitmap);
1315 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1317 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_LEFT_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopPressBitmap);
1318 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1320 GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_LEFT_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopEfBitmap);
1321 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1323 r = GET_BITMAP_CONFIG_N(SCROLL::HANDLER_HORIZONTAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
1324 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1326 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_LEFT_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pFrontScrollingEffectBitmap);
1327 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1329 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_RIGHT_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pReerScrollingEffectBitmap);
1330 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1332 else // if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
1334 if (__isContextMenuScroll)
1336 r = GET_BITMAP_CONFIG_N(SCROLL::CONTEXTTHUMB_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
1337 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1341 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_VERTICAL_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbBitmap);
1342 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1345 r = GET_BITMAP_CONFIG_N(SCROLL::THUMB_VERTICAL_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pThumbEffectBitmap);
1346 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1348 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_TOP_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopBitmap);
1349 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1351 r = GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_TOP_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopPressBitmap);
1352 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1354 GET_BITMAP_CONFIG_N(SCROLL::JUMP_TO_TOP_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pJumpToTopEfBitmap);
1355 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1357 r = GET_BITMAP_CONFIG_N(SCROLL::HANDLER_VERTICAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pHandlerBitmap);
1358 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1360 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_TOP_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pFrontScrollingEffectBitmap);
1361 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1363 r = GET_BITMAP_CONFIG_N(SCROLL::OVERSCROLLING_BOTTOM_BG, BITMAP_PIXEL_FORMAT_ARGB8888, __pReerScrollingEffectBitmap);
1364 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] failed to load image.");
1370 ReleaseBitmapResources();
1376 _ScrollPresenter::LoadShapeConfig(_ScrollDirection scrollDirection, _ControlOrientation orientation)
1378 result r = E_SUCCESS;
1380 // load shape configuration
1381 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1383 if (__isContextMenuScroll)
1385 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
1386 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1388 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
1389 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1391 r = GET_SHAPE_CONFIG(SCROLL::CONTEXTTHUMB_MARGIN, orientation, __thumbMargin);
1392 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1396 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
1397 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1399 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
1400 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1402 r = GET_SHAPE_CONFIG(SCROLL::VERTICAL_THUMB_MARGIN, orientation, __thumbMargin);
1403 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1408 r = GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MIN_WIDTH, orientation, __thumbSizeMin.width);
1409 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1411 r = GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MIN_HEIGHT, orientation, __thumbSizeMin.height);
1412 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1414 r = GET_SHAPE_CONFIG(SCROLL::HORIZONTAL_THUMB_MARGIN, orientation, __thumbMargin);
1415 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1418 r = GET_SHAPE_CONFIG(SCROLL::JUMP_TO_TOP_RIGHT_MARGIN, orientation, __jumpToTopMarginRight);
1419 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1421 r = GET_SHAPE_CONFIG(SCROLL::JUMP_TO_TOP_TOP_MARGIN, orientation, __jumpToTopMarginTop);
1422 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1424 r = GET_FIXED_VALUE_CONFIG(SCROLL::JUMP_TO_TOP_WIDTH, orientation, __jumpToTopSize.width);
1425 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1427 r = GET_FIXED_VALUE_CONFIG(SCROLL::JUMP_TO_TOP_HEIGHT, orientation, __jumpToTopSize.height);
1428 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1430 r = GET_SHAPE_CONFIG(SCROLL::HANDLER_MARGIN, orientation, __handlerMarginLeft);
1431 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1433 r = GET_SHAPE_CONFIG(SCROLL::HANDLER_MIN_WIDTH, orientation, __handlerSizeMin.width);
1434 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1436 r = GET_SHAPE_CONFIG(SCROLL::HANDLER_MIN_HEIGHT, orientation, __handlerSizeMin.height);
1437 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1439 GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_LEFT_WIDTH, orientation, __scrollingEffectWidthLeft);
1440 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1442 GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_RIGHT_WIDTH, orientation, __scrollingEffectWidthRight);
1443 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1445 GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_TOP_HEIGHT, orientation, __scrollingEffectHeightTop);
1446 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1448 GET_SHAPE_CONFIG(SCROLL::OVERSCROLLING_BOTTOM_HEIGHT, orientation, __scrollingEffectHeightBottom);
1449 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
1451 __handlerMarginRight = __handlerMarginLeft;
1452 __handlerMarginTop = __handlerMarginLeft;
1453 __handlerMarginBottom = __handlerMarginLeft;
1458 __thumbSizeMin.SetSize(0.0f, 0.0f);
1459 __thumbMargin = 0.0f;
1460 __jumpToTopSize.SetSize(0.0f, 0.0f);
1461 __jumpToTopMarginRight = 0.0f;
1462 __jumpToTopMarginTop = 0.0f;
1463 __handlerSizeMin.SetSize(0.0f, 0.0f);
1464 __handlerMarginLeft = 0.0f;
1465 __handlerMarginRight = 0.0f;
1466 __handlerMarginTop = 0.0f;
1467 __handlerMarginBottom = 0.0f;
1468 __scrollingEffectWidthLeft = 0.0f;
1469 __scrollingEffectWidthRight = 0.0f;
1470 __scrollingEffectHeightTop = 0.0f;
1471 __scrollingEffectHeightBottom = 0.0f;
1478 _ScrollPresenter::ReleaseBitmapResources(void)
1480 delete __pThumbBitmap;
1481 __pThumbBitmap = null;
1483 delete __pThumbEffectBitmap;
1484 __pThumbEffectBitmap = null;
1486 delete __pJumpToTopBitmap;
1487 __pJumpToTopBitmap = null;
1489 delete __pJumpToTopPressBitmap;
1490 __pJumpToTopPressBitmap = null;
1492 delete __pJumpToTopEfBitmap;
1493 __pJumpToTopEfBitmap = null;
1495 delete __pButtonBitmap;
1496 __pButtonBitmap = null;
1498 delete __pButtonEfBitmap;
1499 __pButtonEfBitmap = null;
1501 delete __pButtonPressBitmap;
1502 __pButtonPressBitmap = null;
1504 delete __pButtonPressEfBitmap;
1505 __pButtonPressEfBitmap = null;
1507 delete __pHandlerBitmap;
1508 __pHandlerBitmap = null;
1510 delete __pFrontScrollingEffectBitmap;
1511 __pFrontScrollingEffectBitmap = null;
1513 delete __pReerScrollingEffectBitmap;
1514 __pReerScrollingEffectBitmap = null;
1520 _ScrollPresenter::CalculateScrollCtrlBounds(_ScrollDirection scrollDirection)
1522 FloatRectangle scrollCtrlBounds;
1523 FloatRectangle parentBounds = GetParentCtrl().GetBoundsF();
1525 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1527 scrollCtrlBounds.width = MAX(scrollCtrlBounds.width, (__thumbSizeMin.width + __thumbMargin));
1528 scrollCtrlBounds.width = MAX(scrollCtrlBounds.width, (__handlerSizeMin.width + __handlerMarginRight + __handlerMarginLeft));
1529 scrollCtrlBounds.width = MAX(scrollCtrlBounds.width, (__jumpToTopSize.width + __jumpToTopMarginRight));
1530 scrollCtrlBounds.width = MIN(scrollCtrlBounds.width, (parentBounds.width));
1531 scrollCtrlBounds.height = parentBounds.height;
1535 scrollCtrlBounds.height = MAX(scrollCtrlBounds.height, (__thumbSizeMin.width + __thumbMargin));
1536 scrollCtrlBounds.height = MAX(scrollCtrlBounds.height, (__handlerSizeMin.width + __handlerMarginRight + __handlerMarginLeft));
1537 scrollCtrlBounds.height = MAX(scrollCtrlBounds.height, (__jumpToTopSize.width + __jumpToTopMarginRight));
1538 scrollCtrlBounds.height = MIN(scrollCtrlBounds.height, (parentBounds.height));
1539 scrollCtrlBounds.width = parentBounds.width;
1542 scrollCtrlBounds.x = parentBounds.width - scrollCtrlBounds.width;
1543 scrollCtrlBounds.y = parentBounds.height - scrollCtrlBounds.height;
1545 return scrollCtrlBounds;
1549 _ScrollPresenter::CalculateThumbBounds(_ScrollDirection scrollDirection)
1551 FloatDimension thumbSize = CalculateThumbSize(scrollDirection);
1552 FloatPoint thumbPosition = CalculateThumbPosition(scrollDirection);
1554 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1555 if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1557 if (thumbPosition.x < 0.0f)
1559 thumbPosition.x = 0.0f;
1561 else if (thumbPosition.x > scrollCtrlBounds.width - thumbSize.width)
1563 thumbPosition.x = scrollCtrlBounds.width - thumbSize.width;
1568 if (thumbPosition.y < 0.0f)
1570 thumbPosition.y = 0.0f;
1572 else if (thumbPosition.y > scrollCtrlBounds.height - thumbSize.height)
1574 thumbPosition.y = scrollCtrlBounds.height - thumbSize.height;
1578 return FloatRectangle(thumbPosition.x, thumbPosition.y, thumbSize.width, thumbSize.height);
1582 _ScrollPresenter::CalculateThumbPosition(_ScrollDirection scrollDirection)
1584 FloatPoint thumbPosition;
1585 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1587 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1589 thumbPosition.x = scrollCtrlBounds.width - (__thumbSizeMin.width + __thumbMargin);
1590 if (thumbPosition.x < 0.0f)
1592 thumbPosition.x = 0.0f;
1595 if (__scrollRange > 0.0f)
1597 thumbPosition.y = (scrollCtrlBounds.height * __scrollPositionCurr) / __scrollRange;
1598 if (__scrollPositionCurr < 0.0f)
1600 thumbPosition.y = 0.0f;
1605 thumbPosition.y = 0.0f;
1610 thumbPosition.y = scrollCtrlBounds.height - (__thumbSizeMin.height + __thumbMargin);
1611 if (thumbPosition.y < 0.0f)
1613 thumbPosition.y = 0.0f;
1616 if (__scrollRange > 0.0f)
1618 thumbPosition.x = (scrollCtrlBounds.width * __scrollPositionCurr) / __scrollRange;
1619 if (__scrollPositionCurr < 0.0f)
1621 thumbPosition.x = 0.0f;
1626 thumbPosition.x = 0.0f;
1630 return thumbPosition;
1634 _ScrollPresenter::CalculateThumbSize(_ScrollDirection scrollDirection)
1636 FloatDimension thumbSize;
1637 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1639 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1641 thumbSize.width = MIN(__thumbSizeMin.width, scrollCtrlBounds.width);
1642 if (__scrollRange > 0.0f)
1644 thumbSize.height = (scrollCtrlBounds.height * __viewRange) / __scrollRange;
1645 thumbSize.height = MAX(__thumbSizeMin.height, thumbSize.height);
1646 thumbSize.height = MIN(scrollCtrlBounds.height, thumbSize.height);
1650 thumbSize.height = 0.0f;
1655 thumbSize.height = MIN(__thumbSizeMin.height, scrollCtrlBounds.height);
1656 if (__scrollRange > 0.0f)
1658 thumbSize.width = (scrollCtrlBounds.width * __viewRange) / __scrollRange;
1659 thumbSize.width = MAX(__thumbSizeMin.width, thumbSize.width);
1660 thumbSize.width = MIN(scrollCtrlBounds.width, thumbSize.width);
1664 thumbSize.width = 0.0f;
1672 _ScrollPresenter::CalculateHandlerBounds(_ScrollDirection scrollDirection)
1674 FloatDimension handlerSize = CalculateHandlerSize(scrollDirection);
1675 FloatPoint handlerPosition = CalculateHandlerPosition(scrollDirection);
1677 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1678 if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1680 if (handlerPosition.x < 0.0f)
1682 handlerPosition.x = 0.0f;
1684 else if (handlerPosition.x > scrollCtrlBounds.width - handlerSize.width)
1686 handlerPosition.x = scrollCtrlBounds.width - handlerSize.width;
1691 if (handlerPosition.y < 0.0f)
1693 handlerPosition.y = 0.0f;
1695 else if (handlerPosition.y > scrollCtrlBounds.height - handlerSize.height)
1697 handlerPosition.y = scrollCtrlBounds.height - handlerSize.height;
1701 return FloatRectangle(handlerPosition.x, handlerPosition.y, handlerSize.width, handlerSize.height);
1705 _ScrollPresenter::CalculateHandlerPosition(_ScrollDirection scrollDirection)
1707 FloatPoint handlerPosition;
1708 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1710 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1712 handlerPosition.x = scrollCtrlBounds.width - (__handlerSizeMin.width + __handlerMarginRight);
1713 if (handlerPosition.x < 0.0f)
1715 handlerPosition.x = 0.0f;
1717 if (__scrollRange > 0.0f)
1719 handlerPosition.y = (scrollCtrlBounds.height * __scrollPositionCurr) / __scrollRange;
1723 handlerPosition.y = 0.0f;
1728 handlerPosition.y = scrollCtrlBounds.height - (__handlerSizeMin.width + __handlerMarginRight);
1729 if (handlerPosition.y < 0.0f)
1731 handlerPosition.y = 0.0f;
1733 if (__scrollRange > 0.0f)
1735 handlerPosition.x = (scrollCtrlBounds.width * __scrollPositionCurr) / __scrollRange;
1739 handlerPosition.x = 0.0f;
1743 return handlerPosition;
1747 _ScrollPresenter::CalculateHandlerSize(_ScrollDirection scrollDirection)
1749 FloatDimension handlerSize;
1750 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1752 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1754 handlerSize.width = MIN(__handlerSizeMin.width, scrollCtrlBounds.width);
1755 if (__scrollRange > 0.0f)
1757 handlerSize.height = (scrollCtrlBounds.height * __viewRange) / __scrollRange;
1761 handlerSize.height = 0.0f;
1766 handlerSize.height = MIN(__handlerSizeMin.width, scrollCtrlBounds.height);
1767 if (__scrollRange > 0.0f)
1769 handlerSize.width = (scrollCtrlBounds.width * __viewRange) / __scrollRange;
1773 handlerSize.width = 0.0f;
1781 _ScrollPresenter::CalculateJumpToTopBounds(_ScrollDirection scrollDirection)
1783 FloatRectangle scrollCtrlBounds = __pCtrlVe->GetBounds();
1784 FloatRectangle jumpToTopBounds(0.0f, 0.0f, 0.0f, 0.0f);
1786 if (scrollDirection == SCROLL_DIRECTION_VERTICAL)
1788 jumpToTopBounds.width = MIN(__jumpToTopSize.width, scrollCtrlBounds.width);
1789 jumpToTopBounds.height = MIN(__jumpToTopSize.height, scrollCtrlBounds.height);
1790 jumpToTopBounds.x = scrollCtrlBounds.width - (__jumpToTopSize.width + __jumpToTopMarginRight);
1791 if (jumpToTopBounds.x < 0.0f)
1793 jumpToTopBounds.x = 0.0f;
1795 jumpToTopBounds.y = __jumpToTopMarginTop;
1799 jumpToTopBounds.width = MIN(__jumpToTopSize.width, scrollCtrlBounds.width);
1800 jumpToTopBounds.height = MIN(__jumpToTopSize.height, scrollCtrlBounds.height);
1801 jumpToTopBounds.y = scrollCtrlBounds.height - (__jumpToTopSize.height + __jumpToTopMarginRight);
1802 if (jumpToTopBounds.y < 0.0f)
1804 jumpToTopBounds.y = 0.0f;
1806 jumpToTopBounds.x = __jumpToTopMarginTop;
1809 return jumpToTopBounds;
1813 _ScrollPresenter::CalculateScrollingEffectFrontBounds(_ScrollDirection scrollDirection)
1815 FloatRectangle scrollCtrlBounds = GetControl().GetBoundsF();
1816 FloatRectangle scrollEffectFrontBounds(0.0f, 0.0f, 0.0f, 0.0f);
1818 if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1820 scrollEffectFrontBounds.width = __scrollingEffectWidthLeft;
1821 scrollEffectFrontBounds.height = scrollCtrlBounds.height;
1825 scrollEffectFrontBounds.width = scrollCtrlBounds.width;
1826 scrollEffectFrontBounds.height = __scrollingEffectHeightTop;
1828 return scrollEffectFrontBounds;
1832 _ScrollPresenter::CalculateScrollingEffectReerBounds(_ScrollDirection scrollDirection)
1834 FloatRectangle scrollCtrlBounds = GetControl().GetBoundsF();
1835 FloatRectangle scrollEffectReerBounds(0.0f, 0.0f, 0.0f, 0.0f);
1837 if (scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
1839 scrollEffectReerBounds.x = scrollCtrlBounds.width - __scrollingEffectWidthRight;
1840 scrollEffectReerBounds.width = __scrollingEffectWidthRight;
1841 scrollEffectReerBounds.height = scrollCtrlBounds.height;
1845 scrollEffectReerBounds.y = scrollCtrlBounds.height - __scrollingEffectHeightBottom;
1846 scrollEffectReerBounds.width = scrollCtrlBounds.width;
1847 scrollEffectReerBounds.height = __scrollingEffectHeightBottom;
1850 return scrollEffectReerBounds;
1854 _ScrollPresenter::AttachScrollChild(_VisualElement** ppScrollVe, const FloatRectangle& bounds, bool visibility)
1856 result r = E_SUCCESS;
1857 _VisualElement* pScrollVe = *ppScrollVe;
1859 if (pScrollVe == null)
1861 pScrollVe = new (std::nothrow) _VisualElement();
1862 SysTryCatch(NID_UI_CTRL, pScrollVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1864 r = pScrollVe->Construct();
1865 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct pScrollVe.", GetErrorMessage(r));
1867 r = pScrollVe->SetSurfaceOpaque(false);
1868 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set surface opaque.", GetErrorMessage(r));
1870 pScrollVe->SetImplicitAnimationEnabled(false);
1872 r = __pCtrlVe->AttachChild(*pScrollVe);
1873 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach child to the __pCtrlVe.", GetErrorMessage(r));
1875 *ppScrollVe = pScrollVe;
1878 pScrollVe->SetBounds(bounds);
1879 pScrollVe->SetShowState(visibility);
1886 pScrollVe->Destroy();
1888 *ppScrollVe = pScrollVe;
1895 _ScrollPresenter::DetachScrollChild(_VisualElement** ppScrollVe, bool destroy)
1897 _VisualElement* pScrollVe = *ppScrollVe;
1903 pScrollVe->Destroy();
1909 pScrollVe->SetShowState(false);
1915 _ScrollPresenter::RelayoutScrollChildren(_ScrollDirection scrollDirection)
1917 result r = E_SUCCESS;
1919 __pCtrlVe->SetBounds(CalculateScrollCtrlBounds(scrollDirection));
1920 if (__enableJumpToTop)
1922 __pJumpToTopVe->SetBounds(CalculateJumpToTopBounds(scrollDirection));
1923 __needUpdateJumpTopTop = true;
1926 if (__enableHandler)
1928 __pHandlerVe->SetBounds(CalculateHandlerBounds(scrollDirection));
1929 __needUpdateHandler = true;
1933 __pThumbVe->SetBounds(CalculateThumbBounds(scrollDirection));
1934 __needUpdateThumb = true;
1937 __pFrontScrollingEffectVe->SetBounds(CalculateScrollingEffectFrontBounds(scrollDirection));
1938 __pReerScrollingEffectVe->SetBounds(CalculateScrollingEffectReerBounds(scrollDirection));
1939 __needUpdateScrollingEffect = true;
1941 r = (GetControl().GetVisualElement())->InvalidateRectangle(null);
1942 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to invalidate Control Ve.");
1948 _ScrollPresenter::DrawThumb(void)
1950 if (__needUpdateThumb != true)
1955 Canvas* pCanvas = null;
1956 Bitmap* pThumbBitmap = null;
1957 result r = E_SUCCESS;
1959 if (__enableHandler != true)
1961 pCanvas = __pThumbVe->GetCanvasN();
1962 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "Failed to get the canvas of __pThumbVe");
1964 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1967 FloatRectangle thumbBounds = __pThumbVe->GetBounds();
1968 thumbBounds.SetPosition(0.0f, 0.0f);
1969 bool isCustomBitmap = false;
1970 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
1972 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::THUMB_VERTICAL_BG_NORMAL);
1976 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::THUMB_HORIZONTAL_BG_NORMAL);
1980 if (__isContextMenuScroll == false)
1982 pThumbBitmap = _BitmapImpl::GetColorReplacedBitmapN(*__pThumbBitmap,
1983 Color::GetColor(COLOR_ID_MAGENTA),
1985 SysTryCatch(NID_UI_CTRL, pThumbBitmap, , GetLastResult(), "[%s] Failed to draw bitmap.",
1986 GetErrorMessage(GetLastResult()));
1988 if (isCustomBitmap == false)
1990 r = DrawBitmap(*pCanvas, thumbBounds, *__pThumbEffectBitmap);
1991 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
1994 r = DrawBitmap(*pCanvas, thumbBounds, *pThumbBitmap);
1995 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
1999 r = DrawBitmap(*pCanvas, thumbBounds, *__pThumbBitmap);
2000 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2004 __needUpdateThumb = false;
2008 delete pThumbBitmap;
2014 _ScrollPresenter::DrawJumpToTop(void)
2016 if (__needUpdateJumpTopTop != true)
2021 Canvas* pCanvas = null;
2022 Bitmap* pColorReplacedBitmap = null;
2023 result r = E_SUCCESS;
2024 bool isCustomBitmap = false;
2025 if (__enableJumpToTop)
2027 String bitmapId = L"SCROLL::JUMP_TO_TOP_NORMAL";
2028 if (__scrollDirection == SCROLL_DIRECTION_HORIZONTAL)
2030 bitmapId = L"SCROLL::JUMP_TO_LEFT_NORMAL";
2033 Color jumpToTopColor = __jumpToTopColor;
2034 Color buttonColor = __buttonColor;
2035 Bitmap* pJumpToTopBitmap = __pJumpToTopBitmap;
2036 Bitmap* pButtonBitmap = __pButtonBitmap;
2037 Bitmap* pButtonEfBitmap = __pButtonEfBitmap;
2038 String buttonBitmapId = L"SCROLL::BUTTON_BG_NORMAL";
2040 if (__jumpToTopPressed)
2042 jumpToTopColor = __jumpToTopColorPressed;
2043 buttonColor = __buttonColorPressed;
2044 pJumpToTopBitmap = __pJumpToTopPressBitmap;
2045 pButtonBitmap = __pButtonPressBitmap;
2046 pButtonEfBitmap = __pButtonPressEfBitmap;
2047 buttonBitmapId = L"SCROLL::BUTTON_BG_PRESSED";
2050 if (__jumpToTopPressed)
2052 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::BUTTON_BG_PRESSED);
2056 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::BUTTON_BG_NORMAL);
2059 pCanvas = __pJumpToTopVe->GetCanvasN();
2060 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "Failed to get the canvas of __pJumpToTopVe");
2062 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2065 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
2066 jumpToTopBounds.SetPosition(0.0f, 0.0f);
2069 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::BUTTON_BG_PRESSED);
2070 if (isCustomBitmap == false)
2072 r = DrawBitmap(*pCanvas, jumpToTopBounds, *pButtonEfBitmap);
2073 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2076 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pButtonBitmap,
2077 Color::GetColor(COLOR_ID_MAGENTA),
2079 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap, , GetLastResult(), "[%s] Failed to draw bitmap.", GetErrorMessage(GetLastResult()));
2081 r = DrawBitmap(*pCanvas, jumpToTopBounds, *pColorReplacedBitmap);
2082 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2083 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
2085 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::JUMP_TO_TOP_NORMAL);
2089 isCustomBitmap = IS_CUSTOM_BITMAP(SCROLL::JUMP_TO_LEFT_NORMAL);
2091 if (isCustomBitmap == false)
2093 r = DrawBitmap(*pCanvas, jumpToTopBounds, *__pJumpToTopEfBitmap);
2094 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2097 pColorReplacedBitmap = _BitmapImpl::GetColorReplacedBitmapN(*pJumpToTopBitmap,
2098 Color::GetColor(COLOR_ID_MAGENTA),
2100 SysTryCatch(NID_UI_CTRL, pColorReplacedBitmap, , GetLastResult(), "[%s] Failed to draw bitmap.", GetErrorMessage(GetLastResult()));
2102 r = DrawBitmap(*pCanvas, jumpToTopBounds, *pColorReplacedBitmap);
2103 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2106 __needUpdateJumpTopTop = false;
2110 delete pColorReplacedBitmap;
2116 _ScrollPresenter::DrawHandler(void)
2118 if (__needUpdateHandler != true)
2123 Canvas* pCanvas = null;
2124 result r = E_SUCCESS;
2126 if (__enableHandler)
2128 // handler bounds setting
2129 pCanvas = __pHandlerVe->GetCanvasN();
2130 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "Failed to get the canvas of __pHandlerVe");
2133 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2136 // draw handler bg bitmap
2137 FloatRectangle handlerBounds = __pHandlerVe->GetBounds();
2138 handlerBounds.SetPosition(0.0f, 0.0f);
2140 r = DrawBitmap(*pCanvas, handlerBounds, *__pHandlerBitmap);
2141 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2144 __needUpdateHandler = false;
2153 _ScrollPresenter::DrawScrollingEffect(void)
2155 if (__needUpdateScrollingEffect != true)
2160 Canvas* pCanvas = null;
2161 result r = E_SUCCESS;
2163 if (__pFrontScrollingEffectBitmap != null)
2165 pCanvas = __pFrontScrollingEffectVe->GetCanvasN();
2166 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of __pFrontScrollingEffectVe", GetErrorMessage(GetLastResult()));
2169 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2172 FloatRectangle effectBounds = __pFrontScrollingEffectVe->GetBounds();
2173 effectBounds.SetPosition(0.0f, 0.0f);
2174 r = DrawBitmap(*pCanvas, effectBounds, *__pFrontScrollingEffectBitmap);
2175 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2180 if (__pReerScrollingEffectBitmap != null)
2182 pCanvas = __pReerScrollingEffectVe->GetCanvasN();
2183 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of __pReerScrollingEffectVe", GetErrorMessage(GetLastResult()));
2186 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
2189 FloatRectangle effectBounds = __pReerScrollingEffectVe->GetBounds();
2190 effectBounds.SetPosition(0.0f, 0.0f);
2191 r = DrawBitmap(*pCanvas, effectBounds, *__pReerScrollingEffectBitmap);
2192 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw bitmap.", GetErrorMessage(r));
2197 __needUpdateScrollingEffect = false;
2206 _ScrollPresenter::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
2208 result r = E_SUCCESS;
2209 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
2211 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
2212 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
2216 FloatPoint pos((bounds.width - bitmap.GetWidthF()) / 2.0f, (bounds.height - bitmap.GetHeightF()) / 2.0f);
2217 r = canvas.DrawBitmap(pos, bitmap);
2218 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
2225 _ScrollPresenter::OnTouchPressedJumpToTop(const _Control& source, const _TouchInfo& touchinfo)
2227 if (__enableJumpToTop && IsScrollVisible())
2229 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
2230 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
2231 jumpToTopBounds.x += ctrlBounds.x;
2232 jumpToTopBounds.y += ctrlBounds.y;
2233 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2234 if (jumpToTopBounds.Contains(touchedPosition))
2236 __needUpdateJumpTopTop = true;
2237 __jumpToTopPressed = true;
2238 SetScrollVisibility(true);
2239 (GetControl().GetVisualElement())->InvalidateRectangle(null);
2248 _ScrollPresenter::OnTouchReleasedJumpToTop(const _Control& source, const _TouchInfo& touchinfo)
2250 if (__jumpToTopPressed)
2252 __needUpdateJumpTopTop = true;
2253 __jumpToTopPressed = false;
2254 (GetControl().GetVisualElement())->InvalidateRectangle(null);
2258 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, __pScrollCtrl);
2259 _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollJumpToTopEventArgN(*__pScrollCtrl);
2260 SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2262 __pScrollEvent->Fire(*pEventArg);
2270 _ScrollPresenter::OnTouchMovedJumpToTop(const _Control& source, const _TouchInfo& touchinfo)
2272 if (__jumpToTopPressed)
2274 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
2275 FloatRectangle jumpToTopBounds = __pJumpToTopVe->GetBounds();
2276 jumpToTopBounds.x += ctrlBounds.x;
2277 jumpToTopBounds.y += ctrlBounds.y;
2278 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2279 if (!(jumpToTopBounds.Contains(touchedPosition)))
2281 __needUpdateJumpTopTop = true;
2282 __jumpToTopPressed = false;
2283 (GetControl().GetVisualElement())->InvalidateRectangle(null);
2292 _ScrollPresenter::OnTouchPressedHandler(const _Control& source, const _TouchInfo& touchinfo)
2294 if (__enableHandler)
2296 FloatRectangle ctrlBounds = __pCtrlVe->GetBounds();
2297 FloatRectangle handlerBounds = __pHandlerVe->GetBounds();
2298 handlerBounds.x += ctrlBounds.x;
2299 handlerBounds.y += ctrlBounds.y;
2300 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2301 if (handlerBounds.Contains(touchedPosition))
2303 __handlerTouched = true;
2304 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
2306 __handlerTouchedPosition = touchinfo.GetCurrentPosition().y;
2310 __handlerTouchedPosition = touchinfo.GetCurrentPosition().x;
2320 _ScrollPresenter::OnTouchReleasedHandler(const _Control& source, const _TouchInfo& touchinfo)
2322 if (__enableHandler)
2324 __handlerTouched = false;
2325 __handlerTouchedPosition = 0.0f;
2329 _UiScrollEventArg* pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pScrollCtrl);
2330 SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2332 __pScrollEvent->Fire(*pEventArg);
2337 // forwarding OnTouchReleased event to parent control
2342 _ScrollPresenter::OnTouchMovedHandler(const _Control& source, const _TouchInfo& touchinfo)
2344 if (__enableHandler && __handlerTouched)
2346 float scrollPosition = GetScrollPosition();
2347 FloatRectangle scrollCtrlBounds = GetControl().GetBoundsF();
2348 float touchPosition = 0.0f;
2349 float scrollBoundsRange = 0.0f;
2351 if (__scrollDirection == SCROLL_DIRECTION_VERTICAL)
2353 touchPosition = touchinfo.GetCurrentPosition().y;
2354 scrollBoundsRange = scrollCtrlBounds.height;
2358 touchPosition = touchinfo.GetCurrentPosition().x;
2359 scrollBoundsRange = scrollCtrlBounds.width;
2362 float touchDistance = touchPosition - __handlerTouchedPosition;
2363 float scrollDistance = ( __scrollRange * touchDistance) / scrollBoundsRange;
2365 scrollPosition += scrollDistance;
2367 int scrollType = -1;
2368 if (_FloatCompare(scrollPosition, 0.0f) || scrollPosition < 0.0f)
2370 scrollType = (__scrollDirection == SCROLL_DIRECTION_VERTICAL) ? SCROLL_END_EVENT_END_TOP : SCROLL_END_EVENT_END_LEFT;
2371 scrollPosition = 0.0f;
2373 else if (scrollPosition >= __scrollRange - __viewRange)
2375 scrollType = (__scrollDirection == SCROLL_DIRECTION_VERTICAL) ? SCROLL_END_EVENT_END_BOTTOM :
2376 SCROLL_END_EVENT_END_RIGHT;
2377 scrollPosition = __scrollRange - __viewRange;
2380 result r = SetScrollPosition(scrollPosition);
2381 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to set scroll position.", GetErrorMessage(r));
2383 __handlerTouchedPosition = touchPosition;
2387 _UiScrollEventArg* pEventArg = null;
2388 if (scrollType >= 0)
2390 pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pScrollCtrl, (ScrollEndEvent)scrollType);
2391 SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2395 pEventArg = _UiScrollEventArg::GetScrollEventArgN(*__pScrollCtrl, GetScrollPosition());
2396 SysTryReturn(NID_UI_CTRL, pEventArg, true, GetLastResult(), "[%s] Propagating.", GetErrorMessage(GetLastResult()));
2399 __pScrollEvent->Fire(*pEventArg);
2405 // forwarding OnTouchMoved event to parent control
2410 _ScrollPresenter::SetParentCtrl(_Control& parentCtrl)
2412 __pParentCtrl = &parentCtrl;
2416 _ScrollPresenter::GetParentCtrl(void) const
2418 return *__pParentCtrl;
2422 _ScrollPresenter::SetControl(_Scroll& scrollCtrl)
2424 __pScrollCtrl = &scrollCtrl;
2428 _ScrollPresenter::GetControl(void) const
2430 return *__pScrollCtrl;
2434 _ScrollPresenter::SetScrollingEffect(void)
2436 if ((__enableScrollingEffect || __enableOverScrollingEffect) && __scrollingEffectVisibility)
2438 if (__scrollPositionCurr < 0.0f)
2440 SetScrollingEffectVisibility(false);
2442 else if (__scrollPositionCurr > (__scrollRange - __viewRange))
2444 SetScrollingEffectVisibility(false);
2448 if (__pFrontScrollingEffectVe->GetOpacity() != SCROLL_OPACITY_DARK_DIM && !__fadeOut)
2450 SetScrollingEffectVisibility(true);
2459 _ScrollPresenter::SetParentBouncing(float rate)
2461 if (rate == __parentBouncingRate)
2466 __parentBouncingRate = rate;
2471 }}} // Tizen::Ui::Controls