After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 695312 - Initial 'text' set in the non-numeric-only GtkSpinButton automatically overwritten to '0.0'
Initial 'text' set in the non-numeric-only GtkSpinButton automatically overwr...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkSpinButton
3.7.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2013-03-06 18:17 UTC by Aleksander Morgado
Modified: 2013-03-08 10:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (1.12 KB, patch)
2013-03-06 18:31 UTC, Aleksander Morgado
reviewed Details | Review
updated patch (1.12 KB, patch)
2013-03-06 19:39 UTC, Aleksander Morgado
committed Details | Review

Description Aleksander Morgado 2013-03-06 18:17:39 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.
Comment 1 Aleksander Morgado 2013-03-06 18:31:24 UTC
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.
Comment 2 Emmanuele Bassi (:ebassi) 2013-03-06 19:23:01 UTC
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.
Comment 3 Aleksander Morgado 2013-03-06 19:39:56 UTC
Created attachment 238236 [details] [review]
updated patch
Comment 4 Michael Natterer 2013-03-08 08:57:41 UTC
That looks fine to me now.
Comment 5 Aleksander Morgado 2013-03-08 10:25:41 UTC
Pushed to git master, gtk-3-6 and gtk-2-24.