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