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