GNOME Bugzilla – Bug 695312
Initial 'text' set in the non-numeric-only GtkSpinButton automatically overwritten to '0.0'
Last modified: 2013-03-08 10:25:41 UTC
If 'text' is set in a GtkSpinButton before the widget is realized, and if no explicit method is connected to '::output' (or if there is a method but it doesn't reset the text), the text string displayed in the entry is overwritten. E.g, if this is created: spin_button = gtk_widget_new (GTK_TYPE_SPIN_BUTTON, "numeric", FALSE, "text", "initial", NULL); when the widget shown, it will display "0.0" instead of "initial" If we set the 'text' property after having realized the same widget, it will correctly update the shown text to the specified string. This is not really a problem in numeric-only spin buttons, as the initial text set would be converted to/from the internal adjustment value automatically.
Created attachment 238221 [details] [review] Patch When the widget is to be realized and the spin button is not numeric-only, check if we already have a text set before falling back to the default output generator.
Review of attachment 238221 [details] [review]: ::: gtk/gtkspinbutton.c @@ +1053,3 @@ + * 'output' signal; and if we don't have any explicit 'text' set initially, + * fallback to the default output. */ + if (return_val == FALSE && we don't usually check for explicit boolean values, so this would be a good time to fix this check. :-) @@ +1054,3 @@ + * fallback to the default output. */ + if (return_val == FALSE && + (spin_button->numeric || !gtk_entry_get_text (GTK_ENTRY (spin_button)))) whereas we do check for NULL pointers explicitly instead of relying on the truthy value of pointers in C.
Created attachment 238236 [details] [review] updated patch
That looks fine to me now.
Pushed to git master, gtk-3-6 and gtk-2-24.