From 428f4657b6c1747e28abeb3b9c2069512b2997d7 Mon Sep 17 00:00:00 2001
From: Robert Roebling <robert@roebling.de>
Date: Mon, 11 Sep 2006 14:20:24 +0000
Subject: [PATCH]   Further RTL fixes.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41162 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 include/wx/gtk/win_gtk.h |  3 +++
 src/gtk/renderer.cpp     |  6 +++++-
 src/gtk/win_gtk.c        | 15 +++++++++++++++
 src/gtk/window.cpp       |  7 ++++++-
 4 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/include/wx/gtk/win_gtk.h b/include/wx/gtk/win_gtk.h
index 34e665a410..a62ed2d841 100644
--- a/include/wx/gtk/win_gtk.h
+++ b/include/wx/gtk/win_gtk.h
@@ -86,6 +86,9 @@ WXDLLIMPEXP_CORE
 void       gtk_pizza_set_yoffset     (GtkPizza          *pizza, gint yoffset); 
 
 
+WXDLLIMPEXP_CORE
+gint       gtk_pizza_get_rtl_offset  (GtkPizza          *pizza); 
+
 WXDLLIMPEXP_CORE
 void       gtk_pizza_set_shadow_type (GtkPizza          *pizza,
                                       GtkMyShadowType    type);
diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp
index 6661e7ff53..f1cd95c856 100644
--- a/src/gtk/renderer.cpp
+++ b/src/gtk/renderer.cpp
@@ -216,6 +216,10 @@ wxRendererGTK::DrawTreeItemButton(wxWindow* win,
     else
         state = GTK_STATE_NORMAL;
 
+    int x_diff = 0;
+    if (win->GetLayoutDirection() == wxLayout_RightToLeft)
+        x_diff = rect.width;
+        
     // VZ: I don't know how to get the size of the expander so as to centre it
     //     in the given rectangle, +2/3 below is just what looks good here...
     gtk_paint_expander
@@ -226,7 +230,7 @@ wxRendererGTK::DrawTreeItemButton(wxWindow* win,
         NULL,
         tree,
         "treeview",
-        dc.LogicalToDeviceX(rect.x) + 2,
+        dc.LogicalToDeviceX(rect.x) + 2 - x_diff,
         dc.LogicalToDeviceY(rect.y) + 3,
         flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED
                                    : GTK_EXPANDER_COLLAPSED
diff --git a/src/gtk/win_gtk.c b/src/gtk/win_gtk.c
index 6e473cfa67..12ccb9b591 100644
--- a/src/gtk/win_gtk.c
+++ b/src/gtk/win_gtk.c
@@ -243,6 +243,21 @@ void       gtk_pizza_set_yoffset     (GtkPizza          *pizza, gint yoffset)
     // do something
 }
 
+gint       gtk_pizza_get_rtl_offset  (GtkPizza          *pizza)
+{
+    gint width;
+
+    g_return_val_if_fail ( (pizza != NULL), 0 );
+    g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), 0 );
+    
+    if (!pizza->bin_window) return 0;
+    
+    gdk_window_get_geometry( pizza->bin_window, NULL, NULL, &width, NULL, NULL );
+    
+    return width;
+}
+
+
 static void
 gtk_pizza_scroll_set_adjustments (GtkPizza     *pizza,
                                     GtkAdjustment  *hadj,
diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp
index c77d7a9041..7f7721e327 100644
--- a/src/gtk/window.cpp
+++ b/src/gtk/window.cpp
@@ -1284,7 +1284,12 @@ template<typename T> void InitMouseEvent(wxWindowGTK *win,
     event.m_y = (wxCoord)gdk_event->y - pt.y;
     
     if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft))
-        event.m_x = GTK_PIZZA(win->m_wxwindow)->m_width - event.m_x;
+    {
+        // origin in the upper right corner
+        int virtual_width = win->GetVirtualSize().x;
+        int window_width = gtk_pizza_get_rtl_offset( GTK_PIZZA(win->m_wxwindow) );
+        event.m_x = wxMax( virtual_width, window_width ) - event.m_x;
+    }
 
     event.SetEventObject( win );
     event.SetId( win->GetId() );
-- 
2.47.2