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_FRAMEWORK
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;
42 typedef std::vector< ActorSizePair > ActorSizeContainer;
45 * This is the internal base class for all controls.
46 * It will provide some common functionality required by all controls.
47 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
48 * be disconnected automatically when the control is destroyed.
50 class ControlImpl : public CustomActorImpl, public ConnectionTrackerInterface
57 * Create a new ControlImpl instance that does not require touch by default.
58 * If touch is required then the user can connect to this class' touch signal.
59 * @return A handle to the ConntrolImpl instance.
68 virtual ~ControlImpl();
73 * This method should be overridden by deriving classes when they wish to be notified when they
76 virtual void OnActivated() { }
79 * This method should be overridden by deriving classes when they wish to respond the accessibility
81 * @param[in] gesture The pan gesture.
82 * @return true if the pan gesture has been consumed by this control
84 virtual bool OnAccessibilityPan(PanGesture gesture);
87 * This method should be overridden by deriving classes when they wish to respond the accessibility
88 * up and down action (i.e. value change of slider control)
89 * @param[in] isIncrease Whether the value should be increased or decreased
90 * @return true if the value changed action has been consumed by this control
92 virtual bool OnAccessibilityValueChange(bool isIncrease);
95 * Sets whether this control supports two dimensional keyboard navigation (i.e. whether it knows how to handle the keyboard
96 * focus movement between its child actors). The control doesn't support it by default.
97 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
99 void SetKeyboardNavigationSupport(bool isSupported);
102 * Gets whether this control supports two dimensional keyboard navigation.
103 * @return true if this control supports two dimensional keyboard navigation.
105 bool IsKeyboardNavigationSupported();
108 * Sets whether this control is a focus group for keyboard navigation (i.e. the scope of keyboard focus movement
109 * can be limitied to its child actors). The control is not a focus group by default.
110 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
112 void SetAsKeyboardFocusGroup(bool isFocusGroup);
115 * Gets whether this control is a focus group for keyboard navigation.
116 * @return true if this control is set as a focus group for keyboard navigation.
118 bool IsKeyboardFocusGroup();
121 * Gets the next keyboard focusable actor in this control towards the given direction.
122 * A control needs to override this function in order to support two dimensional keyboard navigation.
123 * @param[in] currentFocusedActor The current focused actor.
124 * @param[in] direction The direction to move the focus towards.
125 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
126 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
128 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
131 * Informs this control that its chosen focusable actor will be focused. This allows the application to
132 * preform any actions if wishes before the focus is actually moved to the chosen actor.
133 * @param[in] commitedFocusableActor The commited focusable actor.
135 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
138 * Performs actions as requested using the action name.
139 * @param[in] object The object on which to perform the action.
140 * @param[in] actionName The action to perform.
141 * @param[in] attributes The attributes with which to perfrom this action.
142 * @return true if action has been accepted by this control
144 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
149 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
151 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
158 * Second phase initialization.
165 * Allows deriving classes to enable any of the gesture detectors that are available.
166 * Gesture detection can be enabled one at a time or in bitwise format as shown:
168 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
170 * @param[in] type The gesture type(s) to enable.
172 void EnableGestureDetection(Gesture::Type type);
175 * Allows deriving classes to disable any of the gesture detectors.
176 * Like EnableGestureDetection, this can also be called using bitwise or.
177 * @param[in] type The gesture type(s) to disable.
178 * @see EnableGetureDetection
180 void DisableGestureDetection(Gesture::Type type);
183 * If deriving classes wish to fine tune pinch gesture detection then they can access the gesture
184 * detector through this API and modify the detection.
185 * @return The pinch gesture detector.
186 * @pre Pinch detection should have been enabled via EnableGestureDetection().
187 * @see EnableGestureDetection
189 PinchGestureDetector GetPinchGestureDetector() const;
192 * If deriving classes wish to fine tune pan gesture detection then they can access the gesture
193 * detector through this API and modify the detection.
194 * @return The pan gesture detector.
195 * @pre Pan detection should have been enabled via EnableGestureDetection().
196 * @see EnableGestureDetection
198 PanGestureDetector GetPanGestureDetector() const;
201 * If deriving classes wish to fine tune tap gesture detection then they can access the gesture
202 * detector through this API and modify the detection.
203 * @return The tap gesture detector.
204 * @pre Tap detection should have been enabled via EnableGestureDetection().
205 * @see EnableGestureDetection
207 TapGestureDetector GetTapGestureDetector() const;
210 * If deriving classes wish to fine tune long press gesture detection then they can access the
211 * gesture detector through this 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;
218 private: // For derived classes to override
221 * This method is called after the Control has been initialized. Derived classes should do
222 * any second phase initialization by overriding this method.
224 virtual void OnInitialize() { }
227 * This method should be overridden by deriving classes when they wish to be notified when the
229 * @param[in] change Information denoting what has changed.
231 virtual void OnStyleChange(StyleChange change) { }
234 * Called whenever a pinch gesture is detected on this control. This can be overridden by
235 * deriving classes when pinch detection is enabled. The default behaviour is to scale the
236 * control by the pinch scale.
237 * @note If overridden, then the default behaviour will not occur.
238 * @note Pinch detection should be enabled via EnableGestureDetection().
239 * @param[in] pinch The pinch gesture.
240 * @see EnableGestureDetection
242 virtual void OnPinch(PinchGesture pinch);
245 * Called whenever a pan gesture is detected on this control. This should be overridden by
246 * deriving classes when pan detection is enabled.
247 * @note There is no default behaviour with panning.
248 * @note Pan detection should be enabled via EnableGestureDetection().
249 * @param[in] pan The pan gesture.
250 * @see EnableGestureDetection
252 virtual void OnPan(PanGesture pan) { }
255 * Called whenever a tap gesture is detected on this control. This should be overridden by
256 * deriving classes when tap detection is enabled.
257 * @note There is no default behaviour with a tap.
258 * @note Tap detection should be enabled via EnableGestureDetection().
259 * @param[in] tap The tap gesture.
260 * @see EnableGestureDetection
262 virtual void OnTap(TapGesture tap) { }
265 * Called whenever a long press gesture is detected on this control. This should be overridden by
266 * deriving classes when long press detection is enabled.
267 * @note There is no default behaviour associated with a long press.
268 * @note Long press detection should be enabled via EnableGestureDetection().
269 * @param[in] longPress The long press gesture.
270 * @see EnableGestureDetection
272 virtual void OnLongPress(LongPressGesture longPress) { }
275 * Called whenever the control is added to the stage. Could be overridden by derived classes.
277 virtual void OnControlStageConnection() { }
280 * Called whenever the control is removed from the stage. Could be overridden by derived classes.
282 virtual void OnControlStageDisconnection() { }
285 * Called whenever an Actor is added to the control. Could be overridden by derived classes.
287 * @param[in] child The added actor.
289 virtual void OnControlChildAdd( Actor& child ) { }
292 * Called whenever an Actor is removed from the control. Could be overridden by derived classes.
294 * @param[in] child The removed actor.
296 virtual void OnControlChildRemove( Actor& child ) { }
299 * Called whenever the Control's size is set. Could be overridden by derived classes.
301 * @param[in] size The new size.
303 virtual void OnControlSizeSet( const Vector3& size ) { }
306 * Called after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted if this control requested to be relaid-out.
307 * Should be overridden by derived classes if they need to layout actors differently after certain operations like add or
308 * remove actors, resize or after changing especific properties.
310 * @param[in] size The allocated size.
311 * @param[in,out] container The control should add actors to this container that it is not able
312 * to allocate a size for.
314 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
316 private: // From CustomActorImpl, derived classes can override these.
319 * Sends a request to relayout this control. The control will be relaid out after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
321 * It calls OnControlStageConnection() to notify derived classes.
323 * @see Dali::CustomActorImpl::OnStageConnection()
325 virtual void OnStageConnection();
328 * Calls OnControlStageDisconnection() to notify derived classed.
330 * @see Dali::CustomActorImpl::OnStageDisconnection()
332 virtual void OnStageDisconnection();
335 * Sends a request to relayout this control. The control will be relaid out after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
336 * It calls OnControlChildAdd() to notify derived classes.
338 * @note This method shouldn't be overridden by derived classes.
340 * @param[in] child The added actor.
342 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
344 virtual void OnChildAdd(Actor& child);
347 * Sends a request to relayout this control. The control will be relaid out after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
348 * It calls OnControlChildRemove() to notify derived classes.
350 * @note This method shouldn't be overridden by derived classes.
352 * @param[in] child The removed actor.
354 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
356 virtual void OnChildRemove(Actor& child);
359 * It stores the size set by size negotiation and relayout. It also keeps a backup of the size set through the Actor's API used in the size negotiation.
360 * It calls the OnControlSizeSet() to notify derived classes.
362 * @param[in] targetSize The new size.
364 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
366 virtual void OnSizeSet(const Vector3& targetSize);
369 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
371 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
374 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
376 virtual bool OnTouchEvent(const TouchEvent& event);
379 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
381 virtual bool OnKeyEvent(const KeyEvent& event);
384 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
386 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
389 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
391 virtual void OnKeyInputFocusGained();
394 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
396 virtual void OnKeyInputFocusLost();
399 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
401 virtual Actor GetChildByAlias(const std::string& actorAlias);
406 * Perform the activated action.
407 * @param[in] attributes The attributes to perfrom this action.
409 void DoActivatedAction(const PropertyValueContainer& attributes);
411 protected: // Construction
414 * Create a ControlImpl.
415 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
417 ControlImpl(bool requiresTouchEvents);
424 * @copydoc Control::SetSizePolicy()
426 void SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy );
429 * @copydoc Control::GetSizePolicy()
431 void GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const;
434 * @copydoc Control::SetMinimumSize()
436 void SetMinimumSize( const Vector3& size );
439 * @copydoc Control::GetMinimumSize()
441 const Vector3& GetMinimumSize() const;
444 * @copydoc Control::SetMaximumSize()
446 void SetMaximumSize( const Vector3& size );
449 * @copydoc Control::GetMaximumSize()
451 const Vector3& GetMaximumSize() const;
454 * @copydoc Control::GetNaturalSize()
456 virtual Vector3 GetNaturalSize();
459 * @copydoc Control::GetHeightForWidth()
461 virtual float GetHeightForWidth( float width );
464 * @copydoc Control::GetWidthForHeight()
466 virtual float GetWidthForHeight( float height );
469 * Retrieves the current Control's size.
471 * @return The control's size.
473 const Vector3& GetControlSize() const;
476 * Retrieves the Control's size set by the Application / Control.
477 * @return The control's size.
479 const Vector3& GetSizeSet() const;
484 * @copydoc Control::SetKeyInputFocus()
486 void SetKeyInputFocus();
489 * @copydoc Control::HasKeyInputFocus()
491 bool HasKeyInputFocus();
494 * @copydoc Control::ClearKeyInputFocus()
496 void ClearKeyInputFocus();
499 * @copydoc ConnectionTrackerInterface::SignalConnected
501 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
504 * @copydoc ConnectionTrackerInterface::SignalDisconnected
506 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
509 * @copydoc ConnectionTrackerInterface::GetConnectionCount
511 virtual std::size_t GetConnectionCount() const;
516 * Sends a request to be relaid-out. This methos is called from OnStageConnection(), OnChildAdd(), OnChildRemove(), SetSizePolicy(), SetMinimumSize() and SetMaximumSize().
518 * This method could also be called from derived classes every time a control's poperty change and it needs to be relaid-out.
519 * After the Dali::Stage::SignalMessageQueueFlushed() is emitted a relayout process starts and all controls which called this method will be relaid-out.
521 * @note RelayoutRequest() only sends a request per Control before the Dali::Stage::SignalMessageQueueFlushed() signal is emitted. That means a control will be relaid-out
522 * only once, even if more than one request is sent between two consecutive signals.
524 void RelayoutRequest();
527 * Helper method for controls to Relayout their children if they do not know whether that child is
530 * @param[in] actor The actor to relayout.
531 * @param[in] size The size to allocate to the actor.
532 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
534 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
536 private: // Used by the RelayoutController
539 * Called by the RelayoutController to negotiate the size of a control. The size allocated by the
540 * the algorithm is passed in which the control must adhere to. A container is passed in as well
541 * which the control should populate with actors it has not / or does not need to handle in its
544 * @param[in] size The allocated size.
545 * @param[in,out] container The container that holds actors that are fed back into the
546 * RelayoutController algorithm.
548 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
553 * Called by NegotiateSize when the size to allocate to the control has been calculated.
554 * It calls the OnRelaidOut() method which can be overridden by derived classes.
556 * @param[in] size The allocated size.
557 * @param[in,out] container The control should add actors to this container that it is not able
558 * to allocate a size for.
560 void Relayout( Vector2 size, ActorSizeContainer& container );
563 * Used by the KeyInputFocusManager to emit key event signals.
564 * @param[in] event The key event.
565 * @return True if the event was consumed.
567 bool EmitKeyEventSignal(const KeyEvent& event);
574 ControlImpl(const ControlImpl&);
575 ControlImpl& operator=(const ControlImpl&);
580 friend class Internal::StyleChangeProcessor;
581 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
582 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
585 } // namespace Toolkit
592 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__