X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Finternal%2Fcontrols%2Fbuttons%2Fbutton-impl.h;h=89f059159d00c7a2b3250d759a3e96fa2989adac;hp=8365f35e9e88bf65deccf22a95f42b498d25dcf4;hb=efc136204e9a4460a7a2421e673c873e23974a80;hpb=e2eda444afbe82e9591fe198eef339227f90a616 diff --git a/dali-toolkit/internal/controls/buttons/button-impl.h b/dali-toolkit/internal/controls/buttons/button-impl.h index 8365f35..89f0591 100644 --- a/dali-toolkit/internal/controls/buttons/button-impl.h +++ b/dali-toolkit/internal/controls/buttons/button-impl.h @@ -1,27 +1,30 @@ #ifndef __DALI_TOOLKIT_INTERNAL_BUTTON_H__ #define __DALI_TOOLKIT_INTERNAL_BUTTON_H__ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2014 Samsung Electronics Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +// EXTERNAL INCLUDES +#include +#include // INTERNAL INCLUDES -#include #include #include -#include "button-painter-impl.h" namespace Dali { @@ -37,7 +40,7 @@ namespace Internal /** * Button is the base class implementation for all buttons. */ -class Button : public ControlImpl +class Button : public Control { protected: @@ -55,14 +58,64 @@ protected: public: /** - * @copydoc Dali::Toolkit::Button::SetDimmed( bool dimmed ) + * @copydoc Dali::Toolkit::Button::SetDisabled( bool disabled ) + */ + void SetDisabled( bool disabled ); + + /** + * @copydoc Dali::Toolkit::Button::IsDisabled() const + */ + bool IsDisabled() const; + + /** + * @copydoc Dali::Toolkit::Button::SetAutoRepeating( bool autoRepeating ) + */ + void SetAutoRepeating( bool autoRepeating ); + + /** + * @copydoc Dali::Toolkit::Button::IsAutoRepeating() const + */ + bool IsAutoRepeating() const; + + /** + * @copydoc Dali::Toolkit::Button::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ) + */ + void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ); + + /** + * @copydoc Dali::Toolkit::Button::GetInitialAutoRepeatingDelay() const + */ + float GetInitialAutoRepeatingDelay() const; + + /** + * @copydoc Dali::Toolkit::Button::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ) + */ + void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ); + + /** + * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay() const + */ + float GetNextAutoRepeatingDelay() const; + + /** + * @copydoc Dali::Toolkit::Button::SetTogglableButton( bool togglable ) + */ + void SetTogglableButton( bool togglable ); + + /** + * @copydoc Dali::Toolkit::Button::IsTogglableButton() const + */ + bool IsTogglableButton() const; + + /** + * @copydoc Dali::Toolkit::Button::SetSelected( bool selected ) */ - void SetDimmed( bool dimmed ); + void SetSelected( bool selected ); /** - * @copydoc Dali::Toolkit::Button::IsDimmed() const + * @copydoc Dali::Toolkit::Button::IsSelected() const */ - bool IsDimmed() const; + bool IsSelected() const; /** * @copydoc Dali::Toolkit::Button::SetAnimationTime() @@ -74,59 +127,276 @@ public: */ float GetAnimationTime() const; + /** + * @copydoc Dali::Toolkit::Button::SetLabel( const std::string& label ) + */ + void SetLabel( const std::string& label ); + + /** + * @copydoc Dali::Toolkit::Button::SetLabel( Actor label ) + */ + void SetLabel( Actor label ); + + /** + * @copydoc Dali::Toolkit::Button::GetLabel() + */ + Actor GetLabel() const; + + /** + * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image ) + */ + void SetButtonImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::PushButton::GetButtonImage() + */ + Actor GetButtonImage() const; + + /** + * Internal use only. + * @return A reference to the button image. + */ + Actor& GetButtonImage(); + + /** + * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image ) + */ + void SetSelectedImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::PushButton::GetSelectedImage() + */ + Actor GetSelectedImage() const; + + /** + * Internal use only. + * @return A reference to the selected image. + */ + Actor& GetSelectedImage(); + + /** + * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image ) + */ + void SetBackgroundImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage() + */ + Actor GetBackgroundImage() const; + + /** + * Internal use only. + * @return A reference to the background image. + */ + Actor& GetBackgroundImage(); + + /** + * @copydoc Dali::Toolkit::PushButton::SetSelectedBackgroundImage( Actor image ) + */ + void SetSelectedBackgroundImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::PushButton::GetSelectedBackgroundImage() + */ + Actor GetSelectedBackgroundImage() const; + + /** + * Internal use only. + * @return A reference to the selected background image. + */ + Actor& GetSelectedBackgroundImage(); + + /** + * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image ) + */ + void SetDisabledImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::PushButton::GetDisabledImage() + */ + Actor GetDisabledImage() const; + + /** + * Internal use only. + * @return A reference to the disabled button image. + */ + Actor& GetDisabledImage(); + + /** + * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image ) + */ + void SetDisabledSelectedImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::CheckBoxButton::GetDisabledSelectedImage() + */ + Actor GetDisabledSelectedImage() const; + + /** + * Internal use only. + * @return A reference to the disabled selected image. + */ + Actor& GetDisabledSelectedImage(); + + /** + * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image ) + */ + void SetDisabledBackgroundImage( Actor image ); + + /** + * @copydoc Dali::Toolkit::PushButton::GetDisabledBackgroundImage() + */ + Actor GetDisabledBackgroundImage() const; + + /** + * Internal use only. + * @return A reference to the disabled background image. + */ + Actor& GetDisabledBackgroundImage(); + + /** + * Performs actions as requested using the action name. + * @param[in] object The object on which to perform the action. + * @param[in] actionName The action to perform. + * @param[in] attributes The attributes with which to perfrom this action. + * @return true if action has been accepted by this control + */ + static bool DoAction( BaseObject* object, const std::string& actionName, const Property::Map& attributes ); + +protected: + + /** + * @return A reference to the label actor. + */ + Actor& GetLabel(); + private: /** + * Perform the click action to click the button. + * @param[in] attributes The attributes to perfrom this action. + * @return true if this control can perform action. + */ + bool DoClickAction( const Property::Map& attributes ); + + /** * This method is called after the button initialization. * Could be reimplemented in subclasses to provide specific behaviour. */ virtual void OnButtonInitialize() { } /** + * This method is called when the label is set. + */ + virtual void OnLabelSet() {} + + /** + * This method is called when the button image is set + */ + virtual void OnButtonImageSet() {} + + /** + * This method is called when the selected image is set + */ + virtual void OnSelectedImageSet() {} + + /** + * This method is called when the background image is set + */ + virtual void OnBackgroundImageSet() {} + + /** + * This method is called when the selected background image is set + */ + virtual void OnSelectedBackgroundImageSet() {} + + /** + * This method is called when the disabled button image is set + */ + virtual void OnDisabledImageSet() {} + + /** + * This method is called when the disabled selected image is set + */ + virtual void OnDisabledSelectedImageSet() {} + + /** + * This method is called when the disabled background image is set + */ + virtual void OnDisabledBackgroundImageSet() {} + + /** * This method is called from the OnTouchEvent method when the button is down. * Could be reimplemented in subclasses to provide specific behaviour. */ - virtual void OnButtonDown() { } + virtual void OnButtonDown(); /** * This method is called from the OnTouchEvent method when the button is up. * Could be reimplemented in subclasses to provide specific behaviour. */ - virtual void OnButtonUp() { } + virtual void OnButtonUp(); /** * This method is called from the OnTouchEvent method when the touch point leaves the boundary of the button or * more than one touch points are received. * Could be reimplemented in subclasses to provide specific behaviour. */ - virtual void OnTouchPointLeave() { } + virtual void OnTouchPointLeave(); /** * This method is called from the OnTouchEvent method when the touch point is interrupted. * Could be reimplemented in subclasses to provide specific behaviour. */ - virtual void OnTouchPointInterrupted() { } + virtual void OnTouchPointInterrupted(); + + /** + * This method is called when the button is removed from the stage. + * Could be reimplemented in subclasses to provide specific behaviour. + */ + virtual void OnButtonStageDisconnection(); + + /** + * This method is called when the \e selected property is changed. + */ + virtual void OnSelected() {} /** - * This method is called when the animation time is set. - * Needs to be reimplemented in subclasses to set the animation time in different buttons. - * @param animationTime The animation time in seconds. + * This method is called when the \e disabled property is changed. */ - virtual void OnAnimationTimeSet( float animationTime ); + virtual void OnDisabled() {} /** - * This method is called when the animation time is requested. - * Needs to be reimplemented in subclases to return the animation time. - * @return The animation time in seconds. + * This method is called when the button is pressed. */ - virtual float OnAnimationTimeRequested() const; + virtual void OnPressed() {} + + /** + * This method is called when the button is released. + */ + virtual void OnReleased() {} public: /** + * @copydoc Dali::Toolkit::PushButton::PressedSignal() + */ + Toolkit::Button::ButtonSignalType& PressedSignal(); + + /** + * @copydoc Dali::Toolkit::PushButton::ReleasedSignal() + */ + Toolkit::Button::ButtonSignalType& ReleasedSignal(); + + /** * @copydoc Dali::Toolkit::Button::ClickedSignal() */ - Toolkit::Button::ClickedSignalV2& ClickedSignal(); + Toolkit::Button::ButtonSignalType& ClickedSignal(); + + /** + * @copydoc Dali::Toolkit::Button::StateChangedSignal() + */ + Toolkit::Button::ButtonSignalType& StateChangedSignal(); /** * Connects a callback function with the object's signals. @@ -139,6 +409,24 @@ public: */ static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor ); + // Properties + + /** + * Called when a property of an object of this type is set. + * @param[in] object The object whose property is set. + * @param[in] index The property index. + * @param[in] value The new property value. + */ + static void SetProperty( BaseObject* object, Property::Index index, const Property::Value& value ); + + /** + * Called to retrieve a property of an object of this type. + * @param[in] object The object whose property is to be retrieved. + * @param[in] index The property index. + * @return The current value of the property. + */ + static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex ); + protected: // From CustomActorImpl /** @@ -146,7 +434,7 @@ protected: // From CustomActorImpl */ virtual bool OnTouchEvent( const TouchEvent& event ); -private: // From ControlImpl +private: // From Control /** * @copydoc Toolkit::Control::OnInitialize() @@ -154,14 +442,20 @@ private: // From ControlImpl virtual void OnInitialize(); /** - * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize ) + * @copydoc Toolkit::Control::OnAccessibilityActivated() + */ + virtual bool OnAccessibilityActivated(); + + /** + * @copydoc Toolkit::Control::OnKeyboardEnter() */ - virtual void OnControlSizeSet( const Vector3& targetSize ); + virtual bool OnKeyboardEnter(); /** - * @copydoc Dali::CustomActorImpl::OnPropertySet() + * Callback received when the button is disconnected from the stage. + * It resets the button status. */ - virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ); + void OnControlStageDisconnection(); private: @@ -173,17 +467,156 @@ private: * @param[in] actor The tapped actor. * @param[in] tap The tap gesture. */ - void OnTap(Actor actor, TapGesture tap); + void OnTap(Actor actor, const TapGesture& tap); -private: + /** + * Sets up the autorepeating timer. + * @param[in] delay The delay time in seconds. + */ + void SetUpTimer( float delay ); /** - * Callback received when the button is disconected from the stage. - * It resets the button status. + * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer. */ - void OnStageDisconnection(); + bool AutoRepeatingSlot(); + + /** + * Sets the button as selected or unselected. + * @param[in] selected \e selected property value. + * @param[in] emitSignal Emit a signal if this value is \e true. + */ + void SetSelected( bool selected, bool emitSignal ); + + /** + * This method is called when the button is pressed. + */ + void Pressed(); + + /** + * This method is called when the button is released. + */ + void Released(); + +protected: + + enum ButtonState + { + ButtonUp, ///< The button is up. + ButtonDown, ///< The button is down. + }; + + /** + * Button paint states. + */ + enum PaintState + { + UnselectedState, ///< The button is unselected. + SelectedState, ///< The button is selected. + DisabledUnselectedState, ///< The button is disabled and unselected. + DisabledSelectedState, ///< The button is disabled and selected. + }; + + ButtonState GetState(); + PaintState GetPaintState(); + + /** + * Returns the animation to be used for transitioning creating the animation if needed. + * @return The initialised transition animation. + */ + Dali::Animation GetTransitionAnimation(); + + /** + * Prepares the actor to be transitioned in. + * @param[in] actor The actor that will be transitioned in. + */ + virtual void PrepareForTranstionIn( Actor actor ) {} + + /** + * Prepares the actor to be transitioned in. + * @param[in] actor The actor that will be transitioned out. + */ + virtual void PrepareForTranstionOut( Actor actor ) {} + + /** + * Transitions the actor in, allowing derived classes to configure + * the GetTransitionAnimation() animation ready. + * Button is in charge of calling Dali::Animation::Play and so derived classes + * only need to add the animation. + */ + virtual void OnTransitionIn( Actor actor ) {} + + /** + * Transitions the actor out, allowing derived classes to configure + * the GetTransitionAnimation() animation ready. + * Button is in charge of calling Dali::Animation::Play and so derived classes + * only need to add the animation. + */ + virtual void OnTransitionOut( Actor actor ) {} private: + /** + * Starts the transition animation. + * Button::TransitionFinished is called when the animation finishes. + */ + void StartTransitionAnimation(); + + /** + * This method stops all transition animations + */ + void StopTransitionAnimation(); + + /** + * Called when the transition animation finishes. + */ + void TransitionAnimationFinished( Dali::Animation& source ); + + /** + * Resets the Button to the base state for the current paint state. + * Any additionally inserted images needed for transitions that are + * no longer needed and the removed. + */ + void ResetImageLayers(); + + /** + * Transitions in the actor, inserting the actor above childLower below the childUpper. + * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + */ + void TransitionInBetween( Actor childLower, Actor childUpper, Actor actor ); + + /** + * Transitions in the actor, inserting the actor above the child if the child exists or at the bottom otherwise + * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + */ + void TransitionInAbove( Actor child, Actor actor ); + + /** + * Transitions in the actor, inserting the actor at the index + * Will not insert the actor if it is already attached to a parent (and so will not reorder the actor) + */ + void TransitionInAtIndex( unsigned int index, Actor actor ); + + /** + * Transitions out the actor + */ + void TransitionOut( Actor actor ); + + /** + * Inserts the actor to the button and prepares it to be transitioned out + * @return true if the child was inserted, false otherwise + */ + bool InsertButtonImage( unsigned int index, Actor& actor ); + + /** + * Removes the actor from the button and prepares it to be transitioned out + */ + void RemoveButtonImage( Actor& actor ); + + /** + * Finds the index of the actor. + * If the actor doesn't exist, return the last index + 1. + */ + unsigned int FindChildIndex( Actor& actor ); + // Undefined Button( const Button& ); @@ -191,30 +624,48 @@ private: // Undefined Button& operator = ( const Button& ); -protected: // Signals +private: - enum ButtonState - { - ButtonUp, ///< The button is up. - ButtonDown, ///< The button is down. - }; + // Signals + Toolkit::Button::ButtonSignalType mPressedSignal; ///< Signal emitted when the button is pressed. + Toolkit::Button::ButtonSignalType mReleasedSignal; ///< Signal emitted when the button is released. + Toolkit::Button::ButtonSignalType mClickedSignal; ///< Signal emitted when the button is clicked. + Toolkit::Button::ButtonSignalType mStateChangedSignal; ///< Signal emitted when the button's state is changed. - ButtonState mState; ///< Stores the button state. + Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property. - bool mDimmed; ///< Stores the dimmed property. + Actor mLabel; ///< Stores the button label. - ButtonPainterPtr mPainter; ///< Pointer to a ButtonPainter base class. + Actor mUnselectedContent; ///< Stores the unselected content. + Actor mSelectedContent; ///< Stores the selected content. + Actor mBackgroundContent; ///< Stores the background content. + Actor mSelectedBackgroundContent; ///< Stores the selected background content. + Actor mDisabledContent; ///< Stores the disabled content. + Actor mDisabledSelectedContent; ///< Stores the disabled selected content. + Actor mDisabledBackgroundContent; ///< Stores the disabled background content. - Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked. + Animation mTransitionAnimation; ///< Animation used in the state transitions. TapGestureDetector mTapDetector; - Property::Index mPropertyDimmed; ///< Property index for dimmed. + bool mDisabled; ///< Stores the disabled property. + bool mAutoRepeating; ///< Stores the autorepeating property. + bool mTogglableButton; ///< Stores the togglable property. + bool mSelected; ///< Stores the selected state. + float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds. + float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds. + + float mAnimationTime; ///< The animation time. + + // Actions + bool mClickActionPerforming; + + ButtonState mState; ///< Stores the button state. + PaintState mPaintState; ///< Stores the paint state. }; } // namespace Internal - // Helpers for public-api forwarding methods inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button ) @@ -240,4 +691,3 @@ inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button } // namespace Dali #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__ -