2009-05-11 05:23:13 +00:00
|
|
|
|
/* Links
|
|
|
|
|
*
|
|
|
|
|
* GtkLabel can show hyperlinks. The default action is to call
|
2020-04-26 03:33:33 +00:00
|
|
|
|
* gtk_show_uri() 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 gboolean
|
2022-10-28 15:38:57 +00:00
|
|
|
|
activate_link (GtkWidget *label,
|
2020-07-24 18:40:36 +00:00
|
|
|
|
const char *uri,
|
2022-10-28 15:38:57 +00:00
|
|
|
|
gpointer data)
|
2009-05-11 05:23:13 +00:00
|
|
|
|
{
|
|
|
|
|
if (g_strcmp0 (uri, "keynav") == 0)
|
|
|
|
|
{
|
2022-10-28 15:38:57 +00:00
|
|
|
|
GtkAlertDialog *dialog;
|
|
|
|
|
|
|
|
|
|
dialog = gtk_alert_dialog_new ("Keyboard navigation");
|
|
|
|
|
gtk_alert_dialog_set_detail (dialog,
|
|
|
|
|
"The term ‘keynav’ is a shorthand for "
|
|
|
|
|
"keyboard navigation and refers to the process of using "
|
|
|
|
|
"a program (exclusively) via keyboard input.");
|
|
|
|
|
gtk_alert_dialog_show (dialog, GTK_WINDOW (gtk_widget_get_root (label)));
|
|
|
|
|
g_object_unref (dialog);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2020-02-14 19:55:36 +00:00
|
|
|
|
window = gtk_window_new ();
|
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");
|
2020-04-26 03:33:33 +00:00
|
|
|
|
gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
|
2020-05-09 16:03:11 +00:00
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
|
|
|
|
|
label = gtk_label_new ("Some <a href=\"http://en.wikipedia.org/wiki/Text\""
|
2020-04-26 03:33:33 +00:00
|
|
|
|
"title=\"plain text\">text</a> may be marked up "
|
|
|
|
|
"as hyperlinks, which can be clicked "
|
|
|
|
|
"or activated via <a href=\"keynav\">keynav</a> "
|
|
|
|
|
"and they work fine with other markup, like when "
|
2022-05-27 12:43:06 +00:00
|
|
|
|
"linking to <a href=\"http://www.flathub.org/\"><b>"
|
|
|
|
|
"<span letter_spacing=\"1024\" underline=\"none\" color=\"pink\" background=\"darkslategray\">Flathub</span>"
|
|
|
|
|
"</b></a>.");
|
2009-05-11 05:23:13 +00:00
|
|
|
|
gtk_label_set_use_markup (GTK_LABEL (label), TRUE);
|
2020-04-26 03:33:33 +00:00
|
|
|
|
gtk_label_set_max_width_chars (GTK_LABEL (label), 40);
|
|
|
|
|
gtk_label_set_wrap (GTK_LABEL (label), TRUE);
|
|
|
|
|
gtk_label_set_wrap_mode (GTK_LABEL (label), PANGO_WRAP_WORD);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
g_signal_connect (label, "activate-link", G_CALLBACK (activate_link), NULL);
|
2020-04-26 03:33:33 +00:00
|
|
|
|
gtk_widget_set_margin_start (label, 20);
|
|
|
|
|
gtk_widget_set_margin_end (label, 20);
|
|
|
|
|
gtk_widget_set_margin_top (label, 20);
|
|
|
|
|
gtk_widget_set_margin_bottom (label, 20);
|
2020-05-02 21:26:54 +00:00
|
|
|
|
gtk_window_set_child (GTK_WINDOW (window), label);
|
2009-05-11 05:23:13 +00:00
|
|
|
|
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
|
2020-05-09 14:26:22 +00:00
|
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2009-05-11 05:23:13 +00:00
|
|
|
|
|
|
|
|
|
return window;
|
|
|
|
|
}
|