[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / progress-bar / progress-bar-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H
2 #define DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H
3
4 /*
5  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control-impl.h>
23 #include <dali/public-api/animation/animation.h>
24 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.h>
25 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
26 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
27 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 class ProgressBar;
39
40 typedef Dali::IntrusivePtr< ProgressBar > ProgressBarPtr;
41
42 /**
43  * @copydoc Toolkit::ProgressBar
44  */
45 class ProgressBar : public Control
46 {
47 public:
48
49   /**
50    * Create a new ProgressBar with predefined style.
51    * @param[in] progressBarStyle A style value that determines the shape of the progress bar.
52    * @return A public handle to the newly allocated ProgressBar.
53    */
54   static Dali::Toolkit::ProgressBar New( DevelProgressBar::Style progressBarStyle = DevelProgressBar::Style::LINEAR );
55
56 public:
57
58   // Properties
59
60   /**
61    * Set the value of the ProgressBar
62    *
63    * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
64    */
65   void SetProgressValue( float value );
66
67   /**
68    * Get the value of the ProgressBar
69    *
70    * @return The current value of the ProgressBar
71    */
72   float GetProgressValue() const;
73
74   /**
75    * Set the secondary progress value of the ProgressBar
76    *
77    * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
78    */
79   void SetSecondaryProgressValue( float value );
80
81   /**
82    * Get the secondary progress value of the ProgressBar
83    *
84    * @return The current secondary progress value of the ProgressBar
85    */
86   float GetSecondaryProgressValue() const;
87
88   /**
89    * Set the indeterminate state of the ProgressBar
90    *
91    * @param[in] value The value to set.
92    */
93   void SetIndeterminate( bool value );
94
95   /**
96    * Get the indeterminate state value of the ProgressBar
97    *
98    * @return The current determined state of the ProgressBar
99    */
100   bool GetIndeterminate() const;
101
102   /**
103    * Set the indeterminate visual transition of the ProgressBar
104    *
105    * @param[in] Transition data map to set.
106    */
107   void SetIndeterminateVisualTransition( Property::Map transtion );
108
109   /**
110    * Get the indeterminate visual transition data map of the ProgressBar
111    *
112    * @return The current indeterminate visual transition data map of the ProgressBar
113    */
114   Property::Map GetIndeterminateVisualTransition() const;
115
116   /**
117    * Play the indeterminate visual transition
118    */
119   void PlayIndeterminateVisualTransition();
120
121 public:
122   //Signals
123
124   /**
125    * @copydoc toolkit::progressbar::valuechangedsignal()
126    */
127   Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
128
129
130   /**
131    * Connects a callback function with the object's signals.
132    * @param[in] object The object providing the signal.
133    * @param[in] tracker Used to disconnect the signal.
134    * @param[in] signalName The signal to connect to.
135    * @param[in] functor A newly allocated FunctorDelegate.
136    * @return True if the signal was connected.
137    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
138    */
139   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
140                                FunctorDelegate* functor );
141
142   // Properties
143
144   /**
145    * Called when a property of an object of this type is set.
146    * @param[in] object The object whose property is set.
147    * @param[in] index The property index.
148    * @param[in] value The new property value.
149    */
150   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
151
152   /**
153    * Called to retrieve a property of an object of this type.
154    * @param[in] object The object whose property is to be retrieved.
155    * @param[in] index The property index.
156    * @return The current value of the property.
157    */
158   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
159
160 protected:
161
162   /**
163    * Construct a new ProgressBar.
164    */
165   ProgressBar();
166
167   /**
168    * A reference counted object may only be deleted by calling Unreference()
169    */
170   virtual ~ProgressBar();
171
172   /**
173    * @copydoc CustomActorImpl::OnRelayout()
174    */
175   void OnRelayout( const Vector2& size, RelayoutContainer& container ) override;
176
177   /**
178    * @copydoc CustomActorImpl::GetNaturalSize()
179    */
180   Vector3 GetNaturalSize() override;
181
182 private:
183
184   /**
185    * Domain is a from/to pair
186    */
187   struct Domain
188   {
189     Vector2 from;
190     Vector2 to;
191
192     Domain()
193     {
194     }
195     Domain( Vector2 fromVal, Vector2 toVal )
196         : from( fromVal ), to( toVal )
197     {
198     }
199   };
200
201 private:
202
203   /**
204    * @copydoc Toolkit::Control::OnInitialize()
205    */
206   void OnInitialize() override;
207
208   /**
209    * Get the range of the valid values the ProgressBar handle can move between
210    *
211    * @param[in] currentSize The current size of the ProgressBar
212    * @return The range as a domain pair
213    */
214   Domain CalcDomain( const Vector2& currentSize );
215
216   /**
217    * Set indeterminate visual transition animation
218    */
219   void SetIndeterminateVisualTransition( Toolkit::TransitionData transtion );
220
221   /**
222    * Convert value to transition data
223    */
224   Toolkit::TransitionData ConvertPropertyToTransition( const Property::Value& value );
225
226   /**
227    * Update progress bar label when progress value is changed
228    */
229   void CreateVisualsForComponent( Property::Index index, const Property::Value& value, const int visualDepth );
230
231   /**
232    * Update progress bar label when progress value is changed
233    */
234   bool GetPropertyMapForVisual( Property::Index visualIndex, Property::Map& retreivedMap ) const;
235
236   /**
237    * Apply progress value to visual
238    */
239   void ApplyProgressToVisual( float progress, Property::Index index, int depth );
240
241   /**
242    * Apply progress value to visual transform
243    */
244   void ApplyProgressToVisualTransform( float progress, Vector2 trackSize, Property::Index index );
245
246   /**
247    * Check if we should start animating
248    */
249   void OnSceneConnection( int depth ) override;
250
251 private:
252
253   // Undefined
254   ProgressBar( const ProgressBar& );
255
256   // Undefined
257   ProgressBar& operator=( const ProgressBar& rhs );
258
259 private:
260
261   Domain mDomain;                                                     ///< Current domain of the handle
262
263   Animation mIndeterminateVisualAni;                                  ///< Animation for indetrminate visual. Transition animation.
264   Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal;   ///< Signal emitted when the value is changed
265
266   Toolkit::TransitionData mIndeterminateVisualTransition;             ///< Transition data map for mIndeterminateVisualAni
267   float mProgressValue;                                               ///< Current value of ProgressBar
268   float mSecondaryProgressValue;                                      ///< Current loading value of ProgressBar
269   bool mIndeterminate;                                                ///< Whether the progress state is determined or not
270   Property::Map mTrackVisualMap;                                      ///< To backup visual properties when switching determinate/indeterminate.
271   Property::Map mProgressVisualMap;                                   ///< To backup visual properties when switching determinate/indeterminate.
272   Property::Map mSecondaryProgressVisualMap;                          ///< To backup visual properties when switching determinate/indeterminate.
273
274 protected:
275   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
276                           public virtual Dali::Accessibility::Value
277   {
278     using Control::Impl::AccessibleImpl::AccessibleImpl;
279     double GetMinimum() override;
280     double GetCurrent() override;
281     double GetMaximum() override;
282     bool SetCurrent( double ) override;
283     double GetMinimumIncrement() override;
284   };
285 };
286
287 } // namespace Internal
288
289 // Helpers for public-api forwarding methods
290
291 inline Toolkit::Internal::ProgressBar& GetImpl( Toolkit::ProgressBar& pub )
292 {
293   DALI_ASSERT_ALWAYS( pub );
294
295   Dali::RefObject& handle = pub.GetImplementation();
296
297   return static_cast< Toolkit::Internal::ProgressBar& >( handle );
298 }
299
300 inline const Toolkit::Internal::ProgressBar& GetImpl( const Toolkit::ProgressBar& pub )
301 {
302   DALI_ASSERT_ALWAYS( pub );
303
304   const Dali::RefObject& handle = pub.GetImplementation();
305
306   return static_cast< const Toolkit::Internal::ProgressBar& >( handle );
307 }
308
309 } // namespace Toolkit
310
311 } // namespace Dali
312
313 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H