summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-01-28 06:03:50 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-01-28 06:03:50 +0000
commit017a5e3d5be6869abe485ea0c631160d1fa999b9 (patch)
tree6b3b9d92d5665ef66d005945b9ff3e9e9d565c36 /demos
parentbd51b09f77e86e95e279d7a0e12d8389716c0d28 (diff)
downloadgdk-pixbuf-017a5e3d5be6869abe485ea0c631160d1fa999b9.tar.gz
More work on GtkAssistant by Carlos Garnacho:
2006-01-28 Matthias Clasen <mclasen@redhat.com> More work on GtkAssistant by Carlos Garnacho: * demos/gtk-demo/Makefile.am: * demos/gtk-demo/assistant.c: Add a GtkAssistant demo. * gtk/gtkassistant.c: Handle focus, several small fixes to the flow computations.
Diffstat (limited to 'demos')
-rw-r--r--demos/gtk-demo/Makefile.am1
-rw-r--r--demos/gtk-demo/assistant.c165
2 files changed, 166 insertions, 0 deletions
diff --git a/demos/gtk-demo/Makefile.am b/demos/gtk-demo/Makefile.am
index 04038edb7..c3bd17f55 100644
--- a/demos/gtk-demo/Makefile.am
+++ b/demos/gtk-demo/Makefile.am
@@ -6,6 +6,7 @@ democodedir=$(datadir)/gtk-2.0/demo
## demo app, which means alphabetized by demo title, not filename
demos = \
appwindow.c \
+ assistant.c \
button_box.c \
changedisplay.c \
clipboard.c \
diff --git a/demos/gtk-demo/assistant.c b/demos/gtk-demo/assistant.c
new file mode 100644
index 000000000..f5c69dd02
--- /dev/null
+++ b/demos/gtk-demo/assistant.c
@@ -0,0 +1,165 @@
+/* Assistant
+ *
+ * Demonstrates a sample multistep assistant. Assistants are used to divide
+ * an operation into several simpler sequential steps, and to guide the user
+ * through these steps.
+ */
+
+#include <gtk/gtk.h>
+#include "demo-common.h"
+
+static GtkWidget *assistant = NULL;
+
+static void
+on_assistant_apply (GtkWidget *widget, gpointer data)
+{
+ /* Apply here changes, this is a fictional
+ example, so we just do nothing here */
+}
+
+static void
+on_assistant_close_cancel (GtkWidget *widget, gpointer data)
+{
+ GtkWidget **assistant = (GtkWidget **) data;
+
+ gtk_widget_destroy (*assistant);
+ *assistant = NULL;
+}
+
+static void
+on_assistant_prepare (GtkWidget *widget, GtkWidget *page, gpointer data)
+{
+ gint current_page, n_pages;
+ gchar *title;
+
+ current_page = gtk_assistant_get_current_page (GTK_ASSISTANT (widget));
+ n_pages = gtk_assistant_get_n_pages (GTK_ASSISTANT (widget));
+
+ title = g_strdup_printf ("Sample assistant (%d of %d)", current_page + 1, n_pages);
+ gtk_window_set_title (GTK_WINDOW (widget), title);
+ g_free (title);
+}
+
+static void
+on_entry_changed (GtkWidget *widget, gpointer data)
+{
+ GtkAssistant *assistant = GTK_ASSISTANT (data);
+ GtkWidget *current_page;
+ gint page_number;
+ const gchar *text;
+
+ page_number = gtk_assistant_get_current_page (assistant);
+ current_page = gtk_assistant_get_nth_page (assistant, page_number);
+ text = gtk_entry_get_text (GTK_ENTRY (widget));
+
+ if (text && *text)
+ gtk_assistant_set_page_complete (assistant, current_page, TRUE);
+ else
+ gtk_assistant_set_page_complete (assistant, current_page, FALSE);
+}
+
+static void
+create_page1 (GtkWidget *assistant)
+{
+ GtkWidget *box, *label, *entry;
+ GdkPixbuf *pixbuf;
+
+ box = gtk_hbox_new (FALSE, 12);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 12);
+
+ label = gtk_label_new ("You must fill out this entry to continue:");
+ gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
+
+ entry = gtk_entry_new ();
+ gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0);
+ g_signal_connect (G_OBJECT (entry), "changed",
+ G_CALLBACK (on_entry_changed), assistant);
+
+ gtk_widget_show_all (box);
+ gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);
+ gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "Page 1");
+ gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), box, GTK_ASSISTANT_PAGE_INTRO);
+
+ pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG, NULL);
+ gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), box, pixbuf);
+ g_object_unref (pixbuf);
+}
+
+static void
+create_page2 (GtkWidget *assistant)
+{
+ GtkWidget *box, *checkbutton;
+ GdkPixbuf *pixbuf;
+
+ box = gtk_vbox_new (12, FALSE);
+ gtk_container_set_border_width (GTK_CONTAINER (box), 12);
+
+ checkbutton = gtk_check_button_new_with_label ("This is optional data, you may continue "
+ "even if you do not check this");
+ gtk_box_pack_start (GTK_BOX (box), checkbutton, FALSE, FALSE, 0);
+
+ gtk_widget_show_all (box);
+ gtk_assistant_append_page (GTK_ASSISTANT (assistant), box);
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), box, TRUE);
+ gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), box, "Page 2");
+
+ pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG, NULL);
+ gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), box, pixbuf);
+ g_object_unref (pixbuf);
+}
+
+static void
+create_page3 (GtkWidget *assistant)
+{
+ GtkWidget *label;
+ GdkPixbuf *pixbuf;
+
+ label = gtk_label_new ("This is a confirmation page, press 'Apply' to apply changes");
+
+ gtk_widget_show (label);
+ gtk_assistant_append_page (GTK_ASSISTANT (assistant), label);
+ gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), label, GTK_ASSISTANT_PAGE_CONFIRM);
+ gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), label, TRUE);
+ gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), label, "Confirmation");
+
+ pixbuf = gtk_widget_render_icon (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG, NULL);
+ gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), label, pixbuf);
+ g_object_unref (pixbuf);
+}
+
+GtkWidget*
+do_assistant (GtkWidget *do_widget)
+{
+ if (!assistant)
+ {
+ assistant = gtk_assistant_new ();
+
+ gtk_window_set_default_size (GTK_WINDOW (assistant), -1, 300);
+
+ gtk_window_set_screen (GTK_WINDOW (assistant),
+ gtk_widget_get_screen (do_widget));
+
+ create_page1 (assistant);
+ create_page2 (assistant);
+ create_page3 (assistant);
+
+ g_signal_connect (G_OBJECT (assistant), "cancel",
+ G_CALLBACK (on_assistant_close_cancel), &assistant);
+ g_signal_connect (G_OBJECT (assistant), "close",
+ G_CALLBACK (on_assistant_close_cancel), &assistant);
+ g_signal_connect (G_OBJECT (assistant), "apply",
+ G_CALLBACK (on_assistant_apply), NULL);
+ g_signal_connect (G_OBJECT (assistant), "prepare",
+ G_CALLBACK (on_assistant_prepare), NULL);
+ }
+
+ if (!GTK_WIDGET_VISIBLE (assistant))
+ gtk_widget_show (assistant);
+ else
+ {
+ gtk_widget_destroy (assistant);
+ assistant = NULL;
+ }
+
+ return assistant;
+}