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 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
58 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
64 * Create a new ControlImpl instance that does not require touch by default.
65 * If touch is required then the user can connect to this class' touch signal.
66 * @return A handle to the ConntrolImpl instance.
75 virtual ~ControlImpl();
80 * This method should be overridden by deriving classes when they wish to be notified when they
83 virtual void OnActivated() { }
86 * This method should be overridden by deriving classes when they wish to respond the accessibility
88 * @param[in] gesture The pan gesture.
89 * @return true if the pan gesture has been consumed by this control
91 virtual bool OnAccessibilityPan(PanGesture gesture);
94 * This method should be overridden by deriving classes when they wish to respond the accessibility
95 * up and down action (i.e. value change of slider control)
96 * @param[in] isIncrease Whether the value should be increased or decreased
97 * @return true if the value changed action has been consumed by this control
99 virtual bool OnAccessibilityValueChange(bool isIncrease);
102 * Sets whether this control supports two dimensional keyboard navigation (i.e. whether it knows how to handle the keyboard
103 * focus movement between its child actors). The control doesn't support it by default.
104 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
106 void SetKeyboardNavigationSupport(bool isSupported);
109 * Gets whether this control supports two dimensional keyboard navigation.
110 * @return true if this control supports two dimensional keyboard navigation.
112 bool IsKeyboardNavigationSupported();
115 * Sets whether this control is a focus group for keyboard navigation (i.e. the scope of keyboard focus movement
116 * can be limitied to its child actors). The control is not a focus group by default.
117 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
119 void SetAsKeyboardFocusGroup(bool isFocusGroup);
122 * Gets whether this control is a focus group for keyboard navigation.
123 * @return true if this control is set as a focus group for keyboard navigation.
125 bool IsKeyboardFocusGroup();
128 * Gets the next keyboard focusable actor in this control towards the given direction.
129 * A control needs to override this function in order to support two dimensional keyboard navigation.
130 * @param[in] currentFocusedActor The current focused actor.
131 * @param[in] direction The direction to move the focus towards.
132 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
133 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
135 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
138 * Informs this control that its chosen focusable actor will be focused. This allows the application to
139 * preform any actions if wishes before the focus is actually moved to the chosen actor.
140 * @param[in] commitedFocusableActor The commited focusable actor.
142 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
145 * Performs actions as requested using the action name.
146 * @param[in] object The object on which to perform the action.
147 * @param[in] actionName The action to perform.
148 * @param[in] attributes The attributes with which to perfrom this action.
149 * @return true if action has been accepted by this control
151 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
156 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
158 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
165 * Second phase initialization.
172 * Allows deriving classes to enable any of the gesture detectors that are available.
173 * Gesture detection can be enabled one at a time or in bitwise format as shown:
175 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
177 * @param[in] type The gesture type(s) to enable.
179 void EnableGestureDetection(Gesture::Type type);
182 * Allows deriving classes to disable any of the gesture detectors.
183 * Like EnableGestureDetection, this can also be called using bitwise or.
184 * @param[in] type The gesture type(s) to disable.
185 * @see EnableGetureDetection
187 void DisableGestureDetection(Gesture::Type type);
190 * If deriving classes wish to fine tune pinch gesture detection then they can access the gesture
191 * detector through this API and modify the detection.
192 * @return The pinch gesture detector.
193 * @pre Pinch detection should have been enabled via EnableGestureDetection().
194 * @see EnableGestureDetection
196 PinchGestureDetector GetPinchGestureDetector() const;
199 * If deriving classes wish to fine tune pan gesture detection then they can access the gesture
200 * detector through this API and modify the detection.
201 * @return The pan gesture detector.
202 * @pre Pan detection should have been enabled via EnableGestureDetection().
203 * @see EnableGestureDetection
205 PanGestureDetector GetPanGestureDetector() const;
208 * If deriving classes wish to fine tune tap gesture detection then they can access the gesture
209 * detector through this 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 * If deriving classes wish to fine tune long press gesture detection then they can access the
218 * gesture detector through this API and modify the detection.
219 * @return The long press gesture detector.
220 * @pre Long press detection should have been enabled via EnableGestureDetection().
221 * @see EnableGestureDetection
223 LongPressGestureDetector GetLongPressGestureDetector() const;
225 private: // For derived classes to override
228 * This method is called after the Control has been initialized. Derived classes should do
229 * any second phase initialization by overriding this method.
231 virtual void OnInitialize() { }
234 * This method should be overridden by deriving classes when they wish to be notified when the
236 * @param[in] change Information denoting what has changed.
238 virtual void OnStyleChange(StyleChange change) { }
241 * Called whenever a pinch gesture is detected on this control. This can be overridden by
242 * deriving classes when pinch detection is enabled. The default behaviour is to scale the
243 * control by the pinch scale.
244 * @note If overridden, then the default behaviour will not occur.
245 * @note Pinch detection should be enabled via EnableGestureDetection().
246 * @param[in] pinch The pinch gesture.
247 * @see EnableGestureDetection
249 virtual void OnPinch(PinchGesture pinch);
252 * Called whenever a pan gesture is detected on this control. This should be overridden by
253 * deriving classes when pan detection is enabled.
254 * @note There is no default behaviour with panning.
255 * @note Pan detection should be enabled via EnableGestureDetection().
256 * @param[in] pan The pan gesture.
257 * @see EnableGestureDetection
259 virtual void OnPan(PanGesture pan) { }
262 * Called whenever a tap gesture is detected on this control. This should be overridden by
263 * deriving classes when tap detection is enabled.
264 * @note There is no default behaviour with a tap.
265 * @note Tap detection should be enabled via EnableGestureDetection().
266 * @param[in] tap The tap gesture.
267 * @see EnableGestureDetection
269 virtual void OnTap(TapGesture tap) { }
272 * Called whenever a long press gesture is detected on this control. This should be overridden by
273 * deriving classes when long press detection is enabled.
274 * @note There is no default behaviour associated with a long press.
275 * @note Long press detection should be enabled via EnableGestureDetection().
276 * @param[in] longPress The long press gesture.
277 * @see EnableGestureDetection
279 virtual void OnLongPress(LongPressGesture longPress) { }
282 * Called whenever the control is added to the stage. Could be overridden by derived classes.
284 virtual void OnControlStageConnection() { }
287 * Called whenever the control is removed from the stage. Could be overridden by derived classes.
289 virtual void OnControlStageDisconnection() { }
292 * Called whenever an Actor is added to the control. Could be overridden by derived classes.
294 * @param[in] child The added actor.
296 virtual void OnControlChildAdd( Actor& child ) { }
299 * Called whenever an Actor is removed from the control. Could be overridden by derived classes.
301 * @param[in] child The removed actor.
303 virtual void OnControlChildRemove( Actor& child ) { }
306 * Called whenever the Control's size is set. Could be overridden by derived classes.
308 * @param[in] size The new size.
310 virtual void OnControlSizeSet( const Vector3& size ) { }
313 * Called after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted if this control requested to be relaid-out.
314 * Should be overridden by derived classes if they need to layout actors differently after certain operations like add or
315 * remove actors, resize or after changing especific properties.
317 * @param[in] size The allocated size.
318 * @param[in,out] container The control should add actors to this container that it is not able
319 * to allocate a size for.
321 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
323 private: // From CustomActorImpl, derived classes can override these.
326 * Sends a request to relayout this control. The control will be relaid out after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
328 * It calls OnControlStageConnection() to notify derived classes.
330 * @see Dali::CustomActorImpl::OnStageConnection()
332 virtual void OnStageConnection();
335 * Calls OnControlStageDisconnection() to notify derived classed.
337 * @see Dali::CustomActorImpl::OnStageDisconnection()
339 virtual void OnStageDisconnection();
342 * Sends a request to relayout this control. The control will be relaid out after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
343 * It calls OnControlChildAdd() to notify derived classes.
345 * @note This method shouldn't be overridden by derived classes.
347 * @param[in] child The added actor.
349 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
351 virtual void OnChildAdd(Actor& child);
354 * Sends a request to relayout this control. The control will be relaid out after the Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
355 * It calls OnControlChildRemove() to notify derived classes.
357 * @note This method shouldn't be overridden by derived classes.
359 * @param[in] child The removed actor.
361 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
363 virtual void OnChildRemove(Actor& child);
366 * 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.
367 * It calls the OnControlSizeSet() to notify derived classes.
369 * @param[in] targetSize The new size.
371 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
373 virtual void OnSizeSet(const Vector3& targetSize);
376 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
378 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
381 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
383 virtual bool OnTouchEvent(const TouchEvent& event);
386 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
388 virtual bool OnKeyEvent(const KeyEvent& event);
391 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
393 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
396 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
398 virtual void OnKeyInputFocusGained();
401 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
403 virtual void OnKeyInputFocusLost();
406 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
408 virtual Actor GetChildByAlias(const std::string& actorAlias);
413 * Perform the activated action.
414 * @param[in] attributes The attributes to perfrom this action.
416 void DoActivatedAction(const PropertyValueContainer& attributes);
418 protected: // Construction
421 * Create a ControlImpl.
422 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
424 ControlImpl(bool requiresTouchEvents);
431 * @copydoc Control::SetSizePolicy()
433 void SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy );
436 * @copydoc Control::GetSizePolicy()
438 void GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const;
441 * @copydoc Control::SetMinimumSize()
443 void SetMinimumSize( const Vector3& size );
446 * @copydoc Control::GetMinimumSize()
448 const Vector3& GetMinimumSize() const;
451 * @copydoc Control::SetMaximumSize()
453 void SetMaximumSize( const Vector3& size );
456 * @copydoc Control::GetMaximumSize()
458 const Vector3& GetMaximumSize() const;
461 * @copydoc Control::GetNaturalSize()
463 virtual Vector3 GetNaturalSize();
466 * @copydoc Control::GetHeightForWidth()
468 virtual float GetHeightForWidth( float width );
471 * @copydoc Control::GetWidthForHeight()
473 virtual float GetWidthForHeight( float height );
476 * Retrieves the current Control's size.
478 * @return The control's size.
480 const Vector3& GetControlSize() const;
483 * Retrieves the Control's size set by the Application / Control.
484 * @return The control's size.
486 const Vector3& GetSizeSet() const;
491 * @copydoc Control::SetKeyInputFocus()
493 void SetKeyInputFocus();
496 * @copydoc Control::HasKeyInputFocus()
498 bool HasKeyInputFocus();
501 * @copydoc Control::ClearKeyInputFocus()
503 void ClearKeyInputFocus();
506 * @copydoc ConnectionTrackerInterface::SignalConnected
508 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
511 * @copydoc ConnectionTrackerInterface::SignalDisconnected
513 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
516 * @copydoc ConnectionTrackerInterface::GetConnectionCount
518 virtual std::size_t GetConnectionCount() const;
523 * Sends a request to be relaid-out. This methos is called from OnStageConnection(), OnChildAdd(), OnChildRemove(), SetSizePolicy(), SetMinimumSize() and SetMaximumSize().
525 * This method could also be called from derived classes every time a control's poperty change and it needs to be relaid-out.
526 * After the Dali::Stage::SignalMessageQueueFlushed() is emitted a relayout process starts and all controls which called this method will be relaid-out.
528 * @note RelayoutRequest() only sends a request per Control before the Dali::Stage::SignalMessageQueueFlushed() signal is emitted. That means a control will be relaid-out
529 * only once, even if more than one request is sent between two consecutive signals.
531 void RelayoutRequest();
534 * Helper method for controls to Relayout their children if they do not know whether that child is
537 * @param[in] actor The actor to relayout.
538 * @param[in] size The size to allocate to the actor.
539 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
541 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
543 private: // Used by the RelayoutController
546 * Called by the RelayoutController to negotiate the size of a control. The size allocated by the
547 * the algorithm is passed in which the control must adhere to. A container is passed in as well
548 * which the control should populate with actors it has not / or does not need to handle in its
551 * @param[in] size The allocated size.
552 * @param[in,out] container The container that holds actors that are fed back into the
553 * RelayoutController algorithm.
555 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
560 * Called by NegotiateSize when the size to allocate to the control has been calculated.
561 * It calls the OnRelaidOut() method which can be overridden by derived classes.
563 * @param[in] size The allocated size.
564 * @param[in,out] container The control should add actors to this container that it is not able
565 * to allocate a size for.
567 void Relayout( Vector2 size, ActorSizeContainer& container );
570 * Used by the KeyInputFocusManager to emit key event signals.
571 * @param[in] event The key event.
572 * @return True if the event was consumed.
574 bool EmitKeyEventSignal(const KeyEvent& event);
581 ControlImpl(const ControlImpl&);
582 ControlImpl& operator=(const ControlImpl&);
587 friend class Internal::StyleChangeProcessor;
588 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
589 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
592 } // namespace Toolkit
599 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__