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