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