Apply the new doxygen tagging rule for @SINCE
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / public-api / controls / control.h
1 #ifndef __DALI_TOOLKIT_CONTROL_H__
2 #define __DALI_TOOLKIT_CONTROL_H__
3
4 /*
5  * Copyright (c) 2015 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 // EXTERNAL INCLUDES
22 #include <dali/public-api/actors/custom-actor.h>
23 #include <dali/public-api/common/dali-common.h>
24 #include <dali/public-api/events/long-press-gesture-detector.h>
25 #include <dali/public-api/events/pan-gesture-detector.h>
26 #include <dali/public-api/events/pinch-gesture-detector.h>
27 #include <dali/public-api/events/tap-gesture-detector.h>
28 #include <dali/public-api/events/tap-gesture-detector.h>
29 #include <dali/public-api/images/image.h>
30
31 namespace Dali
32 {
33
34 namespace Toolkit
35 {
36
37 //Forward declarations.
38
39 namespace Internal
40 {
41 class Control;
42 }
43 /**
44  * @addtogroup dali_toolkit_controls
45  * @{
46  */
47
48 /**
49  * @brief Control is the base class for all controls.
50  *
51  * The implementation of the control must be supplied; see Internal::Control for more details.
52  * @SINCE_1_0.0
53  * @see Internal::Control
54  *
55  * Signals
56  * | %Signal Name           | Method                                              |
57  * |------------------------|-----------------------------------------------------|
58  * | keyEvent               | @ref KeyEventSignal()                               |
59  * | keyInputFocusGained    | @ref KeyInputFocusGainedSignal()                    |
60  * | keyInputFocusLost      | @ref KeyInputFocusLostSignal()                      |
61  * | tapped                 | @ref GetTapGestureDetector().DetectedSignal()       |
62  * | panned                 | @ref GetPanGestureDetector().DetectedSignal()       |
63  * | pinched                | @ref GetPinchGestureDetector().DetectedSignal()     |
64  * | longPressed            | @ref GetLongPressGestureDetector().DetectedSignal() |
65  *
66  * Actions
67  * | %Action Name           | %Control method called                             |
68  * |------------------------|----------------------------------------------------|
69  * | accessibilityActivated | %OnAccessibilityActivated()                        |
70  */
71 class DALI_IMPORT_API Control : public CustomActor
72 {
73 public:
74
75   /**
76    * @brief The start and end property ranges for control.
77    * @SINCE_1_0.0
78    */
79   enum PropertyRange
80   {
81     PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,        ///< Start index is used by the property registration macro. @SINCE_1_0.0
82     CONTROL_PROPERTY_START_INDEX = PROPERTY_START_INDEX,             ///< Start index of Control properties. @SINCE_1_0.0
83     CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices. @SINCE_1_0.0
84   };
85
86   /**
87    * @brief An enumeration of properties belonging to the Control class.
88    * @SINCE_1_0.0
89    */
90   struct Property
91   {
92     enum
93     {
94       STYLE_NAME = PROPERTY_START_INDEX, ///< name "styleName",        @see SetStyleName,                                                             type std::string @SINCE_1_0.0
95       BACKGROUND_COLOR,                  ///< name "background-color", @deprecated DALi 1.1.3 mutually exclusive with BACKGROUND_IMAGE & BACKGROUND,  type Vector4 @SINCE_1_0.0
96       BACKGROUND_IMAGE,                  ///< name "background-image", @deprecated DALi 1.1.3 mutually exclusive with BACKGROUND_COLOR & BACKGROUND,  type Map @SINCE_1_0.0
97       KEY_INPUT_FOCUS,                   ///< name "keyInputFocus",    @see SetKeyInputFocus,                                                         type bool @SINCE_1_0.0
98       BACKGROUND,                        ///< name "background",       mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE,                   type Map @SINCE_1_1.3
99     };
100   };
101
102   /**
103    * @brief Describes the direction to move the keyboard focus towards.
104    * @SINCE_1_0.0
105    */
106   struct KeyboardFocus
107   {
108     enum Direction
109     {
110       LEFT,   ///< Move keyboard focus towards the left direction @SINCE_1_0.0
111       RIGHT,  ///< Move keyboard focus towards the right direction @SINCE_1_0.0
112       UP,     ///< Move keyboard focus towards the up direction @SINCE_1_0.0
113       DOWN    ///< Move keyboard focus towards the down direction @SINCE_1_0.0
114     };
115   };
116
117   // Typedefs
118
119   /// @brief Key Event signal type;
120   typedef Signal<bool ( Control, const KeyEvent& ) > KeyEventSignalType;
121
122   /// @brief Key InputFocusType signal type;
123   typedef Signal<void ( Control ) > KeyInputFocusSignalType;
124
125 public: // Creation & Destruction
126
127   /**
128    * @brief Create a new instance of a Control.
129    *
130    * @SINCE_1_0.0
131    * @return A handle to a new Control.
132    */
133   static Control New();
134
135   /**
136    * @brief Create an uninitialized Control handle.
137    *
138    * Only derived versions can be instantiated.  Calling member
139    * functions with an uninitialized Dali::Object is not allowed.
140    * @SINCE_1_0.0
141    */
142   Control();
143
144   /**
145    * @brief Copy constructor.
146    *
147    * Creates another handle that points to the same real object
148    * @SINCE_1_0.0
149    * @param[in] uiControl Handle to copy
150    */
151   Control(const Control& uiControl);
152
153   /**
154    * @brief Dali::Control is intended as a base class
155    *
156    * This is non-virtual since derived Handle types must not contain data or virtual methods.
157    * @SINCE_1_0.0
158    */
159   ~Control();
160
161 public: // operators
162
163   /**
164    * @brief Assignment operator.
165    *
166    * Changes this handle to point to another real object
167    * @SINCE_1_0.0
168    * @param[in] handle Object to assign this to
169    * @return reference to this
170    */
171   Control& operator=( const Control& handle );
172
173 public:
174
175   /**
176    * @brief Downcast an Object handle to Control.
177    *
178    * If handle points to a Control the downcast produces valid
179    * handle. If not the returned handle is left uninitialized.
180    *
181    * @SINCE_1_0.0
182    * @param[in] handle Handle to an object
183    * @return handle to a Control or an uninitialized handle
184    */
185   static Control DownCast( BaseHandle handle );
186
187   // Key Input
188
189   /**
190    * @brief This sets the control to receive key events.
191    *
192    * The key event can originate from a virtual or physical keyboard.
193    * @SINCE_1_0.0
194    * @return True if the control has foucs, False otherwise.
195    * @pre The Control has been initialized.
196    * @pre The Control should be on the stage before setting keyboard focus.
197    */
198   void SetKeyInputFocus();
199
200   /**
201    * @brief Quries whether the control has key input focus.
202    *
203    * Note: The control can be set to have the focus and still not receive all the key events if another control has over ridden it.
204    * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
205    * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
206    * controls above it in the focus stack.
207    * To query for the conrol which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor()
208    * @SINCE_1_0.0
209    * @return true if this control has keyboard input focus
210    * @pre The Control has been initialized.
211    * @pre The Control should be on the stage before setting keyboard focus.
212    */
213   bool HasKeyInputFocus();
214
215   /**
216    * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
217    *
218    * A check is performed to ensure it was previously set, if this check fails then nothing is done.
219    * @SINCE_1_0.0
220    * @pre The Actor has been initialized.
221    */
222   void ClearKeyInputFocus();
223
224   // Gesture Detection
225
226   /**
227    * @brief Retrieves the pinch gesture detector of the control.
228    *
229    * @SINCE_1_0.0
230    * @return The pinch gesture detector.
231    * @note Will return an empty handle if the control does not handle the gesture itself.
232    */
233   PinchGestureDetector GetPinchGestureDetector() const;
234
235   /**
236    * @brief Retrieves the pan gesture detector of the control.
237    *
238    * @SINCE_1_0.0
239    * @return The pan gesture detector.
240    * @note Will return an empty handle if the control does not handle the gesture itself.
241    */
242   PanGestureDetector GetPanGestureDetector() const;
243
244   /**
245    * @brief Retrieves the tap gesture detector of the control.
246    *
247    * @SINCE_1_0.0
248    * @return The tap gesture detector.
249    * @note Will return an empty handle if the control does not handle the gesture itself.
250    */
251   TapGestureDetector GetTapGestureDetector() const;
252
253   /**
254    * @brief Retrieves the long press gesture detector of the control.
255    *
256    * @SINCE_1_0.0
257    * @return The long press gesture detector.
258    * @note Will return an empty handle if the control does not handle the gesture itself.
259    */
260   LongPressGestureDetector GetLongPressGestureDetector() const;
261
262   // Styling
263
264   /**
265    * @brief Sets the name of the style to be applied to the control.
266    *
267    * @SINCE_1_0.0
268    * @param[in] styleName A string matching a style described in a stylesheet.
269    */
270   void SetStyleName( const std::string& styleName );
271
272   /**
273    * @brief Retrieves the name of the style to be applied to the control (if any).
274    *
275    * @SINCE_1_0.0
276    * @return A string matching a style or an empty string.
277    */
278   const std::string& GetStyleName() const;
279
280   // Background
281
282   /**
283    * @brief Sets the background color of the control.
284    *
285    * @SINCE_1_0.0
286    * @param[in] color The required background color of the control
287    *
288    * @note if SetBackgroundImage is called later, this background color is removed.
289    *
290    * @note The background color fully blends with the actor color.
291    */
292   void SetBackgroundColor( const Vector4& color );
293
294   /**
295    * @deprecated DALi 1.1.3 API removed.
296    *
297    * @brief Retrieves the background color of the control.
298    *
299    * @SINCE_1_0.0
300    * @return The background color of the control.
301    */
302   Vector4 GetBackgroundColor() const;
303
304   /**
305    * @brief Sets an image as the background of the control.
306    *
307    * @SINCE_1_0.0
308    * @param[in] image The image to set as the background.
309    */
310   void SetBackgroundImage( Image image );
311
312   /**
313    * @brief Clears the background.
314    * @SINCE_1_0.0
315    */
316   void ClearBackground();
317
318   // Signals
319
320   /**
321    * @brief This signal is emitted when key event is received.
322    *
323    * A callback of the following type may be connected:
324    * @code
325    *   bool YourCallbackName(Control control, const KeyEvent& event);
326    * @endcode
327    * The return value of True, indicates that the event should be consumed.
328    * Otherwise the signal will be emitted on the next parent of the actor.
329    * @SINCE_1_0.0
330    * @return The signal to connect to.
331    * @pre The Control has been initialized.
332    */
333   KeyEventSignalType& KeyEventSignal();
334
335   /**
336    * @brief This signal is emitted when the control gets Key Input Focus
337    *
338    * A callback of the following type may be connected:
339    * @code
340    *   bool YourCallbackName( Control control );
341    * @endcode
342    * The return value of True, indicates that the event should be consumed.
343    * Otherwise the signal will be emitted on the next parent of the actor.
344    * @SINCE_1_0.0
345    * @return The signal to connect to.
346    * @pre The Control has been initialized.
347    */
348   KeyInputFocusSignalType& KeyInputFocusGainedSignal();
349
350   /**
351    * @brief This signal is emitted when the control loses Key Input Focus
352    * which could be due to it being gained by another Control or Actor or just cleared from
353    * this control as no longer required.
354    *
355    * A callback of the following type may be connected:
356    * @code
357    *   bool YourCallbackName( Control control );
358    * @endcode
359    * The return value of True, indicates that the event should be consumed.
360    * Otherwise the signal will be emitted on the next parent of the actor.
361    * @SINCE_1_0.0
362    * @return The signal to connect to.
363    * @pre The Control has been initialized.
364    */
365   KeyInputFocusSignalType& KeyInputFocusLostSignal();
366
367 public: // Intended for control developers
368
369   /**
370    * @brief Create an initialised Control.
371    *
372    * @SINCE_1_0.0
373    * @param[in] implementation The implementation for this control.
374    * @return A handle to a newly allocated Dali resource.
375    *
376    * @note Should NOT be called to create a handle from the implementation. As stated, this allocates a NEW Dali resource.
377    */
378   explicit Control(Internal::Control& implementation);
379
380   /**
381    * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
382    * using an Internal CustomActor pointer.
383    *
384    * @SINCE_1_0.0
385    * @param [in] internal A pointer to a newly allocated Dali resource
386    */
387   explicit Control(Dali::Internal::CustomActor* internal);
388
389 public: // Templates for Deriving Classes
390
391   /**
392    * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
393    *
394    * @tparam     T       The handle class
395    * @tparam     I       The implementation class
396    * @SINCE_1_0.0
397    * @param[in]  handle  Handle to an object
398    * @return Handle to a class T or an uninitialized handle.
399    * @see DownCast(BaseHandle)
400    */
401   template<typename T, typename I>
402   DALI_INTERNAL static T DownCast( BaseHandle handle )
403   {
404     T result;
405
406     CustomActor custom = Dali::CustomActor::DownCast( handle );
407     if ( custom )
408     {
409       CustomActorImpl& customImpl = custom.GetImplementation();
410
411       I* impl = dynamic_cast<I*>(&customImpl);
412
413       if (impl)
414       {
415         result = T(customImpl.GetOwner());
416       }
417     }
418
419     return result;
420   }
421
422   /**
423    * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
424    * implementation of their class.
425    *
426    * @tparam     I         The implementation class
427    * @SINCE_1_0.0
428    * @param[in]  internal  Pointer to the Internal::CustomActor
429    */
430   template<typename I>
431   DALI_INTERNAL void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
432   {
433     // Can have a NULL pointer so we only need to check if the internal implementation is our class
434     // when there is a value.
435     if (internal)
436     {
437       DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
438     }
439   }
440
441 };
442
443 /**
444  * @}
445  */
446 } // namespace Toolkit
447
448 } // namespace Dali
449
450 #endif // __DALI_TOOLKIT_CONTROL_H__