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