2000-11-09 16:52:17 +00:00
|
|
|
/* gtktreemodelsort.c
|
2001-12-26 22:43:53 +00:00
|
|
|
* Copyright (C) 2000,2001 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
|
2002-01-13 00:22:04 +00:00
|
|
|
* Copyright (C) 2001,2002 Kristian Rietveld <kris@gtk.org>
|
2000-11-09 16:52:17 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2000-11-10 19:38:53 +00:00
|
|
|
/* NOTE: There is a potential for confusion in this code as to whether an iter,
|
2000-11-21 09:07:45 +00:00
|
|
|
* path or value refers to the GtkTreeModelSort model, or the child model being
|
|
|
|
* sorted. As a convention, variables referencing the child model will have an
|
2000-11-10 19:38:53 +00:00
|
|
|
* s_ prefix before them (ie. s_iter, s_value, s_path);
|
|
|
|
*/
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* ITER FORMAT:
|
|
|
|
*
|
|
|
|
* iter->stamp = tree_model_sort->stamp
|
|
|
|
* iter->user_data = SortLevel
|
|
|
|
* iter->user_data2 = SortElt
|
|
|
|
*/
|
|
|
|
|
2001-12-26 22:43:53 +00:00
|
|
|
/* WARNING: this code is dangerous, can cause sleepless nights,
|
|
|
|
* can cause your dog to die among other bad things
|
|
|
|
*
|
|
|
|
* we warned you and we're not liable for any head injuries.
|
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2002-10-07 19:10:39 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
#include "gtktreemodelsort.h"
|
2001-06-14 23:25:52 +00:00
|
|
|
#include "gtktreesortable.h"
|
2001-09-02 21:47:12 +00:00
|
|
|
#include "gtktreestore.h"
|
2001-06-14 23:25:52 +00:00
|
|
|
#include "gtktreedatalist.h"
|
2001-11-14 02:06:28 +00:00
|
|
|
#include "gtkintl.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
#include "gtktreednd.h"
|
2010-07-09 17:22:23 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2011-04-17 23:34:07 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtktreemodelsort
|
|
|
|
* @Short_description: A GtkTreeModel which makes an underlying tree model sortable
|
|
|
|
* @Title: GtkTreeModelSort
|
|
|
|
* @See_also: #GtkTreeModel, #GtkListStore, #GtkTreeStore, #GtkTreeSortable, #GtkTreeModelFilter
|
|
|
|
*
|
|
|
|
* The #GtkTreeModelSort is a model which implements the #GtkTreeSortable
|
|
|
|
* interface. It does not hold any data itself, but rather is created with
|
|
|
|
* a child model and proxies its data. It has identical column types to
|
|
|
|
* this child model, and the changes in the child are propagated. The
|
|
|
|
* primary purpose of this model is to provide a way to sort a different
|
|
|
|
* model without modifying it. Note that the sort function used by
|
|
|
|
* #GtkTreeModelSort is not guaranteed to be stable.
|
|
|
|
*
|
|
|
|
* The use of this is best demonstrated through an example. In the
|
|
|
|
* following sample code we create two #GtkTreeView widgets each with a
|
|
|
|
* view of the same data. As the model is wrapped here by a
|
|
|
|
* #GtkTreeModelSort, the two #GtkTreeView<!-- -->s can each sort their
|
|
|
|
* view of the data without affecting the other. By contrast, if we
|
|
|
|
* simply put the same model in each widget, then sorting the first would
|
|
|
|
* sort the second.
|
|
|
|
*
|
|
|
|
* <example>
|
|
|
|
* <title>Using a <structname>GtkTreeModelSort</structname></title>
|
|
|
|
* <programlisting>
|
|
|
|
* {
|
|
|
|
* GtkTreeView *tree_view1;
|
|
|
|
* GtkTreeView *tree_view2;
|
|
|
|
* GtkTreeModel *sort_model1;
|
|
|
|
* GtkTreeModel *sort_model2;
|
|
|
|
* GtkTreeModel *child_model;
|
|
|
|
*
|
|
|
|
* // get the child model
|
|
|
|
* child_model = get_my_model ();
|
|
|
|
*
|
|
|
|
* // Create the first tree
|
|
|
|
* sort_model1 = gtk_tree_model_sort_new_with_model (child_model);
|
|
|
|
* tree_view1 = gtk_tree_view_new_with_model (sort_model1);
|
|
|
|
*
|
|
|
|
* // Create the second tree
|
|
|
|
* sort_model2 = gtk_tree_model_sort_new_with_model (child_model);
|
|
|
|
* tree_view2 = gtk_tree_view_new_with_model (sort_model2);
|
|
|
|
*
|
|
|
|
* // Now we can sort the two models independently
|
|
|
|
* gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model1),
|
|
|
|
* COLUMN_1, GTK_SORT_ASCENDING);
|
|
|
|
* gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model2),
|
|
|
|
* COLUMN_1, GTK_SORT_DESCENDING);
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
*
|
|
|
|
* To demonstrate how to access the underlying child model from the sort
|
|
|
|
* model, the next example will be a callback for the #GtkTreeSelection
|
|
|
|
* #GtkTreeSelection::changed signal. In this callback, we get a string
|
|
|
|
* from COLUMN_1 of the model. We then modify the string, find the same
|
|
|
|
* selected row on the child model, and change the row there.
|
|
|
|
*
|
|
|
|
* <example>
|
|
|
|
* <title>Accessing the child model of in a selection changed callback</title>
|
|
|
|
* <programlisting>
|
|
|
|
* void
|
|
|
|
* selection_changed (GtkTreeSelection *selection, gpointer data)
|
|
|
|
* {
|
|
|
|
* GtkTreeModel *sort_model = NULL;
|
|
|
|
* GtkTreeModel *child_model;
|
|
|
|
* GtkTreeIter sort_iter;
|
|
|
|
* GtkTreeIter child_iter;
|
|
|
|
* char *some_data = NULL;
|
|
|
|
* char *modified_data;
|
|
|
|
*
|
|
|
|
* // Get the current selected row and the model.
|
|
|
|
* if (! gtk_tree_selection_get_selected (selection,
|
|
|
|
* &sort_model,
|
|
|
|
* &sort_iter))
|
|
|
|
* return;
|
|
|
|
*
|
|
|
|
* /<!---->* Look up the current value on the selected row and get a new value
|
|
|
|
* * to change it to.
|
|
|
|
* *<!---->/
|
|
|
|
* gtk_tree_model_get (GTK_TREE_MODEL (sort_model), &sort_iter,
|
|
|
|
* COLUMN_1, &some_data,
|
|
|
|
* -1);
|
|
|
|
*
|
|
|
|
* modified_data = change_the_data (some_data);
|
|
|
|
* g_free (some_data);
|
|
|
|
*
|
|
|
|
* // Get an iterator on the child model, instead of the sort model.
|
|
|
|
* gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (sort_model),
|
|
|
|
* &child_iter,
|
|
|
|
* &sort_iter);
|
|
|
|
*
|
|
|
|
* /<!---->* Get the child model and change the value of the row. In this
|
|
|
|
* * example, the child model is a GtkListStore. It could be any other
|
|
|
|
* * type of model, though.
|
|
|
|
* *<!---->/
|
|
|
|
* child_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT (sort_model));
|
|
|
|
* gtk_list_store_set (GTK_LIST_STORE (child_model), &child_iter,
|
|
|
|
* COLUMN_1, &modified_data,
|
|
|
|
* -1);
|
|
|
|
* g_free (modified_data);
|
|
|
|
* }
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
typedef struct _SortElt SortElt;
|
2001-10-19 20:53:08 +00:00
|
|
|
typedef struct _SortLevel SortLevel;
|
|
|
|
typedef struct _SortData SortData;
|
|
|
|
typedef struct _SortTuple SortTuple;
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
struct _SortElt
|
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
SortLevel *children;
|
|
|
|
gint offset;
|
|
|
|
gint ref_count;
|
|
|
|
gint zero_ref_count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _SortLevel
|
|
|
|
{
|
|
|
|
GArray *array;
|
|
|
|
gint ref_count;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *parent_level;
|
2000-11-09 16:52:17 +00:00
|
|
|
};
|
|
|
|
|
2000-11-22 05:16:37 +00:00
|
|
|
struct _SortData
|
|
|
|
{
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort;
|
2001-10-31 00:20:15 +00:00
|
|
|
GtkTreePath *parent_path;
|
|
|
|
gint parent_path_depth;
|
|
|
|
gint *parent_path_indices;
|
|
|
|
GtkTreeIterCompareFunc sort_func;
|
|
|
|
gpointer sort_data;
|
2000-11-22 05:16:37 +00:00
|
|
|
};
|
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
struct _SortTuple
|
|
|
|
{
|
|
|
|
SortElt *elt;
|
2002-01-15 00:12:30 +00:00
|
|
|
gint offset;
|
2001-09-02 21:47:12 +00:00
|
|
|
};
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-11-14 02:06:28 +00:00
|
|
|
/* Properties */
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
|
|
|
/* Construct args */
|
|
|
|
PROP_MODEL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
struct _GtkTreeModelSortPrivate
|
|
|
|
{
|
|
|
|
gpointer root;
|
|
|
|
gint stamp;
|
|
|
|
guint child_flags;
|
|
|
|
GtkTreeModel *child_model;
|
|
|
|
gint zero_ref_count;
|
|
|
|
|
|
|
|
/* sort information */
|
|
|
|
GList *sort_list;
|
|
|
|
gint sort_column_id;
|
|
|
|
GtkSortType order;
|
|
|
|
|
|
|
|
/* default sort */
|
|
|
|
GtkTreeIterCompareFunc default_sort_func;
|
|
|
|
gpointer default_sort_data;
|
|
|
|
GDestroyNotify default_sort_destroy;
|
|
|
|
|
|
|
|
/* signal ids */
|
|
|
|
gulong changed_id;
|
|
|
|
gulong inserted_id;
|
|
|
|
gulong has_child_toggled_id;
|
|
|
|
gulong deleted_id;
|
|
|
|
gulong reordered_id;
|
|
|
|
};
|
|
|
|
|
2011-05-09 08:04:24 +00:00
|
|
|
/* Set this to 0 to disable caching of child iterators. This
|
|
|
|
* allows for more stringent testing. It is recommended to set this
|
|
|
|
* to one when refactoring this code and running the unit tests to
|
|
|
|
* catch more errors.
|
|
|
|
*/
|
|
|
|
#if 1
|
|
|
|
# define GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS(tree_model_sort) \
|
2010-12-18 04:49:27 +00:00
|
|
|
(((GtkTreeModelSort *)tree_model_sort)->priv->child_flags>K_TREE_MODEL_ITERS_PERSIST)
|
2011-05-09 08:04:24 +00:00
|
|
|
#else
|
|
|
|
# define GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS(tree_model_sort) (FALSE)
|
|
|
|
#endif
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
#define SORT_ELT(sort_elt) ((SortElt *)sort_elt)
|
|
|
|
#define SORT_LEVEL(sort_level) ((SortLevel *)sort_level)
|
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
#define SORT_LEVEL_PARENT_ELT(level) (&g_array_index (SORT_LEVEL ((level))->parent_level->array, SortElt, SORT_LEVEL ((level))->parent_elt_index))
|
|
|
|
#define SORT_LEVEL_ELT_INDEX(level, elt) (SORT_ELT ((elt)) - SORT_ELT (SORT_LEVEL ((level))->array->data))
|
|
|
|
|
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
#define GET_CHILD_ITER(tree_model_sort,ch_iter,so_iter) gtk_tree_model_sort_convert_iter_to_child_iter((GtkTreeModelSort*)(tree_model_sort), (ch_iter), (so_iter));
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2002-02-12 01:00:22 +00:00
|
|
|
#define NO_SORT_FUNC ((GtkTreeIterCompareFunc) 0x1)
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
#define VALID_ITER(iter, tree_model_sort) ((iter) != NULL && (iter)->user_data != NULL && (iter)->user_data2 != NULL && (tree_model_sort)->priv->stamp == (iter)->stamp)
|
2002-06-04 17:17:49 +00:00
|
|
|
|
2002-01-13 00:22:04 +00:00
|
|
|
/* general (object/interface init, etc) */
|
2001-09-12 23:16:18 +00:00
|
|
|
static void gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface);
|
|
|
|
static void gtk_tree_model_sort_tree_sortable_init (GtkTreeSortableIface *iface);
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
static void gtk_tree_model_sort_drag_source_init (GtkTreeDragSourceIface*iface);
|
2001-09-12 23:16:18 +00:00
|
|
|
static void gtk_tree_model_sort_finalize (GObject *object);
|
2001-12-26 22:43:53 +00:00
|
|
|
static void gtk_tree_model_sort_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gtk_tree_model_sort_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2002-01-13 00:22:04 +00:00
|
|
|
/* our signal handlers */
|
2001-10-19 20:53:08 +00:00
|
|
|
static void gtk_tree_model_sort_row_changed (GtkTreeModel *model,
|
|
|
|
GtkTreePath *start_path,
|
|
|
|
GtkTreeIter *start_iter,
|
|
|
|
gpointer data);
|
|
|
|
static void gtk_tree_model_sort_row_inserted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
static void gtk_tree_model_sort_row_has_child_toggled (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
static void gtk_tree_model_sort_row_deleted (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
gpointer data);
|
|
|
|
static void gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
|
|
|
|
GtkTreePath *s_path,
|
|
|
|
GtkTreeIter *s_iter,
|
|
|
|
gint *new_order,
|
|
|
|
gpointer data);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
|
|
/* TreeModel interface */
|
2002-07-05 17:25:16 +00:00
|
|
|
static GtkTreeModelFlags gtk_tree_model_sort_get_flags (GtkTreeModel *tree_model);
|
2001-09-02 21:47:12 +00:00
|
|
|
static gint gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model);
|
|
|
|
static GType gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
|
|
|
|
gint index);
|
|
|
|
static gboolean gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path);
|
|
|
|
static GtkTreePath *gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static void gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value);
|
|
|
|
static gboolean gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
2011-01-06 04:39:11 +00:00
|
|
|
static gboolean gtk_tree_model_sort_iter_previous (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
2001-09-02 21:47:12 +00:00
|
|
|
static gboolean gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent);
|
|
|
|
static gboolean gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gint gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gboolean gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
gint n);
|
|
|
|
static gboolean gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *child);
|
|
|
|
static void gtk_tree_model_sort_ref_node (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
2002-02-09 01:28:00 +00:00
|
|
|
static void gtk_tree_model_sort_real_unref_node (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gboolean propagate_unref);
|
2001-09-02 21:47:12 +00:00
|
|
|
static void gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
/* TreeDragSource interface */
|
|
|
|
static gboolean gtk_tree_model_sort_row_draggable (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path);
|
|
|
|
static gboolean gtk_tree_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkSelectionData *selection_data);
|
|
|
|
static gboolean gtk_tree_model_sort_drag_data_delete (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path);
|
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
/* TreeSortable interface */
|
2001-10-24 18:36:50 +00:00
|
|
|
static gboolean gtk_tree_model_sort_get_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint *sort_column_id,
|
|
|
|
GtkSortType *order);
|
|
|
|
static void gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkSortType order);
|
|
|
|
static void gtk_tree_model_sort_set_sort_func (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkTreeIterCompareFunc func,
|
|
|
|
gpointer data,
|
2008-06-18 09:12:32 +00:00
|
|
|
GDestroyNotify destroy);
|
2001-10-03 18:29:20 +00:00
|
|
|
static void gtk_tree_model_sort_set_default_sort_func (GtkTreeSortable *sortable,
|
|
|
|
GtkTreeIterCompareFunc func,
|
|
|
|
gpointer data,
|
2008-06-18 09:12:32 +00:00
|
|
|
GDestroyNotify destroy);
|
2001-10-03 18:29:20 +00:00
|
|
|
static gboolean gtk_tree_model_sort_has_default_sort_func (GtkTreeSortable *sortable);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2002-01-13 00:22:04 +00:00
|
|
|
/* Private functions (sort funcs, level handling and other utils) */
|
2001-10-24 18:36:50 +00:00
|
|
|
static void gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *parent_level,
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index);
|
2001-10-24 18:36:50 +00:00
|
|
|
static void gtk_tree_model_sort_free_level (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *sort_level);
|
|
|
|
static void gtk_tree_model_sort_increment_stamp (GtkTreeModelSort *tree_model_sort);
|
|
|
|
static void gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *level,
|
|
|
|
gboolean recurse,
|
|
|
|
gboolean emit_reordered);
|
|
|
|
static void gtk_tree_model_sort_sort (GtkTreeModelSort *tree_model_sort);
|
2001-10-19 20:53:08 +00:00
|
|
|
static gint gtk_tree_model_sort_level_find_insert (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *level,
|
|
|
|
GtkTreeIter *iter,
|
2003-08-15 18:13:54 +00:00
|
|
|
gint skip_index);
|
2001-10-19 20:53:08 +00:00
|
|
|
static gboolean gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
|
2001-10-24 18:36:50 +00:00
|
|
|
SortLevel *level,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreePath *s_path,
|
|
|
|
GtkTreeIter *s_iter);
|
2001-10-24 18:36:50 +00:00
|
|
|
static GtkTreePath *gtk_tree_model_sort_elt_get_path (SortLevel *level,
|
|
|
|
SortElt *elt);
|
|
|
|
static void gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreeModel *child_model);
|
2001-10-25 20:32:40 +00:00
|
|
|
static GtkTreePath *gtk_real_tree_model_sort_convert_child_path_to_path (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreePath *child_path,
|
|
|
|
gboolean build_levels);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkTreeModelSort, gtk_tree_model_sort, G_TYPE_OBJECT,
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
|
|
|
|
gtk_tree_model_sort_tree_model_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_SORTABLE,
|
|
|
|
gtk_tree_model_sort_tree_sortable_init)
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
|
2006-05-14 04:25:34 +00:00
|
|
|
gtk_tree_model_sort_drag_source_init))
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
|
|
static void
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_init (GtkTreeModelSort *tree_model_sort)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv;
|
|
|
|
|
|
|
|
priv = G_TYPE_INSTANCE_GET_PRIVATE (tree_model_sort,
|
|
|
|
GTK_TYPE_TREE_MODEL_SORT,
|
|
|
|
GtkTreeModelSortPrivate);
|
|
|
|
tree_model_sort->priv = priv;
|
|
|
|
priv->sort_column_id = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
|
|
|
|
priv->stamp = 0;
|
|
|
|
priv->zero_ref_count = 0;
|
|
|
|
priv->root = NULL;
|
|
|
|
priv->sort_list = NULL;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_class_init (GtkTreeModelSortClass *class)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
object_class = (GObjectClass *) class;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-11-14 02:06:28 +00:00
|
|
|
object_class->set_property = gtk_tree_model_sort_set_property;
|
|
|
|
object_class->get_property = gtk_tree_model_sort_get_property;
|
|
|
|
|
doh, this was broken beyond believe.
Tue Dec 12 23:46:44 2000 Tim Janik <timj@gtk.org>
* gtk/stock-icons/Makefile.am: doh, this was broken beyond believe.
* gtk/gtkbox.c: change property types from (u)long to (u)int for
::position and ::padding.
* gtk/gtkcontainer.c: make ::border_width an INT property.
* gtk/gtkpacker.c: make ::position an INT property.
* gtk/gtkscrolledwindow.c (gtk_scrolled_window_adjustment_changed):
guard against NULL h/v scrollbars, since this is used at construction
time.
* gtk/gtkclist.[hc]: nuked gtk_clist_construct(), implemented
internal gtk_clist_constructor().
* gtk/gtkctree.[hc]: nuked gtk_ctree_construct(), implemented
gtk_ctree_constructor().
* gtk/gtkprogressbar.c (gtk_progress_bar_class_init): property
::pulse_step should use ARG_PULSE_STEP, not ARG_FRACTION.
* docs/reference/Makefile.am: fun stuff, disabled docs generation
again, gtk-scan.c needs to introspec paramspecs, not GtkAgs.
* gtk/gtkwidget.[hc]:
removed gtk_widget_setv(), gtk_widget_getv(), gtk_widget_newv()
and gtk_widget_get().
(gtk_widget_new): use g_object_new_valist().
(gtk_widget_set): use g_object_set_valist().
* gtk/gtkobject.[hc]:
removed gtk_object_arg_get_info(), gtk_object_getv(),
gtk_object_query_args(), gtk_object_newv(),
gtk_object_class_add_signals(),
gtk_object_class_user_signal_new(),
gtk_object_class_user_signal_newv(),
gtk_object_arg_set(), gtk_object_arg_get(),
gtk_object_args_collect(),
gtk_object_default_construct(),
gtk_object_constructed(),
GTK_CONSTRUCTED and GTK_OBJECT_CONSTRUCTED().
removed nsignals, signals and n_args members from GtkObjectClass.
(gtk_object_new): use g_object_new_valist().
(gtk_object_set): use g_object_set_valist().
(gtk_object_get): use g_object_get_valist().
* gtk/gtkcompat.h: define gtk_object_default_construct().
* gtk/gtktypeutils.c (gtk_type_new): create constructed objects via
g_object_new().
* gtk/*.c: removed gtk_object_class_add_signals() from class_init()
fucntions, cleaned up method assignments (make sure your structures
are setup properly before calling out). removed all GTK_CONSTRUCTED
hacks ;)
2000-12-13 01:34:41 +00:00
|
|
|
object_class->finalize = gtk_tree_model_sort_finalize;
|
2001-11-14 02:06:28 +00:00
|
|
|
|
|
|
|
/* Properties */
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_MODEL,
|
|
|
|
g_param_spec_object ("model",
|
2004-01-16 23:10:05 +00:00
|
|
|
P_("TreeModelSort Model"),
|
|
|
|
P_("The model for the TreeModelSort to sort"),
|
2001-11-14 02:06:28 +00:00
|
|
|
GTK_TYPE_TREE_MODEL,
|
2005-03-22 02:14:55 +00:00
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2010-12-18 04:49:27 +00:00
|
|
|
|
|
|
|
g_type_class_add_private (class, sizeof (GtkTreeModelSortPrivate));
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_tree_model_init (GtkTreeModelIface *iface)
|
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
iface->get_flags = gtk_tree_model_sort_get_flags;
|
2000-11-09 16:52:17 +00:00
|
|
|
iface->get_n_columns = gtk_tree_model_sort_get_n_columns;
|
|
|
|
iface->get_column_type = gtk_tree_model_sort_get_column_type;
|
|
|
|
iface->get_iter = gtk_tree_model_sort_get_iter;
|
|
|
|
iface->get_path = gtk_tree_model_sort_get_path;
|
|
|
|
iface->get_value = gtk_tree_model_sort_get_value;
|
|
|
|
iface->iter_next = gtk_tree_model_sort_iter_next;
|
2011-01-06 04:39:11 +00:00
|
|
|
iface->iter_previous = gtk_tree_model_sort_iter_previous;
|
2000-11-09 16:52:17 +00:00
|
|
|
iface->iter_children = gtk_tree_model_sort_iter_children;
|
|
|
|
iface->iter_has_child = gtk_tree_model_sort_iter_has_child;
|
|
|
|
iface->iter_n_children = gtk_tree_model_sort_iter_n_children;
|
|
|
|
iface->iter_nth_child = gtk_tree_model_sort_iter_nth_child;
|
|
|
|
iface->iter_parent = gtk_tree_model_sort_iter_parent;
|
2001-03-09 00:19:11 +00:00
|
|
|
iface->ref_node = gtk_tree_model_sort_ref_node;
|
|
|
|
iface->unref_node = gtk_tree_model_sort_unref_node;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2001-06-14 23:25:52 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_tree_sortable_init (GtkTreeSortableIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_sort_column_id = gtk_tree_model_sort_get_sort_column_id;
|
|
|
|
iface->set_sort_column_id = gtk_tree_model_sort_set_sort_column_id;
|
2001-06-15 23:03:27 +00:00
|
|
|
iface->set_sort_func = gtk_tree_model_sort_set_sort_func;
|
2001-10-03 18:29:20 +00:00
|
|
|
iface->set_default_sort_func = gtk_tree_model_sort_set_default_sort_func;
|
|
|
|
iface->has_default_sort_func = gtk_tree_model_sort_has_default_sort_func;
|
2001-06-14 23:25:52 +00:00
|
|
|
}
|
|
|
|
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_drag_source_init (GtkTreeDragSourceIface *iface)
|
|
|
|
{
|
|
|
|
iface->row_draggable = gtk_tree_model_sort_row_draggable;
|
|
|
|
iface->drag_data_delete = gtk_tree_model_sort_drag_data_delete;
|
|
|
|
iface->drag_data_get = gtk_tree_model_sort_drag_data_get;
|
|
|
|
}
|
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_new_with_model:
|
|
|
|
* @child_model: A #GtkTreeModel
|
|
|
|
*
|
2005-07-25 13:55:31 +00:00
|
|
|
* Creates a new #GtkTreeModel, with @child_model as the child model.
|
2001-09-02 21:47:12 +00:00
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Return value: (transfer full): A new #GtkTreeModel.
|
2001-09-02 21:47:12 +00:00
|
|
|
*/
|
2000-11-09 16:52:17 +00:00
|
|
|
GtkTreeModel *
|
2010-09-21 04:18:11 +00:00
|
|
|
gtk_tree_model_sort_new_with_model (GtkTreeModel *child_model)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *retval;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL (child_model), NULL);
|
|
|
|
|
2002-10-07 19:10:39 +00:00
|
|
|
retval = g_object_new (gtk_tree_model_sort_get_type (), NULL);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2000-11-21 09:07:45 +00:00
|
|
|
gtk_tree_model_sort_set_model (GTK_TREE_MODEL_SORT (retval), child_model);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* GObject callbacks */
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_finalize (GObject *object)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) object;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
gtk_tree_model_sort_set_model (tree_model_sort, NULL);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root)
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, priv->root);
|
2001-06-14 23:25:52 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_list)
|
2001-06-14 23:25:52 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
_gtk_tree_data_list_header_free (priv->sort_list);
|
|
|
|
priv->sort_list = NULL;
|
2001-06-14 23:25:52 +00:00
|
|
|
}
|
2001-11-03 20:47:50 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->default_sort_destroy)
|
2006-07-02 14:48:00 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->default_sort_destroy (priv->default_sort_data);
|
|
|
|
priv->default_sort_destroy = NULL;
|
|
|
|
priv->default_sort_data = NULL;
|
2006-07-02 14:48:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-03 20:47:50 +00:00
|
|
|
/* must chain up */
|
2006-05-02 23:56:43 +00:00
|
|
|
G_OBJECT_CLASS (gtk_tree_model_sort_parent_class)->finalize (object);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2001-11-14 02:06:28 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
|
|
|
gtk_tree_model_sort_set_model (tree_model_sort, g_value_get_object (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
|
|
|
case PROP_MODEL:
|
2010-12-18 04:49:27 +00:00
|
|
|
g_value_set_object (value, gtk_tree_model_sort_get_model (tree_model_sort));
|
2001-11-14 02:06:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
static void
|
2001-09-12 23:16:18 +00:00
|
|
|
gtk_tree_model_sort_row_changed (GtkTreeModel *s_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreePath *start_s_path,
|
|
|
|
GtkTreeIter *start_s_iter,
|
2001-09-12 23:16:18 +00:00
|
|
|
gpointer data)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-24 18:36:50 +00:00
|
|
|
GtkTreePath *path = NULL;
|
2000-11-10 19:38:53 +00:00
|
|
|
GtkTreeIter iter;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeIter tmpiter;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
SortElt tmp;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortElt *elt;
|
|
|
|
SortLevel *level;
|
2000-11-10 19:38:53 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
gboolean free_s_path = FALSE;
|
|
|
|
|
2003-08-15 18:13:54 +00:00
|
|
|
gint index = 0, old_index, i;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
g_return_if_fail (start_s_path != NULL || start_s_iter != NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (!start_s_path)
|
2000-11-10 19:38:53 +00:00
|
|
|
{
|
|
|
|
free_s_path = TRUE;
|
2001-10-19 20:53:08 +00:00
|
|
|
start_s_path = gtk_tree_model_get_path (s_model, start_s_iter);
|
2000-11-10 19:38:53 +00:00
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-12-26 22:43:53 +00:00
|
|
|
path = gtk_real_tree_model_sort_convert_child_path_to_path (tree_model_sort,
|
|
|
|
start_s_path,
|
|
|
|
FALSE);
|
2001-10-19 20:53:08 +00:00
|
|
|
if (!path)
|
2000-11-22 05:16:37 +00:00
|
|
|
{
|
|
|
|
if (free_s_path)
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_path_free (start_s_path);
|
2000-11-22 05:16:37 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-12-20 00:37:58 +00:00
|
|
|
|
2000-11-10 19:38:53 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
2006-09-27 12:08:12 +00:00
|
|
|
gtk_tree_model_sort_ref_node (GTK_TREE_MODEL (data), &iter);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
level = iter.user_data;
|
|
|
|
elt = iter.user_data2;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2002-02-12 01:00:22 +00:00
|
|
|
if (level->array->len < 2 ||
|
2010-12-18 04:49:27 +00:00
|
|
|
(priv->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
|
|
|
|
priv->default_sort_func == NO_SORT_FUNC))
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
|
|
|
if (free_s_path)
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_path_free (start_s_path);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-03 18:29:20 +00:00
|
|
|
gtk_tree_model_row_changed (GTK_TREE_MODEL (data), path, &iter);
|
2006-09-27 12:08:12 +00:00
|
|
|
gtk_tree_model_sort_unref_node (GTK_TREE_MODEL (data), &iter);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
gtk_tree_path_free (path);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2005-07-22 03:38:14 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
2001-10-24 18:36:50 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_get_iter (priv->child_model,
|
2001-10-24 18:36:50 +00:00
|
|
|
&tmpiter, start_s_path);
|
|
|
|
}
|
2001-12-26 22:43:53 +00:00
|
|
|
|
2003-08-15 18:13:54 +00:00
|
|
|
old_index = elt - SORT_ELT (level->array->data);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
memcpy (&tmp, elt, sizeof (SortElt));
|
Behaviour change, apply changes if the entry of the editable gets a focus
Tue Oct 15 00:53:14 2002 Kristian Rietveld <kris@gtk.org>
Behaviour change, apply changes if the entry of the editable gets
a focus out event (#82405).
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_focus_out_event):
new function,
(gtk_cell_renderer_text_start_editing): stop editing and apply
changes on focus-out.
Tue Oct 15 00:47:35 2002 Kristian Rietveld <kris@gtk.org>
Fixes an *evil* GtkTreeModelSort bug, #93629.
* gtk/gtktreemodel.c (release_row_references): return if the
refs->list is NULL.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_changed): if we
are swapping two rows (re-insertion on row_changed), also *emit*
a rows_reordered signal. oops.
Tue Oct 15 00:45:03 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtkliststore.c (gtk_list_store_remove_silently): free
the actual link after the node has been removed (#92014).
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_column_finalize):
free the cell_list and the child if the exists (#92014).
Tue Oct 15 00:40:25 2002 Kristian Rietveld <kris@gtk.org>
Don't accept drops if the model has been sorted, #93758)
* gtk/gtkliststore.c (gtk_list_store_row_drop_possible): return
FALSE if the list has been sorted.
* gtk/gtktreestore.c (gtk_tree_store_row_drop_possible): check
if drag_dest is a TreeStore, return FALSE if the tree has been
sorted.
Tue Oct 15 00:33:59 2002 Kristian Rietveld <kris@gtk.org>
Compiler warning fixage, (#85858, #85859, #85860, #85872)
* gtk/gtkcellrendererpixbuf (gtk_cell_renderer_pixbuf_render):
s/guint/GtkCellRendererState/.
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_render):
ditto.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render),
(gtk_cell_renderer_toggle_activate): ditto.
* gtk/gtkliststore.c (gtk_list_store_get_flags): a
s/guint/GtkTreeModelFlags/ on the return type.
2002-10-14 22:50:18 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
|
|
|
index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
|
|
|
|
level,
|
2001-09-02 21:47:12 +00:00
|
|
|
&tmp.iter,
|
2003-08-15 18:13:54 +00:00
|
|
|
old_index);
|
2001-09-02 21:47:12 +00:00
|
|
|
else
|
2001-10-19 20:53:08 +00:00
|
|
|
index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
|
|
|
|
level,
|
2001-09-02 21:47:12 +00:00
|
|
|
&tmpiter,
|
2003-08-15 18:13:54 +00:00
|
|
|
old_index);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2003-06-04 23:44:52 +00:00
|
|
|
if (index < old_index)
|
|
|
|
{
|
|
|
|
g_memmove (level->array->data + ((index + 1)*sizeof (SortElt)),
|
|
|
|
level->array->data + ((index)*sizeof (SortElt)),
|
|
|
|
(old_index - index)* sizeof(SortElt));
|
|
|
|
}
|
|
|
|
else if (index > old_index)
|
|
|
|
{
|
|
|
|
g_memmove (level->array->data + ((old_index)*sizeof (SortElt)),
|
|
|
|
level->array->data + ((old_index + 1)*sizeof (SortElt)),
|
|
|
|
(index - old_index)* sizeof(SortElt));
|
|
|
|
}
|
|
|
|
memcpy (level->array->data + ((index)*sizeof (SortElt)),
|
|
|
|
&tmp, sizeof (SortElt));
|
2001-10-24 18:36:50 +00:00
|
|
|
|
2001-12-26 22:43:53 +00:00
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
if (g_array_index (level->array, SortElt, i).children)
|
2009-09-06 11:35:37 +00:00
|
|
|
g_array_index (level->array, SortElt, i).children->parent_elt_index = i;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-12-26 22:43:53 +00:00
|
|
|
gtk_tree_path_up (path);
|
|
|
|
gtk_tree_path_append_index (path, index);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
Behaviour change, apply changes if the entry of the editable gets a focus
Tue Oct 15 00:53:14 2002 Kristian Rietveld <kris@gtk.org>
Behaviour change, apply changes if the entry of the editable gets
a focus out event (#82405).
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_focus_out_event):
new function,
(gtk_cell_renderer_text_start_editing): stop editing and apply
changes on focus-out.
Tue Oct 15 00:47:35 2002 Kristian Rietveld <kris@gtk.org>
Fixes an *evil* GtkTreeModelSort bug, #93629.
* gtk/gtktreemodel.c (release_row_references): return if the
refs->list is NULL.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_changed): if we
are swapping two rows (re-insertion on row_changed), also *emit*
a rows_reordered signal. oops.
Tue Oct 15 00:45:03 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtkliststore.c (gtk_list_store_remove_silently): free
the actual link after the node has been removed (#92014).
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_column_finalize):
free the cell_list and the child if the exists (#92014).
Tue Oct 15 00:40:25 2002 Kristian Rietveld <kris@gtk.org>
Don't accept drops if the model has been sorted, #93758)
* gtk/gtkliststore.c (gtk_list_store_row_drop_possible): return
FALSE if the list has been sorted.
* gtk/gtktreestore.c (gtk_tree_store_row_drop_possible): check
if drag_dest is a TreeStore, return FALSE if the tree has been
sorted.
Tue Oct 15 00:33:59 2002 Kristian Rietveld <kris@gtk.org>
Compiler warning fixage, (#85858, #85859, #85860, #85872)
* gtk/gtkcellrendererpixbuf (gtk_cell_renderer_pixbuf_render):
s/guint/GtkCellRendererState/.
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_render):
ditto.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render),
(gtk_cell_renderer_toggle_activate): ditto.
* gtk/gtkliststore.c (gtk_list_store_get_flags): a
s/guint/GtkTreeModelFlags/ on the return type.
2002-10-14 22:50:18 +00:00
|
|
|
/* if the item moved, then emit rows_reordered */
|
|
|
|
if (old_index != index)
|
|
|
|
{
|
|
|
|
gint *new_order;
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
GtkTreePath *tmppath;
|
|
|
|
|
|
|
|
new_order = g_new (gint, level->array->len);
|
|
|
|
|
|
|
|
for (j = 0; j < level->array->len; j++)
|
|
|
|
{
|
|
|
|
if (index > old_index)
|
|
|
|
{
|
|
|
|
if (j == index)
|
|
|
|
new_order[j] = old_index;
|
|
|
|
else if (j >= old_index && j < index)
|
|
|
|
new_order[j] = j + 1;
|
|
|
|
else
|
|
|
|
new_order[j] = j;
|
|
|
|
}
|
|
|
|
else if (index < old_index)
|
|
|
|
{
|
|
|
|
if (j == index)
|
|
|
|
new_order[j] = old_index;
|
|
|
|
else if (j > index && j <= old_index)
|
|
|
|
new_order[j] = j - 1;
|
|
|
|
else
|
|
|
|
new_order[j] = j;
|
|
|
|
}
|
|
|
|
/* else? shouldn't really happen */
|
|
|
|
}
|
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
if (level->parent_elt_index >= 0)
|
Behaviour change, apply changes if the entry of the editable gets a focus
Tue Oct 15 00:53:14 2002 Kristian Rietveld <kris@gtk.org>
Behaviour change, apply changes if the entry of the editable gets
a focus out event (#82405).
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_focus_out_event):
new function,
(gtk_cell_renderer_text_start_editing): stop editing and apply
changes on focus-out.
Tue Oct 15 00:47:35 2002 Kristian Rietveld <kris@gtk.org>
Fixes an *evil* GtkTreeModelSort bug, #93629.
* gtk/gtktreemodel.c (release_row_references): return if the
refs->list is NULL.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_changed): if we
are swapping two rows (re-insertion on row_changed), also *emit*
a rows_reordered signal. oops.
Tue Oct 15 00:45:03 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtkliststore.c (gtk_list_store_remove_silently): free
the actual link after the node has been removed (#92014).
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_column_finalize):
free the cell_list and the child if the exists (#92014).
Tue Oct 15 00:40:25 2002 Kristian Rietveld <kris@gtk.org>
Don't accept drops if the model has been sorted, #93758)
* gtk/gtkliststore.c (gtk_list_store_row_drop_possible): return
FALSE if the list has been sorted.
* gtk/gtktreestore.c (gtk_tree_store_row_drop_possible): check
if drag_dest is a TreeStore, return FALSE if the tree has been
sorted.
Tue Oct 15 00:33:59 2002 Kristian Rietveld <kris@gtk.org>
Compiler warning fixage, (#85858, #85859, #85860, #85872)
* gtk/gtkcellrendererpixbuf (gtk_cell_renderer_pixbuf_render):
s/guint/GtkCellRendererState/.
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_render):
ditto.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render),
(gtk_cell_renderer_toggle_activate): ditto.
* gtk/gtkliststore.c (gtk_list_store_get_flags): a
s/guint/GtkTreeModelFlags/ on the return type.
2002-10-14 22:50:18 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
iter.stamp = priv->stamp;
|
Behaviour change, apply changes if the entry of the editable gets a focus
Tue Oct 15 00:53:14 2002 Kristian Rietveld <kris@gtk.org>
Behaviour change, apply changes if the entry of the editable gets
a focus out event (#82405).
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_focus_out_event):
new function,
(gtk_cell_renderer_text_start_editing): stop editing and apply
changes on focus-out.
Tue Oct 15 00:47:35 2002 Kristian Rietveld <kris@gtk.org>
Fixes an *evil* GtkTreeModelSort bug, #93629.
* gtk/gtktreemodel.c (release_row_references): return if the
refs->list is NULL.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_changed): if we
are swapping two rows (re-insertion on row_changed), also *emit*
a rows_reordered signal. oops.
Tue Oct 15 00:45:03 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtkliststore.c (gtk_list_store_remove_silently): free
the actual link after the node has been removed (#92014).
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_column_finalize):
free the cell_list and the child if the exists (#92014).
Tue Oct 15 00:40:25 2002 Kristian Rietveld <kris@gtk.org>
Don't accept drops if the model has been sorted, #93758)
* gtk/gtkliststore.c (gtk_list_store_row_drop_possible): return
FALSE if the list has been sorted.
* gtk/gtktreestore.c (gtk_tree_store_row_drop_possible): check
if drag_dest is a TreeStore, return FALSE if the tree has been
sorted.
Tue Oct 15 00:33:59 2002 Kristian Rietveld <kris@gtk.org>
Compiler warning fixage, (#85858, #85859, #85860, #85872)
* gtk/gtkcellrendererpixbuf (gtk_cell_renderer_pixbuf_render):
s/guint/GtkCellRendererState/.
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_render):
ditto.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render),
(gtk_cell_renderer_toggle_activate): ditto.
* gtk/gtkliststore.c (gtk_list_store_get_flags): a
s/guint/GtkTreeModelFlags/ on the return type.
2002-10-14 22:50:18 +00:00
|
|
|
iter.user_data = level->parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
iter.user_data2 = SORT_LEVEL_PARENT_ELT (level);
|
Behaviour change, apply changes if the entry of the editable gets a focus
Tue Oct 15 00:53:14 2002 Kristian Rietveld <kris@gtk.org>
Behaviour change, apply changes if the entry of the editable gets
a focus out event (#82405).
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_focus_out_event):
new function,
(gtk_cell_renderer_text_start_editing): stop editing and apply
changes on focus-out.
Tue Oct 15 00:47:35 2002 Kristian Rietveld <kris@gtk.org>
Fixes an *evil* GtkTreeModelSort bug, #93629.
* gtk/gtktreemodel.c (release_row_references): return if the
refs->list is NULL.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_changed): if we
are swapping two rows (re-insertion on row_changed), also *emit*
a rows_reordered signal. oops.
Tue Oct 15 00:45:03 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtkliststore.c (gtk_list_store_remove_silently): free
the actual link after the node has been removed (#92014).
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_column_finalize):
free the cell_list and the child if the exists (#92014).
Tue Oct 15 00:40:25 2002 Kristian Rietveld <kris@gtk.org>
Don't accept drops if the model has been sorted, #93758)
* gtk/gtkliststore.c (gtk_list_store_row_drop_possible): return
FALSE if the list has been sorted.
* gtk/gtktreestore.c (gtk_tree_store_row_drop_possible): check
if drag_dest is a TreeStore, return FALSE if the tree has been
sorted.
Tue Oct 15 00:33:59 2002 Kristian Rietveld <kris@gtk.org>
Compiler warning fixage, (#85858, #85859, #85860, #85872)
* gtk/gtkcellrendererpixbuf (gtk_cell_renderer_pixbuf_render):
s/guint/GtkCellRendererState/.
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_render):
ditto.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render),
(gtk_cell_renderer_toggle_activate): ditto.
* gtk/gtkliststore.c (gtk_list_store_get_flags): a
s/guint/GtkTreeModelFlags/ on the return type.
2002-10-14 22:50:18 +00:00
|
|
|
|
|
|
|
tmppath = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_model_sort), &iter);
|
|
|
|
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
tmppath, &iter, new_order);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* toplevel */
|
|
|
|
tmppath = gtk_tree_path_new ();
|
|
|
|
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort), tmppath,
|
|
|
|
NULL, new_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (tmppath);
|
|
|
|
g_free (new_order);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* emit row_changed signal (at new location) */
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
2001-10-24 18:36:50 +00:00
|
|
|
gtk_tree_model_row_changed (GTK_TREE_MODEL (data), path, &iter);
|
2006-09-27 12:08:12 +00:00
|
|
|
gtk_tree_model_sort_unref_node (GTK_TREE_MODEL (data), &iter);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
2000-11-10 19:38:53 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
if (free_s_path)
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_path_free (start_s_path);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_row_inserted (GtkTreeModel *s_model,
|
|
|
|
GtkTreePath *s_path,
|
|
|
|
GtkTreeIter *s_iter,
|
|
|
|
gpointer data)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreePath *path;
|
2000-11-09 16:52:17 +00:00
|
|
|
GtkTreeIter iter;
|
2001-10-24 18:36:50 +00:00
|
|
|
GtkTreeIter real_s_iter;
|
|
|
|
|
|
|
|
gint i = 0;
|
|
|
|
|
|
|
|
gboolean free_s_path = FALSE;
|
|
|
|
|
|
|
|
SortElt *elt;
|
|
|
|
SortLevel *level;
|
|
|
|
SortLevel *parent_level = NULL;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
parent_level = level = SORT_LEVEL (priv->root);
|
2000-11-13 19:23:24 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_if_fail (s_path != NULL || s_iter != NULL);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (!s_path)
|
2000-11-11 00:02:05 +00:00
|
|
|
{
|
2001-10-24 18:36:50 +00:00
|
|
|
s_path = gtk_tree_model_get_path (s_model, s_iter);
|
|
|
|
free_s_path = TRUE;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
if (!s_iter)
|
|
|
|
gtk_tree_model_get_iter (s_model, &real_s_iter, s_path);
|
2001-10-19 20:53:08 +00:00
|
|
|
else
|
2001-10-24 18:36:50 +00:00
|
|
|
real_s_iter = *s_iter;
|
2000-11-11 00:02:05 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (!priv->root)
|
2001-10-24 18:36:50 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, -1);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
/* the build level already put the inserted iter in the level,
|
|
|
|
so no need to handle this signal anymore */
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
goto done_and_submit;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
/* find the parent level */
|
|
|
|
while (i < gtk_tree_path_get_depth (s_path) - 1)
|
|
|
|
{
|
2001-10-24 20:54:32 +00:00
|
|
|
gint j;
|
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
if (!level)
|
|
|
|
{
|
|
|
|
/* level not yet build, we won't cover this signal */
|
|
|
|
goto done;
|
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
if (level->array->len < gtk_tree_path_get_indices (s_path)[i])
|
|
|
|
{
|
2008-05-27 23:16:06 +00:00
|
|
|
g_warning ("%s: A node was inserted with a parent that's not in the tree.\n"
|
2001-10-24 18:36:50 +00:00
|
|
|
"This possibly means that a GtkTreeModel inserted a child node\n"
|
2008-05-27 23:16:06 +00:00
|
|
|
"before the parent was inserted.",
|
|
|
|
G_STRLOC);
|
2001-10-24 18:36:50 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 20:54:32 +00:00
|
|
|
elt = NULL;
|
|
|
|
for (j = 0; j < level->array->len; j++)
|
|
|
|
if (g_array_index (level->array, SortElt, j).offset == gtk_tree_path_get_indices (s_path)[i])
|
|
|
|
{
|
|
|
|
elt = &g_array_index (level->array, SortElt, j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_if_fail (elt != NULL);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
|
|
|
if (!elt->children)
|
|
|
|
{
|
|
|
|
/* not covering this signal */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = elt->children;
|
|
|
|
parent_level = level;
|
|
|
|
i++;
|
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
if (!parent_level)
|
2002-01-13 00:22:04 +00:00
|
|
|
goto done;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (level->ref_count == 0 && level != priv->root)
|
2005-08-23 20:33:42 +00:00
|
|
|
{
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, level);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
if (!gtk_tree_model_sort_insert_value (tree_model_sort,
|
|
|
|
parent_level,
|
|
|
|
s_path,
|
|
|
|
&real_s_iter))
|
|
|
|
goto done;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
done_and_submit:
|
2001-12-26 22:43:53 +00:00
|
|
|
path = gtk_real_tree_model_sort_convert_child_path_to_path (tree_model_sort,
|
|
|
|
s_path,
|
|
|
|
FALSE);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (!path)
|
2000-11-22 05:16:37 +00:00
|
|
|
return;
|
2000-11-13 19:23:24 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-03 18:29:20 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
2001-09-12 23:16:18 +00:00
|
|
|
gtk_tree_model_row_inserted (GTK_TREE_MODEL (data), path, &iter);
|
2000-11-10 19:38:53 +00:00
|
|
|
gtk_tree_path_free (path);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
2002-01-13 00:22:04 +00:00
|
|
|
done:
|
2001-10-24 18:36:50 +00:00
|
|
|
if (free_s_path)
|
|
|
|
gtk_tree_path_free (s_path);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
return;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-09-12 23:16:18 +00:00
|
|
|
gtk_tree_model_sort_row_has_child_toggled (GtkTreeModel *s_model,
|
|
|
|
GtkTreePath *s_path,
|
|
|
|
GtkTreeIter *s_iter,
|
|
|
|
gpointer data)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
|
2000-11-10 19:38:53 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
g_return_if_fail (s_path != NULL && s_iter != NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
path = gtk_real_tree_model_sort_convert_child_path_to_path (tree_model_sort, s_path, FALSE);
|
|
|
|
if (path == NULL)
|
2000-11-22 05:16:37 +00:00
|
|
|
return;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2000-11-10 19:38:53 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
2001-10-25 20:32:40 +00:00
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (data), path, &iter);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
gtk_tree_path_free (path);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-09-12 23:16:18 +00:00
|
|
|
gtk_tree_model_sort_row_deleted (GtkTreeModel *s_model,
|
|
|
|
GtkTreePath *s_path,
|
|
|
|
gpointer data)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
|
2001-10-24 18:36:50 +00:00
|
|
|
GtkTreePath *path = NULL;
|
2001-10-25 20:32:40 +00:00
|
|
|
SortElt *elt;
|
|
|
|
SortLevel *level;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gint offset;
|
|
|
|
gint i;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
g_return_if_fail (s_path != NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
path = gtk_real_tree_model_sort_convert_child_path_to_path (tree_model_sort, s_path, FALSE);
|
|
|
|
if (path == NULL)
|
2001-10-19 20:53:08 +00:00
|
|
|
return;
|
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
level = SORT_LEVEL (iter.user_data);
|
|
|
|
elt = SORT_ELT (iter.user_data2);
|
|
|
|
offset = elt->offset;
|
|
|
|
|
2002-02-12 17:48:02 +00:00
|
|
|
/* we _need_ to emit ::row_deleted before we start unreffing the node
|
|
|
|
* itself. This is because of the row refs, which start unreffing nodes
|
|
|
|
* when we emit ::row_deleted
|
|
|
|
*/
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
while (elt->ref_count > 0)
|
2002-02-09 01:28:00 +00:00
|
|
|
gtk_tree_model_sort_real_unref_node (GTK_TREE_MODEL (data), &iter, FALSE);
|
2001-10-25 20:32:40 +00:00
|
|
|
|
2004-03-01 23:34:08 +00:00
|
|
|
if (level->ref_count == 0)
|
2001-10-24 18:36:50 +00:00
|
|
|
{
|
2005-07-22 03:38:14 +00:00
|
|
|
/* 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.
|
|
|
|
*/
|
2002-02-09 01:28:00 +00:00
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
2001-10-25 20:32:40 +00:00
|
|
|
gtk_tree_path_free (path);
|
2010-12-18 04:49:27 +00:00
|
|
|
if (level == tree_model_sort->priv->root)
|
2005-07-22 03:38:14 +00:00
|
|
|
{
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort,
|
2010-12-18 04:49:27 +00:00
|
|
|
tree_model_sort->priv->root);
|
|
|
|
tree_model_sort->priv->root = NULL;
|
2005-07-22 03:38:14 +00:00
|
|
|
}
|
2001-10-24 18:36:50 +00:00
|
|
|
return;
|
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2002-02-09 01:28:00 +00:00
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
/* Remove the row */
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
if (elt->offset == g_array_index (level->array, SortElt, i).offset)
|
|
|
|
break;
|
|
|
|
|
|
|
|
g_array_remove_index (level->array, i);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
/* update all offsets */
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
elt = & (g_array_index (level->array, SortElt, i));
|
|
|
|
if (elt->offset > offset)
|
|
|
|
elt->offset--;
|
2001-12-26 22:43:53 +00:00
|
|
|
if (elt->children)
|
2009-09-06 11:35:37 +00:00
|
|
|
elt->children->parent_elt_index = i;
|
2000-11-10 19:38:53 +00:00
|
|
|
}
|
2001-10-25 20:32:40 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
static void
|
2001-09-12 23:16:18 +00:00
|
|
|
gtk_tree_model_sort_rows_reordered (GtkTreeModel *s_model,
|
|
|
|
GtkTreePath *s_path,
|
|
|
|
GtkTreeIter *s_iter,
|
|
|
|
gint *new_order,
|
|
|
|
gpointer data)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
SortElt *elt;
|
|
|
|
SortLevel *level;
|
2001-10-29 18:56:00 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
gint *tmp_array;
|
2001-11-01 20:46:01 +00:00
|
|
|
int i, j;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreePath *path;
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = GTK_TREE_MODEL_SORT (data);
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
g_return_if_fail (new_order != NULL);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2007-09-09 23:54:17 +00:00
|
|
|
if (s_path == NULL || gtk_tree_path_get_depth (s_path) == 0)
|
2001-10-19 20:53:08 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root == NULL)
|
2001-10-26 14:44:27 +00:00
|
|
|
return;
|
2001-10-29 18:56:00 +00:00
|
|
|
path = gtk_tree_path_new ();
|
2010-12-18 04:49:27 +00:00
|
|
|
level = SORT_LEVEL (priv->root);
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
else
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-26 14:44:27 +00:00
|
|
|
path = gtk_real_tree_model_sort_convert_child_path_to_path (tree_model_sort, s_path, FALSE);
|
|
|
|
if (path == NULL)
|
|
|
|
return;
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (data), &iter, path);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
level = SORT_LEVEL (iter.user_data);
|
|
|
|
elt = SORT_ELT (iter.user_data2);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
|
|
if (!elt->children)
|
2001-10-29 18:56:00 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return;
|
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
level = elt->children;
|
|
|
|
}
|
|
|
|
|
2001-10-26 14:44:27 +00:00
|
|
|
if (level->array->len < 2)
|
2001-10-19 20:53:08 +00:00
|
|
|
{
|
2001-10-29 18:56:00 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return;
|
|
|
|
}
|
2001-10-24 18:36:50 +00:00
|
|
|
|
2001-10-29 18:56:00 +00:00
|
|
|
tmp_array = g_new (int, level->array->len);
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
2001-11-01 20:46:01 +00:00
|
|
|
{
|
|
|
|
for (j = 0; j < level->array->len; j++)
|
|
|
|
{
|
|
|
|
if (g_array_index (level->array, SortElt, i).offset == new_order[j])
|
|
|
|
tmp_array[i] = j;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-29 18:56:00 +00:00
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
g_array_index (level->array, SortElt, i).offset = tmp_array[i];
|
|
|
|
g_free (tmp_array);
|
2001-11-01 20:46:01 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
|
|
|
|
priv->default_sort_func == NO_SORT_FUNC)
|
2001-10-29 18:56:00 +00:00
|
|
|
{
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_sort_level (tree_model_sort, level,
|
|
|
|
FALSE, FALSE);
|
2002-03-30 20:52:42 +00:00
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (gtk_tree_path_get_depth (path))
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
&iter,
|
|
|
|
path);
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
path, &iter, new_order);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
else
|
2001-10-24 18:36:50 +00:00
|
|
|
{
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
path, NULL, new_order);
|
|
|
|
}
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
2001-10-29 18:56:00 +00:00
|
|
|
gtk_tree_path_free (path);
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Fulfill our model requirements */
|
2002-07-05 17:25:16 +00:00
|
|
|
static GtkTreeModelFlags
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_get_flags (GtkTreeModel *tree_model)
|
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2003-12-13 15:20:28 +00:00
|
|
|
GtkTreeModelFlags flags;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (tree_model_sort->priv->child_model != NULL, 0);
|
2003-12-13 15:20:28 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
flags = gtk_tree_model_get_flags (tree_model_sort->priv->child_model);
|
2003-12-13 15:20:28 +00:00
|
|
|
|
|
|
|
if ((flags & GTK_TREE_MODEL_LIST_ONLY) == GTK_TREE_MODEL_LIST_ONLY)
|
|
|
|
return GTK_TREE_MODEL_LIST_ONLY;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
return 0;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model)
|
|
|
|
{
|
2001-06-14 23:25:52 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (tree_model_sort->priv->child_model == 0)
|
2001-06-14 23:25:52 +00:00
|
|
|
return 0;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
return gtk_tree_model_get_n_columns (tree_model_sort->priv->child_model);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GType
|
|
|
|
gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
|
2001-09-02 21:47:12 +00:00
|
|
|
gint index)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (tree_model_sort->priv->child_model != NULL, G_TYPE_INVALID);
|
2005-12-29 07:47:02 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
return gtk_tree_model_get_column_type (tree_model_sort->priv->child_model, index);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_get_iter (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
gint *indices;
|
|
|
|
SortLevel *level;
|
|
|
|
gint depth, i;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
indices = gtk_tree_path_get_indices (path);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root == NULL)
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, -1);
|
2010-12-18 04:49:27 +00:00
|
|
|
level = SORT_LEVEL (priv->root);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
depth = gtk_tree_path_get_depth (path);
|
|
|
|
if (depth == 0)
|
2011-05-09 07:51:50 +00:00
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
for (i = 0; i < depth - 1; i++)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
if ((level == NULL) ||
|
2002-05-24 16:24:04 +00:00
|
|
|
(indices[i] >= level->array->len))
|
2011-05-09 07:51:50 +00:00
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (g_array_index (level->array, SortElt, indices[i]).children == NULL)
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, indices[i]);
|
2001-10-19 20:53:08 +00:00
|
|
|
level = g_array_index (level->array, SortElt, indices[i]).children;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2003-12-17 22:47:55 +00:00
|
|
|
if (!level || indices[i] >= level->array->len)
|
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
iter->stamp = priv->stamp;
|
2001-10-19 20:53:08 +00:00
|
|
|
iter->user_data = level;
|
|
|
|
iter->user_data2 = &g_array_index (level->array, SortElt, indices[depth - 1]);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
return TRUE;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
gtk_tree_model_sort_get_path (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreePath *retval;
|
|
|
|
SortLevel *level;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint elt_index;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, NULL);
|
|
|
|
g_return_val_if_fail (priv->stamp == iter->stamp, NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
retval = gtk_tree_path_new ();
|
2009-09-06 11:35:37 +00:00
|
|
|
|
|
|
|
level = SORT_LEVEL (iter->user_data);
|
|
|
|
elt_index = SORT_LEVEL_ELT_INDEX (level, iter->user_data2);
|
|
|
|
|
|
|
|
while (level)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_path_prepend_index (retval, elt_index);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
elt_index = level->parent_elt_index;
|
2001-10-19 20:53:08 +00:00
|
|
|
level = level->parent_level;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
return retval;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_get_value (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeIter child_iter;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->child_model != NULL);
|
2005-12-29 07:47:02 +00:00
|
|
|
g_return_if_fail (VALID_ITER (iter, tree_model_sort));
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
GET_CHILD_ITER (tree_model_sort, &child_iter, iter);
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_get_value (priv->child_model,
|
2001-09-02 21:47:12 +00:00
|
|
|
&child_iter, column, value);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_next (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *level;
|
2000-11-09 16:52:17 +00:00
|
|
|
SortElt *elt;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (priv->stamp == iter->stamp, FALSE);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
level = iter->user_data;
|
|
|
|
elt = iter->user_data2;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (elt - (SortElt *)level->array->data >= level->array->len - 1)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
iter->user_data2 = elt + 1;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-01-06 04:39:11 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_previous (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
|
|
|
SortLevel *level;
|
|
|
|
SortElt *elt;
|
|
|
|
|
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (priv->stamp == iter->stamp, FALSE);
|
|
|
|
|
|
|
|
level = iter->user_data;
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
|
|
if (elt == (SortElt *)level->array->data)
|
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
iter->user_data2 = elt - 1;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_children (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *level;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
iter->stamp = 0;
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
2005-12-29 07:47:02 +00:00
|
|
|
if (parent)
|
2006-01-14 19:58:04 +00:00
|
|
|
g_return_val_if_fail (VALID_ITER (parent, tree_model_sort), FALSE);
|
2000-11-22 05:16:37 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (parent == NULL)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root == NULL)
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, -1);
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root == NULL)
|
2001-10-19 20:53:08 +00:00
|
|
|
return FALSE;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
level = priv->root;
|
|
|
|
iter->stamp = priv->stamp;
|
2001-10-19 20:53:08 +00:00
|
|
|
iter->user_data = level;
|
|
|
|
iter->user_data2 = level->array->data;
|
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
else
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
SortElt *elt;
|
|
|
|
|
|
|
|
level = SORT_LEVEL (parent->user_data);
|
|
|
|
elt = SORT_ELT (parent->user_data2);
|
|
|
|
|
|
|
|
if (elt->children == NULL)
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level,
|
|
|
|
SORT_LEVEL_ELT_INDEX (level, elt));
|
|
|
|
|
|
|
|
if (elt->children == NULL)
|
2001-09-02 21:47:12 +00:00
|
|
|
return FALSE;
|
2009-09-06 11:35:37 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
iter->stamp = priv->stamp;
|
2009-09-06 11:35:37 +00:00
|
|
|
iter->user_data = elt->children;
|
|
|
|
iter->user_data2 = elt->children->array->data;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_has_child (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeIter child_iter;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
2005-12-29 07:47:02 +00:00
|
|
|
g_return_val_if_fail (VALID_ITER (iter, tree_model_sort), FALSE);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
GET_CHILD_ITER (tree_model_sort, &child_iter, iter);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
return gtk_tree_model_iter_has_child (priv->child_model, &child_iter);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeIter child_iter;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, 0);
|
2005-12-29 07:47:02 +00:00
|
|
|
if (iter)
|
|
|
|
g_return_val_if_fail (VALID_ITER (iter, tree_model_sort), 0);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (iter == NULL)
|
2010-12-18 04:49:27 +00:00
|
|
|
return gtk_tree_model_iter_n_children (priv->child_model, NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
GET_CHILD_ITER (tree_model_sort, &child_iter, iter);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
return gtk_tree_model_iter_n_children (priv->child_model, &child_iter);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
gint n)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2005-12-29 07:47:02 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *level;
|
2001-10-25 20:32:40 +00:00
|
|
|
/* We have this for the iter == parent case */
|
|
|
|
GtkTreeIter children;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
if (parent)
|
|
|
|
g_return_val_if_fail (VALID_ITER (parent, tree_model_sort), FALSE);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
/* Use this instead of has_child to force us to build the level, if needed */
|
|
|
|
if (gtk_tree_model_sort_iter_children (tree_model, &children, parent) == FALSE)
|
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
level = children.user_data;
|
2001-10-19 20:53:08 +00:00
|
|
|
if (n >= level->array->len)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
iter->stamp = tree_model_sort->priv->stamp;
|
2001-10-25 20:32:40 +00:00
|
|
|
iter->user_data = level;
|
2001-10-19 20:53:08 +00:00
|
|
|
iter->user_data2 = &g_array_index (level->array, SortElt, n);
|
2001-10-25 20:32:40 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_parent (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *child)
|
2005-12-29 07:47:02 +00:00
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *level;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
iter->stamp = 0;
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
2005-12-29 07:47:02 +00:00
|
|
|
g_return_val_if_fail (VALID_ITER (child, tree_model_sort), FALSE);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
level = child->user_data;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (level->parent_level)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
iter->stamp = priv->stamp;
|
2001-10-19 20:53:08 +00:00
|
|
|
iter->user_data = level->parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
iter->user_data2 = SORT_LEVEL_PARENT_ELT (level);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-09 00:19:11 +00:00
|
|
|
gtk_tree_model_sort_ref_node (GtkTreeModel *tree_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter *iter)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2002-02-08 17:13:14 +00:00
|
|
|
GtkTreeIter child_iter;
|
2009-09-06 11:35:37 +00:00
|
|
|
SortLevel *level, *parent_level;
|
2001-09-02 21:47:12 +00:00
|
|
|
SortElt *elt;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->child_model != NULL);
|
2005-12-29 07:47:02 +00:00
|
|
|
g_return_if_fail (VALID_ITER (iter, tree_model_sort));
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
GET_CHILD_ITER (tree_model_sort, &child_iter, iter);
|
2002-02-08 17:13:14 +00:00
|
|
|
|
2007-03-10 17:25:51 +00:00
|
|
|
/* Reference the node in the child model */
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_ref_node (priv->child_model, &child_iter);
|
2002-02-08 17:13:14 +00:00
|
|
|
|
2007-03-10 17:25:51 +00:00
|
|
|
/* Increase the reference count of this element and its level */
|
2001-10-19 20:53:08 +00:00
|
|
|
level = iter->user_data;
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
|
|
elt->ref_count++;
|
|
|
|
level->ref_count++;
|
2007-03-10 17:25:51 +00:00
|
|
|
|
|
|
|
/* Increase the reference count of all parent elements */
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_level = level->parent_level;
|
|
|
|
parent_elt_index = level->parent_elt_index;
|
2007-03-10 17:25:51 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
while (parent_level)
|
2007-03-10 17:25:51 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
GtkTreeIter tmp_iter;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
tmp_iter.stamp = priv->stamp;
|
2009-09-06 11:35:37 +00:00
|
|
|
tmp_iter.user_data = parent_level;
|
|
|
|
tmp_iter.user_data2 = &g_array_index (parent_level->array, SortElt, parent_elt_index);
|
|
|
|
|
2007-03-10 17:25:51 +00:00
|
|
|
gtk_tree_model_sort_ref_node (tree_model, &tmp_iter);
|
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt_index = parent_level->parent_elt_index;
|
|
|
|
parent_level = parent_level->parent_level;
|
2007-03-10 17:25:51 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (level->ref_count == 1)
|
|
|
|
{
|
|
|
|
SortLevel *parent_level = level->parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index = level->parent_elt_index;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* We were at zero -- time to decrement the zero_ref_count val */
|
2006-09-27 12:08:12 +00:00
|
|
|
while (parent_level)
|
2009-09-06 11:35:37 +00:00
|
|
|
{
|
|
|
|
g_array_index (parent_level->array, SortElt, parent_elt_index).zero_ref_count--;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt_index = parent_level->parent_elt_index;
|
2006-09-27 12:08:12 +00:00
|
|
|
parent_level = parent_level->parent_level;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2006-09-27 12:08:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root != level)
|
|
|
|
priv->zero_ref_count--;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-02-09 01:28:00 +00:00
|
|
|
gtk_tree_model_sort_real_unref_node (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gboolean propagate_unref)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) tree_model;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2009-09-06 11:35:37 +00:00
|
|
|
SortLevel *level, *parent_level;
|
2001-09-02 21:47:12 +00:00
|
|
|
SortElt *elt;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->child_model != NULL);
|
2005-12-29 07:47:02 +00:00
|
|
|
g_return_if_fail (VALID_ITER (iter, tree_model_sort));
|
2002-02-08 17:13:14 +00:00
|
|
|
|
2002-02-09 01:28:00 +00:00
|
|
|
if (propagate_unref)
|
2005-10-24 19:01:36 +00:00
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
GET_CHILD_ITER (tree_model_sort, &child_iter, iter);
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_unref_node (priv->child_model, &child_iter);
|
2005-10-24 19:01:36 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
level = iter->user_data;
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
g_return_if_fail (elt->ref_count > 0);
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
elt->ref_count--;
|
|
|
|
level->ref_count--;
|
Behaviour change, apply changes if the entry of the editable gets a focus
Tue Oct 15 00:53:14 2002 Kristian Rietveld <kris@gtk.org>
Behaviour change, apply changes if the entry of the editable gets
a focus out event (#82405).
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_focus_out_event):
new function,
(gtk_cell_renderer_text_start_editing): stop editing and apply
changes on focus-out.
Tue Oct 15 00:47:35 2002 Kristian Rietveld <kris@gtk.org>
Fixes an *evil* GtkTreeModelSort bug, #93629.
* gtk/gtktreemodel.c (release_row_references): return if the
refs->list is NULL.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_row_changed): if we
are swapping two rows (re-insertion on row_changed), also *emit*
a rows_reordered signal. oops.
Tue Oct 15 00:45:03 2002 Kristian Rietveld <kris@gtk.org>
* gtk/gtkliststore.c (gtk_list_store_remove_silently): free
the actual link after the node has been removed (#92014).
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_column_finalize):
free the cell_list and the child if the exists (#92014).
Tue Oct 15 00:40:25 2002 Kristian Rietveld <kris@gtk.org>
Don't accept drops if the model has been sorted, #93758)
* gtk/gtkliststore.c (gtk_list_store_row_drop_possible): return
FALSE if the list has been sorted.
* gtk/gtktreestore.c (gtk_tree_store_row_drop_possible): check
if drag_dest is a TreeStore, return FALSE if the tree has been
sorted.
Tue Oct 15 00:33:59 2002 Kristian Rietveld <kris@gtk.org>
Compiler warning fixage, (#85858, #85859, #85860, #85872)
* gtk/gtkcellrendererpixbuf (gtk_cell_renderer_pixbuf_render):
s/guint/GtkCellRendererState/.
* gtk/gtkcellrenderertext.c (gtk_cell_renderer_text_render):
ditto.
* gtk/gtkcellrenderertoggle.c (gtk_cell_renderer_toggle_render),
(gtk_cell_renderer_toggle_activate): ditto.
* gtk/gtkliststore.c (gtk_list_store_get_flags): a
s/guint/GtkTreeModelFlags/ on the return type.
2002-10-14 22:50:18 +00:00
|
|
|
|
2007-03-10 17:25:51 +00:00
|
|
|
/* Decrease the reference count of all parent elements */
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_level = level->parent_level;
|
|
|
|
parent_elt_index = level->parent_elt_index;
|
2007-03-10 17:25:51 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
while (parent_level)
|
2007-03-10 17:25:51 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
GtkTreeIter tmp_iter;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
tmp_iter.stamp = priv->stamp;
|
2009-09-06 11:35:37 +00:00
|
|
|
tmp_iter.user_data = parent_level;
|
|
|
|
tmp_iter.user_data2 = &g_array_index (parent_level->array, SortElt, parent_elt_index);
|
|
|
|
|
2007-03-10 17:25:51 +00:00
|
|
|
gtk_tree_model_sort_real_unref_node (tree_model, &tmp_iter, FALSE);
|
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt_index = parent_level->parent_elt_index;
|
|
|
|
parent_level = parent_level->parent_level;
|
2007-03-10 17:25:51 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (level->ref_count == 0)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *parent_level = level->parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index = level->parent_elt_index;
|
2001-10-25 20:32:40 +00:00
|
|
|
|
2001-12-26 22:43:53 +00:00
|
|
|
/* We are at zero -- time to increment the zero_ref_count val */
|
2001-10-25 20:32:40 +00:00
|
|
|
while (parent_level)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
g_array_index (parent_level->array, SortElt, parent_elt_index).zero_ref_count++;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt_index = parent_level->parent_elt_index;
|
2001-10-25 20:32:40 +00:00
|
|
|
parent_level = parent_level->parent_level;
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
2006-09-27 12:08:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root != level)
|
|
|
|
priv->zero_ref_count++;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-06-14 23:25:52 +00:00
|
|
|
}
|
|
|
|
|
2002-02-09 01:28:00 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_unref_node (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
gtk_tree_model_sort_real_unref_node (tree_model, iter, TRUE);
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* Sortable interface */
|
2001-06-14 23:25:52 +00:00
|
|
|
static gboolean
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_get_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint *sort_column_id,
|
|
|
|
GtkSortType *order)
|
2001-06-14 23:25:52 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-06-14 23:25:52 +00:00
|
|
|
|
|
|
|
if (sort_column_id)
|
2010-12-18 04:49:27 +00:00
|
|
|
*sort_column_id = priv->sort_column_id;
|
2001-06-14 23:25:52 +00:00
|
|
|
if (order)
|
2010-12-18 04:49:27 +00:00
|
|
|
*order = priv->order;
|
2001-06-14 23:25:52 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID ||
|
|
|
|
priv->sort_column_id == GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID)
|
2004-11-30 21:45:26 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2001-06-14 23:25:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkSortType order)
|
2001-06-14 23:25:52 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2009-01-03 06:57:10 +00:00
|
|
|
if (sort_column_id != GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
2009-01-03 06:57:10 +00:00
|
|
|
if (sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
|
|
|
{
|
|
|
|
GtkTreeDataSortHeader *header = NULL;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
header = _gtk_tree_data_list_get_header (priv->sort_list,
|
2009-01-03 06:57:10 +00:00
|
|
|
sort_column_id);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2009-01-03 06:57:10 +00:00
|
|
|
/* we want to make sure that we have a function */
|
|
|
|
g_return_if_fail (header != NULL);
|
|
|
|
g_return_if_fail (header->func != NULL);
|
|
|
|
}
|
|
|
|
else
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->default_sort_func != NULL);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == sort_column_id)
|
2009-01-03 06:57:10 +00:00
|
|
|
{
|
|
|
|
if (sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->order == order)
|
2009-01-03 06:57:10 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
2001-10-19 20:53:08 +00:00
|
|
|
return;
|
2009-01-03 06:57:10 +00:00
|
|
|
}
|
2001-06-14 23:25:52 +00:00
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->sort_column_id = sort_column_id;
|
|
|
|
priv->order = order;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2001-06-14 23:25:52 +00:00
|
|
|
gtk_tree_sortable_sort_column_changed (sortable);
|
2003-01-27 21:41:06 +00:00
|
|
|
|
|
|
|
gtk_tree_model_sort_sort (tree_model_sort);
|
2001-06-14 23:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-06-15 23:03:27 +00:00
|
|
|
gtk_tree_model_sort_set_sort_func (GtkTreeSortable *sortable,
|
2001-10-19 20:53:08 +00:00
|
|
|
gint sort_column_id,
|
|
|
|
GtkTreeIterCompareFunc func,
|
|
|
|
gpointer data,
|
2008-06-18 09:12:32 +00:00
|
|
|
GDestroyNotify destroy)
|
2001-06-14 23:25:52 +00:00
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *) sortable;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-06-14 23:25:52 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->sort_list = _gtk_tree_data_list_set_header (priv->sort_list,
|
|
|
|
sort_column_id,
|
|
|
|
func, data, destroy);
|
2003-01-27 21:41:06 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == sort_column_id)
|
2003-01-27 21:41:06 +00:00
|
|
|
gtk_tree_model_sort_sort (tree_model_sort);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2001-10-03 18:29:20 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_set_default_sort_func (GtkTreeSortable *sortable,
|
|
|
|
GtkTreeIterCompareFunc func,
|
|
|
|
gpointer data,
|
2008-06-18 09:12:32 +00:00
|
|
|
GDestroyNotify destroy)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->default_sort_destroy)
|
2002-03-03 05:41:28 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GDestroyNotify d = priv->default_sort_destroy;
|
2002-03-03 05:41:28 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->default_sort_destroy = NULL;
|
|
|
|
d (priv->default_sort_data);
|
2002-03-03 05:41:28 +00:00
|
|
|
}
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->default_sort_func = func;
|
|
|
|
priv->default_sort_data = data;
|
|
|
|
priv->default_sort_destroy = destroy;
|
2003-01-27 21:41:06 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
2003-01-27 21:41:06 +00:00
|
|
|
gtk_tree_model_sort_sort (tree_model_sort);
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_has_default_sort_func (GtkTreeSortable *sortable)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)sortable;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
return (tree_model_sort->priv->default_sort_func != NULL);
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
|
|
|
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
/* DragSource interface */
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_row_draggable (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)drag_source;
|
|
|
|
GtkTreePath *child_path;
|
|
|
|
gboolean draggable;
|
|
|
|
|
|
|
|
child_path = gtk_tree_model_sort_convert_path_to_child_path (tree_model_sort,
|
|
|
|
path);
|
2010-12-18 04:49:27 +00:00
|
|
|
draggable = gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (tree_model_sort->priv->child_model), child_path);
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
gtk_tree_path_free (child_path);
|
|
|
|
|
|
|
|
return draggable;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkSelectionData *selection_data)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)drag_source;
|
|
|
|
GtkTreePath *child_path;
|
|
|
|
gboolean gotten;
|
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
child_path = gtk_tree_model_sort_convert_path_to_child_path (tree_model_sort, path);
|
2010-12-18 04:49:27 +00:00
|
|
|
gotten = gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (tree_model_sort->priv->child_model), child_path, selection_data);
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
gtk_tree_path_free (child_path);
|
|
|
|
|
|
|
|
return gotten;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_drag_data_delete (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)drag_source;
|
|
|
|
GtkTreePath *child_path;
|
|
|
|
gboolean deleted;
|
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
child_path = gtk_tree_model_sort_convert_path_to_child_path (tree_model_sort, path);
|
2010-12-18 04:49:27 +00:00
|
|
|
deleted = gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (tree_model_sort->priv->child_model), child_path);
|
Fixes #110249, reworked patch from Joshua N Pritikin.
Thu Dec 18 19:13:12 2003 Kristian Rietveld <kris@gtk.org>
Fixes #110249, reworked patch from Joshua N Pritikin.
* gtk/gtktreemodelsort.c (gtk_tree_model_sort_get_type),
(gtk_tree_model_sort_tree_drag_source_init),
(gtk_tree_model_sort_row_draggable),
(gtk_tree_model_sort_drag_data_get),
(gtk_tree_model_sort_drag_data_delete): implement GtkTreeDragSource.
* gtk/gtktreemodelfilter.c (gtk_tree_model_filter_get_type),
(gtk_tree_model_filter_tree_drag_source_init),
(gtk_tree_model_filter_row_draggable),
(gtk_tree_model_filter_drag_data_get),
(gtk_tree_model_filter_drag_data_delete): ditto.
2003-12-18 18:19:05 +00:00
|
|
|
gtk_tree_path_free (child_path);
|
|
|
|
|
|
|
|
return deleted;
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* sorting code - private */
|
2001-09-02 21:47:12 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_model_sort_compare_func (gconstpointer a,
|
2001-10-19 20:53:08 +00:00
|
|
|
gconstpointer b,
|
|
|
|
gpointer user_data)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-31 00:20:15 +00:00
|
|
|
SortData *data = (SortData *)user_data;
|
|
|
|
GtkTreeModelSort *tree_model_sort = data->tree_model_sort;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-31 00:20:15 +00:00
|
|
|
SortTuple *sa = (SortTuple *)a;
|
|
|
|
SortTuple *sb = (SortTuple *)b;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreeIter iter_a, iter_b;
|
2001-10-31 00:20:15 +00:00
|
|
|
gint retval;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
/* shortcut, if we've the same offsets here, they should be equal */
|
|
|
|
if (sa->offset == sb->offset)
|
|
|
|
return 0;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
2001-10-31 00:20:15 +00:00
|
|
|
iter_a = sa->elt->iter;
|
|
|
|
iter_b = sb->elt->iter;
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-10-31 00:20:15 +00:00
|
|
|
data->parent_path_indices [data->parent_path_depth-1] = sa->elt->offset;
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->child_model), &iter_a, data->parent_path);
|
2001-10-31 00:20:15 +00:00
|
|
|
data->parent_path_indices [data->parent_path_depth-1] = sb->elt->offset;
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (priv->child_model), &iter_b, data->parent_path);
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
retval = (* data->sort_func) (GTK_TREE_MODEL (priv->child_model),
|
2001-10-31 00:20:15 +00:00
|
|
|
&iter_a, &iter_b,
|
|
|
|
data->sort_data);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->order == GTK_SORT_DESCENDING)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
|
|
|
if (retval > 0)
|
2001-10-19 20:53:08 +00:00
|
|
|
retval = -1;
|
2001-09-02 21:47:12 +00:00
|
|
|
else if (retval < 0)
|
2001-10-19 20:53:08 +00:00
|
|
|
retval = 1;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-10-03 18:29:20 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_model_sort_offset_compare_func (gconstpointer a,
|
|
|
|
gconstpointer b,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
gint retval;
|
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
SortTuple *sa = (SortTuple *)a;
|
|
|
|
SortTuple *sb = (SortTuple *)b;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
|
|
SortData *data = (SortData *)user_data;
|
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
if (sa->elt->offset < sb->elt->offset)
|
2001-10-03 18:29:20 +00:00
|
|
|
retval = -1;
|
2001-10-31 00:20:15 +00:00
|
|
|
else if (sa->elt->offset > sb->elt->offset)
|
2001-10-03 18:29:20 +00:00
|
|
|
retval = 1;
|
|
|
|
else
|
|
|
|
retval = 0;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (data->tree_model_sort->priv->order == GTK_SORT_DESCENDING)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
|
|
|
if (retval > 0)
|
|
|
|
retval = -1;
|
|
|
|
else if (retval < 0)
|
|
|
|
retval = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
static void
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_sort_level (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *level,
|
|
|
|
gboolean recurse,
|
|
|
|
gboolean emit_reordered)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-09-02 21:47:12 +00:00
|
|
|
gint i;
|
2006-09-27 12:08:12 +00:00
|
|
|
gint ref_offset;
|
2001-09-02 21:47:12 +00:00
|
|
|
GArray *sort_array;
|
|
|
|
GArray *new_array;
|
2001-10-19 20:53:08 +00:00
|
|
|
gint *new_order;
|
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
SortData data;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
g_return_if_fail (level != NULL);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (level->array->len < 1 && !((SortElt *)level->array->data)->children)
|
2001-09-02 21:47:12 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
iter.stamp = priv->stamp;
|
2006-09-27 12:08:12 +00:00
|
|
|
iter.user_data = level;
|
|
|
|
iter.user_data2 = &g_array_index (level->array, SortElt, 0);
|
|
|
|
|
|
|
|
gtk_tree_model_sort_ref_node (GTK_TREE_MODEL (tree_model_sort), &iter);
|
|
|
|
ref_offset = g_array_index (level->array, SortElt, 0).offset;
|
2005-07-22 03:38:14 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
/* Set up data */
|
|
|
|
data.tree_model_sort = tree_model_sort;
|
2009-09-06 11:35:37 +00:00
|
|
|
if (level->parent_elt_index >= 0)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-31 00:20:15 +00:00
|
|
|
data.parent_path = gtk_tree_model_sort_elt_get_path (level->parent_level,
|
2009-09-06 11:35:37 +00:00
|
|
|
SORT_LEVEL_PARENT_ELT (level));
|
2001-10-31 00:20:15 +00:00
|
|
|
gtk_tree_path_append_index (data.parent_path, 0);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-24 04:18:44 +00:00
|
|
|
data.parent_path = gtk_tree_path_new_first ();
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-31 00:20:15 +00:00
|
|
|
data.parent_path_depth = gtk_tree_path_get_depth (data.parent_path);
|
|
|
|
data.parent_path_indices = gtk_tree_path_get_indices (data.parent_path);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
/* make the array to be sorted */
|
2001-10-19 20:53:08 +00:00
|
|
|
sort_array = g_array_sized_new (FALSE, FALSE, sizeof (SortTuple), level->array->len);
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
|
|
|
SortTuple tuple;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
tuple.elt = &g_array_index (level->array, SortElt, i);
|
2001-10-31 00:20:15 +00:00
|
|
|
tuple.offset = i;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
|
|
g_array_append_val (sort_array, tuple);
|
|
|
|
}
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
2001-10-31 00:20:15 +00:00
|
|
|
{
|
|
|
|
GtkTreeDataSortHeader *header = NULL;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
header = _gtk_tree_data_list_get_header (priv->sort_list,
|
|
|
|
priv->sort_column_id);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
g_return_if_fail (header != NULL);
|
|
|
|
g_return_if_fail (header->func != NULL);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
data.sort_func = header->func;
|
|
|
|
data.sort_data = header->data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* absolutely SHOULD NOT happen: */
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->default_sort_func != NULL);
|
2001-10-31 00:20:15 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
data.sort_func = priv->default_sort_func;
|
|
|
|
data.sort_data = priv->default_sort_data;
|
2001-10-31 00:20:15 +00:00
|
|
|
}
|
|
|
|
|
2002-02-12 01:00:22 +00:00
|
|
|
if (data.sort_func == NO_SORT_FUNC)
|
|
|
|
g_array_sort_with_data (sort_array,
|
|
|
|
gtk_tree_model_sort_offset_compare_func,
|
|
|
|
&data);
|
2001-10-03 18:29:20 +00:00
|
|
|
else
|
2002-02-12 01:00:22 +00:00
|
|
|
g_array_sort_with_data (sort_array,
|
|
|
|
gtk_tree_model_sort_compare_func,
|
|
|
|
&data);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
gtk_tree_path_free (data.parent_path);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
new_array = g_array_sized_new (FALSE, FALSE, sizeof (SortElt), level->array->len);
|
|
|
|
new_order = g_new (gint, level->array->len);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
for (i = 0; i < level->array->len; i++)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-31 00:20:15 +00:00
|
|
|
SortElt *elt;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
elt = g_array_index (sort_array, SortTuple, i).elt;
|
|
|
|
new_order[i] = g_array_index (sort_array, SortTuple, i).offset;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-31 00:20:15 +00:00
|
|
|
g_array_append_val (new_array, *elt);
|
|
|
|
if (elt->children)
|
2009-09-06 11:35:37 +00:00
|
|
|
elt->children->parent_elt_index = i;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_array_free (level->array, TRUE);
|
|
|
|
level->array = new_array;
|
|
|
|
g_array_free (sort_array, TRUE);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
|
|
if (emit_reordered)
|
|
|
|
{
|
2002-04-01 20:40:58 +00:00
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
2009-09-06 11:35:37 +00:00
|
|
|
if (level->parent_elt_index >= 0)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
iter.stamp = priv->stamp;
|
2001-10-19 20:53:08 +00:00
|
|
|
iter.user_data = level->parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
iter.user_data2 = SORT_LEVEL_PARENT_ELT (level);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
&iter);
|
|
|
|
|
2001-09-12 23:16:18 +00:00
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort), path,
|
|
|
|
&iter, new_order);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* toplevel list */
|
|
|
|
path = gtk_tree_path_new ();
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_model_sort), path,
|
|
|
|
NULL, new_order);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2001-12-26 22:43:53 +00:00
|
|
|
|
|
|
|
/* recurse, if possible */
|
|
|
|
if (recurse)
|
|
|
|
{
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
SortElt *elt = &g_array_index (level->array, SortElt, i);
|
|
|
|
|
|
|
|
if (elt->children)
|
|
|
|
gtk_tree_model_sort_sort_level (tree_model_sort,
|
|
|
|
elt->children,
|
|
|
|
TRUE, emit_reordered);
|
|
|
|
}
|
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-09-02 21:47:12 +00:00
|
|
|
g_free (new_order);
|
2005-07-22 03:38:14 +00:00
|
|
|
|
2006-09-27 12:08:12 +00:00
|
|
|
/* get the iter we referenced at the beginning of this function and
|
|
|
|
* unref it again
|
|
|
|
*/
|
2010-12-18 04:49:27 +00:00
|
|
|
iter.stamp = priv->stamp;
|
2006-09-27 12:08:12 +00:00
|
|
|
iter.user_data = level;
|
|
|
|
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
if (g_array_index (level->array, SortElt, i).offset == ref_offset)
|
|
|
|
{
|
|
|
|
iter.user_data2 = &g_array_index (level->array, SortElt, i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_model_sort_unref_node (GTK_TREE_MODEL (tree_model_sort), &iter);
|
2002-01-15 00:12:30 +00:00
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_sort (GtkTreeModelSort *tree_model_sort)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
|
|
|
|
|
|
|
if (priv->sort_column_id == GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID)
|
2009-01-03 06:57:10 +00:00
|
|
|
return;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (!priv->root)
|
2002-01-13 00:22:04 +00:00
|
|
|
return;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
|
|
|
GtkTreeDataSortHeader *header = NULL;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
header = _gtk_tree_data_list_get_header (priv->sort_list,
|
|
|
|
priv->sort_column_id);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
|
|
/* we want to make sure that we have a function */
|
|
|
|
g_return_if_fail (header != NULL);
|
|
|
|
g_return_if_fail (header->func != NULL);
|
|
|
|
}
|
|
|
|
else
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->default_sort_func != NULL);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_sort_sort_level (tree_model_sort, priv->root,
|
2001-10-19 20:53:08 +00:00
|
|
|
TRUE, TRUE);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2000-12-20 00:37:58 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* signal helpers */
|
2000-12-20 00:37:58 +00:00
|
|
|
static gint
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_level_find_insert (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *level,
|
|
|
|
GtkTreeIter *iter,
|
2003-08-15 18:13:54 +00:00
|
|
|
gint skip_index)
|
2000-12-20 00:37:58 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2003-06-04 23:44:52 +00:00
|
|
|
gint start, middle, end;
|
2000-12-20 00:37:58 +00:00
|
|
|
gint cmp;
|
|
|
|
SortElt *tmp_elt;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreeIter tmp_iter;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
|
|
GtkTreeIterCompareFunc func;
|
|
|
|
gpointer data;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
2002-02-12 01:00:22 +00:00
|
|
|
{
|
|
|
|
GtkTreeDataSortHeader *header;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
header = _gtk_tree_data_list_get_header (priv->sort_list,
|
|
|
|
priv->sort_column_id);
|
2002-02-12 01:00:22 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (header != NULL, 0);
|
|
|
|
|
|
|
|
func = header->func;
|
|
|
|
data = header->data;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
func = priv->default_sort_func;
|
|
|
|
data = priv->default_sort_data;
|
2002-02-12 01:00:22 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (func != NO_SORT_FUNC, 0);
|
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2002-02-12 01:00:22 +00:00
|
|
|
g_return_val_if_fail (func != NULL, 0);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2003-06-04 23:44:52 +00:00
|
|
|
start = 0;
|
|
|
|
end = level->array->len;
|
2003-08-15 18:13:54 +00:00
|
|
|
if (skip_index < 0)
|
2003-06-04 23:44:52 +00:00
|
|
|
skip_index = end;
|
2003-08-15 18:13:54 +00:00
|
|
|
else
|
|
|
|
end--;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2003-06-04 23:44:52 +00:00
|
|
|
if (start == end)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
while (start != end)
|
|
|
|
{
|
|
|
|
middle = (start + end) / 2;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2003-06-04 23:44:52 +00:00
|
|
|
if (middle < skip_index)
|
|
|
|
tmp_elt = &(g_array_index (level->array, SortElt, middle));
|
|
|
|
else
|
|
|
|
tmp_elt = &(g_array_index (level->array, SortElt, middle + 1));
|
|
|
|
|
|
|
|
if (!GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
|
|
|
{
|
|
|
|
GtkTreePath *path = gtk_tree_model_sort_elt_get_path (level, tmp_elt);
|
2010-12-18 04:49:27 +00:00
|
|
|
gtk_tree_model_get_iter (priv->child_model,
|
2003-06-04 23:44:52 +00:00
|
|
|
&tmp_iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
tmp_iter = tmp_elt->iter;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->order == GTK_SORT_ASCENDING)
|
|
|
|
cmp = (* func) (GTK_TREE_MODEL (priv->child_model),
|
2001-10-03 18:29:20 +00:00
|
|
|
&tmp_iter, iter, data);
|
2001-09-02 21:47:12 +00:00
|
|
|
else
|
2010-12-18 04:49:27 +00:00
|
|
|
cmp = (* func) (GTK_TREE_MODEL (priv->child_model),
|
2001-10-03 18:29:20 +00:00
|
|
|
iter, &tmp_iter, data);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2003-06-04 23:44:52 +00:00
|
|
|
if (cmp <= 0)
|
|
|
|
start = middle + 1;
|
|
|
|
else
|
|
|
|
end = middle;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2003-06-04 23:44:52 +00:00
|
|
|
if (cmp <= 0)
|
|
|
|
return middle + 1;
|
|
|
|
else
|
|
|
|
return middle;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2000-12-20 00:37:58 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_insert_value (GtkTreeModelSort *tree_model_sort,
|
2001-10-24 18:36:50 +00:00
|
|
|
SortLevel *level,
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreePath *s_path,
|
|
|
|
GtkTreeIter *s_iter)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-24 18:36:50 +00:00
|
|
|
gint offset, index, i;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
SortElt elt;
|
|
|
|
SortElt *tmp_elt;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
offset = gtk_tree_path_get_indices (s_path)[gtk_tree_path_get_depth (s_path) - 1];
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
|
|
|
elt.iter = *s_iter;
|
|
|
|
elt.offset = offset;
|
|
|
|
elt.zero_ref_count = 0;
|
|
|
|
elt.ref_count = 0;
|
|
|
|
elt.children = NULL;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2002-03-07 06:04:03 +00:00
|
|
|
/* update all larger offsets */
|
|
|
|
tmp_elt = SORT_ELT (level->array->data);
|
|
|
|
for (i = 0; i < level->array->len; i++, tmp_elt++)
|
|
|
|
if (tmp_elt->offset >= offset)
|
|
|
|
tmp_elt->offset++;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID &&
|
|
|
|
priv->default_sort_func == NO_SORT_FUNC)
|
2002-02-12 01:00:22 +00:00
|
|
|
index = offset;
|
|
|
|
else
|
|
|
|
index = gtk_tree_model_sort_level_find_insert (tree_model_sort,
|
|
|
|
level, s_iter,
|
2003-08-15 18:13:54 +00:00
|
|
|
-1);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
g_array_insert_vals (level->array, index, &elt, 1);
|
|
|
|
tmp_elt = SORT_ELT (level->array->data);
|
2001-10-24 18:36:50 +00:00
|
|
|
for (i = 0; i < level->array->len; i++, tmp_elt++)
|
2002-03-07 06:04:03 +00:00
|
|
|
if (tmp_elt->children)
|
2009-09-06 11:35:37 +00:00
|
|
|
tmp_elt->children->parent_elt_index = i;
|
2001-12-26 22:43:53 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
return TRUE;
|
2000-12-20 00:37:58 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* sort elt stuff */
|
2001-09-02 21:47:12 +00:00
|
|
|
static GtkTreePath *
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_elt_get_path (SortLevel *level,
|
|
|
|
SortElt *elt)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *walker = level;
|
|
|
|
SortElt *walker2 = elt;
|
2001-09-02 21:47:12 +00:00
|
|
|
GtkTreePath *path;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_val_if_fail (level != NULL, NULL);
|
|
|
|
g_return_val_if_fail (elt != NULL, NULL);
|
2002-01-13 00:22:04 +00:00
|
|
|
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
|
|
|
|
while (walker)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2002-01-13 00:22:04 +00:00
|
|
|
gtk_tree_path_prepend_index (path, walker2->offset);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
if (!walker->parent_level)
|
|
|
|
break;
|
|
|
|
|
|
|
|
walker2 = SORT_LEVEL_PARENT_ELT (walker);
|
2001-10-19 20:53:08 +00:00
|
|
|
walker = walker->parent_level;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2002-01-13 00:22:04 +00:00
|
|
|
return path;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_set_model:
|
|
|
|
* @tree_model_sort: The #GtkTreeModelSort.
|
2010-02-19 16:53:17 +00:00
|
|
|
* @child_model: (allow-none): A #GtkTreeModel, or %NULL.
|
2001-10-19 20:53:08 +00:00
|
|
|
*
|
2005-07-25 13:55:31 +00:00
|
|
|
* 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.
|
2001-10-19 20:53:08 +00:00
|
|
|
**/
|
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_set_model (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreeModel *child_model)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (child_model)
|
2002-10-07 19:10:39 +00:00
|
|
|
g_object_ref (child_model);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->child_model)
|
2001-10-19 20:53:08 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
g_signal_handler_disconnect (priv->child_model,
|
|
|
|
priv->changed_id);
|
|
|
|
g_signal_handler_disconnect (priv->child_model,
|
|
|
|
priv->inserted_id);
|
|
|
|
g_signal_handler_disconnect (priv->child_model,
|
|
|
|
priv->has_child_toggled_id);
|
|
|
|
g_signal_handler_disconnect (priv->child_model,
|
|
|
|
priv->deleted_id);
|
|
|
|
g_signal_handler_disconnect (priv->child_model,
|
|
|
|
priv->reordered_id);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
/* reset our state */
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root)
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, priv->root);
|
|
|
|
priv->root = NULL;
|
|
|
|
_gtk_tree_data_list_header_free (priv->sort_list);
|
|
|
|
priv->sort_list = NULL;
|
|
|
|
g_object_unref (priv->child_model);
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->child_model = child_model;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
if (child_model)
|
|
|
|
{
|
|
|
|
GType *types;
|
|
|
|
gint i, n_columns;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->changed_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
g_signal_connect (child_model, "row-changed",
|
2001-10-19 20:53:08 +00:00
|
|
|
G_CALLBACK (gtk_tree_model_sort_row_changed),
|
|
|
|
tree_model_sort);
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->inserted_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
g_signal_connect (child_model, "row-inserted",
|
2001-10-19 20:53:08 +00:00
|
|
|
G_CALLBACK (gtk_tree_model_sort_row_inserted),
|
|
|
|
tree_model_sort);
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->has_child_toggled_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
g_signal_connect (child_model, "row-has-child-toggled",
|
2001-10-19 20:53:08 +00:00
|
|
|
G_CALLBACK (gtk_tree_model_sort_row_has_child_toggled),
|
|
|
|
tree_model_sort);
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->deleted_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
g_signal_connect (child_model, "row-deleted",
|
2001-10-19 20:53:08 +00:00
|
|
|
G_CALLBACK (gtk_tree_model_sort_row_deleted),
|
|
|
|
tree_model_sort);
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->reordered_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
g_signal_connect (child_model, "rows-reordered",
|
2001-10-19 20:53:08 +00:00
|
|
|
G_CALLBACK (gtk_tree_model_sort_rows_reordered),
|
|
|
|
tree_model_sort);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->child_flags = gtk_tree_model_get_flags (child_model);
|
2001-10-19 20:53:08 +00:00
|
|
|
n_columns = gtk_tree_model_get_n_columns (child_model);
|
|
|
|
|
|
|
|
types = g_new (GType, n_columns);
|
|
|
|
for (i = 0; i < n_columns; i++)
|
|
|
|
types[i] = gtk_tree_model_get_column_type (child_model, i);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->sort_list = _gtk_tree_data_list_header_new (n_columns, types);
|
2001-10-19 20:53:08 +00:00
|
|
|
g_free (types);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->default_sort_func = NO_SORT_FUNC;
|
|
|
|
priv->stamp = g_random_int ();
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_get_model:
|
|
|
|
* @tree_model: a #GtkTreeModelSort
|
|
|
|
*
|
|
|
|
* Returns the model the #GtkTreeModelSort is sorting.
|
|
|
|
*
|
2010-09-21 04:18:11 +00:00
|
|
|
* Return value: (transfer none): the "child model" being sorted
|
2001-10-19 20:53:08 +00:00
|
|
|
**/
|
|
|
|
GtkTreeModel *
|
2005-12-29 07:47:02 +00:00
|
|
|
gtk_tree_model_sort_get_model (GtkTreeModelSort *tree_model)
|
2001-10-19 20:53:08 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model), NULL);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
return tree_model->priv->child_model;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
static GtkTreePath *
|
|
|
|
gtk_real_tree_model_sort_convert_child_path_to_path (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreePath *child_path,
|
|
|
|
gboolean build_levels)
|
2001-10-19 20:53:08 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
gint *child_indices;
|
|
|
|
GtkTreePath *retval;
|
|
|
|
SortLevel *level;
|
|
|
|
gint i;
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, NULL);
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_val_if_fail (child_path != NULL, NULL);
|
|
|
|
|
2000-11-22 05:16:37 +00:00
|
|
|
retval = gtk_tree_path_new ();
|
2001-10-19 20:53:08 +00:00
|
|
|
child_indices = gtk_tree_path_get_indices (child_path);
|
2000-11-22 05:16:37 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root == NULL && build_levels)
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, -1);
|
2010-12-18 04:49:27 +00:00
|
|
|
level = SORT_LEVEL (priv->root);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (child_path); i++)
|
2000-11-22 05:16:37 +00:00
|
|
|
{
|
|
|
|
gint j;
|
2001-10-19 20:53:08 +00:00
|
|
|
gboolean found_child = FALSE;
|
|
|
|
|
|
|
|
if (!level)
|
2000-11-22 05:16:37 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (child_indices[i] >= level->array->len)
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
for (j = 0; j < level->array->len; j++)
|
|
|
|
{
|
|
|
|
if ((g_array_index (level->array, SortElt, j)).offset == child_indices[i])
|
|
|
|
{
|
2001-10-24 18:36:50 +00:00
|
|
|
gtk_tree_path_append_index (retval, j);
|
2001-10-25 20:32:40 +00:00
|
|
|
if (g_array_index (level->array, SortElt, j).children == NULL && build_levels)
|
2001-12-26 22:43:53 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, j);
|
2001-12-26 22:43:53 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
level = g_array_index (level->array, SortElt, j).children;
|
|
|
|
found_child = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (! found_child)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-11-22 05:16:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
2001-06-18 23:44:41 +00:00
|
|
|
|
2001-10-25 20:32:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_convert_child_path_to_path:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort
|
|
|
|
* @child_path: A #GtkTreePath to convert
|
|
|
|
*
|
|
|
|
* 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
|
2005-07-25 13:55:31 +00:00
|
|
|
* 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.
|
2001-10-25 20:32:40 +00:00
|
|
|
*
|
|
|
|
* Return value: A newly allocated #GtkTreePath, or %NULL
|
|
|
|
**/
|
|
|
|
GtkTreePath *
|
|
|
|
gtk_tree_model_sort_convert_child_path_to_path (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreePath *child_path)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort), NULL);
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (tree_model_sort->priv->child_model != NULL, NULL);
|
2001-10-25 20:32:40 +00:00
|
|
|
g_return_val_if_fail (child_path != NULL, NULL);
|
|
|
|
|
|
|
|
return gtk_real_tree_model_sort_convert_child_path_to_path (tree_model_sort, child_path, TRUE);
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_convert_child_iter_to_iter:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort
|
2010-07-07 16:20:37 +00:00
|
|
|
* @sort_iter: (out): An uninitialized #GtkTreeIter.
|
2001-10-19 20:53:08 +00:00
|
|
|
* @child_iter: A valid #GtkTreeIter pointing to a row on the child model
|
|
|
|
*
|
|
|
|
* Sets @sort_iter to point to the row in @tree_model_sort that corresponds to
|
2008-05-28 09:02:29 +00:00
|
|
|
* the row pointed at by @child_iter. If @sort_iter was not set, %FALSE
|
|
|
|
* is returned. Note: a boolean is only returned since 2.14.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE, if @sort_iter was set, i.e. if @sort_iter is a
|
|
|
|
* valid iterator pointer to a visible row in the child model.
|
2001-10-19 20:53:08 +00:00
|
|
|
**/
|
2008-05-28 09:02:29 +00:00
|
|
|
gboolean
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_convert_child_iter_to_iter (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreeIter *sort_iter,
|
|
|
|
GtkTreeIter *child_iter)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2008-05-28 09:02:29 +00:00
|
|
|
gboolean ret;
|
2001-10-19 20:53:08 +00:00
|
|
|
GtkTreePath *child_path, *path;
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2008-05-28 09:02:29 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort), FALSE);
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
2008-05-28 09:02:29 +00:00
|
|
|
g_return_val_if_fail (sort_iter != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (child_iter != NULL, FALSE);
|
2009-07-30 12:35:09 +00:00
|
|
|
g_return_val_if_fail (sort_iter != child_iter, FALSE);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
sort_iter->stamp = 0;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
child_path = gtk_tree_model_get_path (priv->child_model, child_iter);
|
2008-05-28 09:02:29 +00:00
|
|
|
g_return_val_if_fail (child_path != NULL, FALSE);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
path = gtk_tree_model_sort_convert_child_path_to_path (tree_model_sort, child_path);
|
2001-09-02 21:47:12 +00:00
|
|
|
gtk_tree_path_free (child_path);
|
2008-05-27 23:16:06 +00:00
|
|
|
|
|
|
|
if (!path)
|
|
|
|
{
|
|
|
|
g_warning ("%s: The conversion of the child path to a GtkTreeModel sort path failed", G_STRLOC);
|
2008-05-28 09:02:29 +00:00
|
|
|
return FALSE;
|
2008-05-27 23:16:06 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2008-05-28 09:02:29 +00:00
|
|
|
ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
sort_iter, path);
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_path_free (path);
|
2008-05-28 09:02:29 +00:00
|
|
|
|
|
|
|
return ret;
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_convert_path_to_child_path:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort
|
|
|
|
* @sorted_path: A #GtkTreePath to convert
|
|
|
|
*
|
2005-07-25 13:55:31 +00:00
|
|
|
* 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.
|
2001-10-19 20:53:08 +00:00
|
|
|
*
|
2002-01-10 16:36:25 +00:00
|
|
|
* Return value: A newly allocated #GtkTreePath, or %NULL
|
2001-10-19 20:53:08 +00:00
|
|
|
**/
|
|
|
|
GtkTreePath *
|
|
|
|
gtk_tree_model_sort_convert_path_to_child_path (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreePath *sorted_path)
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
gint *sorted_indices;
|
|
|
|
GtkTreePath *retval;
|
|
|
|
SortLevel *level;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort), NULL);
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_val_if_fail (priv->child_model != NULL, NULL);
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_val_if_fail (sorted_path != NULL, NULL);
|
|
|
|
|
|
|
|
retval = gtk_tree_path_new ();
|
|
|
|
sorted_indices = gtk_tree_path_get_indices (sorted_path);
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->root == NULL)
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, -1);
|
2010-12-18 04:49:27 +00:00
|
|
|
level = SORT_LEVEL (priv->root);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (sorted_path); i++)
|
|
|
|
{
|
2002-04-17 22:26:44 +00:00
|
|
|
gint count = sorted_indices[i];
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if ((level == NULL) ||
|
2002-04-17 22:26:44 +00:00
|
|
|
(level->array->len <= count))
|
2001-10-19 20:53:08 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-04-17 22:26:44 +00:00
|
|
|
|
|
|
|
if (g_array_index (level->array, SortElt, count).children == NULL)
|
2009-09-06 11:35:37 +00:00
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, count);
|
2002-03-16 23:30:44 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (level == NULL)
|
2002-04-17 22:26:44 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
break;
|
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2002-04-17 22:26:44 +00:00
|
|
|
gtk_tree_path_append_index (retval, g_array_index (level->array, SortElt, count).offset);
|
|
|
|
level = g_array_index (level->array, SortElt, count).children;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_convert_iter_to_child_iter:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort
|
2010-07-07 16:20:37 +00:00
|
|
|
* @child_iter: (out): An uninitialized #GtkTreeIter
|
2001-10-19 20:53:08 +00:00
|
|
|
* @sorted_iter: A valid #GtkTreeIter pointing to a row on @tree_model_sort.
|
|
|
|
*
|
2002-03-14 17:56:57 +00:00
|
|
|
* Sets @child_iter to point to the row pointed to by @sorted_iter.
|
2001-10-19 20:53:08 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreeIter *child_iter,
|
|
|
|
GtkTreeIter *sorted_iter)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
|
2010-12-18 04:49:27 +00:00
|
|
|
g_return_if_fail (priv->child_model != NULL);
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_if_fail (child_iter != NULL);
|
2005-12-29 07:47:02 +00:00
|
|
|
g_return_if_fail (VALID_ITER (sorted_iter, tree_model_sort));
|
2009-07-30 12:35:09 +00:00
|
|
|
g_return_if_fail (sorted_iter != child_iter);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
2001-10-03 18:29:20 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
*child_iter = SORT_ELT (sorted_iter->user_data2)->iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2011-05-09 08:04:24 +00:00
|
|
|
gboolean valid = FALSE;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2002-01-13 00:22:04 +00:00
|
|
|
path = gtk_tree_model_sort_elt_get_path (sorted_iter->user_data,
|
|
|
|
sorted_iter->user_data2);
|
2011-05-09 08:04:24 +00:00
|
|
|
valid = gtk_tree_model_get_iter (priv->child_model, child_iter, path);
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_path_free (path);
|
2011-05-09 08:04:24 +00:00
|
|
|
|
|
|
|
g_return_if_fail (valid == TRUE);
|
2001-10-03 18:29:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_build_level (GtkTreeModelSort *tree_model_sort,
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *parent_level,
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2000-11-09 16:52:17 +00:00
|
|
|
GtkTreeIter iter;
|
2009-09-06 11:35:37 +00:00
|
|
|
SortElt *parent_elt = NULL;
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *new_level;
|
|
|
|
gint length = 0;
|
|
|
|
gint i;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
g_assert (priv->child_model != NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (parent_level == NULL)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
if (gtk_tree_model_get_iter_first (priv->child_model, &iter) == FALSE)
|
2001-10-19 20:53:08 +00:00
|
|
|
return;
|
2010-12-18 04:49:27 +00:00
|
|
|
length = gtk_tree_model_iter_n_children (priv->child_model, NULL);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreeIter parent_iter;
|
|
|
|
GtkTreeIter child_parent_iter;
|
2001-06-18 23:44:41 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt = &g_array_index (parent_level->array, SortElt, parent_elt_index);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
parent_iter.stamp = priv->stamp;
|
2001-10-19 20:53:08 +00:00
|
|
|
parent_iter.user_data = parent_level;
|
|
|
|
parent_iter.user_data2 = parent_elt;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (tree_model_sort,
|
|
|
|
&child_parent_iter,
|
|
|
|
&parent_iter);
|
2010-12-18 04:49:27 +00:00
|
|
|
if (gtk_tree_model_iter_children (priv->child_model,
|
2001-10-19 20:53:08 +00:00
|
|
|
&iter,
|
|
|
|
&child_parent_iter) == FALSE)
|
|
|
|
return;
|
2002-02-09 21:56:30 +00:00
|
|
|
|
|
|
|
/* stamp may have changed */
|
|
|
|
gtk_tree_model_sort_convert_iter_to_child_iter (tree_model_sort,
|
|
|
|
&child_parent_iter,
|
|
|
|
&parent_iter);
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
length = gtk_tree_model_iter_n_children (priv->child_model, &child_parent_iter);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_if_fail (length > 0);
|
|
|
|
|
|
|
|
new_level = g_new (SortLevel, 1);
|
|
|
|
new_level->array = g_array_sized_new (FALSE, FALSE, sizeof (SortElt), length);
|
|
|
|
new_level->ref_count = 0;
|
|
|
|
new_level->parent_level = parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
new_level->parent_elt_index = parent_elt_index;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
if (parent_elt_index >= 0)
|
2001-10-19 20:53:08 +00:00
|
|
|
parent_elt->children = new_level;
|
2000-11-09 16:52:17 +00:00
|
|
|
else
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->root = new_level;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
/* increase the count of zero ref_counts.*/
|
2001-12-26 22:43:53 +00:00
|
|
|
while (parent_level)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2009-09-06 11:35:37 +00:00
|
|
|
g_array_index (parent_level->array, SortElt, parent_elt_index).zero_ref_count++;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt_index = parent_level->parent_elt_index;
|
2001-12-26 22:43:53 +00:00
|
|
|
parent_level = parent_level->parent_level;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
2009-09-06 11:35:37 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (new_level != priv->root)
|
|
|
|
priv->zero_ref_count++;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
SortElt sort_elt;
|
|
|
|
sort_elt.offset = i;
|
|
|
|
sort_elt.zero_ref_count = 0;
|
|
|
|
sort_elt.ref_count = 0;
|
|
|
|
sort_elt.children = NULL;
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
|
|
|
{
|
|
|
|
sort_elt.iter = iter;
|
2010-12-18 04:49:27 +00:00
|
|
|
if (gtk_tree_model_iter_next (priv->child_model, &iter) == FALSE &&
|
2001-10-19 20:53:08 +00:00
|
|
|
i < length - 1)
|
|
|
|
{
|
2008-05-27 23:16:06 +00:00
|
|
|
if (parent_level)
|
|
|
|
{
|
|
|
|
GtkTreePath *level;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
level = gtk_tree_model_sort_elt_get_path (parent_level,
|
|
|
|
parent_elt);
|
|
|
|
str = gtk_tree_path_to_string (level);
|
|
|
|
gtk_tree_path_free (level);
|
|
|
|
|
|
|
|
g_warning ("%s: There is a discrepancy between the sort model "
|
|
|
|
"and the child model. The child model is "
|
|
|
|
"advertising a wrong length for level %s:.",
|
|
|
|
G_STRLOC, str);
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_warning ("%s: There is a discrepancy between the sort model "
|
|
|
|
"and the child model. The child model is "
|
|
|
|
"advertising a wrong length for the root level.",
|
|
|
|
G_STRLOC);
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_array_append_val (new_level->array, sort_elt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* sort level */
|
|
|
|
gtk_tree_model_sort_sort_level (tree_model_sort, new_level,
|
|
|
|
FALSE, FALSE);
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_free_level (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *sort_level)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2000-11-09 16:52:17 +00:00
|
|
|
gint i;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_assert (sort_level);
|
2000-11-10 19:38:53 +00:00
|
|
|
|
2006-09-27 12:08:12 +00:00
|
|
|
for (i = 0; i < sort_level->array->len; i++)
|
|
|
|
{
|
|
|
|
if (g_array_index (sort_level->array, SortElt, i).children)
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort,
|
|
|
|
SORT_LEVEL (g_array_index (sort_level->array, SortElt, i).children));
|
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
if (sort_level->ref_count == 0)
|
2000-11-09 16:52:17 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
SortLevel *parent_level = sort_level->parent_level;
|
2009-09-06 11:35:37 +00:00
|
|
|
gint parent_elt_index = sort_level->parent_elt_index;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2006-09-27 12:08:12 +00:00
|
|
|
while (parent_level)
|
2009-09-06 11:35:37 +00:00
|
|
|
{
|
|
|
|
g_array_index (parent_level->array, SortElt, parent_elt_index).zero_ref_count--;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
parent_elt_index = parent_level->parent_elt_index;
|
2006-09-27 12:08:12 +00:00
|
|
|
parent_level = parent_level->parent_level;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (sort_level != priv->root)
|
|
|
|
priv->zero_ref_count--;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
2002-01-15 00:12:30 +00:00
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
if (sort_level->parent_elt_index >= 0)
|
|
|
|
SORT_LEVEL_PARENT_ELT (sort_level)->children = NULL;
|
2001-10-19 20:53:08 +00:00
|
|
|
else
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->root = NULL;
|
2001-12-26 22:43:53 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_array_free (sort_level->array, TRUE);
|
2001-12-26 22:43:53 +00:00
|
|
|
sort_level->array = NULL;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_free (sort_level);
|
2001-12-26 22:43:53 +00:00
|
|
|
sort_level = NULL;
|
2000-11-09 16:52:17 +00:00
|
|
|
}
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_model_sort_increment_stamp (GtkTreeModelSort *tree_model_sort)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
|
|
|
|
2002-02-12 17:48:02 +00:00
|
|
|
do
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->stamp++;
|
2002-02-12 17:48:02 +00:00
|
|
|
}
|
2010-12-18 04:49:27 +00:00
|
|
|
while (priv->stamp == 0);
|
2001-10-25 20:32:40 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_clear_cache (tree_model_sort);
|
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
|
|
static void
|
2001-10-19 20:53:08 +00:00
|
|
|
gtk_tree_model_sort_clear_cache_helper (GtkTreeModelSort *tree_model_sort,
|
|
|
|
SortLevel *level)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_assert (level != NULL);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
for (i = 0; i < level->array->len; i++)
|
2001-09-02 21:47:12 +00:00
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
if (g_array_index (level->array, SortElt, i).zero_ref_count > 0)
|
2001-10-24 18:36:50 +00:00
|
|
|
gtk_tree_model_sort_clear_cache_helper (tree_model_sort, g_array_index (level->array, SortElt, i).children);
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (level->ref_count == 0 && level != tree_model_sort->priv->root)
|
2002-02-12 01:00:22 +00:00
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, level);
|
2001-09-02 21:47:12 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_reset_default_sort_func:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort
|
|
|
|
*
|
|
|
|
* This resets the default sort function to be in the 'unsorted' state. That
|
2002-04-24 22:21:25 +00:00
|
|
|
* is, it is in the same order as the child model. It will re-sort the model
|
|
|
|
* to be in the same order as the child model only if the #GtkTreeModelSort
|
|
|
|
* is in 'unsorted' state.
|
2001-10-19 20:53:08 +00:00
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_tree_model_sort_reset_default_sort_func (GtkTreeModelSort *tree_model_sort)
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->default_sort_destroy)
|
2002-03-03 05:41:28 +00:00
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
GDestroyNotify d = priv->default_sort_destroy;
|
2002-03-03 05:41:28 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->default_sort_destroy = NULL;
|
|
|
|
d (priv->default_sort_data);
|
2002-03-03 05:41:28 +00:00
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->default_sort_func = NO_SORT_FUNC;
|
|
|
|
priv->default_sort_data = NULL;
|
|
|
|
priv->default_sort_destroy = NULL;
|
2002-04-24 22:21:25 +00:00
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (priv->sort_column_id == GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
2002-04-24 22:21:25 +00:00
|
|
|
gtk_tree_model_sort_sort (tree_model_sort);
|
2010-12-18 04:49:27 +00:00
|
|
|
priv->sort_column_id = GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID;
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_clear_cache:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort
|
|
|
|
*
|
|
|
|
* This function should almost never be called. It clears the @tree_model_sort
|
|
|
|
* of any cached iterators that haven't been reffed with
|
|
|
|
* gtk_tree_model_ref_node(). This might be useful if the child model being
|
|
|
|
* sorted is static (and doesn't change often) and there has been a lot of
|
|
|
|
* unreffed access to nodes. As a side effect of this function, all unreffed
|
|
|
|
* iters will be invalid.
|
|
|
|
**/
|
|
|
|
void
|
|
|
|
gtk_tree_model_sort_clear_cache (GtkTreeModelSort *tree_model_sort)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort));
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
if (tree_model_sort->priv->zero_ref_count > 0)
|
|
|
|
gtk_tree_model_sort_clear_cache_helper (tree_model_sort, (SortLevel *)tree_model_sort->priv->root);
|
2001-10-19 20:53:08 +00:00
|
|
|
}
|
2002-06-04 17:17:49 +00:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_sort_iter_is_valid_helper (GtkTreeIter *iter,
|
|
|
|
SortLevel *level)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
SortElt *elt = &g_array_index (level->array, SortElt, i);
|
|
|
|
|
|
|
|
if (iter->user_data == level && iter->user_data2 == elt)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (elt->children)
|
|
|
|
if (gtk_tree_model_sort_iter_is_valid_helper (iter, elt->children))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_sort_iter_is_valid:
|
|
|
|
* @tree_model_sort: A #GtkTreeModelSort.
|
|
|
|
* @iter: A #GtkTreeIter.
|
|
|
|
*
|
2005-07-25 13:55:31 +00:00
|
|
|
* <warning><para>
|
|
|
|
* This function is slow. Only use it for debugging and/or testing purposes.
|
|
|
|
* </para></warning>
|
2002-06-04 17:17:49 +00:00
|
|
|
*
|
|
|
|
* Checks if the given iter is a valid iter for this #GtkTreeModelSort.
|
|
|
|
*
|
|
|
|
* Return value: %TRUE if the iter is valid, %FALSE if the iter is invalid.
|
2002-11-28 00:33:17 +00:00
|
|
|
*
|
|
|
|
* Since: 2.2
|
2002-06-04 17:17:49 +00:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gtk_tree_model_sort_iter_is_valid (GtkTreeModelSort *tree_model_sort,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_SORT (tree_model_sort), FALSE);
|
|
|
|
g_return_val_if_fail (iter != NULL, FALSE);
|
|
|
|
|
|
|
|
if (!VALID_ITER (iter, tree_model_sort))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return gtk_tree_model_sort_iter_is_valid_helper (iter,
|
2010-12-18 04:49:27 +00:00
|
|
|
tree_model_sort->priv->root);
|
2002-06-04 17:17:49 +00:00
|
|
|
}
|