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 the accessibility
104 * @param[in] touchEvent The touch event.
105 * @return true if the touch event has been consumed by this control
107 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
110 * @brief This method should be overridden by deriving classes when they wish to respond
111 * the accessibility up and down action (i.e. value change of slider control).
113 * @param[in] isIncrease Whether the value should be increased or decreased
114 * @return true if the value changed action has been consumed by this control
116 virtual bool OnAccessibilityValueChange(bool isIncrease);
119 * @brief Sets whether this control supports two dimensional
120 * keyboard navigation (i.e. whether it knows how to handle the
121 * keyboardn focus movement between its child actors).
123 * The control doesn't support it by default.
124 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
126 void SetKeyboardNavigationSupport(bool isSupported);
129 * @brief Gets whether this control supports two dimensional keyboard navigation.
131 * @return true if this control supports two dimensional keyboard navigation.
133 bool IsKeyboardNavigationSupported();
136 * @brief Sets whether this control is a focus group for keyboard navigation.
138 * (i.e. the scope of keyboard focus movement
139 * can be limitied to its child actors). The control is not a focus group by default.
140 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
142 void SetAsKeyboardFocusGroup(bool isFocusGroup);
145 * @brief Gets whether this control is a focus group for keyboard navigation.
147 * @return true if this control is set as a focus group for keyboard navigation.
149 bool IsKeyboardFocusGroup();
152 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
154 * A control needs to override this function in order to support two dimensional keyboard navigation.
155 * @param[in] currentFocusedActor The current focused actor.
156 * @param[in] direction The direction to move the focus towards.
157 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
158 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
160 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
163 * @brief Informs this control that its chosen focusable actor will be focused.
165 * This allows the application to preform any actions if wishes
166 * before the focus is actually moved to the chosen actor.
168 * @param[in] commitedFocusableActor The commited focusable actor.
170 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
173 * @brief Performs actions as requested using the action name.
175 * @param[in] object The object on which to perform the action.
176 * @param[in] actionName The action to perform.
177 * @param[in] attributes The attributes with which to perfrom this action.
178 * @return true if action has been accepted by this control
180 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
183 * @brief If deriving classes wish to fine tune pinch gesture
184 * detection then they can access the gesture detector through this
185 * API and modify the detection.
187 * @return The pinch gesture detector.
188 * @pre Pinch detection should have been enabled via EnableGestureDetection().
189 * @see EnableGestureDetection
191 PinchGestureDetector GetPinchGestureDetector() const;
194 * @brief If deriving classes wish to fine tune pan gesture
195 * detection then they can access the gesture detector through this
196 * API and modify the detection.
198 * @return The pan gesture detector.
199 * @pre Pan detection should have been enabled via EnableGestureDetection().
200 * @see EnableGestureDetection
202 PanGestureDetector GetPanGestureDetector() const;
205 * @brief If deriving classes wish to fine tune tap gesture
206 * detection then they can access the gesture detector through this
207 * API and modify the detection.
209 * @return The tap gesture detector.
210 * @pre Tap detection should have been enabled via EnableGestureDetection().
211 * @see EnableGestureDetection
213 TapGestureDetector GetTapGestureDetector() const;
216 * @brief If deriving classes wish to fine tune long press gesture
217 * detection then they can access the gesture detector through this
218 * API and modify the detection.
220 * @return The long press gesture detector.
221 * @pre Long press detection should have been enabled via EnableGestureDetection().
222 * @see EnableGestureDetection
224 LongPressGestureDetector GetLongPressGestureDetector() const;
229 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
231 void SetBackgroundColor( const Vector4& color );
234 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
236 Vector4 GetBackgroundColor() const;
239 * @copydoc Dali::Toolkit::Control::SetBackground
241 void SetBackground( Image image );
244 * @copydoc Dali::Toolkit::Control::ClearBackground
246 void ClearBackground();
249 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
251 Actor GetBackgroundActor() const;
256 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
258 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
265 * @brief Second phase initialization.
272 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
274 * Gesture detection can be enabled one at a time or in bitwise format as shown:
276 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
278 * @param[in] type The gesture type(s) to enable.
280 void EnableGestureDetection(Gesture::Type type);
283 * @brief Allows deriving classes to disable any of the gesture detectors.
285 * Like EnableGestureDetection, this can also be called using bitwise or.
286 * @param[in] type The gesture type(s) to disable.
287 * @see EnableGetureDetection
289 void DisableGestureDetection(Gesture::Type type);
291 private: // For derived classes to override
294 * @brief This method is called after the Control has been initialized.
296 * Derived classes should do any second phase initialization by
297 * overriding this method.
299 virtual void OnInitialize() { }
302 * @brief Callback for when the theme changes.
304 virtual void OnThemeChange( Toolkit::StyleManager styleManager );
307 * @brief Called whenever a pinch gesture is detected on this control.
309 * This can be overridden by deriving classes when pinch detection
310 * is enabled. The default behaviour is to scale the control by the
313 * @note If overridden, then the default behaviour will not occur.
314 * @note Pinch detection should be enabled via EnableGestureDetection().
315 * @param[in] pinch The pinch gesture.
316 * @see EnableGestureDetection
318 virtual void OnPinch(PinchGesture pinch);
321 * @brief Called whenever a pan gesture is detected on this control.
323 * This should be overridden by deriving classes when pan detection
326 * @note There is no default behaviour with panning.
327 * @note Pan detection should be enabled via EnableGestureDetection().
328 * @param[in] pan The pan gesture.
329 * @see EnableGestureDetection
331 virtual void OnPan(PanGesture pan) { }
334 * @brief Called whenever a tap gesture is detected on this control.
336 * This should be overridden by deriving classes when tap detection
339 * @note There is no default behaviour with a tap.
340 * @note Tap detection should be enabled via EnableGestureDetection().
341 * @param[in] tap The tap gesture.
342 * @see EnableGestureDetection
344 virtual void OnTap(TapGesture tap) { }
347 * @brief Called whenever a long press gesture is detected on this control.
349 * This should be overridden by deriving classes when long press
350 * detection is enabled.
352 * @note There is no default behaviour associated with a long press.
353 * @note Long press detection should be enabled via EnableGestureDetection().
354 * @param[in] longPress The long press gesture.
355 * @see EnableGestureDetection
357 virtual void OnLongPress(LongPressGesture longPress) { }
360 * @brief Called whenever the control is added to the stage.
362 * Could be overridden by derived classes.
364 virtual void OnControlStageConnection() { }
367 * @brief Called whenever the control is removed from the stage.
369 * Could be overridden by derived classes.
371 virtual void OnControlStageDisconnection() { }
374 * @brief Called whenever an Actor is added to the control.
376 * Could be overridden by derived classes.
378 * @param[in] child The added actor.
380 virtual void OnControlChildAdd( Actor& child ) { }
383 * @brief Called whenever an Actor is removed from the control.
385 * Could be overridden by derived classes.
387 * @param[in] child The removed actor.
389 virtual void OnControlChildRemove( Actor& child ) { }
392 * @brief Called whenever the Control's size is set.
394 * Could be overridden by derived classes.
396 * @param[in] size The new size.
398 virtual void OnControlSizeSet( const Vector3& size ) { }
401 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
402 * signal is emitted if this control requested to be relaid-out.
404 * Should be overridden by derived classes if they need to layout
405 * actors differently after certain operations like add or remove
406 * actors, resize or after changing especific properties.
408 * @param[in] size The allocated size.
409 * @param[in,out] container The control should add actors to this container that it is not able
410 * to allocate a size for.
412 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
414 private: // From CustomActorImpl, derived classes can override these.
417 * @brief Sends a request to relayout this control.
419 * The control will be relaid out after the
420 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
422 * It calls OnControlStageConnection() to notify derived classes.
424 * @see Dali::CustomActorImpl::OnStageConnection()
426 virtual void OnStageConnection();
429 * @brief Calls OnControlStageDisconnection() to notify derived classed.
431 * @see Dali::CustomActorImpl::OnStageDisconnection()
433 virtual void OnStageDisconnection();
436 * @brief Sends a request to relayout this control.
438 * The control will be relaid out after the
439 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
440 * calls OnControlChildAdd() to notify derived classes.
442 * @note This method shouldn't be overridden by derived classes.
444 * @param[in] child The added actor.
446 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
448 virtual void OnChildAdd(Actor& child);
451 * @brief Sends a request to relayout this control.
453 * The control will be relaid out after the
454 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
455 * calls OnControlChildRemove() to notify derived classes.
457 * @note This method shouldn't be overridden by derived classes.
459 * @param[in] child The removed actor.
461 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
463 virtual void OnChildRemove(Actor& child);
466 * @brief It stores the size set by size negotiation and relayout.
468 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
469 * It calls the OnControlSizeSet() to notify derived classes.
471 * @param[in] targetSize The new size.
473 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
475 virtual void OnSizeSet(const Vector3& targetSize);
478 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
480 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
483 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
485 virtual bool OnTouchEvent(const TouchEvent& event);
488 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
490 virtual bool OnKeyEvent(const KeyEvent& event);
493 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
495 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
498 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
500 virtual void OnKeyInputFocusGained();
503 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
505 virtual void OnKeyInputFocusLost();
508 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
510 virtual Actor GetChildByAlias(const std::string& actorAlias);
515 * @brief Perform the activated action.
517 * @param[in] attributes The attributes to perfrom this action.
519 void DoActivatedAction(const PropertyValueContainer& attributes);
521 protected: // Construction
523 // Flags for the constructor
524 enum ControlBehaviour
526 CONTROL_BEHAVIOUR_NONE = 0x0,
527 REQUIRES_TOUCH_EVENTS = 0x1, ///< True if the OnTouchEvent() callback is required.
528 REQUIRES_THEME_CHANGE_SIGNALS = 0x2 ///< True if this control should listen to theme change signals
532 * @deprecated Use the constructor taking flags instead
533 * @brief Create a Control.
535 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
537 Control(bool requiresTouchEvents);
540 * @brief Create a Control.
542 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
544 Control(ControlBehaviour behaviourFlags);
551 * @copydoc Toolkit::Control::SetSizePolicy()
553 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
556 * @copydoc Toolkit::Control::GetSizePolicy()
558 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
561 * @copydoc Toolkit::Control::SetMinimumSize()
563 void SetMinimumSize( const Vector3& size );
566 * @copydoc Toolkit::Control::GetMinimumSize()
568 const Vector3& GetMinimumSize() const;
571 * @copydoc Toolkit::Control::SetMaximumSize()
573 void SetMaximumSize( const Vector3& size );
576 * @copydoc Toolkit::Control::GetMaximumSize()
578 const Vector3& GetMaximumSize() const;
581 * @copydoc Toolkit::Control::GetNaturalSize()
583 virtual Vector3 GetNaturalSize();
586 * @copydoc Toolkit::Control::GetHeightForWidth()
588 virtual float GetHeightForWidth( float width );
591 * @copydoc Toolkit::Control::GetWidthForHeight()
593 virtual float GetWidthForHeight( float height );
596 * @brief Retrieves the current Control's size.
598 * @return The control's size.
600 const Vector3& GetControlSize() const;
603 * @brief Retrieves the Control's size set by the Application / Control.
605 * @return The control's size.
607 const Vector3& GetSizeSet() const;
612 * @copydoc Toolkit::Control::SetKeyInputFocus()
614 void SetKeyInputFocus();
617 * @copydoc Toolkit::Control::HasKeyInputFocus()
619 bool HasKeyInputFocus();
622 * @copydoc Toolkit::Control::ClearKeyInputFocus()
624 void ClearKeyInputFocus();
627 * @copydoc ConnectionTrackerInterface::SignalConnected
629 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
632 * @copydoc ConnectionTrackerInterface::SignalDisconnected
634 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
637 * @copydoc ConnectionTrackerInterface::GetConnectionCount
639 virtual std::size_t GetConnectionCount() const;
644 * @brief Sends a request to be relaid-out.
646 * This method is called from OnStageConnection(), OnChildAdd(),
647 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
650 * This method could also be called from derived classes every time
651 * a control's poperty change and it needs to be relaid-out. After
652 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
653 * relayout process starts and all controls which called this method
654 * will be relaid-out.
656 * @note RelayoutRequest() only sends a request per Control before
657 * the Dali::Stage::SignalMessageQueueFlushed() signal is
658 * emitted. That means a control will be relaid-out only once, even
659 * if more than one request is sent between two consecutive signals.
661 void RelayoutRequest();
664 * @brief Helper method for controls to Relayout their children if
665 * they do not know whether that child is a control or not.
667 * @param[in] actor The actor to relayout.
668 * @param[in] size The size to allocate to the actor.
669 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
671 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
673 private: // Used by the RelayoutController
676 * @brief Called by the RelayoutController to negotiate the size of a control.
678 * The size allocated by the the algorithm is passed in which the
679 * control must adhere to. A container is passed in as well which
680 * the control should populate with actors it has not / or does not
681 * need to handle in its size negotiation.
683 * @param[in] size The allocated size.
684 * @param[in,out] container The container that holds actors that are fed back into the
685 * RelayoutController algorithm.
687 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
692 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
694 * It calls the OnRelaidOut() method which can be overridden by derived classes.
696 * @param[in] size The allocated size.
697 * @param[in,out] container The control should add actors to this container that it is not able
698 * to allocate a size for.
700 void Relayout( Vector2 size, ActorSizeContainer& container );
703 * @brief Used by the KeyInputFocusManager to emit key event signals.
705 * @param[in] event The key event.
706 * @return True if the event was consumed.
708 bool EmitKeyEventSignal(const KeyEvent& event);
715 Control(const Control&);
716 Control& operator=(const Control&);
721 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
722 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
725 } // namespace Internal
727 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
729 } // namespace Toolkit
736 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__