Refactored Button and derived classes, moving state change and transition logic to...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / buttons / push-button-impl.h
index dff5fc5..51164b5 100644 (file)
@@ -1,27 +1,28 @@
 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
 
 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
 #define __DALI_TOOLKIT_INTERNAL_PUSH_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.
+ *
+ */
 
 
-// INTERNAL INCLUDES
-#include <dali/public-api/common/dali-vector.h>
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/vector-wrapper.h>
 
 
+// INTERNAL INCLUDES
 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
-
 #include "button-impl.h"
 
 namespace Dali
 #include "button-impl.h"
 
 namespace Dali
@@ -48,299 +49,124 @@ public:
    */
   static Dali::Toolkit::PushButton New();
 
    */
   static Dali::Toolkit::PushButton New();
 
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetAutoRepeating( bool autoRepeating )
-   */
-  void SetAutoRepeating( bool autoRepeating );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::IsAutoRepeating() const
-   */
-  bool IsAutoRepeating() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
-   */
-  void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::GetInitialAutoRepeatingDelay() const
-   */
-  float GetInitialAutoRepeatingDelay() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
-   */
-  void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::GetNextAutoRepeatingDelay() const
-   */
-  float GetNextAutoRepeatingDelay() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetToggleButton( bool toggle )
-   */
-  void SetToggleButton( bool toggle );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::IsToggleButton() const
-   */
-  bool IsToggleButton() const;
+protected:
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetToggled( bool toggle )
-   */
-  void SetToggled( bool toggle );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::IsToggled() const
-   */
-  bool IsToggled() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
-   */
-  void SetButtonImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
-   */
-  void SetButtonImage( Actor image );
-
-  /**
-   * Used by the painter only.
-   * @return A reference to the button image.
-   */
-  Actor& GetButtonImage();
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::
-   */
-  Actor GetButtonImage() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
-   */
-  void SetBackgroundImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
-   */
-  void SetBackgroundImage( Actor image );
-
-  /**
-   * Used by the painter only.
-   * @return A reference to the background image.
-   */
-  Actor& GetBackgroundImage();
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
-   */
-  Actor GetBackgroundImage() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetPressedImage( const Image image )
-   */
-  void SetPressedImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetPressedImage( Actor image )
-   */
-  void SetPressedImage( Actor image );
-
-  /**
-   * Used by the painter only.
-   * @return A reference to the pressed image.
-   */
-  Actor& GetPressedImage();
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::GetPressedImage()
-   */
-  Actor GetPressedImage() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Image image )
-   */
-  void SetDimmedBackgroundImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Actor image )
-   */
-  void SetDimmedBackgroundImage( Actor image );
-
-  /**
-   * Used by the painter only.
-   * @return A reference to the dimmed background image.
-   */
-  Actor& GetDimmedBackgroundImage();
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::GetDimmedBackgroundImage()
-   */
-  Actor GetDimmedBackgroundImage() const;
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Image image )
-   */
-  void SetDimmedImage( Image image );
-
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Actor image )
-   */
-  void SetDimmedImage( Actor image );
-
-  /**
-   * Used by the painter only.
-   * @return A reference to the dimmed button image.
+   * Construct a new PushButton.
    */
    */
-  Actor& GetDimmedImage();
+  PushButton();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::GetDimmedImage()
+   * A reference counted object may only be deleted by calling Unreference()
    */
    */
-  Actor GetDimmedImage() const;
+  virtual ~PushButton();
 
 
-  /**
-   * @copydoc Dali::Toolkit::PushButton::SetLabelText( const std::string& text )
-   */
-  void SetLabelText( const std::string& text );
+private: // From Button
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::SetLabelText( Actor text )
+   * @copydoc Toolkit::Internal::Button::OnButtonInitialize()
    */
    */
-  void SetLabelText( Actor text );
+  virtual void OnButtonInitialize();
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the label actor.
+   * @copydoc Toolkit::Internal::Button::OnLabelSet()
    */
    */
-  Actor& GetLabel();
+  virtual void OnLabelSet();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::GetLabelText()
+   * @copydoc Toolkit::Internal::Button::OnButtonImageSet()
    */
    */
-  Actor GetLabelText() const;
+  virtual void OnButtonImageSet();
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the background image that is fading out.
+   * @copydoc Toolkit::Internal::Button::OnSelectedImageSet()
    */
    */
-  Actor& GetFadeOutBackgroundImage();
+  virtual void OnSelectedImageSet();
 
   /**
 
   /**
-   * Used by the painter only.
-   * @return A reference to the button image that is fading out.
+   * @copydoc Toolkit::Internal::Button::OnBackgroundImage()
    */
    */
-  Actor& GetFadeOutButtonImage();
-
-public: // Signals
+  virtual void OnBackgroundImageSet();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::ToggledSignal()
+   * @copydoc Toolkit::Internal::Button::OnSelectedBackgroundImageSet()
    */
    */
-  Toolkit::PushButton::ToggledSignalV2& ToggledSignal();
+  virtual void OnSelectedBackgroundImageSet();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::PressedSignal()
+   * @copydoc Toolkit::Internal::Button::OnDisabledImageSet()
    */
    */
-  Toolkit::PushButton::PressedSignalV2& PressedSignal();
+  virtual void OnDisabledImageSet();
 
   /**
 
   /**
-   * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
+   * @copydoc Toolkit::Internal::Button::OnDisabledSelectedImageSet()
    */
    */
-  Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
+  virtual void OnDisabledSelectedImageSet();
 
   /**
 
   /**
-   * Connects a callback function with the object's signals.
-   * @param[in] object The object providing the signal.
-   * @param[in] tracker Used to disconnect the signal.
-   * @param[in] signalName The signal to connect to.
-   * @param[in] functor A newly allocated FunctorDelegate.
-   * @return True if the signal was connected.
-   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
+   * @copydoc Toolkit::Internal::Button::OnDisabledBackgroundImageSet()
    */
    */
