(SuperBlurView) Ensure the image can be set as a property
[platform/core/uifw/dali-toolkit.git] / capi / dali-toolkit / public-api / controls / control.h
1 #ifndef __DALI_TOOLKIT_CONTROL_H__
2 #define __DALI_TOOLKIT_CONTROL_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_CONTROLS_MODULE
22  * @{
23  */
24
25 // INTERNAL INCLUDES
26 #include <dali/dali.h>
27
28 namespace Dali DALI_IMPORT_API
29 {
30
31 namespace Toolkit
32 {
33
34 //Forward declarations.
35
36 class ControlImpl;
37
38 /**
39  * @brief Control is the base class for all controls.
40  *
41  * The implementation of the control must be supplied; see ControlImpl for more details.
42  * @see ControlImpl
43  */
44 class Control : public CustomActor, public ConnectionTrackerInterface
45 {
46 public:
47
48   // Action Names
49   static const char* const ACTION_CONTROL_ACTIVATED; ///< name "control-activated"
50
51   // Signal Names
52   static const char* const SIGNAL_KEY_EVENT;         ///< name "key-event"
53
54   /**
55    * @brief Describes how a control could be resized.
56    */
57   enum SizePolicy
58   {
59     Fixed,    ///< Size can't grow or shrink.
60     Minimum,  ///< Size can grow but shrink up to a minimum level.
61     Maximum,  ///< Size can shrink but grow up to a maximum value.
62     Range,    ///< Size can grow or shrink between a minimum and a maximum values.
63     Flexible, ///< Size can grow or shrink with no limits.
64   };
65
66   /**
67    * @brief Describes what a control should do when a contained actor/control exceeds the boundary of the control.
68    */
69   enum ExceedPolicy
70   {
71     Crop,   ///< Control's contents will be cropped.
72     Shrink, ///< Control's contents will be shrunk.
73     Scroll  ///< Control's contents will be added to a scroll.
74   };
75
76   /**
77    * @brief Describes the direction to move the keyboard focus towards.
78    */
79   enum KeyboardFocusNavigationDirection
80   {
81     Left,   ///< Move keyboard focus towards the left direction
82     Right,  ///< Move keyboard focus towards the right direction
83     Up,     ///< Move keyboard focus towards the up direction
84     Down    ///< Move keyboard focus towards the down direction
85   };
86
87   // Typedefs
88
89   /// @brief Key Event signal type;
90   typedef SignalV2<bool ( Control, const KeyEvent& ) > KeyEventSignalV2;
91
92 public: // Creation & Destruction
93
94   /**
95    * @brief Create a new instance of a Control.
96    *
97    * @return A handle to a new Control.
98    */
99   static Control New();
100
101   /**
102    * @brief Create an uninitialized Control handle.
103    *
104    * Only derived versions can be instantiated.  Calling member
105    * functions with an uninitialized Dali::Object is not allowed.
106    */
107   Control();
108
109   /**
110    * @brief Copy constructor.
111    *
112    * Creates another handle that points to the same real object
113    * @param[in] uiControl Handle to copy
114    */
115   Control(const Control& uiControl);
116
117   /**
118    * @brief Virtual destructor.
119    *
120    * Dali::Object derived classes do not contain member data.
121    */
122   virtual ~Control();
123
124 public: // operators
125
126   /**
127    * @brief Assignment operator.
128    *
129    * Changes this handle to point to another real object
130    * @param[in] handle Object to assign this to
131    * @return reference to this
132    */
133   Control& operator=( const Control& handle );
134
135 public:
136
137   /**
138    * @brief Downcast an Object handle to Control.
139    *
140    * If handle points to a Control the downcast produces valid
141    * handle. If not the returned handle is left uninitialized.
142    *
143    * @param[in] handle Handle to an object
144    * @return handle to a Control or an uninitialized handle
145    */
146   static Control DownCast( BaseHandle handle );
147
148   /**
149    * @brief Retrieve the Control implementation.
150    *
151    * @return The implementation.
152    */
153   ControlImpl& GetImplementation();
154
155   /**
156    * @brief Retrieve the Control implementation.
157    *
158    * @return The implementation.
159    */
160   const ControlImpl& GetImplementation() const;
161
162   /**
163    * @brief Sets the size policies for the width and height dimensions.
164    *
165    * @param[in] widthPolicy Size policy for the width dimension.
166    * @param[in] heightPolicy Size policy for the height dimension.
167    */
168   void SetSizePolicy( SizePolicy widthPolicy, SizePolicy heightPolicy );
169
170   /**
171    * @brief Retrieves the size policies for the width and height dimensions.
172    *
173    * @param[out] widthPolicy Width's size policy.
174    * @param[out] heightPolicy Height's size policy.
175    */
176   void GetSizePolicy( SizePolicy& widthPolicy, SizePolicy& heightPolicy ) const;
177
178   /**
179    * @brief Sets the minimum size for the control.
180    *
181    * @param[in] size The minimum size.
182    */
183   void SetMinimumSize( const Vector3& size );
184
185   /**
186    * @brief Retrieves the minimum size.
187    *
188    * @return The minimum size.
189    */
190   const Vector3& GetMinimumSize() const;
191
192   /**
193    * @brief Sets the maximum size.
194    *
195    * @param[in] size The maximum size.
196    */
197   void SetMaximumSize( const Vector3& size );
198
199   /**
200    * @brief Retrieves the maximum size.
201    *
202    * @return The maximum size.
203    */
204   const Vector3& GetMaximumSize() const;
205
206   /**
207    * @brief Works out the natural size.
208    *
209    * Natural size is the control's size with any restriction.
210    *
211    * @return The natural size.
212    */
213   Vector3 GetNaturalSize();
214
215   /**
216    * @brief Works out the control's height for a given width.
217    *
218    * @param[in] width The control's width.
219    *
220    * @return The control's height for the given width.
221    */
222   float GetHeightForWidth( float width );
223
224   /**
225    * @brief Works out the control's width for a given height.
226    *
227    * @param[in] height The control's height.
228    *
229    * @return The control's width for the given height.
230    */
231   float GetWidthForHeight( float height );
232
233   /**
234    * @brief This sets the control to receive key events.
235    *
236    * The key event can originate from a virtual or physical keyboard.
237    * @pre The Control has been initialized.
238    * @pre The Control should be on the stage before setting keyboard focus.
239    * @return True if the control has foucs, False otherwise.
240    */
241   void SetKeyInputFocus();
242
243   /**
244    * @brief Quries whether the control has key input focus.
245    *
246    * 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.
247    * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
248    * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
249    * controls above it in the focus stack.
250    * To query for the conrol which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor()
251    * @pre The Control has been initialized.
252    * @pre The Control should be on the stage before setting keyboard focus.
253    * @return true if this control has keyboard input focus
254    */
255   bool HasKeyInputFocus();
256
257   /**
258    * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
259    *
260    * A check is performed to ensure it was previously set, if this check fails then nothing is done.
261    * @pre The Actor has been initialized.
262    */
263   void ClearKeyInputFocus();
264
265   /**
266    * @brief Retrieves the pinch gesture detector of the control.
267    *
268    * @return The pinch gesture detector.
269    * @pre Pinch detection should have been enabled in the control.
270    */
271   PinchGestureDetector GetPinchGestureDetector() const;
272
273   /**
274    * @brief Retrieves the pan gesture detector of the control.
275    *
276    * @return The pan gesture detector.
277    * @pre Pan detection should have been enabled in the control.
278    */
279   PanGestureDetector GetPanGestureDetector() const;
280
281   /**
282    * @brief Retrieves the tap gesture detector of the control.
283    *
284    * @return The tap gesture detector.
285    * @pre Tap detection should have been enabled in the control.
286    */
287   TapGestureDetector GetTapGestureDetector() const;
288
289   /**
290    * @brief Retrieves the long press gesture detector of the control.
291    *
292    * @return The long press gesture detector.
293    * @pre Long press detection should have been enabled in the control.
294    */
295   LongPressGestureDetector GetLongPressGestureDetector() const;
296
297 //signals
298 public:
299
300   /**
301    * @brief This signal is emitted when key event is received.
302    *
303    * A callback of the following type may be connected:
304    * @code
305    *   bool YourCallbackName(Control control, const KeyEvent& event);
306    * @endcode
307    * The return value of True, indicates that the touch event should be consumed.
308    * Otherwise the signal will be emitted on the next sensitive parent of the actor.
309    * @pre The Control has been initialized.
310    * @return The signal to connect to.
311    */
312   KeyEventSignalV2& KeyEventSignal();
313
314 protected:
315
316   /**
317    * @copydoc ConnectionTrackerInterface::SignalConnected
318    */
319   virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
320
321   /**
322    * @copydoc ConnectionTrackerInterface::SignalDisconnected
323    */
324   virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
325
326   /**
327    * @copydoc ConnectionTrackerInterface::GetConnectionCount
328    */
329   virtual std::size_t GetConnectionCount() const;
330
331 public: // Not intended for application developers
332
333   /**
334    * @brief Create an initialised Control.
335    *
336    * @param[in] implementation The implementation for this control.
337    * @return A handle to a newly allocated Dali resource.
338    */
339   Control(ControlImpl& implementation);
340
341   /**
342    * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
343    * using an Internal CustomActor pointer.
344    *
345    * @param [in] internal A pointer to a newly allocated Dali resource
346    */
347   Control(Dali::Internal::CustomActor* internal);
348
349 public: // Templates for Deriving Classes
350
351   /**
352    * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
353    *
354    * @tparam     T       The handle class
355    * @tparam     I       The implementation class
356    * @param[in]  handle  Handle to an object
357    * @return Handle to a class T or an uninitialized handle.
358    * @see DownCast(BaseHandle)
359    */
360   template<typename T, typename I>
361   static T DownCast( BaseHandle handle )
362   {
363     T result;
364
365     CustomActor custom = Dali::CustomActor::DownCast( handle );
366     if ( custom )
367     {
368       CustomActorImpl& customImpl = custom.GetImplementation();
369
370       I* impl = dynamic_cast<I*>(&customImpl);
371
372       if (impl)
373       {
374         result = T(customImpl.GetOwner());
375       }
376     }
377
378     return result;
379   }
380
381   /**
382    * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
383    * implementation of their class.
384    *
385    * @tparam     I         The implementation class
386    * @param[in]  internal  Pointer to the Internal::CustomActor
387    */
388   template<typename I>
389   void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
390   {
391     // Can have a NULL pointer so we only need to check if the internal implementation is our class
392     // when there is a value.
393     if (internal)
394     {
395       DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
396     }
397   }
398
399 };
400
401 } // namespace Toolkit
402
403 } // namespace Dali
404
405 /**
406  * @}
407  */
408 #endif // __DALI_TOOLKIT_CONTROL_H__