[3.0] (button) Downgrade warning level of setting Label Text APIs to only show with...
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / buttons / button.h
1 #ifndef __DALI_TOOLKIT_BUTTON_H__
2 #define __DALI_TOOLKIT_BUTTON_H__
3
4 /*
5  * Copyright (c) 2015 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 namespace Dali
25 {
26
27 namespace Toolkit
28 {
29
30 namespace Internal DALI_INTERNAL
31 {
32 class Button;
33 }
34 /**
35  * @addtogroup dali_toolkit_controls_buttons
36  * @{
37  */
38
39 /**
40  * @brief Button is a base class for different kind of buttons.
41  *
42  * This class provides the disabled property and the clicked signal.
43  *
44  * A ClickedSignal() is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
45  *
46  * When the \e disabled property is set to \e true, no signal is emitted.
47  *
48  * Button provides the following properties which modify the signals emitted:
49  * <ul>
50  *   <li>\e autorepeating
51  *       When \e autorepeating is set to \e true, a Button::PressedSignal(), Button::ReleasedSignal() and Button::ClickedSignal() signals are emitted at regular
52  *       intervals while the button is touched.
53  *       The intervals could be modified with the Button::SetInitialAutoRepeatingDelay and Button::SetNextAutoRepeatingDelay methods.
54  *
55  *       A \e togglable button can't be \e autorepeating. If the \e autorepeating property is set to \e true, then the \e togglable property is set to
56  *       false but no signal is emitted.
57  *
58  *   <li>\e togglable
59  *       When \e togglable is set to \e true, a Button::StateChangedSignal() signal is emitted, with the selected state.
60  * </ul>
61  *
62  * The button's appearance can be modified by setting properties for the various image filenames.
63  *
64  * 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
65  * button is not pressed and is replaced by the \e selected image when the button is pressed. The text label is placed always on the top of all images.
66  *
67  * When the button is disabled, \e background, \e button and \e selected images are replaced by their \e disabled images.
68  *
69  * It's not mandatory to set all images. A button could be defined only by setting its \e background image or by setting its \e background and \e selected images.
70  *
71  * Signals
72  * | %Signal Name     | Method                      |
73  * |------------------|-----------------------------|
74  * | pressed          | @ref PressedSignal()        |
75  * | released         | @ref ReleasedSignal()       |
76  * | clicked          | @ref ClickedSignal()        |
77  * | stateChanged     | @ref StateChangedSignal()   |
78  *
79  * Actions
80  * | %Action Name     | Attributes              | Description                                   |
81  * |------------------|-------------------------|-----------------------------------------------|
82  * | buttonClick      | Doesn't have attributes | Simulates a button click. See @ref DoAction() |
83  * @SINCE_1_0.0
84  */
85 class DALI_IMPORT_API Button : public Control
86 {
87 public:
88
89   /**
90    * @brief Enumeration for the start and end property ranges for this control.
91    * @SINCE_1_0.0
92    */
93   enum PropertyRange
94   {
95     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1, ///< @SINCE_1_0.0
96     PROPERTY_END_INDEX =   PROPERTY_START_INDEX + 1000              ///< Reserve property indices @SINCE_1_0.0
97   };
98
99   /**
100    * @brief Enumeration for the instance of properties belonging to the Button class.
101    * @SINCE_1_0.0
102    */
103   struct Property
104   {
105     /**
106      * @brief Enumeration for the instance of properties belonging to the Button class.
107      * @SINCE_1_0.0
108      */
109     enum
110     {
111       DISABLED = PROPERTY_START_INDEX, ///< name "disabled",                     @see SetDisabled(),                  type bool @SINCE_1_0.0
112       AUTO_REPEATING,                  ///< name "autoRepeating",                @see SetAutoRepeating(),             type bool @SINCE_1_0.0
113       INITIAL_AUTO_REPEATING_DELAY,    ///< name "initialAutoRepeatingDelay",    @see SetInitialAutoRepeatingDelay(), type float @SINCE_1_0.0
114       NEXT_AUTO_REPEATING_DELAY,       ///< name "nextAutoRepeatingDelay",       @see SetNextAutoRepeatingDelay(),    type float @SINCE_1_0.0
115       TOGGLABLE,                       ///< name "togglable",                    @see SetTogglableButton(),           type bool @SINCE_1_0.0
116       SELECTED,                        ///< name "selected",                     @see SetSelected(),                  type bool @SINCE_1_0.0
117       UNSELECTED_STATE_IMAGE,          ///< name "unselectedStateImage",         @see SetUnselectedImage(),           type std::string @SINCE_1_0.0
118       SELECTED_STATE_IMAGE,            ///< name "selectedStateImage",           @see SetSelectedImage(),             type std::string @SINCE_1_0.0
119       DISABLED_STATE_IMAGE,            ///< name "disabledStateImage",           @see SetDisabledImage(),             type std::string @SINCE_1_0.0
120       UNSELECTED_COLOR,                ///< name "unselectedColor",                                                   type Vector4 @SINCE_1_0.0
121       SELECTED_COLOR,                  ///< name "selectedColor",                                                     type Vector4 @SINCE_1_0.0
122       LABEL,                           ///< name "label",                                                             type Property::Map @SINCE_1_0.0
123
124       // Deprecated properties:
125       LABEL_TEXT,                      ///< name "labelText",                    @see SetLabelText(),                 type std::string @SINCE_1_0.0
126     };
127   };
128
129 public:
130
131   /**
132    * @brief Creates an uninitialized Button.
133    *
134    * Only derived versions can be instantiated.  Calling member
135    * functions with an uninitialized Dali::Object is not allowed.
136    * @SINCE_1_0.0
137    */
138   Button();
139
140   /**
141    * @brief Copy constructor.
142    * @SINCE_1_0.0
143    * @param[in] button Handle to an object
144    */
145   Button( const Button& button );
146
147   /**
148    * @brief Assignment operator.
149    * @SINCE_1_0.0
150    * @param[in] button Handle to an object
151    * @return A reference to this
152    */
153   Button& operator=( const Button& button );
154
155   /**
156    * @brief Downcasts a handle to Button handle.
157    *
158    * If handle points to a Button, the downcast produces valid handle.
159    * If not the returned handle is left uninitialized.
160    *
161    * @SINCE_1_0.0
162    * @param[in] handle Handle to an object
163    * @return A handle to a Button or an uninitialized handle
164    */
165   static Button DownCast( BaseHandle handle );
166
167   /**
168    * @brief Destructor.
169    *
170    * This is non-virtual since derived Handle types must not contain data or virtual methods.
171    * @SINCE_1_0.0
172    */
173   ~Button();
174
175   // Deprecated API
176
177   /**
178    * @DEPRECATED_1_1.32 Use SetProperty DISABLED or Styling file
179    *
180    * @brief Sets the button as \e disabled.
181    *
182    * No signals are emitted when the \e disabled property is set.
183    *
184    * @SINCE_1_0.0
185    * @param[in] disabled Disabled property
186    */
187   void SetDisabled( bool disabled ) DALI_DEPRECATED_API;
188
189   /**
190    * @DEPRECATED_1_1.32 Use GetProperty DISABLED
191    *
192    * @brief Returns if the button is disabled.
193    * @SINCE_1_0.0
194    * @return \e true if the button is \e disabled
195    */
196   bool IsDisabled() const DALI_DEPRECATED_API;
197
198   /**
199    * @DEPRECATED_1_1.32 SetProperty AUTO_REPEATING or Styling file
200    *
201    * @brief Sets the \e autorepeating property.
202    *
203    * If the \e autorepeating property is set to \e true, then the \e togglable property is set to false
204    * but no signal is emitted.
205    *
206    * @SINCE_1_0.0
207    * @param[in] autoRepeating \e autorepeating property
208    */
209   void SetAutoRepeating( bool autoRepeating ) DALI_DEPRECATED_API;
210
211   /**
212    * @DEPRECATED_1_1.32 GetProperty AUTO_REPEATING
213    *
214    * @brief Returns if the autorepeating property is set.
215    * @SINCE_1_0.0
216    * @return \e true if the \e autorepeating property is set
217    */
218   bool IsAutoRepeating() const DALI_DEPRECATED_API;
219
220   /**
221    * @DEPRECATED_1_1.32 SetProperty INITIAL_AUTO_REPEATING_DELAY or Styling file
222    *
223    * @brief Sets the initial autorepeating delay.
224    *
225    * By default, this value is set to 0.15 seconds.
226    *
227    * @SINCE_1_0.0
228    * @param[in] initialAutoRepeatingDelay in seconds
229    * @pre initialAutoRepeatingDelay must be greater than zero.
230    */
231   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay ) DALI_DEPRECATED_API;
232
233   /**
234    * @DEPRECATED_1_1.32 GetProperty INITIAL_AUTO_REPEATING_DELAY
235    *
236    * @brief Gets the initial autorepeating delay in seconds.
237    * @SINCE_1_0.0
238    * @return The initial autorepeating delay in seconds
239    */
240   float GetInitialAutoRepeatingDelay() const DALI_DEPRECATED_API;
241
242   /**
243    * @DEPRECATED_1_1.32 SetProperty NEXT_AUTO_REPEATING_DELAY or Styling file
244    *
245    * @brief Sets the next autorepeating delay.
246    *
247    * By default, this value is set to 0.05 seconds.
248    *
249    * @SINCE_1_0.0
250    * @param[in] nextAutoRepeatingDelay in seconds
251    * @pre nextAutoRepeatingDelay must be greater than zero.
252    */
253   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay ) DALI_DEPRECATED_API;
254
255   /**
256    * @DEPRECATED_1_1.32 GetProperty NEXT_AUTO_REPEATING_DELAY
257    *
258    * @brief Gets the next autorepeating delay in seconds.
259    * @SINCE_1_0.0
260    * @return The next autorepeating delay in seconds
261    */
262   float GetNextAutoRepeatingDelay() const DALI_DEPRECATED_API;
263
264   /**
265    * @DEPRECATED_1_1.32 SetProperty TOGGLABLE or Styling file
266    *
267    * @brief Sets the \e togglable property.
268    *
269    * If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
270    *
271    * @SINCE_1_0.0
272    * @param[in] togglable Togglable property
273    */
274   void SetTogglableButton( bool togglable ) DALI_DEPRECATED_API;
275
276   /**
277    * @DEPRECATED_1_1.32 GetProperty TOGGLABLE
278    *
279    * @brief Returns if the togglable property is set.
280    * @SINCE_1_0.0
281    * @return \e true if the \e togglable property is set
282    */
283   bool IsTogglableButton() const DALI_DEPRECATED_API;
284
285   /**
286    * @DEPRECATED_1_1.32 SetProperty SELECTED
287    *
288    * @brief Sets the button as selected or unselected.
289    *
290    * \e togglable property must be set to \e true.
291    *
292    * Emits a Button::StateChangedSignal() signal.
293    *
294    * @SINCE_1_0.0
295    * @param[in] selected Selected property
296    */
297   void SetSelected( bool selected ) DALI_DEPRECATED_API;
298
299   /**
300    * DEPRECATED_1_1.32  GetProperty SELECTED
301    *
302    * @brief Returns if the selected property is set and the button is togglable.
303    * @SINCE_1_0.0
304    * @return \e true if the button is \e selected
305    */
306   bool IsSelected() const DALI_DEPRECATED_API;
307
308   /**
309    * @DEPRECATED_1_1.32 Use Styling file to set animation
310    *
311    * @brief Sets the animation time.
312    *
313    * @SINCE_1_0.0
314    * @param[in] animationTime The animation time in seconds
315    */
316   void SetAnimationTime( float animationTime ) DALI_DEPRECATED_API;
317
318   /**
319    * DEPRECATED_1_1.32 Use Styling file to set animation
320    *
321    * @brief Retrieves button's animation time.
322    *
323    * @SINCE_1_0.0
324    * @return The animation time in seconds
325    */
326   float GetAnimationTime() const DALI_DEPRECATED_API;
327
328   /**
329    * @brief Sets the button's label.
330    *
331    * @SINCE_1_0.0
332    * @param[in] label The label text
333    */
334   void SetLabelText( const std::string& label ) DALI_DEPRECATED_API;
335
336   /**
337    * DEPRECATED_1_1.32 GetProperty LABEL
338    *
339    * @brief Gets the label.
340    *
341    * @SINCE_1_0.0
342    * @return The label text
343    */
344   std::string GetLabelText() const DALI_DEPRECATED_API;
345
346   /**
347    * @DEPRECATED_1_1.32 Use Styling file
348    *
349    * @brief Sets the unselected button image.
350    *
351    * @SINCE_1_0.0
352    * @param[in] filename The button image
353    */
354   void SetUnselectedImage( const std::string& filename ) DALI_DEPRECATED_API;
355
356   /**
357    * @DEPRECATED_1_1.32 Use styling
358    *
359    * @brief Sets the background image.
360    *
361    * @SINCE_1_0.0
362    * @param[in] filename The background image
363    */
364   void SetBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API;
365
366   /**
367    * @DEPRECATED_1_1.32 Use styling file
368    *
369    * @brief Sets the selected image.
370    *
371    * @SINCE_1_0.0
372    * @param[in] filename The selected image
373    */
374   void SetSelectedImage( const std::string& filename ) DALI_DEPRECATED_API;
375
376   /**
377    * @DEPRECATED_1_1.32 Use styling file
378    *
379    * @brief Sets the selected background image.
380    *
381    * @SINCE_1_0.0
382    * @param[in] filename The selected background image
383    */
384   void SetSelectedBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API;
385
386   /**
387    * @DEPRECATED_1_1.32 Use styling file
388    *
389    * @brief Sets the disabled background image.
390    *
391    * @SINCE_1_0.0
392    * @param[in] filename The disabled background image
393    */
394   void SetDisabledBackgroundImage( const std::string& filename ) DALI_DEPRECATED_API;
395
396   /**
397    * @DEPRECATED_1_1.32 Use styling file
398    *
399    * @brief Sets the disabled button image.
400    *
401    * @SINCE_1_0.0
402    * @param[in] filename The disabled button image
403    */
404   void SetDisabledImage( const std::string& filename ) DALI_DEPRECATED_API;
405
406   /**
407    * @DEPRECATED_1_1.32 Use styling file
408    *
409    * @brief Sets the disabled selected button image.
410    *
411    * @SINCE_1_0.0
412    * @param[in] filename The disabled selected button image
413    */
414   void SetDisabledSelectedImage( const std::string& filename ) DALI_DEPRECATED_API;
415
416   /**
417    * @DEPRECATED_1_0.50. Instead, use SetLabelText
418    *
419    * @brief Sets the label with an actor.
420    *
421    * @SINCE_1_0.0
422    * @param[in] label The actor to use as a label
423    */
424   void SetLabel( Actor label ) DALI_DEPRECATED_API;
425
426   /**
427    * @DEPRECATED_1_0.50. Instead, use SetUnselectedImage.
428    *
429    * @brief Sets the button image.
430    *
431    * @SINCE_1_0.0
432    * @param[in] image The button image
433    */
434   void SetButtonImage( Image image ) DALI_DEPRECATED_API;
435
436   /**
437    * @DEPRECATED_1_0.50. Instead, use SetSelectedImage( const std::string& filename ).
438    *
439    * @brief Sets the selected image.
440    *
441    * @SINCE_1_0.0
442    * @param[in] image The selected image
443    */
444   void SetSelectedImage( Image image ) DALI_DEPRECATED_API;
445
446   /**
447    * @DEPRECATED_1_0.50
448    *
449    * @brief Gets the button image.
450    *
451    * @SINCE_1_0.0
452    * @remarks Avoid using this method as it's a legacy code.
453    * @return An actor with the button image
454    */
455   Actor GetButtonImage() const DALI_DEPRECATED_API;
456
457   /**
458    * @DEPRECATED_1_0.50
459    *
460    * @brief Gets the selected image.
461    *
462    * @SINCE_1_0.0
463    * @remarks Avoid using this method as it's a legacy code.
464    * @return An actor with the selected image
465    */
466   Actor GetSelectedImage() const DALI_DEPRECATED_API;
467
468 public: //Signals
469
470   /**
471    * @brief Button signal type.
472    * @SINCE_1_0.0
473    */
474   typedef Signal< bool ( Button ) > ButtonSignalType;
475
476   /**
477    * @brief This signal is emitted when the button is touched.
478    *
479    * A callback of the following type may be connected:
480    * @code
481    *   bool YourCallbackName( Button button );
482    * @endcode
483    * @SINCE_1_0.0
484    * @return The signal to connect to
485    */
486   ButtonSignalType& PressedSignal();
487
488   /**
489    * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
490    *
491    * A callback of the following type may be connected:
492    * @code
493    *   bool YourCallbackName( Button button );
494    * @endcode
495    * @SINCE_1_0.0
496    * @return The signal to connect to
497    */
498   ButtonSignalType& ReleasedSignal();
499
500   /**
501    * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
502    *
503    * A callback of the following type may be connected:
504    * @code
505    *   bool YourCallbackName( Button button );
506    * @endcode
507    * @SINCE_1_0.0
508    * @return The signal to connect to
509    */
510   ButtonSignalType& ClickedSignal();
511
512   /**
513    * @brief This signal is emitted when the button's state is changed.
514    *
515    * The application can get the state by calling IsSelected().
516    *
517    * A callback of the following type may be connected:
518    * @code
519    *   bool YourCallbackName( Button button );
520    * @endcode
521    * @SINCE_1_0.0
522    * @return The signal to connect to
523    */
524   ButtonSignalType& StateChangedSignal();
525
526 public: // Not intended for application developers
527
528   /**
529    * @internal
530    * @brief Creates a handle using the Toolkit::Internal implementation.
531    *
532    * @SINCE_1_0.0
533    * @param[in] implementation The Control implementation
534    */
535   DALI_INTERNAL Button( Internal::Button& implementation );
536
537   /**
538    * @internal
539    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
540    *
541    * @SINCE_1_0.0
542    * @param[in] internal A pointer to the internal CustomActor
543    */
544   DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
545 };
546
547 /**
548  * @}
549  */
550 } // namespace Toolkit
551
552 } // namespace Dali
553
554 #endif // __DALI_TOOLKIT_BUTTON_H__