]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't crash when changing label of label-less wxToggleButton in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 Nov 2011 19:49:54 +0000 (19:49 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 27 Nov 2011 19:49:54 +0000 (19:49 +0000)
If a button doesn't show any text label, simply don't do anything when
SetLabel() is called instead of replacing the image shown by the button with a
text label as the button doesn't expect this to happen and doing it breaks its
assumptions about the widgets it has and results in assert failures later.

Closes #13693.

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

src/gtk/tglbtn.cpp

index 4886ce1fcc55184a99a33e6f6e1194c36346855c..47a55a53af087feb9d9581cb1398cbdd83da6056 100644 (file)
@@ -166,6 +166,14 @@ void wxToggleButton::SetLabel(const wxString& label)
 
     wxAnyButton::SetLabel(label);
 
+    if ( HasFlag(wxBU_NOTEXT) )
+    {
+        // Don't try to update the label for a button not showing it, this is
+        // unnecessary and can also actually replace the image we show with the
+        // label entirely breaking the button code, see #13693.
+        return;
+    }
+
     const wxString labelGTK = GTKConvertMnemonics(label);
 
     gtk_button_set_label(GTK_BUTTON(m_widget), wxGTK_CONV(labelGTK));
@@ -184,10 +192,13 @@ bool wxToggleButton::DoSetLabelMarkup(const wxString& markup)
 
     wxControl::SetLabel(stripped);
 
-    GtkLabel * const label = GTKGetLabel();
-    wxCHECK_MSG( label, false, "no label in this toggle button?" );
+    if ( !HasFlag(wxBU_NOTEXT) )
+    {
+        GtkLabel * const label = GTKGetLabel();
+        wxCHECK_MSG( label, false, "no label in this toggle button?" );
 
-    GTKSetLabelWithMarkupForLabel(label, markup);
+        GTKSetLabelWithMarkupForLabel(label, markup);
+    }
 
     return true;
 }