2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
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_FastScrollPresenter.cpp
20 * @brief This is the implementation file for the _FastScrollPresenter class.
23 #include <FBaseErrors.h>
24 #include <FBaseString.h>
26 #include <FGrpColor.h>
27 #include <FGrpRectangle.h>
28 #include <FGrpCanvas.h>
29 #include <FGrpBitmap.h>
30 #include <FUiAnimVisualElementAnimation.h>
31 #include <FUiAnimVisualElementAnimationProvider.h>
32 #include <FUiAnimIVisualElementAnimationStatusEventListener.h>
33 #include <FUiAnimVisualElementContentProvider.h>
34 #include <FUiAnimIVisualElementContentProvider.h>
35 #include <FUiAnimVisualElement.h>
36 #include <FBaseSysLog.h>
37 #include <FGrp_BitmapImpl.h>
38 #include "FGrp_TextTextObject.h"
39 #include <FGrp_TextTextSimple.h>
40 #include "FUiAnim_VisualElement.h"
41 #include "FUi_Control.h"
42 #include "FUi_UiTouchEvent.h"
43 #include "FUi_ResourceManager.h"
44 #include "FUi_CoordinateSystemUtils.h"
46 #include "FUiCtrl_IFastScrollListener.h"
47 #include "FUiCtrl_UiFastScrollEvent.h"
48 #include "FUiCtrl_UiFastScrollEventArg.h"
49 #include "FUiCtrl_FastScroll.h"
50 #include "FUiCtrl_FastScrollPresenter.h"
51 #include "FUiCtrl_FastScrollModel.h"
52 #include "FUiCtrl_FastScrollIndex.h"
54 #include "FUiAnim_MatrixUtil.h"
56 using namespace Tizen::Base;
57 using namespace Tizen::Graphics;
58 using namespace Tizen::Ui;
59 using namespace Tizen::Ui::Animations;
60 using namespace Tizen::Graphics::_Text;
64 const float FASTSCROLL_OPACITY_ON = 1.0f;
65 const float FASTSCROLL_OPACITY_SELECTEDBG_DIM = 0.5f;
66 const float FASTSCROLL_OPACITY_LIGHT_DIM = 0.3f;
67 const float FASTSCROLL_OPACITY_OFF = 0.0f;
68 const int FASTSCROLL_POPUPINDEX_COUNT = 3;
71 namespace Tizen { namespace Ui { namespace Controls
74 _FastScrollViewConfig::_FastScrollViewConfig(void)
75 : __indexBgColor(Color::GetColor(COLOR_ID_BLACK))
76 , __indexHighlightColor(Color::GetColor(COLOR_ID_BLACK))
77 , __indexSelectedLineColor(Color::GetColor(COLOR_ID_BLACK))
78 , __indexTextColor(Color::GetColor(COLOR_ID_BLACK))
79 , __indexDividerColor(Color::GetColor(COLOR_ID_BLACK))
80 , __selectedIndexBgColor(Color::GetColor(COLOR_ID_BLACK))
81 , __selectedIndexTextColor(Color::GetColor(COLOR_ID_BLACK))
82 , __popupBgColor(Color::GetColor(COLOR_ID_BLACK))
83 , __popupTextColor(Color::GetColor(COLOR_ID_BLACK))
84 , __indexSizeMin(0.0f, 0.0f)
85 , __popupSize(0.0f, 0.0f)
86 , __indexMarginTop(0.0f)
88 , __indexLeftLineThickness(0.0f)
89 , __indexTextSize(0.0f)
90 , __indexSeparatorThickness(0.0f)
91 , __selectedIndexMarginRight(0.0f)
92 , __selectedIndexHeight(0.0f)
93 , __popupWidthIncrement(0.0f)
94 , __popupTextSize(0.0f)
95 , __popupShadowRight(0.0f)
96 , __popupShadowBottom(0.0f)
97 , __pIndexBgBitmap(null)
98 , __pSelectedIndexBgBitmap(null)
99 , __pSelectedIndexlineBitmap(null)
100 , __pPopupBgBitmap(null)
101 , __pPopupBgEffectBitmap(null)
106 _FastScrollViewConfig::~_FastScrollViewConfig(void)
111 _FastScrollViewConfig*
112 _FastScrollViewConfig::CreateFastScrollViewConfigN(_ControlOrientation orientation)
114 _FastScrollViewConfig* pConfig = new (std::nothrow) _FastScrollViewConfig();
115 SysTryReturn(NID_UI_CTRL, pConfig, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
117 result r = pConfig->Construct(orientation);
118 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
120 SetLastResult(E_SUCCESS);
130 _FastScrollViewConfig::ReloadConfig(_ControlOrientation orientation)
132 result r = E_SUCCESS;
134 // release allocated resources.
137 // load bitmap resources
138 r = GET_BITMAP_CONFIG_N(FASTSCROLL::INDEX_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pIndexBgBitmap);
139 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
141 r = GET_BITMAP_CONFIG_N(FASTSCROLL::INDEX_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pSelectedIndexBgBitmap);
142 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
144 r = GET_BITMAP_CONFIG_N(FASTSCROLL::INDEX_LINE_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pSelectedIndexlineBitmap);
145 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
147 r = GET_BITMAP_CONFIG_N(FASTSCROLL::POPUP_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pPopupBgBitmap);
148 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
150 r = GET_BITMAP_CONFIG_N(FASTSCROLL::POPUP_BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pPopupBgEffectBitmap);
151 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
154 // load shape configuration
155 r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __indexSizeMin.width);
156 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
158 r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __indexSizeMin.height);
159 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
161 r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __indexMarginTop);
162 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
164 r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_LEFT_LINE_THICKNESS, _CONTROL_ORIENTATION_PORTRAIT, __indexLeftLineThickness);
165 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
167 r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __indexTextSize);
168 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
170 r = GET_FIXED_VALUE_CONFIG(FASTSCROLL::INDEX_SEPARATOR_THICKNESS, _CONTROL_ORIENTATION_PORTRAIT, __indexSeparatorThickness);
171 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
173 r = GET_SHAPE_CONFIG(FASTSCROLL::SELECTED_INDEX_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __selectedIndexMarginRight);
174 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
176 r = GET_SHAPE_CONFIG(FASTSCROLL::SELECTED_INDEX_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __selectedIndexHeight);
177 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
179 r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __popupSize.width);
180 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
182 r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __popupSize.height);
183 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
185 r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_WIDTH_INCREMENT, _CONTROL_ORIENTATION_PORTRAIT, __popupWidthIncrement);
186 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
188 r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __popupTextSize);
189 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
191 r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_RIGHT_SHADOW, _CONTROL_ORIENTATION_PORTRAIT, __popupShadowRight);
192 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
194 r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_BOTTOM_SHADOW, _CONTROL_ORIENTATION_PORTRAIT, __popupShadowBottom);
195 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
198 // load color configuration
199 r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_BG_NORMAL, __indexBgColor);
200 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
202 r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_LINE_PRESSED, __indexSelectedLineColor);
203 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
205 r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_TEXT_NORMAL, __indexTextColor);
206 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
208 r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_DIVIDER_NORMAL, __indexDividerColor);
209 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
211 r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_BG_PRESSED, __selectedIndexBgColor);
212 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
214 r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_TEXT_PRESSED, __selectedIndexTextColor);
215 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
217 r = GET_COLOR_CONFIG(FASTSCROLL::POPUP_BG_NORMAL, __popupBgColor);
218 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
220 r = GET_COLOR_CONFIG(FASTSCROLL::POPUP_TEXT_NORMAL, __popupTextColor);
221 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
226 __indexBgColor = Color::GetColor(COLOR_ID_BLACK);
227 __indexHighlightColor = Color::GetColor(COLOR_ID_BLACK);
228 __indexSelectedLineColor= Color::GetColor(COLOR_ID_BLACK);
229 __indexTextColor = Color::GetColor(COLOR_ID_BLACK);
230 __indexDividerColor= Color::GetColor(COLOR_ID_BLACK);
231 __selectedIndexBgColor = Color::GetColor(COLOR_ID_BLACK);
232 __selectedIndexTextColor = Color::GetColor(COLOR_ID_BLACK);
233 __popupBgColor = Color::GetColor(COLOR_ID_BLACK);
234 __popupTextColor = Color::GetColor(COLOR_ID_BLACK);
236 __indexSizeMin.SetSize(0.0f, 0.0f);
237 __popupSize.SetSize(0.0f, 0.0f);
239 __indexMarginTop = 0.0f;
241 __indexLeftLineThickness = 0.0f;
242 __indexTextSize = 0.0f;
243 __indexSeparatorThickness = 0.0f;
244 __selectedIndexMarginRight = 0.0f;
245 __selectedIndexHeight = 0.0f;
246 __popupWidthIncrement = 0.0f;
247 __popupTextSize = 0.0f;
248 __popupShadowRight = 0.0f;
249 __popupShadowBottom = 0.0f;
257 _FastScrollViewConfig::ReleaseResources(void)
259 delete __pIndexBgBitmap;
260 delete __pSelectedIndexBgBitmap;
261 delete __pSelectedIndexlineBitmap;
262 delete __pPopupBgBitmap;
263 delete __pPopupBgEffectBitmap;
265 __pIndexBgBitmap = null;
266 __pSelectedIndexBgBitmap = null;
267 __pSelectedIndexlineBitmap = null;
268 __pPopupBgBitmap = null;
269 __pPopupBgEffectBitmap = null;
273 _FastScrollViewConfig::Construct(_ControlOrientation orientation)
275 return ReloadConfig(orientation);
279 _FastScrollIndexView::_FastScrollIndexView(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
280 : __parentVe(parentVe)
281 , __viewConfig(viewConfig)
283 , __pSelectedIndex(null)
284 , __pSelectedIndexInOmittedIndex(null)
285 , __pFormerIndex(null)
286 , __pBaseIndexVe(null)
287 , __pSelectedBgVe(null)
288 , __pSelectedIndexVe(null)
289 , __needUpdateBaseIndex(false)
290 , __needUpdateSelectedIndex(false)
291 , __needDestroySelf(false)
295 _FastScrollIndexView::~_FastScrollIndexView(void)
297 if (__pSelectedIndexVe)
299 __pSelectedIndexVe->RemoveAllAnimations();
300 __pSelectedIndexVe->SetAnimationProvider(null);
302 __pSelectedIndexVe->Destroy();
303 __pSelectedIndexVe = null;
308 __pSelectedBgVe->RemoveAllAnimations();
309 __pSelectedBgVe->SetAnimationProvider(null);
311 __pSelectedBgVe->Destroy();
312 __pSelectedBgVe = null;
317 __pBaseIndexVe->RemoveAllAnimations();
318 __pBaseIndexVe->SetAnimationProvider(null);
320 __pBaseIndexVe->Destroy();
321 __pBaseIndexVe = null;
325 _FastScrollIndexView*
326 _FastScrollIndexView::CreateFastScrollIndexViewN(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
328 _FastScrollIndexView* pIndexView = new (std::nothrow) _FastScrollIndexView(parentVe, viewConfig);
329 SysTryReturn(NID_UI_CTRL, pIndexView, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
331 result r = pIndexView->Construct();
332 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
334 SetLastResult(E_SUCCESS);
344 _FastScrollIndexView::FadeOutAndDestroy(void)
346 __needDestroySelf = true;
347 if (__pSelectedIndexVe)
349 __pSelectedIndexVe->RemoveAllAnimations();
354 __pSelectedBgVe->RemoveAllAnimations();
357 return SetIndexVisibility(false);
361 _FastScrollIndexView::SetBaseIndex(_FastScrollIndex* pIndex)
363 __pBaseIndex = pIndex;
365 result r = UpdateIndex(false);
366 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the index view.");
372 _FastScrollIndexView::GetBaseIndex(void) const
378 _FastScrollIndexView::SetIndexBounds(const FloatRectangle& indexBounds)
380 SysTryReturnResult(NID_UI_CTRL, __pSelectedIndexVe, E_INVALID_STATE, "__pSelectedIndexVe must not be null.");
382 FloatRectangle veBounds(indexBounds.x, indexBounds.y, indexBounds.width, indexBounds.height);
383 __pBaseIndexVe->SetBounds(veBounds);
385 __needUpdateBaseIndex = true;
389 __pSelectedIndexVe->SetBounds(veBounds);
391 __needUpdateSelectedIndex = true;
397 _FastScrollIndexView::GetIndexBounds(void) const
399 FloatRectangle veBounds = __pBaseIndexVe->GetBounds();
400 return Rectangle(veBounds.x, veBounds.y, veBounds.width, veBounds.height);
404 _FastScrollIndexView::GetIndexBoundsF(void) const
406 return __pBaseIndexVe->GetBounds();
410 _FastScrollIndexView::GetIndexAtPoint(const FloatPoint& point) const
412 SysTryReturn(NID_UI_CTRL, __pBaseIndex, null, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
414 int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
415 SysTryReturn(NID_UI_CTRL, childCount > 0, null, E_INVALID_STATE, "[E_INVALID_STATE] The index have no children.");
417 _FastScrollIndex* pChildIndex = null;
419 FloatRectangle bounds = __pBaseIndexVe->GetBounds();
420 if (bounds.Contains(point) == true)
422 float touchY = point.y - bounds.y - __viewConfig.__indexMarginTop;
423 float indexHeight = GetIndexHeight();
426 if (!(_FloatCompare(touchY, 0.0f) || _FloatCompare(indexHeight, 0.0f)))
428 indexOrder = _CoordinateSystemUtils::ConvertToInteger(touchY / indexHeight);
431 pChildIndex = __pBaseIndex->GetChildIndex(indexOrder, true);
432 SysTryReturn(NID_UI_CTRL, pChildIndex, null, GetLastResult(), "[%s] Failed to get the child index.",
433 GetErrorMessage(GetLastResult()));
436 SetLastResult(E_SUCCESS);
441 _FastScrollIndexView::GetOmissionIndexAtPoint(_FastScrollIndex* pIndex, const FloatPoint& point) const
443 FloatRectangle bounds = __pBaseIndexVe->GetBounds();
444 float touchY = point.y - bounds.y - __viewConfig.__indexMarginTop - (pIndex->GetIndexOrder(true) * GetIndexHeight());
445 float indexHeight = GetIndexHeight() / pIndex->GetChildCount();
446 int omissionIndexOrder = 0;
448 if (!(_FloatCompare(touchY, 0.0f) || _FloatCompare(indexHeight, 0.0f)))
450 omissionIndexOrder = _CoordinateSystemUtils::ConvertToInteger(touchY / indexHeight);
453 _FastScrollIndex* pChildIndex = pIndex->GetChildIndex(omissionIndexOrder);
454 SysTryReturn(NID_UI_CTRL, pChildIndex, null, GetLastResult(), "[%s] Failed to get the child index.",
455 GetErrorMessage(GetLastResult()));
457 SetLastResult(E_SUCCESS);
462 _FastScrollIndexView::GetIndexHeight(void) const
464 FloatRectangle bounds = __pBaseIndexVe->GetBounds();
465 float indexHeight = __viewConfig.__indexSizeMin.height;
467 if (__pBaseIndex->GetParentIndex() == null)
469 float indexHeightPerChild = (bounds.height - __viewConfig.__indexMarginTop * 2.0f) / (__pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType()));
470 if (indexHeight < indexHeightPerChild)
472 indexHeight = indexHeightPerChild;
480 _FastScrollIndexView::SelectIndex(int indexOrder)
482 result r = E_SUCCESS;
484 SysTryReturnResult(NID_UI_CTRL, __pBaseIndex, E_INVALID_STATE, "__pBaseIndex must not be null.");
486 _FastScrollIndex* pIndex = __pBaseIndex->GetChildIndex(indexOrder, true);
487 SysTryReturnResult(NID_UI_CTRL, pIndex, GetLastResult(), "Failed to get the child index.");
489 r = SelectIndex(pIndex, false);
490 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to select the index.");
496 _FastScrollIndexView::SelectIndex(_FastScrollIndex* pIndex, bool animation)
498 result r = E_SUCCESS;
500 if (__pSelectedIndex == pIndex)
505 __pSelectedIndex = pIndex;
507 if (__pSelectedIndex)
509 __pSelectedBgVe->SetBounds(CalculateSelectedBg());
510 if (GetSelectedIndexVisibility() == false)
512 r = SetSelectedIndexVisibility(true, animation);
513 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the Selected Bg ve.");
518 if (GetSelectedIndexVisibility() == true)
520 r = SetSelectedIndexVisibility(false, animation);
521 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the Selected Bg ve.");
523 SetSelectedIndexInOmittedIndex(null);
524 __pFormerIndex = null;
527 r = UpdateIndex(false);
528 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the index view.");
534 _FastScrollIndexView::GetSelectedIndexOrder(void) const
536 SysTryReturn(NID_UI_CTRL, __pBaseIndex, -1, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
537 SysTryReturn(NID_UI_CTRL, __pSelectedIndex, -1, E_INVALID_STATE, "[E_INVALID_STATE] __pSelectedIndex must not be null.");
539 return __pBaseIndex->GetChildOrder(__pSelectedIndex, true);
543 _FastScrollIndexView::SetSelectedIndex(_FastScrollIndex* pIndex)
545 __pSelectedIndex = pIndex;
549 _FastScrollIndexView::GetSelectedIndex(void) const
551 return __pSelectedIndex;
555 _FastScrollIndexView::SetSelectedIndexInOmittedIndex(_FastScrollIndex* pIndex)
557 __pFormerIndex = __pSelectedIndexInOmittedIndex;
558 __pSelectedIndexInOmittedIndex = pIndex;
562 _FastScrollIndexView::GetSelectedIndexInOmittedIndex(void) const
564 return __pSelectedIndexInOmittedIndex;
568 _FastScrollIndexView::GetFormerIndex(void) const
570 return __pFormerIndex;
574 _FastScrollIndexView::IsOnAnimation(void) const
580 _FastScrollIndexView::RemoveAllAnimations(void)
582 __pBaseIndexVe->RemoveAllAnimations();
586 _FastScrollIndexView::SetIndexVisibility(bool visibility)
588 result r = E_SUCCESS;
590 __pBaseIndexVe->SetImplicitAnimationEnabled(true);
594 __pBaseIndexVe->SetOpacity(FASTSCROLL_OPACITY_ON);
598 __pBaseIndexVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
600 // else keep up current visibility.
602 __pBaseIndexVe->SetImplicitAnimationEnabled(false);
608 _FastScrollIndexView::GetIndexVisibility(void) const
610 float opacity = __pBaseIndexVe->GetOpacity();
611 if (opacity > FASTSCROLL_OPACITY_OFF)
622 _FastScrollIndexView::SetSelectedIndexVisibility(bool visibility, bool animation)
624 SysTryReturnResult(NID_UI_CTRL, __pSelectedIndexVe, E_INVALID_STATE, "__pSelectedIndexVe must not be null.");
625 SysTryReturnResult(NID_UI_CTRL, __pSelectedBgVe, E_INVALID_STATE, "__pSelectedBgVe must not be null.");
629 __pSelectedIndexVe->SetImplicitAnimationEnabled(true);
630 __pSelectedBgVe->SetImplicitAnimationEnabled(true);
635 __pSelectedIndexVe->SetOpacity(FASTSCROLL_OPACITY_ON);
636 __pSelectedBgVe->SetOpacity(FASTSCROLL_OPACITY_SELECTEDBG_DIM);
640 __pSelectedIndexVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
641 __pSelectedBgVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
643 // else keep up current visibility.
645 __pSelectedIndexVe->SetImplicitAnimationEnabled(false);
646 __pSelectedBgVe->SetImplicitAnimationEnabled(false);
652 _FastScrollIndexView::GetSelectedIndexVisibility(void) const
654 SysTryReturn(NID_UI_CTRL, __pSelectedIndexVe, false, E_INVALID_STATE, "[E_INVALID_STATE] __pSelectedIndexVe must not be null.");
656 float opacity = __pSelectedIndexVe->GetOpacity();
657 if (opacity > FASTSCROLL_OPACITY_OFF)
667 _FastScrollIndexView::UpdateIndex(bool bNeedUpdateBaseIndex)
669 result r = E_SUCCESS;
671 r = __parentVe.InvalidateRectangle(null);
672 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to invalidate the index Ve.");
674 if (__pSelectedIndex)
676 __needUpdateSelectedIndex = true;
679 if (bNeedUpdateBaseIndex)
681 __needUpdateBaseIndex = true;
688 _FastScrollIndexView::OnDraw(void)
691 if (__pSelectedIndex)
698 VisualElementAnimation*
699 _FastScrollIndexView::CreateAnimationForProperty(VisualElement& target, const String& property)
701 VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
705 const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
708 pAnimation->SetTimingFunction(pTimingFunction);
710 pAnimation->SetVisualElementAnimationStatusEventListener(this);
716 _FastScrollIndexView::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
721 _FastScrollIndexView::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
726 _FastScrollIndexView::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
728 if (__pBaseIndexVe == (static_cast <_VisualElement*>(&target)))
730 if (__needDestroySelf && completedNormally)
732 if (__pSelectedIndexVe)
734 __pSelectedIndexVe->RemoveAllAnimations();
735 __pSelectedIndexVe->SetAnimationProvider(null);
740 __pSelectedBgVe->RemoveAllAnimations();
741 __pSelectedBgVe->SetAnimationProvider(null);
744 __pBaseIndexVe->RemoveAllAnimations();
745 __pBaseIndexVe->SetAnimationProvider(null);
753 _FastScrollIndexView::CalculateSelectedBg(void)
755 SysTryReturn(NID_UI_CTRL, __pBaseIndex, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE,
756 "[E_INVALID_STATE] __pBaseIndex must not be null.");
757 SysTryReturn(NID_UI_CTRL, __pSelectedIndexVe, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE,
758 "[E_INVALID_STATE] __pSelectedIndexVe must not be null.");
759 SysTryReturn(NID_UI_CTRL, __pSelectedIndex, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE,
760 "[E_INVALID_STATE] __pSelectedIndex must not be null.");
762 int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
763 SysTryReturn(NID_UI_CTRL, childCount > 0, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE, "[E_INVALID_STATE] The index have no children.");
765 FloatRectangle bounds = __pBaseIndexVe->GetBounds();
766 float indexHeight = GetIndexHeight();
767 int selectedIndexOrder = GetSelectedIndexOrder();
768 FloatRectangle selectedRect(0.0f, 0.0f, (bounds.width - __viewConfig.__selectedIndexMarginRight), __viewConfig.__selectedIndexHeight);
770 if (_FloatCompare(bounds.height, __viewConfig.__selectedIndexHeight) || (bounds.height < __viewConfig.__selectedIndexHeight))
772 selectedRect.height = bounds.height;
776 if (selectedIndexOrder == 0)
778 selectedRect.y = 0.0f;
779 selectedRect.height = indexHeight + __viewConfig.__indexMarginTop;
781 else if (selectedIndexOrder == childCount - 1)
783 selectedRect.y = ((selectedIndexOrder * indexHeight) + __viewConfig.__indexMarginTop);
784 selectedRect.height = bounds.height - selectedRect.y;
788 selectedRect.y = ((selectedIndexOrder * indexHeight) + __viewConfig.__indexMarginTop);
789 if (indexHeight < __viewConfig.__selectedIndexHeight)
791 selectedRect.y -= ((__viewConfig.__selectedIndexHeight - indexHeight) / 2.0f);
795 selectedRect.height = indexHeight;
798 if (selectedRect.y < 0.0f)
800 selectedRect.y = 0.0f;
809 _FastScrollIndexView::DrawBaseIndex()
811 if (!__needUpdateBaseIndex)
815 SysTryReturnVoidResult(NID_UI_CTRL, __pBaseIndex, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
817 result r = E_SUCCESS;
818 int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
819 SysTryReturnVoidResult(NID_UI_CTRL, childCount > 0, E_INVALID_STATE, "[E_INVALID_STATE] The index have no children.");
821 Canvas* pCanvas = __pBaseIndexVe->GetCanvasN();
822 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the index ve.",
823 GetErrorMessage(GetLastResult()));
825 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
828 pCanvas->SetLineWidth(__viewConfig.__indexSeparatorThickness);
830 FloatRectangle bounds = __pBaseIndexVe->GetBounds();
831 float indexHeight = GetIndexHeight();
833 FloatRectangle bgBounds(0.0f, 0.0f, bounds.width, bounds.height);
834 if (__viewConfig.__pIndexBgBitmap)
836 Bitmap* pReplacementColorBackgroundBitmap =
837 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pIndexBgBitmap,
838 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__indexBgColor);
839 DrawBitmap(*pCanvas, bgBounds, *pReplacementColorBackgroundBitmap);
841 delete pReplacementColorBackgroundBitmap;
844 FloatRectangle indexRect(0.0f, __viewConfig.__indexMarginTop, bounds.width, indexHeight);
845 Bitmap* pReplacementColorBitmap = null;
847 TextObject* pTextObject = new (std::nothrow) TextObject();
848 SysTryCatch(NID_UI_CTRL, pTextObject, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
850 pTextObject->Construct();
852 for (int i = 0; i < childCount; i++)
854 TextSimple* pSimpleText = null;
856 _FastScrollIndex* pChildIndex = __pBaseIndex->GetChildIndex(i, true);
857 SysTryCatch(NID_UI_CTRL, pChildIndex, , GetLastResult(), "[%s] Failed to get the child index.",
858 GetErrorMessage(GetLastResult()));
860 Bitmap* pChildIndexImage = pChildIndex->GetIndexImage();
861 if (pChildIndexImage)
863 FloatRectangle imageRect = indexRect;
864 float scaleFactor = indexRect.width / pChildIndexImage->GetWidthF();
865 float heightScaleFactor = indexRect.height / pChildIndexImage->GetHeightF();
866 if (scaleFactor > heightScaleFactor)
868 scaleFactor = heightScaleFactor;
871 imageRect.width = pChildIndexImage->GetWidthF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
872 imageRect.height = pChildIndexImage->GetHeightF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
874 if (indexRect.width - imageRect.width > 0.0f)
876 imageRect.x = indexRect.x + (indexRect.width - imageRect.width) / 2.0f;
879 if (indexRect.height - imageRect.height > 0.0f)
881 imageRect.y = indexRect.y + (indexRect.height - imageRect.height) / 2.0f;
884 pReplacementColorBitmap =
885 _BitmapImpl::GetColorReplacedBitmapN(*pChildIndexImage,
886 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__indexTextColor);
887 r = DrawBitmap(*pCanvas, imageRect, *pReplacementColorBitmap,
888 FloatRectangle(0.0f, 0.0f, pChildIndexImage->GetWidthF(), pChildIndexImage->GetHeightF()));
889 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw a bitmap.", GetErrorMessage(r));
891 delete pReplacementColorBitmap;
892 pReplacementColorBitmap = null;
896 String* pChildIndexText = pChildIndex->GetIndexText();
897 SysTryCatch(NID_UI_CTRL, pChildIndexText, , E_INVALID_STATE, "pChildIndexText must not be null.");
899 pTextObject->RemoveAll();
901 pSimpleText = new (std::nothrow)TextSimple(const_cast<wchar_t*>(pChildIndexText->GetPointer()), pChildIndexText->GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
902 SysTryCatch(NID_UI_CTRL, pSimpleText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed");
904 r = pTextObject->AppendElement(*pSimpleText);
905 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to append simple text.", GetErrorMessage(r));
907 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
908 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set wrap.", GetErrorMessage(r));
910 r = pTextObject->SetFont(__viewConfig.__pFont, 0, pTextObject->GetTextLength());
911 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
913 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
914 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set alignment.", GetErrorMessage(r));
916 r = pTextObject->SetBounds(indexRect);
917 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds of pTextObject.", GetErrorMessage(r));
919 r = pTextObject->SetForegroundColor(__viewConfig.__indexTextColor, 0, pTextObject->GetTextLength());
920 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set foreground color.", GetErrorMessage(r));
922 r = pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
923 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw text.", GetErrorMessage(r));
927 indexRect.y += indexHeight;
928 if (i != (childCount - 1))
930 pCanvas->SetForegroundColor(__viewConfig.__indexDividerColor);
931 pCanvas->DrawLine(FloatPoint(indexRect.x, indexRect.y + __viewConfig.__indexSeparatorThickness),
932 FloatPoint(indexRect.x + indexRect.width, indexRect.y + __viewConfig.__indexSeparatorThickness));
936 __needUpdateBaseIndex = false;
941 delete pReplacementColorBitmap;
945 _FastScrollIndexView::DrawSelectedBg()
947 if (!__needUpdateSelectedIndex)
952 SysTryReturnVoidResult(NID_UI_CTRL, __pSelectedIndex, E_INVALID_STATE,
953 "[E_INVALID_STATE] __pSelectedIndex must not be null.");
955 Canvas* pCanvas = __pSelectedBgVe->GetCanvasN();
956 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the Selected Bg ve.",
957 GetErrorMessage(GetLastResult()));
959 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
962 FloatRectangle bounds = __pSelectedBgVe->GetBounds();
965 if (__viewConfig.__pSelectedIndexBgBitmap)
967 Bitmap* pReplacementColorBackgroundBitmap = null;
968 pReplacementColorBackgroundBitmap =
969 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pSelectedIndexBgBitmap,
970 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__selectedIndexBgColor);
971 DrawBitmap(*pCanvas, bounds, *pReplacementColorBackgroundBitmap);
973 delete pReplacementColorBackgroundBitmap;
980 _FastScrollIndexView::DrawSelectedIndex()
982 if (!__needUpdateSelectedIndex)
987 SysTryReturnVoidResult(NID_UI_CTRL, __pSelectedIndex, E_INVALID_STATE, "[E_INVALID_STATE] __pSelectedIndex must not be null.");
989 Canvas* pCanvas = __pSelectedIndexVe->GetCanvasN();
990 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the selected index ve.",
991 GetErrorMessage(GetLastResult()));
993 result r = E_SUCCESS;
994 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
996 FloatRectangle bounds = __pSelectedIndexVe->GetBounds();
997 FloatRectangle outlineBounds = __pSelectedBgVe->GetBounds();
999 int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
1000 int selectedIndexOrder = GetSelectedIndexOrder();
1002 pCanvas->SetLineWidth(__viewConfig.__indexLeftLineThickness);
1003 pCanvas->SetForegroundColor(__viewConfig.__indexSelectedLineColor);
1005 if (selectedIndexOrder == 0)
1007 pCanvas->DrawLine(FloatPoint(0.0f, outlineBounds.height), FloatPoint(outlineBounds.width, outlineBounds.height));
1008 pCanvas->DrawLine(FloatPoint(outlineBounds.width, outlineBounds.y), FloatPoint(outlineBounds.width, outlineBounds.height));
1010 pCanvas->DrawLine(FloatPoint(1.0f, outlineBounds.height), FloatPoint(1.0f, bounds.height));
1012 else if (selectedIndexOrder == childCount - 1)
1014 pCanvas->DrawLine(FloatPoint(0.0f, outlineBounds.y), FloatPoint(outlineBounds.width, outlineBounds.y));
1015 pCanvas->DrawLine(FloatPoint(outlineBounds.width, outlineBounds.y), FloatPoint(outlineBounds.width, bounds.height));
1017 pCanvas->DrawLine(FloatPoint(1.0f, 0.0f), FloatPoint(1.0f, outlineBounds.y));
1019 else if (__viewConfig.__pSelectedIndexlineBitmap)
1021 Bitmap* pReplacementColorBackgroundBitmap = null;
1022 pReplacementColorBackgroundBitmap =
1023 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pSelectedIndexlineBitmap,
1024 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__indexSelectedLineColor);
1025 DrawBitmap(*pCanvas, outlineBounds, *pReplacementColorBackgroundBitmap);
1027 delete pReplacementColorBackgroundBitmap;
1029 pCanvas->DrawLine(FloatPoint(1.0f, 0.0f), FloatPoint(1.0f, outlineBounds.y));
1030 pCanvas->DrawLine(FloatPoint(1.0f, (outlineBounds.y + outlineBounds.height)), FloatPoint(1.0f, bounds.height));
1034 TextObject* pTextObject = null;
1035 TextSimple* pSimpleText = null;
1037 float indexHeight = GetIndexHeight();
1038 FloatRectangle indexRect(0.0f, ((GetSelectedIndexOrder() * indexHeight) + __viewConfig.__indexMarginTop),
1039 bounds.width, indexHeight);
1041 Bitmap* pChildIndexImage = __pSelectedIndex->GetIndexImage();
1042 Bitmap* pReplacementColorBitmap = null;
1043 if (pChildIndexImage)
1045 FloatRectangle imageRect = indexRect;
1046 float scaleFactor = indexRect.width / pChildIndexImage->GetWidthF();
1047 float heightScaleFactor = indexRect.height / pChildIndexImage->GetHeightF();
1048 if (scaleFactor > heightScaleFactor)
1050 scaleFactor = heightScaleFactor;
1053 imageRect.width = pChildIndexImage->GetWidthF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
1054 imageRect.height = pChildIndexImage->GetHeightF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
1056 if (indexRect.width - imageRect.width > 0.0f)
1058 imageRect.x = indexRect.x + (indexRect.width - imageRect.width) / 2.0f;
1061 if (indexRect.height - imageRect.height > 0.0f)
1063 imageRect.y = indexRect.y + (indexRect.height - imageRect.height) / 2.0f;
1066 pReplacementColorBitmap =
1067 _BitmapImpl::GetColorReplacedBitmapN(*pChildIndexImage,
1068 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__selectedIndexTextColor);
1069 r = DrawBitmap(*pCanvas, imageRect, *pReplacementColorBitmap,
1070 FloatRectangle(0.0f, 0.0f, pChildIndexImage->GetWidthF(), pChildIndexImage->GetHeightF()));
1071 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw a bitmap.", GetErrorMessage(r));
1073 delete pReplacementColorBitmap;
1074 pReplacementColorBitmap = null;
1078 String* pChildIndexText = __pSelectedIndex->GetIndexText();
1079 SysTryCatch(NID_UI_CTRL, pChildIndexText, , E_INVALID_STATE, "[E_INVALID_STATE] pChildIndexText must not be null.");
1081 pTextObject = new (std::nothrow) TextObject();
1082 SysTryCatch(NID_UI_CTRL, pTextObject, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1084 pTextObject->Construct();
1086 pSimpleText = new (std::nothrow)TextSimple(const_cast<wchar_t*>(pChildIndexText->GetPointer()), pChildIndexText->GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1087 SysTryCatch(NID_UI_CTRL, pSimpleText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1089 r = pTextObject->AppendElement(*pSimpleText);
1090 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to append simpletext.", GetErrorMessage(r));
1092 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1093 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set wrap.", GetErrorMessage(r));
1095 r = pTextObject->SetFont(__viewConfig.__pFont, 0, pTextObject->GetTextLength());
1096 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
1098 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1099 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set alignment.", GetErrorMessage(r));
1101 r = pTextObject->SetBounds(indexRect);
1102 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds of pTextObject.", GetErrorMessage(r));
1104 r = pTextObject->SetForegroundColor(__viewConfig.__selectedIndexTextColor, 0, pTextObject->GetTextLength());
1105 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set foreground color.", GetErrorMessage(r));
1107 r = pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1108 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw text.", GetErrorMessage(r));
1111 __needUpdateSelectedIndex = false;
1117 delete pReplacementColorBitmap;
1121 _FastScrollIndexView::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
1123 result r = E_SUCCESS;
1124 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1126 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1127 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1131 r = canvas.DrawBitmap(bounds, bitmap);
1132 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1139 _FastScrollIndexView::DrawBitmap(Canvas& canvas, const FloatRectangle& srcRect, const Bitmap& bitmap, const FloatRectangle& dstRect)
1141 result r = E_SUCCESS;
1142 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1144 r = canvas.DrawNinePatchedBitmap(srcRect, bitmap);
1145 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1149 r = canvas.DrawBitmap(srcRect, bitmap, dstRect);
1150 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1157 _FastScrollIndexView::Construct(void)
1159 result r = E_SUCCESS;
1161 // FormattedText for Title text
1162 __pBaseIndexVe = new (std::nothrow) _VisualElement();
1163 SysTryCatch(NID_UI_CTRL, __pBaseIndexVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1165 r = __pBaseIndexVe->Construct();
1166 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the index Ve.", GetErrorMessage(r));
1168 __pBaseIndexVe->SetAnimationProvider(this);
1170 r = __pBaseIndexVe->SetSurfaceOpaque(false);
1171 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the base index ve.", GetErrorMessage(r));
1173 __pBaseIndexVe->SetImplicitAnimationEnabled(false);
1175 r = __parentVe.AttachChild(*__pBaseIndexVe);
1176 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the base index ve to the parent.", GetErrorMessage(r));
1178 __pBaseIndexVe->SetShowState(true);
1181 __pSelectedBgVe = new (std::nothrow) _VisualElement();
1182 SysTryCatch(NID_UI_CTRL, __pSelectedBgVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1184 r = __pSelectedBgVe->Construct();
1185 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the selected Bg ve.", GetErrorMessage(r));
1187 __pSelectedBgVe->SetAnimationProvider(this);
1189 r = __pSelectedBgVe->SetSurfaceOpaque(false);
1190 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the selected Bg ve.", GetErrorMessage(r));
1192 __pSelectedBgVe->SetImplicitAnimationEnabled(false);
1194 r = __pBaseIndexVe->AttachChild(*__pSelectedBgVe);
1195 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the selected Bg ve to the parent.", GetErrorMessage(r));
1197 __pSelectedBgVe->SetOpacity(FASTSCROLL_OPACITY_SELECTEDBG_DIM);
1199 __pSelectedBgVe->SetShowState(true);
1201 //__pSelectedIndexVe
1202 __pSelectedIndexVe = new (std::nothrow) _VisualElement();
1203 SysTryCatch(NID_UI_CTRL, __pSelectedIndexVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1205 r = __pSelectedIndexVe->Construct();
1206 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the selected index ve.", GetErrorMessage(r));
1208 __pSelectedIndexVe->SetAnimationProvider(this);
1210 r = __pSelectedIndexVe->SetSurfaceOpaque(false);
1211 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the selected index ve.", GetErrorMessage(r));
1213 __pSelectedIndexVe->SetImplicitAnimationEnabled(false);
1215 r = __pBaseIndexVe->AttachChild(*__pSelectedIndexVe);
1216 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the selected index ve to the parent.", GetErrorMessage(r));
1218 __pSelectedIndexVe->SetShowState(true);
1223 if (__pSelectedIndexVe)
1225 __pSelectedIndexVe->Destroy();
1226 __pSelectedIndexVe = null;
1229 if (__pSelectedBgVe)
1231 __pSelectedBgVe->Destroy();
1232 __pSelectedBgVe = null;
1237 __pBaseIndexVe->Destroy();
1238 __pBaseIndexVe = null;
1244 _FastScrollPopupView::_FastScrollPopupView(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
1245 : __parentVe(parentVe)
1246 , __viewConfig(viewConfig)
1248 , __needUpdatePopupVe(false)
1249 , __needUpdatePopupIndexVe(false)
1250 , __needDestroySelf(false)
1254 _FastScrollPopupView::~_FastScrollPopupView(void)
1256 for (int i = 0; i < GetIndexVeCount(); i++)
1258 _VisualElement* pIndexVe = GetIndexVe(i);
1262 pIndexVe->RemoveAllAnimations();
1263 pIndexVe->SetAnimationProvider(null);
1264 pIndexVe->Destroy();
1267 __indexViews.RemoveAll(false);
1271 __pPopupVe->RemoveAllAnimations();
1272 __pPopupVe->SetAnimationProvider(null);
1274 __pPopupVe->Destroy();
1279 _FastScrollPopupView*
1280 _FastScrollPopupView::CreateFastScrollPopupViewN(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
1282 _FastScrollPopupView* pPopupView = new (std::nothrow) _FastScrollPopupView(parentVe, viewConfig);
1283 SysTryReturn(NID_UI_CTRL, pPopupView, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1285 result r = pPopupView->Construct();
1286 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1288 SetLastResult(E_SUCCESS);
1298 _FastScrollPopupView::FadeOutAndDestroy(void)
1300 __needDestroySelf = true;
1302 for (int i = 0; i < GetIndexVeCount(); i++)
1304 _VisualElement* pIndexVe = GetIndexVe(i);
1305 SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index view.");
1307 pIndexVe->RemoveAllAnimations();
1310 return SetPopupVisibility(false);
1314 _FastScrollPopupView::SelectIndex(int indexLevel, _FastScrollIndex* pIndex, _FastScrollIndex* pFormerIndex)
1316 _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1317 SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index view.");
1321 pIndexVe->SetOpacity(FASTSCROLL_OPACITY_ON);
1322 FloatRectangle popupVeBounds = __pPopupVe->GetBounds();
1323 FloatMatrix4 popupVeMatrix;
1324 popupVeMatrix.SetAsIdentity();
1326 if (pFormerIndex && (pFormerIndex != pIndex))
1328 FloatRectangle popupIndexVeBounds = pIndexVe->GetBounds();
1330 int selectedOrder = pIndex->GetIndexOrder(false);
1331 int oldOrder = pFormerIndex->GetIndexOrder(false);
1333 if (selectedOrder > oldOrder)
1335 _MatrixUtilTranslate(popupVeMatrix, 0.0f, 0.0f, 0.0f);
1339 _MatrixUtilTranslate(popupVeMatrix, 0.0f, -(popupVeBounds.height * (FASTSCROLL_POPUPINDEX_COUNT - 1)), 0.0f);
1341 pIndexVe->SetTransformMatrix(popupVeMatrix);
1342 pIndexVe->SetImplicitAnimationEnabled(true);
1344 popupVeMatrix.SetAsIdentity();
1345 _MatrixUtilTranslate(popupVeMatrix, 0.0f, -popupVeBounds.height, 0.0f);
1346 pIndexVe->SetTransformMatrix(popupVeMatrix);
1348 pIndexVe->SetImplicitAnimationEnabled(false);
1352 _MatrixUtilTranslate(popupVeMatrix, 0.0f, -popupVeBounds.height, 0.0f);
1353 pIndexVe->SetTransformMatrix(popupVeMatrix);
1358 pIndexVe->SetOpacity(FASTSCROLL_OPACITY_LIGHT_DIM);
1365 _FastScrollPopupView::AddPopupIndexVe(int indexLevel)
1367 result r = E_SUCCESS;
1368 _VisualElement* pPopupIndexVe = new (std::nothrow) _VisualElement();
1369 SysTryCatch(NID_UI_CTRL, pPopupIndexVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1371 r = pPopupIndexVe->Construct();
1372 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the popup index ve.", GetErrorMessage(r));
1374 pPopupIndexVe->SetAnimationProvider(this);
1376 r = pPopupIndexVe->SetSurfaceOpaque(false);
1377 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the popup index ve.", GetErrorMessage(r));
1379 pPopupIndexVe->SetImplicitAnimationEnabled(false);
1381 r = __pPopupVe->AttachChild(*pPopupIndexVe);
1382 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the popup index ve to the popup ve.", GetErrorMessage(r));
1384 pPopupIndexVe->SetShowState(true);
1386 r = __indexViews.InsertAt(*pPopupIndexVe, indexLevel);
1387 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to change the last index view.", GetErrorMessage(r));
1394 pPopupIndexVe->RemoveAllAnimations();
1395 pPopupIndexVe->SetAnimationProvider(null);
1397 pPopupIndexVe->Destroy();
1404 _FastScrollPopupView::RemovePopupIndexVe(int indexLevel)
1406 result r = E_SUCCESS;
1408 if (indexLevel < GetIndexVeCount())
1410 _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1411 SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index ve.");
1413 r = __indexViews.Remove(*pIndexVe, false);
1414 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove the popup index ve.");
1416 pIndexVe->RemoveAllAnimations();
1417 pIndexVe->SetAnimationProvider(null);
1418 pIndexVe->Destroy();
1425 _FastScrollPopupView::SetPopupBounds(const FloatRectangle& indexBounds)
1427 SysTryReturnResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "__pPopupVe must not be null.");
1429 __pPopupVe->SetBounds(indexBounds);
1435 _FastScrollPopupView::SetPopupIndexBounds(int indexLevel, const _FastScrollIndex* pBaseIndex)
1437 FloatRectangle veBounds = __pPopupVe->GetBounds();
1438 _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1439 SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index view.");
1445 veBounds.height = veBounds.height * FASTSCROLL_POPUPINDEX_COUNT;
1448 int indexVeCount = GetIndexVeCount();
1449 float indexWidth = veBounds.width;
1450 if (indexVeCount > 0)
1452 indexWidth /= indexVeCount;
1455 veBounds.width = indexWidth;
1456 veBounds.x = veBounds.width * indexLevel;
1458 pIndexVe->SetBounds(veBounds);
1464 _FastScrollPopupView::GetIndexVe(int indexLevel) const
1466 Object* pObj = const_cast<Object*>(__indexViews.GetAt(indexLevel));
1467 SysTryReturn(NID_UI_CTRL, pObj, null, GetLastResult(), "[%s] Failed to get the popup index ve.",
1468 GetErrorMessage(GetLastResult()));
1470 return dynamic_cast<_VisualElement*>(pObj);
1474 _FastScrollPopupView::GetIndexVeCount(void) const
1476 return __indexViews.GetCount();
1480 _FastScrollPopupView::IsOnAnimation(void) const
1486 _FastScrollPopupView::RemoveAllAnimations(void)
1488 SysTryReturnVoidResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "[E_INVALID_STATE] __pPopupVe must not be null.");
1489 __pPopupVe->RemoveAllAnimations();
1493 _FastScrollPopupView::SetPopupVisibility(bool visibility)
1495 SysTryReturnResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "__pPopupVe must not be null.");
1499 __pPopupVe->SetTransformMatrix(__matrixFadeInStart);
1500 __pPopupVe->SetImplicitAnimationEnabled(true);
1501 __pPopupVe->SetOpacity(FASTSCROLL_OPACITY_ON);
1502 __pPopupVe->SetTransformMatrix(__matrixOrigin);
1503 __pPopupVe->SetImplicitAnimationEnabled(false);
1507 __pPopupVe->SetImplicitAnimationEnabled(true);
1508 __pPopupVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
1509 __pPopupVe->SetTransformMatrix(__matrixFadeOutEnd);
1510 __pPopupVe->SetImplicitAnimationEnabled(false);
1512 // else keep up current visibility.
1518 _FastScrollPopupView::GetPopupVisibility(void) const
1520 SysTryReturn(NID_UI_CTRL, __pPopupVe, false, E_INVALID_STATE, "[E_INVALID_STATE] __pPopupVe must not be null.");
1522 float opacity = __pPopupVe->GetOpacity();
1523 if (opacity > FASTSCROLL_OPACITY_OFF)
1532 _FastScrollPopupView::SetPopupVeUpdateNeeded(bool needUpdate)
1534 __needUpdatePopupIndexVe = needUpdate;
1538 _FastScrollPopupView::UpdateIndex(void)
1540 SysTryReturnResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "__pPopupVe must not be null.");
1542 result r = E_SUCCESS;
1544 r = __parentVe.InvalidateRectangle(null);
1545 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to invalidate the popup Ve.");
1547 __needUpdatePopupIndexVe = true;
1553 _FastScrollPopupView::OnDraw(int indexLevel, const _FastScrollIndex* pBaseIndex, const _FastScrollIndex* pSelectedIndex)
1556 DrawPopupIndexVe(indexLevel, pBaseIndex, pSelectedIndex);
1559 VisualElementAnimation*
1560 _FastScrollPopupView::CreateAnimationForProperty(VisualElement& target, const String& property)
1562 VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
1566 const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
1567 if (pTimingFunction)
1569 pAnimation->SetTimingFunction(pTimingFunction);
1571 pAnimation->SetVisualElementAnimationStatusEventListener(this);
1577 _FastScrollPopupView::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
1582 _FastScrollPopupView::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
1587 _FastScrollPopupView::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
1589 SysTryReturnVoidResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "[E_INVALID_STATE] The popup Ve must not be null.");
1590 if (__pPopupVe == (static_cast <_VisualElement*>(&target)))
1592 if (__needDestroySelf && completedNormally)
1594 for (int i = 0; i < GetIndexVeCount(); i++)
1596 _VisualElement* pIndexVe = GetIndexVe(i);
1599 pIndexVe->RemoveAllAnimations();
1600 pIndexVe->SetAnimationProvider(null);
1604 __pPopupVe->RemoveAllAnimations();
1605 __pPopupVe->SetAnimationProvider(null);
1613 _FastScrollPopupView::DrawPopupVe(void)
1615 if (!__needUpdatePopupVe)
1620 SysTryReturnVoidResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "[E_INVALID_STATE] __pPopupVe must not be null.");
1622 Canvas* pCanvas = __pPopupVe->GetCanvasN();
1623 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the popup ve.",
1624 GetErrorMessage(GetLastResult()));
1626 FloatRectangle bounds = __pPopupVe->GetBounds();
1627 bounds.SetPosition(0.0f, 0.0f);
1629 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1631 bool isCustomBitmap = IS_CUSTOM_BITMAP(FASTSCROLL::POPUP_BG_NORMAL);
1633 if (__viewConfig.__pPopupBgEffectBitmap && isCustomBitmap == false)
1635 DrawBitmap(*pCanvas, bounds, *__viewConfig.__pPopupBgEffectBitmap);
1638 if (__viewConfig.__pPopupBgBitmap)
1640 Bitmap* pReplacementColorBackgroundBitmap = null;
1641 pReplacementColorBackgroundBitmap =
1642 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pPopupBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__popupBgColor);
1643 DrawBitmap(*pCanvas, bounds, *pReplacementColorBackgroundBitmap);
1645 delete pReplacementColorBackgroundBitmap;
1650 __needUpdatePopupVe = false;
1655 _FastScrollPopupView::DrawPopupIndexVe(int indexLevel, const _FastScrollIndex* pBaseIndex, const _FastScrollIndex* pSelectedIndex)
1657 if (__needUpdatePopupIndexVe != true)
1662 SysTryReturnVoidResult(NID_UI_CTRL, pBaseIndex, E_INVALID_STATE, "[E_INVALID_STATE] pBaseIndex must not be null.");
1663 SysTryReturnVoidResult(NID_UI_CTRL, pSelectedIndex, E_INVALID_STATE, "[E_INVALID_STATE] pBaseIndex must not be null.");
1665 result r = E_SUCCESS;
1667 int childCount = pBaseIndex->GetChildCount();
1668 SysTryReturnVoidResult(NID_UI_CTRL, childCount > 0, E_INVALID_STATE, "[E_INVALID_STATE] The index have no children.");
1670 _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1671 SysTryReturnVoidResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "[%s] Failed to get the popup index ve.",
1672 GetErrorMessage(GetLastResult()));
1674 Canvas* pCanvas = pIndexVe->GetCanvasN();
1675 SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the popup index ve.",
1676 GetErrorMessage(GetLastResult()));
1678 pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1681 FloatRectangle veBounds = pIndexVe->GetBounds();
1682 FloatRectangle bounds(veBounds.x, veBounds.y, veBounds.width, veBounds.height);
1684 float indexHeight = bounds.height / FASTSCROLL_POPUPINDEX_COUNT;
1685 if (indexHeight < __viewConfig.__popupTextSize)
1687 indexHeight = __viewConfig.__popupTextSize;
1690 FloatRectangle indexRect(0.0f, 0.0f, bounds.width, indexHeight);
1691 int selectedOrder = pSelectedIndex->GetIndexOrder(false);
1692 Bitmap* pReplacementColorBitmap = null;
1694 TextObject* pTextObject = new (std::nothrow) TextObject();
1695 SysTryCatch(NID_UI_CTRL, pTextObject, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1697 pTextObject->Construct();
1699 for (int i = -1; i < 2; i++)
1701 TextSimple* pSimpleText = null;
1703 _FastScrollIndex* pChildIndex = pBaseIndex->GetChildIndex(selectedOrder + i);
1706 Bitmap* pChildIndexImage = pChildIndex->GetIndexImage();
1707 if (pChildIndexImage)
1709 FloatRectangle imageRect = indexRect;
1710 float scaleFactor = indexRect.width / pChildIndexImage->GetWidthF();
1711 float heightScale = indexRect.height / pChildIndexImage->GetHeightF();
1712 float rectHeight = indexRect.height;
1713 if (rectHeight > __viewConfig.__popupTextSize)
1715 rectHeight = __viewConfig.__popupTextSize;
1718 if (scaleFactor > heightScale)
1720 scaleFactor = heightScale;
1722 imageRect.width = pChildIndexImage->GetWidthF() * scaleFactor;
1723 imageRect.height = pChildIndexImage->GetHeightF() * scaleFactor;
1725 if (indexRect.width - imageRect.width > 0.0f)
1727 imageRect.x = indexRect.x + (indexRect.width - imageRect.width) / 2.0f;
1730 if (indexRect.height - imageRect.height > 0.0f)
1732 imageRect.y = indexRect.y + (indexRect.height - imageRect.height) / 2.0f;
1735 pReplacementColorBitmap =
1736 _BitmapImpl::GetColorReplacedBitmapN(*pChildIndexImage,
1737 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__popupTextColor);
1738 r = DrawBitmap(*pCanvas, imageRect, *pReplacementColorBitmap,
1739 FloatRectangle(0.0f, 0.0f, pChildIndexImage->GetWidthF(), pChildIndexImage->GetHeightF()));
1740 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw a bitmap.", GetErrorMessage(r));
1742 delete pReplacementColorBitmap;
1743 pReplacementColorBitmap = null;
1747 String* pChildIndexText = pChildIndex->GetIndexText();
1748 SysTryCatch(NID_UI_CTRL, pChildIndexText, , E_INVALID_STATE, "[E_INVALID_STATE] pChildIndexText must not be null.");
1750 pTextObject->RemoveAll();
1752 pSimpleText = new (std::nothrow)TextSimple(const_cast<wchar_t*>(pChildIndexText->GetPointer()), pChildIndexText->GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1753 SysTryCatch(NID_UI_CTRL, pSimpleText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1755 r = pTextObject->AppendElement(*pSimpleText);
1756 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to append simple text.", GetErrorMessage(r));
1758 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1759 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set wrap.", GetErrorMessage(r));
1761 r = pTextObject->SetFont(__viewConfig.__pFont, 0, pTextObject->GetTextLength());
1762 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
1764 r = pTextObject->SetForegroundColor(__viewConfig.__popupTextColor, 0, pTextObject->GetTextLength());
1765 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set foreground color.", GetErrorMessage(r));
1767 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1768 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set alignment.", GetErrorMessage(r));
1770 r = pTextObject->SetBounds(indexRect);
1771 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds of pTextObject.", GetErrorMessage(r));
1773 r = pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1774 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw text.", GetErrorMessage(r));
1778 indexRect.y += indexHeight;
1785 delete pReplacementColorBitmap;
1789 _FastScrollPopupView::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
1791 result r = E_SUCCESS;
1792 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1794 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1795 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1799 r = canvas.DrawBitmap(bounds, bitmap);
1800 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1807 _FastScrollPopupView::DrawBitmap(Canvas& canvas, const FloatRectangle& srcRect, const Bitmap& bitmap, const FloatRectangle& dstRect)
1809 result r = E_SUCCESS;
1810 if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1812 r = canvas.DrawNinePatchedBitmap(srcRect, bitmap);
1813 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1817 r = canvas.DrawBitmap(srcRect, bitmap, dstRect);
1818 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1825 _FastScrollPopupView::Construct(void)
1827 result r = E_SUCCESS;
1829 __pPopupVe = new (std::nothrow) _VisualElement();
1830 SysTryCatch(NID_UI_CTRL, __pPopupVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1832 r = __pPopupVe->Construct();
1833 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the popup ve.", GetErrorMessage(r));
1835 __pPopupVe->SetAnimationProvider(this);
1837 r = __pPopupVe->SetSurfaceOpaque(false);
1838 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the popup ve.", GetErrorMessage(r));
1840 __pPopupVe->SetImplicitAnimationEnabled(false);
1842 r = __parentVe.AttachChild(*__pPopupVe);
1843 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the popup ve to the parent.", GetErrorMessage(r));
1845 __pPopupVe->SetShowState(true);
1846 __pPopupVe->SetClipChildrenEnabled(true);
1847 __pPopupVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
1849 __needUpdatePopupVe = true;
1851 __matrixOrigin.SetAsIdentity();
1852 __matrixFadeInStart.SetAsIdentity();
1853 __matrixFadeOutEnd.SetAsIdentity();
1855 _MatrixUtilScale(__matrixFadeInStart, 0.8f, 0.8f, 1.0f);
1856 _MatrixUtilScale(__matrixFadeOutEnd, 0.1f, 0.1f, 1.0f);
1863 __pPopupVe->Destroy();
1870 _FastScrollPresenter::_FastScrollPresenter(_Control& parentCtrl, _FastScroll& fastScroll, bool visibility)
1871 : __parentCtrl(parentCtrl)
1872 , __fastScroll(fastScroll)
1874 , __pViewConfig(null)
1875 , __pFastScrollEvent(null)
1876 , __pFastScrollModel(null)
1879 , __pPopupView(null)
1880 , __focusedIndexLevel(0)
1881 , __pSelectedIndex(null)
1882 , __enableFadeEffect(true)
1883 , __indexCountMax(0)
1886 , __scrollVisibility(visibility)
1887 , __fadeEffectDuration_ms(500)
1891 _FastScrollPresenter::~_FastScrollPresenter(void)
1893 delete __pFastScrollEvent;
1894 __pFastScrollEvent = null;
1896 delete __pFastScrollModel;
1897 __pFastScrollModel = null;
1899 delete __pPopupView;
1900 __pPopupView = null;
1902 RemoveAllIndexViews(false);
1904 delete __pViewConfig;
1905 __pViewConfig = null;
1909 __pCtrlVe->RemoveAllAnimations();
1910 __pCtrlVe->SetAnimationProvider(null);
1914 _FastScrollPresenter*
1915 _FastScrollPresenter::CreateFastScrollPresenterN(_Control& parentCtrl, _FastScroll& fastScroll, bool visibility)
1917 _FastScrollPresenter* pPresenter = new (std::nothrow) _FastScrollPresenter(parentCtrl, fastScroll, visibility);
1918 SysTryReturn(NID_UI_CTRL, pPresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1920 result r = pPresenter->Construct();
1921 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1932 _FastScrollPresenter::SetRootIndex(_FastScrollIndex* pIndex)
1934 result r = E_SUCCESS;
1936 // initialize index views
1937 RemoveAllIndexViews(false);
1939 // initialize the popup view
1942 r = __pPopupView->SetPopupVisibility(false);
1943 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to clear visibility of the popup view.");
1946 r = SetFontInfo(FONT_STYLE_PLAIN, __pViewConfig->__indexTextSize);
1947 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set font.");
1949 // set the root index into _FastScrollModel
1950 r = __pFastScrollModel->SetRootIndex(pIndex);
1951 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the root index into _FastScrollModel");
1953 // add new root index view.
1956 r = AddIndexView(0, *pIndex);
1957 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add the root index view.");
1964 _FastScrollPresenter::GetRootIndex(void) const
1966 return __pFastScrollModel->GetRootIndex();
1970 _FastScrollPresenter::UpdateIndex(void)
1972 result r = E_SUCCESS;
1974 // update the base index of index views
1975 int indexViewCount = GetIndexViewCount();
1976 for (int i = 0; i < indexViewCount; i++)
1978 _FastScrollIndexView* pIndexView = GetIndexView(i);
1979 SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
1981 _FastScrollIndex* pIndex = pIndexView->GetBaseIndex();
1983 if ((pIndex->GetChildCount() > __indexCountMax) && (pIndex->GetIndexType() != FAST_SCROLL_INDEX_TYPE_OMISSION))
1985 r = pIndex->SetOmissionIndex(__indexCountMax);
1986 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set omiited index.");
1989 r = pIndexView->UpdateIndex(true);
1990 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the index view.");
1993 // update the base index of the popup view
1996 r = __pPopupView->UpdateIndex();
1997 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the popup view.");
2004 _FastScrollPresenter::EnableFadeEffect(bool enable)
2006 __enableFadeEffect = enable;
2010 _FastScrollPresenter::IsEnabledFadeEffect(void) const
2012 return __enableFadeEffect;
2016 _FastScrollPresenter::IsOnFadeEffect(void) const
2018 return (__fadeIn || __fadeOut);
2022 _FastScrollPresenter::IsScrollVisible(void) const
2024 return (__fadeIn || __fadeOut || __scrollVisibility);
2028 _FastScrollPresenter::SetScrollVisibility(bool visibility)
2030 result r = E_SUCCESS;
2032 if (GetScrollVisibility() == visibility)
2034 // keep up current visibility.
2038 if (visibility == false && __pSelectedIndex != null)
2043 __pCtrlVe->RemoveAllAnimations();
2046 if (__enableFadeEffect)
2051 __pCtrlVe->SetImplicitAnimationEnabled(true);
2054 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_ON);
2056 if (__enableFadeEffect)
2058 __pCtrlVe->SetImplicitAnimationEnabled(false);
2068 if (__enableFadeEffect)
2073 __pCtrlVe->SetImplicitAnimationEnabled(true);
2076 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
2078 if (__enableFadeEffect)
2080 __pCtrlVe->SetImplicitAnimationEnabled(false);
2089 __scrollVisibility = visibility;
2095 _FastScrollPresenter::GetScrollVisibility(void) const
2097 float opacity = __pCtrlVe->GetOpacity();
2099 if (__enableFadeEffect)
2101 if (__scrollVisibility)
2106 else if (opacity > FASTSCROLL_OPACITY_OFF)
2115 _FastScrollPresenter::CancelFadeEffect(void)
2120 __scrollVisibility = false;
2121 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
2126 __scrollVisibility = true;
2127 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_ON);
2132 _FastScrollPresenter::AddFastScrollEventListener(const Controls::_IUiFastScrollListener& listener)
2134 result r = E_SUCCESS;
2136 if (__pFastScrollEvent == null)
2138 __pFastScrollEvent = new (std::nothrow) _UiFastScrollEvent();
2139 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollEvent, E_OUT_OF_MEMORY,
2140 "[E_OUT_OF_MEMORY] Memory allocation failed.");
2142 r = __pFastScrollEvent->Construct(__fastScroll);
2143 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2146 r = __pFastScrollEvent->AddListener(listener);
2147 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2151 _FastScrollPresenter::RemoveFastScrollEventListener(const Controls::_IUiFastScrollListener& listener)
2153 result r = E_SUCCESS;
2155 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollEvent, E_INVALID_STATE, "[E_INVALID_STATE] __pFastScrollEvent must not be null.");
2157 r = __pFastScrollEvent->RemoveListener(listener);
2158 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2162 _FastScrollPresenter::OnParentBoundsChanged(void)
2164 RelayoutFastScrollChildren();
2168 _FastScrollPresenter::OnDraw(void)
2171 int indexViewCount = GetIndexViewCount();
2172 for (int i = 0; i < indexViewCount; i++)
2174 _FastScrollIndexView* pIndexView = GetIndexView(i);
2175 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2176 GetErrorMessage(GetLastResult()));
2178 result r = SetFontInfo(FONT_STYLE_PLAIN, __pViewConfig->__indexTextSize);
2179 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set font.", GetErrorMessage(r));
2180 pIndexView->OnDraw();
2182 // draw the popup view
2183 if (__pPopupView && i <= __focusedIndexLevel)
2185 r = SetFontInfo(FONT_STYLE_PLAIN, __pViewConfig->__popupTextSize);
2186 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set font.", GetErrorMessage(r));
2187 __pPopupView->OnDraw(i, pIndexView->GetBaseIndex(), pIndexView->GetSelectedIndexInOmittedIndex());
2193 __pPopupView->SetPopupVeUpdateNeeded(false);
2198 _FastScrollPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2200 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2201 return OnTouchPressedAndMoved(touchedPosition, true);
2205 _FastScrollPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2207 return OnTouchReleasedAndCanceled();
2211 _FastScrollPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
2213 FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2214 return OnTouchPressedAndMoved(touchedPosition, false);
2218 _FastScrollPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
2220 return OnTouchReleasedAndCanceled();
2224 _FastScrollPresenter::OnFontChanged(Font* pFont)
2226 __pViewConfig->__pFont = pFont;
2230 _FastScrollPresenter::OnFontInfoRequested(unsigned long& style, float& size)
2232 style = __fontStyle;
2237 _FastScrollPresenter::SetFontInfo(unsigned long style, float size)
2239 __fontStyle = style;
2242 __pViewConfig->__pFont = __fastScroll.GetFallbackFont();
2243 SysTryReturnResult(NID_UI_CTRL, __pViewConfig->__pFont, GetLastResult(), "Failed to get a font.");
2248 VisualElementAnimation*
2249 _FastScrollPresenter::CreateAnimationForProperty(VisualElement& target, const String& property)
2251 VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
2255 const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
2256 if (pTimingFunction)
2258 pAnimation->SetTimingFunction(pTimingFunction);
2260 pAnimation->SetVisualElementAnimationStatusEventListener(this);
2266 _FastScrollPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
2271 _FastScrollPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
2276 _FastScrollPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
2278 if (__pCtrlVe == (static_cast <_VisualElement*>(&target)))
2286 _FastScrollPresenter::HitTest(const Tizen::Graphics::FloatPoint& point)
2288 if (IsScrollVisible() == false)
2290 return HIT_TEST_NOWHERE;
2293 int indexViewCount = GetIndexViewCount();
2294 for (int i = 0; i < indexViewCount; i++)
2296 _FastScrollIndexView* pIndexView = GetIndexView(i);
2297 SysTryReturn(NID_UI_CTRL, pIndexView, HIT_TEST_NOWHERE, GetLastResult(), "[%s] Failed to get the index view.",
2298 GetErrorMessage(GetLastResult()));
2300 FloatRectangle indexBounds = pIndexView->GetIndexBoundsF();
2301 if (indexBounds.Contains(point) == true)
2303 return HIT_TEST_MATCH;
2307 return HIT_TEST_NOWHERE;
2311 _FastScrollPresenter::OnIndexDataUpdated(_FastScrollIndex& updatedIndex)
2313 result r = E_SUCCESS;
2315 int indexViewCount = GetIndexViewCount();
2316 for (int i = 0; i < indexViewCount; i++)
2318 _FastScrollIndexView* pIndexView = GetIndexView(i);
2319 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2320 GetErrorMessage(GetLastResult()));
2322 if (pIndexView->GetBaseIndex() == &updatedIndex)
2324 r = pIndexView->UpdateIndex(false);
2325 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2329 r = __pPopupView->UpdateIndex();
2330 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update the popup view.", GetErrorMessage(r));
2338 _FastScrollPresenter::OnIndexDeleted(_FastScrollIndex& deletedIndex)
2340 result r = E_SUCCESS;
2342 int indexViewCount = GetIndexViewCount();
2343 for (int i = 0; i < indexViewCount; i++)
2345 _FastScrollIndexView* pIndexView = GetIndexView(i);
2346 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2347 GetErrorMessage(GetLastResult()));
2349 if (pIndexView->GetBaseIndex() == &deletedIndex)
2351 // first of all, update the base index view
2354 _FastScrollIndexView* pBaseIndexView = GetIndexView(i - 1);
2355 SysTryReturnVoidResult(NID_UI_CTRL, pBaseIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2356 GetErrorMessage(GetLastResult()));
2358 r = pBaseIndexView->UpdateIndex(false);
2359 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2362 // then remove the index view for detached index.
2363 RemoveIndexView(i, true);
2365 delete __pPopupView;
2366 __pPopupView = null;
2370 else if (pIndexView->GetBaseIndex() == deletedIndex.GetParentIndex())
2372 r = pIndexView->UpdateIndex(false);
2373 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2375 r = __pPopupView->UpdateIndex();
2376 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update popup view.", GetErrorMessage(r));
2382 _FastScrollPresenter::OnChildIndexAttached(_FastScrollIndex& parentIndex, int attachedOrder, _FastScrollIndex& attachedIndex)
2384 result r = E_SUCCESS;
2386 int indexViewCount = GetIndexViewCount();
2387 for (int i = 0; i < indexViewCount; i++)
2389 _FastScrollIndexView* pIndexView = GetIndexView(i);
2390 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2391 GetErrorMessage(GetLastResult()));
2393 if (pIndexView->GetBaseIndex() == &parentIndex)
2395 r = pIndexView->UpdateIndex(false);
2396 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2398 r = __pPopupView->UpdateIndex();
2399 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update popup view.", GetErrorMessage(r));
2406 _FastScrollPresenter::OnChildIndexDetached(_FastScrollIndex& parentIndex, int detachedOrder, _FastScrollIndex& detachedIndex)
2408 result r = E_SUCCESS;
2410 int indexViewCount = GetIndexViewCount();
2411 for (int i = 0; i < indexViewCount; i++)
2413 _FastScrollIndexView* pIndexView = GetIndexView(i);
2414 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2415 GetErrorMessage(GetLastResult()));
2417 if (pIndexView->GetBaseIndex() == &detachedIndex)
2419 // first of all, update the base index view
2422 _FastScrollIndexView* pBaseIndexView = GetIndexView(i - 1);
2423 SysTryReturnVoidResult(NID_UI_CTRL, pBaseIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2424 GetErrorMessage(GetLastResult()));
2426 r = pBaseIndexView->UpdateIndex(false);
2427 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2430 // then remove the index view for detached index.
2431 RemoveIndexView(i, true);
2433 delete __pPopupView;
2434 __pPopupView = null;
2437 else if (pIndexView->GetBaseIndex() == &parentIndex)
2439 r = pIndexView->UpdateIndex(false);
2440 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2442 r = __pPopupView->UpdateIndex();
2443 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update popup view.", GetErrorMessage(r));
2450 _FastScrollPresenter::Construct(void)
2452 result r = E_SUCCESS;
2454 // load color/shape configuration and bitmap resources
2455 __pViewConfig = _FastScrollViewConfig::CreateFastScrollViewConfigN(_CONTROL_ORIENTATION_PORTRAIT);
2456 SysTryReturnResult(NID_UI_CTRL, __pViewConfig, GetLastResult(), "Failed to create _FastScrollViewConfig.");
2458 // create _FastScrollModel
2459 __pFastScrollModel = _FastScrollModel::CreateFastScrollModelN();
2460 SysTryCatch(NID_UI_CTRL, __pFastScrollModel, , GetLastResult(), "[%s] Failed to create _FastScrollModel.",
2461 GetErrorMessage(GetLastResult()));
2463 // initialize visual elements
2464 __pCtrlVe = __fastScroll.GetVisualElement();
2465 SysTryCatch(NID_UI_CTRL, __pCtrlVe, , GetLastResult(), "[%s] Failed to get VisualElement of the _FastScroll",
2466 GetErrorMessage(GetLastResult()));
2468 __pCtrlVe->SetAnimationProvider(this);
2469 __pCtrlVe->SetClipChildrenEnabled(false);
2471 if (__scrollVisibility)
2473 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_ON);
2477 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
2480 // initialize the fastscroll control
2481 r = __fastScroll.SetBounds(CalculateFastScrollBounds(0));
2482 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the bounds of _FastScroll", GetErrorMessage(r));
2484 __fastScroll.SetBackgroundColor(Tizen::Graphics::Color(0, 0, 0, 0));
2486 __indexCountMax = _CoordinateSystemUtils::ConvertToInteger((__fastScroll.GetBoundsF().height -
2487 (__pViewConfig->__indexMarginTop * 2.0f)) / __pViewConfig->__indexSizeMin.height);
2492 delete __pFastScrollModel;
2493 __pFastScrollModel = null;
2495 delete __pViewConfig;
2496 __pViewConfig = null;
2498 return GetLastResult();
2502 _FastScrollPresenter::CalculateFastScrollBounds(int indexCount)
2504 FloatRectangle fastScrollBounds(0.0f, 0.0f, 0.0f, 0.0f);
2505 FloatRectangle parentBounds = __parentCtrl.GetBoundsF();
2506 fastScrollBounds.width = parentBounds.width;
2507 fastScrollBounds.height = parentBounds.height;
2508 return fastScrollBounds;
2512 _FastScrollPresenter::CalculateIndexBounds(int indexLevel, _FastScrollIndex& pIndex)
2514 FloatRectangle fastScrollBounds = __fastScroll.GetBoundsF();
2515 FloatRectangle indexBounds(0.0f, 0.0f, __pViewConfig->__indexSizeMin.width, fastScrollBounds.height);
2517 indexBounds.x = fastScrollBounds.width - __pViewConfig->__indexSizeMin.width;
2518 for (int i = 1; i <= indexLevel; i++)
2520 indexBounds.x -= __pViewConfig->__indexGap + __pViewConfig->__indexSizeMin.width;
2523 if (indexBounds.x < 0.0f)
2525 indexBounds.x = 0.0f;
2528 if (indexLevel != 0)
2530 int childCount = pIndex.GetChildCount();
2531 indexBounds.height = (childCount * __pViewConfig->__indexSizeMin.height) + (__pViewConfig->__indexMarginTop * 2.0f);
2533 if (indexBounds.height < fastScrollBounds.height)
2535 _FastScrollIndexView* pParentIndexView = GetIndexView(indexLevel - 1);
2536 if (pParentIndexView)
2538 FloatRectangle parentBounds = pParentIndexView->GetIndexBoundsF();
2540 indexBounds.y = parentBounds.y + (pIndex.GetIndexOrder() * pParentIndexView->GetIndexHeight()) - __pViewConfig->__indexMarginTop;
2541 if (indexBounds.y < fastScrollBounds.y)
2543 indexBounds.y = fastScrollBounds.y;
2546 float totalHeight = indexBounds.y + indexBounds.height;
2547 if (_FloatCompare(totalHeight, fastScrollBounds.height) || (totalHeight > fastScrollBounds.height))
2549 indexBounds.y = fastScrollBounds.height - indexBounds.height;
2555 indexBounds.height = fastScrollBounds.height;
2563 _FastScrollPresenter::CalculatePopupBounds(void)
2565 FloatRectangle popupBounds(0.0f, 0.0f, 0.0f, 0.0f);
2566 FloatRectangle parentBounds = __parentCtrl.GetBoundsF();
2567 FloatRectangle fastScrollBounds = __fastScroll.GetBoundsF();
2569 popupBounds.width = __pViewConfig->__popupSize.width + (__pViewConfig->__popupWidthIncrement * __focusedIndexLevel);
2570 if (popupBounds.width > parentBounds.width)
2572 popupBounds.width = parentBounds.width;
2575 popupBounds.height = __pViewConfig->__popupSize.height;
2576 if (popupBounds.height > parentBounds.height)
2578 popupBounds.height = parentBounds.height;
2581 popupBounds.x = ((parentBounds.width - popupBounds.width) / 2.0f) - fastScrollBounds.x;
2582 if (popupBounds.x < 0.0f)
2584 popupBounds.x = 0.0f;
2587 popupBounds.y = ((parentBounds.height - popupBounds.height) / 2.0f) - fastScrollBounds.y;
2588 if (popupBounds.y < 0.0f)
2590 popupBounds.y = 0.0f;
2597 _FastScrollPresenter::RelayoutFastScrollChildren(void)
2599 result r = E_SUCCESS;
2601 int indexViewCount = GetIndexViewCount();
2603 // initialize the fastscroll control
2604 r = __fastScroll.SetBounds(CalculateFastScrollBounds(indexViewCount));
2605 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set the bounds of _FastScroll", GetErrorMessage(r));
2607 __indexCountMax = _CoordinateSystemUtils::ConvertToInteger((__fastScroll.GetBoundsF().height -
2608 (__pViewConfig->__indexMarginTop * 2.0f)) / __pViewConfig->__indexSizeMin.height);
2610 for (int i = 0; i < indexViewCount; i++)
2612 _FastScrollIndexView* pIndexView = GetIndexView(i);
2613 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2614 GetErrorMessage(GetLastResult()));
2616 r = pIndexView->SetIndexBounds(CalculateIndexBounds(i, *(pIndexView->GetBaseIndex())));
2617 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set bounds of the index.", GetErrorMessage(r));
2619 _FastScrollIndex* pIndex = pIndexView->GetBaseIndex();
2620 if (pIndex->GetIndexType() == FAST_SCROLL_INDEX_TYPE_OMISSION)
2622 _FastScrollIndex* pSelectedIndex = pIndexView->GetSelectedIndex();
2623 if (pSelectedIndex && pSelectedIndex->GetOmitted())
2625 pIndexView->SetSelectedIndex(null);
2627 r = pIndex->RemoveOmissionChildren(false);
2628 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to remove omission index view", GetErrorMessage(r));
2631 if (pIndex->GetChildCount() > __indexCountMax)
2633 r = pIndex->SetOmissionIndex(__indexCountMax);
2634 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set omission index.", GetErrorMessage(r));
2637 r = pIndexView->UpdateIndex(false);
2638 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2643 r = __pPopupView->SetPopupBounds(CalculatePopupBounds());
2644 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set bounds of the popup view.", GetErrorMessage(r));
2649 _FastScrollPresenter::SelectOnIndexViews(const FloatPoint& point, bool animation)
2651 result r = E_SUCCESS;
2653 _FastScrollIndex* pSelectedIndex = null;
2654 int selectedIndexLevel = 0;
2655 int indexViewCount = GetIndexViewCount();
2656 SysTryReturn(NID_UI_CTRL, indexViewCount > 0, null, E_INVALID_STATE, "[E_INVALID_STATE] The root index view is invalid state.");
2658 // search the hit index on index views, then fade out other index views
2659 for (int i = 0; i < indexViewCount; i++)
2661 _FastScrollIndexView* pIndexView = GetIndexView(i);
2662 SysTryReturn(NID_UI_CTRL, pIndexView, null, GetLastResult(), "[%s] Failed to get the index view.",
2663 GetErrorMessage(GetLastResult()));
2665 _FastScrollIndex* pIndex = pIndexView->GetIndexAtPoint(point);
2668 // select the index of the index view.
2669 r = pIndexView->SelectIndex(pIndex, animation);
2670 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to select the index.", GetErrorMessage(r));
2671 pSelectedIndex = pIndex;
2672 if (pIndex->GetOmitted() == true)
2674 pSelectedIndex = pIndexView->GetOmissionIndexAtPoint(pIndex, point);
2676 pIndexView->SetSelectedIndexInOmittedIndex(pSelectedIndex);
2678 selectedIndexLevel = i;
2683 // if can no find the index on views, select index of the last index view
2684 if ((pSelectedIndex == null) && (__focusedIndexLevel != -1))
2686 _FastScrollIndexView* pFocusedIndexView = GetIndexView(__focusedIndexLevel);
2687 SysTryReturn(NID_UI_CTRL, pFocusedIndexView, null, GetLastResult(), "[%s] Failed to get the index view.",
2688 GetErrorMessage(GetLastResult()));
2690 _FastScrollIndex* pIndex = pFocusedIndexView->GetIndexAtPoint(FloatPoint(pFocusedIndexView->GetIndexBoundsF().x, point.y));
2693 // select the index of the focused index view.
2694 r = pFocusedIndexView->SelectIndex(pIndex, animation);
2695 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to select the index.", GetErrorMessage(r));
2696 pSelectedIndex = pIndex;
2698 if (pIndex->GetOmitted() == true)
2700 pSelectedIndex = pFocusedIndexView->GetOmissionIndexAtPoint(pIndex,
2701 FloatPoint(pFocusedIndexView->GetIndexBoundsF().x, point.y));
2703 pFocusedIndexView->SetSelectedIndexInOmittedIndex(pSelectedIndex);
2705 selectedIndexLevel = __focusedIndexLevel;
2709 pSelectedIndex = pFocusedIndexView->GetSelectedIndex();
2710 selectedIndexLevel = __focusedIndexLevel;
2716 int childCount = pSelectedIndex->GetChildCount();
2719 _FastScrollIndexView* pSelectedIndexView = GetIndexView(selectedIndexLevel + 1);
2720 if (pSelectedIndexView)
2722 r = pSelectedIndexView->SelectIndex((_FastScrollIndex*)null, false);
2723 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to select the index.", GetErrorMessage(r));
2725 r = pSelectedIndexView->SetBaseIndex(pSelectedIndex);
2726 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set the base index of the index view.", GetErrorMessage(r));
2728 r = pSelectedIndexView->SetIndexBounds(CalculateIndexBounds(selectedIndexLevel + 1, *pSelectedIndex));
2729 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set bounds of the index.", GetErrorMessage(r));
2731 r = pSelectedIndexView->SetIndexVisibility(true);
2732 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set the visibility of the index view.", GetErrorMessage(r));
2734 indexViewCount = GetIndexViewCount();
2735 while (indexViewCount > selectedIndexLevel + 2)
2737 r = RemoveIndexView(indexViewCount - 1, true);
2738 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to remove the index view.", GetErrorMessage(r));
2739 indexViewCount = GetIndexViewCount();
2744 r = AddIndexView(*pSelectedIndex);
2745 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to add new child index.", GetErrorMessage(r));
2748 if ((childCount > __indexCountMax) && (pSelectedIndex->GetIndexType() != FAST_SCROLL_INDEX_TYPE_OMISSION))
2750 r = pSelectedIndex->SetOmissionIndex(__indexCountMax);
2751 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set omission index.", GetErrorMessage(r));
2756 indexViewCount = GetIndexViewCount();
2757 while (indexViewCount > selectedIndexLevel + 1)
2759 r = RemoveIndexView(indexViewCount - 1, true);
2760 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to remove the index view.", GetErrorMessage(r));
2761 indexViewCount = GetIndexViewCount();
2767 indexViewCount = GetIndexViewCount();
2768 while (indexViewCount > 1)
2770 r = RemoveIndexView(indexViewCount - 1, true);
2771 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to remove the index view.", GetErrorMessage(r));
2772 indexViewCount = GetIndexViewCount();
2776 __focusedIndexLevel = selectedIndexLevel;
2777 return pSelectedIndex;
2781 _FastScrollPresenter::DeselectIndexViews(void)
2783 result r = E_SUCCESS;
2785 while (GetIndexViewCount() > 1)
2787 RemoveIndexView(GetIndexViewCount() - 1, true);
2790 _FastScrollIndexView* pIndexView = GetIndexView(0);
2791 SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
2793 r = pIndexView->SelectIndex((_FastScrollIndex*)null, true);
2794 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to clear the index selection.");
2795 pIndexView->SetSelectedIndexInOmittedIndex(null);
2797 __fastScroll.Invalidate();
2803 _FastScrollPresenter::SetPopupIndex(_FastScrollIndex& popupIndex, const FloatPoint& point)
2805 result r = E_SUCCESS;
2807 // set the selected node into the popup views.
2808 if (__pPopupView == null)
2810 __pPopupView = _FastScrollPopupView::CreateFastScrollPopupViewN(*__pCtrlVe, *__pViewConfig);
2811 SysTryReturnResult(NID_UI_CTRL, __pPopupView, GetLastResult(), "Propagating.");
2813 r = __pPopupView->SetPopupBounds(CalculatePopupBounds());
2814 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the popup view.");
2816 r = __pPopupView->SetPopupVisibility(true);
2817 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the popup view.");
2820 int indexViewCount = __focusedIndexLevel + 1;
2821 int popupIndexViewCount = __pPopupView->GetIndexVeCount();
2823 if (indexViewCount != popupIndexViewCount)
2825 r = __pPopupView->SetPopupBounds(CalculatePopupBounds());
2826 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the popup view.");
2828 if (indexViewCount > popupIndexViewCount)
2830 for (int i = popupIndexViewCount; i < indexViewCount; i++)
2832 r = __pPopupView->AddPopupIndexVe(i);
2833 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add popup index ve.");
2836 else if (indexViewCount < popupIndexViewCount)
2838 for (int i = indexViewCount; i < popupIndexViewCount; i++)
2840 r = __pPopupView->RemovePopupIndexVe(i);
2841 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove popup index ve.");
2846 r = __pPopupView->UpdateIndex();
2847 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the popup view.");
2849 for (int i = 0; i < indexViewCount; i++)
2851 _FastScrollIndexView* pIndexView = GetIndexView(i);
2852 SysTryReturnResult(NID_UI_CTRL, pIndexView, r, "Failed to index view.");
2854 r = __pPopupView->SetPopupIndexBounds(i, pIndexView->GetBaseIndex());
2855 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the popup index ve.");
2857 _FastScrollIndex* pFormerIndex = null;
2858 if ( i == __focusedIndexLevel )
2860 pFormerIndex = pIndexView->GetFormerIndex();
2861 r = __pPopupView->SelectIndex(i, &popupIndex, pFormerIndex);
2862 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to select the popup index.");
2866 r = __pPopupView->SelectIndex(i, null, null);
2867 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to select the popup index.");
2875 _FastScrollPresenter::ClearPopupIndex(void)
2877 result r = E_SUCCESS;
2879 // clear the node data of the popup view
2882 r = __pPopupView->FadeOutAndDestroy();
2883 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to clear visibility of the popup view.");
2885 __pPopupView = null;
2892 _FastScrollPresenter::FireFastScrollEvent(_FastScrollIndex& selectedIndex)
2894 // fire the fast scroll event
2895 if (__pFastScrollEvent)
2897 String* pIndexNodeText = selectedIndex.GetIndexText();
2900 _UiFastScrollEventArg* pEventArg = new (std::nothrow) _UiFastScrollEventArg(*__pFastScrollEvent->GetSource(), selectedIndex);
2901 SysTryReturnResult(NID_UI_CTRL, pEventArg, E_OUT_OF_MEMORY, "Memory allocation failed.");
2903 __pFastScrollEvent->Fire(*pEventArg);
2911 _FastScrollPresenter::OnTouchPressedAndMoved(const FloatPoint& point, bool animation)
2913 result r = E_SUCCESS;
2914 if (__scrollVisibility == false)
2916 r = SetScrollVisibility(true);
2917 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to fade out fastscroll.", GetErrorMessage(r));
2920 _FastScrollIndex* pSelectedIndex = SelectOnIndexViews(point, animation);
2921 if (pSelectedIndex && (__pSelectedIndex != pSelectedIndex))
2923 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP);
2924 r = SetPopupIndex(*pSelectedIndex, point);
2925 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to set the poup index.", GetErrorMessage(r));
2927 r = FireFastScrollEvent(*pSelectedIndex);
2928 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to send the fast scroll event.", GetErrorMessage(r));
2931 __pSelectedIndex = pSelectedIndex;
2937 _FastScrollPresenter::OnTouchReleasedAndCanceled(void)
2939 result r = E_SUCCESS;
2941 r = DeselectIndexViews();
2942 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to deselect index views.", GetErrorMessage(r));
2944 r = ClearPopupIndex();
2945 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to clear the popup index.", GetErrorMessage(r));
2947 __pSelectedIndex = null;
2948 if (__scrollVisibility == true)
2950 r = SetScrollVisibility(false);
2951 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to fade out fastscroll.", GetErrorMessage(r));
2958 _FastScrollPresenter::AddIndexView(_FastScrollIndex& baseIndex)
2960 return AddIndexView(GetIndexViewCount(), baseIndex);
2964 _FastScrollPresenter::AddIndexView(int indexLevel, _FastScrollIndex& baseIndex)
2966 result r = E_SUCCESS;
2968 _FastScrollIndexView* pNewIndexView = _FastScrollIndexView::CreateFastScrollIndexViewN( *__pCtrlVe, *__pViewConfig);
2969 SysTryReturnResult(NID_UI_CTRL, pNewIndexView, GetLastResult(), "Propagating.");
2971 r = __fastScroll.SetBounds(CalculateFastScrollBounds(GetIndexViewCount() + 1));
2972 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _FastScroll.");
2974 r = pNewIndexView->SetIndexBounds(CalculateIndexBounds(indexLevel, baseIndex));
2975 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the index view.");
2977 r = pNewIndexView->SetBaseIndex(&baseIndex);
2978 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the index data for the index view.");
2980 r = pNewIndexView->SetIndexVisibility(true);
2981 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the index view.");
2983 r = __indexViews.InsertAt(*pNewIndexView, indexLevel);
2984 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to change the last index view.");
2990 _FastScrollPresenter::RemoveIndexView(int indexLevel, bool fadeout)
2992 result r = E_SUCCESS;
2994 int indexViewCount = GetIndexViewCount();
2995 if (indexLevel < indexViewCount)
2997 _FastScrollIndexView* pIndexView = GetIndexView(indexLevel);
2998 SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
3002 r = pIndexView->FadeOutAndDestroy();
3003 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to request to fade out of the index view.");
3006 r = __indexViews.Remove(*pIndexView, false);
3007 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove the index views.");
3009 // initialize the fastscroll control
3010 r = __fastScroll.SetBounds(CalculateFastScrollBounds(GetIndexViewCount()));
3011 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _FastScroll");
3018 _FastScrollPresenter::RemoveAllIndexViews(bool fadeout)
3020 result r = E_SUCCESS;
3024 int indexViewCount = GetIndexViewCount();
3025 for (int i = 0; i < indexViewCount; i++)
3027 _FastScrollIndexView* pIndexView = GetIndexView(i);
3028 SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
3030 r = pIndexView->FadeOutAndDestroy();
3031 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to request to fade out of the index view.");
3035 __indexViews.RemoveAll(true);
3037 // initialize the fastscroll control
3038 r = __fastScroll.SetBounds(CalculateFastScrollBounds(0));
3039 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _FastScroll.");
3044 _FastScrollIndexView*
3045 _FastScrollPresenter::GetIndexView(int indexLevel) const
3047 Object* pIndexView = const_cast<Object*>(__indexViews.GetAt(indexLevel));
3048 SysTryReturn(NID_UI_CTRL, pIndexView, null, GetLastResult(), "[%s] Failed to get the index view.",
3049 GetErrorMessage(GetLastResult()));
3051 return dynamic_cast<_FastScrollIndexView*>(pIndexView);
3055 _FastScrollPresenter::GetIndexViewCount(void) const
3057 return __indexViews.GetCount();
3060 } } } // Tizen::Ui::Controls