Merge "Remove obsolete and non functional SizeChanged signal from actor" into tizen
[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 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-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 Control
41 {
42 public:
43
44   // Properties
45   enum
46   {
47     BUTTON_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
48     BUTTON_PROPERTY_END_INDEX = BUTTON_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
49   };
50
51 protected:
52
53   /**
54    * Construct a new Button.
55    */
56   Button();
57
58   /**
59    * A reference counted object may only be deleted by calling Unreference()
60    */
61   virtual ~Button();
62
63 public:
64
65   /**
66    * @copydoc Dali::Toolkit::Button::SetDisabled( bool disabled )
67    */
68   void SetDisabled( bool disabled );
69
70   /**
71    * @copydoc Dali::Toolkit::Button::IsDisabled() const
72    */
73   bool IsDisabled() const;
74
75   /**
76    * @copydoc Dali::Toolkit::Button::SetAnimationTime()
77    */
78   void SetAnimationTime( float animationTime );
79
80   /**
81    * @copydoc Dali::Toolkit::Button::GetAnimationTime()
82    */
83   float GetAnimationTime() const;
84
85 private:
86
87   /**
88    * This method is called after the button initialization.
89    * Could be reimplemented in subclasses to provide specific behaviour.
90    */
91   virtual void OnButtonInitialize() { }
92
93   /**
94    * This method is called from the OnTouchEvent method when the button is down.
95    * Could be reimplemented in subclasses to provide specific behaviour.
96    */
97   virtual void OnButtonDown();
98
99   /**
100    * This method is called from the OnTouchEvent method when the button is up.
101    * Could be reimplemented in subclasses to provide specific behaviour.
102    */
103   virtual void OnButtonUp();
104
105   /**
106    * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
107    * more than one touch points are received.
108    * Could be reimplemented in subclasses to provide specific behaviour.
109    */
110   virtual void OnTouchPointLeave() { }
111
112   /**
113    * This method is called from the OnTouchEvent method when the touch point is interrupted.
114    * Could be reimplemented in subclasses to provide specific behaviour.
115    */
116   virtual void OnTouchPointInterrupted() { }
117
118   /**
119    * This method is called when the animation time is set.
120    * Needs to be reimplemented in subclasses to set the animation time in different buttons.
121    * @param animationTime The animation time in seconds.
122    */
123   virtual void OnAnimationTimeSet( float animationTime );
124
125   /**
126    * This method is called when the animation time is requested.
127    * Needs to be reimplemented in subclases to return the animation time.
128    * @return The animation time in seconds.
129    */
130   virtual float OnAnimationTimeRequested() const;
131
132   /**
133    * This method is called when the button is removed from the stage.
134    * Could be reimplemented in subclasses to provide specific behaviour.
135    */
136   virtual void OnButtonStageDisconnection() { }
137
138 public:
139
140   /**
141    * @copydoc Dali::Toolkit::Button::ClickedSignal()
142    */
143   Toolkit::Button::ClickedSignalType& ClickedSignal();
144
145   /**
146    * @copydoc Dali::Toolkit::Button::StateChangedSignal()
147    */
148   Toolkit::Button::StateChangedSignalType& StateChangedSignal();
149
150   /**
151    * Connects a callback function with the object's signals.
152    * @param[in] object The object providing the signal.
153    * @param[in] tracker Used to disconnect the signal.
154    * @param[in] signalName The signal to connect to.
155    * @param[in] functor A newly allocated FunctorDelegate.
156    * @return True if the signal was connected.
157    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
158    */
159   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
160
161   // Properties
162
163   /**
164    * Called when a property of an object of this type is set.
165    * @param[in] object The object whose property is set.
166    * @param[in] index The property index.
167    * @param[in] value The new property value.
168    */
169   static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
170
171   /**
172    * Called to retrieve a property of an object of this type.
173    * @param[in] object The object whose property is to be retrieved.
174    * @param[in] index The property index.
175    * @return The current value of the property.
176    */
177   static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
178
179 protected: // From CustomActorImpl
180
181   /**
182    * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
183    */
184   virtual bool OnTouchEvent( const TouchEvent& event );
185
186 private: // From Control
187
188   /**
189    * @copydoc Toolkit::Control::OnInitialize()
190    */
191   virtual void OnInitialize();
192
193   /**
194    * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
195    */
196   virtual void OnControlSizeSet( const Vector3& targetSize );
197
198   /**
199    * Callback received when the button is disconnected from the stage.
200    * It resets the button status.
201    */
202   void OnControlStageDisconnection();
203
204 private:
205
206   /**
207    * Handler for tap events.
208    * We do not actually do anything when we receive a tap as the button handles tap event through
209    * the touch event system itself as it requires more than just tap handling (e.g. leave events).
210    * This stops any of our parents receiving a tap gesture when it occurs within our area.
211    * @param[in]  actor  The tapped actor.
212    * @param[in]  tap    The tap gesture.
213    */
214   void OnTap(Actor actor, const TapGesture& tap);
215
216 private:
217
218   // Undefined
219   Button( const Button& );
220
221   // Undefined
222   Button& operator = ( const Button& );
223
224 protected:
225
226   enum ButtonState
227   {
228     ButtonUp,                         ///< The button is up.
229     ButtonDown,                       ///< The button is down.
230   };
231
232   ButtonPainterPtr mPainter;              ///< Pointer to a ButtonPainter base class.
233
234   Toolkit::Button::ClickedSignalType mClickedSignal;           ///< Signal emitted when the button is clicked.
235   Toolkit::Button::StateChangedSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed.
236
237   TapGestureDetector mTapDetector;
238
239   ButtonState      mState;                ///< Stores the button state.
240
241   bool             mDisabled;             ///< Stores the disabled property.
242 };
243
244 } // namespace Internal
245
246
247 // Helpers for public-api forwarding methods
248
249 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
250 {
251   DALI_ASSERT_ALWAYS( button );
252
253   Dali::RefObject& handle = button.GetImplementation();
254
255   return static_cast<Toolkit::Internal::Button&>( handle );
256 }
257
258 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
259 {
260   DALI_ASSERT_ALWAYS( button );
261
262   const Dali::RefObject& handle = button.GetImplementation();
263
264   return static_cast<const Toolkit::Internal::Button&>( handle );
265 }
266
267 } // namespace Toolkit
268
269 } // namespace Dali
270
271 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__
272