Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wpf/WinForms: Release capture if MouseUp event is handled by user code #2498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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