[dali_2.3.19] Merge branch 'devel/master'
[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) 2021 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/devel-api/controls/control-devel.h>
23 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar-devel.h>
24 #include <dali-toolkit/devel-api/visual-factory/transition-data.h>
25 #include <dali-toolkit/internal/controls/control/control-data-impl.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
27 #include <dali-toolkit/public-api/controls/progress-bar/progress-bar.h>
28 #include <dali/public-api/animation/animation.h>
29
30 namespace Dali
31 {
32 namespace Toolkit
33 {
34 namespace Internal
35 {
36 class ProgressBar;
37
38 typedef Dali::IntrusivePtr<ProgressBar> ProgressBarPtr;
39
40 /**
41  * @copydoc Toolkit::ProgressBar
42  */
43 class ProgressBar : public Control
44 {
45 public:
46   /**
47    * Create a new ProgressBar with predefined style.
48    * @param[in] progressBarStyle A style value that determines the shape of the progress bar.
49    * @return A public handle to the newly allocated ProgressBar.
50    */
51   static Dali::Toolkit::ProgressBar New(DevelProgressBar::Style progressBarStyle = DevelProgressBar::Style::LINEAR);
52
53 public:
54   // Properties
55
56   /**
57    * Set the value of the ProgressBar
58    *
59    * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
60    */
61   void SetProgressValue(float value);
62
63   /**
64    * Get the value of the ProgressBar
65    *
66    * @return The current value of the ProgressBar
67    */
68   float GetProgressValue() const;
69
70   /**
71    * Set the secondary progress value of the ProgressBar
72    *
73    * @param[in] value The secondary progress value to set. Will be clamped to [lowerBound .. upperBound]
74    */
75   void SetSecondaryProgressValue(float value);
76
77   /**
78    * Get the secondary progress value of the ProgressBar
79    *
80    * @return The current secondary progress value of the ProgressBar
81    */
82   float GetSecondaryProgressValue() const;
83
84   /**
85    * Set the indeterminate state of the ProgressBar
86    *
87    * @param[in] value The value to set.
88    */
89   void SetIndeterminate(bool value);
90
91   /**
92    * Get the indeterminate state value of the ProgressBar
93    *
94    * @return The current determined state of the ProgressBar
95    */
96   bool GetIndeterminate() const;
97
98   /**
99    * Set the indeterminate visual transition of the ProgressBar
100    *
101    * @param[in] Transition data map to set.
102    */
103   void SetIndeterminateVisualTransition(Property::Map transtion);
104
105   /**
106    * Get the indeterminate visual transition data map of the ProgressBar
107    *
108    * @return The current indeterminate visual transition data map of the ProgressBar
109    */
110   Property::Map GetIndeterminateVisualTransition() const;
111
112   /**
113    * Play the indeterminate visual transition
114    */
115   void PlayIndeterminateVisualTransition();
116
117 public:
118   //Signals
119
120   /**
121    * @copydoc toolkit::progressbar::valuechangedsignal()
122    */
123   Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
124
125   /**
126    * Connects a callback function with the object's signals.
127    * @param[in] object The object providing the signal.
128    * @param[in] tracker Used to disconnect the signal.
129    * @param[in] signalName The signal to connect to.
130    * @param[in] functor A newly allocated FunctorDelegate.
131    * @return True if the signal was connected.
132    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
133    */
134   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
135
136   // Properties
137
138   /**
139    * Called when a property of an object of this type is set.
140    * @param[in] object The object whose property is set.
141    * @param[in] index The property index.
142    * @param[in] value The new property value.
143    */
144   static void SetProperty(BaseObject* object, Property::Index index, const Property::Value& value);
145
146   /**
147    * Called to retrieve a property of an object of this type.
148    * @param[in] object The object whose property is to be retrieved.
149    * @param[in] index The property index.
150    * @return The current value of the property.
151    */
152   static Property::Value GetProperty(BaseObject* object, Property::Index propertyIndex);
153
154 protected:
155   /**
156    * Construct a new ProgressBar.
157    */
158   ProgressBar();
159
160   /**
161    * A reference counted object may only be deleted by calling Unreference()
162    */
163   virtual ~ProgressBar();
164
165   /**
166    * @copydoc CustomActorImpl::OnRelayout()
167    */
168   void OnRelayout(const Vector2& size, RelayoutContainer& container) override;
169
170   /**
171    * @copydoc CustomActorImpl::GetNaturalSize()
172    */
173   Vector3 GetNaturalSize() override;
174
175 private:
176   /**
177    * Domain is a from/to pair
178    */
179   struct Domain
180   {
181     Vector2 from;
182     Vector2 to;
183
184     Domain()
185     {
186     }
187     Domain(Vector2 fromVal, Vector2 toVal)
188     : from(fromVal),
189       to(toVal)
190     {
191     }
192   };
193
194 private:
195   /**
196    * @copydoc Toolkit::Control::OnInitialize()
197    */
198   void OnInitialize() override;
199
200   /**
201    * Get the range of the valid values the ProgressBar handle can move between
202    *
203    * @param[in] currentSize The current size of the ProgressBar
204    * @return The range as a domain pair
205    */
206   Domain CalcDomain(const Vector2& currentSize);
207
208   /**
209    * Set indeterminate visual transition animation
210    */
211   void SetIndeterminateVisualTransition(Toolkit::TransitionData transtion);
212
213   /**
214    * Convert value to transition data
215    */
216   Toolkit::TransitionData ConvertPropertyToTransition(const Property::Value& value);
217
218   /**
219    * Update progress bar label when progress value is changed
220    */
221   void CreateVisualsForComponent(Property::Index index, const Property::Value& value, const int visualDepth);
222
223   /**
224    * Update progress bar label when progress value is changed
225    */
226   bool GetPropertyMapForVisual(Property::Index visualIndex, Property::Map& retreivedMap) const;
227
228   /**
229    * Apply progress value to visual
230    */
231   void ApplyProgressToVisual(float progress, Property::Index index, int depth);
232
233   /**
234    * Apply progress value to visual transform
235    */
236   void ApplyProgressToVisualTransform(float progress, Vector2 trackSize, Property::Index index);
237
238   /**
239    * Check if we should start animating
240    */
241   void OnSceneConnection(int depth) override;
242
243 private:
244   // Undefined
245   ProgressBar(const ProgressBar&);
246
247   // Undefined
248   ProgressBar& operator=(const ProgressBar& rhs);
249
250 private:
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   Property::Map           mTrackVisualMap;                ///< To backup visual properties when switching determinate/indeterminate.
261   Property::Map           mProgressVisualMap;             ///< To backup visual properties when switching determinate/indeterminate.
262   Property::Map           mSecondaryProgressVisualMap;    ///< To backup visual properties when switching determinate/indeterminate.
263
264 protected:
265   struct AccessibleImpl : public DevelControl::AccessibleImpl,
266                           public virtual Dali::Accessibility::Value
267   {
268     using DevelControl::AccessibleImpl::AccessibleImpl;
269     double GetMinimum() override;
270     double GetCurrent() override;
271     double GetMaximum() override;
272     bool   SetCurrent(double) override;
273     double GetMinimumIncrement() override;
274   };
275 };
276
277 } // namespace Internal
278
279 // Helpers for public-api forwarding methods
280
281 inline Toolkit::Internal::ProgressBar& GetImpl(Toolkit::ProgressBar& pub)
282 {
283   DALI_ASSERT_ALWAYS(pub);
284
285   Dali::RefObject& handle = pub.GetImplementation();
286
287   return static_cast<Toolkit::Internal::ProgressBar&>(handle);
288 }
289
290 inline const Toolkit::Internal::ProgressBar& GetImpl(const Toolkit::ProgressBar& pub)
291 {
292   DALI_ASSERT_ALWAYS(pub);
293
294   const Dali::RefObject& handle = pub.GetImplementation();
295
296   return static_cast<const Toolkit::Internal::ProgressBar&>(handle);
297 }
298
299 } // namespace Toolkit
300
301 } // namespace Dali
302
303 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H