[SRUK] Initial copy from Tizen 2.2 version
[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: // Signals
240
241   /**
242    * @copydoc Dali::Toolkit::PushButton::ToggledSignal()
243    */
244   Toolkit::PushButton::ToggledSignalV2& ToggledSignal();
245
246   /**
247    * @copydoc Dali::Toolkit::PushButton::PressedSignal()
248    */
249   Toolkit::PushButton::PressedSignalV2& PressedSignal();
250
251   /**
252    * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
253    */
254   Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
255
256   /**
257    * Connects a callback function with the object's signals.
258    * @param[in] object The object providing the signal.
259    * @param[in] tracker Used to disconnect the signal.
260    * @param[in] signalName The signal to connect to.
261    * @param[in] functor A newly allocated FunctorDelegate.
262    * @return True if the signal was connected.
263    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
264    */
265   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
266
267 protected: // From Button
268
269   /**
270    * Sets the Leave signal.
271    */
272   virtual void OnButtonInitialize();
273
274   /**
275    * Emits signals and notifies the painter accordingly with the set button
276    * properties when the button is pressed.
277    */
278   virtual void OnButtonDown();
279
280   /**
281    * Emits signals and notifies the painter accordingly with the set button
282    * properties when the button is released.
283    */
284   virtual void OnButtonUp();
285
286   /**
287    * Emits signals and notifies the painter accordingly with the set button
288    * properties when the touch point leaves the boundary of the button.
289    */
290   virtual void OnTouchPointLeave();
291
292   /**
293    * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
294    */
295   virtual void OnTouchPointInterrupted();
296
297   /**
298    * Sets the push button animation time.
299    * @param animationTime The animation time in seconds.
300    */
301   virtual void OnAnimationTimeSet( float animationTime );
302
303   /**
304    * Retrieves the animation time.
305    * @return The animation time in seconds.
306    */
307   virtual float OnAnimationTimeRequested() const;
308
309 protected: // From ControlImpl
310
311   /**
312    * Respond the activate notification.
313    */
314   virtual void OnActivated();
315
316 private:
317
318   /**
319    * Perform the click action to click the button.
320    * @param[in] attributes The attributes to perfrom this action.
321    */
322   void DoClickAction(const PropertyValueContainer& attributes);
323
324 public:
325
326   /**
327    * Performs actions as requested using the action name.
328    * @param[in] object The object on which to perform the action.
329    * @param[in] actionName The action to perform.
330    * @param[in] attributes The attributes with which to perfrom this action.
331    * @return true if action has been accepted by this control
332    */
333   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
334
335   /**
336    * Construct a new PushButton.
337    */
338   PushButton();
339
340   /**
341    * A reference counted object may only be deleted by calling Unreference()
342    */
343   virtual ~PushButton();
344
345 private:
346
347   // Undefined
348   PushButton( const PushButton& );
349
350   // Undefined
351   PushButton& operator=( const PushButton& );
352
353   /**
354    * Sets up the autorepeating timer.
355    * @param[in] delay The delay time in seconds.
356    */
357   void SetUpTimer( float delay );
358
359   /**
360    * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
361    */
362   bool AutoRepeatingSlot();
363
364 private:
365   bool  mAutoRepeating;             ///< Stores the autorepeating property.
366   float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
367   float mNextAutoRepeatingDelay;    ///< Stores the next autorepeating delay in seconds.
368   bool  mToggleButton;              ///< Stores the toggle property.
369
370   // AutoRepeating
371   Timer mAutoRepeatingTimer;        ///< Timer used to implement the autorepeating property.
372
373   // Toggle
374   bool  mToggled;                   ///< Stores the toggle state.
375
376   // Signals
377   Toolkit::PushButton::ToggledSignalV2 mToggledSignalV2;   ///< Signal emitted when the button is toggled.
378   Toolkit::PushButton::PressedSignalV2 mPressedSignalV2;   ///< Signal emitted when the button is pressed.
379   Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
380
381   Actor mButtonImage;               ///< Stores the released image.
382   Actor mBackgroundImage;           ///< Stores the background image.
383   Actor mPressedImage;              ///< Stores the pressed image.
384   Actor mDimmedImage;               ///< Stores the dimmed image.
385   Actor mDimmedBackgroundImage;     ///< Stores the dimmed background image.
386
387   Actor mLabel;                     ///< Stores the text label.
388
389   Actor mFadeOutBackgroundImage;    ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
390   Actor mFadeOutButtonImage;        ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
391
392   // Actions
393   bool mClickActionPerforming;
394 };
395
396 } // namespace Internal
397
398 // Helpers for public-api forwarding methods
399
400 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
401 {
402   DALI_ASSERT_ALWAYS( button );
403
404   Dali::RefObject& handle = button.GetImplementation();
405
406   return static_cast<Toolkit::Internal::PushButton&>( handle );
407 }
408
409 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
410 {
411   DALI_ASSERT_ALWAYS( button );
412
413   const Dali::RefObject& handle = button.GetImplementation();
414
415   return static_cast<const Toolkit::Internal::PushButton&>( handle );
416 }
417
418 } // namespace Toolkit
419
420 } // namespace Dali
421
422 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__