1 #ifndef __DALI_TOOLKIT_CONTROL_IMPL_H__
2 #define __DALI_TOOLKIT_CONTROL_IMPL_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-toolkit/public-api/controls/control.h>
28 namespace Dali DALI_IMPORT_API
36 namespace Internal DALI_INTERNAL
38 class RelayoutControllerImpl;
39 class KeyInputFocusManager;
42 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
43 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
49 * @brief This is the internal base class for all controls.
51 * It will provide some common functionality required by all controls.
52 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
53 * be disconnected automatically when the control is destroyed.
55 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
62 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
63 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
69 * @brief Create a new ControlImpl instance that does not require touch by default.
71 * If touch is required then the user can connect to this class' touch signal.
72 * @return A handle to the ConntrolImpl instance.
74 static Toolkit::Control New();
79 * @brief Virtual destructor.
86 * @brief This method should be overridden by deriving classes when they wish to be notified when they
89 virtual void OnActivated() { }
92 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
95 * @param[in] gesture The pan gesture.
96 * @return true if the pan gesture has been consumed by this control
98 virtual bool OnAccessibilityPan(PanGesture gesture);
101 * @brief This method should be overridden by deriving classes when they wish to respond
102 * the accessibility up and down action (i.e. value change of slider control).
104 * @param[in] isIncrease Whether the value should be increased or decreased
105 * @return true if the value changed action has been consumed by this control
107 virtual bool OnAccessibilityValueChange(bool isIncrease);
110 * @brief Sets whether this control supports two dimensional
111 * keyboard navigation (i.e. whether it knows how to handle the
112 * keyboardn focus movement between its child actors).
114 * The control doesn't support it by default.
115 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
117 void SetKeyboardNavigationSupport(bool isSupported);
120 * @brief Gets whether this control supports two dimensional keyboard navigation.
122 * @return true if this control supports two dimensional keyboard navigation.
124 bool IsKeyboardNavigationSupported();
127 * @brief Sets whether this control is a focus group for keyboard navigation.
129 * (i.e. the scope of keyboard focus movement
130 * can be limitied to its child actors). The control is not a focus group by default.
131 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
133 void SetAsKeyboardFocusGroup(bool isFocusGroup);
136 * @brief Gets whether this control is a focus group for keyboard navigation.
138 * @return true if this control is set as a focus group for keyboard navigation.
140 bool IsKeyboardFocusGroup();
143 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
145 * A control needs to override this function in order to support two dimensional keyboard navigation.
146 * @param[in] currentFocusedActor The current focused actor.
147 * @param[in] direction The direction to move the focus towards.
148 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
149 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
151 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
154 * @brief Informs this control that its chosen focusable actor will be focused.
156 * This allows the application to preform any actions if wishes
157 * before the focus is actually moved to the chosen actor.
159 * @param[in] commitedFocusableActor The commited focusable actor.
161 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
164 * @brief Performs actions as requested using the action name.
166 * @param[in] object The object on which to perform the action.
167 * @param[in] actionName The action to perform.
168 * @param[in] attributes The attributes with which to perfrom this action.
169 * @return true if action has been accepted by this control
171 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
174 * @brief If deriving classes wish to fine tune pinch gesture
175 * detection then they can access the gesture detector through this
176 * API and modify the detection.
178 * @return The pinch gesture detector.
179 * @pre Pinch detection should have been enabled via EnableGestureDetection().
180 * @see EnableGestureDetection
182 PinchGestureDetector GetPinchGestureDetector() const;
185 * @brief If deriving classes wish to fine tune pan gesture
186 * detection then they can access the gesture detector through this
187 * API and modify the detection.
189 * @return The pan gesture detector.
190 * @pre Pan detection should have been enabled via EnableGestureDetection().
191 * @see EnableGestureDetection
193 PanGestureDetector GetPanGestureDetector() const;
196 * @brief If deriving classes wish to fine tune tap gesture
197 * detection then they can access the gesture detector through this
198 * API and modify the detection.
200 * @return The tap gesture detector.
201 * @pre Tap detection should have been enabled via EnableGestureDetection().
202 * @see EnableGestureDetection
204 TapGestureDetector GetTapGestureDetector() const;
207 * @brief If deriving classes wish to fine tune long press gesture
208 * detection then they can access the gesture detector through this
209 * API and modify the detection.
211 * @return The long press gesture detector.
212 * @pre Long press detection should have been enabled via EnableGestureDetection().
213 * @see EnableGestureDetection
215 LongPressGestureDetector GetLongPressGestureDetector() const;
220 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
222 void SetBackgroundColor( const Vector4& color );
225 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
227 Vector4 GetBackgroundColor() const;
230 * @copydoc Dali::Toolkit::Control::SetBackground
232 void SetBackground( Image image );
235 * @copydoc Dali::Toolkit::Control::ClearBackground
237 void ClearBackground();
240 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
242 Actor GetBackgroundActor() const;
247 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
249 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
256 * @brief Second phase initialization.
263 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
265 * Gesture detection can be enabled one at a time or in bitwise format as shown:
267 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
269 * @param[in] type The gesture type(s) to enable.
271 void EnableGestureDetection(Gesture::Type type);
274 * @brief Allows deriving classes to disable any of the gesture detectors.
276 * Like EnableGestureDetection, this can also be called using bitwise or.
277 * @param[in] type The gesture type(s) to disable.
278 * @see EnableGetureDetection
280 void DisableGestureDetection(Gesture::Type type);
282 private: // For derived classes to override
285 * @brief This method is called after the Control has been initialized.
287 * Derived classes should do any second phase initialization by
288 * overriding this method.
290 virtual void OnInitialize() { }
293 * @brief Callback for when the theme changes.
295 virtual void OnThemeChange( Toolkit::StyleManager styleManager );
298 * @brief Called whenever a pinch gesture is detected on this control.
300 * This can be overridden by deriving classes when pinch detection
301 * is enabled. The default behaviour is to scale the control by the
304 * @note If overridden, then the default behaviour will not occur.
305 * @note Pinch detection should be enabled via EnableGestureDetection().
306 * @param[in] pinch The pinch gesture.
307 * @see EnableGestureDetection
309 virtual void OnPinch(PinchGesture pinch);
312 * @brief Called whenever a pan gesture is detected on this control.
314 * This should be overridden by deriving classes when pan detection
317 * @note There is no default behaviour with panning.
318 * @note Pan detection should be enabled via EnableGestureDetection().
319 * @param[in] pan The pan gesture.
320 * @see EnableGestureDetection
322 virtual void OnPan(PanGesture pan) { }
325 * @brief Called whenever a tap gesture is detected on this control.
327 * This should be overridden by deriving classes when tap detection
330 * @note There is no default behaviour with a tap.
331 * @note Tap detection should be enabled via EnableGestureDetection().
332 * @param[in] tap The tap gesture.
333 * @see EnableGestureDetection
335 virtual void OnTap(TapGesture tap) { }
338 * @brief Called whenever a long press gesture is detected on this control.
340 * This should be overridden by deriving classes when long press
341 * detection is enabled.
343 * @note There is no default behaviour associated with a long press.
344 * @note Long press detection should be enabled via EnableGestureDetection().
345 * @param[in] longPress The long press gesture.
346 * @see EnableGestureDetection
348 virtual void OnLongPress(LongPressGesture longPress) { }
351 * @brief Called whenever the control is added to the stage.
353 * Could be overridden by derived classes.
355 virtual void OnControlStageConnection() { }
358 * @brief Called whenever the control is removed from the stage.
360 * Could be overridden by derived classes.
362 virtual void OnControlStageDisconnection() { }
365 * @brief Called whenever an Actor is added to the control.
367 * Could be overridden by derived classes.
369 * @param[in] child The added actor.
371 virtual void OnControlChildAdd( Actor& child ) { }
374 * @brief Called whenever an Actor is removed from the control.
376 * Could be overridden by derived classes.
378 * @param[in] child The removed actor.
380 virtual void OnControlChildRemove( Actor& child ) { }
383 * @brief Called whenever the Control's size is set.
385 * Could be overridden by derived classes.
387 * @param[in] size The new size.
389 virtual void OnControlSizeSet( const Vector3& size ) { }
392 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
393 * signal is emitted if this control requested to be relaid-out.
395 * Should be overridden by derived classes if they need to layout
396 * actors differently after certain operations like add or remove
397 * actors, resize or after changing especific properties.
399 * @param[in] size The allocated size.
400 * @param[in,out] container The control should add actors to this container that it is not able
401 * to allocate a size for.
403 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
405 private: // From CustomActorImpl, derived classes can override these.
408 * @brief Sends a request to relayout this control.
410 * The control will be relaid out after the
411 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
413 * It calls OnControlStageConnection() to notify derived classes.
415 * @see Dali::CustomActorImpl::OnStageConnection()
417 virtual void OnStageConnection();
420 * @brief Calls OnControlStageDisconnection() to notify derived classed.
422 * @see Dali::CustomActorImpl::OnStageDisconnection()
424 virtual void OnStageDisconnection();
427 * @brief Sends a request to relayout this control.
429 * The control will be relaid out after the
430 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
431 * calls OnControlChildAdd() to notify derived classes.
433 * @note This method shouldn't be overridden by derived classes.
435 * @param[in] child The added actor.
437 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
439 virtual void OnChildAdd(Actor& child);
442 * @brief Sends a request to relayout this control.
444 * The control will be relaid out after the
445 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
446 * calls OnControlChildRemove() to notify derived classes.
448 * @note This method shouldn't be overridden by derived classes.
450 * @param[in] child The removed actor.
452 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
454 virtual void OnChildRemove(Actor& child);
457 * @brief It stores the size set by size negotiation and relayout.
459 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
460 * It calls the OnControlSizeSet() to notify derived classes.
462 * @param[in] targetSize The new size.
464 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
466 virtual void OnSizeSet(const Vector3& targetSize);
469 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
471 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
474 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
476 virtual bool OnTouchEvent(const TouchEvent& event);
479 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
481 virtual bool OnKeyEvent(const KeyEvent& event);
484 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
486 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
489 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
491 virtual void OnKeyInputFocusGained();
494 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
496 virtual void OnKeyInputFocusLost();
499 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
501 virtual Actor GetChildByAlias(const std::string& actorAlias);
506 * @brief Perform the activated action.
508 * @param[in] attributes The attributes to perfrom this action.
510 void DoActivatedAction(const PropertyValueContainer& attributes);
512 protected: // Construction
514 // Flags for the constructor
515 enum ControlBehaviour
517 CONTROL_BEHAVIOUR_NONE = 0x0,
518 REQUIRES_TOUCH_EVENTS = 0x1, ///< True if the OnTouchEvent() callback is required.
519 REQUIRES_THEME_CHANGE_SIGNALS = 0x2 ///< True if this control should listen to theme change signals
523 * @deprecated Use the constructor taking flags instead
524 * @brief Create a Control.
526 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
528 Control(bool requiresTouchEvents);
531 * @brief Create a Control.
533 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
535 Control(ControlBehaviour behaviourFlags);
542 * @copydoc Toolkit::Control::SetSizePolicy()
544 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
547 * @copydoc Toolkit::Control::GetSizePolicy()
549 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
552 * @copydoc Toolkit::Control::SetMinimumSize()
554 void SetMinimumSize( const Vector3& size );
557 * @copydoc Toolkit::Control::GetMinimumSize()
559 const Vector3& GetMinimumSize() const;
562 * @copydoc Toolkit::Control::SetMaximumSize()
564 void SetMaximumSize( const Vector3& size );
567 * @copydoc Toolkit::Control::GetMaximumSize()
569 const Vector3& GetMaximumSize() const;
572 * @copydoc Toolkit::Control::GetNaturalSize()
574 virtual Vector3 GetNaturalSize();
577 * @copydoc Toolkit::Control::GetHeightForWidth()
579 virtual float GetHeightForWidth( float width );
582 * @copydoc Toolkit::Control::GetWidthForHeight()
584 virtual float GetWidthForHeight( float height );
587 * @brief Retrieves the current Control's size.
589 * @return The control's size.
591 const Vector3& GetControlSize() const;
594 * @brief Retrieves the Control's size set by the Application / Control.
596 * @return The control's size.
598 const Vector3& GetSizeSet() const;
603 * @copydoc Toolkit::Control::SetKeyInputFocus()
605 void SetKeyInputFocus();
608 * @copydoc Toolkit::Control::HasKeyInputFocus()
610 bool HasKeyInputFocus();
613 * @copydoc Toolkit::Control::ClearKeyInputFocus()
615 void ClearKeyInputFocus();
618 * @copydoc ConnectionTrackerInterface::SignalConnected
620 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
623 * @copydoc ConnectionTrackerInterface::SignalDisconnected
625 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
628 * @copydoc ConnectionTrackerInterface::GetConnectionCount
630 virtual std::size_t GetConnectionCount() const;
635 * @brief Sends a request to be relaid-out.
637 * This method is called from OnStageConnection(), OnChildAdd(),
638 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
641 * This method could also be called from derived classes every time
642 * a control's poperty change and it needs to be relaid-out. After
643 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
644 * relayout process starts and all controls which called this method
645 * will be relaid-out.
647 * @note RelayoutRequest() only sends a request per Control before
648 * the Dali::Stage::SignalMessageQueueFlushed() signal is
649 * emitted. That means a control will be relaid-out only once, even
650 * if more than one request is sent between two consecutive signals.
652 void RelayoutRequest();
655 * @brief Helper method for controls to Relayout their children if
656 * they do not know whether that child is a control or not.
658 * @param[in] actor The actor to relayout.
659 * @param[in] size The size to allocate to the actor.
660 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
662 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
664 private: // Used by the RelayoutController
667 * @brief Called by the RelayoutController to negotiate the size of a control.
669 * The size allocated by the the algorithm is passed in which the
670 * control must adhere to. A container is passed in as well which
671 * the control should populate with actors it has not / or does not
672 * need to handle in its size negotiation.
674 * @param[in] size The allocated size.
675 * @param[in,out] container The container that holds actors that are fed back into the
676 * RelayoutController algorithm.
678 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
683 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
685 * It calls the OnRelaidOut() method which can be overridden by derived classes.
687 * @param[in] size The allocated size.
688 * @param[in,out] container The control should add actors to this container that it is not able
689 * to allocate a size for.
691 void Relayout( Vector2 size, ActorSizeContainer& container );
694 * @brief Used by the KeyInputFocusManager to emit key event signals.
696 * @param[in] event The key event.
697 * @return True if the event was consumed.
699 bool EmitKeyEventSignal(const KeyEvent& event);
706 Control(const Control&);
707 Control& operator=(const Control&);
712 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
713 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
716 } // namespace Internal
718 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
720 } // namespace Toolkit
727 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__