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 Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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.
22 * @addtogroup CAPI_DALI_TOOLKIT_CONTROLS_MODULE
27 #include <dali-toolkit/public-api/controls/control.h>
29 namespace Dali DALI_IMPORT_API
35 namespace Internal DALI_INTERNAL
37 class StyleChangeProcessor;
38 class RelayoutControllerImpl;
39 class KeyInputFocusManager;
42 typedef std::pair< Actor, Vector2 > ActorSizePair; ///< Pair of actor and size
43 typedef std::vector< ActorSizePair > ActorSizeContainer; ///< Container of actors and their sizes
46 * @brief This is the internal base class for all controls.
48 * It will provide some common functionality required by all controls.
49 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
50 * be disconnected automatically when the control is destroyed.
52 class ControlImpl : public CustomActorImpl, public ConnectionTrackerInterface
59 CONTROL_PROPERTY_START_INDEX = PROPERTY_REGISTRATION_START_INDEX,
60 CONTROL_PROPERTY_END_INDEX = CONTROL_PROPERTY_START_INDEX + 1000 ///< Reserving 1000 property indices
66 * @brief Create a new ControlImpl instance that does not require touch by default.
68 * If touch is required then the user can connect to this class' touch signal.
69 * @return A handle to the ConntrolImpl instance.
76 * @brief Virtual destructor.
78 virtual ~ControlImpl();
83 * @brief This method should be overridden by deriving classes when they wish to be notified when they
86 virtual void OnActivated() { }
89 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
92 * @param[in] gesture The pan gesture.
93 * @return true if the pan gesture has been consumed by this control
95 virtual bool OnAccessibilityPan(PanGesture gesture);
98 * @brief This method should be overridden by deriving classes when they wish to respond
99 * the accessibility up and down action (i.e. value change of slider control).
101 * @param[in] isIncrease Whether the value should be increased or decreased
102 * @return true if the value changed action has been consumed by this control
104 virtual bool OnAccessibilityValueChange(bool isIncrease);
107 * @brief Sets whether this control supports two dimensional
108 * keyboard navigation (i.e. whether it knows how to handle the
109 * keyboardn focus movement between its child actors).
111 * The control doesn't support it by default.
112 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
114 void SetKeyboardNavigationSupport(bool isSupported);
117 * @brief Gets whether this control supports two dimensional keyboard navigation.
119 * @return true if this control supports two dimensional keyboard navigation.
121 bool IsKeyboardNavigationSupported();
124 * @brief Sets whether this control is a focus group for keyboard navigation.
126 * (i.e. the scope of keyboard focus movement
127 * can be limitied to its child actors). The control is not a focus group by default.
128 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
130 void SetAsKeyboardFocusGroup(bool isFocusGroup);
133 * @brief Gets whether this control is a focus group for keyboard navigation.
135 * @return true if this control is set as a focus group for keyboard navigation.
137 bool IsKeyboardFocusGroup();
140 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
142 * A control needs to override this function in order to support two dimensional keyboard navigation.
143 * @param[in] currentFocusedActor The current focused actor.
144 * @param[in] direction The direction to move the focus towards.
145 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
146 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
148 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
151 * @brief Informs this control that its chosen focusable actor will be focused.
153 * This allows the application to preform any actions if wishes
154 * before the focus is actually moved to the chosen actor.
156 * @param[in] commitedFocusableActor The commited focusable actor.
158 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor) { }
161 * @brief Performs actions as requested using the action name.
163 * @param[in] object The object on which to perform the action.
164 * @param[in] actionName The action to perform.
165 * @param[in] attributes The attributes with which to perfrom this action.
166 * @return true if action has been accepted by this control
168 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
171 * @brief If deriving classes wish to fine tune pinch gesture
172 * detection then they can access the gesture detector through this
173 * API and modify the detection.
175 * @return The pinch gesture detector.
176 * @pre Pinch detection should have been enabled via EnableGestureDetection().
177 * @see EnableGestureDetection
179 PinchGestureDetector GetPinchGestureDetector() const;
182 * @brief If deriving classes wish to fine tune pan gesture
183 * detection then they can access the gesture detector through this
184 * API and modify the detection.
186 * @return The pan gesture detector.
187 * @pre Pan detection should have been enabled via EnableGestureDetection().
188 * @see EnableGestureDetection
190 PanGestureDetector GetPanGestureDetector() const;
193 * @brief If deriving classes wish to fine tune tap gesture
194 * detection then they can access the gesture detector through this
195 * API and modify the detection.
197 * @return The tap gesture detector.
198 * @pre Tap detection should have been enabled via EnableGestureDetection().
199 * @see EnableGestureDetection
201 TapGestureDetector GetTapGestureDetector() const;
204 * @brief If deriving classes wish to fine tune long press gesture
205 * detection then they can access the gesture detector through this
206 * API and modify the detection.
208 * @return The long press gesture detector.
209 * @pre Long press detection should have been enabled via EnableGestureDetection().
210 * @see EnableGestureDetection
212 LongPressGestureDetector GetLongPressGestureDetector() const;
217 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
219 void SetBackgroundColor( const Vector4& color );
222 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
224 Vector4 GetBackgroundColor() const;
227 * @copydoc Dali::Toolkit::Control::SetBackground
229 void SetBackground( Image image );
232 * @copydoc Dali::Toolkit::Control::ClearBackground
234 void ClearBackground();
237 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
239 Actor GetBackgroundActor() const;
244 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
246 Toolkit::Control::KeyEventSignalV2& KeyEventSignal();
253 * @brief Second phase initialization.
260 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
262 * Gesture detection can be enabled one at a time or in bitwise format as shown:
264 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
266 * @param[in] type The gesture type(s) to enable.
268 void EnableGestureDetection(Gesture::Type type);
271 * @brief Allows deriving classes to disable any of the gesture detectors.
273 * Like EnableGestureDetection, this can also be called using bitwise or.
274 * @param[in] type The gesture type(s) to disable.
275 * @see EnableGetureDetection
277 void DisableGestureDetection(Gesture::Type type);
279 private: // For derived classes to override
282 * @brief This method is called after the Control has been initialized.
284 * Derived classes should do any second phase initialization by
285 * overriding this method.
287 virtual void OnInitialize() { }
290 * @brief This method should be overridden by deriving classes when
291 * they wish to be notified when the style changes.
293 * @param[in] change Information denoting what has changed.
295 virtual void OnStyleChange(StyleChange change) { }
298 * @brief Called whenever a pinch gesture is detected on this control.
300 * This can be overridden by deriving classes when pinch detection
301 * is enabled. The default behaviour is to scale the control by the
304 * @note If overridden, then the default behaviour will not occur.
305 * @note Pinch detection should be enabled via EnableGestureDetection().
306 * @param[in] pinch The pinch gesture.
307 * @see EnableGestureDetection
309 virtual void OnPinch(PinchGesture pinch);
312 * @brief Called whenever a pan gesture is detected on this control.
314 * This should be overridden by deriving classes when pan detection
317 * @note There is no default behaviour with panning.
318 * @note Pan detection should be enabled via EnableGestureDetection().
319 * @param[in] pan The pan gesture.
320 * @see EnableGestureDetection
322 virtual void OnPan(PanGesture pan) { }
325 * @brief Called whenever a tap gesture is detected on this control.
327 * This should be overridden by deriving classes when tap detection
330 * @note There is no default behaviour with a tap.
331 * @note Tap detection should be enabled via EnableGestureDetection().
332 * @param[in] tap The tap gesture.
333 * @see EnableGestureDetection
335 virtual void OnTap(TapGesture tap) { }
338 * @brief Called whenever a long press gesture is detected on this control.
340 * This should be overridden by deriving classes when long press
341 * detection is enabled.
343 * @note There is no default behaviour associated with a long press.
344 * @note Long press detection should be enabled via EnableGestureDetection().
345 * @param[in] longPress The long press gesture.
346 * @see EnableGestureDetection
348 virtual void OnLongPress(LongPressGesture longPress) { }
351 * @brief Called whenever the control is added to the stage.
353 * Could be overridden by derived classes.
355 virtual void OnControlStageConnection() { }
358 * @brief Called whenever the control is removed from the stage.
360 * Could be overridden by derived classes.
362 virtual void OnControlStageDisconnection() { }
365 * @brief Called whenever an Actor is added to the control.
367 * Could be overridden by derived classes.
369 * @param[in] child The added actor.
371 virtual void OnControlChildAdd( Actor& child ) { }
374 * @brief Called whenever an Actor is removed from the control.
376 * Could be overridden by derived classes.
378 * @param[in] child The removed actor.
380 virtual void OnControlChildRemove( Actor& child ) { }
383 * @brief Called whenever the Control's size is set.
385 * Could be overridden by derived classes.
387 * @param[in] size The new size.
389 virtual void OnControlSizeSet( const Vector3& size ) { }
392 * @brief Called after the Dali::Stage::SignalMessageQueueFlushed()
393 * signal is emitted if this control requested to be relaid-out.
395 * Should be overridden by derived classes if they need to layout
396 * actors differently after certain operations like add or remove
397 * actors, resize or after changing especific properties.
399 * @param[in] size The allocated size.
400 * @param[in,out] container The control should add actors to this container that it is not able
401 * to allocate a size for.
403 virtual void OnRelaidOut( Vector2 size, ActorSizeContainer& container );
405 private: // From CustomActorImpl, derived classes can override these.
408 * @brief Sends a request to relayout this control.
410 * The control will be relaid out after the
411 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
413 * It calls OnControlStageConnection() to notify derived classes.
415 * @see Dali::CustomActorImpl::OnStageConnection()
417 virtual void OnStageConnection();
420 * @brief Calls OnControlStageDisconnection() to notify derived classed.
422 * @see Dali::CustomActorImpl::OnStageDisconnection()
424 virtual void OnStageDisconnection();
427 * @brief Sends a request to relayout this control.
429 * The control will be relaid out after the
430 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
431 * calls OnControlChildAdd() to notify derived classes.
433 * @note This method shouldn't be overridden by derived classes.
435 * @param[in] child The added actor.
437 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
439 virtual void OnChildAdd(Actor& child);
442 * @brief Sends a request to relayout this control.
444 * The control will be relaid out after the
445 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
446 * calls OnControlChildRemove() to notify derived classes.
448 * @note This method shouldn't be overridden by derived classes.
450 * @param[in] child The removed actor.
452 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
454 virtual void OnChildRemove(Actor& child);
457 * @brief It stores the size set by size negotiation and relayout.
459 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
460 * It calls the OnControlSizeSet() to notify derived classes.
462 * @param[in] targetSize The new size.
464 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
466 virtual void OnSizeSet(const Vector3& targetSize);
469 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
471 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
474 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
476 virtual bool OnTouchEvent(const TouchEvent& event);
479 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
481 virtual bool OnKeyEvent(const KeyEvent& event);
484 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
486 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
489 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusGained()
491 virtual void OnKeyInputFocusGained();
494 * @copydoc Dali::CustomActorImpl::OnKeyInputFocusLost()
496 virtual void OnKeyInputFocusLost();
499 * @copydoc Dali::CustomActorImpl::GetChildByAlias(const std::string& actorAlias)
501 virtual Actor GetChildByAlias(const std::string& actorAlias);
506 * @brief Perform the activated action.
508 * @param[in] attributes The attributes to perfrom this action.
510 void DoActivatedAction(const PropertyValueContainer& attributes);
512 protected: // Construction
515 * @brief Create a ControlImpl.
517 * @param[in] requiresTouchEvents True if the OnTouchEvent() callback is required.
519 ControlImpl(bool requiresTouchEvents);
526 * @copydoc Control::SetSizePolicy()
528 void SetSizePolicy( Control::SizePolicy widthPolicy, Control::SizePolicy heightPolicy );
531 * @copydoc Control::GetSizePolicy()
533 void GetSizePolicy( Control::SizePolicy& widthPolicy, Control::SizePolicy& heightPolicy ) const;
536 * @copydoc Control::SetMinimumSize()
538 void SetMinimumSize( const Vector3& size );
541 * @copydoc Control::GetMinimumSize()
543 const Vector3& GetMinimumSize() const;
546 * @copydoc Control::SetMaximumSize()
548 void SetMaximumSize( const Vector3& size );
551 * @copydoc Control::GetMaximumSize()
553 const Vector3& GetMaximumSize() const;
556 * @copydoc Control::GetNaturalSize()
558 virtual Vector3 GetNaturalSize();
561 * @copydoc Control::GetHeightForWidth()
563 virtual float GetHeightForWidth( float width );
566 * @copydoc Control::GetWidthForHeight()
568 virtual float GetWidthForHeight( float height );
571 * @brief Retrieves the current Control's size.
573 * @return The control's size.
575 const Vector3& GetControlSize() const;
578 * @brief Retrieves the Control's size set by the Application / Control.
580 * @return The control's size.
582 const Vector3& GetSizeSet() const;
587 * @copydoc Control::SetKeyInputFocus()
589 void SetKeyInputFocus();
592 * @copydoc Control::HasKeyInputFocus()
594 bool HasKeyInputFocus();
597 * @copydoc Control::ClearKeyInputFocus()
599 void ClearKeyInputFocus();
602 * @copydoc ConnectionTrackerInterface::SignalConnected
604 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
607 * @copydoc ConnectionTrackerInterface::SignalDisconnected
609 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
612 * @copydoc ConnectionTrackerInterface::GetConnectionCount
614 virtual std::size_t GetConnectionCount() const;
619 * @brief Sends a request to be relaid-out.
621 * This method is called from OnStageConnection(), OnChildAdd(),
622 * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and
625 * This method could also be called from derived classes every time
626 * a control's poperty change and it needs to be relaid-out. After
627 * the Dali::Stage::SignalMessageQueueFlushed() is emitted a
628 * relayout process starts and all controls which called this method
629 * will be relaid-out.
631 * @note RelayoutRequest() only sends a request per Control before
632 * the Dali::Stage::SignalMessageQueueFlushed() signal is
633 * emitted. That means a control will be relaid-out only once, even
634 * if more than one request is sent between two consecutive signals.
636 void RelayoutRequest();
639 * @brief Helper method for controls to Relayout their children if
640 * they do not know whether that child is a control or not.
642 * @param[in] actor The actor to relayout.
643 * @param[in] size The size to allocate to the actor.
644 * @param[in,out] container The container that holds actors that have not been allocated a size yet.
646 static void Relayout( Actor actor, Vector2 size, ActorSizeContainer& container );
648 private: // Used by the RelayoutController
651 * @brief Called by the RelayoutController to negotiate the size of a control.
653 * The size allocated by the the algorithm is passed in which the
654 * control must adhere to. A container is passed in as well which
655 * the control should populate with actors it has not / or does not
656 * need to handle in its size negotiation.
658 * @param[in] size The allocated size.
659 * @param[in,out] container The container that holds actors that are fed back into the
660 * RelayoutController algorithm.
662 void NegotiateSize( Vector2 size, ActorSizeContainer& container );
667 * @brief Called by NegotiateSize when the size to allocate to the control has been calculated.
669 * It calls the OnRelaidOut() method which can be overridden by derived classes.
671 * @param[in] size The allocated size.
672 * @param[in,out] container The control should add actors to this container that it is not able
673 * to allocate a size for.
675 void Relayout( Vector2 size, ActorSizeContainer& container );
678 * @brief Used by the KeyInputFocusManager to emit key event signals.
680 * @param[in] event The key event.
681 * @return True if the event was consumed.
683 bool EmitKeyEventSignal(const KeyEvent& event);
690 ControlImpl(const ControlImpl&);
691 ControlImpl& operator=(const ControlImpl&);
696 friend class Internal::StyleChangeProcessor;
697 friend class Internal::RelayoutControllerImpl; ///< Relayout controller needs to call Relayout() which is private.
698 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call which is private.
701 } // namespace Toolkit
708 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__