2009-05-11 05:23:13 +00:00
|
|
|
/* Links
|
|
|
|
*
|
|
|
|
* GtkLabel can show hyperlinks. The default action is to call
|
2017-02-16 00:24:57 +00:00
|
|
|
* gtk_show_uri_on_window() on their URI, but it is possible to override
|
2009-05-11 05:23:13 +00:00
|
|
|
* this with a custom handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
static void
|
|
|
|
response_cb (GtkWidget *dialog,
|
|
|
|
gint response_id,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy (dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2009-05-11 06:44:12 +00:00
|
|
|
activate_link (GtkWidget *label,
|
|
|
|
const gchar *uri,
|
|
|
|
gpointer data)
|
2009-05-11 05:23:13 +00:00
|
|
|
{
|
|
|
|
if (g_strcmp0 (uri, "keynav") == 0)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *parent;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
parent = GTK_WIDGET (gtk_widget_get_root (label));
|
2009-05-11 05:23:13 +00:00
|
|
|
dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (parent),
|
|
|
|
GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
"The term <i>keynav</i> is a shorthand for "
|
|
|
|
"keyboard navigation and refers to the process of using "
|
|
|
|
"a program (exclusively) via keyboard input.");
|
2014-04-13 05:13:40 +00:00
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
|
|
|
gtk_window_present (GTK_WINDOW (dialog));
|
|
|
|
g_signal_connect (dialog, "response", G_CALLBACK (response_cb), NULL);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_links (GtkWidget *do_widget)
|
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
2009-05-11 05:23:13 +00:00
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2009-08-31 05:08:31 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Links");
|
2009-05-11 05:23:13 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
2011-09-02 03:55:47 +00:00
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
|
|
|
label = gtk_label_new ("Some <a href=\"http://en.wikipedia.org/wiki/Text\""
|
|
|
|
"title=\"plain text\">text</a> may be marked up\n"
|
|
|
|
"as hyperlinks, which can be clicked\n"
|
2012-01-06 01:04:01 +00:00
|
|
|
"or activated via <a href=\"keynav\">keynav</a>\n"
|
|
|
|
"and they work fine with other markup, like when\n"
|
|
|
|
"searching on <a href=\"http://www.google.com/\">"
|
|
|
|
"<span color=\"#0266C8\">G</span><span color=\"#F90101\">o</span>"
|
|
|
|
"<span color=\"#F2B50F\">o</span><span color=\"#0266C8\">g</span>"
|
|
|
|
"<span color=\"#00933B\">l</span><span color=\"#F90101\">e</span>"
|
|
|
|
"</a>.");
|
2009-05-11 05:23:13 +00:00
|
|
|
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
|
|
|
|
g_signal_connect (label, "activate-link", G_CALLBACK (activate_link), NULL);
|
|
|
|
gtk_container_add (GTK_CONTAINER (window), label);
|
|
|
|
gtk_widget_show (label);
|
|
|
|
}
|
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_show (window);
|
2009-05-11 05:23:13 +00:00
|
|
|
else
|
2015-06-28 13:23:28 +00:00
|
|
|
gtk_widget_destroy (window);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|