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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <dali/public-api/common/dali-vector.h>
24 #include <dali-toolkit/public-api/controls/buttons/push-button.h>
26 #include "button-impl.h"
38 * PushButton implementation class.
40 * \sa Dali::Toolkit::PushButton
42 class PushButton : public Button
47 * Create a new PushButton.
48 * @return A smart-pointer to the newly allocated PushButton.
50 static Dali::Toolkit::PushButton New();
53 * @copydoc Dali::Toolkit::PushButton::SetAutoRepeating( bool autoRepeating )
55 void SetAutoRepeating( bool autoRepeating );
58 * @copydoc Dali::Toolkit::PushButton::IsAutoRepeating() const
60 bool IsAutoRepeating() const;
63 * @copydoc Dali::Toolkit::PushButton::SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay )
65 void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
68 * @copydoc Dali::Toolkit::PushButton::GetInitialAutoRepeatingDelay() const
70 float GetInitialAutoRepeatingDelay() const;
73 * @copydoc Dali::Toolkit::PushButton::SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay )
75 void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
78 * @copydoc Dali::Toolkit::PushButton::GetNextAutoRepeatingDelay() const
80 float GetNextAutoRepeatingDelay() const;
83 * @copydoc Dali::Toolkit::PushButton::SetToggleButton( bool toggle )
85 void SetToggleButton( bool toggle );
88 * @copydoc Dali::Toolkit::PushButton::IsToggleButton() const
90 bool IsToggleButton() const;
93 * @copydoc Dali::Toolkit::PushButton::SetToggled( bool toggle )
95 void SetToggled( bool toggle );
98 * @copydoc Dali::Toolkit::PushButton::IsToggled() const
100 bool IsToggled() const;
103 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( const Image image )
105 void SetButtonImage( Image image );
108 * @copydoc Dali::Toolkit::PushButton::SetButtonImage( Actor image )
110 void SetButtonImage( Actor image );
113 * Used by the painter only.
114 * @return A reference to the button image.
116 Actor& GetButtonImage();
119 * @copydoc Dali::Toolkit::PushButton::
121 Actor GetButtonImage() const;
124 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( const Image image )
126 void SetBackgroundImage( Image image );
129 * @copydoc Dali::Toolkit::PushButton::SetBackgroundImage( Actor image )
131 void SetBackgroundImage( Actor image );
134 * Used by the painter only.
135 * @return A reference to the background image.
137 Actor& GetBackgroundImage();
140 * @copydoc Dali::Toolkit::PushButton::GetBackgroundImage()
142 Actor GetBackgroundImage() const;
145 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( const Image image )
147 void SetPressedImage( Image image );
150 * @copydoc Dali::Toolkit::PushButton::SetPressedImage( Actor image )
152 void SetPressedImage( Actor image );
155 * Used by the painter only.
156 * @return A reference to the pressed image.
158 Actor& GetPressedImage();
161 * @copydoc Dali::Toolkit::PushButton::GetPressedImage()
163 Actor GetPressedImage() const;
166 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Image image )
168 void SetDimmedBackgroundImage( Image image );
171 * @copydoc Dali::Toolkit::PushButton::SetDimmedBackgroundImage( Actor image )
173 void SetDimmedBackgroundImage( Actor image );
176 * Used by the painter only.
177 * @return A reference to the dimmed background image.
179 Actor& GetDimmedBackgroundImage();
182 * @copydoc Dali::Toolkit::PushButton::GetDimmedBackgroundImage()
184 Actor GetDimmedBackgroundImage() const;
187 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Image image )
189 void SetDimmedImage( Image image );
192 * @copydoc Dali::Toolkit::PushButton::SetDimmedImage( Actor image )
194 void SetDimmedImage( Actor image );
197 * Used by the painter only.
198 * @return A reference to the dimmed button image.
200 Actor& GetDimmedImage();
203 * @copydoc Dali::Toolkit::PushButton::GetDimmedImage()
205 Actor GetDimmedImage() const;
208 * @copydoc Dali::Toolkit::PushButton::SetLabelText( const std::string& text )
210 void SetLabelText( const std::string& text );
213 * @copydoc Dali::Toolkit::PushButton::SetLabelText( Actor text )
215 void SetLabelText( Actor text );
218 * Used by the painter only.
219 * @return A reference to the label actor.
224 * @copydoc Dali::Toolkit::PushButton::GetLabelText()
226 Actor GetLabelText() const;
229 * Used by the painter only.
230 * @return A reference to the background image that is fading out.
232 Actor& GetFadeOutBackgroundImage();
235 * Used by the painter only.
236 * @return A reference to the button image that is fading out.
238 Actor& GetFadeOutButtonImage();
245 * @copydoc Dali::Toolkit::PushButton::ToggledSignal()
247 Toolkit::PushButton::ToggledSignalV2& ToggledSignal();
250 * @copydoc Dali::Toolkit::PushButton::PressedSignal()
252 Toolkit::PushButton::PressedSignalV2& PressedSignal();
255 * @copydoc Dali::Toolkit::PushButton::ReleasedSignal()
257 Toolkit::PushButton::ReleasedSignalV2& ReleasedSignal();
260 * Connects a callback function with the object's signals.
261 * @param[in] object The object providing the signal.
262 * @param[in] tracker Used to disconnect the signal.
263 * @param[in] signalName The signal to connect to.
264 * @param[in] functor A newly allocated FunctorDelegate.
265 * @return True if the signal was connected.
266 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
268 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
273 * @copydoc Button::SetProperty
275 static void SetProperty( BaseObject* object, Property::Index propertyIndex, const Property::Value& value );
278 * @copydoc Button::GetProperty
280 static Property::Value GetProperty( BaseObject* object, Property::Index propertyIndex );
282 protected: // From Button
285 * Sets the Leave signal.
287 virtual void OnButtonInitialize();
290 * Emits signals and notifies the painter accordingly with the set button
291 * properties when the button is pressed.
293 virtual void OnButtonDown();
296 * Emits signals and notifies the painter accordingly with the set button
297 * properties when the button is released.
299 virtual void OnButtonUp();
302 * Emits signals and notifies the painter accordingly with the set button
303 * properties when the touch point leaves the boundary of the button.
305 virtual void OnTouchPointLeave();
308 * Currently it doesn't need different behaviour than @see OnTouchPointLeave()
310 virtual void OnTouchPointInterrupted();
313 * Sets the push button animation time.
314 * @param animationTime The animation time in seconds.
316 virtual void OnAnimationTimeSet( float animationTime );
319 * Retrieves the animation time.
320 * @return The animation time in seconds.
322 virtual float OnAnimationTimeRequested() const;
325 * This method is called when the button is removed from the stage.
327 virtual void OnButtonStageDisconnection();
329 protected: // From Control
332 * Respond the activate notification.
334 virtual void OnActivated();
337 * @copydoc Control::GetNaturalSize()
339 virtual Vector3 GetNaturalSize();
344 * Perform the click action to click the button.
345 * @param[in] attributes The attributes to perfrom this action.
347 void DoClickAction(const PropertyValueContainer& attributes);
352 * Performs actions as requested using the action name.
353 * @param[in] object The object on which to perform the action.
354 * @param[in] actionName The action to perform.
355 * @param[in] attributes The attributes with which to perfrom this action.
356 * @return true if action has been accepted by this control
358 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
361 * Construct a new PushButton.
366 * A reference counted object may only be deleted by calling Unreference()
368 virtual ~PushButton();
373 PushButton( const PushButton& );
376 PushButton& operator=( const PushButton& );
379 * Sets up the autorepeating timer.
380 * @param[in] delay The delay time in seconds.
382 void SetUpTimer( float delay );
385 * Slot called when Dali::Timer::SignalTick signal. Resets the autorepeating timer.
387 bool AutoRepeatingSlot();
390 bool mAutoRepeating; ///< Stores the autorepeating property.
391 float mInitialAutoRepeatingDelay; ///< Stores the initial autorepeating delay in seconds.
392 float mNextAutoRepeatingDelay; ///< Stores the next autorepeating delay in seconds.
393 bool mToggleButton; ///< Stores the toggle property.
396 Timer mAutoRepeatingTimer; ///< Timer used to implement the autorepeating property.
399 bool mToggled; ///< Stores the toggle state.
402 Toolkit::PushButton::ToggledSignalV2 mToggledSignalV2; ///< Signal emitted when the button is toggled.
403 Toolkit::PushButton::PressedSignalV2 mPressedSignalV2; ///< Signal emitted when the button is pressed.
404 Toolkit::PushButton::ReleasedSignalV2 mReleasedSignalV2; ///< Signal emitted when the button is released.
406 Actor mButtonImage; ///< Stores the released image.
407 Actor mBackgroundImage; ///< Stores the background image.
408 Actor mPressedImage; ///< Stores the pressed image.
409 Actor mDimmedImage; ///< Stores the dimmed image.
410 Actor mDimmedBackgroundImage; ///< Stores the dimmed background image.
412 Actor mLabel; ///< Stores the text label.
414 Actor mFadeOutBackgroundImage; ///< Stores a background image, which is in a fade out animation, to be removed when the animation finishes.
415 Actor mFadeOutButtonImage; ///< Stores a foreground image, which is in a fade out animation, to be removed when the animation finishes.
418 bool mClickActionPerforming;
421 } // namespace Internal
423 // Helpers for public-api forwarding methods
425 inline Toolkit::Internal::PushButton& GetImplementation( Toolkit::PushButton& button )
427 DALI_ASSERT_ALWAYS( button );
429 Dali::RefObject& handle = button.GetImplementation();
431 return static_cast<Toolkit::Internal::PushButton&>( handle );
434 inline const Toolkit::Internal::PushButton& GetImplementation( const Toolkit::PushButton& button )
436 DALI_ASSERT_ALWAYS( button );
438 const Dali::RefObject& handle = button.GetImplementation();
440 return static_cast<const Toolkit::Internal::PushButton&>( handle );
443 } // namespace Toolkit
447 #endif // __DALI_TOOLKIT_INTERNAL_PUSH_BUTTON_H__