[dali_1.2.5] 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) 2016 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/public-api/object/property-map.h>
23
24 // INTERNAL INCLUDES
25 #include <dali-toolkit/public-api/controls/control-impl.h>
26 #include <dali-toolkit/devel-api/controls/progress-bar/progress-bar.h>
27 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
28 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
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   /**
51    * Create a new ProgressBar.
52    *
53    * @return A public handle to the newly allocated ProgressBar.
54    */
55   static Dali::Toolkit::ProgressBar New();
56
57 public:
58
59   // Properties
60
61   /**
62    * Set the value of the ProgressBar
63    *
64    * @param[in] value The value to set. Will be clamped to [lowerBound .. upperBound]
65    */
66
67   void SetProgressValue( float value );
68
69   /**
70    * Get the value of the ProgressBar
71    *
72    * @return The current value of the ProgressBar
73    */
74   float GetProgressValue() const;
75
76 public:
77   //Signals
78
79   /**
80    * @copydoc Toolkit::ProgressBar::ValueChangedSignal()
81    */
82   Toolkit::ProgressBar::ValueChangedSignalType& ValueChangedSignal();
83
84   /**
85    * Connects a callback function with the object's signals.
86    * @param[in] object The object providing the signal.
87    * @param[in] tracker Used to disconnect the signal.
88    * @param[in] signalName The signal to connect to.
89    * @param[in] functor A newly allocated FunctorDelegate.
90    * @return True if the signal was connected.
91    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
92    */
93   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName,
94                                FunctorDelegate* functor );
95
96   // Properties
97
98   /**
99    * Called when a property of an object of this type is set.
100    * @param[in] object The object whose property is set.
101    * @param[in] index The property index.
102    * @param[in] value The new property value.
103    */
104   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
105
106   /**
107    * Called to retrieve a property of an object of this type.
108    * @param[in] object The object whose property is to be retrieved.
109    * @param[in] index The property index.
110    * @return The current value of the property.
111    */
112   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
113
114 protected:
115
116   /**
117    * Construct a new ProgressBar.
118    */
119   ProgressBar();
120
121   /**
122    * A reference counted object may only be deleted by calling Unreference()
123    */
124   virtual ~ProgressBar();
125
126   /**
127    * @copydoc CustomActorImpl::OnRelayout()
128    */
129   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
130
131   /**
132    * @copydoc CustomActorImpl::GetNaturalSize()
133    */
134   virtual Vector3 GetNaturalSize();
135
136 private:
137
138   /**
139    * Domain is a from/to pair
140    */
141   struct Domain
142   {
143     Vector2 from;
144     Vector2 to;
145
146     Domain()
147     {
148     }
149     Domain( Vector2 fromVal, Vector2 toVal )
150         : from( fromVal ), to( toVal )
151     {
152     }
153   };
154
155 private:
156
157   /**
158    * @copydoc Toolkit::Control::OnInitialize()
159    */
160   virtual void OnInitialize();
161
162   /**
163    * Get the range of the valid values the ProgressBar handle can move between
164    *
165    * @param[in] currentSize The current size of the ProgressBar
166    * @return The range as a domain pair
167    */
168   Domain CalcDomain( const Vector2& currentSize );
169
170   /**
171    * Create the track for the ProgressBar
172    *
173    * @return The track actor
174    */
175   Toolkit::ImageView CreateTrack();
176
177   /**
178    * Create the progress track for the ProgressBar
179    *
180    * @return The track actor
181    */
182   Toolkit::ImageView CreateProgress();
183
184   /**
185    * Create all the children
186    */
187   void CreateChildren();
188
189   /**
190    * Set value choosing whether to fire signals or not
191    *
192    * @paramp[in] value The value to set
193    * @param[in] raiseSignals Configure signals to be raised or not.
194    */
195   void DisplayValue( float value, bool raiseSignals );
196
197   /**
198    * Create the image for the track
199    *
200    * @param[in] filename The track image
201    */
202   void SetTrackVisual( const std::string& filename );
203
204   /**
205    * @brief Set the track visual from an Dali::Property::Map
206    *
207    * @param[in] map The Dali::Property::Map to use for to display
208    */
209   void SetTrackVisual( Dali::Property::Map map );
210
211   /**
212    * @brief Return the track image.
213    *
214    * @return The track image.
215    */
216   std::string GetTrackVisual();
217
218   /**
219    * Create the image for the progress bar
220    *
221    * @param[in] filename The progress bar image
222    */
223   void SetProgressVisual( const std::string& filename );
224
225   /**
226    * @brief Set the progress visual from an Dali::Property::Map
227    *
228    * @param[in] map The Dali::Property::Map to use for to display
229    */
230   void SetProgressVisual( Dali::Property::Map map );
231
232   /**
233    * @brief Return the progress bar image.
234    *
235    * @return The progress bar image if it exists.
236    */
237   std::string GetProgressVisual();
238
239 private:
240
241   // Undefined
242   ProgressBar( const ProgressBar& );
243
244   // Undefined
245   ProgressBar& operator=( const ProgressBar& rhs );
246
247 private:
248
249   Domain mDomain;                           ///< Current domain of the handle
250
251   Toolkit::ImageView mTrack;                ///< Track image
252   Toolkit::ImageView mProgress;             ///< Progress bar
253   Toolkit::TextLabel mValueTextLabel;       ///< Text value to show progress percentage
254   Toolkit::ProgressBar::ValueChangedSignalType mValueChangedSignal;       ///< Signal emitted when the value is changed
255
256   std::string mTrackVisual;           ///< Image for track image
257   std::string mProgressVisual;        ///< Image for progress bar image
258
259   Property::Map mTrackMap;         ///< the Property::Map if the image came from a Property::Map, empty otherwise
260   Property::Map mProgressMap;      ///< the Property::Map if the image came from a Property::Map, empty otherwise
261
262   Vector2 mTrackVisualSize;      ///< Size of the track image used
263   Vector2 mProgressVisualSize;   ///< Size of progress image used
264
265   float mValue;             ///< Current value of ProgressBar
266 };
267
268 } // namespace Internal
269
270 // Helpers for public-api forwarding methods
271
272 inline Toolkit::Internal::ProgressBar& GetImpl( Toolkit::ProgressBar& pub )
273 {
274   DALI_ASSERT_ALWAYS( pub );
275
276   Dali::RefObject& handle = pub.GetImplementation();
277
278   return static_cast< Toolkit::Internal::ProgressBar& >( handle );
279 }
280
281 inline const Toolkit::Internal::ProgressBar& GetImpl( const Toolkit::ProgressBar& pub )
282 {
283   DALI_ASSERT_ALWAYS( pub );
284
285   const Dali::RefObject& handle = pub.GetImplementation();
286
287   return static_cast< const Toolkit::Internal::ProgressBar& >( handle );
288 }
289
290 } // namespace Toolkit
291
292 } // namespace Dali
293
294 #endif // DALI_TOOLKIT_INTERNAL_PROGRESS_BAR_H