[Tizen](ATSPI) 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
22 // INTERNAL INCLUDES
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include <dali/public-api/animation/animation.h>
25 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.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.
51    *
52    * @return A public handle to the newly allocated ProgressBar.
53    */
54   static Dali::Toolkit::ProgressBar New();
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   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
176
177   /**
178    * @copydoc CustomActorImpl::GetNaturalSize()
179    */
180   virtual Vector3 GetNaturalSize();
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   virtual void OnInitialize();
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    * Check if we should start animating
238    */
239   virtual void OnStageConnection( int depth );
240
241 private:
242
243   // Undefined
244   ProgressBar( const ProgressBar& );
245
246   // Undefined
247   ProgressBar& operator=( const ProgressBar& rhs );
248
249 private:
250
251   Domain mDomain;                                                     ///< Current domain of the handle
252
253   Animation mIndeterminateVisualAni;                                  ///< Animation for indetrminate visual. Transition animation.
254   Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal;   ///< Signal emitted when the value is changed
255
256   Toolkit::TransitionData mIndeterminateVisualTransition;             ///< Transition data map for mIndeterminateVisualAni
257   float mProgressValue;                                               ///< Current value of ProgressBar
258   float mSecondaryProgressValue;                                      ///< Current loading value of ProgressBar
259   bool mIndeterminate;                                                ///< Whether the progress state is determined or not
260
261 protected:
262   struct AccessibleImpl : public Control::Impl::AccessibleImpl,
263                           public virtual Dali::Accessibility::Value
264   {
265     using Control::Impl::AccessibleImpl::AccessibleImpl;
266     double GetMinimum() override;
267     double GetCurrent() override;
268     double GetMaximum() override;
269     bool SetCurrent( double ) override;
270     double GetMinimumIncrement() override;
271   };
272 };
273
274 } // namespace Internal
275
276 // Helpers for public-api forwarding methods
277
278 inline Toolkit::Internal::ProgressBar& GetImpl( Toolkit::ProgressBar& pub )
279 {
280   DALI_ASSERT_ALWAYS( pub );
281
282   Dali::RefObject& handle = pub.GetImplementation();
283
284   return static_cast< Toolkit::Internal::ProgressBar& >( handle );
285 }
286
287 inline const Toolkit::Internal::ProgressBar& GetImpl( const Toolkit::ProgressBar& pub )
288 {
289   DALI_ASSERT_ALWAYS( pub );
290
291   const Dali::RefObject& handle = pub.GetImplementation();
292
293   return static_cast< const Toolkit::Internal::ProgressBar& >( handle );
294 }
295
296 } // namespace Toolkit
297
298 } // namespace Dali
299
300 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H