Upgrade gesture handler (#1180)
authorneostom432 <31119276+neostom432@users.noreply.github.com>
Wed, 11 Dec 2019 10:01:09 +0000 (19:01 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Wed, 11 Dec 2019 10:01:09 +0000 (19:01 +0900)
* Support multiple callbacks for gesture event

* Change other gestures

src/Tizen.NUI/Tizen.NUI.sln
src/Tizen.NUI/src/public/LongPressGestureDetector.cs
src/Tizen.NUI/src/public/PanGestureDetector.cs
src/Tizen.NUI/src/public/PinchGestureDetector.cs
src/Tizen.NUI/src/public/RotationGestureDetector.cs
src/Tizen.NUI/src/public/TapGestureDetector.cs

index bcf6ac3..ffbf8ff 100755 (executable)
@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.26430.12
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.29519.87
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.NUI", "Tizen.NUI.csproj", "{473C3BEC-2F67-4285-85FC-BF4E96BFFF1C}"
 EndProject
@@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.Common",
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.Applications.ComponentBased", "..\Tizen.Applications.ComponentBased\Tizen.Applications.ComponentBased.csproj", "{A9B4744E-EECC-44B6-8357-843DD20617EC}"
 EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tizen.NUI.Components", "..\Tizen.NUI.Components\Tizen.NUI.Components.csproj", "{A3F5B81C-E1C9-4DC6-BC57-9682D300AE86}"
+EndProject
 Global
        GlobalSection(SolutionConfigurationPlatforms) = preSolution
                Debug|Any CPU = Debug|Any CPU
@@ -41,8 +43,19 @@ Global
                {2AEDCAA7-543F-48A1-BEA3-CF3E14F6EDC2}.Debug|Any CPU.Build.0 = Debug|Any CPU
                {2AEDCAA7-543F-48A1-BEA3-CF3E14F6EDC2}.Release|Any CPU.ActiveCfg = Release|Any CPU
                {2AEDCAA7-543F-48A1-BEA3-CF3E14F6EDC2}.Release|Any CPU.Build.0 = Release|Any CPU
+               {A9B4744E-EECC-44B6-8357-843DD20617EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {A9B4744E-EECC-44B6-8357-843DD20617EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {A9B4744E-EECC-44B6-8357-843DD20617EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {A9B4744E-EECC-44B6-8357-843DD20617EC}.Release|Any CPU.Build.0 = Release|Any CPU
+               {A3F5B81C-E1C9-4DC6-BC57-9682D300AE86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+               {A3F5B81C-E1C9-4DC6-BC57-9682D300AE86}.Debug|Any CPU.Build.0 = Debug|Any CPU
+               {A3F5B81C-E1C9-4DC6-BC57-9682D300AE86}.Release|Any CPU.ActiveCfg = Release|Any CPU
+               {A3F5B81C-E1C9-4DC6-BC57-9682D300AE86}.Release|Any CPU.Build.0 = Release|Any CPU
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
        EndGlobalSection
+       GlobalSection(ExtensibilityGlobals) = postSolution
+               SolutionGuid = {5E9D6A9F-1A8C-47A9-9666-0B1900CF03FD}
+       EndGlobalSection
 EndGlobal
index 6829753..302f97f 100755 (executable)
@@ -33,9 +33,6 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
-        private DaliEventHandler<object, DetectedEventArgs> _longPressGestureEventHandler;
-        private DetectedCallbackDelegate _longPressGestureCallbackDelegate;
-
         /// <summary>
         /// Constructor.
         /// </summary>
@@ -87,8 +84,10 @@ namespace Tizen.NUI
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
+        private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr longPressGesture);
+        private delegate void DetectedCallbackType(IntPtr actor, IntPtr longPressGesture);
+        private DetectedCallbackType _detectedCallback;
 
         /// <summary>
         /// This signal is emitted when the specified long press is detected on the attached view.
@@ -99,29 +98,22 @@ namespace Tizen.NUI
         {
             add
             {
-                lock (this)
+                if (_detectedEventHandler == null)
                 {
-                    // Restricted to only one listener.
-                    if (_longPressGestureEventHandler == null)
-                    {
-                        _longPressGestureEventHandler += value;
-
-                        _longPressGestureCallbackDelegate = new DetectedCallbackDelegate(OnLongPressGestureDetected);
-                        this.DetectedSignal().Connect(_longPressGestureCallbackDelegate);
-                    }
+                    _detectedCallback = OnLongPressGestureDetected;
+                    DetectedSignal().Connect(_detectedCallback);
                 }
+
+                _detectedEventHandler += value;
             }
 
             remove
             {
-                lock (this)
-                {
-                    if (_longPressGestureEventHandler != null)
-                    {
-                        this.DetectedSignal().Disconnect(_longPressGestureCallbackDelegate);
-                    }
+                _detectedEventHandler -= value;
 
-                    _longPressGestureEventHandler -= value;
+                if (_detectedEventHandler == null && DetectedSignal().Empty() == false)
+                {
+                    DetectedSignal().Disconnect(_detectedCallback);
                 }
             }
         }
@@ -254,10 +246,10 @@ namespace Tizen.NUI
 
             e.LongPressGesture = Tizen.NUI.LongPressGesture.GetLongPressGestureFromPtr(longPressGesture);
 
-            if (_longPressGestureEventHandler != null)
+            if (_detectedEventHandler != null)
             {
                 //Here we send all data to user event handlers.
-                _longPressGestureEventHandler(this, e);
+                _detectedEventHandler(this, e);
             }
         }
 
index 5490cf9..407d0cb 100755 (executable)
@@ -30,9 +30,6 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
-        private DaliEventHandler<object, DetectedEventArgs> _panGestureEventHandler;
-        private DetectedCallbackDelegate _panGestureCallbackDelegate;
-
         /// <summary>
         /// Creates an initialized PanGestureDetector.
         /// </summary>
@@ -60,9 +57,10 @@ namespace Tizen.NUI
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
-
+        private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr panGesture);
+        private delegate void DetectedCallbackType(IntPtr actor, IntPtr panGesture);
+        private DetectedCallbackType _detectedCallback;
 
         /// <summary>
         /// This signal is emitted when the specified pan is detected on the attached view.
@@ -73,29 +71,22 @@ namespace Tizen.NUI
         {
             add
             {
-                lock (this)
+                if (_detectedEventHandler == null)
                 {
-                    // Restricted to only one listener
-                    if (_panGestureEventHandler == null)
-                    {
-                        _panGestureEventHandler += value;
-
-                        _panGestureCallbackDelegate = new DetectedCallbackDelegate(OnPanGestureDetected);
-                        this.DetectedSignal().Connect(_panGestureCallbackDelegate);
-                    }
+                    _detectedCallback = OnPanGestureDetected;
+                    DetectedSignal().Connect(_detectedCallback);
                 }
+
+                _detectedEventHandler += value;
             }
 
             remove
             {
-                lock (this)
-                {
-                    if (_panGestureEventHandler != null)
-                    {
-                        this.DetectedSignal().Disconnect(_panGestureCallbackDelegate);
-                    }
+                _detectedEventHandler -= value;
 
-                    _panGestureEventHandler -= value;
+                if (_detectedEventHandler == null && DetectedSignal().Empty() == false)
+                {
+                    DetectedSignal().Disconnect(_detectedCallback);
                 }
             }
         }
@@ -541,6 +532,10 @@ namespace Tizen.NUI
             //Release your own unmanaged resources here.
             //You should not access any managed member here except static instance.
             //because the execution order of Finalizes is non-deterministic.
+            if (_detectedCallback != null)
+            {
+                DetectedSignal().Disconnect(_detectedCallback);
+            }
 
             if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
@@ -568,10 +563,9 @@ namespace Tizen.NUI
 
             e.PanGesture = Tizen.NUI.PanGesture.GetPanGestureFromPtr(panGesture);
 
-            if (_panGestureEventHandler != null)
+            if (_detectedEventHandler != null)
             {
-                //here we send all data to user event handlers
-                _panGestureEventHandler(this, e);
+                _detectedEventHandler(this, e);
             }
         }
 
index 773a014..590ac77 100755 (executable)
@@ -30,9 +30,6 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
-        private DaliEventHandler<object, DetectedEventArgs> _pinchGestureEventHandler;
-        private DetectedCallbackDelegate _pinchGestureCallbackDelegate;
-
         /// <summary>
         /// Creates an initialized PinchGestureDetector.
         /// </summary>
@@ -60,8 +57,10 @@ namespace Tizen.NUI
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
+        private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr pinchGesture);
+        private delegate void DetectedCallbackType(IntPtr actor, IntPtr pinchGesture);
+        private DetectedCallbackType _detectedCallback;
 
         /// <summary>
         /// This signal is emitted when the specified pinch is detected on the attached view.
@@ -72,29 +71,22 @@ namespace Tizen.NUI
         {
             add
             {
-                lock (this)
+                if (_detectedEventHandler == null)
                 {
-                    // Restricted to only one listener
-                    if (_pinchGestureEventHandler == null)
-                    {
-                        _pinchGestureEventHandler += value;
-
-                        _pinchGestureCallbackDelegate = new DetectedCallbackDelegate(OnPinchGestureDetected);
-                        this.DetectedSignal().Connect(_pinchGestureCallbackDelegate);
-                    }
+                    _detectedCallback = OnPinchGestureDetected;
+                    DetectedSignal().Connect(_detectedCallback);
                 }
+
+                _detectedEventHandler += value;
             }
 
             remove
             {
-                lock (this)
-                {
-                    if (_pinchGestureEventHandler != null)
-                    {
-                        this.DetectedSignal().Disconnect(_pinchGestureCallbackDelegate);
-                    }
+                _detectedEventHandler -= value;
 
-                    _pinchGestureEventHandler -= value;
+                if (_detectedEventHandler == null && DetectedSignal().Empty() == false)
+                {
+                    DetectedSignal().Disconnect(_detectedCallback);
                 }
             }
         }
@@ -149,6 +141,10 @@ namespace Tizen.NUI
             //Release your own unmanaged resources here.
             //You should not access any managed member here except static instance.
             //Because the execution order of Finalizes is non-deterministic.
+            if (_detectedCallback != null)
+            {
+                DetectedSignal().Disconnect(_detectedCallback);
+            }
 
             if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
@@ -176,10 +172,10 @@ namespace Tizen.NUI
 
             e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
 
-            if (_pinchGestureEventHandler != null)
+            if (_detectedEventHandler != null)
             {
                 //Here we send all data to user event handlers.
-                _pinchGestureEventHandler(this, e);
+                _detectedEventHandler(this, e);
             }
         }
 
index 510bf2c..b85ba75 100755 (executable)
@@ -30,10 +30,6 @@ namespace Tizen.NUI
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
 
-        private DaliEventHandler<object, DetectedEventArgs> _rotationGestureEventHandler;
-        private DetectedCallbackDelegate _rotationGestureCallbackDelegate;
-
-
         /// <summary>
         /// Creates an initialized RotationGestureDetector.
         /// </summary>
@@ -61,8 +57,10 @@ namespace Tizen.NUI
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
+        private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr rotationGesture);
+        private delegate void DetectedCallbackType(IntPtr actor, IntPtr rotationGesture);
+        private DetectedCallbackType _detectedCallback;
 
         /// <summary>
         /// This signal is emitted when the specified rotation is detected on the attached view.
@@ -73,29 +71,22 @@ namespace Tizen.NUI
         {
             add
             {
-                lock (this)
+                if (_detectedEventHandler == null)
                 {
-                    // Restricted to only one listener
-                    if (_rotationGestureEventHandler == null)
-                    {
-                        _rotationGestureEventHandler += value;
-
-                        _rotationGestureCallbackDelegate = new DetectedCallbackDelegate(OnRotationGestureDetected);
-                        this.DetectedSignal().Connect(_rotationGestureCallbackDelegate);
-                    }
+                    _detectedCallback = OnRotationGestureDetected;
+                    DetectedSignal().Connect(_detectedCallback);
                 }
+
+                _detectedEventHandler += value;
             }
 
             remove
             {
-                lock (this)
-                {
-                    if (_rotationGestureEventHandler != null)
-                    {
-                        this.DetectedSignal().Disconnect(_rotationGestureCallbackDelegate);
-                    }
+                _detectedEventHandler -= value;
 
-                    _rotationGestureEventHandler -= value;
+                if (_detectedEventHandler == null && DetectedSignal().Empty() == false)
+                {
+                    DetectedSignal().Disconnect(_detectedCallback);
                 }
             }
         }
@@ -158,7 +149,10 @@ namespace Tizen.NUI
             //Release your own unmanaged resources here.
             //You should not access any managed member here except static instance.
             //Because the execution order of Finalizes is non-deterministic.
-
+            if (_detectedCallback != null)
+            {
+                DetectedSignal().Disconnect(_detectedCallback);
+            }
 
             if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
@@ -186,10 +180,10 @@ namespace Tizen.NUI
 
             e.RotationGesture = Tizen.NUI.RotationGesture.GetRotationGestureFromPtr(rotationGesture);
 
-            if (_rotationGestureEventHandler != null)
+            if (_detectedEventHandler != null)
             {
                 //Here we send all data to user event handlers.
-                _rotationGestureEventHandler(this, e);
+                _detectedEventHandler(this, e);
             }
         }
 
index d8196c5..be694fe 100755 (executable)
@@ -31,8 +31,6 @@ namespace Tizen.NUI
     public class TapGestureDetector : GestureDetector
     {
         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
-        private DaliEventHandler<object, DetectedEventArgs> _tapGestureEventHandler;
-        private DetectedCallbackDelegate _tapGestureCallbackDelegate;
 
         /// <summary>
         /// Creates an initialized TapGestureDetector.
@@ -61,8 +59,10 @@ namespace Tizen.NUI
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
         }
 
+        private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
-        private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr TapGesture);
+        private delegate void DetectedCallbackType(IntPtr actor, IntPtr TapGesture);
+        private DetectedCallbackType _detectedCallback;
 
         /// <summary>
         /// This signal is emitted when the specified tap is detected on the attached view.
@@ -73,29 +73,22 @@ namespace Tizen.NUI
         {
             add
             {
-                lock (this)
+                if (_detectedEventHandler == null)
                 {
-                    // Restricted to only one listener
-                    if (_tapGestureEventHandler == null)
-                    {
-                        _tapGestureEventHandler += value;
-
-                        _tapGestureCallbackDelegate = new DetectedCallbackDelegate(OnTapGestureDetected);
-                        this.DetectedSignal().Connect(_tapGestureCallbackDelegate);
-                    }
+                    _detectedCallback = OnTapGestureDetected;
+                    DetectedSignal().Connect(_detectedCallback);
                 }
+
+                _detectedEventHandler += value;
             }
 
             remove
             {
-                lock (this)
-                {
-                    if (_tapGestureEventHandler != null)
-                    {
-                        this.DetectedSignal().Disconnect(_tapGestureCallbackDelegate);
-                    }
+                _detectedEventHandler -= value;
 
-                    _tapGestureEventHandler -= value;
+                if (_detectedEventHandler == null && DetectedSignal().Empty() == false)
+                {
+                    DetectedSignal().Disconnect(_detectedCallback);
                 }
             }
         }
@@ -212,6 +205,10 @@ namespace Tizen.NUI
             //Release your own unmanaged resources here.
             //You should not access any managed member here except static instance.
             //because the execution order of Finalizes is non-deterministic.
+            if (_detectedCallback != null)
+            {
+                DetectedSignal().Disconnect(_detectedCallback);
+            }
 
             if (swigCPtr.Handle != global::System.IntPtr.Zero)
             {
@@ -240,10 +237,10 @@ namespace Tizen.NUI
 
             e.TapGesture = Tizen.NUI.TapGesture.GetTapGestureFromPtr(tapGesture);
 
-            if (_tapGestureEventHandler != null)
+            if (_detectedEventHandler != null)
             {
                 //here we send all data to user event handlers
-                _tapGestureEventHandler(this, e);
+                _detectedEventHandler(this, e);
             }
         }