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 541399 - Widget tooltips: treat "" same as NULL
Widget tooltips: treat "" same as NULL
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: .General
2.13.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks: 541296
 
 
Reported: 2008-07-03 14:47 UTC by Murray Cumming
Modified: 2008-07-10 17:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtk_widget_tooltip_empty_is_null.patch (1.81 KB, patch)
2008-07-03 14:48 UTC, Murray Cumming
committed Details | Review

Description Murray Cumming 2008-07-03 14:47:54 UTC
Patch attached:

2008-07-03  Murray Cumming  <murrayc@murrayc.com>

	* gtk/gtkwidget.c (gtk_widget_set_property):  tooltip-text and 
	tooltip-markup properties: Interpret an empty string as a NULL 
	string because an empty tooltip is silly. This will help 
	language bindings that do not bother to have the two types of 
	empty/null strings.
Comment 1 Murray Cumming 2008-07-03 14:48:53 UTC
Created attachment 113926 [details] [review]
gtk_widget_tooltip_empty_is_null.patch
Comment 2 Tim Janik 2008-07-04 09:18:47 UTC
Comment on attachment 113926 [details] [review]
gtk_widget_tooltip_empty_is_null.patch

Thanks, the patch looks good Murray, please apply after the following coding style issues have been fixed.

>Index: gtk/gtkwidget.c
>===================================================================
>--- gtk/gtkwidget.c	(revision 20744)
>+++ gtk/gtkwidget.c	(working copy)
>@@ -2478,6 +2478,13 @@
>       tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
>       tooltip_markup = g_value_dup_string (value);
> 
>+      /* Treat an empty string as a NULL string, 
>+         because an empty string would be useless for a tooltip: */

All comment lines are prefixed with '*' in Gtk+ coding style. also '*/' should go on its own line.

>+      if (tooltip_markup && (strlen (tooltip_markup) == 0)) {

Braces also go on their own line.
>+	g_free (tooltip_markup);
>+        tooltip_markup = NULL;
>+      }
>+
>       g_object_set_qdata_full (object, quark_tooltip_markup,
> 			       tooltip_markup, g_free);
> 
>@@ -2486,7 +2493,14 @@
>       break;
>     case PROP_TOOLTIP_TEXT:
>       tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
>+
>       tooltip_text = g_value_get_string (value);
>+
>+      /* Treat an empty string as a NULL string, 
>+         because an empty string would be useless for a tooltip: */

dito.

>+      if (tooltip_text && (strlen (tooltip_text) == 0))
>+        tooltip_text = NULL;
>+
>       tooltip_markup = tooltip_text ? g_markup_escape_text (tooltip_text, -1) : NULL;
> 
>       g_object_set_qdata_full (object, quark_tooltip_markup,
Comment 3 Markus Schwab 2008-07-08 19:16:16 UTC
Admittedly I have no clue about GTK's coding styles/rules, so sorry if I ask something stupid, but wouldn't it be faster to replace the "strlen"-calls in the patch with a check if the first char is a '\0', i.e.

  if (tooltip_markup && *tooltip_markup)  /* or (*tooltip_markup != '\0') */

and

  if (tooltip_text && *tooltip_text)
Comment 4 Tim Janik 2008-07-08 21:16:59 UTC
(In reply to comment #3)
> Admittedly I have no clue about GTK's coding styles/rules, so sorry if I ask
> something stupid, but wouldn't it be faster to replace the "strlen"-calls in
> the patch with a check if the first char is a '\0', i.e.
> 
>   if (tooltip_markup && *tooltip_markup)  /* or (*tooltip_markup != '\0') */
> 
> and
> 
>   if (tooltip_text && *tooltip_text)

Yes, it would be faster, but only a tiny bit and the code in question isn't performance critical in anyway. In general, readability should be the prime concern, personally I don't have a strong preference for one over the other here though.

Comment 5 Murray Cumming 2008-07-10 17:48:31 UTC
Committed to trunk and and gtk-2-12 with Tim's code formatting changes.