]> Pileus Git - ~andy/gtk/blobdiff - demos/gtk-demo/assistant.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / demos / gtk-demo / assistant.c
index 232d345c07c57455dc64e722c6fea111ad53e908..b461171c65179062c946f9cf3c355af9c99c9e95 100644 (file)
@@ -1,12 +1,11 @@
 /* Assistant
  *
- * Demonstrates a sample multistep assistant. Assistants are used to divide
+ * Demonstrates a sample multi-step 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 GtkWidget *progress_bar = NULL;
@@ -23,13 +22,14 @@ apply_changes_gradually (gpointer data)
   if (fraction < 1.0)
     {
       gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (progress_bar), fraction);
-      return TRUE;
+      return G_SOURCE_CONTINUE;
     }
   else
     {
       /* Close automatically once changes are fully applied. */
       gtk_widget_destroy (assistant);
-      return FALSE;
+      assistant = NULL;
+      return G_SOURCE_REMOVE;
     }
 }
 
@@ -92,7 +92,6 @@ static void
 create_page1 (GtkWidget *assistant)
 {
   GtkWidget *box, *label, *entry;
-  GdkPixbuf *pixbuf;
 
   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
   gtk_container_set_border_width (GTK_CONTAINER (box), 12);
@@ -101,48 +100,39 @@ create_page1 (GtkWidget *assistant)
   gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
 
   entry = gtk_entry_new ();
+  gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);
   gtk_box_pack_start (GTK_BOX (box), entry, TRUE, TRUE, 0);
   g_signal_connect (G_OBJECT (entry), "changed",
-                   G_CALLBACK (on_entry_changed), assistant);
+                    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_pixbuf (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
-  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_box_new (GTK_ORIENTATION_VERTICAL, 12);
   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");
+                                                 "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_pixbuf (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
-  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");
 
@@ -151,30 +141,24 @@ create_page3 (GtkWidget *assistant)
   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_pixbuf (assistant, GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG);
-  gtk_assistant_set_page_header_image (GTK_ASSISTANT (assistant), label, pixbuf);
-  g_object_unref (pixbuf);
 }
 
 static void
 create_page4 (GtkWidget *assistant)
 {
-  GtkWidget *page;
-
-  page = gtk_alignment_new (0.5, 0.5, 0.5, 0.0);
-
   progress_bar = gtk_progress_bar_new ();
-  gtk_container_add (GTK_CONTAINER (page), progress_bar);
+  gtk_widget_set_halign (progress_bar, GTK_ALIGN_CENTER);
+  gtk_widget_set_valign (progress_bar, GTK_ALIGN_CENTER);
 
-  gtk_widget_show_all (page);
-  gtk_assistant_append_page (GTK_ASSISTANT (assistant), page);
-  gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), page, GTK_ASSISTANT_PAGE_PROGRESS);
-  gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), page, "Applying changes");
+  gtk_widget_show (progress_bar);
+  gtk_assistant_append_page (GTK_ASSISTANT (assistant), progress_bar);
+  gtk_assistant_set_page_type (GTK_ASSISTANT (assistant), progress_bar, GTK_ASSISTANT_PAGE_PROGRESS);
+  gtk_assistant_set_page_title (GTK_ASSISTANT (assistant), progress_bar, "Applying changes");
 
   /* This prevents the assistant window from being
-   * closed while we're "busy" applying changes. */
-  gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), page, FALSE);
+   * closed while we're "busy" applying changes.
+   */
+  gtk_assistant_set_page_complete (GTK_ASSISTANT (assistant), progress_bar, FALSE);
 }
 
 GtkWidget*
@@ -184,10 +168,10 @@ do_assistant (GtkWidget *do_widget)
     {
       assistant = gtk_assistant_new ();
 
-        gtk_window_set_default_size (GTK_WINDOW (assistant), -1, 300);
+         gtk_window_set_default_size (GTK_WINDOW (assistant), -1, 300);
 
       gtk_window_set_screen (GTK_WINDOW (assistant),
-                            gtk_widget_get_screen (do_widget));
+                             gtk_widget_get_screen (do_widget));
 
       create_page1 (assistant);
       create_page2 (assistant);
@@ -195,13 +179,13 @@ do_assistant (GtkWidget *do_widget)
       create_page4 (assistant);
 
       g_signal_connect (G_OBJECT (assistant), "cancel",
-                       G_CALLBACK (on_assistant_close_cancel), &assistant);
+                        G_CALLBACK (on_assistant_close_cancel), &assistant);
       g_signal_connect (G_OBJECT (assistant), "close",
-                       G_CALLBACK (on_assistant_close_cancel), &assistant);
+                        G_CALLBACK (on_assistant_close_cancel), &assistant);
       g_signal_connect (G_OBJECT (assistant), "apply",
-                       G_CALLBACK (on_assistant_apply), NULL);
+                        G_CALLBACK (on_assistant_apply), NULL);
       g_signal_connect (G_OBJECT (assistant), "prepare",
-                       G_CALLBACK (on_assistant_prepare), NULL);
+                        G_CALLBACK (on_assistant_prepare), NULL);
     }
 
   if (!gtk_widget_get_visible (assistant))