[dali_1.0.2] Merge branch '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_TOGGLED; ///< name "toggled"
84   static const char* const SIGNAL_PRESSED; ///< name "pressed"
85   static const char* const SIGNAL_RELEASED; ///< name "released"
86
87   //Action Names
88   static const char* const ACTION_PUSH_BUTTON_CLICK; ///< name "push-button-click"
89
90   // Properties
91   static const Property::Index PROPERTY_AUTO_REPEATING;               ///< name "auto-repeating",               @see SetAutoRepeating(),             type BOOLEAN
92   static const Property::Index PROPERTY_INITIAL_AUTO_REPEATING_DELAY; ///< name "initial-auto-repeating-delay", @see SetInitialAutoRepeatingDelay(), type FLOAT
93   static const Property::Index PROPERTY_NEXT_AUTO_REPEATING_DELAY;    ///< name "next-auto-repeating-delay",    @see SetNextAutoRepeatingDelay(),    type FLOAT
94   static const Property::Index PROPERTY_TOGGLABLE;                    ///< name "togglable",                    @see SetToggleButton(),              type BOOLEAN
95   static const Property::Index PROPERTY_TOGGLE;                       ///< name "toggle",                       @see SetToggled(),                   type BOOLEAN
96   static const Property::Index PROPERTY_NORMAL_STATE_ACTOR;           ///< name "button-state-actor",           @see SetButtonImage(),               type MAP
97   static const Property::Index PROPERTY_PRESSED_STATE_ACTOR;          ///< name "pressed-state-actor",          @see SetPressedImage(),              type MAP
98   static const Property::Index PROPERTY_DIMMED_STATE_ACTOR;           ///< name "dimmed-state-actor",           @see SetDimmedImage(),               type MAP
99   static const Property::Index PROPERTY_LABEL_ACTOR;                  ///< name "label-actor",                  @see SetLabelText(),                 type STRING
100
101 public:
102
103   /**
104    * @brief Create an uninitialized PushButton; this can be initialized with PushButton::New().
105    *
106    * Calling member functions with an uninitialized Dali::Object is not allowed.
107    */
108   PushButton();
109
110   /**
111    * @brief Copy constructor.
112    */
113   PushButton( const PushButton& pushButton );
114
115   /**
116    * @brief Assignment operator.
117    */
118   PushButton& operator=( const PushButton& pushButton );
119
120   /**
121    * @brief Destructor
122    *
123    * This is non-virtual since derived Handle types must not contain data or virtual methods.
124    */
125   ~PushButton();
126
127   /**
128    * @brief Create an initialized PushButton.
129    *
130    * @return A handle to a newly allocated Dali resource.
131    */
132   static PushButton New();
133
134   /**
135    * @brief Downcast an Object handle to PushButton.
136    *
137    * If handle points to a PushButton the downcast produces valid
138    * handle. If not the returned handle is left uninitialized.
139    *
140    * @param[in] handle Handle to an object
141    * @return handle to a PushButton or an uninitialized handle
142    */
143   static PushButton DownCast( BaseHandle handle );
144
145   /**
146    * @brief Sets the \e autorepeating property.
147    *
148    * If the \e autorepeating property is set to \e true, then the \e toggle property is set to false
149    * but no signal is emitted.
150    *
151    * @param[in] autoRepeating \e autorepeating property.
152    */
153   void SetAutoRepeating( bool autoRepeating );
154
155   /**
156    * @return \e true if the \e autorepeating property is set.
157    */
158   bool IsAutoRepeating() const;
159
160   /**
161    * @brief Sets the initial autorepeating delay.
162    *
163    * By default this value is set to 0.15 seconds.
164    *
165    * @pre initialAutoRepeatingDelay must be greater than zero.
166    * @param[in] initialAutoRepeatingDelay in seconds.
167    */
168   void SetInitialAutoRepeatingDelay( float initialAutoRepeatingDelay );
169
170   /**
171    * @return the initial autorepeating delay in seconds.
172    */
173   float GetInitialAutoRepeatingDelay() const;
174
175   /**
176    * @brief Sets the next autorepeating delay.
177    *
178    * By default this value is set to 0.05 seconds.
179    *
180    * @pre nextAutoRepeatingDelay must be greater than zero.
181    * @param[in] nextAutoRepeatingDelay in seconds.
182    */
183   void SetNextAutoRepeatingDelay( float nextAutoRepeatingDelay );
184
185   /**
186    * @return the next autorepeating delay in seconds.
187    */
188   float GetNextAutoRepeatingDelay() const;
189
190   /**
191    * @brief Sets the \e toggle property.
192    *
193    * If the \e toggle property is set to \e true, then the \e autorepeating property is set to false.
194    *
195    * @param[in] toggle property.
196    */
197   void SetToggleButton( bool toggle );
198
199   /**
200    * @return \e true if the \e toggle property is set.
201    */
202   bool IsToggleButton() const;
203
204   /**
205    * @brief Sets the button as toggled or not toggled.
206    *
207    * \e toggle property must be set to \e true.
208    *
209    * Emits a PushButton::ToggledSignal() signal.
210    *
211    * @param[in] toggle state.
212    */
213   void SetToggled( bool toggle );
214
215   /**
216    * @return \e true if the \e toggle property is set and the button is toggled.
217    */
218   bool IsToggled() const;
219
220   /**
221    * @brief Sets the button image.
222    *
223    * @param[in] image The button image.
224    */
225   void SetButtonImage( Image image );
226
227   /**
228    * @copydoc SetButtonImage( Image image )
229    */
230   void SetButtonImage( Actor image );
231
232   /**
233    * @brief Gets the button image.
234    *
235    * @return An actor with the button image.
236    */
237   Actor GetButtonImage() const;
238
239   /**
240    * @brief Sets the background image.
241    *
242    * @param[in] image The background image.
243    */
244   void SetBackgroundImage( Image image );
245
246   /**
247    * @copydoc SetBackgroundImage( Image image )
248    */
249   void SetBackgroundImage( Actor image );
250
251   /**
252    * @brief Gets the background image.
253    *
254    * @return An actor with the background image.
255    */
256   Actor GetBackgroundImage() const;
257
258   /**
259    * @brief Sets the pressed image.
260    *
261    * @param[in] image The pressed image.
262    */
263   void SetPressedImage( Image image );
264
265   /**
266    * @copydoc SetPressedImage( Image image )
267    */
268   void SetPressedImage( Actor image );
269
270   /**
271    * @brief Gets the pressed image.
272    *
273    * @return An actor with the pressed image.
274    */
275   Actor GetPressedImage() const;
276
277   /**
278    * @brief Sets the dimmed background image.
279    *
280    * @param[in] image The dimmed background image.
281    */
282   void SetDimmedBackgroundImage( Image image );
283
284   /**
285    * @copydoc SetDimmedBackgroundImage( Image image )
286    */
287   void SetDimmedBackgroundImage( Actor image );
288
289   /**
290    * @brief Gets the dimmed background image.
291    *
292    * @return An actor with the dimmed background image.
293    */
294   Actor GetDimmedBackgroundImage() const;
295
296   /**
297    * @brief Sets the dimmed button image.
298    *
299    * @param[in] image The dimmed button image.
300    */
301   void SetDimmedImage( Image image );
302
303   /**
304    * @copydoc SetDimmedImage( Image image )
305    */
306   void SetDimmedImage( Actor image );
307
308   /**
309    * @brief Gets the dimmed image.
310    *
311    * @return An actor with the dimmed image.
312    */
313   Actor GetDimmedImage() const;
314
315   /**
316    * @brief Sets the text label.
317    *
318    * @param[in] text Label text.
319    */
320   void SetLabelText( const std::string& text );
321
322   /**
323    * @copydoc SetLabelText( const std::string& text )
324    */
325   void SetLabelText( Actor text );
326
327   /**
328    * @brief Gets the label text.
329    *
330    * @return An actor with the label text.
331    */
332   Actor GetLabelText() const;
333
334 public: //Signals
335
336   /// @brief PushButton Toggled signal type.
337   typedef SignalV2< bool ( Button, bool ) > ToggledSignalV2;
338
339   /// @brief PushButton Pressed signal type.
340   typedef SignalV2< bool ( Button ) > PressedSignalV2;
341
342   /// @brief PushButton Released signal type.
343   typedef SignalV2< bool ( Button ) > ReleasedSignalV2;
344
345   /**
346    * @brief Signal emitted when the \e toggle property is set and the button is touched.
347    */
348   ToggledSignalV2& ToggledSignal();
349
350   /**
351    * @brief Signal emitted when the button is touched.
352    */
353   PressedSignalV2& PressedSignal();
354
355   /**
356    * @brief Signal emitted when the button is touched and the touch point leaves the boundary of the button.
357    */
358   ReleasedSignalV2& ReleasedSignal();
359
360 public: // Not intended for application developers
361
362   /**
363    * @brief Creates a handle using the Toolkit::Internal implementation.
364    *
365    * @param[in]  implementation  The Control implementation.
366    */
367   PushButton( Internal::PushButton& implementation );
368
369   /**
370    * @brief Allows the creation of this Control from an Internal::CustomActor pointer.
371    *
372    * @param[in]  internal  A pointer to the internal CustomActor.
373    */
374   PushButton( Dali::Internal::CustomActor* internal );
375 };
376
377 } // namespace Toolkit
378
379 } // namespace Dali
380
381 #endif // __DALI_TOOLKIT_PUSH_BUTTON_H__