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, see <http://www.gnu.org/licenses/>.
22  */
23 
24 /**
25  * SECTION:gtklinkbutton
26  * @Title: GtkLinkButton
27  * @Short_description: Create buttons bound to a URL
28  * @See_also: #GtkButton
29  *
30  * A GtkLinkButton is a #GtkButton with a hyperlink, similar to the one
31  * used by web browsers, which triggers an action when clicked. It is useful
32  * to show quick links to resources.
33  *
34  * A link button is created by calling either gtk_link_button_new() or
35  * gtk_link_button_new_with_label(). If using the former, the URI you pass
36  * to the constructor is used as a label for the widget.
37  *
38  * The URI bound to a GtkLinkButton can be set specifically using
39  * gtk_link_button_set_uri(), and retrieved using gtk_link_button_get_uri().
40  *
41  * By default, GtkLinkButton calls gtk_show_uri_on_window() when the button is
42  * clicked. This behaviour can be overridden by connecting to the
43  * #GtkLinkButton::activate-link signal and returning %TRUE from the
44  * signal handler.
45  *
46  * # CSS nodes
47  *
48  * GtkLinkButton has a single CSS node with name button. To differentiate
49  * it from a plain #GtkButton, it gets the .link style class.
50  */
51 
52 #include "config.h"
53 
54 #include "gtklinkbutton.h"
55 
56 #include <string.h>
57 
58 #include "gtkclipboard.h"
59 #include "gtkdnd.h"
60 #include "gtklabel.h"
61 #include "gtkmain.h"
62 #include "gtkmarshalers.h"
63 #include "gtkmenu.h"
64 #include "gtkmenuitem.h"
65 #include "gtksizerequest.h"
66 #include "gtkshow.h"
67 #include "gtktooltip.h"
68 #include "gtkprivate.h"
69 #include "gtkintl.h"
70 #include "gtktextutil.h"
71 
72 #include "a11y/gtklinkbuttonaccessible.h"
73 
74 struct _GtkLinkButtonPrivate
75 {
76   gchar *uri;
77 
78   gboolean visited;
79 
80   GtkWidget *popup_menu;
81 };
82 
83 enum
84 {
85   PROP_0,
86   PROP_URI,
87   PROP_VISITED
88 };
89 
90 enum
91 {
92   ACTIVATE_LINK,
93 
94   LAST_SIGNAL
95 };
96 
97 static void     gtk_link_button_finalize     (GObject          *object);
98 static void     gtk_link_button_get_property (GObject          *object,
99 					      guint             prop_id,
100 					      GValue           *value,
101 					      GParamSpec       *pspec);
102 static void     gtk_link_button_set_property (GObject          *object,
103 					      guint             prop_id,
104 					      const GValue     *value,
105 					      GParamSpec       *pspec);
106 static gboolean gtk_link_button_button_press (GtkWidget        *widget,
107 					      GdkEventButton   *event);
108 static void     gtk_link_button_clicked      (GtkButton        *button);
109 static gboolean gtk_link_button_popup_menu   (GtkWidget        *widget);
110 static void     gtk_link_button_realize      (GtkWidget        *widget);
111 static void     gtk_link_button_unrealize    (GtkWidget        *widget);
112 static void     gtk_link_button_drag_begin   (GtkWidget        *widget,
113                                               GdkDragContext   *context);
114 static void gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
115 					      GdkDragContext   *context,
116 					      GtkSelectionData *selection,
117 					      guint             _info,
118 					      guint             _time,
119 					      gpointer          user_data);
120 static gboolean gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
121                                                   gint          x,
122                                                   gint          y,
123                                                   gboolean      keyboard_tip,
124                                                   GtkTooltip   *tooltip,
125                                                   gpointer      data);
126 static gboolean gtk_link_button_activate_link (GtkLinkButton *link_button);
127 
128 static const GtkTargetEntry link_drop_types[] = {
129   { "text/uri-list", 0, 0 },
130   { "_NETSCAPE_URL", 0, 0 }
131 };
132 
133 static guint link_signals[LAST_SIGNAL] = { 0, };
134 
G_DEFINE_TYPE_WITH_PRIVATE(GtkLinkButton,gtk_link_button,GTK_TYPE_BUTTON)135 G_DEFINE_TYPE_WITH_PRIVATE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON)
136 
137 static void
138 gtk_link_button_class_init (GtkLinkButtonClass *klass)
139 {
140   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
141   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
142   GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
143 
144   gobject_class->set_property = gtk_link_button_set_property;
145   gobject_class->get_property = gtk_link_button_get_property;
146   gobject_class->finalize = gtk_link_button_finalize;
147 
148   widget_class->button_press_event = gtk_link_button_button_press;
149   widget_class->popup_menu = gtk_link_button_popup_menu;
150   widget_class->realize = gtk_link_button_realize;
151   widget_class->unrealize = gtk_link_button_unrealize;
152   widget_class->drag_begin = gtk_link_button_drag_begin;
153 
154   button_class->clicked = gtk_link_button_clicked;
155 
156   klass->activate_link = gtk_link_button_activate_link;
157 
158   /**
159    * GtkLinkButton:uri:
160    *
161    * The URI bound to this button.
162    *
163    * Since: 2.10
164    */
165   g_object_class_install_property (gobject_class,
166                                    PROP_URI,
167                                    g_param_spec_string ("uri",
168                                                         P_("URI"),
169                                                         P_("The URI bound to this button"),
170                                                         NULL,
171                                                         GTK_PARAM_READWRITE));
172 
173   /**
174    * GtkLinkButton:visited:
175    *
176    * The 'visited' state of this button. A visited link is drawn in a
177    * different color.
178    *
179    * Since: 2.14
180    */
181   g_object_class_install_property (gobject_class,
182                                    PROP_VISITED,
183                                    g_param_spec_boolean ("visited",
184                                                          P_("Visited"),
185                                                          P_("Whether this link has been visited."),
186                                                          FALSE,
187                                                          GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
188 
189   /**
190    * GtkLinkButton::activate-link:
191    * @button: the #GtkLinkButton that emitted the signal
192    *
193    * The ::activate-link signal is emitted each time the #GtkLinkButton
194    * has been clicked.
195    *
196    * The default handler will call gtk_show_uri_on_window() with the URI stored inside
197    * the #GtkLinkButton:uri property.
198    *
199    * To override the default behavior, you can connect to the ::activate-link
200    * signal and stop the propagation of the signal by returning %TRUE from
201    * your handler.
202    */
203   link_signals[ACTIVATE_LINK] =
204     g_signal_new (I_("activate-link"),
205                   G_TYPE_FROM_CLASS (klass),
206                   G_SIGNAL_RUN_LAST,
207                   G_STRUCT_OFFSET (GtkLinkButtonClass, activate_link),
208                   _gtk_boolean_handled_accumulator, NULL,
209                   _gtk_marshal_BOOLEAN__VOID,
210                   G_TYPE_BOOLEAN, 0);
211 
212   gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_LINK_BUTTON_ACCESSIBLE);
213   gtk_widget_class_set_css_name (widget_class, "button");
214 }
215 
216 static void
gtk_link_button_init(GtkLinkButton * link_button)217 gtk_link_button_init (GtkLinkButton *link_button)
218 {
219   GtkStyleContext *context;
220 
221   link_button->priv = gtk_link_button_get_instance_private (link_button);
222 
223   gtk_button_set_relief (GTK_BUTTON (link_button), GTK_RELIEF_NONE);
224   gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
225 
226   g_signal_connect (link_button, "drag-data-get",
227   		    G_CALLBACK (gtk_link_button_drag_data_get_cb), NULL);
228 
229   g_object_set (link_button, "has-tooltip", TRUE, NULL);
230   g_signal_connect (link_button, "query-tooltip",
231                     G_CALLBACK (gtk_link_button_query_tooltip_cb), NULL);
232 
233   /* enable drag source */
234   gtk_drag_source_set (GTK_WIDGET (link_button),
235   		       GDK_BUTTON1_MASK,
236   		       link_drop_types, G_N_ELEMENTS (link_drop_types),
237   		       GDK_ACTION_COPY);
238 
239   context = gtk_widget_get_style_context (GTK_WIDGET (link_button));
240   gtk_style_context_add_class (context, "link");
241 }
242 
243 static void
gtk_link_button_finalize(GObject * object)244 gtk_link_button_finalize (GObject *object)
245 {
246   GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
247 
248   g_free (link_button->priv->uri);
249 
250   G_OBJECT_CLASS (gtk_link_button_parent_class)->finalize (object);
251 }
252 
253 static void
gtk_link_button_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)254 gtk_link_button_get_property (GObject    *object,
255 			      guint       prop_id,
256 			      GValue     *value,
257 			      GParamSpec *pspec)
258 {
259   GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
260 
261   switch (prop_id)
262     {
263     case PROP_URI:
264       g_value_set_string (value, link_button->priv->uri);
265       break;
266     case PROP_VISITED:
267       g_value_set_boolean (value, link_button->priv->visited);
268       break;
269     default:
270       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
271       break;
272     }
273 }
274 
275 static void
gtk_link_button_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)276 gtk_link_button_set_property (GObject      *object,
277 			      guint         prop_id,
278 			      const GValue *value,
279 			      GParamSpec   *pspec)
280 {
281   GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
282 
283   switch (prop_id)
284     {
285     case PROP_URI:
286       gtk_link_button_set_uri (link_button, g_value_get_string (value));
287       break;
288     case PROP_VISITED:
289       gtk_link_button_set_visited (link_button, g_value_get_boolean (value));
290       break;
291     default:
292       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
293       break;
294     }
295 }
296 
297 static void
set_hand_cursor(GtkWidget * widget,gboolean show_hand)298 set_hand_cursor (GtkWidget *widget,
299 		 gboolean   show_hand)
300 {
301   GdkDisplay *display;
302   GdkCursor *cursor;
303 
304   display = gtk_widget_get_display (widget);
305 
306   cursor = NULL;
307   if (show_hand)
308     cursor = gdk_cursor_new_from_name (display, "pointer");
309 
310   gdk_window_set_cursor (gtk_button_get_event_window (GTK_BUTTON (widget)), cursor);
311   gdk_display_flush (display);
312 
313   if (cursor)
314     g_object_unref (cursor);
315 }
316 
317 static void
gtk_link_button_realize(GtkWidget * widget)318 gtk_link_button_realize (GtkWidget *widget)
319 {
320   GTK_WIDGET_CLASS (gtk_link_button_parent_class)->realize (widget);
321 
322   set_hand_cursor (widget, TRUE);
323 }
324 
325 static void
gtk_link_button_unrealize(GtkWidget * widget)326 gtk_link_button_unrealize (GtkWidget *widget)
327 {
328   set_hand_cursor (widget, FALSE);
329 
330   GTK_WIDGET_CLASS (gtk_link_button_parent_class)->unrealize (widget);
331 }
332 
333 static void
popup_menu_detach(GtkWidget * attach_widget,GtkMenu * menu)334 popup_menu_detach (GtkWidget *attach_widget,
335 		   GtkMenu   *menu)
336 {
337   GtkLinkButton *link_button = GTK_LINK_BUTTON (attach_widget);
338 
339   link_button->priv->popup_menu = NULL;
340 }
341 
342 static void
copy_activate_cb(GtkWidget * widget,GtkLinkButton * link_button)343 copy_activate_cb (GtkWidget     *widget,
344 		  GtkLinkButton *link_button)
345 {
346   GtkLinkButtonPrivate *priv = link_button->priv;
347 
348   gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (link_button),
349 			  			    GDK_SELECTION_CLIPBOARD),
350 		  	  priv->uri, -1);
351 }
352 
353 static void
gtk_link_button_do_popup(GtkLinkButton * link_button,const GdkEvent * event)354 gtk_link_button_do_popup (GtkLinkButton  *link_button,
355                           const GdkEvent *event)
356 {
357   GtkLinkButtonPrivate *priv = link_button->priv;
358 
359   if (gtk_widget_get_realized (GTK_WIDGET (link_button)))
360     {
361       GtkWidget *menu_item;
362 
363       if (priv->popup_menu)
364 	gtk_widget_destroy (priv->popup_menu);
365 
366       priv->popup_menu = gtk_menu_new ();
367       gtk_style_context_add_class (gtk_widget_get_style_context (priv->popup_menu),
368                                    GTK_STYLE_CLASS_CONTEXT_MENU);
369 
370       gtk_menu_attach_to_widget (GTK_MENU (priv->popup_menu),
371 		      		 GTK_WIDGET (link_button),
372 				 popup_menu_detach);
373 
374       menu_item = gtk_menu_item_new_with_mnemonic (_("Copy URL"));
375       g_signal_connect (menu_item, "activate",
376 		        G_CALLBACK (copy_activate_cb), link_button);
377       gtk_widget_show (menu_item);
378       gtk_menu_shell_append (GTK_MENU_SHELL (priv->popup_menu), menu_item);
379 
380       if (event && gdk_event_triggers_context_menu (event))
381         gtk_menu_popup_at_pointer (GTK_MENU (priv->popup_menu), event);
382       else
383         {
384           gtk_menu_popup_at_widget (GTK_MENU (priv->popup_menu),
385                                     GTK_WIDGET (link_button),
386                                     GDK_GRAVITY_SOUTH,
387                                     GDK_GRAVITY_NORTH_WEST,
388                                     event);
389 
390           gtk_menu_shell_select_first (GTK_MENU_SHELL (priv->popup_menu), FALSE);
391         }
392     }
393 }
394 
395 static gboolean
gtk_link_button_button_press(GtkWidget * widget,GdkEventButton * event)396 gtk_link_button_button_press (GtkWidget      *widget,
397 			      GdkEventButton *event)
398 {
399   if (!gtk_widget_has_focus (widget))
400     gtk_widget_grab_focus (widget);
401 
402   /* Don't popup the menu if there's no URI set,
403    * otherwise the menu item will trigger a warning */
404   if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
405       GTK_LINK_BUTTON (widget)->priv->uri != NULL)
406     {
407       gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), (GdkEvent *) event);
408 
409       return TRUE;
410     }
411 
412   if (GTK_WIDGET_CLASS (gtk_link_button_parent_class)->button_press_event)
413     return GTK_WIDGET_CLASS (gtk_link_button_parent_class)->button_press_event (widget, event);
414 
415   return FALSE;
416 }
417 
418 static gboolean
gtk_link_button_activate_link(GtkLinkButton * link_button)419 gtk_link_button_activate_link (GtkLinkButton *link_button)
420 {
421   GtkWidget *toplevel;
422   GError *error;
423 
424   toplevel = gtk_widget_get_toplevel (GTK_WIDGET (link_button));
425 
426   error = NULL;
427   gtk_show_uri_on_window (GTK_WINDOW (toplevel), link_button->priv->uri, GDK_CURRENT_TIME, &error);
428   if (error)
429     {
430       g_warning ("Unable to show '%s': %s",
431                  link_button->priv->uri,
432                  error->message);
433       g_error_free (error);
434 
435       return FALSE;
436     }
437 
438   gtk_link_button_set_visited (link_button, TRUE);
439 
440   return TRUE;
441 }
442 
443 static void
gtk_link_button_clicked(GtkButton * button)444 gtk_link_button_clicked (GtkButton *button)
445 {
446   gboolean retval = FALSE;
447 
448   g_signal_emit (button, link_signals[ACTIVATE_LINK], 0, &retval);
449 }
450 
451 static gboolean
gtk_link_button_popup_menu(GtkWidget * widget)452 gtk_link_button_popup_menu (GtkWidget *widget)
453 {
454   gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), NULL);
455 
456   return TRUE;
457 }
458 
459 static void
gtk_link_button_drag_begin(GtkWidget * widget,GdkDragContext * context)460 gtk_link_button_drag_begin (GtkWidget      *widget,
461                             GdkDragContext *context)
462 {
463   gtk_drag_set_icon_name (context, "text-x-generic", 0, 0);
464 }
465 
466 static void
gtk_link_button_drag_data_get_cb(GtkWidget * widget,GdkDragContext * context,GtkSelectionData * selection,guint _info,guint _time,gpointer user_data)467 gtk_link_button_drag_data_get_cb (GtkWidget        *widget,
468 				  GdkDragContext   *context,
469 				  GtkSelectionData *selection,
470 				  guint             _info,
471 				  guint             _time,
472 				  gpointer          user_data)
473 {
474   GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
475   gchar *uri;
476 
477   uri = g_strdup_printf ("%s\r\n", link_button->priv->uri);
478   gtk_selection_data_set (selection,
479                           gtk_selection_data_get_target (selection),
480   			  8,
481   			  (guchar *) uri,
482 			  strlen (uri));
483 
484   g_free (uri);
485 }
486 
487 /**
488  * gtk_link_button_new:
489  * @uri: a valid URI
490  *
491  * Creates a new #GtkLinkButton with the URI as its text.
492  *
493  * Returns: a new link button widget.
494  *
495  * Since: 2.10
496  */
497 GtkWidget *
gtk_link_button_new(const gchar * uri)498 gtk_link_button_new (const gchar *uri)
499 {
500   gchar *utf8_uri = NULL;
501   GtkWidget *retval;
502 
503   g_return_val_if_fail (uri != NULL, NULL);
504 
505   if (g_utf8_validate (uri, -1, NULL))
506     {
507       utf8_uri = g_strdup (uri);
508     }
509   else
510     {
511       GError *conv_err = NULL;
512 
513       utf8_uri = g_locale_to_utf8 (uri, -1, NULL, NULL, &conv_err);
514       if (conv_err)
515         {
516           g_warning ("Attempting to convert URI '%s' to UTF-8, but failed "
517                      "with error: %s",
518                      uri,
519                      conv_err->message);
520           g_error_free (conv_err);
521 
522           utf8_uri = g_strdup (_("Invalid URI"));
523         }
524     }
525 
526   retval = g_object_new (GTK_TYPE_LINK_BUTTON,
527   			 "label", utf8_uri,
528   			 "uri", uri,
529   			 NULL);
530 
531   g_free (utf8_uri);
532 
533   return retval;
534 }
535 
536 /**
537  * gtk_link_button_new_with_label:
538  * @uri: a valid URI
539  * @label: (allow-none): the text of the button
540  *
541  * Creates a new #GtkLinkButton containing a label.
542  *
543  * Returns: (transfer none): a new link button widget.
544  *
545  * Since: 2.10
546  */
547 GtkWidget *
gtk_link_button_new_with_label(const gchar * uri,const gchar * label)548 gtk_link_button_new_with_label (const gchar *uri,
549 				const gchar *label)
550 {
551   GtkWidget *retval;
552 
553   g_return_val_if_fail (uri != NULL, NULL);
554 
555   if (!label)
556     return gtk_link_button_new (uri);
557 
558   retval = g_object_new (GTK_TYPE_LINK_BUTTON,
559 		         "label", label,
560 			 "uri", uri,
561 			 NULL);
562 
563   return retval;
564 }
565 
566 static gboolean
gtk_link_button_query_tooltip_cb(GtkWidget * widget,gint x,gint y,gboolean keyboard_tip,GtkTooltip * tooltip,gpointer data)567 gtk_link_button_query_tooltip_cb (GtkWidget    *widget,
568                                   gint          x,
569                                   gint          y,
570                                   gboolean      keyboard_tip,
571                                   GtkTooltip   *tooltip,
572                                   gpointer      data)
573 {
574   GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
575   const gchar *label, *uri;
576   gchar *text, *markup;
577 
578   label = gtk_button_get_label (GTK_BUTTON (link_button));
579   uri = link_button->priv->uri;
580   text = gtk_widget_get_tooltip_text (widget);
581   markup = gtk_widget_get_tooltip_markup (widget);
582 
583   if (text == NULL &&
584       markup == NULL &&
585       label && *label != '\0' && uri && strcmp (label, uri) != 0)
586     {
587       gtk_tooltip_set_text (tooltip, uri);
588       return TRUE;
589     }
590 
591   g_free (text);
592   g_free (markup);
593 
594   return FALSE;
595 }
596 
597 
598 
599 /**
600  * gtk_link_button_set_uri:
601  * @link_button: a #GtkLinkButton
602  * @uri: a valid URI
603  *
604  * Sets @uri as the URI where the #GtkLinkButton points. As a side-effect
605  * this unsets the “visited” state of the button.
606  *
607  * Since: 2.10
608  */
609 void
gtk_link_button_set_uri(GtkLinkButton * link_button,const gchar * uri)610 gtk_link_button_set_uri (GtkLinkButton *link_button,
611 			 const gchar   *uri)
612 {
613   GtkLinkButtonPrivate *priv;
614 
615   g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
616   g_return_if_fail (uri != NULL);
617 
618   priv = link_button->priv;
619 
620   g_free (priv->uri);
621   priv->uri = g_strdup (uri);
622 
623   g_object_notify (G_OBJECT (link_button), "uri");
624 
625   gtk_link_button_set_visited (link_button, FALSE);
626 }
627 
628 /**
629  * gtk_link_button_get_uri:
630  * @link_button: a #GtkLinkButton
631  *
632  * Retrieves the URI set using gtk_link_button_set_uri().
633  *
634  * Returns: a valid URI.  The returned string is owned by the link button
635  *   and should not be modified or freed.
636  *
637  * Since: 2.10
638  */
639 const gchar *
gtk_link_button_get_uri(GtkLinkButton * link_button)640 gtk_link_button_get_uri (GtkLinkButton *link_button)
641 {
642   g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), NULL);
643 
644   return link_button->priv->uri;
645 }
646 
647 /**
648  * gtk_link_button_set_visited:
649  * @link_button: a #GtkLinkButton
650  * @visited: the new “visited” state
651  *
652  * Sets the “visited” state of the URI where the #GtkLinkButton
653  * points.  See gtk_link_button_get_visited() for more details.
654  *
655  * Since: 2.14
656  */
657 void
gtk_link_button_set_visited(GtkLinkButton * link_button,gboolean visited)658 gtk_link_button_set_visited (GtkLinkButton *link_button,
659                              gboolean       visited)
660 {
661   g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
662 
663   visited = visited != FALSE;
664 
665   if (link_button->priv->visited != visited)
666     {
667       link_button->priv->visited = visited;
668 
669       if (visited)
670         {
671           gtk_widget_unset_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK);
672           gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_VISITED, FALSE);
673         }
674       else
675         {
676           gtk_widget_unset_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_VISITED);
677           gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
678         }
679 
680       g_object_notify (G_OBJECT (link_button), "visited");
681     }
682 }
683 
684 /**
685  * gtk_link_button_get_visited:
686  * @link_button: a #GtkLinkButton
687  *
688  * Retrieves the “visited” state of the URI where the #GtkLinkButton
689  * points. The button becomes visited when it is clicked. If the URI
690  * is changed on the button, the “visited” state is unset again.
691  *
692  * The state may also be changed using gtk_link_button_set_visited().
693  *
694  * Returns: %TRUE if the link has been visited, %FALSE otherwise
695  *
696  * Since: 2.14
697  */
698 gboolean
gtk_link_button_get_visited(GtkLinkButton * link_button)699 gtk_link_button_get_visited (GtkLinkButton *link_button)
700 {
701   g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), FALSE);
702 
703   return link_button->priv->visited;
704 }
705