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