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