From: Robert Roebling Date: Sun, 10 Sep 2006 19:39:22 +0000 (+0000) Subject: Implemented window coord mirroring for RTL. This X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6959763942eb0e852113945c54113f3521b9c26f?ds=inline Implemented window coord mirroring for RTL. This is only implemented for *setting* the coordinates which is enough for wxSizers and 99% or other dialogs to work. Also reversed the meaning of wxStaticText alignment in RTL mode. It is possible that later versions of GTK actually do that themselves. (?) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41137 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/win_gtk.h b/include/wx/gtk/win_gtk.h index b873dffa5d..34e665a410 100644 --- a/include/wx/gtk/win_gtk.h +++ b/include/wx/gtk/win_gtk.h @@ -50,11 +50,10 @@ struct _GtkPizza GList *children; GtkMyShadowType shadow_type; - guint m_width; - guint m_height; - guint m_xoffset; guint m_yoffset; + + gint m_width; GdkWindow *bin_window; @@ -77,10 +76,6 @@ GtkWidget* gtk_pizza_new (void); /* accessors */ -WXDLLIMPEXP_CORE -gint gtk_pizza_get_width (GtkPizza *pizza); -WXDLLIMPEXP_CORE -gint gtk_pizza_get_height (GtkPizza *pizza); WXDLLIMPEXP_CORE gint gtk_pizza_get_xoffset (GtkPizza *pizza); WXDLLIMPEXP_CORE diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index c8ab59de09..8d2c1e01b4 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -72,6 +72,15 @@ bool wxStaticText::Create(wxWindow *parent, justify = GTK_JUSTIFY_RIGHT; else // wxALIGN_LEFT is 0 justify = GTK_JUSTIFY_LEFT; + + if (GetLayoutDirection() == wxLayout_RightToLeft) + { + if (justify == GTK_JUSTIFY_RIGHT) + justify = GTK_JUSTIFY_LEFT; + if (justify == GTK_JUSTIFY_LEFT) + justify = GTK_JUSTIFY_RIGHT; + } + gtk_label_set_justify(GTK_LABEL(m_widget), justify); // GTK_JUSTIFY_LEFT is 0, RIGHT 1 and CENTER 2 diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 614a4dce0a..33ef92100e 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -237,8 +237,13 @@ static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* (int)alloc->height ); */ + // Tell the wxWindow class about the new size win->m_width = alloc->width; win->m_height = alloc->height; + + if (win->m_mainWidget) + GTK_PIZZA(win->m_mainWidget)->m_width = win->m_width; + win->GtkUpdateSize(); } } @@ -559,6 +564,8 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, GTK_WIDGET_UNSET_FLAGS( m_mainWidget, GTK_CAN_FOCUS ); gtk_container_add( GTK_CONTAINER(m_widget), m_mainWidget ); + GTK_PIZZA(m_mainWidget)->m_width = m_width; + if (m_miniEdge == 0) // wxMiniFrame has its own version. { // For m_mainWidget themes @@ -852,6 +859,9 @@ void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int si } if (width != -1) m_width = width; if (height != -1) m_height = height; + + if (m_mainWidget) + GTK_PIZZA(m_mainWidget)->m_width = m_width; /* if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH) @@ -1024,6 +1034,7 @@ void wxTopLevelWindowGTK::GtkOnSize() if (client_h < 0) client_h = 0; + // Let the parent perform the resize gtk_pizza_set_size( GTK_PIZZA(m_mainWidget), m_wxwindow, client_x, client_y, client_w, client_h ); diff --git a/src/gtk/win_gtk.c b/src/gtk/win_gtk.c index 8d31fb8675..6e473cfa67 100644 --- a/src/gtk/win_gtk.c +++ b/src/gtk/win_gtk.c @@ -189,13 +189,12 @@ gtk_pizza_init (GtkPizza *pizza) pizza->children = NULL; - pizza->m_width = 20; - pizza->m_height = 20; - pizza->bin_window = NULL; pizza->m_xoffset = 0; pizza->m_yoffset = 0; + + pizza->m_width = -1; pizza->external_expose = FALSE; } @@ -210,22 +209,6 @@ gtk_pizza_new () return GTK_WIDGET (pizza); } -gint gtk_pizza_get_width (GtkPizza *pizza) -{ - g_return_val_if_fail ( (pizza != NULL), -1 ); - g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); - - return pizza->m_width; -} - -gint gtk_pizza_get_height (GtkPizza *pizza) -{ - g_return_val_if_fail ( (pizza != NULL), -1 ); - g_return_val_if_fail ( (GTK_IS_PIZZA (pizza)), -1 ); - - return pizza->m_height; -} - gint gtk_pizza_get_xoffset (GtkPizza *pizza) { g_return_val_if_fail ( (pizza != NULL), -1 ); @@ -311,6 +294,12 @@ gtk_pizza_put (GtkPizza *pizza, g_return_if_fail (GTK_IS_PIZZA (pizza)); g_return_if_fail (widget != NULL); + if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL) + { + // reverse horizontal placement + x = pizza->m_width - x - width; + } + child_info = g_new (GtkPizzaChild, 1); child_info->widget = widget; @@ -319,6 +308,9 @@ gtk_pizza_put (GtkPizza *pizza, child_info->width = width; child_info->height = height; + if (GTK_IS_PIZZA(widget)) + GTK_PIZZA(widget)->m_width = width; + pizza->children = g_list_append (pizza->children, child_info); if (GTK_WIDGET_REALIZED (pizza)) @@ -362,15 +354,25 @@ gtk_pizza_set_size (GtkPizza *pizza, if (child->widget == widget) { - if ((child->x == x) && + gint new_x = x; + if (gtk_widget_get_direction( GTK_WIDGET(pizza) ) == GTK_TEXT_DIR_RTL) + { + // reverse horizontal placement + new_x = pizza->m_width - new_x - width; + } + + if ((child->x == new_x) && (child->y == y) && (child->width == width) && (child->height == height)) return; - child->x = x; + child->x = new_x; child->y = y; child->width = width; child->height = height; + + if (GTK_IS_PIZZA(widget)) + GTK_PIZZA(widget)->m_width = width; gtk_widget_set_size_request (widget, width, height); diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 1fe968ef99..375ad6d806 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2115,7 +2115,7 @@ gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win ) static void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), - GtkAllocation *WXUNUSED(alloc), + GtkAllocation *alloc, wxWindow *win ) { if (g_isIdle) @@ -2127,6 +2127,8 @@ void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), if ((client_width == win->m_oldClientWidth) && (client_height == win->m_oldClientHeight)) return; + GTK_PIZZA(win->m_wxwindow)->m_width = alloc->width; + win->m_oldClientWidth = client_width; win->m_oldClientHeight = client_height; @@ -2732,7 +2734,9 @@ bool wxWindowGTK::Destroy() void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height) { + // inform the parent to perform the move gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), m_widget, x, y, width, height ); + } void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags ) @@ -3479,7 +3483,16 @@ void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir) GTKSetLayout(m_widget, dir); if (m_wxwindow) - GTKSetLayout(m_widget, dir); + GTKSetLayout(m_wxwindow, dir); +} + +wxCoord +wxWindowGTK::AdjustForLayoutDirection(wxCoord x, + wxCoord WXUNUSED(width), + wxCoord WXUNUSED(widthTotal)) const +{ + // We now mirrors the coordinates of RTL windows in GtkPizza + return x; } void wxWindowGTK::DoMoveInTabOrder(wxWindow *win, MoveKind move)