From: Jean-Philippe Bruyère Date: Wed, 17 Mar 2021 11:45:17 +0000 (+0100) Subject: handle drop dockWin in dockWin, AllowedDockTypes check X-Git-Tag: v0.9.5-beta~60 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=13e599ad0e9b285f55127f0ee631246b25b34ead;p=jp%2Fcrow.git handle drop dockWin in dockWin, AllowedDockTypes check --- diff --git a/Crow/Default.style b/Crow/Default.style index 8e769699..f2f94823 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -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"; diff --git a/Crow/src/Interface.cs b/Crow/src/Interface.cs index 63a86a14..4cd9eabb 100644 --- a/Crow/src/Interface.cs +++ b/Crow/src/Interface.cs @@ -461,6 +461,8 @@ namespace Crow public List CrowThreads = new List();//used to monitor thread finished public bool DragAndDropInProgress => DragAndDropOperation != null; + public Widget DropTarget => DragAndDropOperation?.DropTarget; + public DragDropEventArgs DragAndDropOperation = null; internal Widget dragndropHover; diff --git a/Crow/src/Widgets/DockStack.cs b/Crow/src/Widgets/DockStack.cs index 50f241b5..5645e374 100644 --- a/Crow/src/Widgets/DockStack.cs +++ b/Crow/src/Widgets/DockStack.cs @@ -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; } diff --git a/Crow/src/Widgets/DockWindow.cs b/Crow/src/Widgets/DockWindow.cs index a020397e..72a22a75 100644 --- a/Crow/src/Widgets/DockWindow.cs +++ b/Crow/src/Widgets/DockWindow.cs @@ -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; diff --git a/Crow/src/Widgets/Widget.cs b/Crow/src/Widgets/Widget.cs index d1f085aa..1553dab4 100644 --- a/Crow/src/Widgets/Widget.cs +++ b/Crow/src/Widgets/Widget.cs @@ -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 contextCommands; #endregion @@ -1314,6 +1316,9 @@ namespace Crow } #region Drag&Drop + /// + /// If true, allow widget to be dragged and dropped. + /// [DesignCategory ("DragAndDrop")][DefaultValue(false)] public virtual bool AllowDrag { get => allowDrag; @@ -1324,6 +1329,10 @@ namespace Crow NotifyValueChanged ("AllowDrag", allowDrag); } } + /// + /// If true, allow widgets of type listed in 'AllowedDropTypes' to be dropped in this widget + /// during drag and drop operations. + /// [DesignCategory ("DragAndDrop")][DefaultValue(false)] public virtual bool AllowDrop { get => allowDrop; @@ -1333,18 +1342,30 @@ namespace Crow allowDrop = value; NotifyValueChanged ("AllowDrop", allowDrop); } - } - -// public List AllowedDroppedTypes; -// public void AddAllowedDroppedType (Type newType){ -// if (AllowedDroppedTypes == null) -// AllowedDroppedTypes = new List (); -// AllowedDroppedTypes.Add (newType); -// NotifyValueChanged ("AllowDrop", AllowDrop); -// } -// [XmlIgnore]public virtual bool AllowDrop { -// get { return AllowedDroppedTypes?.Count>0; } -// } + } + /// + /// Semicolon separated list of accepted types as dropped widget. + /// + [DesignCategory ("DragAndDrop")][DefaultValue ("Crow.Widget")] + public virtual string AllowedDropTypes { + get => allowedDropTypes; + set { + if (allowedDropTypes == value) + return; + allowedDropTypes = value; + NotifyValueChanged ("AllowedDropTypes", allowedDropTypes); + } + } + // public List AllowedDroppedTypes; + // public void AddAllowedDroppedType (Type newType){ + // if (AllowedDroppedTypes == null) + // AllowedDroppedTypes = new List (); + // 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); /// /// equivalent to mouse move for a dragged widget, no bubbling. /// @@ -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) {