From d9a0615feaa40d5f79d814310f12b2b41c4e98bb Mon Sep 17 00:00:00 2001 From: Alexander Sorokin Date: Fri, 10 Nov 2017 09:59:10 +0300 Subject: [PATCH] [WPF] Fixed drag operation starting even when mouse is outside TreeView This closes #752 --- Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs | 2 ++ Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs b/Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs index 9fbaf9704..de989d5c4 100644 --- a/Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs +++ b/Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs @@ -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); } @@ -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); } diff --git a/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs b/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs index 3033dea5b..2dc69f258 100644 --- a/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs +++ b/Xwt.WPF/Xwt.WPFBackend/WidgetBackend.cs @@ -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); @@ -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) @@ -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; } @@ -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;