1 #ifndef __DALI_TOOLKIT_CONTROL_IMPL_H__
2 #define __DALI_TOOLKIT_CONTROL_IMPL_H__
5 * Copyright (c) 2015 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 #include <dali/public-api/adaptor-framework/style-change.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <dali/public-api/events/long-press-gesture.h>
25 #include <dali/public-api/events/pan-gesture.h>
26 #include <dali/public-api/events/pinch-gesture.h>
27 #include <dali/public-api/events/tap-gesture.h>
28 #include <dali/public-api/object/property-index-ranges.h>
29 #include <dali/public-api/object/type-info.h>
32 #include <dali-toolkit/public-api/controls/control.h>
42 namespace Internal DALI_INTERNAL
44 class KeyInputFocusManager;
51 * @brief This is the internal base class for all controls.
53 * It will provide some common functionality required by all controls.
54 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
55 * be disconnected automatically when the control is destroyed.
57 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
61 // Creation & Destruction
64 * @brief Create a new ControlImpl instance that does not require touch by default.
66 * If touch is required then the user can connect to this class' touch signal.
67 * @return A handle to the ControlImpl instance.
69 static Toolkit::Control New();
72 * @brief Virtual destructor.
79 * @copydoc Dali::CustomActorImpl::GetHeightForWidth()
81 virtual float GetHeightForWidth( float width );
84 * @copydoc Dali::CustomActorImpl::GetWidthForHeight()
86 virtual float GetWidthForHeight( float height );
89 * @copydoc Toolkit::Control::GetNaturalSize()
91 virtual Vector3 GetNaturalSize();
94 * @brief Retrieves the current Control's size.
96 * @return The control's size.
98 const Vector3& GetControlSize() const;
101 * @brief Retrieves the Control's size set by the Application / Control.
103 * @return The control's size.
105 const Vector3& GetSizeSet() const;
110 * @copydoc Toolkit::Control::SetKeyInputFocus()
112 void SetKeyInputFocus();
115 * @copydoc Toolkit::Control::HasKeyInputFocus()
117 bool HasKeyInputFocus();
120 * @copydoc Toolkit::Control::ClearKeyInputFocus()
122 void ClearKeyInputFocus();
127 * @brief If deriving classes wish to fine tune pinch gesture
128 * detection then they can access the gesture detector through this
129 * API and modify the detection.
131 * @return The pinch gesture detector.
132 * @pre Pinch detection should have been enabled via EnableGestureDetection().
133 * @see EnableGestureDetection
135 PinchGestureDetector GetPinchGestureDetector() const;
138 * @brief If deriving classes wish to fine tune pan gesture
139 * detection then they can access the gesture detector through this
140 * API and modify the detection.
142 * @return The pan gesture detector.
143 * @pre Pan detection should have been enabled via EnableGestureDetection().
144 * @see EnableGestureDetection
146 PanGestureDetector GetPanGestureDetector() const;
149 * @brief If deriving classes wish to fine tune tap gesture
150 * detection then they can access the gesture detector through this
151 * API and modify the detection.
153 * @return The tap gesture detector.
154 * @pre Tap detection should have been enabled via EnableGestureDetection().
155 * @see EnableGestureDetection
157 TapGestureDetector GetTapGestureDetector() const;
160 * @brief If deriving classes wish to fine tune long press gesture
161 * detection then they can access the gesture detector through this
162 * API and modify the detection.
164 * @return The long press gesture detector.
165 * @pre Long press detection should have been enabled via EnableGestureDetection().
166 * @see EnableGestureDetection
168 LongPressGestureDetector GetLongPressGestureDetector() const;
173 * @copydoc Dali::Toolkit::Control::SetStyleName
175 void SetStyleName( const std::string& styleName );
178 * @copydoc Dali::Toolkit::Control::GetStyleName
180 const std::string& GetStyleName() const;
183 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
185 void SetBackgroundColor( const Vector4& color );
188 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
190 Vector4 GetBackgroundColor() const;
193 * @copydoc Dali::Toolkit::Control::SetBackgroundImage
195 void SetBackgroundImage( Image image );
198 * @copydoc Dali::Toolkit::Control::ClearBackground
200 void ClearBackground();
203 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
205 Actor GetBackgroundActor() const;
207 // Keyboard Navigation
210 * @brief Sets whether this control supports two dimensional
211 * keyboard navigation (i.e. whether it knows how to handle the
212 * keyboard focus movement between its child actors).
214 * The control doesn't support it by default.
215 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
217 void SetKeyboardNavigationSupport(bool isSupported);
220 * @brief Gets whether this control supports two dimensional keyboard navigation.
222 * @return true if this control supports two dimensional keyboard navigation.
224 bool IsKeyboardNavigationSupported();
226 // Called by Focus Managers
229 * @brief Called by the focus manager and keyboard focus manager to Activate the Control
231 DALI_INTERNAL void Activate();
234 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
237 * @param[in] gesture The pan gesture.
238 * @return true if the pan gesture has been consumed by this control
240 virtual bool OnAccessibilityPan(PanGesture gesture);
243 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
246 * @param[in] touchEvent The touch event.
247 * @return true if the touch event has been consumed by this control
249 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
252 * @brief This method should be overridden by deriving classes when they wish to respond
253 * the accessibility up and down action (i.e. value change of slider control).
255 * @param[in] isIncrease Whether the value should be increased or decreased
256 * @return true if the value changed action has been consumed by this control
258 virtual bool OnAccessibilityValueChange(bool isIncrease);
263 * @brief Sets whether this control is a focus group for keyboard navigation.
265 * (i.e. the scope of keyboard focus movement
266 * can be limitied to its child actors). The control is not a focus group by default.
267 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
269 void SetAsKeyboardFocusGroup(bool isFocusGroup);
272 * @brief Gets whether this control is a focus group for keyboard navigation.
274 * @return true if this control is set as a focus group for keyboard navigation.
276 bool IsKeyboardFocusGroup();
279 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
281 * A control needs to override this function in order to support two dimensional keyboard navigation.
282 * @param[in] currentFocusedActor The current focused actor.
283 * @param[in] direction The direction to move the focus towards.
284 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
285 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
287 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
290 * @brief Informs this control that its chosen focusable actor will be focused.
292 * This allows the application to preform any actions if wishes
293 * before the focus is actually moved to the chosen actor.
295 * @param[in] commitedFocusableActor The commited focusable actor.
297 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
300 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal
302 * Should be called last by the control after it acts on the Input Focus change.
304 * @param[in] focusGained True if gained, False if lost
306 void EmitKeyInputFocusSignal( bool focusGained );
311 * @brief Performs actions as requested using the action name.
313 * @param[in] object The object on which to perform the action.
314 * @param[in] actionName The action to perform.
315 * @param[in] attributes The attributes with which to perfrom this action.
316 * @return true if action has been accepted by this control
318 static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
321 * Connects a callback function with the object's signals.
322 * @param[in] object The object providing the signal.
323 * @param[in] tracker Used to disconnect the signal.
324 * @param[in] signalName The signal to connect to.
325 * @param[in] functor A newly allocated FunctorDelegate.
326 * @return True if the signal was connected.
327 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
329 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
332 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
334 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
337 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
339 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
342 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
344 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
347 * @brief Called by the KeyInputFocusManager to emit key event signals.
349 * @param[in] event The key event.
350 * @return True if the event was consumed.
352 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
358 // Flags for the constructor
359 enum ControlBehaviour
361 REQUIRES_STYLE_CHANGE_SIGNALS = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 0 ), ///< True if needs to monitor style change signals such as theme/font change
362 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 1 ), ///< True if needs to support keyboard navigation
364 LAST_CONTROL_BEHAVIOUR_FLAG
367 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log< LAST_CONTROL_BEHAVIOUR_FLAG - 1 >::value + 1; ///< Total count of flags
370 * @brief Create a Control.
372 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
374 Control(ControlBehaviour behaviourFlags);
377 * @brief Second phase initialization.
384 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
386 * Gesture detection can be enabled one at a time or in bitwise format as shown:
388 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
390 * @param[in] type The gesture type(s) to enable.
392 void EnableGestureDetection(Gesture::Type type);
395 * @brief Allows deriving classes to disable any of the gesture detectors.
397 * Like EnableGestureDetection, this can also be called using bitwise or.
398 * @param[in] type The gesture type(s) to disable.
399 * @see EnableGetureDetection
401 void DisableGestureDetection(Gesture::Type type);
404 * @copydoc Dali::CustomActorImpl::RelayoutDependentOnChildren()
406 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
410 // For derived classes to override
413 * @brief This method is called after the Control has been initialized.
415 * Derived classes should do any second phase initialization by overriding this method.
417 virtual void OnInitialize();
420 * @brief This method is called when the control is activated.
422 * Derived classes should override this if they wish to be notified when they are activated.
424 virtual void OnActivated();
427 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
429 * @param[in] styleManager The StyleManager object.
430 * @param[in] change Information denoting what has changed.
432 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change );
435 * @brief Called whenever a pinch gesture is detected on this control.
437 * This can be overridden by deriving classes when pinch detection
438 * is enabled. The default behaviour is to scale the control by the
441 * @note If overridden, then the default behaviour will not occur.
442 * @note Pinch detection should be enabled via EnableGestureDetection().
443 * @param[in] pinch The pinch gesture.
444 * @see EnableGestureDetection
446 virtual void OnPinch(const PinchGesture& pinch);
449 * @brief Called whenever a pan gesture is detected on this control.
451 * This should be overridden by deriving classes when pan detection
454 * @note There is no default behaviour with panning.
455 * @note Pan detection should be enabled via EnableGestureDetection().
456 * @param[in] pan The pan gesture.
457 * @see EnableGestureDetection
459 virtual void OnPan( const PanGesture& pan );
462 * @brief Called whenever a tap gesture is detected on this control.
464 * This should be overridden by deriving classes when tap detection
467 * @note There is no default behaviour with a tap.
468 * @note Tap detection should be enabled via EnableGestureDetection().
469 * @param[in] tap The tap gesture.
470 * @see EnableGestureDetection
472 virtual void OnTap( const TapGesture& tap );
475 * @brief Called whenever a long press gesture is detected on this control.
477 * This should be overridden by deriving classes when long press
478 * detection is enabled.
480 * @note There is no default behaviour associated with a long press.
481 * @note Long press detection should be enabled via EnableGestureDetection().
482 * @param[in] longPress The long press gesture.
483 * @see EnableGestureDetection
485 virtual void OnLongPress( const LongPressGesture& longPress );
488 * @brief Called whenever the control is added to the stage.
490 * Could be overridden by derived classes.
492 virtual void OnControlStageConnection();
495 * @brief Called whenever the control is removed from the stage.
497 * Could be overridden by derived classes.
499 virtual void OnControlStageDisconnection();
502 * @brief Called whenever an Actor is added to the control.
504 * Could be overridden by derived classes.
506 * @param[in] child The added actor.
508 virtual void OnControlChildAdd( Actor& child );
511 * @brief Called whenever an Actor is removed from the control.
513 * Could be overridden by derived classes.
515 * @param[in] child The removed actor.
517 virtual void OnControlChildRemove( Actor& child );
520 * @brief Called whenever the Control's size is set.
522 * Could be overridden by derived classes.
524 * @param[in] size The new size.
526 virtual void OnControlSizeSet( const Vector3& size );
529 * @brief Called when the control gains key input focus.
531 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
533 virtual void OnKeyInputFocusGained();
536 * @brief Called when the control loses key input focus.
538 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
540 virtual void OnKeyInputFocusLost();
542 // From CustomActorImpl, derived classes can override these.
545 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
547 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
550 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
552 virtual bool OnTouchEvent(const TouchEvent& event);
555 * @copydoc Dali::CustomActorImpl::OnHoverEvent(const HoverEvent&)
557 virtual bool OnHoverEvent(const HoverEvent& event);
560 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
562 virtual bool OnKeyEvent(const KeyEvent& event);
565 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
567 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
570 * @copydoc Dali::CustomActorImpl::OnCalculateRelayoutSize()
572 virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
575 * @copydoc Dali::CustomActorImpl::OnLayoutNegotiated()
577 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
580 * @copydoc Dali::CustomActorImpl::OnRelayout()
582 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
585 * @copydoc Dali::CustomActorImpl::OnSetResizePolicy()
587 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
590 * @copydoc Dali::CustomActorImpl::CalculateChildSize()
592 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension );
594 // From CustomActorImpl, derived classes should NOT override these.
597 * @brief Sends a request to relayout this control.
599 * The control will be relaid out after the
600 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
602 * It calls OnControlStageConnection() to notify derived classes.
604 * @see Dali::CustomActorImpl::OnStageConnection()
606 virtual void OnStageConnection();
609 * @brief Calls OnControlStageDisconnection() to notify derived classed.
611 * @see Dali::CustomActorImpl::OnStageDisconnection()
613 virtual void OnStageDisconnection();
616 * @brief Sends a request to relayout this control.
618 * The control will be relaid out after the
619 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
620 * calls OnControlChildAdd() to notify derived classes.
622 * @note This method shouldn't be overridden by derived classes.
624 * @param[in] child The added actor.
626 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
628 virtual void OnChildAdd(Actor& child);
631 * @brief Sends a request to relayout this control.
633 * The control will be relaid out after the
634 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
635 * calls OnControlChildRemove() to notify derived classes.
637 * @note This method shouldn't be overridden by derived classes.
639 * @param[in] child The removed actor.
641 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
643 virtual void OnChildRemove(Actor& child);
646 * @brief It stores the size set by size negotiation and relayout.
648 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
649 * It calls the OnControlSizeSet() to notify derived classes.
651 * @param[in] targetSize The new size.
653 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
655 virtual void OnSizeSet(const Vector3& targetSize);
657 // From ConnectionTrackerInterface
660 * @copydoc ConnectionTrackerInterface::SignalConnected
662 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
665 * @copydoc ConnectionTrackerInterface::SignalDisconnected
667 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
672 DALI_INTERNAL Control(const Control&);
673 DALI_INTERNAL Control& operator=(const Control&);
678 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call several methods which are private. // TODO: Remove
681 } // namespace Internal
683 } // namespace Toolkit
687 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__