]> O.S.I.I.S - jp/crow.git/commitdiff
handle drop dockWin in dockWin, AllowedDockTypes check
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 17 Mar 2021 11:45:17 +0000 (12:45 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Wed, 17 Mar 2021 11:45:17 +0000 (12:45 +0100)
Crow/Default.style
Crow/src/Interface.cs
Crow/src/Widgets/DockStack.cs
Crow/src/Widgets/DockWindow.cs
Crow/src/Widgets/Widget.cs

index 8e7696992dc747f66e5be7644c5aff4005bbe055..f2f9482384896eef54d2d4a177345959776f553a 100644 (file)
@@ -188,6 +188,7 @@ DockStack {
        Margin="2";
        Spacing="2";
        AllowDrop = "true";
+       AllowedDropTypes = "Crow.DockWindow";
        Focusable="true";
        //DragEnter="{Background=Blue}";
        //DragLeave="{Background=Transparent}";
@@ -197,6 +198,8 @@ DockWindow {
        //Background = "Onyx";
        Focusable = "true";
        AllowDrag = "true";
+       AllowDrop="true";
+       AllowedDropTypes = "Crow.DockWindow";
        AlwaysOnTop = "true";
        Margin="0";
        Width="200";
index 63a86a14a68cfa676a6f4212a75f391f34b20a59..4cd9eabb219a23fb4eefee281827f147376cb9bd 100644 (file)
@@ -461,6 +461,8 @@ namespace Crow
                public List<CrowThread> CrowThreads = new List<CrowThread>();//used to monitor thread finished
 
                public bool DragAndDropInProgress => DragAndDropOperation != null;
+               public Widget DropTarget => DragAndDropOperation?.DropTarget;
+
                public DragDropEventArgs DragAndDropOperation = null;
                internal Widget dragndropHover;
 
index 50f241b5bb72c897e71e0009e48d0084e1bd424a..5645e3745019f22072d701f6735c0c51cd911e2a 100644 (file)
@@ -92,7 +92,8 @@ namespace Crow
 
                public void onDragMouseMove (object sender, MouseMoveEventArgs e)
                {
-                       if (IsDropTarget) {                             
+
+                       //if (IsDropTarget) {                           
                                DockWindow dw = IFace.DragAndDropOperation.DragSource as DockWindow;
                                if (dw == null || dw.IsDocked) {
                                        base.onMouseMove (sender, e);
@@ -149,7 +150,7 @@ namespace Crow
 
                                if (curDockPos != dw.DockingPosition)
                                        RegisterForGraphicUpdate ();
-                       }
+                       //}
                        //base.onMouseMove (sender, e);
                }
 
@@ -189,9 +190,8 @@ namespace Crow
                                g.Paint (gr);                   
 
                        childrenRWLock.ExitReadLock ();
-
-
-                       if (!IsDropTarget) {
+                       
+                       if (!(IsDropTarget || (IFace.DropTarget is DockWindow dtdw && dtdw.Parent == this))) {
                                gr.Restore ();
                                return;
                        }
index a020397ed6a0a5e6e07544f2995dc2dee4a70608..72a22a75631ad7aaeb0014500f91f96141269a72 100644 (file)
@@ -74,9 +74,15 @@ namespace Crow
                                moveAndResize (e.XDelta, e.YDelta, currentDirection);
                        
                        base.onDrag (sender, e);
-                       (IFace.DragAndDropOperation.DropTarget as DockStack)?.onDragMouseMove (this, e);
+                       if (IFace.DragAndDropOperation.DropTarget is DockStack ds)
+                               ds.onDragMouseMove (this, e);
+                       else if (IFace.DragAndDropOperation.DropTarget is DockWindow dw)
+                               (dw.Parent as DockStack)?.onDragMouseMove (this, e);
                }
-               public override void onMouseDown (object sender, MouseButtonEventArgs e)
+        protected override void onDragEnter (object sender, DragDropEventArgs e) {
+            base.onDragEnter (sender, e);
+        }
+        public override void onMouseDown (object sender, MouseButtonEventArgs e)
                {
                        e.Handled = true;
                        base.onMouseDown (sender, e);
@@ -104,8 +110,12 @@ namespace Crow
                }
                public override void onDrop (object sender, DragDropEventArgs e)
                {
-                       if (!isDocked && DockingPosition != Alignment.Undefined && e.DropTarget is DockStack)
-                               Dock (e.DropTarget as DockStack);
+                       if (!(isDocked || DockingPosition == Alignment.Undefined)) {
+                               if (e.DropTarget is DockStack ds)
+                                       Dock (ds);
+                               else if (e.DropTarget is DockWindow dw)
+                                       Dock (dw.Parent as DockStack);
+                       }
                        base.onDrop (sender, e);
                }
                public void Undock () {
@@ -115,8 +125,8 @@ namespace Crow
 
                                IFace.AddWidget (this);
 
-                               Left = savedSlot.Left;
-                               Top = savedSlot.Top;
+                               Left = IFace.MousePosition.X - 10;
+                               Top = IFace.MousePosition.Y - 10;
                                Width = savedSlot.Width;
                                Height = savedSlot.Height;
 
index d1f085aa0e66f0ee398095e4f166d8089051a2a7..1553dab4147fcd71ca3babc64f14cf5cb9bc51a6 100644 (file)
@@ -13,6 +13,7 @@ using System.Diagnostics;
 using Crow.IML;
 using System.Threading;
 using Glfw;
+using System.Linq;
 
 
 #if DESIGN_MODE
@@ -287,6 +288,7 @@ namespace Crow
                bool isDragged;
                bool allowDrag;
                bool allowDrop;
+               string allowedDropTypes;
                string tooltip;
                IList<Command> contextCommands;
                #endregion
@@ -1314,6 +1316,9 @@ namespace Crow
                }
 
                #region Drag&Drop
+               /// <summary>
+               /// If true, allow widget to be dragged and dropped.
+               /// </summary>
                [DesignCategory ("DragAndDrop")][DefaultValue(false)]
                public virtual bool AllowDrag {
                        get => allowDrag;
@@ -1324,6 +1329,10 @@ namespace Crow
                                NotifyValueChanged ("AllowDrag", allowDrag);
                        }
                }
+               /// <summary>
+               /// If true, allow widgets of type listed in 'AllowedDropTypes' to be dropped in this widget
+               /// during drag and drop operations.
+               /// </summary>
                [DesignCategory ("DragAndDrop")][DefaultValue(false)]
                public virtual bool AllowDrop {
                        get => allowDrop;
@@ -1333,18 +1342,30 @@ namespace Crow
                                allowDrop = value;
                                NotifyValueChanged ("AllowDrop", allowDrop);
                        }
-               }
-
-//             public List<Type> AllowedDroppedTypes;
-//             public void AddAllowedDroppedType (Type newType){
-//                     if (AllowedDroppedTypes == null)
-//                             AllowedDroppedTypes = new List<Type> ();
-//                     AllowedDroppedTypes.Add (newType);
-//                     NotifyValueChanged ("AllowDrop", AllowDrop);
-//             }
-//             [XmlIgnore]public virtual bool AllowDrop {
-//                     get { return AllowedDroppedTypes?.Count>0; }
-//             }
+               }               
+               /// <summary>
+               /// Semicolon separated list of accepted types as dropped widget.
+               /// </summary>
+               [DesignCategory ("DragAndDrop")][DefaultValue ("Crow.Widget")]
+               public virtual string AllowedDropTypes {
+                       get => allowedDropTypes;
+                       set {
+                               if (allowedDropTypes == value)
+                                       return;
+                               allowedDropTypes = value;
+                               NotifyValueChanged ("AllowedDropTypes", allowedDropTypes);
+                       }
+               }
+               //              public List<Type> AllowedDroppedTypes;
+               //              public void AddAllowedDroppedType (Type newType){
+               //                      if (AllowedDroppedTypes == null)
+               //                              AllowedDroppedTypes = new List<Type> ();
+               //                      AllowedDroppedTypes.Add (newType);
+               //                      NotifyValueChanged ("AllowDrop", AllowDrop);
+               //              }
+               //              [XmlIgnore]public virtual bool AllowDrop {
+               //                      get { return AllowedDroppedTypes?.Count>0; }
+               //              }
                [XmlIgnore]public virtual bool IsDragged {
                        get => isDragged;
                        set {
@@ -1355,6 +1376,9 @@ namespace Crow
                                NotifyValueChanged ("IsDragged", IsDragged);
                        }
                }
+               public bool AcceptDrop (Widget droppedWidget) =>
+                       string.IsNullOrEmpty(AllowedDropTypes) || droppedWidget == null ? false :
+                       AllowedDropTypes.Split (';').Contains (droppedWidget.GetType ().FullName);
                /// <summary>
                /// equivalent to mouse move for a dragged widget, no bubbling.
                /// </summary>
@@ -1920,7 +1944,7 @@ namespace Crow
                        if (IFace.DragAndDropInProgress) {
                                if (IFace.dragndropHover != this) {
                                        IFace.dragndropHover = this;
-                                       if (AllowDrop)
+                                       if (AllowDrop && IFace.DragAndDropOperation.DragSource.AcceptDrop (this))
                                                onDragEnter (this, IFace.DragAndDropOperation);
                                }
                        } else if (IFace.HoverWidget != this) {