]> Pileus Git - ~andy/gtk/blobdiff - tests/testcombochange.c
Replace a lot of idle and timeout calls by the new gdk_threads api.
[~andy/gtk] / tests / testcombochange.c
index 97224b3729e042eaf1fc30a9a3fd3d10083053b6..7e42cbca1423bf8f6cb3cb2c0b19f79fe2acb56c 100644 (file)
@@ -1,3 +1,24 @@
+/* testcombochange.c
+ * Copyright (C) 2004  Red Hat, Inc.
+ * Author: Owen Taylor
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
 #include <gtk/gtk.h>
 #include <stdarg.h>
 
@@ -8,7 +29,7 @@ GArray *contents;
 static char next_value = 'A';
 
 static void
-test_init ()
+test_init (void)
 {
   if (g_file_test ("../gdk-pixbuf/libpixbufloader-pnm.la",
                   G_FILE_TEST_EXISTS))
@@ -19,7 +40,7 @@ test_init ()
 }
 
 static void
-log (const char *fmt,
+combochange_log (const char *fmt,
      ...)
 {
   GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (text_view));
@@ -119,7 +140,7 @@ on_insert (void)
 
   g_array_insert_val (contents, insert_pos, new_value);
 
-  log ("Inserted '%c' at position %d", new_value[0], insert_pos);
+  combochange_log ("Inserted '%c' at position %d", new_value[0], insert_pos);
 }
 
 static void
@@ -140,7 +161,7 @@ on_delete (void)
 
   old_val = g_array_index (contents, char, delete_pos);
   g_array_remove_index (contents, delete_pos);
-  log ("Deleted '%c' from position %d", old_val, delete_pos);
+  combochange_log ("Deleted '%c' from position %d", old_val, delete_pos);
 }
 
 static void
@@ -155,11 +176,11 @@ on_reorder (void)
   for (i = 0; i < contents->len; i++)
     shuffle_array[i] = i;
 
-  for (i = 0; i < contents->len - 1; i++)
+  for (i = 0; i + 1 < contents->len; i++)
     {
       gint pos = g_random_int_range (i, contents->len);
       gint tmp;
-      
+
       tmp = shuffle_array[i];
       shuffle_array[i] = shuffle_array[pos];
       shuffle_array[pos] = tmp;
@@ -174,11 +195,42 @@ on_reorder (void)
   g_array_free (contents, TRUE);
   contents = new_contents;
 
-  log ("Reordered array");
+  combochange_log ("Reordered array");
     
   g_free (shuffle_array);
 }
 
+static int n_animations = 0;
+static int timer = 0;
+
+static gint
+animation_timer (gpointer data)
+{
+  switch (g_random_int_range (0, 3)) 
+    {
+    case 0: 
+      on_insert ();
+      break;
+    case 1:
+      on_delete ();
+      break;
+    case 2:
+      on_reorder ();
+      break;
+    }
+
+  n_animations--;
+  return n_animations > 0;
+}
+
+static void
+on_animate (void)
+{
+  n_animations += 20;
+  timer = gdk_threads_add_timeout (1000, (GSourceFunc) animation_timer, NULL);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -262,6 +314,10 @@ main (int argc, char **argv)
   gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0);
   g_signal_connect (button, "clicked", G_CALLBACK (on_reorder), NULL);
 
+  button = align_button_new ("Animate");
+  gtk_box_pack_start (GTK_BOX (button_vbox), button, FALSE, FALSE, 0);
+  g_signal_connect (button, "clicked", G_CALLBACK (on_animate), NULL);
+
   gtk_widget_show_all (dialog);
   gtk_dialog_run (GTK_DIALOG (dialog));