]> Pileus Git - ~andy/gtk/blob - gtk/gtklinkbutton.c
GtkLinkButton: unseal private pointer
[~andy/gtk] / gtk / gtklinkbutton.c
1 /* GTK - The GIMP Toolkit
2  * gtklinkbutton.c - an hyperlink-enabled button
3  * 
4  * Copyright (C) 2006 Emmanuele Bassi <ebassi@gmail.com>
5  * All rights reserved.
6  *
7  * Based on gnome-href code by:
8  *      James Henstridge <james@daa.com.au>
9  * 
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
23  */
24
25 #include "config.h"
26
27 #include <string.h>
28
29 #include "gtkclipboard.h"
30 #include "gtkdnd.h"
31 #include "gtkimagemenuitem.h"
32 #include "gtklabel.h"
33 #include "gtkmain.h"
34 #include "gtkmenu.h"
35 #include "gtkmenuitem.h"
36 #include "gtkstock.h"
37 #include "gtkshow.h"
38 #include "gtktooltip.h"
39
40 #include "gtklinkbutton.h"
41
42 #include "gtkintl.h"
43
44
45 struct _GtkLinkButtonPrivate
46 {
47   gchar *uri;
48
49   gboolean visited;
50
51   GtkWidget *popup_menu;
52 };
53
54 enum
55 {
56   PROP_0,
57   PROP_URI,
58   PROP_VISITED
59 };
60
61
62 static void     gtk_link_button_finalize     (GObject          *object);
63 static void     gtk_link_button_get_property (GObject          *object,
64                                               guint             prop_id,
65                                               GValue           *value,
66                                               GParamSpec       *pspec);
67 static void     gtk_link_button_set_property (GObject          *object,
68                                               guint             prop_id,
69                                               const GValue     *value,
70                                               GParamSpec       *pspec);
71 static void     gtk_link_button_add          (GtkContainer     *container,
72                                               GtkWidget        *widget);
73 static gboolean gtk_link_button_button_press (GtkWidget        *widget,
74                                               GdkEventButton   *event);
75 static void     gtk_link_button_clicked      (GtkButton        *button);
76 static gboolean gtk_link_button_popup_menu   (GtkWidget        *widget);
77 static void     gtk_link_button_style_set    (GtkWidget        *widget,
78                                               GtkStyle         *old_style);
79 static gboolean gtk_link_button_enter_cb     (GtkWidget        *widget,
80                                               GdkEventCrossing *event,
81                                               gpointer          user_data);
82 static gboolean gtk_link_button_leave_cb     (GtkWidget        *widget,
83                                               GdkEventCrossing *event,
84                                               gpointer          user_data);
85 static void gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
86                                               GdkDragContext   *context,
87                                               GtkSelectionData *selection,
88                                               guint             _info,
89                                               guint             _time,
90                                               gpointer          user_data);
91 static gboolean gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
92                                                   gint          x,
93                                                   gint          y,
94                                                   gboolean      keyboard_tip,
95                                                   GtkTooltip   *tooltip,
96                                                   gpointer      data);
97
98
99 static const GtkTargetEntry link_drop_types[] = {
100   { "text/uri-list", 0, 0 },
101   { "_NETSCAPE_URL", 0, 0 }
102 };
103
104 static const GdkColor default_link_color = { 0, 0, 0, 0xeeee };
105 static const GdkColor default_visited_link_color = { 0, 0x5555, 0x1a1a, 0x8b8b };
106
107 static GtkLinkButtonUriFunc uri_func = NULL;
108 static gpointer uri_func_data = NULL;
109 static GDestroyNotify uri_func_destroy = NULL;
110
111 G_DEFINE_TYPE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON)
112
113 static void
114 gtk_link_button_class_init (GtkLinkButtonClass *klass)
115 {
116   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
117   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
118   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
119   GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
120   
121   gobject_class->set_property = gtk_link_button_set_property;
122   gobject_class->get_property = gtk_link_button_get_property;
123   gobject_class->finalize = gtk_link_button_finalize;
124   
125   widget_class->button_press_event = gtk_link_button_button_press;
126   widget_class->popup_menu = gtk_link_button_popup_menu;
127   widget_class->style_set = gtk_link_button_style_set;
128   
129   container_class->add = gtk_link_button_add;
130
131   button_class->clicked = gtk_link_button_clicked;
132
133   /**
134    * GtkLinkButton:uri
135    * 
136    * The URI bound to this button. 
137    *
138    * Since: 2.10
139    */
140   g_object_class_install_property (gobject_class,
141                                    PROP_URI,
142                                    g_param_spec_string ("uri",
143                                                         P_("URI"),
144                                                         P_("The URI bound to this button"),
145                                                         NULL,
146                                                         G_PARAM_READWRITE));
147   /**
148    * GtkLinkButton:visited
149    * 
150    * The 'visited' state of this button. A visited link is drawn in a
151    * different color.
152    *
153    * Since: 2.14
154    */
155   g_object_class_install_property (gobject_class,
156                                    PROP_VISITED,
157                                    g_param_spec_boolean ("visited",
158                                                          P_("Visited"),
159                                                          P_("Whether this link has been visited."),
160                                                          FALSE,
161                                                          G_PARAM_READWRITE));
162   
163   g_type_class_add_private (gobject_class, sizeof (GtkLinkButtonPrivate));
164 }
165
166 static void
167 gtk_link_button_init (GtkLinkButton *link_button)
168 {
169   link_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (link_button,
170                                                    GTK_TYPE_LINK_BUTTON,
171                                                    GtkLinkButtonPrivate);
172
173   gtk_button_set_relief (GTK_BUTTON (link_button), GTK_RELIEF_NONE);
174   
175   g_signal_connect (link_button, "enter-notify-event",
176                     G_CALLBACK (gtk_link_button_enter_cb), NULL);
177   g_signal_connect (link_button, "leave-notify-event",
178                     G_CALLBACK (gtk_link_button_leave_cb), NULL);
179   g_signal_connect (link_button, "drag-data-get",
180                     G_CALLBACK (gtk_link_button_drag_data_get_cb), NULL);
181
182   g_object_set (link_button, "has-tooltip", TRUE, NULL);
183   g_signal_connect (link_button, "query-tooltip",
184                     G_CALLBACK (gtk_link_button_query_tooltip_cb), NULL);
185   
186   /* enable drag source */
187   gtk_drag_source_set (GTK_WIDGET (link_button),
188                        GDK_BUTTON1_MASK,
189                        link_drop_types, G_N_ELEMENTS (link_drop_types),
190                        GDK_ACTION_COPY);
191 }
192
193 static void
194 gtk_link_button_finalize (GObject *object)
195 {
196   GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
197   
198   g_free (link_button->priv->uri);
199   
200   G_OBJECT_CLASS (gtk_link_button_parent_class)->finalize (object);
201 }
202
203 static void
204 gtk_link_button_get_property (GObject    *object,
205                               guint       prop_id,
206                               GValue     *value,
207                               GParamSpec *pspec)
208 {
209   GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
210   
211   switch (prop_id)
212     {
213     case PROP_URI:
214       g_value_set_string (value, link_button->priv->uri);
215       break;
216     case PROP_VISITED:
217       g_value_set_boolean (value, link_button->priv->visited);
218       break;
219     default:
220       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
221       break;
222     }
223 }
224
225 static void
226 gtk_link_button_set_property (GObject      *object,
227                               guint         prop_id,
228                               const GValue *value,
229                               GParamSpec   *pspec)
230 {
231   GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
232   
233   switch (prop_id)
234     {
235     case PROP_URI:
236       gtk_link_button_set_uri (link_button, g_value_get_string (value));
237       break;
238     case PROP_VISITED:
239       gtk_link_button_set_visited (link_button, g_value_get_boolean (value));
240       break;
241     default:
242       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
243       break;
244     }
245 }
246
247 static void
248 set_link_color (GtkLinkButton *link_button)
249 {
250   GdkColor *link_color = NULL;
251   GtkWidget *label;
252
253   label = gtk_bin_get_child (GTK_BIN (link_button));
254   if (!GTK_IS_LABEL (label))
255     return;
256
257   if (link_button->priv->visited)
258     {
259       gtk_widget_style_get (GTK_WIDGET (link_button),
260                             "visited-link-color", &link_color, NULL);
261       if (!link_color)
262         link_color = (GdkColor *) &default_visited_link_color;
263     }
264   else
265     {
266       gtk_widget_style_get (GTK_WIDGET (link_button),
267                             "link-color", &link_color, NULL);
268       if (!link_color)
269         link_color = (GdkColor *) &default_link_color;
270     }
271
272   gtk_widget_modify_fg (label, GTK_STATE_NORMAL, link_color);
273   gtk_widget_modify_fg (label, GTK_STATE_ACTIVE, link_color);
274   gtk_widget_modify_fg (label, GTK_STATE_PRELIGHT, link_color);
275   gtk_widget_modify_fg (label, GTK_STATE_SELECTED, link_color);
276
277   if (link_color != &default_link_color &&
278       link_color != &default_visited_link_color)
279     gdk_color_free (link_color);
280 }
281
282 static void
283 set_link_underline (GtkLinkButton *link_button)
284 {
285   GtkWidget *label;
286   
287   label = gtk_bin_get_child (GTK_BIN (link_button));
288   if (GTK_IS_LABEL (label))
289     {
290       PangoAttrList *attributes;
291       PangoAttribute *uline;
292
293       uline = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
294       uline->start_index = 0;
295       uline->end_index = G_MAXUINT;
296       attributes = pango_attr_list_new ();
297       pango_attr_list_insert (attributes, uline); 
298       gtk_label_set_attributes (GTK_LABEL (label), attributes);
299       pango_attr_list_unref (attributes);
300     }
301 }
302
303 static void
304 gtk_link_button_add (GtkContainer *container,
305                      GtkWidget    *widget)
306 {
307   GTK_CONTAINER_CLASS (gtk_link_button_parent_class)->add (container, widget);
308
309   set_link_color (GTK_LINK_BUTTON (container));
310   set_link_underline (GTK_LINK_BUTTON (container));
311 }
312
313 static void
314 gtk_link_button_style_set (GtkWidget *widget,
315                            GtkStyle  *old_style)
316 {
317   GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
318
319   set_link_color (link_button);
320 }
321
322 static void
323 set_hand_cursor (GtkWidget *widget,
324                  gboolean   show_hand)
325 {
326   GdkDisplay *display;
327   GdkCursor *cursor;
328
329   display = gtk_widget_get_display (widget);
330
331   cursor = NULL;
332   if (show_hand)
333     cursor = gdk_cursor_new_for_display (display, GDK_HAND2);
334
335   gdk_window_set_cursor (widget->window, cursor);
336   gdk_display_flush (display);
337
338   if (cursor)
339     gdk_cursor_unref (cursor);
340 }
341
342 static void
343 popup_menu_detach (GtkWidget *attach_widget,
344                    GtkMenu   *menu)
345 {
346   GtkLinkButton *link_button = GTK_LINK_BUTTON (attach_widget);
347
348   link_button->priv->popup_menu = NULL;
349 }
350
351 static void
352 popup_position_func (GtkMenu  *menu,
353                      gint     *x,
354                      gint     *y,
355                      gboolean *push_in,
356                      gpointer  user_data)
357 {
358   GtkLinkButton *link_button = GTK_LINK_BUTTON (user_data);
359   GtkLinkButtonPrivate *priv = link_button->priv;
360   GtkWidget *widget = GTK_WIDGET (link_button);
361   GdkScreen *screen = gtk_widget_get_screen (widget);
362   GtkRequisition req;
363   gint monitor_num;
364   GdkRectangle monitor;
365   
366   g_return_if_fail (gtk_widget_get_realized (widget));
367
368   gdk_window_get_origin (widget->window, x, y);
369
370   gtk_widget_size_request (priv->popup_menu, &req);
371
372   *x += widget->allocation.width / 2;
373   *y += widget->allocation.height;
374
375   monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
376   gtk_menu_set_monitor (menu, monitor_num);
377   gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
378
379   *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
380   *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
381
382   *push_in = FALSE;
383 }
384
385 static void
386 copy_activate_cb (GtkWidget     *widget,
387                   GtkLinkButton *link_button)
388 {
389   GtkLinkButtonPrivate *priv = link_button->priv;
390   
391   gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (link_button),
392                                                     GDK_SELECTION_CLIPBOARD),
393                           priv->uri, -1);
394 }
395
396 static void
397 gtk_link_button_do_popup (GtkLinkButton  *link_button,
398                           GdkEventButton *event)
399 {
400   GtkLinkButtonPrivate *priv = link_button->priv;
401   gint button;
402   guint time;
403   
404   if (event)
405     {
406       button = event->button;
407       time = event->time;
408     }
409   else
410     {
411       button = 0;
412       time = gtk_get_current_event_time ();
413     }
414
415   if (gtk_widget_get_realized (GTK_WIDGET (link_button)))
416     {
417       GtkWidget *menu_item;
418       
419       if (priv->popup_menu)
420         gtk_widget_destroy (priv->popup_menu);
421
422       priv->popup_menu = gtk_menu_new ();
423       
424       gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
425                                  GTK_WIDGET (link_button),
426                                  popup_menu_detach);
427
428       menu_item = gtk_image_menu_item_new_with_mnemonic (_("Copy URL"));
429       gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item),
430                                      gtk_image_new_from_stock (GTK_STOCK_COPY,
431                                                                GTK_ICON_SIZE_MENU));
432       g_signal_connect (menu_item, "activate",
433                         G_CALLBACK (copy_activate_cb), link_button);
434       gtk_widget_show (menu_item);
435       gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menu_item);
436       
437       if (button)
438         gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
439                         NULL, NULL,
440                         button, time);
441       else
442         {
443           gtk_menu_popup (GTK_MENU (priv->popup_menu), NULL, NULL,
444                           popup_position_func, link_button,
445                           button, time);
446           gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->popup_menu), FALSE);
447         }
448     }
449 }
450
451 static gboolean
452 gtk_link_button_button_press (GtkWidget      *widget,
453                               GdkEventButton *event)
454 {
455   if (!gtk_widget_has_focus (widget))
456     gtk_widget_grab_focus (widget);
457
458   if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS))
459     {
460       gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event);
461       
462       return TRUE;
463     }
464
465   if (GTK_WIDGET_CLASS (gtk_link_button_parent_class)->button_press_event)
466     return GTK_WIDGET_CLASS (gtk_link_button_parent_class)->button_press_event (widget, event);
467   
468   return FALSE;
469 }
470
471 static void
472 gtk_link_button_clicked (GtkButton *button)
473 {
474   GtkLinkButton *link_button = GTK_LINK_BUTTON (button);
475
476   if (uri_func)
477     (* uri_func) (link_button, link_button->priv->uri, uri_func_data);
478   else
479     {
480       GdkScreen *screen;
481       GError *error;
482
483       if (gtk_widget_has_screen (GTK_WIDGET (button)))
484         screen = gtk_widget_get_screen (GTK_WIDGET (button));
485       else
486         screen = NULL;
487
488       error = NULL;
489       gtk_show_uri (screen, link_button->priv->uri, GDK_CURRENT_TIME, &error);
490       if (error)
491         {
492           g_warning ("Unable to show '%s': %s",
493                      link_button->priv->uri,
494                      error->message);
495           g_error_free (error);
496         }
497     }
498
499   gtk_link_button_set_visited (link_button, TRUE);
500 }
501
502 static gboolean
503 gtk_link_button_popup_menu (GtkWidget *widget)
504 {
505   gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), NULL);
506
507   return TRUE; 
508 }
509
510 static gboolean
511 gtk_link_button_enter_cb (GtkWidget        *widget,
512                           GdkEventCrossing *crossing,
513                           gpointer          user_data)
514 {
515   set_hand_cursor (widget, TRUE);
516   
517   return FALSE;
518 }
519
520 static gboolean
521 gtk_link_button_leave_cb (GtkWidget        *widget,
522                           GdkEventCrossing *crossing,
523                           gpointer          user_data)
524 {
525   set_hand_cursor (widget, FALSE);
526   
527   return FALSE;
528 }
529
530 static void
531 gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
532                                   GdkDragContext   *context,
533                                   GtkSelectionData *selection,
534                                   guint             _info,
535                                   guint             _time,
536                                   gpointer          user_data)
537 {
538   GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
539   gchar *uri;
540   
541   uri = g_strdup_printf ("%s\r\n", link_button->priv->uri);
542   gtk_selection_data_set (selection,
543                           selection->target,
544                           8,
545                           (guchar *) uri,
546                           strlen (uri));
547   
548   g_free (uri);
549 }
550
551 /**
552  * gtk_link_button_new:
553  * @uri: a valid URI
554  *
555  * Creates a new #GtkLinkButton with the URI as its text.
556  *
557  * Return value: a new link button widget.
558  *
559  * Since: 2.10
560  */
561 GtkWidget *
562 gtk_link_button_new (const gchar *uri)
563 {
564   gchar *utf8_uri = NULL;
565   GtkWidget *retval;
566   
567   g_return_val_if_fail (uri != NULL, NULL);
568   
569   if (g_utf8_validate (uri, -1, NULL))
570     {
571       utf8_uri = g_strdup (uri);
572     }
573   else
574     {
575       GError *conv_err = NULL;
576     
577       utf8_uri = g_locale_to_utf8 (uri, -1, NULL, NULL, &conv_err);
578       if (conv_err)
579         {
580           g_warning ("Attempting to convert URI `%s' to UTF-8, but failed "
581                      "with error: %s\n",
582                      uri,
583                      conv_err->message);
584           g_error_free (conv_err);
585         
586           utf8_uri = g_strdup (_("Invalid URI"));
587         }
588     }
589   
590   retval = g_object_new (GTK_TYPE_LINK_BUTTON,
591                          "label", utf8_uri,
592                          "uri", uri,
593                          NULL);
594   
595   g_free (utf8_uri);
596   
597   return retval;
598 }
599
600 /**
601  * gtk_link_button_new_with_label:
602  * @uri: a valid URI
603  * @label: (allow-none): the text of the button
604  *
605  * Creates a new #GtkLinkButton containing a label.
606  *
607  * Return value: (transfer none): a new link button widget.
608  *
609  * Since: 2.10
610  */
611 GtkWidget *
612 gtk_link_button_new_with_label (const gchar *uri,
613                                 const gchar *label)
614 {
615   GtkWidget *retval;
616   
617   g_return_val_if_fail (uri != NULL, NULL);
618   
619   if (!label)
620     return gtk_link_button_new (uri);
621
622   retval = g_object_new (GTK_TYPE_LINK_BUTTON,
623                          "label", label,
624                          "uri", uri,
625                          NULL);
626
627   return retval;
628 }
629
630 static gboolean 
631 gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
632                                   gint          x,
633                                   gint          y,
634                                   gboolean      keyboard_tip,
635                                   GtkTooltip   *tooltip,
636                                   gpointer      data)
637 {
638   GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
639   const gchar *label, *uri;
640
641   label = gtk_button_get_label (GTK_BUTTON (link_button));
642   uri = link_button->priv->uri;
643
644   if (!gtk_widget_get_tooltip_text (widget)
645     && !gtk_widget_get_tooltip_markup (widget)
646     && label && *label != '\0' && uri && strcmp (label, uri) != 0)
647     {
648       gtk_tooltip_set_text (tooltip, uri);
649       return TRUE;
650     }
651
652   return FALSE;
653 }
654
655
656 /**
657  * gtk_link_button_set_uri:
658  * @link_button: a #GtkLinkButton
659  * @uri: a valid URI
660  *
661  * Sets @uri as the URI where the #GtkLinkButton points. As a side-effect
662  * this unsets the 'visited' state of the button.
663  *
664  * Since: 2.10
665  */
666 void
667 gtk_link_button_set_uri (GtkLinkButton *link_button,
668                          const gchar   *uri)
669 {
670   GtkLinkButtonPrivate *priv;
671
672   g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
673   g_return_if_fail (uri != NULL);
674
675   priv = link_button->priv;
676
677   g_free (priv->uri);
678   priv->uri = g_strdup (uri);
679
680   g_object_notify (G_OBJECT (link_button), "uri");
681
682   gtk_link_button_set_visited (link_button, FALSE);
683 }
684
685 /**
686  * gtk_link_button_get_uri:
687  * @link_button: a #GtkLinkButton
688  *
689  * Retrieves the URI set using gtk_link_button_set_uri().
690  *
691  * Return value: a valid URI.  The returned string is owned by the link button
692  *   and should not be modified or freed.
693  *
694  * Since: 2.10
695  */
696 G_CONST_RETURN gchar *
697 gtk_link_button_get_uri (GtkLinkButton *link_button)
698 {
699   g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), NULL);
700   
701   return link_button->priv->uri;
702 }
703
704 /**
705  * gtk_link_button_set_uri_hook:
706  * @func: (allow-none): a function called each time a #GtkLinkButton is clicked, or %NULL
707  * @data: (allow-none): user data to be passed to @func, or %NULL
708  * @destroy: (allow-none): a #GDestroyNotify that gets called when @data is no longer needed, or %NULL
709  *
710  * Sets @func as the function that should be invoked every time a user clicks
711  * a #GtkLinkButton. This function is called before every callback registered
712  * for the "clicked" signal.
713  *
714  * If no uri hook has been set, GTK+ defaults to calling gtk_show_uri().
715  *
716  * Return value: the previously set hook function.
717  *
718  * Since: 2.10
719  */
720 GtkLinkButtonUriFunc
721 gtk_link_button_set_uri_hook (GtkLinkButtonUriFunc func,
722                               gpointer             data,
723                               GDestroyNotify       destroy)
724 {
725   GtkLinkButtonUriFunc old_uri_func;
726
727   if (uri_func_destroy)
728     (* uri_func_destroy) (uri_func_data);
729
730   old_uri_func = uri_func;
731
732   uri_func = func;
733   uri_func_data = data;
734   uri_func_destroy = destroy;
735
736   return old_uri_func;
737 }
738
739 /**
740  * gtk_link_button_set_visited:
741  * @link_button: a #GtkLinkButton
742  * @visited: the new 'visited' state
743  *
744  * Sets the 'visited' state of the URI where the #GtkLinkButton
745  * points.  See gtk_link_button_get_visited() for more details.
746  *
747  * Since: 2.14
748  */
749 void
750 gtk_link_button_set_visited (GtkLinkButton *link_button,
751                              gboolean       visited)
752 {
753   g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
754
755   visited = visited != FALSE;
756
757   if (link_button->priv->visited != visited)
758     {
759       link_button->priv->visited = visited;
760
761       set_link_color (link_button);
762
763       g_object_notify (G_OBJECT (link_button), "visited");
764     }
765 }
766
767 /**
768  * gtk_link_button_get_visited:
769  * @link_button: a #GtkLinkButton
770  *
771  * Retrieves the 'visited' state of the URI where the #GtkLinkButton
772  * points. The button becomes visited when it is clicked. If the URI
773  * is changed on the button, the 'visited' state is unset again.
774  *
775  * The state may also be changed using gtk_link_button_set_visited().
776  *
777  * Return value: %TRUE if the link has been visited, %FALSE otherwise
778  *
779  * Since: 2.14
780  */
781 gboolean
782 gtk_link_button_get_visited (GtkLinkButton *link_button)
783 {
784   g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), FALSE);
785   
786   return link_button->priv->visited;
787 }