]> Pileus Git - ~andy/gtk/blobdiff - tests/testtreeview.c
Use GtkComboBox instead of GtkCombo in testsocket
[~andy/gtk] / tests / testtreeview.c
index 2ccc90e762213d39c99270c904c31873087bc20c..8f376bdf5478b567e610f810216830d62e2d3144 100644 (file)
@@ -1,7 +1,28 @@
+/* testtreeview.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, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#undef GTK_DISABLE_DEPRECATED
 #include <string.h>
 #include "prop-editor.h"
 #include <gtk/gtk.h>
-
+#include <stdlib.h>
 
 /* Don't copy this bad example; inline RGB data is always a better
  * idea than inline XPMs.
@@ -237,6 +258,66 @@ toggled_callback (GtkCellRendererToggle *celltoggle,
                g_type_name (G_TYPE_FROM_INSTANCE (model)));
 }
 
+static void
+edited_callback (GtkCellRendererText *renderer,
+                const gchar   *path_string,
+                const gchar   *new_text,
+                GtkTreeView  *tree_view)
+{
+  GtkTreeModel *model = NULL;
+  GtkTreeModelSort *sort_model = NULL;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  guint value = atoi (new_text);
+  
+  g_return_if_fail (GTK_IS_TREE_VIEW (tree_view));
+
+  model = gtk_tree_view_get_model (tree_view);
+  
+  if (GTK_IS_TREE_MODEL_SORT (model))
+    {
+      sort_model = GTK_TREE_MODEL_SORT (model);
+      model = gtk_tree_model_sort_get_model (sort_model);
+    }
+
+  if (model == NULL)
+    return;
+
+  if (sort_model)
+    {
+      g_warning ("FIXME implement conversion from TreeModelSort iter to child model iter");
+      return;
+    }
+      
+  path = gtk_tree_path_new_from_string (path_string);
+  if (!gtk_tree_model_get_iter (model,
+                                &iter, path))
+    {
+      g_warning ("%s: bad path?", G_STRLOC);
+      return;
+    }
+  gtk_tree_path_free (path);
+
+  if (GTK_IS_LIST_STORE (model))
+    {
+      gtk_list_store_set (GTK_LIST_STORE (model),
+                          &iter,
+                          4,
+                          value,
+                          -1);
+    }
+  else if (GTK_IS_TREE_STORE (model))
+    {
+      gtk_tree_store_set (GTK_TREE_STORE (model),
+                          &iter,
+                          4,
+                          value,
+                          -1);
+    }
+  else
+    g_warning ("don't know how to actually toggle value for model type %s",
+               g_type_name (G_TYPE_FROM_INSTANCE (model)));
+}
 
 static ColumnsType current_column_type = COLUMNS_LOTS;
 
@@ -247,7 +328,8 @@ set_columns_type (GtkTreeView *tree_view, ColumnsType type)
   GtkCellRenderer *rend;
   GdkPixbuf *pixbuf;
   GtkWidget *image;
-  
+  GtkObject *adjustment;
+    
   current_column_type = type;
   
   col = gtk_tree_view_get_column (tree_view, 0);
@@ -324,7 +406,7 @@ set_columns_type (GtkTreeView *tree_view, ColumnsType type)
       /* you could also set this per-row by tying it to a column
        * in the model of course.
        */
-      g_object_set (G_OBJECT (rend), "radio", TRUE, NULL);
+      g_object_set (rend, "radio", TRUE, NULL);
       
       g_signal_connect (rend, "toggled",
                        G_CALLBACK (toggled_callback), tree_view);
@@ -337,19 +419,25 @@ set_columns_type (GtkTreeView *tree_view, ColumnsType type)
       setup_column (col);
       
       gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
-      
-#if 0
 
-      rend = gtk_cell_renderer_text_new ();
-      
+      rend = gtk_cell_renderer_spin_new ();
+
+      adjustment = gtk_adjustment_new (0, 0, 10000, 100, 100, 100);
+      g_object_set (rend, "editable", TRUE, NULL);
+      g_object_set (rend, "adjustment", adjustment, NULL);
+
+      g_signal_connect (rend, "edited",
+                       G_CALLBACK (edited_callback), tree_view);
+
       col = gtk_tree_view_column_new_with_attributes ("Column 5",
                                                       rend,
-                                                      "text", 3,
+                                                      "text", 4,
                                                       NULL);
 
       setup_column (col);
       
       gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), col);
+#if 0
       
       rend = gtk_cell_renderer_text_new ();
       
@@ -648,7 +736,7 @@ main (int    argc,
   
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-  gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
+  gtk_window_set_default_size (GTK_WINDOW (window), 430, 400);
 
   table = gtk_table_new (3, 1, FALSE);
 
@@ -803,7 +891,7 @@ gtk_tree_model_types_get_type (void)
 
   if (!model_types_type)
     {
-      static const GTypeInfo model_types_info =
+      const GTypeInfo model_types_info =
       {
         sizeof (GtkTreeModelTypesClass),
        NULL,           /* base_init */
@@ -816,7 +904,7 @@ gtk_tree_model_types_get_type (void)
         (GInstanceInitFunc) gtk_tree_model_types_init
       };
 
-      static const GInterfaceInfo tree_model_info =
+      const GInterfaceInfo tree_model_info =
       {
        (GInterfaceInitFunc) gtk_tree_model_types_tree_model_init,
        NULL,
@@ -839,7 +927,7 @@ gtk_tree_model_types_new (void)
 {
   GtkTreeModelTypes *retval;
 
-  retval = GTK_TREE_MODEL_TYPES (g_object_new (GTK_TYPE_MODEL_TYPES, NULL));
+  retval = g_object_new (GTK_TYPE_MODEL_TYPES, NULL);
 
   return retval;
 }
@@ -962,7 +1050,7 @@ gtk_real_model_types_get_value (GtkTreeModel *tree_model,
         
         g_value_init (value, G_TYPE_STRING);
 
-        str = g_strdup_printf ("%ld", type);
+        str = g_strdup_printf ("%ld", (long int) type);
         g_value_set_string (value, str);
         g_free (str);
       }
@@ -1161,7 +1249,9 @@ gtk_real_model_types_iter_parent (GtkTreeModel *tree_model,
   if (parent == G_TYPE_INVALID)
     {
       if (type > G_TYPE_FUNDAMENTAL_MAX)
-        g_warning ("no parent for %ld %s\n", type, g_type_name (type));
+        g_warning ("no parent for %ld %s\n",
+                   (long int) type,
+                   g_type_name (type));
       return FALSE;
     }
   else
@@ -1176,6 +1266,8 @@ gtk_real_model_types_iter_parent (GtkTreeModel *tree_model,
  * Automated testing
  */
 
+#if 0
+
 static void
 treestore_torture_recurse (GtkTreeStore *store,
                            GtkTreeIter  *root,
@@ -1265,6 +1357,8 @@ treestore_torture_recurse (GtkTreeStore *store,
     }
 }
 
+#endif
+
 static void
 run_automated_tests (void)
 {