Fix prevent issues
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scroll-bar / scroll-bar-impl.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali-toolkit/internal/controls/scroll-bar/scroll-bar-impl.h>
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23 #include <dali/public-api/animation/constraint.h>
24 #include <dali/public-api/animation/constraints.h>
25 #include <dali/public-api/images/resource-image.h>
26 #include <dali/public-api/object/type-registry.h>
27 #include <dali/public-api/object/property-array.h>
28 #include <dali/devel-api/object/type-registry-helper.h>
29 #include <dali/integration-api/debug.h>
30
31
32 // INTERNAL INCLUDES
33 #include <dali-toolkit/internal/controls/scrollable/item-view/item-view-impl.h>
34
35 using namespace Dali;
36
37 namespace
38 {
39
40 const char* DEFAULT_INDICATOR_IMAGE_PATH = DALI_IMAGE_DIR "popup_scroll.png";
41 const Vector4 DEFAULT_INDICATOR_NINE_PATCH_BORDER(4.0f, 9.0f, 7.0f, 11.0f);
42 const float MINIMUM_INDICATOR_HEIGHT(20.0f); // The minimum indicator height for the nine patch border
43 const float DEFAULT_SLIDER_DEPTH(1.0f);
44 const float DEFAULT_INDICATOR_SHOW_DURATION(0.5f);
45 const float DEFAULT_INDICATOR_HIDE_DURATION(0.5f);
46 const float DEFAULT_PAN_GESTURE_PROCESS_TIME(16.7f); // 16.7 milliseconds, i.e. one frame
47 const float DEFAULT_INDICATOR_FIXED_HEIGHT(80.0f);
48
49 /**
50  * Indicator size constraint
51  * Indicator size depends on both indicator's parent size and the scroll content size
52  */
53 struct IndicatorSizeConstraint
54 {
55   IndicatorSizeConstraint()
56   {
57   }
58
59   /**
60    * Constraint operator
61    * @param[in] current The current indicator size
62    * @param[in] parentSizeProperty The parent size of scroll indicator.
63    * @return The new scroll indicator size.
64    */
65   void operator()(Vector3& current, const PropertyInputContainer& inputs )
66   {
67     const Vector3& parentSize = inputs[0]->GetVector3();
68     const float contentSize = inputs[1]->GetFloat();
69
70     float height = contentSize > parentSize.height ?
71                    parentSize.height * ( parentSize.height / contentSize ) :
72                    parentSize.height * ( (parentSize.height - contentSize * 0.5f) / parentSize.height);
73
74     current.y = std::max(MINIMUM_INDICATOR_HEIGHT, height);
75   }
76 };
77
78 /**
79  * Indicator position constraint
80  * Positions the indicator to reflect the current scroll position within the scroll domain.
81  */
82 struct IndicatorPositionConstraint
83 {
84   /**
85    * @param[in] minPosition The minimum limit of scroll position
86    * @param[in] maxPosition the maximum limit of scroll position
87    */
88   IndicatorPositionConstraint()
89   {
90   }
91
92   /**
93    * Constraint operator
94    * @param[in,out] current The current indicator position
95    * @param[in] inputs Contains the size of indicator, the size of indicator's parent, and the scroll position of the scrollable container (from 0.0 -> 1.0 in each axis)
96    * @return The new indicator position is returned.
97    */
98   void operator()( Vector3& current, const PropertyInputContainer& inputs )
99   {
100     const Vector3& indicatorSize = inputs[0]->GetVector3();
101     const Vector3& parentSize = inputs[1]->GetVector3();
102     const float scrollPosition = -inputs[2]->GetFloat();
103     const float minScrollPosition = inputs[3]->GetFloat();
104     const float maxScrollPosition = inputs[4]->GetFloat();
105
106     float relativePosition = std::max( 0.0f, std::min( 1.0f, (scrollPosition - minScrollPosition) / (maxScrollPosition - minScrollPosition) ) );
107     current.y = ( parentSize.height - indicatorSize.height ) * relativePosition;
108     current.z = DEFAULT_SLIDER_DEPTH;
109   }
110 };
111
112 } // unnamed namespace
113
114 namespace Dali
115 {
116
117 namespace Toolkit
118 {
119
120 namespace Internal
121 {
122
123 namespace
124 {
125
126 using namespace Dali;
127
128 BaseHandle Create()
129 {
130   return Toolkit::ScrollBar::New();
131 }
132
133 // Setup properties, signals and actions using the type-registry.
134 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::ScrollBar, Toolkit::Control, Create );
135
136 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scroll-direction",                  STRING, SCROLL_DIRECTION          )
137 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-height-policy",           STRING, INDICATOR_HEIGHT_POLICY   )
138 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-fixed-height",            FLOAT,  INDICATOR_FIXED_HEIGHT    )
139 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-show-duration",           FLOAT,  INDICATOR_SHOW_DURATION   )
140 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicator-hide-duration",           FLOAT,  INDICATOR_HIDE_DURATION   )
141 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scroll-position-intervals",         ARRAY,  SCROLL_POSITION_INTERVALS )
142
143 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "pan-finished",                      PAN_FINISHED_SIGNAL )
144 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "scroll-position-interval-reached",  SCROLL_POSITION_INTERVAL_REACHED_SIGNAL )
145
146 DALI_TYPE_REGISTRATION_END()
147
148 const char* SCROLL_DIRECTION_NAME[] = {"Vertical", "Horizontal"};
149 const char* INDICATOR_HEIGHT_POLICY_NAME[] = {"Variable", "Fixed"};
150
151 }
152
153 ScrollBar::ScrollBar(Toolkit::ScrollBar::Direction direction)
154 : Control( ControlBehaviour( REQUIRES_TOUCH_EVENTS | REQUIRES_STYLE_CHANGE_SIGNALS ) ),
155   mDirection(direction),
156   mScrollableObject(WeakHandleBase()),
157   mPropertyScrollPosition(Property::INVALID_INDEX),
158   mPropertyMinScrollPosition(Property::INVALID_INDEX),
159   mPropertyMaxScrollPosition(Property::INVALID_INDEX),
160   mPropertyScrollContentSize(Property::INVALID_INDEX),
161   mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION),
162   mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
163   mScrollStart(0.0f),
164   mIsPanning(false),
165   mCurrentScrollPosition(0.0f),
166   mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable),
167   mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT)
168 {
169 }
170
171 ScrollBar::~ScrollBar()
172 {
173 }
174
175 void ScrollBar::OnInitialize()
176 {
177   CreateDefaultIndicatorActor();
178   Self().SetDrawMode(DrawMode::OVERLAY_2D);
179 }
180
181 void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize )
182 {
183   if( handle
184       && propertyScrollPosition != Property::INVALID_INDEX
185       && propertyMinScrollPosition != Property::INVALID_INDEX
186       && propertyMaxScrollPosition != Property::INVALID_INDEX
187       && propertyScrollContentSize != Property::INVALID_INDEX )
188   {
189     mScrollableObject = WeakHandleBase(handle);
190     mPropertyScrollPosition = propertyScrollPosition;
191     mPropertyMinScrollPosition = propertyMinScrollPosition;
192     mPropertyMaxScrollPosition = propertyMaxScrollPosition;
193     mPropertyScrollContentSize = propertyScrollContentSize;
194
195     ApplyConstraints();
196   }
197   else
198   {
199     DALI_LOG_ERROR("Can not set empty handle of source object or invalid source property index\n");
200   }
201 }
202
203 void ScrollBar::CreateDefaultIndicatorActor()
204 {
205   Image indicatorImage = ResourceImage::New( DEFAULT_INDICATOR_IMAGE_PATH );
206   ImageActor indicator = ImageActor::New( indicatorImage );
207   indicator.SetNinePatchBorder( DEFAULT_INDICATOR_NINE_PATCH_BORDER );
208   indicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
209   indicator.SetParentOrigin( ParentOrigin::TOP_LEFT );
210   indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT );
211
212   SetScrollIndicator(indicator);
213 }
214
215 void ScrollBar::SetScrollIndicator( Actor indicator )
216 {
217   // Don't allow empty handle
218   if( indicator )
219   {
220     mIndicator = indicator;
221     Self().Add(mIndicator);
222
223     EnableGestureDetection(Gesture::Type(Gesture::Pan));
224
225     PanGestureDetector detector( GetPanGestureDetector() );
226     detector.DetachAll();
227     detector.Attach( mIndicator );
228
229     unsigned int childCount = mIndicator.GetChildCount();
230     for ( unsigned int index = 0; index < childCount; index++ )
231     {
232       Actor child = mIndicator.GetChildAt( index );
233       if ( child )
234       {
235         detector.Attach( child );
236       }
237     }
238   }
239   else
240   {
241     DALI_LOG_ERROR("Empty handle of scroll indicator\n");
242   }
243 }
244
245 Actor ScrollBar::GetScrollIndicator()
246 {
247   return mIndicator;
248 }
249
250 void ScrollBar::ApplyConstraints()
251 {
252   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
253
254   if( scrollableHandle )
255   {
256     if(mIndicatorSizeConstraint)
257     {
258       mIndicatorSizeConstraint.Remove();
259     }
260
261     // Set indicator height according to the indicator's height policy
262     if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
263     {
264       mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
265     }
266     else
267     {
268       mIndicatorSizeConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint() );
269       mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
270       mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) );
271       mIndicatorSizeConstraint.Apply();
272     }
273
274     if(mIndicatorPositionConstraint)
275     {
276       mIndicatorPositionConstraint.Remove();
277     }
278
279     mIndicatorPositionConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint() );
280     mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) );
281     mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
282     mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) );
283     mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) );
284     mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) );
285     mIndicatorPositionConstraint.Apply();
286   }
287 }
288
289 void ScrollBar::SetScrollPositionIntervals( const Dali::Vector<float>& positions )
290 {
291   mScrollPositionIntervals = positions;
292
293   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
294
295   if( scrollableHandle )
296   {
297     if( mPositionNotification )
298     {
299       scrollableHandle.RemovePropertyNotification(mPositionNotification);
300     }
301
302     mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) );
303     mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached );
304   }
305 }
306
307 Dali::Vector<float> ScrollBar::GetScrollPositionIntervals() const
308 {
309   return mScrollPositionIntervals;
310 }
311
312 void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source)
313 {
314   // Emit the signal to notify the scroll position crossing
315   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
316   if(scrollableHandle)
317   {
318     mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty<float>(mPropertyScrollPosition));
319   }
320 }
321
322 void ScrollBar::ShowIndicator()
323 {
324   // Cancel any animation
325   if(mAnimation)
326   {
327     mAnimation.Clear();
328     mAnimation.Reset();
329   }
330
331   if(mIndicatorShowDuration > 0.0f)
332   {
333     mAnimation = Animation::New( mIndicatorShowDuration );
334     mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 1.0f, AlphaFunction::EASE_IN );
335     mAnimation.Play();
336   }
337   else
338   {
339     mIndicator.SetOpacity(1.0f);
340   }
341 }
342
343 void ScrollBar::HideIndicator()
344 {
345   // Cancel any animation
346   if(mAnimation)
347   {
348     mAnimation.Clear();
349     mAnimation.Reset();
350   }
351
352   if(mIndicatorHideDuration > 0.0f)
353   {
354     mAnimation = Animation::New( mIndicatorHideDuration );
355     mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN );
356     mAnimation.Play();
357   }
358   else
359   {
360     mIndicator.SetOpacity(0.0f);
361   }
362 }
363
364 bool ScrollBar::OnPanGestureProcessTick()
365 {
366   // Update the scroll position property.
367   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
368   if( scrollableHandle )
369   {
370     scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
371   }
372
373   return true;
374 }
375
376 void ScrollBar::OnPan( const PanGesture& gesture )
377 {
378   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
379
380   if(scrollableHandle)
381   {
382     Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle);
383
384     switch(gesture.state)
385     {
386       case Gesture::Started:
387       {
388         if( !mPanProcessTimer )
389         {
390           // Make sure the pan gesture is only being processed once per frame.
391           mPanProcessTimer = Timer::New( DEFAULT_PAN_GESTURE_PROCESS_TIME );
392           mPanProcessTimer.TickSignal().Connect( this, &ScrollBar::OnPanGestureProcessTick );
393           mPanProcessTimer.Start();
394         }
395
396         ShowIndicator();
397         mScrollStart = scrollableHandle.GetProperty<float>(mPropertyScrollPosition);
398         mGestureDisplacement = Vector3::ZERO;
399         mIsPanning = true;
400
401         break;
402       }
403       case Gesture::Continuing:
404       {
405         Vector3 delta(gesture.displacement.x, gesture.displacement.y, 0.0f);
406         mGestureDisplacement+=delta;
407
408         Vector3 span = Self().GetCurrentSize() - mIndicator.GetCurrentSize();
409         float minScrollPosition = scrollableHandle.GetProperty<float>(mPropertyMinScrollPosition);
410         float maxScrollPosition = scrollableHandle.GetProperty<float>(mPropertyMaxScrollPosition);
411         float domainSize = maxScrollPosition - minScrollPosition;
412
413         mCurrentScrollPosition = mScrollStart - mGestureDisplacement.y * domainSize / span.y;
414         mCurrentScrollPosition = 0.0f - std::min(maxScrollPosition, std::max(-mCurrentScrollPosition, minScrollPosition));
415
416         break;
417       }
418       default:
419       {
420         mIsPanning = false;
421
422         if( mPanProcessTimer )
423         {
424           // Destroy the timer when pan gesture is finished.
425           mPanProcessTimer.Stop();
426           mPanProcessTimer.TickSignal().Disconnect( this, &ScrollBar::OnPanGestureProcessTick );
427           mPanProcessTimer.Reset();
428         }
429
430         if(itemView)
431         {
432           // Refresh the ItemView cache with extra items
433           GetImpl(itemView).DoRefresh(mCurrentScrollPosition, true);
434         }
435
436         mPanFinishedSignal.Emit();
437
438         break;
439       }
440     }
441
442     if(itemView)
443     {
444       // Disable automatic refresh in ItemView during fast scrolling
445       GetImpl(itemView).SetRefreshEnabled(!mIsPanning);
446     }
447   }
448 }
449
450 void ScrollBar::OnSizeSet( const Vector3& size )
451 {
452   if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
453   {
454     mIndicator.SetSize(size.width, mIndicatorFixedHeight);
455   }
456 }
457
458 void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction )
459 {
460   mDirection = direction;
461 }
462
463 Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const
464 {
465   return mDirection;
466 }
467
468 void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy )
469 {
470   mIndicatorHeightPolicy = policy;
471   ApplyConstraints();
472 }
473
474 Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() const
475 {
476   return mIndicatorHeightPolicy;
477 }
478
479 void ScrollBar::SetIndicatorFixedHeight( float height )
480 {
481   mIndicatorFixedHeight = height;
482
483   if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
484   {
485     mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
486   }
487 }
488
489 float ScrollBar::GetIndicatorFixedHeight() const
490 {
491   return mIndicatorFixedHeight;
492 }
493
494 void ScrollBar::SetIndicatorShowDuration( float durationSeconds )
495 {
496   mIndicatorShowDuration = durationSeconds;
497 }
498
499 float ScrollBar::GetIndicatorShowDuration() const
500 {
501   return mIndicatorShowDuration;
502 }
503
504 void ScrollBar::SetIndicatorHideDuration( float durationSeconds )
505 {
506   mIndicatorHideDuration = durationSeconds;
507 }
508
509 float ScrollBar::GetIndicatorHideDuration() const
510 {
511   return mIndicatorHideDuration;
512 }
513
514 void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue )
515 {
516   std::string directionName( propertyValue.Get<std::string>() );
517   if(directionName == "Vertical")
518   {
519     SetScrollDirection(Toolkit::ScrollBar::Vertical);
520   }
521   else if(directionName == "Horizontal")
522   {
523     SetScrollDirection(Toolkit::ScrollBar::Horizontal);
524   }
525   else
526   {
527     DALI_ASSERT_ALWAYS( !"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value." );
528   }
529 }
530
531 void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue )
532 {
533   std::string policyName( propertyValue.Get<std::string>() );
534   if(policyName == "Variable")
535   {
536     SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable);
537   }
538   else if(policyName == "Fixed")
539   {
540     SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
541   }
542   else
543   {
544     DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." );
545   }
546 }
547
548 bool ScrollBar::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
549 {
550   Dali::BaseHandle handle( object );
551
552   bool connected( true );
553   Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle );
554
555   if( 0 == strcmp( signalName.c_str(), PAN_FINISHED_SIGNAL ) )
556   {
557     scrollBar.PanFinishedSignal().Connect( tracker, functor );
558   }
559   else if( 0 == strcmp( signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) )
560   {
561     scrollBar.ScrollPositionIntervalReachedSignal().Connect( tracker, functor );
562   }
563   else
564   {
565     // signalName does not match any signal
566     connected = false;
567   }
568
569   return connected;
570 }
571
572 void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
573 {
574   Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
575
576   if( scrollBar )
577   {
578     ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
579     switch( index )
580     {
581       case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
582       {
583         scrollBarImpl.OnScrollDirectionPropertySet( value );
584         break;
585       }
586       case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
587       {
588         scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value );
589         break;
590       }
591       case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
592       {
593         scrollBarImpl.SetIndicatorFixedHeight(value.Get<float>());
594         break;
595       }
596       case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
597       {
598         scrollBarImpl.SetIndicatorShowDuration(value.Get<float>());
599         break;
600       }
601       case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
602       {
603         scrollBarImpl.SetIndicatorHideDuration(value.Get<float>());
604         break;
605       }
606       case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
607       {
608         Property::Array* array = value.GetArray();
609         if( array )
610         {
611           Dali::Vector<float> positions;
612           size_t positionCount = array->Count();
613           positions.Resize( positionCount );
614           for( size_t i = 0; i != positionCount; ++i )
615           {
616             array->GetElementAt( i ).Get( positions[i] );
617           }
618
619           scrollBarImpl.SetScrollPositionIntervals(positions);
620         }
621         break;
622       }
623     }
624   }
625 }
626
627 Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index )
628 {
629   Property::Value value;
630
631   Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
632
633   if( scrollBar )
634   {
635     ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
636     switch( index )
637     {
638       case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
639       {
640         value = SCROLL_DIRECTION_NAME[ scrollBarImpl.GetScrollDirection() ];
641         break;
642       }
643       case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
644       {
645         value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ];
646         break;
647       }
648       case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
649       {
650         value = scrollBarImpl.GetIndicatorFixedHeight();
651         break;
652       }
653       case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
654       {
655         value = scrollBarImpl.GetIndicatorShowDuration();
656         break;
657       }
658       case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
659       {
660         value = scrollBarImpl.GetIndicatorHideDuration();
661         break;
662       }
663       case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
664       {
665         Property::Value value( Property::ARRAY );
666         Property::Array* array = value.GetArray();
667
668         if( array )
669         {
670           Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
671           size_t positionCount( array->Count() );
672           for( size_t i( 0 ); i != positionCount; ++i )
673           {
674             array->PushBack( positions[i] );
675           }
676         }
677         break;
678       }
679     }
680   }
681   return value;
682 }
683
684 Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction)
685 {
686   // Create the implementation, temporarily owned by this handle on stack
687   IntrusivePtr< ScrollBar > impl = new ScrollBar(direction);
688
689   // Pass ownership to CustomActor handle
690   Toolkit::ScrollBar handle( *impl );
691
692   // Second-phase init of the implementation
693   // This can only be done after the CustomActor connection has been made...
694   impl->Initialize();
695
696   return handle;
697 }
698
699 } // namespace Internal
700
701 } // namespace Toolkit
702
703 } // namespace Dali