Property refactor in dali-toolkit: Toolkit changes
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / button-impl.h
index d7df9f0..f9dee5a 100644 (file)
@@ -1,27 +1,29 @@
 #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 <dali/public-api/adaptor-framework/timer.h>
 
 // INTERNAL INCLUDES
-#include <dali/dali.h>
 #include <dali-toolkit/public-api/controls/buttons/button.h>
 #include <dali-toolkit/public-api/controls/control-impl.h>
-#include "button-painter-impl.h"
 
 namespace Dali
 {
@@ -37,16 +39,8 @@ namespace Internal
 /**
  * Button is the base class implementation for all buttons.
  */
-class Button : public ControlImpl
+class Button : public Control
 {
-public:
-
-  // Properties
-  enum
-  {
-    BUTTON_PROPERTY_START_INDEX = ControlImpl::CONTROL_PROPERTY_END_INDEX + 1,
-    BUTTON_PROPERTY_END_INDEX = BUTTON_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
-  };
 
 protected:
 
@@ -63,14 +57,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 SetDimmed( bool dimmed );
+  void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
 
   /**
-   * @copydoc Dali::Toolkit::Button::IsDimmed() const
+   * @copydoc Dali::Toolkit::Button::GetNextAutoRepeatingDelay() const
    */
-  bool IsDimmed() 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 SetSelected( bool selected );
+
+  /**
+   * @copydoc Dali::Toolkit::Button::IsSelected() const
+   */
+  bool IsSelected() const;
 
   /**
    * @copydoc Dali::Toolkit::Button::SetAnimationTime()
@@ -82,9 +126,143 @@ 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::GetButtonImage()
+   */
+  Actor GetButtonImage() const;
+
+  /**
+   * Internal use only.
+   * @return A reference to the button image.
+   */
+  Actor& GetButtonImage();
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::GetSelectedImage()
+   */
+  Actor GetSelectedImage() const;
+
+  /**
+   * Internal use only.
+   * @return A reference to the selected image.
+   */
+  Actor& GetSelectedImage();
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
+   */
+  Actor GetBackgroundImage() const;
+
+  /**
+   * Internal use only.
+   * @return A reference to the background image.
+   */
+  Actor& GetBackgroundImage();
+
+  /**
+   * @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::GetDisabledSelectedImage()
+   */
+  Actor GetDisabledSelectedImage() const;
+
+  /**
+   * Internal use only.
+   * @return A reference to the disabled selected image.
+   */
+  Actor& GetDisabledSelectedImage();
+
+  /**
+   * @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 PropertyValueContainer& attributes );
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
+   */
+  virtual void SetButtonImage( Actor image ) {}
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::SetSelectedImage( Actor image )
+   */
+  virtual void SetSelectedImage( Actor image ) {}
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
+   */
+  virtual void SetBackgroundImage( Actor image ) {}
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::SetDisabledImage( Actor image )
+   */
+  virtual void SetDisabledImage( Actor image ) {}
+
+  /**
+   * @copydoc Dali::Toolkit::CheckBoxButton::SetDisabledSelectedImage( Actor image )
+   */
+  virtual void SetDisabledSelectedImage( Actor image ) {}
+
+  /**
+   * @copydoc Dali::Toolkit::PushButton::SetDisabledBackgroundImage( Actor image )
+   */
+  virtual void SetDisabledBackgroundImage( Actor image ) {}
+
+protected:
+
+  /**
+   * Internal use only.
+   * @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.
+   */
+  void DoClickAction( const PropertyValueContainer& attributes );
+
+  /**
    * This method is called after the button initialization.
    * Could be reimplemented in subclasses to provide specific behaviour.
    */
@@ -94,47 +272,84 @@ private:
    * 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 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 label is set.
    */
-  virtual void OnAnimationTimeSet( float animationTime );
+  virtual void OnLabelSet() {}
 
   /**
-   * 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 \e selected property is changed.
    */
-  virtual float OnAnimationTimeRequested() const;
+  virtual void OnSelected( bool selected ) {}
+
+  /**
+   * This method is called when the \e disabled property is changed.
+   */
+  virtual void OnDisabled( bool disabled ) {}
+
+  /**
+   * This method is called when the button is pressed.
+   */
+  virtual void OnPressed() {}
+
+  /**
+   * This method is called when the button is released.
+   */
+  virtual void OnReleased() {}
+
+  /**
+   * This method is called when the button is clicked
+   */
+  virtual void OnClicked() {}
 
 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.
@@ -172,7 +387,7 @@ protected: // From CustomActorImpl
    */
   virtual bool OnTouchEvent( const TouchEvent& event );
 
-private: // From ControlImpl
+private: // From Control
 
   /**
    * @copydoc Toolkit::Control::OnInitialize()
@@ -180,9 +395,15 @@ private: // From ControlImpl
   virtual void OnInitialize();
 
   /**
-   * @copydoc Toolkit::Control::OnControlSizeSet( const Vector3& targetSize )
+   * @copydoc Toolkit::Control::OnActivated()
    */
-  virtual void OnControlSizeSet( const Vector3& targetSize );
+  virtual void OnActivated();
+
+  /**
+   * Callback received when the button is disconnected from the stage.
+   * It resets the button status.
+   */
+  void OnControlStageDisconnection();
 
 private:
 
@@ -194,15 +415,45 @@ 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();
+
+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.
+    UnselectedSelectedTransition, ///< The button is in transition from unselected to selected.
+    SelectedUnselectedTransition, ///< The push button is in transition from selected to unselected.
+    UnselectedDisabledTransition, ///< The button is in transition from unselected to disabled.
+    DisabledUnselectedTransition, ///< The button is in transition from disabled to unselected.
+    SelectedDisabledTransition,   ///< The button is in transition from selected to disabled.
+    DisabledSelectedTransition    ///< The button is in transition from disabled to selected.
+  };
+
+  ButtonState GetState();
 
 private:
 
@@ -212,28 +463,43 @@ private:
   // Undefined
   Button& operator = ( const Button& );
 
-protected: // Signals
-
-  enum ButtonState
-  {
-    ButtonUp,                         ///< The button is up.
-    ButtonDown,                       ///< The button is down.
-  };
+private:
 
-  ButtonState      mState;                ///< Stores the button state.
+  // 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.
 
-  bool             mDimmed;               ///< Stores the dimmed property.
+  Timer mAutoRepeatingTimer;                   ///< Timer used to implement the autorepeating property.
 
-  ButtonPainterPtr mPainter;              ///< Pointer to a ButtonPainter base class.
+  Actor mLabel;                                ///< Stores the button label.
 
-  Toolkit::Button::ClickedSignalV2 mClickedSignalV2; ///< Signal emitted when the button is clicked.
+  Actor mButtonContent;                        ///< Stores the unselected content.
+  Actor mSelectedContent;                      ///< Stores the selected content.
+  Actor mBackgroundContent;                    ///< Stores the background content.
+  Actor mDisabledContent;                      ///< Stores the disabled content.
+  Actor mDisabledSelectedContent;              ///< Stores the disabled selected content.
+  Actor mDisabledBackgroundContent;            ///< Stores the disabled background content.
 
   TapGestureDetector mTapDetector;
+
+  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.
 };
 
 } // namespace Internal
 
-
 // Helpers for public-api forwarding methods
 
 inline Toolkit::Internal::Button& GetImplementation( Toolkit::Button& button )
@@ -259,4 +525,3 @@ inline const Toolkit::Internal::Button& GetImplementation( const Toolkit::Button
 } // namespace Dali
 
 #endif // __DALI_TOOLKIT_INTERNAL_BUTTON_H__
-