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
|
2012-02-27 13:01:10 +00:00
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2000-11-09 16:52:17 +00:00
|
|
|
|
*/
|
|
|
|
|
|
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
|
2014-02-09 22:24:06 +00:00
|
|
|
|
* #GtkTreeModelSort, the two #GtkTreeViews can each sort their
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* 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.
|
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
|
* ## Using a #GtkTreeModelSort
|
|
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* {
|
|
|
|
|
* GtkTreeView *tree_view1;
|
|
|
|
|
* GtkTreeView *tree_view2;
|
|
|
|
|
* GtkTreeModel *sort_model1;
|
|
|
|
|
* GtkTreeModel *sort_model2;
|
|
|
|
|
* GtkTreeModel *child_model;
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // get the child model
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* child_model = get_my_model ();
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Create the first tree
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* sort_model1 = gtk_tree_model_sort_new_with_model (child_model);
|
|
|
|
|
* tree_view1 = gtk_tree_view_new_with_model (sort_model1);
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Create the second tree
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* sort_model2 = gtk_tree_model_sort_new_with_model (child_model);
|
|
|
|
|
* tree_view2 = gtk_tree_view_new_with_model (sort_model2);
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Now we can sort the two models independently
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* 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);
|
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2011-04-17 23:34:07 +00:00
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*
|
2014-02-04 21:57:57 +00:00
|
|
|
|
* ## Accessing the child model of in a selection changed callback
|
|
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* 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;
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Get the current selected row and the model.
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* if (! gtk_tree_selection_get_selected (selection,
|
|
|
|
|
* &sort_model,
|
|
|
|
|
* &sort_iter))
|
|
|
|
|
* return;
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Look up the current value on the selected row and get
|
|
|
|
|
* // a new value to change it to.
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* 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);
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Get an iterator on the child model, instead of the sort model.
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* gtk_tree_model_sort_convert_iter_to_child_iter (GTK_TREE_MODEL_SORT (sort_model),
|
|
|
|
|
* &child_iter,
|
|
|
|
|
* &sort_iter);
|
|
|
|
|
*
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // 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.
|
2011-04-17 23:34:07 +00:00
|
|
|
|
* 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);
|
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2011-04-17 23:34:07 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
2011-08-11 10:23:52 +00:00
|
|
|
|
/* Notes on this implementation of GtkTreeModelSort
|
|
|
|
|
* ================================================
|
|
|
|
|
*
|
|
|
|
|
* Warnings
|
|
|
|
|
* --------
|
|
|
|
|
*
|
|
|
|
|
* In this code there is a potential for confusion as to whether an iter,
|
|
|
|
|
* path or value refers to the GtkTreeModelSort model, or to the child model
|
|
|
|
|
* that has been set. As a convention, variables referencing the child model
|
|
|
|
|
* will have an s_ prefix before them (ie. s_iter, s_value, s_path);
|
|
|
|
|
* Conversion of iterators and paths between GtkTreeModelSort and the child
|
|
|
|
|
* model is done through the various gtk_tree_model_sort_convert_* functions.
|
|
|
|
|
*
|
|
|
|
|
* Iterator format
|
|
|
|
|
* ---------------
|
|
|
|
|
*
|
|
|
|
|
* The iterator format of iterators handed out by GtkTreeModelSort is as
|
|
|
|
|
* follows:
|
|
|
|
|
*
|
|
|
|
|
* iter->stamp = tree_model_sort->stamp
|
|
|
|
|
* iter->user_data = SortLevel
|
|
|
|
|
* iter->user_data2 = SortElt
|
|
|
|
|
*
|
|
|
|
|
* Internal data structure
|
|
|
|
|
* -----------------------
|
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* Using SortLevel and SortElt, GtkTreeModelSort maintains a “cache” of
|
2011-08-11 10:23:52 +00:00
|
|
|
|
* the mapping from GtkTreeModelSort nodes to nodes in the child model.
|
|
|
|
|
* This is to avoid sorting a level each time an operation is requested
|
|
|
|
|
* on GtkTreeModelSort, such as get iter, get path, get value.
|
|
|
|
|
*
|
|
|
|
|
* A SortElt corresponds to a single node. A node and its siblings are
|
|
|
|
|
* stored in a SortLevel. The SortLevel keeps a reference to the parent
|
|
|
|
|
* SortElt and its SortLevel (if any). The SortElt can have a "children"
|
|
|
|
|
* pointer set, which points at a child level (a sub level).
|
|
|
|
|
*
|
|
|
|
|
* In a SortLevel, nodes are stored in a GSequence. The GSequence
|
|
|
|
|
* allows for fast additions and removals, and supports sorting
|
|
|
|
|
* the level of SortElt nodes.
|
|
|
|
|
*
|
|
|
|
|
* It is important to recognize the two different mappings that play
|
|
|
|
|
* a part in this code:
|
|
|
|
|
* I. The mapping from the client to this model. The order in which
|
|
|
|
|
* nodes are stored in the GSequence is the order in which the
|
|
|
|
|
* nodes are exposed to clients of the GtkTreeModelSort.
|
|
|
|
|
* II. The mapping from this model to its child model. Each SortElt
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* contains an “offset” field which is the offset of the
|
2011-08-11 10:23:52 +00:00
|
|
|
|
* corresponding node in the child model.
|
|
|
|
|
*
|
|
|
|
|
* Reference counting
|
|
|
|
|
* ------------------
|
|
|
|
|
*
|
|
|
|
|
* GtkTreeModelSort forwards all reference and unreference operations
|
|
|
|
|
* to the corresponding node in the child model. The reference count
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* of each node is also maintained internally, in the “ref_count”
|
2011-08-11 10:23:52 +00:00
|
|
|
|
* fields in SortElt and SortLevel. For each ref and unref operation on
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* a SortElt, the “ref_count” of the SortLevel is updated accordingly.
|
2011-08-11 10:23:52 +00:00
|
|
|
|
* In addition, if a SortLevel has a parent, a reference is taken on
|
|
|
|
|
* this parent. This happens in gtk_tree_model_sort_build_level() and
|
|
|
|
|
* the reference is released again in gtk_tree_model_sort_free_level().
|
|
|
|
|
* This ensures that when GtkTreeModelSort takes a reference on a node
|
|
|
|
|
* (for example during sorting), all parent nodes are referenced
|
|
|
|
|
* according to reference counting rule 1, see the GtkTreeModel
|
|
|
|
|
* documentation.
|
|
|
|
|
*
|
|
|
|
|
* When a level has a reference count of zero, which means that
|
|
|
|
|
* none of the nodes in the level is referenced, the level has
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* a “zero ref count” on all its parents. As soon as the level
|
2011-08-11 10:23:52 +00:00
|
|
|
|
* reaches a reference count of zero, the zero ref count value is
|
|
|
|
|
* incremented by one on all parents of this level. Similarly, as
|
|
|
|
|
* soon as the reference count of a level changes from zero, the
|
|
|
|
|
* zero ref count value is decremented by one on all parents.
|
|
|
|
|
*
|
|
|
|
|
* The zero ref count value is used to clear unused portions of
|
|
|
|
|
* the cache. If a SortElt has a zero ref count of one, then
|
|
|
|
|
* its child level is unused and can be removed from the cache.
|
|
|
|
|
* If the zero ref count value is higher than one, then the
|
|
|
|
|
* child level contains sublevels which are unused as well.
|
|
|
|
|
* gtk_tree_model_sort_clear_cache() uses this to not recurse
|
|
|
|
|
* into levels which have a zero ref count of zero.
|
|
|
|
|
*/
|
|
|
|
|
|
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;
|
|
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
|
struct _SortElt
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
SortLevel *children;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int offset;
|
|
|
|
|
int ref_count;
|
|
|
|
|
int zero_ref_count;
|
|
|
|
|
int old_index; /* used while sorting */
|
2013-09-22 03:37:48 +00:00
|
|
|
|
GSequenceIter *siter; /* iter into seq */
|
2001-10-19 20:53:08 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _SortLevel
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequence *seq;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int ref_count;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *parent_elt;
|
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
|
|
|
|
GtkTreeIterCompareFunc sort_func;
|
|
|
|
|
gpointer sort_data;
|
2000-11-22 05:16:37 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GtkTreePath *parent_path;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *parent_path_indices;
|
|
|
|
|
int parent_path_depth;
|
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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int stamp;
|
2010-12-18 04:49:27 +00:00
|
|
|
|
guint child_flags;
|
|
|
|
|
GtkTreeModel *child_model;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int zero_ref_count;
|
2010-12-18 04:49:27 +00:00
|
|
|
|
|
|
|
|
|
/* sort information */
|
|
|
|
|
GList *sort_list;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id;
|
2010-12-18 04:49:27 +00:00
|
|
|
|
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)
|
2011-08-10 21:24:58 +00:00
|
|
|
|
#define GET_ELT(siter) ((SortElt *) (siter ? g_sequence_get (siter) : NULL))
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
2009-09-06 11:35:37 +00:00
|
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *new_order,
|
2001-10-19 20:53:08 +00:00
|
|
|
|
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);
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int gtk_tree_model_sort_get_n_columns (GtkTreeModel *tree_model);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
static GType gtk_tree_model_sort_get_column_type (GtkTreeModel *tree_model,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int index);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int column,
|
2001-09-02 21:47:12 +00:00
|
|
|
|
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);
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int gtk_tree_model_sort_iter_n_children (GtkTreeModel *tree_model,
|
2001-09-02 21:47:12 +00:00
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
static gboolean gtk_tree_model_sort_iter_nth_child (GtkTreeModel *tree_model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *parent,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int n);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
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);
|
2020-02-18 00:41:42 +00:00
|
|
|
|
static GdkContentProvider *
|
|
|
|
|
gtk_tree_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
|
|
|
|
|
GtkTreePath *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
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *sort_column_id,
|
2001-10-24 18:36:50 +00:00
|
|
|
|
GtkSortType *order);
|
|
|
|
|
static void gtk_tree_model_sort_set_sort_column_id (GtkTreeSortable *sortable,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id,
|
2001-10-24 18:36:50 +00:00
|
|
|
|
GtkSortType order);
|
|
|
|
|
static void gtk_tree_model_sort_set_sort_func (GtkTreeSortable *sortable,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id,
|
2001-10-24 18:36:50 +00:00
|
|
|
|
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,
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *parent_elt);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
static void gtk_tree_model_sort_free_level (GtkTreeModelSort *tree_model_sort,
|
2011-06-02 20:01:45 +00:00
|
|
|
|
SortLevel *sort_level,
|
|
|
|
|
gboolean unref);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
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 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
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int gtk_tree_model_sort_compare_func (gconstpointer a,
|
2011-08-10 21:24:58 +00:00
|
|
|
|
gconstpointer b,
|
|
|
|
|
gpointer user_data);
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int gtk_tree_model_sort_offset_compare_func (gconstpointer a,
|
2011-08-10 21:24:58 +00:00
|
|
|
|
gconstpointer b,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
static void gtk_tree_model_sort_clear_cache_helper (GtkTreeModelSort *tree_model_sort,
|
|
|
|
|
SortLevel *level);
|
|
|
|
|
|
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,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkTreeModelSort)
|
2006-05-02 23:56:43 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2013-06-27 19:02:52 +00:00
|
|
|
|
tree_model_sort->priv = priv =
|
|
|
|
|
gtk_tree_model_sort_get_instance_private (tree_model_sort);
|
2010-12-18 04:49:27 +00:00
|
|
|
|
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));
|
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
|
|
|
|
/**
|
2019-12-03 15:36:42 +00:00
|
|
|
|
* gtk_tree_model_sort_new_with_model: (constructor)
|
2001-09-02 21:47:12 +00:00
|
|
|
|
* @child_model: A #GtkTreeModel
|
|
|
|
|
*
|
2019-12-03 15:36:42 +00:00
|
|
|
|
* Creates a new #GtkTreeModelSort, with @child_model as the child model.
|
2001-09-02 21:47:12 +00:00
|
|
|
|
*
|
2019-12-03 15:36:42 +00:00
|
|
|
|
* Returns: (transfer full) (type Gtk.TreeModelSort): A new #GtkTreeModelSort.
|
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)
|
2011-06-02 20:01:45 +00:00
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, priv->root, TRUE);
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
/* helpers */
|
|
|
|
|
static SortElt *
|
|
|
|
|
sort_elt_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_slice_new (SortElt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
sort_elt_free (gpointer elt)
|
|
|
|
|
{
|
|
|
|
|
g_slice_free (SortElt, elt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
increase_offset_iter (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
SortElt *elt = data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int offset = GPOINTER_TO_INT (user_data);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
|
|
|
|
|
if (elt->offset >= offset)
|
|
|
|
|
elt->offset++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
decrease_offset_iter (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
SortElt *elt = data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int offset = GPOINTER_TO_INT (user_data);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
|
|
|
|
|
if (elt->offset > offset)
|
|
|
|
|
elt->offset--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
fill_sort_data (SortData *data,
|
|
|
|
|
GtkTreeModelSort *tree_model_sort,
|
|
|
|
|
SortLevel *level)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
|
|
|
|
|
|
|
|
|
data->tree_model_sort = tree_model_sort;
|
|
|
|
|
|
|
|
|
|
if (priv->sort_column_id != GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeDataSortHeader *header;
|
|
|
|
|
|
|
|
|
|
header = _gtk_tree_data_list_get_header (priv->sort_list,
|
|
|
|
|
priv->sort_column_id);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (header != NULL);
|
|
|
|
|
g_return_if_fail (header->func != NULL);
|
|
|
|
|
|
|
|
|
|
data->sort_func = header->func;
|
|
|
|
|
data->sort_data = header->data;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* absolutely SHOULD NOT happen: */
|
|
|
|
|
g_return_if_fail (priv->default_sort_func != NULL);
|
|
|
|
|
|
|
|
|
|
data->sort_func = priv->default_sort_func;
|
|
|
|
|
data->sort_data = priv->default_sort_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (level->parent_elt)
|
|
|
|
|
{
|
|
|
|
|
data->parent_path = gtk_tree_model_sort_elt_get_path (level->parent_level,
|
|
|
|
|
level->parent_elt);
|
|
|
|
|
gtk_tree_path_append_index (data->parent_path, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
data->parent_path = gtk_tree_path_new_first ();
|
|
|
|
|
}
|
|
|
|
|
data->parent_path_depth = gtk_tree_path_get_depth (data->parent_path);
|
|
|
|
|
data->parent_path_indices = gtk_tree_path_get_indices (data->parent_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
free_sort_data (SortData *data)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (data->parent_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SortElt *
|
|
|
|
|
lookup_elt_with_offset (GtkTreeModelSort *tree_model_sort,
|
|
|
|
|
SortLevel *level,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int offset,
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter **ret_siter)
|
|
|
|
|
{
|
|
|
|
|
GSequenceIter *siter, *end_siter;
|
|
|
|
|
|
|
|
|
|
/* FIXME: We have to do a search like this, because the sequence is not
|
|
|
|
|
* (always) sorted on offset order. Perhaps we should introduce a
|
|
|
|
|
* second sequence which is sorted on offset order.
|
|
|
|
|
*/
|
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
|
|
|
|
{
|
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
|
|
|
|
|
|
|
|
|
if (elt->offset == offset)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret_siter)
|
|
|
|
|
*ret_siter = siter;
|
|
|
|
|
|
|
|
|
|
return GET_ELT (siter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-10-19 20:53:08 +00:00
|
|
|
|
SortElt *elt;
|
|
|
|
|
SortLevel *level;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortData sort_data;
|
2000-11-10 19:38:53 +00:00
|
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
|
gboolean free_s_path = FALSE;
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int index = 0, old_index;
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (g_sequence_get_length (level->seq) < 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;
|
|
|
|
|
}
|
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))
|
2011-08-10 21:24:58 +00:00
|
|
|
|
tmpiter = elt->iter;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
else
|
2011-08-10 21:24:58 +00:00
|
|
|
|
gtk_tree_model_get_iter (priv->child_model,
|
|
|
|
|
&tmpiter, start_s_path);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
old_index = g_sequence_iter_get_position (elt->siter);
|
|
|
|
|
|
|
|
|
|
fill_sort_data (&sort_data, tree_model_sort, level);
|
|
|
|
|
g_sequence_sort_changed (elt->siter,
|
|
|
|
|
gtk_tree_model_sort_compare_func,
|
|
|
|
|
&sort_data);
|
|
|
|
|
free_sort_data (&sort_data);
|
2001-10-24 18:36:50 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
index = g_sequence_iter_get_position (elt->siter);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
/* Prepare the path for signal emission */
|
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)
|
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *new_order;
|
|
|
|
|
int j;
|
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
|
|
|
|
|
|
|
|
|
GtkTreePath *tmppath;
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
new_order = g_new (int, g_sequence_get_length (level->seq));
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
for (j = 0; j < g_sequence_get_length (level->seq); j++)
|
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 (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 */
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
if (level->parent_elt)
|
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;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
iter.user_data2 = level->parent_elt;
|
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;
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i = 0;
|
2001-10-24 18:36:50 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2011-08-07 15:58:37 +00:00
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
|
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)
|
|
|
|
|
{
|
|
|
|
|
if (!level)
|
|
|
|
|
{
|
|
|
|
|
/* level not yet build, we won't cover this signal */
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (g_sequence_get_length (level->seq) < gtk_tree_path_get_indices (s_path)[i])
|
2001-10-24 18:36:50 +00:00
|
|
|
|
{
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
elt = lookup_elt_with_offset (tree_model_sort, level,
|
|
|
|
|
gtk_tree_path_get_indices (s_path)[i],
|
|
|
|
|
NULL);
|
2001-10-24 20:54:32 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
2011-06-02 20:01:45 +00:00
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, level, TRUE);
|
2005-08-23 20:33:42 +00:00
|
|
|
|
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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int offset;
|
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
|
|
|
|
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
|
|
|
|
|
2011-06-02 20:01:45 +00:00
|
|
|
|
/* If this node has children, we free the level (recursively) here
|
|
|
|
|
* and specify that unref may not be used, because parent and its
|
|
|
|
|
* children have been removed by now.
|
|
|
|
|
*/
|
|
|
|
|
if (elt->children)
|
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort,
|
|
|
|
|
elt->children, FALSE);
|
|
|
|
|
|
2013-04-25 14:30:12 +00:00
|
|
|
|
if (level->ref_count == 0 && g_sequence_get_length (level->seq) == 1)
|
2001-10-24 18:36:50 +00:00
|
|
|
|
{
|
2002-02-09 01:28:00 +00:00
|
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
2011-05-09 08:29:54 +00:00
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
|
2001-10-25 20:32:40 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
2011-05-09 08:29:54 +00:00
|
|
|
|
|
2010-12-18 04:49:27 +00:00
|
|
|
|
if (level == tree_model_sort->priv->root)
|
2005-07-22 03:38:14 +00:00
|
|
|
|
{
|
2011-06-02 20:01:45 +00:00
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort,
|
|
|
|
|
tree_model_sort->priv->root,
|
|
|
|
|
TRUE);
|
2010-12-18 04:49:27 +00:00
|
|
|
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
g_sequence_remove (elt->siter);
|
|
|
|
|
elt = NULL;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
/* The sequence is not ordered on offset, so we traverse the entire
|
|
|
|
|
* sequence.
|
|
|
|
|
*/
|
|
|
|
|
g_sequence_foreach (level->seq, decrease_offset_iter,
|
|
|
|
|
GINT_TO_POINTER (offset));
|
2001-10-25 20:32:40 +00:00
|
|
|
|
|
2011-05-09 08:29:54 +00:00
|
|
|
|
gtk_tree_model_sort_increment_stamp (tree_model_sort);
|
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
|
|
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *new_order,
|
2001-09-12 23:16:18 +00:00
|
|
|
|
gpointer data)
|
2001-09-02 21:47:12 +00:00
|
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
|
SortLevel *level;
|
2001-10-29 18:56:00 +00:00
|
|
|
|
GtkTreeIter iter;
|
2015-05-31 01:29:21 +00:00
|
|
|
|
GtkTreePath *path;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *tmp_array;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
int i, length;
|
|
|
|
|
GSequenceIter *siter, *end_siter;
|
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
|
|
|
|
{
|
2015-05-31 01:29:21 +00:00
|
|
|
|
SortElt *elt;
|
|
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
length = g_sequence_get_length (level->seq);
|
|
|
|
|
if (length < 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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
tmp_array = g_new (int, length);
|
|
|
|
|
|
|
|
|
|
/* FIXME: I need to think about whether this can be done in a more
|
|
|
|
|
* efficient way?
|
|
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
2001-11-01 20:46:01 +00:00
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int j;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < length; j++)
|
2001-11-01 20:46:01 +00:00
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (elt->offset == new_order[j])
|
2001-11-01 20:46:01 +00:00
|
|
|
|
tmp_array[i] = j;
|
|
|
|
|
}
|
2011-08-10 21:24:58 +00:00
|
|
|
|
|
|
|
|
|
i++;
|
2001-11-01 20:46:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
/* This loop cannot be merged with the above loop nest, because that
|
|
|
|
|
* would introduce duplicate offsets.
|
|
|
|
|
*/
|
|
|
|
|
i = 0;
|
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
|
|
|
|
{
|
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
|
|
|
|
|
|
|
|
|
elt->offset = tmp_array[i];
|
|
|
|
|
i++;
|
|
|
|
|
}
|
2001-10-29 18:56:00 +00:00
|
|
|
|
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
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2000-11-09 16:52:17 +00:00
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int 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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *indices;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
SortLevel *level;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int depth, i;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter *siter;
|
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)
|
2011-08-07 15:58:37 +00:00
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
|
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) ||
|
2011-08-10 21:24:58 +00:00
|
|
|
|
(indices[i] >= g_sequence_get_length (level->seq)))
|
2011-05-09 07:51:50 +00:00
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->seq, indices[i]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elt = GET_ELT (siter);
|
2020-03-05 06:02:24 +00:00
|
|
|
|
g_assert (elt);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (elt->children == NULL)
|
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, elt);
|
|
|
|
|
|
|
|
|
|
level = elt->children;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (!level || indices[i] >= g_sequence_get_length (level->seq))
|
2003-12-17 22:47:55 +00:00
|
|
|
|
{
|
|
|
|
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
|
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->seq, indices[depth - 1]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
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;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *elt;
|
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);
|
2011-08-07 15:58:37 +00:00
|
|
|
|
elt = SORT_ELT (iter->user_data2);
|
2009-09-06 11:35:37 +00:00
|
|
|
|
|
|
|
|
|
while (level)
|
2001-09-02 21:47:12 +00:00
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int index;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
|
|
|
|
|
index = g_sequence_iter_get_position (elt->siter);
|
|
|
|
|
gtk_tree_path_prepend_index (retval, index);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
elt = level->parent_elt;
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int column,
|
2001-10-19 20:53:08 +00:00
|
|
|
|
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;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
SortElt *elt;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter *siter;
|
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);
|
|
|
|
|
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
|
|
|
|
elt = iter->user_data2;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
siter = g_sequence_iter_next (elt->siter);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
2000-11-09 16:52:17 +00:00
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
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;
|
|
|
|
|
SortElt *elt;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter *siter;
|
2011-01-06 04:39:11 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (priv->child_model != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (priv->stamp == iter->stamp, FALSE);
|
|
|
|
|
|
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
2012-04-22 20:32:46 +00:00
|
|
|
|
if (g_sequence_iter_is_begin (elt->siter))
|
2011-01-06 04:39:11 +00:00
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2012-04-22 20:32:46 +00:00
|
|
|
|
|
|
|
|
|
siter = g_sequence_iter_prev (elt->siter);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
2011-01-06 04:39:11 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2011-08-07 15:58:37 +00:00
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter->user_data2 = g_sequence_get (g_sequence_get_begin_iter (level->seq));
|
2001-10-19 20:53:08 +00:00
|
|
|
|
}
|
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)
|
2011-08-07 15:58:37 +00:00
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, elt);
|
2009-09-06 11:35:37 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter->user_data2 = g_sequence_get (g_sequence_get_begin_iter (elt->children->seq));
|
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
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2000-11-09 16:52:17 +00:00
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int 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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (n >= g_sequence_get_length (level->seq))
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter->user_data2 = g_sequence_get (g_sequence_get_iter_at_pos (level->seq, 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;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
iter->user_data2 = level->parent_elt;
|
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;
|
2011-06-02 19:51:51 +00:00
|
|
|
|
SortLevel *level;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
SortElt *elt;
|
|
|
|
|
|
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
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
|
if (level->ref_count == 1)
|
|
|
|
|
{
|
|
|
|
|
SortLevel *parent_level = level->parent_level;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *parent_elt = level->parent_elt;
|
2009-09-06 11:35:37 +00:00
|
|
|
|
|
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
|
|
|
|
{
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt->zero_ref_count--;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
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;
|
2011-06-02 19:51:51 +00:00
|
|
|
|
SortLevel *level;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
SortElt *elt;
|
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
|
|
|
|
|
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;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *parent_elt = level->parent_elt;
|
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
|
|
|
|
{
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt->zero_ref_count++;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *sort_column_id,
|
2001-10-19 20:53:08 +00:00
|
|
|
|
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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id,
|
2001-10-19 20:53:08 +00:00
|
|
|
|
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
|
|
|
|
|
2018-01-16 23:16:21 +00:00
|
|
|
|
if (priv->sort_column_id == sort_column_id && priv->order == order)
|
|
|
|
|
return;
|
|
|
|
|
|
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-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,
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int sort_column_id,
|
2001-10-19 20:53:08 +00:00
|
|
|
|
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;
|
|
|
|
|
|
2018-01-16 23:15:13 +00:00
|
|
|
|
return (tree_model_sort->priv->default_sort_func != NO_SORT_FUNC);
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 00:41:42 +00:00
|
|
|
|
static GdkContentProvider *
|
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_model_sort_drag_data_get (GtkTreeDragSource *drag_source,
|
2020-02-18 00:41:42 +00:00
|
|
|
|
GtkTreePath *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
|
|
|
|
{
|
|
|
|
|
GtkTreeModelSort *tree_model_sort = (GtkTreeModelSort *)drag_source;
|
|
|
|
|
GtkTreePath *child_path;
|
2020-02-18 00:41:42 +00:00
|
|
|
|
GdkContentProvider *gotten;
|
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
|
|
|
|
|
2005-12-29 07:47:02 +00:00
|
|
|
|
child_path = gtk_tree_model_sort_convert_path_to_child_path (tree_model_sort, path);
|
2020-02-18 00:41:42 +00:00
|
|
|
|
gotten = gtk_tree_drag_source_drag_data_get (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 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 */
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2001-09-02 21:47:12 +00:00
|
|
|
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
const SortElt *sa = a;
|
|
|
|
|
const SortElt *sb = b;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
|
GtkTreeIter iter_a, iter_b;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int retval;
|
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
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter_a = sa->iter;
|
|
|
|
|
iter_b = sb->iter;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
data->parent_path_indices [data->parent_path_depth-1] = sa->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);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
data->parent_path_indices [data->parent_path_depth-1] = sb->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;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
static int
|
2001-10-03 18:29:20 +00:00
|
|
|
|
gtk_tree_model_sort_offset_compare_func (gconstpointer a,
|
|
|
|
|
gconstpointer b,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int retval;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
const SortElt *sa = (SortElt *)a;
|
|
|
|
|
const SortElt *sb = (SortElt *)b;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
|
|
|
|
SortData *data = (SortData *)user_data;
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (sa->offset < sb->offset)
|
2001-10-03 18:29:20 +00:00
|
|
|
|
retval = -1;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
else if (sa->offset > sb->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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter *begin_siter, *end_siter, *siter;
|
|
|
|
|
SortElt *begin_elt;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *new_order;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
begin_siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
begin_elt = g_sequence_get (begin_siter);
|
|
|
|
|
|
|
|
|
|
if (g_sequence_get_length (level->seq) < 1 && !begin_elt->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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter.user_data2 = begin_elt;
|
2006-09-27 12:08:12 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_sort_ref_node (GTK_TREE_MODEL (tree_model_sort), &iter);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
2001-09-02 21:47:12 +00:00
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
elt->old_index = i;
|
|
|
|
|
i++;
|
2001-09-02 21:47:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
fill_sort_data (&data, tree_model_sort, level);
|
2001-10-31 00:20:15 +00:00
|
|
|
|
|
2002-02-12 01:00:22 +00:00
|
|
|
|
if (data.sort_func == NO_SORT_FUNC)
|
2011-08-10 21:24:58 +00:00
|
|
|
|
g_sequence_sort (level->seq, gtk_tree_model_sort_offset_compare_func,
|
|
|
|
|
&data);
|
2001-10-03 18:29:20 +00:00
|
|
|
|
else
|
2011-08-10 21:24:58 +00:00
|
|
|
|
g_sequence_sort (level->seq, gtk_tree_model_sort_compare_func, &data);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
free_sort_data (&data);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2020-07-24 13:54:49 +00:00
|
|
|
|
new_order = g_new (int, g_sequence_get_length (level->seq));
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
i = 0;
|
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
2001-09-02 21:47:12 +00:00
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
new_order[i++] = elt->old_index;
|
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);
|
2011-08-07 15:58:37 +00:00
|
|
|
|
if (level->parent_elt)
|
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;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
iter.user_data2 = level->parent_elt;
|
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)
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
2001-12-26 22:43:53 +00:00
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
2001-12-26 22:43:53 +00:00
|
|
|
|
|
|
|
|
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
iter.user_data2 = begin_elt;
|
2006-09-27 12:08:12 +00:00
|
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
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;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt;
|
|
|
|
|
SortData data;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int offset;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
elt = sort_elt_new ();
|
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))
|
2011-08-10 21:24:58 +00:00
|
|
|
|
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 */
|
2011-08-10 21:24:58 +00:00
|
|
|
|
g_sequence_foreach (level->seq, increase_offset_iter, GINT_TO_POINTER (offset));
|
|
|
|
|
|
|
|
|
|
fill_sort_data (&data, tree_model_sort, level);
|
2002-03-07 06:04:03 +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)
|
2011-08-10 21:24:58 +00:00
|
|
|
|
{
|
|
|
|
|
elt->siter = g_sequence_insert_sorted (level->seq, elt,
|
|
|
|
|
gtk_tree_model_sort_offset_compare_func,
|
|
|
|
|
&data);
|
|
|
|
|
}
|
2002-02-12 01:00:22 +00:00
|
|
|
|
else
|
2011-08-10 21:24:58 +00:00
|
|
|
|
{
|
|
|
|
|
elt->siter = g_sequence_insert_sorted (level->seq, elt,
|
|
|
|
|
gtk_tree_model_sort_compare_func,
|
|
|
|
|
&data);
|
|
|
|
|
}
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
free_sort_data (&data);
|
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;
|
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
walker2 = walker->parent_elt;
|
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)
|
2011-06-02 20:01:45 +00:00
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, priv->root, TRUE);
|
2010-12-18 04:49:27 +00:00
|
|
|
|
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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i, n_columns;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
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.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *child_indices;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
SortLevel *level;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
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);
|
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)
|
2011-08-07 15:58:37 +00:00
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
|
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
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *tmp;
|
|
|
|
|
GSequenceIter *siter;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (child_indices[i] >= g_sequence_get_length (level->seq))
|
2001-10-19 20:53:08 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2011-08-10 21:24:58 +00:00
|
|
|
|
tmp = lookup_elt_with_offset (tree_model_sort, level,
|
|
|
|
|
child_indices[i], &siter);
|
|
|
|
|
if (tmp)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_append_index (retval, g_sequence_iter_get_position (siter));
|
|
|
|
|
if (tmp->children == NULL && build_levels)
|
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, tmp);
|
|
|
|
|
|
|
|
|
|
level = tmp->children;
|
|
|
|
|
found_child = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
|
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
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* point to the same row in the sorted model. If @child_path isn’t a valid
|
2005-07-25 13:55:31 +00:00
|
|
|
|
* path on the child model, then %NULL is returned.
|
2001-10-25 20:32:40 +00:00
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): A newly allocated #GtkTreePath, or %NULL
|
2001-10-25 20:32:40 +00:00
|
|
|
|
**/
|
|
|
|
|
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.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE, if @sort_iter was set, i.e. if @sort_iter is a
|
2008-05-28 09:02:29 +00:00
|
|
|
|
* 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
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): 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;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int *sorted_indices;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
SortLevel *level;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int i;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2011-08-07 15:58:37 +00:00
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, NULL, NULL);
|
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++)
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = NULL;
|
|
|
|
|
GSequenceIter *siter;
|
2002-04-17 22:26:44 +00:00
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
|
if ((level == NULL) ||
|
2011-08-10 21:24:58 +00:00
|
|
|
|
(g_sequence_get_length (level->seq) <= sorted_indices[i]))
|
2001-10-19 20:53:08 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2002-04-17 22:26:44 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->seq, sorted_indices[i]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elt = GET_ELT (siter);
|
2020-03-05 06:02:24 +00:00
|
|
|
|
g_assert (elt);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
if (elt->children == NULL)
|
|
|
|
|
gtk_tree_model_sort_build_level (tree_model_sort, level, elt);
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
gtk_tree_path_append_index (retval, elt->offset);
|
|
|
|
|
level = elt->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,
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *parent_elt)
|
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;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
SortLevel *new_level;
|
2020-07-24 13:54:49 +00:00
|
|
|
|
int length = 0;
|
|
|
|
|
int 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
|
|
|
|
|
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);
|
2011-06-02 19:51:51 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_sort_ref_node (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
|
&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);
|
2011-08-10 21:24:58 +00:00
|
|
|
|
new_level->seq = g_sequence_new (sort_elt_free);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
new_level->ref_count = 0;
|
|
|
|
|
new_level->parent_level = parent_level;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
new_level->parent_elt = parent_elt;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
if (parent_elt)
|
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
|
|
|
|
{
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt->zero_ref_count++;
|
2001-10-03 18:29:20 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
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++)
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *sort_elt;
|
|
|
|
|
|
|
|
|
|
sort_elt = sort_elt_new ();
|
|
|
|
|
sort_elt->offset = i;
|
|
|
|
|
sort_elt->zero_ref_count = 0;
|
|
|
|
|
sort_elt->ref_count = 0;
|
|
|
|
|
sort_elt->children = NULL;
|
2001-10-19 20:53:08 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_SORT_CACHE_CHILD_ITERS (tree_model_sort))
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-10 21:24:58 +00:00
|
|
|
|
|
|
|
|
|
sort_elt->siter = g_sequence_append (new_level->seq, sort_elt);
|
2001-10-19 20:53:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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,
|
2011-06-02 20:01:45 +00:00
|
|
|
|
SortLevel *sort_level,
|
|
|
|
|
gboolean unref)
|
2000-11-09 16:52:17 +00:00
|
|
|
|
{
|
2010-12-18 04:49:27 +00:00
|
|
|
|
GtkTreeModelSortPrivate *priv = tree_model_sort->priv;
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
GSequenceIter *end_siter;
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
2001-10-19 20:53:08 +00:00
|
|
|
|
g_assert (sort_level);
|
2000-11-10 19:38:53 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
end_siter = g_sequence_get_end_iter (sort_level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (sort_level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
2006-09-27 12:08:12 +00:00
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
|
|
|
|
|
|
|
|
|
if (elt->children)
|
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort,
|
|
|
|
|
elt->children, unref);
|
2006-09-27 12:08:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
SortElt *parent_elt = sort_level->parent_elt;
|
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
|
|
|
|
{
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt->zero_ref_count--;
|
2002-01-15 00:12:30 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
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
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
if (sort_level->parent_elt)
|
2011-06-02 19:51:51 +00:00
|
|
|
|
{
|
2011-06-02 20:01:45 +00:00
|
|
|
|
if (unref)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter parent_iter;
|
2011-06-02 19:51:51 +00:00
|
|
|
|
|
2011-06-02 20:01:45 +00:00
|
|
|
|
parent_iter.stamp = tree_model_sort->priv->stamp;
|
|
|
|
|
parent_iter.user_data = sort_level->parent_level;
|
2011-08-07 15:58:37 +00:00
|
|
|
|
parent_iter.user_data2 = sort_level->parent_elt;
|
2011-06-02 19:51:51 +00:00
|
|
|
|
|
2011-06-02 20:01:45 +00:00
|
|
|
|
gtk_tree_model_sort_unref_node (GTK_TREE_MODEL (tree_model_sort),
|
|
|
|
|
&parent_iter);
|
|
|
|
|
}
|
2011-06-02 19:51:51 +00:00
|
|
|
|
|
2011-08-07 15:58:37 +00:00
|
|
|
|
sort_level->parent_elt->children = NULL;
|
2011-06-02 19:51:51 +00:00
|
|
|
|
}
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
g_sequence_free (sort_level->seq);
|
|
|
|
|
sort_level->seq = NULL;
|
2001-12-26 22:43:53 +00:00
|
|
|
|
|
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
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_sort_clear_cache_helper_iter (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelSort *tree_model_sort = user_data;
|
|
|
|
|
SortElt *elt = data;
|
|
|
|
|
|
|
|
|
|
if (elt->zero_ref_count > 0)
|
|
|
|
|
gtk_tree_model_sort_clear_cache_helper (tree_model_sort, elt->children);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
{
|
2001-10-19 20:53:08 +00:00
|
|
|
|
g_assert (level != NULL);
|
2001-09-02 21:47:12 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
g_sequence_foreach (level->seq, gtk_tree_model_sort_clear_cache_helper_iter,
|
|
|
|
|
tree_model_sort);
|
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)
|
2011-06-02 20:01:45 +00:00
|
|
|
|
gtk_tree_model_sort_free_level (tree_model_sort, level, TRUE);
|
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
|
|
|
|
|
*
|
2014-02-07 19:03:49 +00:00
|
|
|
|
* 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
|
2014-02-07 19:03:49 +00:00
|
|
|
|
* 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
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* of any cached iterators that haven’t been reffed with
|
2001-10-19 20:53:08 +00:00
|
|
|
|
* gtk_tree_model_ref_node(). This might be useful if the child model being
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* sorted is static (and doesn’t change often) and there has been a lot of
|
2001-10-19 20:53:08 +00:00
|
|
|
|
* 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)
|
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
GSequenceIter *end_siter;
|
2002-06-04 17:17:49 +00:00
|
|
|
|
|
2011-08-10 21:24:58 +00:00
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter != end_siter; siter = g_sequence_iter_next (siter))
|
2002-06-04 17:17:49 +00:00
|
|
|
|
{
|
2011-08-10 21:24:58 +00:00
|
|
|
|
SortElt *elt = g_sequence_get (siter);
|
2002-06-04 17:17:49 +00:00
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*
|
2014-02-05 07:17:03 +00:00
|
|
|
|
* > This function is slow. Only use it for debugging and/or testing
|
|
|
|
|
* > purposes.
|
2002-06-04 17:17:49 +00:00
|
|
|
|
*
|
|
|
|
|
* Checks if the given iter is a valid iter for this #GtkTreeModelSort.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE if the iter is valid, %FALSE if the iter is invalid.
|
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
|
|
|
|
}
|