From 9f6f5ab4f5c1f3bb71033bb894afaa040bbac19f Mon Sep 17 00:00:00 2001 From: Paul Cornett Date: Sun, 19 Oct 2014 00:59:20 +0000 Subject: [PATCH] Fix ClientToScreen()/ScreenToClient() when used immediately after window creation. And whenever window does not have an up-to-date GTK size allocation. Closes #16061 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_3_0_BRANCH@78033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/window.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 996daafade..7fb8b0433f 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -3091,7 +3091,37 @@ void wxWindowGTK::DoClientToScreen( int *x, int *y ) const { wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); - if (gtk_widget_get_window(m_widget) == NULL) return; + if (!m_useCachedClientSize && !IsTopLevel() && m_parent) + { + m_parent->DoClientToScreen(x, y); + int xx, yy; + DoGetPosition(&xx, &yy); + if (m_wxwindow) + { + GtkBorder border; + WX_PIZZA(m_wxwindow)->get_border(border); + xx += border.left; + yy += border.top; + } + if (y) *y += yy; + if (x) + { + if (GetLayoutDirection() != wxLayout_RightToLeft) + *x += xx; + else + { + int w; + // undo RTL conversion done by parent + m_parent->DoGetClientSize(&w, NULL); + *x = w - *x; + + DoGetClientSize(&w, NULL); + *x += xx; + *x = w - *x; + } + } + return; + } GdkWindow *source = NULL; if (m_wxwindow) @@ -3099,6 +3129,8 @@ void wxWindowGTK::DoClientToScreen( int *x, int *y ) const else source = gtk_widget_get_window(m_widget); + wxCHECK_RET(source, "ClientToScreen failed on unrealized window"); + int org_x = 0; int org_y = 0; gdk_window_get_origin( source, &org_x, &org_y ); @@ -3130,7 +3162,37 @@ void wxWindowGTK::DoScreenToClient( int *x, int *y ) const { wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); - if (!gtk_widget_get_realized(m_widget)) return; + if (!m_useCachedClientSize && !IsTopLevel() && m_parent) + { + m_parent->DoScreenToClient(x, y); + int xx, yy; + DoGetPosition(&xx, &yy); + if (m_wxwindow) + { + GtkBorder border; + WX_PIZZA(m_wxwindow)->get_border(border); + xx += border.left; + yy += border.top; + } + if (y) *y -= yy; + if (x) + { + if (GetLayoutDirection() != wxLayout_RightToLeft) + *x -= xx; + else + { + int w; + // undo RTL conversion done by parent + m_parent->DoGetClientSize(&w, NULL); + *x = w - *x; + + DoGetClientSize(&w, NULL); + *x -= xx; + *x = w - *x; + } + } + return; + } GdkWindow *source = NULL; if (m_wxwindow) @@ -3138,6 +3200,8 @@ void wxWindowGTK::DoScreenToClient( int *x, int *y ) const else source = gtk_widget_get_window(m_widget); + wxCHECK_RET(source, "ScreenToClient failed on unrealized window"); + int org_x = 0; int org_y = 0; gdk_window_get_origin( source, &org_x, &org_y );