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
49 BUTTON_PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
50 BUTTON_PROPERTY_END_INDEX = BUTTON_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
56 * Construct a new Button.
61 * A reference counted object may only be deleted by calling Unreference()
68 * @copydoc Dali::Toolkit::Button::SetDisabled( bool disabled )
70 void SetDisabled( bool disabled );
73 * @copydoc Dali::Toolkit::Button::IsDisabled() const
75 bool IsDisabled() const;
78 * @copydoc Dali::Toolkit::Button::SetAutoRepeating( bool autoRepeating )
80 void SetAutoRepeating( bool autoRepeating );
83 * @copydoc Dali::Toolkit::Button::IsAutoRepeating() const
85 bool IsAutoRepeating() const;
88 * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
90 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
93 * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay() const
95 float GetInitialAutoRepeatingDelay() const;
98 * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
100 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
103 * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay() const
105 float GetNextAutoRepeatingDelay() const;
108 * @copydoc Dali::Toolkit::Button::SetTogglableButton( bool togglable )
110 void SetTogglableButton( bool togglable );
113 * @copydoc Dali::Toolkit::Button::IsTogglableButton() const
115 bool IsTogglableButton() const;
118 * @copydoc Dali::Toolkit::Button::SetSelected( bool selected )
120 void SetSelected( bool selected );
123 * @copydoc Dali::Toolkit::Button::IsSelected() const
125 bool IsSelected() const;
128 * @copydoc Dali::Toolkit::Button::SetAnimationTime()
130 void SetAnimationTime( float animationTime );
133 * @copydoc Dali::Toolkit::Button::GetAnimationTime()
135 float GetAnimationTime() const;
138 * @copydoc Dali::Toolkit::Button::SetLabel( const std::string& label )
140 void SetLabel( const std::string& label );
143 * @copydoc Dali::Toolkit::Button::SetLabel( Actor label )
145 void SetLabel( Actor label );
148 * @copydoc Dali::Toolkit::Button::GetLabel()
150 Actor GetLabel() const;
153 * @copydoc Dali::Toolkit::PushButton::GetButtonImage()
155 Actor GetButtonImage() const;
159 * @return A reference to the button image.
161 Actor& GetButtonImage();
164 * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
166 Actor GetSelectedImage() const;
170 * @return A reference to the selected image.
172 Actor& GetSelectedImage();
175 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
177 Actor GetBackgroundImage() const;
181 * @return A reference to the background image.
183 Actor& GetBackgroundImage();
186 * @copydoc Dali::Toolkit::PushButton::GetDisabledImage()
188 Actor GetDisabledImage() const;
192 * @return A reference to the disabled button image.
194 Actor& GetDisabledImage();
197 * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage()
199 Actor GetDisabledSelectedImage() const;
203 * @return A reference to the disabled selected image.
205 Actor& GetDisabledSelectedImage();
208 * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage()
210 Actor GetDisabledBackgroundImage() const;
214 * @return A reference to the disabled background image.
216 Actor& GetDisabledBackgroundImage();
219 * Performs actions as requested using the action name.
220 * @param[in] object The object on which to perform the action.
221 * @param[in] actionName The action to perform.
222 * @param[in] attributes The attributes with which to perfrom this action.
223 * @return true if action has been accepted by this control
225 static bool DoAction( BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes );
228 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
230 virtual void SetButtonImage( Actor image ) {}
233 * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
235 virtual void SetSelectedImage( Actor image ) {}
238 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
240 virtual void SetBackgroundImage( Actor image ) {}
243 * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
245 virtual void SetDisabledImage( Actor image ) {}
248 * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
250 virtual void SetDisabledSelectedImage( Actor image ) {}
253 * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
255 virtual void SetDisabledBackgroundImage( Actor image ) {}
261 * @return A reference to the label actor.
268 * Perform the click action to click the button.
269 * @param[in] attributes The attributes to perfrom this action.
271 void DoClickAction( const PropertyValueContainer& attributes );
274 * This method is called after the button initialization.
275 * Could be reimplemented in subclasses to provide specific behaviour.
277 virtual void OnButtonInitialize() { }
280 * This method is called from the OnTouchEvent method when the button is down.
281 * Could be reimplemented in subclasses to provide specific behaviour.
283 virtual void OnButtonDown();
286 * This method is called from the OnTouchEvent method when the button is up.
287 * Could be reimplemented in subclasses to provide specific behaviour.
289 virtual void OnButtonUp();
292 * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or
293 * more than one touch points are received.
294 * Could be reimplemented in subclasses to provide specific behaviour.
296 virtual void OnTouchPointLeave();
299 * This method is called from the OnTouchEvent method when the touch point is interrupted.
300 * Could be reimplemented in subclasses to provide specific behaviour.
302 virtual void OnTouchPointInterrupted();
305 * This method is called when the button is removed from the stage.
306 * Could be reimplemented in subclasses to provide specific behaviour.
308 virtual void OnButtonStageDisconnection();
311 * This method is called when the label is set.
313 virtual void OnLabelSet() {}
316 * This method is called when the \e selected property is changed.
318 virtual void OnSelected( bool selected ) {}
321 * This method is called when the \e disabled property is changed.
323 virtual void OnDisabled( bool disabled ) {}
326 * This method is called when the button is pressed.
328 virtual void OnPressed() {}
331 * This method is called when the button is released.
333 virtual void OnReleased() {}
336 * This method is called when the button is clicked
338 virtual void OnClicked() {}
343 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
345 Toolkit::Button::ButtonSignalType& PressedSignal();
348 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
350 Toolkit::Button::ButtonSignalType& ReleasedSignal();
353 * @copydoc Dali::Toolkit::Button::ClickedSignal()
355 Toolkit::Button::ButtonSignalType& ClickedSignal();
358 * @copydoc Dali::Toolkit::Button::StateChangedSignal()
360 Toolkit::Button::ButtonSignalType& StateChangedSignal();
363 * Connects a callback function with the object's signals.
364 * @param[in] object The object providing the signal.
365 * @param[in] tracker Used to disconnect the signal.
366 * @param[in] signalName The signal to connect to.
367 * @param[in] functor A newly allocated FunctorDelegate.
368 * @return True if the signal was connected.
369 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
371 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
376 * Called when a property of an object of this type is set.
377 * @param[in] object The object whose property is set.
378 * @param[in] index The property index.
379 * @param[in] value The new property value.
381 static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value );
384 * Called to retrieve a property of an object of this type.
385 * @param[in] object The object whose property is to be retrieved.
386 * @param[in] index The property index.
387 * @return The current value of the property.
389 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
391 protected: // From CustomActorImpl
394 * @copydoc Dali::CustomActorImpl::OnTouchEvent( const TouchEvent& event )
396 virtual bool OnTouchEvent( const TouchEvent& event );
398 private: // From Control
401 * @copydoc Toolkit::Control::OnInitialize()
403 virtual void OnInitialize();
406 * @copydoc Toolkit::Control::OnActivated()
408 virtual void OnActivated();
411 * Callback received when the button is disconnected from the stage.
412 * It resets the button status.
414 void OnControlStageDisconnection();
419 * Handler for tap events.
420 * We do not actually do anything when we receive a tap as the button handles tap event through
421 * the touch event system itself as it requires more than just tap handling (e.g. leave events).
422 * This stops any of our parents receiving a tap gesture when it occurs within our area.
423 * @param[in] actor The tapped actor.
424 * @param[in] tap The tap gesture.
426 void OnTap(Actor actor, const TapGesture& tap);
429 * Sets up the autorepeating timer.
430 * @param[in] delay The delay time in seconds.
432 void SetUpTimer( float delay );
435 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
437 bool AutoRepeatingSlot();
443 ButtonUp, ///< The button is up.
444 ButtonDown, ///< The button is down.
448 * Button paint states.
452 UnselectedState, ///< The button is unselected.
453 SelectedState, ///< The button is selected.
454 DisabledUnselectedState, ///< The button is disabled and unselected.
455 DisabledSelectedState, ///< The button is disabled and selected.
456 UnselectedSelectedTransition, ///< The button is in transition from unselected to selected.
457 SelectedUnselectedTransition, ///< The push button is in transition from selected to unselected.
458 UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled.
459 DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected.
460 SelectedDisabledTransition, ///< The button is in transition from selected to disabled.
461 DisabledSelectedTransition ///< The button is in transition from disabled to selected.
464 ButtonState GetState();
469 Button( const Button& );
472 Button& operator = ( const Button& );
477 Toolkit::Button::ButtonSignalType mPressedSignal; ///< Signal emitted when the button is pressed.
478 Toolkit::Button::ButtonSignalType mReleasedSignal; ///< Signal emitted when the button is released.
479 Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked.
480 Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed.
482 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
484 Actor mLabel; ///< Stores the button label.
486 Actor mButtonContent; ///< Stores the unselected content.
487 Actor mSelectedContent; ///< Stores the selected content.
488 Actor mBackgroundContent; ///< Stores the background content.
489 Actor mDisabledContent; ///< Stores the disabled content.
490 Actor mDisabledSelectedContent; ///< Stores the disabled selected content.
491 Actor mDisabledBackgroundContent; ///< Stores the disabled background content.
493 TapGestureDetector mTapDetector;
495 bool mDisabled; ///< Stores the disabled property.
496 bool mAutoRepeating; ///< Stores the autorepeating property.
497 bool mTogglableButton; ///< Stores the togglable property.
498 bool mSelected; ///< Stores the selected state.
499 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
500 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
501 float mAnimationTime; ///< The animation time.
504 bool mClickActionPerforming;
506 ButtonState mState; ///< Stores the button state.
509 } // namespace Internal
511 // Helpers for public-api forwarding methods
513 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
515 DALI_ASSERT_ALWAYS( button );
517 Dali::RefObject& handle = button.GetImplementation();
519 return static_cast<Toolkit::Internal::Button&>( handle );
522 inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button& button )
524 DALI_ASSERT_ALWAYS( button );
526 const Dali::RefObject& handle = button.GetImplementation();
528 return static_cast<const Toolkit::Internal::Button&>( handle );
531 } // namespace Toolkit
535 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__