#include <config.h>
#include <string.h>
-#include "gtkalias.h"
#include "gtktreemodelsort.h"
#include "gtktreesortable.h"
#include "gtktreestore.h"
#include "gtktreedatalist.h"
#include "gtkintl.h"
+#include "gtkprivate.h"
#include "gtktreednd.h"
+#include "gtkalias.h"
typedef struct _SortElt SortElt;
typedef struct _SortLevel SortLevel;
#define SORT_ELT(sort_elt) ((SortElt *)sort_elt)
#define SORT_LEVEL(sort_level) ((SortLevel *)sort_level)
-#define GET_CHILD_ITER(tree_model_sort,child_iter,sort_iter) gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT (tree_model_sort), child_iter, sort_iter);
+#define GET_CHILD_ITER(tree_model_sort,ch_iter,so_iter) gtk_tree_model_sort_convert_iter_to_child_iter(GTK_TREE_MODEL_SORT (tree_model_sort), ch_iter, so_iter);
#define NO_SORT_FUNC ((GtkTreeIterCompareFunc) 0x1)
P_("TreeModelSort Model"),
P_("The model for the TreeModelSort to sort"),
GTK_TYPE_TREE_MODEL,
- G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+ GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
}
static void
* gtk_tree_model_sort_new_with_model:
* @child_model: A #GtkTreeModel
*
- * Creates a new #GtkTreeModel, with @child_model as the child_model.
+ * Creates a new #GtkTreeModel, with @child_model as the child model.
*
* Return value: A new #GtkTreeModel.
*/
level = iter.user_data;
elt = iter.user_data2;
+ level->ref_count++;
+
if (level->array->len < 2 ||
(tree_model_sort->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
tree_model_sort->default_sort_func == NO_SORT_FUNC))
gtk_tree_path_free (path);
+ level->ref_count--;
+
return;
}
-
+
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
{
gtk_tree_model_get_iter (tree_model_sort->child_model,
g_free (new_order);
}
+ level->ref_count--;
+
/* emit row_changed signal (at new location) */
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
gtk_tree_model_row_changed (GTK_TREE_MODEL (data), path, &iter);
if (!parent_level)
goto done;
+ if (level->ref_count == 0 && level != tree_model_sort->root)
+ {
+ gtk_tree_model_sort_free_level (tree_model_sort, level);
+ goto done;
+ }
+
if (!gtk_tree_model_sort_insert_value (tree_model_sort,
parent_level,
s_path,
if (level->ref_count == 0)
{
- /* This will prune the level, so I can just emit the signal and not worry
- * about cleaning this level up. */
+ /* This will prune the level, so I can just emit the signal and
+ * not worry about cleaning this level up.
+ * Careful, root level is not cleaned up in increment stamp.
+ */
gtk_tree_model_sort_increment_stamp (tree_model_sort);
gtk_tree_path_free (path);
if (level == tree_model_sort->root)
- tree_model_sort->root = NULL;
+ {
+ gtk_tree_model_sort_free_level (tree_model_sort,
+ tree_model_sort->root);
+ tree_model_sort->root = NULL;
+ }
return;
}
if (level->array->len < 1 && !((SortElt *)level->array->data)->children)
return;
+ level->ref_count++;
+
/* Set up data */
data.tree_model_sort = tree_model_sort;
if (level->parent_elt)
}
g_free (new_order);
+
+ level->ref_count--;
}
static void
/**
* gtk_tree_model_sort_set_model:
* @tree_model_sort: The #GtkTreeModelSort.
- * @child_model: A #GtkTreeModel, or NULL.
+ * @child_model: A #GtkTreeModel, or %NULL.
*
- * Sets the model of @tree_model_sort to be @model. If @model is NULL, then the
- * old model is unset. The sort function is unset as a result of this call.
- * The model will be in an unsorted state until a sort function is set.
+ * Sets the model of @tree_model_sort to be @model. If @model is %NULL,
+ * then the old model is unset. The sort function is unset as a result
+ * of this call. The model will be in an unsorted state until a sort
+ * function is set.
**/
static void
gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
*
* Converts @child_path to a path relative to @tree_model_sort. That is,
* @child_path points to a path in the child model. The returned path will
- * point to the same row in the sorted model. If @child_path isn't a valid path
- * on the child model, then %NULL is returned.
+ * point to the same row in the sorted model. If @child_path isn't a valid
+ * path on the child model, then %NULL is returned.
*
* Return value: A newly allocated #GtkTreePath, or %NULL
**/
* @tree_model_sort: A #GtkTreeModelSort
* @sorted_path: A #GtkTreePath to convert
*
- * Converts @sorted_path to a path on the child model of @tree_model_sort. That
- * is, @sorted_path points to a location in @tree_model_sort. The returned path
- * will point to the same location in the model not being sorted. If @sorted_path
- * does not point to a location in the child model, %NULL is returned.
+ * Converts @sorted_path to a path on the child model of @tree_model_sort.
+ * That is, @sorted_path points to a location in @tree_model_sort. The
+ * returned path will point to the same location in the model not being
+ * sorted. If @sorted_path does not point to a location in the child model,
+ * %NULL is returned.
*
* Return value: A newly allocated #GtkTreePath, or %NULL
**/
if (gtk_tree_model_iter_next (tree_model_sort->child_model, &iter) == FALSE &&
i < length - 1)
{
- g_warning ("There is a discrepency between the sort model and the child model.");
+ g_warning ("There is a discrepancy between the sort model and the child model.");
return;
}
}
* @tree_model_sort: A #GtkTreeModelSort.
* @iter: A #GtkTreeIter.
*
- * WARNING: This function is slow. Only use it for debugging and/or testing
- * purposes.
+ * <warning><para>
+ * This function is slow. Only use it for debugging and/or testing purposes.
+ * </para></warning>
*
* Checks if the given iter is a valid iter for this #GtkTreeModelSort.
*
return gtk_tree_model_sort_iter_is_valid_helper (iter,
tree_model_sort->root);
}
+
+#define __GTK_TREE_MODEL_SORT_C__
+#include "gtkaliasdef.c"