[gtk+/wip/list: 2/8] tests: Add testlistview



commit 02bc5022faae140a517f2f06457854d4a04dd5a0
Author: Benjamin Otte <otte redhat com>
Date:   Wed May 9 05:06:56 2012 +0200

    tests: Add testlistview

 tests/Makefile.am    |    4 ++++
 tests/testlistview.c |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c3a6ac0..04cc234 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -108,6 +108,7 @@ noinst_PROGRAMS =  $(TEST_PROGS)	\
 	testtooltips			\
 	testexpand			\
 	testexpander			\
+	testlistview			\
 	testvolumebutton		\
 	testscrolledwindow		\
 	testswitch			\
@@ -232,6 +233,7 @@ testtreemenu_DEPENDENCIES = $(TEST_DEPS)
 testwindows_DEPENDENCIES = $(TEST_DEPS)
 testexpand_DEPENDENCIES = $(TEST_DEPS)
 testexpander_DEPENDENCIES = $(TEST_DEPS)
+testlistview_DEPENDENCIES = $(TEST_DEPS)
 testswitch_DEPENDENCIES = $(TEST_DEPS)
 styleexamples_DEPENDENCIES = $(TEST_DEPS)
 testtoplevelembed_DEPENDENCIES = $(TEST_DEPS)
@@ -409,6 +411,8 @@ testexpand_SOURCES = testexpand.c
 
 testexpander_SOURCES = testexpander.c
 
+testlistview_SOURCES = testlistview.c
+
 testswitch_SOURCES = testswitch.c
 
 styleexamples_SOURCES = styleexamples.c
diff --git a/tests/testlistview.c b/tests/testlistview.c
new file mode 100644
index 0000000..dbedbd6
--- /dev/null
+++ b/tests/testlistview.c
@@ -0,0 +1,49 @@
+#include <gtk/gtk.h>
+
+static GtkTreeModel *
+create_treemodel (void)
+{
+  GtkListStore *store;
+  char *all_the_words;
+  char **words;
+  guint i;
+
+  store = gtk_list_store_new (1, G_TYPE_STRING);
+
+  if (!g_file_get_contents ("/usr/share/dict/words", &all_the_words, NULL, NULL))
+    return GTK_TREE_MODEL (store);
+
+  words = g_strsplit (all_the_words, "\n", -1);
+  g_free (all_the_words);
+
+  for (i = 0; words[i] && i < 10; i++)
+    {
+      gtk_list_store_insert_with_values (store, NULL, -1, 0, words[i], -1);
+    }
+
+  return GTK_TREE_MODEL (store);
+}
+
+int
+main (int argc, char *argv[])
+{
+  GtkWidget *window, *list;
+  GtkTreeModel *model;
+
+  gtk_init (&argc, &argv);
+
+  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+  g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
+
+  model = create_treemodel ();
+  list = gtk_list_view_new_with_model (model);
+  g_object_unref (model);
+
+  gtk_container_add (GTK_CONTAINER (window), list);
+  gtk_widget_show_all (window);
+
+  gtk_main ();
+
+  return 0;
+}
+



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