Fix compile error. Non initialized variable.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / scrollable / scrollable-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 // EXTERNAL INCLUDES
19 #include <cstring> // for strcmp
20 #include <dali/public-api/object/type-registry.h>
21 #include <dali/public-api/object/type-registry-helper.h>
22
23 // INTERNAL INCLUDES
24 #include <dali-toolkit/internal/controls/scrollable/scrollable-impl.h>
25
26 using namespace Dali;
27
28 namespace Dali
29 {
30
31 namespace Toolkit
32 {
33
34 namespace Internal
35 {
36
37 namespace
38 {
39
40 BaseHandle Create()
41 {
42   // empty handle as we cannot create Scrollable (but type registered for scroll signal)
43   return BaseHandle();
44 }
45
46 // Setup properties, signals and actions using the type-registry.
47 DALI_TYPE_REGISTRATION_BEGIN( Toolkit::Scrollable, Toolkit::Control, Create );
48
49 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootEffectColor",      VECTOR4, OVERSHOOT_EFFECT_COLOR    )
50 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootAnimationSpeed",   FLOAT,   OVERSHOOT_ANIMATION_SPEED )
51 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootEnabled",          BOOLEAN, OVERSHOOT_ENABLED )
52 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "overshootSize",             VECTOR2, OVERSHOOT_SIZE )
53 DALI_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollToAlphaFunction",     INTEGER, SCROLL_TO_ALPHA_FUNCTION )
54
55 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollRelativePosition",   VECTOR2, SCROLL_RELATIVE_POSITION)
56 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollPositionMin",        VECTOR2, SCROLL_POSITION_MIN)
57 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, Scrollable, "scrollPositionMinX",    SCROLL_POSITION_MIN_X, SCROLL_POSITION_MIN, 0)
58 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, Scrollable, "scrollPositionMinY",    SCROLL_POSITION_MIN_Y, SCROLL_POSITION_MIN, 1)
59 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "scrollPositionMax",        VECTOR2, SCROLL_POSITION_MAX)
60 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, Scrollable, "scrollPositionMaxX",    SCROLL_POSITION_MAX_X, SCROLL_POSITION_MAX, 0)
61 DALI_ANIMATABLE_PROPERTY_COMPONENT_REGISTRATION( Toolkit, Scrollable, "scrollPositionMaxY",    SCROLL_POSITION_MAX_Y, SCROLL_POSITION_MAX, 1)
62 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "canScrollVertical",        BOOLEAN, CAN_SCROLL_VERTICAL)
63 DALI_ANIMATABLE_PROPERTY_REGISTRATION( Toolkit, Scrollable, "canScrollHorizontal",      BOOLEAN, CAN_SCROLL_HORIZONTAL)
64
65 DALI_SIGNAL_REGISTRATION(              Toolkit, Scrollable, "scrollStarted",                     SIGNAL_SCROLL_STARTED    )
66 DALI_SIGNAL_REGISTRATION(              Toolkit, Scrollable, "scrollCompleted",                   SIGNAL_SCROLL_COMPLETED  )
67 DALI_SIGNAL_REGISTRATION(              Toolkit, Scrollable, "scrollUpdated",                     SIGNAL_SCROLL_UPDATED    )
68
69 DALI_TYPE_REGISTRATION_END()
70
71 const Vector4 DEFAULT_OVERSHOOT_COLOUR(0.0f, 0.64f, 0.85f, 0.25f);
72 const float DEFAULT_OVERSHOOT_ANIMATION_SPEED(120.0f); // 120 pixels per second
73 const Vector2 OVERSHOOT_DEFAULT_SIZE( 720.0f, 42.0f );
74
75 }
76
77 ///////////////////////////////////////////////////////////////////////////////////////////////////
78 // Scrollable
79 ///////////////////////////////////////////////////////////////////////////////////////////////////
80
81 // Scrollable controls are not layout containers so they dont need size negotiation..
82 // we dont want size negotiation while scrolling if we can avoid it
83 Scrollable::Scrollable()
84 : Control( ControlBehaviour( DISABLE_SIZE_NEGOTIATION ) ),
85   mOvershootEffectColor(  DEFAULT_OVERSHOOT_COLOUR ),
86   mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
87   mOvershootSize( OVERSHOOT_DEFAULT_SIZE ),
88   mScrollToAlphaFunction( AlphaFunction::EASE_OUT ),
89   mScrollStartedSignal(),
90   mScrollUpdatedSignal(),
91   mScrollCompletedSignal(),
92   mOvershootEnabled(true)
93 {
94 }
95
96 Scrollable::Scrollable( ControlBehaviour behaviourFlags )
97 : Control( ControlBehaviour( behaviourFlags ) ),
98   mOvershootEffectColor(  DEFAULT_OVERSHOOT_COLOUR ),
99   mOvershootAnimationSpeed ( DEFAULT_OVERSHOOT_ANIMATION_SPEED ),
100   mOvershootSize( OVERSHOOT_DEFAULT_SIZE ),
101   mScrollToAlphaFunction( AlphaFunction::EASE_OUT ),
102   mScrollStartedSignal(),
103   mScrollUpdatedSignal(),
104   mScrollCompletedSignal(),
105   mOvershootEnabled(true)
106 {
107 }
108
109 Scrollable::~Scrollable()
110 {
111 }
112
113 bool Scrollable::IsOvershootEnabled() const
114 {
115   return mOvershootEnabled;
116 }
117
118 void Scrollable::SetOvershootEnabled(bool enable)
119 {
120   EnableScrollOvershoot(enable);
121   mOvershootEnabled = enable;
122 }
123
124 Vector4 Scrollable::GetOvershootEffectColor() const
125 {
126   return mOvershootEffectColor;
127 };
128
129 void Scrollable::SetOvershootAnimationSpeed( float pixelsPerSecond )
130 {
131   mOvershootAnimationSpeed = pixelsPerSecond;
132 }
133
134 float Scrollable::GetOvershootAnimationSpeed() const
135 {
136   return mOvershootAnimationSpeed;
137 };
138
139 const Vector2& Scrollable::GetOvershootSize() const
140 {
141   return mOvershootSize;
142 }
143
144 Toolkit::Scrollable::ScrollStartedSignalType& Scrollable::ScrollStartedSignal()
145 {
146   return mScrollStartedSignal;
147 }
148
149 Toolkit::Scrollable::ScrollUpdatedSignalType& Scrollable::ScrollUpdatedSignal()
150 {
151   return mScrollUpdatedSignal;
152 }
153
154 Toolkit::Scrollable::ScrollCompletedSignalType& Scrollable::ScrollCompletedSignal()
155 {
156   return mScrollCompletedSignal;
157 }
158
159 bool Scrollable::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
160 {
161   Dali::BaseHandle handle( object );
162
163   bool connected( true );
164   Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( handle );
165
166   if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_STARTED ) )
167   {
168     scrollable.ScrollStartedSignal().Connect( tracker, functor );
169   }
170   else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_UPDATED ) )
171   {
172     scrollable.ScrollUpdatedSignal().Connect( tracker, functor );
173   }
174   else if( 0 == strcmp( signalName.c_str(), SIGNAL_SCROLL_COMPLETED ) )
175   {
176     scrollable.ScrollCompletedSignal().Connect( tracker, functor );
177   }
178   else
179   {
180     // signalName does not match any signal
181     connected = false;
182   }
183
184   return connected;
185 }
186
187 void Scrollable::SetProperty( BaseObject* object, Property::Index index, const Property::Value& value )
188 {
189   Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
190
191   if( scrollable )
192   {
193     Scrollable& scrollableImpl( GetImpl( scrollable ) );
194     switch( index )
195     {
196       case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
197       {
198         scrollableImpl.SetOvershootEffectColor( value.Get<Vector4>() );
199         break;
200       }
201       case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
202       {
203         scrollableImpl.SetOvershootAnimationSpeed( value.Get<float>() );
204         break;
205       }
206       case Toolkit::Scrollable::Property::OVERSHOOT_ENABLED:
207       {
208         scrollableImpl.SetOvershootEnabled( value.Get<bool>() );
209         break;
210       }
211       case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
212       {
213         scrollableImpl.SetOvershootSize( value.Get<Vector2>() );
214         break;
215       }
216       case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
217       {
218         int alphaFunction = value.Get<int>();
219
220         if( alphaFunction >= AlphaFunction::DEFAULT &&
221             alphaFunction <  AlphaFunction::COUNT )
222         {
223           scrollableImpl.mScrollToAlphaFunction = static_cast< AlphaFunction::BuiltinFunction >( alphaFunction );
224         }
225         break;
226       }
227     }
228   }
229 }
230
231 Property::Value Scrollable::GetProperty( BaseObject* object, Property::Index index )
232 {
233   Property::Value value;
234
235   Toolkit::Scrollable scrollable = Toolkit::Scrollable::DownCast( Dali::BaseHandle( object ) );
236
237   if( scrollable )
238   {
239     Scrollable& scrollableImpl( GetImpl( scrollable ) );
240     switch( index )
241     {
242       case Toolkit::Scrollable::Property::OVERSHOOT_EFFECT_COLOR:
243       {
244         value = scrollableImpl.GetOvershootEffectColor();
245         break;
246       }
247       case Toolkit::Scrollable::Property::OVERSHOOT_ANIMATION_SPEED:
248       {
249         value = scrollableImpl.GetOvershootAnimationSpeed();
250         break;
251       }
252       case Toolkit::Scrollable::Property::OVERSHOOT_ENABLED:
253       {
254         value = scrollableImpl.IsOvershootEnabled();
255         break;
256       }
257       case Toolkit::Scrollable::Property::OVERSHOOT_SIZE:
258       {
259         value = scrollableImpl.mOvershootSize;
260         break;
261       }
262       case Toolkit::Scrollable::Property::SCROLL_TO_ALPHA_FUNCTION:
263       {
264         value = static_cast<int>( scrollableImpl.mScrollToAlphaFunction );
265         break;
266       }
267     }
268   }
269
270   return value;
271 }
272
273 } // namespace Internal
274
275 } // namespace Toolkit
276
277 } // namespace Dali