<?xml version="1.0"?>
<HorizontalStack Background="Onyx" Margin="10" Width="90%" Height="90%" Spacing="100" Focusable="true">
- <Container StartDrag="{Background=Yellow}" EndDrag="{Background=Mantis}" Focusable="true" Fit="true"
- MouseEnter="{/txt.Foreground=Red;Background=Blue}" MouseLeave="{/txt.Foreground=White}"
+ <Container Name="source" StartDrag="{Background=Jet}" EndDrag="{Background=Mantis}" Focusable="true" Fit="true"
+ Drop="{../target.Background=Green}"
+ MouseEnter="{/txt.Foreground=Red}" MouseLeave="{/txt.Foreground=White}" MouseClick="{Background=Mantis}"
AllowDrag="true" Width="200" Height="200" Background="Mantis">
<VerticalStack Margin="50">
<Label Name="txt" Text="Drag me" Foreground="Gray"/>
- <Label Text="Dragged" Visible="{/IsDragged}"/>
+ <Label Text="Dragged" Visible="{../../IsDragged}" Foreground="Gray"/>
</VerticalStack>
</Container>
- <Container StartDrag="{Background=Yellow}" EndDrag="{Background=Mantis}" Focusable="true" Fit="true"
+ <Container Name="target" DragEnter="{Background=Mantis}" DragLeave="{Background=Jet}" Focusable="true" Fit="true"
MouseEnter="{/txt.Foreground=Red}" MouseLeave="{/txt.Foreground=White}"
- AllowDrop="true" Background="Mantis">
+ AllowDrop="true" Background="Jet">
<VerticalStack Margin="50">
<Label Name="txt" Text="Drop here" Foreground="Gray"/>
- <Label Text="Dragged" Visible="{/IsDragged}"/>
+ <Label Text="Dragged" Visible="{../../IsDragged}" Foreground="Gray"/>
</VerticalStack>
</Container>
</HorizontalStack>
\ No newline at end of file
--- /dev/null
+//
+// LayoutingEventArgs.cs
+//
+// Author:
+// Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
+//
+// Copyright (c) 2013-2017 Jean-Philippe Bruyère
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+using System;
+
+namespace Crow
+{
+ public class DragDropEventArgs: EventArgs
+ {
+ /// <summary>
+ /// Source of the drag and drop operation
+ /// </summary>
+ public GraphicObject DragSource;
+ /// <summary>
+ /// Target of the drag and drop operation
+ /// </summary>
+ public GraphicObject DropTarget;
+
+ //public DragDropEventArgs (GraphicObject source, GraphicObject target = null) : base()
+ public DragDropEventArgs (GraphicObject source = null, GraphicObject target = null) : base()
+ {
+ DragSource = source;
+ DropTarget = target;
+ }
+
+ public override string ToString ()
+ {
+ return string.Format ("{0} => {1}", DragSource,DropTarget);
+ }
+ }
+}
+
/// <summary>Occurs when the enabled state this object is set to false</summary>
public event EventHandler Disabled;
public event EventHandler StartDrag;
+ public event EventHandler DragEnter;
+ public event EventHandler DragLeave;
public event EventHandler EndDrag;
- public event EventHandler Dropped;
+ public event EventHandler Drop;
/// <summary>Occurs when one part of the rendering slot changed</summary>
public event EventHandler<LayoutingEventArgs> LayoutChanged;
/// <summary>Occurs when DataSource changed</summary>
return;
isDragged = value;
- if (isDragged) {
- CurrentInterface.HoverWidget = null;
- onStartDrag (this, null);
- }
-
- NotifyValueChanged ("IsDrag", IsDragged);
+ NotifyValueChanged ("IsDragged", IsDragged);
}
}
/// <summary>
- /// start dragging
+ /// fired when drag and drop operation start
/// </summary>
- protected virtual void onStartDrag (object sender, EventArgs e){
- Debug.WriteLine("DRAG => " + this.ToString());
- StartDrag.Raise (this, null);
+ protected virtual void onStartDrag (object sender, DragDropEventArgs e){
+ CurrentInterface.HoverWidget = this.focusParent;
+ IsDragged = true;
+ StartDrag.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : START DRAG => " + e.ToString());
}
/// <summary>
/// Occured when dragging ends without dropping
/// </summary>
- protected virtual void onEndDrag (object sender, EventArgs e){
+ protected virtual void onEndDrag (object sender, DragDropEventArgs e){
IsDragged = false;
- EndDrag.Raise (this, null);
- Debug.WriteLine("END DRAG => " + this.ToString());
+ EndDrag.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : END DRAG => " + e.ToString());
}
- /// <summary>
- /// Dragging end with a dropping
- /// </summary>
- protected virtual void onDrop (object sender, EventArgs e){
+ protected virtual void onDragEnter (object sender, DragDropEventArgs e){
+ e.DropTarget = this;
+ DragEnter.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : DRAG Enter => " + e.ToString());
+ }
+ protected virtual void onDragLeave (object sender, DragDropEventArgs e){
+ e.DropTarget = null;
+ DragLeave.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : DRAG Leave => " + e.ToString());
+ }
+ protected virtual void onDrop (object sender, DragDropEventArgs e){
IsDragged = false;
- Debug.WriteLine("DROPPED => " + this.ToString());
- Dropped.Raise (this, null);
+ Drop.Raise (this, e);
+ Debug.WriteLine(this.ToString() + " : DROP => " + e.ToString());
}
+
#endregion
#region Queuing
}
public virtual void onMouseMove(object sender, MouseMoveEventArgs e)
{
- if (AllowDrag & !IsDragged & IsActive)
- IsDragged = true;
+ if (AllowDrag & HasFocus & e.Mouse.LeftButton == ButtonState.Pressed) {
+ if (CurrentInterface.DragAndDropOperation == null) {
+ CurrentInterface.DragAndDropOperation = new DragDropEventArgs (this);
+ onStartDrag (this, CurrentInterface.DragAndDropOperation);
+ }
+ }
//bubble event to the top
GraphicObject p = focusParent;
Debug.WriteLine("MOUSE UP => " + this.ToString());
#endif
- if (IsDragged){
- bool dropOK = false;
- if (CurrentInterface.HoverWidget!=null) {
- if (CurrentInterface.HoverWidget.AllowDrop)
- dropOK = true;
+ if (CurrentInterface.DragAndDropOperation != null){
+ if (CurrentInterface.DragAndDropOperation.DragSource == this) {
+ if (CurrentInterface.DragAndDropOperation.DropTarget != null)
+ onDrop (this, CurrentInterface.DragAndDropOperation);
+ else
+ onEndDrag (this, CurrentInterface.DragAndDropOperation);
+ CurrentInterface.DragAndDropOperation = null;
}
- if (dropOK)
- onDrop (this, null);
- else
- onEndDrag (this, null);
}
//bubble event to the top
#if DEBUG_FOCUS
Debug.WriteLine("MouseEnter => " + this.ToString());
#endif
+
+ if (CurrentInterface.DragAndDropOperation != null) {
+ if (this.AllowDrop) {
+ if (CurrentInterface.DragAndDropOperation.DragSource != this && CurrentInterface.DragAndDropOperation.DropTarget != this)
+ onDragEnter (this, CurrentInterface.DragAndDropOperation);
+ }
+ }
+
MouseEnter.Raise (this, e);
}
public virtual void onMouseLeave(object sender, MouseMoveEventArgs e)
#if DEBUG_FOCUS
Debug.WriteLine("MouseLeave => " + this.ToString());
#endif
+ if (CurrentInterface.DragAndDropOperation != null) {
+ if (CurrentInterface.DragAndDropOperation.DropTarget == this)
+ onDragLeave (this, CurrentInterface.DragAndDropOperation);
+ }
MouseLeave.Raise (this, e);
}
#endregion