]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement support for markup labels for wxGTK wxButton.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 Feb 2011 12:48:30 +0000 (12:48 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 Feb 2011 12:48:30 +0000 (12:48 +0000)
Simply directly set the markup for the GtkLabel used by GtkButton internally.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67066 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/button.h
src/gtk/button.cpp

index 7d1e5847a1afc79be2435897c37246243272a77d..8116c10f3b7b56781ea1877715bd8cb82823ff8e 100644 (file)
@@ -67,6 +67,10 @@ protected:
     virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
     virtual void DoSetBitmapPosition(wxDirection dir);
 
+#if wxUSE_MARKUP
+    virtual bool DoSetLabelMarkup(const wxString& markup);
+#endif // wxUSE_MARKUP
+
 private:
     typedef wxButtonBase base_type;
 
@@ -91,6 +95,10 @@ private:
     // show the given bitmap (must be valid)
     void GTKDoShowBitmap(const wxBitmap& bitmap);
 
+    // Return the GtkLabel used by this button.
+    GtkLabel *GTKGetLabel() const;
+
+
     // the bitmaps for the different state of the buttons, all of them may be
     // invalid and the button only shows a bitmap at all if State_Normal bitmap
     // is valid
index 19c8d2521b406395d3b4d74040ff766b92a4547c..089fcbda13dc8b3249beb87bfa1c93416b310f0d 100644 (file)
@@ -262,6 +262,24 @@ void wxButton::SetLabel( const wxString &lbl )
     GTKApplyWidgetStyle( false );
 }
 
+bool wxButton::DoSetLabelMarkup(const wxString& markup)
+{
+    wxCHECK_MSG( m_widget != NULL, false, "invalid button" );
+
+    const wxString stripped = RemoveMarkup(markup);
+    if ( stripped.empty() && !markup.empty() )
+        return false;
+
+    wxControl::SetLabel(stripped);
+
+    GtkLabel * const label = GTKGetLabel();
+    wxCHECK_MSG( label, false, "no label in this button?" );
+
+    GTKSetLabelWithMarkupForLabel(label, markup);
+
+    return true;
+}
+
 bool wxButton::Enable( bool enable )
 {
     if (!base_type::Enable(enable))
@@ -282,6 +300,25 @@ GdkWindow *wxButton::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const
     return GTK_BUTTON(m_widget)->event_window;
 }
 
+GtkLabel *wxButton::GTKGetLabel() const
+{
+    GtkWidget *child = GTK_BIN(m_widget)->child;
+    if ( GTK_IS_ALIGNMENT(child) )
+    {
+        GtkWidget *box = GTK_BIN(child)->child;
+        for (GList* item = GTK_BOX(box)->children; item; item = item->next)
+        {
+            GtkBoxChild* boxChild = static_cast<GtkBoxChild*>(item->data);
+            if ( GTK_IS_LABEL(boxChild->widget) )
+                return GTK_LABEL(boxChild->widget);
+        }
+
+        return NULL;
+    }
+
+    return GTK_LABEL(child);
+}
+
 void wxButton::DoApplyWidgetStyle(GtkRcStyle *style)
 {
     gtk_widget_modify_style(m_widget, style);