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();
242 * @copydoc Dali::Toolkit::PushButton::ToggledSignal()
244 Toolkit::PushButton::ToggledSignalV2& ToggledSignal();
247 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
249 Toolkit::PushButton::PressedSignalV2& PressedSignal();
252 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
254 Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
257 * Connects a callback function with the object's signals.
258 * @param[in] object The object providing the signal.
259 * @param[in] tracker Used to disconnect the signal.
260 * @param[in] signalName The signal to connect to.
261 * @param[in] functor A newly allocated FunctorDelegate.
262 * @return True if the signal was connected.
263 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
265 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
267 protected: // From Button
270 * Sets the Leave signal.
272 virtual void OnButtonInitialize();
275 * Emits signals and notifies the painter accordingly with the set button
276 * properties when the button is pressed.
278 virtual void OnButtonDown();
281 * Emits signals and notifies the painter accordingly with the set button
282 * properties when the button is released.
284 virtual void OnButtonUp();
287 * Emits signals and notifies the painter accordingly with the set button
288 * properties when the touch point leaves the boundary of the button.
290 virtual void OnTouchPointLeave();
293 * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
295 virtual void OnTouchPointInterrupted();
298 * Sets the push button animation time.
299 * @param animationTime The animation time in seconds.
301 virtual void OnAnimationTimeSet( float animationTime );
304 * Retrieves the animation time.
305 * @return The animation time in seconds.
307 virtual float OnAnimationTimeRequested() const;
309 protected: // From ControlImpl
312 * Respond the activate notification.
314 virtual void OnActivated();
319 * Perform the click action to click the button.
320 * @param[in] attributes The attributes to perfrom this action.
322 void DoClickAction(const PropertyValueContainer& attributes);
327 * Performs actions as requested using the action name.
328 * @param[in] object The object on which to perform the action.
329 * @param[in] actionName The action to perform.
330 * @param[in] attributes The attributes with which to perfrom this action.
331 * @return true if action has been accepted by this control
333 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
336 * Construct a new PushButton.
341 * A reference counted object may only be deleted by calling Unreference()
343 virtual ~PushButton();
348 PushButton( const PushButton& );
351 PushButton& operator=( const PushButton& );
354 * Sets up the autorepeating timer.
355 * @param[in] delay The delay time in seconds.
357 void SetUpTimer( float delay );
360 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
362 bool AutoRepeatingSlot();
365 bool mAutoRepeating; ///< Stores the autorepeating property.
366 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
367 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
368 bool mToggleButton; ///< Stores the toggle property.
371 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
374 bool mToggled; ///< Stores the toggle state.
377 Toolkit::PushButton::ToggledSignalV2 mToggledSignalV2; ///< Signal emitted when the button is toggled.
378 Toolkit::PushButton::PressedSignalV2 mPressedSignalV2; ///< Signal emitted when the button is pressed.
379 Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
381 Actor mButtonImage; ///< Stores the released image.
382 Actor mBackgroundImage; ///< Stores the background image.
383 Actor mPressedImage; ///< Stores the pressed image.
384 Actor mDimmedImage; ///< Stores the dimmed image.
385 Actor mDimmedBackgroundImage; ///< Stores the dimmed background image.
387 Actor mLabel; ///< Stores the text label.
389 Actor mFadeOutBackgroundImage; ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
390 Actor mFadeOutButtonImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
393 bool mClickActionPerforming;
396 } // namespace Internal
398 // Helpers for public-api forwarding methods
400 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
402 DALI_ASSERT_ALWAYS( button );
404 Dali::RefObject& handle = button.GetImplementation();
406 return static_cast<Toolkit::Internal::PushButton&>( handle );
409 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
411 DALI_ASSERT_ALWAYS( button );
413 const Dali::RefObject& handle = button.GetImplementation();
415 return static_cast<const Toolkit::Internal::PushButton&>( handle );
418 } // namespace Toolkit
422 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__