From: jpbruyere Date: Tue, 2 May 2017 13:06:13 +0000 (+0200) Subject: basic drag&drop functional X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=711ba64404c4842d7e3e7c7ade5c48e00d81a623;p=jp%2Fcrow.git basic drag&drop functional --- diff --git a/Default.style b/Default.style index 0db6a08a..b8eb8096 100644 --- a/Default.style +++ b/Default.style @@ -88,6 +88,12 @@ ToolWindow { Width = 150; Height = 150; } +DocksView { + AllowDrop = true; +} +DockingView { + AllowDrag = true; +} FileDialog { Template = #Crow.FileDialog.template; Focusable = true; diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index 370e2816..dfb00e06 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -190,6 +190,7 @@ namespace Crow object tag; bool isDragged; bool allowDrag; + bool allowDrop; #endregion @@ -311,6 +312,8 @@ namespace Crow public event EventHandler Enabled; /// Occurs when the enabled state this object is set to false public event EventHandler Disabled; + public event EventHandler Dragged; + public event EventHandler Dropped; /// Occurs when one part of the rendering slot changed public event EventHandler LayoutChanged; /// Occurs when DataSource changed @@ -1012,7 +1015,7 @@ namespace Crow } #region Drag&Drop - [XmlAttributeAttribute()][DefaultValue(false)] + [XmlAttributeAttribute][DefaultValue(false)] public virtual bool AllowDrag { get { return allowDrag; } set { @@ -1022,12 +1025,27 @@ namespace Crow NotifyValueChanged ("AllowDrag", allowDrag); } } - - public List AllowedDroppedTypes; - - [XmlIgnore]public virtual bool AllowDrop { - get { return AllowedDroppedTypes?.Count>0; } + [XmlAttributeAttribute][DefaultValue(false)] + public virtual bool AllowDrop { + get { return allowDrop; } + set { + if (allowDrop == value) + return; + 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; } +// } [XmlIgnore]public virtual bool IsDragged { get { return isDragged; } set { @@ -1035,18 +1053,35 @@ namespace Crow return; isDragged = value; - if (isDragged) + if (isDragged) { currentInterface.HoverWidget = null; + onStartDrag (this, null); + } NotifyValueChanged ("IsDrag", IsDragged); } } - - public void AddAllowedDroppedType (Type newType){ - if (AllowedDroppedTypes == null) - AllowedDroppedTypes = new List (); - AllowedDroppedTypes.Add (newType); - NotifyValueChanged ("AllowDrop", AllowDrop); + /// + /// start dragging + /// + protected virtual void onStartDrag (object sender, EventArgs e){ + Debug.WriteLine("DRAG => " + this.ToString()); + Dragged.Raise (this, null); + } + /// + /// Occured when dragging ends without dropping + /// + protected virtual void onEndDrag (object sender, EventArgs e){ + IsDragged = false; + Debug.WriteLine("END DRAG => " + this.ToString()); + } + /// + /// Dragging end with a dropping + /// + protected virtual void onDrop (object sender, EventArgs e){ + IsDragged = false; + Debug.WriteLine("DROPPED => " + this.ToString()); + Dropped.Raise (this, null); } #endregion @@ -1479,6 +1514,9 @@ namespace Crow } public virtual void onMouseMove(object sender, MouseMoveEventArgs e) { + if (AllowDrag & !IsDragged & IsActive) + IsDragged = true; + //bubble event to the top GraphicObject p = Parent as GraphicObject; if (p != null) @@ -1513,6 +1551,18 @@ namespace Crow MouseDown.Raise (this, e); } public virtual void onMouseUp(object sender, MouseButtonEventArgs e){ + if (IsDragged){ + bool dropOK = false; + if (currentInterface.HoverWidget!=null) { + if (currentInterface.HoverWidget.AllowDrop) + dropOK = true; + } + if (dropOK) + onDrop (this, null); + else + onEndDrag (this, null); + } + //bubble event to the top GraphicObject p = Parent as GraphicObject; if (p != null) diff --git a/src/Interface.cs b/src/Interface.cs index 2dab2c85..20d5ca4d 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -758,7 +758,8 @@ namespace Crow //TODO, ensure object is still in the graphic tree //send move evt even if mouse move outside bounds ActiveWidget.onMouseMove (this, e); - return true; + if (!ActiveWidget.IsDragged)//if active is dragged, process mouse move as it was not visible. + return true; } if (HoverWidget != null) {