]> Pileus Git - ~andy/gtk/blobdiff - tests/testtreesort.c
reftests: Add test for recent fix
[~andy/gtk] / tests / testtreesort.c
index a657430bafcfcdf71f2632ca6e4d9d2d810839df..b45ede02dcf08d9ed3627da7a7da4100b0162219 100644 (file)
@@ -1,7 +1,24 @@
+/* testtreesort.c
+ * Copyright (C) 2001 Red Hat, Inc
+ * Author: Jonathan Blandford
+ *
+ * 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
 #include <gtk/gtk.h>
 
-#include "../gtk/gtktreedatalist.h"
-
 
 typedef struct _ListSort ListSort;
 struct _ListSort
@@ -51,6 +68,31 @@ enum
   NUM_COLUMNS
 };
 
+gboolean
+select_func (GtkTreeSelection  *selection,
+            GtkTreeModel      *model,
+            GtkTreePath       *path,
+            gboolean           path_currently_selected,
+            gpointer           data)
+{
+  if (gtk_tree_path_get_depth (path) > 1)
+    return TRUE;
+  return FALSE;
+}
+
+static void
+switch_search_method (GtkWidget *button,
+                     gpointer   tree_view)
+{
+  if (!gtk_tree_view_get_search_entry (GTK_TREE_VIEW (tree_view)))
+    {
+      gpointer data = g_object_get_data (tree_view, "my-search-entry");
+      gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_ENTRY (data));
+    }
+  else
+    gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), NULL);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -66,6 +108,7 @@ main (int argc, char *argv[])
   GtkTreeIter iter;
   gint i;
 
+  GtkWidget *entry, *button;
   GtkWidget *window2, *vbox2, *scrolled_window2, *tree_view2;
   GtkWidget *window3, *vbox3, *scrolled_window3, *tree_view3;
 
@@ -77,12 +120,18 @@ main (int argc, char *argv[])
 
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_title (GTK_WINDOW (window), "Words, words, words - Window 1");
-  gtk_signal_connect (GTK_OBJECT (window), "destroy", gtk_main_quit, NULL);
-  vbox = gtk_vbox_new (FALSE, 8);
+  g_signal_connect (window, "destroy", gtk_main_quit, NULL);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
   gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
   gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Jonathan and Kristian's list of cool words. (And Anders' cool list of numbers) \n\nThis is just a GtkTreeStore"), FALSE, FALSE, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
 
+  entry = gtk_entry_new ();
+  gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0);
+
+  button = gtk_button_new_with_label ("Switch search method");
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
   gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_ETCHED_IN);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
@@ -96,6 +145,13 @@ main (int argc, char *argv[])
 */
   tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
 
+  gtk_tree_view_set_search_entry (GTK_TREE_VIEW (tree_view), GTK_ENTRY (entry));
+  g_object_set_data (G_OBJECT (tree_view), "my-search-entry", entry);
+  g_signal_connect (button, "clicked",
+                   G_CALLBACK (switch_search_method), tree_view);
+
+ /* gtk_tree_selection_set_select_function (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)), select_func, NULL, NULL);*/
+
   /* 12 iters now, 12 later... */
   for (i = 0; data[i].word_1 != NULL; i++)
     {
@@ -138,8 +194,8 @@ main (int argc, char *argv[])
   
   smodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (model));
   ssmodel = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (smodel));
+  g_object_unref (model);
 
-  g_object_unref (G_OBJECT (model));
   gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
 
   renderer = gtk_cell_renderer_text_new ();
@@ -194,8 +250,8 @@ main (int argc, char *argv[])
       window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_title (GTK_WINDOW (window2), 
                            "Words, words, words - window 2");
-      gtk_signal_connect (GTK_OBJECT (window2), "destroy", gtk_main_quit, NULL);
-      vbox2 = gtk_vbox_new (FALSE, 8);
+      g_signal_connect (window2, "destroy", gtk_main_quit, NULL);
+      vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
       gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
       gtk_box_pack_start (GTK_BOX (vbox2), 
                          gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeStore of window 1"),
@@ -266,8 +322,8 @@ main (int argc, char *argv[])
       window3 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
       gtk_window_set_title (GTK_WINDOW (window3), 
                            "Words, words, words - Window 3");
-      gtk_signal_connect (GTK_OBJECT (window3), "destroy", gtk_main_quit, NULL);
-      vbox3 = gtk_vbox_new (FALSE, 8);
+      g_signal_connect (window3, "destroy", gtk_main_quit, NULL);
+      vbox3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
       gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
       gtk_box_pack_start (GTK_BOX (vbox3), 
                          gtk_label_new ("Jonathan and Kristian's list of words.\n\nA GtkTreeModelSort wrapping the GtkTreeModelSort of window 2"),