Controls to Emit Signals when Key Input Focus lost or gained 11/38511/4
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 21 Apr 2015 13:36:35 +0000 (14:36 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Tue, 21 Apr 2015 15:56:48 +0000 (16:56 +0100)
Change-Id: Iecc83cf41be7783436fa5a936d1e17e8afa1f692
Signed-off-by: Agnelo Vaz <agnelo.vaz@samsung.com>
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/public-api/controls/control-impl.cpp
dali-toolkit/public-api/controls/control-impl.h
dali-toolkit/public-api/controls/control.cpp
dali-toolkit/public-api/controls/control.h

index f17ea34..bf87e6c 100644 (file)
@@ -514,6 +514,8 @@ void TextField::OnKeyInputFocusGained()
   }
 
   mController->KeyboardFocusGainEvent();
+
+  EmitKeyInputFocusSignal( true ); // Calls back into the Control hence done last.
 }
 
 void TextField::OnKeyInputFocusLost()
@@ -533,6 +535,8 @@ void TextField::OnKeyInputFocusLost()
   }
 
   mController->KeyboardFocusLostEvent();
+
+  EmitKeyInputFocusSignal( false ); // Calls back into the Control hence done last.
 }
 
 void TextField::OnTap( const TapGesture& gesture )
index ee67dad..17161d0 100644 (file)
@@ -67,11 +67,13 @@ DALI_TYPE_REGISTRATION_BEGIN( Control, CustomActor, Create );
 
 // Note: Properties are registered separately below,
 
-DALI_SIGNAL_REGISTRATION( Control, "key-event",                 SIGNAL_KEY_EVENT         )
-DALI_SIGNAL_REGISTRATION( Control, "tapped",                    SIGNAL_TAPPED            )
-DALI_SIGNAL_REGISTRATION( Control, "panned",                    SIGNAL_PANNED            )
-DALI_SIGNAL_REGISTRATION( Control, "pinched",                   SIGNAL_PINCHED           )
-DALI_SIGNAL_REGISTRATION( Control, "long-pressed",              SIGNAL_LONG_PRESSED      )
+DALI_SIGNAL_REGISTRATION( Control, "key-event",                 SIGNAL_KEY_EVENT              )
+DALI_SIGNAL_REGISTRATION( Control, "key-input-focus-gained",    SIGNAL_KEY_INPUT_FOCUS_GAINED )
+DALI_SIGNAL_REGISTRATION( Control, "key-input-focus-lost",      SIGNAL_KEY_INPUT_FOCUS_LOST   )
+DALI_SIGNAL_REGISTRATION( Control, "tapped",                    SIGNAL_TAPPED                 )
+DALI_SIGNAL_REGISTRATION( Control, "panned",                    SIGNAL_PANNED                 )
+DALI_SIGNAL_REGISTRATION( Control, "pinched",                   SIGNAL_PINCHED                )
+DALI_SIGNAL_REGISTRATION( Control, "long-pressed",              SIGNAL_LONG_PRESSED           )
 
 DALI_ACTION_REGISTRATION( Control, "control-activated",         ACTION_CONTROL_ACTIVATED )
 
@@ -380,6 +382,8 @@ public:
   Background* mBackground;           ///< Only create the background if we use it
   Vector3* mStartingPinchScale;      ///< The scale when a pinch gesture starts, TODO: consider removing this
   Toolkit::Control::KeyEventSignalType mKeyEventSignal;
+  Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusGainedSignal;
+  Toolkit::Control::KeyInputFocusSignalType mKeyInputFocusLostSignal;
 
   // Gesture Detection
   PinchGestureDetector mPinchGestureDetector;
@@ -699,6 +703,14 @@ bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* t
     {
       controlImpl.KeyEventSignal().Connect( tracker, functor );
     }
