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