[dali_1.1.9] Merge branch 'devel/master'
[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, "scrollDirection",                   STRING, SCROLL_DIRECTION          )
137 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHeightPolicy",             STRING, INDICATOR_HEIGHT_POLICY   )
138 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorFixedHeight",              FLOAT,  INDICATOR_FIXED_HEIGHT    )
139 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorShowDuration",             FLOAT,  INDICATOR_SHOW_DURATION   )
140 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "indicatorHideDuration",             FLOAT,  INDICATOR_HIDE_DURATION   )
141 DALI_PROPERTY_REGISTRATION( Toolkit, ScrollBar, "scrollPositionIntervals",           ARRAY,  SCROLL_POSITION_INTERVALS )
142
143 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "panFinished",                       PAN_FINISHED_SIGNAL )
144 DALI_SIGNAL_REGISTRATION(   Toolkit, ScrollBar, "scrollPositionIntervalReached",     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   mIndicatorShowAlpha(1.0f),
156   mDirection(direction),
157   mScrollableObject(WeakHandleBase()),
158   mPropertyScrollPosition(Property::INVALID_INDEX),
159   mPropertyMinScrollPosition(Property::INVALID_INDEX),
160   mPropertyMaxScrollPosition(Property::INVALID_INDEX),
161   mPropertyScrollContentSize(Property::INVALID_INDEX),
162   mIndicatorShowDuration(DEFAULT_INDICATOR_SHOW_DURATION),
163   mIndicatorHideDuration(DEFAULT_INDICATOR_HIDE_DURATION),
164   mScrollStart(0.0f),
165   mCurrentScrollPosition(0.0f),
166   mIndicatorHeightPolicy(Toolkit::ScrollBar::Variable),
167   mIndicatorFixedHeight(DEFAULT_INDICATOR_FIXED_HEIGHT),
168   mIsPanning(false),
169   mIndicatorFirstShow(true)
170 {
171 }
172
173 ScrollBar::~ScrollBar()
174 {
175 }
176
177 void ScrollBar::OnInitialize()
178 {
179   CreateDefaultIndicatorActor();
180   Self().SetDrawMode(DrawMode::OVERLAY_2D);
181 }
182
183 void ScrollBar::SetScrollPropertySource( Handle handle, Property::Index propertyScrollPosition, Property::Index propertyMinScrollPosition, Property::Index propertyMaxScrollPosition, Property::Index propertyScrollContentSize )
184 {
185   if( handle
186       && propertyScrollPosition != Property::INVALID_INDEX
187       && propertyMinScrollPosition != Property::INVALID_INDEX
188       && propertyMaxScrollPosition != Property::INVALID_INDEX
189       && propertyScrollContentSize != Property::INVALID_INDEX )
190   {
191     mScrollableObject = WeakHandleBase(handle);
192     mPropertyScrollPosition = propertyScrollPosition;
193     mPropertyMinScrollPosition = propertyMinScrollPosition;
194     mPropertyMaxScrollPosition = propertyMaxScrollPosition;
195     mPropertyScrollContentSize = propertyScrollContentSize;
196
197     ApplyConstraints();
198   }
199   else
200   {
201     DALI_LOG_ERROR("Can not set empty handle of source object or invalid source property index\n");
202   }
203 }
204
205 void ScrollBar::CreateDefaultIndicatorActor()
206 {
207   Image indicatorImage = ResourceImage::New( DEFAULT_INDICATOR_IMAGE_PATH );
208   ImageActor indicator = ImageActor::New( indicatorImage );
209   indicator.SetNinePatchBorder( DEFAULT_INDICATOR_NINE_PATCH_BORDER );
210   indicator.SetStyle( ImageActor::STYLE_NINE_PATCH );
211   indicator.SetParentOrigin( ParentOrigin::TOP_LEFT );
212   indicator.SetAnchorPoint( AnchorPoint::TOP_LEFT );
213
214   SetScrollIndicator(indicator);
215 }
216
217 void ScrollBar::SetScrollIndicator( Actor indicator )
218 {
219   // Don't allow empty handle
220   if( indicator )
221   {
222     mIndicator = indicator;
223     mIndicatorFirstShow = true;
224     Self().Add(mIndicator);
225
226     EnableGestureDetection(Gesture::Type(Gesture::Pan));
227
228     PanGestureDetector detector( GetPanGestureDetector() );
229     detector.DetachAll();
230     detector.Attach( mIndicator );
231
232     unsigned int childCount = mIndicator.GetChildCount();
233     for ( unsigned int index = 0; index < childCount; index++ )
234     {
235       Actor child = mIndicator.GetChildAt( index );
236       if ( child )
237       {
238         detector.Attach( child );
239       }
240     }
241   }
242   else
243   {
244     DALI_LOG_ERROR("Empty handle of scroll indicator\n");
245   }
246 }
247
248 Actor ScrollBar::GetScrollIndicator()
249 {
250   return mIndicator;
251 }
252
253 void ScrollBar::ApplyConstraints()
254 {
255   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
256
257   if( scrollableHandle )
258   {
259     if(mIndicatorSizeConstraint)
260     {
261       mIndicatorSizeConstraint.Remove();
262     }
263
264     // Set indicator height according to the indicator's height policy
265     if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
266     {
267       mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
268     }
269     else
270     {
271       mIndicatorSizeConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::SIZE, IndicatorSizeConstraint() );
272       mIndicatorSizeConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
273       mIndicatorSizeConstraint.AddSource( Source( scrollableHandle, mPropertyScrollContentSize ) );
274       mIndicatorSizeConstraint.Apply();
275     }
276
277     if(mIndicatorPositionConstraint)
278     {
279       mIndicatorPositionConstraint.Remove();
280     }
281
282     mIndicatorPositionConstraint = Constraint::New<Vector3>( mIndicator, Actor::Property::POSITION, IndicatorPositionConstraint() );
283     mIndicatorPositionConstraint.AddSource( LocalSource( Actor::Property::SIZE ) );
284     mIndicatorPositionConstraint.AddSource( ParentSource( Actor::Property::SIZE ) );
285     mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyScrollPosition ) );
286     mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMinScrollPosition ) );
287     mIndicatorPositionConstraint.AddSource( Source( scrollableHandle, mPropertyMaxScrollPosition ) );
288     mIndicatorPositionConstraint.Apply();
289   }
290 }
291
292 void ScrollBar::SetScrollPositionIntervals( const Dali::Vector<float>& positions )
293 {
294   mScrollPositionIntervals = positions;
295
296   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
297
298   if( scrollableHandle )
299   {
300     if( mPositionNotification )
301     {
302       scrollableHandle.RemovePropertyNotification(mPositionNotification);
303     }
304
305     mPositionNotification = scrollableHandle.AddPropertyNotification( mPropertyScrollPosition, VariableStepCondition(mScrollPositionIntervals) );
306     mPositionNotification.NotifySignal().Connect( this, &ScrollBar::OnScrollPositionIntervalReached );
307   }
308 }
309
310 Dali::Vector<float> ScrollBar::GetScrollPositionIntervals() const
311 {
312   return mScrollPositionIntervals;
313 }
314
315 void ScrollBar::OnScrollPositionIntervalReached(PropertyNotification& source)
316 {
317   // Emit the signal to notify the scroll position crossing
318   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
319   if(scrollableHandle)
320   {
321     mScrollPositionIntervalReachedSignal.Emit(scrollableHandle.GetProperty<float>(mPropertyScrollPosition));
322   }
323 }
324
325 void ScrollBar::ShowIndicator()
326 {
327   // Cancel any animation
328   if(mAnimation)
329   {
330     mAnimation.Clear();
331     mAnimation.Reset();
332   }
333
334   if( mIndicatorFirstShow )
335   {
336     // Preserve the alpha value from the stylesheet
337     mIndicatorShowAlpha = Self().GetCurrentColor().a;
338     mIndicatorFirstShow = false;
339   }
340
341   if(mIndicatorShowDuration > 0.0f)
342   {
343     mAnimation = Animation::New( mIndicatorShowDuration );
344     mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), mIndicatorShowAlpha, AlphaFunction::EASE_IN );
345     mAnimation.Play();
346   }
347   else
348   {
349     mIndicator.SetOpacity(mIndicatorShowAlpha);
350   }
351 }
352
353 void ScrollBar::HideIndicator()
354 {
355   // Cancel any animation
356   if(mAnimation)
357   {
358     mAnimation.Clear();
359     mAnimation.Reset();
360   }
361
362   if(mIndicatorHideDuration > 0.0f)
363   {
364     mAnimation = Animation::New( mIndicatorHideDuration );
365     mAnimation.AnimateTo( Property( mIndicator, Actor::Property::COLOR_ALPHA ), 0.0f, AlphaFunction::EASE_IN );
366     mAnimation.Play();
367   }
368   else
369   {
370     mIndicator.SetOpacity(0.0f);
371   }
372 }
373
374 bool ScrollBar::OnPanGestureProcessTick()
375 {
376   // Update the scroll position property.
377   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
378   if( scrollableHandle )
379   {
380     scrollableHandle.SetProperty(mPropertyScrollPosition, mCurrentScrollPosition);
381   }
382
383   return true;
384 }
385
386 void ScrollBar::OnPan( const PanGesture& gesture )
387 {
388   Handle scrollableHandle = mScrollableObject.GetBaseHandle();
389
390   if(scrollableHandle)
391   {
392     Dali::Toolkit::ItemView itemView = Dali::Toolkit::ItemView::DownCast(scrollableHandle);
393
394     switch(gesture.state)
395     {
396       case Gesture::Started:
397       {
398         if( !mPanProcessTimer )
399         {
400           // Make sure the pan gesture is only being processed once per frame.
401           mPanProcessTimer = Timer::New( DEFAULT_PAN_GESTURE_PROCESS_TIME );
402           mPanProcessTimer.TickSignal().Connect( this, &ScrollBar::OnPanGestureProcessTick );
403           mPanProcessTimer.Start();
404         }
405
406         ShowIndicator();
407         mScrollStart = scrollableHandle.GetProperty<float>(mPropertyScrollPosition);
408         mGestureDisplacement = Vector3::ZERO;
409         mIsPanning = true;
410
411         break;
412       }
413       case Gesture::Continuing:
414       {
415         Vector3 delta(gesture.displacement.x, gesture.displacement.y, 0.0f);
416         mGestureDisplacement+=delta;
417
418         Vector3 span = Self().GetCurrentSize() - mIndicator.GetCurrentSize();
419         float minScrollPosition = scrollableHandle.GetProperty<float>(mPropertyMinScrollPosition);
420         float maxScrollPosition = scrollableHandle.GetProperty<float>(mPropertyMaxScrollPosition);
421         float domainSize = maxScrollPosition - minScrollPosition;
422
423         mCurrentScrollPosition = mScrollStart - mGestureDisplacement.y * domainSize / span.y;
424         mCurrentScrollPosition = 0.0f - std::min(maxScrollPosition, std::max(-mCurrentScrollPosition, minScrollPosition));
425
426         break;
427       }
428       default:
429       {
430         mIsPanning = false;
431
432         if( mPanProcessTimer )
433         {
434           // Destroy the timer when pan gesture is finished.
435           mPanProcessTimer.Stop();
436           mPanProcessTimer.TickSignal().Disconnect( this, &ScrollBar::OnPanGestureProcessTick );
437           mPanProcessTimer.Reset();
438         }
439
440         if(itemView)
441         {
442           // Refresh the ItemView cache with extra items
443           GetImpl(itemView).DoRefresh(mCurrentScrollPosition, true);
444         }
445
446         mPanFinishedSignal.Emit();
447
448         break;
449       }
450     }
451
452     if(itemView)
453     {
454       // Disable automatic refresh in ItemView during fast scrolling
455       GetImpl(itemView).SetRefreshEnabled(!mIsPanning);
456     }
457   }
458 }
459
460 void ScrollBar::OnSizeSet( const Vector3& size )
461 {
462   if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
463   {
464     mIndicator.SetSize(size.width, mIndicatorFixedHeight);
465   }
466 }
467
468 void ScrollBar::SetScrollDirection( Toolkit::ScrollBar::Direction direction )
469 {
470   mDirection = direction;
471 }
472
473 Toolkit::ScrollBar::Direction ScrollBar::GetScrollDirection() const
474 {
475   return mDirection;
476 }
477
478 void ScrollBar::SetIndicatorHeightPolicy( Toolkit::ScrollBar::IndicatorHeightPolicy policy )
479 {
480   mIndicatorHeightPolicy = policy;
481   ApplyConstraints();
482 }
483
484 Toolkit::ScrollBar::IndicatorHeightPolicy ScrollBar::GetIndicatorHeightPolicy() const
485 {
486   return mIndicatorHeightPolicy;
487 }
488
489 void ScrollBar::SetIndicatorFixedHeight( float height )
490 {
491   mIndicatorFixedHeight = height;
492
493   if(mIndicatorHeightPolicy == Toolkit::ScrollBar::Fixed)
494   {
495     mIndicator.SetSize(Self().GetCurrentSize().width, mIndicatorFixedHeight);
496   }
497 }
498
499 float ScrollBar::GetIndicatorFixedHeight() const
500 {
501   return mIndicatorFixedHeight;
502 }
503
504 void ScrollBar::SetIndicatorShowDuration( float durationSeconds )
505 {
506   mIndicatorShowDuration = durationSeconds;
507 }
508
509 float ScrollBar::GetIndicatorShowDuration() const
510 {
511   return mIndicatorShowDuration;
512 }
513
514 void ScrollBar::SetIndicatorHideDuration( float durationSeconds )
515 {
516   mIndicatorHideDuration = durationSeconds;
517 }
518
519 float ScrollBar::GetIndicatorHideDuration() const
520 {
521   return mIndicatorHideDuration;
522 }
523
524 void ScrollBar::OnScrollDirectionPropertySet( Property::Value propertyValue )
525 {
526   std::string directionName( propertyValue.Get<std::string>() );
527   if(directionName == "Vertical")
528   {
529     SetScrollDirection(Toolkit::ScrollBar::Vertical);
530   }
531   else if(directionName == "Horizontal")
532   {
533     SetScrollDirection(Toolkit::ScrollBar::Horizontal);
534   }
535   else
536   {
537     DALI_ASSERT_ALWAYS( !"ScrollBar::OnScrollDirectionPropertySet(). Invalid Property value." );
538   }
539 }
540
541 void ScrollBar::OnIndicatorHeightPolicyPropertySet( Property::Value propertyValue )
542 {
543   std::string policyName( propertyValue.Get<std::string>() );
544   if(policyName == "Variable")
545   {
546     SetIndicatorHeightPolicy(Toolkit::ScrollBar::Variable);
547   }
548   else if(policyName == "Fixed")
549   {
550     SetIndicatorHeightPolicy(Toolkit::ScrollBar::Fixed);
551   }
552   else
553   {
554     DALI_ASSERT_ALWAYS( !"ScrollBar::OnIndicatorHeightPolicyPropertySet(). Invalid Property value." );
555   }
556 }
557
558 bool ScrollBar::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
559 {
560   Dali::BaseHandle handle( object );
561
562   bool connected( true );
563   Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( handle );
564
565   if( 0 == strcmp( signalName.c_str(), PAN_FINISHED_SIGNAL ) )
566   {
567     scrollBar.PanFinishedSignal().Connect( tracker, functor );
568   }
569   else if( 0 == strcmp( signalName.c_str(), SCROLL_POSITION_INTERVAL_REACHED_SIGNAL ) )
570   {
571     scrollBar.ScrollPositionIntervalReachedSignal().Connect( tracker, functor );
572   }
573   else
574   {
575     // signalName does not match any signal
576     connected = false;
577   }
578
579   return connected;
580 }
581
582 void ScrollBar::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
583 {
584   Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
585
586   if( scrollBar )
587   {
588     ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
589     switch( index )
590     {
591       case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
592       {
593         scrollBarImpl.OnScrollDirectionPropertySet( value );
594         break;
595       }
596       case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
597       {
598         scrollBarImpl.OnIndicatorHeightPolicyPropertySet( value );
599         break;
600       }
601       case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
602       {
603         scrollBarImpl.SetIndicatorFixedHeight(value.Get<float>());
604         break;
605       }
606       case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
607       {
608         scrollBarImpl.SetIndicatorShowDuration(value.Get<float>());
609         break;
610       }
611       case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
612       {
613         scrollBarImpl.SetIndicatorHideDuration(value.Get<float>());
614         break;
615       }
616       case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
617       {
618         Property::Array* array = value.GetArray();
619         if( array )
620         {
621           Dali::Vector<float> positions;
622           size_t positionCount = array->Count();
623           positions.Resize( positionCount );
624           for( size_t i = 0; i != positionCount; ++i )
625           {
626             array->GetElementAt( i ).Get( positions[i] );
627           }
628
629           scrollBarImpl.SetScrollPositionIntervals(positions);
630         }
631         break;
632       }
633     }
634   }
635 }
636
637 Property::Value ScrollBar::GetProperty( BaseObject* object, Property::Index index )
638 {
639   Property::Value value;
640
641   Toolkit::ScrollBar scrollBar = Toolkit::ScrollBar::DownCast( Dali::BaseHandle( object ) );
642
643   if( scrollBar )
644   {
645     ScrollBar& scrollBarImpl( GetImpl( scrollBar ) );
646     switch( index )
647     {
648       case Toolkit::ScrollBar::Property::SCROLL_DIRECTION:
649       {
650         value = SCROLL_DIRECTION_NAME[ scrollBarImpl.GetScrollDirection() ];
651         break;
652       }
653       case Toolkit::ScrollBar::Property::INDICATOR_HEIGHT_POLICY:
654       {
655         value = INDICATOR_HEIGHT_POLICY_NAME[ scrollBarImpl.GetIndicatorHeightPolicy() ];
656         break;
657       }
658       case Toolkit::ScrollBar::Property::INDICATOR_FIXED_HEIGHT:
659       {
660         value = scrollBarImpl.GetIndicatorFixedHeight();
661         break;
662       }
663       case Toolkit::ScrollBar::Property::INDICATOR_SHOW_DURATION:
664       {
665         value = scrollBarImpl.GetIndicatorShowDuration();
666         break;
667       }
668       case Toolkit::ScrollBar::Property::INDICATOR_HIDE_DURATION:
669       {
670         value = scrollBarImpl.GetIndicatorHideDuration();
671         break;
672       }
673       case Toolkit::ScrollBar::Property::SCROLL_POSITION_INTERVALS:
674       {
675         Property::Value value( Property::ARRAY );
676         Property::Array* array = value.GetArray();
677
678         if( array )
679         {
680           Dali::Vector<float> positions = scrollBarImpl.GetScrollPositionIntervals();
681           size_t positionCount( array->Count() );
682           for( size_t i( 0 ); i != positionCount; ++i )
683           {
684             array->PushBack( positions[i] );
685           }
686         }
687         break;
688       }
689     }
690   }
691   return value;
692 }
693
694 Toolkit::ScrollBar ScrollBar::New(Toolkit::ScrollBar::Direction direction)
695 {
696   // Create the implementation, temporarily owned by this handle on stack
697   IntrusivePtr< ScrollBar > impl = new ScrollBar(direction);
698
699   // Pass ownership to CustomActor handle
700   Toolkit::ScrollBar handle( *impl );
701
702   // Second-phase init of the implementation
703   // This can only be done after the CustomActor connection has been made...
704   impl->Initialize();
705
706   return handle;
707 }
708
709 } // namespace Internal
710
711 } // namespace Toolkit
712
713 } // namespace Dali