2003-07-11 12:51:24 +00:00
|
|
|
|
/* gtktreemodelfilter.c
|
|
|
|
|
* Copyright (C) 2000,2001 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
|
|
|
|
|
* Copyright (C) 2001-2003 Kristian Rietveld <kris@gtk.org>
|
|
|
|
|
*
|
2003-10-24 18:36:55 +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.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
2003-10-24 18:36:55 +00:00
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2003-10-24 18:36:55 +00:00
|
|
|
|
* Library General Public License for more details.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
2003-10-24 18:36:55 +00:00
|
|
|
|
* 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/>.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
|
#include "config.h"
|
2003-07-11 12:51:24 +00:00
|
|
|
|
#include "gtktreemodelfilter.h"
|
2003-10-23 18:25:53 +00:00
|
|
|
|
#include "gtkintl.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"
|
2005-03-22 02:14:55 +00:00
|
|
|
|
#include "gtkprivate.h"
|
2003-07-11 12:51:24 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
|
2010-10-22 20:32:10 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SECTION:gtktreemodelfilter
|
|
|
|
|
* @Short_description: A GtkTreeModel which hides parts of an underlying tree model
|
|
|
|
|
* @Title: GtkTreeModelFilter
|
|
|
|
|
* @See_also:#GtkTreeModelSort
|
|
|
|
|
*
|
|
|
|
|
* A #GtkTreeModelFilter is a tree model which wraps another tree model,
|
|
|
|
|
* and can do the following things:
|
2014-02-02 06:07:39 +00:00
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* - Filter specific rows, based on data from a “visible column”, a column
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* storing booleans indicating whether the row should be filtered or not,
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* or based on the return value of a “visible function”, which gets a
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* model, iter and user_data and returns a boolean indicating whether the
|
|
|
|
|
* row should be filtered or not.
|
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* - Modify the “appearance” of the model, using a modify function.
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* This is extremely powerful and allows for just changing some
|
|
|
|
|
* values and also for creating a completely different model based
|
|
|
|
|
* on the given child model.
|
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* - Set a different root node, also known as a “virtual root”. You can pass
|
2014-02-02 06:07:39 +00:00
|
|
|
|
* in a #GtkTreePath indicating the root node for the filter at construction
|
|
|
|
|
* time.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* The basic API is similar to #GtkTreeModelSort. For an example on its usage,
|
|
|
|
|
* see the section on #GtkTreeModelSort.
|
|
|
|
|
*
|
|
|
|
|
* When using #GtkTreeModelFilter, it is important to realize that
|
|
|
|
|
* #GtkTreeModelFilter maintains an internal cache of all nodes which are
|
|
|
|
|
* visible in its clients. The cache is likely to be a subtree of the tree
|
|
|
|
|
* exposed by the child model. #GtkTreeModelFilter will not cache the entire
|
|
|
|
|
* child model when unnecessary to not compromise the caching mechanism
|
|
|
|
|
* that is exposed by the reference counting scheme. If the child model
|
|
|
|
|
* implements reference counting, unnecessary signals may not be emitted
|
|
|
|
|
* because of reference counting rule 3, see the #GtkTreeModel
|
|
|
|
|
* documentation. (Note that e.g. #GtkTreeStore does not implement
|
|
|
|
|
* reference counting and will always emit all signals, even when
|
|
|
|
|
* the receiving node is not visible).
|
|
|
|
|
*
|
|
|
|
|
* Because of this, limitations for possible visible functions do apply.
|
|
|
|
|
* In general, visible functions should only use data or properties from
|
|
|
|
|
* the node for which the visibility state must be determined, its siblings
|
|
|
|
|
* or its parents. Usually, having a dependency on the state of any child
|
|
|
|
|
* node is not possible, unless references are taken on these explicitly.
|
|
|
|
|
* When no such reference exists, no signals may be received for these child
|
|
|
|
|
* nodes (see reference couting rule number 3 in the #GtkTreeModel section).
|
|
|
|
|
*
|
|
|
|
|
* Determining the visibility state of a given node based on the state
|
|
|
|
|
* of its child nodes is a frequently occurring use case. Therefore,
|
|
|
|
|
* #GtkTreeModelFilter explicitly supports this. For example, when a node
|
|
|
|
|
* does not have any children, you might not want the node to be visible.
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* As soon as the first row is added to the node’s child level (or the
|
|
|
|
|
* last row removed), the node’s visibility should be updated.
|
2011-08-20 07:36:35 +00:00
|
|
|
|
*
|
|
|
|
|
* This introduces a dependency from the node on its child nodes. In order
|
2014-01-14 14:02:26 +00:00
|
|
|
|
* to accommodate this, #GtkTreeModelFilter must make sure the necessary
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* signals are received from the child model. This is achieved by building,
|
|
|
|
|
* for all nodes which are exposed as visible nodes to #GtkTreeModelFilter's
|
|
|
|
|
* clients, the child level (if any) and take a reference on the first node
|
|
|
|
|
* in this level. Furthermore, for every row-inserted, row-changed or
|
|
|
|
|
* row-deleted signal (also these which were not handled because the node
|
|
|
|
|
* was not cached), #GtkTreeModelFilter will check if the visibility state
|
|
|
|
|
* of any parent node has changed.
|
|
|
|
|
*
|
|
|
|
|
* Beware, however, that this explicit support is limited to these two
|
|
|
|
|
* cases. For example, if you want a node to be visible only if two nodes
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* in a child’s child level (2 levels deeper) are visible, you are on your
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* own. In this case, either rely on #GtkTreeStore to emit all signals
|
|
|
|
|
* because it does not implement reference counting, or for models that
|
|
|
|
|
* do implement reference counting, obtain references on these child levels
|
|
|
|
|
* yourself.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-08-20 07:36:35 +00:00
|
|
|
|
/* Notes on this implementation of GtkTreeModelFilter
|
|
|
|
|
* ==================================================
|
|
|
|
|
*
|
|
|
|
|
* Warnings
|
|
|
|
|
* --------
|
|
|
|
|
*
|
|
|
|
|
* In this code there is a potential for confusion as to whether an iter,
|
|
|
|
|
* path or value refers to the GtkTreeModelFilter model, or to the child
|
|
|
|
|
* model that has been set. As a convention, variables referencing the
|
|
|
|
|
* child model will have a c_ prefix before them (ie. c_iter, c_value,
|
|
|
|
|
* c_path). In case the c_ prefixed names are already in use, an f_
|
|
|
|
|
* prefix is used. Conversion of iterators and paths between
|
|
|
|
|
* GtkTreeModelFilter and the child model is done through the various
|
|
|
|
|
* gtk_tree_model_filter_convert_* functions.
|
|
|
|
|
*
|
|
|
|
|
* Even though the GtkTreeModelSort and GtkTreeModelFilter have very
|
|
|
|
|
* similar data structures, many assumptions made in the GtkTreeModelSort
|
|
|
|
|
* code do *not* apply in the GtkTreeModelFilter case. Reference counting
|
|
|
|
|
* in particular is more complicated in GtkTreeModelFilter, because
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* we explicitly support reliance on the state of a node’s children as
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* outlined in the public API documentation. Because of these differences,
|
|
|
|
|
* you are strongly recommended to first read through these notes before
|
|
|
|
|
* making any modification to the code.
|
|
|
|
|
*
|
|
|
|
|
* Iterator format
|
|
|
|
|
* ---------------
|
|
|
|
|
*
|
|
|
|
|
* The iterator format of iterators handed out by GtkTreeModelFilter is
|
|
|
|
|
* as follows:
|
2005-10-25 21:00:40 +00:00
|
|
|
|
*
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* iter->stamp = filter->priv->stamp
|
|
|
|
|
* iter->user_data = FilterLevel
|
|
|
|
|
* iter->user_data2 = FilterElt
|
2005-10-25 21:00:40 +00:00
|
|
|
|
*
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* Internal data structure
|
|
|
|
|
* -----------------------
|
|
|
|
|
*
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* Using FilterLevel and FilterElt, GtkTreeModelFilter maintains a “cache”
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* of the mapping from GtkTreeModelFilter nodes to nodes in the child model.
|
|
|
|
|
* This is to avoid re-creating a level each time (which involves computing
|
|
|
|
|
* visibility for each node in that level) an operation is requested on
|
|
|
|
|
* GtkTreeModelFilter, such as get iter, get path and get value.
|
|
|
|
|
*
|
|
|
|
|
* A FilterElt corresponds to a single node. The FilterElt can either be
|
|
|
|
|
* visible or invisible in the model that is exposed to the clients of this
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* GtkTreeModelFilter. The visibility state is stored in the “visible_siter”
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* field, which is NULL when the node is not visible. The FilterLevel keeps
|
|
|
|
|
* a reference to the parent FilterElt and its FilterLevel (if any). The
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* FilterElt can have a “children” pointer set, which points at a child
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* level (a sub level).
|
|
|
|
|
*
|
|
|
|
|
* In a FilterLevel, two separate GSequences are maintained. One contains
|
|
|
|
|
* all nodes of this FilterLevel, regardless of the visibility state of
|
|
|
|
|
* the node. Another contains only visible nodes. A visible FilterElt
|
|
|
|
|
* is thus present in both the full and the visible GSequence. The
|
|
|
|
|
* GSequence allows for fast access, addition and removal of 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 *visible* GSequence is the order in
|
|
|
|
|
* which the nodes are exposed to clients of the GtkTreeModelFilter.
|
|
|
|
|
* II. The mapping from this model to its child model. Each FilterElt
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* contains an “offset” field which is the offset of the
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* corresponding node in the child model.
|
|
|
|
|
*
|
|
|
|
|
* Throughout the code, two kinds of paths relative to the GtkTreeModelFilter
|
|
|
|
|
* (those generated from the sequence positions) are used. There are paths
|
|
|
|
|
* which take non-visible nodes into account (generated from the full
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* sequences) and paths which don’t (generated from the visible sequences).
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* Paths which have been generated from the full sequences should only be
|
|
|
|
|
* used internally and NEVER be passed along with a signal emisson.
|
|
|
|
|
*
|
|
|
|
|
* Reference counting
|
|
|
|
|
* ------------------
|
|
|
|
|
*
|
|
|
|
|
* GtkTreeModelFilter forwards all reference and unreference operations
|
|
|
|
|
* to the corresponding node in the child model. In addition,
|
|
|
|
|
* GtkTreeModelFilter will also add references of its own. The full reference
|
|
|
|
|
* count of each node (i.e. all forwarded references and these by the
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* filter model) is maintained internally in the “ref_count” fields in
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* FilterElt and FilterLevel. Because there is a need to determine whether
|
|
|
|
|
* a node should be visible for the client, the reference count of only
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* the forwarded references is maintained as well, in the “ext_ref_count”
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* fields.
|
|
|
|
|
*
|
|
|
|
|
* In a few cases, GtkTreeModelFilter takes additional references on
|
|
|
|
|
* nodes. The first case is that a reference is taken on the parent
|
|
|
|
|
* (if any) of each level. This happens in gtk_tree_model_filter_build_level()
|
|
|
|
|
* and the reference is released again in gtk_tree_model_filter_free_level().
|
|
|
|
|
* This ensures that for all references which are taken by the filter
|
|
|
|
|
* model, all parent nodes are referenced according to reference counting
|
|
|
|
|
* rule 1 in the GtkTreeModel documentation.
|
|
|
|
|
*
|
|
|
|
|
* A second case is required to support visible functions which depend on
|
2014-02-07 18:01:26 +00:00
|
|
|
|
* the state of a node’s children (see the public API documentation for
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* GtkTreeModelFilter above). We build the child level of each node that
|
|
|
|
|
* could be visible in the client (i.e. the level has an ext_ref_count > 0;
|
|
|
|
|
* not the elt, because the elt might be invisible and thus unreferenced
|
|
|
|
|
* by the client). For each node that becomes visible, due to insertion or
|
|
|
|
|
* changes in visibility state, it is checked whether node has children, if
|
|
|
|
|
* so the child level is built.
|
|
|
|
|
*
|
|
|
|
|
* A reference is taken on the first node of each level so that the child
|
|
|
|
|
* model will emit all signals for this level, due to reference counting
|
|
|
|
|
* rule 3 in the GtkTreeModel documentation. If due to changes in the level,
|
|
|
|
|
* another node becomes the first node (e.g. due to insertion or reordering),
|
|
|
|
|
* this reference is transferred from the old to the new first node.
|
|
|
|
|
*
|
|
|
|
|
* When a level has an *external* reference count of zero (which means that
|
|
|
|
|
* none of the nodes in the level is referenced by the clients), the level
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* has a “zero ref count” on all its parents. As soon as the level reaches
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* an *external* reference count of zero, the zero ref count value is
|
|
|
|
|
* incremented by one for all parents of this level. Due to the additional
|
|
|
|
|
* references taken by the filter model, it is important to base the
|
|
|
|
|
* zero ref count on the external reference count instead of on the full
|
|
|
|
|
* reference count of the node.
|
|
|
|
|
*
|
|
|
|
|
* The zero ref count value aids in determining which portions of the
|
|
|
|
|
* cache are possibly unused and could be removed. If a FilterElt has
|
|
|
|
|
* a zero ref count of one, then its child level is unused. However, the
|
|
|
|
|
* child level can only be removed from the cache if the FilterElt's
|
2011-09-07 07:25:36 +00:00
|
|
|
|
* parent level has an external ref count of zero. (Not the parent elt,
|
|
|
|
|
* because an invisible parent elt with external ref count == 0 might still
|
|
|
|
|
* become visible because of a state change in its child level!). Otherwise,
|
|
|
|
|
* monitoring this level is necessary to possibly update the visibility state
|
2011-08-20 07:36:35 +00:00
|
|
|
|
* of the parent. This is an important difference from GtkTreeModelSort!
|
|
|
|
|
*
|
|
|
|
|
* Signals are only required for levels with an external ref count > 0.
|
|
|
|
|
* This due to reference counting rule 3, see the GtkTreeModel
|
|
|
|
|
* documentation. In the GtkTreeModelFilter we try hard to stick to this
|
|
|
|
|
* rule and not emit redundant signals (though redundant emissions of
|
|
|
|
|
* row-has-child-toggled could appear frequently; it does happen that
|
|
|
|
|
* we simply forward the signal emitted by e.g. GtkTreeStore but also
|
|
|
|
|
* emit our own copy).
|
2005-10-25 21:00:40 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2011-08-20 07:36:35 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
typedef struct _FilterElt FilterElt;
|
|
|
|
|
typedef struct _FilterLevel FilterLevel;
|
|
|
|
|
|
|
|
|
|
struct _FilterElt
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
FilterLevel *children;
|
|
|
|
|
gint offset;
|
|
|
|
|
gint ref_count;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gint ext_ref_count;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint zero_ref_count;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *visible_siter; /* iter into visible_seq */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _FilterLevel
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequence *seq;
|
|
|
|
|
GSequence *visible_seq;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint ref_count;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gint ext_ref_count;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
FilterLevel *parent_level;
|
|
|
|
|
};
|
|
|
|
|
|
2003-10-11 23:12:20 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
struct _GtkTreeModelFilterPrivate
|
|
|
|
|
{
|
2011-04-12 16:50:05 +00:00
|
|
|
|
GtkTreeModel *child_model;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gpointer root;
|
2011-04-12 16:50:05 +00:00
|
|
|
|
GtkTreePath *virtual_root;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint stamp;
|
|
|
|
|
guint child_flags;
|
|
|
|
|
gint zero_ref_count;
|
2011-04-12 16:50:05 +00:00
|
|
|
|
gint visible_column;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
GtkTreeModelFilterVisibleFunc visible_func;
|
|
|
|
|
gpointer visible_data;
|
2008-06-18 09:12:32 +00:00
|
|
|
|
GDestroyNotify visible_destroy;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
GType *modify_types;
|
|
|
|
|
GtkTreeModelFilterModifyFunc modify_func;
|
|
|
|
|
gpointer modify_data;
|
2008-06-18 09:12:32 +00:00
|
|
|
|
GDestroyNotify modify_destroy;
|
2011-04-12 16:50:05 +00:00
|
|
|
|
gint modify_n_columns;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-04-12 16:50:05 +00:00
|
|
|
|
guint visible_method_set : 1;
|
|
|
|
|
guint modify_func_set : 1;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-04-12 16:50:05 +00:00
|
|
|
|
guint in_row_deleted : 1;
|
|
|
|
|
guint virtual_root_deleted : 1;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* signal ids */
|
2010-10-08 00:37:23 +00:00
|
|
|
|
gulong changed_id;
|
|
|
|
|
gulong inserted_id;
|
|
|
|
|
gulong has_child_toggled_id;
|
|
|
|
|
gulong deleted_id;
|
|
|
|
|
gulong reordered_id;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
PROP_0,
|
|
|
|
|
PROP_CHILD_MODEL,
|
|
|
|
|
PROP_VIRTUAL_ROOT
|
|
|
|
|
};
|
|
|
|
|
|
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_FILTER_CACHE_CHILD_ITERS(filter) \
|
2003-07-11 12:51:24 +00:00
|
|
|
|
(((GtkTreeModelFilter *)filter)->priv->child_flags & GTK_TREE_MODEL_ITERS_PERSIST)
|
2011-05-09 08:04:24 +00:00
|
|
|
|
#else
|
|
|
|
|
# define GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS(filter) (FALSE)
|
|
|
|
|
#endif
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-09-07 07:36:18 +00:00
|
|
|
|
/* Defining this constant enables more assertions, which will be
|
|
|
|
|
* helpful when debugging the code.
|
|
|
|
|
*/
|
|
|
|
|
#undef MODEL_FILTER_DEBUG
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
#define FILTER_ELT(filter_elt) ((FilterElt *)filter_elt)
|
|
|
|
|
#define FILTER_LEVEL(filter_level) ((FilterLevel *)filter_level)
|
2011-08-07 15:11:13 +00:00
|
|
|
|
#define GET_ELT(siter) ((FilterElt*) (siter ? g_sequence_get (siter) : NULL))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* general code (object/interface init, properties, etc) */
|
|
|
|
|
static void gtk_tree_model_filter_tree_model_init (GtkTreeModelIface *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_filter_drag_source_init (GtkTreeDragSourceIface *iface);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void gtk_tree_model_filter_finalize (GObject *object);
|
|
|
|
|
static void gtk_tree_model_filter_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
static void gtk_tree_model_filter_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
|
|
/* signal handlers */
|
|
|
|
|
static void gtk_tree_model_filter_row_changed (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gpointer data);
|
|
|
|
|
static void gtk_tree_model_filter_row_inserted (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gpointer data);
|
|
|
|
|
static void gtk_tree_model_filter_row_has_child_toggled (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gpointer data);
|
|
|
|
|
static void gtk_tree_model_filter_row_deleted (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
gpointer data);
|
|
|
|
|
static void gtk_tree_model_filter_rows_reordered (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gint *new_order,
|
|
|
|
|
gpointer data);
|
|
|
|
|
|
|
|
|
|
/* GtkTreeModel interface */
|
2004-08-03 22:41:31 +00:00
|
|
|
|
static GtkTreeModelFlags gtk_tree_model_filter_get_flags (GtkTreeModel *model);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static gint gtk_tree_model_filter_get_n_columns (GtkTreeModel *model);
|
|
|
|
|
static GType gtk_tree_model_filter_get_column_type (GtkTreeModel *model,
|
|
|
|
|
gint index);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
static gboolean gtk_tree_model_filter_get_iter_full (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreePath *path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static gboolean gtk_tree_model_filter_get_iter (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreePath *path);
|
|
|
|
|
static GtkTreePath *gtk_tree_model_filter_get_path (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
static void gtk_tree_model_filter_get_value (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gint column,
|
|
|
|
|
GValue *value);
|
|
|
|
|
static gboolean gtk_tree_model_filter_iter_next (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter);
|
2011-01-06 04:39:11 +00:00
|
|
|
|
static gboolean gtk_tree_model_filter_iter_previous (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static gboolean gtk_tree_model_filter_iter_children (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *parent);
|
|
|
|
|
static gboolean gtk_tree_model_filter_iter_has_child (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
static gint gtk_tree_model_filter_iter_n_children (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
static gboolean gtk_tree_model_filter_iter_nth_child (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
|
gint n);
|
|
|
|
|
static gboolean gtk_tree_model_filter_iter_parent (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *child);
|
|
|
|
|
static void gtk_tree_model_filter_ref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
|
static void gtk_tree_model_filter_unref_node (GtkTreeModel *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_filter_row_draggable (GtkTreeDragSource *drag_source,
|
|
|
|
|
GtkTreePath *path);
|
2020-02-18 00:41:42 +00:00
|
|
|
|
static GdkContentProvider *
|
|
|
|
|
gtk_tree_model_filter_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_filter_drag_data_delete (GtkTreeDragSource *drag_source,
|
|
|
|
|
GtkTreePath *path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
static void gtk_tree_model_filter_build_level (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *parent_level,
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *parent_elt,
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gboolean emit_inserted);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void gtk_tree_model_filter_free_level (GtkTreeModelFilter *filter,
|
2011-05-09 08:29:37 +00:00
|
|
|
|
FilterLevel *filter_level,
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gboolean unref_self,
|
|
|
|
|
gboolean unref_parent,
|
2011-09-07 20:06:40 +00:00
|
|
|
|
gboolean unref_external);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
static GtkTreePath *gtk_tree_model_filter_elt_get_path (FilterLevel *level,
|
|
|
|
|
FilterElt *elt,
|
|
|
|
|
GtkTreePath *root);
|
|
|
|
|
|
|
|
|
|
static GtkTreePath *gtk_tree_model_filter_add_root (GtkTreePath *src,
|
|
|
|
|
GtkTreePath *root);
|
|
|
|
|
static GtkTreePath *gtk_tree_model_filter_remove_root (GtkTreePath *src,
|
|
|
|
|
GtkTreePath *root);
|
|
|
|
|
|
|
|
|
|
static void gtk_tree_model_filter_increment_stamp (GtkTreeModelFilter *filter);
|
|
|
|
|
|
2009-12-09 09:21:34 +00:00
|
|
|
|
static void gtk_tree_model_filter_real_modify (GtkTreeModelFilter *self,
|
|
|
|
|
GtkTreeModel *child_model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GValue *value,
|
|
|
|
|
gint column);
|
|
|
|
|
static gboolean gtk_tree_model_filter_real_visible (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModel *child_model,
|
|
|
|
|
GtkTreeIter *child_iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static gboolean gtk_tree_model_filter_visible (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeIter *child_iter);
|
|
|
|
|
static void gtk_tree_model_filter_clear_cache_helper (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level);
|
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
static void gtk_tree_model_filter_real_ref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean external);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void gtk_tree_model_filter_real_unref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gboolean external,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gboolean propagate_unref);
|
|
|
|
|
|
|
|
|
|
static void gtk_tree_model_filter_set_model (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModel *child_model);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
static void gtk_tree_model_filter_ref_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *path);
|
|
|
|
|
static void gtk_tree_model_filter_unref_path (GtkTreeModelFilter *filter,
|
2011-05-09 08:29:37 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
int depth);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void gtk_tree_model_filter_set_root (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *root);
|
|
|
|
|
|
|
|
|
|
static GtkTreePath *gtk_real_tree_model_filter_convert_child_path_to_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *child_path,
|
|
|
|
|
gboolean build_levels,
|
2004-08-04 05:38:58 +00:00
|
|
|
|
gboolean fetch_children);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2009-09-01 14:10:05 +00:00
|
|
|
|
static gboolean gtk_tree_model_filter_elt_is_visible_in_target (FilterLevel *level,
|
|
|
|
|
FilterElt *elt);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-05-14 09:47:01 +00:00
|
|
|
|
static FilterElt *gtk_tree_model_filter_insert_elt_in_level (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
gint offset,
|
|
|
|
|
gint *index);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static FilterElt *gtk_tree_model_filter_fetch_child (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
gint offset,
|
|
|
|
|
gint *index);
|
2011-05-20 18:39:12 +00:00
|
|
|
|
static void gtk_tree_model_filter_remove_elt_from_level (GtkTreeModelFilter *filter,
|
2011-05-20 18:33:30 +00:00
|
|
|
|
FilterLevel *level,
|
|
|
|
|
FilterElt *elt);
|
2004-08-04 05:38:58 +00:00
|
|
|
|
static void gtk_tree_model_filter_update_children (GtkTreeModelFilter *filter,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
FilterLevel *level,
|
|
|
|
|
FilterElt *elt);
|
2011-05-21 09:45:08 +00:00
|
|
|
|
static void gtk_tree_model_filter_emit_row_inserted_for_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
|
2006-05-02 23:56:43 +00:00
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkTreeModelFilter, gtk_tree_model_filter, G_TYPE_OBJECT,
|
2013-06-27 19:02:52 +00:00
|
|
|
|
G_ADD_PRIVATE (GtkTreeModelFilter)
|
2006-05-02 23:56:43 +00:00
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
|
|
|
|
|
gtk_tree_model_filter_tree_model_init)
|
|
|
|
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
|
2006-05-14 04:25:34 +00:00
|
|
|
|
gtk_tree_model_filter_drag_source_init))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_init (GtkTreeModelFilter *filter)
|
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
|
filter->priv = gtk_tree_model_filter_get_instance_private (filter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->visible_column = -1;
|
|
|
|
|
filter->priv->zero_ref_count = 0;
|
|
|
|
|
filter->priv->visible_method_set = FALSE;
|
|
|
|
|
filter->priv->modify_func_set = FALSE;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
filter->priv->in_row_deleted = FALSE;
|
2006-09-27 12:11:46 +00:00
|
|
|
|
filter->priv->virtual_root_deleted = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_class_init (GtkTreeModelFilterClass *filter_class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
|
|
object_class = (GObjectClass *) filter_class;
|
|
|
|
|
|
|
|
|
|
object_class->set_property = gtk_tree_model_filter_set_property;
|
|
|
|
|
object_class->get_property = gtk_tree_model_filter_get_property;
|
|
|
|
|
|
|
|
|
|
object_class->finalize = gtk_tree_model_filter_finalize;
|
|
|
|
|
|
2009-12-09 09:21:34 +00:00
|
|
|
|
filter_class->visible = gtk_tree_model_filter_real_visible;
|
|
|
|
|
filter_class->modify = gtk_tree_model_filter_real_modify;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_CHILD_MODEL,
|
2005-03-09 06:15:13 +00:00
|
|
|
|
g_param_spec_object ("child-model",
|
2016-03-26 22:59:02 +00:00
|
|
|
|
P_("The child model"),
|
|
|
|
|
P_("The model for the filtermodel to filter"),
|
2003-07-11 12:51:24 +00:00
|
|
|
|
GTK_TYPE_TREE_MODEL,
|
2005-03-22 02:14:55 +00:00
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
|
PROP_VIRTUAL_ROOT,
|
2005-03-09 06:15:13 +00:00
|
|
|
|
g_param_spec_boxed ("virtual-root",
|
2016-03-26 22:59:02 +00:00
|
|
|
|
P_("The virtual root"),
|
|
|
|
|
P_("The virtual root (relative to the child model) for this filtermodel"),
|
2003-07-11 12:51:24 +00:00
|
|
|
|
GTK_TYPE_TREE_PATH,
|
2005-03-22 02:14:55 +00:00
|
|
|
|
GTK_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_tree_model_init (GtkTreeModelIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->get_flags = gtk_tree_model_filter_get_flags;
|
|
|
|
|
iface->get_n_columns = gtk_tree_model_filter_get_n_columns;
|
|
|
|
|
iface->get_column_type = gtk_tree_model_filter_get_column_type;
|
|
|
|
|
iface->get_iter = gtk_tree_model_filter_get_iter;
|
|
|
|
|
iface->get_path = gtk_tree_model_filter_get_path;
|
|
|
|
|
iface->get_value = gtk_tree_model_filter_get_value;
|
|
|
|
|
iface->iter_next = gtk_tree_model_filter_iter_next;
|
2011-01-06 04:39:11 +00:00
|
|
|
|
iface->iter_previous = gtk_tree_model_filter_iter_previous;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
iface->iter_children = gtk_tree_model_filter_iter_children;
|
|
|
|
|
iface->iter_has_child = gtk_tree_model_filter_iter_has_child;
|
|
|
|
|
iface->iter_n_children = gtk_tree_model_filter_iter_n_children;
|
|
|
|
|
iface->iter_nth_child = gtk_tree_model_filter_iter_nth_child;
|
|
|
|
|
iface->iter_parent = gtk_tree_model_filter_iter_parent;
|
|
|
|
|
iface->ref_node = gtk_tree_model_filter_ref_node;
|
|
|
|
|
iface->unref_node = gtk_tree_model_filter_unref_node;
|
|
|
|
|
}
|
|
|
|
|
|
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_filter_drag_source_init (GtkTreeDragSourceIface *iface)
|
|
|
|
|
{
|
|
|
|
|
iface->row_draggable = gtk_tree_model_filter_row_draggable;
|
|
|
|
|
iface->drag_data_delete = gtk_tree_model_filter_drag_data_delete;
|
|
|
|
|
iface->drag_data_get = gtk_tree_model_filter_drag_data_get;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_finalize (GObject *object)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *) object;
|
|
|
|
|
|
2006-09-27 12:11:46 +00:00
|
|
|
|
if (filter->priv->virtual_root && !filter->priv->virtual_root_deleted)
|
|
|
|
|
{
|
2011-05-09 08:29:37 +00:00
|
|
|
|
gtk_tree_model_filter_unref_path (filter, filter->priv->virtual_root,
|
|
|
|
|
-1);
|
2006-09-27 12:11:46 +00:00
|
|
|
|
filter->priv->virtual_root_deleted = TRUE;
|
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_model_filter_set_model (filter, NULL);
|
|
|
|
|
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
gtk_tree_path_free (filter->priv->virtual_root);
|
|
|
|
|
|
|
|
|
|
if (filter->priv->root)
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, filter->priv->root, TRUE, TRUE, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2007-03-09 21:57:37 +00:00
|
|
|
|
g_free (filter->priv->modify_types);
|
2006-06-12 13:42:29 +00:00
|
|
|
|
|
|
|
|
|
if (filter->priv->modify_destroy)
|
|
|
|
|
filter->priv->modify_destroy (filter->priv->modify_data);
|
|
|
|
|
|
|
|
|
|
if (filter->priv->visible_destroy)
|
|
|
|
|
filter->priv->visible_destroy (filter->priv->visible_data);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* must chain up */
|
2006-05-02 23:56:43 +00:00
|
|
|
|
G_OBJECT_CLASS (gtk_tree_model_filter_parent_class)->finalize (object);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_set_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
const GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CHILD_MODEL:
|
|
|
|
|
gtk_tree_model_filter_set_model (filter, g_value_get_object (value));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_VIRTUAL_ROOT:
|
|
|
|
|
gtk_tree_model_filter_set_root (filter, g_value_get_boxed (value));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_get_property (GObject *object,
|
|
|
|
|
guint prop_id,
|
|
|
|
|
GValue *value,
|
|
|
|
|
GParamSpec *pspec)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (object);
|
|
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
|
{
|
|
|
|
|
case PROP_CHILD_MODEL:
|
|
|
|
|
g_value_set_object (value, filter->priv->child_model);
|
|
|
|
|
break;
|
|
|
|
|
case PROP_VIRTUAL_ROOT:
|
|
|
|
|
g_value_set_boxed (value, filter->priv->virtual_root);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* helpers */
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
static FilterElt *
|
|
|
|
|
filter_elt_new (void)
|
|
|
|
|
{
|
|
|
|
|
return g_slice_new (FilterElt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
filter_elt_free (gpointer elt)
|
|
|
|
|
{
|
|
|
|
|
g_slice_free (FilterElt, elt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
filter_elt_cmp (gconstpointer a,
|
|
|
|
|
gconstpointer b,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
const FilterElt *elt_a = a;
|
|
|
|
|
const FilterElt *elt_b = b;
|
|
|
|
|
|
|
|
|
|
if (elt_a->offset > elt_b->offset)
|
|
|
|
|
return +1;
|
|
|
|
|
else if (elt_a->offset < elt_b->offset)
|
|
|
|
|
return -1;
|
|
|
|
|
else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static FilterElt *
|
|
|
|
|
lookup_elt_with_offset (GSequence *seq,
|
|
|
|
|
gint offset,
|
|
|
|
|
GSequenceIter **ret_siter)
|
|
|
|
|
{
|
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
FilterElt dummy;
|
|
|
|
|
|
|
|
|
|
dummy.offset = offset;
|
|
|
|
|
siter = g_sequence_lookup (seq, &dummy, filter_elt_cmp, NULL);
|
|
|
|
|
|
|
|
|
|
if (ret_siter)
|
|
|
|
|
*ret_siter = siter;
|
|
|
|
|
|
|
|
|
|
return GET_ELT (siter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
increase_offset_iter (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
FilterElt *elt = data;
|
|
|
|
|
gint offset = GPOINTER_TO_INT (user_data);
|
|
|
|
|
|
|
|
|
|
if (elt->offset >= offset)
|
|
|
|
|
elt->offset++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
decrease_offset_iter (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
FilterElt *elt = data;
|
|
|
|
|
gint offset = GPOINTER_TO_INT (user_data);
|
|
|
|
|
|
|
|
|
|
if (elt->offset > offset)
|
|
|
|
|
elt->offset--;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_build_level (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *parent_level,
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *parent_elt,
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gboolean emit_inserted)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
GtkTreeIter first_node;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
GtkTreeIter root;
|
|
|
|
|
FilterLevel *new_level;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
FilterLevel *tmp_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *tmp_elt;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
GtkTreeIter f_iter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint length = 0;
|
|
|
|
|
gint i;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gboolean empty = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_assert (filter->priv->child_model != NULL);
|
|
|
|
|
|
2011-07-10 14:21:08 +00:00
|
|
|
|
/* Avoid building a level that already exists */
|
|
|
|
|
if (parent_level)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
g_assert (parent_elt->children == NULL);
|
2011-07-10 14:21:08 +00:00
|
|
|
|
else
|
|
|
|
|
g_assert (filter->priv->root == NULL);
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (filter->priv->in_row_deleted)
|
|
|
|
|
return;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!parent_level)
|
|
|
|
|
{
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_model_get_iter (filter->priv->child_model, &root, filter->priv->virtual_root) == FALSE)
|
|
|
|
|
return;
|
|
|
|
|
length = gtk_tree_model_iter_n_children (filter->priv->child_model, &root);
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_children (filter->priv->child_model, &iter, &root) == FALSE)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (!gtk_tree_model_get_iter_first (filter->priv->child_model, &iter))
|
|
|
|
|
return;
|
|
|
|
|
length = gtk_tree_model_iter_n_children (filter->priv->child_model, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter parent_iter;
|
|
|
|
|
GtkTreeIter child_parent_iter;
|
|
|
|
|
|
|
|
|
|
parent_iter.stamp = filter->priv->stamp;
|
|
|
|
|
parent_iter.user_data = parent_level;
|
|
|
|
|
parent_iter.user_data2 = parent_elt;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (filter,
|
|
|
|
|
&child_parent_iter,
|
|
|
|
|
&parent_iter);
|
|
|
|
|
if (gtk_tree_model_iter_children (filter->priv->child_model, &iter, &child_parent_iter) == FALSE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* stamp may have changed */
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (filter,
|
|
|
|
|
&child_parent_iter,
|
|
|
|
|
&parent_iter);
|
|
|
|
|
length = gtk_tree_model_iter_n_children (filter->priv->child_model, &child_parent_iter);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
/* Take a reference on the parent */
|
|
|
|
|
gtk_tree_model_filter_real_ref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&parent_iter, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (length > 0);
|
|
|
|
|
|
|
|
|
|
new_level = g_new (FilterLevel, 1);
|
2011-08-07 15:11:13 +00:00
|
|
|
|
new_level->seq = g_sequence_new (filter_elt_free);
|
|
|
|
|
new_level->visible_seq = g_sequence_new (NULL);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
new_level->ref_count = 0;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
new_level->ext_ref_count = 0;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
new_level->parent_elt = parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
new_level->parent_level = parent_level;
|
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (parent_elt)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
parent_elt->children = new_level;
|
|
|
|
|
else
|
|
|
|
|
filter->priv->root = new_level;
|
|
|
|
|
|
|
|
|
|
/* increase the count of zero ref_counts */
|
2011-07-10 14:35:38 +00:00
|
|
|
|
tmp_level = parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
tmp_elt = parent_elt;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
while (tmp_level)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-20 08:54:49 +00:00
|
|
|
|
tmp_elt->zero_ref_count++;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
tmp_elt = tmp_level->parent_elt;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
tmp_level = tmp_level->parent_level;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (new_level != filter->priv->root)
|
|
|
|
|
filter->priv->zero_ref_count++;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
first_node = iter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_model_filter_visible (filter, &iter))
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
FilterElt *filter_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
filter_elt = filter_elt_new ();
|
|
|
|
|
filter_elt->offset = i;
|
|
|
|
|
filter_elt->zero_ref_count = 0;
|
|
|
|
|
filter_elt->ref_count = 0;
|
|
|
|
|
filter_elt->ext_ref_count = 0;
|
|
|
|
|
filter_elt->children = NULL;
|
|
|
|
|
filter_elt->visible_siter = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
2011-08-07 15:11:13 +00:00
|
|
|
|
filter_elt->iter = iter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_append (new_level->seq, filter_elt);
|
|
|
|
|
filter_elt->visible_siter = g_sequence_append (new_level->visible_seq, filter_elt);
|
|
|
|
|
empty = FALSE;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
Bug 596580 - Blank rows in entry autocompletion
gtk_tree_model_build_level() always needs to emit row-inserted when
requested, this should not depend on whether the level has a parent
level or a virtual root, which is a check whether or not we need to
reference the node in the child model. Furthermore, we also need
to emit row-has-child-toggled after row-inserted when appropriate.
When gtk_tree_model_filter_row_changed() pulls in the root level, it
must request build_level() to emit signals for this. The refilter
function uses row_changed to process the changes, so build_level() in
the first call to row_changed() might pull in multiple new nodes in this
scenario, for all of these signals need to be emitted. Of course,
build_level() will then also emit the signals for the node row_changed()
is processing, we should not emit a duplicate signal, this is now
accounted for.
Add a unit test for this. For this small functionality to block the
row-changed signal has been implemented, so that we can simulate calls
to the refilter function using the current visible column setup.
2009-09-30 08:19:07 +00:00
|
|
|
|
if (emit_inserted)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *f_path;
|
|
|
|
|
GtkTreeIter children;
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = new_level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
f_iter.user_data2 = filter_elt;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
Bug 596580 - Blank rows in entry autocompletion
gtk_tree_model_build_level() always needs to emit row-inserted when
requested, this should not depend on whether the level has a parent
level or a virtual root, which is a check whether or not we need to
reference the node in the child model. Furthermore, we also need
to emit row-has-child-toggled after row-inserted when appropriate.
When gtk_tree_model_filter_row_changed() pulls in the root level, it
must request build_level() to emit signals for this. The refilter
function uses row_changed to process the changes, so build_level() in
the first call to row_changed() might pull in multiple new nodes in this
scenario, for all of these signals need to be emitted. Of course,
build_level() will then also emit the signals for the node row_changed()
is processing, we should not emit a duplicate signal, this is now
accounted for.
Add a unit test for this. For this small functionality to block the
row-changed signal has been implemented, so that we can simulate calls
to the refilter function using the current visible column setup.
2009-09-30 08:19:07 +00:00
|
|
|
|
f_path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter);
|
|
|
|
|
gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter),
|
|
|
|
|
f_path, &f_iter);
|
|
|
|
|
gtk_tree_path_free (f_path);
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_children (filter->priv->child_model,
|
|
|
|
|
&children, &iter))
|
|
|
|
|
gtk_tree_model_filter_update_children (filter,
|
|
|
|
|
new_level,
|
|
|
|
|
FILTER_ELT (f_iter.user_data2));
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
while (gtk_tree_model_iter_next (filter->priv->child_model, &iter));
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* The level does not contain any visible nodes. However, changes in
|
|
|
|
|
* this level might affect the parent node, which can either be visible
|
|
|
|
|
* or invisible. Therefore, this level can only be removed again,
|
2011-09-07 07:25:36 +00:00
|
|
|
|
* if the parent level has an external reference count of zero. That is,
|
|
|
|
|
* if this level changes state, no signals are required in the parent
|
|
|
|
|
* level.
|
2011-07-10 14:35:38 +00:00
|
|
|
|
*/
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (empty &&
|
2011-09-07 07:25:36 +00:00
|
|
|
|
(parent_level && parent_level->ext_ref_count == 0))
|
2011-07-10 14:35:38 +00:00
|
|
|
|
{
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, new_level, FALSE, TRUE, FALSE);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If none of the nodes are visible, we will just pull in the
|
|
|
|
|
* first node of the level.
|
|
|
|
|
*/
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (empty)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
FilterElt *filter_elt;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
filter_elt = filter_elt_new ();
|
|
|
|
|
filter_elt->offset = 0;
|
|
|
|
|
filter_elt->zero_ref_count = 0;
|
|
|
|
|
filter_elt->ref_count = 0;
|
|
|
|
|
filter_elt->ext_ref_count = 0;
|
|
|
|
|
filter_elt->children = NULL;
|
|
|
|
|
filter_elt->visible_siter = NULL;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
2011-08-07 15:11:13 +00:00
|
|
|
|
filter_elt->iter = first_node;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_append (new_level->seq, filter_elt);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* Keep a reference on the first node of this level. We need this
|
|
|
|
|
* to make sure that we get all signals for this level.
|
|
|
|
|
*/
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = new_level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
f_iter.user_data2 = g_sequence_get (g_sequence_get_begin_iter (new_level->seq));
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
gtk_tree_model_filter_real_ref_node (GTK_TREE_MODEL (filter), &f_iter, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_free_level (GtkTreeModelFilter *filter,
|
2011-05-09 08:29:37 +00:00
|
|
|
|
FilterLevel *filter_level,
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gboolean unref_self,
|
|
|
|
|
gboolean unref_parent,
|
2011-09-07 20:06:40 +00:00
|
|
|
|
gboolean unref_external)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
GSequenceIter *end_siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_assert (filter_level);
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
end_siter = g_sequence_get_end_iter (filter_level->seq);
|
|
|
|
|
for (siter = g_sequence_get_begin_iter (filter_level->seq);
|
|
|
|
|
siter != end_siter;
|
|
|
|
|
siter = g_sequence_iter_next (siter))
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
FilterElt *elt = g_sequence_get (siter);
|
|
|
|
|
|
|
|
|
|
if (elt->children)
|
2011-09-11 14:53:27 +00:00
|
|
|
|
{
|
|
|
|
|
/* If we recurse and unref_self == FALSE, then unref_parent
|
|
|
|
|
* must also be FALSE (otherwise a still unref a node in this
|
|
|
|
|
* level).
|
|
|
|
|
*/
|
|
|
|
|
gtk_tree_model_filter_free_level (filter,
|
|
|
|
|
FILTER_LEVEL (elt->children),
|
|
|
|
|
unref_self,
|
|
|
|
|
unref_self == FALSE ? FALSE : unref_parent,
|
|
|
|
|
unref_external);
|
|
|
|
|
}
|
2011-09-07 20:06:40 +00:00
|
|
|
|
|
|
|
|
|
if (unref_external)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = filter_level;
|
|
|
|
|
f_iter.user_data2 = elt;
|
|
|
|
|
|
|
|
|
|
while (elt->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter,
|
2011-09-11 14:53:27 +00:00
|
|
|
|
TRUE, unref_self);
|
2011-09-07 20:06:40 +00:00
|
|
|
|
}
|
2011-07-10 14:35:38 +00:00
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* Release the reference on the first item.
|
|
|
|
|
*/
|
2011-09-11 14:53:27 +00:00
|
|
|
|
if (unref_self)
|
2011-07-10 14:35:38 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter f_iter;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = filter_level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
f_iter.user_data2 = g_sequence_get (g_sequence_get_begin_iter (filter_level->seq));
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, FALSE, TRUE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
if (filter_level->ext_ref_count == 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
FilterLevel *parent_level = filter_level->parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *parent_elt = filter_level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2006-09-27 14:16:47 +00:00
|
|
|
|
while (parent_level)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt->zero_ref_count--;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
|
|
|
|
parent_level = parent_level->parent_level;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
2006-09-27 14:16:47 +00:00
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (filter_level != filter->priv->root)
|
|
|
|
|
filter->priv->zero_ref_count--;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-09-17 04:08:40 +00:00
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
if (filter_level == filter->priv->root)
|
|
|
|
|
g_assert (filter->priv->zero_ref_count == 0);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (filter_level->parent_elt)
|
2011-07-10 14:35:38 +00:00
|
|
|
|
{
|
|
|
|
|
/* Release reference on parent */
|
2011-09-11 14:53:27 +00:00
|
|
|
|
GtkTreeIter parent_iter;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-09-11 14:53:27 +00:00
|
|
|
|
parent_iter.stamp = filter->priv->stamp;
|
|
|
|
|
parent_iter.user_data = filter_level->parent_level;
|
|
|
|
|
parent_iter.user_data2 = filter_level->parent_elt;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&parent_iter, FALSE, unref_parent);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
filter_level->parent_elt->children = NULL;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
else
|
|
|
|
|
filter->priv->root = NULL;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_free (filter_level->seq);
|
|
|
|
|
g_sequence_free (filter_level->visible_seq);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
g_free (filter_level);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* prune_level() is like free_level(), however instead of being fully
|
|
|
|
|
* freed, the level is pruned to a level with only the first node used
|
|
|
|
|
* for monitoring. For now it is only being called from
|
|
|
|
|
* gtk_tree_model_filter_remove_elt_from_level(), which is the reason
|
2014-02-05 18:07:34 +00:00
|
|
|
|
* this function is lacking a “gboolean unref” argument.
|
2011-09-07 20:06:40 +00:00
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_prune_level (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level)
|
|
|
|
|
{
|
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
GSequenceIter *end_siter;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
|
|
/* This function is called when the parent of level became invisible.
|
|
|
|
|
* All external ref counts of the children need to be dropped.
|
|
|
|
|
* All children except the first one can be removed.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* Any child levels can be freed */
|
|
|
|
|
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))
|
|
|
|
|
{
|
2015-05-31 01:29:03 +00:00
|
|
|
|
elt = g_sequence_get (siter);
|
2011-09-07 20:06:40 +00:00
|
|
|
|
|
|
|
|
|
if (elt->children)
|
|
|
|
|
gtk_tree_model_filter_free_level (filter,
|
2011-09-11 14:53:27 +00:00
|
|
|
|
FILTER_LEVEL (elt->children),
|
|
|
|
|
TRUE, TRUE, TRUE);
|
2011-09-07 20:06:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* For the first item, only drop the external references */
|
|
|
|
|
elt = g_sequence_get (g_sequence_get_begin_iter (level->seq));
|
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = level;
|
|
|
|
|
f_iter.user_data2 = elt;
|
|
|
|
|
|
|
|
|
|
while (elt->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, TRUE, TRUE);
|
|
|
|
|
|
|
|
|
|
if (elt->visible_siter)
|
|
|
|
|
{
|
|
|
|
|
g_sequence_remove (elt->visible_siter);
|
|
|
|
|
elt->visible_siter = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove the other elts */
|
|
|
|
|
end_siter = g_sequence_get_end_iter (level->seq);
|
|
|
|
|
siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter = g_sequence_iter_next (siter);
|
|
|
|
|
for (; siter != end_siter; siter = g_sequence_iter_next (siter))
|
|
|
|
|
{
|
|
|
|
|
elt = g_sequence_get (siter);
|
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = level;
|
|
|
|
|
f_iter.user_data2 = elt;
|
|
|
|
|
|
|
|
|
|
while (elt->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, TRUE, TRUE);
|
2011-09-11 10:02:12 +00:00
|
|
|
|
/* In this case, we do remove reference counts we've added ourselves,
|
|
|
|
|
* since the node will be removed from the data structures.
|
|
|
|
|
*/
|
|
|
|
|
while (elt->ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, FALSE, TRUE);
|
2011-09-07 20:06:40 +00:00
|
|
|
|
|
|
|
|
|
if (elt->visible_siter)
|
|
|
|
|
{
|
|
|
|
|
g_sequence_remove (elt->visible_siter);
|
|
|
|
|
elt->visible_siter = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Remove [begin + 1, end] */
|
|
|
|
|
siter = g_sequence_get_begin_iter (level->seq);
|
|
|
|
|
siter = g_sequence_iter_next (siter);
|
|
|
|
|
|
|
|
|
|
g_sequence_remove_range (siter, end_siter);
|
|
|
|
|
|
|
|
|
|
/* The level must have reached an ext ref count of zero by now, though
|
|
|
|
|
* we only assert on this in debugging mode.
|
|
|
|
|
*/
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (level->ext_ref_count == 0);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_level_transfer_first_ref (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level,
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *from_iter,
|
|
|
|
|
GSequenceIter *to_iter)
|
2011-07-10 14:35:38 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
f_iter.user_data2 = g_sequence_get (to_iter);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_real_ref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, FALSE);
|
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
f_iter.user_data2 = g_sequence_get (from_iter);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, FALSE, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_level_transfer_first_ref_with_index (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
gint from_index,
|
|
|
|
|
gint to_index)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_filter_level_transfer_first_ref (filter, level,
|
|
|
|
|
g_sequence_get_iter_at_pos (level->seq, from_index),
|
|
|
|
|
g_sequence_get_iter_at_pos (level->seq, to_index));
|
|
|
|
|
}
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* Creates paths suitable for accessing the child model. */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static GtkTreePath *
|
|
|
|
|
gtk_tree_model_filter_elt_get_path (FilterLevel *level,
|
|
|
|
|
FilterElt *elt,
|
|
|
|
|
GtkTreePath *root)
|
|
|
|
|
{
|
|
|
|
|
FilterLevel *walker = level;
|
|
|
|
|
FilterElt *walker2 = elt;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreePath *real_path;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (level != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (elt != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
|
|
|
|
|
|
while (walker)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_prepend_index (path, walker2->offset);
|
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
walker2 = walker->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
walker = walker->parent_level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (root)
|
|
|
|
|
{
|
2003-09-08 19:51:16 +00:00
|
|
|
|
real_path = gtk_tree_model_filter_add_root (path, root);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return real_path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
|
gtk_tree_model_filter_add_root (GtkTreePath *src,
|
|
|
|
|
GtkTreePath *root)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
retval = gtk_tree_path_copy (root);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (src); i++)
|
2010-06-28 18:15:10 +00:00
|
|
|
|
gtk_tree_path_append_index (retval, gtk_tree_path_get_indices (src)[i]);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
|
gtk_tree_model_filter_remove_root (GtkTreePath *src,
|
|
|
|
|
GtkTreePath *root)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
gint i;
|
|
|
|
|
gint depth;
|
|
|
|
|
gint *indices;
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_path_get_depth (src) <= gtk_tree_path_get_depth (root))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
depth = gtk_tree_path_get_depth (src);
|
2010-06-28 18:15:10 +00:00
|
|
|
|
indices = gtk_tree_path_get_indices (src);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (root); i++)
|
2010-06-28 18:15:10 +00:00
|
|
|
|
if (indices[i] != gtk_tree_path_get_indices (root)[i])
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
retval = gtk_tree_path_new ();
|
|
|
|
|
|
|
|
|
|
for (; i < depth; i++)
|
|
|
|
|
gtk_tree_path_append_index (retval, indices[i]);
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_increment_stamp (GtkTreeModelFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
filter->priv->stamp++;
|
|
|
|
|
}
|
|
|
|
|
while (filter->priv->stamp == 0);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_clear_cache (filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2009-12-09 09:21:34 +00:00
|
|
|
|
gtk_tree_model_filter_real_visible (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModel *child_model,
|
|
|
|
|
GtkTreeIter *child_iter)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
if (filter->priv->visible_func)
|
|
|
|
|
{
|
2009-12-09 09:21:34 +00:00
|
|
|
|
return filter->priv->visible_func (child_model,
|
2005-08-24 04:15:28 +00:00
|
|
|
|
child_iter,
|
|
|
|
|
filter->priv->visible_data)
|
2005-08-24 04:36:12 +00:00
|
|
|
|
? TRUE : FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
else if (filter->priv->visible_column >= 0)
|
|
|
|
|
{
|
2011-09-30 15:31:04 +00:00
|
|
|
|
GValue val = G_VALUE_INIT;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2009-12-09 09:21:34 +00:00
|
|
|
|
gtk_tree_model_get_value (child_model, child_iter,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->visible_column, &val);
|
|
|
|
|
|
|
|
|
|
if (g_value_get_boolean (&val))
|
|
|
|
|
{
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_value_unset (&val);
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* no visible function set, so always visible */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-09 09:21:34 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_visible (GtkTreeModelFilter *self,
|
|
|
|
|
GtkTreeIter *child_iter)
|
|
|
|
|
{
|
|
|
|
|
return GTK_TREE_MODEL_FILTER_GET_CLASS (self)->visible (self,
|
|
|
|
|
self->priv->child_model, child_iter);
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_clear_cache_helper_iter (gpointer data,
|
|
|
|
|
gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = user_data;
|
|
|
|
|
FilterElt *elt = data;
|
|
|
|
|
|
2011-09-07 07:36:18 +00:00
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (elt->zero_ref_count >= 0);
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt->zero_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_clear_cache_helper (filter, elt->children);
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_clear_cache_helper (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level)
|
|
|
|
|
{
|
|
|
|
|
g_assert (level);
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_foreach (level->seq, gtk_tree_model_filter_clear_cache_helper_iter, filter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* If the level's ext_ref_count is zero, it means the level is not visible
|
|
|
|
|
* and can be removed. But, since we support monitoring a child level
|
|
|
|
|
* of a parent for changes (these might affect the parent), we will only
|
2011-09-07 07:25:36 +00:00
|
|
|
|
* free the level if the parent level also has an external ref
|
2011-07-10 14:35:38 +00:00
|
|
|
|
* count of zero. In that case, changes concerning our parent are
|
|
|
|
|
* not requested.
|
2011-09-07 20:11:37 +00:00
|
|
|
|
*
|
|
|
|
|
* The root level is always visible, so an exception holds for levels
|
|
|
|
|
* with the root level as parent level: these have to remain cached.
|
2011-07-10 14:35:38 +00:00
|
|
|
|
*/
|
2011-06-26 20:04:05 +00:00
|
|
|
|
if (level->ext_ref_count == 0 && level != filter->priv->root &&
|
2011-09-07 20:11:37 +00:00
|
|
|
|
level->parent_level && level->parent_level != filter->priv->root &&
|
|
|
|
|
level->parent_level->ext_ref_count == 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, level, TRUE, TRUE, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-09-01 14:10:05 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_elt_is_visible_in_target (FilterLevel *level,
|
|
|
|
|
FilterElt *elt)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter)
|
2009-09-01 14:10:05 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (!level->parent_elt)
|
2009-09-01 14:10:05 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
2011-08-05 15:40:04 +00:00
|
|
|
|
elt = level->parent_elt;
|
2009-09-01 14:10:05 +00:00
|
|
|
|
level = level->parent_level;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt && !elt->visible_siter)
|
2009-09-01 14:10:05 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
while (level);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
/* If a change has occurred in path (inserted, changed or deleted),
|
|
|
|
|
* then this function is used to check all its ancestors. An ancestor
|
|
|
|
|
* could have changed state as a result and this needs to be propagated
|
|
|
|
|
* to the objects monitoring the filter model.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
int *indices = gtk_tree_path_get_indices (path);
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
FilterLevel *level;
|
2015-10-29 14:17:44 +00:00
|
|
|
|
GtkTreeIter c_iter, tmp_iter, *root_iter;
|
2011-05-21 09:45:08 +00:00
|
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-10-29 14:17:44 +00:00
|
|
|
|
root_iter = NULL;
|
|
|
|
|
if (filter->priv->virtual_root &&
|
|
|
|
|
gtk_tree_model_get_iter (filter->priv->child_model, &tmp_iter,
|
|
|
|
|
filter->priv->virtual_root))
|
|
|
|
|
root_iter = &tmp_iter;
|
2011-05-21 09:45:08 +00:00
|
|
|
|
gtk_tree_model_iter_nth_child (filter->priv->child_model, &c_iter,
|
2015-10-29 14:17:44 +00:00
|
|
|
|
root_iter,
|
2011-05-21 09:45:08 +00:00
|
|
|
|
indices[i]);
|
|
|
|
|
|
|
|
|
|
while (i < gtk_tree_path_get_depth (path) - 1)
|
|
|
|
|
{
|
|
|
|
|
gboolean requested_state;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = lookup_elt_with_offset (level->seq,
|
|
|
|
|
gtk_tree_path_get_indices (path)[i], NULL);
|
2011-05-21 09:45:08 +00:00
|
|
|
|
|
|
|
|
|
requested_state = gtk_tree_model_filter_visible (filter, &c_iter);
|
|
|
|
|
|
|
|
|
|
if (!elt)
|
|
|
|
|
{
|
|
|
|
|
int index;
|
|
|
|
|
GtkTreePath *c_path;
|
|
|
|
|
|
|
|
|
|
if (requested_state == FALSE)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* The elt does not exist in this level (so it is not
|
|
|
|
|
* visible), but should now be visible. We emit the
|
|
|
|
|
* row-inserted and row-has-child-toggled signals.
|
|
|
|
|
*/
|
|
|
|
|
elt = gtk_tree_model_filter_insert_elt_in_level (filter,
|
|
|
|
|
&c_iter,
|
|
|
|
|
level,
|
|
|
|
|
indices[i],
|
|
|
|
|
&index);
|
|
|
|
|
|
|
|
|
|
/* insert_elt_in_level defaults to FALSE */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt->visible_siter = g_sequence_insert_sorted (level->visible_seq,
|
|
|
|
|
elt,
|
|
|
|
|
filter_elt_cmp, NULL);
|
2011-05-21 09:45:08 +00:00
|
|
|
|
|
|
|
|
|
c_path = gtk_tree_model_get_path (filter->priv->child_model,
|
|
|
|
|
&c_iter);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_emit_row_inserted_for_path (filter,
|
|
|
|
|
filter->priv->child_model,
|
|
|
|
|
c_path,
|
|
|
|
|
&c_iter);
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (c_path);
|
|
|
|
|
|
|
|
|
|
/* We can immediately return, because this node was not visible
|
|
|
|
|
* before and its children will be checked for in response to
|
|
|
|
|
* the emitted row-has-child-toggled signal.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-08-07 15:11:13 +00:00
|
|
|
|
else if (elt->visible_siter)
|
2011-05-21 09:45:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (!requested_state)
|
|
|
|
|
{
|
|
|
|
|
/* A node has turned invisible. Remove it from the level
|
|
|
|
|
* and emit row-deleted. Since this node is being
|
|
|
|
|
* deleted. it makes no sense to look further up the
|
|
|
|
|
* chain.
|
|
|
|
|
*/
|
|
|
|
|
gtk_tree_model_filter_remove_elt_from_level (filter,
|
|
|
|
|
level, elt);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Otherwise continue up the chain */
|
|
|
|
|
}
|
2011-08-07 15:11:13 +00:00
|
|
|
|
else if (!elt->visible_siter)
|
2011-05-21 09:45:08 +00:00
|
|
|
|
{
|
|
|
|
|
if (requested_state)
|
|
|
|
|
{
|
|
|
|
|
/* A node is already in the cache, but invisible. This
|
|
|
|
|
* is usually a node on which a reference is kept by
|
|
|
|
|
* the filter model, or a node fetched on the filter's
|
|
|
|
|
* request, and thus not shown. Therefore, we will
|
|
|
|
|
* not emit row-inserted for this node. Instead,
|
|
|
|
|
* we signal to its parent that a change has occurred.
|
2011-07-10 14:24:05 +00:00
|
|
|
|
*
|
|
|
|
|
* Exception: root level, in this case, we must emit
|
|
|
|
|
* row-inserted.
|
2011-05-21 09:45:08 +00:00
|
|
|
|
*/
|
2011-07-10 14:24:05 +00:00
|
|
|
|
if (level->parent_level)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
GtkTreePath *f_path;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt->visible_siter = g_sequence_insert_sorted (level->visible_seq, elt,
|
|
|
|
|
filter_elt_cmp, NULL);
|
2011-07-10 14:24:05 +00:00
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = level->parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
f_iter.user_data2 = level->parent_elt;
|
2011-07-10 14:24:05 +00:00
|
|
|
|
|
|
|
|
|
f_path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter);
|
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
|
|
|
|
f_path, &f_iter);
|
|
|
|
|
gtk_tree_path_free (f_path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *c_path;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt->visible_siter = g_sequence_insert_sorted (level->visible_seq, elt,
|
|
|
|
|
filter_elt_cmp, NULL);
|
2011-07-10 14:24:05 +00:00
|
|
|
|
|
|
|
|
|
c_path = gtk_tree_model_get_path (filter->priv->child_model,
|
|
|
|
|
&c_iter);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-07-10 14:24:05 +00:00
|
|
|
|
gtk_tree_model_filter_emit_row_inserted_for_path (filter,
|
|
|
|
|
filter->priv->child_model,
|
|
|
|
|
c_path,
|
|
|
|
|
&c_iter);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-07-10 14:24:05 +00:00
|
|
|
|
gtk_tree_path_free (c_path);
|
|
|
|
|
}
|
2011-05-21 09:45:08 +00:00
|
|
|
|
|
|
|
|
|
/* We can immediately return, because this node was not visible
|
|
|
|
|
* before and the parent will check its children, including
|
|
|
|
|
* this node, in response to the emitted row-has-child-toggled
|
|
|
|
|
* signal.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Not visible, so no need to continue. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!elt->children)
|
|
|
|
|
{
|
|
|
|
|
/* If an elt does not have children, these are not visible.
|
|
|
|
|
* Therefore, any signals emitted for these children will
|
|
|
|
|
* be ignored, so we do not have to emit them.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
level = elt->children;
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
|
|
tmp_iter = c_iter;
|
|
|
|
|
gtk_tree_model_iter_nth_child (filter->priv->child_model, &c_iter,
|
|
|
|
|
&tmp_iter, indices[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-14 09:47:01 +00:00
|
|
|
|
static FilterElt *
|
|
|
|
|
gtk_tree_model_filter_insert_elt_in_level (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
gint offset,
|
|
|
|
|
gint *index)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
FilterElt *elt;
|
|
|
|
|
GSequenceIter *siter;
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = filter_elt_new ();
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
|
elt->iter = *c_iter;
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt->offset = offset;
|
|
|
|
|
elt->zero_ref_count = 0;
|
|
|
|
|
elt->ref_count = 0;
|
|
|
|
|
elt->ext_ref_count = 0;
|
|
|
|
|
elt->children = NULL;
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
/* Because we don't emit row_inserted, the node is invisible and thus
|
|
|
|
|
* not inserted in visible_seq
|
|
|
|
|
*/
|
|
|
|
|
elt->visible_siter = NULL;
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_insert_sorted (level->seq, elt, filter_elt_cmp, NULL);
|
|
|
|
|
*index = g_sequence_iter_get_position (siter);
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* If the insert location is zero, we need to move our reference
|
|
|
|
|
* on the old first node to the new first node.
|
|
|
|
|
*/
|
|
|
|
|
if (*index == 0)
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gtk_tree_model_filter_level_transfer_first_ref_with_index (filter, level,
|
|
|
|
|
1, 0);
|
2011-05-14 09:47:01 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
return elt;
|
2011-05-14 09:47:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static FilterElt *
|
|
|
|
|
gtk_tree_model_filter_fetch_child (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
gint offset,
|
|
|
|
|
gint *index)
|
|
|
|
|
{
|
|
|
|
|
gint len;
|
|
|
|
|
GtkTreePath *c_path = NULL;
|
|
|
|
|
GtkTreeIter c_iter;
|
|
|
|
|
GtkTreePath *c_parent_path = NULL;
|
|
|
|
|
GtkTreeIter c_parent_iter;
|
|
|
|
|
|
|
|
|
|
/* check if child exists and is visible */
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (level->parent_elt)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
c_parent_path =
|
|
|
|
|
gtk_tree_model_filter_elt_get_path (level->parent_level,
|
2011-08-05 15:40:04 +00:00
|
|
|
|
level->parent_elt,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->virtual_root);
|
|
|
|
|
if (!c_parent_path)
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
c_parent_path = gtk_tree_path_copy (filter->priv->virtual_root);
|
|
|
|
|
else
|
|
|
|
|
c_parent_path = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c_parent_path)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_get_iter (filter->priv->child_model,
|
|
|
|
|
&c_parent_iter,
|
|
|
|
|
c_parent_path);
|
|
|
|
|
len = gtk_tree_model_iter_n_children (filter->priv->child_model,
|
|
|
|
|
&c_parent_iter);
|
|
|
|
|
|
|
|
|
|
c_path = gtk_tree_path_copy (c_parent_path);
|
|
|
|
|
gtk_tree_path_free (c_parent_path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
len = gtk_tree_model_iter_n_children (filter->priv->child_model, NULL);
|
|
|
|
|
c_path = gtk_tree_path_new ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_append_index (c_path, offset);
|
|
|
|
|
gtk_tree_model_get_iter (filter->priv->child_model, &c_iter, c_path);
|
|
|
|
|
gtk_tree_path_free (c_path);
|
|
|
|
|
|
|
|
|
|
if (offset >= len || !gtk_tree_model_filter_visible (filter, &c_iter))
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2011-05-14 09:47:01 +00:00
|
|
|
|
return gtk_tree_model_filter_insert_elt_in_level (filter, &c_iter,
|
|
|
|
|
level, offset,
|
|
|
|
|
index);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-22 16:40:21 +00:00
|
|
|
|
/* Note that this function is never called from the row-deleted handler.
|
|
|
|
|
* This means that this function is only used for removing elements
|
|
|
|
|
* which are still present in the child model. As a result, we must
|
|
|
|
|
* take care to properly release the references the filter model has
|
|
|
|
|
* on the child model nodes.
|
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
2011-05-20 18:39:12 +00:00
|
|
|
|
gtk_tree_model_filter_remove_elt_from_level (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
FilterElt *elt)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-05-20 18:33:30 +00:00
|
|
|
|
FilterElt *parent;
|
|
|
|
|
FilterLevel *parent_level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gint length, orig_level_ext_ref_count;
|
2011-05-20 18:33:30 +00:00
|
|
|
|
GtkTreeIter iter;
|
2011-05-20 18:43:48 +00:00
|
|
|
|
GtkTreePath *path = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gboolean emit_child_toggled = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* We need to know about the level's ext ref count before removal
|
|
|
|
|
* of this node.
|
|
|
|
|
*/
|
|
|
|
|
orig_level_ext_ref_count = level->ext_ref_count;
|
|
|
|
|
|
2011-05-20 18:33:30 +00:00
|
|
|
|
iter.stamp = filter->priv->stamp;
|
|
|
|
|
iter.user_data = level;
|
|
|
|
|
iter.user_data2 = elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-09-19 09:20:08 +00:00
|
|
|
|
parent = level->parent_elt;
|
|
|
|
|
parent_level = level->parent_level;
|
|
|
|
|
|
2011-09-11 18:16:34 +00:00
|
|
|
|
if (!parent || orig_level_ext_ref_count > 0)
|
2011-09-07 20:06:40 +00:00
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
|
else
|
|
|
|
|
/* If the level is not visible, the parent is potentially invisible
|
|
|
|
|
* too. Either way, as no signal will be emitted, there is no use
|
|
|
|
|
* for a path.
|
|
|
|
|
*/
|
|
|
|
|
path = NULL;
|
2011-05-20 18:43:48 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
length = g_sequence_get_length (level->seq);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-20 18:41:50 +00:00
|
|
|
|
/* first register the node to be invisible */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_remove (elt->visible_siter);
|
|
|
|
|
elt->visible_siter = NULL;
|
2011-05-20 18:41:50 +00:00
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* If level != root level and the number of visible nodes is 0 (ie. this
|
|
|
|
|
* is the last node to be removed from the level), emit
|
|
|
|
|
* row-has-child-toggled.
|
2005-10-25 21:00:40 +00:00
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2009-09-01 15:49:02 +00:00
|
|
|
|
if (level != filter->priv->root
|
2011-08-07 15:11:13 +00:00
|
|
|
|
&& g_sequence_get_length (level->visible_seq) == 0
|
2009-09-06 11:35:37 +00:00
|
|
|
|
&& parent
|
2011-08-07 15:11:13 +00:00
|
|
|
|
&& parent->visible_siter)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
emit_child_toggled = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* Distinguish:
|
|
|
|
|
* - length > 1: in this case, the node is removed from the level
|
|
|
|
|
* and row-deleted is emitted.
|
|
|
|
|
* - length == 1: in this case, we need to decide whether to keep
|
|
|
|
|
* the level or to free it.
|
|
|
|
|
*/
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (length > 1)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2009-09-05 14:12:48 +00:00
|
|
|
|
/* We emit row-deleted, and remove the node from the cache.
|
|
|
|
|
* If it has any children, these will be removed here as well.
|
2005-10-25 21:00:40 +00:00
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* FIXME: I am not 100% sure it is always save to fully free the
|
|
|
|
|
* level here. Perhaps the state of the parent level, etc. has to
|
|
|
|
|
* be checked to make the right decision, like is done below for
|
|
|
|
|
* the case length == 1.
|
|
|
|
|
*/
|
2009-09-05 14:12:48 +00:00
|
|
|
|
if (elt->children)
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, elt->children, TRUE, TRUE, TRUE);
|
2009-09-05 14:12:48 +00:00
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* If the first node is being removed, transfer, the reference */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt == g_sequence_get (g_sequence_get_begin_iter (level->seq)))
|
2011-07-10 14:35:38 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gtk_tree_model_filter_level_transfer_first_ref_with_index (filter, level,
|
|
|
|
|
0, 1);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
while (elt->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
2011-09-07 20:06:40 +00:00
|
|
|
|
&iter, TRUE, TRUE);
|
|
|
|
|
/* In this case, we do remove reference counts we've added ourselves,
|
|
|
|
|
* since the node will be removed from the data structures.
|
|
|
|
|
*/
|
2011-07-10 14:35:38 +00:00
|
|
|
|
while (elt->ref_count > 0)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
2011-09-07 20:06:40 +00:00
|
|
|
|
&iter, FALSE, TRUE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* remove the node */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
lookup_elt_with_offset (level->seq, elt->offset, &siter);
|
|
|
|
|
g_sequence_remove (siter);
|
2011-06-26 19:44:13 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
2011-06-26 20:04:05 +00:00
|
|
|
|
|
|
|
|
|
/* Only if the node is in the root level (parent == NULL) or
|
2011-07-10 14:35:38 +00:00
|
|
|
|
* the level is visible, a row-deleted signal is necessary.
|
2011-06-26 20:04:05 +00:00
|
|
|
|
*/
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (!parent || orig_level_ext_ref_count > 0)
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (filter), path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
2011-09-07 20:06:40 +00:00
|
|
|
|
else
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* There is only one node left in this level */
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (length == 1);
|
|
|
|
|
#endif
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* The row is signalled as deleted to the client. We have to
|
|
|
|
|
* drop the remaining external reference count here, the client
|
|
|
|
|
* will not do it.
|
|
|
|
|
*
|
|
|
|
|
* We keep the reference counts we've obtained ourselves.
|
2011-07-10 14:35:38 +00:00
|
|
|
|
*/
|
2011-06-26 20:04:05 +00:00
|
|
|
|
while (elt->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
2011-09-07 20:06:40 +00:00
|
|
|
|
&iter, TRUE, TRUE);
|
2011-06-26 19:44:13 +00:00
|
|
|
|
|
2011-09-07 20:06:40 +00:00
|
|
|
|
/* This level is still required if:
|
|
|
|
|
* - it is the root level
|
|
|
|
|
* - its parent level is the root level
|
|
|
|
|
* - its parent level has an external ref count > 0
|
|
|
|
|
*/
|
|
|
|
|
if (! (level == filter->priv->root ||
|
|
|
|
|
level->parent_level == filter->priv->root ||
|
|
|
|
|
level->parent_level->ext_ref_count > 0))
|
|
|
|
|
{
|
|
|
|
|
/* Otherwise, the level can be removed */
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, level, TRUE, TRUE, TRUE);
|
2011-09-07 20:06:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Level is kept, but we turn our attention to a child level.
|
|
|
|
|
*
|
|
|
|
|
* If level is not the root level, it is a child level with
|
|
|
|
|
* an ext ref count that is now 0. That means that any child level
|
|
|
|
|
* of elt can be removed.
|
|
|
|
|
*/
|
|
|
|
|
if (level != filter->priv->root)
|
|
|
|
|
{
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (level->ext_ref_count == 0);
|
|
|
|
|
#endif
|
|
|
|
|
if (elt->children)
|
|
|
|
|
gtk_tree_model_filter_free_level (filter, elt->children,
|
2011-09-11 14:53:27 +00:00
|
|
|
|
TRUE, TRUE, TRUE);
|
2011-09-07 20:06:40 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* In this case, we want to keep the level with the first
|
|
|
|
|
* node pulled in to monitor for signals.
|
|
|
|
|
*/
|
|
|
|
|
if (elt->children)
|
|
|
|
|
gtk_tree_model_filter_prune_level (filter, elt->children);
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
if (!parent || orig_level_ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (filter), path);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-20 18:43:48 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (emit_child_toggled && parent->ext_ref_count > 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter piter;
|
|
|
|
|
GtkTreePath *ppath;
|
|
|
|
|
|
|
|
|
|
piter.stamp = filter->priv->stamp;
|
|
|
|
|
piter.user_data = parent_level;
|
|
|
|
|
piter.user_data2 = parent;
|
|
|
|
|
|
|
|
|
|
ppath = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &piter);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
|
|
|
|
ppath, &piter);
|
|
|
|
|
gtk_tree_path_free (ppath);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* This function is called after the given node has become visible.
|
|
|
|
|
* When the node has children, we should build the level and
|
|
|
|
|
* take a reference on the first child.
|
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
2004-08-04 05:38:58 +00:00
|
|
|
|
gtk_tree_model_filter_update_children (GtkTreeModelFilter *filter,
|
|
|
|
|
FilterLevel *level,
|
|
|
|
|
FilterElt *elt)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeIter c_iter;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
iter.stamp = filter->priv->stamp;
|
|
|
|
|
iter.user_data = level;
|
|
|
|
|
iter.user_data2 = elt;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (filter, &c_iter, &iter);
|
|
|
|
|
|
2011-09-07 07:25:36 +00:00
|
|
|
|
if ((!level->parent_level || level->parent_level->ext_ref_count > 0) &&
|
2011-07-10 14:35:38 +00:00
|
|
|
|
gtk_tree_model_iter_has_child (filter->priv->child_model, &c_iter))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (!elt->children)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt->ext_ref_count > 0 && elt->children &&
|
|
|
|
|
g_sequence_get_length (elt->children->seq))
|
2011-07-10 14:35:38 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
|
|
|
|
path,
|
|
|
|
|
&iter);
|
|
|
|
|
if (path)
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
/* Path is relative to the child model (this is on search on elt offset)
|
|
|
|
|
* but with the virtual root already removed if necesssary.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
find_elt_with_offset (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
FilterLevel **level_,
|
|
|
|
|
FilterElt **elt_)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterLevel *parent_level = NULL;
|
|
|
|
|
FilterElt *elt = NULL;
|
|
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
while (i < gtk_tree_path_get_depth (path))
|
|
|
|
|
{
|
|
|
|
|
if (!level)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = lookup_elt_with_offset (level->seq,
|
|
|
|
|
gtk_tree_path_get_indices (path)[i],
|
|
|
|
|
NULL);
|
2011-05-14 12:09:51 +00:00
|
|
|
|
|
|
|
|
|
if (!elt)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
parent_level = level;
|
|
|
|
|
level = elt->children;
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (level_)
|
|
|
|
|
*level_ = parent_level;
|
|
|
|
|
|
|
|
|
|
if (elt_)
|
|
|
|
|
*elt_ = elt;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* TreeModel signals */
|
2011-05-14 12:42:31 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_emit_row_inserted_for_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter)
|
|
|
|
|
{
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter, children;
|
|
|
|
|
gboolean signals_emitted = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!filter->priv->root)
|
|
|
|
|
{
|
2011-05-21 09:45:08 +00:00
|
|
|
|
/* The root level has not been exposed to the view yet, so we
|
|
|
|
|
* need to emit signals for any node that is being inserted.
|
|
|
|
|
*/
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, TRUE);
|
2011-05-14 12:42:31 +00:00
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
/* Check if the root level was built. Then child levels
|
|
|
|
|
* that matter have also been built (due to update_children,
|
|
|
|
|
* which triggers iter_n_children).
|
2011-05-14 12:42:31 +00:00
|
|
|
|
*/
|
|
|
|
|
if (filter->priv->root &&
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_get_length (FILTER_LEVEL (filter->priv->root)->visible_seq) > 0)
|
2011-05-14 12:42:31 +00:00
|
|
|
|
signals_emitted = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
|
|
2011-05-14 12:42:31 +00:00
|
|
|
|
/* We need to disallow to build new levels, because we are then pulling
|
|
|
|
|
* in a child in an invisible level. We only want to find path if it
|
|
|
|
|
* is in a visible level (and thus has a parent that is visible).
|
|
|
|
|
*/
|
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
|
c_path,
|
|
|
|
|
FALSE,
|
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
|
/* parent is probably being filtered out */
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (filter), &iter, path);
|
|
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
|
|
|
|
|
/* Make sure elt is visible. elt can already be visible in case
|
2011-08-07 15:11:13 +00:00
|
|
|
|
* it was pulled in above, so avoid inserted it into visible_seq twice.
|
2011-05-14 12:42:31 +00:00
|
|
|
|
*/
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter)
|
2011-05-14 12:42:31 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt->visible_siter = g_sequence_insert_sorted (level->visible_seq,
|
|
|
|
|
elt, filter_elt_cmp,
|
|
|
|
|
NULL);
|
2011-05-14 12:42:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check whether the node and all of its parents are visible */
|
|
|
|
|
if (gtk_tree_model_filter_elt_is_visible_in_target (level, elt))
|
|
|
|
|
{
|
|
|
|
|
/* visibility changed -- reget path */
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (!signals_emitted &&
|
|
|
|
|
(!level->parent_level || level->ext_ref_count > 0))
|
2011-05-14 12:42:31 +00:00
|
|
|
|
gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter), path, &iter);
|
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (level->parent_level && level->parent_elt->ext_ref_count > 0 &&
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_get_length (level->visible_seq) == 1)
|
2011-05-14 12:42:31 +00:00
|
|
|
|
{
|
|
|
|
|
/* We know that this is the first visible node in this level, so
|
|
|
|
|
* we need to emit row-has-child-toggled on the parent. This
|
|
|
|
|
* does not apply to the root level.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_up (path);
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
|
|
|
|
path,
|
|
|
|
|
&iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!signals_emitted
|
|
|
|
|
&& gtk_tree_model_iter_children (c_model, &children, c_iter))
|
|
|
|
|
gtk_tree_model_filter_update_children (filter, level, elt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_row_changed (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (data);
|
|
|
|
|
GtkTreeIter iter;
|
2004-08-04 05:38:58 +00:00
|
|
|
|
GtkTreeIter children;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
GtkTreeIter real_c_iter;
|
|
|
|
|
GtkTreePath *path = NULL;
|
2011-05-21 09:45:08 +00:00
|
|
|
|
GtkTreePath *real_path = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
|
|
|
|
|
gboolean requested_state;
|
|
|
|
|
gboolean current_state;
|
|
|
|
|
gboolean free_c_path = FALSE;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (c_path != NULL || c_iter != NULL);
|
|
|
|
|
|
|
|
|
|
if (!c_path)
|
|
|
|
|
{
|
|
|
|
|
c_path = gtk_tree_model_get_path (c_model, c_iter);
|
|
|
|
|
free_c_path = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
real_path = gtk_tree_model_filter_remove_root (c_path,
|
|
|
|
|
filter->priv->virtual_root);
|
|
|
|
|
else
|
|
|
|
|
real_path = gtk_tree_path_copy (c_path);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (c_iter)
|
|
|
|
|
real_c_iter = *c_iter;
|
|
|
|
|
else
|
|
|
|
|
gtk_tree_model_get_iter (c_model, &real_c_iter, c_path);
|
|
|
|
|
|
2003-09-08 19:51:16 +00:00
|
|
|
|
/* is this node above the virtual root? */
|
2011-01-24 02:50:39 +00:00
|
|
|
|
if (filter->priv->virtual_root &&
|
|
|
|
|
(gtk_tree_path_get_depth (filter->priv->virtual_root)
|
2003-09-08 19:51:16 +00:00
|
|
|
|
>= gtk_tree_path_get_depth (c_path)))
|
|
|
|
|
goto done;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* what's the requested state? */
|
|
|
|
|
requested_state = gtk_tree_model_filter_visible (filter, &real_c_iter);
|
|
|
|
|
|
|
|
|
|
/* now, let's see whether the item is there */
|
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
|
c_path,
|
|
|
|
|
FALSE,
|
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
|
|
if (path)
|
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (filter),
|
|
|
|
|
&iter, path);
|
2011-08-07 15:11:13 +00:00
|
|
|
|
current_state = FILTER_ELT (iter.user_data2)->visible_siter != NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
current_state = FALSE;
|
|
|
|
|
|
|
|
|
|
if (current_state == FALSE && requested_state == FALSE)
|
|
|
|
|
/* no changes required */
|
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
|
|
if (current_state == TRUE && requested_state == FALSE)
|
|
|
|
|
{
|
2011-05-21 09:45:08 +00:00
|
|
|
|
gtk_tree_model_filter_remove_elt_from_level (filter,
|
|
|
|
|
FILTER_LEVEL (iter.user_data),
|
2011-05-20 18:39:12 +00:00
|
|
|
|
FILTER_ELT (iter.user_data2));
|
2004-02-02 22:44:05 +00:00
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (filter, real_path);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (current_state == TRUE && requested_state == TRUE)
|
|
|
|
|
{
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
|
2009-09-04 07:28:21 +00:00
|
|
|
|
if (gtk_tree_model_filter_elt_is_visible_in_target (level, elt))
|
|
|
|
|
{
|
2011-10-03 19:35:21 +00:00
|
|
|
|
/* propagate the signal; also get a path taking only visible
|
|
|
|
|
* nodes into account.
|
|
|
|
|
*/
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (level->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_row_changed (GTK_TREE_MODEL (filter), path, &iter);
|
2009-09-04 07:28:21 +00:00
|
|
|
|
|
|
|
|
|
/* and update the children */
|
|
|
|
|
if (gtk_tree_model_iter_children (c_model, &children, &real_c_iter))
|
|
|
|
|
gtk_tree_model_filter_update_children (filter, level, elt);
|
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (filter, real_path);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* only current == FALSE and requested == TRUE is left,
|
|
|
|
|
* pull in the child
|
|
|
|
|
*/
|
|
|
|
|
g_return_if_fail (current_state == FALSE && requested_state == TRUE);
|
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (filter, real_path);
|
|
|
|
|
|
2011-05-14 12:42:31 +00:00
|
|
|
|
gtk_tree_model_filter_emit_row_inserted_for_path (filter, c_model,
|
|
|
|
|
c_path, c_iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
if (path)
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (free_c_path)
|
|
|
|
|
gtk_tree_path_free (c_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_row_inserted (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (data);
|
2003-11-18 20:09:33 +00:00
|
|
|
|
GtkTreePath *real_path = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
GtkTreeIter real_c_iter;
|
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
FilterElt *elt = NULL;
|
|
|
|
|
FilterLevel *level = NULL;
|
|
|
|
|
FilterLevel *parent_level = NULL;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
FilterElt dummy;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2005-09-13 19:57:42 +00:00
|
|
|
|
gint i = 0, offset;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
gboolean free_c_path = FALSE;
|
2011-05-14 12:42:31 +00:00
|
|
|
|
gboolean emit_row_inserted = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (c_path != NULL || c_iter != NULL);
|
|
|
|
|
|
|
|
|
|
if (!c_path)
|
|
|
|
|
{
|
|
|
|
|
c_path = gtk_tree_model_get_path (c_model, c_iter);
|
|
|
|
|
free_c_path = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c_iter)
|
|
|
|
|
real_c_iter = *c_iter;
|
|
|
|
|
else
|
|
|
|
|
gtk_tree_model_get_iter (c_model, &real_c_iter, c_path);
|
|
|
|
|
|
|
|
|
|
/* the row has already been inserted. so we need to fixup the
|
|
|
|
|
* virtual root here first
|
|
|
|
|
*/
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
if (gtk_tree_path_get_depth (filter->priv->virtual_root) >=
|
|
|
|
|
gtk_tree_path_get_depth (c_path))
|
|
|
|
|
{
|
2015-05-31 01:29:03 +00:00
|
|
|
|
gint depth;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint *v_indices, *c_indices;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gboolean common_prefix = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
depth = gtk_tree_path_get_depth (c_path) - 1;
|
2010-06-28 18:15:10 +00:00
|
|
|
|
v_indices = gtk_tree_path_get_indices (filter->priv->virtual_root);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
c_indices = gtk_tree_path_get_indices (c_path);
|
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
for (i = 0; i < depth; i++)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (v_indices[i] != c_indices[i])
|
|
|
|
|
{
|
|
|
|
|
common_prefix = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
if (common_prefix && v_indices[depth] >= c_indices[depth])
|
|
|
|
|
(v_indices[depth])++;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* subtract virtual root if necessary */
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
real_path = gtk_tree_model_filter_remove_root (c_path,
|
|
|
|
|
filter->priv->virtual_root);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* not our child */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!real_path)
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
real_path = gtk_tree_path_copy (c_path);
|
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (!filter->priv->root)
|
|
|
|
|
{
|
|
|
|
|
/* The root level has not been exposed to the view yet, so we
|
|
|
|
|
* need to emit signals for any node that is being inserted.
|
|
|
|
|
*/
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, TRUE);
|
2011-05-21 09:45:08 +00:00
|
|
|
|
|
|
|
|
|
/* Check if the root level was built. Then child levels
|
|
|
|
|
* that matter have also been built (due to update_children,
|
|
|
|
|
* which triggers iter_n_children).
|
|
|
|
|
*/
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (filter->priv->root)
|
2011-05-21 09:45:08 +00:00
|
|
|
|
{
|
|
|
|
|
emit_row_inserted = FALSE;
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (gtk_tree_path_get_depth (real_path) - 1 >= 1)
|
|
|
|
|
{
|
2011-05-14 12:09:51 +00:00
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
GtkTreePath *parent = gtk_tree_path_copy (real_path);
|
|
|
|
|
gtk_tree_path_up (parent);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
found = find_elt_with_offset (filter, parent, &parent_level, &elt);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
gtk_tree_path_free (parent);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
if (!found)
|
|
|
|
|
/* Parent is not in the cache and probably being filtered out */
|
|
|
|
|
goto done;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
level = elt->children;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
if (!level)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt && elt->visible_siter)
|
2011-05-14 12:09:51 +00:00
|
|
|
|
{
|
|
|
|
|
/* The level in which the new node should be inserted does not
|
|
|
|
|
* exist, but the parent, elt, does. If elt is visible, emit
|
|
|
|
|
* row-has-child-toggled.
|
|
|
|
|
*/
|
|
|
|
|
GtkTreePath *tmppath;
|
|
|
|
|
GtkTreeIter tmpiter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
tmpiter.stamp = filter->priv->stamp;
|
|
|
|
|
tmpiter.user_data = parent_level;
|
|
|
|
|
tmpiter.user_data2 = elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
tmppath = gtk_tree_model_get_path (GTK_TREE_MODEL (filter),
|
|
|
|
|
&tmpiter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
if (tmppath)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
|
|
|
|
tmppath, &tmpiter);
|
|
|
|
|
gtk_tree_path_free (tmppath);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-05-14 12:09:51 +00:00
|
|
|
|
goto done;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* let's try to insert the value */
|
2010-06-28 18:15:10 +00:00
|
|
|
|
offset = gtk_tree_path_get_indices (real_path)[gtk_tree_path_get_depth (real_path) - 1];
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* update the offsets, yes if we didn't insert the node above, there will
|
|
|
|
|
* be a gap here. This will be filled with the node (via fetch_child) when
|
|
|
|
|
* it becomes visible
|
|
|
|
|
*/
|
2011-08-07 15:11:13 +00:00
|
|
|
|
dummy.offset = offset;
|
|
|
|
|
siter = g_sequence_search (level->seq, &dummy, filter_elt_cmp, NULL);
|
|
|
|
|
siter = g_sequence_iter_prev (siter);
|
|
|
|
|
g_sequence_foreach_range (siter, g_sequence_get_end_iter (level->seq),
|
|
|
|
|
increase_offset_iter, GINT_TO_POINTER (offset));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* only insert when visible */
|
|
|
|
|
if (gtk_tree_model_filter_visible (filter, &real_c_iter))
|
|
|
|
|
{
|
2011-05-14 09:47:01 +00:00
|
|
|
|
FilterElt *felt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 09:47:01 +00:00
|
|
|
|
felt = gtk_tree_model_filter_insert_elt_in_level (filter,
|
|
|
|
|
&real_c_iter,
|
|
|
|
|
level, offset,
|
|
|
|
|
&i);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-05-14 09:47:01 +00:00
|
|
|
|
/* insert_elt_in_level defaults to FALSE */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
felt->visible_siter = g_sequence_insert_sorted (level->visible_seq,
|
|
|
|
|
felt,
|
|
|
|
|
filter_elt_cmp, NULL);
|
2011-05-14 12:42:31 +00:00
|
|
|
|
emit_row_inserted = TRUE;
|
|
|
|
|
}
|
2003-11-18 20:09:33 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
done:
|
2011-09-10 08:32:16 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (filter, real_path);
|
2011-05-21 09:45:08 +00:00
|
|
|
|
|
2011-05-14 12:42:31 +00:00
|
|
|
|
if (emit_row_inserted)
|
|
|
|
|
gtk_tree_model_filter_emit_row_inserted_for_path (filter, c_model,
|
|
|
|
|
c_path, c_iter);
|
|
|
|
|
|
2003-11-18 20:09:33 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (free_c_path)
|
|
|
|
|
gtk_tree_path_free (c_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_row_has_child_toggled (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (data);
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
2009-09-02 10:45:41 +00:00
|
|
|
|
gboolean requested_state;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (c_path != NULL && c_iter != NULL);
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* If we get row-has-child-toggled on the virtual root, and there is
|
|
|
|
|
* no root level; try to build it now.
|
|
|
|
|
*/
|
|
|
|
|
if (filter->priv->virtual_root && !filter->priv->root
|
|
|
|
|
&& !gtk_tree_path_compare (c_path, filter->priv->virtual_root))
|
|
|
|
|
{
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, TRUE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2009-09-02 10:45:41 +00:00
|
|
|
|
/* For all other levels, there is a chance that the visibility state
|
|
|
|
|
* of the parent has changed now.
|
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
|
c_path,
|
|
|
|
|
FALSE,
|
|
|
|
|
TRUE);
|
|
|
|
|
if (!path)
|
|
|
|
|
return;
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (data), &iter, path);
|
|
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
|
2009-09-02 10:45:41 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
requested_state = gtk_tree_model_filter_visible (filter, c_iter);
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter && !requested_state)
|
2009-09-02 10:45:41 +00:00
|
|
|
|
{
|
|
|
|
|
/* The parent node currently is not visible and will not become
|
|
|
|
|
* visible, so we will not pass on the row-has-child-toggled event.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-08-07 15:11:13 +00:00
|
|
|
|
else if (elt->visible_siter && !requested_state)
|
2009-09-02 10:45:41 +00:00
|
|
|
|
{
|
|
|
|
|
/* The node is no longer visible, so it has to be removed.
|
2011-05-20 18:39:12 +00:00
|
|
|
|
* _remove_elt_from_level() takes care of emitting row-has-child-toggled
|
2009-09-02 10:45:41 +00:00
|
|
|
|
* when required.
|
|
|
|
|
*/
|
2011-05-20 18:39:12 +00:00
|
|
|
|
gtk_tree_model_filter_remove_elt_from_level (filter, level, elt);
|
2009-09-02 10:45:41 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-08-07 15:11:13 +00:00
|
|
|
|
else if (!elt->visible_siter && requested_state)
|
2009-09-02 10:45:41 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt->visible_siter = g_sequence_insert_sorted (level->visible_seq,
|
|
|
|
|
elt, filter_elt_cmp,
|
|
|
|
|
NULL);
|
2009-09-02 10:45:41 +00:00
|
|
|
|
|
|
|
|
|
/* Only insert if the parent is visible in the target */
|
|
|
|
|
if (gtk_tree_model_filter_elt_is_visible_in_target (level, elt))
|
|
|
|
|
{
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
|
gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter), path, &iter);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
|
|
/* We do not update children now, because that will happen
|
|
|
|
|
* below.
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* For the remaining possibility, elt->visible && requested_state
|
|
|
|
|
* no action is required.
|
|
|
|
|
*/
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
/* If this node is referenced and has children, build the level so we
|
|
|
|
|
* can monitor it for changes.
|
|
|
|
|
*/
|
2011-07-10 14:35:38 +00:00
|
|
|
|
if (elt->ref_count > 1 && !elt->children &&
|
|
|
|
|
gtk_tree_model_iter_has_child (c_model, c_iter))
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
/* get a path taking only visible nodes into account */
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (data), &iter);
|
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (data), path, &iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-09 07:06:25 +00:00
|
|
|
|
static void
|
2011-05-09 08:29:37 +00:00
|
|
|
|
gtk_tree_model_filter_virtual_root_deleted (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *c_path)
|
2011-05-09 07:06:25 +00:00
|
|
|
|
{
|
2011-06-26 19:44:13 +00:00
|
|
|
|
gint i, nodes;
|
2011-05-09 07:06:25 +00:00
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
FilterLevel *level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
2011-05-09 08:29:37 +00:00
|
|
|
|
/* The virtual root (or one of its ancestors) has been deleted. This
|
|
|
|
|
* means that all content for our model is now gone. We deal with
|
|
|
|
|
* this by removing everything in the filter model: we just iterate
|
|
|
|
|
* over the root level and emit a row-deleted for each FilterElt.
|
|
|
|
|
* (FIXME: Should we emit row-deleted for child nodes as well? This
|
|
|
|
|
* has never been fully clear in TreeModel).
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* We unref the path of the virtual root, up to and not including the
|
|
|
|
|
* deleted node which can no longer be unreffed.
|
|
|
|
|
*/
|
|
|
|
|
gtk_tree_model_filter_unref_path (filter, filter->priv->virtual_root,
|
|
|
|
|
gtk_tree_path_get_depth (c_path) - 1);
|
2011-05-09 07:06:25 +00:00
|
|
|
|
filter->priv->virtual_root_deleted = TRUE;
|
|
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
nodes = g_sequence_get_length (level->visible_seq);
|
2011-06-26 19:44:13 +00:00
|
|
|
|
|
|
|
|
|
/* We should not propagate the unref here. An unref for any of these
|
|
|
|
|
* nodes will fail, since the respective nodes in the child model are
|
|
|
|
|
* no longer there.
|
|
|
|
|
*/
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, filter->priv->root, FALSE, TRUE, FALSE);
|
2011-06-26 19:44:13 +00:00
|
|
|
|
|
2011-05-09 07:06:25 +00:00
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
2011-06-26 19:44:13 +00:00
|
|
|
|
|
2011-05-09 07:06:25 +00:00
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
|
gtk_tree_path_append_index (path, 0);
|
|
|
|
|
|
2011-06-26 19:44:13 +00:00
|
|
|
|
for (i = 0; i < nodes; i++)
|
2011-05-09 07:06:25 +00:00
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (filter), path);
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_adjust_virtual_root (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *c_path)
|
|
|
|
|
{
|
|
|
|
|
gint i;
|
|
|
|
|
gint level;
|
|
|
|
|
gint *v_indices, *c_indices;
|
|
|
|
|
gboolean common_prefix = TRUE;
|
|
|
|
|
|
|
|
|
|
level = gtk_tree_path_get_depth (c_path) - 1;
|
|
|
|
|
v_indices = gtk_tree_path_get_indices (filter->priv->virtual_root);
|
|
|
|
|
c_indices = gtk_tree_path_get_indices (c_path);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < level; i++)
|
|
|
|
|
if (v_indices[i] != c_indices[i])
|
|
|
|
|
{
|
|
|
|
|
common_prefix = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (common_prefix && v_indices[level] > c_indices[level])
|
|
|
|
|
(v_indices[level])--;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-09 20:22:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_row_deleted_invisible_node (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *c_path)
|
|
|
|
|
{
|
|
|
|
|
int offset;
|
|
|
|
|
GtkTreePath *real_path;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
FilterElt dummy;
|
|
|
|
|
GSequenceIter *siter;
|
2011-05-09 20:22:24 +00:00
|
|
|
|
|
|
|
|
|
/* The node deleted in the child model is not visible in the
|
|
|
|
|
* filter model. We will not emit a signal, just fixup the offsets
|
|
|
|
|
* of the other nodes.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!filter->priv->root)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
/* subtract vroot if necessary */
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
real_path = gtk_tree_model_filter_remove_root (c_path,
|
|
|
|
|
filter->priv->virtual_root);
|
|
|
|
|
/* we don't handle this */
|
|
|
|
|
if (!real_path)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
real_path = gtk_tree_path_copy (c_path);
|
|
|
|
|
|
|
|
|
|
if (gtk_tree_path_get_depth (real_path) - 1 >= 1)
|
|
|
|
|
{
|
2011-05-14 12:09:51 +00:00
|
|
|
|
gboolean found = FALSE;
|
|
|
|
|
GtkTreePath *parent = gtk_tree_path_copy (real_path);
|
|
|
|
|
gtk_tree_path_up (parent);
|
2011-05-09 20:22:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
found = find_elt_with_offset (filter, parent, &level, &elt);
|
2011-05-09 20:22:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
gtk_tree_path_free (parent);
|
2011-05-09 20:22:24 +00:00
|
|
|
|
|
2011-05-14 12:09:51 +00:00
|
|
|
|
if (!found)
|
|
|
|
|
{
|
|
|
|
|
/* parent is filtered out, so no level */
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
return;
|
2011-05-09 20:22:24 +00:00
|
|
|
|
}
|
2011-05-14 12:09:51 +00:00
|
|
|
|
|
|
|
|
|
level = elt->children;
|
2011-05-09 20:22:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
offset = gtk_tree_path_get_indices (real_path)[gtk_tree_path_get_depth (real_path) - 1];
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* decrease offset of all nodes following the deleted node */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
dummy.offset = offset;
|
|
|
|
|
siter = g_sequence_search (level->seq, &dummy, filter_elt_cmp, NULL);
|
|
|
|
|
g_sequence_foreach_range (siter, g_sequence_get_end_iter (level->seq),
|
|
|
|
|
decrease_offset_iter, GINT_TO_POINTER (offset));
|
2011-05-09 20:22:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_row_deleted (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (data);
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *elt, *parent_elt = NULL;
|
2006-10-08 05:07:55 +00:00
|
|
|
|
FilterLevel *level, *parent_level = NULL;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gboolean emit_child_toggled = FALSE;
|
2011-02-16 23:40:14 +00:00
|
|
|
|
gboolean emit_row_deleted = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint offset;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
gint orig_level_ext_ref_count;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (c_path != NULL);
|
|
|
|
|
|
|
|
|
|
/* special case the deletion of an ancestor of the virtual root */
|
|
|
|
|
if (filter->priv->virtual_root &&
|
|
|
|
|
(gtk_tree_path_is_ancestor (c_path, filter->priv->virtual_root) ||
|
|
|
|
|
!gtk_tree_path_compare (c_path, filter->priv->virtual_root)))
|
|
|
|
|
{
|
2011-05-09 08:29:37 +00:00
|
|
|
|
gtk_tree_model_filter_virtual_root_deleted (filter, c_path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-09 07:06:25 +00:00
|
|
|
|
/* adjust the virtual root for the deleted row */
|
|
|
|
|
if (filter->priv->virtual_root &&
|
|
|
|
|
gtk_tree_path_get_depth (filter->priv->virtual_root) >=
|
|
|
|
|
gtk_tree_path_get_depth (c_path))
|
|
|
|
|
gtk_tree_model_filter_adjust_virtual_root (filter, c_path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
|
c_path,
|
|
|
|
|
FALSE,
|
|
|
|
|
FALSE);
|
2003-11-18 19:57:14 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!path)
|
|
|
|
|
{
|
2011-05-09 20:22:24 +00:00
|
|
|
|
gtk_tree_model_filter_row_deleted_invisible_node (filter, c_path);
|
2003-11-18 19:57:14 +00:00
|
|
|
|
return;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* a node was deleted, which was in our cache */
|
|
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (data), &iter, path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
offset = elt->offset;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
orig_level_ext_ref_count = level->ext_ref_count;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt->visible_siter)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* get a path taking only visible nodes into account */
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (g_sequence_get_length (level->visible_seq) == 1)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
|
|
|
|
emit_child_toggled = TRUE;
|
|
|
|
|
parent_level = level->parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt = level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-16 23:40:14 +00:00
|
|
|
|
emit_row_deleted = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-05-09 08:29:37 +00:00
|
|
|
|
/* Release the references on this node, without propagation because
|
|
|
|
|
* the node does not exist anymore in the child model. The filter
|
|
|
|
|
* model's references on the node in case of level->parent or use
|
|
|
|
|
* of a virtual root are automatically destroyed by the child model.
|
2005-10-25 21:00:40 +00:00
|
|
|
|
*/
|
2011-06-26 20:04:05 +00:00
|
|
|
|
while (elt->ext_ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (data), &iter,
|
|
|
|
|
TRUE, FALSE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-10-03 20:38:42 +00:00
|
|
|
|
if (elt->children)
|
|
|
|
|
/* If this last node has children, then the recursion in free_level
|
|
|
|
|
* will release this reference.
|
|
|
|
|
*/
|
|
|
|
|
while (elt->ref_count > 1)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (data), &iter,
|
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
else
|
|
|
|
|
while (elt->ref_count > 0)
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (data), &iter,
|
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (g_sequence_get_length (level->seq) == 1)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
/* kill level */
|
2011-09-11 14:53:27 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, level, FALSE, TRUE, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *tmp;
|
2011-07-10 14:35:38 +00:00
|
|
|
|
gboolean is_first;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
lookup_elt_with_offset (level->seq, elt->offset, &siter);
|
|
|
|
|
is_first = g_sequence_get_begin_iter (level->seq) == siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-10-03 20:38:42 +00:00
|
|
|
|
if (elt->children)
|
|
|
|
|
gtk_tree_model_filter_free_level (filter, elt->children,
|
2012-03-19 01:24:03 +00:00
|
|
|
|
FALSE, FALSE, FALSE);
|
2011-10-03 20:38:42 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* remove the row */
|
2011-10-03 20:38:42 +00:00
|
|
|
|
if (elt->visible_siter)
|
|
|
|
|
g_sequence_remove (elt->visible_siter);
|
2011-08-07 15:11:13 +00:00
|
|
|
|
tmp = g_sequence_iter_next (siter);
|
|
|
|
|
g_sequence_remove (siter);
|
|
|
|
|
g_sequence_foreach_range (tmp, g_sequence_get_end_iter (level->seq),
|
|
|
|
|
decrease_offset_iter, GINT_TO_POINTER (offset));
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
/* Take a reference on the new first node. The first node previously
|
|
|
|
|
* keeping this reference has been removed above.
|
|
|
|
|
*/
|
|
|
|
|
if (is_first)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
|
f_iter.user_data = level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
f_iter.user_data2 = g_sequence_get (g_sequence_get_begin_iter (level->seq));
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_real_ref_node (GTK_TREE_MODEL (filter),
|
|
|
|
|
&f_iter, FALSE);
|
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-02-16 23:40:14 +00:00
|
|
|
|
if (emit_row_deleted)
|
|
|
|
|
{
|
|
|
|
|
/* emit row_deleted */
|
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (!parent_elt || orig_level_ext_ref_count > 0)
|
2011-07-10 14:35:38 +00:00
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
|
2011-02-16 23:40:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (emit_child_toggled && parent_level)
|
|
|
|
|
{
|
2011-02-16 23:40:14 +00:00
|
|
|
|
GtkTreeIter iter2;
|
|
|
|
|
GtkTreePath *path2;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-02-16 23:40:14 +00:00
|
|
|
|
iter2.stamp = filter->priv->stamp;
|
|
|
|
|
iter2.user_data = parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
iter2.user_data2 = parent_elt;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
/* We set in_row_deleted to TRUE to avoid a level build triggered
|
|
|
|
|
* by row-has-child-toggled (parent model could call iter_has_child
|
|
|
|
|
* for example).
|
|
|
|
|
*/
|
|
|
|
|
filter->priv->in_row_deleted = TRUE;
|
2011-02-16 23:40:14 +00:00
|
|
|
|
path2 = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter2);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
2011-02-16 23:40:14 +00:00
|
|
|
|
path2, &iter2);
|
|
|
|
|
gtk_tree_path_free (path2);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
filter->priv->in_row_deleted = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *real_path;
|
|
|
|
|
|
|
|
|
|
real_path = gtk_tree_model_filter_remove_root (c_path,
|
2014-01-16 14:23:20 +00:00
|
|
|
|
filter->priv->virtual_root);
|
2011-05-21 09:45:08 +00:00
|
|
|
|
if (real_path)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (filter, real_path);
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
gtk_tree_model_filter_check_ancestors (filter, c_path);
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_rows_reordered (GtkTreeModel *c_model,
|
|
|
|
|
GtkTreePath *c_path,
|
|
|
|
|
GtkTreeIter *c_iter,
|
|
|
|
|
gint *new_order,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (data);
|
|
|
|
|
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequence *tmp_seq;
|
|
|
|
|
GSequenceIter *tmp_end_iter;
|
2011-09-11 10:00:00 +00:00
|
|
|
|
GSequenceIter *old_first_siter = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint *tmp_array;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gint i, elt_count;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint length;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (new_order != NULL);
|
|
|
|
|
|
2007-09-09 19:48:22 +00:00
|
|
|
|
if (c_path == NULL || gtk_tree_path_get_depth (c_path) == 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
length = gtk_tree_model_iter_n_children (c_model, NULL);
|
|
|
|
|
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
gint new_pos = -1;
|
|
|
|
|
|
|
|
|
|
/* reorder root level of path */
|
|
|
|
|
for (i = 0; i < length; i++)
|
2010-06-28 18:15:10 +00:00
|
|
|
|
if (new_order[i] == gtk_tree_path_get_indices (filter->priv->virtual_root)[0])
|
2003-07-11 12:51:24 +00:00
|
|
|
|
new_pos = i;
|
|
|
|
|
|
|
|
|
|
if (new_pos < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-06-28 18:15:10 +00:00
|
|
|
|
gtk_tree_path_get_indices (filter->priv->virtual_root)[0] = new_pos;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
|
|
/* virtual root anchor reordering */
|
|
|
|
|
if (filter->priv->virtual_root &&
|
2006-02-17 15:00:47 +00:00
|
|
|
|
gtk_tree_path_is_ancestor (c_path, filter->priv->virtual_root))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
gint new_pos = -1;
|
2015-05-31 01:29:03 +00:00
|
|
|
|
gint len;
|
|
|
|
|
gint depth;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
GtkTreeIter real_c_iter;
|
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
depth = gtk_tree_path_get_depth (c_path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
if (c_iter)
|
|
|
|
|
real_c_iter = *c_iter;
|
|
|
|
|
else
|
|
|
|
|
gtk_tree_model_get_iter (c_model, &real_c_iter, c_path);
|
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
len = gtk_tree_model_iter_n_children (c_model, &real_c_iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
for (i = 0; i < len; i++)
|
|
|
|
|
if (new_order[i] == gtk_tree_path_get_indices (filter->priv->virtual_root)[depth])
|
2003-07-11 12:51:24 +00:00
|
|
|
|
new_pos = i;
|
|
|
|
|
|
|
|
|
|
if (new_pos < 0)
|
|
|
|
|
return;
|
|
|
|
|
|
2015-05-31 01:29:03 +00:00
|
|
|
|
gtk_tree_path_get_indices (filter->priv->virtual_root)[depth] = new_pos;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
|
c_path,
|
|
|
|
|
FALSE,
|
|
|
|
|
FALSE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!path && filter->priv->virtual_root &&
|
|
|
|
|
gtk_tree_path_compare (c_path, filter->priv->virtual_root))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!path && !filter->priv->virtual_root)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!path)
|
|
|
|
|
{
|
|
|
|
|
/* root level mode */
|
|
|
|
|
if (!c_iter)
|
|
|
|
|
gtk_tree_model_get_iter (c_model, c_iter, c_path);
|
|
|
|
|
length = gtk_tree_model_iter_n_children (c_model, c_iter);
|
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (data),
|
|
|
|
|
&iter, path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
|
|
|
|
|
if (!elt->children)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
level = elt->children;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (filter), &child_iter, &iter);
|
|
|
|
|
length = gtk_tree_model_iter_n_children (c_model, &child_iter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!level || g_sequence_get_length (level->seq) < 1)
|
2004-01-28 23:56:50 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
/* NOTE: we do not bail out here if level->seq->len < 2 like
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* GtkTreeModelSort does. This because we do some special tricky
|
|
|
|
|
* reordering.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
tmp_seq = g_sequence_new (filter_elt_free);
|
|
|
|
|
tmp_end_iter = g_sequence_get_end_iter (tmp_seq);
|
|
|
|
|
tmp_array = g_new (gint, g_sequence_get_length (level->visible_seq));
|
|
|
|
|
elt_count = 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-09-11 10:00:00 +00:00
|
|
|
|
old_first_siter = g_sequence_get_iter_at_pos (level->seq, 0);
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
for (i = 0; i < length; i++)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = lookup_elt_with_offset (level->seq, new_order[i], &siter);
|
|
|
|
|
if (elt == NULL)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
/* Only for visible items an entry should be present in the order array
|
|
|
|
|
* to be emitted.
|
|
|
|
|
*/
|
|
|
|
|
if (elt->visible_siter)
|
|
|
|
|
tmp_array[elt_count++] = g_sequence_iter_get_position (elt->visible_siter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
/* Steal elt from level->seq and append it to tmp_seq */
|
|
|
|
|
g_sequence_move (siter, tmp_end_iter);
|
|
|
|
|
elt->offset = i;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_warn_if_fail (g_sequence_get_length (level->seq) == 0);
|
|
|
|
|
g_sequence_free (level->seq);
|
|
|
|
|
level->seq = tmp_seq;
|
|
|
|
|
g_sequence_sort (level->visible_seq, filter_elt_cmp, NULL);
|
|
|
|
|
|
2011-07-10 14:35:38 +00:00
|
|
|
|
/* Transfer the reference from the old item at position 0 to the
|
2011-09-11 10:00:00 +00:00
|
|
|
|
* new item at position 0, unless the old item at position 0 is also
|
|
|
|
|
* at position 0 in the new sequence.
|
2011-07-10 14:35:38 +00:00
|
|
|
|
*/
|
2011-09-11 10:00:00 +00:00
|
|
|
|
if (g_sequence_iter_get_position (old_first_siter) != 0)
|
2011-07-10 14:35:38 +00:00
|
|
|
|
gtk_tree_model_filter_level_transfer_first_ref (filter,
|
|
|
|
|
level,
|
2011-09-11 10:00:00 +00:00
|
|
|
|
old_first_siter,
|
2011-08-07 15:11:13 +00:00
|
|
|
|
g_sequence_get_iter_at_pos (level->seq, 0));
|
2011-07-10 14:35:38 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* emit rows_reordered */
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (g_sequence_get_length (level->visible_seq) > 0)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
2011-07-24 16:52:59 +00:00
|
|
|
|
if (!gtk_tree_path_get_indices (path))
|
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, NULL,
|
|
|
|
|
tmp_array);
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* get a path taking only visible nodes into account */
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (data), &iter);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-07-24 16:52:59 +00:00
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, &iter,
|
|
|
|
|
tmp_array);
|
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
/* done */
|
|
|
|
|
g_free (tmp_array);
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TreeModelIface implementation */
|
2004-08-03 22:41:31 +00:00
|
|
|
|
static GtkTreeModelFlags
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_model_filter_get_flags (GtkTreeModel *model)
|
|
|
|
|
{
|
2003-12-13 15:20:28 +00:00
|
|
|
|
GtkTreeModelFlags flags;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), 0);
|
2003-12-13 15:20:28 +00:00
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL, 0);
|
|
|
|
|
|
|
|
|
|
flags = gtk_tree_model_get_flags (GTK_TREE_MODEL_FILTER (model)->priv->child_model);
|
|
|
|
|
|
|
|
|
|
if ((flags & GTK_TREE_MODEL_LIST_ONLY) == GTK_TREE_MODEL_LIST_ONLY)
|
|
|
|
|
return GTK_TREE_MODEL_LIST_ONLY;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
gtk_tree_model_filter_get_n_columns (GtkTreeModel *model)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), 0);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, 0);
|
|
|
|
|
|
|
|
|
|
if (filter->priv->child_model == NULL)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2014-08-30 05:59:05 +00:00
|
|
|
|
/* so we can't set the modify func after this ... */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->modify_func_set = TRUE;
|
|
|
|
|
|
|
|
|
|
if (filter->priv->modify_n_columns > 0)
|
|
|
|
|
return filter->priv->modify_n_columns;
|
|
|
|
|
|
|
|
|
|
return gtk_tree_model_get_n_columns (filter->priv->child_model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GType
|
|
|
|
|
gtk_tree_model_filter_get_column_type (GtkTreeModel *model,
|
|
|
|
|
gint index)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), G_TYPE_INVALID);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, G_TYPE_INVALID);
|
|
|
|
|
|
2014-08-30 05:59:05 +00:00
|
|
|
|
/* so we can't set the modify func after this ... */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->modify_func_set = TRUE;
|
|
|
|
|
|
|
|
|
|
if (filter->priv->modify_types)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (index < filter->priv->modify_n_columns, G_TYPE_INVALID);
|
|
|
|
|
|
|
|
|
|
return filter->priv->modify_types[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gtk_tree_model_get_column_type (filter->priv->child_model, index);
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* A special case of _get_iter; this function can also get iters which
|
|
|
|
|
* are not visible. These iters should ONLY be passed internally, never
|
|
|
|
|
* pass those along with a signal emission.
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_get_iter_full (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
gint *indices;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
gint depth, i;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
|
2010-06-28 18:15:10 +00:00
|
|
|
|
indices = gtk_tree_path_get_indices (path);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
if (filter->priv->root == NULL)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
depth = gtk_tree_path_get_depth (path);
|
|
|
|
|
if (!depth)
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < depth - 1; i++)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!level || indices[i] >= g_sequence_get_length (level->seq))
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->seq, indices[i]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
2011-05-09 07:51:50 +00:00
|
|
|
|
iter->stamp = 0;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = GET_ELT (siter);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
if (!elt->children)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
level = elt->children;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!level || indices[i] >= g_sequence_get_length (level->seq))
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
|
iter->user_data = level;
|
|
|
|
|
|
2011-08-07 15:11:13 +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);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_get_iter (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
gint *indices;
|
|
|
|
|
FilterLevel *level;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
FilterElt *elt;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gint depth, i;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
|
2010-06-28 18:15:10 +00:00
|
|
|
|
indices = gtk_tree_path_get_indices (path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
if (filter->priv->root == NULL)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
depth = gtk_tree_path_get_depth (path);
|
|
|
|
|
if (!depth)
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < depth - 1; i++)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!level || indices[i] >= g_sequence_get_length (level->visible_seq))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-05-09 07:51:50 +00:00
|
|
|
|
iter->stamp = 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->visible_seq, indices[i]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = GET_ELT (siter);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (!elt->children)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
level = elt->children;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!level || indices[i] >= g_sequence_get_length (level->visible_seq))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
|
iter->user_data = level;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->visible_seq, indices[depth - 1]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
|
gtk_tree_model_filter_get_path (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), NULL);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == iter->stamp, NULL);
|
|
|
|
|
|
|
|
|
|
level = iter->user_data;
|
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
return NULL;
|
|
|
|
|
|
2008-01-10 09:27:40 +00:00
|
|
|
|
retval = gtk_tree_path_new ();
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
while (level)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gint index;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
index = g_sequence_iter_get_position (elt->visible_siter);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_path_prepend_index (retval, index);
|
2011-08-07 15:11:13 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
elt = level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
level = level->parent_level;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2009-12-09 09:21:34 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_real_modify (GtkTreeModelFilter *self,
|
|
|
|
|
GtkTreeModel *child_model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GValue *value,
|
|
|
|
|
gint column)
|
|
|
|
|
{
|
|
|
|
|
if (self->priv->modify_func)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (column < self->priv->modify_n_columns);
|
|
|
|
|
|
|
|
|
|
g_value_init (value, self->priv->modify_types[column]);
|
|
|
|
|
self->priv->modify_func (GTK_TREE_MODEL (self),
|
2014-08-30 05:59:05 +00:00
|
|
|
|
iter, value, column,
|
|
|
|
|
self->priv->modify_data);
|
2009-12-09 09:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (self),
|
|
|
|
|
&child_iter, iter);
|
|
|
|
|
gtk_tree_model_get_value (child_model, &child_iter, column, value);
|
2009-12-09 09:21:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_get_value (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gint column,
|
|
|
|
|
GValue *value)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = GTK_TREE_MODEL_FILTER (model);
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (model));
|
|
|
|
|
g_return_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL);
|
|
|
|
|
g_return_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == iter->stamp);
|
|
|
|
|
|
2009-12-09 09:21:34 +00:00
|
|
|
|
GTK_TREE_MODEL_FILTER_GET_CLASS (model)->modify (filter,
|
|
|
|
|
filter->priv->child_model, iter, value, column);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_iter_next (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
FilterElt *elt;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == iter->stamp, FALSE);
|
|
|
|
|
|
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_iter_next (elt->visible_siter);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
return TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-06 04:39:11 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_iter_previous (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
FilterElt *elt;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2011-01-06 04:39:11 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == iter->stamp, FALSE);
|
|
|
|
|
|
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
2012-07-14 00:34:26 +00:00
|
|
|
|
if (g_sequence_iter_is_begin (elt->visible_siter))
|
2011-01-06 04:39:11 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
2011-01-06 04:39:11 +00:00
|
|
|
|
}
|
2012-07-14 00:34:26 +00:00
|
|
|
|
siter = g_sequence_iter_prev (elt->visible_siter);
|
2011-01-06 04:39:11 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
2011-01-06 04:39:11 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
return TRUE;
|
2011-01-06 04:39:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_iter_children (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *parent)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
FilterLevel *level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
if (parent)
|
|
|
|
|
g_return_val_if_fail (filter->priv->stamp == parent->stamp, FALSE);
|
|
|
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
|
{
|
|
|
|
|
if (!filter->priv->root)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!filter->priv->root)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
level = filter->priv->root;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_get_begin_iter (level->visible_seq);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
|
iter->user_data = level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
return TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (FILTER_ELT (parent->user_data2)->children == NULL)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter,
|
|
|
|
|
FILTER_LEVEL (parent->user_data),
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FILTER_ELT (parent->user_data2),
|
2005-10-25 21:00:40 +00:00
|
|
|
|
FALSE);
|
2011-08-05 15:40:04 +00:00
|
|
|
|
if (FILTER_ELT (parent->user_data2)->children == NULL)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
level = FILTER_ELT (parent->user_data2)->children;
|
|
|
|
|
siter = g_sequence_get_begin_iter (level->visible_seq);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
|
iter->user_data = level;
|
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_iter_has_child (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->priv->stamp == iter->stamp, FALSE);
|
|
|
|
|
|
|
|
|
|
filter = GTK_TREE_MODEL_FILTER (model);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, iter);
|
|
|
|
|
elt = FILTER_ELT (iter->user_data2);
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* we need to build the level to check if not all children are filtered
|
|
|
|
|
* out
|
|
|
|
|
*/
|
|
|
|
|
if (!elt->children
|
|
|
|
|
&& gtk_tree_model_iter_has_child (filter->priv->child_model, &child_iter))
|
|
|
|
|
gtk_tree_model_filter_build_level (filter, FILTER_LEVEL (iter->user_data),
|
2011-08-05 15:40:04 +00:00
|
|
|
|
elt, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (elt->children && g_sequence_get_length (elt->children->visible_seq) > 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gint
|
|
|
|
|
gtk_tree_model_filter_iter_n_children (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), 0);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, 0);
|
|
|
|
|
if (iter)
|
|
|
|
|
g_return_val_if_fail (filter->priv->stamp == iter->stamp, 0);
|
|
|
|
|
|
|
|
|
|
if (!iter)
|
|
|
|
|
{
|
|
|
|
|
if (!filter->priv->root)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (filter->priv->root)
|
2011-08-07 15:11:13 +00:00
|
|
|
|
return g_sequence_get_length (FILTER_LEVEL (filter->priv->root)->visible_seq);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elt = FILTER_ELT (iter->user_data2);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!elt->visible_siter)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, iter);
|
|
|
|
|
|
|
|
|
|
if (!elt->children &&
|
|
|
|
|
gtk_tree_model_iter_has_child (filter->priv->child_model, &child_iter))
|
|
|
|
|
gtk_tree_model_filter_build_level (filter,
|
|
|
|
|
FILTER_LEVEL (iter->user_data),
|
2011-08-05 15:40:04 +00:00
|
|
|
|
elt, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (elt->children)
|
2011-08-07 15:11:13 +00:00
|
|
|
|
return g_sequence_get_length (elt->children->visible_seq);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_iter_nth_child (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
|
gint n)
|
|
|
|
|
{
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
GtkTreeIter children;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
if (parent)
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == parent->stamp, FALSE);
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* use this instead of has_child to force us to build the level, if needed */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (gtk_tree_model_filter_iter_children (model, &children, parent) == FALSE)
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
level = children.user_data;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->visible_seq, n);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
|
|
|
|
return FALSE;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
iter->stamp = GTK_TREE_MODEL_FILTER (model)->priv->stamp;
|
|
|
|
|
iter->user_data = level;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
iter->user_data2 = GET_ELT (siter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_iter_parent (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
GtkTreeIter *child)
|
|
|
|
|
{
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == child->stamp, FALSE);
|
|
|
|
|
|
|
|
|
|
level = child->user_data;
|
|
|
|
|
|
|
|
|
|
if (level->parent_level)
|
|
|
|
|
{
|
|
|
|
|
iter->stamp = GTK_TREE_MODEL_FILTER (model)->priv->stamp;
|
|
|
|
|
iter->user_data = level->parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
iter->user_data2 = level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_ref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
2011-06-26 20:04:05 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_model_filter_real_ref_node (model, iter, TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_real_ref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gboolean external)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (model));
|
|
|
|
|
g_return_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->child_model != NULL);
|
|
|
|
|
g_return_if_fail (GTK_TREE_MODEL_FILTER (model)->priv->stamp == iter->stamp);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, iter);
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_ref_node (filter->priv->child_model, &child_iter);
|
|
|
|
|
|
|
|
|
|
level = iter->user_data;
|
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
|
|
|
|
elt->ref_count++;
|
|
|
|
|
level->ref_count++;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
|
|
|
|
|
if (external)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-06-26 20:04:05 +00:00
|
|
|
|
elt->ext_ref_count++;
|
|
|
|
|
level->ext_ref_count++;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
if (level->ext_ref_count == 1)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-06-26 20:04:05 +00:00
|
|
|
|
FilterLevel *parent_level = level->parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *parent_elt = level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
/* we were at zero -- time to decrease the zero_ref_count val */
|
|
|
|
|
while (parent_level)
|
|
|
|
|
{
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt->zero_ref_count--;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
parent_level = parent_level->parent_level;
|
|
|
|
|
}
|
2006-09-27 14:16:47 +00:00
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
if (filter->priv->root != level)
|
|
|
|
|
filter->priv->zero_ref_count--;
|
2011-09-07 07:36:18 +00:00
|
|
|
|
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (filter->priv->zero_ref_count >= 0);
|
2011-09-17 04:08:40 +00:00
|
|
|
|
if (filter->priv->zero_ref_count > 0)
|
|
|
|
|
g_assert (filter->priv->root != NULL);
|
2011-09-07 07:36:18 +00:00
|
|
|
|
#endif
|
2011-06-26 20:04:05 +00:00
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
2011-09-07 07:36:18 +00:00
|
|
|
|
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (elt->ref_count >= elt->ext_ref_count);
|
|
|
|
|
g_assert (elt->ref_count >= 0);
|
|
|
|
|
g_assert (elt->ext_ref_count >= 0);
|
|
|
|
|
#endif
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_unref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
|
{
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gtk_tree_model_filter_real_unref_node (model, iter, TRUE, TRUE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_real_unref_node (GtkTreeModel *model,
|
|
|
|
|
GtkTreeIter *iter,
|
2011-06-26 20:04:05 +00:00
|
|
|
|
gboolean external,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gboolean propagate_unref)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *filter = (GtkTreeModelFilter *)model;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (model));
|
|
|
|
|
g_return_if_fail (filter->priv->child_model != NULL);
|
|
|
|
|
g_return_if_fail (filter->priv->stamp == iter->stamp);
|
|
|
|
|
|
|
|
|
|
if (propagate_unref)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, iter);
|
|
|
|
|
gtk_tree_model_unref_node (filter->priv->child_model, &child_iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
level = iter->user_data;
|
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (elt->ref_count > 0);
|
2011-09-07 07:36:18 +00:00
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (elt->ref_count >= elt->ext_ref_count);
|
|
|
|
|
g_assert (elt->ref_count >= 0);
|
|
|
|
|
g_assert (elt->ext_ref_count >= 0);
|
|
|
|
|
#endif
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
elt->ref_count--;
|
|
|
|
|
level->ref_count--;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
|
|
|
|
|
if (external)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-06-26 20:04:05 +00:00
|
|
|
|
elt->ext_ref_count--;
|
|
|
|
|
level->ext_ref_count--;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
if (level->ext_ref_count == 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-06-26 20:04:05 +00:00
|
|
|
|
FilterLevel *parent_level = level->parent_level;
|
2011-08-05 15:40:04 +00:00
|
|
|
|
FilterElt *parent_elt = level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
/* we are at zero -- time to increase the zero_ref_count val */
|
|
|
|
|
while (parent_level)
|
|
|
|
|
{
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt->zero_ref_count++;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
|
2011-08-05 15:40:04 +00:00
|
|
|
|
parent_elt = parent_level->parent_elt;
|
2011-06-26 20:04:05 +00:00
|
|
|
|
parent_level = parent_level->parent_level;
|
|
|
|
|
}
|
2006-09-27 14:16:47 +00:00
|
|
|
|
|
2011-06-26 20:04:05 +00:00
|
|
|
|
if (filter->priv->root != level)
|
|
|
|
|
filter->priv->zero_ref_count++;
|
2011-09-07 07:36:18 +00:00
|
|
|
|
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (filter->priv->zero_ref_count >= 0);
|
2011-09-17 04:08:40 +00:00
|
|
|
|
if (filter->priv->zero_ref_count > 0)
|
|
|
|
|
g_assert (filter->priv->root != NULL);
|
2011-09-07 07:36:18 +00:00
|
|
|
|
#endif
|
2011-06-26 20:04:05 +00:00
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
2011-09-07 07:36:18 +00:00
|
|
|
|
|
|
|
|
|
#ifdef MODEL_FILTER_DEBUG
|
|
|
|
|
g_assert (elt->ref_count >= elt->ext_ref_count);
|
|
|
|
|
g_assert (elt->ref_count >= 0);
|
|
|
|
|
g_assert (elt->ext_ref_count >= 0);
|
|
|
|
|
#endif
|
2003-07-11 12:51:24 +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
|
|
|
|
/* TreeDragSource interface implementation */
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_row_draggable (GtkTreeDragSource *drag_source,
|
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *tree_model_filter = (GtkTreeModelFilter *)drag_source;
|
|
|
|
|
GtkTreePath *child_path;
|
|
|
|
|
gboolean draggable;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (drag_source), FALSE);
|
|
|
|
|
g_return_val_if_fail (path != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, path);
|
|
|
|
|
draggable = gtk_tree_drag_source_row_draggable (GTK_TREE_DRAG_SOURCE (tree_model_filter->priv->child_model), child_path);
|
|
|
|
|
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_filter_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
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *tree_model_filter = (GtkTreeModelFilter *)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
|
|
|
|
|
2020-02-18 00:41:42 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (drag_source), NULL);
|
|
|
|
|
g_return_val_if_fail (path != NULL, NULL);
|
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
|
|
|
|
|
|
|
|
|
child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, path);
|
2020-02-18 00:41:42 +00:00
|
|
|
|
gotten = gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (tree_model_filter->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_filter_drag_data_delete (GtkTreeDragSource *drag_source,
|
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeModelFilter *tree_model_filter = (GtkTreeModelFilter *)drag_source;
|
|
|
|
|
GtkTreePath *child_path;
|
|
|
|
|
gboolean deleted;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (drag_source), FALSE);
|
|
|
|
|
g_return_val_if_fail (path != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
child_path = gtk_tree_model_filter_convert_path_to_child_path (tree_model_filter, path);
|
|
|
|
|
deleted = gtk_tree_drag_source_drag_data_delete (GTK_TREE_DRAG_SOURCE (tree_model_filter->priv->child_model), child_path);
|
|
|
|
|
gtk_tree_path_free (child_path);
|
|
|
|
|
|
|
|
|
|
return deleted;
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* bits and pieces */
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_set_model (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModel *child_model)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
|
|
|
|
|
if (filter->priv->child_model)
|
|
|
|
|
{
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_handler_disconnect (filter->priv->child_model,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->changed_id);
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_handler_disconnect (filter->priv->child_model,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->inserted_id);
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_handler_disconnect (filter->priv->child_model,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->has_child_toggled_id);
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_handler_disconnect (filter->priv->child_model,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->deleted_id);
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_signal_handler_disconnect (filter->priv->child_model,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->reordered_id);
|
|
|
|
|
|
|
|
|
|
/* reset our state */
|
|
|
|
|
if (filter->priv->root)
|
2011-09-07 20:06:40 +00:00
|
|
|
|
gtk_tree_model_filter_free_level (filter, filter->priv->root,
|
2011-09-11 14:53:27 +00:00
|
|
|
|
TRUE, TRUE, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
filter->priv->root = NULL;
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_object_unref (filter->priv->child_model);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->visible_column = -1;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
/* FIXME: do we need to destroy more here? */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
filter->priv->child_model = child_model;
|
|
|
|
|
|
|
|
|
|
if (child_model)
|
|
|
|
|
{
|
2004-11-19 23:18:38 +00:00
|
|
|
|
g_object_ref (filter->priv->child_model);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
filter->priv->changed_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
|
g_signal_connect (child_model, "row-changed",
|
2003-07-11 12:51:24 +00:00
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_changed),
|
|
|
|
|
filter);
|
|
|
|
|
filter->priv->inserted_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
|
g_signal_connect (child_model, "row-inserted",
|
2003-07-11 12:51:24 +00:00
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_inserted),
|
|
|
|
|
filter);
|
|
|
|
|
filter->priv->has_child_toggled_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
|
g_signal_connect (child_model, "row-has-child-toggled",
|
2003-07-11 12:51:24 +00:00
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_has_child_toggled),
|
|
|
|
|
filter);
|
|
|
|
|
filter->priv->deleted_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
|
g_signal_connect (child_model, "row-deleted",
|
2003-07-11 12:51:24 +00:00
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_deleted),
|
|
|
|
|
filter);
|
|
|
|
|
filter->priv->reordered_id =
|
2008-08-08 14:23:32 +00:00
|
|
|
|
g_signal_connect (child_model, "rows-reordered",
|
2003-07-11 12:51:24 +00:00
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_rows_reordered),
|
|
|
|
|
filter);
|
|
|
|
|
|
|
|
|
|
filter->priv->child_flags = gtk_tree_model_get_flags (child_model);
|
|
|
|
|
filter->priv->stamp = g_random_int ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_ref_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *path)
|
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
GtkTreePath *p;
|
|
|
|
|
|
|
|
|
|
len = gtk_tree_path_get_depth (path);
|
|
|
|
|
p = gtk_tree_path_copy (path);
|
|
|
|
|
while (len--)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (filter->priv->child_model), &iter, p);
|
|
|
|
|
gtk_tree_model_ref_node (GTK_TREE_MODEL (filter->priv->child_model), &iter);
|
|
|
|
|
gtk_tree_path_up (p);
|
|
|
|
|
}
|
2006-02-08 15:20:43 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (p);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_unref_path (GtkTreeModelFilter *filter,
|
2011-05-09 08:29:37 +00:00
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
int depth)
|
2005-10-25 21:00:40 +00:00
|
|
|
|
{
|
|
|
|
|
int len;
|
|
|
|
|
GtkTreePath *p;
|
|
|
|
|
|
2011-05-09 08:29:37 +00:00
|
|
|
|
if (depth != -1)
|
|
|
|
|
len = depth;
|
|
|
|
|
else
|
|
|
|
|
len = gtk_tree_path_get_depth (path);
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
p = gtk_tree_path_copy (path);
|
|
|
|
|
while (len--)
|
|
|
|
|
{
|
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (filter->priv->child_model), &iter, p);
|
|
|
|
|
gtk_tree_model_unref_node (GTK_TREE_MODEL (filter->priv->child_model), &iter);
|
|
|
|
|
gtk_tree_path_up (p);
|
|
|
|
|
}
|
2006-02-08 15:20:43 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (p);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static void
|
|
|
|
|
gtk_tree_model_filter_set_root (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *root)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
|
2012-07-16 01:14:33 +00:00
|
|
|
|
if (root)
|
|
|
|
|
{
|
|
|
|
|
filter->priv->virtual_root = gtk_tree_path_copy (root);
|
|
|
|
|
gtk_tree_model_filter_ref_path (filter, filter->priv->virtual_root);
|
|
|
|
|
filter->priv->virtual_root_deleted = FALSE;
|
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
else
|
2012-07-16 01:14:33 +00:00
|
|
|
|
filter->priv->virtual_root = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* public API */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_new:
|
|
|
|
|
* @child_model: A #GtkTreeModel.
|
2009-12-10 10:23:40 +00:00
|
|
|
|
* @root: (allow-none): A #GtkTreePath or %NULL.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
|
|
|
|
* Creates a new #GtkTreeModel, with @child_model as the child_model
|
|
|
|
|
* and @root as the virtual root.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer full): A new #GtkTreeModel.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkTreeModel *
|
|
|
|
|
gtk_tree_model_filter_new (GtkTreeModel *child_model,
|
|
|
|
|
GtkTreePath *root)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL (child_model), NULL);
|
|
|
|
|
|
2012-07-16 01:14:33 +00:00
|
|
|
|
return g_object_new (GTK_TYPE_TREE_MODEL_FILTER,
|
|
|
|
|
"child-model", child_model,
|
|
|
|
|
"virtual-root", root,
|
|
|
|
|
NULL);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_get_model:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
|
*
|
|
|
|
|
* Returns a pointer to the child model of @filter.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: (transfer none): A pointer to a #GtkTreeModel.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkTreeModel *
|
|
|
|
|
gtk_tree_model_filter_get_model (GtkTreeModelFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (filter), NULL);
|
|
|
|
|
|
|
|
|
|
return filter->priv->child_model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_set_visible_func:
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* @filter: A #GtkTreeModelFilter
|
|
|
|
|
* @func: A #GtkTreeModelFilterVisibleFunc, the visible function
|
|
|
|
|
* @data: (allow-none): User data to pass to the visible function, or %NULL
|
|
|
|
|
* @destroy: (allow-none): Destroy notifier of @data, or %NULL
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* Sets the visible function used when filtering the @filter to be @func.
|
|
|
|
|
* The function should return %TRUE if the given row should be visible and
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* %FALSE otherwise.
|
2003-09-30 21:14:09 +00:00
|
|
|
|
*
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* If the condition calculated by the function changes over time (e.g.
|
|
|
|
|
* because it depends on some global parameters), you must call
|
|
|
|
|
* gtk_tree_model_filter_refilter() to keep the visibility information
|
|
|
|
|
* of the model up-to-date.
|
2005-03-29 06:04:18 +00:00
|
|
|
|
*
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* Note that @func is called whenever a row is inserted, when it may still
|
|
|
|
|
* be empty. The visible function should therefore take special care of empty
|
2008-08-02 04:42:36 +00:00
|
|
|
|
* rows, like in the example below.
|
|
|
|
|
*
|
2014-01-27 19:55:18 +00:00
|
|
|
|
* |[<!-- language="C" -->
|
2008-08-02 04:42:36 +00:00
|
|
|
|
* static gboolean
|
|
|
|
|
* visible_func (GtkTreeModel *model,
|
|
|
|
|
* GtkTreeIter *iter,
|
|
|
|
|
* gpointer data)
|
|
|
|
|
* {
|
2014-02-15 04:34:22 +00:00
|
|
|
|
* // Visible if row is non-empty and first column is “HI”
|
2008-08-02 04:42:36 +00:00
|
|
|
|
* gchar *str;
|
|
|
|
|
* gboolean visible = FALSE;
|
|
|
|
|
*
|
|
|
|
|
* gtk_tree_model_get (model, iter, 0, &str, -1);
|
|
|
|
|
* if (str && strcmp (str, "HI") == 0)
|
|
|
|
|
* visible = TRUE;
|
|
|
|
|
* g_free (str);
|
|
|
|
|
*
|
|
|
|
|
* return visible;
|
|
|
|
|
* }
|
2014-01-27 17:12:55 +00:00
|
|
|
|
* ]|
|
2008-08-02 04:42:36 +00:00
|
|
|
|
*
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* Note that gtk_tree_model_filter_set_visible_func() or
|
|
|
|
|
* gtk_tree_model_filter_set_visible_column() can only be called
|
|
|
|
|
* once for a given filter model.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tree_model_filter_set_visible_func (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeModelFilterVisibleFunc func,
|
|
|
|
|
gpointer data,
|
2008-06-18 09:12:32 +00:00
|
|
|
|
GDestroyNotify destroy)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
g_return_if_fail (filter->priv->visible_method_set == FALSE);
|
|
|
|
|
|
|
|
|
|
filter->priv->visible_func = func;
|
|
|
|
|
filter->priv->visible_data = data;
|
|
|
|
|
filter->priv->visible_destroy = destroy;
|
|
|
|
|
|
|
|
|
|
filter->priv->visible_method_set = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_set_modify_func:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
|
* @n_columns: The number of columns in the filter model.
|
2014-02-09 22:24:06 +00:00
|
|
|
|
* @types: (array length=n_columns): The #GTypes of the columns.
|
2004-02-12 01:52:26 +00:00
|
|
|
|
* @func: A #GtkTreeModelFilterModifyFunc
|
2010-02-19 16:53:17 +00:00
|
|
|
|
* @data: (allow-none): User data to pass to the modify function, or %NULL.
|
|
|
|
|
* @destroy: (allow-none): Destroy notifier of @data, or %NULL.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
2004-03-05 22:54:14 +00:00
|
|
|
|
* With the @n_columns and @types parameters, you give an array of column
|
|
|
|
|
* types for this model (which will be exposed to the parent model/view).
|
|
|
|
|
* The @func, @data and @destroy parameters are for specifying the modify
|
2014-01-28 06:54:48 +00:00
|
|
|
|
* function. The modify function will get called for each
|
2004-03-05 22:54:14 +00:00
|
|
|
|
* data access, the goal of the modify function is to return the data which
|
|
|
|
|
* should be displayed at the location specified using the parameters of the
|
|
|
|
|
* modify function.
|
2003-09-30 21:14:09 +00:00
|
|
|
|
*
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* Note that gtk_tree_model_filter_set_modify_func()
|
|
|
|
|
* can only be called once for a given filter model.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tree_model_filter_set_modify_func (GtkTreeModelFilter *filter,
|
|
|
|
|
gint n_columns,
|
|
|
|
|
GType *types,
|
|
|
|
|
GtkTreeModelFilterModifyFunc func,
|
|
|
|
|
gpointer data,
|
2008-06-18 09:12:32 +00:00
|
|
|
|
GDestroyNotify destroy)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
g_return_if_fail (func != NULL);
|
|
|
|
|
g_return_if_fail (filter->priv->modify_func_set == FALSE);
|
|
|
|
|
|
|
|
|
|
filter->priv->modify_n_columns = n_columns;
|
|
|
|
|
filter->priv->modify_types = g_new0 (GType, n_columns);
|
|
|
|
|
memcpy (filter->priv->modify_types, types, sizeof (GType) * n_columns);
|
|
|
|
|
filter->priv->modify_func = func;
|
|
|
|
|
filter->priv->modify_data = data;
|
|
|
|
|
filter->priv->modify_destroy = destroy;
|
|
|
|
|
|
|
|
|
|
filter->priv->modify_func_set = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_set_visible_column:
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* @filter: A #GtkTreeModelFilter
|
|
|
|
|
* @column: A #gint which is the column containing the visible information
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
|
|
|
|
* Sets @column of the child_model to be the column where @filter should
|
|
|
|
|
* look for visibility information. @columns should be a column of type
|
|
|
|
|
* %G_TYPE_BOOLEAN, where %TRUE means that a row is visible, and %FALSE
|
|
|
|
|
* if not.
|
2003-09-30 21:14:09 +00:00
|
|
|
|
*
|
2014-08-30 05:59:05 +00:00
|
|
|
|
* Note that gtk_tree_model_filter_set_visible_func() or
|
|
|
|
|
* gtk_tree_model_filter_set_visible_column() can only be called
|
|
|
|
|
* once for a given filter model.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tree_model_filter_set_visible_column (GtkTreeModelFilter *filter,
|
|
|
|
|
gint column)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
g_return_if_fail (column >= 0);
|
|
|
|
|
g_return_if_fail (filter->priv->visible_method_set == FALSE);
|
|
|
|
|
|
|
|
|
|
filter->priv->visible_column = column;
|
|
|
|
|
|
|
|
|
|
filter->priv->visible_method_set = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* conversion */
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_convert_child_iter_to_iter:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
2010-07-07 16:20:37 +00:00
|
|
|
|
* @filter_iter: (out): An uninitialized #GtkTreeIter.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* @child_iter: A valid #GtkTreeIter pointing to a row on the child model.
|
|
|
|
|
*
|
|
|
|
|
* Sets @filter_iter to point to the row in @filter that corresponds to the
|
2006-06-12 14:48:43 +00:00
|
|
|
|
* row pointed at by @child_iter. If @filter_iter was not set, %FALSE is
|
|
|
|
|
* returned.
|
|
|
|
|
*
|
2014-02-19 23:49:43 +00:00
|
|
|
|
* Returns: %TRUE, if @filter_iter was set, i.e. if @child_iter is a
|
2006-06-12 14:48:43 +00:00
|
|
|
|
* valid iterator pointing to a visible row in child model.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
2006-06-12 14:48:43 +00:00
|
|
|
|
gboolean
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_model_filter_convert_child_iter_to_iter (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeIter *filter_iter,
|
|
|
|
|
GtkTreeIter *child_iter)
|
|
|
|
|
{
|
2006-06-12 14:48:43 +00:00
|
|
|
|
gboolean ret;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
GtkTreePath *child_path, *path;
|
|
|
|
|
|
2006-06-12 14:48:43 +00:00
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (filter), FALSE);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail (filter_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 (filter_iter != child_iter, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
filter_iter->stamp = 0;
|
|
|
|
|
|
|
|
|
|
child_path = gtk_tree_model_get_path (filter->priv->child_model, child_iter);
|
2006-06-12 14:48:43 +00:00
|
|
|
|
g_return_val_if_fail (child_path != NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
path = gtk_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
|
child_path);
|
|
|
|
|
gtk_tree_path_free (child_path);
|
|
|
|
|
|
2006-06-12 14:48:43 +00:00
|
|
|
|
if (!path)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
ret = gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), filter_iter, path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
2006-06-12 14:48:43 +00:00
|
|
|
|
|
|
|
|
|
return ret;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_convert_iter_to_child_iter:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
2010-07-07 16:20:37 +00:00
|
|
|
|
* @child_iter: (out): An uninitialized #GtkTreeIter.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* @filter_iter: A valid #GtkTreeIter pointing to a row on @filter.
|
|
|
|
|
*
|
|
|
|
|
* Sets @child_iter to point to the row pointed to by @filter_iter.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreeIter *child_iter,
|
|
|
|
|
GtkTreeIter *filter_iter)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
g_return_if_fail (filter->priv->child_model != NULL);
|
|
|
|
|
g_return_if_fail (child_iter != NULL);
|
|
|
|
|
g_return_if_fail (filter_iter != NULL);
|
|
|
|
|
g_return_if_fail (filter_iter->stamp == filter->priv->stamp);
|
2009-07-30 12:35:09 +00:00
|
|
|
|
g_return_if_fail (filter_iter != child_iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
|
{
|
|
|
|
|
*child_iter = FILTER_ELT (filter_iter->user_data2)->iter;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *path;
|
2011-05-09 08:04:24 +00:00
|
|
|
|
gboolean valid = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
path = gtk_tree_model_filter_elt_get_path (filter_iter->user_data,
|
|
|
|
|
filter_iter->user_data2,
|
2003-09-08 19:51:16 +00:00
|
|
|
|
filter->priv->virtual_root);
|
2011-05-09 08:04:24 +00:00
|
|
|
|
valid = gtk_tree_model_get_iter (filter->priv->child_model, child_iter,
|
|
|
|
|
path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_path_free (path);
|
2011-05-09 08:04:24 +00:00
|
|
|
|
|
|
|
|
|
g_return_if_fail (valid == TRUE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* The path returned can only be used internally in the filter model. */
|
2003-07-11 12:51:24 +00:00
|
|
|
|
static GtkTreePath *
|
|
|
|
|
gtk_real_tree_model_filter_convert_child_path_to_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *child_path,
|
|
|
|
|
gboolean build_levels,
|
2004-08-04 05:38:58 +00:00
|
|
|
|
gboolean fetch_children)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
gint *child_indices;
|
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
GtkTreePath *real_path;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
FilterElt *tmp;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (filter), NULL);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (child_path != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
if (!filter->priv->virtual_root)
|
|
|
|
|
real_path = gtk_tree_path_copy (child_path);
|
|
|
|
|
else
|
|
|
|
|
real_path = gtk_tree_model_filter_remove_root (child_path,
|
|
|
|
|
filter->priv->virtual_root);
|
|
|
|
|
|
|
|
|
|
if (!real_path)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
retval = gtk_tree_path_new ();
|
2010-06-28 18:15:10 +00:00
|
|
|
|
child_indices = gtk_tree_path_get_indices (real_path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
|
|
if (filter->priv->root == NULL && build_levels)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (real_path); i++)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gboolean found_child = FALSE;
|
|
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
tmp = lookup_elt_with_offset (level->seq, child_indices[i], &siter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (tmp)
|
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
gtk_tree_path_append_index (retval, g_sequence_iter_get_position (siter));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!tmp->children && build_levels)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, tmp, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
level = tmp->children;
|
|
|
|
|
found_child = TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-04 05:38:58 +00:00
|
|
|
|
if (!found_child && fetch_children)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
2011-08-07 15:11:13 +00:00
|
|
|
|
int j;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
tmp = gtk_tree_model_filter_fetch_child (filter, level,
|
|
|
|
|
child_indices[i],
|
|
|
|
|
&j);
|
|
|
|
|
|
|
|
|
|
/* didn't find the child, let's try to bring it back */
|
|
|
|
|
if (!tmp || tmp->offset != child_indices[i])
|
|
|
|
|
{
|
|
|
|
|
/* not there */
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_append_index (retval, j);
|
|
|
|
|
if (!tmp->children && build_levels)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, tmp, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
level = tmp->children;
|
|
|
|
|
found_child = TRUE;
|
|
|
|
|
}
|
2004-08-04 05:38:58 +00:00
|
|
|
|
else if (!found_child && !fetch_children)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
/* no path */
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_convert_child_path_to_path:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
|
* @child_path: A #GtkTreePath to convert.
|
|
|
|
|
*
|
|
|
|
|
* Converts @child_path to a path relative to @filter. That is, @child_path
|
|
|
|
|
* points to a path in the child model. The rerturned path will point to the
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* same row in the filtered model. If @child_path isn’t a valid path on the
|
2006-06-12 14:48:43 +00:00
|
|
|
|
* child model or points to a row which is not visible in @filter, then %NULL
|
|
|
|
|
* is returned.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): A newly allocated #GtkTreePath, or %NULL.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkTreePath *
|
|
|
|
|
gtk_tree_model_filter_convert_child_path_to_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *child_path)
|
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
|
/* this function does the sanity checks */
|
2005-10-25 21:00:40 +00:00
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
2003-07-11 12:51:24 +00:00
|
|
|
|
child_path,
|
|
|
|
|
TRUE,
|
|
|
|
|
TRUE);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
2006-06-12 14:48:43 +00:00
|
|
|
|
if (!path)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
/* get a new path which only takes visible nodes into account.
|
|
|
|
|
* -- if this gives any performance issues, we can write a special
|
|
|
|
|
* version of convert_child_path_to_path immediately returning
|
|
|
|
|
* a visible-nodes-only path.
|
|
|
|
|
*/
|
2006-06-02 18:39:25 +00:00
|
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (filter), &iter, path);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
|
|
|
|
|
|
return path;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_convert_path_to_child_path:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
|
* @filter_path: A #GtkTreePath to convert.
|
|
|
|
|
*
|
|
|
|
|
* Converts @filter_path to a path on the child model of @filter. That is,
|
|
|
|
|
* @filter_path points to a location in @filter. The returned path will
|
|
|
|
|
* point to the same location in the model not being filtered. If @filter_path
|
|
|
|
|
* does not point to a location in the child model, %NULL is returned.
|
|
|
|
|
*
|
2015-12-28 20:14:08 +00:00
|
|
|
|
* Returns: (nullable) (transfer full): A newly allocated #GtkTreePath, or %NULL.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
GtkTreePath *
|
|
|
|
|
gtk_tree_model_filter_convert_path_to_child_path (GtkTreeModelFilter *filter,
|
|
|
|
|
GtkTreePath *filter_path)
|
|
|
|
|
{
|
|
|
|
|
gint *filter_indices;
|
|
|
|
|
GtkTreePath *retval;
|
|
|
|
|
FilterLevel *level;
|
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (filter), NULL);
|
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail (filter_path != NULL, NULL);
|
|
|
|
|
|
|
|
|
|
/* convert path */
|
|
|
|
|
retval = gtk_tree_path_new ();
|
2010-06-28 18:15:10 +00:00
|
|
|
|
filter_indices = gtk_tree_path_get_indices (filter_path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
if (!filter->priv->root)
|
2011-08-05 15:40:04 +00:00
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (filter_path); i++)
|
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
|
FilterElt *elt;
|
2011-08-07 15:11:13 +00:00
|
|
|
|
GSequenceIter *siter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
if (!level)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
siter = g_sequence_get_iter_at_pos (level->visible_seq, filter_indices[i]);
|
|
|
|
|
if (g_sequence_iter_is_end (siter))
|
2003-07-11 12:51:24 +00:00
|
|
|
|
{
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-07 15:11:13 +00:00
|
|
|
|
elt = GET_ELT (siter);
|
|
|
|
|
if (elt->children == NULL)
|
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
gtk_tree_path_append_index (retval, elt->offset);
|
|
|
|
|
level = elt->children;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* apply vroot */
|
|
|
|
|
|
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
|
{
|
|
|
|
|
GtkTreePath *real_retval;
|
|
|
|
|
|
|
|
|
|
real_retval = gtk_tree_model_filter_add_root (retval,
|
|
|
|
|
filter->priv->virtual_root);
|
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
|
|
|
|
|
|
return real_retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
gtk_tree_model_filter_refilter_helper (GtkTreeModel *model,
|
|
|
|
|
GtkTreePath *path,
|
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
/* evil, don't try this at home, but certainly speeds things up */
|
|
|
|
|
gtk_tree_model_filter_row_changed (model, path, iter, data);
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_refilter:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
|
*
|
|
|
|
|
* Emits ::row_changed for each row in the child model, which causes
|
|
|
|
|
* the filter to re-evaluate whether a row is visible or not.
|
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tree_model_filter_refilter (GtkTreeModelFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
|
|
|
|
|
/* S L O W */
|
|
|
|
|
gtk_tree_model_foreach (filter->priv->child_model,
|
|
|
|
|
gtk_tree_model_filter_refilter_helper,
|
|
|
|
|
filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* gtk_tree_model_filter_clear_cache:
|
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
|
*
|
|
|
|
|
* This function should almost never be called. It clears the @filter
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* of any cached iterators that haven’t been reffed with
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* gtk_tree_model_ref_node(). This might be useful if the child model
|
2014-02-07 18:32:47 +00:00
|
|
|
|
* being filtered is static (and doesn’t change often) and there has been
|
2003-07-11 12:51:24 +00:00
|
|
|
|
* a lot of unreffed access to nodes. As a side effect of this function,
|
2006-02-08 15:20:43 +00:00
|
|
|
|
* all unreffed iters will be invalid.
|
2003-07-11 12:51:24 +00:00
|
|
|
|
*/
|
|
|
|
|
void
|
|
|
|
|
gtk_tree_model_filter_clear_cache (GtkTreeModelFilter *filter)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
|
if (filter->priv->zero_ref_count > 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
|
gtk_tree_model_filter_clear_cache_helper (filter,
|
|
|
|
|
FILTER_LEVEL (filter->priv->root));
|
|
|
|
|
}
|