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::SetButtonImage( Actor image )
147 void SetButtonImage( Actor image );
150 * @copydoc Dali::Toolkit::PushButton::GetButtonImage()
152 Actor GetButtonImage() const;
156 * @return A reference to the button image.
158 Actor& GetButtonImage();
161 * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
163 void SetSelectedImage( Actor image );
166 * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
168 Actor GetSelectedImage() const;
172 * @return A reference to the selected image.
174 Actor& GetSelectedImage();
177 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
179 void SetBackgroundImage( Actor image );
182 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
184 Actor GetBackgroundImage() const;
188 * @return A reference to the background image.
190 Actor& GetBackgroundImage();
193 * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage( Actor image )
195 void SetSelectedBackgroundImage( Actor image );
198 * @copydoc Dali::Toolkit::PushButton::GetSelectedBackgroundImage()
200 Actor GetSelectedBackgroundImage() const;
204 * @return A reference to the selected background image.
206 Actor& GetSelectedBackgroundImage();
209 * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
211 void SetDisabledImage( Actor image );
214 * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
216 Actor GetDisabledImage() const;
220 * @return A reference to the disabled button image.
222 Actor& GetDisabledImage();
225 * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
227 void SetDisabledSelectedImage( Actor image );
230 * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
232 Actor GetDisabledSelectedImage() const;
236 * @return A reference to the disabled selected image.
238 Actor& GetDisabledSelectedImage();
241 * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
243 void SetDisabledBackgroundImage( Actor image );
246 * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
248 Actor GetDisabledBackgroundImage() const;
252 * @return A reference to the disabled background image.
254 Actor& GetDisabledBackgroundImage();
257 * Performs actions as requested using the action name.
258 * @param[in] object The object on which to perform the action.
259 * @param[in] actionName The action to perform.
260 * @param[in] attributes The attributes with which to perfrom this action.
261 * @return true if action has been accepted by this control
263 static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes );
268 * @return A reference to the label actor.
273 * It changes the transition state of the push button.
275 void UpdatePaintTransitionState();
280 * Perform the click action to click the button.
281 * @param[in] attributes The attributes to perfrom this action.
282 * @return true if this control can perform action.
284 bool DoClickAction( const Property::Map& attributes );
287 * This method is called after the button initialization.
288 * Could be reimplemented in subclasses to provide specific behaviour.
290 virtual void OnButtonInitialize() { }
293 * This method is called when the label is set.
295 virtual void OnLabelSet() {}
298 * This method is called when the button image is set
300 virtual void OnButtonImageSet() {}
303 * This method is called when the selected image is set
305 virtual void OnSelectedImageSet() {}
308 * This method is called when the background image is set
310 virtual void OnBackgroundImageSet() {}
313 * This method is called when the selected background image is set
315 virtual void OnSelectedBackgroundImageSet() {}
318 * This method is called when the disabled button image is set
320 virtual void OnDisabledImageSet() {}
323 * This method is called when the disabled selected image is set
325 virtual void OnDisabledSelectedImageSet() {}
328 * This method is called when the disabled background image is set
330 virtual void OnDisabledBackgroundImageSet() {}
333 * This method is called from the OnTouchEvent method when the button is down.
334 * Could be reimplemented in subclasses to provide specific behaviour.
336 virtual void OnButtonDown();
339 * This method is called from the OnTouchEvent method when the button is up.
340 * Could be reimplemented in subclasses to provide specific behaviour.
342 virtual void OnButtonUp();
345 * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
346 * more than one touch points are received.
347 * Could be reimplemented in subclasses to provide specific behaviour.
349 virtual void OnTouchPointLeave();
352 * This method is called from the OnTouchEvent method when the touch point is interrupted.
353 * Could be reimplemented in subclasses to provide specific behaviour.
355 virtual void OnTouchPointInterrupted();
358 * This method is called when the button is removed from the stage.
359 * Could be reimplemented in subclasses to provide specific behaviour.
361 virtual void OnButtonStageDisconnection();
364 * This method is called when the \e selected property is changed.
365 * @return true if the transition animation is started.
367 virtual bool OnSelected() { return false; }
370 * This method is called when the \e disabled property is changed.
371 * @return true if the transition animation is started.
373 virtual bool OnDisabled() { return false; }
376 * This method is called when the button is pressed.
377 * @return true if the transition animation is started.
379 virtual bool OnPressed() { return false; }
382 * This method is called when the button is released.
383 * @return true if the transition animation is started.
385 virtual bool OnReleased() { return false; }
388 * This method stops all animations
390 virtual void StopAllAnimations() {}
395 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
397 Toolkit::Button::ButtonSignalType& PressedSignal();
400 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
402 Toolkit::Button::ButtonSignalType& ReleasedSignal();
405 * @copydoc Dali::Toolkit::Button::ClickedSignal()
407 Toolkit::Button::ButtonSignalType& ClickedSignal();
410 * @copydoc Dali::Toolkit::Button::StateChangedSignal()
412 Toolkit::Button::ButtonSignalType& StateChangedSignal();
415 * Connects a callback function with the object's signals.
416 * @param[in] object The object providing the signal.
417 * @param[in] tracker Used to disconnect the signal.
418 * @param[in] signalName The signal to connect to.
419 * @param[in] functor A newly allocated FunctorDelegate.
420 * @return True if the signal was connected.
421 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
423 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
428 * Called when a property of an object of this type is set.
429 * @param[in] object The object whose property is set.
430 * @param[in] index The property index.
431 * @param[in] value The new property value.
433 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
436 * Called to retrieve a property of an object of this type.
437 * @param[in] object The object whose property is to be retrieved.
438 * @param[in] index The property index.
439 * @return The current value of the property.
441 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
443 protected: // From CustomActorImpl
446 * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
448 virtual bool OnTouchEvent( const TouchEvent& event );
450 private: // From Control
453 * @copydoc Toolkit::Control::OnInitialize()
455 virtual void OnInitialize();
458 * @copydoc Toolkit::Control::OnAccessibilityActivated()
460 virtual bool OnAccessibilityActivated();
463 * @copydoc Toolkit::Control::OnKeyboardEnter()
465 virtual bool OnKeyboardEnter();
468 * Callback received when the button is disconnected from the stage.
469 * It resets the button status.
471 void OnControlStageDisconnection();
476 * Handler for tap events.
477 * We do not actually do anything when we receive a tap as the button handles tap event through
478 * the touch event system itself as it requires more than just tap handling (e.g. leave events).
479 * This stops any of our parents receiving a tap gesture when it occurs within our area.
480 * @param[in] actor The tapped actor.
481 * @param[in] tap The tap gesture.
483 void OnTap(Actor actor, const TapGesture& tap);
486 * Sets up the autorepeating timer.
487 * @param[in] delay The delay time in seconds.
489 void SetUpTimer( float delay );
492 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
494 bool AutoRepeatingSlot();
497 * Sets the button as selected or unselected.
498 * @param[in] selected \e selected property value.
499 * @param[in] emitSignal Emit a signal if this value is \e true.
501 void SetSelected( bool selected, bool emitSignal );
504 * This method is called when the button is pressed.
509 * This method is called when the button is released.
517 ButtonUp, ///< The button is up.
518 ButtonDown, ///< The button is down.
522 * Button paint states.
526 UnselectedState, ///< The button is unselected.
527 SelectedState, ///< The button is selected.
528 DisabledUnselectedState, ///< The button is disabled and unselected.
529 DisabledSelectedState, ///< The button is disabled and selected.
530 UnselectedSelectedTransition, ///< The button is in transition from unselected to selected.
531 SelectedUnselectedTransition, ///< The button is in transition from selected to unselected.
532 UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled.
533 DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected.
534 SelectedDisabledTransition, ///< The button is in transition from selected to disabled.
535 DisabledSelectedTransition ///< The button is in transition from disabled to selected.
538 ButtonState GetState();
539 PaintState GetPaintState();
542 * Inserts the actor to the button.
544 void InsertChild( unsigned int index, Actor& actor );
547 * Removes the actor from the button.
549 void RemoveChild( Actor& actor );
552 * Finds the index of the actor.
553 * If the actor doesn't exist, return the last index + 1.
555 unsigned int FindChildIndex( Actor& actor );
560 Button( const Button& );
563 Button& operator = ( const Button& );
568 Toolkit::Button::ButtonSignalType mPressedSignal; ///< Signal emitted when the button is pressed.
569 Toolkit::Button::ButtonSignalType mReleasedSignal; ///< Signal emitted when the button is released.
570 Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked.
571 Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed.
573 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
575 Actor mLabel; ///< Stores the button label.
577 Actor mButtonContent; ///< Stores the unselected content.
578 Actor mSelectedContent; ///< Stores the selected content.
579 Actor mBackgroundContent; ///< Stores the background content.
580 Actor mSelectedBackgroundContent; ///< Stores the selected background content.
581 Actor mDisabledContent; ///< Stores the disabled content.
582 Actor mDisabledSelectedContent; ///< Stores the disabled selected content.
583 Actor mDisabledBackgroundContent; ///< Stores the disabled background content.
585 TapGestureDetector mTapDetector;
587 bool mDisabled; ///< Stores the disabled property.
588 bool mAutoRepeating; ///< Stores the autorepeating property.
589 bool mTogglableButton; ///< Stores the togglable property.
590 bool mSelected; ///< Stores the selected state.
591 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
592 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
593 float mAnimationTime; ///< The animation time.
596 bool mClickActionPerforming;
598 ButtonState mState; ///< Stores the button state.
599 PaintState mPaintState; ///< Stores the paint state.
602 } // namespace Internal
604 // Helpers for public-api forwarding methods
606 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
608 DALI_ASSERT_ALWAYS( button );
610 Dali::RefObject& handle = button.GetImplementation();
612 return static_cast<Toolkit::Internal::Button&>( handle );
615 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
617 DALI_ASSERT_ALWAYS( button );
619 const Dali::RefObject& handle = button.GetImplementation();
621 return static_cast<const Toolkit::Internal::Button&>( handle );
624 } // namespace Toolkit
628 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__