1 #ifndef __DALI_TOOLKIT_CONTROL_H__
2 #define __DALI_TOOLKIT_CONTROL_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
37 //Forward declarations.
44 * @addtogroup dali_toolkit_controls
49 * @brief Control is the base class for all controls.
51 * The implementation of the control must be supplied; see Internal::Control for more details.
53 * @see Internal::Control
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() |
67 * | %Action Name | %Control method called |
68 * |------------------------|----------------------------------------------------|
69 * | accessibilityActivated | %OnAccessibilityActivated() |
71 class DALI_IMPORT_API Control : public CustomActor
76 * @brief The start and end property ranges for control.
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
87 * @brief An enumeration of properties belonging to the Control class.
95 * @brief name "styleName", type std::string
99 STYLE_NAME = PROPERTY_START_INDEX,
102 * @brief name "background-color", mutually exclusive with BACKGROUND_IMAGE & BACKGROUND, type Vector4
109 * @brief name "background-image", mutually exclusive with BACKGROUND_COLOR & BACKGROUND, type Map
114 * @brief name "keyInputFocus", type bool
116 * @see SetKeyInputFocus
120 * @brief name "background", mutually exclusive with BACKGROUND_COLOR & BACKGROUND_IMAGE, type Map or std::string for URL
128 * @brief Describes the direction to move the keyboard focus towards.
134 * @brief Keyboard focus direction
139 LEFT, ///< Move keyboard focus towards the left direction @SINCE_1_0.0
140 RIGHT, ///< Move keyboard focus towards the right direction @SINCE_1_0.0
141 UP, ///< Move keyboard focus towards the up direction @SINCE_1_0.0
142 DOWN ///< Move keyboard focus towards the down direction @SINCE_1_0.0
148 /// @brief Key Event signal type;
149 typedef Signal<bool ( Control, const KeyEvent& ) > KeyEventSignalType;
151 /// @brief Key InputFocusType signal type;
152 typedef Signal<void ( Control ) > KeyInputFocusSignalType;
154 public: // Creation & Destruction
157 * @brief Create a new instance of a Control.
160 * @return A handle to a new Control.
162 static Control New();
165 * @brief Create an uninitialized Control handle.
167 * Only derived versions can be instantiated. Calling member
168 * functions with an uninitialized Dali::Object is not allowed.
174 * @brief Copy constructor.
176 * Creates another handle that points to the same real object.
178 * @param[in] uiControl Handle to copy
180 Control(const Control& uiControl);
183 * @brief Dali::Control is intended as a base class.
185 * This is non-virtual since derived Handle types must not contain data or virtual methods.
193 * @brief Assignment operator.
195 * Changes this handle to point to another real object.
197 * @param[in] handle Object to assign this to
198 * @return reference to this
200 Control& operator=( const Control& handle );
205 * @brief Downcast a handle to Control handle.
207 * If handle points to a Control the downcast produces valid
208 * handle. If not the returned handle is left uninitialized.
211 * @param[in] handle Handle to an object
212 * @return A handle to a Control or an uninitialized handle
214 static Control DownCast( BaseHandle handle );
219 * @brief This sets the control to receive key events.
221 * The key event can originate from a virtual or physical keyboard.
223 * @pre The Control has been initialized.
224 * @pre The Control should be on the stage before setting keyboard focus.
226 void SetKeyInputFocus();
229 * @brief Quries whether the control has key input focus.
232 * @return true if this control has keyboard input focus
233 * @pre The Control has been initialized.
234 * @pre The Control should be on the stage before setting keyboard focus.
235 * @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.
236 * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
237 * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
238 * controls above it in the focus stack.
239 * To query for the conrol which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor().
241 bool HasKeyInputFocus();
244 * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
246 * A check is performed to ensure it was previously set, if this check fails then nothing is done.
248 * @pre The Actor has been initialized.
250 void ClearKeyInputFocus();
255 * @brief Retrieves the pinch gesture detector of the control.
258 * @return The pinch gesture detector.
259 * @note Will return an empty handle if the control does not handle the gesture itself.
261 PinchGestureDetector GetPinchGestureDetector() const;
264 * @brief Retrieves the pan gesture detector of the control.
267 * @return The pan gesture detector.
268 * @note Will return an empty handle if the control does not handle the gesture itself.
270 PanGestureDetector GetPanGestureDetector() const;
273 * @brief Retrieves the tap gesture detector of the control.
276 * @return The tap gesture detector.
277 * @note Will return an empty handle if the control does not handle the gesture itself.
279 TapGestureDetector GetTapGestureDetector() const;
282 * @brief Retrieves the long press gesture detector of the control.
285 * @return The long press gesture detector.
286 * @note Will return an empty handle if the control does not handle the gesture itself.
288 LongPressGestureDetector GetLongPressGestureDetector() const;
293 * @brief Sets the name of the style to be applied to the control.
296 * @param[in] styleName A string matching a style described in a stylesheet.
298 void SetStyleName( const std::string& styleName );
301 * @brief Retrieves the name of the style to be applied to the control (if any).
303 * @return A string matching a style or an empty string.
305 const std::string& GetStyleName() const;
310 * @brief Sets the background color of the control.
313 * @param[in] color The required background color of the control
315 * @note if SetBackgroundImage is called later, this background color is removed.
317 * @note The background color fully blends with the actor color.
319 void SetBackgroundColor( const Vector4& color );
324 * @brief Retrieves the background color of the control.
327 * @return The background color of the control.
329 Vector4 GetBackgroundColor() const;
332 * @DEPRECATED_1_2.8, use Property::BACKGROUND instead
334 * @brief Sets an image as the background of the control.
337 * @param[in] image The image to set as the background.
339 void SetBackgroundImage( Image image );
342 * @brief Clears the background.
345 void ClearBackground();
350 * @brief This signal is emitted when key event is received.
352 * A callback of the following type may be connected:
354 * bool YourCallbackName(Control control, const KeyEvent& event);
356 * The return value of True, indicates that the event should be consumed.
357 * Otherwise the signal will be emitted on the next parent of the actor.
359 * @return The signal to connect to.
360 * @pre The Control has been initialized.
362 KeyEventSignalType& KeyEventSignal();
365 * @brief This signal is emitted when the control gets Key Input Focus.
367 * A callback of the following type may be connected:
369 * bool YourCallbackName( Control control );
371 * The return value of True, indicates that the event should be consumed.
372 * Otherwise the signal will be emitted on the next parent of the actor.
374 * @return The signal to connect to.
375 * @pre The Control has been initialized.
377 KeyInputFocusSignalType& KeyInputFocusGainedSignal();
380 * @brief This signal is emitted when the control loses Key Input Focus
381 * which could be due to it being gained by another Control or Actor or just cleared from
382 * this control as no longer required.
384 * A callback of the following type may be connected:
386 * bool YourCallbackName( Control control );
388 * The return value of True, indicates that the event should be consumed.
389 * Otherwise the signal will be emitted on the next parent of the actor.
391 * @return The signal to connect to.
392 * @pre The Control has been initialized.
394 KeyInputFocusSignalType& KeyInputFocusLostSignal();
396 public: // Intended for control developers
399 * @brief Create an initialised Control.
402 * @param[in] implementation The implementation for this control.
403 * @return A handle to a newly allocated Dali resource.
405 * @note Should NOT be called to create a handle from the implementation. As stated, this allocates a NEW Dali resource.
407 explicit Control(Internal::Control& implementation);
410 * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
411 * using an Internal CustomActor pointer.
414 * @param [in] internal A pointer to a newly allocated Dali resource
416 explicit Control(Dali::Internal::CustomActor* internal);
418 public: // Templates for Deriving Classes
421 * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
423 * @tparam T The handle class
424 * @tparam I The implementation class
426 * @param[in] handle Handle to an object
427 * @return Handle to a class T or an uninitialized handle.
428 * @see DownCast(BaseHandle)
430 template<typename T, typename I>
431 DALI_INTERNAL static T DownCast( BaseHandle handle )
435 CustomActor custom = Dali::CustomActor::DownCast( handle );
438 CustomActorImpl& customImpl = custom.GetImplementation();
440 I* impl = dynamic_cast<I*>(&customImpl);
444 result = T(customImpl.GetOwner());
452 * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
453 * implementation of their class.
455 * @tparam I The implementation class
457 * @param[in] internal Pointer to the Internal::CustomActor
460 DALI_INTERNAL void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
462 // Can have a NULL pointer so we only need to check if the internal implementation is our class
463 // when there is a value.
466 DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
475 } // namespace Toolkit
479 #endif // __DALI_TOOLKIT_CONTROL_H__