From 638f0f89fcbf3815380255f929434a98a23a7c16 Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Thu, 21 Jan 2021 11:27:00 -0800 Subject: [PATCH] Fix mouse event coordinates for single-line wxTextCtrl with GTK3 --- include/wx/gtk/private/event.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/wx/gtk/private/event.h b/include/wx/gtk/private/event.h index eda9e6e7f4..4ea9d587d1 100644 --- a/include/wx/gtk/private/event.h +++ b/include/wx/gtk/private/event.h @@ -59,6 +59,21 @@ template void InitMouseEvent(wxWindowGTK *win, event.m_x = (wxCoord)gdk_event->x - pt.x; event.m_y = (wxCoord)gdk_event->y - pt.y; + // Some no-window widgets, notably GtkEntry on GTK3, have a GdkWindow + // covering part of their area. Event coordinates from that window are + // not relative to the widget, so do the conversion here. + if (!gtk_widget_get_has_window(win->m_widget) && + gtk_widget_get_window(win->m_widget) == gdk_window_get_parent(gdk_event->window)) + { + GtkAllocation a; + gtk_widget_get_allocation(win->m_widget, &a); + int posX, posY; + gdk_window_get_position(gdk_event->window, &posX, &posY); + + event.m_x += posX - a.x; + event.m_y += posY - a.y; + } + if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft)) { // origin in the upper right corner