From 4ae21c7f1aa5c5339fab45c270dfd5048457bb99 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 11 Feb 2015 21:16:11 +0000 Subject: [PATCH] Make wxStaticText alignment work with wxGTK2. Alignment was silently ignored in wxStaticText with GTK+ 2 since 2.12 or so, make it work even at the price of using a non-default ellipsize mode as this seems to be the only way to have it at all. Closes #12539. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78478 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/stattext.cpp | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/gtk/stattext.cpp b/src/gtk/stattext.cpp index 97e4a6ac15..c2838b7a15 100644 --- a/src/gtk/stattext.cpp +++ b/src/gtk/stattext.cpp @@ -55,11 +55,35 @@ bool wxStaticText::Create(wxWindow *parent, GtkJustification justify; if ( style & wxALIGN_CENTER_HORIZONTAL ) - justify = GTK_JUSTIFY_CENTER; + { +#ifndef __WXGTK3__ + // This looks like a bug in GTK+ and seems to be fixed in GTK+3, but + // using non-default justification with default ellipsize mode doesn't + // work: the justification is just ignored. In practice, alignment is + // more important, so turn on ellipsize mode even if it was not + // specified to make it work if necessary. + if ( !(style & wxST_ELLIPSIZE_MASK) ) + style |= wxST_ELLIPSIZE_MIDDLE; +#endif // GTK+ 2 + + justify = GTK_JUSTIFY_CENTER; + } else if ( style & wxALIGN_RIGHT ) - justify = GTK_JUSTIFY_RIGHT; - else - justify = GTK_JUSTIFY_LEFT; + { +#ifndef __WXGTK3__ + // As above, we need to use a non-default ellipsize mode for the + // alignment to have any effect. + if ( !(style & wxST_ELLIPSIZE_MASK) ) + style |= wxST_ELLIPSIZE_START; +#endif // GTK+ 2 + + justify = GTK_JUSTIFY_RIGHT; + } + else // must be wxALIGN_LEFT which is 0 + { + // No need to play games with wxST_ELLIPSIZE_XXX. + justify = GTK_JUSTIFY_LEFT; + } if (GetLayoutDirection() == wxLayout_RightToLeft) {