1 #ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_BUTTON_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/adaptor-framework/timer.h>
25 #include <dali-toolkit/public-api/controls/buttons/button.h>
26 #include <dali-toolkit/public-api/controls/control-impl.h>
40 * Button is the base class implementation for all buttons.
42 class Button : public Control
48 * Construct a new Button.
53 * A reference counted object may only be deleted by calling Unreference()
60 * @copydoc Dali::Toolkit::Button::SetDisabled( bool disabled )
62 void SetDisabled( bool disabled );
65 * @copydoc Dali::Toolkit::Button::IsDisabled() const
67 bool IsDisabled() const;
70 * @copydoc Dali::Toolkit::Button::SetAutoRepeating( bool autoRepeating )
72 void SetAutoRepeating( bool autoRepeating );
75 * @copydoc Dali::Toolkit::Button::IsAutoRepeating() const
77 bool IsAutoRepeating() const;
80 * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
82 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
85 * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay() const
87 float GetInitialAutoRepeatingDelay() const;
90 * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
92 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
95 * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay() const
97 float GetNextAutoRepeatingDelay() const;
100 * @copydoc Dali::Toolkit::Button::SetTogglableButton( bool togglable )
102 void SetTogglableButton( bool togglable );
105 * @copydoc Dali::Toolkit::Button::IsTogglableButton() const
107 bool IsTogglableButton() const;
110 * @copydoc Dali::Toolkit::Button::SetSelected( bool selected )
112 void SetSelected( bool selected );
115 * @copydoc Dali::Toolkit::Button::IsSelected() const
117 bool IsSelected() const;
120 * @copydoc Dali::Toolkit::Button::SetAnimationTime()
122 void SetAnimationTime( float animationTime );
125 * @copydoc Dali::Toolkit::Button::GetAnimationTime()
127 float GetAnimationTime() const;
130 * @copydoc Dali::Toolkit::Button::SetLabel( const std::string& label )
132 void SetLabel( const std::string& label );
135 * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
137 void SetLabel( Actor label );
140 * @copydoc Dali::Toolkit::Button::GetLabel()
142 Actor GetLabel() const;
145 * @copydoc Dali::Toolkit::PushButton::GetButtonImage()
147 Actor GetButtonImage() const;
151 * @return A reference to the button image.
153 Actor& GetButtonImage();
156 * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
158 Actor GetSelectedImage() const;
162 * @return A reference to the selected image.
164 Actor& GetSelectedImage();
167 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
169 Actor GetBackgroundImage() const;
173 * @return A reference to the background image.
175 Actor& GetBackgroundImage();
178 * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
180 Actor GetDisabledImage() const;
184 * @return A reference to the disabled button image.
186 Actor& GetDisabledImage();
189 * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
191 Actor GetDisabledSelectedImage() const;
195 * @return A reference to the disabled selected image.
197 Actor& GetDisabledSelectedImage();
200 * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
202 Actor GetDisabledBackgroundImage() const;
206 * @return A reference to the disabled background image.
208 Actor& GetDisabledBackgroundImage();
211 * Performs actions as requested using the action name.
212 * @param[in] object The object on which to perform the action.
213 * @param[in] actionName The action to perform.
214 * @param[in] attributes The attributes with which to perfrom this action.
215 * @return true if action has been accepted by this control
217 static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes );
220 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
222 virtual void SetButtonImage( Actor image ) {}
225 * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
227 virtual void SetSelectedImage( Actor image ) {}
230 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
232 virtual void SetBackgroundImage( Actor image ) {}
235 * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
237 virtual void SetDisabledImage( Actor image ) {}
240 * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
242 virtual void SetDisabledSelectedImage( Actor image ) {}
245 * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
247 virtual void SetDisabledBackgroundImage( Actor image ) {}
253 * @return A reference to the label actor.
260 * Perform the click action to click the button.
261 * @param[in] attributes The attributes to perfrom this action.
263 void DoClickAction( const PropertyValueContainer& attributes );
266 * This method is called after the button initialization.
267 * Could be reimplemented in subclasses to provide specific behaviour.
269 virtual void OnButtonInitialize() { }
272 * This method is called from the OnTouchEvent method when the button is down.
273 * Could be reimplemented in subclasses to provide specific behaviour.
275 virtual void OnButtonDown();
278 * This method is called from the OnTouchEvent method when the button is up.
279 * Could be reimplemented in subclasses to provide specific behaviour.
281 virtual void OnButtonUp();
284 * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
285 * more than one touch points are received.
286 * Could be reimplemented in subclasses to provide specific behaviour.
288 virtual void OnTouchPointLeave();
291 * This method is called from the OnTouchEvent method when the touch point is interrupted.
292 * Could be reimplemented in subclasses to provide specific behaviour.
294 virtual void OnTouchPointInterrupted();
297 * This method is called when the button is removed from the stage.
298 * Could be reimplemented in subclasses to provide specific behaviour.
300 virtual void OnButtonStageDisconnection();
303 * This method is called when the label is set.
305 virtual void OnLabelSet() {}
308 * This method is called when the \e selected property is changed.
310 virtual void OnSelected( bool selected ) {}
313 * This method is called when the \e disabled property is changed.
315 virtual void OnDisabled( bool disabled ) {}
318 * This method is called when the button is pressed.
320 virtual void OnPressed() {}
323 * This method is called when the button is released.
325 virtual void OnReleased() {}
328 * This method is called when the button is clicked
330 virtual void OnClicked() {}
335 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
337 Toolkit::Button::ButtonSignalType& PressedSignal();
340 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
342 Toolkit::Button::ButtonSignalType& ReleasedSignal();
345 * @copydoc Dali::Toolkit::Button::ClickedSignal()
347 Toolkit::Button::ButtonSignalType& ClickedSignal();
350 * @copydoc Dali::Toolkit::Button::StateChangedSignal()
352 Toolkit::Button::ButtonSignalType& StateChangedSignal();
355 * Connects a callback function with the object's signals.
356 * @param[in] object The object providing the signal.
357 * @param[in] tracker Used to disconnect the signal.
358 * @param[in] signalName The signal to connect to.
359 * @param[in] functor A newly allocated FunctorDelegate.
360 * @return True if the signal was connected.
361 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
363 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
368 * Called when a property of an object of this type is set.
369 * @param[in] object The object whose property is set.
370 * @param[in] index The property index.
371 * @param[in] value The new property value.
373 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
376 * Called to retrieve a property of an object of this type.
377 * @param[in] object The object whose property is to be retrieved.
378 * @param[in] index The property index.
379 * @return The current value of the property.
381 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
383 protected: // From CustomActorImpl
386 * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
388 virtual bool OnTouchEvent( const TouchEvent& event );
390 private: // From Control
393 * @copydoc Toolkit::Control::OnInitialize()
395 virtual void OnInitialize();
398 * @copydoc Toolkit::Control::OnActivated()
400 virtual void OnActivated();
403 * Callback received when the button is disconnected from the stage.
404 * It resets the button status.
406 void OnControlStageDisconnection();
411 * Handler for tap events.
412 * We do not actually do anything when we receive a tap as the button handles tap event through
413 * the touch event system itself as it requires more than just tap handling (e.g. leave events).
414 * This stops any of our parents receiving a tap gesture when it occurs within our area.
415 * @param[in] actor The tapped actor.
416 * @param[in] tap The tap gesture.
418 void OnTap(Actor actor, const TapGesture& tap);
421 * Sets up the autorepeating timer.
422 * @param[in] delay The delay time in seconds.
424 void SetUpTimer( float delay );
427 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
429 bool AutoRepeatingSlot();
435 ButtonUp, ///< The button is up.
436 ButtonDown, ///< The button is down.
440 * Button paint states.
444 UnselectedState, ///< The button is unselected.
445 SelectedState, ///< The button is selected.
446 DisabledUnselectedState, ///< The button is disabled and unselected.
447 DisabledSelectedState, ///< The button is disabled and selected.
448 UnselectedSelectedTransition, ///< The button is in transition from unselected to selected.
449 SelectedUnselectedTransition, ///< The push button is in transition from selected to unselected.
450 UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled.
451 DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected.
452 SelectedDisabledTransition, ///< The button is in transition from selected to disabled.
453 DisabledSelectedTransition ///< The button is in transition from disabled to selected.
456 ButtonState GetState();
461 Button( const Button& );
464 Button& operator = ( const Button& );
469 Toolkit::Button::ButtonSignalType mPressedSignal; ///< Signal emitted when the button is pressed.
470 Toolkit::Button::ButtonSignalType mReleasedSignal; ///< Signal emitted when the button is released.
471 Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked.
472 Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed.
474 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
476 Actor mLabel; ///< Stores the button label.
478 Actor mButtonContent; ///< Stores the unselected content.
479 Actor mSelectedContent; ///< Stores the selected content.
480 Actor mBackgroundContent; ///< Stores the background content.
481 Actor mDisabledContent; ///< Stores the disabled content.
482 Actor mDisabledSelectedContent; ///< Stores the disabled selected content.
483 Actor mDisabledBackgroundContent; ///< Stores the disabled background content.
485 TapGestureDetector mTapDetector;
487 bool mDisabled; ///< Stores the disabled property.
488 bool mAutoRepeating; ///< Stores the autorepeating property.
489 bool mTogglableButton; ///< Stores the togglable property.
490 bool mSelected; ///< Stores the selected state.
491 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
492 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
493 float mAnimationTime; ///< The animation time.
496 bool mClickActionPerforming;
498 ButtonState mState; ///< Stores the button state.
501 } // namespace Internal
503 // Helpers for public-api forwarding methods
505 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
507 DALI_ASSERT_ALWAYS( button );
509 Dali::RefObject& handle = button.GetImplementation();
511 return static_cast<Toolkit::Internal::Button&>( handle );
514 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
516 DALI_ASSERT_ALWAYS( button );
518 const Dali::RefObject& handle = button.GetImplementation();
520 return static_cast<const Toolkit::Internal::Button&>( handle );
523 } // namespace Toolkit
527 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__