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 the accessibility
105 * @param[in] touchEvent The touch event.
106 * @return true if the touch event has been consumed by this control
108 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
111 * @brief This method should be overridden by deriving classes when they wish to respond
112 * the accessibility up and down action (i.e. value change of slider control).
114 * @param[in] isIncrease Whether the value should be increased or decreased
115 * @return true if the value changed action has been consumed by this control
117 virtual bool OnAccessibilityValueChange(bool isIncrease);
120 * @brief Sets whether this control supports two dimensional
121 * keyboard navigation (i.e. whether it knows how to handle the
122 * keyboardn focus movement between its child actors).
124 * The control doesn't support it by default.
125 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
127 void SetKeyboardNavigationSupport(bool isSupported);
130 * @brief Gets whether this control supports two dimensional keyboard navigation.
132 * @return true if this control supports two dimensional keyboard navigation.
134 bool IsKeyboardNavigationSupported();
137 * @brief Sets whether this control is a focus group for keyboard navigation.
139 * (i.e. the scope of keyboard focus movement
140 * can be limitied to its child actors). The control is not a focus group by default.
141 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
143 void SetAsKeyboardFocusGroup(bool isFocusGroup);
146 * @brief Gets whether this control is a focus group for keyboard navigation.
148 * @return true if this control is set as a focus group for keyboard navigation.
150 bool IsKeyboardFocusGroup();
153 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
155 * A control needs to override this function in order to support two dimensional keyboard navigation.
156 * @param[in] currentFocusedActor The current focused actor.
157 * @param[in] direction The direction to move the focus towards.
158 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
159 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
161 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
164 * @brief Informs this control that its chosen focusable actor will be focused.
166 * This allows the application to preform any actions if wishes
167 * before the focus is actually moved to the chosen actor.
169 * @param[in] commitedFocusableActor The commited focusable actor.
171 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
174 * @brief Performs actions as requested using the action name.
176 * @param[in] object The object on which to perform the action.
177 * @param[in] actionName The action to perform.
178 * @param[in] attributes The attributes with which to perfrom this action.
179 * @return true if action has been accepted by this control
181 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
184 * @brief If deriving classes wish to fine tune pinch gesture
185 * detection then they can access the gesture detector through this
186 * API and modify the detection.
188 * @return The pinch gesture detector.
189 * @pre Pinch detection should have been enabled via EnableGestureDetection().
190 * @see EnableGestureDetection
192 PinchGestureDetector GetPinchGestureDetector() const;
195 * @brief If deriving classes wish to fine tune pan gesture
196 * detection then they can access the gesture detector through this
197 * API and modify the detection.
199 * @return The pan gesture detector.
200 * @pre Pan detection should have been enabled via EnableGestureDetection().
201 * @see EnableGestureDetection
203 PanGestureDetector GetPanGestureDetector() const;
206 * @brief If deriving classes wish to fine tune tap gesture
207 * detection then they can access the gesture detector through this
208 * API and modify the detection.
210 * @return The tap gesture detector.
211 * @pre Tap detection should have been enabled via EnableGestureDetection().
212 * @see EnableGestureDetection
214 TapGestureDetector GetTapGestureDetector() const;
217 * @brief If deriving classes wish to fine tune long press gesture
218 * detection then they can access the gesture detector through this
219 * API and modify the detection.
221 * @return The long press gesture detector.
222 * @pre Long press detection should have been enabled via EnableGestureDetection().
223 * @see EnableGestureDetection
225 LongPressGestureDetector GetLongPressGestureDetector() const;
230 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
232 void SetBackgroundColor( const Vector4& color );
235 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
237 Vector4 GetBackgroundColor() const;
240 * @copydoc Dali::Toolkit::Control::SetBackground
242 void SetBackground( Image image );
245 * @copydoc Dali::Toolkit::Control::ClearBackground
247 void ClearBackground();
250 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
252 Actor GetBackgroundActor() const;
257 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
259 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
266 * @brief Second phase initialization.
273 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
275 * Gesture detection can be enabled one at a time or in bitwise format as shown:
277 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
279 * @param[in] type The gesture type(s) to enable.
281 void EnableGestureDetection(Gesture::Type type);
284 * @brief Allows deriving classes to disable any of the gesture detectors.
286 * Like EnableGestureDetection, this can also be called using bitwise or.
287 * @param[in] type The gesture type(s) to disable.
288 * @see EnableGetureDetection
290 void DisableGestureDetection(Gesture::Type type);
292 private: // For derived classes to override
295 * @brief This method is called after the Control has been initialized.
297 * Derived classes should do any second phase initialization by
298 * overriding this method.
300 virtual void OnInitialize() { }
303 * @brief This method should be overridden by deriving classes when
304 * they wish to be notified when the style changes.
306 * @param[in] change Information denoting what has changed.
308 virtual void OnStyleChange(StyleChange change) { }
311 * @brief Called whenever a pinch gesture is detected on this control.
313 * This can be overridden by deriving classes when pinch detection
314 * is enabled. The default behaviour is to scale the control by the
317 * @note If overridden, then the default behaviour will not occur.
318 * @note Pinch detection should be enabled via EnableGestureDetection().
319 * @param[in] pinch The pinch gesture.
320 * @see EnableGestureDetection
322 virtual void OnPinch(PinchGesture pinch);
325 * @brief Called whenever a pan gesture is detected on this control.
327 * This should be overridden by deriving classes when pan detection
330 * @note There is no default behaviour with panning.
331 * @note Pan detection should be enabled via EnableGestureDetection().
332 * @param[in] pan The pan gesture.
333 * @see EnableGestureDetection
335 virtual void OnPan(PanGesture pan) { }
338 * @brief Called whenever a tap gesture is detected on this control.
340 * This should be overridden by deriving classes when tap detection
343 * @note There is no default behaviour with a tap.
344 * @note Tap detection should be enabled via EnableGestureDetection().
345 * @param[in] tap The tap gesture.
346 * @see EnableGestureDetection
348 virtual void OnTap(TapGesture tap) { }
351 * @brief Called whenever a long press gesture is detected on this control.
353 * This should be overridden by deriving classes when long press
354 * detection is enabled.
356 * @note There is no default behaviour associated with a long press.
357 * @note Long press detection should be enabled via EnableGestureDetection().
358 * @param[in] longPress The long press gesture.
359 * @see EnableGestureDetection
361 virtual void OnLongPress(LongPressGesture longPress) { }
364 * @brief Called whenever the control is added to the stage.
366 * Could be overridden by derived classes.
368 virtual void OnControlStageConnection() { }
371 * @brief Called whenever the control is removed from the stage.
373 * Could be overridden by derived classes.
375 virtual void OnControlStageDisconnection() { }
378 * @brief Called whenever an Actor is added to the control.
380 * Could be overridden by derived classes.
382 * @param[in] child The added actor.
384 virtual void OnControlChildAdd( Actor& child ) { }
387 * @brief Called whenever an Actor is removed from the control.
389 * Could be overridden by derived classes.
391 * @param[in] child The removed actor.
393 virtual void OnControlChildRemove( Actor& child ) { }
396 * @brief Called whenever the Control's size is set.
398 * Could be overridden by derived classes.
400 * @param[in] size The new size.
402 virtual void OnControlSizeSet( const Vector3& size ) { }
405 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
406 * signal is emitted if this control requested to be relaid-out.
408 * Should be overridden by derived classes if they need to layout
409 * actors differently after certain operations like add or remove
410 * actors, resize or after changing especific properties.
412 * @param[in] size The allocated size.
413 * @param[in,out] container The control should add actors to this container that it is not able
414 * to allocate a size for.
416 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
418 private: // From CustomActorImpl, derived classes can override these.
421 * @brief Sends a request to relayout this control.
423 * The control will be relaid out after the
424 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
426 * It calls OnControlStageConnection() to notify derived classes.
428 * @see Dali::CustomActorImpl::OnStageConnection()
430 virtual void OnStageConnection();
433 * @brief Calls OnControlStageDisconnection() to notify derived classed.
435 * @see Dali::CustomActorImpl::OnStageDisconnection()
437 virtual void OnStageDisconnection();
440 * @brief Sends a request to relayout this control.
442 * The control will be relaid out after the
443 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
444 * calls OnControlChildAdd() to notify derived classes.
446 * @note This method shouldn't be overridden by derived classes.
448 * @param[in] child The added actor.
450 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
452 virtual void OnChildAdd(Actor& child);
455 * @brief Sends a request to relayout this control.
457 * The control will be relaid out after the
458 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
459 * calls OnControlChildRemove() to notify derived classes.
461 * @note This method shouldn't be overridden by derived classes.
463 * @param[in] child The removed actor.
465 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
467 virtual void OnChildRemove(Actor& child);
470 * @brief It stores the size set by size negotiation and relayout.
472 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
473 * It calls the OnControlSizeSet() to notify derived classes.
475 * @param[in] targetSize The new size.
477 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
479 virtual void OnSizeSet(const Vector3& targetSize);
482 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
484 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
487 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
489 virtual bool OnTouchEvent(const TouchEvent& event);
492 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
494 virtual bool OnKeyEvent(const KeyEvent& event);
497 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
499 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
502 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
504 virtual void OnKeyInputFocusGained();
507 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
509 virtual void OnKeyInputFocusLost();
512 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
514 virtual Actor GetChildByAlias(const std::string& actorAlias);
519 * @brief Perform the activated action.
521 * @param[in] attributes The attributes to perfrom this action.
523 void DoActivatedAction(const PropertyValueContainer& attributes);
525 protected: // Construction
528 * @brief Create a Control.
530 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
532 Control(bool requiresTouchEvents);
539 * @copydoc Toolkit::Control::SetSizePolicy()
541 void SetSizePolicy( Toolkit::Control::SizePolicy widthPolicy, Toolkit::Control::SizePolicy heightPolicy );
544 * @copydoc Toolkit::Control::GetSizePolicy()
546 void GetSizePolicy( Toolkit::Control::SizePolicy& widthPolicy, Toolkit::Control::SizePolicy& heightPolicy ) const;
549 * @copydoc Toolkit::Control::SetMinimumSize()
551 void SetMinimumSize( const Vector3& size );
554 * @copydoc Toolkit::Control::GetMinimumSize()
556 const Vector3& GetMinimumSize() const;
559 * @copydoc Toolkit::Control::SetMaximumSize()
561 void SetMaximumSize( const Vector3& size );
564 * @copydoc Toolkit::Control::GetMaximumSize()
566 const Vector3& GetMaximumSize() const;
569 * @copydoc Toolkit::Control::GetNaturalSize()
571 virtual Vector3 GetNaturalSize();
574 * @copydoc Toolkit::Control::GetHeightForWidth()
576 virtual float GetHeightForWidth( float width );
579 * @copydoc Toolkit::Control::GetWidthForHeight()
581 virtual float GetWidthForHeight( float height );
584 * @brief Retrieves the current Control's size.
586 * @return The control's size.
588 const Vector3& GetControlSize() const;
591 * @brief Retrieves the Control's size set by the Application / Control.
593 * @return The control's size.
595 const Vector3& GetSizeSet() const;
600 * @copydoc Toolkit::Control::SetKeyInputFocus()
602 void SetKeyInputFocus();
605 * @copydoc Toolkit::Control::HasKeyInputFocus()
607 bool HasKeyInputFocus();
610 * @copydoc Toolkit::Control::ClearKeyInputFocus()
612 void ClearKeyInputFocus();
615 * @copydoc ConnectionTrackerInterface::SignalConnected
617 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
620 * @copydoc ConnectionTrackerInterface::SignalDisconnected
622 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
625 * @copydoc ConnectionTrackerInterface::GetConnectionCount
627 virtual std::size_t GetConnectionCount() const;
632 * @brief Sends a request to be relaid-out.
634 * This method is called from OnStageConnection(), OnChildAdd(),
635 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
638 * This method could also be called from derived classes every time
639 * a control's poperty change and it needs to be relaid-out. After
640 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
641 * relayout process starts and all controls which called this method
642 * will be relaid-out.
644 * @note RelayoutRequest() only sends a request per Control before
645 * the Dali::Stage::SignalMessageQueueFlushed() signal is
646 * emitted. That means a control will be relaid-out only once, even
647 * if more than one request is sent between two consecutive signals.
649 void RelayoutRequest();
652 * @brief Helper method for controls to Relayout their children if
653 * they do not know whether that child is a control or not.
655 * @param[in] actor The actor to relayout.
656 * @param[in] size The size to allocate to the actor.
657 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
659 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
661 private: // Used by the RelayoutController
664 * @brief Called by the RelayoutController to negotiate the size of a control.
666 * The size allocated by the the algorithm is passed in which the
667 * control must adhere to. A container is passed in as well which
668 * the control should populate with actors it has not / or does not
669 * need to handle in its size negotiation.
671 * @param[in] size The allocated size.
672 * @param[in,out] container The container that holds actors that are fed back into the
673 * RelayoutController algorithm.
675 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
680 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
682 * It calls the OnRelaidOut() method which can be overridden by derived classes.
684 * @param[in] size The allocated size.
685 * @param[in,out] container The control should add actors to this container that it is not able
686 * to allocate a size for.
688 void Relayout( Vector2 size, ActorSizeContainer& container );
691 * @brief Used by the KeyInputFocusManager to emit key event signals.
693 * @param[in] event The key event.
694 * @return True if the event was consumed.
696 bool EmitKeyEventSignal(const KeyEvent& event);
703 Control(const Control&);
704 Control& operator=(const Control&);
709 friend class Internal::StyleChangeProcessor;
710 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
711 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
714 } // namespace Internal
716 typedef Internal::Control ControlImpl; ///< @deprecated, Use Internal::Control
718 } // namespace Toolkit
725 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__