summaryrefslogtreecommitdiff
path: root/gtk/gtklinkbutton.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2008-02-16 05:28:22 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2008-02-16 05:28:22 +0000
commit311cdbb34633280dc64633f1d516c4b3240f832e (patch)
treeee378c91752e61610c2d496c1364cc4e116ee57f /gtk/gtklinkbutton.c
parent580ae3106df4343da3af311c8838006a2b2883e0 (diff)
downloadgtk+-311cdbb34633280dc64633f1d516c4b3240f832e.tar.gz
Show the URI in a tooltip. (#505480, Teppo Turtiainen)
2008-02-16 Matthias Clasen <mclasen@redhat.com> * gtk/gtklinkbutton.c: Show the URI in a tooltip. (#505480, Teppo Turtiainen) svn path=/trunk/; revision=19596
Diffstat (limited to 'gtk/gtklinkbutton.c')
-rw-r--r--gtk/gtklinkbutton.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index 927b9b6f1f..751f915960 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -38,6 +38,7 @@
#include "gtkmenu.h"
#include "gtkmenuitem.h"
#include "gtkstock.h"
+#include "gtktooltip.h"
#include "gtklinkbutton.h"
@@ -92,6 +93,12 @@ static void gtk_link_button_drag_data_get_cb (GtkWidget *widget,
guint _info,
guint _time,
gpointer user_data);
+static gboolean gtk_link_button_query_tooltip_cb (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ gpointer data);
static const GtkTargetEntry link_drop_types[] = {
@@ -159,6 +166,9 @@ gtk_link_button_init (GtkLinkButton *link_button)
G_CALLBACK (gtk_link_button_leave_cb), NULL);
g_signal_connect (link_button, "drag_data_get",
G_CALLBACK (gtk_link_button_drag_data_get_cb), NULL);
+ g_object_set (link_button, "has-tooltip", TRUE, NULL);
+ g_signal_connect (link_button, "query-tooltip",
+ G_CALLBACK (gtk_link_button_query_tooltip_cb), NULL);
/* enable drag source */
gtk_drag_source_set (GTK_WIDGET (link_button),
@@ -538,8 +548,8 @@ gtk_link_button_new (const gchar *uri)
}
retval = g_object_new (GTK_TYPE_LINK_BUTTON,
- "uri", uri,
"label", utf8_uri,
+ "uri", uri,
NULL);
g_free (utf8_uri);
@@ -577,6 +587,30 @@ gtk_link_button_new_with_label (const gchar *uri,
return retval;
}
+static gboolean
+gtk_link_button_query_tooltip_cb (GtkWidget *widget,
+ gint x,
+ gint y,
+ gboolean keyboard_tip,
+ GtkTooltip *tooltip,
+ gpointer data)
+{
+ GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
+ const gchar *label, *uri;
+
+ label = gtk_button_get_label (GTK_BUTTON (link_button));
+ uri = link_button->priv->uri;
+
+ if (label && *label != '\0' && uri && strcmp (label, uri) != 0)
+ {
+ gtk_tooltip_set_text (tooltip, uri);
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+
/**
* gtk_link_button_set_uri:
* @link_button: a #GtkLinkButton
@@ -590,17 +624,18 @@ void
gtk_link_button_set_uri (GtkLinkButton *link_button,
const gchar *uri)
{
- gchar *tmp;
+ GtkLinkButtonPrivate *priv;
g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
g_return_if_fail (uri != NULL);
-
- tmp = link_button->priv->uri;
- link_button->priv->uri = g_strdup (uri);
- g_free (tmp);
- link_button->priv->visited = FALSE;
-
+ priv = link_button->priv;
+
+ g_free (priv->uri);
+ priv->uri = g_strdup (uri);
+
+ priv->visited = FALSE;
+
g_object_notify (G_OBJECT (link_button), "uri");
}