[Tizen] Add deprecated log to Control
[platform/core/uifw/dali-toolkit-legacy.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) 2019 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-toolkit/public-api/dali-toolkit-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 // INTERNAL INCLUDES
32 #include <dali-toolkit/public-api/visuals/visual-properties.h>
33
34 namespace Dali
35 {
36
37 namespace Toolkit
38 {
39
40 //Forward declarations.
41
42 namespace Internal
43 {
44 class Control;
45 }
46 /**
47  * @addtogroup dali_toolkit_controls
48  * @{
49  */
50
51 /**
52  * @DEPRECATED_1_5.19
53  *
54  * @brief Control is the base class for all controls.
55  *
56  * The implementation of the control must be supplied; see Internal::Control for more details.
57  * @SINCE_1_0.0
58  * @see Internal::Control
59  *
60  * Signals
61  * | %Signal Name           | Method                                              |
62  * |------------------------|-----------------------------------------------------|
63  * | keyEvent               | @ref KeyEventSignal()                               |
64  * | keyInputFocusGained    | @ref KeyInputFocusGainedSignal()                    |
65  * | keyInputFocusLost      | @ref KeyInputFocusLostSignal()                      |
66  * | resourceReady          | @ref ResourceReadySignal()                          |
67  * | tapped                 | @ref GetTapGestureDetector().DetectedSignal()       |
68  * | panned                 | @ref GetPanGestureDetector().DetectedSignal()       |
69  * | pinched                | @ref GetPinchGestureDetector().DetectedSignal()     |
70  * | longPressed            | @ref GetLongPressGestureDetector().DetectedSignal() |
71  *
72  * Actions
73  * | %Action Name           | %Control method called                             |
74  * |------------------------|----------------------------------------------------|
75  * | accessibilityActivated | %OnAccessibilityActivated()                        |
76  */
77 class DALI_TOOLKIT_API Control : public CustomActor
78 {
79 public:
80
81   /**
82    * @brief Enumeration for the start and end property ranges for control.
83    * @SINCE_1_0.0
84    */
85   enum PropertyRange
86   {
87     PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,        ///< Start index is used by the property registration macro. @SINCE_1_0.0
88     CONTROL_PROPERTY_START_INDEX = PROPERTY_START_INDEX,             ///< Start index of Control properties. @SINCE_1_0.0
89     CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices. @SINCE_1_0.0
90   };
91
92   /**
93    * @brief Enumeration for the instance of properties belonging to the Control class.
94    * @SINCE_1_0.0
95    */
96   struct Property
97   {
98     /**
99      * @brief Enumeration for the instance of properties belonging to the Control class.
100      * @SINCE_1_0.0
101      */
102     enum
103     {
104       /**
105        * @brief The name of the style to be applied to the control.
106        * @details Name "styleName", type Property::STRING.
107        * @see Toolkit::Control::SetStyleName()
108        * @SINCE_1_0.0
109        */
110       STYLE_NAME = PROPERTY_START_INDEX,
111
112       RESERVED_PROPERTY_01, ///< Reserved index for a removed property.
113       RESERVED_PROPERTY_02, ///< Reserved index for a removed property.
114
115       /**
116        * @brief Receives key events to the control.
117        * @details Name "keyInputFocus", type Property::BOOLEAN.
118        * @see Toolkit::Control::SetKeyInputFocus()
119        * @SINCE_1_0.0
120        */
121       KEY_INPUT_FOCUS,
122
123       /**
124        * @brief The background of the control.
125        *
126        * @details Name "background", type Property::MAP or std::string for URL or Property::VECTOR4 for Color.
127        * @SINCE_1_1.3
128        */
129       BACKGROUND,
130
131       /**
132        * @brief The outer space around the control.
133        * @details Name "margin", type Property::EXTENTS.
134        * @SINCE_1_2.62
135        * @note Margin property is to be supported by Layout algorithms and containers in future.
136        */
137       MARGIN,
138
139       /**
140        * @brief The inner space of the control.
141        * @details Name "padding", type Property::EXTENTS.
142        * @SINCE_1_2.62
143        */
144       PADDING
145     };
146   };
147
148   /**
149    * @brief Describes the direction to move the keyboard focus towards.
150    * @SINCE_1_0.0
151    */
152   struct KeyboardFocus
153   {
154     /**
155      * @brief Keyboard focus direction.
156      * @SINCE_1_0.0
157      */
158     enum Direction
159     {
160       LEFT,   ///< Move keyboard focus towards the left direction @SINCE_1_0.0
161       RIGHT,  ///< Move keyboard focus towards the right direction @SINCE_1_0.0
162       UP,     ///< Move keyboard focus towards the up direction @SINCE_1_0.0
163       DOWN,    ///< Move keyboard focus towards the down direction @SINCE_1_0.0
164       PAGE_UP,     ///< Move keyboard focus towards the previous page direction @SINCE_1_2.14
165       PAGE_DOWN    ///< Move keyboard focus towards the next page direction @SINCE_1_2.14
166     };
167   };
168
169   // Typedefs
170
171   /// @brief Key Event signal type. @SINCE_1_0.0
172   typedef Signal<bool ( Control, const KeyEvent& ) > KeyEventSignalType;
173
174   /// @brief Key InputFocusType signal type. @SINCE_1_0.0
175   typedef Signal<void ( Control ) > KeyInputFocusSignalType;
176
177   /// @brief ResourceReady signal type. @SINCE_1_2.60
178   typedef Signal<void ( Control ) > ResourceReadySignalType;
179
180 public: // Creation & Destruction
181
182   /**
183    * @DEPRECATED_1_5.19
184    *
185    * @brief Creates a new instance of a Control.
186    *
187    * @SINCE_1_0.0
188    * @return A handle to a new Control
189    */
190   static Control New();
191
192   /**
193    * @brief Creates an uninitialized Control handle.
194    *
195    * Only derived versions can be instantiated.  Calling member
196    * functions with an uninitialized Dali::Object is not allowed.
197    * @SINCE_1_0.0
198    */
199   Control();
200
201   /**
202    * @brief Copy constructor.
203    *
204    * Creates another handle that points to the same real object.
205    * @SINCE_1_0.0
206    * @param[in] uiControl Handle to copy
207    */
208   Control(const Control& uiControl);
209
210   /**
211    * @brief Dali::Control is intended as a base class.
212    *
213    * This is non-virtual since derived Handle types must not contain data or virtual methods.
214    * @SINCE_1_0.0
215    */
216   ~Control();
217
218 public: // operators
219
220   /**
221    * @brief Assignment operator.
222    *
223    * Changes this handle to point to another real object.
224    * @SINCE_1_0.0
225    * @param[in] handle Object to assign this to
226    * @return Reference to this
227    */
228   Control& operator=( const Control& handle );
229
230 public:
231
232   /**
233    * @brief Downcasts a handle to Control handle.
234    *
235    * If handle points to a Control, the downcast produces valid handle.
236    * If not, the returned handle is left uninitialized.
237    *
238    * @SINCE_1_0.0
239    * @param[in] handle Handle to an object
240    * @return A handle to a Control or an uninitialized handle
241    */
242   static Control DownCast( BaseHandle handle );
243
244   // Key Input
245
246   /**
247    * @brief This sets the control to receive key events.
248    *
249    * The key event can originate from a virtual or physical keyboard.
250    * @SINCE_1_0.0
251    * @pre The Control has been initialized.
252    * @pre The Control should be on the stage before setting keyboard focus.
253    */
254   void SetKeyInputFocus();
255
256   /**
257    * @brief Quries whether the control has key input focus.
258    *
259    * @SINCE_1_0.0
260    * @return true if this control has keyboard input focus
261    * @pre The Control has been initialized.
262    * @pre The Control should be on the stage before setting keyboard focus.
263    * @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.
264    * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
265    * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
266    * controls above it in the focus stack.
267    * To query for the control which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor().
268    */
269   bool HasKeyInputFocus();
270
271   /**
272    * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
273    *
274    * A check is performed to ensure it was previously set, if this check fails then nothing is done.
275    * @SINCE_1_0.0
276    * @pre The Actor has been initialized.
277    */
278   void ClearKeyInputFocus();
279
280   // Gesture Detection
281
282   /**
283    * @brief Retrieves the pinch gesture detector of the control.
284    *
285    * @SINCE_1_0.0
286    * @return The pinch gesture detector
287    * @note Will return an empty handle if the control does not handle the gesture itself.
288    */
289   PinchGestureDetector GetPinchGestureDetector() const;
290
291   /**
292    * @brief Retrieves the pan gesture detector of the control.
293    *
294    * @SINCE_1_0.0
295    * @return The pan gesture detector
296    * @note Will return an empty handle if the control does not handle the gesture itself.
297    */
298   PanGestureDetector GetPanGestureDetector() const;
299
300   /**
301    * @brief Retrieves the tap gesture detector of the control.
302    *
303    * @SINCE_1_0.0
304    * @return The tap gesture detector
305    * @note Will return an empty handle if the control does not handle the gesture itself.
306    */
307   TapGestureDetector GetTapGestureDetector() const;
308
309   /**
310    * @brief Retrieves the long press gesture detector of the control.
311    *
312    * @SINCE_1_0.0
313    * @return The long press gesture detector
314    * @note Will return an empty handle if the control does not handle the gesture itself.
315    */
316   LongPressGestureDetector GetLongPressGestureDetector() const;
317
318   // Styling
319
320   /**
321    * @brief Sets the name of the style to be applied to the control.
322    *
323    * @SINCE_1_0.0
324    * @param[in] styleName A string matching a style described in a stylesheet
325    */
326   void SetStyleName( const std::string& styleName );
327
328   /**
329    * @brief Retrieves the name of the style to be applied to the control (if any).
330    * @SINCE_1_0.0
331    * @return A string matching a style, or an empty string
332    */
333   const std::string& GetStyleName() const;
334
335   // Background
336
337   /**
338    * @brief Sets the background color of the control.
339    *
340    * @SINCE_1_0.0
341    * @param[in] color The required background color of the control
342    *
343    * @note If SetBackgroundImage is called later, this background color is removed.
344    *
345    * @note The background color fully blends with the actor color.
346    */
347   void SetBackgroundColor( const Vector4& color );
348
349   /**
350    * @brief Clears the background.
351    * @SINCE_1_0.0
352    */
353   void ClearBackground();
354
355   // Resources
356
357   /**
358    * @brief Query if all resources required by a control are loaded and ready.
359    *
360    * Most resources are only loaded when the control is placed on stage.
361    * @SINCE_1_2.60
362    * @return true if the resources are loaded and ready, false otherwise
363    */
364   bool IsResourceReady() const;
365
366   /**
367    * @brief Get the loading state of the visual resource.
368    *
369    * @SINCE_1_3_5
370    * @param[in] index The Property index of the visual
371    * @return Return the loading status (PREPARING, READY and FAILED) of visual resource
372    */
373   Visual::ResourceStatus GetVisualResourceStatus( const Dali::Property::Index index );
374
375   // Signals
376
377   /**
378    * @brief This signal is emitted when key event is received.
379    *
380    * A callback of the following type may be connected:
381    * @code
382    *   bool YourCallbackName(Control control, const KeyEvent& event);
383    * @endcode
384    * The return value of True, indicates that the event should be consumed.
385    * Otherwise the signal will be emitted on the next parent of the actor.
386    * @SINCE_1_0.0
387    * @return The signal to connect to
388    * @pre The Control has been initialized.
389    */
390   KeyEventSignalType& KeyEventSignal();
391
392   /**
393    * @brief This signal is emitted when the control gets Key Input Focus.
394    *
395    * A callback of the following type may be connected:
396    * @code
397    *   bool YourCallbackName( Control control );
398    * @endcode
399    * The return value of True, indicates that the event should be consumed.
400    * Otherwise the signal will be emitted on the next parent of the actor.
401    * @SINCE_1_0.0
402    * @return The signal to connect to
403    * @pre The Control has been initialized.
404    */
405   KeyInputFocusSignalType& KeyInputFocusGainedSignal();
406
407   /**
408    * @brief This signal is emitted when the control loses Key Input Focus.
409    *
410    * This could be due to it being gained by another Control or Actor or just cleared from
411    * this control as no longer required.
412    *
413    * A callback of the following type may be connected:
414    * @code
415    *   bool YourCallbackName( Control control );
416    * @endcode
417    * The return value of True, indicates that the event should be consumed.
418    * Otherwise the signal will be emitted on the next parent of the actor.
419    * @SINCE_1_0.0
420    * @return The signal to connect to
421    * @pre The Control has been initialized.
422    */
423   KeyInputFocusSignalType& KeyInputFocusLostSignal();
424
425   /**
426    * @brief This signal is emitted after all resources required by a control are loaded and ready.
427    *
428    * Most resources are only loaded when the control is placed on stage.
429    *
430    * If resources are shared between ImageViews, they are cached.
431    * In this case, the ResourceReady signal may be sent before there is an object to connect to.
432    * To protect against this, IsResourceReady() can be checked first.
433    *
434    * @code
435    *    auto newControl = Control::New();
436    *    newControl.SetResource( resourceUrl );
437    *    if ( newControl.IsResourceReady() )
438    *    {
439    *       // do something
440    *    }
441    *    else
442    *    {
443    *      newControl.ResourceReadySignal.Connect( .... )
444    *    }
445    * @endcode
446    *
447    * A callback of the following type may be connected:
448    * @code
449    *   void YourCallbackName( Control control );
450    * @endcode
451    *
452    * @SINCE_1_2.60
453    * @return The signal to connect to
454    * @note A RelayoutRequest is queued by Control before this signal is emitted
455    */
456   ResourceReadySignalType& ResourceReadySignal();
457
458 public: // Intended for control developers
459
460   /**
461    * @brief Creates an initialized Control.
462    *
463    * @SINCE_1_0.0
464    * @param[in] implementation The implementation for this control
465    * @return A handle to a newly allocated Dali resource
466    * @note Should NOT be called to create a handle from the implementation. As stated, this allocates a NEW Dali resource.
467    */
468   explicit Control(Internal::Control& implementation);
469
470   /**
471    * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
472    * using an Internal CustomActor pointer.
473    *
474    * @SINCE_1_0.0
475    * @param[in] internal A pointer to a newly allocated Dali resource
476    */
477   explicit Control(Dali::Internal::CustomActor* internal);
478
479 public: // Templates for Deriving Classes
480
481   /**
482    * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
483    *
484    * @tparam     T      The handle class
485    * @tparam     I      The implementation class
486    * @SINCE_1_0.0
487    * @param[in] handle Handle to an object
488    * @return Handle to a class T or an uninitialized handle
489    * @see DownCast(BaseHandle)
490    */
491   template<typename T, typename I>
492   DALI_INTERNAL static T DownCast( BaseHandle handle )
493   {
494     T result;
495
496     CustomActor custom = Dali::CustomActor::DownCast( handle );
497     if ( custom )
498     {
499       CustomActorImpl& customImpl = custom.GetImplementation();
500
501       I* impl = dynamic_cast<I*>(&customImpl);
502
503       if (impl)
504       {
505         result = T(customImpl.GetOwner());
506       }
507     }
508
509     return result;
510   }
511
512   /**
513    * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
514    * implementation of their class.
515    *
516    * @tparam     I       The implementation class
517    * @SINCE_1_0.0
518    * @param[in] internal Pointer to the Internal::CustomActor
519    */
520   template<typename I>
521   DALI_INTERNAL void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
522   {
523     // Can have a NULL pointer so we only need to check if the internal implementation is our class
524     // when there is a value.
525     if (internal)
526     {
527       DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
528     }
529   }
530
531 };
532
533 /**
534  * @}
535  */
536 } // namespace Toolkit
537
538 } // namespace Dali
539
540 #endif // DALI_TOOLKIT_CONTROL_H