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);
if (curDockPos != dw.DockingPosition)
RegisterForGraphicUpdate ();
- }
+ //}
//base.onMouseMove (sender, e);
}
g.Paint (gr);
childrenRWLock.ExitReadLock ();
-
-
- if (!IsDropTarget) {
+
+ if (!(IsDropTarget || (IFace.DropTarget is DockWindow dtdw && dtdw.Parent == this))) {
gr.Restore ();
return;
}
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);
}
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 () {
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;
using Crow.IML;
using System.Threading;
using Glfw;
+using System.Linq;
#if DESIGN_MODE
bool isDragged;
bool allowDrag;
bool allowDrop;
+ string allowedDropTypes;
string tooltip;
IList<Command> contextCommands;
#endregion
}
#region Drag&Drop
+ /// <summary>
+ /// If true, allow widget to be dragged and dropped.
+ /// </summary>
[DesignCategory ("DragAndDrop")][DefaultValue(false)]
public virtual bool AllowDrag {
get => allowDrag;
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;
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 {
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>
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) {