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/events/long-press-gesture.h>
24 #include <dali/public-api/events/pan-gesture.h>
25 #include <dali/public-api/events/pinch-gesture.h>
26 #include <dali/public-api/events/tap-gesture.h>
27 #include <dali/public-api/object/property-index-ranges.h>
28 #include <dali/public-api/object/type-info.h>
31 #include <dali-toolkit/public-api/controls/control.h>
41 namespace Internal DALI_INTERNAL
43 class KeyInputFocusManager;
50 * @brief This is the internal base class for all controls.
52 * It will provide some common functionality required by all controls.
53 * Implements ConnectionTrackerInterface so that signals (typically connected to member functions) will
54 * be disconnected automatically when the control is destroyed.
56 class DALI_IMPORT_API Control : public CustomActorImpl, public ConnectionTrackerInterface
60 // Creation & Destruction
63 * @brief 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 ControlImpl instance.
68 static Toolkit::Control New();
71 * @brief Virtual destructor.
78 * @copydoc Dali::CustomActorImpl::GetHeightForWidth()
80 virtual float GetHeightForWidth( float width );
83 * @copydoc Dali::CustomActorImpl::GetWidthForHeight()
85 virtual float GetWidthForHeight( float height );
88 * @copydoc Toolkit::Control::GetNaturalSize()
90 virtual Vector3 GetNaturalSize();
93 * @brief Retrieves the current Control's size.
95 * @return The control's size.
97 const Vector3& GetControlSize() const;
100 * @brief Retrieves the Control's size set by the Application / Control.
102 * @return The control's size.
104 const Vector3& GetSizeSet() const;
109 * @copydoc Toolkit::Control::SetKeyInputFocus()
111 void SetKeyInputFocus();
114 * @copydoc Toolkit::Control::HasKeyInputFocus()
116 bool HasKeyInputFocus();
119 * @copydoc Toolkit::Control::ClearKeyInputFocus()
121 void ClearKeyInputFocus();
126 * @brief If deriving classes wish to fine tune pinch gesture
127 * detection then they can access the gesture detector through this
128 * API and modify the detection.
130 * @return The pinch gesture detector.
131 * @pre Pinch detection should have been enabled via EnableGestureDetection().
132 * @see EnableGestureDetection
134 PinchGestureDetector GetPinchGestureDetector() const;
137 * @brief If deriving classes wish to fine tune pan gesture
138 * detection then they can access the gesture detector through this
139 * API and modify the detection.
141 * @return The pan gesture detector.
142 * @pre Pan detection should have been enabled via EnableGestureDetection().
143 * @see EnableGestureDetection
145 PanGestureDetector GetPanGestureDetector() const;
148 * @brief If deriving classes wish to fine tune tap gesture
149 * detection then they can access the gesture detector through this
150 * API and modify the detection.
152 * @return The tap gesture detector.
153 * @pre Tap detection should have been enabled via EnableGestureDetection().
154 * @see EnableGestureDetection
156 TapGestureDetector GetTapGestureDetector() const;
159 * @brief If deriving classes wish to fine tune long press gesture
160 * detection then they can access the gesture detector through this
161 * API and modify the detection.
163 * @return The long press gesture detector.
164 * @pre Long press detection should have been enabled via EnableGestureDetection().
165 * @see EnableGestureDetection
167 LongPressGestureDetector GetLongPressGestureDetector() const;
172 * @copydoc Dali::Toolkit::Control::SetStyleName
174 void SetStyleName( const std::string& styleName );
177 * @copydoc Dali::Toolkit::Control::GetStyleName
179 const std::string& GetStyleName() const;
182 * @copydoc Dali::Toolkit::Control::SetBackgroundColor
184 void SetBackgroundColor( const Vector4& color );
187 * @copydoc Dali::Toolkit::Control::GetBackgroundColor
189 Vector4 GetBackgroundColor() const;
192 * @copydoc Dali::Toolkit::Control::SetBackgroundImage
194 void SetBackgroundImage( Image image );
197 * @copydoc Dali::Toolkit::Control::ClearBackground
199 void ClearBackground();
202 * @copydoc Dali::Toolkit::Control::GetBackgroundActor
204 Actor GetBackgroundActor() const;
206 // Keyboard Navigation
209 * @brief Sets whether this control supports two dimensional
210 * keyboard navigation (i.e. whether it knows how to handle the
211 * keyboard focus movement between its child actors).
213 * The control doesn't support it by default.
214 * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
216 void SetKeyboardNavigationSupport(bool isSupported);
219 * @brief Gets whether this control supports two dimensional keyboard navigation.
221 * @return true if this control supports two dimensional keyboard navigation.
223 bool IsKeyboardNavigationSupported();
225 // Called by Focus Managers
228 * @brief Called by the focus manager and keyboard focus manager to Activate the Control
230 DALI_INTERNAL void Activate();
233 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
236 * @param[in] gesture The pan gesture.
237 * @return true if the pan gesture has been consumed by this control
239 virtual bool OnAccessibilityPan(PanGesture gesture);
242 * @brief This method should be overridden by deriving classes when they wish to respond the accessibility
245 * @param[in] touchEvent The touch event.
246 * @return true if the touch event has been consumed by this control
248 virtual bool OnAccessibilityTouch(const TouchEvent& touchEvent);
251 * @brief This method should be overridden by deriving classes when they wish to respond
252 * the accessibility up and down action (i.e. value change of slider control).
254 * @param[in] isIncrease Whether the value should be increased or decreased
255 * @return true if the value changed action has been consumed by this control
257 virtual bool OnAccessibilityValueChange(bool isIncrease);
262 * @brief Sets whether this control is a focus group for keyboard navigation.
264 * (i.e. the scope of keyboard focus movement
265 * can be limitied to its child actors). The control is not a focus group by default.
266 * @param[in] isFocusGroup Whether this control is set as a focus group for keyboard navigation.
268 void SetAsKeyboardFocusGroup(bool isFocusGroup);
271 * @brief Gets whether this control is a focus group for keyboard navigation.
273 * @return true if this control is set as a focus group for keyboard navigation.
275 bool IsKeyboardFocusGroup();
278 * @brief Gets the next keyboard focusable actor in this control towards the given direction.
280 * A control needs to override this function in order to support two dimensional keyboard navigation.
281 * @param[in] currentFocusedActor The current focused actor.
282 * @param[in] direction The direction to move the focus towards.
283 * @param[in] loopEnabled Whether the focus movement should be looped within the control.
284 * @return the next keyboard focusable actor in this control or an empty handle if no actor can be focused.
286 virtual Actor GetNextKeyboardFocusableActor(Actor currentFocusedActor, Toolkit::Control::KeyboardFocusNavigationDirection direction, bool loopEnabled);
289 * @brief Informs this control that its chosen focusable actor will be focused.
291 * This allows the application to preform any actions if wishes
292 * before the focus is actually moved to the chosen actor.
294 * @param[in] commitedFocusableActor The commited focusable actor.
296 virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
299 * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal
301 * Should be called last by the control after it acts on the Input Focus change.
303 * @param[in] focusGained True if gained, False if lost
305 void EmitKeyInputFocusSignal( bool focusGained );
310 * @brief Performs actions as requested using the action name.
312 * @param[in] object The object on which to perform the action.
313 * @param[in] actionName The action to perform.
314 * @param[in] attributes The attributes with which to perfrom this action.
315 * @return true if action has been accepted by this control
317 static bool DoAction(BaseObject* object, const std::string& actionName, const PropertyValueContainer& attributes);
320 * Connects a callback function with the object's signals.
321 * @param[in] object The object providing the signal.
322 * @param[in] tracker Used to disconnect the signal.
323 * @param[in] signalName The signal to connect to.
324 * @param[in] functor A newly allocated FunctorDelegate.
325 * @return True if the signal was connected.
326 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
328 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
331 * @copydoc Dali::Toolkit::Control::KeyEventSignal()
333 Toolkit::Control::KeyEventSignalType& KeyEventSignal();
336 * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
338 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
341 * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
343 Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
346 * @brief Called by the KeyInputFocusManager to emit key event signals.
348 * @param[in] event The key event.
349 * @return True if the event was consumed.
351 DALI_INTERNAL bool EmitKeyEventSignal(const KeyEvent& event);
357 // Flags for the constructor
358 enum ControlBehaviour
360 REQUIRES_STYLE_CHANGE_SIGNALS = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 0 ), ///< True if needs to monitor style change signals such as theme/font change
361 REQUIRES_KEYBOARD_NAVIGATION_SUPPORT = 1 << ( CustomActorImpl::ACTOR_FLAG_COUNT + 1 ), ///< True if needs to support keyboard navigation
363 LAST_CONTROL_BEHAVIOUR_FLAG
366 static const int CONTROL_BEHAVIOUR_FLAG_COUNT = Log< LAST_CONTROL_BEHAVIOUR_FLAG - 1 >::value + 1; ///< Total count of flags
369 * @brief Create a Control.
371 * @param[in] behaviourFlags Behavioural flags from ControlBehaviour enum
373 Control(ControlBehaviour behaviourFlags);
376 * @brief Second phase initialization.
383 * @brief Allows deriving classes to enable any of the gesture detectors that are available.
385 * Gesture detection can be enabled one at a time or in bitwise format as shown:
387 * EnableGestureDetection(Gesture::Type(Gesture::Pinch | Gesture::Tap | Gesture::Pan));
389 * @param[in] type The gesture type(s) to enable.
391 void EnableGestureDetection(Gesture::Type type);
394 * @brief Allows deriving classes to disable any of the gesture detectors.
396 * Like EnableGestureDetection, this can also be called using bitwise or.
397 * @param[in] type The gesture type(s) to disable.
398 * @see EnableGetureDetection
400 void DisableGestureDetection(Gesture::Type type);
403 * @copydoc Dali::CustomActorImpl::RelayoutDependentOnChildren()
405 virtual bool RelayoutDependentOnChildren( Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
409 // For derived classes to override
412 * @brief This method is called after the Control has been initialized.
414 * Derived classes should do any second phase initialization by overriding this method.
416 virtual void OnInitialize();
419 * @brief This method is called when the control is activated.
421 * Derived classes should override this if they wish to be notified when they are activated.
423 virtual void OnActivated();
426 * @brief This method should be overridden by deriving classes requiring notifications when the style changes.
428 * @param[in] styleManager The StyleManager object.
429 * @param[in] change Information denoting what has changed.
431 virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange change );
434 * @brief Called whenever a pinch gesture is detected on this control.
436 * This can be overridden by deriving classes when pinch detection
437 * is enabled. The default behaviour is to scale the control by the
440 * @note If overridden, then the default behaviour will not occur.
441 * @note Pinch detection should be enabled via EnableGestureDetection().
442 * @param[in] pinch The pinch gesture.
443 * @see EnableGestureDetection
445 virtual void OnPinch(const PinchGesture& pinch);
448 * @brief Called whenever a pan gesture is detected on this control.
450 * This should be overridden by deriving classes when pan detection
453 * @note There is no default behaviour with panning.
454 * @note Pan detection should be enabled via EnableGestureDetection().
455 * @param[in] pan The pan gesture.
456 * @see EnableGestureDetection
458 virtual void OnPan( const PanGesture& pan );
461 * @brief Called whenever a tap gesture is detected on this control.
463 * This should be overridden by deriving classes when tap detection
466 * @note There is no default behaviour with a tap.
467 * @note Tap detection should be enabled via EnableGestureDetection().
468 * @param[in] tap The tap gesture.
469 * @see EnableGestureDetection
471 virtual void OnTap( const TapGesture& tap );
474 * @brief Called whenever a long press gesture is detected on this control.
476 * This should be overridden by deriving classes when long press
477 * detection is enabled.
479 * @note There is no default behaviour associated with a long press.
480 * @note Long press detection should be enabled via EnableGestureDetection().
481 * @param[in] longPress The long press gesture.
482 * @see EnableGestureDetection
484 virtual void OnLongPress( const LongPressGesture& longPress );
487 * @brief Called whenever the control is added to the stage.
489 * Could be overridden by derived classes.
491 virtual void OnControlStageConnection();
494 * @brief Called whenever the control is removed from the stage.
496 * Could be overridden by derived classes.
498 virtual void OnControlStageDisconnection();
501 * @brief Called whenever an Actor is added to the control.
503 * Could be overridden by derived classes.
505 * @param[in] child The added actor.
507 virtual void OnControlChildAdd( Actor& child );
510 * @brief Called whenever an Actor is removed from the control.
512 * Could be overridden by derived classes.
514 * @param[in] child The removed actor.
516 virtual void OnControlChildRemove( Actor& child );
519 * @brief Called whenever the Control's size is set.
521 * Could be overridden by derived classes.
523 * @param[in] size The new size.
525 virtual void OnControlSizeSet( const Vector3& size );
528 * @brief Called when the control gains key input focus.
530 * Should be overridden by derived classes if they need to customize what happens when focus is gained.
532 virtual void OnKeyInputFocusGained();
535 * @brief Called when the control loses key input focus.
537 * Should be overridden by derived classes if they need to customize what happens when focus is lost.
539 virtual void OnKeyInputFocusLost();
541 // From CustomActorImpl, derived classes can override these.
544 * @copydoc Dali::CustomActorImpl::OnSizeAnimation(Animation&, const Vector3&)
546 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize);
549 * @copydoc Dali::CustomActorImpl::OnTouchEvent(const TouchEvent&)
551 virtual bool OnTouchEvent(const TouchEvent& event);
554 * @copydoc Dali::CustomActorImpl::OnHoverEvent(const HoverEvent&)
556 virtual bool OnHoverEvent(const HoverEvent& event);
559 * @copydoc Dali::CustomActorImpl::OnKeyEvent(const KeyEvent&)
561 virtual bool OnKeyEvent(const KeyEvent& event);
564 * @copydoc Dali::CustomActorImpl::OnMouseWheelEvent(const MouseWheelEvent&)
566 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event);
569 * @copydoc Dali::CustomActorImpl::OnCalculateRelayoutSize()
571 virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
574 * @copydoc Dali::CustomActorImpl::OnLayoutNegotiated()
576 virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
579 * @copydoc Dali::CustomActorImpl::OnRelayout()
581 virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
584 * @copydoc Dali::CustomActorImpl::OnSetResizePolicy()
586 virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension );
589 * @copydoc Dali::CustomActorImpl::CalculateChildSize()
591 virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension );
593 // From CustomActorImpl, derived classes should NOT override these.
596 * @brief Sends a request to relayout this control.
598 * The control will be relaid out after the
599 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted.
601 * It calls OnControlStageConnection() to notify derived classes.
603 * @see Dali::CustomActorImpl::OnStageConnection()
605 virtual void OnStageConnection();
608 * @brief Calls OnControlStageDisconnection() to notify derived classed.
610 * @see Dali::CustomActorImpl::OnStageDisconnection()
612 virtual void OnStageDisconnection();
615 * @brief Sends a request to relayout this control.
617 * The control will be relaid out after the
618 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
619 * calls OnControlChildAdd() to notify derived classes.
621 * @note This method shouldn't be overridden by derived classes.
623 * @param[in] child The added actor.
625 * @see Dali::CustomActorImpl::OnChildAdd(Actor&)
627 virtual void OnChildAdd(Actor& child);
630 * @brief Sends a request to relayout this control.
632 * The control will be relaid out after the
633 * Dali::Stage::SignalMessageQueueFlushed() signal is emitted. It
634 * calls OnControlChildRemove() to notify derived classes.
636 * @note This method shouldn't be overridden by derived classes.
638 * @param[in] child The removed actor.
640 * @see Dali::CustomActorImpl::OnChildRemove(Actor&)
642 virtual void OnChildRemove(Actor& child);
645 * @brief It stores the size set by size negotiation and relayout.
647 * It also keeps a backup of the size set through the Actor's API used in the size negotiation.
648 * It calls the OnControlSizeSet() to notify derived classes.
650 * @param[in] targetSize The new size.
652 * @see Dali::CustomActorImpl::OnSizeSet(const Vector3&)
654 virtual void OnSizeSet(const Vector3& targetSize);
656 // From ConnectionTrackerInterface
659 * @copydoc ConnectionTrackerInterface::SignalConnected
661 virtual void SignalConnected( SlotObserver* slotObserver, CallbackBase* callback );
664 * @copydoc ConnectionTrackerInterface::SignalDisconnected
666 virtual void SignalDisconnected( SlotObserver* slotObserver, CallbackBase* callback );
671 DALI_INTERNAL Control(const Control&);
672 DALI_INTERNAL Control& operator=(const Control&);
677 friend class Internal::KeyInputFocusManager; ///< KeyInputFocusManager needs to call several methods which are private. // TODO: Remove
680 } // namespace Internal
682 } // namespace Toolkit
686 #endif // __DALI_TOOLKIT_CONTROL_IMPL_H__