1 #ifndef __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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.
21 #include <dali/public-api/common/dali-vector.h>
23 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
25 #include "button-impl.h"
37 * PushButton implementation class.
39 * \sa Dali::Toolkit::PushButton
41 class PushButton : public Button
46 * Create a new PushButton.
47 * @return A smart-pointer to the newly allocated PushButton.
49 static Dali::Toolkit::PushButton New();
52 * @copydoc Dali::Toolkit::PushButton::SetAutoRepeating( bool autoRepeating )
54 void SetAutoRepeating( bool autoRepeating );
57 * @copydoc Dali::Toolkit::PushButton::IsAutoRepeating() const
59 bool IsAutoRepeating() const;
62 * @copydoc Dali::Toolkit::PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
64 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
67 * @copydoc Dali::Toolkit::PushButton::GetInitialAutoRepeatingDelay() const
69 float GetInitialAutoRepeatingDelay() const;
72 * @copydoc Dali::Toolkit::PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
74 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
77 * @copydoc Dali::Toolkit::PushButton::GetNextAutoRepeatingDelay() const
79 float GetNextAutoRepeatingDelay() const;
82 * @copydoc Dali::Toolkit::PushButton::SetToggleButton( bool toggle )
84 void SetToggleButton( bool toggle );
87 * @copydoc Dali::Toolkit::PushButton::IsToggleButton() const
89 bool IsToggleButton() const;
92 * @copydoc Dali::Toolkit::PushButton::SetToggled( bool toggle )
94 void SetToggled( bool toggle );
97 * @copydoc Dali::Toolkit::PushButton::IsToggled() const
99 bool IsToggled() const;
102 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
104 void SetButtonImage( Image image );
107 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
109 void SetButtonImage( Actor image );
112 * Used by the painter only.
113 * @return A reference to the button image.
115 Actor& GetButtonImage();
118 * @copydoc Dali::Toolkit::PushButton::
120 Actor GetButtonImage() const;
123 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
125 void SetBackgroundImage( Image image );
128 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
130 void SetBackgroundImage( Actor image );
133 * Used by the painter only.
134 * @return A reference to the background image.
136 Actor& GetBackgroundImage();
139 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
141 Actor GetBackgroundImage() const;
144 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( const Image image )
146 void SetPressedImage( Image image );
149 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( Actor image )
151 void SetPressedImage( Actor image );
154 * Used by the painter only.
155 * @return A reference to the pressed image.
157 Actor& GetPressedImage();
160 * @copydoc Dali::Toolkit::PushButton::GetPressedImage()
162 Actor GetPressedImage() const;
165 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Image image )
167 void SetDimmedBackgroundImage( Image image );
170 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Actor image )
172 void SetDimmedBackgroundImage( Actor image );
175 * Used by the painter only.
176 * @return A reference to the dimmed background image.
178 Actor& GetDimmedBackgroundImage();
181 * @copydoc Dali::Toolkit::PushButton::GetDimmedBackgroundImage()
183 Actor GetDimmedBackgroundImage() const;
186 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Image image )
188 void SetDimmedImage( Image image );
191 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Actor image )
193 void SetDimmedImage( Actor image );
196 * Used by the painter only.
197 * @return A reference to the dimmed button image.
199 Actor& GetDimmedImage();
202 * @copydoc Dali::Toolkit::PushButton::GetDimmedImage()
204 Actor GetDimmedImage() const;
207 * @copydoc Dali::Toolkit::PushButton::SetLabelText( const std::string& text )
209 void SetLabelText( const std::string& text );
212 * @copydoc Dali::Toolkit::PushButton::SetLabelText( Actor text )
214 void SetLabelText( Actor text );
217 * Used by the painter only.
218 * @return A reference to the label actor.
223 * @copydoc Dali::Toolkit::PushButton::GetLabelText()
225 Actor GetLabelText() const;
228 * Used by the painter only.
229 * @return A reference to the background image that is fading out.
231 Actor& GetFadeOutBackgroundImage();
234 * Used by the painter only.
235 * @return A reference to the button image that is fading out.
237 Actor& GetFadeOutButtonImage();
244 * @copydoc Dali::Toolkit::PushButton::ToggledSignal()
246 Toolkit::PushButton::ToggledSignalV2& ToggledSignal();
249 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
251 Toolkit::PushButton::PressedSignalV2& PressedSignal();
254 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
256 Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
259 * Connects a callback function with the object's signals.
260 * @param[in] object The object providing the signal.
261 * @param[in] tracker Used to disconnect the signal.
262 * @param[in] signalName The signal to connect to.
263 * @param[in] functor A newly allocated FunctorDelegate.
264 * @return True if the signal was connected.
265 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
267 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
272 * @copydoc Button::SetProperty
274 static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
277 * @copydoc Button::GetProperty
279 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
281 protected: // From Button
284 * Sets the Leave signal.
286 virtual void OnButtonInitialize();
289 * Emits signals and notifies the painter accordingly with the set button
290 * properties when the button is pressed.
292 virtual void OnButtonDown();
295 * Emits signals and notifies the painter accordingly with the set button
296 * properties when the button is released.
298 virtual void OnButtonUp();
301 * Emits signals and notifies the painter accordingly with the set button
302 * properties when the touch point leaves the boundary of the button.
304 virtual void OnTouchPointLeave();
307 * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
309 virtual void OnTouchPointInterrupted();
312 * Sets the push button animation time.
313 * @param animationTime The animation time in seconds.
315 virtual void OnAnimationTimeSet( float animationTime );
318 * Retrieves the animation time.
319 * @return The animation time in seconds.
321 virtual float OnAnimationTimeRequested() const;
323 protected: // From ControlImpl
326 * Respond the activate notification.
328 virtual void OnActivated();
333 * Perform the click action to click the button.
334 * @param[in] attributes The attributes to perfrom this action.
336 void DoClickAction(const PropertyValueContainer& attributes);
341 * Performs actions as requested using the action name.
342 * @param[in] object The object on which to perform the action.
343 * @param[in] actionName The action to perform.
344 * @param[in] attributes The attributes with which to perfrom this action.
345 * @return true if action has been accepted by this control
347 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
350 * Construct a new PushButton.
355 * A reference counted object may only be deleted by calling Unreference()
357 virtual ~PushButton();
362 PushButton( const PushButton& );
365 PushButton& operator=( const PushButton& );
368 * Sets up the autorepeating timer.
369 * @param[in] delay The delay time in seconds.
371 void SetUpTimer( float delay );
374 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
376 bool AutoRepeatingSlot();
379 bool mAutoRepeating; ///< Stores the autorepeating property.
380 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
381 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
382 bool mToggleButton; ///< Stores the toggle property.
385 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
388 bool mToggled; ///< Stores the toggle state.
391 Toolkit::PushButton::ToggledSignalV2 mToggledSignalV2; ///< Signal emitted when the button is toggled.
392 Toolkit::PushButton::PressedSignalV2 mPressedSignalV2; ///< Signal emitted when the button is pressed.
393 Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
395 Actor mButtonImage; ///< Stores the released image.
396 Actor mBackgroundImage; ///< Stores the background image.
397 Actor mPressedImage; ///< Stores the pressed image.
398 Actor mDimmedImage; ///< Stores the dimmed image.
399 Actor mDimmedBackgroundImage; ///< Stores the dimmed background image.
401 Actor mLabel; ///< Stores the text label.
403 Actor mFadeOutBackgroundImage; ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
404 Actor mFadeOutButtonImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
407 bool mClickActionPerforming;
410 } // namespace Internal
412 // Helpers for public-api forwarding methods
414 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
416 DALI_ASSERT_ALWAYS( button );
418 Dali::RefObject& handle = button.GetImplementation();
420 return static_cast<Toolkit::Internal::PushButton&>( handle );
423 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
425 DALI_ASSERT_ALWAYS( button );
427 const Dali::RefObject& handle = button.GetImplementation();
429 return static_cast<const Toolkit::Internal::PushButton&>( handle );
432 } // namespace Toolkit
436 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__