gtk+ r19596 - in trunk: . gtk



Author: matthiasc
Date: Sat Feb 16 05:28:22 2008
New Revision: 19596
URL: http://svn.gnome.org/viewvc/gtk+?rev=19596&view=rev

Log:
2008-02-16  Matthias Clasen  <mclasen redhat com>

        * gtk/gtklinkbutton.c: Show the URI in a tooltip.  (#505480,
        Teppo Turtiainen)



Modified:
   trunk/ChangeLog
   trunk/gtk/gtklinkbutton.c

Modified: trunk/gtk/gtklinkbutton.c
==============================================================================
--- trunk/gtk/gtklinkbutton.c	(original)
+++ trunk/gtk/gtklinkbutton.c	Sat Feb 16 05:28:22 2008
@@ -38,6 +38,7 @@
 #include "gtkmenu.h"
 #include "gtkmenuitem.h"
 #include "gtkstock.h"
+#include "gtktooltip.h"
 
 #include "gtklinkbutton.h"
 
@@ -92,6 +93,12 @@
 					      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 @@
   		    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 @@
     }
   
   retval = g_object_new (GTK_TYPE_LINK_BUTTON,
-  			 "uri", uri,
   			 "label", utf8_uri,
+  			 "uri", uri,
   			 NULL);
   
   g_free (utf8_uri);
@@ -577,6 +587,30 @@
   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 @@
 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");
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]