Changed indicator bg color.
[platform/framework/native/uifw.git] / src / ui / controls / FUiCtrl_FastScrollPresenter.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0/
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FUiCtrl_FastScrollPresenter.cpp
20  * @brief               This is the implementation file for the _FastScrollPresenter class.
21  */
22 #include <wchar.h>
23 #include <FBaseErrors.h>
24 #include <FBaseString.h>
25
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"
45 #include "FUi_Math.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"
53
54 #include "FUiAnim_MatrixUtil.h"
55
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;
61
62 namespace
63 {
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;
69 }
70
71 namespace Tizen { namespace Ui { namespace Controls
72 {
73
74 _FastScrollViewConfig::_FastScrollViewConfig(void)
75         : __indexBgColor(Color::GetColor(COLOR_ID_BLACK))
76         , __indexHighlightColor(Color::GetColor(COLOR_ID_BLACK))
77         , __indexLineColor(Color::GetColor(COLOR_ID_BLACK))
78         , __indexSelectedLineColor(Color::GetColor(COLOR_ID_BLACK))
79         , __indexTextColor(Color::GetColor(COLOR_ID_BLACK))
80         , __indexDividerColor(Color::GetColor(COLOR_ID_BLACK))
81         , __selectedIndexBgColor(Color::GetColor(COLOR_ID_BLACK))
82         , __selectedIndexTextColor(Color::GetColor(COLOR_ID_BLACK))
83         , __popupBgColor(Color::GetColor(COLOR_ID_BLACK))
84         , __popupTextColor(Color::GetColor(COLOR_ID_BLACK))
85         , __indexSizeMin(0.0f, 0.0f)
86         , __popupSize(0.0f, 0.0f)
87         , __indexMarginTop(0.0f)
88         , __indexGap(0.0f)
89         , __indexLeftLineThickness(0.0f)
90         , __indexTextSize(0.0f)
91         , __indexSeparatorThickness(0.0f)
92         , __indexSeparatorWidth(0.0f)
93         , __selectedIndexMarginRight(0.0f)
94         , __selectedIndexHeight(0.0f)
95         , __popupWidthIncrement(0.0f)
96         , __popupTextSize(0.0f)
97         , __popupShadowRight(0.0f)
98         , __popupShadowBottom(0.0f)
99         , __pIndexBgBitmap(null)
100         , __pSelectedIndexBgBitmap(null)
101         , __pSelectedIndexlineBitmap(null)
102         , __pPopupBgBitmap(null)
103         , __pPopupBgEffectBitmap(null)
104         , __pFont(null)
105         , __ignoreTouchEvent(false)
106 {
107 }
108
109 _FastScrollViewConfig::~_FastScrollViewConfig(void)
110 {
111         ReleaseResources();
112 }
113
114 _FastScrollViewConfig*
115 _FastScrollViewConfig::CreateFastScrollViewConfigN(_ControlOrientation orientation)
116 {
117         _FastScrollViewConfig* pConfig = new (std::nothrow) _FastScrollViewConfig();
118         SysTryReturn(NID_UI_CTRL, pConfig, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
119
120         result r = pConfig->Construct(orientation);
121         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
122
123         SetLastResult(E_SUCCESS);
124         return pConfig;
125
126 CATCH:
127         delete pConfig;
128
129         return null;
130 }
131
132 result
133 _FastScrollViewConfig::ReloadConfig(_ControlOrientation orientation)
134 {
135         result r = E_SUCCESS;
136
137         // release allocated resources.
138         ReleaseResources();
139
140         // load bitmap resources
141         r = GET_BITMAP_CONFIG_N(FASTSCROLL::INDEX_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pIndexBgBitmap);
142         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
143
144         r = GET_BITMAP_CONFIG_N(FASTSCROLL::INDEX_BG_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pSelectedIndexBgBitmap);
145         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
146
147         r = GET_BITMAP_CONFIG_N(FASTSCROLL::INDEX_LINE_PRESSED, BITMAP_PIXEL_FORMAT_ARGB8888, __pSelectedIndexlineBitmap);
148         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
149
150         r = GET_BITMAP_CONFIG_N(FASTSCROLL::POPUP_BG_NORMAL, BITMAP_PIXEL_FORMAT_ARGB8888, __pPopupBgBitmap);
151         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
152
153         r = GET_BITMAP_CONFIG_N(FASTSCROLL::POPUP_BG_EFFECT, BITMAP_PIXEL_FORMAT_ARGB8888, __pPopupBgEffectBitmap);
154         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to load image.");
155
156
157         // load shape configuration
158         r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __indexSizeMin.width);
159         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
160
161         r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __indexSizeMin.height);
162         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
163
164         r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_TOP_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __indexMarginTop);
165         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
166
167         r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_LEFT_LINE_THICKNESS, _CONTROL_ORIENTATION_PORTRAIT, __indexLeftLineThickness);
168         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
169
170         r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __indexTextSize);
171         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
172
173         r = GET_FIXED_VALUE_CONFIG(FASTSCROLL::INDEX_SEPARATOR_THICKNESS, _CONTROL_ORIENTATION_PORTRAIT, __indexSeparatorThickness);
174         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
175
176         r = GET_SHAPE_CONFIG(FASTSCROLL::INDEX_SEPARATOR_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __indexSeparatorWidth);
177         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
178
179         r = GET_SHAPE_CONFIG(FASTSCROLL::SELECTED_INDEX_RIGHT_MARGIN, _CONTROL_ORIENTATION_PORTRAIT, __selectedIndexMarginRight);
180         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
181
182         r = GET_SHAPE_CONFIG(FASTSCROLL::SELECTED_INDEX_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __selectedIndexHeight);
183         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
184
185         r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_WIDTH, _CONTROL_ORIENTATION_PORTRAIT, __popupSize.width);
186         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
187
188         r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_HEIGHT, _CONTROL_ORIENTATION_PORTRAIT, __popupSize.height);
189         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
190
191         r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_WIDTH_INCREMENT, _CONTROL_ORIENTATION_PORTRAIT, __popupWidthIncrement);
192         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
193
194         r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_TEXT_SIZE, _CONTROL_ORIENTATION_PORTRAIT, __popupTextSize);
195         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
196
197         r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_RIGHT_SHADOW, _CONTROL_ORIENTATION_PORTRAIT, __popupShadowRight);
198         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
199
200         r = GET_SHAPE_CONFIG(FASTSCROLL::POPUP_BOTTOM_SHADOW, _CONTROL_ORIENTATION_PORTRAIT, __popupShadowBottom);
201         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
202
203
204         // load color configuration
205         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_BG_NORMAL, __indexBgColor);
206         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
207
208         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_LINE_NORMAL, __indexLineColor);
209         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
210
211         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_LINE_PRESSED, __indexSelectedLineColor);
212         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
213
214         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_TEXT_NORMAL, __indexTextColor);
215         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
216
217         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_DIVIDER_NORMAL, __indexDividerColor);
218         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
219
220         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_BG_PRESSED, __selectedIndexBgColor);
221         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
222
223         r = GET_COLOR_CONFIG(FASTSCROLL::INDEX_TEXT_PRESSED, __selectedIndexTextColor);
224         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
225
226         r = GET_COLOR_CONFIG(FASTSCROLL::POPUP_BG_NORMAL, __popupBgColor);
227         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
228
229         r = GET_COLOR_CONFIG(FASTSCROLL::POPUP_TEXT_NORMAL, __popupTextColor);
230         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , E_SYSTEM, "[E_SYSTEM] Failed to get resource.");
231
232         return E_SUCCESS;
233
234 CATCH:
235         __indexBgColor = Color::GetColor(COLOR_ID_BLACK);
236         __indexHighlightColor = Color::GetColor(COLOR_ID_BLACK);
237         __indexLineColor= Color::GetColor(COLOR_ID_BLACK);
238         __indexSelectedLineColor= Color::GetColor(COLOR_ID_BLACK);
239         __indexTextColor = Color::GetColor(COLOR_ID_BLACK);
240         __indexDividerColor= Color::GetColor(COLOR_ID_BLACK);
241         __selectedIndexBgColor = Color::GetColor(COLOR_ID_BLACK);
242         __selectedIndexTextColor = Color::GetColor(COLOR_ID_BLACK);
243         __popupBgColor = Color::GetColor(COLOR_ID_BLACK);
244         __popupTextColor = Color::GetColor(COLOR_ID_BLACK);
245
246         __indexSizeMin.SetSize(0.0f, 0.0f);
247         __popupSize.SetSize(0.0f, 0.0f);
248
249         __indexMarginTop = 0.0f;
250         __indexGap = 0.0f;
251         __indexLeftLineThickness = 0.0f;
252         __indexTextSize = 0.0f;
253         __indexSeparatorThickness = 0.0f;
254         __indexSeparatorWidth = 0.0f;
255         __selectedIndexMarginRight = 0.0f;
256         __selectedIndexHeight = 0.0f;
257         __popupWidthIncrement = 0.0f;
258         __popupTextSize = 0.0f;
259         __popupShadowRight = 0.0f;
260         __popupShadowBottom = 0.0f;
261         __ignoreTouchEvent = false;
262         ReleaseResources();
263
264         return E_SYSTEM;
265 }
266
267 void
268 _FastScrollViewConfig::ReleaseResources(void)
269 {
270         delete __pIndexBgBitmap;
271         delete __pSelectedIndexBgBitmap;
272         delete __pSelectedIndexlineBitmap;
273         delete __pPopupBgBitmap;
274         delete __pPopupBgEffectBitmap;
275
276         __pIndexBgBitmap = null;
277         __pSelectedIndexBgBitmap = null;
278         __pSelectedIndexlineBitmap = null;
279         __pPopupBgBitmap = null;
280         __pPopupBgEffectBitmap = null;
281 }
282
283 result
284 _FastScrollViewConfig::Construct(_ControlOrientation orientation)
285 {
286         return ReloadConfig(orientation);
287 }
288
289
290 _FastScrollIndexView::_FastScrollIndexView(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
291         : __parentVe(parentVe)
292         , __viewConfig(viewConfig)
293         , __pBaseIndex(null)
294         , __pSelectedIndex(null)
295         , __pSelectedIndexInOmittedIndex(null)
296         , __pFormerIndex(null)
297         , __pBaseIndexVe(null)
298         , __pSelectedBgVe(null)
299         , __pSelectedIndexVe(null)
300         , __needUpdateBaseIndex(false)
301         , __needUpdateSelectedIndex(false)
302         , __needDestroySelf(false)
303 {
304 }
305
306 _FastScrollIndexView::~_FastScrollIndexView(void)
307 {
308         if (__pSelectedIndexVe)
309         {
310                 __pSelectedIndexVe->RemoveAllAnimations();
311                 __pSelectedIndexVe->SetAnimationProvider(null);
312
313                 __pSelectedIndexVe->Destroy();
314                 __pSelectedIndexVe = null;
315         }
316
317         if (__pSelectedBgVe)
318         {
319                 __pSelectedBgVe->RemoveAllAnimations();
320                 __pSelectedBgVe->SetAnimationProvider(null);
321
322                 __pSelectedBgVe->Destroy();
323                 __pSelectedBgVe = null;
324         }
325
326         if (__pBaseIndexVe)
327         {
328                 __pBaseIndexVe->RemoveAllAnimations();
329                 __pBaseIndexVe->SetAnimationProvider(null);
330
331                 __pBaseIndexVe->Destroy();
332                 __pBaseIndexVe = null;
333         }
334 }
335
336 _FastScrollIndexView*
337 _FastScrollIndexView::CreateFastScrollIndexViewN(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
338 {
339         _FastScrollIndexView* pIndexView = new (std::nothrow) _FastScrollIndexView(parentVe, viewConfig);
340         SysTryReturn(NID_UI_CTRL, pIndexView, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
341
342         result r = pIndexView->Construct();
343         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
344
345         SetLastResult(E_SUCCESS);
346         return pIndexView;
347
348 CATCH:
349         delete pIndexView;
350
351         return null;
352 }
353
354 result
355 _FastScrollIndexView::FadeOutAndDestroy(void)
356 {
357         __needDestroySelf = true;
358         if (__pSelectedIndexVe)
359         {
360                 __pSelectedIndexVe->RemoveAllAnimations();
361         }
362
363         if (__pSelectedBgVe)
364         {
365                 __pSelectedBgVe->RemoveAllAnimations();
366         }
367
368         return SetIndexVisibility(false);
369 }
370
371 result
372 _FastScrollIndexView::SetBaseIndex(_FastScrollIndex* pIndex)
373 {
374         if (__pBaseIndex == pIndex)
375         {
376                 return E_SUCCESS;
377         }
378
379         __pBaseIndex = pIndex;
380
381         result r = UpdateIndex(false);
382         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the index view.");
383
384         return E_SUCCESS;
385 }
386
387 _FastScrollIndex*
388 _FastScrollIndexView::GetBaseIndex(void) const
389 {
390         return __pBaseIndex;
391 }
392
393 result
394 _FastScrollIndexView::SetIndexBounds(const FloatRectangle& indexBounds)
395 {
396         SysTryReturnResult(NID_UI_CTRL, __pSelectedIndexVe, E_INVALID_STATE, "__pSelectedIndexVe must not be null.");
397
398         FloatRectangle veBounds(indexBounds.x, indexBounds.y, indexBounds.width, indexBounds.height);
399         __pBaseIndexVe->SetBounds(veBounds);
400
401         __needUpdateBaseIndex = true;
402
403         veBounds.x = 0.0f;
404         veBounds.y = 0.0f;
405         __pSelectedIndexVe->SetBounds(veBounds);
406
407         __needUpdateSelectedIndex = true;
408
409         return E_SUCCESS;
410 }
411
412 Rectangle
413 _FastScrollIndexView::GetIndexBounds(void) const
414 {
415         FloatRectangle veBounds = __pBaseIndexVe->GetBounds();
416         return Rectangle(veBounds.x, veBounds.y, veBounds.width, veBounds.height);
417 }
418
419 FloatRectangle
420 _FastScrollIndexView::GetIndexBoundsF(void) const
421 {
422         return __pBaseIndexVe->GetBounds();
423 }
424
425 _FastScrollIndex*
426 _FastScrollIndexView::GetIndexAtPoint(const FloatPoint& point) const
427 {
428         SysTryReturn(NID_UI_CTRL, __pBaseIndex, null, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
429
430         int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
431         SysTryReturn(NID_UI_CTRL, childCount > 0, null, E_INVALID_STATE, "[E_INVALID_STATE] The index has no children.");
432
433         _FastScrollIndex* pChildIndex = null;
434
435         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
436         if (bounds.Contains(point) == true)
437         {
438                 float touchY = point.y - bounds.y - __viewConfig.__indexMarginTop;
439                 float indexHeight = GetIndexHeight();
440                 int indexOrder = 0;
441
442                 if (!(_FloatCompare(touchY, 0.0f) || _FloatCompare(indexHeight, 0.0f)))
443                 {
444                         indexOrder = _CoordinateSystemUtils::ConvertToInteger(touchY / indexHeight);
445                 }
446
447                 pChildIndex = __pBaseIndex->GetChildIndex(indexOrder, true);
448                 SysTryReturn(NID_UI_CTRL, pChildIndex, null, GetLastResult(), "[%s] Failed to get the child index.",
449                                 GetErrorMessage(GetLastResult()));
450         }
451
452         SetLastResult(E_SUCCESS);
453         return pChildIndex;
454 }
455
456 _FastScrollIndex*
457 _FastScrollIndexView::GetOmissionIndexAtPoint(_FastScrollIndex* pIndex, const FloatPoint& point) const
458 {
459         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
460         float touchY = point.y - bounds.y - __viewConfig.__indexMarginTop - (pIndex->GetIndexOrder(true) * GetIndexHeight());
461         int hiddenChildCount = pIndex->GetChildCount();
462         SysTryReturn(NID_UI_CTRL, hiddenChildCount > 0, null, E_INVALID_STATE, "[E_INVALID_STATE] Failed to get the hidden index");
463         float indexHeight = GetIndexHeight() /hiddenChildCount;
464         int omissionIndexOrder = 0;
465
466         if ((touchY > 0.0f) && !_FloatCompare(indexHeight, 0.0f))
467         {
468                 omissionIndexOrder = _CoordinateSystemUtils::ConvertToInteger(touchY / indexHeight);
469         }
470
471         _FastScrollIndex* pChildIndex = pIndex->GetChildIndex(omissionIndexOrder);
472         SysTryReturn(NID_UI_CTRL, pChildIndex, null, GetLastResult(), "[%s] Failed to get the child index.",
473                                 GetErrorMessage(GetLastResult()));
474
475         SetLastResult(E_SUCCESS);
476         return pChildIndex;
477 }
478
479 float
480 _FastScrollIndexView::GetIndexHeight(void) const
481 {
482         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
483         float indexHeight = __viewConfig.__indexSizeMin.height;
484
485         if (__pBaseIndex->GetParentIndex() == null)
486         {
487                 float indexHeightPerChild = (bounds.height - __viewConfig.__indexMarginTop * 2.0f) / (__pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType()));
488                 if (indexHeight < indexHeightPerChild)
489                 {
490                         indexHeight = indexHeightPerChild;
491                 }
492         }
493
494         return indexHeight;
495 }
496
497 result
498 _FastScrollIndexView::SelectIndex(int indexOrder)
499 {
500         result r = E_SUCCESS;
501
502         SysTryReturnResult(NID_UI_CTRL, __pBaseIndex, E_INVALID_STATE, "__pBaseIndex must not be null.");
503
504         _FastScrollIndex* pIndex = __pBaseIndex->GetChildIndex(indexOrder, true);
505         SysTryReturnResult(NID_UI_CTRL, pIndex, GetLastResult(), "Failed to get the child index.");
506
507         r = SelectIndex(pIndex, false);
508         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to select the index.");
509
510         return E_SUCCESS;
511 }
512
513 result
514 _FastScrollIndexView::SelectIndex(_FastScrollIndex* pIndex, bool animation)
515 {
516         result r = E_SUCCESS;
517
518         if (__pSelectedIndex == pIndex)
519         {
520                 return E_SUCCESS;
521         }
522
523         __pSelectedIndex = pIndex;
524
525         if (__pSelectedIndex)
526         {
527                 __pSelectedBgVe->SetBounds(CalculateSelectedBg());
528                 if (GetSelectedIndexVisibility() == false)
529                 {
530                         r = SetSelectedIndexVisibility(true, animation);
531                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the Selected Bg ve.");
532                 }
533         }
534         else
535         {
536                 if (GetSelectedIndexVisibility() == true)
537                 {
538                         r = SetSelectedIndexVisibility(false, animation);
539                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the Selected Bg ve.");
540                 }
541                 SetSelectedIndexInOmittedIndex(null);
542                 __pFormerIndex = null;
543         }
544
545         r = UpdateIndex(false);
546         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the index view.");
547
548         return E_SUCCESS;
549 }
550
551 void
552 _FastScrollIndexView::SelectIndexList(bool isNext)
553 {
554         FloatMatrix4 baseVeMatrix;
555         baseVeMatrix.SetAsIdentity();
556         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
557
558         if (isNext)
559         {
560                 _MatrixUtilTranslate(baseVeMatrix, 0.0f, bounds.height, 0.0f);
561         }
562         else
563         {
564                 _MatrixUtilTranslate(baseVeMatrix, 0.0f, -bounds.height, 0.0f);
565         }
566         __pBaseIndexVe->SetTransformMatrix(baseVeMatrix);
567         __pBaseIndexVe->SetImplicitAnimationEnabled(true);
568
569         baseVeMatrix.SetAsIdentity();
570         _MatrixUtilTranslate(baseVeMatrix, 0.0f, 0.0f, 0.0f);
571         __pBaseIndexVe->SetTransformMatrix(baseVeMatrix);
572
573         __pBaseIndexVe->SetImplicitAnimationEnabled(false);
574         __needUpdateBaseIndex = true;
575 }
576
577
578 int
579 _FastScrollIndexView::GetSelectedIndexOrder(void) const
580 {
581         SysTryReturn(NID_UI_CTRL, __pBaseIndex, -1, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
582         SysTryReturn(NID_UI_CTRL, __pSelectedIndex, -1, E_INVALID_STATE, "[E_INVALID_STATE] __pSelectedIndex must not be null.");
583
584         return __pBaseIndex->GetChildOrder(__pSelectedIndex, true);
585 }
586
587 void
588 _FastScrollIndexView::SetSelectedIndex(_FastScrollIndex* pIndex)
589 {
590         __pSelectedIndex = pIndex;
591 }
592
593 _FastScrollIndex*
594 _FastScrollIndexView::GetSelectedIndex(void) const
595 {
596         return __pSelectedIndex;
597 }
598
599 void
600 _FastScrollIndexView::SetSelectedIndexInOmittedIndex(_FastScrollIndex* pIndex)
601 {
602         if (pIndex == __pSelectedIndexInOmittedIndex)
603         {
604                 return;
605         }
606
607         __pFormerIndex = __pSelectedIndexInOmittedIndex;
608         __pSelectedIndexInOmittedIndex = pIndex;
609 }
610
611 _FastScrollIndex*
612 _FastScrollIndexView::GetSelectedIndexInOmittedIndex(void) const
613 {
614         return __pSelectedIndexInOmittedIndex;
615 }
616
617 _FastScrollIndex*
618 _FastScrollIndexView::GetFormerIndex(void) const
619 {
620         return __pFormerIndex;
621 }
622
623 bool
624 _FastScrollIndexView::IsOnAnimation(void) const
625 {
626         return false;
627 }
628
629 void
630 _FastScrollIndexView::RemoveAllAnimations(void)
631 {
632         __pBaseIndexVe->RemoveAllAnimations();
633 }
634
635 result
636 _FastScrollIndexView::SetIndexVisibility(bool visibility)
637 {
638         result r = E_SUCCESS;
639
640         __pBaseIndexVe->SetImplicitAnimationEnabled(true);
641
642         if (visibility)
643         {
644                 __pBaseIndexVe->SetOpacity(FASTSCROLL_OPACITY_ON);
645         }
646         else
647         {
648                 __pBaseIndexVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
649         }
650         // else keep up current visibility.
651
652         __pBaseIndexVe->SetImplicitAnimationEnabled(false);
653
654         return r;
655 }
656
657 bool
658 _FastScrollIndexView::GetIndexVisibility(void) const
659 {
660         float opacity = __pBaseIndexVe->GetOpacity();
661         if (opacity > FASTSCROLL_OPACITY_OFF)
662         {
663                 return true;
664         }
665         else
666         {
667                 return false;
668         }
669 }
670
671 result
672 _FastScrollIndexView::SetSelectedIndexVisibility(bool visibility, bool animation)
673 {
674         SysTryReturnResult(NID_UI_CTRL, __pSelectedIndexVe, E_INVALID_STATE, "__pSelectedIndexVe must not be null.");
675         SysTryReturnResult(NID_UI_CTRL, __pSelectedBgVe, E_INVALID_STATE, "__pSelectedBgVe must not be null.");
676
677         if (animation)
678         {
679                 __pSelectedIndexVe->SetImplicitAnimationEnabled(true);
680                 __pSelectedBgVe->SetImplicitAnimationEnabled(true);
681         }
682
683         if (visibility)
684         {
685                 __pSelectedIndexVe->SetOpacity(FASTSCROLL_OPACITY_ON);
686                 __pSelectedBgVe->SetOpacity(FASTSCROLL_OPACITY_SELECTEDBG_DIM);
687         }
688         else
689         {
690                 __pSelectedIndexVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
691                 __pSelectedBgVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
692         }
693         // else keep up current visibility.
694
695         __pSelectedIndexVe->SetImplicitAnimationEnabled(false);
696         __pSelectedBgVe->SetImplicitAnimationEnabled(false);
697
698         return E_SUCCESS;
699 }
700
701 bool
702 _FastScrollIndexView::GetSelectedIndexVisibility(void) const
703 {
704         SysTryReturn(NID_UI_CTRL, __pSelectedIndexVe, false, E_INVALID_STATE, "[E_INVALID_STATE] __pSelectedIndexVe must not be null.");
705
706         float opacity = __pSelectedIndexVe->GetOpacity();
707         if (opacity > FASTSCROLL_OPACITY_OFF)
708         {
709                 return true;
710         }
711
712         return false;
713 }
714
715
716 result
717 _FastScrollIndexView::AddAccessibilityElement(const _AccessibilityContainer& control)
718 {
719         SysTryReturnResult(NID_UI_CTRL, __pBaseIndex, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
720
721         int omittedChildCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
722         SysTryReturnResult(NID_UI_CTRL, omittedChildCount > 0, E_INVALID_STATE, "The index has no children.");
723
724         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
725         float indexHeight = GetIndexHeight();
726         FloatRectangle indexRect(bounds.x, __viewConfig.__indexMarginTop, bounds.width, indexHeight);
727         int nonOmittedIndex = 0;
728
729         _AccessibilityElement* pAccessibilityElement = null;
730         result r = E_SUCCESS;
731         for (int i = 0; i < omittedChildCount; )
732         {
733                 _FastScrollIndex* pChildIndex = __pBaseIndex->GetChildIndex(i, true);
734                 SysTryReturnResult(NID_UI_CTRL, pChildIndex, GetLastResult(), "Failed to get the child index.");
735
736                 int omittedCount = 0;
737                 if (pChildIndex->GetOmitted())
738                 {
739                         omittedCount = pChildIndex->GetChildCount();
740                         pChildIndex = __pBaseIndex->GetChildIndex(nonOmittedIndex, false);
741                         SysTryReturnResult(NID_UI_CTRL, pChildIndex, GetLastResult(), "Failed to get the child index.");
742                 }
743
744                 Bitmap* pChildIndexImage = pChildIndex->GetIndexImage();
745                 if (pChildIndexImage == null)
746                 {
747                         String* pChildIndexText = pChildIndex->GetIndexText();
748                         SysTryReturnResult(NID_UI_CTRL, pChildIndexText, E_INVALID_STATE, "pChildIndexText must not be null.");
749
750                         _AccessibilityContainer* pAccessibilityContainer = const_cast <_AccessibilityContainer*>(&control);
751                         pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
752                         SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
753                         pAccessibilityElement->SetBounds(indexRect);
754                         pAccessibilityElement->SetLabel(*pChildIndexText);
755                         pAccessibilityElement->SetName(L"FastScrollIndex");
756                         pAccessibilityElement->SetHint(L"double tap to move ," + *pChildIndexText + L", list");
757                         r = pAccessibilityContainer->AddElement(*pAccessibilityElement);
758                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to add accessibility element.", GetErrorMessage(r));
759                 }
760
761                 if (omittedCount > 1)
762                 {
763                         omittedCount--;
764                 }
765                 else
766                 {
767                         indexRect.y += indexHeight;
768                         i++;
769                 }
770
771                 nonOmittedIndex++;
772         }
773
774         return E_SUCCESS;
775
776 CATCH:
777         delete pAccessibilityElement;
778         return r;
779 }
780
781 result
782 _FastScrollIndexView::UpdateIndex(bool bNeedUpdateBaseIndex)
783 {
784         result r = E_SUCCESS;
785
786         r = __parentVe.InvalidateRectangle(null);
787         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to invalidate the index Ve.");
788
789         if (__pSelectedIndex)
790         {
791                 __needUpdateSelectedIndex = true;
792         }
793
794         if (bNeedUpdateBaseIndex)
795         {
796                 __needUpdateBaseIndex = true;
797         }
798
799         return E_SUCCESS;
800 }
801
802 void
803 _FastScrollIndexView::OnDraw(void)
804 {
805         DrawBaseIndex();
806         if (__pSelectedIndex)
807         {
808                 DrawSelectedBg();
809                 DrawSelectedIndex();
810         }
811 }
812
813 VisualElementAnimation*
814 _FastScrollIndexView::CreateAnimationForProperty(VisualElement& target, const String& property)
815 {
816         VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
817
818         if (pAnimation)
819         {
820                 const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
821                 if (pTimingFunction)
822                 {
823                         pAnimation->SetTimingFunction(pTimingFunction);
824                 }
825                 pAnimation->SetVisualElementAnimationStatusEventListener(this);
826         }
827         return pAnimation;
828 }
829
830 void
831 _FastScrollIndexView::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
832 {
833 }
834
835 void
836 _FastScrollIndexView::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
837 {
838 }
839
840 void
841 _FastScrollIndexView::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
842 {
843         if (__pBaseIndexVe == (static_cast <_VisualElement*>(&target)))
844         {
845                 if (__needDestroySelf && completedNormally)
846                 {
847                         if (__pSelectedIndexVe)
848                         {
849                                 __pSelectedIndexVe->RemoveAllAnimations();
850                                 __pSelectedIndexVe->SetAnimationProvider(null);
851                         }
852
853                         if (__pSelectedBgVe)
854                         {
855                                 __pSelectedBgVe->RemoveAllAnimations();
856                                 __pSelectedBgVe->SetAnimationProvider(null);
857                         }
858
859                         __pBaseIndexVe->RemoveAllAnimations();
860                         __pBaseIndexVe->SetAnimationProvider(null);
861
862                         delete this;
863                 }
864                 else if (__viewConfig.__ignoreTouchEvent)
865                 {
866                         __viewConfig.__ignoreTouchEvent = false;
867                 }
868         }
869 }
870
871 FloatRectangle
872 _FastScrollIndexView::CalculateSelectedBg(void)
873 {
874         SysTryReturn(NID_UI_CTRL, __pBaseIndex, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE,
875                         "[E_INVALID_STATE] __pBaseIndex must not be     null.");
876         SysTryReturn(NID_UI_CTRL, __pSelectedIndexVe, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE,
877                         "[E_INVALID_STATE] __pSelectedIndexVe must not be null.");
878         SysTryReturn(NID_UI_CTRL, __pSelectedIndex, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE,
879                         "[E_INVALID_STATE] __pSelectedIndex must not be null.");
880
881         int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
882         SysTryReturn(NID_UI_CTRL, childCount > 0, FloatRectangle(0.0f, 0.0f, 0.0f, 0.0f), E_INVALID_STATE, "[E_INVALID_STATE] The index has no children.");
883
884         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
885         float indexHeight = GetIndexHeight();
886         int selectedIndexOrder = GetSelectedIndexOrder();
887         FloatRectangle selectedRect(0.0f, 0.0f, (bounds.width - __viewConfig.__selectedIndexMarginRight), __viewConfig.__selectedIndexHeight);
888
889         if (_FloatCompare(bounds.height, __viewConfig.__selectedIndexHeight) || (bounds.height < __viewConfig.__selectedIndexHeight))
890         {
891                 selectedRect.height = bounds.height;
892         }
893         else
894         {
895                 selectedRect.y = ((selectedIndexOrder * indexHeight) + __viewConfig.__indexMarginTop);
896                 if (indexHeight < __viewConfig.__selectedIndexHeight)
897                 {
898                         selectedRect.y -= ((__viewConfig.__selectedIndexHeight - indexHeight) / 2.0f);
899                 }
900                 else
901                 {
902                         selectedRect.height = indexHeight;
903                 }
904
905                 if (selectedRect.y < 0.0f)
906                 {
907                         selectedRect.y = 0.0f;
908                 }
909         }
910
911         return selectedRect;
912 }
913
914 void
915 _FastScrollIndexView::DrawBaseIndex()
916 {
917         if (!__needUpdateBaseIndex)
918         {
919                 return;
920         }
921         SysTryReturnVoidResult(NID_UI_CTRL, __pBaseIndex, E_INVALID_STATE, "[E_INVALID_STATE] __pBaseIndex must not be null.");
922
923         result r = E_SUCCESS;
924         int childCount = __pBaseIndex->GetChildCount(__pBaseIndex->GetIndexType());
925         SysTryReturnVoidResult(NID_UI_CTRL, childCount > 0, E_INVALID_STATE, "[E_INVALID_STATE] The index has no children.");
926
927         Canvas* pCanvas = __pBaseIndexVe->GetCanvasN();
928         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the index ve.",
929                         GetErrorMessage(GetLastResult()));
930
931         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
932         pCanvas->Clear();
933
934         pCanvas->SetLineWidth(__viewConfig.__indexSeparatorThickness);
935         pCanvas->SetForegroundColor(__viewConfig.__indexLineColor);
936
937
938         FloatRectangle bounds = __pBaseIndexVe->GetBounds();
939         float indexHeight = GetIndexHeight();
940
941         FloatRectangle bgBounds(0.0f, 0.0f, bounds.width, bounds.height);
942         if (__viewConfig.__pIndexBgBitmap)
943         {
944                 Bitmap* pReplacementColorBackgroundBitmap =
945                                 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pIndexBgBitmap,
946                                                                 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__indexBgColor);
947                 DrawBitmap(*pCanvas, bgBounds, *pReplacementColorBackgroundBitmap);
948
949                 delete pReplacementColorBackgroundBitmap;
950         }
951         pCanvas->DrawLine(FloatPoint(1.0f, 0.0f), FloatPoint(1.0f, bounds.height));
952
953         FloatRectangle indexRect(0.0f, __viewConfig.__indexMarginTop, bounds.width, indexHeight);
954         Bitmap* pReplacementColorBitmap = null;
955         float separatorX = indexRect.x + ((indexRect.width - __viewConfig.__indexSeparatorWidth)/2.0f);
956
957         TextObject* pTextObject = new (std::nothrow) TextObject();
958         SysTryCatch(NID_UI_CTRL, pTextObject, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
959
960         pTextObject->Construct();
961
962         for (int i = 0; i < childCount; i++)
963         {
964                 TextSimple* pSimpleText = null;
965
966                 _FastScrollIndex* pChildIndex = __pBaseIndex->GetChildIndex(i, true);
967                 SysTryCatch(NID_UI_CTRL, pChildIndex, , GetLastResult(), "[%s] Failed to get the child index.",
968                                 GetErrorMessage(GetLastResult()));
969
970                 Bitmap* pChildIndexImage = pChildIndex->GetIndexImage();
971                 if (pChildIndexImage)
972                 {
973                         FloatRectangle imageRect = indexRect;
974                         float scaleFactor = indexRect.width / pChildIndexImage->GetWidthF();
975                         float heightScaleFactor = indexRect.height / pChildIndexImage->GetHeightF();
976                         if (scaleFactor > heightScaleFactor)
977                         {
978                                 scaleFactor = heightScaleFactor;
979                         }
980
981                         imageRect.width = pChildIndexImage->GetWidthF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
982                         imageRect.height = pChildIndexImage->GetHeightF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
983
984                         if (indexRect.width - imageRect.width > 0.0f)
985                         {
986                                 imageRect.x = indexRect.x + (indexRect.width - imageRect.width) / 2.0f;
987                         }
988
989                         if (indexRect.height - imageRect.height > 0.0f)
990                         {
991                                 imageRect.y = indexRect.y + (indexRect.height - imageRect.height) / 2.0f;
992                         }
993
994                         pReplacementColorBitmap =
995                                 _BitmapImpl::GetColorReplacedBitmapN(*pChildIndexImage,
996                                                                 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__indexTextColor);
997                         r = DrawBitmap(*pCanvas, imageRect, *pReplacementColorBitmap,
998                                         FloatRectangle(0.0f, 0.0f, pChildIndexImage->GetWidthF(), pChildIndexImage->GetHeightF()));
999                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw a bitmap.", GetErrorMessage(r));
1000
1001                         delete pReplacementColorBitmap;
1002                         pReplacementColorBitmap = null;
1003                 }
1004                 else
1005                 {
1006                         String* pChildIndexText = pChildIndex->GetIndexText();
1007                         SysTryCatch(NID_UI_CTRL, pChildIndexText, , E_INVALID_STATE, "pChildIndexText must not be null.");
1008
1009                         pTextObject->RemoveAll();
1010
1011                         pSimpleText = new (std::nothrow)TextSimple(const_cast<wchar_t*>(pChildIndexText->GetPointer()), pChildIndexText->GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1012                         SysTryCatch(NID_UI_CTRL, pSimpleText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed");
1013
1014                         r = pTextObject->AppendElement(*pSimpleText);
1015                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to append simple text.", GetErrorMessage(r));
1016
1017                         r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1018                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set wrap.", GetErrorMessage(r));
1019
1020                         r = pTextObject->SetFont(__viewConfig.__pFont, 0, pTextObject->GetTextLength());
1021                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
1022
1023                         r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1024                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set alignment.", GetErrorMessage(r));
1025
1026                         r = pTextObject->SetBounds(indexRect);
1027                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds of pTextObject.", GetErrorMessage(r));
1028
1029                         r = pTextObject->SetForegroundColor(__viewConfig.__indexTextColor, 0, pTextObject->GetTextLength());
1030                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set foreground color.", GetErrorMessage(r));
1031
1032                         r = pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1033                         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw text.", GetErrorMessage(r));
1034
1035                 }
1036
1037                 indexRect.y += indexHeight;
1038                 if (i != (childCount - 1))
1039                 {
1040                         pCanvas->SetForegroundColor(__viewConfig.__indexDividerColor);
1041                         pCanvas->DrawLine(FloatPoint(separatorX, indexRect.y + __viewConfig.__indexSeparatorThickness),
1042                                                         FloatPoint(__viewConfig.__indexSeparatorWidth, indexRect.y + __viewConfig.__indexSeparatorThickness));
1043                 }
1044         }
1045
1046         __needUpdateBaseIndex = false;
1047         //fall through
1048 CATCH:
1049         delete pTextObject;
1050         delete pCanvas;
1051         delete pReplacementColorBitmap;
1052 }
1053
1054 void
1055 _FastScrollIndexView::DrawSelectedBg()
1056 {
1057         if (!__needUpdateSelectedIndex)
1058         {
1059                 return;
1060         }
1061
1062         SysTryReturnVoidResult(NID_UI_CTRL, __pSelectedIndex, E_INVALID_STATE,
1063                         "[E_INVALID_STATE] __pSelectedIndex must not be null.");
1064
1065         Canvas* pCanvas = __pSelectedBgVe->GetCanvasN();
1066         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the Selected Bg ve.",
1067                         GetErrorMessage(GetLastResult()));
1068
1069         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1070         pCanvas->Clear();
1071
1072         FloatRectangle bounds = __pSelectedBgVe->GetBounds();
1073         bounds.y = 0.0f;
1074
1075         if (__viewConfig.__pSelectedIndexBgBitmap)
1076         {
1077                 Bitmap* pReplacementColorBackgroundBitmap = null;
1078                 pReplacementColorBackgroundBitmap =
1079                                 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pSelectedIndexBgBitmap,
1080                                                                 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__selectedIndexBgColor);
1081                 DrawBitmap(*pCanvas, bounds, *pReplacementColorBackgroundBitmap);
1082
1083                 delete pReplacementColorBackgroundBitmap;
1084         }
1085
1086         delete pCanvas;
1087 }
1088
1089 void
1090 _FastScrollIndexView::DrawSelectedIndex()
1091 {
1092         if (!__needUpdateSelectedIndex)
1093         {
1094                 return;
1095         }
1096
1097         SysTryReturnVoidResult(NID_UI_CTRL, __pSelectedIndex, E_INVALID_STATE, "[E_INVALID_STATE] __pSelectedIndex must not be null.");
1098
1099         Canvas* pCanvas = __pSelectedIndexVe->GetCanvasN();
1100         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the selected index ve.",
1101                         GetErrorMessage(GetLastResult()));
1102
1103         result r = E_SUCCESS;
1104         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1105         pCanvas->Clear();
1106         FloatRectangle bounds = __pSelectedIndexVe->GetBounds();
1107         FloatRectangle outlineBounds = __pSelectedBgVe->GetBounds();
1108
1109         pCanvas->SetLineWidth(__viewConfig.__indexLeftLineThickness);
1110         pCanvas->SetForegroundColor(__viewConfig.__indexSelectedLineColor);
1111
1112         if (__viewConfig.__pSelectedIndexlineBitmap)
1113         {
1114                 Bitmap* pReplacementColorBackgroundBitmap = null;
1115                 pReplacementColorBackgroundBitmap =
1116                                 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pSelectedIndexlineBitmap,
1117                                                                 Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__indexSelectedLineColor);
1118                 DrawBitmap(*pCanvas, outlineBounds, *pReplacementColorBackgroundBitmap);
1119
1120                 delete pReplacementColorBackgroundBitmap;
1121
1122                 pCanvas->DrawLine(FloatPoint(1.0f, 0.0f), FloatPoint(1.0f, outlineBounds.y));
1123                 pCanvas->DrawLine(FloatPoint(1.0f, (outlineBounds.y + outlineBounds.height)), FloatPoint(1.0f, bounds.height));
1124         }
1125
1126         //draw text
1127         TextObject* pTextObject = null;
1128         TextSimple* pSimpleText = null;
1129
1130         float indexHeight = GetIndexHeight();
1131         FloatRectangle indexRect(0.0f, ((GetSelectedIndexOrder() * indexHeight) + __viewConfig.__indexMarginTop),
1132                         bounds.width, indexHeight);
1133
1134         Bitmap* pChildIndexImage = __pSelectedIndex->GetIndexImage();
1135         Bitmap* pReplacementColorBitmap = null;
1136         if (pChildIndexImage)
1137         {
1138                 FloatRectangle imageRect = indexRect;
1139                 float scaleFactor = indexRect.width / pChildIndexImage->GetWidthF();
1140                 float heightScaleFactor = indexRect.height / pChildIndexImage->GetHeightF();
1141                 if (scaleFactor > heightScaleFactor)
1142                 {
1143                         scaleFactor = heightScaleFactor;
1144                 }
1145
1146                 imageRect.width = pChildIndexImage->GetWidthF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
1147                 imageRect.height = pChildIndexImage->GetHeightF() * scaleFactor + FASTSCROLL_OPACITY_SELECTEDBG_DIM;
1148
1149                 if (indexRect.width - imageRect.width > 0.0f)
1150                 {
1151                         imageRect.x = indexRect.x + (indexRect.width - imageRect.width) / 2.0f;
1152                 }
1153
1154                 if (indexRect.height - imageRect.height > 0.0f)
1155                 {
1156                         imageRect.y = indexRect.y + (indexRect.height - imageRect.height) / 2.0f;
1157                 }
1158
1159                 pReplacementColorBitmap =
1160                         _BitmapImpl::GetColorReplacedBitmapN(*pChildIndexImage,
1161                                                         Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__selectedIndexTextColor);
1162                 r = DrawBitmap(*pCanvas, imageRect, *pReplacementColorBitmap,
1163                                 FloatRectangle(0.0f, 0.0f, pChildIndexImage->GetWidthF(), pChildIndexImage->GetHeightF()));
1164                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw a bitmap.", GetErrorMessage(r));
1165
1166                 delete pReplacementColorBitmap;
1167                 pReplacementColorBitmap = null;
1168         }
1169         else
1170         {
1171                 String* pChildIndexText = __pSelectedIndex->GetIndexText();
1172                 SysTryCatch(NID_UI_CTRL, pChildIndexText, , E_INVALID_STATE, "[E_INVALID_STATE] pChildIndexText must not be null.");
1173
1174                 pTextObject = new (std::nothrow) TextObject();
1175                 SysTryCatch(NID_UI_CTRL, pTextObject, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1176
1177                 pTextObject->Construct();
1178
1179                 pSimpleText = new (std::nothrow)TextSimple(const_cast<wchar_t*>(pChildIndexText->GetPointer()), pChildIndexText->GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1180                 SysTryCatch(NID_UI_CTRL, pSimpleText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1181
1182                 r = pTextObject->AppendElement(*pSimpleText);
1183                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to append simpletext.", GetErrorMessage(r));
1184
1185                 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1186                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set wrap.", GetErrorMessage(r));
1187
1188                 r = pTextObject->SetFont(__viewConfig.__pFont, 0, pTextObject->GetTextLength());
1189                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
1190
1191                 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1192                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set alignment.", GetErrorMessage(r));
1193
1194                 r = pTextObject->SetBounds(indexRect);
1195                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds of pTextObject.", GetErrorMessage(r));
1196
1197                 r = pTextObject->SetForegroundColor(__viewConfig.__selectedIndexTextColor, 0, pTextObject->GetTextLength());
1198                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set foreground color.", GetErrorMessage(r));
1199
1200                 r = pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1201                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw text.", GetErrorMessage(r));
1202
1203         }
1204         __needUpdateSelectedIndex = false;
1205
1206         //fall through
1207 CATCH:
1208         delete pTextObject;
1209         delete pCanvas;
1210         delete pReplacementColorBitmap;
1211 }
1212
1213 result
1214 _FastScrollIndexView::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
1215 {
1216         result r = E_SUCCESS;
1217         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1218         {
1219                 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1220                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1221         }
1222         else
1223         {
1224                 r = canvas.DrawBitmap(bounds, bitmap);
1225                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1226         }
1227
1228         return E_SUCCESS;
1229 }
1230
1231 result
1232 _FastScrollIndexView::DrawBitmap(Canvas& canvas, const FloatRectangle& srcRect, const Bitmap& bitmap, const FloatRectangle& dstRect)
1233 {
1234         result r = E_SUCCESS;
1235         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1236         {
1237                 r = canvas.DrawNinePatchedBitmap(srcRect, bitmap);
1238                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1239         }
1240         else
1241         {
1242                 r = canvas.DrawBitmap(srcRect, bitmap, dstRect);
1243                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1244         }
1245
1246         return E_SUCCESS;
1247 }
1248
1249 result
1250 _FastScrollIndexView::Construct(void)
1251 {
1252         result r = E_SUCCESS;
1253
1254         // FormattedText for Title text
1255         __pBaseIndexVe = new (std::nothrow) _VisualElement();
1256         SysTryCatch(NID_UI_CTRL, __pBaseIndexVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1257
1258         r = __pBaseIndexVe->Construct();
1259         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the index Ve.", GetErrorMessage(r));
1260
1261         __pBaseIndexVe->SetAnimationProvider(this);
1262
1263         r = __pBaseIndexVe->SetSurfaceOpaque(false);
1264         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the base index ve.", GetErrorMessage(r));
1265
1266         __pBaseIndexVe->SetImplicitAnimationEnabled(false);
1267
1268         r = __parentVe.AttachChild(*__pBaseIndexVe);
1269         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the base index ve to the parent.", GetErrorMessage(r));
1270
1271         __pBaseIndexVe->SetShowState(true);
1272
1273         //__pSelectedBgVe
1274         __pSelectedBgVe = new (std::nothrow) _VisualElement();
1275         SysTryCatch(NID_UI_CTRL, __pSelectedBgVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1276
1277         r = __pSelectedBgVe->Construct();
1278         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the selected Bg ve.", GetErrorMessage(r));
1279
1280         __pSelectedBgVe->SetAnimationProvider(this);
1281
1282         r = __pSelectedBgVe->SetSurfaceOpaque(false);
1283         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the selected Bg ve.", GetErrorMessage(r));
1284
1285         __pSelectedBgVe->SetImplicitAnimationEnabled(false);
1286
1287         r = __pBaseIndexVe->AttachChild(*__pSelectedBgVe);
1288         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the selected Bg ve to the parent.", GetErrorMessage(r));
1289
1290         __pSelectedBgVe->SetOpacity(FASTSCROLL_OPACITY_SELECTEDBG_DIM);
1291
1292         __pSelectedBgVe->SetShowState(true);
1293
1294         //__pSelectedIndexVe
1295         __pSelectedIndexVe = new (std::nothrow) _VisualElement();
1296         SysTryCatch(NID_UI_CTRL, __pSelectedIndexVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1297
1298         r = __pSelectedIndexVe->Construct();
1299         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the selected index ve.", GetErrorMessage(r));
1300
1301         __pSelectedIndexVe->SetAnimationProvider(this);
1302
1303         r = __pSelectedIndexVe->SetSurfaceOpaque(false);
1304         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the selected index ve.", GetErrorMessage(r));
1305
1306         __pSelectedIndexVe->SetImplicitAnimationEnabled(false);
1307
1308         r = __pBaseIndexVe->AttachChild(*__pSelectedIndexVe);
1309         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the selected index ve to the parent.", GetErrorMessage(r));
1310
1311         __pSelectedIndexVe->SetShowState(true);
1312
1313         return E_SUCCESS;
1314
1315 CATCH:
1316         if (__pSelectedIndexVe)
1317         {
1318                 __pSelectedIndexVe->Destroy();
1319                 __pSelectedIndexVe = null;
1320         }
1321
1322         if (__pSelectedBgVe)
1323         {
1324                 __pSelectedBgVe->Destroy();
1325                 __pSelectedBgVe = null;
1326         }
1327
1328         if (__pBaseIndexVe)
1329         {
1330                 __pBaseIndexVe->Destroy();
1331                 __pBaseIndexVe = null;
1332         }
1333
1334         return r;
1335 }
1336
1337 _FastScrollPopupView::_FastScrollPopupView(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
1338         : __parentVe(parentVe)
1339         , __viewConfig(viewConfig)
1340         , __pPopupVe(null)
1341         , __needUpdatePopupVe(false)
1342         , __needUpdatePopupIndexVe(false)
1343         , __needDestroySelf(false)
1344 {
1345 }
1346
1347 _FastScrollPopupView::~_FastScrollPopupView(void)
1348 {
1349         for (int i = 0; i < GetIndexVeCount(); i++)
1350         {
1351                 _VisualElement* pIndexVe = GetIndexVe(i);
1352
1353                 if (pIndexVe)
1354                 {
1355                         pIndexVe->RemoveAllAnimations();
1356                         pIndexVe->SetAnimationProvider(null);
1357                         pIndexVe->Destroy();
1358                 }
1359         }
1360         __indexViews.RemoveAll(false);
1361
1362         if (__pPopupVe)
1363         {
1364                 __pPopupVe->RemoveAllAnimations();
1365                 __pPopupVe->SetAnimationProvider(null);
1366
1367                 __pPopupVe->Destroy();
1368                 __pPopupVe = null;
1369         }
1370 }
1371
1372 _FastScrollPopupView*
1373 _FastScrollPopupView::CreateFastScrollPopupViewN(_VisualElement& parentVe, _FastScrollViewConfig& viewConfig)
1374 {
1375         _FastScrollPopupView* pPopupView = new (std::nothrow) _FastScrollPopupView(parentVe, viewConfig);
1376         SysTryReturn(NID_UI_CTRL, pPopupView, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1377
1378         result r = pPopupView->Construct();
1379         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
1380
1381         SetLastResult(E_SUCCESS);
1382         return pPopupView;
1383
1384 CATCH:
1385         delete pPopupView;
1386
1387         return null;
1388 }
1389
1390 result
1391 _FastScrollPopupView::FadeOutAndDestroy(void)
1392 {
1393         __needDestroySelf = true;
1394
1395         for (int i = 0; i < GetIndexVeCount(); i++)
1396         {
1397                 _VisualElement* pIndexVe = GetIndexVe(i);
1398                 SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index view.");
1399
1400                 pIndexVe->RemoveAllAnimations();
1401         }
1402
1403         return SetPopupVisibility(false);
1404 }
1405
1406 result
1407 _FastScrollPopupView::SelectIndex(int indexLevel, _FastScrollIndex* pIndex, _FastScrollIndex* pFormerIndex)
1408 {
1409         _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1410         SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index view.");
1411
1412         if (pIndex)
1413         {
1414                 pIndexVe->SetOpacity(FASTSCROLL_OPACITY_ON);
1415                 FloatRectangle popupVeBounds = __pPopupVe->GetBounds();
1416                 FloatMatrix4 popupVeMatrix;
1417                 popupVeMatrix.SetAsIdentity();
1418
1419                 if (pFormerIndex && (pFormerIndex != pIndex))
1420                 {
1421                         FloatRectangle popupIndexVeBounds = pIndexVe->GetBounds();
1422
1423                         int selectedOrder = pIndex->GetIndexOrder(false);
1424                         int oldOrder = pFormerIndex->GetIndexOrder(false);
1425
1426                         if (selectedOrder > oldOrder)
1427                         {
1428                                 _MatrixUtilTranslate(popupVeMatrix, 0.0f, 0.0f, 0.0f);
1429                         }
1430                         else
1431                         {
1432                                 _MatrixUtilTranslate(popupVeMatrix, 0.0f, -(popupVeBounds.height * (FASTSCROLL_POPUPINDEX_COUNT - 1)), 0.0f);
1433                         }
1434                         pIndexVe->SetTransformMatrix(popupVeMatrix);
1435                         pIndexVe->SetImplicitAnimationEnabled(true);
1436
1437                         popupVeMatrix.SetAsIdentity();
1438                         _MatrixUtilTranslate(popupVeMatrix, 0.0f, -popupVeBounds.height, 0.0f);
1439                         pIndexVe->SetTransformMatrix(popupVeMatrix);
1440
1441                         pIndexVe->SetImplicitAnimationEnabled(false);
1442                 }
1443                 else
1444                 {
1445                         _MatrixUtilTranslate(popupVeMatrix, 0.0f, -popupVeBounds.height, 0.0f);
1446                         pIndexVe->SetTransformMatrix(popupVeMatrix);
1447                 }
1448         }
1449         else
1450         {
1451                 pIndexVe->SetOpacity(FASTSCROLL_OPACITY_LIGHT_DIM);
1452         }
1453
1454         return E_SUCCESS;
1455 }
1456
1457 result
1458 _FastScrollPopupView::AddPopupIndexVe(int indexLevel)
1459 {
1460         result r = E_SUCCESS;
1461         _VisualElement* pPopupIndexVe = new (std::nothrow) _VisualElement();
1462         SysTryCatch(NID_UI_CTRL, pPopupIndexVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1463
1464         r = pPopupIndexVe->Construct();
1465         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the popup index ve.", GetErrorMessage(r));
1466
1467         pPopupIndexVe->SetAnimationProvider(this);
1468
1469         r = pPopupIndexVe->SetSurfaceOpaque(false);
1470         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the popup index ve.", GetErrorMessage(r));
1471
1472         pPopupIndexVe->SetImplicitAnimationEnabled(false);
1473
1474         r = __pPopupVe->AttachChild(*pPopupIndexVe);
1475         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the popup index ve to the popup ve.", GetErrorMessage(r));
1476
1477         pPopupIndexVe->SetShowState(true);
1478
1479         r = __indexViews.InsertAt(*pPopupIndexVe, indexLevel);
1480         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to change the last index view.", GetErrorMessage(r));
1481
1482         return E_SUCCESS;
1483
1484 CATCH:
1485         if (pPopupIndexVe)
1486         {
1487                 pPopupIndexVe->RemoveAllAnimations();
1488                 pPopupIndexVe->SetAnimationProvider(null);
1489
1490                 pPopupIndexVe->Destroy();
1491         }
1492
1493         return r;
1494 }
1495
1496 result
1497 _FastScrollPopupView::RemovePopupIndexVe(int indexLevel)
1498 {
1499         result r = E_SUCCESS;
1500
1501         if (indexLevel < GetIndexVeCount())
1502         {
1503                 _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1504                 SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index ve.");
1505
1506                 r = __indexViews.Remove(*pIndexVe, false);
1507                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove the popup index ve.");
1508
1509                 pIndexVe->RemoveAllAnimations();
1510                 pIndexVe->SetAnimationProvider(null);
1511                 pIndexVe->Destroy();
1512         }
1513
1514         return E_SUCCESS;
1515 }
1516
1517 result
1518 _FastScrollPopupView::SetPopupBounds(const FloatRectangle& indexBounds)
1519 {
1520         SysTryReturnResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "__pPopupVe must not be null.");
1521
1522         __pPopupVe->SetBounds(indexBounds);
1523
1524         return E_SUCCESS;
1525 }
1526
1527 result
1528 _FastScrollPopupView::SetPopupIndexBounds(int indexLevel, const _FastScrollIndex* pBaseIndex)
1529 {
1530         FloatRectangle veBounds = __pPopupVe->GetBounds();
1531         _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1532         SysTryReturnResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "Failed to get the popup index view.");
1533
1534         if (pBaseIndex)
1535         {
1536                 veBounds.x = 0.0f;
1537                 veBounds.y = 0.0f;
1538                 veBounds.height = veBounds.height * FASTSCROLL_POPUPINDEX_COUNT;
1539         }
1540
1541         int indexVeCount = GetIndexVeCount();
1542         float indexWidth = veBounds.width;
1543         if (indexVeCount > 0)
1544         {
1545                 indexWidth /= indexVeCount;
1546         }
1547
1548         veBounds.width = indexWidth;
1549         veBounds.x = veBounds.width * indexLevel;
1550
1551         pIndexVe->SetBounds(veBounds);
1552
1553         return E_SUCCESS;
1554 }
1555
1556 _VisualElement*
1557 _FastScrollPopupView::GetIndexVe(int indexLevel) const
1558 {
1559         Object* pObj = const_cast<Object*>(__indexViews.GetAt(indexLevel));
1560         SysTryReturn(NID_UI_CTRL, pObj, null, GetLastResult(), "[%s] Failed to get the popup index ve.",
1561                         GetErrorMessage(GetLastResult()));
1562
1563         return dynamic_cast<_VisualElement*>(pObj);
1564 }
1565
1566 int
1567 _FastScrollPopupView::GetIndexVeCount(void) const
1568 {
1569         return __indexViews.GetCount();
1570 }
1571
1572 bool
1573 _FastScrollPopupView::IsOnAnimation(void) const
1574 {
1575         return false;
1576 }
1577
1578 void
1579 _FastScrollPopupView::RemoveAllAnimations(void)
1580 {
1581         SysTryReturnVoidResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "[E_INVALID_STATE] __pPopupVe must not be null.");
1582         __pPopupVe->RemoveAllAnimations();
1583 }
1584
1585 result
1586 _FastScrollPopupView::SetPopupVisibility(bool visibility)
1587 {
1588         SysTryReturnResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "__pPopupVe must not be null.");
1589
1590         if (visibility)
1591         {
1592                 __pPopupVe->SetTransformMatrix(__matrixFadeInStart);
1593                 __pPopupVe->SetImplicitAnimationEnabled(true);
1594                 __pPopupVe->SetOpacity(FASTSCROLL_OPACITY_ON);
1595                 __pPopupVe->SetTransformMatrix(__matrixOrigin);
1596                 __pPopupVe->SetImplicitAnimationEnabled(false);
1597         }
1598         else
1599         {
1600                 __pPopupVe->SetImplicitAnimationEnabled(true);
1601                 __pPopupVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
1602                 __pPopupVe->SetTransformMatrix(__matrixFadeOutEnd);
1603                 __pPopupVe->SetImplicitAnimationEnabled(false);
1604         }
1605         // else keep up current visibility.
1606
1607         return E_SUCCESS;
1608 }
1609
1610 bool
1611 _FastScrollPopupView::GetPopupVisibility(void) const
1612 {
1613         SysTryReturn(NID_UI_CTRL, __pPopupVe, false, E_INVALID_STATE, "[E_INVALID_STATE] __pPopupVe must not be null.");
1614
1615         float opacity = __pPopupVe->GetOpacity();
1616         if (opacity > FASTSCROLL_OPACITY_OFF)
1617         {
1618                 return true;
1619         }
1620
1621         return false;
1622 }
1623
1624 void
1625 _FastScrollPopupView::SetPopupVeUpdateNeeded(bool needUpdate)
1626 {
1627         __needUpdatePopupIndexVe = needUpdate;
1628 }
1629
1630 result
1631 _FastScrollPopupView::UpdateIndex(void)
1632 {
1633         SysTryReturnResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "__pPopupVe must not be null.");
1634
1635         result r = E_SUCCESS;
1636
1637         r = __parentVe.InvalidateRectangle(null);
1638         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to invalidate the popup Ve.");
1639
1640         __needUpdatePopupIndexVe = true;
1641
1642         return E_SUCCESS;
1643 }
1644
1645 void
1646 _FastScrollPopupView::OnDraw(int indexLevel, const _FastScrollIndex* pBaseIndex, const _FastScrollIndex* pSelectedIndex)
1647 {
1648         DrawPopupVe();
1649         DrawPopupIndexVe(indexLevel, pBaseIndex, pSelectedIndex);
1650 }
1651
1652 VisualElementAnimation*
1653 _FastScrollPopupView::CreateAnimationForProperty(VisualElement& target, const String& property)
1654 {
1655         VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
1656
1657         if (pAnimation)
1658         {
1659                 const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
1660                 if (pTimingFunction)
1661                 {
1662                         pAnimation->SetTimingFunction(pTimingFunction);
1663                 }
1664                 pAnimation->SetVisualElementAnimationStatusEventListener(this);
1665         }
1666         return pAnimation;
1667 }
1668
1669 void
1670 _FastScrollPopupView::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
1671 {
1672 }
1673
1674 void
1675 _FastScrollPopupView::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
1676 {
1677 }
1678
1679 void
1680 _FastScrollPopupView::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
1681 {
1682         SysTryReturnVoidResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "[E_INVALID_STATE] The popup Ve must not be null.");
1683         if (__pPopupVe == (static_cast <_VisualElement*>(&target)))
1684         {
1685                 if (__needDestroySelf && completedNormally)
1686                 {
1687                         for (int i = 0; i < GetIndexVeCount(); i++)
1688                         {
1689                                 _VisualElement* pIndexVe = GetIndexVe(i);
1690                                 if (pIndexVe)
1691                                 {
1692                                         pIndexVe->RemoveAllAnimations();
1693                                         pIndexVe->SetAnimationProvider(null);
1694                                 }
1695                         }
1696
1697                         __pPopupVe->RemoveAllAnimations();
1698                         __pPopupVe->SetAnimationProvider(null);
1699
1700                         delete this;
1701                 }
1702         }
1703 }
1704
1705 void
1706 _FastScrollPopupView::DrawPopupVe(void)
1707 {
1708         if (!__needUpdatePopupVe)
1709         {
1710                 return;
1711         }
1712
1713         SysTryReturnVoidResult(NID_UI_CTRL, __pPopupVe, E_INVALID_STATE, "[E_INVALID_STATE] __pPopupVe must not be null.");
1714
1715         Canvas* pCanvas = __pPopupVe->GetCanvasN();
1716         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the popup ve.",
1717                         GetErrorMessage(GetLastResult()));
1718
1719         FloatRectangle bounds = __pPopupVe->GetBounds();
1720         bounds.SetPosition(0.0f, 0.0f);
1721
1722         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1723         pCanvas->Clear();
1724         bool isCustomBitmap = IS_CUSTOM_BITMAP(FASTSCROLL::POPUP_BG_NORMAL);
1725
1726         if (__viewConfig.__pPopupBgEffectBitmap && isCustomBitmap == false)
1727         {
1728                 DrawBitmap(*pCanvas, bounds, *__viewConfig.__pPopupBgEffectBitmap);
1729         }
1730
1731         if (__viewConfig.__pPopupBgBitmap)
1732         {
1733                 Bitmap* pReplacementColorBackgroundBitmap = null;
1734                 pReplacementColorBackgroundBitmap =
1735                                 _BitmapImpl::GetColorReplacedBitmapN(*__viewConfig.__pPopupBgBitmap, Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__popupBgColor);
1736                 DrawBitmap(*pCanvas, bounds, *pReplacementColorBackgroundBitmap);
1737
1738                 delete pReplacementColorBackgroundBitmap;
1739         }
1740
1741         delete pCanvas;
1742
1743         __needUpdatePopupVe = false;
1744 }
1745
1746
1747 void
1748 _FastScrollPopupView::DrawPopupIndexVe(int indexLevel, const _FastScrollIndex* pBaseIndex, const _FastScrollIndex* pSelectedIndex)
1749 {
1750         if (__needUpdatePopupIndexVe != true)
1751         {
1752                 return;
1753         }
1754
1755         SysTryReturnVoidResult(NID_UI_CTRL, pBaseIndex, E_INVALID_STATE, "[E_INVALID_STATE] pBaseIndex must not be null.");
1756         SysTryReturnVoidResult(NID_UI_CTRL, pSelectedIndex, E_INVALID_STATE, "[E_INVALID_STATE] pBaseIndex must not be null.");
1757
1758         result r = E_SUCCESS;
1759
1760         int childCount = pBaseIndex->GetChildCount();
1761         SysTryReturnVoidResult(NID_UI_CTRL, childCount > 0, E_INVALID_STATE, "[E_INVALID_STATE] The index has no children.");
1762
1763         _VisualElement* pIndexVe = GetIndexVe(indexLevel);
1764         SysTryReturnVoidResult(NID_UI_CTRL, pIndexVe, GetLastResult(), "[%s] Failed to get the popup index ve.",
1765                                 GetErrorMessage(GetLastResult()));
1766
1767         Canvas* pCanvas = pIndexVe->GetCanvasN();
1768         SysTryReturnVoidResult(NID_UI_CTRL, pCanvas, GetLastResult(), "[%s] Failed to get the canvas of the popup index ve.",
1769                         GetErrorMessage(GetLastResult()));
1770
1771         pCanvas->SetBackgroundColor(Color(0, 0, 0, 0));
1772         pCanvas->Clear();
1773
1774         FloatRectangle veBounds = pIndexVe->GetBounds();
1775         FloatRectangle bounds(veBounds.x, veBounds.y, veBounds.width, veBounds.height);
1776
1777         float indexHeight = bounds.height / FASTSCROLL_POPUPINDEX_COUNT;
1778         if (indexHeight < __viewConfig.__indexTextSize)
1779         {
1780                 indexHeight = __viewConfig.__indexTextSize;
1781         }
1782
1783         FloatRectangle indexRect(0.0f, 0.0f, bounds.width, indexHeight);
1784         int selectedOrder = pSelectedIndex->GetIndexOrder(false);
1785         Bitmap* pReplacementColorBitmap = null;
1786
1787         TextObject* pTextObject = new (std::nothrow) TextObject();
1788         SysTryCatch(NID_UI_CTRL, pTextObject, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1789
1790         pTextObject->Construct();
1791
1792         for (int i = -1; i < 2; i++)
1793         {
1794                 TextSimple* pSimpleText = null;
1795
1796                 _FastScrollIndex* pChildIndex = pBaseIndex->GetChildIndex(selectedOrder + i);
1797                 if (pChildIndex)
1798                 {
1799                         Bitmap* pChildIndexImage = pChildIndex->GetIndexImage();
1800                         if (pChildIndexImage)
1801                         {
1802                                 FloatRectangle imageRect = indexRect;
1803                                 float scaleFactor = indexRect.width / pChildIndexImage->GetWidthF();
1804                                 float heightScale = indexRect.height / pChildIndexImage->GetHeightF();
1805                                 float rectHeight = indexRect.height;
1806                                 if (rectHeight > __viewConfig.__popupTextSize)
1807                                 {
1808                                         rectHeight = __viewConfig.__popupTextSize;
1809                                 }
1810
1811                                 if (scaleFactor > heightScale)
1812                                 {
1813                                         scaleFactor = heightScale;
1814                                 }
1815                                 imageRect.width = pChildIndexImage->GetWidthF() * scaleFactor;
1816                                 imageRect.height = pChildIndexImage->GetHeightF() * scaleFactor;
1817
1818                                 if (indexRect.width - imageRect.width > 0.0f)
1819                                 {
1820                                         imageRect.x = indexRect.x + (indexRect.width - imageRect.width) / 2.0f;
1821                                 }
1822
1823                                 if (indexRect.height - imageRect.height > 0.0f)
1824                                 {
1825                                         imageRect.y = indexRect.y + (indexRect.height - imageRect.height) / 2.0f;
1826                                 }
1827
1828                                 pReplacementColorBitmap =
1829                                         _BitmapImpl::GetColorReplacedBitmapN(*pChildIndexImage,
1830                                                         Color::GetColor(COLOR_ID_MAGENTA), __viewConfig.__popupTextColor);
1831                                 r = DrawBitmap(*pCanvas, imageRect, *pReplacementColorBitmap,
1832                                                 FloatRectangle(0.0f, 0.0f, pChildIndexImage->GetWidthF(), pChildIndexImage->GetHeightF()));
1833                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw a bitmap.", GetErrorMessage(r));
1834
1835                                 delete pReplacementColorBitmap;
1836                                 pReplacementColorBitmap = null;
1837                         }
1838                         else
1839                         {
1840                                 String* pChildIndexText = pChildIndex->GetIndexText();
1841                                 SysTryCatch(NID_UI_CTRL, pChildIndexText, , E_INVALID_STATE, "[E_INVALID_STATE] pChildIndexText must not be null.");
1842
1843                                 pTextObject->RemoveAll();
1844
1845                                 pSimpleText = new (std::nothrow)TextSimple(const_cast<wchar_t*>(pChildIndexText->GetPointer()), pChildIndexText->GetLength(), TEXT_ELEMENT_SOURCE_TYPE_EXTERNAL);
1846                                 SysTryCatch(NID_UI_CTRL, pSimpleText, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1847
1848                                 r = pTextObject->AppendElement(*pSimpleText);
1849                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to append simple text.", GetErrorMessage(r));
1850
1851                                 r = pTextObject->SetWrap(TEXT_OBJECT_WRAP_TYPE_WORD);
1852                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set wrap.", GetErrorMessage(r));
1853
1854                                 r = pTextObject->SetFont(__viewConfig.__pFont, 0, pTextObject->GetTextLength());
1855                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set font.", GetErrorMessage(r));
1856
1857                                 r = pTextObject->SetForegroundColor(__viewConfig.__popupTextColor, 0, pTextObject->GetTextLength());
1858                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set foreground color.", GetErrorMessage(r));
1859
1860                                 r = pTextObject->SetAlignment(TEXT_OBJECT_ALIGNMENT_CENTER | TEXT_OBJECT_ALIGNMENT_MIDDLE);
1861                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set alignment.", GetErrorMessage(r));
1862
1863                                 r = pTextObject->SetBounds(indexRect);
1864                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set bounds of pTextObject.", GetErrorMessage(r));
1865
1866                                 r = pTextObject->Draw(*_CanvasImpl::GetInstance(*pCanvas));
1867                                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to draw text.", GetErrorMessage(r));
1868                         }
1869                 }
1870
1871                 indexRect.y += indexHeight;
1872         }
1873
1874         //fall through
1875 CATCH:
1876         delete pTextObject;
1877         delete pCanvas;
1878         delete pReplacementColorBitmap;
1879 }
1880
1881 result
1882 _FastScrollPopupView::DrawBitmap(Canvas& canvas, const FloatRectangle& bounds, const Bitmap& bitmap)
1883 {
1884         result r = E_SUCCESS;
1885         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1886         {
1887                 r = canvas.DrawNinePatchedBitmap(bounds, bitmap);
1888                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1889         }
1890         else
1891         {
1892                 r = canvas.DrawBitmap(bounds, bitmap);
1893                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1894         }
1895
1896         return E_SUCCESS;
1897 }
1898
1899 result
1900 _FastScrollPopupView::DrawBitmap(Canvas& canvas, const FloatRectangle& srcRect, const Bitmap& bitmap, const FloatRectangle& dstRect)
1901 {
1902         result r = E_SUCCESS;
1903         if (_BitmapImpl::CheckNinePatchedBitmapStrictly(bitmap))
1904         {
1905                 r = canvas.DrawNinePatchedBitmap(srcRect, bitmap);
1906                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw ninepathced bitmap");
1907         }
1908         else
1909         {
1910                 r = canvas.DrawBitmap(srcRect, bitmap, dstRect);
1911                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to draw bitmap");
1912         }
1913
1914         return E_SUCCESS;
1915 }
1916
1917 result
1918 _FastScrollPopupView::Construct(void)
1919 {
1920         result r = E_SUCCESS;
1921
1922         __pPopupVe = new (std::nothrow) _VisualElement();
1923         SysTryCatch(NID_UI_CTRL, __pPopupVe, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
1924
1925         r = __pPopupVe->Construct();
1926         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to construct the popup ve.", GetErrorMessage(r));
1927
1928         __pPopupVe->SetAnimationProvider(this);
1929
1930         r = __pPopupVe->SetSurfaceOpaque(false);
1931         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the opaque of the popup ve.", GetErrorMessage(r));
1932
1933         __pPopupVe->SetImplicitAnimationEnabled(false);
1934
1935         r = __parentVe.AttachChild(*__pPopupVe);
1936         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to attach the popup ve to the parent.", GetErrorMessage(r));
1937
1938         __pPopupVe->SetShowState(true);
1939         __pPopupVe->SetClipChildrenEnabled(true);
1940         __pPopupVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
1941
1942         __needUpdatePopupVe = true;
1943
1944         __matrixOrigin.SetAsIdentity();
1945         __matrixFadeInStart.SetAsIdentity();
1946         __matrixFadeOutEnd.SetAsIdentity();
1947
1948         _MatrixUtilScale(__matrixFadeInStart, 0.8f, 0.8f, 1.0f);
1949         _MatrixUtilScale(__matrixFadeOutEnd, 0.1f, 0.1f, 1.0f);
1950
1951         return E_SUCCESS;
1952
1953 CATCH:
1954         if (__pPopupVe)
1955         {
1956                 __pPopupVe->Destroy();
1957                 __pPopupVe = null;
1958         }
1959
1960         return r;
1961 }
1962
1963 _FastScrollPresenter::_FastScrollPresenter(_Control& parentCtrl, _FastScroll& fastScroll, bool enableFadeEffect, bool visibility)
1964         : __parentCtrl(parentCtrl)
1965         , __fastScroll(fastScroll)
1966         , __pCtrlVe(null)
1967         , __pViewConfig(null)
1968         , __pFastScrollEvent(null)
1969         , __pFastScrollModel(null)
1970         , __fontStyle(0)
1971         , __fontSize(0.0f)
1972         , __pPopupView(null)
1973         , __focusedIndexLevel(0)
1974         , __pSelectedIndex(null)
1975         , __enableFadeEffect(enableFadeEffect)
1976         , __indexCountMax(0)
1977         , __fadeIn(false)
1978         , __fadeOut(false)
1979         , __scrollVisibility(visibility)
1980         , __fadeEffectDuration_ms(500)
1981 {
1982 }
1983
1984 _FastScrollPresenter::~_FastScrollPresenter(void)
1985 {
1986         delete __pFastScrollEvent;
1987         __pFastScrollEvent = null;
1988
1989         delete __pFastScrollModel;
1990         __pFastScrollModel = null;
1991
1992         delete __pPopupView;
1993         __pPopupView = null;
1994
1995         RemoveAllIndexViews(false);
1996
1997         delete __pViewConfig;
1998         __pViewConfig = null;
1999
2000         if (__pCtrlVe)
2001         {
2002                 __pCtrlVe->RemoveAllAnimations();
2003                 __pCtrlVe->SetAnimationProvider(null);
2004         }
2005 }
2006
2007 _FastScrollPresenter*
2008 _FastScrollPresenter::CreateFastScrollPresenterN(_Control& parentCtrl, _FastScroll& fastScroll, bool enableFadeEffect, bool visibility)
2009 {
2010         _FastScrollPresenter* pPresenter = new (std::nothrow) _FastScrollPresenter(parentCtrl, fastScroll, enableFadeEffect, visibility);
2011         SysTryReturn(NID_UI_CTRL, pPresenter, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
2012
2013         result r = pPresenter->Construct();
2014         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
2015
2016         return pPresenter;
2017
2018 CATCH:
2019         delete pPresenter;
2020
2021         return null;
2022 }
2023
2024 result
2025 _FastScrollPresenter::SetRootIndex(_FastScrollIndex* pIndex)
2026 {
2027         result r = E_SUCCESS;
2028
2029         // initialize index views
2030         RemoveAllIndexViews(false);
2031
2032         // initialize the popup view
2033         if (__pPopupView)
2034         {
2035                 r = __pPopupView->SetPopupVisibility(false);
2036                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to clear visibility of the popup view.");
2037         }
2038
2039         r = SetFontInfo(FONT_STYLE_PLAIN, __pViewConfig->__indexTextSize);
2040         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set font.");
2041
2042         // set the root index into _FastScrollModel
2043         r = __pFastScrollModel->SetRootIndex(pIndex);
2044         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the root index into _FastScrollModel");
2045
2046         // add new root index view.
2047         if (pIndex)
2048         {
2049                 r = AddIndexView(0, *pIndex);
2050                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add the root index view.");
2051         }
2052
2053         return E_SUCCESS;
2054 }
2055
2056 _FastScrollIndex*
2057 _FastScrollPresenter::GetRootIndex(void) const
2058 {
2059         return __pFastScrollModel->GetRootIndex();
2060 }
2061
2062 result
2063 _FastScrollPresenter::UpdateIndex(void)
2064 {
2065         result r = E_SUCCESS;
2066
2067         // update the base index of index views
2068         int indexViewCount = GetIndexViewCount();
2069         for (int i = 0; i < indexViewCount; i++)
2070         {
2071                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2072                 SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
2073
2074                 _FastScrollIndex* pIndex = pIndexView->GetBaseIndex();
2075
2076                 if ((pIndex->GetChildCount() > __indexCountMax) && (pIndex->GetIndexType() != FAST_SCROLL_INDEX_TYPE_OMISSION))
2077                 {
2078                         r = pIndex->SetOmissionIndex(__indexCountMax);
2079                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set omiited index.");
2080                 }
2081
2082                 r = pIndexView->UpdateIndex(true);
2083                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the index view.");
2084         }
2085
2086         // update the base index of the popup view
2087         if (__pPopupView)
2088         {
2089                 r = __pPopupView->UpdateIndex();
2090                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the popup view.");
2091         }
2092
2093         return E_SUCCESS;
2094 }
2095
2096 void
2097 _FastScrollPresenter::EnableFadeEffect(bool enable)
2098 {
2099         __enableFadeEffect = enable;
2100 }
2101
2102 bool
2103 _FastScrollPresenter::IsEnabledFadeEffect(void) const
2104 {
2105         return __enableFadeEffect;
2106 }
2107
2108 bool
2109 _FastScrollPresenter::IsOnFadeEffect(void) const
2110 {
2111         return (__fadeIn || __fadeOut);
2112 }
2113
2114 bool
2115 _FastScrollPresenter::IsScrollVisible(void) const
2116 {
2117         return (__fadeIn || __fadeOut || __scrollVisibility);
2118 }
2119
2120 result
2121 _FastScrollPresenter::SetScrollVisibility(bool visibility)
2122 {
2123         result r = E_SUCCESS;
2124
2125         if (GetScrollVisibility() == visibility)
2126         {
2127                 // keep up current visibility.
2128                 return E_SUCCESS;
2129         }
2130
2131         if (__pViewConfig->__ignoreTouchEvent && visibility == false)
2132         {
2133                 return E_SUCCESS;
2134         }
2135
2136         if (visibility == false && __pSelectedIndex != null)
2137         {
2138                 return E_SUCCESS;
2139         }
2140
2141         __pCtrlVe->RemoveAllAnimations();
2142         if (visibility)
2143         {
2144                 if (__enableFadeEffect)
2145                 {
2146                         __fadeIn = true;
2147                         __fadeOut = false;
2148
2149                         __pCtrlVe->SetImplicitAnimationEnabled(true);
2150                 }
2151
2152                 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_ON);
2153
2154                 if (__enableFadeEffect)
2155                 {
2156                         __pCtrlVe->SetImplicitAnimationEnabled(false);
2157                 }
2158                 else
2159                 {
2160                         __fadeIn = false;
2161                         __fadeOut = false;
2162                 }
2163         }
2164         else
2165         {
2166                 if (__enableFadeEffect)
2167                 {
2168                         __fadeIn = false;
2169                         __fadeOut = true;
2170
2171                         __pCtrlVe->SetImplicitAnimationEnabled(true);
2172                 }
2173
2174                 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
2175
2176                 if (__enableFadeEffect)
2177                 {
2178                         __pCtrlVe->SetImplicitAnimationEnabled(false);
2179                 }
2180                 else
2181                 {
2182                         __fadeIn = false;
2183                         __fadeOut = false;
2184                 }
2185         }
2186
2187         __scrollVisibility = visibility;
2188
2189         return  r;
2190 }
2191
2192 bool
2193 _FastScrollPresenter::GetScrollVisibility(void) const
2194 {
2195         float opacity = __pCtrlVe->GetOpacity();
2196
2197         if (__enableFadeEffect)
2198         {
2199                 if (__scrollVisibility)
2200                 {
2201                         return true;
2202                 }
2203         }
2204         else if (opacity > FASTSCROLL_OPACITY_OFF)
2205         {
2206                 return true;
2207         }
2208
2209         return false;
2210 }
2211
2212 void
2213 _FastScrollPresenter::CancelFadeEffect(void)
2214 {
2215         if (__fadeIn)
2216         {
2217                 __fadeIn = false;
2218                 __scrollVisibility = false;
2219                 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
2220         }
2221         else if (__fadeOut)
2222         {
2223                 __fadeOut = false;
2224                 __scrollVisibility = true;
2225                 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_ON);
2226         }
2227 }
2228
2229 void
2230 _FastScrollPresenter::AddFastScrollEventListener(const Controls::_IUiFastScrollListener& listener)
2231 {
2232         result r = E_SUCCESS;
2233
2234         if (__pFastScrollEvent == null)
2235         {
2236                 __pFastScrollEvent = new (std::nothrow) _UiFastScrollEvent();
2237                 SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollEvent, E_OUT_OF_MEMORY,
2238                                 "[E_OUT_OF_MEMORY] Memory allocation failed.");
2239
2240                 r = __pFastScrollEvent->Construct(__fastScroll);
2241                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2242         }
2243
2244         r = __pFastScrollEvent->AddListener(listener);
2245         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2246 }
2247
2248 void
2249 _FastScrollPresenter::RemoveFastScrollEventListener(const Controls::_IUiFastScrollListener& listener)
2250 {
2251         result r = E_SUCCESS;
2252
2253         SysTryReturnVoidResult(NID_UI_CTRL, __pFastScrollEvent, E_INVALID_STATE, "[E_INVALID_STATE] __pFastScrollEvent must not be null.");
2254
2255         r = __pFastScrollEvent->RemoveListener(listener);
2256         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
2257 }
2258
2259 result
2260 _FastScrollPresenter::AddAccessibilityElement(const _AccessibilityContainer& control, bool onAccessibility)
2261 {
2262         _FastScrollIndexView* pIndexView = GetIndexView(0);
2263         SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get fastscroll indexview.",
2264                         GetErrorMessage(GetLastResult()));
2265
2266         _AccessibilityContainer* pAccessibilityContainer = const_cast <_AccessibilityContainer*>(&control);
2267         result r = pAccessibilityContainer->RemoveAllElement();
2268         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove accessibility elements.");
2269         _AccessibilityElement* pAccessibilityElement = null;
2270
2271         if (onAccessibility)
2272         {
2273                 r = pIndexView->AddAccessibilityElement(control);
2274                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to Add accessibility element.");
2275         }
2276         else
2277         {
2278                 pAccessibilityElement = new (std::nothrow) _AccessibilityElement(true);
2279                 SysTryReturnResult(NID_UI_CTRL, pAccessibilityElement, E_OUT_OF_MEMORY, "Memory allocation failed.");
2280
2281                 pAccessibilityElement->SetBounds(pIndexView->GetIndexBounds());
2282                 pAccessibilityElement->SetTrait(L"Fast scroll bar");
2283                 pAccessibilityElement->SetName(L"FastScroll");
2284                 pAccessibilityElement->SetHint(L"double tap to enter fast scroll mode");
2285                 r = pAccessibilityContainer->AddElement(*pAccessibilityElement);
2286                 SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to Add accessibility element.", GetErrorMessage(r));
2287         }
2288         return E_SUCCESS;
2289
2290 CATCH:
2291         delete pAccessibilityElement;
2292         return r;
2293 }
2294
2295 void
2296 _FastScrollPresenter::OnParentBoundsChanged(void)
2297 {
2298         RelayoutFastScrollChildren();
2299 }
2300
2301 void
2302 _FastScrollPresenter::OnDraw(void)
2303 {
2304         // draw index views
2305         bool availableTextSize = (__fastScroll.GetBoundsF().height >= __pViewConfig->__popupTextSize);
2306         int indexViewCount = GetIndexViewCount();
2307         for (int i = 0; i < indexViewCount; i++)
2308         {
2309                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2310                 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2311                                 GetErrorMessage(GetLastResult()));
2312
2313                 result r = SetFontInfo(FONT_STYLE_PLAIN, __pViewConfig->__indexTextSize);
2314                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set font.", GetErrorMessage(r));
2315                 pIndexView->OnDraw();
2316
2317                 // draw the popup view
2318                 if (__pPopupView && i <= __focusedIndexLevel)
2319                 {
2320                         if (availableTextSize)
2321                         {
2322                                 r = SetFontInfo(FONT_STYLE_PLAIN, __pViewConfig->__popupTextSize);
2323                         }
2324                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set font.", GetErrorMessage(r));
2325                         __pPopupView->OnDraw(i, pIndexView->GetBaseIndex(), pIndexView->GetSelectedIndexInOmittedIndex());
2326                 }
2327         }
2328
2329         if (__pPopupView)
2330         {
2331                 __pPopupView->SetPopupVeUpdateNeeded(false);
2332         }
2333 }
2334
2335 bool
2336 _FastScrollPresenter::OnTouchPressed(const _Control& source, const _TouchInfo& touchinfo)
2337 {
2338         FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2339         __pViewConfig->__ignoreTouchEvent = false;
2340         return OnTouchPressedAndMoved(touchedPosition, true);
2341 }
2342
2343 bool
2344 _FastScrollPresenter::OnTouchReleased(const _Control& source, const _TouchInfo& touchinfo)
2345 {
2346         return OnTouchReleasedAndCanceled();
2347 }
2348
2349 bool
2350 _FastScrollPresenter::OnTouchMoved(const _Control& source, const _TouchInfo& touchinfo)
2351 {
2352         FloatPoint touchedPosition = touchinfo.GetCurrentPosition();
2353         return OnTouchPressedAndMoved(touchedPosition, false);
2354 }
2355
2356 bool
2357 _FastScrollPresenter::OnTouchCanceled(const _Control& source, const _TouchInfo& touchinfo)
2358 {
2359         return OnTouchReleasedAndCanceled();
2360 }
2361
2362 void
2363 _FastScrollPresenter::OnAncestorVisibleStateChanged(const _Control& control)
2364 {
2365         OnTouchReleasedAndCanceled();
2366 }
2367
2368 void
2369 _FastScrollPresenter::OnAncestorEnableStateChanged(const _Control& control)
2370 {
2371         OnTouchReleasedAndCanceled();
2372 }
2373
2374 void
2375 _FastScrollPresenter::OnAncestorInputEnableStateChanged(const _Control& control)
2376 {
2377         OnTouchReleasedAndCanceled();
2378 }
2379
2380 void
2381 _FastScrollPresenter::OnFontChanged(Font* pFont)
2382 {
2383         __pViewConfig->__pFont = pFont;
2384 }
2385
2386 void
2387 _FastScrollPresenter::OnFontInfoRequested(unsigned long& style, float& size)
2388 {
2389         style = __fontStyle;
2390         size = __fontSize;
2391 }
2392
2393 result
2394 _FastScrollPresenter::SetFontInfo(unsigned long style, float size)
2395 {
2396         __fontStyle = style;
2397         __fontSize = size;
2398
2399         __pViewConfig->__pFont = __fastScroll.GetFallbackFont();
2400         SysTryReturnResult(NID_UI_CTRL, __pViewConfig->__pFont, GetLastResult(), "Failed to get a font.");
2401
2402         return E_SUCCESS;
2403 }
2404
2405 VisualElementAnimation*
2406 _FastScrollPresenter::CreateAnimationForProperty(VisualElement& target, const String& property)
2407 {
2408         VisualElementAnimation* pAnimation = VisualElementAnimationProvider::CreateAnimationForProperty(target, property);
2409
2410         if (pAnimation)
2411         {
2412                 const IVisualElementAnimationTimingFunction* pTimingFunction = VisualElementAnimation::GetTimingFunctionByName("EaseInOut");
2413                 if (pTimingFunction)
2414                 {
2415                         pAnimation->SetTimingFunction(pTimingFunction);
2416                 }
2417                 pAnimation->SetVisualElementAnimationStatusEventListener(this);
2418         }
2419         return pAnimation;
2420 }
2421
2422 void
2423 _FastScrollPresenter::OnVisualElementAnimationStarted(const VisualElementAnimation& animation, const String& keyName, VisualElement& target)
2424 {
2425 }
2426
2427 void
2428 _FastScrollPresenter::OnVisualElementAnimationRepeated(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, long currentRepeatCount)
2429 {
2430 }
2431
2432 void
2433 _FastScrollPresenter::OnVisualElementAnimationFinished(const VisualElementAnimation& animation, const String& keyName, VisualElement& target, bool completedNormally)
2434 {
2435         if (__pCtrlVe == (static_cast <_VisualElement*>(&target)))
2436         {
2437                 __fadeIn = false;
2438                 __fadeOut = false;
2439         }
2440 }
2441
2442 HitTestResult
2443 _FastScrollPresenter::HitTest(const Tizen::Graphics::FloatPoint& point)
2444 {
2445         if (IsScrollVisible() == false)
2446         {
2447                 return HIT_TEST_NOWHERE;
2448         }
2449
2450         int indexViewCount = GetIndexViewCount();
2451         for (int i = 0; i < indexViewCount; i++)
2452         {
2453                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2454                 SysTryReturn(NID_UI_CTRL, pIndexView, HIT_TEST_NOWHERE, GetLastResult(), "[%s] Failed to get the index view.",
2455                                 GetErrorMessage(GetLastResult()));
2456
2457                 FloatRectangle indexBounds = pIndexView->GetIndexBoundsF();
2458                 if (indexBounds.Contains(point) == true)
2459                 {
2460                         return HIT_TEST_MATCH;
2461                 }
2462         }
2463
2464         return HIT_TEST_NOWHERE;
2465 }
2466
2467 void
2468 _FastScrollPresenter::OnIndexDataUpdated(_FastScrollIndex& updatedIndex)
2469 {
2470         result r = E_SUCCESS;
2471
2472         int indexViewCount = GetIndexViewCount();
2473         for (int i = 0; i < indexViewCount; i++)
2474         {
2475                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2476                 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2477                                 GetErrorMessage(GetLastResult()));
2478
2479                 if (pIndexView->GetBaseIndex() == &updatedIndex)
2480                 {
2481                         r = pIndexView->UpdateIndex(false);
2482                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2483
2484                         if (__pPopupView)
2485                         {
2486                                 r = __pPopupView->UpdateIndex();
2487                                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update the popup view.", GetErrorMessage(r));
2488                         }
2489                         break;
2490                 }
2491         }
2492 }
2493
2494 void
2495 _FastScrollPresenter::OnIndexDeleted(_FastScrollIndex& deletedIndex)
2496 {
2497         result r = E_SUCCESS;
2498
2499         int indexViewCount = GetIndexViewCount();
2500         for (int i = 0; i < indexViewCount; i++)
2501         {
2502                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2503                 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2504                                 GetErrorMessage(GetLastResult()));
2505
2506                 if (pIndexView->GetBaseIndex() == &deletedIndex)
2507                 {
2508                         // first of all, update the base index view
2509                         if (i != 0)
2510                         {
2511                                 _FastScrollIndexView* pBaseIndexView = GetIndexView(i - 1);
2512                                 SysTryReturnVoidResult(NID_UI_CTRL, pBaseIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2513                                                 GetErrorMessage(GetLastResult()));
2514
2515                                 r = pBaseIndexView->UpdateIndex(false);
2516                                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2517                         }
2518
2519                         // then remove the index view for detached index.
2520                         RemoveIndexView(i, true);
2521
2522                         delete __pPopupView;
2523                         __pPopupView = null;
2524
2525                         break;
2526                 }
2527                 else if (pIndexView->GetBaseIndex() == deletedIndex.GetParentIndex())
2528                 {
2529                         r = pIndexView->UpdateIndex(false);
2530                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2531
2532                         r = __pPopupView->UpdateIndex();
2533                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update popup view.", GetErrorMessage(r));
2534                 }
2535         }
2536 }
2537
2538 void
2539 _FastScrollPresenter::OnChildIndexAttached(_FastScrollIndex& parentIndex, int attachedOrder, _FastScrollIndex& attachedIndex)
2540 {
2541         result r = E_SUCCESS;
2542
2543         int indexViewCount = GetIndexViewCount();
2544         for (int i = 0; i < indexViewCount; i++)
2545         {
2546                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2547                 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2548                                 GetErrorMessage(GetLastResult()));
2549
2550                 if (pIndexView->GetBaseIndex() == &parentIndex)
2551                 {
2552                         r = pIndexView->UpdateIndex(false);
2553                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2554
2555                         r = __pPopupView->UpdateIndex();
2556                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update popup view.", GetErrorMessage(r));
2557                         break;
2558                 }
2559         }
2560 }
2561
2562 void
2563 _FastScrollPresenter::OnChildIndexDetached(_FastScrollIndex& parentIndex, int detachedOrder, _FastScrollIndex& detachedIndex)
2564 {
2565         result r = E_SUCCESS;
2566
2567         int indexViewCount = GetIndexViewCount();
2568         for (int i = 0; i < indexViewCount; i++)
2569         {
2570                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2571                 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2572                                 GetErrorMessage(GetLastResult()));
2573
2574                 if (pIndexView->GetBaseIndex() == &detachedIndex)
2575                 {
2576                         // first of all, update the base index view
2577                         if (i != 0)
2578                         {
2579                                 _FastScrollIndexView* pBaseIndexView = GetIndexView(i - 1);
2580                                 SysTryReturnVoidResult(NID_UI_CTRL, pBaseIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2581                                                 GetErrorMessage(GetLastResult()));
2582
2583                                 r = pBaseIndexView->UpdateIndex(false);
2584                                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2585                         }
2586
2587                         // then remove the index view for detached index.
2588                         RemoveIndexView(i, true);
2589
2590                         delete __pPopupView;
2591                         __pPopupView = null;
2592                         break;
2593                 }
2594                 else if (pIndexView->GetBaseIndex() == &parentIndex)
2595                 {
2596                         r = pIndexView->UpdateIndex(false);
2597                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2598
2599                         r = __pPopupView->UpdateIndex();
2600                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update popup view.", GetErrorMessage(r));
2601                 }
2602         }
2603 }
2604
2605
2606 result
2607 _FastScrollPresenter::Construct(void)
2608 {
2609         result r = E_SUCCESS;
2610
2611         // load color/shape configuration and bitmap resources
2612         __pViewConfig = _FastScrollViewConfig::CreateFastScrollViewConfigN(_CONTROL_ORIENTATION_PORTRAIT);
2613         SysTryReturnResult(NID_UI_CTRL, __pViewConfig, GetLastResult(), "Failed to create _FastScrollViewConfig.");
2614
2615         // create _FastScrollModel
2616         __pFastScrollModel = _FastScrollModel::CreateFastScrollModelN();
2617         SysTryCatch(NID_UI_CTRL, __pFastScrollModel, , GetLastResult(), "[%s] Failed to create _FastScrollModel.",
2618                         GetErrorMessage(GetLastResult()));
2619
2620         // initialize visual elements
2621         __pCtrlVe = __fastScroll.GetVisualElement();
2622         SysTryCatch(NID_UI_CTRL, __pCtrlVe, , GetLastResult(), "[%s] Failed to get VisualElement of the _FastScroll",
2623                         GetErrorMessage(GetLastResult()));
2624
2625         __pCtrlVe->SetAnimationProvider(this);
2626         __pCtrlVe->SetClipChildrenEnabled(false);
2627
2628         if (__scrollVisibility)
2629         {
2630                 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_ON);
2631         }
2632         else
2633         {
2634                 __pCtrlVe->SetOpacity(FASTSCROLL_OPACITY_OFF);
2635         }
2636
2637         // initialize the fastscroll control
2638         r = __fastScroll.SetBounds(CalculateFastScrollBounds(0));
2639         SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Failed to set the bounds of _FastScroll", GetErrorMessage(r));
2640
2641         __fastScroll.SetBackgroundColor(Tizen::Graphics::Color(0, 0, 0, 0));
2642
2643         __indexCountMax = _CoordinateSystemUtils::ConvertToInteger((__fastScroll.GetBoundsF().height -
2644                                 (__pViewConfig->__indexMarginTop * 2.0f)) /     __pViewConfig->__indexSizeMin.height);
2645
2646         return E_SUCCESS;
2647
2648 CATCH:
2649         delete __pFastScrollModel;
2650         __pFastScrollModel = null;
2651
2652         delete __pViewConfig;
2653         __pViewConfig = null;
2654
2655         return GetLastResult();
2656 }
2657
2658 FloatRectangle
2659 _FastScrollPresenter::CalculateFastScrollBounds(int indexCount)
2660 {
2661         FloatRectangle fastScrollBounds(0.0f, 0.0f, 0.0f, 0.0f);
2662         FloatRectangle parentBounds = __parentCtrl.GetBoundsF();
2663         fastScrollBounds.width = parentBounds.width;
2664         fastScrollBounds.height = parentBounds.height;
2665         return fastScrollBounds;
2666 }
2667
2668 FloatRectangle
2669 _FastScrollPresenter::CalculateIndexBounds(int indexLevel, _FastScrollIndex& pIndex)
2670 {
2671         FloatRectangle fastScrollBounds = __fastScroll.GetBoundsF();
2672         FloatRectangle indexBounds(0.0f, 0.0f, __pViewConfig->__indexSizeMin.width, fastScrollBounds.height);
2673
2674         indexBounds.x = fastScrollBounds.width - __pViewConfig->__indexSizeMin.width;
2675         for (int i = 1; i <= indexLevel; i++)
2676         {
2677                 indexBounds.x -= __pViewConfig->__indexGap + __pViewConfig->__indexSizeMin.width;
2678         }
2679
2680         if (indexBounds.x < 0.0f)
2681         {
2682                 indexBounds.x = 0.0f;
2683         }
2684
2685         if (indexLevel != 0)
2686         {
2687                 int childCount = pIndex.GetChildCount();
2688                 indexBounds.height = (childCount * __pViewConfig->__indexSizeMin.height) + (__pViewConfig->__indexMarginTop * 2.0f);
2689
2690                 if (indexBounds.height < fastScrollBounds.height)
2691                 {
2692                         _FastScrollIndexView* pParentIndexView = GetIndexView(indexLevel - 1);
2693                         if (pParentIndexView)
2694                         {
2695                                 FloatRectangle parentBounds = pParentIndexView->GetIndexBoundsF();
2696
2697                                 indexBounds.y = parentBounds.y + (pIndex.GetIndexOrder() * pParentIndexView->GetIndexHeight()) - __pViewConfig->__indexMarginTop;
2698                                 if (indexBounds.y < fastScrollBounds.y)
2699                                 {
2700                                         indexBounds.y = fastScrollBounds.y;
2701                                 }
2702
2703                                 float totalHeight = indexBounds.y + indexBounds.height;
2704                                 if (_FloatCompare(totalHeight, fastScrollBounds.height) || (totalHeight > fastScrollBounds.height))
2705                                 {
2706                                         indexBounds.y = fastScrollBounds.height - indexBounds.height;
2707                                 }
2708                         }
2709                 }
2710                 else
2711                 {
2712                         indexBounds.height = fastScrollBounds.height;
2713                 }
2714         }
2715
2716         return indexBounds;
2717 }
2718
2719 FloatRectangle
2720 _FastScrollPresenter::CalculatePopupBounds(void)
2721 {
2722         FloatRectangle popupBounds(0.0f, 0.0f, 0.0f, 0.0f);
2723         FloatRectangle parentBounds = __parentCtrl.GetBoundsF();
2724         FloatRectangle fastScrollBounds = __fastScroll.GetBoundsF();
2725
2726         popupBounds.width = __pViewConfig->__popupSize.width + (__pViewConfig->__popupWidthIncrement * __focusedIndexLevel);
2727         if (popupBounds.width > parentBounds.width)
2728         {
2729                 popupBounds.width = parentBounds.width;
2730         }
2731
2732         popupBounds.height = __pViewConfig->__popupSize.height;
2733         if (popupBounds.height > parentBounds.height)
2734         {
2735                 popupBounds.height = parentBounds.height;
2736         }
2737
2738         popupBounds.x = ((parentBounds.width - popupBounds.width) / 2.0f) - fastScrollBounds.x;
2739         if (popupBounds.x < 0.0f)
2740         {
2741                 popupBounds.x = 0.0f;
2742         }
2743
2744         popupBounds.y = ((parentBounds.height - popupBounds.height) / 2.0f) - fastScrollBounds.y;
2745         if (popupBounds.y < 0.0f)
2746         {
2747                 popupBounds.y = 0.0f;
2748         }
2749
2750         return popupBounds;
2751 }
2752
2753 void
2754 _FastScrollPresenter::RelayoutFastScrollChildren(void)
2755 {
2756         result r = E_SUCCESS;
2757
2758         int indexViewCount = GetIndexViewCount();
2759
2760         // initialize the fastscroll control
2761         r = __fastScroll.SetBounds(CalculateFastScrollBounds(indexViewCount));
2762         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set the bounds of _FastScroll", GetErrorMessage(r));
2763
2764         __indexCountMax = _CoordinateSystemUtils::ConvertToInteger((__fastScroll.GetBoundsF().height -
2765                                 (__pViewConfig->__indexMarginTop * 2.0f)) /     __pViewConfig->__indexSizeMin.height);
2766
2767         for (int i = 0; i < indexViewCount; i++)
2768         {
2769                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2770                 SysTryReturnVoidResult(NID_UI_CTRL, pIndexView, GetLastResult(), "[%s] Failed to get the index view.",
2771                                 GetErrorMessage(GetLastResult()));
2772
2773                 r = pIndexView->SetIndexBounds(CalculateIndexBounds(i, *(pIndexView->GetBaseIndex())));
2774                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set bounds of the index.", GetErrorMessage(r));
2775
2776                 _FastScrollIndex* pIndex = pIndexView->GetBaseIndex();
2777                 if (pIndex->GetIndexType() == FAST_SCROLL_INDEX_TYPE_OMISSION)
2778                 {
2779                         _FastScrollIndex* pSelectedIndex = pIndexView->GetSelectedIndex();
2780                         if (pSelectedIndex && pSelectedIndex->GetOmitted())
2781                         {
2782                                 pIndexView->SetSelectedIndex(null);
2783                         }
2784                         r = pIndex->RemoveOmissionChildren(false);
2785                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to remove omission index view", GetErrorMessage(r));
2786                 }
2787
2788                 if (pIndex->GetChildCount() > __indexCountMax)
2789                 {
2790                         r = pIndex->SetOmissionIndex(__indexCountMax);
2791                         SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set omission index.", GetErrorMessage(r));
2792                 }
2793
2794                 r = pIndexView->UpdateIndex(false);
2795                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to update index view.", GetErrorMessage(r));
2796         }
2797
2798         if (__pPopupView)
2799         {
2800                 r = __pPopupView->SetPopupBounds(CalculatePopupBounds());
2801                 SysTryReturnVoidResult(NID_UI_CTRL, r == E_SUCCESS, r, "[%s] Failed to set bounds of the popup view.", GetErrorMessage(r));
2802         }
2803 }
2804
2805 _FastScrollIndex*
2806 _FastScrollPresenter::SelectOnIndexViews(const FloatPoint& point, bool isPressed)
2807 {
2808         result r = E_SUCCESS;
2809
2810         _FastScrollIndex* pSelectedIndex = null;
2811         int selectedIndexLevel = 0;
2812         int indexViewCount = GetIndexViewCount();
2813         SysTryReturn(NID_UI_CTRL, indexViewCount > 0, null, E_INVALID_STATE, "[E_INVALID_STATE] The root index view is invalid state.");
2814
2815         // search the hit index on index views, then fade out other index views
2816         for (int i = 0; i < indexViewCount; i++)
2817         {
2818                 _FastScrollIndexView* pIndexView = GetIndexView(i);
2819                 SysTryReturn(NID_UI_CTRL, pIndexView, null, GetLastResult(), "[%s] Failed to get the index view.",
2820                                 GetErrorMessage(GetLastResult()));
2821
2822                 _FastScrollIndex* pIndex = pIndexView->GetIndexAtPoint(point);
2823                 if (pIndex)
2824                 {
2825                         // select the index of the index view.
2826                         r = pIndexView->SelectIndex(pIndex, isPressed);
2827                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to select the index.", GetErrorMessage(r));
2828                         pSelectedIndex = pIndex;
2829                         if (pIndex->GetOmitted() == true)
2830                         {
2831                                 pSelectedIndex = pIndexView->GetOmissionIndexAtPoint(pIndex, point);
2832                         }
2833
2834                         pIndexView->SetSelectedIndexInOmittedIndex(pSelectedIndex);
2835
2836                         selectedIndexLevel = i;
2837                         break;
2838                 }
2839         }
2840
2841         // if can no find the index on views, select index of the last index view
2842         if ((pSelectedIndex == null) && (__focusedIndexLevel != -1))
2843         {
2844                 _FastScrollIndexView* pFocusedIndexView = GetIndexView(__focusedIndexLevel);
2845                 SysTryReturn(NID_UI_CTRL, pFocusedIndexView, null, GetLastResult(), "[%s] Failed to get the index view.",
2846                                 GetErrorMessage(GetLastResult()));
2847
2848                 _FastScrollIndex* pIndex = pFocusedIndexView->GetIndexAtPoint(FloatPoint(pFocusedIndexView->GetIndexBoundsF().x, point.y));
2849                 if (pIndex)
2850                 {
2851                         // select the index of the focused index view.
2852                         r = pFocusedIndexView->SelectIndex(pIndex, isPressed);
2853                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to select the index.", GetErrorMessage(r));
2854                         pSelectedIndex = pIndex;
2855
2856                         if (pIndex->GetOmitted() == true)
2857                         {
2858                                 pSelectedIndex = pFocusedIndexView->GetOmissionIndexAtPoint(pIndex,
2859                                                                                 FloatPoint(pFocusedIndexView->GetIndexBoundsF().x, point.y));
2860                                 if (pSelectedIndex == null)
2861                                 {
2862                                         pSelectedIndex = pFocusedIndexView->GetSelectedIndexInOmittedIndex();
2863                                 }
2864                         }
2865                         pFocusedIndexView->SetSelectedIndexInOmittedIndex(pSelectedIndex);
2866
2867                         selectedIndexLevel = __focusedIndexLevel;
2868                 }
2869                 else
2870                 {
2871                         pSelectedIndex = pFocusedIndexView->GetSelectedIndex();
2872                         if (pSelectedIndex && pSelectedIndex->GetOmitted() == true)
2873                         {
2874                                 pSelectedIndex = pFocusedIndexView->GetSelectedIndexInOmittedIndex();
2875                         }
2876                         selectedIndexLevel = __focusedIndexLevel;
2877                 }
2878         }
2879
2880         if (pSelectedIndex)
2881         {
2882                 int childCount = pSelectedIndex->GetChildCount();
2883                 if (childCount > 0 && (pSelectedIndex->GetOmitted() == false))
2884                 {
2885                         _FastScrollIndexView* pSelectedIndexView = GetIndexView(selectedIndexLevel + 1);
2886                         if (pSelectedIndexView)
2887                         {
2888                                 r = pSelectedIndexView->SelectIndex((_FastScrollIndex*)null, false);
2889                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to select the index.", GetErrorMessage(r));
2890
2891                                 r = pSelectedIndexView->SetBaseIndex(pSelectedIndex);
2892                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set the base index of the index view.", GetErrorMessage(r));
2893
2894                                 r = pSelectedIndexView->SetIndexBounds(CalculateIndexBounds(selectedIndexLevel + 1, *pSelectedIndex));
2895                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set bounds of the index.", GetErrorMessage(r));
2896
2897                                 r = pSelectedIndexView->SetIndexVisibility(true);
2898                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set the visibility of the index view.", GetErrorMessage(r));
2899
2900                                 indexViewCount = GetIndexViewCount();
2901                                 while (indexViewCount > selectedIndexLevel + 2)
2902                                 {
2903                                         r = RemoveIndexView(indexViewCount - 1, true);
2904                                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to remove the index view.", GetErrorMessage(r));
2905                                         indexViewCount = GetIndexViewCount();
2906                                 }
2907                         }
2908                         else
2909                         {
2910                                 r = AddIndexView(*pSelectedIndex);
2911                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to add new child index.", GetErrorMessage(r));
2912                         }
2913
2914                         if ((childCount > __indexCountMax) && (pSelectedIndex->GetIndexType() != FAST_SCROLL_INDEX_TYPE_OMISSION))
2915                         {
2916                                 r = pSelectedIndex->SetOmissionIndex(__indexCountMax);
2917                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to set omission index.", GetErrorMessage(r));
2918                         }
2919                 }
2920                 else
2921                 {
2922                         indexViewCount = GetIndexViewCount();
2923                         while (indexViewCount > selectedIndexLevel + 1)
2924                         {
2925                                 r = RemoveIndexView(indexViewCount - 1, true);
2926                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to remove the index view.", GetErrorMessage(r));
2927                                 indexViewCount = GetIndexViewCount();
2928                         }
2929                 }
2930         }
2931         else
2932         {
2933                 indexViewCount = GetIndexViewCount();
2934                 while (indexViewCount > 1)
2935                 {
2936                         r = RemoveIndexView(indexViewCount - 1, true);
2937                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, null, r, "[%s] Failed to remove the index view.", GetErrorMessage(r));
2938                         indexViewCount = GetIndexViewCount();
2939                 }
2940         }
2941
2942         __focusedIndexLevel = selectedIndexLevel;
2943         return pSelectedIndex;
2944 }
2945
2946 result
2947 _FastScrollPresenter::DeselectIndexViews(void)
2948 {
2949         result r = E_SUCCESS;
2950
2951         while (GetIndexViewCount() > 1)
2952         {
2953                 RemoveIndexView(GetIndexViewCount() - 1, true);
2954         }
2955
2956         _FastScrollIndexView* pIndexView = GetIndexView(0);
2957         SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
2958
2959         r = pIndexView->SelectIndex((_FastScrollIndex*)null, true);
2960         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to clear the index selection.");
2961         pIndexView->SetSelectedIndexInOmittedIndex(null);
2962
2963         __fastScroll.Invalidate();
2964
2965         return E_SUCCESS;
2966 }
2967
2968 result
2969 _FastScrollPresenter::SetPopupIndex(_FastScrollIndex& popupIndex, const FloatPoint& point)
2970 {
2971         result r = E_SUCCESS;
2972
2973         // set the selected node into the popup views.
2974         if (__pPopupView == null)
2975         {
2976                 __pPopupView = _FastScrollPopupView::CreateFastScrollPopupViewN(*__pCtrlVe, *__pViewConfig);
2977                 SysTryReturnResult(NID_UI_CTRL, __pPopupView, GetLastResult(), "Propagating.");
2978
2979                 r = __pPopupView->SetPopupBounds(CalculatePopupBounds());
2980                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the popup view.");
2981
2982                 r = __pPopupView->SetPopupVisibility(true);
2983                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the popup view.");
2984         }
2985
2986         int indexViewCount = __focusedIndexLevel + 1;
2987         int popupIndexViewCount = __pPopupView->GetIndexVeCount();
2988
2989         if (indexViewCount != popupIndexViewCount)
2990         {
2991                 r = __pPopupView->SetPopupBounds(CalculatePopupBounds());
2992                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the popup view.");
2993
2994                 if (indexViewCount > popupIndexViewCount)
2995                 {
2996                         for (int i = popupIndexViewCount; i < indexViewCount; i++)
2997                         {
2998                                 r = __pPopupView->AddPopupIndexVe(i);
2999                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to add popup index ve.");
3000                         }
3001                 }
3002                 else if (indexViewCount < popupIndexViewCount)
3003                 {
3004                         for (int i = indexViewCount; i < popupIndexViewCount; i++)
3005                         {
3006                                 r = __pPopupView->RemovePopupIndexVe(i);
3007                                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove popup index ve.");
3008                         }
3009                 }
3010         }
3011
3012         r = __pPopupView->UpdateIndex();
3013         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to update the popup view.");
3014
3015         for (int i = 0; i < indexViewCount; i++)
3016         {
3017                 _FastScrollIndexView* pIndexView = GetIndexView(i);
3018                 SysTryReturnResult(NID_UI_CTRL, pIndexView, r, "Failed to index view.");
3019
3020                 r = __pPopupView->SetPopupIndexBounds(i, pIndexView->GetBaseIndex());
3021                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the popup index ve.");
3022
3023                 _FastScrollIndex* pFormerIndex = null;
3024                 if ( i == __focusedIndexLevel )
3025                 {
3026                         pFormerIndex = pIndexView->GetFormerIndex();
3027                         r = __pPopupView->SelectIndex(i, &popupIndex, pFormerIndex);
3028                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to select the popup index.");
3029                 }
3030                 else
3031                 {
3032                         r = __pPopupView->SelectIndex(i, null, null);
3033                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to select the popup index.");
3034                 }
3035         }
3036
3037         return E_SUCCESS;
3038 }
3039
3040 result
3041 _FastScrollPresenter::ClearPopupIndex(void)
3042 {
3043         result r = E_SUCCESS;
3044
3045         // clear the node data of the popup view
3046         if (__pPopupView)
3047         {
3048                 r = __pPopupView->FadeOutAndDestroy();
3049                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to clear visibility of the popup view.");
3050
3051                 __pPopupView = null;
3052         }
3053
3054         return E_SUCCESS;
3055 }
3056
3057 result
3058 _FastScrollPresenter::FireFastScrollEvent(_FastScrollIndex& selectedIndex)
3059 {
3060         // fire the fast scroll event
3061         if (__pFastScrollEvent)
3062         {
3063                 String* pIndexNodeText = selectedIndex.GetIndexText();
3064                 if (pIndexNodeText)
3065                 {
3066                         _UiFastScrollEventArg* pEventArg = new (std::nothrow) _UiFastScrollEventArg(*__pFastScrollEvent->GetSource(), selectedIndex);
3067                         SysTryReturnResult(NID_UI_CTRL, pEventArg, E_OUT_OF_MEMORY,     "Memory allocation failed.");
3068
3069                         __pFastScrollEvent->Fire(*pEventArg);
3070                 }
3071         }
3072
3073         return E_SUCCESS;
3074 }
3075
3076 bool
3077 _FastScrollPresenter::OnTouchPressedAndMoved(const FloatPoint& point, bool isPressed)
3078 {
3079         result r = E_SUCCESS;
3080         if (__pViewConfig->__ignoreTouchEvent)
3081         {
3082                 return true;
3083         }
3084
3085         if (__enableFadeEffect && __scrollVisibility == false)
3086         {
3087                 r = SetScrollVisibility(true);
3088                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to fade out fastscroll.", GetErrorMessage(r));
3089         }
3090
3091         _FastScrollIndex* pSelectedIndex = SelectOnIndexViews(point, isPressed);
3092         if (pSelectedIndex)
3093         {
3094                 if (pSelectedIndex->GetNextIndexList() || pSelectedIndex->GetPreviousIndexList())
3095                 {
3096                         _FastScrollIndexView* pIndexView = GetIndexView(__focusedIndexLevel);
3097                         SysTryReturn(NID_UI_CTRL, pIndexView != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
3098
3099                         _FastScrollIndex* pBaseIndex = pIndexView->GetBaseIndex();
3100                         SysTryReturn(NID_UI_CTRL, pBaseIndex != null, true, r, "[%s] Propagating.", GetErrorMessage(r));
3101
3102                         bool isNext = true;
3103                         if (pSelectedIndex->GetNextIndexList())
3104                         {
3105                                 pBaseIndex->SetCurrentIndexList(pSelectedIndex->GetNextIndexList());
3106                         }
3107                         else
3108                         {
3109                                 pBaseIndex->SetCurrentIndexList(pSelectedIndex->GetPreviousIndexList());
3110                                 isNext = false;
3111                         }
3112
3113                         if (pBaseIndex->GetIndexType() == FAST_SCROLL_INDEX_TYPE_OMISSION)
3114                         {
3115                                 r = pBaseIndex->RemoveOmissionChildren(false);
3116                                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to remove omission index view", GetErrorMessage(r));
3117                         }
3118
3119                         __pViewConfig->__ignoreTouchEvent = true;
3120                         OnTouchReleasedAndCanceled();
3121                         UpdateIndex();
3122                         pIndexView->SelectIndexList(isNext);
3123
3124                         if (__pSelectedIndex != pSelectedIndex)
3125                         {
3126                                 PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, &__fastScroll);
3127                         }
3128                         return true;
3129                 }
3130                 else if (__pSelectedIndex != pSelectedIndex)
3131                 {
3132                         PLAY_FEEDBACK(_RESOURCE_FEEDBACK_PATTERN_TAP, &__fastScroll);
3133                         r = SetPopupIndex(*pSelectedIndex, point);
3134                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to set the popup index.", GetErrorMessage(r));
3135
3136                         r = FireFastScrollEvent(*pSelectedIndex);
3137                         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to send the fast scroll event.", GetErrorMessage(r));
3138                         __pSelectedIndex = pSelectedIndex;
3139                 }
3140         }
3141
3142         return true;
3143 }
3144
3145 bool
3146 _FastScrollPresenter::OnTouchReleasedAndCanceled(void)
3147 {
3148         result r = E_SUCCESS;
3149
3150         r = DeselectIndexViews();
3151         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to deselect index views.", GetErrorMessage(r));
3152
3153         r = ClearPopupIndex();
3154         SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to clear the popup index.", GetErrorMessage(r));
3155
3156         __pSelectedIndex = null;
3157
3158         if (__enableFadeEffect && __pViewConfig->__ignoreTouchEvent == false && __scrollVisibility == true)
3159         {
3160                 r = SetScrollVisibility(false);
3161                 SysTryReturn(NID_UI_CTRL, r == E_SUCCESS, true, r, "[%s] Failed to fade out fastscroll.", GetErrorMessage(r));
3162         }
3163
3164         return true;
3165 }
3166
3167 result
3168 _FastScrollPresenter::AddIndexView(_FastScrollIndex& baseIndex)
3169 {
3170         return AddIndexView(GetIndexViewCount(), baseIndex);
3171 }
3172
3173 result
3174 _FastScrollPresenter::AddIndexView(int indexLevel, _FastScrollIndex& baseIndex)
3175 {
3176         result r = E_SUCCESS;
3177
3178         _FastScrollIndexView* pNewIndexView = _FastScrollIndexView::CreateFastScrollIndexViewN( *__pCtrlVe, *__pViewConfig);
3179         SysTryReturnResult(NID_UI_CTRL, pNewIndexView, GetLastResult(), "Propagating.");
3180
3181         r = __fastScroll.SetBounds(CalculateFastScrollBounds(GetIndexViewCount() + 1));
3182         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _FastScroll.");
3183
3184         r = pNewIndexView->SetIndexBounds(CalculateIndexBounds(indexLevel, baseIndex));
3185         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set bounds of the index view.");
3186
3187         r = pNewIndexView->SetBaseIndex(&baseIndex);
3188         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the index data for the index view.");
3189
3190         r = pNewIndexView->SetIndexVisibility(true);
3191         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set visibility of the index view.");
3192
3193         r = __indexViews.InsertAt(*pNewIndexView, indexLevel);
3194         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to change the last index view.");
3195
3196         return E_SUCCESS;
3197 }
3198
3199 result
3200 _FastScrollPresenter::RemoveIndexView(int indexLevel, bool fadeout)
3201 {
3202         result r = E_SUCCESS;
3203
3204         int indexViewCount = GetIndexViewCount();
3205         if (indexLevel < indexViewCount)
3206         {
3207                 _FastScrollIndexView* pIndexView = GetIndexView(indexLevel);
3208                 SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
3209
3210                 if (fadeout)
3211                 {
3212                         r = pIndexView->FadeOutAndDestroy();
3213                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to request to fade out of the index view.");
3214                 }
3215
3216                 r = __indexViews.Remove(*pIndexView, false);
3217                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to remove the index views.");
3218
3219                 // initialize the fastscroll control
3220                 r = __fastScroll.SetBounds(CalculateFastScrollBounds(GetIndexViewCount()));
3221                 SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _FastScroll");
3222         }
3223
3224         return E_SUCCESS;
3225 }
3226
3227 result
3228 _FastScrollPresenter::RemoveAllIndexViews(bool fadeout)
3229 {
3230         result r = E_SUCCESS;
3231
3232         if (fadeout)
3233         {
3234                 int indexViewCount = GetIndexViewCount();
3235                 for (int i = 0; i < indexViewCount; i++)
3236                 {
3237                         _FastScrollIndexView* pIndexView = GetIndexView(i);
3238                         SysTryReturnResult(NID_UI_CTRL, pIndexView, GetLastResult(), "Failed to get the index view.");
3239
3240                         r = pIndexView->FadeOutAndDestroy();
3241                         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to request to fade out of the index view.");
3242                 }
3243         }
3244
3245         __indexViews.RemoveAll(true);
3246
3247         // initialize the fastscroll control
3248         r = __fastScroll.SetBounds(CalculateFastScrollBounds(0));
3249         SysTryReturnResult(NID_UI_CTRL, r == E_SUCCESS, r, "Failed to set the bounds of _FastScroll.");
3250
3251         return E_SUCCESS;
3252 }
3253
3254 _FastScrollIndexView*
3255 _FastScrollPresenter::GetIndexView(int indexLevel) const
3256 {
3257         Object* pIndexView = const_cast<Object*>(__indexViews.GetAt(indexLevel));
3258         SysTryReturn(NID_UI_CTRL, pIndexView, null, GetLastResult(), "[%s] Failed to get the index view.",
3259                         GetErrorMessage(GetLastResult()));
3260
3261         return dynamic_cast<_FastScrollIndexView*>(pIndexView);
3262 }
3263
3264 int
3265 _FastScrollPresenter::GetIndexViewCount(void) const
3266 {
3267         return __indexViews.GetCount();
3268 }
3269
3270 } } } // Tizen::Ui::Controls