]> Pileus Git - ~andy/gtk/commitdiff
New function to help handle keeping things in sync.
authorJonathan Blandford <jrb@redhat.com>
Sat, 11 Nov 2000 00:02:05 +0000 (00:02 +0000)
committerJonathan Blandford <jrb@src.gnome.org>
Sat, 11 Nov 2000 00:02:05 +0000 (00:02 +0000)
Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>

* gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
function to help handle keeping things in sync.

ChangeLog
ChangeLog.pre-2-0
ChangeLog.pre-2-10
ChangeLog.pre-2-2
ChangeLog.pre-2-4
ChangeLog.pre-2-6
ChangeLog.pre-2-8
gtk/gtktreemodelsort.c
gtk/gtktreemodelsort.h

index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index 25d6f67f723ec411f4853c7df955f13291554dd6..1ae3eac50b2a65374f2704834079bdf5b60c6d6a 100644 (file)
@@ -1,3 +1,8 @@
+Fri Nov 10 19:06:41 2000  Jonathan Blandford  <jrb@redhat.com>
+
+       * gtk/gtktreemodelsort.c (gtk_tree_model_sort_insert_value): New
+       function to help handle keeping things in sync.
+
 Fri Nov 10 12:10:34 2000  Jonathan Blandford  <jrb@redhat.com>
 
        * gtk/gtkliststore.c (gtk_model_simple_class_init): use the new
index bbfbd5e1ca9ee55a3692ef7fa8cd71d0095df314..010cce89fa76f74e1faa6263d0b8663174c2077d 100644 (file)
@@ -229,7 +229,7 @@ gtk_tree_model_sort_new (void)
 
 GtkTreeModel *
 gtk_tree_model_sort_new_with_model (GtkTreeModel      *model,
-                                   GValueCompareFunc *func,
+                                   GValueCompareFunc  func,
                                    gint               sort_col)
 {
   GtkTreeModel *retval;
@@ -407,29 +407,49 @@ gtk_tree_model_sort_changed (GtkTreeModel *s_model,
     gtk_tree_path_free (s_path);
 }
 
-#if 0
 static void
 gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
-                                 GtkTreeIter      *old_iter,
-                                 GtkTreePath      *path)
+                                 GtkTreePath      *s_path,
+                                 GtkTreeIter      *s_iter)
 {
-  GtkTreePath *parent_path;
+  GtkTreePath *tmp_path;
   GArray *array;
   GtkTreeIter iter;
-  SortElt new_elt;
+  SortElt elt;
   SortElt *tmp_elt;
   gint high, low, middle;
-  GValueCompareFunc *func;
+  GValueCompareFunc func;
+  GValue s_value = {0, };
   GValue tmp_value = {0, };
-  GValue old_value = {0, };
 
-  parent_path = gtk_tree_path_copy (path);
-  gtk_tree_path_up (parent_path);
-  gtk_tree_model_get_iter (GTK_TREE_MODEL (sort),
-                          &iter,
-                          parent_path);
-  gtk_tree_path_free (parent_path);
-  array = ((SortElt *) iter.tree_node)->children;
+  elt.iter = *s_iter;
+  elt.ref = 0;
+  elt.children = NULL;
+
+  tmp_path = gtk_tree_path_copy (s_path);
+  if (gtk_tree_path_up (tmp_path))
+    {
+      GtkTreePath *parent_path;
+
+      parent_path = gtk_tree_model_sort_convert_path (sort, tmp_path);
+      gtk_tree_model_get_iter (GTK_TREE_MODEL (sort), &iter, parent_path);
+      elt.parent = ((SortElt *) iter.tree_node);
+      array = ((SortElt *) iter.tree_node)->children;
+      if (array == NULL)
+       {
+         ((SortElt *) iter.tree_node)->children = g_array_sized_new (FALSE, FALSE, sizeof (SortElt), 1);
+         array = ((SortElt *) iter.tree_node)->children;
+       }
+      gtk_tree_path_free (parent_path);
+    }
+  else
+    {
+      if (sort->root == NULL)
+       sort->root = g_array_sized_new (FALSE, FALSE, sizeof (SortElt), 1);
+      array = sort->root;
+      elt.parent = NULL;
+    }
+  gtk_tree_path_free (tmp_path);
 
   if (sort->func)
     func = sort->func;
@@ -444,38 +464,44 @@ gtk_tree_model_sort_insert_value (GtkTreeModelSort *sort,
          func = &g_value_int_compare_func;
          break;
        default:
-         g_warning ("No comparison function for row %d\n", sort->sort_col);
+         g_warning ("No comparison function for row %d (Type %s)\n",
+                    sort->sort_col,
+                    g_type_name (gtk_tree_model_get_column_type (sort->model, sort->sort_col)));
          return;
        }
     }
 
