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