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
|
|
|
|
* License along with this library; if not, write to the
|
2003-07-11 12:51:24 +00:00
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2004-03-06 03:38:59 +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-20 07:01:23 +00:00
|
|
|
#include "gtkalias.h"
|
2005-03-22 02:14:55 +00:00
|
|
|
#include "gtkprivate.h"
|
2003-07-11 12:51:24 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/* ITER FORMAT:
|
|
|
|
*
|
|
|
|
* iter->stamp = filter->priv->stamp
|
|
|
|
* iter->user_data = FilterLevel
|
|
|
|
* iter->user_data2 = FilterElt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* all paths, iters, etc prefixed with c_ are paths, iters, etc relative to the
|
|
|
|
* child model.
|
|
|
|
*/
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* A few notes:
|
|
|
|
* There are three model/views involved, so there are two mappings:
|
|
|
|
* * this model -> child model: mapped via offset in FilterElt.
|
|
|
|
* * this model -> parent model (or view): mapped via the array index
|
|
|
|
* of FilterElt.
|
|
|
|
*
|
|
|
|
* Note that there are two kinds of paths relative to the filter model
|
|
|
|
* (those generated from the array indices): paths taking non-visible
|
|
|
|
* nodes into account, and paths which don't. Paths which take
|
|
|
|
* non-visible nodes into account should only be used internally and
|
|
|
|
* NEVER be passed along with a signal emission.
|
|
|
|
*
|
|
|
|
* The filter model has a reference on every node that is not in the root
|
|
|
|
* level and has a parent with ref_count > 1. Exception is a virtual root
|
|
|
|
* level; all nodes in the virtual root level are referenced too.
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
gint zero_ref_count;
|
|
|
|
gboolean visible;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _FilterLevel
|
|
|
|
{
|
|
|
|
GArray *array;
|
|
|
|
gint ref_count;
|
2005-10-25 21:00:40 +00:00
|
|
|
gint visible_nodes;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
FilterElt *parent_elt;
|
|
|
|
FilterLevel *parent_level;
|
|
|
|
};
|
|
|
|
|
2003-10-11 23:12:20 +00:00
|
|
|
#define GTK_TREE_MODEL_FILTER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_TREE_MODEL_FILTER, GtkTreeModelFilterPrivate))
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
struct _GtkTreeModelFilterPrivate
|
|
|
|
{
|
|
|
|
gpointer root;
|
|
|
|
gint stamp;
|
|
|
|
guint child_flags;
|
|
|
|
GtkTreeModel *child_model;
|
|
|
|
gint zero_ref_count;
|
|
|
|
|
|
|
|
GtkTreePath *virtual_root;
|
|
|
|
|
|
|
|
GtkTreeModelFilterVisibleFunc visible_func;
|
|
|
|
gpointer visible_data;
|
|
|
|
GtkDestroyNotify visible_destroy;
|
|
|
|
|
|
|
|
gint modify_n_columns;
|
|
|
|
GType *modify_types;
|
|
|
|
GtkTreeModelFilterModifyFunc modify_func;
|
|
|
|
gpointer modify_data;
|
|
|
|
gpointer modify_destroy;
|
|
|
|
|
|
|
|
gint visible_column;
|
|
|
|
|
|
|
|
gboolean visible_method_set;
|
|
|
|
gboolean modify_func_set;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gboolean in_row_deleted;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
/* signal ids */
|
|
|
|
guint changed_id;
|
|
|
|
guint inserted_id;
|
|
|
|
guint has_child_toggled_id;
|
|
|
|
guint deleted_id;
|
|
|
|
guint reordered_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* properties */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
|
|
|
PROP_CHILD_MODEL,
|
|
|
|
PROP_VIRTUAL_ROOT
|
|
|
|
};
|
|
|
|
|
|
|
|
#define GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS(filter) \
|
|
|
|
(((GtkTreeModelFilter *)filter)->priv->child_flags & GTK_TREE_MODEL_ITERS_PERSIST)
|
|
|
|
|
|
|
|
#define FILTER_ELT(filter_elt) ((FilterElt *)filter_elt)
|
|
|
|
#define FILTER_LEVEL(filter_level) ((FilterLevel *)filter_level)
|
|
|
|
|
|
|
|
/* general code (object/interface init, properties, etc) */
|
|
|
|
static void gtk_tree_model_filter_init (GtkTreeModelFilter *filter);
|
|
|
|
static void gtk_tree_model_filter_class_init (GtkTreeModelFilterClass *filter_class);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
static gboolean gtk_tree_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkSelectionData *selection_data);
|
|
|
|
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,
|
2005-10-25 21:00:40 +00:00
|
|
|
FilterElt *parent_elt,
|
|
|
|
gboolean emit_inserted);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
static void gtk_tree_model_filter_free_level (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *filter_level);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
static void gtk_tree_model_filter_real_unref_node (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
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,
|
|
|
|
GtkTreePath *path);
|
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
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
static FilterElt *gtk_tree_model_filter_get_nth (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *level,
|
|
|
|
int n);
|
|
|
|
static FilterElt *gtk_tree_model_filter_get_nth_visible (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *level,
|
|
|
|
int n);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
static FilterElt *gtk_tree_model_filter_fetch_child (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *level,
|
|
|
|
gint offset,
|
|
|
|
gint *index);
|
|
|
|
static void gtk_tree_model_filter_remove_node (GtkTreeModelFilter *filter,
|
2005-10-25 21:00:40 +00:00
|
|
|
GtkTreeIter *iter);
|
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);
|
|
|
|
static FilterElt *bsearch_elt_with_offset (GArray *array,
|
|
|
|
gint offset,
|
|
|
|
gint *index);
|
|
|
|
|
|
|
|
|
|
|
|
static GObjectClass *parent_class = NULL;
|
|
|
|
|
|
|
|
GType
|
|
|
|
gtk_tree_model_filter_get_type (void)
|
|
|
|
{
|
|
|
|
static GType tree_model_filter_type = 0;
|
|
|
|
|
|
|
|
if (!tree_model_filter_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo tree_model_filter_info =
|
|
|
|
{
|
|
|
|
sizeof (GtkTreeModelFilterClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gtk_tree_model_filter_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GtkTreeModelFilter),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gtk_tree_model_filter_init
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GInterfaceInfo tree_model_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_model_filter_tree_model_init,
|
|
|
|
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
|
|
|
static const GInterfaceInfo drag_source_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_model_filter_drag_source_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
tree_model_filter_type = g_type_register_static (G_TYPE_OBJECT,
|
2005-09-01 05:11:46 +00:00
|
|
|
I_("GtkTreeModelFilter"),
|
2003-07-11 12:51:24 +00:00
|
|
|
&tree_model_filter_info, 0);
|
|
|
|
|
|
|
|
g_type_add_interface_static (tree_model_filter_type,
|
|
|
|
GTK_TYPE_TREE_MODEL,
|
|
|
|
&tree_model_info);
|
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
|
|
|
|
|
|
|
g_type_add_interface_static (tree_model_filter_type,
|
|
|
|
GTK_TYPE_TREE_DRAG_SOURCE,
|
|
|
|
&drag_source_info);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tree_model_filter_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_init (GtkTreeModelFilter *filter)
|
|
|
|
{
|
|
|
|
filter->priv = GTK_TREE_MODEL_FILTER_GET_PRIVATE (filter);
|
|
|
|
|
|
|
|
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;
|
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;
|
|
|
|
parent_class = g_type_class_peek_parent (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;
|
|
|
|
|
|
|
|
/* Properties -- FIXME: disabled translations for now, until I can come up with a
|
|
|
|
* better description
|
|
|
|
*/
|
|
|
|
g_object_class_install_property (object_class,
|
|
|
|
PROP_CHILD_MODEL,
|
2005-03-09 06:15:13 +00:00
|
|
|
g_param_spec_object ("child-model",
|
2003-07-11 12:51:24 +00:00
|
|
|
("The child model"),
|
|
|
|
("The model for the filtermodel to filter"),
|
|
|
|
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",
|
2003-07-11 12:51:24 +00:00
|
|
|
("The virtual root"),
|
|
|
|
("The virtual root (relative to the child model) for this filtermodel"),
|
|
|
|
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
|
|
|
|
|
|
|
g_type_class_add_private (object_class, sizeof (GtkTreeModelFilterPrivate));
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
gtk_tree_model_filter_unref_path (filter, filter->priv->virtual_root);
|
|
|
|
|
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)
|
|
|
|
gtk_tree_model_filter_free_level (filter, filter->priv->root);
|
|
|
|
|
|
|
|
if (filter->priv->modify_types)
|
|
|
|
g_free (filter->priv->modify_types);
|
|
|
|
|
|
|
|
/* must chain up */
|
|
|
|
parent_class->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_build_level (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *parent_level,
|
2005-10-25 21:00:40 +00:00
|
|
|
FilterElt *parent_elt,
|
|
|
|
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;
|
|
|
|
gint length = 0;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_assert (filter->priv->child_model != 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_return_if_fail (length > 0);
|
|
|
|
|
|
|
|
new_level = g_new (FilterLevel, 1);
|
|
|
|
new_level->array = g_array_sized_new (FALSE, FALSE,
|
|
|
|
sizeof (FilterElt),
|
|
|
|
length);
|
|
|
|
new_level->ref_count = 0;
|
2005-10-25 21:00:40 +00:00
|
|
|
new_level->visible_nodes = 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
new_level->parent_elt = parent_elt;
|
|
|
|
new_level->parent_level = parent_level;
|
|
|
|
|
|
|
|
if (parent_elt)
|
|
|
|
parent_elt->children = new_level;
|
|
|
|
else
|
|
|
|
filter->priv->root = new_level;
|
|
|
|
|
|
|
|
/* increase the count of zero ref_counts */
|
|
|
|
while (parent_level)
|
|
|
|
{
|
|
|
|
parent_elt->zero_ref_count++;
|
|
|
|
|
|
|
|
parent_elt = parent_level->parent_elt;
|
|
|
|
parent_level = parent_level->parent_level;
|
|
|
|
}
|
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))
|
|
|
|
{
|
|
|
|
FilterElt filter_elt;
|
|
|
|
|
|
|
|
filter_elt.offset = i;
|
|
|
|
filter_elt.zero_ref_count = 0;
|
|
|
|
filter_elt.ref_count = 0;
|
|
|
|
filter_elt.children = NULL;
|
|
|
|
filter_elt.visible = TRUE;
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
filter_elt.iter = iter;
|
|
|
|
|
|
|
|
g_array_append_val (new_level->array, filter_elt);
|
2005-10-25 21:00:40 +00:00
|
|
|
new_level->visible_nodes++;
|
|
|
|
|
|
|
|
if (new_level->parent_level || filter->priv->virtual_root)
|
|
|
|
{
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
f_iter.user_data = new_level;
|
|
|
|
f_iter.user_data2 = &(g_array_index (new_level->array, FilterElt, new_level->array->len - 1));
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &f_iter);
|
|
|
|
|
|
|
|
if (emit_inserted)
|
|
|
|
{
|
|
|
|
GtkTreePath *f_path;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
|
|
|
if (new_level->array->len == 0
|
|
|
|
&& (new_level != filter->priv->root || filter->priv->virtual_root))
|
|
|
|
{
|
|
|
|
/* If none of the nodes are visible, we will just pull in the
|
|
|
|
* first node of the level and keep a reference on it. We need this
|
|
|
|
* to make sure that we get all signals for this level.
|
|
|
|
*/
|
|
|
|
FilterElt filter_elt;
|
2005-10-28 14:16:45 +00:00
|
|
|
GtkTreeIter f_iter;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
filter_elt.offset = 0;
|
|
|
|
filter_elt.zero_ref_count = 0;
|
|
|
|
filter_elt.ref_count = 0;
|
|
|
|
filter_elt.children = NULL;
|
|
|
|
filter_elt.visible = FALSE;
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
filter_elt.iter = first_node;
|
|
|
|
|
|
|
|
g_array_append_val (new_level->array, filter_elt);
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
f_iter.user_data = new_level;
|
|
|
|
f_iter.user_data2 = &(g_array_index (new_level->array, FilterElt, new_level->array->len - 1));
|
|
|
|
|
|
|
|
gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &f_iter);
|
|
|
|
}
|
|
|
|
else if (new_level->array->len == 0)
|
|
|
|
gtk_tree_model_filter_free_level (filter, new_level);
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_free_level (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *filter_level)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_assert (filter_level);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
for (i = 0; i < filter_level->array->len; i++)
|
|
|
|
{
|
|
|
|
if (g_array_index (filter_level->array, FilterElt, i).children)
|
|
|
|
gtk_tree_model_filter_free_level (filter,
|
|
|
|
FILTER_LEVEL (g_array_index (filter_level->array, FilterElt, i).children));
|
|
|
|
|
|
|
|
if (filter_level->parent_level || filter->priv->virtual_root)
|
|
|
|
{
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
f_iter.user_data = filter_level;
|
|
|
|
f_iter.user_data2 = &(g_array_index (filter_level->array, FilterElt, i));
|
|
|
|
|
|
|
|
gtk_tree_model_filter_unref_node (GTK_TREE_MODEL (filter), &f_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
if (filter_level->ref_count == 0)
|
|
|
|
{
|
|
|
|
FilterLevel *parent_level = filter_level->parent_level;
|
|
|
|
FilterElt *parent_elt = filter_level->parent_elt;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (parent_elt)
|
|
|
|
parent_elt->zero_ref_count--;
|
|
|
|
|
|
|
|
if (parent_level)
|
|
|
|
{
|
|
|
|
parent_elt = parent_level->parent_elt;
|
|
|
|
parent_level = parent_level->parent_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (parent_level);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (filter_level->parent_elt)
|
|
|
|
filter_level->parent_elt->children = NULL;
|
|
|
|
else
|
|
|
|
filter->priv->root = NULL;
|
|
|
|
|
|
|
|
g_array_free (filter_level->array, TRUE);
|
|
|
|
filter_level->array = NULL;
|
|
|
|
|
|
|
|
g_free (filter_level);
|
|
|
|
filter_level = NULL;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
walker2 = walker->parent_elt;
|
|
|
|
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++)
|
|
|
|
gtk_tree_path_append_index (retval, gtk_tree_path_get_indices (src)[i]);
|
|
|
|
|
|
|
|
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);
|
|
|
|
indices = gtk_tree_path_get_indices (src);
|
|
|
|
|
|
|
|
for (i = 0; i < gtk_tree_path_get_depth (root); i++)
|
|
|
|
if (indices[i] != gtk_tree_path_get_indices (root)[i])
|
|
|
|
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
|
|
|
|
gtk_tree_model_filter_visible (GtkTreeModelFilter *filter,
|
|
|
|
GtkTreeIter *child_iter)
|
|
|
|
{
|
|
|
|
if (filter->priv->visible_func)
|
|
|
|
{
|
2005-08-24 04:15:28 +00:00
|
|
|
return filter->priv->visible_func (filter->priv->child_model,
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
GValue val = {0, };
|
|
|
|
|
|
|
|
gtk_tree_model_get_value (filter->priv->child_model, child_iter,
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_clear_cache_helper (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *level)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_assert (level);
|
|
|
|
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
if (g_array_index (level->array, FilterElt, i).zero_ref_count > 0)
|
|
|
|
gtk_tree_model_filter_clear_cache_helper (filter, g_array_index (level->array, FilterElt, i).children);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level->ref_count == 0 && level != filter->priv->root)
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_free_level (filter, level);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
static FilterElt *
|
|
|
|
gtk_tree_model_filter_get_nth (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *level,
|
|
|
|
int n)
|
|
|
|
{
|
|
|
|
if (level->array->len <= n)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &g_array_index (level->array, FilterElt, n);
|
|
|
|
}
|
|
|
|
|
|
|
|
static FilterElt *
|
|
|
|
gtk_tree_model_filter_get_nth_visible (GtkTreeModelFilter *filter,
|
|
|
|
FilterLevel *level,
|
|
|
|
int n)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
if (level->visible_nodes <= n)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
elt = FILTER_ELT (level->array->data);
|
|
|
|
while (!elt->visible)
|
|
|
|
elt++;
|
|
|
|
|
|
|
|
while (i < n)
|
|
|
|
{
|
|
|
|
if (elt->visible)
|
|
|
|
i++;
|
|
|
|
elt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!elt->visible)
|
|
|
|
elt++;
|
|
|
|
|
|
|
|
return elt;
|
|
|
|
}
|
|
|
|
|
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 i = 0;
|
|
|
|
gint start, middle, end;
|
|
|
|
gint len;
|
|
|
|
GtkTreePath *c_path = NULL;
|
|
|
|
GtkTreeIter c_iter;
|
|
|
|
GtkTreePath *c_parent_path = NULL;
|
|
|
|
GtkTreeIter c_parent_iter;
|
|
|
|
FilterElt elt;
|
|
|
|
|
|
|
|
/* check if child exists and is visible */
|
|
|
|
if (level->parent_elt)
|
|
|
|
{
|
|
|
|
c_parent_path =
|
|
|
|
gtk_tree_model_filter_elt_get_path (level->parent_level,
|
|
|
|
level->parent_elt,
|
|
|
|
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;
|
|
|
|
|
|
|
|
/* add child */
|
|
|
|
elt.offset = offset;
|
|
|
|
elt.zero_ref_count = 0;
|
|
|
|
elt.ref_count = 0;
|
|
|
|
elt.children = NULL;
|
|
|
|
/* visibility should be FALSE as we don't emit row_inserted */
|
|
|
|
elt.visible = FALSE;
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
elt.iter = c_iter;
|
|
|
|
|
|
|
|
/* find index (binary search on offset) */
|
|
|
|
start = 0;
|
|
|
|
end = level->array->len;
|
|
|
|
|
|
|
|
if (start != end)
|
|
|
|
{
|
|
|
|
while (start != end)
|
|
|
|
{
|
|
|
|
middle = (start + end) / 2;
|
|
|
|
|
|
|
|
if (g_array_index (level->array, FilterElt, middle).offset <= offset)
|
|
|
|
start = middle + 1;
|
|
|
|
else
|
|
|
|
end = middle;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_array_index (level->array, FilterElt, middle).offset <= offset)
|
|
|
|
i = middle + 1;
|
|
|
|
else
|
|
|
|
i = middle;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
g_array_insert_val (level->array, i, elt);
|
|
|
|
*index = i;
|
|
|
|
|
2005-06-30 19:07:16 +00:00
|
|
|
if (i > 0)
|
|
|
|
i--;
|
|
|
|
|
|
|
|
for ( ; i < level->array->len; i++)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
FilterElt *e = &(g_array_index (level->array, FilterElt, i));
|
|
|
|
if (e->children)
|
|
|
|
e->children->parent_elt = e;
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
c_iter.stamp = filter->priv->stamp;
|
|
|
|
c_iter.user_data = level;
|
|
|
|
c_iter.user_data2 = &g_array_index (level->array, FilterElt, *index);
|
|
|
|
|
|
|
|
if (level->parent_level || filter->priv->virtual_root)
|
|
|
|
gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &c_iter);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
return &g_array_index (level->array, FilterElt, *index);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_remove_node (GtkTreeModelFilter *filter,
|
2005-10-25 21:00:40 +00:00
|
|
|
GtkTreeIter *iter)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
FilterElt *elt, *parent;
|
|
|
|
FilterLevel *level, *parent_level;
|
2005-10-25 21:00:40 +00:00
|
|
|
gint offset, i, length;
|
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
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter->user_data);
|
|
|
|
elt = FILTER_ELT (iter->user_data2);
|
|
|
|
|
|
|
|
parent = level->parent_elt;
|
|
|
|
parent_level = level->parent_level;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
length = level->array->len;
|
2005-10-25 21:00:40 +00:00
|
|
|
offset = elt->offset;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* we distinguish a couple of cases:
|
|
|
|
* - root level, length > 1: emit row-deleted and remove.
|
|
|
|
* - root level, length == 1: emit row-deleted and keep in cache.
|
|
|
|
* - level, length == 1: parent->ref_count > 1: emit row-deleted and keep.
|
|
|
|
* - level, length > 1: emit row-deleted and remove.
|
|
|
|
* - else, remove level.
|
|
|
|
*
|
|
|
|
* if level != root level and visible nodes == 0, emit row-has-child-toggled.
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (level != filter->priv->root && level->visible_nodes == 0)
|
|
|
|
emit_child_toggled = TRUE;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (length > 1)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2005-10-25 21:00:40 +00:00
|
|
|
FilterElt *tmp;
|
|
|
|
|
|
|
|
/* we emit row-deleted, and remove the node from the cache.
|
|
|
|
*/
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), iter);
|
2005-10-25 21:00:40 +00:00
|
|
|
elt->visible = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
2005-10-25 21:00:40 +00:00
|
|
|
iter->stamp = filter->priv->stamp;
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (filter), path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
while (elt->ref_count > 1)
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
iter, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (parent_level || filter->priv->virtual_root)
|
|
|
|
gtk_tree_model_filter_unref_node (GTK_TREE_MODEL (filter), iter);
|
|
|
|
else
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
iter, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
/* remove the node */
|
|
|
|
tmp = bsearch_elt_with_offset (level->array, elt->offset, &i);
|
|
|
|
|
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
g_array_remove_index (level->array, i);
|
|
|
|
|
2005-08-10 04:15:43 +00:00
|
|
|
i--;
|
|
|
|
for (i = MAX (i, 0); i < level->array->len; i++)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
/* NOTE: here we do *not* decrease offsets, because the node was
|
|
|
|
* not removed from the child model
|
|
|
|
*/
|
|
|
|
elt = &g_array_index (level->array, FilterElt, i);
|
|
|
|
if (elt->children)
|
|
|
|
elt->children->parent_elt = elt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-25 21:00:40 +00:00
|
|
|
else if ((length == 1 && parent && parent->ref_count > 1)
|
|
|
|
|| (length == 1 && level == filter->priv->root))
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* we emit row-deleted, but keep the node in the cache and
|
|
|
|
* referenced.
|
|
|
|
*/
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), iter);
|
|
|
|
elt->visible = FALSE;
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (filter), path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
/* blow level away */
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), iter);
|
|
|
|
elt->visible = FALSE;
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (filter), path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
while (elt->ref_count > 1)
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (filter),
|
|
|
|
iter, FALSE);
|
|
|
|
|
|
|
|
gtk_tree_model_filter_free_level (filter, level);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (emit_child_toggled)
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!elt->visible)
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_has_child (filter->priv->child_model, &c_iter))
|
|
|
|
{
|
|
|
|
GtkTreePath *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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static FilterElt *
|
|
|
|
bsearch_elt_with_offset (GArray *array,
|
|
|
|
gint offset,
|
|
|
|
gint *index)
|
|
|
|
{
|
|
|
|
gint start, middle, end;
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
start = 0;
|
|
|
|
end = array->len;
|
|
|
|
|
|
|
|
if (array->len < 1)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (start == end)
|
|
|
|
{
|
|
|
|
elt = &g_array_index (array, FilterElt, 0);
|
|
|
|
|
|
|
|
if (elt->offset == offset)
|
|
|
|
{
|
|
|
|
*index = 0;
|
|
|
|
return elt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-02-13 23:02:58 +00:00
|
|
|
do
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
middle = (start + end) / 2;
|
|
|
|
|
|
|
|
elt = &g_array_index (array, FilterElt, middle);
|
|
|
|
|
|
|
|
if (elt->offset < offset)
|
|
|
|
start = middle + 1;
|
|
|
|
else if (elt->offset > offset)
|
|
|
|
end = middle;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2004-02-13 23:02:58 +00:00
|
|
|
while (start != end);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
if (elt->offset == offset)
|
|
|
|
{
|
|
|
|
*index = middle;
|
|
|
|
return elt;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TreeModel signals */
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
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? */
|
|
|
|
if (filter->priv->virtual_root
|
|
|
|
&& (gtk_tree_path_get_depth (filter->priv->virtual_root)
|
|
|
|
>= 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);
|
2003-07-11 12:51:24 +00:00
|
|
|
current_state = FILTER_ELT (iter.user_data2)->visible;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
current_state = FALSE;
|
|
|
|
|
|
|
|
if (current_state == FALSE && requested_state == FALSE)
|
|
|
|
/* no changes required */
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (current_state == TRUE && requested_state == FALSE)
|
|
|
|
{
|
|
|
|
/* get rid of this node */
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
2005-10-25 21:00:40 +00:00
|
|
|
level->visible_nodes--;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gtk_tree_model_filter_remove_node (filter, &iter);
|
2004-02-02 22:44:05 +00:00
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (current_state == TRUE && requested_state == TRUE)
|
|
|
|
{
|
2005-10-25 21:00:40 +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);
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_row_changed (GTK_TREE_MODEL (filter), path, &iter);
|
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
2004-08-04 05:38:58 +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
|
|
|
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only current == FALSE and requested == TRUE is left,
|
|
|
|
* pull in the child
|
|
|
|
*/
|
|
|
|
g_return_if_fail (current_state == FALSE && requested_state == TRUE);
|
|
|
|
|
|
|
|
/* make sure the new item has been pulled in */
|
|
|
|
if (!filter->priv->root)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
FilterLevel *root;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
root = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
if (root)
|
|
|
|
{
|
|
|
|
for (i = 0; i < root->array->len; i++)
|
|
|
|
g_array_index (root->array, FilterElt, i).visible = FALSE;
|
2005-10-25 21:00:40 +00:00
|
|
|
root->visible_nodes = 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-02-24 14:42:26 +00:00
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
if (!path)
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
c_path,
|
2003-09-08 19:51:16 +00:00
|
|
|
TRUE,
|
2003-07-11 12:51:24 +00:00
|
|
|
TRUE);
|
|
|
|
|
2005-02-24 14:42:26 +00:00
|
|
|
if (!path)
|
|
|
|
/* parent is probably being filtered out */
|
|
|
|
goto done;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (filter), &iter, path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* elt->visible can be TRUE at this point if it was pulled in above */
|
|
|
|
if (!elt->visible)
|
|
|
|
{
|
|
|
|
elt->visible = TRUE;
|
|
|
|
level->visible_nodes++;
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if ((level->parent_elt && level->parent_elt->visible) || !level->parent_elt)
|
|
|
|
{
|
|
|
|
/* visibility changed -- reget path */
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gtk_tree_model_row_inserted (GTK_TREE_MODEL (filter), path, &iter);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (gtk_tree_model_iter_children (c_model, &children, c_iter))
|
|
|
|
gtk_tree_model_filter_update_children (filter, level, elt);
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
if (path)
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
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 *path = NULL;
|
|
|
|
GtkTreePath *real_path = NULL;
|
2003-07-11 12:51:24 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
GtkTreeIter real_c_iter;
|
|
|
|
|
|
|
|
FilterElt *elt;
|
|
|
|
FilterLevel *level;
|
|
|
|
FilterLevel *parent_level;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
gint level;
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
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])
|
2003-07-11 12:51:24 +00:00
|
|
|
(v_indices[level])++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!filter->priv->root)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
/* build level will pull in the new child */
|
|
|
|
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
|
|
|
|
&& FILTER_LEVEL (filter->priv->root)->visible_nodes)
|
|
|
|
goto done_and_emit;
|
|
|
|
else
|
|
|
|
goto done;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parent_level = level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
if (gtk_tree_path_get_depth (real_path) - 1 >= 1)
|
|
|
|
{
|
|
|
|
/* find the parent level */
|
|
|
|
while (i < gtk_tree_path_get_depth (real_path) - 1)
|
|
|
|
{
|
|
|
|
gint j;
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
/* we don't cover this signal */
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
elt = bsearch_elt_with_offset (level->array,
|
|
|
|
gtk_tree_path_get_indices (real_path)[i],
|
|
|
|
&j);
|
|
|
|
|
|
|
|
if (!elt)
|
|
|
|
/* parent is probably being filtered out */
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
if (!elt->children)
|
|
|
|
{
|
|
|
|
GtkTreePath *tmppath;
|
|
|
|
GtkTreeIter tmpiter;
|
|
|
|
|
|
|
|
tmpiter.stamp = filter->priv->stamp;
|
|
|
|
tmpiter.user_data = level;
|
|
|
|
tmpiter.user_data2 = elt;
|
|
|
|
|
|
|
|
tmppath = gtk_tree_model_get_path (GTK_TREE_MODEL (data),
|
|
|
|
&tmpiter);
|
|
|
|
|
|
|
|
if (tmppath)
|
|
|
|
{
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (data),
|
|
|
|
tmppath, &tmpiter);
|
|
|
|
gtk_tree_path_free (tmppath);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* not covering this signal */
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
level = elt->children;
|
|
|
|
parent_level = level;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!parent_level)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* let's try to insert the value */
|
|
|
|
offset = gtk_tree_path_get_indices (real_path)[gtk_tree_path_get_depth (real_path) - 1];
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
*/
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
FilterElt *e = &g_array_index (level->array, FilterElt, i);
|
|
|
|
if ((e->offset >= offset))
|
|
|
|
e->offset++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* only insert when visible */
|
|
|
|
if (gtk_tree_model_filter_visible (filter, &real_c_iter))
|
|
|
|
{
|
|
|
|
FilterElt felt;
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
felt.iter = real_c_iter;
|
|
|
|
|
|
|
|
felt.offset = offset;
|
|
|
|
felt.zero_ref_count = 0;
|
|
|
|
felt.ref_count = 0;
|
|
|
|
felt.visible = TRUE;
|
|
|
|
felt.children = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
if (g_array_index (level->array, FilterElt, i).offset > offset)
|
|
|
|
break;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
level->visible_nodes++;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
g_array_insert_val (level->array, i, felt);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (level->parent_level || filter->priv->virtual_root)
|
|
|
|
{
|
|
|
|
GtkTreeIter f_iter;
|
|
|
|
|
|
|
|
f_iter.stamp = filter->priv->stamp;
|
|
|
|
f_iter.user_data = level;
|
|
|
|
f_iter.user_data2 = &g_array_index (level->array, FilterElt, i);
|
|
|
|
|
|
|
|
gtk_tree_model_filter_ref_node (GTK_TREE_MODEL (filter), &f_iter);
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2004-08-04 05:38:58 +00:00
|
|
|
/* another iteration to update the references of children to parents. */
|
2003-07-11 12:51:24 +00:00
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
FilterElt *e = &g_array_index (level->array, FilterElt, i);
|
|
|
|
if (e->children)
|
|
|
|
e->children->parent_elt = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* don't emit the signal if we aren't visible */
|
|
|
|
if (!gtk_tree_model_filter_visible (filter, &real_c_iter))
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
done_and_emit:
|
|
|
|
/* NOTE: pass c_path here and NOT real_path. This function does
|
|
|
|
* root subtraction itself
|
|
|
|
*/
|
|
|
|
path = gtk_real_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
c_path,
|
|
|
|
FALSE, TRUE);
|
|
|
|
|
|
|
|
if (!path)
|
2003-11-18 20:09:33 +00:00
|
|
|
goto done;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
gtk_tree_model_filter_get_iter_full (GTK_TREE_MODEL (data), &iter, path);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_row_inserted (GTK_TREE_MODEL (data), path, &iter);
|
|
|
|
|
2003-11-18 20:09:33 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
done:
|
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;
|
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))
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, TRUE);
|
|
|
|
return;
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
if (!gtk_tree_model_filter_visible (filter, c_iter))
|
|
|
|
return;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
elt = FILTER_ELT (iter.user_data2);
|
|
|
|
|
|
|
|
g_assert (elt->visible);
|
|
|
|
|
|
|
|
/* If this node is referenced and has children, build the level so we
|
|
|
|
* can monitor it for changes.
|
|
|
|
*/
|
|
|
|
if (elt->ref_count > 1 && gtk_tree_model_iter_has_child (c_model, c_iter))
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, TRUE);
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2005-10-25 21:00:40 +00:00
|
|
|
FilterElt *elt, *parent;
|
|
|
|
FilterLevel *level, *parent_level;
|
|
|
|
gboolean emit_child_toggled = FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
gint offset;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
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)))
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
GtkTreePath *path;
|
|
|
|
FilterLevel *level = FILTER_LEVEL (filter->priv->root);
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* remove everything in the filter model
|
|
|
|
*
|
|
|
|
* For now, we just iterate over the root level and emit a
|
|
|
|
* row_deleted for each FilterElt. Not sure if this is correct.
|
|
|
|
*/
|
|
|
|
|
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
gtk_tree_path_append_index (path, 0);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
for (i = 0; i < level->visible_nodes; i++)
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_tree_model_filter_free_level (filter, filter->priv->root);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fixup virtual root */
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
{
|
|
|
|
if (gtk_tree_path_get_depth (filter->priv->virtual_root) >=
|
|
|
|
gtk_tree_path_get_depth (c_path))
|
|
|
|
{
|
|
|
|
gint level;
|
|
|
|
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
|
|
|
|
|
|
|
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);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
for (i = 0; i < level; i++)
|
|
|
|
if (v_indices[i] != c_indices[i])
|
|
|
|
{
|
|
|
|
common_prefix = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-28 17:15:15 +00:00
|
|
|
if (common_prefix && v_indices[level] > c_indices[level])
|
2003-07-11 12:51:24 +00:00
|
|
|
(v_indices[level])--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2005-10-25 21:00:40 +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.
|
|
|
|
*/
|
2003-11-18 19:57:14 +00:00
|
|
|
GtkTreePath *real_path;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
if (!filter->priv->root)
|
|
|
|
return;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
level = FILTER_LEVEL (filter->priv->root);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
/* 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);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
i = 0;
|
|
|
|
if (gtk_tree_path_get_depth (real_path) - 1 >= 1)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
/* find the level where the deletion occurred */
|
2003-11-18 19:57:14 +00:00
|
|
|
while (i < gtk_tree_path_get_depth (real_path) - 1)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
2003-11-18 19:57:14 +00:00
|
|
|
gint j;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
if (!level)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
2003-11-18 19:57:14 +00:00
|
|
|
/* we don't cover this */
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
return;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
elt = bsearch_elt_with_offset (level->array,
|
|
|
|
gtk_tree_path_get_indices (real_path)[i],
|
|
|
|
&j);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
if (!elt || !elt->children)
|
|
|
|
{
|
|
|
|
/* parent is filtered out, so no level */
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
return;
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +00:00
|
|
|
level = elt->children;
|
|
|
|
i++;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
2003-11-18 19:57:14 +00:00
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2003-11-18 19:57:14 +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;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* decrease offset of all nodes following the deleted node */
|
2003-11-18 19:57:14 +00:00
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
elt = &g_array_index (level->array, FilterElt, i);
|
|
|
|
if (elt->offset > offset)
|
|
|
|
elt->offset--;
|
|
|
|
if (elt->children)
|
|
|
|
elt->children->parent_elt = elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (elt->visible)
|
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
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
level->visible_nodes--;
|
|
|
|
|
|
|
|
if (level->visible_nodes == 0)
|
|
|
|
{
|
|
|
|
emit_child_toggled = TRUE;
|
|
|
|
parent_level = level->parent_level;
|
|
|
|
parent = level->parent_elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* emit row_deleted */
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_filter_increment_stamp (filter);
|
|
|
|
gtk_tree_model_row_deleted (GTK_TREE_MODEL (data), path);
|
|
|
|
iter.stamp = filter->priv->stamp;
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* The filter model's reference on the child node is released
|
|
|
|
* below.
|
|
|
|
*/
|
|
|
|
while (elt->ref_count > 1)
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (data), &iter,
|
|
|
|
FALSE);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
if (level->array->len == 1)
|
|
|
|
{
|
|
|
|
/* kill level */
|
|
|
|
gtk_tree_model_filter_free_level (filter, level);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
FilterElt *tmp;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* release the filter model's reference on the node */
|
|
|
|
if (level->parent_level || filter->priv->virtual_root)
|
|
|
|
gtk_tree_model_filter_unref_node (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
else
|
|
|
|
gtk_tree_model_filter_real_unref_node (GTK_TREE_MODEL (data), &iter,
|
|
|
|
FALSE);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
/* remove the row */
|
|
|
|
tmp = bsearch_elt_with_offset (level->array, elt->offset, &i);
|
|
|
|
|
|
|
|
offset = tmp->offset;
|
|
|
|
g_array_remove_index (level->array, i);
|
|
|
|
|
2005-08-10 04:15:43 +00:00
|
|
|
i--;
|
|
|
|
for (i = MAX (i, 0); i < level->array->len; i++)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
elt = &g_array_index (level->array, FilterElt, i);
|
|
|
|
if (elt->offset > offset)
|
|
|
|
elt->offset--;
|
|
|
|
if (elt->children)
|
|
|
|
elt->children->parent_elt = elt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (emit_child_toggled && parent_level)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
iter.stamp = filter->priv->stamp;
|
|
|
|
iter.user_data = parent_level;
|
|
|
|
iter.user_data2 = parent;
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
path = gtk_tree_model_get_path (GTK_TREE_MODEL (filter), &iter);
|
|
|
|
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (filter),
|
|
|
|
path, &iter);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
filter->priv->in_row_deleted = FALSE;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
gint *tmp_array;
|
|
|
|
gint i, j, elt_count;
|
|
|
|
gint length;
|
|
|
|
|
|
|
|
GArray *new_array;
|
|
|
|
|
|
|
|
g_return_if_fail (new_order != NULL);
|
|
|
|
|
|
|
|
if (c_path == NULL || gtk_tree_path_get_indices (c_path) == NULL)
|
|
|
|
{
|
|
|
|
if (!filter->priv->root)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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++)
|
|
|
|
if (new_order[i] == gtk_tree_path_get_indices (filter->priv->virtual_root)[0])
|
|
|
|
new_pos = i;
|
|
|
|
|
|
|
|
if (new_pos < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_path_get_indices (filter->priv->virtual_root)[0] = new_pos;
|
|
|
|
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 &&
|
|
|
|
gtk_tree_path_get_depth (c_path) <
|
|
|
|
gtk_tree_path_get_depth (filter->priv->virtual_root))
|
|
|
|
{
|
|
|
|
gint new_pos = -1;
|
|
|
|
gint length;
|
|
|
|
gint level;
|
|
|
|
GtkTreeIter real_c_iter;
|
|
|
|
|
|
|
|
level = gtk_tree_path_get_depth (c_path);
|
|
|
|
|
|
|
|
if (c_iter)
|
|
|
|
real_c_iter = *c_iter;
|
|
|
|
else
|
|
|
|
gtk_tree_model_get_iter (c_model, &real_c_iter, c_path);
|
|
|
|
|
|
|
|
length = gtk_tree_model_iter_n_children (c_model, &real_c_iter);
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++)
|
|
|
|
if (new_order[i] == gtk_tree_path_get_indices (filter->priv->virtual_root)[level])
|
|
|
|
new_pos = i;
|
|
|
|
|
|
|
|
if (new_pos < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_path_get_indices (filter->priv->virtual_root)[level] = new_pos;
|
|
|
|
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
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter.user_data);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (level->array->len < 1)
|
2004-01-28 23:56:50 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
return;
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
/* NOTE: we do not bail out here if level->array->len < 2 like
|
|
|
|
* GtkTreeModelSort does. This because we do some special tricky
|
|
|
|
* reordering.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* construct a new array */
|
|
|
|
new_array = g_array_sized_new (FALSE, FALSE, sizeof (FilterElt),
|
|
|
|
level->array->len);
|
|
|
|
tmp_array = g_new (gint, level->array->len);
|
|
|
|
|
|
|
|
for (i = 0, elt_count = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
FilterElt *e = NULL;
|
|
|
|
gint old_offset = -1;
|
|
|
|
|
|
|
|
for (j = 0; j < level->array->len; j++)
|
|
|
|
if (g_array_index (level->array, FilterElt, j).offset == new_order[i])
|
|
|
|
{
|
|
|
|
e = &g_array_index (level->array, FilterElt, j);
|
|
|
|
old_offset = j;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!e)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmp_array[elt_count] = old_offset;
|
|
|
|
g_array_append_val (new_array, *e);
|
|
|
|
g_array_index (new_array, FilterElt, elt_count).offset = i;
|
|
|
|
elt_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_array_free (level->array, TRUE);
|
|
|
|
level->array = new_array;
|
|
|
|
|
|
|
|
/* fix up stuff */
|
|
|
|
for (i = 0; i < level->array->len; i++)
|
|
|
|
{
|
|
|
|
FilterElt *e = &g_array_index (level->array, FilterElt, i);
|
|
|
|
if (e->children)
|
|
|
|
e->children->parent_elt = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* emit rows_reordered */
|
|
|
|
if (!gtk_tree_path_get_indices (path))
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, NULL,
|
|
|
|
tmp_array);
|
|
|
|
else
|
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 (data), &iter);
|
|
|
|
|
|
|
|
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (data), path, &iter,
|
|
|
|
tmp_array);
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
/* so we can't modify the modify func after this ... */
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* so we can't modify the modify func after this ... */
|
|
|
|
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;
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
|
|
|
indices = gtk_tree_path_get_indices (path);
|
|
|
|
|
|
|
|
if (filter->priv->root == NULL)
|
|
|
|
gtk_tree_model_filter_build_level (filter, NULL, NULL, FALSE);
|
|
|
|
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++)
|
|
|
|
{
|
|
|
|
if (!level || indices[i] >= level->array->len)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
elt = gtk_tree_model_filter_get_nth (filter, level, indices[i]);
|
|
|
|
|
|
|
|
if (!elt->children)
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
|
|
|
level = elt->children;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!level || indices[i] >= level->array->len)
|
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
iter->user_data = level;
|
|
|
|
|
|
|
|
elt = gtk_tree_model_filter_get_nth (filter, level, indices[depth - 1]);
|
|
|
|
iter->user_data2 = elt;
|
|
|
|
|
|
|
|
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;
|
2003-07-11 12:51:24 +00:00
|
|
|
gint depth, i;
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL_FILTER (model), FALSE);
|
|
|
|
g_return_val_if_fail (filter->priv->child_model != NULL, FALSE);
|
|
|
|
|
|
|
|
indices = gtk_tree_path_get_indices (path);
|
|
|
|
|
|
|
|
if (filter->priv->root == NULL)
|
2005-10-25 21:00:40 +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++)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
if (!level || indices[i] >= level->visible_nodes)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
elt = gtk_tree_model_filter_get_nth_visible (filter, level, indices[i]);
|
|
|
|
|
|
|
|
if (!elt->children)
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
|
|
|
level = elt->children;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (!level || indices[i] >= level->visible_nodes)
|
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
|
|
|
|
|
|
|
elt = gtk_tree_model_filter_get_nth_visible (filter, level,
|
|
|
|
indices[depth - 1]);
|
|
|
|
iter->user_data2 = elt;
|
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);
|
|
|
|
|
|
|
|
retval = gtk_tree_path_new ();
|
|
|
|
level = iter->user_data;
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (!elt->visible)
|
|
|
|
return NULL;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
while (level)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
int i = 0, index = 0;
|
|
|
|
|
|
|
|
while (&g_array_index (level->array, FilterElt, i) != elt)
|
|
|
|
{
|
|
|
|
if (g_array_index (level->array, FilterElt, i).visible)
|
|
|
|
index++;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
g_assert (i < level->array->len);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_prepend_index (retval, index);
|
2003-07-11 12:51:24 +00:00
|
|
|
elt = level->parent_elt;
|
|
|
|
level = level->parent_level;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_get_value (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value)
|
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (filter->priv->modify_func)
|
|
|
|
{
|
|
|
|
g_return_if_fail (column < filter->priv->modify_n_columns);
|
|
|
|
|
|
|
|
g_value_init (value, filter->priv->modify_types[column]);
|
|
|
|
filter->priv->modify_func (model,
|
|
|
|
iter,
|
|
|
|
value,
|
|
|
|
column,
|
|
|
|
filter->priv->modify_data);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER (model), &child_iter, iter);
|
|
|
|
gtk_tree_model_get_value (GTK_TREE_MODEL_FILTER (model)->priv->child_model,
|
|
|
|
&child_iter, column, value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_filter_iter_next (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
int i;
|
2003-07-11 12:51:24 +00:00
|
|
|
FilterLevel *level;
|
|
|
|
FilterElt *elt;
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
level = iter->user_data;
|
|
|
|
elt = iter->user_data2;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
i = elt - FILTER_ELT (level->array->data);
|
|
|
|
|
|
|
|
while (i < level->array->len - 1)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
i++;
|
|
|
|
elt++;
|
|
|
|
|
|
|
|
if (elt->visible)
|
|
|
|
{
|
|
|
|
iter->user_data2 = elt;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
/* no next visible iter */
|
|
|
|
iter->stamp = 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
return FALSE;
|
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;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
if (!filter->priv->root)
|
2005-10-25 21:00:40 +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;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
if (!level->visible_nodes)
|
|
|
|
return FALSE;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
iter->user_data = level;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
while (i < level->array->len)
|
|
|
|
{
|
|
|
|
if (!g_array_index (level->array, FilterElt, i).visible)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->user_data2 = &g_array_index (level->array, FilterElt, i);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
int i = 0;
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
if (FILTER_ELT (parent->user_data2)->children == NULL)
|
|
|
|
gtk_tree_model_filter_build_level (filter,
|
|
|
|
FILTER_LEVEL (parent->user_data),
|
2005-10-25 21:00:40 +00:00
|
|
|
FILTER_ELT (parent->user_data2),
|
|
|
|
FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
if (FILTER_ELT (parent->user_data2)->children == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (FILTER_ELT (parent->user_data2)->children->visible_nodes <= 0)
|
2003-07-11 12:51:24 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
iter->stamp = filter->priv->stamp;
|
|
|
|
iter->user_data = FILTER_ELT (parent->user_data2)->children;
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
level = FILTER_LEVEL (iter->user_data);
|
|
|
|
|
|
|
|
while (i < level->array->len)
|
|
|
|
{
|
|
|
|
if (!g_array_index (level->array, FilterElt, i).visible)
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->user_data2 = &g_array_index (level->array, FilterElt, i);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
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);
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (!elt->visible)
|
|
|
|
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),
|
2005-10-25 21:00:40 +00:00
|
|
|
elt, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (elt->children && elt->children->visible_nodes > 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)
|
2005-10-25 21:00:40 +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)
|
|
|
|
return FILTER_LEVEL (filter->priv->root)->visible_nodes;
|
|
|
|
|
|
|
|
return 0;
|
2003-07-11 12:51:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
elt = FILTER_ELT (iter->user_data2);
|
2005-10-25 21:00:40 +00:00
|
|
|
|
|
|
|
if (!elt->visible)
|
|
|
|
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),
|
2005-10-25 21:00:40 +00:00
|
|
|
elt, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (elt->children)
|
|
|
|
return elt->children->visible_nodes;
|
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)
|
|
|
|
{
|
2005-10-25 21:00:40 +00:00
|
|
|
FilterElt *elt;
|
2003-07-11 12:51:24 +00:00
|
|
|
FilterLevel *level;
|
|
|
|
GtkTreeIter children;
|
|
|
|
|
|
|
|
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;
|
2005-10-25 21:00:40 +00:00
|
|
|
elt = FILTER_ELT (level->array->data);
|
|
|
|
|
|
|
|
if (n >= level->visible_nodes)
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
iter->stamp = 0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
elt = gtk_tree_model_filter_get_nth_visible (GTK_TREE_MODEL_FILTER (model),
|
|
|
|
level, n);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
iter->stamp = GTK_TREE_MODEL_FILTER (model)->priv->stamp;
|
|
|
|
iter->user_data = level;
|
2005-10-25 21:00:40 +00:00
|
|
|
iter->user_data2 = elt;
|
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;
|
|
|
|
iter->user_data2 = level->parent_elt;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_ref_node (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
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++;
|
|
|
|
if (level->ref_count == 1)
|
|
|
|
{
|
|
|
|
FilterLevel *parent_level = level->parent_level;
|
|
|
|
FilterElt *parent_elt = level->parent_elt;
|
|
|
|
|
|
|
|
/* we were at zero -- time to decrease the zero_ref_count val */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if (parent_elt)
|
|
|
|
parent_elt->zero_ref_count--;
|
|
|
|
|
|
|
|
if (parent_level)
|
|
|
|
{
|
|
|
|
parent_elt = parent_level->parent_elt;
|
|
|
|
parent_level = parent_level->parent_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (parent_level);
|
|
|
|
filter->priv->zero_ref_count--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_unref_node (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter)
|
|
|
|
{
|
|
|
|
gtk_tree_model_filter_real_unref_node (model, iter, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_model_filter_real_unref_node (GtkTreeModel *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
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);
|
|
|
|
|
|
|
|
elt->ref_count--;
|
|
|
|
level->ref_count--;
|
|
|
|
if (level->ref_count == 0)
|
|
|
|
{
|
|
|
|
FilterLevel *parent_level = level->parent_level;
|
|
|
|
FilterElt *parent_elt = level->parent_elt;
|
|
|
|
|
|
|
|
/* we are at zero -- time to increase the zero_ref_count val */
|
|
|
|
while (parent_level)
|
|
|
|
{
|
|
|
|
parent_elt->zero_ref_count++;
|
|
|
|
|
|
|
|
parent_elt = parent_level->parent_elt;
|
|
|
|
parent_level = parent_level->parent_level;
|
|
|
|
}
|
|
|
|
filter->priv->zero_ref_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_model_filter_drag_data_get (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkSelectionData *selection_data)
|
|
|
|
{
|
|
|
|
GtkTreeModelFilter *tree_model_filter = (GtkTreeModelFilter *)drag_source;
|
|
|
|
GtkTreePath *child_path;
|
|
|
|
gboolean gotten;
|
|
|
|
|
|
|
|
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);
|
|
|
|
gotten = gtk_tree_drag_source_drag_data_get (GTK_TREE_DRAG_SOURCE (tree_model_filter->priv->child_model), child_path, selection_data);
|
|
|
|
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)
|
|
|
|
gtk_tree_model_filter_free_level (filter, filter->priv->root);
|
|
|
|
|
|
|
|
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 =
|
|
|
|
g_signal_connect (child_model, "row_changed",
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_changed),
|
|
|
|
filter);
|
|
|
|
filter->priv->inserted_id =
|
|
|
|
g_signal_connect (child_model, "row_inserted",
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_inserted),
|
|
|
|
filter);
|
|
|
|
filter->priv->has_child_toggled_id =
|
|
|
|
g_signal_connect (child_model, "row_has_child_toggled",
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_has_child_toggled),
|
|
|
|
filter);
|
|
|
|
filter->priv->deleted_id =
|
|
|
|
g_signal_connect (child_model, "row_deleted",
|
|
|
|
G_CALLBACK (gtk_tree_model_filter_row_deleted),
|
|
|
|
filter);
|
|
|
|
filter->priv->reordered_id =
|
|
|
|
g_signal_connect (child_model, "rows_reordered",
|
|
|
|
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,
|
|
|
|
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_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));
|
|
|
|
|
|
|
|
if (!root)
|
|
|
|
filter->priv->virtual_root = NULL;
|
|
|
|
else
|
|
|
|
filter->priv->virtual_root = gtk_tree_path_copy (root);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* public API */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_filter_new:
|
|
|
|
* @child_model: A #GtkTreeModel.
|
|
|
|
* @root: A #GtkTreePath or %NULL.
|
|
|
|
*
|
|
|
|
* Creates a new #GtkTreeModel, with @child_model as the child_model
|
|
|
|
* and @root as the virtual root.
|
|
|
|
*
|
|
|
|
* Return value: A new #GtkTreeModel.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-11 12:51:24 +00:00
|
|
|
*/
|
|
|
|
GtkTreeModel *
|
|
|
|
gtk_tree_model_filter_new (GtkTreeModel *child_model,
|
|
|
|
GtkTreePath *root)
|
|
|
|
{
|
|
|
|
GtkTreeModel *retval;
|
2005-10-25 21:00:40 +00:00
|
|
|
GtkTreeModelFilter *filter;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_MODEL (child_model), NULL);
|
|
|
|
|
2004-11-19 23:18:38 +00:00
|
|
|
retval = g_object_new (GTK_TYPE_TREE_MODEL_FILTER,
|
2005-03-26 05:49:15 +00:00
|
|
|
"child-model", child_model,
|
|
|
|
"virtual-root", root,
|
2004-11-19 23:18:38 +00:00
|
|
|
NULL);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
filter = GTK_TREE_MODEL_FILTER (retval);
|
|
|
|
if (filter->priv->virtual_root)
|
|
|
|
gtk_tree_model_filter_ref_path (filter, filter->priv->virtual_root);
|
|
|
|
|
2003-07-11 12:51:24 +00:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_filter_get_model:
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
*
|
|
|
|
* Returns a pointer to the child model of @filter.
|
|
|
|
*
|
|
|
|
* Return value: A pointer to a #GtkTreeModel.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
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:
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
* @func: A #GtkTreeModelFilterVisibleFunc, the visible function.
|
|
|
|
* @data: User data to pass to the visible function, or %NULL.
|
|
|
|
* @destroy: Destroy notifier of @data, or %NULL.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* %FALSE otherwise.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
2005-03-29 06:04:18 +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 uptodate.
|
|
|
|
*
|
2003-09-30 21:14:09 +00:00
|
|
|
* Since: 2.4
|
2003-07-11 12:51:24 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tree_model_filter_set_visible_func (GtkTreeModelFilter *filter,
|
|
|
|
GtkTreeModelFilterVisibleFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GtkDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (filter->priv->visible_func)
|
|
|
|
{
|
|
|
|
GtkDestroyNotify d = filter->priv->visible_destroy;
|
|
|
|
|
|
|
|
filter->priv->visible_destroy = NULL;
|
|
|
|
d (filter->priv->visible_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
|
|
|
* @types: The #GType<!-- -->s of the columns.
|
2004-02-12 01:52:26 +00:00
|
|
|
* @func: A #GtkTreeModelFilterModifyFunc
|
2003-07-11 12:51:24 +00:00
|
|
|
* @data: User data to pass to the modify function, or %NULL.
|
|
|
|
* @destroy: Destroy notifier of @data, or %NULL.
|
|
|
|
*
|
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
|
|
|
|
* function. The modify function will get called for <emphasis>each</emphasis>
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* Since: 2.4
|
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,
|
|
|
|
GtkDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (filter->priv->modify_destroy)
|
|
|
|
{
|
|
|
|
GtkDestroyNotify d = filter->priv->modify_destroy;
|
|
|
|
|
|
|
|
filter->priv->modify_destroy = NULL;
|
|
|
|
d (filter->priv->modify_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
* @column: A #gint which is the column containing the visible information.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
|
|
|
* Since: 2.4
|
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.
|
|
|
|
* @filter_iter: An uninitialized #GtkTreeIter.
|
|
|
|
* @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
|
|
|
|
* row pointed at by @child_iter.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-11 12:51:24 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gtk_tree_model_filter_convert_child_iter_to_iter (GtkTreeModelFilter *filter,
|
|
|
|
GtkTreeIter *filter_iter,
|
|
|
|
GtkTreeIter *child_iter)
|
|
|
|
{
|
|
|
|
GtkTreePath *child_path, *path;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_MODEL_FILTER (filter));
|
|
|
|
g_return_if_fail (filter->priv->child_model != NULL);
|
|
|
|
g_return_if_fail (filter_iter != NULL);
|
|
|
|
g_return_if_fail (child_iter != NULL);
|
|
|
|
|
|
|
|
filter_iter->stamp = 0;
|
|
|
|
|
|
|
|
child_path = gtk_tree_model_get_path (filter->priv->child_model, child_iter);
|
|
|
|
g_return_if_fail (child_path != NULL);
|
|
|
|
|
|
|
|
path = gtk_tree_model_filter_convert_child_path_to_path (filter,
|
|
|
|
child_path);
|
|
|
|
gtk_tree_path_free (child_path);
|
|
|
|
g_return_if_fail (path != NULL);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), filter_iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gtk_tree_model_filter_convert_iter_to_child_iter:
|
|
|
|
* @filter: A #GtkTreeModelFilter.
|
|
|
|
* @child_iter: An uninitialized #GtkTreeIter.
|
|
|
|
* @filter_iter: A valid #GtkTreeIter pointing to a row on @filter.
|
|
|
|
*
|
|
|
|
* Sets @child_iter to point to the row pointed to by @filter_iter.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-11 12:51:24 +00:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (GTK_TREE_MODEL_FILTER_CACHE_CHILD_ITERS (filter))
|
|
|
|
{
|
|
|
|
*child_iter = FILTER_ELT (filter_iter->user_data2)->iter;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
|
|
|
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);
|
2003-07-11 12:51:24 +00:00
|
|
|
gtk_tree_model_get_iter (filter->priv->child_model, child_iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 ();
|
|
|
|
child_indices = gtk_tree_path_get_indices (real_path);
|
|
|
|
|
|
|
|
if (filter->priv->root == NULL && build_levels)
|
2005-10-25 21:00:40 +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++)
|
|
|
|
{
|
|
|
|
gint j;
|
|
|
|
gboolean found_child = FALSE;
|
|
|
|
|
|
|
|
if (!level)
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (real_path);
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = bsearch_elt_with_offset (level->array, child_indices[i], &j);
|
|
|
|
if (tmp)
|
|
|
|
{
|
|
|
|
gtk_tree_path_append_index (retval, j);
|
|
|
|
if (!tmp->children && build_levels)
|
2005-10-25 21:00:40 +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
|
|
|
{
|
|
|
|
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)
|
2005-10-25 21:00:40 +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
|
|
|
|
* same row in the filtered model. If @child_path isn't a valid path on the
|
|
|
|
* child model, then %NULL is returned.
|
|
|
|
*
|
|
|
|
* Return value: A newly allocated #GtkTreePath, or %NULL.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
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
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (filter), &iter, path);
|
|
|
|
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* Return value: A newly allocated #GtkTreePath, or %NULL.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
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 ();
|
|
|
|
filter_indices = gtk_tree_path_get_indices (filter_path);
|
|
|
|
if (!filter->priv->root)
|
2005-10-25 21:00:40 +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;
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (!level || level->visible_nodes <= filter_indices[i])
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
elt = gtk_tree_model_filter_get_nth_visible (filter, level,
|
|
|
|
filter_indices[i]);
|
|
|
|
|
|
|
|
if (elt->children == NULL)
|
|
|
|
gtk_tree_model_filter_build_level (filter, level, elt, FALSE);
|
2003-07-11 12:51:24 +00:00
|
|
|
|
2005-10-25 21:00:40 +00:00
|
|
|
if (!level || level->visible_nodes <= filter_indices[i])
|
2003-07-11 12:51:24 +00:00
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
2003-07-11 12:51:24 +00:00
|
|
|
*/
|
|
|
|
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
|
|
|
|
* of any cached iterators that haven't been reffed with
|
|
|
|
* gtk_tree_model_ref_node(). This might be useful if the child model
|
|
|
|
* being filtered is static (and doesn't change often) and there has been
|
|
|
|
* a lot of unreffed access to nodes. As a side effect of this function,
|
2006-02-08 15:20:43 +00:00
|
|
|
* all unreffed iters will be invalid.
|
2003-09-30 21:14:09 +00:00
|
|
|
*
|
|
|
|
* Since: 2.4
|
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));
|
|
|
|
}
|
2005-03-20 07:01:23 +00:00
|
|
|
|
|
|
|
#define __GTK_TREE_MODEL_FILTER_C__
|
|
|
|
#include "gtkaliasdef.c"
|