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

Commit

Permalink
Merge pull request #753 from alsorokin/fix-drag-from-outside
Browse files Browse the repository at this point in the history
 [WPF] Fixed drag operation starting even when mouse is outside TreeView
  • Loading branch information
sevoku authored Nov 17, 2017
2 parents 11bc60a + d9a0615 commit fa9239a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions TestApps/Samples/Samples/TreeViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// THE SOFTWARE.
using System;
using Xwt;
using Xwt.Drawing;

namespace Samples
{
Expand Down Expand Up @@ -147,6 +148,8 @@ public TreeViews ()
view.DragStarted += delegate(object sender, DragStartedEventArgs e) {
var val = store.GetNavigatorAt (view.SelectedRow).GetValue (text);
e.DragOperation.Data.AddValue (val);
var img = Image.FromResource(GetType(), "class.png");
e.DragOperation.SetDragImage(img, (int)img.Size.Width, (int)img.Size.Height);
e.DragOperation.Finished += delegate(object s, DragFinishedEventArgs args) {
Console.WriteLine ("D:" + args.DeleteSource);
};
Expand Down
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 fa9239a

Please sign in to comment.