Skip to content

Commit

Permalink
Merge pull request #2498 from cwensley/curtis/wpf-release-capture-on-…
Browse files Browse the repository at this point in the history
…mouseup

Wpf/WinForms: Release capture if MouseUp event is handled by user code
  • Loading branch information
cwensley authored Jun 7, 2023
2 parents 3abe8c7 + 1bb39ed commit 6faef4b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/Eto.WinForms/Forms/ApplicationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,16 @@ void SetOptions()
}, null, Win32.WM.LBUTTONDBLCLK, Win32.WM.RBUTTONDBLCLK, Win32.WM.MBUTTONDBLCLK);
void OnMouseUpHandler(Control c, Control.ICallback cb, MouseEventArgs e)
{
if (c.Handler is IWindowsControl handler && handler.MouseCaptured)
var handler = c.Handler as IWindowsControl;
if (handler != null && handler.MouseCaptured)
{
handler.MouseCaptured = false;
handler.ContainerControl.Capture = false;
}
cb.OnMouseUp(c, e);

if (handler != null && e.Handled && handler.ContainerControl.Capture)
handler.ContainerControl.Capture = false;
}

bubble.AddBubbleMouseEvent(OnMouseUpHandler, false, Win32.WM.LBUTTONUP, b => MouseButtons.Primary);
Expand Down
6 changes: 5 additions & 1 deletion src/Eto.WinForms/Forms/WindowsControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,11 @@ void HandleMouseUp(Object sender, swf.MouseEventArgs e)
MouseCaptured = false;
Control.Capture = false;
}
Callback.OnMouseUp(Widget, e.ToEto(Control));
var args = e.ToEto(Control);
Callback.OnMouseUp(Widget, args);

if (args.Handled && Control.Capture)
Control.Capture = false;
}

void HandleMouseMove(Object sender, swf.MouseEventArgs e)
Expand Down
5 changes: 5 additions & 0 deletions src/Eto.Wpf/Forms/WpfFrameworkElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,11 @@ protected virtual void HandleMouseUp(object sender, swi.MouseButtonEventArgs e)

Callback.OnMouseUp(Widget, args);
e.Handled = args.Handled;

// If the mouse was captured intrinsically we need to release capture otherwise it hangs the app
// since the caller is overriding default behaviour.
if (e.Handled && Control.IsMouseCaptured)
Control.ReleaseMouseCapture();
}

void HandleMouseDoubleClick(object sender, swi.MouseButtonEventArgs e)
Expand Down

0 comments on commit 6faef4b

Please sign in to comment.