Introduce convenience property "GtkWidget:tooltip-text" taking care of

2007-06-15 Mathias Hasselmann <mathias.hasselmann@gmx.de>

        * docs/reference/gtk/gtk-sections.txt, gtk/gtk.symbols,
        gtk/gtkwidget.c, gtk/gtkwidget.h, tests/testtooltips.c: Introduce
        convenience property "GtkWidget:tooltip-text" taking care of escaping
        it for unwanted markup entities. Add functions to set tooltip text:
        gtk_widget_set_tooltip_text(), gtk_widget_set_tooltip_markup(),
        gtk_widget_get_tooltip_text(), gtk_widget_get_tooltip_markup().

        * gtk/gtktooltip.c, gtk/gtktooltip.h: Add gtk_tooltip_set_text()
        to set the tooltip text without using markup.

        Patches from Emmanuele Bassi (#447643).

svn path=/trunk/; revision=18142
This commit is contained in:
Mathias Hasselmann 2007-06-15 18:24:55 +00:00 committed by Mathias Hasselmann
parent 4d638bf0c1
commit 9b604e29a2
8 changed files with 223 additions and 29 deletions

View File

@ -1,3 +1,15 @@
2007-06-15 Mathias Hasselmann <mathias.hasselmann@gmx.de>
* docs/reference/gtk/gtk-sections.txt, gtk/gtk.symbols,
gtk/gtkwidget.c, gtk/gtkwidget.h, tests/testtooltips.c: Introduce
convenience property "GtkWidget:tooltip-text" taking care of escaping
it for unwanted markup entities. Add functions to set tooltip text:
gtk_widget_set_tooltip_text(), gtk_widget_set_tooltip_markup(),
gtk_widget_get_tooltip_text(), gtk_widget_get_tooltip_markup().
* gtk/gtktooltip.c, gtk/gtktooltip.h: Add gtk_tooltip_set_text()
to set the tooltip text without using markup.
2007-06-15 Johan Dahlin <jdahlin@async.com.br>
reviewed by: Matthias Clasen

View File

@ -4163,6 +4163,7 @@ gtk_tooltips_get_type
<FILE>gtktooltip</FILE>
<TITLE>GtkTooltip</TITLE>
gtk_tooltip_set_markup
gtk_tooltip_set_text
gtk_tooltip_set_icon
gtk_tooltip_set_icon_from_stock
gtk_tooltip_set_custom
@ -5259,6 +5260,10 @@ gtk_widget_get_action
gtk_widget_is_composited
gtk_widget_error_bell
gtk_widget_keynav_failed
gtk_widget_get_tooltip_markup
gtk_widget_set_tooltip_markup
gtk_widget_get_tooltip_text
gtk_widget_set_tooltip_text
gtk_widget_get_tooltip_window
gtk_widget_set_tooltip_window
gtk_widget_trigger_tooltip_query

View File

@ -4067,6 +4067,7 @@ gtk_tooltip_set_custom
gtk_tooltip_set_icon
gtk_tooltip_set_icon_from_stock
gtk_tooltip_set_markup
gtk_tooltip_set_text
gtk_tooltip_trigger_tooltip_query
#endif
#endif
@ -4637,6 +4638,8 @@ gtk_widget_get_screen
gtk_widget_get_settings
gtk_widget_get_size_request
gtk_widget_get_style
gtk_widget_get_tooltip_markup
gtk_widget_get_tooltip_text
gtk_widget_get_tooltip_window
gtk_widget_get_toplevel
gtk_widget_get_type G_GNUC_CONST
@ -4711,6 +4714,8 @@ gtk_widget_set_sensitive
gtk_widget_set_size_request
gtk_widget_set_state
gtk_widget_set_style
gtk_widget_set_tooltip_markup
gtk_widget_set_tooltip_text
gtk_widget_set_tooltip_window
gtk_widget_shape_combine_mask
gtk_widget_input_shape_combine_mask

View File

@ -214,6 +214,30 @@ gtk_tooltip_set_markup (GtkTooltip *tooltip,
gtk_widget_hide (tooltip->label);
}
/**
* gtk_tooltip_set_text:
* @tooltip: a #GtkTooltip
* @text: a text string or %NULL
*
* Sets the text of the tooltip to be @text. If @text is %NULL, the label
* will be hidden. See also gtk_tooltip_set_markup().
*
* Since: 2.12
*/
void
gtk_tooltip_set_text (GtkTooltip *tooltip,
const gchar *text)
{
g_return_if_fail (GTK_IS_TOOLTIP (tooltip));
gtk_label_set_text (GTK_LABEL (tooltip->label), text);
if (text)
gtk_widget_show (tooltip->label);
else
gtk_widget_hide (tooltip->label);
}
/**
* gtk_tooltip_set_icon:
* @tooltip: a #GtkTooltip

View File

@ -33,6 +33,8 @@ GType gtk_tooltip_get_type (void);
void gtk_tooltip_set_markup (GtkTooltip *tooltip,
const gchar *markup);
void gtk_tooltip_set_text (GtkTooltip *tooltip,
const gchar *text);
void gtk_tooltip_set_icon (GtkTooltip *tooltip,
GdkPixbuf *pixbuf);
void gtk_tooltip_set_icon_from_stock (GtkTooltip *tooltip,

View File

@ -151,7 +151,8 @@ enum {
PROP_EXTENSION_EVENTS,
PROP_NO_SHOW_ALL,
PROP_HAS_TOOLTIP,
PROP_TOOLTIP_MARKUP
PROP_TOOLTIP_MARKUP,
PROP_TOOLTIP_TEXT
};
typedef struct _GtkStateData GtkStateData;
@ -620,21 +621,41 @@ gtk_widget_class_init (GtkWidgetClass *klass)
P_("Whether this widget has a tooltip"),
FALSE,
GTK_PARAM_READWRITE));
/**
* GtkWidget:tooltip-markup:
*
* Sets the text of tooltip to be the given string, which is marked up
* with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
* Also see gtk_tooltip_set_markup().
*
* This is a convenience property which will take care of getting the
* tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
* will automatically be set to %TRUE and there will be taken care of
* #GtkWidget::query-tooltip in the default signal handler.
*
* Since: 2.12
*/
/**
* GtkWidget:tooltip-text:
*
* Sets the text of tooltip to be the given string.
*
* Also see gtk_tooltip_set_text().
*
* This is a convenience property which will take care of getting the
* tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
* will automatically be set to %TRUE and there will be taken care of
* #GtkWidget::query-tooltip in the default signal handler.
*
* Since: 2.12
*/
g_object_class_install_property (gobject_class,
PROP_TOOLTIP_TEXT,
g_param_spec_string ("tooltip-text",
P_("Tooltip Text"),
P_("The contents of the tooltip for this widget"),
NULL,
GTK_PARAM_READWRITE));
/**
* GtkWidget:tooltip-markup:
*
* Sets the text of tooltip to be the given string, which is marked up
* with the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
* Also see gtk_tooltip_set_markup().
*
* This is a convenience property which will take care of getting the
* tooltip shown if the given string is not %NULL: #GtkWidget:has-tooltip
* will automatically be set to %TRUE and there will be taken care of
* #GtkWidget::query-tooltip in the default signal handler.
*
* Since: 2.12
*/
g_object_class_install_property (gobject_class,
PROP_TOOLTIP_MARKUP,
g_param_spec_string ("tooltip-markup",
@ -2005,14 +2026,22 @@ gtk_widget_set_property (GObject *object,
gtk_widget_set_has_tooltip (widget, g_value_get_boolean (value), FALSE);
break;
case PROP_TOOLTIP_MARKUP:
tooltip_markup = g_object_get_qdata (object, quark_tooltip_markup);
tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
tooltip_markup = g_value_dup_string (value);
g_object_set_qdata_full (object, quark_tooltip_markup,
tooltip_markup, g_free);
tmp = (tooltip_window != NULL || tooltip_markup != NULL);
gtk_widget_set_has_tooltip (widget, tmp, FALSE);
break;
case PROP_TOOLTIP_TEXT:
tooltip_window = g_object_get_qdata (object, quark_tooltip_window);
tooltip_markup = g_markup_escape_text (g_value_get_string (value), -1);
g_object_set_qdata_full (object, quark_tooltip_markup,
tooltip_markup, g_free);
tmp = (tooltip_window != NULL || tooltip_markup != NULL);
gtk_widget_set_has_tooltip (widget, tmp, FALSE);
break;
@ -2113,6 +2142,25 @@ gtk_widget_get_property (GObject *object,
case PROP_HAS_TOOLTIP:
g_value_set_boolean (value, GPOINTER_TO_UINT (g_object_get_qdata (object, quark_has_tooltip)));
break;
case PROP_TOOLTIP_TEXT:
{
gchar *escaped = g_object_get_qdata (object, quark_tooltip_markup);
if (!escaped)
g_value_set_string (value, NULL);
else
{
gchar *text;
if (pango_parse_markup (escaped, -1, 0, NULL, &text, NULL, NULL))
{
g_value_set_string (value, text);
g_free (text);
}
else
g_value_set_string (value, NULL);
}
}
break;
case PROP_TOOLTIP_MARKUP:
g_value_set_string (value, g_object_get_qdata (object, quark_tooltip_markup));
break;
@ -8854,6 +8902,99 @@ gtk_widget_trigger_tooltip_query (GtkWidget *widget)
gtk_tooltip_trigger_tooltip_query (gtk_widget_get_display (widget));
}
/**
* gtk_widget_set_tooltip_text:
* @widget: a #GtkWidget
* @text: the contents of the tooltip for @widget
*
* Sets @text as the contents of the tooltip. This function will take
* care of setting GtkWidget:has-tooltip to %TRUE and of the default
* handler for the GtkWidget::query-tooltip signal.
*
* See also the GtkWidget:tooltip-text property and gtk_tooltip_set_text().
*
* Since: 2.12
*/
void
gtk_widget_set_tooltip_text (GtkWidget *widget,
const gchar *text)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_object_set (G_OBJECT (widget), "tooltip-text", text, NULL);
}
/**
* gtk_widget_get_tooltip_text:
* @widget: a #GtkWidget
*
* Gets the contents of the tooltip for @widget.
*
* Return value: the tooltip text, or %NULL. You should free the
* returned string with g_free() when done.
*
* Since: 2.12
*/
gchar *
gtk_widget_get_tooltip_text (GtkWidget *widget)
{
gchar *text = NULL;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_object_get (G_OBJECT (widget), "tooltip-text", &text, NULL);
return text;
}
/**
* gtk_widget_set_tooltip_markup:
* @widget: a #GtkWidget
* @markup: the contents of the tooltip for @widget, or %NULL
*
* Sets @markup as the contents of the tooltip, which is marked up with
* the <link linkend="PangoMarkupFormat">Pango text markup language</link>.
*
* This function will take care of setting GtkWidget:has-tooltip to %TRUE
* and of the default handler for the GtkWidget::query-tooltip signal.
*
* See also the GtkWidget:tooltip-markup property and
* gtk_tooltip_set_markup().
*
* Since: 2.12
*/
void
gtk_widget_set_tooltip_markup (GtkWidget *widget,
const gchar *markup)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
g_object_set (G_OBJECT (widget), "tooltip-markup", markup, NULL);
}
/**
* gtk_widget_get_tooltip_markup:
* @widget: a #GtkWidget
*
* Gets the contents of the tooltip for @widget.
*
* Return value: the tooltip text, or %NULL. You should free the
* returned string with g_free() when done.
*
* Since: 2.12
*/
gchar *
gtk_widget_get_tooltip_markup (GtkWidget *widget)
{
gchar *text = NULL;
g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
g_object_get (G_OBJECT (widget), "tooltip-markup", &text, NULL);
return text;
}
#define __GTK_WIDGET_C__
#include "gtkaliasdef.c"

View File

@ -787,11 +787,16 @@ void gtk_widget_add_mnemonic_label (GtkWidget *widget,
void gtk_widget_remove_mnemonic_label (GtkWidget *widget,
GtkWidget *label);
void gtk_widget_set_tooltip_window (GtkWidget *widget,
GtkWindow *custom_window);
GtkWindow *gtk_widget_get_tooltip_window (GtkWidget *widget);
void gtk_widget_trigger_tooltip_query (GtkWidget *widget);
void gtk_widget_set_tooltip_window (GtkWidget *widget,
GtkWindow *custom_window);
GtkWindow *gtk_widget_get_tooltip_window (GtkWidget *widget);
void gtk_widget_trigger_tooltip_query (GtkWidget *widget);
void gtk_widget_set_tooltip_text (GtkWidget *widget,
const gchar *text);
gchar * gtk_widget_get_tooltip_text (GtkWidget *widget);
void gtk_widget_set_tooltip_markup (GtkWidget *widget,
const gchar *markup);
gchar * gtk_widget_get_tooltip_markup (GtkWidget *widget);
GType gtk_requisition_get_type (void) G_GNUC_CONST;
GtkRequisition *gtk_requisition_copy (const GtkRequisition *requisition);

View File

@ -83,7 +83,7 @@ query_tooltip_text_view_cb (GtkWidget *widget,
}
if (gtk_text_iter_has_tag (&iter, tag))
gtk_tooltip_set_markup (tooltip, "Tooltip on text tag");
gtk_tooltip_set_text (tooltip, "Tooltip on text tag");
else
return FALSE;
@ -286,7 +286,7 @@ main (int argc, char *argv[])
/* A check button using the tooltip-markup property */
button = gtk_check_button_new_with_label ("This one uses the tooltip-markup property");
g_object_set (button, "tooltip-markup", "Hello, I am a static tooltip.", NULL);
gtk_widget_set_tooltip_text (button, "Hello, I am a static tooltip.");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* A check button using the query-tooltip signal */
@ -299,13 +299,13 @@ main (int argc, char *argv[])
/* A label */
button = gtk_label_new ("I am just a label");
gtk_label_set_selectable (GTK_LABEL (button), FALSE);
g_object_set (button, "tooltip-markup", "Label tooltip", NULL);
gtk_widget_set_tooltip_text (button, "Label & and tooltip");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* A selectable label */
button = gtk_label_new ("I am a selectable label");
gtk_label_set_selectable (GTK_LABEL (button), TRUE);
g_object_set (button, "tooltip-markup", "Another Label tooltip", NULL);
gtk_widget_set_tooltip_markup (button, "<b>Another</b> Label tooltip");
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* Another one, with a custom tooltip window */
@ -325,7 +325,7 @@ main (int argc, char *argv[])
/* An insensitive button */
button = gtk_button_new_with_label ("This one is insensitive");
gtk_widget_set_sensitive (button, FALSE);
g_object_set (button, "tooltip-markup", "Insensitive!", NULL);
g_object_set (button, "tooltip-text", "Insensitive!", NULL);
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
/* Testcases from Kris without a tree view don't exist. */
@ -347,7 +347,7 @@ main (int argc, char *argv[])
/* Set a tooltip on the column */
column = gtk_tree_view_get_column (GTK_TREE_VIEW (tree_view), 0);
gtk_tree_view_column_set_clickable (column, TRUE);
g_object_set (column->button, "tooltip-markup", "Header", NULL);
g_object_set (column->button, "tooltip-text", "Header", NULL);
gtk_box_pack_start (GTK_BOX (box), tree_view, FALSE, FALSE, 2);