Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Commit

Permalink
[WPF] Fixed drag operation starting even when mouse is outside TreeView
Browse files Browse the repository at this point in the history
This closes #752
  • Loading branch information
Alexander Sorokin committed Nov 17, 2017
1 parent ee9009b commit d9a0615
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ protected override void OnMouseLeftButtonDown (MouseButtonEventArgs e)
{
if (!view.SelectedItems.Contains (this.DataContext) || CtrlPressed)
view.SelectItem (this);
view.Backend.WidgetMouseDownForDragHandler (this, e);
e.Handled = true;
base.OnMouseLeftButtonDown (e);
}
Expand All @@ -141,6 +142,7 @@ protected override void OnMouseLeftButtonUp (MouseButtonEventArgs e)
{
if (view.SelectedItems.Contains (this.DataContext) && !CtrlPressed)
view.SelectItem (this);
view.Backend.WidgetMouseUpForDragHandler(this, e);
e.Handled = true;
base.OnMouseLeftButtonUp (e);
}
Expand Down
10 changes: 8 additions & 2 deletions Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,11 @@ void WidgetMouseDownHandler (object o, MouseButtonEventArgs e)
e.Handled = true;
}

internal void WidgetMouseDownForDragHandler(object o, MouseButtonEventArgs e)
{
SetupDragRect(e);
}

void WidgetMouseUpHandler (object o, MouseButtonEventArgs e)
{
var args = e.ToXwtButtonArgs (Widget);
Expand Down Expand Up @@ -742,6 +747,7 @@ public void SetDragSource (TransferDataType [] types, DragDropAction dragAction)
DragDropInfo.TargetTypes = types == null ? new TransferDataType [0] : types;
Widget.MouseUp += WidgetMouseUpForDragHandler;
Widget.MouseMove += WidgetMouseMoveForDragHandler;
Widget.MouseDown += WidgetMouseDownForDragHandler;
}

private void SetupDragRect (MouseEventArgs e)
Expand All @@ -752,7 +758,7 @@ private void SetupDragRect (MouseEventArgs e)
DragDropInfo.DragRect = new Rect (loc.X - width / 2, loc.Y - height / 2, width, height);
}

void WidgetMouseUpForDragHandler (object o, EventArgs e)
internal void WidgetMouseUpForDragHandler (object o, EventArgs e)
{
DragDropInfo.DragRect = Rect.Empty;
}
Expand All @@ -765,7 +771,7 @@ void WidgetMouseMoveForDragHandler (object o, MouseEventArgs e)
return;

if (DragDropInfo.DragRect.IsEmpty)
SetupDragRect (e);
return;

if (DragDropInfo.DragRect.Contains (e.GetPosition (Widget)))
return;
Expand Down

0 comments on commit d9a0615

Please sign in to comment.