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
56 static const char* const SIGNAL_KEY_EVENT; ///< name "key-event"
61 static const char* const ACTION_CONTROL_ACTIVATED; ///< name "control-activated"
65 * @brief Describes how a control could be resized.
69 Fixed, ///< Size can't grow or shrink.
70 Minimum, ///< Size can grow but shrink up to a minimum level.
71 Maximum, ///< Size can shrink but grow up to a maximum value.
72 Range, ///< Size can grow or shrink between a minimum and a maximum values.
73 Flexible, ///< Size can grow or shrink with no limits.
77 * @brief Describes what a control should do when a contained actor/control exceeds the boundary of the control.
81 Crop, ///< Control's contents will be cropped.
82 Shrink, ///< Control's contents will be shrunk.
83 Scroll ///< Control's contents will be added to a scroll.
87 * @brief Describes the direction to move the keyboard focus towards.
89 enum KeyboardFocusNavigationDirection
91 Left, ///< Move keyboard focus towards the left direction
92 Right, ///< Move keyboard focus towards the right direction
93 Up, ///< Move keyboard focus towards the up direction
94 Down ///< Move keyboard focus towards the down direction
99 /// @brief Key Event signal type;
100 typedef SignalV2<bool ( Control, const KeyEvent& ) > KeyEventSignalV2;
102 public: // Creation & Destruction
105 * @brief Create a new instance of a Control.
107 * @return A handle to a new Control.
109 static Control New();
112 * @brief Create an uninitialized Control handle.
114 * Only derived versions can be instantiated. Calling member
115 * functions with an uninitialized Dali::Object is not allowed.
120 * @brief Copy constructor.
122 * Creates another handle that points to the same real object
123 * @param[in] uiControl Handle to copy
125 Control(const Control& uiControl);
128 * @brief Virtual destructor.
130 * Dali::Object derived classes do not contain member data.
137 * @brief Assignment operator.
139 * Changes this handle to point to another real object
140 * @param[in] handle Object to assign this to
141 * @return reference to this
143 Control& operator=( const Control& handle );
148 * @brief Downcast an Object handle to Control.
150 * If handle points to a Control the downcast produces valid
151 * handle. If not the returned handle is left uninitialized.
153 * @param[in] handle Handle to an object
154 * @return handle to a Control or an uninitialized handle
156 static Control DownCast( BaseHandle handle );
159 * @brief Retrieve the Control implementation.
161 * @return The implementation.
163 ControlImpl& GetImplementation();
166 * @brief Retrieve the Control implementation.
168 * @return The implementation.
170 const ControlImpl& GetImplementation() const;
175 * @brief Sets the size policies for the width and height dimensions.
177 * @param[in] widthPolicy Size policy for the width dimension.
178 * @param[in] heightPolicy Size policy for the height dimension.
180 void SetSizePolicy( SizePolicy widthPolicy, SizePolicy heightPolicy );
183 * @brief Retrieves the size policies for the width and height dimensions.
185 * @param[out] widthPolicy Width's size policy.
186 * @param[out] heightPolicy Height's size policy.
188 void GetSizePolicy( SizePolicy& widthPolicy, SizePolicy& heightPolicy ) const;
191 * @brief Sets the minimum size for the control.
193 * @param[in] size The minimum size.
195 void SetMinimumSize( const Vector3& size );
198 * @brief Retrieves the minimum size.
200 * @return The minimum size.
202 const Vector3& GetMinimumSize() const;
205 * @brief Sets the maximum size.
207 * @param[in] size The maximum size.
209 void SetMaximumSize( const Vector3& size );
212 * @brief Retrieves the maximum size.
214 * @return The maximum size.
216 const Vector3& GetMaximumSize() const;
219 * @brief Works out the natural size.
221 * Natural size is the control's size with any restriction.
223 * @return The natural size.
225 Vector3 GetNaturalSize();
228 * @brief Works out the control's height for a given width.
230 * @param[in] width The control's width.
232 * @return The control's height for the given width.
234 float GetHeightForWidth( float width );
237 * @brief Works out the control's width for a given height.
239 * @param[in] height The control's height.
241 * @return The control's width for the given height.
243 float GetWidthForHeight( float height );
248 * @brief This sets the control to receive key events.
250 * The key event can originate from a virtual or physical keyboard.
251 * @pre The Control has been initialized.
252 * @pre The Control should be on the stage before setting keyboard focus.
253 * @return True if the control has foucs, False otherwise.
255 void SetKeyInputFocus();
258 * @brief Quries whether the control has key input focus.
260 * 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.
261 * As the key input focus mechanism works like a stack, the top most control receives all the key events, and passes on the
262 * unhandled events to the controls below in the stack. A control in the stack will regain key input focus when there are no more
263 * controls above it in the focus stack.
264 * To query for the conrol which is on top of the focus stack use Dali::Toolkit::KeyInputFocusManager::GetCurrentKeyboardFocusActor()
265 * @pre The Control has been initialized.
266 * @pre The Control should be on the stage before setting keyboard focus.
267 * @return true if this control has keyboard input focus
269 bool HasKeyInputFocus();
272 * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
274 * A check is performed to ensure it was previously set, if this check fails then nothing is done.
275 * @pre The Actor has been initialized.
277 void ClearKeyInputFocus();
282 * @brief Retrieves the pinch gesture detector of the control.
284 * @return The pinch gesture detector.
285 * @pre Pinch detection should have been enabled in the control.
287 PinchGestureDetector GetPinchGestureDetector() const;
290 * @brief Retrieves the pan gesture detector of the control.
292 * @return The pan gesture detector.
293 * @pre Pan detection should have been enabled in the control.
295 PanGestureDetector GetPanGestureDetector() const;
298 * @brief Retrieves the tap gesture detector of the control.
300 * @return The tap gesture detector.
301 * @pre Tap detection should have been enabled in the control.
303 TapGestureDetector GetTapGestureDetector() const;
306 * @brief Retrieves the long press gesture detector of the control.
308 * @return The long press gesture detector.
309 * @pre Long press detection should have been enabled in the control.
311 LongPressGestureDetector GetLongPressGestureDetector() const;
316 * @brief Sets the background color of the control.
318 * @param[in] color The required background color of the control
320 void SetBackgroundColor( const Vector4& color );
323 * @brief Retrieves the background color of the control.
325 * @return The background color of the control.
327 Vector4 GetBackgroundColor() const;
330 * @brief Sets an image as the background of the control.
332 * The color of this image is blended with the background color @see SetBackgroundColor
334 * @param[in] image The image to set as the background.
336 void SetBackground( Image image );
339 * @brief Clears the background.
341 void ClearBackground();
344 * @brief Retrieves the actor used as the background for this control.
346 * @return The actor that used as the background for this control.
348 Actor GetBackgroundActor() const;
353 * @brief This signal is emitted when key event is received.
355 * A callback of the following type may be connected:
357 * bool YourCallbackName(Control control, const KeyEvent& event);
359 * The return value of True, indicates that the touch event should be consumed.
360 * Otherwise the signal will be emitted on the next sensitive parent of the actor.
361 * @pre The Control has been initialized.
362 * @return The signal to connect to.
364 KeyEventSignalV2& KeyEventSignal();
369 * @copydoc ConnectionTrackerInterface::SignalConnected
371 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
374 * @copydoc ConnectionTrackerInterface::SignalDisconnected
376 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
379 * @copydoc ConnectionTrackerInterface::GetConnectionCount
381 virtual std::size_t GetConnectionCount() const;
383 public: // Not intended for application developers
386 * @brief Create an initialised Control.
388 * @param[in] implementation The implementation for this control.
389 * @return A handle to a newly allocated Dali resource.
391 Control(ControlImpl& implementation);
394 * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
395 * using an Internal CustomActor pointer.
397 * @param [in] internal A pointer to a newly allocated Dali resource
399 Control(Dali::Internal::CustomActor* internal);
401 public: // Templates for Deriving Classes
404 * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
406 * @tparam T The handle class
407 * @tparam I The implementation class
408 * @param[in] handle Handle to an object
409 * @return Handle to a class T or an uninitialized handle.
410 * @see DownCast(BaseHandle)
412 template<typename T, typename I>
413 static T DownCast( BaseHandle handle )
417 CustomActor custom = Dali::CustomActor::DownCast( handle );
420 CustomActorImpl& customImpl = custom.GetImplementation();
422 I* impl = dynamic_cast<I*>(&customImpl);
426 result = T(customImpl.GetOwner());
434 * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
435 * implementation of their class.
437 * @tparam I The implementation class
438 * @param[in] internal Pointer to the Internal::CustomActor
441 void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
443 // Can have a NULL pointer so we only need to check if the internal implementation is our class
444 // when there is a value.
447 DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
453 } // namespace Toolkit
460 #endif // __DALI_TOOLKIT_CONTROL_H__