[gnome-control-center/wip/animated-notebook] shell: Make test case's buttons work



commit 8721742afef14390edff460bddc61b7f4e4e2c2f
Author: Bastien Nocera <hadess hadess net>
Date:   Fri May 4 14:22:00 2012 +0100

    shell: Make test case's buttons work

 shell/test-notebook.c |   50 +++++++++++++++++++++++++++++++++---------------
 1 files changed, 34 insertions(+), 16 deletions(-)
---
diff --git a/shell/test-notebook.c b/shell/test-notebook.c
index 592ced2..7697de0 100644
--- a/shell/test-notebook.c
+++ b/shell/test-notebook.c
@@ -1,22 +1,31 @@
 #include <stdlib.h>
 #include "cc-notebook.h"
 
-enum {
-  PAGE_1,
-  PAGE_2,
-  PAGE_3,
-  PAGE_4,
-  PAGE_5,
+#define NUM_PAGES 5
 
-  N_PAGES
-};
+static GHashTable *pages;
+static GtkWidget *notebook;
 
-static int pages[N_PAGES] = { 0, };
+static void
+goto_page (GtkButton *button,
+	   gpointer   user_data)
+{
+	int target = GPOINTER_TO_INT (user_data);
+	GtkWidget *widget;
+
+	if (target < 1)
+		target = NUM_PAGES;
+	else if (target > NUM_PAGES)
+		target = 1;
+	widget = g_hash_table_lookup (pages, GINT_TO_POINTER (target));
+	cc_notebook_select_page (CC_NOTEBOOK (notebook), widget);
+}
 
 static GtkWidget *
-create_page_contents (const char *text)
+create_page_contents (int page_num)
 {
   GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+  char *text = g_strdup_printf ("Page number %d", page_num);
 
   GtkWidget *hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
   gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
@@ -24,10 +33,14 @@ create_page_contents (const char *text)
   GtkWidget *back_button = gtk_button_new_with_label ("â");
   gtk_widget_set_halign (back_button, GTK_ALIGN_START);
   gtk_box_pack_start (GTK_BOX (hbox), back_button, FALSE, FALSE, 0);
+  g_signal_connect (G_OBJECT (back_button), "clicked",
+		    G_CALLBACK (goto_page), GINT_TO_POINTER (page_num - 1));
 
   GtkWidget *fwd_button = gtk_button_new_with_label ("â");
   gtk_widget_set_halign (fwd_button, GTK_ALIGN_END);
   gtk_box_pack_end (GTK_BOX (hbox), fwd_button, FALSE, FALSE, 0);
+  g_signal_connect (G_OBJECT (fwd_button), "clicked",
+		    G_CALLBACK (goto_page), GINT_TO_POINTER (page_num + 1));
 
   GtkWidget *label = gtk_label_new (text);
   gtk_widget_set_name (label, text);
@@ -36,6 +49,8 @@ create_page_contents (const char *text)
 
   gtk_widget_show_all (vbox);
 
+  g_hash_table_insert (pages, GINT_TO_POINTER (page_num), vbox);
+
   return vbox;
 }
 
@@ -49,6 +64,8 @@ on_page_change (CcNotebook *notebook)
 int
 main (int argc, char *argv[])
 {
+  guint i;
+
   if (gtk_clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS)
     return EXIT_FAILURE;
 
@@ -56,15 +73,16 @@ main (int argc, char *argv[])
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
   gtk_widget_show (window);
 
-  GtkWidget *notebook = cc_notebook_new ();
+  notebook = cc_notebook_new ();
   gtk_container_add (GTK_CONTAINER (window), notebook);
   g_signal_connect (notebook, "notify::current-page", G_CALLBACK (on_page_change), NULL);
 
-  pages[PAGE_1] = cc_notebook_add_page ((CcNotebook *) notebook, create_page_contents ("Page number 1"));
-  pages[PAGE_2] = cc_notebook_add_page ((CcNotebook *) notebook, create_page_contents ("Page number 2"));
-  pages[PAGE_3] = cc_notebook_add_page ((CcNotebook *) notebook, create_page_contents ("Page number 3"));
-  pages[PAGE_4] = cc_notebook_add_page ((CcNotebook *) notebook, create_page_contents ("Page number 4"));
-  pages[PAGE_5] = cc_notebook_add_page ((CcNotebook *) notebook, create_page_contents ("Page number 5"));
+  pages = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+  for (i = 1; i <= NUM_PAGES; i++) {
+    GtkWidget *page = create_page_contents (i);
+    cc_notebook_add_page ((CcNotebook *) notebook, page);
+  }
 
   gtk_widget_show_all (window);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]