/*
- * Copyright(c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
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")]
+ [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);
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragAndDrop_RemoveListener")]
+ [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)]
public static extern bool RemoveListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetView, global::System.Runtime.InteropServices.HandleRef callback);
+ [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);
+
+ [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)]
+ public static extern bool WindowRemoveListener(global::System.Runtime.InteropServices.HandleRef dragAndDrop, global::System.Runtime.InteropServices.HandleRef targetWindow, global::System.Runtime.InteropServices.HandleRef callback);
+
[global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_DragEvent_GetAction")]
public static extern int GetAction(global::System.IntPtr dragAndDrop);
/*
- * Copyright(c) 2022 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2023 Samsung Electronics Co., Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
public delegate void SourceEventHandler(DragSourceEventType sourceEventType);
private delegate void InternalSourceEventHandler(int sourceEventType);
public delegate void DragAndDropEventHandler(View targetView, DragEvent dragEvent);
+ public delegate void DragAndDropWindowEventHandler(Window targetWindow, DragEvent dragEvent);
private delegate void InternalDragAndDropEventHandler(global::System.IntPtr dragEvent);
private InternalSourceEventHandler sourceEventCb;
private Dictionary<View, InternalDragAndDropEventHandler> targetEventDictionary = new Dictionary<View, InternalDragAndDropEventHandler>();
+ private Dictionary<Window, InternalDragAndDropEventHandler> targetWindowEventDictionary = new Dictionary<Window, InternalDragAndDropEventHandler>();
private View mShadowView;
private Window mDragWindow;
private int shadowWidth;
if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView),
new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
{
- throw new InvalidOperationException("Fail to AddListener");
+ throw new InvalidOperationException("Fail to AddListener for View");
}
}
{
if (!targetEventDictionary.ContainsKey(targetView))
{
- throw new InvalidOperationException("Fail to RemoveListener");
+ throw new InvalidOperationException("Fail to RemoveListener for View");
}
InternalDragAndDropEventHandler cb = targetEventDictionary[targetView];
if (!Interop.DragAndDrop.RemoveListener(SwigCPtr, View.getCPtr(targetView),
new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
{
- throw new InvalidOperationException("Fail to RemoveListener");
+ throw new InvalidOperationException("Fail to RemoveListener for View");
+ }
+ }
+
+ /// <summary>
+ /// Adds listener for drop targets
+ /// </summary>
+ /// <param name="targetWindow">The target Window</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, 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);
+
+ 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);
+ }
+ };
+
+ targetWindowEventDictionary.Add(targetWindow, cb);
+
+ if (!Interop.DragAndDrop.WindowAddListener(SwigCPtr, Window.getCPtr(targetWindow),
+ new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
+ {
+ throw new InvalidOperationException("Fail to AddListener for Window");
+ }
+ }
+
+ /// <summary>
+ /// Removes listener for drop targets
+ /// </summary>
+ /// <param name="targetWindow">The target window</param>
+ /// <param name="callback">The callback function to remove</param>
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public void RemoveListener(Window targetWindow, DragAndDropWindowEventHandler callback)
+ {
+ if (!targetWindowEventDictionary.ContainsKey(targetWindow))
+ {
+ throw new InvalidOperationException("Fail to RemoveListener for Window");
+ }
+
+ InternalDragAndDropEventHandler cb = targetWindowEventDictionary[targetWindow];
+ targetWindowEventDictionary.Remove(targetWindow);
+ if (!Interop.DragAndDrop.WindowRemoveListener(SwigCPtr, Window.getCPtr(targetWindow),
+ new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate<Delegate>(cb))))
+ {
+ throw new InvalidOperationException("Fail to RemoveListener for Window");
}
}
}