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 StyleChangeProcessor;
39 class RelayoutControllerImpl;
40 class KeyInputFocusManager;
43 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
44 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
50 * @brief This is the internal base class for all controls.
52 * It will provide some common functionality required by all controls.
53 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
54 * be disconnected automatically when the control is destroyed.
56 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
63 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
64 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
70 * @brief Create a new ControlImpl instance that does not require touch by default.
72 * If touch is required then the user can connect to this class' touch signal.
73 * @return A handle to the ConntrolImpl instance.
75 static Toolkit::Control New();
80 * @brief Virtual destructor.
87 * @brief This method should be overridden by deriving classes when they wish to be notified when they
90 virtual void OnActivated() { }
93 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
96 * @param[in] gesture The pan gesture.
97 * @return true if the pan gesture has been consumed by this control
99 virtual bool OnAccessibilityPan(PanGesture gesture);
102 * @brief This method should be overridden by deriving classes when they wish to respond
103 * the accessibility up and down action (i.e. value change of slider control).
105 * @param[in] isIncrease Whether the value should be increased or decreased
106 * @return true if the value changed action has been consumed by this control
108 virtual bool OnAccessibilityValueChange(bool isIncrease);
111 * @brief Sets whether this control supports two dimensional
112 * keyboard navigation (i.e. whether it knows how to handle the
113 * keyboardn focus movement between its child actors).
115 * The control doesn't support it by default.
116 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
118 void SetKeyboardNavigationSupport(bool isSupported);
121 * @brief Gets whether this control supports two dimensional keyboard navigation.
123 * @return true if this control supports two dimensional keyboard navigation.
125 bool IsKeyboardNavigationSupported();
128 * @brief Sets whether this control is a focus group for keyboard navigation.
130 * (i.e. the scope of keyboard focus movement
131 * can be limitied to its child actors). The control is not a focus group by default.
132 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
134 void SetAsKeyboardFocusGroup(bool isFocusGroup);
137 * @brief Gets whether this control is a focus group for keyboard navigation.
139 * @return true if this control is set as a focus group for keyboard navigation.
141 bool IsKeyboardFocusGroup();
144 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
146 * A control needs to override this function in order to support two dimensional keyboard navigation.
147 * @param[in] currentFocusedActor The current focused actor.
148 * @param[in] direction The direction to move the focus towards.
149 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
150 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
152 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
155 * @brief Informs this control that its chosen focusable actor will be focused.
157 * This allows the application to preform any actions if wishes
158 * before the focus is actually moved to the chosen actor.
160 * @param[in] commitedFocusableActor The commited focusable actor.
162 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
165 * @brief Performs actions as requested using the action name.
167 * @param[in] object The object on which to perform the action.
168 * @param[in] actionName The action to perform.
169 * @param[in] attributes The attributes with which to perfrom this action.
170 * @return true if action has been accepted by this control
172 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
175 * @brief If deriving classes wish to fine tune pinch gesture
176 * detection then they can access the gesture detector through this
177 * API and modify the detection.
179 * @return The pinch gesture detector.
180 * @pre Pinch detection should have been enabled via EnableGestureDetection().
181 * @see EnableGestureDetection
183 PinchGestureDetector GetPinchGestureDetector() const;
186 * @brief If deriving classes wish to fine tune pan gesture
187 * detection then they can access the gesture detector through this
188 * API and modify the detection.
190 * @return The pan gesture detector.
191 * @pre Pan detection should have been enabled via EnableGestureDetection().
192 * @see EnableGestureDetection
194 PanGestureDetector GetPanGestureDetector() const;
197 * @brief If deriving classes wish to fine tune tap gesture
198 * detection then they can access the gesture detector through this
199 * API and modify the detection.
201 * @return The tap gesture detector.
202 * @pre Tap detection should have been enabled via EnableGestureDetection().
203 * @see EnableGestureDetection
205 TapGestureDetector GetTapGestureDetector() const;
208 * @brief If deriving classes wish to fine tune long press gesture
209 * detection then they can access the gesture detector through this
210 * API and modify the detection.
212 * @return The long press gesture detector.
213 * @pre Long press detection should have been enabled via EnableGestureDetection().
214 * @see EnableGestureDetection
216 LongPressGestureDetector GetLongPressGestureDetector() const;
221 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
223 void SetBackgroundColor( const Vector4& color );
226 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
228 Vector4 GetBackgroundColor() const;
231 * @copydoc Dali::Toolkit::Control::SetBackground
233 void SetBackground( Image image );
236 * @copydoc Dali::Toolkit::Control::ClearBackground
238 void ClearBackground();
241 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
243 Actor GetBackgroundActor() const;
248 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
250 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
257 * @brief Second phase initialization.
264 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
266 * Gesture detection can be enabled one at a time or in bitwise format as shown:
268 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
270 * @param[in] type The gesture type(s) to enable.
272 void EnableGestureDetection(Gesture::Type type);
275 * @brief Allows deriving classes to disable any of the gesture detectors.
277 * Like EnableGestureDetection, this can also be called using bitwise or.
278 * @param[in] type The gesture type(s) to disable.
279 * @see EnableGetureDetection
281 void DisableGestureDetection(Gesture::Type type);
283 private: // For derived classes to override
286 * @brief This method is called after the Control has been initialized.
288 * Derived classes should do any second phase initialization by
289 * overriding this method.
291 virtual void OnInitialize() { }
294 * @brief This method should be overridden by deriving classes when
295 * they wish to be notified when the style changes.
297 * @param[in] change Information denoting what has changed.
299 virtual void OnStyleChange(StyleChange change) { }
302 * @brief Called whenever a pinch gesture is detected on this control.
304 * This can be overridden by deriving classes when pinch detection
305 * is enabled. The default behaviour is to scale the control by the
308 * @note If overridden, then the default behaviour will not occur.
309 * @note Pinch detection should be enabled via EnableGestureDetection().
310 * @param[in] pinch The pinch gesture.
311 * @see EnableGestureDetection
313 virtual void OnPinch(PinchGesture pinch);
316 * @brief Called whenever a pan gesture is detected on this control.
318 * This should be overridden by deriving classes when pan detection
321 * @note There is no default behaviour with panning.
322 * @note Pan detection should be enabled via EnableGestureDetection().
323 * @param[in] pan The pan gesture.
324 * @see EnableGestureDetection
326 virtual void OnPan(PanGesture pan) { }
329 * @brief Called whenever a tap gesture is detected on this control.
331 * This should be overridden by deriving classes when tap detection
334 * @note There is no default behaviour with a tap.
335 * @note Tap detection should be enabled via EnableGestureDetection().
336 * @param[in] tap The tap gesture.
337 * @see EnableGestureDetection
339 virtual void OnTap(TapGesture tap) { }
342 * @brief Called whenever a long press gesture is detected on this control.
344 * This should be overridden by deriving classes when long press
345 * detection is enabled.
347 * @note There is no default behaviour associated with a long press.
348 * @note Long press detection should be enabled via EnableGestureDetection().
349 * @param[in] longPress The long press gesture.
350 * @see EnableGestureDetection
352 virtual void OnLongPress(LongPressGesture longPress) { }
355 * @brief Called whenever the control is added to the stage.
357 * Could be overridden by derived classes.
359 virtual void OnControlStageConnection() { }
362 * @brief Called whenever the control is removed from the stage.
364 * Could be overridden by derived classes.
366 virtual void OnControlStageDisconnection() { }
369 * @brief Called whenever an Actor is added to the control.
371 * Could be overridden by derived classes.
373 * @param[in] child The added actor.
375 virtual void OnControlChildAdd( Actor& child ) { }
378 * @brief Called whenever an Actor is removed from the control.
380 * Could be overridden by derived classes.
382 * @param[in] child The removed actor.
384 virtual void OnControlChildRemove( Actor& child ) { }
387 * @brief Called whenever the Control's size is set.
389 * Could be overridden by derived classes.
391 * @param[in] size The new size.
393 virtual void OnControlSizeSet( const Vector3& size ) { }
396 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
397 * signal is emitted if this control requested to be relaid-out.
399 * Should be overridden by derived classes if they need to layout
400 * actors differently after certain operations like add or remove
401 * actors, resize or after changing especific properties.
403 * @param[in] size The allocated size.
404 * @param[in,out] container The control should add actors to this container that it is not able
405 * to allocate a size for.
407 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
409 private: // From CustomActorImpl, derived classes can override these.
412 * @brief Sends a request to relayout this control.
414 * The control will be relaid out after the
415 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
417 * It calls OnControlStageConnection() to notify derived classes.
419 * @see Dali::CustomActorImpl::OnStageConnection()
421 virtual void OnStageConnection();
424 * @brief Calls OnControlStageDisconnection() to notify derived classed.
426 * @see Dali::CustomActorImpl::OnStageDisconnection()
428 virtual void OnStageDisconnection();
431 * @brief Sends a request to relayout this control.
433 * The control will be relaid out after the
434 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
435 * calls OnControlChildAdd() to notify derived classes.
437 * @note This method shouldn't be overridden by derived classes.
439 * @param[in] child The added actor.
441 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
443 virtual void OnChildAdd(Actor& child);
446 * @brief Sends a request to relayout this control.
448 * The control will be relaid out after the
449 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
450 * calls OnControlChildRemove() to notify derived classes.
452 * @note This method shouldn't be overridden by derived classes.
454 * @param[in] child The removed actor.
456 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
458 virtual void OnChildRemove(Actor& child);
461 * @brief It stores the size set by size negotiation and relayout.
463 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
464 * It calls the OnControlSizeSet() to notify derived classes.
466 * @param[in] targetSize The new size.
468 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
470 virtual void OnSizeSet(const Vector3& targetSize);
473 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
475 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
478 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
480 virtual bool OnTouchEvent(const TouchEvent& event);
483 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
485 virtual bool OnKeyEvent(const KeyEvent& event);
488 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
490 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
493 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
495 virtual void OnKeyInputFocusGained();
498 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
500 virtual void OnKeyInputFocusLost();
503 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
505 virtual Actor GetChildByAlias(const std::string& actorAlias);
510 * @brief Perform the activated action.
512 * @param[in] attributes The attributes to perfrom this action.
514 void DoActivatedAction(const PropertyValueContainer& attributes);
516 protected: // Construction
519 * @brief Create a Control.
521 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
523 Control(bool requiresTouchEvents);
530 * @copydoc Toolkit::Control::SetSizePolicy()
532 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
535 * @copydoc Toolkit::Control::GetSizePolicy()
537 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
540 * @copydoc Toolkit::Control::SetMinimumSize()
542 void SetMinimumSize( const Vector3& size );
545 * @copydoc Toolkit::Control::GetMinimumSize()
547 const Vector3& GetMinimumSize() const;
550 * @copydoc Toolkit::Control::SetMaximumSize()
552 void SetMaximumSize( const Vector3& size );
555 * @copydoc Toolkit::Control::GetMaximumSize()
557 const Vector3& GetMaximumSize() const;
560 * @copydoc Toolkit::Control::GetNaturalSize()
562 virtual Vector3 GetNaturalSize();
565 * @copydoc Toolkit::Control::GetHeightForWidth()
567 virtual float GetHeightForWidth( float width );
570 * @copydoc Toolkit::Control::GetWidthForHeight()
572 virtual float GetWidthForHeight( float height );
575 * @brief Retrieves the current Control's size.
577 * @return The control's size.
579 const Vector3& GetControlSize() const;
582 * @brief Retrieves the Control's size set by the Application / Control.
584 * @return The control's size.
586 const Vector3& GetSizeSet() const;
591 * @copydoc Toolkit::Control::SetKeyInputFocus()
593 void SetKeyInputFocus();
596 * @copydoc Toolkit::Control::HasKeyInputFocus()
598 bool HasKeyInputFocus();
601 * @copydoc Toolkit::Control::ClearKeyInputFocus()
603 void ClearKeyInputFocus();
606 * @copydoc ConnectionTrackerInterface::SignalConnected
608 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
611 * @copydoc ConnectionTrackerInterface::SignalDisconnected
613 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
616 * @copydoc ConnectionTrackerInterface::GetConnectionCount
618 virtual std::size_t GetConnectionCount() const;
623 * @brief Sends a request to be relaid-out.
625 * This method is called from OnStageConnection(), OnChildAdd(),
626 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
629 * This method could also be called from derived classes every time
630 * a control's poperty change and it needs to be relaid-out. After
631 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
632 * relayout process starts and all controls which called this method
633 * will be relaid-out.
635 * @note RelayoutRequest() only sends a request per Control before
636 * the Dali::Stage::SignalMessageQueueFlushed() signal is
637 * emitted. That means a control will be relaid-out only once, even
638 * if more than one request is sent between two consecutive signals.
640 void RelayoutRequest();
643 * @brief Helper method for controls to Relayout their children if
644 * they do not know whether that child is a control or not.
646 * @param[in] actor The actor to relayout.
647 * @param[in] size The size to allocate to the actor.
648 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
650 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
652 private: // Used by the RelayoutController
655 * @brief Called by the RelayoutController to negotiate the size of a control.
657 * The size allocated by the the algorithm is passed in which the
658 * control must adhere to. A container is passed in as well which
659 * the control should populate with actors it has not / or does not
660 * need to handle in its size negotiation.
662 * @param[in] size The allocated size.
663 * @param[in,out] container The container that holds actors that are fed back into the
664 * RelayoutController algorithm.
666 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
671 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
673 * It calls the OnRelaidOut() method which can be overridden by derived classes.
675 * @param[in] size The allocated size.
676 * @param[in,out] container The control should add actors to this container that it is not able
677 * to allocate a size for.
679 void Relayout( Vector2 size, ActorSizeContainer& container );
682 * @brief Used by the KeyInputFocusManager to emit key event signals.
684 * @param[in] event The key event.
685 * @return True if the event was consumed.
687 bool EmitKeyEventSignal(const KeyEvent& event);
694 Control(const Control&);
695 Control& operator=(const Control&);
700 friend class Internal::StyleChangeProcessor;
701 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
702 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
705 } // namespace Internal
707 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
709 } // namespace Toolkit
716 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__