]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/stattext.cpp
added missing #pragma hdrstop
[wxWidgets.git] / src / gtk / stattext.cpp
index 2641ea02f33db4b7a9c41169d89db99d8dc0c86d..6fe31c64c634923521cbeff0e98b69b1503d2f25 100644 (file)
@@ -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
@@ -120,8 +129,34 @@ void wxStaticText::SetLabel( const wxString &label )
 
 bool wxStaticText::SetFont( const wxFont &font )
 {
+    const bool wasUnderlined = GetFont().GetUnderlined();
+
     bool ret = wxControl::SetFont(font);
 
+    if ( font.GetUnderlined() != wasUnderlined )
+    {
+        // the underlines for mnemonics are incompatible with using attributes
+        // so turn them off when setting underlined font and restore them when
+        // unsetting it
+        gtk_label_set_use_underline(GTK_LABEL(m_widget), wasUnderlined);
+
+        if ( wasUnderlined )
+        {
+            // it's not underlined any more, remove the attributes we set
+            gtk_label_set_attributes(GTK_LABEL(m_widget), NULL);
+        }
+        else // the text is underlined now
+        {
+            PangoAttrList *attrs = pango_attr_list_new();
+            PangoAttribute *a = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE);
+            a->start_index = 0;
+            a->end_index = (guint)-1;
+            pango_attr_list_insert(attrs, a);
+            gtk_label_set_attributes(GTK_LABEL(m_widget), attrs);
+            pango_attr_list_unref(attrs);
+        }
+    }
+
     // adjust the label size to the new label unless disabled
     if (!HasFlag(wxST_NO_AUTORESIZE))
     {
@@ -154,7 +189,8 @@ wxSize wxStaticText::DoGetBestSize() const
 
     gtk_label_set_line_wrap( GTK_LABEL(m_widget), TRUE );
 
-    return wxSize (req.width, req.height);
+    // Adding 1 to width to workaround GTK sometimes wrapping the text needlessly
+    return wxSize (req.width+1, req.height);
 }
 
 bool wxStaticText::SetForegroundColour(const wxColour& colour)