1 #ifndef __DALI_TOOLKIT_CONTROL_H__
2 #define __DALI_TOOLKIT_CONTROL_H__
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
11 // http://floralicense.org/license/
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.
21 * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
26 #include <dali/dali.h>
28 namespace Dali DALI_IMPORT_API
34 //Forward declarations.
39 * @brief Control is the base class for all controls.
41 * The implementation of the control must be supplied; see ControlImpl for more details.
44 class Control : public CustomActor, public ConnectionTrackerInterface
50 static const Property::Index PROPERTY_BACKGROUND_COLOR; ///< name "background-color", @see SetBackgroundColor, type VECTOR4
51 static const Property::Index PROPERTY_BACKGROUND; ///< name "background", @see SetBackground, type MAP
52 static const Property::Index PROPERTY_WIDTH_POLICY; ///< name "width-policy", @see SetSizePolicy, type STRING
53 static const Property::Index PROPERTY_HEIGHT_POLICY; ///< name "height-policy", @see SetSizePolicy, type STRING
54 static const Property::Index PROPERTY_MINIMUM_SIZE; ///< name "minimum-size", @see SetMinimumSize, type VECTOR3
55 static const Property::Index PROPERTY_MAXIMUM_SIZE; ///< name "maximum-size", @see SetMaximumSize, type VECTOR3
56 static const Property::Index PROPERTY_KEY_INPUT_FOCUS; ///< name "key-input-focus", @see SetKeyInputFocus, type BOOLEAN
61 static const char* const SIGNAL_KEY_EVENT; ///< name "key-event"
66 static const char* const ACTION_CONTROL_ACTIVATED; ///< name "control-activated"
70 * @brief Describes how a control could be resized.
74 Fixed, ///< Size can't grow or shrink.
75 Minimum, ///< Size can grow but shrink up to a minimum level.
76 Maximum, ///< Size can shrink but grow up to a maximum value.
77 Range, ///< Size can grow or shrink between a minimum and a maximum values.
78 Flexible, ///< Size can grow or shrink with no limits.
82 * @brief Describes what a control should do when a contained actor/control exceeds the boundary of the control.
86 Crop, ///< Control's contents will be cropped.
87 Shrink, ///< Control's contents will be shrunk.
88 Scroll ///< Control's contents will be added to a scroll.
92 * @brief Describes the direction to move the keyboard focus towards.
94 enum KeyboardFocusNavigationDirection
96 Left, ///< Move keyboard focus towards the left direction
97 Right, ///< Move keyboard focus towards the right direction
98 Up, ///< Move keyboard focus towards the up direction
99 Down ///< Move keyboard focus towards the down direction
104 /// @brief Key Event signal type;
105 typedef SignalV2<bool ( Control, const KeyEvent& ) > KeyEventSignalV2;
107 public: // Creation & Destruction
110 * @brief Create a new instance of a Control.
112 * @return A handle to a new Control.
114 static Control New();
117 * @brief Create an uninitialized Control handle.
119 * Only derived versions can be instantiated. Calling member
120 * functions with an uninitialized Dali::Object is not allowed.
125 * @brief Copy constructor.
127 * Creates another handle that points to the same real object
128 * @param[in] uiControl Handle to copy
130 Control(const Control& uiControl);
133 * @brief Virtual destructor.
135 * Dali::Object derived classes do not contain member data.
142 * @brief Assignment operator.
144 * Changes this handle to point to another real object
145 * @param[in] handle Object to assign this to
146 * @return reference to this
148 Control& operator=( const Control& handle );
153 * @brief Downcast an Object handle to Control.
155 * If handle points to a Control the downcast produces valid
156 * handle. If not the returned handle is left uninitialized.
158 * @param[in] handle Handle to an object
159 * @return handle to a Control or an uninitialized handle
161 static Control DownCast( BaseHandle handle );
164 * @brief Retrieve the Control implementation.
166 * @return The implementation.
168 ControlImpl& GetImplementation();
171 * @brief Retrieve the Control implementation.
173 * @return The implementation.
175 const ControlImpl& GetImplementation() const;
180 * @brief Sets the size policies for the width and height dimensions.
182 * @param[in] widthPolicy Size policy for the width dimension.
183 * @param[in] heightPolicy Size policy for the height dimension.
185 void SetSizePolicy( SizePolicy widthPolicy, SizePolicy heightPolicy );
188 * @brief Retrieves the size policies for the width and height dimensions.
190 * @param[out] widthPolicy Width's size policy.
191 * @param[out] heightPolicy Height's size policy.
193 void GetSizePolicy( SizePolicy& widthPolicy, SizePolicy& heightPolicy ) const;
196 * @brief Sets the minimum size for the control.
198 * @param[in] size The minimum size.
200 void SetMinimumSize( const Vector3& size );
203 * @brief Retrieves the minimum size.
205 * @return The minimum size.
207 const Vector3& GetMinimumSize() const;
210 * @brief Sets the maximum size.
212 * @param[in] size The maximum size.
214 void SetMaximumSize( const Vector3& size );
217 * @brief Retrieves the maximum size.
219 * @return The maximum size.
221 const Vector3& GetMaximumSize() const;
224 * @brief Works out the natural size.
226 * Natural size is the control's size with any restriction.
228 * @return The natural size.
230 Vector3 GetNaturalSize();
233 * @brief Works out the control's height for a given width.
235 * @param[in] width The control's width.
237 * @return The control's height for the given width.
239 float GetHeightForWidth( float width );
242 * @brief Works out the control's width for a given height.
244 * @param[in] height The control's height.
246 * @return The control's width for the given height.
248 float GetWidthForHeight( float height );
253 * @brief This sets the control to receive key events.
255 * The key event can originate from a virtual or physical keyboard.
256 * @pre The Control has been initialized.
257 * @pre The Control should be on the stage before setting keyboard focus.
258 * @return True if the control has foucs, False otherwise.
260 void SetKeyInputFocus();
263 * @brief Quries whether the control has key input focus.
265 * 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.
266 * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
267 * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
268 * controls above it in the focus stack.
269 * To query for the conrol which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor()
270 * @pre The Control has been initialized.
271 * @pre The Control should be on the stage before setting keyboard focus.
272 * @return true if this control has keyboard input focus
274 bool HasKeyInputFocus();
277 * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
279 * A check is performed to ensure it was previously set, if this check fails then nothing is done.
280 * @pre The Actor has been initialized.
282 void ClearKeyInputFocus();
287 * @brief Retrieves the pinch gesture detector of the control.
289 * @return The pinch gesture detector.
290 * @pre Pinch detection should have been enabled in the control.
292 PinchGestureDetector GetPinchGestureDetector() const;
295 * @brief Retrieves the pan gesture detector of the control.
297 * @return The pan gesture detector.
298 * @pre Pan detection should have been enabled in the control.
300 PanGestureDetector GetPanGestureDetector() const;
303 * @brief Retrieves the tap gesture detector of the control.
305 * @return The tap gesture detector.
306 * @pre Tap detection should have been enabled in the control.
308 TapGestureDetector GetTapGestureDetector() const;
311 * @brief Retrieves the long press gesture detector of the control.
313 * @return The long press gesture detector.
314 * @pre Long press detection should have been enabled in the control.
316 LongPressGestureDetector GetLongPressGestureDetector() const;
321 * @brief Sets the background color of the control.
323 * @param[in] color The required background color of the control
325 void SetBackgroundColor( const Vector4& color );
328 * @brief Retrieves the background color of the control.
330 * @return The background color of the control.
332 Vector4 GetBackgroundColor() const;
335 * @brief Sets an image as the background of the control.
337 * The color of this image is blended with the background color @see SetBackgroundColor
339 * @param[in] image The image to set as the background.
341 void SetBackground( Image image );
344 * @brief Clears the background.
346 void ClearBackground();
349 * @brief Retrieves the actor used as the background for this control.
351 * @return The actor that used as the background for this control.
353 Actor GetBackgroundActor() const;
358 * @brief This signal is emitted when key event is received.
360 * A callback of the following type may be connected:
362 * bool YourCallbackName(Control control, const KeyEvent& event);
364 * The return value of True, indicates that the touch event should be consumed.
365 * Otherwise the signal will be emitted on the next sensitive parent of the actor.
366 * @pre The Control has been initialized.
367 * @return The signal to connect to.
369 KeyEventSignalV2& KeyEventSignal();
374 * @copydoc ConnectionTrackerInterface::SignalConnected
376 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
379 * @copydoc ConnectionTrackerInterface::SignalDisconnected
381 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
384 * @copydoc ConnectionTrackerInterface::GetConnectionCount
386 virtual std::size_t GetConnectionCount() const;
388 public: // Not intended for application developers
391 * @brief Create an initialised Control.
393 * @param[in] implementation The implementation for this control.
394 * @return A handle to a newly allocated Dali resource.
396 Control(ControlImpl& implementation);
399 * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
400 * using an Internal CustomActor pointer.
402 * @param [in] internal A pointer to a newly allocated Dali resource
404 Control(Dali::Internal::CustomActor* internal);
406 public: // Templates for Deriving Classes
409 * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
411 * @tparam T The handle class
412 * @tparam I The implementation class
413 * @param[in] handle Handle to an object
414 * @return Handle to a class T or an uninitialized handle.
415 * @see DownCast(BaseHandle)
417 template<typename T, typename I>
418 static T DownCast( BaseHandle handle )
422 CustomActor custom = Dali::CustomActor::DownCast( handle );
425 CustomActorImpl& customImpl = custom.GetImplementation();
427 I* impl = dynamic_cast<I*>(&customImpl);
431 result = T(customImpl.GetOwner());
439 * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
440 * implementation of their class.
442 * @tparam I The implementation class
443 * @param[in] internal Pointer to the Internal::CustomActor
446 void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
448 // Can have a NULL pointer so we only need to check if the internal implementation is our class
449 // when there is a value.
452 DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
458 } // namespace Toolkit
465 #endif // __DALI_TOOLKIT_CONTROL_H__