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
49 static const char* const ACTION_CONTROL_ACTIVATED; ///< name "control-activated"
52 static const char* const SIGNAL_KEY_EVENT; ///< name "key-event"
55 * @brief Describes how a control could be resized.
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.
67 * @brief Describes what a control should do when a contained actor/control exceeds the boundary of the control.
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.
77 * @brief Describes the direction to move the keyboard focus towards.
79 enum KeyboardFocusNavigationDirection
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
89 /// @brief Key Event signal type;
90 typedef SignalV2<bool ( Control, const KeyEvent& ) > KeyEventSignalV2;
92 public: // Creation & Destruction
95 * @brief Create a new instance of a Control.
97 * @return A handle to a new Control.
102 * @brief Create an uninitialized Control handle.
104 * Only derived versions can be instantiated. Calling member
105 * functions with an uninitialized Dali::Object is not allowed.
110 * @brief Copy constructor.
112 * Creates another handle that points to the same real object
113 * @param[in] uiControl Handle to copy
115 Control(const Control& uiControl);
118 * @brief Virtual destructor.
120 * Dali::Object derived classes do not contain member data.
127 * @brief Assignment operator.
129 * Changes this handle to point to another real object
130 * @param[in] handle Object to assign this to
131 * @return reference to this
133 Control& operator=( const Control& handle );
138 * @brief Downcast an Object handle to Control.
140 * If handle points to a Control the downcast produces valid
141 * handle. If not the returned handle is left uninitialized.
143 * @param[in] handle Handle to an object
144 * @return handle to a Control or an uninitialized handle
146 static Control DownCast( BaseHandle handle );
149 * @brief Retrieve the Control implementation.
151 * @return The implementation.
153 ControlImpl& GetImplementation();
156 * @brief Retrieve the Control implementation.
158 * @return The implementation.
160 const ControlImpl& GetImplementation() const;
163 * @brief Sets the size policies for the width and height dimensions.
165 * @param[in] widthPolicy Size policy for the width dimension.
166 * @param[in] heightPolicy Size policy for the height dimension.
168 void SetSizePolicy( SizePolicy widthPolicy, SizePolicy heightPolicy );
171 * @brief Retrieves the size policies for the width and height dimensions.
173 * @param[out] widthPolicy Width's size policy.
174 * @param[out] heightPolicy Height's size policy.
176 void GetSizePolicy( SizePolicy& widthPolicy, SizePolicy& heightPolicy ) const;
179 * @brief Sets the minimum size for the control.
181 * @param[in] size The minimum size.
183 void SetMinimumSize( const Vector3& size );
186 * @brief Retrieves the minimum size.
188 * @return The minimum size.
190 const Vector3& GetMinimumSize() const;
193 * @brief Sets the maximum size.
195 * @param[in] size The maximum size.
197 void SetMaximumSize( const Vector3& size );
200 * @brief Retrieves the maximum size.
202 * @return The maximum size.
204 const Vector3& GetMaximumSize() const;
207 * @brief Works out the natural size.
209 * Natural size is the control's size with any restriction.
211 * @return The natural size.
213 Vector3 GetNaturalSize();
216 * @brief Works out the control's height for a given width.
218 * @param[in] width The control's width.
220 * @return The control's height for the given width.
222 float GetHeightForWidth( float width );
225 * @brief Works out the control's width for a given height.
227 * @param[in] height The control's height.
229 * @return The control's width for the given height.
231 float GetWidthForHeight( float height );
234 * @brief This sets the control to receive key events.
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.
241 void SetKeyInputFocus();
244 * @brief Quries whether the control has key input focus.
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
255 bool HasKeyInputFocus();
258 * @brief Once an actor is Set to receive key input focus this function is called to stop it receiving key events.
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.
263 void ClearKeyInputFocus();
266 * @brief Retrieves the pinch gesture detector of the control.
268 * @return The pinch gesture detector.
269 * @pre Pinch detection should have been enabled in the control.
271 PinchGestureDetector GetPinchGestureDetector() const;
274 * @brief Retrieves the pan gesture detector of the control.
276 * @return The pan gesture detector.
277 * @pre Pan detection should have been enabled in the control.
279 PanGestureDetector GetPanGestureDetector() const;
282 * @brief Retrieves the tap gesture detector of the control.
284 * @return The tap gesture detector.
285 * @pre Tap detection should have been enabled in the control.
287 TapGestureDetector GetTapGestureDetector() const;
290 * @brief Retrieves the long press gesture detector of the control.
292 * @return The long press gesture detector.
293 * @pre Long press detection should have been enabled in the control.
295 LongPressGestureDetector GetLongPressGestureDetector() const;
301 * @brief This signal is emitted when key event is received.
303 * A callback of the following type may be connected:
305 * bool YourCallbackName(Control control, const KeyEvent& event);
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.
312 KeyEventSignalV2& KeyEventSignal();
317 * @copydoc ConnectionTrackerInterface::SignalConnected
319 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
322 * @copydoc ConnectionTrackerInterface::SignalDisconnected
324 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
327 * @copydoc ConnectionTrackerInterface::GetConnectionCount
329 virtual std::size_t GetConnectionCount() const;
331 public: // Not intended for application developers
334 * @brief Create an initialised Control.
336 * @param[in] implementation The implementation for this control.
337 * @return A handle to a newly allocated Dali resource.
339 Control(ControlImpl& implementation);
342 * @brief This constructor is used by CustomActor within Dali core to create additional Control handles
343 * using an Internal CustomActor pointer.
345 * @param [in] internal A pointer to a newly allocated Dali resource
347 Control(Dali::Internal::CustomActor* internal);
349 public: // Templates for Deriving Classes
352 * @brief Template to allow deriving controls to DownCast handles to deriving handle classes.
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)
360 template<typename T, typename I>
361 static T DownCast( BaseHandle handle )
365 CustomActor custom = Dali::CustomActor::DownCast( handle );
368 CustomActorImpl& customImpl = custom.GetImplementation();
370 I* impl = dynamic_cast<I*>(&customImpl);
374 result = T(customImpl.GetOwner());
382 * @brief Template to allow deriving controls to verify whether the Internal::CustomActor* is actually an
383 * implementation of their class.
385 * @tparam I The implementation class
386 * @param[in] internal Pointer to the Internal::CustomActor
389 void VerifyCustomActorPointer(Dali::Internal::CustomActor* internal)
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.
395 DALI_ASSERT_DEBUG(dynamic_cast<I*>(&CustomActor(internal).GetImplementation()));
401 } // namespace Toolkit
408 #endif // __DALI_TOOLKIT_CONTROL_H__