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
34 namespace Internal DALI_INTERNAL
36 class StyleChangeProcessor;
37 class RelayoutControllerImpl;
38 class KeyInputFocusManager;
41 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
42 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
45 * @brief This is the internal base class for all controls.
47 * It will provide some common functionality required by all controls.
48 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
49 * be disconnected automatically when the control is destroyed.
51 class ControlImpl : public CustomActorImpl, public ConnectionTrackerInterface
58 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
59 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
65 * @brief Create a new ControlImpl instance that does not require touch by default.
67 * If touch is required then the user can connect to this class' touch signal.
68 * @return A handle to the ConntrolImpl instance.
75 * @brief Virtual destructor.
77 virtual ~ControlImpl();
82 * @brief This method should be overridden by deriving classes when they wish to be notified when they
85 virtual void OnActivated() { }
88 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
91 * @param[in] gesture The pan gesture.
92 * @return true if the pan gesture has been consumed by this control
94 virtual bool OnAccessibilityPan(PanGesture gesture);
97 * @brief This method should be overridden by deriving classes when they wish to respond
98 * the accessibility up and down action (i.e. value change of slider control).
100 * @param[in] isIncrease Whether the value should be increased or decreased
101 * @return true if the value changed action has been consumed by this control
103 virtual bool OnAccessibilityValueChange(bool isIncrease);
106 * @brief Sets whether this control supports two dimensional
107 * keyboard navigation (i.e. whether it knows how to handle the
108 * keyboardn focus movement between its child actors).
110 * The control doesn't support it by default.
111 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
113 void SetKeyboardNavigationSupport(bool isSupported);
116 * @brief Gets whether this control supports two dimensional keyboard navigation.
118 * @return true if this control supports two dimensional keyboard navigation.
120 bool IsKeyboardNavigationSupported();
123 * @brief Sets whether this control is a focus group for keyboard navigation.
125 * (i.e. the scope of keyboard focus movement
126 * can be limitied to its child actors). The control is not a focus group by default.
127 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
129 void SetAsKeyboardFocusGroup(bool isFocusGroup);
132 * @brief Gets whether this control is a focus group for keyboard navigation.
134 * @return true if this control is set as a focus group for keyboard navigation.
136 bool IsKeyboardFocusGroup();
139 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
141 * A control needs to override this function in order to support two dimensional keyboard navigation.
142 * @param[in] currentFocusedActor The current focused actor.
143 * @param[in] direction The direction to move the focus towards.
144 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
145 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
147 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
150 * @brief Informs this control that its chosen focusable actor will be focused.
152 * This allows the application to preform any actions if wishes
153 * before the focus is actually moved to the chosen actor.
155 * @param[in] commitedFocusableActor The commited focusable actor.
157 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
160 * @brief Performs actions as requested using the action name.
162 * @param[in] object The object on which to perform the action.
163 * @param[in] actionName The action to perform.
164 * @param[in] attributes The attributes with which to perfrom this action.
165 * @return true if action has been accepted by this control
167 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
172 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
174 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
181 * @brief Second phase initialization.
188 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
190 * Gesture detection can be enabled one at a time or in bitwise format as shown:
192 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
194 * @param[in] type The gesture type(s) to enable.
196 void EnableGestureDetection(Gesture::Type type);
199 * @brief Allows deriving classes to disable any of the gesture detectors.
201 * Like EnableGestureDetection, this can also be called using bitwise or.
202 * @param[in] type The gesture type(s) to disable.
203 * @see EnableGetureDetection
205 void DisableGestureDetection(Gesture::Type type);
208 * @brief If deriving classes wish to fine tune pinch gesture
209 * detection then they can access the gesture detector through this
210 * API and modify the detection.
212 * @return The pinch gesture detector.
213 * @pre Pinch detection should have been enabled via EnableGestureDetection().
214 * @see EnableGestureDetection
216 PinchGestureDetector GetPinchGestureDetector() const;
219 * @brief If deriving classes wish to fine tune pan gesture
220 * detection then they can access the gesture detector through this
221 * API and modify the detection.
223 * @return The pan gesture detector.
224 * @pre Pan detection should have been enabled via EnableGestureDetection().
225 * @see EnableGestureDetection
227 PanGestureDetector GetPanGestureDetector() const;
230 * @brief If deriving classes wish to fine tune tap gesture
231 * detection then they can access the gesture detector through this
232 * API and modify the detection.
234 * @return The tap gesture detector.
235 * @pre Tap detection should have been enabled via EnableGestureDetection().
236 * @see EnableGestureDetection
238 TapGestureDetector GetTapGestureDetector() const;
241 * @brief If deriving classes wish to fine tune long press gesture
242 * detection then they can access the gesture detector through this
243 * API and modify the detection.
245 * @return The long press gesture detector.
246 * @pre Long press detection should have been enabled via EnableGestureDetection().
247 * @see EnableGestureDetection
249 LongPressGestureDetector GetLongPressGestureDetector() const;
251 private: // For derived classes to override
254 * @brief This method is called after the Control has been initialized.
256 * Derived classes should do any second phase initialization by
257 * overriding this method.
259 virtual void OnInitialize() { }
262 * @brief This method should be overridden by deriving classes when
263 * they wish to be notified when the style changes.
265 * @param[in] change Information denoting what has changed.
267 virtual void OnStyleChange(StyleChange change) { }
270 * @brief Called whenever a pinch gesture is detected on this control.
272 * This can be overridden by deriving classes when pinch detection
273 * is enabled. The default behaviour is to scale the control by the
276 * @note If overridden, then the default behaviour will not occur.
277 * @note Pinch detection should be enabled via EnableGestureDetection().
278 * @param[in] pinch The pinch gesture.
279 * @see EnableGestureDetection
281 virtual void OnPinch(PinchGesture pinch);
284 * @brief Called whenever a pan gesture is detected on this control.
286 * This should be overridden by deriving classes when pan detection
289 * @note There is no default behaviour with panning.
290 * @note Pan detection should be enabled via EnableGestureDetection().
291 * @param[in] pan The pan gesture.
292 * @see EnableGestureDetection
294 virtual void OnPan(PanGesture pan) { }
297 * @brief Called whenever a tap gesture is detected on this control.
299 * This should be overridden by deriving classes when tap detection
302 * @note There is no default behaviour with a tap.
303 * @note Tap detection should be enabled via EnableGestureDetection().
304 * @param[in] tap The tap gesture.
305 * @see EnableGestureDetection
307 virtual void OnTap(TapGesture tap) { }
310 * @brief Called whenever a long press gesture is detected on this control.
312 * This should be overridden by deriving classes when long press
313 * detection is enabled.
315 * @note There is no default behaviour associated with a long press.
316 * @note Long press detection should be enabled via EnableGestureDetection().
317 * @param[in] longPress The long press gesture.
318 * @see EnableGestureDetection
320 virtual void OnLongPress(LongPressGesture longPress) { }
323 * @brief Called whenever the control is added to the stage.
325 * Could be overridden by derived classes.
327 virtual void OnControlStageConnection() { }
330 * @brief Called whenever the control is removed from the stage.
332 * Could be overridden by derived classes.
334 virtual void OnControlStageDisconnection() { }
337 * @brief Called whenever an Actor is added to the control.
339 * Could be overridden by derived classes.
341 * @param[in] child The added actor.
343 virtual void OnControlChildAdd( Actor& child ) { }
346 * @brief Called whenever an Actor is removed from the control.
348 * Could be overridden by derived classes.
350 * @param[in] child The removed actor.
352 virtual void OnControlChildRemove( Actor& child ) { }
355 * @brief Called whenever the Control's size is set.
357 * Could be overridden by derived classes.
359 * @param[in] size The new size.
361 virtual void OnControlSizeSet( const Vector3& size ) { }
364 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
365 * signal is emitted if this control requested to be relaid-out.
367 * Should be overridden by derived classes if they need to layout
368 * actors differently after certain operations like add or remove
369 * actors, resize or after changing especific properties.
371 * @param[in] size The allocated size.
372 * @param[in,out] container The control should add actors to this container that it is not able
373 * to allocate a size for.
375 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
377 private: // From CustomActorImpl, derived classes can override these.
380 * @brief Sends a request to relayout this control.
382 * The control will be relaid out after the
383 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
385 * It calls OnControlStageConnection() to notify derived classes.
387 * @see Dali::CustomActorImpl::OnStageConnection()
389 virtual void OnStageConnection();
392 * @brief Calls OnControlStageDisconnection() to notify derived classed.
394 * @see Dali::CustomActorImpl::OnStageDisconnection()
396 virtual void OnStageDisconnection();
399 * @brief Sends a request to relayout this control.
401 * The control will be relaid out after the
402 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
403 * calls OnControlChildAdd() to notify derived classes.
405 * @note This method shouldn't be overridden by derived classes.
407 * @param[in] child The added actor.
409 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
411 virtual void OnChildAdd(Actor& child);
414 * @brief Sends a request to relayout this control.
416 * The control will be relaid out after the
417 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
418 * calls OnControlChildRemove() to notify derived classes.
420 * @note This method shouldn't be overridden by derived classes.
422 * @param[in] child The removed actor.
424 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
426 virtual void OnChildRemove(Actor& child);
429 * @brief It stores the size set by size negotiation and relayout.
431 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
432 * It calls the OnControlSizeSet() to notify derived classes.
434 * @param[in] targetSize The new size.
436 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
438 virtual void OnSizeSet(const Vector3& targetSize);
441 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
443 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
446 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
448 virtual bool OnTouchEvent(const TouchEvent& event);
451 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
453 virtual bool OnKeyEvent(const KeyEvent& event);
456 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
458 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
461 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
463 virtual void OnKeyInputFocusGained();
466 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
468 virtual void OnKeyInputFocusLost();
471 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
473 virtual Actor GetChildByAlias(const std::string& actorAlias);
478 * @brief Perform the activated action.
480 * @param[in] attributes The attributes to perfrom this action.
482 void DoActivatedAction(const PropertyValueContainer& attributes);
484 protected: // Construction
487 * @brief Create a ControlImpl.
489 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
491 ControlImpl(bool requiresTouchEvents);
498 * @copydoc Control::SetSizePolicy()
500 void SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy );
503 * @copydoc Control::GetSizePolicy()
505 void GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const;
508 * @copydoc Control::SetMinimumSize()
510 void SetMinimumSize( const Vector3& size );
513 * @copydoc Control::GetMinimumSize()
515 const Vector3& GetMinimumSize() const;
518 * @copydoc Control::SetMaximumSize()
520 void SetMaximumSize( const Vector3& size );
523 * @copydoc Control::GetMaximumSize()
525 const Vector3& GetMaximumSize() const;
528 * @copydoc Control::GetNaturalSize()
530 virtual Vector3 GetNaturalSize();
533 * @copydoc Control::GetHeightForWidth()
535 virtual float GetHeightForWidth( float width );
538 * @copydoc Control::GetWidthForHeight()
540 virtual float GetWidthForHeight( float height );
543 * @brief Retrieves the current Control's size.
545 * @return The control's size.
547 const Vector3& GetControlSize() const;
550 * @brief Retrieves the Control's size set by the Application / Control.
552 * @return The control's size.
554 const Vector3& GetSizeSet() const;
559 * @copydoc Control::SetKeyInputFocus()
561 void SetKeyInputFocus();
564 * @copydoc Control::HasKeyInputFocus()
566 bool HasKeyInputFocus();
569 * @copydoc Control::ClearKeyInputFocus()
571 void ClearKeyInputFocus();
574 * @copydoc ConnectionTrackerInterface::SignalConnected
576 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
579 * @copydoc ConnectionTrackerInterface::SignalDisconnected
581 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
584 * @copydoc ConnectionTrackerInterface::GetConnectionCount
586 virtual std::size_t GetConnectionCount() const;
591 * @brief Sends a request to be relaid-out.
593 * This method is called from OnStageConnection(), OnChildAdd(),
594 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
597 * This method could also be called from derived classes every time
598 * a control's poperty change and it needs to be relaid-out. After
599 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
600 * relayout process starts and all controls which called this method
601 * will be relaid-out.
603 * @note RelayoutRequest() only sends a request per Control before
604 * the Dali::Stage::SignalMessageQueueFlushed() signal is
605 * emitted. That means a control will be relaid-out only once, even
606 * if more than one request is sent between two consecutive signals.
608 void RelayoutRequest();
611 * @brief Helper method for controls to Relayout their children if
612 * they do not know whether that child is a control or not.
614 * @param[in] actor The actor to relayout.
615 * @param[in] size The size to allocate to the actor.
616 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
618 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
620 private: // Used by the RelayoutController
623 * @brief Called by the RelayoutController to negotiate the size of a control.
625 * The size allocated by the the algorithm is passed in which the
626 * control must adhere to. A container is passed in as well which
627 * the control should populate with actors it has not / or does not
628 * need to handle in its size negotiation.
630 * @param[in] size The allocated size.
631 * @param[in,out] container The container that holds actors that are fed back into the
632 * RelayoutController algorithm.
634 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
639 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
641 * It calls the OnRelaidOut() method which can be overridden by derived classes.
643 * @param[in] size The allocated size.
644 * @param[in,out] container The control should add actors to this container that it is not able
645 * to allocate a size for.
647 void Relayout( Vector2 size, ActorSizeContainer& container );
650 * @brief Used by the KeyInputFocusManager to emit key event signals.
652 * @param[in] event The key event.
653 * @return True if the event was consumed.
655 bool EmitKeyEventSignal(const KeyEvent& event);
662 ControlImpl(const ControlImpl&);
663 ControlImpl& operator=(const ControlImpl&);
668 friend class Internal::StyleChangeProcessor;
669 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
670 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
673 } // namespace Toolkit
680 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__