-  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
-
-protected: // From Button
+  virtual void OnDisabledBackgroundImageSet();
 
   /**
 
   /**
-   * Sets the Leave signal.
+   * @copydoc Toolkit::Internal::Button::PrepareForTranstionIn( Actor actor )
    */
    */
-  virtual void OnButtonInitialize();
+  virtual void PrepareForTranstionIn( Actor actor );
 
   /**
 
   /**
-   * Emits signals and notifies the painter accordingly with the set button
-   * properties when the button is pressed.
+   * @copydoc Toolkit::Internal::Button::PrepareForTranstionOut( Actor actor )
    */
    */
-  virtual void OnButtonDown();
+  virtual void PrepareForTranstionOut( Actor actor );
 
   /**
 
   /**
-   * Emits signals and notifies the painter accordingly with the set button
-   * properties when the button is released.
+   * @copydoc Toolkit::Internal::Button::OnTransitionIn( Actor actor )
    */
    */
-  virtual void OnButtonUp();
+  virtual void OnTransitionIn( Actor actor );
 
   /**
 
   /**
-   * Emits signals and notifies the painter accordingly with the set button
-   * properties when the touch point leaves the boundary of the button.
+   * @copydoc Toolkit::Internal::Button::OnTransitionOut( Actor actor )
    */
    */
-  virtual void OnTouchPointLeave();
+  virtual void OnTransitionOut( Actor actor );
 
 
-  /**
-   * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
-   */
-  virtual void OnTouchPointInterrupted();
+private: // From Control
 
   /**
 
   /**
-   * Sets the push button animation time.
-   * @param animationTime The animation time in seconds.
+   * @copydoc CustomActorImpl::OnSizeSet( const Vector3& targetSize )
    */
    */
-  virtual void OnAnimationTimeSet( float animationTime );
+  virtual void OnSizeSet( const Vector3& targetSize );
 
   /**
 
   /**
-   * Retrieves the animation time.
-   * @return The animation time in seconds.
+   * @copydoc Toolkit::Control::GetNaturalSize
    */
    */
-  virtual float OnAnimationTimeRequested() const;
-
-protected: // From ControlImpl
+  virtual Vector3 GetNaturalSize();
 
   /**
 
   /**
-   * Respond the activate notification.
+   * @copydoc Toolkit::Control::OnSetResizePolicy
    */
    */
-  virtual void OnActivated();
+  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
 
 private:
 
   /**
 
 private:
 
   /**
-   * Perform the click action to click the button.
-   * @param[in] attributes The attributes to perfrom this action.
+   * It adds the actor to the root actor and to the fade in animation.
+   * @param[inout] actor The actor.
+   * @param[in] opacity The opacity to fade to
    */
    */
-  void DoClickAction(const PropertyValueContainer& attributes);
-
-public:
+  void FadeImageTo( Actor actor, float opacity );
 
   /**
 
   /**
-   * 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
+   * @brief Custom configuration for size negotiation
    */
    */
-  static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
+  void ConfigureSizeNegotiation();
 
   /**
 
   /**
-   * Construct a new PushButton.
+   * @brief Configure size negotiation for a given dimension
+   *
+   * @param[in] dimension The dimension to configure
+   * @param[in] images The list of images to configure
+   * @param[in] label The text label to configure
    */
    */
-  PushButton();
-
-  /**
-   * A reference counted object may only be deleted by calling Unreference()
-   */
-  virtual ~PushButton();
+  void ConfigureSizeNegotiationDimension( Dimension::Type dimension, const std::vector< Actor >& images, Actor& label );
 
 private:
 
 
 private:
 
@@ -350,47 +176,9 @@ private:
   // Undefined
   PushButton& operator=( const PushButton& );
 
   // Undefined
   PushButton& operator=( const PushButton& );
 
-  /**
-   * Sets up the autorepeating timer.
-   * @param[in] delay The delay time in seconds.
-   */
-  void SetUpTimer( float delay );
-
-  /**
-   * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
-   */
-  bool AutoRepeatingSlot();
-
 private:
 private:
-  bool  mAutoRepeating;             ///< Stores the autorepeating property.
-  float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
-  float mNextAutoRepeatingDelay;    ///< Stores the next autorepeating delay in seconds.
-  bool  mToggleButton;              ///< Stores the toggle property.
-
-  // AutoRepeating
-  Timer mAutoRepeatingTimer;        ///< Timer used to implement the autorepeating property.
-
-  // Toggle
-  bool  mToggled;                   ///< Stores the toggle state.
-
-  // Signals
-  Toolkit::PushButton::ToggledSignalV2 mToggledSignalV2;   ///< Signal emitted when the button is toggled.
-  Toolkit::PushButton::PressedSignalV2 mPressedSignalV2;   ///< Signal emitted when the button is pressed.
-  Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
-
-  Actor mButtonImage;               ///< Stores the released image.
-  Actor mBackgroundImage;           ///< Stores the background image.
-  Actor mPressedImage;              ///< Stores the pressed image.
-  Actor mDimmedImage;               ///< Stores the dimmed image.
-  Actor mDimmedBackgroundImage;     ///< Stores the dimmed background image.
-
-  Actor mLabel;                     ///< Stores the text label.
-
-  Actor mFadeOutBackgroundImage;    ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
-  Actor mFadeOutButtonImage;        ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
 
 
-  // Actions
-  bool mClickActionPerforming;
+  Vector3               mSize;                      ///< The button's size.
 };
 
 } // namespace Internal
 };
 
 } // namespace Internal