Deprecating Button API in favour of using Properties or style file
[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  * Is 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     | %Button method called       |
81  * |------------------|-----------------------------|
82  * | buttonClick      | %DoClickAction()            |
83  * @SINCE_1_0.0
84  */
85 class DALI_IMPORT_API Button : public Control
86 {
87 public:
88
89   /**
90    * @brief 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 An enumeration of properties belonging to the Button class.
101    * @SINCE_1_0.0
102    */
103   struct Property
104   {
105     enum
106     {
107       DISABLED = PROPERTY_START_INDEX, ///< name "disabled",                     @see SetDisabled(),                  type bool @SINCE_1_0.0
108       AUTO_REPEATING,                  ///< name "autoRepeating",                @see SetAutoRepeating(),             type bool @SINCE_1_0.0
109       INITIAL_AUTO_REPEATING_DELAY,    ///< name "initialAutoRepeatingDelay",    @see SetInitialAutoRepeatingDelay(), type float @SINCE_1_0.0
110       NEXT_AUTO_REPEATING_DELAY,       ///< name "nextAutoRepeatingDelay",       @see SetNextAutoRepeatingDelay(),    type float @SINCE_1_0.0
111       TOGGLABLE,                       ///< name "togglable",                    @see SetTogglableButton(),           type bool @SINCE_1_0.0
112       SELECTED,                        ///< name "selected",                     @see SetSelected(),                  type bool @SINCE_1_0.0
113       UNSELECTED_STATE_IMAGE,          ///< name "unselectedStateImage",         @see SetUnselectedImage(),           type std::string @SINCE_1_0.0
114       SELECTED_STATE_IMAGE,            ///< name "selectedStateImage",           @see SetSelectedImage(),             type std::string @SINCE_1_0.0
115       DISABLED_STATE_IMAGE,            ///< name "disabledStateImage",           @see SetDisabledImage(),             type std::string @SINCE_1_0.0
116       UNSELECTED_COLOR,                ///< name "unselectedColor",                                                   type Vector4 @SINCE_1_0.0
117       SELECTED_COLOR,                  ///< name "selectedColor",                                                     type Vector4 @SINCE_1_0.0
118       LABEL,                           ///< name "label",                                                             type Property::Map @SINCE_1_0.0
119
120       // Deprecated properties:
121       LABEL_TEXT,                      ///< name "labelText",                    @see SetLabelText(),                 type std::string @SINCE_1_0.0
122     };
123   };
124
125 public:
126
127   /**
128    * @brief Create an uninitialized Button.
129    *
130    * Only derived versions can be instantiated.  Calling member
131    * functions with an uninitialized Dali::Object is not allowed.
132    * @SINCE_1_0.0
133    */
134   Button();
135
136   /**
137    * @brief Copy constructor.
138    * @SINCE_1_0.0
139    */
140   Button( const Button& button );
141
142   /**
143    * @brief Assignment operator.
144    * @SINCE_1_0.0
145    */
146   Button& operator=( const Button& button );
147
148   /**
149    * @brief Downcast a handle to Button handle.
150    *
151    * If handle points to a Button the downcast produces valid
152    * handle. If not the returned handle is left uninitialized.
153    *
154    * @SINCE_1_0.0
155    * @param[in] handle Handle to an object
156    * @return A handle to a Button or an uninitialized handle
157    */
158   static Button DownCast( BaseHandle handle );
159
160   /**
161    * @brief Destructor
162    *
163    * This is non-virtual since derived Handle types must not contain data or virtual methods.
164    * @SINCE_1_0.0
165    */
166   ~Button();
167
168   // Deprecated API
169
170   /**
171    * @DEPRECATED_1_1.32 Use SetProperty DISABLED or Styling file
172    *
173    * @brief Sets the button as \e disabled.
174    *
175    * No signals are emitted when the \e disabled property is set.
176    *
177    * @SINCE_1_0.0
178    * @param[in] disabled property.
179    */
180   void SetDisabled( bool disabled );
181
182   /**
183    * @DEPRECATED_1_1.32 Use GetProperty DISABLED
184    *
185    * @brief Returns if the button is disabled.
186    * @SINCE_1_0.0
187    * @return \e true if the button is \e disabled.
188    */
189   bool IsDisabled() const;
190
191   /**
192    * @DEPRECATED_1_1.32 SetProperty AUTO_REPEATING or Styling file
193    *
194    * @brief Sets the \e autorepeating property.
195    *
196    * If the \e autorepeating property is set to \e true, then the \e togglable property is set to false
197    * but no signal is emitted.
198    *
199    * @SINCE_1_0.0
200    * @param[in] autoRepeating \e autorepeating property.
201    */
202   void SetAutoRepeating( bool autoRepeating );
203
204   /**
205    * @DEPRECATED_1_1.32 GetProperty AUTO_REPEATING
206    *
207    * @brief Returns if the autorepeating property is set.
208    * @SINCE_1_0.0
209    * @return \e true if the \e autorepeating property is set.
210    */
211   bool IsAutoRepeating() const;
212
213   /**
214    * @DEPRECATED_1_1.32 SetProperty INITIAL_AUTO_REPEATING_DELAY or Styling file
215    *
216    * @brief Sets the initial autorepeating delay.
217    *
218    * By default this value is set to 0.15 seconds.
219    *
220    * @SINCE_1_0.0
221    * @param[in] initialAutoRepeatingDelay in seconds.
222    * @pre initialAutoRepeatingDelay must be greater than zero.
223    */
224   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
225
226   /**
227    * @DEPRECATED_1_1.32 GetProperty INITIAL_AUTO_REPEATING_DELAY
228    *
229    * @brief Gets the initial autorepeating delay in seconds.
230    * @SINCE_1_0.0
231    * @return the initial autorepeating delay in seconds.
232    */
233   float GetInitialAutoRepeatingDelay() const;
234
235   /**
236    * @DEPRECATED_1_1.32 SetProperty NEXT_AUTO_REPEATING_DELAY or Styling file
237    *
238    * @brief Sets the next autorepeating delay.
239    *
240    * By default this value is set to 0.05 seconds.
241    *
242    * @SINCE_1_0.0
243    * @param[in] nextAutoRepeatingDelay in seconds.
244    * @pre nextAutoRepeatingDelay must be greater than zero.
245    */
246   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
247
248   /**
249    * @DEPRECATED_1_1.32 GetProperty NEXT_AUTO_REPEATING_DELAY
250    *
251    * @brief Gets the next autorepeating delay in seconds.
252    * @SINCE_1_0.0
253    * @return the next autorepeating delay in seconds.
254    */
255   float GetNextAutoRepeatingDelay() const;
256
257   /**
258    * @DEPRECATED_1_1.32 SetProperty TOGGLABLE or Styling file
259    *
260    * @brief Sets the \e togglable property.
261    *
262    * If the \e togglable property is set to \e true, then the \e autorepeating property is set to false.
263    *
264    * @SINCE_1_0.0
265    * @param[in] togglable property.
266    */
267   void SetTogglableButton( bool togglable );
268
269   /**
270    * @DEPRECATED_1_1.32 GetProperty TOGGLABLE
271    *
272    * @brief Returns if the togglable property is set.
273    * @SINCE_1_0.0
274    * @return \e true if the \e togglable property is set.
275    */
276   bool IsTogglableButton() const;
277
278   /**
279    * @DEPRECATED_1_1.32 SetProperty SELECTED
280    *
281    * @brief Sets the button as selected or unselected.
282    *
283    * \e togglable property must be set to \e true.
284    *
285    * Emits a Button::StateChangedSignal() signal.
286    *
287    * @SINCE_1_0.0
288    * @param[in] selected property.
289    */
290   void SetSelected( bool selected );
291
292   /**
293    * DEPRECATED_1_1.32  SetProperty SELECTED
294    *
295    * @brief Returns if the selected property is set and the button is togglable.
296    * @SINCE_1_0.0
297    * @return \e true if the button is \e selected.
298    */
299   bool IsSelected() const;
300
301   /**
302    * @DEPRECATED_1_1.32 Use Styling file to set animation
303    *
304    * @brief Sets the animation time.
305    *
306    * @SINCE_1_0.0
307    * @param[in] animationTime The animation time in seconds.
308    */
309   void SetAnimationTime( float animationTime );
310
311   /**
312    * DEPRECATED_1_1.32 Use Styling file to set animation
313    *
314    * @brief Retrieves button's animation time.
315    *
316    * @SINCE_1_0.0
317    * @return The animation time in seconds.
318    */
319   float GetAnimationTime() const;
320
321   /**
322    * @DEPRECATED_1_1.32 SetProperty LABEL or Styling file
323    *
324    * @brief Sets the button's label.
325    *
326    * @SINCE_1_0.0
327    * @param[in] label The label text.
328    */
329   void SetLabelText( const std::string& label );
330
331   /**
332    * DEPRECATED_1_1.32 GetProperty LABEL
333    *
334    * @brief Gets the label.
335    *
336    * @SINCE_1_0.0
337    * @return The label text.
338    */
339   std::string GetLabelText() const;
340
341   /**
342    * @DEPRECATED_1_1.32 Use Styling file
343    *
344    * @brief Sets the unselected button image.
345    *
346    * @SINCE_1_0.0
347    * @param[in] filename The button image.
348    */
349   void SetUnselectedImage( const std::string& filename );
350
351   /**
352    * @DEPRECATED_1_1.32 Use styling
353    *
354    * @brief Sets the background image.
355    *
356    * @SINCE_1_0.0
357    * @param[in] filename The background image.
358    */
359   void SetBackgroundImage( const std::string& filename );
360
361   /**
362    * @DEPRECATED_1_1.32 Use styling file
363    *
364    * @brief Sets the selected image.
365    *
366    * @SINCE_1_0.0
367    * @param[in] filename The selected image.
368    */
369   void SetSelectedImage( const std::string& filename );
370
371   /**
372    * @DEPRECATED_1_1.32 Use styling file
373    *
374    * @brief Sets the selected background image.
375    *
376    * @SINCE_1_0.0
377    * @param[in] filename The selected background image.
378    */
379   void SetSelectedBackgroundImage( const std::string& filename );
380
381   /**
382    * @DEPRECATED_1_1.32 Use styling file
383    *
384    * @brief Sets the disabled background image.
385    *
386    * @SINCE_1_0.0
387    * @param[in] filename The disabled background image.
388    */
389   void SetDisabledBackgroundImage( const std::string& filename );
390
391   /**
392    * @DEPRECATED_1_1.32 Use styling file
393    *
394    * @brief Sets the disabled button image.
395    *
396    * @SINCE_1_0.0
397    * @param[in] filename The disabled button image.
398    */
399   void SetDisabledImage( const std::string& filename );
400
401   /**
402    * @DEPRECATED_1_1.32 Use styling file
403    *
404    * @brief Sets the disabled selected button image.
405    *
406    * @SINCE_1_0.0
407    * @param[in] filename The disabled selected button image.
408    */
409   void SetDisabledSelectedImage( const std::string& filename );
410
411   /**
412    * @DEPRECATED_1_0.50. Instead, use SetLabelText.
413    *
414    * @brief Sets the label with an actor.
415    *
416    * @SINCE_1_0.0
417    * @param[in]  label The actor to use as a label
418    */
419   void SetLabel( Actor label );
420
421   /**
422    * @DEPRECATED_1_0.50. Instead, use SetUnselectedImage.
423    *
424    * @brief Sets the button image.
425    *
426    * @SINCE_1_0.0
427    * @param[in]  image The button image.
428    */
429   void SetButtonImage( Image image );
430
431   /**
432    * @DEPRECATED_1_0.50. Instead, use SetSelectedImage( const std::string& filename ).
433    *
434    * @brief Sets the selected image.
435    *
436    * @SINCE_1_0.0
437    * @param[in]  image The selected image.
438    */
439   void SetSelectedImage( Image image );
440
441   /**
442    * @DEPRECATED_1_0.50
443    *
444    * @brief Gets the button image.
445    *
446    * @SINCE_1_0.0
447    * @remarks Avoid using this method as it's a legacy code.
448    * @return     An actor with the button image.
449    */
450   Actor GetButtonImage() const;
451
452   /**
453    * @DEPRECATED_1_0.50
454    *
455    * @brief Gets the selected image.
456    *
457    * @SINCE_1_0.0
458    * @remarks Avoid using this method as it's a legacy code.
459    * @return     An actor with the selected image.
460    */
461   Actor GetSelectedImage() const;
462
463 public: //Signals
464
465   /**
466    * @brief Button signal type
467    * @SINCE_1_0.0
468    */
469   typedef Signal< bool ( Button ) > ButtonSignalType;
470
471   /**
472    * @brief This signal is emitted when the button is touched.
473    *
474    * A callback of the following type may be connected:
475    * @code
476    *   bool YourCallbackName( Button button );
477    * @endcode
478    * @SINCE_1_0.0
479    * @return The signal to connect to.
480    */
481   ButtonSignalType& PressedSignal();
482
483   /**
484    * @brief This signal is emitted when the button is touched and the touch point leaves the boundary of the button.
485    *
486    * A callback of the following type may be connected:
487    * @code
488    *   bool YourCallbackName( Button button );
489    * @endcode
490    * @SINCE_1_0.0
491    * @return The signal to connect to.
492    */
493   ButtonSignalType& ReleasedSignal();
494
495   /**
496    * @brief This signal is emitted when the button is touched and the touch point doesn't leave the boundary of the button.
497    *
498    * A callback of the following type may be connected:
499    * @code
500    *   bool YourCallbackName( Button button );
501    * @endcode
502    * @SINCE_1_0.0
503    * @return The signal to connect to.
504    */
505   ButtonSignalType& ClickedSignal();
506
507   /**
508    * @brief This signal is emitted when the button's state is changed.
509    *
510    * The application can get the state by calling IsSelected().
511    *
512    * A callback of the following type may be connected:
513    * @code
514    *   bool YourCallbackName( Button button );
515    * @endcode
516    * @SINCE_1_0.0
517    * @return The signal to connect to.
518    */
519   ButtonSignalType& StateChangedSignal();
520
521 public: // Not intended for application developers
522
523   /**
524    * @brief Creates a handle using the Toolkit::Internal implementation.
525    *
526    * @SINCE_1_0.0
527    * @param[in]  implementation  The Control implementation.
528    */
529   DALI_INTERNAL Button( Internal::Button& implementation );
530
531   /**
532    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
533    *
534    * @SINCE_1_0.0
535    * @param[in]  internal  A pointer to the internal CustomActor.
536    */
537   DALI_INTERNAL Button( Dali::Internal::CustomActor* internal );
538 };
539
540 /**
541  * @}
542  */
543 } // namespace Toolkit
544
545 } // namespace Dali
546
547 #endif // __DALI_TOOLKIT_BUTTON_H__