Button refactoring: rename properties
[platform/core/uifw/dali-toolkit.git] / base / dali-toolkit / internal / controls / buttons / push-button-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
3
4 /*
5  * Copyright (c) 2014 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/adaptor-framework/timer.h>
23 #include <dali/public-api/common/dali-vector.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
27 #include "button-impl.h"
28
29 namespace Dali
30 {
31
32 namespace Toolkit
33 {
34
35 namespace Internal
36 {
37
38 /**
39  * PushButton implementation class.
40  *
41  * \sa Dali::Toolkit::PushButton
42  */
43 class PushButton : public Button
44 {
45 public:
46
47   /**
48    * Create a new PushButton.
49    * @return A smart-pointer to the newly allocated PushButton.
50    */
51   static Dali::Toolkit::PushButton New();
52
53   /**
54    * @copydoc Dali::Toolkit::PushButton::SetAutoRepeating( bool autoRepeating )
55    */
56   void SetAutoRepeating( bool autoRepeating );
57
58   /**
59    * @copydoc Dali::Toolkit::PushButton::IsAutoRepeating() const
60    */
61   bool IsAutoRepeating() const;
62
63   /**
64    * @copydoc Dali::Toolkit::PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
65    */
66   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
67
68   /**
69    * @copydoc Dali::Toolkit::PushButton::GetInitialAutoRepeatingDelay() const
70    */
71   float GetInitialAutoRepeatingDelay() const;
72
73   /**
74    * @copydoc Dali::Toolkit::PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
75    */
76   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
77
78   /**
79    * @copydoc Dali::Toolkit::PushButton::GetNextAutoRepeatingDelay() const
80    */
81   float GetNextAutoRepeatingDelay() const;
82
83   /**
84    * @copydoc Dali::Toolkit::PushButton::SetToggleButton( bool toggle )
85    */
86   void SetToggleButton( bool toggle );
87
88   /**
89    * @copydoc Dali::Toolkit::PushButton::IsToggleButton() const
90    */
91   bool IsToggleButton() const;
92
93   /**
94    * @copydoc Dali::Toolkit::PushButton::SetToggled( bool toggle )
95    */
96   void SetToggled( bool toggle );
97
98   /**
99    * @copydoc Dali::Toolkit::PushButton::IsToggled() const
100    */
101   bool IsToggled() const;
102
103   /**
104    * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
105    */
106   void SetButtonImage( Image image );
107
108   /**
109    * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
110    */
111   void SetButtonImage( Actor image );
112
113   /**
114    * Used by the painter only.
115    * @return A reference to the button image.
116    */
117   Actor& GetButtonImage();
118
119   /**
120    * @copydoc Dali::Toolkit::PushButton::
121    */
122   Actor GetButtonImage() const;
123
124   /**
125    * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
126    */
127   void SetBackgroundImage( Image image );
128
129   /**
130    * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
131    */
132   void SetBackgroundImage( Actor image );
133
134   /**
135    * Used by the painter only.
136    * @return A reference to the background image.
137    */
138   Actor& GetBackgroundImage();
139
140   /**
141    * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
142    */
143   Actor GetBackgroundImage() const;
144
145   /**
146    * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( const Image image )
147    */
148   void SetSelectedImage( Image image );
149
150   /**
151    * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
152    */
153   void SetSelectedImage( Actor image );
154
155   /**
156    * Used by the painter only.
157    * @return A reference to the selected image.
158    */
159   Actor& GetSelectedImage();
160
161   /**
162    * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
163    */
164   Actor GetSelectedImage() const;
165
166   /**
167    * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Image image )
168    */
169   void SetDisabledBackgroundImage( Image image );
170
171   /**
172    * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
173    */
174   void SetDisabledBackgroundImage( Actor image );
175
176   /**
177    * Used by the painter only.
178    * @return A reference to the disabled background image.
179    */
180   Actor& GetDisabledBackgroundImage();
181
182   /**
183    * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
184    */
185   Actor GetDisabledBackgroundImage() const;
186
187   /**
188    * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Image image )
189    */
190   void SetDisabledImage( Image image );
191
192   /**
193    * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
194    */
195   void SetDisabledImage( Actor image );
196
197   /**
198    * Used by the painter only.
199    * @return A reference to the disabled button image.
200    */
201   Actor& GetDisabledImage();
202
203   /**
204    * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
205    */
206   Actor GetDisabledImage() const;
207
208   /**
209    * @copydoc Dali::Toolkit::PushButton::SetLabel( const std::string& label )
210    */
211   void SetLabel( const std::string& label );
212
213   /**
214    * @copydoc Dali::Toolkit::PushButton::SetLabel( Actor label )
215    */
216   void SetLabel( Actor label );
217
218   /**
219    * @copydoc Dali::Toolkit::PushButton::GetLabel()
220    */
221   Actor GetLabel() const;
222
223   /**
224    * Used by the painter only.
225    * @return A reference to the label actor.
226    */
227   Actor& GetLabel();
228
229   /**
230    * Used by the painter only.
231    * @return A reference to the background image that is fading out.
232    */
233   Actor& GetFadeOutBackgroundImage();
234
235   /**
236    * Used by the painter only.
237    * @return A reference to the button image that is fading out.
238    */
239   Actor& GetFadeOutButtonImage();
240
241 public:
242
243   // Signals
244
245   /**
246    * @copydoc Dali::Toolkit::PushButton::PressedSignal()
247    */
248   Toolkit::PushButton::PressedSignalType& PressedSignal();
249
250   /**
251    * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
252    */
253   Toolkit::PushButton::ReleasedSignalType& ReleasedSignal();
254
255   /**
256    * Connects a callback function with the object's signals.
257    * @param[in] object The object providing the signal.
258    * @param[in] tracker Used to disconnect the signal.
259    * @param[in] signalName The signal to connect to.
260    * @param[in] functor A newly allocated FunctorDelegate.
261    * @return True if the signal was connected.
262    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
263    */
264   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
265
266   // Properties
267
268   /**
269    * @copydoc Button::SetProperty
270    */
271   static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
272
273   /**
274    * @copydoc Button::GetProperty
275    */
276   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
277
278 protected: // From Button
279
280   /**
281    * Sets the Leave signal.
282    */
283   virtual void OnButtonInitialize();
284
285   /**
286    * Emits signals and notifies the painter accordingly with the set button
287    * properties when the button is pressed.
288    */
289   virtual void OnButtonDown();
290
291   /**
292    * Emits signals and notifies the painter accordingly with the set button
293    * properties when the button is released.
294    */
295   virtual void OnButtonUp();
296
297   /**
298    * Emits signals and notifies the painter accordingly with the set button
299    * properties when the touch point leaves the boundary of the button.
300    */
301   virtual void OnTouchPointLeave();
302
303   /**
304    * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
305    */
306   virtual void OnTouchPointInterrupted();
307
308   /**
309    * Sets the push button animation time.
310    * @param animationTime The animation time in seconds.
311    */
312   virtual void OnAnimationTimeSet( float animationTime );
313
314   /**
315    * Retrieves the animation time.
316    * @return The animation time in seconds.
317    */
318   virtual float OnAnimationTimeRequested() const;
319
320   /**
321    * This method is called when the button is removed from the stage.
322    */
323   virtual void OnButtonStageDisconnection();
324
325 protected: // From Control
326
327   /**
328    * Respond the activate notification.
329    */
330   virtual void OnActivated();
331
332   /**
333    * @copydoc Control::GetNaturalSize()
334    */
335   virtual Vector3 GetNaturalSize();
336
337 private:
338
339   /**
340    * Perform the click action to click the button.
341    * @param[in] attributes The attributes to perfrom this action.
342    */
343   void DoClickAction(const PropertyValueContainer& attributes);
344
345 public:
346
347   /**
348    * Performs actions as requested using the action name.
349    * @param[in] object The object on which to perform the action.
350    * @param[in] actionName The action to perform.
351    * @param[in] attributes The attributes with which to perfrom this action.
352    * @return true if action has been accepted by this control
353    */
354   static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
355
356   /**
357    * Construct a new PushButton.
358    */
359   PushButton();
360
361   /**
362    * A reference counted object may only be deleted by calling Unreference()
363    */
364   virtual ~PushButton();
365
366 private:
367
368   // Undefined
369   PushButton( const PushButton& );
370
371   // Undefined
372   PushButton& operator=( const PushButton& );
373
374   /**
375    * Sets up the autorepeating timer.
376    * @param[in] delay The delay time in seconds.
377    */
378   void SetUpTimer( float delay );
379
380   /**
381    * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
382    */
383   bool AutoRepeatingSlot();
384
385 private:
386   bool  mAutoRepeating;             ///< Stores the autorepeating property.
387   float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
388   float mNextAutoRepeatingDelay;    ///< Stores the next autorepeating delay in seconds.
389   bool  mToggleButton;              ///< Stores the toggle property.
390
391   // AutoRepeating
392   Timer mAutoRepeatingTimer;        ///< Timer used to implement the autorepeating property.
393
394   // Toggle
395   bool  mToggled;                   ///< Stores the toggle state.
396
397   // Signals
398   Toolkit::PushButton::PressedSignalType mPressedSignal;   ///< Signal emitted when the button is pressed.
399   Toolkit::PushButton::ReleasedSignalType mReleasedSignal; ///< Signal emitted when the button is released.
400
401   Actor mButtonImage;               ///< Stores the unselected image.
402   Actor mBackgroundImage;           ///< Stores the background image.
403   Actor mSelectedImage;             ///< Stores the selected image.
404   Actor mDisabledImage;             ///< Stores the disabled image.
405   Actor mDisabledBackgroundImage;   ///< Stores the disabled background image.
406
407   Actor mLabel;                     ///< Stores the text label.
408
409   Actor mFadeOutBackgroundImage;    ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
410   Actor mFadeOutButtonImage;        ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
411
412   // Actions
413   bool mClickActionPerforming;
414 };
415
416 } // namespace Internal
417
418 // Helpers for public-api forwarding methods
419
420 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
421 {
422   DALI_ASSERT_ALWAYS( button );
423
424   Dali::RefObject& handle = button.GetImplementation();
425
426   return static_cast<Toolkit::Internal::PushButton&>( handle );
427 }
428
429 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
430 {
431   DALI_ASSERT_ALWAYS( button );
432
433   const Dali::RefObject& handle = button.GetImplementation();
434
435   return static_cast<const Toolkit::Internal::PushButton&>( handle );
436 }
437
438 } // namespace Toolkit
439
440 } // namespace Dali
441
442 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__