(Control) Can connect to gestures through scripting 75/26775/2
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 28 Aug 2014 14:36:21 +0000 (15:36 +0100)
committerAdeel Kazmi <adeel.kazmi@samsung.com>
Thu, 28 Aug 2014 14:44:12 +0000 (15:44 +0100)
Change-Id: Ica8d74426994d2f3a0398cf6bb0907508491823d

base/dali-toolkit/public-api/controls/control-impl.cpp
base/dali-toolkit/public-api/controls/control-impl.h
base/dali-toolkit/public-api/controls/control.cpp
base/dali-toolkit/public-api/controls/control.h

index 975152e..99174c4 100644 (file)
@@ -76,6 +76,12 @@ TypeRegistration CONTROL_TYPE( typeid(Control), typeid(CustomActor), Create );
 
 TypeAction ACTION_TYPE_1( CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction );
 
 
 TypeAction ACTION_TYPE_1( CONTROL_TYPE, Toolkit::Control::ACTION_CONTROL_ACTIVATED, &Internal::Control::DoAction );
 
+SignalConnectorType SIGNAL_CONNECTOR_1( CONTROL_TYPE, Toolkit::Control::SIGNAL_KEY_EVENT,     &Internal::Control::DoConnectSignal );
+SignalConnectorType SIGNAL_CONNECTOR_2( CONTROL_TYPE, Toolkit::Control::SIGNAL_TAPPED,        &Internal::Control::DoConnectSignal );
+SignalConnectorType SIGNAL_CONNECTOR_3( CONTROL_TYPE, Toolkit::Control::SIGNAL_PANNED,        &Internal::Control::DoConnectSignal );
+SignalConnectorType SIGNAL_CONNECTOR_4( CONTROL_TYPE, Toolkit::Control::SIGNAL_PINCHED,       &Internal::Control::DoConnectSignal );
+SignalConnectorType SIGNAL_CONNECTOR_5( CONTROL_TYPE, Toolkit::Control::SIGNAL_LONG_PRESSED,  &Internal::Control::DoConnectSignal );
+
 /**
  * Structure which holds information about the background of a control
  */
 /**
  * Structure which holds information about the background of a control
  */
@@ -945,6 +951,50 @@ bool Control::DoAction(BaseObject* object, const std::string& actionName, const
   return ret;
 }
 
   return ret;
 }
 
+bool Control::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
+{
+  Dali::BaseHandle handle( object );
+
+  bool connected( false );
+  Toolkit::Control control = Toolkit::Control::DownCast(handle);
+  if ( control )
+  {
+    Control& controlImpl( control.GetImplementation() );
+    connected = true;
+
+    if ( Toolkit::Control::SIGNAL_KEY_EVENT == signalName )
+    {
+      controlImpl.KeyEventSignal().Connect( tracker, functor );
+    }
+    else if( Toolkit::Control::SIGNAL_TAPPED == signalName )
+    {
+      controlImpl.EnableGestureDetection( Gesture::Tap );
+      controlImpl.GetTapGestureDetector().DetectedSignal().Connect( tracker, functor );
+    }
+    else if( Toolkit::Control::SIGNAL_PANNED == signalName )
+    {
+      controlImpl.EnableGestureDetection( Gesture::Pan );
+      controlImpl.GetPanGestureDetector().DetectedSignal().Connect( tracker, functor );
+    }
+    else if( Toolkit::Control::SIGNAL_PINCHED == signalName )
+    {
+      controlImpl.EnableGestureDetection( Gesture::Pinch );
+      controlImpl.GetPinchGestureDetector().DetectedSignal().Connect( tracker, functor );
+    }
+    else if( Toolkit::Control::SIGNAL_LONG_PRESSED == signalName )
+    {
+      controlImpl.EnableGestureDetection( Gesture::LongPress );
+      controlImpl.GetLongPressGestureDetector().DetectedSignal().Connect( tracker, functor );
+    }
+    else
+    {
+      // signalName does not match any signal
+      connected = false;
+    }
+  }
+  return connected;
+}
+
 void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
 {
   if( change.themeChange )
 void Control::DoStyleChange( Toolkit::StyleManager styleManager, StyleChange change )
 {
   if( change.themeChange )
index df822ef..71ffabc 100644 (file)
@@ -179,6 +179,17 @@ public:
   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
 
   /**
   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
 
   /**
+   * Connects a callback function with the object's signals.
+   * @param[in] object The object providing the signal.
+   * @param[in] tracker Used to disconnect the signal.
+   * @param[in] signalName The signal to connect to.
+   * @param[in] functor A newly allocated FunctorDelegate.
+   * @return True if the signal was connected.
+   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
+   */
+  static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
+
+  /**
    * @brief If deriving classes wish to fine tune pinch gesture
    * detection then they can access the gesture detector through this
    * API and modify the detection.
    * @brief If deriving classes wish to fine tune pinch gesture
    * detection then they can access the gesture detector through this
    * API and modify the detection.
index 917a5b9..d01ad83 100644 (file)
@@ -25,7 +25,12 @@ namespace Toolkit
 {
 
 const char* const Control::ACTION_CONTROL_ACTIVATED = "control-activated";
 {
 
 const char* const Control::ACTION_CONTROL_ACTIVATED = "control-activated";
+
 const char* const Control::SIGNAL_KEY_EVENT = "key-event";
 const char* const Control::SIGNAL_KEY_EVENT = "key-event";
+const char* const Control::SIGNAL_TAPPED = "tapped";
+const char* const Control::SIGNAL_PANNED = "panned";
+const char* const Control::SIGNAL_PINCHED = "pinched";
+const char* const Control::SIGNAL_LONG_PRESSED = "long-pressed";
 
 Control Control::New()
 {
 
 Control Control::New()
 {
index 82ab066..951c2b6 100644 (file)
@@ -58,6 +58,10 @@ public:
   /// @name Signals
   /** @{ */
   static const char* const SIGNAL_KEY_EVENT;                 ///< name "key-event"
   /// @name Signals
   /** @{ */
   static const char* const SIGNAL_KEY_EVENT;                 ///< name "key-event"
+  static const char* const SIGNAL_TAPPED;                    ///< name "tapped"
+  static const char* const SIGNAL_PANNED;                    ///< name "panned"
+  static const char* const SIGNAL_PINCHED;                   ///< name "pinched"
+  static const char* const SIGNAL_LONG_PRESSED;              ///< name "long-pressed"
   /** @} */
 
   /// @name Actions
   /** @} */
 
   /// @name Actions