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