30bad261b7ebb046027dd3bd621767cc1a6bd264
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / buttons / push-button.h
1 #ifndef __DALI_TOOLKIT_PUSH_BUTTON_H__
2 #define __DALI_TOOLKIT_PUSH_BUTTON_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 /**
22  * @addtogroup CAPI_DALI_TOOLKIT_BUTTONS_MODULE
23  * @{
24  */
25
26 // INTERNAL INCLUDES
27 #include "button.h"
28
29 namespace Dali DALI_IMPORT_API
30 {
31
32 namespace Toolkit
33 {
34
35 // Forward declarations
36
37 namespace Internal DALI_INTERNAL
38 {
39 // Forward declarations
40
41 class PushButton;
42 }
43
44 /**
45  * @brief A PushButton changes its appearance when is pressed and returns to its original when is released.
46  *
47  * By default a PushButton emits a PushButton::PressedSignal() signal when the button is pressed, a Button::ClickedSignal() signal when it's clicked
48  * and a PushButton::ReleasedSignal() signal when it's released or having pressed it, the touch point leaves the boundary of the button.
49  *
50  * PushButton provides the following properties which modify signals emitted:
51  * <ul>
52  *   <li>\e autorepeating
53  *
54  *       When \e autorepeating is set to \e true, a PushButton::PressedSignal(), PushButton::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
55  *       intervals while the button is touched.
56  *
57  *       The intervals could be modified with the PushButton::SetInitialAutoRepeatingDelay and PushButton::SetNextAutoRepeatingDelay methods.
58  *
59  *       A \e toggle button can't be \e autorepeating. If the \e autorepeating property is set to \e true, then the \e toggle property is set to
60  *       false but no signal is emitted.
61  *
62  *   <li>\e toggle
63  *
64  *       When \e toggle is set to \e true, a PushButton::ToggledSignal() signal is emitted, with the toggle state, every time the button is touched instead
65  *       of emit PushButton::PressedSignal(), Button::ClickedSignal() and PushButton::ReleasedSignal() signals.
66  *
67  *       An \e autorepeating button can't be \e toggle. If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
68  * </ul>
69  *
70  * The button's appearance could be modified by setting images or actors with PushButton::SetButtonImage, PushButton::SetBackgroundImage,
71  * PushButton::SetPressedImage, PushButton::SetDimmedBackgroundImage and  PushButton::SetDimmedImage or setting a text with
72  * PushButton::SetLabelText.
73  *
74  * The \e background is always shown and doesn't change if the button is pressed or released. The \e button image is shown over the \e background image when the
75  * button is not pressed and is replaced by the \e pressed image when the button is pressed. The text label is placed always on the top of all images.
76  *
77  * When the button is dimmed, \e background, \e button and \e pressed images are replaced by their \e dimmed images.
78  *
79  * The methods used to modify the button's appearance could receive Dali::Actor objects as a parameter, so more complex images could be defined.
80  *
81  * Is not mandatory set all images. A button could be defined only by setting its \e background image or by setting its \e background and \e pressed images.
82  */
83 class PushButton : public Button
84 {
85 public:
86
87   //Signal Names
88   static const char* const SIGNAL_TOGGLED; ///< name "toggled"
89   static const char* const SIGNAL_PRESSED; ///< name "pressed"
90   static const char* const SIGNAL_RELEASED; ///< name "released"
91
92   //Action Names
93   static const char* const ACTION_PUSH_BUTTON_CLICK; ///< name "push-button-click"
94
95   // Properties
96   static const Property::Index PROPERTY_AUTO_REPEATING;               ///< name "auto-repeating",               @see SetAutoRepeating(),             type BOOLEAN
97   static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
98   static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY;    ///< name "next-auto-repeating-delay",    @see SetNextAutoRepeatingDelay(),    type FLOAT
99   static const Property::Index PROPERTY_TOGGLABLE;                    ///< name "togglable",                    @see SetToggleButton(),              type BOOLEAN
100   static const Property::Index PROPERTY_TOGGLE;                       ///< name "toggle",                       @see SetToggled(),                   type BOOLEAN
101   static const Property::Index PROPERTY_NORMAL_STATE_ACTOR;           ///< name "button-state-actor",           @see SetButtonImage(),               type MAP
102   static const Property::Index PROPERTY_PRESSED_STATE_ACTOR;          ///< name "pressed-state-actor",          @see SetPressedImage(),              type MAP
103   static const Property::Index PROPERTY_DIMMED_STATE_ACTOR;           ///< name "dimmed-state-actor",           @see SetDimmedImage(),               type MAP
104   static const Property::Index PROPERTY_LABEL_ACTOR;                  ///< name "label-actor",                  @see SetLabelText(),                 type STRING
105
106 public:
107
108   /**
109    * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
110    *
111    * Calling member functions with an uninitialized Dali::Object is not allowed.
112    */
113   PushButton();
114
115   /**
116    * @brief Copy constructor.
117    */
118   PushButton( const PushButton& pushButton );
119
120   /**
121    * @brief Assignment operator.
122    */
123   PushButton& operator=( const PushButton& pushButton );
124
125   /**
126    * @brief Destructor
127    *
128    * This is non-virtual since derived Handle types must not contain data or virtual methods.
129    */
130   ~PushButton();
131
132   /**
133    * @brief Create an initialized PushButton.
134    *
135    * @return A handle to a newly allocated Dali resource.
136    */
137   static PushButton New();
138
139   /**
140    * @brief Downcast an Object handle to PushButton.
141    *
142    * If handle points to a PushButton the downcast produces valid
143    * handle. If not the returned handle is left uninitialized.
144    *
145    * @param[in] handle Handle to an object
146    * @return handle to a PushButton or an uninitialized handle
147    */
148   static PushButton DownCast( BaseHandle handle );
149
150   /**
151    * @brief Sets the \e autorepeating property.
152    *
153    * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
154    * but no signal is emitted.
155    *
156    * @param[in] autoRepeating \e autorepeating property.
157    */
158   void SetAutoRepeating( bool autoRepeating );
159
160   /**
161    * @return \e true if the \e autorepeating property is set.
162    */
163   bool IsAutoRepeating() const;
164
165   /**
166    * @brief Sets the initial autorepeating delay.
167    *
168    * By default this value is set to 0.15 seconds.
169    *
170    * @pre initialAutoRepeatingDelay must be greater than zero.
171    * @param[in] initialAutoRepeatingDelay in seconds.
172    */
173   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
174
175   /**
176    * @return the initial autorepeating delay in seconds.
177    */
178   float GetInitialAutoRepeatingDelay() const;
179
180   /**
181    * @brief Sets the next autorepeating delay.
182    *
183    * By default this value is set to 0.05 seconds.
184    *
185    * @pre nextAutoRepeatingDelay must be greater than zero.
186    * @param[in] nextAutoRepeatingDelay in seconds.
187    */
188   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
189
190   /**
191    * @return the next autorepeating delay in seconds.
192    */
193   float GetNextAutoRepeatingDelay() const;
194
195   /**
196    * @brief Sets the \e toggle property.
197    *
198    * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
199    *
200    * @param[in] toggle property.
201    */
202   void SetToggleButton( bool toggle );
203
204   /**
205    * @return \e true if the \e toggle property is set.
206    */
207   bool IsToggleButton() const;
208
209   /**
210    * @brief Sets the button as toggled or not toggled.
211    *
212    * \e toggle property must be set to \e true.
213    *
214    * Emits a PushButton::ToggledSignal() signal.
215    *
216    * @param[in] toggle state.
217    */
218   void SetToggled( bool toggle );
219
220   /**
221    * @return \e true if the \e toggle property is set and the button is toggled.
222    */
223   bool IsToggled() const;
224
225   /**
226    * @brief Sets the button image.
227    *
228    * @param[in] image The button image.
229    */
230   void SetButtonImage( Image image );
231
232   /**
233    * @copydoc SetButtonImage( Image image )
234    */
235   void SetButtonImage( Actor image );
236
237   /**
238    * @brief Gets the button image.
239    *
240    * @return An actor with the button image.
241    */
242   Actor GetButtonImage() const;
243
244   /**
245    * @brief Sets the background image.
246    *
247    * @param[in] image The background image.
248    */
249   void SetBackgroundImage( Image image );
250
251   /**
252    * @copydoc SetBackgroundImage( Image image )
253    */
254   void SetBackgroundImage( Actor image );
255
256   /**
257    * @brief Gets the background image.
258    *
259    * @return An actor with the background image.
260    */
261   Actor GetBackgroundImage() const;
262
263   /**
264    * @brief Sets the pressed image.
265    *
266    * @param[in] image The pressed image.
267    */
268   void SetPressedImage( Image image );
269
270   /**
271    * @copydoc SetPressedImage( Image image )
272    */
273   void SetPressedImage( Actor image );
274
275   /**
276    * @brief Gets the pressed image.
277    *
278    * @return An actor with the pressed image.
279    */
280   Actor GetPressedImage() const;
281
282   /**
283    * @brief Sets the dimmed background image.
284    *
285    * @param[in] image The dimmed background image.
286    */
287   void SetDimmedBackgroundImage( Image image );
288
289   /**
290    * @copydoc SetDimmedBackgroundImage( Image image )
291    */
292   void SetDimmedBackgroundImage( Actor image );
293
294   /**
295    * @brief Gets the dimmed background image.
296    *
297    * @return An actor with the dimmed background image.
298    */
299   Actor GetDimmedBackgroundImage() const;
300
301   /**
302    * @brief Sets the dimmed button image.
303    *
304    * @param[in] image The dimmed button image.
305    */
306   void SetDimmedImage( Image image );
307
308   /**
309    * @copydoc SetDimmedImage( Image image )
310    */
311   void SetDimmedImage( Actor image );
312
313   /**
314    * @brief Gets the dimmed image.
315    *
316    * @return An actor with the dimmed image.
317    */
318   Actor GetDimmedImage() const;
319
320   /**
321    * @brief Sets the text label.
322    *
323    * @param[in] text Label text.
324    */
325   void SetLabelText( const std::string& text );
326
327   /**
328    * @copydoc SetLabelText( const std::string& text )
329    */
330   void SetLabelText( Actor text );
331
332   /**
333    * @brief Gets the label text.
334    *
335    * @return An actor with the label text.
336    */
337   Actor GetLabelText() const;
338
339 public: //Signals
340
341   /// @brief PushButton Toggled signal type.
342   typedef SignalV2< bool ( Button, bool ) > ToggledSignalV2;
343
344   /// @brief PushButton Pressed signal type.
345   typedef SignalV2< bool ( Button ) > PressedSignalV2;
346
347   /// @brief PushButton Released signal type.
348   typedef SignalV2< bool ( Button ) > ReleasedSignalV2;
349
350   /**
351    * @brief Signal emitted when the \e toggle property is set and the button is touched.
352    */
353   ToggledSignalV2& ToggledSignal();
354
355   /**
356    * @brief Signal emitted when the button is touched.
357    */
358   PressedSignalV2& PressedSignal();
359
360   /**
361    * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
362    */
363   ReleasedSignalV2& ReleasedSignal();
364
365 public: // Not intended for application developers
366
367   /**
368    * @brief Creates a handle using the Toolkit::Internal implementation.
369    *
370    * @param[in]  implementation  The Control implementation.
371    */
372   PushButton( Internal::PushButton& implementation );
373
374   /**
375    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
376    *
377    * @param[in]  internal  A pointer to the internal CustomActor.
378    */
379   PushButton( Dali::Internal::CustomActor* internal );
380 };
381
382 } // namespace Toolkit
383
384 } // namespace Dali
385
386 /**
387  * @}
388  */
389 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__