diff options
Diffstat (limited to 'demos/gtk-demo')
-rw-r--r-- | demos/gtk-demo/Makefile.am | 5 | ||||
-rw-r--r-- | demos/gtk-demo/links.c | 85 |
2 files changed, 89 insertions, 1 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am index 46ebc03a1b..aced886a3d 100644 --- a/demos/gtk-demo/Makefile.am +++ b/demos/gtk-demo/Makefile.am @@ -3,7 +3,7 @@ include $(top_srcdir)/Makefile.decl democodedir=$(datadir)/gtk-2.0/demo -## These should be in the order you want them to appear in the +## These should be in the order you want them to appear in the ## demo app, which means alphabetized by demo title, not filename demos = \ appwindow.c \ @@ -23,6 +23,7 @@ demos = \ iconview.c \ iconview_edit.c \ images.c \ + links.c \ list_store.c \ menus.c \ panes.c \ @@ -96,3 +97,5 @@ IMAGEFILES= alphatest.png \ democode_DATA = $(demos) $(IMAGEFILES) demo.ui DISTCLEANFILES = demos.h + +-include $(top_srcdir)/git.mk diff --git a/demos/gtk-demo/links.c b/demos/gtk-demo/links.c new file mode 100644 index 0000000000..c506144c87 --- /dev/null +++ b/demos/gtk-demo/links.c @@ -0,0 +1,85 @@ +/* Links + * + * GtkLabel can show hyperlinks. The default action is to call + * gtk_show_uri() on their URI, but it is possible to override + * 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 +activate_link (GtkWidget *label, + const gchar *uri, + gpointer data) +{ + if (g_strcmp0 (uri, "keynav") == 0) + { + GtkWidget *dialog; + GtkWidget *parent; + + parent = gtk_widget_get_toplevel (label); + 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."); + + 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) +{ + static GtkWidget *window = NULL; + GtkWidget *box; + GtkWidget *label; + + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_screen (GTK_WINDOW (window), + gtk_widget_get_screen (do_widget)); + gtk_container_set_border_width (GTK_CONTAINER (window), 12); + g_signal_connect (window, "destroy", + G_CALLBACK(gtk_widget_destroyed), &window); + g_signal_connect (window, "delete-event", + G_CALLBACK (gtk_true), NULL); + + 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" + "or activated via <a href=\"keynav\">keynav</a>"); + 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); + } + + if (!GTK_WIDGET_VISIBLE (window)) + { + gtk_widget_show (window); + } + else + { + gtk_widget_destroy (window); + window = NULL; + } + + return window; +} |