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, global::System.Runtime.InteropServices.HandleRef callback);
+ public static extern bool StartDragAndDrop(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef sourceView, global::System.Runtime.InteropServices.HandleRef shadow, string [] mimeTypes, int mimeTypsSize, string [] dataSet, int dataSetSize, global::System.Runtime.InteropServices.HandleRef callback);
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_AddListener")]
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
- public static extern bool AddListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetView, global::System.Runtime.InteropServices.HandleRef callback);
+ public static extern bool AddListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetView, string mimeType, global::System.Runtime.InteropServices.HandleRef callback);
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_RemoveListener")]
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_Window_AddListener")]
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
- public static extern bool WindowAddListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetWindow, global::System.Runtime.InteropServices.HandleRef callback);
+ public static extern bool WindowAddListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetWindow, string mimeType, global::System.Runtime.InteropServices.HandleRef callback);
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_Window_RemoveListener")]
[return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetPosition")]
public static extern global::System.IntPtr GetPosition(global::System.IntPtr dragAndDrop);
- [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetMimeType")]
- public static extern string GetMimeType(global::System.IntPtr dragAndDrop);
+ [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetMimeTypes")]
+ public static extern bool GetMimeTypes(global::System.IntPtr dragAndDrop, out global::System.IntPtr mimeTypes, out int count);
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetData")]
public static extern string GetData(global::System.IntPtr dragAndDrop);
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Collections.Generic;
+using System.Linq;
using System.Diagnostics.CodeAnalysis;
using Tizen.NUI.BaseComponents;
{
public delegate void SourceEventHandler(DragSourceEventType sourceEventType);
private delegate void InternalSourceEventHandler(int sourceEventType);
- public delegate void DragAndDropEventHandler(View targetView, DragEvent dragEvent);
+ public delegate void DragAndDropEventHandler(View targetView, DragEvent navtiveDragEvent);
[EditorBrowsable(EditorBrowsableState.Never)]
- public delegate void DragAndDropWindowEventHandler(Window targetWindow, DragEvent dragEvent);
- private delegate void InternalDragAndDropEventHandler(global::System.IntPtr dragEvent);
+ public delegate void DragAndDropWindowEventHandler(Window targetWindow, DragEvent navtiveDragEvent);
+ private delegate void InternalDragAndDropEventHandler(global::System.IntPtr navtiveDragEvent);
private InternalSourceEventHandler sourceEventCb;
private Dictionary<View, InternalDragAndDropEventHandler> targetEventDictionary = new Dictionary<View, InternalDragAndDropEventHandler>();
private Dictionary<Window, InternalDragAndDropEventHandler> targetWindowEventDictionary = new Dictionary<Window, InternalDragAndDropEventHandler>();
private int dragWindowOffsetX = 0;
private int dragWindowOffsetY = 0;
- private bool initDrag = false;
-
private const int MinDragWindowWidth = 100;
private const int MinDragWindowHeight = 100;
+ private void ProcessDragEventTargetCallback(IntPtr navtiveDragEvent, View targetView, DragAndDropEventHandler callback)
+ {
+ DragType type = (DragType)Interop.DragAndDrop.GetAction(navtiveDragEvent);
+ DragEvent dragEvent = new DragEvent();
+ global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(navtiveDragEvent);
+ dragEvent.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, true);
+
+ IntPtr nativeMimeTypes;
+ int count;
+ Interop.DragAndDrop.GetMimeTypes(navtiveDragEvent, out nativeMimeTypes, out count);
+ if (count > 0)
+ {
+ IntPtr [] nativeMimeTypesArrary = new IntPtr[count];
+ Marshal.Copy(nativeMimeTypes, nativeMimeTypesArrary, 0, count);
+
+ string [] managedMimeTypes = new string[count];
+
+ for (int iterator = 0; iterator < count; iterator++)
+ {
+ managedMimeTypes[iterator] = Marshal.PtrToStringAnsi(nativeMimeTypesArrary[iterator]);
+ }
+
+ dragEvent.MimeType = managedMimeTypes[0];
+ dragEvent.MimeTypes = managedMimeTypes;
+ }
+
+ if (type == DragType.Enter)
+ {
+ dragEvent.DragType = type;
+ callback(targetView, dragEvent);
+ }
+ else if (type == DragType.Leave)
+ {
+ dragEvent.DragType = type;
+ callback(targetView, dragEvent);
+ }
+ else if (type == DragType.Move)
+ {
+ dragEvent.DragType = type;
+ callback(targetView, dragEvent);
+ }
+ else if (type == DragType.Drop)
+ {
+ dragEvent.DragType = type;
+ dragEvent.Data = Interop.DragAndDrop.GetData(navtiveDragEvent);
+ callback(targetView, dragEvent);
+ }
+ }
+
+ private void ProcessDragEventWindowCallback(IntPtr navtiveDragEvent, Window targetWindow, DragAndDropWindowEventHandler callback)
+ {
+ DragType type = (DragType)Interop.DragAndDrop.GetAction(navtiveDragEvent);
+ DragEvent dragEvent = new DragEvent();
+ global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(navtiveDragEvent);
+ dragEvent.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false);
+
+ IntPtr nativeMimeTypes;
+ int count;
+ Interop.DragAndDrop.GetMimeTypes(navtiveDragEvent, out nativeMimeTypes, out count);
+ if (count > 0)
+ {
+ IntPtr [] nativeMimeTypesArrary = new IntPtr[count];
+ Marshal.Copy(nativeMimeTypes, nativeMimeTypesArrary, 0, count);
+
+ string [] managedMimeTypes = new string[count];
+
+ for (int iterator = 0; iterator < count; iterator++)
+ {
+ managedMimeTypes[iterator] = Marshal.PtrToStringAnsi(nativeMimeTypesArrary[iterator]);
+ }
+
+ dragEvent.MimeType = managedMimeTypes[0];
+ dragEvent.MimeTypes = managedMimeTypes;
+ }
+
+ if (type == DragType.Enter)
+ {
+ dragEvent.DragType = type;
+ callback(targetWindow, dragEvent);
+ }
+ else if (type == DragType.Leave)
+ {
+ dragEvent.DragType = type;
+ callback(targetWindow, dragEvent);
+ }
+ else if (type == DragType.Move)
+ {
+ dragEvent.DragType = type;
+ callback(targetWindow, dragEvent);
+ }
+ else if (type == DragType.Drop)
+ {
+ dragEvent.DragType = type;
+ dragEvent.Data = Interop.DragAndDrop.GetData(navtiveDragEvent);
+ callback(targetWindow, dragEvent);
+ }
+ }
+
private DragAndDrop() : this(Interop.DragAndDrop.New(), true)
{
if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
/// <param name="callback">The source event callback</param>
/// <since_tizen> 10 </since_tizen>
public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData, SourceEventHandler callback)
- {
- if (initDrag)
- {
- Tizen.Log.Fatal("NUI", "Start Drag And Drop Initializing...");
- return;
- }
- initDrag = true;
-
+ {
if (Window.IsSupportedMultiWindow() == false)
{
throw new NotSupportedException("This device does not support surfaceless_context. So Window cannot be created.");
{
if ((DragSourceEventType)sourceEventType != DragSourceEventType.Start)
{
- Tizen.Log.Fatal("NUI", "DnD Source Event is Called");
+ Tizen.Log.Fatal("NUI", "DnD Source Event is Called");
ReleaseDragWindow();
}
//Show Drag Window before StartDragAndDrop
mDragWindow.Show();
- if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), dragData.MimeType, dragData.Data,
+ string [] mimeTypes;
+ string [] dataSet;
+
+ if (string.IsNullOrEmpty(dragData.MimeType) && dragData.DataMap != null)
+ {
+ mimeTypes = dragData.DataMap.Keys.ToArray();
+ dataSet = dragData.DataMap.Values.ToArray();
+ }
+ else
+ {
+ mimeTypes = new string[1];
+ mimeTypes[0] = dragData.MimeType;
+
+ dataSet = new string[1];
+ dataSet[0] = dragData.Data;
+ }
+
+ if (!Interop.DragAndDrop.StartDragAndDrop(SwigCPtr, View.getCPtr(sourceView), Window.getCPtr(mDragWindow), mimeTypes, mimeTypes.Length, dataSet, dataSet.Length,
new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(sourceEventCb))))
{
throw new InvalidOperationException("Fail to StartDragAndDrop");
}
-
- }
-
- initDrag = false;
+ }
}
/// <summary>
/// <since_tizen> 10 </since_tizen>
public void AddListener(View targetView, DragAndDropEventHandler callback)
{
- InternalDragAndDropEventHandler cb = (dragEvent) =>
- {
- DragType type = (DragType)Interop.DragAndDrop.GetAction(dragEvent);
- DragEvent ev = new DragEvent();
- global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(dragEvent);
- ev.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, true);
+ AddListener(targetView, "*/*", callback);
+ }
- if (type == DragType.Enter)
- {
- ev.DragType = type;
- ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent);
- callback(targetView, ev);
- }
- else if (type == DragType.Leave)
- {
- ev.DragType = type;
- callback(targetView, ev);
- }
- else if (type == DragType.Move)
- {
- ev.DragType = type;
- ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent);
- callback(targetView, ev);
- }
- else if (type == DragType.Drop)
- {
- ev.DragType = type;
- ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent);
- ev.Data = Interop.DragAndDrop.GetData(dragEvent);
- callback(targetView, ev);
- }
- };
+ /// <summary>
+ /// Adds listener for drop targets
+ /// </summary>
+ /// <param name="targetView">The target view</param>
+ /// <param name="mimeType">The mime type for target view</param>
+ /// <param name="callback">The callback function to get drag event when the drag source enters, moves, leaves and drops on the drop target</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void AddListener(View targetView, string mimeType, DragAndDropEventHandler callback)
+ {
+ InternalDragAndDropEventHandler cb = (navtiveDragEvent) => ProcessDragEventTargetCallback(navtiveDragEvent, targetView, callback);
targetEventDictionary.Add(targetView, cb);
- if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView),
+ if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView), mimeType,
new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
{
throw new InvalidOperationException("Fail to AddListener for View");
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddListener(Window targetWindow, DragAndDropWindowEventHandler callback)
{
- InternalDragAndDropEventHandler cb = (dragEvent) =>
- {
- DragType type = (DragType)Interop.DragAndDrop.GetAction(dragEvent);
- DragEvent ev = new DragEvent();
- global::System.IntPtr cPtr = Interop.DragAndDrop.GetPosition(dragEvent);
- ev.Position = (cPtr == global::System.IntPtr.Zero) ? null : new Position(cPtr, false);
+ AddListener(targetWindow, "*/*", callback);
+ }
- if (type == DragType.Enter)
- {
- ev.DragType = type;
- callback(targetWindow, ev);
- }
- else if (type == DragType.Leave)
- {
- ev.DragType = type;
- callback(targetWindow, ev);
- }
- else if (type == DragType.Move)
- {
- ev.DragType = type;
- callback(targetWindow, ev);
- }
- else if (type == DragType.Drop)
- {
- ev.DragType = type;
- ev.MimeType = Interop.DragAndDrop.GetMimeType(dragEvent);
- ev.Data = Interop.DragAndDrop.GetData(dragEvent);
- callback(targetWindow, ev);
- }
- };
+ /// <summary>
+ /// Adds listener for drop targets
+ /// </summary>
+ /// <param name="targetWindow">The target Window</param>
+ /// <param name="mimeType">The mime type for target view</param>
+ /// <param name="callback">The callback function to get drag event when the drag source enters, moves, leaves and drops on the drop target</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void AddListener(Window targetWindow, string mimeType, DragAndDropWindowEventHandler callback)
+ {
+ InternalDragAndDropEventHandler cb = (navtiveDragEvent) => ProcessDragEventWindowCallback(navtiveDragEvent, targetWindow, callback);
targetWindowEventDictionary.Add(targetWindow, cb);
- if (!Interop.DragAndDrop.WindowAddListener(SwigCPtr, Window.getCPtr(targetWindow),
+ if (!Interop.DragAndDrop.WindowAddListener(SwigCPtr, Window.getCPtr(targetWindow), mimeType,
new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
{
throw new InvalidOperationException("Fail to AddListener for Window");