+    else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_GAINED ) )
+    {
+      controlImpl.KeyInputFocusGainedSignal().Connect( tracker, functor );
+    }
+    else if( 0 == strcmp( signalName.c_str(), SIGNAL_KEY_INPUT_FOCUS_LOST ) )
+    {
+      controlImpl.KeyInputFocusLostSignal().Connect( tracker, functor );
+    }
     else if( 0 == strcmp( signalName.c_str(), SIGNAL_TAPPED ) )
     {
       controlImpl.EnableGestureDetection( Gesture::Tap );
@@ -733,6 +745,16 @@ Toolkit::Control::KeyEventSignalType& Control::KeyEventSignal()
   return mImpl->mKeyEventSignal;
 }
 
+Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusGainedSignal()
+{
+  return mImpl->mKeyInputFocusGainedSignal;
+}
+
+Toolkit::Control::KeyInputFocusSignalType& Control:: KeyInputFocusLostSignal()
+{
+  return mImpl->mKeyInputFocusLostSignal;
+}
+
 bool Control::EmitKeyEventSignal( const KeyEvent& event )
 {
   // Guard against destruction during signal emission
@@ -929,14 +951,36 @@ void Control::OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dime
 {
 }
 
+void Control::EmitKeyInputFocusSignal( bool focusGained )
+{
+  Dali::Toolkit::Control handle( GetOwner() );
+
+  if ( focusGained )
+  {
+     // signals are allocated dynamically when someone connects
+     if ( !mImpl->mKeyInputFocusGainedSignal.Empty() )
+     {
+      mImpl->mKeyInputFocusGainedSignal.Emit( handle );
+     }
+  }
+  else
+  {
+    // signals are allocated dynamically when someone connects
+    if ( !mImpl->mKeyInputFocusLostSignal.Empty() )
+    {
+      mImpl->mKeyInputFocusLostSignal.Emit( handle );
+    }
+  }
+}
+
 void Control::OnKeyInputFocusGained()
 {
-  // Do Nothing
+  EmitKeyInputFocusSignal( true );
 }
 
 void Control::OnKeyInputFocusLost()
 {
-  // Do Nothing
+  EmitKeyInputFocusSignal( false );
 }
 
 void Control::OnSizeAnimation(Animation& animation, const Vector3& targetSize)
index 7f14784..35e679f 100644 (file)
@@ -209,7 +209,7 @@ public:
   /**
    * @brief Sets whether this control supports two dimensional
    * keyboard navigation (i.e. whether it knows how to handle the
-   * keyboardn focus movement between its child actors).
+   * keyboard focus movement between its child actors).
    *
    * The control doesn't support it by default.
    * @param[in] isSupported Whether this control supports two dimensional keyboard navigation.
@@ -296,6 +296,15 @@ public:
    */
   virtual void OnKeyboardFocusChangeCommitted(Actor commitedFocusableActor);
 
+  /**
+   * @brief Emits KeyInputFocusGained signal if true else emits KeyInputFocusLost signal
+   *
+   * Should be called last by the control after it acts on the Input Focus change.
+   *
+   * @param[in] focusGained True if gained, False if lost
+   */
+  void EmitKeyInputFocusSignal( bool focusGained );
+
   // Actions & Signals
 
   /**
@@ -325,6 +334,16 @@ public:
   Toolkit::Control::KeyEventSignalType& KeyEventSignal();
 
   /**
+   * @copydoc Dali::Toolkit::Control::KeyInputFocusGainedSignal()
+   */
+  Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusGainedSignal();
+
+  /**
+   * @copydoc Dali::Toolkit::Control::KeyInputFocusLostSignal()
+   */
+  Toolkit::Control::KeyInputFocusSignalType& KeyInputFocusLostSignal();
+
+  /**
    * @brief Called by the KeyInputFocusManager to emit key event signals.
    *
    * @param[in] event The key event.
index 63d15a8..5bbc4e7 100644 (file)
@@ -144,6 +144,16 @@ Control::KeyEventSignalType& Control::KeyEventSignal()
   return GetImplementation().KeyEventSignal();
 }
 
+Control::KeyInputFocusSignalType& Control::KeyInputFocusGainedSignal()
+{
+  return GetImplementation().KeyInputFocusGainedSignal();
+}
+
+Control::KeyInputFocusSignalType& Control::KeyInputFocusLostSignal()
+{
+  return GetImplementation().KeyInputFocusLostSignal();
+}
+
 Control::Control(Internal::Control& implementation)
 : CustomActor(implementation)
 {
index f0f216b..7e4e693 100644 (file)
@@ -48,13 +48,15 @@ class Control;
  * @see Internal::Control
  *
  * Signals
- * | %Signal Name      | Method                                              |
- * |-------------------|-----------------------------------------------------|
- * | key-event         | @ref KeyEventSignal()                               |
- * | tapped            | @ref GetTapGestureDetector().DetectedSignal()       |
- * | panned            | @ref GetPanGestureDetector().DetectedSignal()       |
- * | pinched           | @ref GetPinchGestureDetector().DetectedSignal()     |
- * | long-pressed      | @ref GetLongPressGestureDetector().DetectedSignal() |
+ * | %Signal Name           | Method                                              |
+ * |------------------------|-----------------------------------------------------|
+ * | key-event              | @ref KeyEventSignal()                               |
+ * | key-input-focus-gained | @ref KeyInputFocusGainedSignal()                    |
+ * | key-input-focus-lost   | @ref KeyInputFocusLostSignal()                      |
+ * | tapped                 | @ref GetTapGestureDetector().DetectedSignal()       |
+ * | panned                 | @ref GetPanGestureDetector().DetectedSignal()       |
+ * | pinched                | @ref GetPinchGestureDetector().DetectedSignal()     |
+ * | long-pressed           | @ref GetLongPressGestureDetector().DetectedSignal() |
  *
  * Actions
  * | %Action Name      | %Control method called                              |
@@ -105,6 +107,9 @@ public:
   /// @brief Key Event signal type;
   typedef Signal<bool ( Control, const KeyEvent& ) > KeyEventSignalType;
 
+  /// @brief Key InputFocusType signal type;
+  typedef Signal<void ( Control ) > KeyInputFocusSignalType;
+
 public: // Creation & Destruction
 
   /**
@@ -307,13 +312,43 @@ public:
    * @code
    *   bool YourCallbackName(Control control, const KeyEvent& event);
    * @endcode
-   * The return value of True, indicates that the touch event should be consumed.
-   * Otherwise the signal will be emitted on the next sensitive parent of the actor.
+   * The return value of True, indicates that the event should be consumed.
+   * Otherwise the signal will be emitted on the next parent of the actor.
    * @pre The Control has been initialized.
    * @return The signal to connect to.
    */
   KeyEventSignalType& KeyEventSignal();
 
+  /**
+   * @brief This signal is emitted when the control gets Key Input Focus
+   *
+   * A callback of the following type may be connected:
+   * @code
+   *   bool YourCallbackName( Control control );
+   * @endcode
+   * The return value of True, indicates that the event should be consumed.
+   * Otherwise the signal will be emitted on the next parent of the actor.
+   * @pre The Control has been initialized.
+   * @return The signal to connect to.
+   */
+  KeyInputFocusSignalType& KeyInputFocusGainedSignal();
+
+  /**
+   * @brief This signal is emitted when the control loses Key Input Focus
+   * which could be due to it being gained by another Control or Actor or just cleared from
+   * this control as no longer required.
+   *
+   * A callback of the following type may be connected:
+   * @code
+   *   bool YourCallbackName( Control control );
+   * @endcode
+   * The return value of True, indicates that the event should be consumed.
+   * Otherwise the signal will be emitted on the next parent of the actor.
+   * @pre The Control has been initialized.
+   * @return The signal to connect to.
+   */
+  KeyInputFocusSignalType& KeyInputFocusLostSignal();
+
 public: // Intended for control developers
 
   /**