-  new_elt.iter = iter;
-  new_elt.ref = 0;
-  new_elt.parent = ((SortElt *) iter.tree_node);
-  new_elt.children = NULL;
+  gtk_tree_model_get_value (sort->model, s_iter, sort->sort_col, &s_value);
 
   low = 0;
   high = array->len;
   middle = (low + high)/2;
 
   /* Insert the value into the array */
-  while (1)
+  while (low != high)
     {
       gint cmp;
-      tmp_elt = &(g_array_index (array, SortElt,middle));
-      gtk_tree_model_get_value (sort->model, tmp_elt, sort->sort_col, &tmp_value);
-
-      cmp = ((func) (&tmp_value, value));
-      if (retval < 0)
-       ;
-      else if (retval == 0)
-       g_array_insert_vals
-       ;
-      else if (retval > 0)
-       ;
+      tmp_elt = &(g_array_index (array, SortElt, middle));
+      gtk_tree_model_get_value (sort->model,
+                               (GtkTreeIter *) tmp_elt,
+                               sort->sort_col,
+                               &tmp_value);
+
+      cmp = ((func) (&tmp_value, &s_value));
+      g_value_unset (&tmp_value);
+
+      if (cmp < 0)
+       high = middle;
+      else if (cmp > 0)
+       low = middle;
+      else if (cmp == 0)
+       break;
+      middle = (low + high)/2;
     }
+
+  g_array_insert_vals (array, middle, &elt, 1);
+  g_value_unset (&s_value);
 }
-#endif
 
 static void
 gtk_tree_model_sort_inserted (GtkTreeModel *s_model,
@@ -489,19 +515,28 @@ gtk_tree_model_sort_inserted (GtkTreeModel *s_model,
 
   g_return_if_fail (s_path != NULL || s_iter != NULL);
 
+  if (s_path == NULL)
+    s_path = gtk_tree_model_get_path (s_model, s_iter);
+
   if (!(tree_model_sort->flags & GTK_TREE_MODEL_ITERS_PERSIST))
     {
-      gtk_tree_model_sort_free_level ((GArray *)tree_model_sort->root);
+      gtk_tree_model_sort_free_level ((GArray *) tree_model_sort->root);
       tree_model_sort->root = NULL;
     }
   else
     {
-    }
+      GtkTreeIter real_s_iter;
 
-  if (s_path == NULL)
-    s_path = gtk_tree_model_get_path (s_model, s_iter);
+      if (s_iter == NULL)
+       gtk_tree_model_get_iter (s_model, &real_s_iter, s_path);
+      else
+       real_s_iter = *s_iter;
+
+      gtk_tree_model_sort_insert_value (tree_model_sort, s_path, &real_s_iter);
+    }
 
   path = gtk_tree_model_sort_convert_path (tree_model_sort, s_path);
+
   gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
   gtk_signal_emit_by_name (GTK_OBJECT (data), "inserted", path, iter);
   gtk_tree_path_free (path);
index 01366e6cb73e9f82d51aa33fe8be51cfc2cf3baa..65935e41f4d648eb610e9e773a99415ac427819a 100644 (file)
@@ -48,7 +48,7 @@ struct _GtkTreeModelSort
   guint flags;
   GtkTreeModel *model;
   gint sort_col;
-  GValueCompareFunc *func;
+  GValueCompareFunc func;
 };
 
 struct _GtkTreeModelSortClass
@@ -74,7 +74,7 @@ struct _GtkTreeModelSortClass
 GtkType       gtk_tree_model_sort_get_type       (void);
 GtkTreeModel *gtk_tree_model_sort_new            (void);
 GtkTreeModel *gtk_tree_model_sort_new_with_model (GtkTreeModel      *model,
-                                                 GValueCompareFunc *func,
+                                                 GValueCompareFunc  func,
                                                  gint               sort_col);
 void          gtk_tree_model_sort_set_model      (GtkTreeModelSort  *tree_model_sort,
                                                  GtkTreeModel      *model);