8365f35e9e88bf65deccf22a95f42b498d25dcf4
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.h
1 #ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_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/dali.h>
22 #include <dali-toolkit/public-api/controls/buttons/button.h>
23 #include <dali-toolkit/public-api/controls/control-impl.h>
24 #include "button-painter-impl.h"
25
26 namespace Dali
27 {
28
29 namespace Toolkit
30 {
31
32 class Button;
33
34 namespace Internal
35 {
36
37 /**
38  * Button is the base class implementation for all buttons.
39  */
40 class Button : public ControlImpl
41 {
42
43 protected:
44
45   /**
46    * Construct a new Button.
47    */
48   Button();
49
50   /**
51    * A reference counted object may only be deleted by calling Unreference()
52    */
53   virtual ~Button();
54
55 public:
56
57   /**
58    * @copydoc Dali::Toolkit::Button::SetDimmed( bool dimmed )
59    */
60   void SetDimmed( bool dimmed );
61
62   /**
63    * @copydoc Dali::Toolkit::Button::IsDimmed() const
64    */
65   bool IsDimmed() const;
66
67   /**
68    * @copydoc Dali::Toolkit::Button::SetAnimationTime()
69    */
70   void SetAnimationTime( float animationTime );
71
72   /**
73    * @copydoc Dali::Toolkit::Button::GetAnimationTime()
74    */
75   float GetAnimationTime() const;
76
77 private:
78
79   /**
80    * This method is called after the button initialization.
81    * Could be reimplemented in subclasses to provide specific behaviour.
82    */
83   virtual void OnButtonInitialize() { }
84
85   /**
86    * This method is called from the OnTouchEvent method when the button is down.
87    * Could be reimplemented in subclasses to provide specific behaviour.
88    */
89   virtual void OnButtonDown() { }
90
91   /**
92    * This method is called from the OnTouchEvent method when the button is up.
93    * Could be reimplemented in subclasses to provide specific behaviour.
94    */
95   virtual void OnButtonUp() { }
96
97   /**
98    * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
99    * more than one touch points are received.
100    * Could be reimplemented in subclasses to provide specific behaviour.
101    */
102   virtual void OnTouchPointLeave() { }
103
104   /**
105    * This method is called from the OnTouchEvent method when the touch point is interrupted.
106    * Could be reimplemented in subclasses to provide specific behaviour.
107    */
108   virtual void OnTouchPointInterrupted() { }
109
110   /**
111    * This method is called when the animation time is set.
112    * Needs to be reimplemented in subclasses to set the animation time in different buttons.
113    * @param animationTime The animation time in seconds.
114    */
115   virtual void OnAnimationTimeSet( float animationTime );
116
117   /**
118    * This method is called when the animation time is requested.
119    * Needs to be reimplemented in subclases to return the animation time.
120    * @return The animation time in seconds.
121    */
122   virtual float OnAnimationTimeRequested() const;
123
124 public:
125
126   /**
127    * @copydoc Dali::Toolkit::Button::ClickedSignal()
128    */
129   Toolkit::Button::ClickedSignalV2& ClickedSignal();
130
131   /**
132    * Connects a callback function with the object's signals.
133    * @param[in] object The object providing the signal.
134    * @param[in] tracker Used to disconnect the signal.
135    * @param[in] signalName The signal to connect to.
136    * @param[in] functor A newly allocated FunctorDelegate.
137    * @return True if the signal was connected.
138    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
139    */
140   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
141
142 protected: // From CustomActorImpl
143
144   /**
145    * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
146    */
147   virtual bool OnTouchEvent( const TouchEvent& event );
148
149 private: // From ControlImpl
150
151   /**
152    * @copydoc Toolkit::Control::OnInitialize()
153    */
154   virtual void OnInitialize();
155
156   /**
157    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
158    */
159   virtual void OnControlSizeSet( const Vector3& targetSize );
160
161   /**
162    * @copydoc Dali::CustomActorImpl::OnPropertySet()
163    */
164   virtual void OnPropertySet( Property::Index index, Property::Value propertyValue );
165
166 private:
167
168   /**
169    * Handler for tap events.
170    * We do not actually do anything when we receive a tap as the button handles tap event through
171    * the touch event system itself as it requires more than just tap handling (e.g. leave events).
172    * This stops any of our parents receiving a tap gesture when it occurs within our area.
173    * @param[in]  actor  The tapped actor.
174    * @param[in]  tap    The tap gesture.
175    */
176   void OnTap(Actor actor, TapGesture tap);
177
178 private:
179
180   /**
181    * Callback received when the button is disconected from the stage.
182    * It resets the button status.
183    */
184   void OnStageDisconnection();
185
186 private:
187
188   // Undefined
189   Button( const Button& );
190
191   // Undefined
192   Button& operator = ( const Button& );
193
194 protected: // Signals
195
196   enum ButtonState
197   {
198     ButtonUp,                         ///< The button is up.
199     ButtonDown,                       ///< The button is down.
200   };
201
202   ButtonState      mState;                ///< Stores the button state.
203
204   bool             mDimmed;               ///< Stores the dimmed property.
205
206   ButtonPainterPtr mPainter;              ///< Pointer to a ButtonPainter base class.
207
208   Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked.
209
210   TapGestureDetector mTapDetector;
211
212   Property::Index  mPropertyDimmed;       ///< Property index for dimmed.
213 };
214
215 } // namespace Internal
216
217
218 // Helpers for public-api forwarding methods
219
220 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
221 {
222   DALI_ASSERT_ALWAYS( button );
223
224   Dali::RefObject& handle = button.GetImplementation();
225
226   return static_cast<Toolkit::Internal::Button&>( handle );
227 }
228
229 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
230 {
231   DALI_ASSERT_ALWAYS( button );
232
233   const Dali::RefObject& handle = button.GetImplementation();
234
235   return static_cast<const Toolkit::Internal::Button&>( handle );
236 }
237
238 } // namespace Toolkit
239
240 } // namespace Dali
241
242 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__
243