[NUI] Implements drag source events.
authorTaehyub Kim <taehyub.kim@samsung.com>
Fri, 22 Apr 2022 10:10:47 +0000 (19:10 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Wed, 27 Apr 2022 00:31:21 +0000 (09:31 +0900)
src/Tizen.NUI/src/internal/Interop/Interop.DragAndDrop.cs
src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs
src/Tizen.NUI/src/public/DragAndDrop/DragEvent.cs
test/NUIDnDSource/NUIDnDSource.cs

index d440590..4d498b0 100755 (executable)
@@ -33,7 +33,7 @@ namespace Tizen.NUI
             public static extern global::System.IntPtr New();
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_StartDragAndDrop")]
-            public static extern bool StartDragAndDrop(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef sourceView, global::System.Runtime.InteropServices.HandleRef shadow, string mimeType, string data);
+            public static extern bool StartDragAndDrop(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef sourceView, global::System.Runtime.InteropServices.HandleRef shadow, string mimeType, string data, global::System.Runtime.InteropServices.HandleRef callback);
 
             [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_AddListener")]
             public static extern bool AddListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetView, global::System.Runtime.InteropServices.HandleRef callback);
index 19f3e9a..a44cc4d 100755 (executable)
@@ -26,13 +26,20 @@ namespace Tizen.NUI
     /// <summary>
     /// DragAndDrop controls the drag objet and data.
     /// </summary>
+    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000: Dispose objects before losing scope", Justification = "It does not have ownership.")]
     [EditorBrowsable(EditorBrowsableState.Never)]
     public class DragAndDrop : BaseHandle
     {
         [EditorBrowsable(EditorBrowsableState.Never)]
+        public delegate void SourceEventHandler(SourceEventType sourceEventType);
+        private delegate void InternalSourceEventHandler(int sourceEventType);
         public delegate void DragAndDropEventHandler(View targetView, DragEvent dragEvent);
         private delegate void InternalDragAndDropEventHandler(global::System.IntPtr dragEvent);
+        private InternalSourceEventHandler sourceEventCb;
         private Dictionary<View, InternalDragAndDropEventHandler> targetEventDictionary = new Dictionary<View, InternalDragAndDropEventHandler>();
+        private Window mDragWindow;
+        private const int shadowWidth = 150;
+        private const int shadowHeight = 150;
 
         [EditorBrowsable(EditorBrowsableState.Never)]
         private DragAndDrop() : this(Interop.DragAndDrop.New(), true)
@@ -54,12 +61,47 @@ namespace Tizen.NUI
         /// <param name="sourceView">The soruce view</param>
         /// <param name="shadowView">The shadow view for drag object</param>
         /// <param name="dragData">The data to send</param>
+        /// <param name="callback">The source event callback</param>
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData)
+        public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData, SourceEventHandler callback)
         {
-            if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), View.getCPtr(shadowView), dragData.MimeType, dragData.Data))
+            if (null == shadowView)
             {
-                throw new InvalidOperationException("Fail to StartDragAndDrop");
+                throw new ArgumentNullException(nameof(shadowView));
+            }
+
+            if (mDragWindow)
+            {
+                mDragWindow.Hide();
+                mDragWindow.Dispose();
+                mDragWindow = null;
+            }
+
+            //FIXME: Drag window cannot be reused because the current window server does not allow reuse.
+            //       When window server allows the drag window to be reused, makes the mDragWindow created once.
+            mDragWindow = new Window("DragWindow", new Rectangle(-shadowWidth, -shadowHeight, shadowWidth, shadowHeight), true)
+            {
+              BackgroundColor = Color.Transparent,
+            };
+
+            if (mDragWindow)
+            {
+                shadowView.SetSize(shadowWidth, shadowHeight);
+                shadowView.SetOpacity(0.9f);
+
+                mDragWindow.Add(shadowView);
+                mDragWindow.Show();
+
+                sourceEventCb = (sourceEventType) =>
+                {
+                    callback((SourceEventType)sourceEventType);
+                };
+
+                if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), dragData.MimeType, dragData.Data,
+                                                        new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(sourceEventCb))))
+                {
+                    throw new InvalidOperationException("Fail to StartDragAndDrop");
+                }
             }
         }
 
index 71cb4dc..ee7a8cd 100755 (executable)
@@ -21,6 +21,30 @@ using Tizen.NUI.Binding;
 namespace Tizen.NUI
 {
     /// <summary>
+    /// Source event type.
+    /// </summary>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public enum SourceEventType
+    {
+        /// <summary>
+        /// Drag and drop is started.
+        /// </summary>
+        Start,
+        /// <summary>
+        /// Drag and drop is cancelled.
+        /// </summary>
+        Cancel,
+        /// <summary>
+        /// Drag and drop is accepted.
+        /// </summary>
+        Accept,
+        /// <summary>
+        /// Drag and drop is finished.
+        /// </summary>
+        Finish
+    }
+
+    /// <summary>
     /// This specifies drag data.
     /// </summary>
     /// Suppress warning : This struct will be used data of callback, so override equals and operator does not necessary.
index c7a9353..af1ddcf 100644 (file)
@@ -131,6 +131,26 @@ namespace NUIDnDSource
             }
         }
 
+        public void OnSourceEventFunc(SourceEventType type)
+        {
+          if (type == SourceEventType.Start)
+          {
+            Tizen.Log.Debug("NUIDnDSource", "Source App SourceEvnetType: " + "Start");
+          }
+          else if (type == SourceEventType.Cancel)
+          {
+            Tizen.Log.Debug("NUIDnDSource", "Source App SourceEvnetType: " + "Cancel");
+          }
+          else if (type == SourceEventType.Accept)
+          {
+            Tizen.Log.Debug("NUIDnDSource", "Source App SourceEvnetType: " + "Accept");
+          }
+          else if (type == SourceEventType.Finish)
+          {
+            Tizen.Log.Debug("NUIDnDSource", "Source App SourceEvnetType: " + "Finish");
+          }
+        }
+
         private void OnTouchEvent(object source, Window.TouchEventArgs e)
         {
             if (e.Touch.GetState(0) == PointStateType.Down)
@@ -140,7 +160,7 @@ namespace NUIDnDSource
                 DragData dragData;
                 dragData.MimeType = "text/uri-list";
                 dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png";
-                dnd.StartDragAndDrop(sourceView, shadowView, dragData);
+                dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceEventFunc);
             }
         }