2008-07-01 22:57:50 +00:00
|
|
|
/* GTK - The GIMP Toolkit
|
2019-08-25 12:52:24 +00:00
|
|
|
* gtklinkbutton.c - a hyperlink-enabled button
|
2011-01-04 22:32:12 +00:00
|
|
|
*
|
2006-01-24 03:35:53 +00:00
|
|
|
* Copyright (C) 2006 Emmanuele Bassi <ebassi@gmail.com>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Based on gnome-href code by:
|
2011-01-04 22:32:12 +00:00
|
|
|
* James Henstridge <james@daa.com.au>
|
|
|
|
*
|
2006-01-24 03:35:53 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2006-01-24 03:35:53 +00:00
|
|
|
*/
|
|
|
|
|
2010-09-24 17:41:29 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtklinkbutton
|
|
|
|
* @Title: GtkLinkButton
|
|
|
|
* @Short_description: Create buttons bound to a URL
|
|
|
|
* @See_also: #GtkButton
|
|
|
|
*
|
|
|
|
* A GtkLinkButton is a #GtkButton with a hyperlink, similar to the one
|
|
|
|
* used by web browsers, which triggers an action when clicked. It is useful
|
|
|
|
* to show quick links to resources.
|
|
|
|
*
|
|
|
|
* A link button is created by calling either gtk_link_button_new() or
|
|
|
|
* gtk_link_button_new_with_label(). If using the former, the URI you pass
|
|
|
|
* to the constructor is used as a label for the widget.
|
|
|
|
*
|
|
|
|
* The URI bound to a GtkLinkButton can be set specifically using
|
|
|
|
* gtk_link_button_set_uri(), and retrieved using gtk_link_button_get_uri().
|
|
|
|
*
|
2020-04-12 01:58:19 +00:00
|
|
|
* By default, GtkLinkButton calls gtk_show_uri() when the button is
|
2010-09-24 17:41:29 +00:00
|
|
|
* clicked. This behaviour can be overridden by connecting to the
|
2010-10-14 14:22:19 +00:00
|
|
|
* #GtkLinkButton::activate-link signal and returning %TRUE from the
|
|
|
|
* signal handler.
|
2015-10-30 04:50:48 +00:00
|
|
|
*
|
|
|
|
* # CSS nodes
|
|
|
|
*
|
|
|
|
* GtkLinkButton has a single CSS node with name button. To differentiate
|
|
|
|
* it from a plain #GtkButton, it gets the .link style class.
|
2020-07-30 00:26:16 +00:00
|
|
|
*
|
|
|
|
* # Accessibility
|
|
|
|
*
|
2020-10-22 01:54:17 +00:00
|
|
|
* GtkLinkButton uses the #GTK_ACCESSIBLE_ROLE_LINK role.
|
2010-09-24 17:41:29 +00:00
|
|
|
*/
|
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2010-09-14 01:33:06 +00:00
|
|
|
#include "gtklinkbutton.h"
|
|
|
|
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtkdragsource.h"
|
2019-05-29 17:10:46 +00:00
|
|
|
#include "gtkgestureclick.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtkgesturesingle.h"
|
|
|
|
#include "gtkintl.h"
|
2006-01-24 03:35:53 +00:00
|
|
|
#include "gtklabel.h"
|
2011-10-23 11:57:07 +00:00
|
|
|
#include "gtkmain.h"
|
2010-10-14 14:22:19 +00:00
|
|
|
#include "gtkmarshalers.h"
|
2019-06-12 01:34:19 +00:00
|
|
|
#include "gtkpopovermenu.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtkprivate.h"
|
2008-12-08 02:47:21 +00:00
|
|
|
#include "gtkshow.h"
|
2018-02-08 23:42:38 +00:00
|
|
|
#include "gtksizerequest.h"
|
2008-02-16 05:28:22 +00:00
|
|
|
#include "gtktooltip.h"
|
2017-05-09 14:53:45 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2006-01-24 03:35:53 +00:00
|
|
|
|
2018-02-08 23:42:38 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2019-05-19 21:05:40 +00:00
|
|
|
typedef struct _GtkLinkButtonClass GtkLinkButtonClass;
|
|
|
|
|
|
|
|
struct _GtkLinkButton
|
|
|
|
{
|
|
|
|
/*< private >*/
|
|
|
|
GtkButton parent_instance;
|
2020-04-26 19:31:14 +00:00
|
|
|
|
|
|
|
char *uri;
|
|
|
|
gboolean visited;
|
|
|
|
GtkWidget *popup_menu;
|
2019-05-19 21:05:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkLinkButtonClass
|
|
|
|
{
|
|
|
|
/*< private >*/
|
|
|
|
GtkButtonClass parent_class;
|
|
|
|
|
|
|
|
/*< public >*/
|
|
|
|
gboolean (* activate_link) (GtkLinkButton *button);
|
|
|
|
};
|
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2008-08-07 11:37:57 +00:00
|
|
|
PROP_URI,
|
|
|
|
PROP_VISITED
|
2006-01-24 03:35:53 +00:00
|
|
|
};
|
|
|
|
|
2010-10-14 14:22:19 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ACTIVATE_LINK,
|
|
|
|
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
2006-01-24 03:35:53 +00:00
|
|
|
|
|
|
|
static void gtk_link_button_finalize (GObject *object);
|
|
|
|
static void gtk_link_button_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_link_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_link_button_clicked (GtkButton *button);
|
2020-03-16 02:25:09 +00:00
|
|
|
static void gtk_link_button_popup_menu (GtkWidget *widget,
|
|
|
|
const char *action_name,
|
|
|
|
GVariant *parameters);
|
2008-02-16 05:28:22 +00:00
|
|
|
static gboolean gtk_link_button_query_tooltip_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2008-02-16 05:28:22 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data);
|
2019-05-29 17:10:46 +00:00
|
|
|
static void gtk_link_button_pressed_cb (GtkGestureClick *gesture,
|
2016-12-02 11:22:41 +00:00
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer user_data);
|
|
|
|
|
2010-10-14 14:22:19 +00:00
|
|
|
static gboolean gtk_link_button_activate_link (GtkLinkButton *link_button);
|
2006-01-24 03:35:53 +00:00
|
|
|
|
2017-11-16 23:28:53 +00:00
|
|
|
static const char *link_drop_types[] = {
|
|
|
|
"text/uri-list",
|
|
|
|
"_NETSCAPE_URL"
|
2006-01-24 03:35:53 +00:00
|
|
|
};
|
|
|
|
|
2010-10-14 14:22:19 +00:00
|
|
|
static guint link_signals[LAST_SIGNAL] = { 0, };
|
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
G_DEFINE_TYPE (GtkLinkButton, gtk_link_button, GTK_TYPE_BUTTON)
|
2006-01-24 03:35:53 +00:00
|
|
|
|
2019-06-15 02:25:46 +00:00
|
|
|
static void
|
|
|
|
gtk_link_button_activate_clipboard_copy (GtkWidget *widget,
|
|
|
|
const char *name,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
|
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
gdk_clipboard_set_text (gtk_widget_get_clipboard (widget), link_button->uri);
|
2019-06-15 02:25:46 +00:00
|
|
|
}
|
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
static void
|
|
|
|
gtk_link_button_class_init (GtkLinkButtonClass *klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
|
2015-07-05 17:31:28 +00:00
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
gobject_class->set_property = gtk_link_button_set_property;
|
|
|
|
gobject_class->get_property = gtk_link_button_get_property;
|
|
|
|
gobject_class->finalize = gtk_link_button_finalize;
|
2015-07-05 17:31:28 +00:00
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
button_class->clicked = gtk_link_button_clicked;
|
|
|
|
|
2010-10-14 14:22:19 +00:00
|
|
|
klass->activate_link = gtk_link_button_activate_link;
|
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
* GtkLinkButton:uri:
|
|
|
|
*
|
|
|
|
* The URI bound to this button.
|
2006-01-24 03:35:53 +00:00
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
2014-06-09 13:04:33 +00:00
|
|
|
PROP_URI,
|
|
|
|
g_param_spec_string ("uri",
|
|
|
|
P_("URI"),
|
|
|
|
P_("The URI bound to this button"),
|
|
|
|
NULL,
|
|
|
|
GTK_PARAM_READWRITE));
|
|
|
|
|
2008-08-07 11:37:57 +00:00
|
|
|
/**
|
2012-04-13 00:07:28 +00:00
|
|
|
* GtkLinkButton:visited:
|
|
|
|
*
|
2008-08-07 11:37:57 +00:00
|
|
|
* The 'visited' state of this button. A visited link is drawn in a
|
|
|
|
* different color.
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (gobject_class,
|
2014-06-09 13:04:33 +00:00
|
|
|
PROP_VISITED,
|
|
|
|
g_param_spec_boolean ("visited",
|
2008-08-07 11:37:57 +00:00
|
|
|
P_("Visited"),
|
|
|
|
P_("Whether this link has been visited."),
|
|
|
|
FALSE,
|
2014-06-09 13:04:33 +00:00
|
|
|
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
|
2010-10-14 14:22:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* GtkLinkButton::activate-link:
|
|
|
|
* @button: the #GtkLinkButton that emitted the signal
|
|
|
|
*
|
|
|
|
* The ::activate-link signal is emitted each time the #GtkLinkButton
|
|
|
|
* has been clicked.
|
|
|
|
*
|
2020-04-12 01:58:19 +00:00
|
|
|
* The default handler will call gtk_show_uri() with the URI stored inside
|
2010-10-14 14:22:19 +00:00
|
|
|
* the #GtkLinkButton:uri property.
|
|
|
|
*
|
|
|
|
* To override the default behavior, you can connect to the ::activate-link
|
|
|
|
* signal and stop the propagation of the signal by returning %TRUE from
|
|
|
|
* your handler.
|
|
|
|
*/
|
|
|
|
link_signals[ACTIVATE_LINK] =
|
|
|
|
g_signal_new (I_("activate-link"),
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST,
|
|
|
|
G_STRUCT_OFFSET (GtkLinkButtonClass, activate_link),
|
|
|
|
_gtk_boolean_handled_accumulator, NULL,
|
|
|
|
_gtk_marshal_BOOLEAN__VOID,
|
|
|
|
G_TYPE_BOOLEAN, 0);
|
2011-06-27 03:48:54 +00:00
|
|
|
|
2017-11-18 03:49:57 +00:00
|
|
|
gtk_widget_class_set_css_name (widget_class, I_("button"));
|
2020-10-22 01:54:17 +00:00
|
|
|
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_LINK);
|
2019-06-12 01:34:19 +00:00
|
|
|
|
2020-04-11 03:59:21 +00:00
|
|
|
/**
|
|
|
|
* GtkLinkButton|clipboard.copy:
|
|
|
|
*
|
|
|
|
* Copies the url to the clipboard.
|
|
|
|
*/
|
2019-06-22 18:24:46 +00:00
|
|
|
gtk_widget_class_install_action (widget_class, "clipboard.copy", NULL,
|
2019-06-15 02:25:46 +00:00
|
|
|
gtk_link_button_activate_clipboard_copy);
|
2020-03-16 02:25:09 +00:00
|
|
|
|
2020-04-11 03:59:21 +00:00
|
|
|
/**
|
|
|
|
* GtkLinkButton|menu.popup:
|
|
|
|
*
|
|
|
|
* Opens the context menu.
|
|
|
|
*/
|
2020-03-16 02:25:09 +00:00
|
|
|
gtk_widget_class_install_action (widget_class, "menu.popup", NULL, gtk_link_button_popup_menu);
|
|
|
|
|
|
|
|
gtk_widget_class_add_binding_action (widget_class,
|
|
|
|
GDK_KEY_F10, GDK_SHIFT_MASK,
|
|
|
|
"menu.popup",
|
|
|
|
NULL);
|
|
|
|
gtk_widget_class_add_binding_action (widget_class,
|
|
|
|
GDK_KEY_Menu, 0,
|
|
|
|
"menu.popup",
|
|
|
|
NULL);
|
2019-06-12 01:34:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GMenuModel *
|
|
|
|
gtk_link_button_get_menu_model (void)
|
|
|
|
{
|
|
|
|
GMenu *menu, *section;
|
|
|
|
|
|
|
|
menu = g_menu_new ();
|
|
|
|
|
|
|
|
section = g_menu_new ();
|
2019-08-25 12:22:46 +00:00
|
|
|
g_menu_append (section, _("_Copy URL"), "clipboard.copy");
|
2019-06-12 01:34:19 +00:00
|
|
|
g_menu_append_section (menu, NULL, G_MENU_MODEL (section));
|
|
|
|
g_object_unref (section);
|
|
|
|
|
|
|
|
return G_MENU_MODEL (menu);
|
|
|
|
}
|
|
|
|
|
2019-12-31 03:34:50 +00:00
|
|
|
#define GTK_TYPE_LINK_CONTENT (gtk_link_content_get_type ())
|
|
|
|
#define GTK_LINK_CONTENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_LINK_CONTENT, GtkLinkContent))
|
|
|
|
|
|
|
|
typedef struct _GtkLinkContent GtkLinkContent;
|
|
|
|
typedef struct _GtkLinkContentClass GtkLinkContentClass;
|
|
|
|
|
|
|
|
struct _GtkLinkContent
|
|
|
|
{
|
|
|
|
GdkContentProvider parent;
|
|
|
|
GtkLinkButton *link;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GtkLinkContentClass
|
|
|
|
{
|
|
|
|
GdkContentProviderClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
GType gtk_link_content_get_type (void) G_GNUC_CONST;
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GtkLinkContent, gtk_link_content, GDK_TYPE_CONTENT_PROVIDER)
|
|
|
|
|
|
|
|
static GdkContentFormats *
|
|
|
|
gtk_link_content_ref_formats (GdkContentProvider *provider)
|
|
|
|
{
|
|
|
|
GtkLinkContent *content = GTK_LINK_CONTENT (provider);
|
|
|
|
|
|
|
|
if (content->link)
|
|
|
|
return gdk_content_formats_union (gdk_content_formats_new_for_gtype (G_TYPE_STRING),
|
|
|
|
gdk_content_formats_new (link_drop_types, G_N_ELEMENTS (link_drop_types)));
|
|
|
|
else
|
|
|
|
return gdk_content_formats_new (NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_link_content_get_value (GdkContentProvider *provider,
|
|
|
|
GValue *value,
|
|
|
|
GError **error)
|
|
|
|
{
|
|
|
|
GtkLinkContent *content = GTK_LINK_CONTENT (provider);
|
|
|
|
|
|
|
|
if (G_VALUE_HOLDS (value, G_TYPE_STRING) &&
|
|
|
|
content->link != NULL)
|
|
|
|
{
|
|
|
|
char *uri;
|
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
uri = g_strdup_printf ("%s\r\n", content->link->uri);
|
2019-12-31 03:34:50 +00:00
|
|
|
g_value_set_string (value, uri);
|
|
|
|
g_free (uri);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GDK_CONTENT_PROVIDER_CLASS (gtk_link_content_parent_class)->get_value (provider, value, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_link_content_class_init (GtkLinkContentClass *class)
|
|
|
|
{
|
|
|
|
GdkContentProviderClass *provider_class = GDK_CONTENT_PROVIDER_CLASS (class);
|
|
|
|
|
|
|
|
provider_class->ref_formats = gtk_link_content_ref_formats;
|
|
|
|
provider_class->get_value = gtk_link_content_get_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_link_content_init (GtkLinkContent *content)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
static void
|
|
|
|
gtk_link_button_init (GtkLinkButton *link_button)
|
|
|
|
{
|
2018-03-09 05:14:59 +00:00
|
|
|
GtkGesture *gesture;
|
2019-12-31 03:34:50 +00:00
|
|
|
GdkContentProvider *content;
|
|
|
|
GtkDragSource *source;
|
2015-10-30 04:50:48 +00:00
|
|
|
|
2020-04-17 04:20:09 +00:00
|
|
|
gtk_button_set_has_frame (GTK_BUTTON (link_button), FALSE);
|
2013-10-08 10:50:08 +00:00
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
|
2019-08-25 12:30:33 +00:00
|
|
|
gtk_widget_set_has_tooltip (GTK_WIDGET (link_button), TRUE);
|
2013-10-08 10:50:08 +00:00
|
|
|
|
2008-02-16 05:28:22 +00:00
|
|
|
g_signal_connect (link_button, "query-tooltip",
|
|
|
|
G_CALLBACK (gtk_link_button_query_tooltip_cb), NULL);
|
2013-10-08 10:50:08 +00:00
|
|
|
|
2020-01-06 19:46:14 +00:00
|
|
|
source = gtk_drag_source_new ();
|
2019-12-31 03:34:50 +00:00
|
|
|
content = g_object_new (GTK_TYPE_LINK_CONTENT, NULL);
|
|
|
|
GTK_LINK_CONTENT (content)->link = link_button;
|
2020-01-06 19:46:14 +00:00
|
|
|
gtk_drag_source_set_content (source, content);
|
2019-12-31 03:34:50 +00:00
|
|
|
g_object_unref (content);
|
2020-01-07 06:08:11 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (link_button), GTK_EVENT_CONTROLLER (source));
|
2015-10-30 04:50:48 +00:00
|
|
|
|
2019-05-29 17:10:46 +00:00
|
|
|
gesture = gtk_gesture_click_new ();
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (gesture), FALSE);
|
|
|
|
gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
|
|
|
|
gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_BUBBLE);
|
|
|
|
g_signal_connect (gesture, "pressed", G_CALLBACK (gtk_link_button_pressed_cb),
|
2016-12-02 11:22:41 +00:00
|
|
|
link_button);
|
2018-03-09 05:14:59 +00:00
|
|
|
gtk_widget_add_controller (GTK_WIDGET (link_button), GTK_EVENT_CONTROLLER (gesture));
|
2016-12-02 11:22:41 +00:00
|
|
|
|
2020-02-06 16:32:26 +00:00
|
|
|
gtk_widget_add_css_class (GTK_WIDGET (link_button), "link");
|
2017-07-25 13:46:01 +00:00
|
|
|
|
2018-01-19 12:21:41 +00:00
|
|
|
gtk_widget_set_cursor_from_name (GTK_WIDGET (link_button), "pointer");
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_link_button_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
|
2018-03-07 13:02:19 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
g_free (link_button->uri);
|
2019-06-12 01:34:19 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
g_clear_pointer (&link_button->popup_menu, gtk_widget_unparent);
|
2019-06-12 01:34:19 +00:00
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
G_OBJECT_CLASS (gtk_link_button_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_link_button_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_URI:
|
2020-04-26 19:31:14 +00:00
|
|
|
g_value_set_string (value, link_button->uri);
|
2006-01-24 03:35:53 +00:00
|
|
|
break;
|
2008-08-07 11:37:57 +00:00
|
|
|
case PROP_VISITED:
|
2020-04-26 19:31:14 +00:00
|
|
|
g_value_set_boolean (value, link_button->visited);
|
2008-08-07 11:37:57 +00:00
|
|
|
break;
|
2006-01-24 03:35:53 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_link_button_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkLinkButton *link_button = GTK_LINK_BUTTON (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_URI:
|
|
|
|
gtk_link_button_set_uri (link_button, g_value_get_string (value));
|
|
|
|
break;
|
2008-08-07 11:37:57 +00:00
|
|
|
case PROP_VISITED:
|
|
|
|
gtk_link_button_set_visited (link_button, g_value_get_boolean (value));
|
|
|
|
break;
|
2006-01-24 03:35:53 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-12 01:34:19 +00:00
|
|
|
gtk_link_button_do_popup (GtkLinkButton *link_button,
|
|
|
|
double x,
|
|
|
|
double y)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
2020-04-26 19:31:14 +00:00
|
|
|
if (!link_button->popup_menu)
|
2019-06-12 01:34:19 +00:00
|
|
|
{
|
|
|
|
GMenuModel *model;
|
|
|
|
|
|
|
|
model = gtk_link_button_get_menu_model ();
|
2020-04-26 19:31:14 +00:00
|
|
|
link_button->popup_menu = gtk_popover_menu_new_from_model (model);
|
|
|
|
gtk_widget_set_parent (link_button->popup_menu, GTK_WIDGET (link_button));
|
|
|
|
gtk_popover_set_position (GTK_POPOVER (link_button->popup_menu), GTK_POS_BOTTOM);
|
2019-06-12 01:34:19 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
gtk_popover_set_has_arrow (GTK_POPOVER (link_button->popup_menu), FALSE);
|
|
|
|
gtk_widget_set_halign (link_button->popup_menu, GTK_ALIGN_START);
|
2019-06-12 01:34:19 +00:00
|
|
|
|
|
|
|
g_object_unref (model);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (x != -1 && y != -1)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
2019-06-12 01:34:19 +00:00
|
|
|
GdkRectangle rect = { x, y, 1, 1 };
|
2020-04-26 19:31:14 +00:00
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (link_button->popup_menu), &rect);
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
2019-06-12 01:34:19 +00:00
|
|
|
else
|
2020-04-26 19:31:14 +00:00
|
|
|
gtk_popover_set_pointing_to (GTK_POPOVER (link_button->popup_menu), NULL);
|
2019-06-12 01:34:19 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
gtk_popover_popup (GTK_POPOVER (link_button->popup_menu));
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 11:22:41 +00:00
|
|
|
static void
|
2019-05-29 17:10:46 +00:00
|
|
|
gtk_link_button_pressed_cb (GtkGestureClick *gesture,
|
|
|
|
int n_press,
|
|
|
|
double x,
|
|
|
|
double y,
|
|
|
|
gpointer user_data)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
2016-12-02 11:22:41 +00:00
|
|
|
GtkLinkButton *link_button = user_data;
|
|
|
|
GdkEventSequence *sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
|
2020-02-16 16:09:02 +00:00
|
|
|
GdkEvent *event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
|
2006-01-24 03:35:53 +00:00
|
|
|
|
2016-12-02 11:22:41 +00:00
|
|
|
if (!gtk_widget_has_focus (GTK_WIDGET (link_button)))
|
|
|
|
gtk_widget_grab_focus (GTK_WIDGET (link_button));
|
2011-09-27 13:37:28 +00:00
|
|
|
|
2016-12-02 11:22:41 +00:00
|
|
|
if (gdk_event_triggers_context_menu (event) &&
|
2020-04-26 19:31:14 +00:00
|
|
|
link_button->uri != NULL)
|
2016-12-02 11:22:41 +00:00
|
|
|
{
|
2019-06-12 01:34:19 +00:00
|
|
|
gtk_link_button_do_popup (link_button, x, y);
|
2016-12-02 11:22:41 +00:00
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED);
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-14 14:22:19 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_link_button_activate_link (GtkLinkButton *link_button)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
2016-07-13 15:23:47 +00:00
|
|
|
GtkWidget *toplevel;
|
2006-01-24 03:35:53 +00:00
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (GTK_WIDGET (link_button)));
|
2008-12-08 02:39:28 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
gtk_show_uri (GTK_WINDOW (toplevel), link_button->uri, GDK_CURRENT_TIME);
|
2008-08-07 11:37:57 +00:00
|
|
|
gtk_link_button_set_visited (link_button, TRUE);
|
2010-10-14 14:22:19 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_link_button_clicked (GtkButton *button)
|
|
|
|
{
|
|
|
|
gboolean retval = FALSE;
|
|
|
|
|
|
|
|
g_signal_emit (button, link_signals[ACTIVATE_LINK], 0, &retval);
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 02:25:09 +00:00
|
|
|
static void
|
|
|
|
gtk_link_button_popup_menu (GtkWidget *widget,
|
|
|
|
const char *action_name,
|
|
|
|
GVariant *parameters)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
2019-06-12 01:34:19 +00:00
|
|
|
gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), -1, -1);
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_link_button_new:
|
|
|
|
* @uri: a valid URI
|
|
|
|
*
|
|
|
|
* Creates a new #GtkLinkButton with the URI as its text.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: a new link button widget.
|
2006-01-24 03:35:53 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_link_button_new (const char *uri)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *utf8_uri = NULL;
|
2006-01-24 03:35:53 +00:00
|
|
|
GtkWidget *retval;
|
|
|
|
|
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
|
|
|
|
|
|
|
if (g_utf8_validate (uri, -1, NULL))
|
|
|
|
{
|
|
|
|
utf8_uri = g_strdup (uri);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GError *conv_err = NULL;
|
|
|
|
|
|
|
|
utf8_uri = g_locale_to_utf8 (uri, -1, NULL, NULL, &conv_err);
|
|
|
|
if (conv_err)
|
|
|
|
{
|
2015-09-20 06:32:48 +00:00
|
|
|
g_warning ("Attempting to convert URI '%s' to UTF-8, but failed "
|
2016-02-28 16:06:25 +00:00
|
|
|
"with error: %s",
|
2006-01-24 03:35:53 +00:00
|
|
|
uri,
|
|
|
|
conv_err->message);
|
|
|
|
g_error_free (conv_err);
|
|
|
|
|
|
|
|
utf8_uri = g_strdup (_("Invalid URI"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = g_object_new (GTK_TYPE_LINK_BUTTON,
|
2008-02-11 09:55:29 +00:00
|
|
|
"label", utf8_uri,
|
2008-02-16 05:28:22 +00:00
|
|
|
"uri", uri,
|
2006-01-24 03:35:53 +00:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_free (utf8_uri);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_link_button_new_with_label:
|
|
|
|
* @uri: a valid URI
|
2009-12-10 10:23:40 +00:00
|
|
|
* @label: (allow-none): the text of the button
|
2006-01-24 03:35:53 +00:00
|
|
|
*
|
|
|
|
* Creates a new #GtkLinkButton containing a label.
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: (transfer none): a new link button widget.
|
2006-01-24 03:35:53 +00:00
|
|
|
*/
|
|
|
|
GtkWidget *
|
2020-07-24 18:40:36 +00:00
|
|
|
gtk_link_button_new_with_label (const char *uri,
|
|
|
|
const char *label)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
|
|
|
GtkWidget *retval;
|
|
|
|
|
2006-04-01 00:25:00 +00:00
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
2006-01-24 03:35:53 +00:00
|
|
|
|
|
|
|
if (!label)
|
|
|
|
return gtk_link_button_new (uri);
|
|
|
|
|
|
|
|
retval = g_object_new (GTK_TYPE_LINK_BUTTON,
|
|
|
|
"label", label,
|
|
|
|
"uri", uri,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2008-02-16 05:28:22 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_link_button_query_tooltip_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2008-02-16 05:28:22 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GtkLinkButton *link_button = GTK_LINK_BUTTON (widget);
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *label, *uri;
|
2020-04-22 18:32:17 +00:00
|
|
|
const char *text, *markup;
|
2008-02-16 05:28:22 +00:00
|
|
|
|
|
|
|
label = gtk_button_get_label (GTK_BUTTON (link_button));
|
2020-04-26 19:31:14 +00:00
|
|
|
uri = link_button->uri;
|
2017-05-05 05:22:27 +00:00
|
|
|
text = gtk_widget_get_tooltip_text (widget);
|
|
|
|
markup = gtk_widget_get_tooltip_markup (widget);
|
2008-02-16 05:28:22 +00:00
|
|
|
|
2017-05-05 05:22:27 +00:00
|
|
|
if (text == NULL &&
|
|
|
|
markup == NULL &&
|
|
|
|
label && *label != '\0' && uri && strcmp (label, uri) != 0)
|
2008-02-16 05:28:22 +00:00
|
|
|
{
|
|
|
|
gtk_tooltip_set_text (tooltip, uri);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-10-08 10:50:08 +00:00
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
/**
|
|
|
|
* gtk_link_button_set_uri:
|
|
|
|
* @link_button: a #GtkLinkButton
|
|
|
|
* @uri: a valid URI
|
|
|
|
*
|
2008-08-07 11:37:57 +00:00
|
|
|
* Sets @uri as the URI where the #GtkLinkButton points. As a side-effect
|
2014-02-07 19:03:49 +00:00
|
|
|
* this unsets the “visited” state of the button.
|
2006-01-24 03:35:53 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_link_button_set_uri (GtkLinkButton *link_button,
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *uri)
|
2006-01-24 03:35:53 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
|
|
|
|
g_return_if_fail (uri != NULL);
|
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
g_free (link_button->uri);
|
|
|
|
link_button->uri = g_strdup (uri);
|
2008-02-16 05:28:22 +00:00
|
|
|
|
2006-01-24 03:35:53 +00:00
|
|
|
g_object_notify (G_OBJECT (link_button), "uri");
|
2008-08-07 11:37:57 +00:00
|
|
|
|
|
|
|
gtk_link_button_set_visited (link_button, FALSE);
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_link_button_get_uri:
|
|
|
|
* @link_button: a #GtkLinkButton
|
|
|
|
*
|
|
|
|
* Retrieves the URI set using gtk_link_button_set_uri().
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: a valid URI. The returned string is owned by the link button
|
2006-01-24 03:35:53 +00:00
|
|
|
* and should not be modified or freed.
|
|
|
|
*/
|
2020-07-24 18:40:36 +00:00
|
|
|
const char *
|
2006-01-24 03:35:53 +00:00
|
|
|
gtk_link_button_get_uri (GtkLinkButton *link_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), NULL);
|
2018-03-07 13:02:19 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
return link_button->uri;
|
2006-01-24 03:35:53 +00:00
|
|
|
}
|
|
|
|
|
2008-08-07 11:37:57 +00:00
|
|
|
/**
|
|
|
|
* gtk_link_button_set_visited:
|
|
|
|
* @link_button: a #GtkLinkButton
|
2014-02-07 19:03:49 +00:00
|
|
|
* @visited: the new “visited” state
|
2008-08-07 11:37:57 +00:00
|
|
|
*
|
2014-02-07 19:03:49 +00:00
|
|
|
* Sets the “visited” state of the URI where the #GtkLinkButton
|
2008-08-07 11:37:57 +00:00
|
|
|
* points. See gtk_link_button_get_visited() for more details.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_link_button_set_visited (GtkLinkButton *link_button,
|
|
|
|
gboolean visited)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_LINK_BUTTON (link_button));
|
|
|
|
|
|
|
|
visited = visited != FALSE;
|
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
if (link_button->visited != visited)
|
2008-08-07 11:37:57 +00:00
|
|
|
{
|
2020-04-26 19:31:14 +00:00
|
|
|
link_button->visited = visited;
|
2008-08-07 11:37:57 +00:00
|
|
|
|
2013-10-08 10:50:08 +00:00
|
|
|
if (visited)
|
|
|
|
{
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK);
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_VISITED, FALSE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_unset_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_VISITED);
|
|
|
|
gtk_widget_set_state_flags (GTK_WIDGET (link_button), GTK_STATE_FLAG_LINK, FALSE);
|
|
|
|
}
|
2008-08-07 11:37:57 +00:00
|
|
|
|
|
|
|
g_object_notify (G_OBJECT (link_button), "visited");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_link_button_get_visited:
|
|
|
|
* @link_button: a #GtkLinkButton
|
|
|
|
*
|
2014-02-07 19:03:49 +00:00
|
|
|
* Retrieves the “visited” state of the URI where the #GtkLinkButton
|
2008-08-07 11:37:57 +00:00
|
|
|
* points. The button becomes visited when it is clicked. If the URI
|
2014-02-07 19:03:49 +00:00
|
|
|
* is changed on the button, the “visited” state is unset again.
|
2008-08-07 11:37:57 +00:00
|
|
|
*
|
|
|
|
* The state may also be changed using gtk_link_button_set_visited().
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
* Returns: %TRUE if the link has been visited, %FALSE otherwise
|
2008-08-07 11:37:57 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gtk_link_button_get_visited (GtkLinkButton *link_button)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_LINK_BUTTON (link_button), FALSE);
|
2018-03-07 13:02:19 +00:00
|
|
|
|
2020-04-26 19:31:14 +00:00
|
|
|
return link_button->visited;
|
2008-08-07 11:37:57 +00:00
|
|
|
}
|