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);
170 * @brief If deriving classes wish to fine tune pinch gesture
171 * detection then they can access the gesture detector through this
172 * API and modify the detection.
174 * @return The pinch gesture detector.
175 * @pre Pinch detection should have been enabled via EnableGestureDetection().
176 * @see EnableGestureDetection
178 PinchGestureDetector GetPinchGestureDetector() const;
181 * @brief If deriving classes wish to fine tune pan gesture
182 * detection then they can access the gesture detector through this
183 * API and modify the detection.
185 * @return The pan gesture detector.
186 * @pre Pan detection should have been enabled via EnableGestureDetection().
187 * @see EnableGestureDetection
189 PanGestureDetector GetPanGestureDetector() const;
192 * @brief If deriving classes wish to fine tune tap gesture
193 * detection then they can access the gesture detector through this
194 * API and modify the detection.
196 * @return The tap gesture detector.
197 * @pre Tap detection should have been enabled via EnableGestureDetection().
198 * @see EnableGestureDetection
200 TapGestureDetector GetTapGestureDetector() const;
203 * @brief If deriving classes wish to fine tune long press gesture
204 * detection then they can access the gesture detector through this
205 * API and modify the detection.
207 * @return The long press gesture detector.
208 * @pre Long press detection should have been enabled via EnableGestureDetection().
209 * @see EnableGestureDetection
211 LongPressGestureDetector GetLongPressGestureDetector() const;
216 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
218 void SetBackgroundColor( const Vector4& color );
221 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
223 Vector4 GetBackgroundColor() const;
226 * @copydoc Dali::Toolkit::Control::SetBackground
228 void SetBackground( Image image );
231 * @copydoc Dali::Toolkit::Control::ClearBackground
233 void ClearBackground();
236 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
238 Actor GetBackgroundActor() const;
243 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
245 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
252 * @brief Second phase initialization.
259 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
261 * Gesture detection can be enabled one at a time or in bitwise format as shown:
263 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
265 * @param[in] type The gesture type(s) to enable.
267 void EnableGestureDetection(Gesture::Type type);
270 * @brief Allows deriving classes to disable any of the gesture detectors.
272 * Like EnableGestureDetection, this can also be called using bitwise or.
273 * @param[in] type The gesture type(s) to disable.
274 * @see EnableGetureDetection
276 void DisableGestureDetection(Gesture::Type type);
278 private: // For derived classes to override
281 * @brief This method is called after the Control has been initialized.
283 * Derived classes should do any second phase initialization by
284 * overriding this method.
286 virtual void OnInitialize() { }
289 * @brief This method should be overridden by deriving classes when
290 * they wish to be notified when the style changes.
292 * @param[in] change Information denoting what has changed.
294 virtual void OnStyleChange(StyleChange change) { }
297 * @brief Called whenever a pinch gesture is detected on this control.
299 * This can be overridden by deriving classes when pinch detection
300 * is enabled. The default behaviour is to scale the control by the
303 * @note If overridden, then the default behaviour will not occur.
304 * @note Pinch detection should be enabled via EnableGestureDetection().
305 * @param[in] pinch The pinch gesture.
306 * @see EnableGestureDetection
308 virtual void OnPinch(PinchGesture pinch);
311 * @brief Called whenever a pan gesture is detected on this control.
313 * This should be overridden by deriving classes when pan detection
316 * @note There is no default behaviour with panning.
317 * @note Pan detection should be enabled via EnableGestureDetection().
318 * @param[in] pan The pan gesture.
319 * @see EnableGestureDetection
321 virtual void OnPan(PanGesture pan) { }
324 * @brief Called whenever a tap gesture is detected on this control.
326 * This should be overridden by deriving classes when tap detection
329 * @note There is no default behaviour with a tap.
330 * @note Tap detection should be enabled via EnableGestureDetection().
331 * @param[in] tap The tap gesture.
332 * @see EnableGestureDetection
334 virtual void OnTap(TapGesture tap) { }
337 * @brief Called whenever a long press gesture is detected on this control.
339 * This should be overridden by deriving classes when long press
340 * detection is enabled.
342 * @note There is no default behaviour associated with a long press.
343 * @note Long press detection should be enabled via EnableGestureDetection().
344 * @param[in] longPress The long press gesture.
345 * @see EnableGestureDetection
347 virtual void OnLongPress(LongPressGesture longPress) { }
350 * @brief Called whenever the control is added to the stage.
352 * Could be overridden by derived classes.
354 virtual void OnControlStageConnection() { }
357 * @brief Called whenever the control is removed from the stage.
359 * Could be overridden by derived classes.
361 virtual void OnControlStageDisconnection() { }
364 * @brief Called whenever an Actor is added to the control.
366 * Could be overridden by derived classes.
368 * @param[in] child The added actor.
370 virtual void OnControlChildAdd( Actor& child ) { }
373 * @brief Called whenever an Actor is removed from the control.
375 * Could be overridden by derived classes.
377 * @param[in] child The removed actor.
379 virtual void OnControlChildRemove( Actor& child ) { }
382 * @brief Called whenever the Control's size is set.
384 * Could be overridden by derived classes.
386 * @param[in] size The new size.
388 virtual void OnControlSizeSet( const Vector3& size ) { }
391 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
392 * signal is emitted if this control requested to be relaid-out.
394 * Should be overridden by derived classes if they need to layout
395 * actors differently after certain operations like add or remove
396 * actors, resize or after changing especific properties.
398 * @param[in] size The allocated size.
399 * @param[in,out] container The control should add actors to this container that it is not able
400 * to allocate a size for.
402 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
404 private: // From CustomActorImpl, derived classes can override these.
407 * @brief Sends a request to relayout this control.
409 * The control will be relaid out after the
410 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
412 * It calls OnControlStageConnection() to notify derived classes.
414 * @see Dali::CustomActorImpl::OnStageConnection()
416 virtual void OnStageConnection();
419 * @brief Calls OnControlStageDisconnection() to notify derived classed.
421 * @see Dali::CustomActorImpl::OnStageDisconnection()
423 virtual void OnStageDisconnection();
426 * @brief Sends a request to relayout this control.
428 * The control will be relaid out after the
429 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
430 * calls OnControlChildAdd() to notify derived classes.
432 * @note This method shouldn't be overridden by derived classes.
434 * @param[in] child The added actor.
436 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
438 virtual void OnChildAdd(Actor& child);
441 * @brief Sends a request to relayout this control.
443 * The control will be relaid out after the
444 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
445 * calls OnControlChildRemove() to notify derived classes.
447 * @note This method shouldn't be overridden by derived classes.
449 * @param[in] child The removed actor.
451 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
453 virtual void OnChildRemove(Actor& child);
456 * @brief It stores the size set by size negotiation and relayout.
458 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
459 * It calls the OnControlSizeSet() to notify derived classes.
461 * @param[in] targetSize The new size.
463 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
465 virtual void OnSizeSet(const Vector3& targetSize);
468 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
470 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
473 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
475 virtual bool OnTouchEvent(const TouchEvent& event);
478 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
480 virtual bool OnKeyEvent(const KeyEvent& event);
483 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
485 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
488 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
490 virtual void OnKeyInputFocusGained();
493 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
495 virtual void OnKeyInputFocusLost();
498 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
500 virtual Actor GetChildByAlias(const std::string& actorAlias);
505 * @brief Perform the activated action.
507 * @param[in] attributes The attributes to perfrom this action.
509 void DoActivatedAction(const PropertyValueContainer& attributes);
511 protected: // Construction
514 * @brief Create a ControlImpl.
516 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
518 ControlImpl(bool requiresTouchEvents);
525 * @copydoc Control::SetSizePolicy()
527 void SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy );
530 * @copydoc Control::GetSizePolicy()
532 void GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const;
535 * @copydoc Control::SetMinimumSize()
537 void SetMinimumSize( const Vector3& size );
540 * @copydoc Control::GetMinimumSize()
542 const Vector3& GetMinimumSize() const;
545 * @copydoc Control::SetMaximumSize()
547 void SetMaximumSize( const Vector3& size );
550 * @copydoc Control::GetMaximumSize()
552 const Vector3& GetMaximumSize() const;
555 * @copydoc Control::GetNaturalSize()
557 virtual Vector3 GetNaturalSize();
560 * @copydoc Control::GetHeightForWidth()
562 virtual float GetHeightForWidth( float width );
565 * @copydoc Control::GetWidthForHeight()
567 virtual float GetWidthForHeight( float height );
570 * @brief Retrieves the current Control's size.
572 * @return The control's size.
574 const Vector3& GetControlSize() const;
577 * @brief Retrieves the Control's size set by the Application / Control.
579 * @return The control's size.
581 const Vector3& GetSizeSet() const;
586 * @copydoc Control::SetKeyInputFocus()
588 void SetKeyInputFocus();
591 * @copydoc Control::HasKeyInputFocus()
593 bool HasKeyInputFocus();
596 * @copydoc Control::ClearKeyInputFocus()
598 void ClearKeyInputFocus();
601 * @copydoc ConnectionTrackerInterface::SignalConnected
603 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
606 * @copydoc ConnectionTrackerInterface::SignalDisconnected
608 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
611 * @copydoc ConnectionTrackerInterface::GetConnectionCount
613 virtual std::size_t GetConnectionCount() const;
618 * @brief Sends a request to be relaid-out.
620 * This method is called from OnStageConnection(), OnChildAdd(),
621 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
624 * This method could also be called from derived classes every time
625 * a control's poperty change and it needs to be relaid-out. After
626 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
627 * relayout process starts and all controls which called this method
628 * will be relaid-out.
630 * @note RelayoutRequest() only sends a request per Control before
631 * the Dali::Stage::SignalMessageQueueFlushed() signal is
632 * emitted. That means a control will be relaid-out only once, even
633 * if more than one request is sent between two consecutive signals.
635 void RelayoutRequest();
638 * @brief Helper method for controls to Relayout their children if
639 * they do not know whether that child is a control or not.
641 * @param[in] actor The actor to relayout.
642 * @param[in] size The size to allocate to the actor.
643 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
645 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
647 private: // Used by the RelayoutController
650 * @brief Called by the RelayoutController to negotiate the size of a control.
652 * The size allocated by the the algorithm is passed in which the
653 * control must adhere to. A container is passed in as well which
654 * the control should populate with actors it has not / or does not
655 * need to handle in its size negotiation.
657 * @param[in] size The allocated size.
658 * @param[in,out] container The container that holds actors that are fed back into the
659 * RelayoutController algorithm.
661 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
666 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
668 * It calls the OnRelaidOut() method which can be overridden by derived classes.
670 * @param[in] size The allocated size.
671 * @param[in,out] container The control should add actors to this container that it is not able
672 * to allocate a size for.
674 void Relayout( Vector2 size, ActorSizeContainer& container );
677 * @brief Used by the KeyInputFocusManager to emit key event signals.
679 * @param[in] event The key event.
680 * @return True if the event was consumed.
682 bool EmitKeyEventSignal(const KeyEvent& event);
689 ControlImpl(const ControlImpl&);
690 ControlImpl& operator=(const ControlImpl&);
695 friend class Internal::StyleChangeProcessor;
696 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
697 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
700 } // namespace Toolkit
707 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__