1 #ifndef __DALI_TOOLKIT_CONTROL_H__
2 #define __DALI_TOOLKIT_CONTROL_H__
5 * Copyright (c) 2014 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 * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
27 #include <dali/dali.h>
29 namespace Dali DALI_IMPORT_API
35 //Forward declarations.
43 * @brief Control is the base class for all controls.
45 * The implementation of the control must be supplied; see Internal::Control for more details.
46 * @see Internal::Control
48 class Control : public CustomActor, public ConnectionTrackerInterface
54 static const Property::Index PROPERTY_BACKGROUND_COLOR; ///< name "background-color", @see SetBackgroundColor, type VECTOR4
55 static const Property::Index PROPERTY_BACKGROUND; ///< name "background", @see SetBackground, type MAP
56 static const Property::Index PROPERTY_WIDTH_POLICY; ///< name "width-policy", @see SetSizePolicy, type STRING
57 static const Property::Index PROPERTY_HEIGHT_POLICY; ///< name "height-policy", @see SetSizePolicy, type STRING
58 static const Property::Index PROPERTY_MINIMUM_SIZE; ///< name "minimum-size", @see SetMinimumSize, type VECTOR3
59 static const Property::Index PROPERTY_MAXIMUM_SIZE; ///< name "maximum-size", @see SetMaximumSize, type VECTOR3
60 static const Property::Index PROPERTY_KEY_INPUT_FOCUS; ///< name "key-input-focus", @see SetKeyInputFocus, type BOOLEAN
65 static const char* const SIGNAL_KEY_EVENT; ///< name "key-event"
70 static const char* const ACTION_CONTROL_ACTIVATED; ///< name "control-activated"
74 * @brief Describes how a control could be resized.
78 Fixed, ///< Size can't grow or shrink.
79 Minimum, ///< Size can grow but shrink up to a minimum level.
80 Maximum, ///< Size can shrink but grow up to a maximum value.
81 Range, ///< Size can grow or shrink between a minimum and a maximum values.
82 Flexible, ///< Size can grow or shrink with no limits.
86 * @brief Describes what a control should do when a contained actor/control exceeds the boundary of the control.
90 Crop, ///< Control's contents will be cropped.
91 Shrink, ///< Control's contents will be shrunk.
92 Scroll ///< Control's contents will be added to a scroll.
96 * @brief Describes the direction to move the keyboard focus towards.
98 enum KeyboardFocusNavigationDirection
100 Left, ///< Move keyboard focus towards the left direction
101 Right, ///< Move keyboard focus towards the right direction
102 Up, ///< Move keyboard focus towards the up direction
103 Down ///< Move keyboard focus towards the down direction
108 /// @brief Key Event signal type;
109 typedef SignalV2<bool ( Control, const KeyEvent& ) > KeyEventSignalV2;
111 public: // Creation & Destruction
114 * @brief Create a new instance of a Control.
116 * @return A handle to a new Control.
118 static Control New();
121 * @brief Create an uninitialized Control handle.
123 * Only derived versions can be instantiated. Calling member
124 * functions with an uninitialized Dali::Object is not allowed.
129 * @brief Copy constructor.
131 * Creates another handle that points to the same real object
132 * @param[in] uiControl Handle to copy
134 Control(const Control& uiControl);
137 * @brief Virtual destructor.
139 * Dali::Object derived classes do not contain member data.
146 * @brief Assignment operator.
148 * Changes this handle to point to another real object
149 * @param[in] handle Object to assign this to
150 * @return reference to this
152 Control& operator=( const Control& handle );
157 * @brief Downcast an Object handle to Control.
159 * If handle points to a Control the downcast produces valid
160 * handle. If not the returned handle is left uninitialized.
162 * @param[in] handle Handle to an object
163 * @return handle to a Control or an uninitialized handle
165 static Control DownCast( BaseHandle handle );
168 * @brief Retrieve the Control implementation.
170 * @return The implementation.
172 Internal::Control& GetImplementation();
175 * @brief Retrieve the Control implementation.
177 * @return The implementation.
179 const Internal::Control& GetImplementation() const;
184 * @brief Sets the size policies for the width and height dimensions.
186 * @param[in] widthPolicy Size policy for the width dimension.
187 * @param[in] heightPolicy Size policy for the height dimension.
189 void SetSizePolicy( SizePolicy widthPolicy, SizePolicy heightPolicy );
192 * @brief Retrieves the size policies for the width and height dimensions.
194 * @param[out] widthPolicy Width's size policy.
195 * @param[out] heightPolicy Height's size policy.
197 void GetSizePolicy( SizePolicy& widthPolicy, SizePolicy& heightPolicy ) const;
200 * @brief Sets the minimum size for the control.
202 * @param[in] size The minimum size.
204 void SetMinimumSize( const Vector3& size );
207 * @brief Retrieves the minimum size.
209 * @return The minimum size.
211 const Vector3& GetMinimumSize() const;
214 * @brief Sets the maximum size.
216 * @param[in] size The maximum size.
218 void SetMaximumSize( const Vector3& size );
221 * @brief Retrieves the maximum size.
223 * @return The maximum size.
225 const Vector3& GetMaximumSize() const;
228 * @brief Works out the natural size.
230 * Natural size is the control's size with any restriction.
232 * @return The natural size.
234 Vector3 GetNaturalSize();
237 * @brief Works out the control's height for a given width.
239 * @param[in] width The control's width.
241 * @return The control's height for the given width.
243 float GetHeightForWidth( float width );
246 * @brief Works out the control's width for a given height.
248 * @param[in] height The control's height.
250 * @return The control's width for the given height.
252 float GetWidthForHeight( float height );
257 * @brief This sets the control to receive key events.
259 * The key event can originate from a virtual or physical keyboard.
260 * @pre The Control has been initialized.
261 * @pre The Control should be on the stage before setting keyboard focus.
262 * @return True if the control has foucs, False otherwise.
264 void SetKeyInputFocus();
267 * @brief Quries whether the control has key input focus.
269 * 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.
270 * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
271 * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
272 * controls above it in the focus stack.
273 * To query for the conrol which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor()
274 * @pre The Control has been initialized.
275 * @pre The Control should be on the stage before setting keyboard focus.
276 * @return true if this control has keyboard input focus
278 bool HasKeyInputFocus();
281 * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
283 * A check is performed to ensure it was previously set, if this check fails then nothing is done.
284 * @pre The Actor has been initialized.
286 void ClearKeyInputFocus();
291 * @brief Retrieves the pinch gesture detector of the control.
293 * @return The pinch gesture detector.
294 * @pre Pinch detection should have been enabled in the control.
296 PinchGestureDetector GetPinchGestureDetector() const;
299 * @brief Retrieves the pan gesture detector of the control.
301 * @return The pan gesture detector.
302 * @pre Pan detection should have been enabled in the control.
304 PanGestureDetector GetPanGestureDetector() const;
307 * @brief Retrieves the tap gesture detector of the control.
309 * @return The tap gesture detector.
310 * @pre Tap detection should have been enabled in the control.
312 TapGestureDetector GetTapGestureDetector() const;
315 * @brief Retrieves the long press gesture detector of the control.
317 * @return The long press gesture detector.
318 * @pre Long press detection should have been enabled in the control.
320 LongPressGestureDetector GetLongPressGestureDetector() const;
325 * @brief Sets the background color of the control.
327 * @param[in] color The required background color of the control
329 void SetBackgroundColor( const Vector4& color );
332 * @brief Retrieves the background color of the control.
334 * @return The background color of the control.
336 Vector4 GetBackgroundColor() const;
339 * @brief Sets an image as the background of the control.
341 * The color of this image is blended with the background color @see SetBackgroundColor
343 * @param[in] image The image to set as the background.
345 void SetBackground( Image image );
348 * @brief Clears the background.
350 void ClearBackground();
353 * @brief Retrieves the actor used as the background for this control.
355 * @return The actor that used as the background for this control.
357 Actor GetBackgroundActor() const;
362 * @brief This signal is emitted when key event is received.
364 * A callback of the following type may be connected:
366 * bool YourCallbackName(Control control, const KeyEvent& event);
368 * The return value of True, indicates that the touch event should be consumed.
369 * Otherwise the signal will be emitted on the next sensitive parent of the actor.
370 * @pre The Control has been initialized.
371 * @return The signal to connect to.
373 KeyEventSignalV2& KeyEventSignal();
378 * @copydoc ConnectionTrackerInterface::SignalConnected
380 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
383 * @copydoc ConnectionTrackerInterface::SignalDisconnected
385 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
388 * @copydoc ConnectionTrackerInterface::GetConnectionCount
390 virtual std::size_t GetConnectionCount() const;
392 public: // Not intended for application developers
395 * @brief Create an initialised Control.
397 * @param[in] implementation The implementation for this control.
398 * @return A handle to a newly allocated Dali resource.
400 Control(Internal::Control& implementation);
403 * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
404 * using an Internal CustomActor pointer.
406 * @param [in] internal A pointer to a newly allocated Dali resource
408 Control(Dali::Internal::CustomActor* internal);
410 public: // Templates for Deriving Classes
413 * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
415 * @tparam T The handle class
416 * @tparam I The implementation class
417 * @param[in] handle Handle to an object
418 * @return Handle to a class T or an uninitialized handle.
419 * @see DownCast(BaseHandle)
421 template<typename T, typename I>
422 static T DownCast( BaseHandle handle )
426 CustomActor custom = Dali::CustomActor::DownCast( handle );
429 CustomActorImpl& customImpl = custom.GetImplementation();
431 I* impl = dynamic_cast<I*>(&customImpl);
435 result = T(customImpl.GetOwner());
443 * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
444 * implementation of their class.
446 * @tparam I The implementation class
447 * @param[in] internal Pointer to the Internal::CustomActor
450 void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
452 // Can have a NULL pointer so we only need to check if the internal implementation is our class
453 // when there is a value.
456 DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
462 } // namespace Toolkit
469 #endif // __DALI_TOOLKIT_CONTROL_H__