2000-10-05 01:04:57 +00:00
|
|
|
/* gtktreestore.c
|
|
|
|
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gtktreemodel.h"
|
|
|
|
#include "gtktreestore.h"
|
|
|
|
#include "gtktreedatalist.h"
|
2001-01-31 00:57:49 +00:00
|
|
|
#include "gtktreednd.h"
|
2000-10-05 01:04:57 +00:00
|
|
|
#include <string.h>
|
2000-10-26 00:36:47 +00:00
|
|
|
#include <gobject/gvaluecollector.h>
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
#define G_NODE(node) ((GNode *)node)
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static void gtk_tree_store_init (GtkTreeStore *tree_store);
|
|
|
|
static void gtk_tree_store_class_init (GtkTreeStoreClass *tree_store_class);
|
|
|
|
static void gtk_tree_store_tree_model_init (GtkTreeModelIface *iface);
|
2001-01-31 00:57:49 +00:00
|
|
|
static void gtk_tree_store_drag_source_init(GtkTreeDragSourceIface *iface);
|
|
|
|
static void gtk_tree_store_drag_dest_init (GtkTreeDragDestIface *iface);
|
2001-03-23 00:35:19 +00:00
|
|
|
static void gtk_tree_store_sortable_init (GtkTreeSortableIface *iface);
|
2000-11-09 16:52:17 +00:00
|
|
|
static guint gtk_tree_store_get_flags (GtkTreeModel *tree_model);
|
2000-10-26 00:36:47 +00:00
|
|
|
static gint gtk_tree_store_get_n_columns (GtkTreeModel *tree_model);
|
2000-11-10 19:38:53 +00:00
|
|
|
static GType gtk_tree_store_get_column_type (GtkTreeModel *tree_model,
|
|
|
|
gint index);
|
2000-10-26 00:36:47 +00:00
|
|
|
static GtkTreePath *gtk_tree_store_get_path (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
2000-10-27 23:34:58 +00:00
|
|
|
static void gtk_tree_store_get_value (GtkTreeModel *tree_model,
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value);
|
|
|
|
static gboolean gtk_tree_store_iter_next (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gboolean gtk_tree_store_iter_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent);
|
|
|
|
static gboolean gtk_tree_store_iter_has_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gint gtk_tree_store_iter_n_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gboolean gtk_tree_store_iter_nth_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
2000-11-09 16:52:17 +00:00
|
|
|
GtkTreeIter *parent,
|
2000-10-26 00:36:47 +00:00
|
|
|
gint n);
|
|
|
|
static gboolean gtk_tree_store_iter_parent (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
2000-11-09 16:52:17 +00:00
|
|
|
GtkTreeIter *child);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
/* DND interfaces */
|
2001-01-31 00:57:49 +00:00
|
|
|
static gboolean gtk_tree_store_drag_data_delete (GtkTreeDragSource *drag_source,
|
2001-03-23 00:35:19 +00:00
|
|
|
GtkTreePath *path);
|
2001-01-31 00:57:49 +00:00
|
|
|
static gboolean gtk_tree_store_drag_data_get (GtkTreeDragSource *drag_source,
|
2001-03-23 00:35:19 +00:00
|
|
|
GtkTreePath *path,
|
|
|
|
GtkSelectionData *selection_data);
|
2001-01-31 00:57:49 +00:00
|
|
|
static gboolean gtk_tree_store_drag_data_received (GtkTreeDragDest *drag_dest,
|
2001-03-23 00:35:19 +00:00
|
|
|
GtkTreePath *dest,
|
|
|
|
GtkSelectionData *selection_data);
|
2001-01-31 00:57:49 +00:00
|
|
|
static gboolean gtk_tree_store_row_drop_possible (GtkTreeDragDest *drag_dest,
|
2001-03-23 00:35:19 +00:00
|
|
|
GtkTreeModel *src_model,
|
|
|
|
GtkTreePath *src_path,
|
|
|
|
GtkTreePath *dest_path);
|
|
|
|
|
|
|
|
/* Sortable Interfaces */
|
|
|
|
|
|
|
|
static void gtk_tree_store_get_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint *sort_column_id,
|
|
|
|
GtkTreeSortOrder *order);
|
|
|
|
static void gtk_tree_store_set_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkTreeSortOrder order);
|
|
|
|
static void gtk_tree_store_sort_column_id_set_func (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkTreeIterCompareFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GtkDestroyNotify destroy);
|
|
|
|
|
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
static void validate_gnode (GNode *node);
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
validate_tree (GtkTreeStore *tree_store)
|
|
|
|
{
|
|
|
|
if (gtk_debug_flags & GTK_DEBUG_TREE)
|
|
|
|
{
|
|
|
|
g_assert (G_NODE (tree_store->root)->parent == NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
validate_gnode (G_NODE (tree_store->root));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
GtkType
|
|
|
|
gtk_tree_store_get_type (void)
|
|
|
|
{
|
2001-02-21 23:49:22 +00:00
|
|
|
static GType tree_store_type = 0;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (!tree_store_type)
|
|
|
|
{
|
|
|
|
static const GTypeInfo tree_store_info =
|
|
|
|
{
|
|
|
|
sizeof (GtkTreeStoreClass),
|
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
(GClassInitFunc) gtk_tree_store_class_init,
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
|
|
|
sizeof (GtkTreeStore),
|
|
|
|
0, /* n_preallocs */
|
|
|
|
(GInstanceInitFunc) gtk_tree_store_init
|
|
|
|
};
|
|
|
|
|
2000-10-16 23:11:55 +00:00
|
|
|
static const GInterfaceInfo tree_model_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_store_tree_model_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
static const GInterfaceInfo drag_source_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_store_drag_source_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const GInterfaceInfo drag_dest_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_store_drag_dest_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
2001-03-23 00:35:19 +00:00
|
|
|
|
|
|
|
static const GInterfaceInfo sortable_info =
|
|
|
|
{
|
|
|
|
(GInterfaceInitFunc) gtk_tree_store_sortable_init,
|
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2001-02-21 23:49:22 +00:00
|
|
|
tree_store_type = g_type_register_static (G_TYPE_OBJECT, "GtkTreeStore", &tree_store_info, 0);
|
2001-01-31 00:57:49 +00:00
|
|
|
|
2000-10-16 23:11:55 +00:00
|
|
|
g_type_add_interface_static (tree_store_type,
|
|
|
|
GTK_TYPE_TREE_MODEL,
|
|
|
|
&tree_model_info);
|
2001-01-31 00:57:49 +00:00
|
|
|
g_type_add_interface_static (tree_store_type,
|
|
|
|
GTK_TYPE_TREE_DRAG_SOURCE,
|
|
|
|
&drag_source_info);
|
|
|
|
g_type_add_interface_static (tree_store_type,
|
|
|
|
GTK_TYPE_TREE_DRAG_DEST,
|
|
|
|
&drag_dest_info);
|
2001-03-23 00:35:19 +00:00
|
|
|
g_type_add_interface_static (tree_store_type,
|
|
|
|
GTK_TYPE_TREE_SORTABLE,
|
|
|
|
&sortable_info);
|
2001-01-31 00:57:49 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tree_store_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-16 23:11:55 +00:00
|
|
|
gtk_tree_store_class_init (GtkTreeStoreClass *tree_store_class)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2001-02-21 23:49:22 +00:00
|
|
|
GObjectClass *object_class;
|
|
|
|
|
|
|
|
object_class = (GObjectClass *) tree_store_class;
|
|
|
|
|
2000-10-16 23:11:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_store_tree_model_init (GtkTreeModelIface *iface)
|
|
|
|
{
|
2000-11-09 16:52:17 +00:00
|
|
|
iface->get_flags = gtk_tree_store_get_flags;
|
2000-10-16 23:11:55 +00:00
|
|
|
iface->get_n_columns = gtk_tree_store_get_n_columns;
|
2000-11-10 19:38:53 +00:00
|
|
|
iface->get_column_type = gtk_tree_store_get_column_type;
|
2000-10-16 23:11:55 +00:00
|
|
|
iface->get_path = gtk_tree_store_get_path;
|
2000-10-27 23:34:58 +00:00
|
|
|
iface->get_value = gtk_tree_store_get_value;
|
2000-10-26 00:36:47 +00:00
|
|
|
iface->iter_next = gtk_tree_store_iter_next;
|
|
|
|
iface->iter_children = gtk_tree_store_iter_children;
|
|
|
|
iface->iter_has_child = gtk_tree_store_iter_has_child;
|
|
|
|
iface->iter_n_children = gtk_tree_store_iter_n_children;
|
|
|
|
iface->iter_nth_child = gtk_tree_store_iter_nth_child;
|
|
|
|
iface->iter_parent = gtk_tree_store_iter_parent;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_store_drag_source_init (GtkTreeDragSourceIface *iface)
|
|
|
|
{
|
|
|
|
iface->drag_data_delete = gtk_tree_store_drag_data_delete;
|
|
|
|
iface->drag_data_get = gtk_tree_store_drag_data_get;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-03-23 00:35:19 +00:00
|
|
|
gtk_tree_store_drag_dest_init (GtkTreeDragDestIface *iface)
|
2001-01-31 00:57:49 +00:00
|
|
|
{
|
|
|
|
iface->drag_data_received = gtk_tree_store_drag_data_received;
|
|
|
|
iface->row_drop_possible = gtk_tree_store_row_drop_possible;
|
|
|
|
}
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_store_sortable_init (GtkTreeSortableIface *iface)
|
|
|
|
{
|
|
|
|
iface->get_sort_column_id = NULL;
|
|
|
|
iface->set_sort_column_id = NULL;
|
|
|
|
iface->sort_column_id_set_func = NULL;
|
|
|
|
}
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
static void
|
|
|
|
gtk_tree_store_init (GtkTreeStore *tree_store)
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
tree_store->root = g_node_new (NULL);
|
2000-11-09 16:52:17 +00:00
|
|
|
tree_store->stamp = g_random_int ();
|
2001-03-23 00:35:19 +00:00
|
|
|
tree_store->sort_list = NULL;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeStore *
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_store_new (void)
|
|
|
|
{
|
2001-02-21 23:49:22 +00:00
|
|
|
return GTK_TREE_STORE (g_object_new (gtk_tree_store_get_type (), NULL));
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeStore *
|
2000-11-10 19:38:53 +00:00
|
|
|
gtk_tree_store_new_with_types (gint n_columns,
|
|
|
|
...)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeStore *retval;
|
2000-10-05 01:04:57 +00:00
|
|
|
va_list args;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
g_return_val_if_fail (n_columns > 0, NULL);
|
|
|
|
|
|
|
|
retval = gtk_tree_store_new ();
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_store_set_n_columns (retval, n_columns);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
va_start (args, n_columns);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
for (i = 0; i < n_columns; i++)
|
2001-03-10 01:34:48 +00:00
|
|
|
{
|
|
|
|
GType type = va_arg (args, GType);
|
|
|
|
if (! _gtk_tree_data_list_check_type (type))
|
|
|
|
{
|
|
|
|
g_warning ("%s: Invalid type %s passed to gtk_tree_store_new_with_types\n", G_STRLOC, g_type_name (type));
|
|
|
|
g_object_unref (G_OBJECT (retval));
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
gtk_tree_store_set_column_type (retval, i, type);
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_store_set_n_columns:
|
|
|
|
* @tree_store:
|
|
|
|
* @n_columns:
|
|
|
|
*
|
|
|
|
* As a side effect of calling this function, all sort columns that overlap with
|
|
|
|
* the current number of columns will be removed.
|
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_store_set_n_columns (GtkTreeStore *tree_store,
|
|
|
|
gint n_columns)
|
|
|
|
{
|
|
|
|
GType *new_columns;
|
|
|
|
|
|
|
|
g_return_if_fail (tree_store != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (tree_store));
|
|
|
|
|
|
|
|
if (tree_store->n_columns == n_columns)
|
|
|
|
return;
|
|
|
|
|
|
|
|
new_columns = g_new0 (GType, n_columns);
|
|
|
|
if (tree_store->column_headers)
|
|
|
|
{
|
|
|
|
/* copy the old header orders over */
|
|
|
|
if (n_columns >= tree_store->n_columns)
|
|
|
|
memcpy (new_columns, tree_store->column_headers, tree_store->n_columns * sizeof (gchar *));
|
|
|
|
else
|
|
|
|
memcpy (new_columns, tree_store->column_headers, n_columns * sizeof (GType));
|
|
|
|
|
|
|
|
g_free (tree_store->column_headers);
|
|
|
|
}
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
if (tree_store->sort_list)
|
|
|
|
_gtk_tree_data_list_header_free (tree_store->sort_list);
|
|
|
|
|
|
|
|
tree_store->sort_list = _gtk_tree_data_list_header_new (n_columns, tree_store->column_headers);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
tree_store->column_headers = new_columns;
|
|
|
|
tree_store->n_columns = n_columns;
|
|
|
|
}
|
|
|
|
|
2001-03-10 01:34:48 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_store_set_column_type:
|
|
|
|
* @tree_store: a #GtkTreeStore
|
|
|
|
* @column: column number
|
|
|
|
* @type: type of the data to be stored in @column
|
2001-03-23 00:35:19 +00:00
|
|
|
*
|
2001-03-10 01:34:48 +00:00
|
|
|
* Supported types include: %G_TYPE_UINT, %G_TYPE_INT, %G_TYPE_UCHAR,
|
|
|
|
* %G_TYPE_CHAR, %G_TYPE_BOOLEAN, %G_TYPE_POINTER, %G_TYPE_FLOAT,
|
|
|
|
* %G_TYPE_DOUBLE, %G_TYPE_STRING, %G_TYPE_OBJECT, and %G_TYPE_BOXED, along with
|
|
|
|
* subclasses of those types such as %GDK_TYPE_PIXBUF.
|
2001-03-23 00:35:19 +00:00
|
|
|
*
|
2001-03-10 01:34:48 +00:00
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
|
|
|
gtk_tree_store_set_column_type (GtkTreeStore *tree_store,
|
|
|
|
gint column,
|
|
|
|
GType type)
|
|
|
|
{
|
|
|
|
g_return_if_fail (tree_store != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (tree_store));
|
|
|
|
g_return_if_fail (column >=0 && column < tree_store->n_columns);
|
2001-03-10 01:34:48 +00:00
|
|
|
if (!_gtk_tree_data_list_check_type (type))
|
|
|
|
{
|
|
|
|
g_warning ("%s: Invalid type %s passed to gtk_tree_store_new_with_types\n", G_STRLOC, g_type_name (type));
|
|
|
|
return;
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
tree_store->column_headers[column] = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* fulfill the GtkTreeModel requirements */
|
|
|
|
/* NOTE: GtkTreeStore::root is a GNode, that acts as the parent node. However,
|
2001-01-31 00:57:49 +00:00
|
|
|
* it is not visible to the tree or to the user., and the path "0" refers to the
|
2000-10-05 01:04:57 +00:00
|
|
|
* first child of GtkTreeStore::root.
|
|
|
|
*/
|
2000-11-09 16:52:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
static guint
|
|
|
|
gtk_tree_store_get_flags (GtkTreeModel *tree_model)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), 0);
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL_ITERS_PERSIST;
|
|
|
|
}
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
static gint
|
|
|
|
gtk_tree_store_get_n_columns (GtkTreeModel *tree_model)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), 0);
|
|
|
|
|
|
|
|
return GTK_TREE_STORE (tree_model)->n_columns;
|
|
|
|
}
|
|
|
|
|
2000-11-10 19:38:53 +00:00
|
|
|
static GType
|
|
|
|
gtk_tree_store_get_column_type (GtkTreeModel *tree_model,
|
|
|
|
gint index)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), G_TYPE_INVALID);
|
|
|
|
g_return_val_if_fail (index < GTK_TREE_STORE (tree_model)->n_columns &&
|
|
|
|
index >= 0, G_TYPE_INVALID);
|
|
|
|
|
|
|
|
return GTK_TREE_STORE (tree_model)->column_headers[index];
|
|
|
|
}
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
static GtkTreePath *
|
|
|
|
gtk_tree_store_get_path (GtkTreeModel *tree_model,
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *retval;
|
|
|
|
GNode *tmp_node;
|
|
|
|
gint i = 0;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
g_return_val_if_fail (tree_model != NULL, NULL);
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), NULL);
|
|
|
|
g_return_val_if_fail (iter != NULL, NULL);
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (iter->user_data != NULL, NULL);
|
2001-01-10 23:44:22 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
validate_tree ((GtkTreeStore*)tree_model);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
g_assert (G_NODE (iter->user_data)->parent != NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
if (G_NODE (iter->user_data)->parent == G_NODE (GTK_TREE_STORE (tree_model)->root))
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
retval = gtk_tree_path_new ();
|
|
|
|
tmp_node = G_NODE (GTK_TREE_STORE (tree_model)->root)->children;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter tmp_iter = *iter;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
tmp_iter.user_data = G_NODE (iter->user_data)->parent;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
retval = gtk_tree_store_get_path (tree_model,
|
2000-10-26 00:36:47 +00:00
|
|
|
&tmp_iter);
|
2001-01-04 23:36:19 +00:00
|
|
|
tmp_node = G_NODE (iter->user_data)->parent->children;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (retval == NULL)
|
|
|
|
return NULL;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if (tmp_node == NULL)
|
|
|
|
{
|
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; tmp_node; tmp_node = tmp_node->next)
|
|
|
|
{
|
2001-01-04 23:36:19 +00:00
|
|
|
if (tmp_node == G_NODE (iter->user_data))
|
2000-10-05 01:04:57 +00:00
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if (tmp_node == NULL)
|
|
|
|
{
|
|
|
|
/* We couldn't find node, meaning it's prolly not ours */
|
2000-10-26 00:36:47 +00:00
|
|
|
/* Perhaps I should do a g_return_if_fail here. */
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (retval);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_append_index (retval, i);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_get_value (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreeDataList *list;
|
|
|
|
gint tmp_column = column;
|
|
|
|
|
|
|
|
g_return_if_fail (tree_model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (tree_model));
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (iter != NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
g_return_if_fail (column < GTK_TREE_STORE (tree_model)->n_columns);
|
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
list = G_NODE (iter->user_data)->data;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
while (tmp_column-- > 0 && list)
|
|
|
|
list = list->next;
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (list)
|
|
|
|
{
|
2000-10-27 23:34:58 +00:00
|
|
|
_gtk_tree_data_list_node_to_value (list,
|
|
|
|
GTK_TREE_STORE (tree_model)->column_headers[column],
|
|
|
|
value);
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We want to return an initialized but empty (default) value */
|
|
|
|
g_value_init (value, GTK_TREE_STORE (tree_model)->column_headers[column]);
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_store_iter_next (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (iter->user_data != NULL, FALSE);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (G_NODE (iter->user_data)->next)
|
|
|
|
{
|
|
|
|
iter->user_data = G_NODE (iter->user_data)->next;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
2000-10-05 01:04:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_iter_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2001-01-31 00:57:49 +00:00
|
|
|
GNode *children;
|
|
|
|
|
|
|
|
g_return_val_if_fail (parent == NULL || parent->user_data != NULL, FALSE);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
if (parent)
|
2001-01-31 00:57:49 +00:00
|
|
|
children = G_NODE (parent->user_data)->children;
|
2000-11-09 16:52:17 +00:00
|
|
|
else
|
2001-01-31 00:57:49 +00:00
|
|
|
children = G_NODE (GTK_TREE_STORE (tree_model)->root)->children;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (children)
|
|
|
|
{
|
|
|
|
iter->stamp = GTK_TREE_STORE (tree_model)->stamp;
|
|
|
|
iter->user_data = children;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_store_iter_has_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (tree_model != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), FALSE);
|
|
|
|
g_return_val_if_fail (iter != NULL, FALSE);
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (iter->user_data != NULL, FALSE);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
return G_NODE (iter->user_data)->children != NULL;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_store_iter_n_children (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GNode *node;
|
2000-10-05 01:04:57 +00:00
|
|
|
gint i = 0;
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (tree_model != NULL, 0);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), 0);
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (iter != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (iter->user_data != NULL, FALSE);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-11-09 16:52:17 +00:00
|
|
|
if (iter == NULL)
|
|
|
|
node = G_NODE (GTK_TREE_STORE (tree_model)->root)->children;
|
|
|
|
else
|
2001-01-04 23:36:19 +00:00
|
|
|
node = G_NODE (iter->user_data)->children;
|
2001-01-31 00:57:49 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
while (node)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
i++;
|
2000-10-26 00:36:47 +00:00
|
|
|
node = node->next;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_iter_nth_child (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
2000-10-05 01:04:57 +00:00
|
|
|
gint n)
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GNode *parent_node;
|
2001-01-31 00:57:49 +00:00
|
|
|
GNode *child;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (tree_model != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (tree_model), FALSE);
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (parent == NULL || parent->user_data != NULL, FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (parent == NULL)
|
|
|
|
parent_node = GTK_TREE_STORE (tree_model)->root;
|
|
|
|
else
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = parent->user_data;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
child = g_node_nth_child (parent_node, n);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (child)
|
|
|
|
{
|
|
|
|
iter->user_data = child;
|
|
|
|
iter->stamp = GTK_TREE_STORE (tree_model)->stamp;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
else
|
2001-01-31 00:57:49 +00:00
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_iter_parent (GtkTreeModel *tree_model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *child)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2001-01-31 00:57:49 +00:00
|
|
|
GNode *parent;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (iter != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (iter->user_data != NULL, FALSE);
|
|
|
|
|
|
|
|
parent = G_NODE (child->user_data)->parent;
|
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
g_assert (parent != NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (parent != GTK_TREE_STORE (tree_model)->root)
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
2001-01-31 00:57:49 +00:00
|
|
|
iter->user_data = parent;
|
|
|
|
iter->stamp = GTK_TREE_STORE (tree_model)->stamp;
|
|
|
|
return TRUE;
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
2001-01-31 00:57:49 +00:00
|
|
|
else
|
|
|
|
return FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a somewhat inelegant function that does a lot of list
|
|
|
|
* manipulations on it's own.
|
|
|
|
*/
|
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_set_cell (GtkTreeStore *tree_store,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gint column,
|
|
|
|
GValue *value)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreeDataList *list;
|
|
|
|
GtkTreeDataList *prev;
|
2001-02-22 01:56:08 +00:00
|
|
|
GtkTreePath *path = NULL;
|
2001-03-10 01:34:48 +00:00
|
|
|
GValue real_value = {0, };
|
|
|
|
gboolean converted = FALSE;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
g_return_if_fail (tree_store != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (tree_store));
|
|
|
|
g_return_if_fail (column >= 0 && column < tree_store->n_columns);
|
2001-03-13 02:00:37 +00:00
|
|
|
g_return_if_fail (G_IS_VALUE (value));
|
2001-03-10 01:34:48 +00:00
|
|
|
|
2001-03-10 17:13:46 +00:00
|
|
|
if (! g_type_is_a (G_VALUE_TYPE (value), tree_store->column_headers[column]))
|
2001-03-10 01:34:48 +00:00
|
|
|
{
|
2001-03-10 17:13:46 +00:00
|
|
|
if (! (g_value_type_compatible (G_VALUE_TYPE (value), tree_store->column_headers[column]) &&
|
|
|
|
g_value_type_compatible (tree_store->column_headers[column], G_VALUE_TYPE (value))))
|
2001-03-10 01:34:48 +00:00
|
|
|
{
|
|
|
|
g_warning ("%s: Unable to convert from %s to %s\n",
|
|
|
|
G_STRLOC,
|
|
|
|
g_type_name (G_VALUE_TYPE (value)),
|
2001-03-10 17:13:46 +00:00
|
|
|
g_type_name (tree_store->column_headers[column]));
|
2001-03-10 01:34:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!g_value_transform (value, &real_value))
|
|
|
|
{
|
|
|
|
g_warning ("%s: Unable to make conversion from %s to %s\n",
|
|
|
|
G_STRLOC,
|
|
|
|
g_type_name (G_VALUE_TYPE (value)),
|
2001-03-10 17:13:46 +00:00
|
|
|
g_type_name (tree_store->column_headers[column]));
|
2001-03-10 01:34:48 +00:00
|
|
|
g_value_unset (&real_value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
converted = TRUE;
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
prev = list = G_NODE (iter->user_data)->data;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-02-22 01:56:08 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
while (list != NULL)
|
|
|
|
{
|
|
|
|
if (column == 0)
|
|
|
|
{
|
2001-03-10 01:34:48 +00:00
|
|
|
if (converted)
|
|
|
|
_gtk_tree_data_list_value_to_node (list, &real_value);
|
|
|
|
else
|
|
|
|
_gtk_tree_data_list_value_to_node (list, value);
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_changed (GTK_TREE_MODEL (tree_store), path, iter);
|
|
|
|
gtk_tree_path_free (path);
|
2001-03-10 01:34:48 +00:00
|
|
|
if (converted)
|
|
|
|
g_value_unset (&real_value);
|
2000-10-05 01:04:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
column--;
|
|
|
|
prev = list;
|
|
|
|
list = list->next;
|
|
|
|
}
|
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
if (G_NODE (iter->user_data)->data == NULL)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2001-01-04 23:36:19 +00:00
|
|
|
G_NODE (iter->user_data)->data = list = _gtk_tree_data_list_alloc ();
|
2000-10-05 01:04:57 +00:00
|
|
|
list->next = NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-27 23:34:58 +00:00
|
|
|
list = prev->next = _gtk_tree_data_list_alloc ();
|
2000-10-05 01:04:57 +00:00
|
|
|
list->next = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (column != 0)
|
|
|
|
{
|
2000-10-27 23:34:58 +00:00
|
|
|
list->next = _gtk_tree_data_list_alloc ();
|
2000-10-05 01:04:57 +00:00
|
|
|
list = list->next;
|
|
|
|
list->next = NULL;
|
|
|
|
column --;
|
|
|
|
}
|
2001-03-10 01:34:48 +00:00
|
|
|
if (converted)
|
2001-03-10 17:13:46 +00:00
|
|
|
_gtk_tree_data_list_value_to_node (list, &real_value);
|
2001-03-10 01:34:48 +00:00
|
|
|
else
|
|
|
|
_gtk_tree_data_list_value_to_node (list, value);
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_changed (GTK_TREE_MODEL (tree_store), path, iter);
|
|
|
|
gtk_tree_path_free (path);
|
2001-03-10 01:34:48 +00:00
|
|
|
if (converted)
|
|
|
|
g_value_unset (&real_value);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2001-02-17 00:16:08 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_store_set_valist:
|
|
|
|
* @tree_store: a #GtkTreeStore
|
|
|
|
* @iter: row to set data for
|
|
|
|
* @var_args: va_list of column/value pairs
|
|
|
|
*
|
|
|
|
* See gtk_tree_store_set(); this version takes a va_list for
|
|
|
|
* use by language bindings.
|
2001-03-23 00:35:19 +00:00
|
|
|
*
|
2001-02-17 00:16:08 +00:00
|
|
|
**/
|
2000-10-05 01:04:57 +00:00
|
|
|
void
|
2001-01-08 18:26:05 +00:00
|
|
|
gtk_tree_store_set_valist (GtkTreeStore *tree_store,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
va_list var_args)
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
|
|
|
gint column;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (tree_store));
|
|
|
|
|
|
|
|
column = va_arg (var_args, gint);
|
|
|
|
|
2001-01-08 18:26:05 +00:00
|
|
|
while (column != -1)
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
|
|
|
GValue value = { 0, };
|
|
|
|
gchar *error = NULL;
|
|
|
|
|
|
|
|
if (column >= tree_store->n_columns)
|
|
|
|
{
|
2001-01-08 18:26:05 +00:00
|
|
|
g_warning ("%s: Invalid column number %d added to iter (remember to end your list of columns with a -1)", G_STRLOC, column);
|
2000-10-26 00:36:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
g_value_init (&value, tree_store->column_headers[column]);
|
|
|
|
|
2001-02-17 06:04:40 +00:00
|
|
|
G_VALUE_COLLECT (&value, var_args, 0, &error);
|
2000-10-26 00:36:47 +00:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
g_warning ("%s: %s", G_STRLOC, error);
|
|
|
|
g_free (error);
|
|
|
|
|
|
|
|
/* we purposely leak the value here, it might not be
|
|
|
|
* in a sane state if an error condition occoured
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_set_cell (tree_store,
|
|
|
|
iter,
|
|
|
|
column,
|
|
|
|
&value);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
|
|
|
g_value_unset (&value);
|
|
|
|
|
|
|
|
column = va_arg (var_args, gint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-08 18:26:05 +00:00
|
|
|
/**
|
|
|
|
* gtk_tree_store_set:
|
|
|
|
* @tree_store: a #GtkTreeStore
|
|
|
|
* @iter: row iterator
|
|
|
|
* @Varargs: pairs of column number and value, terminated with -1
|
2001-03-23 00:35:19 +00:00
|
|
|
*
|
2001-01-08 18:26:05 +00:00
|
|
|
* Sets the value of one or more cells in the row referenced by @iter.
|
|
|
|
* The variable argument list should contain integer column numbers,
|
|
|
|
* each column number followed by the value to be set. For example,
|
|
|
|
* The list is terminated by a -1. For example, to set column 0 with type
|
|
|
|
* %G_TYPE_STRING to "Foo", you would write gtk_tree_store_set (store, iter,
|
|
|
|
* 0, "Foo", -1).
|
|
|
|
**/
|
2000-10-26 00:36:47 +00:00
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_set (GtkTreeStore *tree_store,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
...)
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
|
|
|
va_list var_args;
|
|
|
|
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (tree_store));
|
|
|
|
|
|
|
|
va_start (var_args, iter);
|
2001-01-08 18:26:05 +00:00
|
|
|
gtk_tree_store_set_valist (tree_store, iter, var_args);
|
2000-10-26 00:36:47 +00:00
|
|
|
va_end (var_args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_remove (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2001-02-22 01:56:08 +00:00
|
|
|
GtkTreeIter new_iter = {0,};
|
2000-10-05 01:04:57 +00:00
|
|
|
GNode *parent;
|
|
|
|
|
|
|
|
g_return_if_fail (model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (model));
|
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
parent = G_NODE (iter->user_data)->parent;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
g_assert (parent != NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
if (G_NODE (iter->user_data)->data)
|
|
|
|
_gtk_tree_data_list_free ((GtkTreeDataList *) G_NODE (iter->user_data)->data,
|
2000-10-27 23:34:58 +00:00
|
|
|
model->column_headers);
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), iter);
|
2001-01-04 23:36:19 +00:00
|
|
|
g_node_destroy (G_NODE (iter->user_data));
|
2000-10-27 23:34:58 +00:00
|
|
|
|
|
|
|
model->stamp++;
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_deleted (GTK_TREE_MODEL (model), path);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if (parent != G_NODE (model->root) && parent->children == NULL)
|
|
|
|
{
|
|
|
|
gtk_tree_path_up (path);
|
2001-02-22 01:56:08 +00:00
|
|
|
|
|
|
|
new_iter.stamp = model->stamp;
|
|
|
|
new_iter.user_data = parent;
|
2001-03-05 19:43:24 +00:00
|
|
|
gtk_tree_model_has_child_toggled (GTK_TREE_MODEL (model), path, &new_iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_insert (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
gint position)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2001-01-31 00:57:49 +00:00
|
|
|
GNode *parent_node;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (model));
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (parent)
|
|
|
|
parent_node = parent->user_data;
|
|
|
|
else
|
|
|
|
parent_node = model->root;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
iter->stamp = model->stamp;
|
2001-01-04 23:36:19 +00:00
|
|
|
iter->user_data = g_node_new (NULL);
|
2001-01-31 00:57:49 +00:00
|
|
|
g_node_insert (parent_node, position, G_NODE (iter->user_data));
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), iter);
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_inserted (GTK_TREE_MODEL (model), path, iter);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (path);
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
validate_tree ((GtkTreeStore*)model);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_insert_before (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
GtkTreeIter *sibling)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2001-01-31 00:57:49 +00:00
|
|
|
GNode *parent_node = NULL;
|
2001-01-10 23:44:22 +00:00
|
|
|
GNode *new_node;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (model));
|
|
|
|
g_return_if_fail (iter != NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
new_node = g_node_new (NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (parent == NULL && sibling == NULL)
|
|
|
|
parent_node = model->root;
|
|
|
|
else if (parent == NULL)
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = G_NODE (sibling->user_data)->parent;
|
2001-01-10 23:44:22 +00:00
|
|
|
else if (sibling == NULL)
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = G_NODE (parent->user_data);
|
2001-01-10 23:44:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_NODE (sibling->user_data)->parent ==
|
|
|
|
G_NODE (parent->user_data));
|
|
|
|
parent_node = G_NODE (parent->user_data);
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_node_insert_before (parent_node,
|
2001-01-04 23:36:19 +00:00
|
|
|
sibling ? G_NODE (sibling->user_data) : NULL,
|
2001-01-10 23:44:22 +00:00
|
|
|
new_node);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
iter->stamp = model->stamp;
|
|
|
|
iter->user_data = new_node;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), iter);
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_inserted (GTK_TREE_MODEL (model), path, iter);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (path);
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
validate_tree ((GtkTreeStore*)model);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_insert_after (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent,
|
|
|
|
GtkTreeIter *sibling)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2000-10-26 00:36:47 +00:00
|
|
|
GNode *parent_node;
|
2001-01-10 23:44:22 +00:00
|
|
|
GNode *new_node;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (model));
|
|
|
|
g_return_if_fail (iter != NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
new_node = g_node_new (NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (parent == NULL && sibling == NULL)
|
|
|
|
parent_node = model->root;
|
|
|
|
else if (parent == NULL)
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = G_NODE (sibling->user_data)->parent;
|
2001-01-10 23:44:22 +00:00
|
|
|
else if (sibling == NULL)
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = G_NODE (parent->user_data);
|
2001-01-10 23:44:22 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
g_return_if_fail (G_NODE (sibling->user_data)->parent ==
|
|
|
|
G_NODE (parent->user_data));
|
|
|
|
parent_node = G_NODE (parent->user_data);
|
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_node_insert_after (parent_node,
|
2001-01-04 23:36:19 +00:00
|
|
|
sibling ? G_NODE (sibling->user_data) : NULL,
|
2001-01-10 23:44:22 +00:00
|
|
|
new_node);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
iter->stamp = model->stamp;
|
|
|
|
iter->user_data = new_node;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), iter);
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_inserted (GTK_TREE_MODEL (model), path, iter);
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (path);
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
validate_tree ((GtkTreeStore*)model);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_prepend (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GNode *parent_node;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_if_fail (model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (model));
|
|
|
|
g_return_if_fail (iter != NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
if (parent == NULL)
|
2000-10-26 00:36:47 +00:00
|
|
|
parent_node = model->root;
|
|
|
|
else
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = parent->user_data;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (parent_node->children == NULL)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
iter->stamp = model->stamp;
|
|
|
|
iter->user_data = g_node_new (NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-10 23:44:22 +00:00
|
|
|
g_node_prepend (parent_node, iter->user_data);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (parent_node != model->root)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), parent);
|
2001-03-05 19:43:24 +00:00
|
|
|
gtk_tree_model_has_child_toggled (GTK_TREE_MODEL (model), path, parent);
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_path_append_index (path, 0);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_inserted (GTK_TREE_MODEL (model), path, iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_insert_after (model, iter, parent, NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
validate_tree ((GtkTreeStore*)model);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
void
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_append (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *parent)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GNode *parent_node;
|
|
|
|
|
|
|
|
g_return_if_fail (model != NULL);
|
|
|
|
g_return_if_fail (GTK_IS_TREE_STORE (model));
|
|
|
|
g_return_if_fail (iter != NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
if (parent == NULL)
|
2000-10-26 00:36:47 +00:00
|
|
|
parent_node = model->root;
|
|
|
|
else
|
2001-01-04 23:36:19 +00:00
|
|
|
parent_node = parent->user_data;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
if (parent_node->children == NULL)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
iter->stamp = model->stamp;
|
|
|
|
iter->user_data = g_node_new (NULL);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
g_node_append (parent_node, G_NODE (iter->user_data));
|
2000-10-26 00:36:47 +00:00
|
|
|
|
|
|
|
if (parent_node != model->root)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), parent);
|
2001-03-05 19:43:24 +00:00
|
|
|
gtk_tree_model_has_child_toggled (GTK_TREE_MODEL (model), path, parent);
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_path_append_index (path, 0);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (model), iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_inserted (GTK_TREE_MODEL (model), path, iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_insert_before (model, iter, parent, NULL);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
validate_tree ((GtkTreeStore*)model);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2000-10-27 23:34:58 +00:00
|
|
|
gtk_tree_store_is_ancestor (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreeIter *descendant)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (model != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (model), FALSE);
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (iter != NULL, FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
g_return_val_if_fail (descendant != NULL, FALSE);
|
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
return g_node_is_ancestor (G_NODE (iter->user_data),
|
|
|
|
G_NODE (descendant->user_data));
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
gint
|
2000-10-26 00:36:47 +00:00
|
|
|
gtk_tree_store_iter_depth (GtkTreeStore *model,
|
|
|
|
GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (model != NULL, 0);
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (model), 0);
|
2000-10-26 00:36:47 +00:00
|
|
|
g_return_val_if_fail (iter != NULL, 0);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-01-04 23:36:19 +00:00
|
|
|
return g_node_depth (G_NODE (iter->user_data)) - 1;
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
/* DND */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_drag_data_delete (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (drag_source), FALSE);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_source),
|
|
|
|
&iter,
|
|
|
|
path))
|
|
|
|
{
|
|
|
|
gtk_tree_store_remove (GTK_TREE_STORE (drag_source),
|
|
|
|
&iter);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_drag_data_get (GtkTreeDragSource *drag_source,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkSelectionData *selection_data)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (drag_source), FALSE);
|
|
|
|
|
|
|
|
/* Note that we don't need to handle the GTK_TREE_MODEL_ROW
|
|
|
|
* target, because the default handler does it for us, but
|
|
|
|
* we do anyway for the convenience of someone maybe overriding the
|
|
|
|
* default handler.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (gtk_selection_data_set_tree_row (selection_data,
|
|
|
|
GTK_TREE_MODEL (drag_source),
|
|
|
|
path))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME handle text targets at least. */
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
copy_node_data (GtkTreeStore *tree_store,
|
|
|
|
GtkTreeIter *src_iter,
|
|
|
|
GtkTreeIter *dest_iter)
|
|
|
|
{
|
|
|
|
GtkTreeDataList *dl = G_NODE (src_iter->user_data)->data;
|
|
|
|
GtkTreeDataList *copy_head = NULL;
|
|
|
|
GtkTreeDataList *copy_prev = NULL;
|
|
|
|
GtkTreeDataList *copy_iter = NULL;
|
2001-02-22 01:56:08 +00:00
|
|
|
GtkTreePath *path;
|
2001-01-31 00:57:49 +00:00
|
|
|
gint col;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
col = 0;
|
|
|
|
while (dl)
|
|
|
|
{
|
2001-03-10 01:34:48 +00:00
|
|
|
copy_iter = _gtk_tree_data_list_node_copy (dl, tree_store->column_headers[col]);
|
2001-01-31 00:57:49 +00:00
|
|
|
|
|
|
|
if (copy_head == NULL)
|
|
|
|
copy_head = copy_iter;
|
|
|
|
|
|
|
|
if (copy_prev)
|
|
|
|
copy_prev->next = copy_iter;
|
|
|
|
|
|
|
|
copy_prev = copy_iter;
|
|
|
|
|
|
|
|
dl = dl->next;
|
|
|
|
++col;
|
|
|
|
}
|
2001-03-10 01:34:48 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
G_NODE (dest_iter->user_data)->data = copy_head;
|
|
|
|
|
2001-03-10 01:34:48 +00:00
|
|
|
path = gtk_tree_store_get_path (GTK_TREE_MODEL (tree_store), dest_iter);
|
2001-02-22 01:56:08 +00:00
|
|
|
gtk_tree_model_changed (GTK_TREE_MODEL (tree_store), path, dest_iter);
|
|
|
|
gtk_tree_path_free (path);
|
2001-01-31 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
recursive_node_copy (GtkTreeStore *tree_store,
|
|
|
|
GtkTreeIter *src_iter,
|
|
|
|
GtkTreeIter *dest_iter)
|
|
|
|
{
|
|
|
|
GtkTreeIter child;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
model = GTK_TREE_MODEL (tree_store);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
copy_node_data (tree_store, src_iter, dest_iter);
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_children (model,
|
|
|
|
&child,
|
|
|
|
src_iter))
|
|
|
|
{
|
|
|
|
/* Need to create children and recurse. Note our
|
|
|
|
* dependence on persistent iterators here.
|
|
|
|
*/
|
|
|
|
do
|
|
|
|
{
|
|
|
|
GtkTreeIter copy;
|
|
|
|
|
|
|
|
/* Gee, a really slow algorithm... ;-) FIXME */
|
|
|
|
gtk_tree_store_append (tree_store,
|
|
|
|
©,
|
|
|
|
dest_iter);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
recursive_node_copy (tree_store, &child, ©);
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (model, &child));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_drag_data_received (GtkTreeDragDest *drag_dest,
|
|
|
|
GtkTreePath *dest,
|
|
|
|
GtkSelectionData *selection_data)
|
|
|
|
{
|
|
|
|
GtkTreeModel *tree_model;
|
|
|
|
GtkTreeStore *tree_store;
|
|
|
|
GtkTreeModel *src_model = NULL;
|
|
|
|
GtkTreePath *src_path = NULL;
|
|
|
|
gboolean retval = FALSE;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
g_return_val_if_fail (GTK_IS_TREE_STORE (drag_dest), FALSE);
|
|
|
|
|
|
|
|
tree_model = GTK_TREE_MODEL (drag_dest);
|
|
|
|
tree_store = GTK_TREE_STORE (drag_dest);
|
|
|
|
|
|
|
|
validate_tree (tree_store);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (gtk_selection_data_get_tree_row (selection_data,
|
|
|
|
&src_model,
|
|
|
|
&src_path) &&
|
|
|
|
src_model == tree_model)
|
|
|
|
{
|
|
|
|
/* Copy the given row to a new position */
|
|
|
|
GtkTreeIter src_iter;
|
|
|
|
GtkTreeIter dest_iter;
|
|
|
|
GtkTreePath *prev;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (!gtk_tree_model_get_iter (src_model,
|
|
|
|
&src_iter,
|
|
|
|
src_path))
|
|
|
|
{
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the path to insert _after_ (dest is the path to insert _before_) */
|
|
|
|
prev = gtk_tree_path_copy (dest);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (!gtk_tree_path_prev (prev))
|
|
|
|
{
|
|
|
|
GtkTreeIter dest_parent;
|
|
|
|
GtkTreePath *parent;
|
|
|
|
GtkTreeIter *dest_parent_p;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
/* dest was the first spot at the current depth; which means
|
|
|
|
* we are supposed to prepend.
|
|
|
|
*/
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
/* Get the parent, NULL if parent is the root */
|
|
|
|
dest_parent_p = NULL;
|
|
|
|
parent = gtk_tree_path_copy (dest);
|
|
|
|
if (gtk_tree_path_up (parent))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get_iter (tree_model,
|
|
|
|
&dest_parent,
|
|
|
|
parent);
|
|
|
|
dest_parent_p = &dest_parent;
|
|
|
|
}
|
|
|
|
gtk_tree_path_free (parent);
|
|
|
|
parent = NULL;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
gtk_tree_store_prepend (GTK_TREE_STORE (tree_model),
|
|
|
|
&dest_iter,
|
|
|
|
dest_parent_p);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
retval = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_model),
|
|
|
|
&dest_iter,
|
|
|
|
prev))
|
|
|
|
{
|
|
|
|
GtkTreeIter tmp_iter = dest_iter;
|
|
|
|
gtk_tree_store_insert_after (GTK_TREE_STORE (tree_model),
|
|
|
|
&dest_iter,
|
|
|
|
NULL,
|
|
|
|
&tmp_iter);
|
|
|
|
retval = TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (prev);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
/* If we succeeded in creating dest_iter, walk src_iter tree branch,
|
|
|
|
* duplicating it below dest_iter.
|
|
|
|
*/
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (retval)
|
|
|
|
{
|
|
|
|
recursive_node_copy (tree_store,
|
|
|
|
&src_iter,
|
|
|
|
&dest_iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* FIXME maybe add some data targets eventually, or handle text
|
|
|
|
* targets in the simple case.
|
|
|
|
*/
|
remove validation idle
2001-02-08 Havoc Pennington <hp@redhat.com>
* gtk/gtktextview.c (gtk_text_view_destroy_layout): remove
validation idle
* demos/gtk-demo/main.c (create_tree): adjust to changes in text
cell renderer
* demos/pixbuf-demo.c (timeout): remove deprecated
gtk_widget_draw
* demos/testpixbuf-save.c (main): remove deprecated
gtk_drawing_area_size
* gtk/gtktreeview.c (gtk_tree_view_size_allocate): allocate
buttons even if the model isn't setup. gtk_tree_view_check_dirty()
at the start of the allocation.
(gtk_tree_view_check_dirty): handle column->button == NULL, handle
unsetup or NULL model.
* gtk/gtkstyle.c (gtk_default_draw_flat_box): drawing for the
even/odd/sorted cells in the tree view.
* gtk/gtktreeselection.c (gtk_tree_selection_real_unselect_all):
bugfixes
* gtk/gtktreeview.c: assorted bugfixy stuff. Draw the row
backgrounds with draw_flat_box using different detail for even/odd
rows.
* gtk/gtkrbtree.c, gtkrbtree.h: Keep track of the parity of each
row, so we can draw the alternating colors thing
* gtk/gtktexttag.c (gtk_text_tag_set_property): if we change a
property from a synonym property, notify for the synonym.
Also, nuke the background_gdk_set and foreground_gdk_set synonyms
(gtk_text_tag_get_property): Always return the font, even if
all its fields aren't set
* gtk/gtkcellrenderertext.h (struct _GtkCellRendererText): don't
store the attr list; it leaves us with no way to change attributes
in _render according to the render flags, and no way to implement
get_property. Instead store all the specific text attributes.
Separate whether an attribute is enabled from its value. Sync all
properties with GtkTextTag, make them all consistent, etc.
* gtk/gtkcellrenderer.h: Add a flag GTK_CELL_RENDERER_SORTED so
renderers can highlight the sort row/column
* gtk/gtktreeviewcolumn.c (gtk_tree_view_column_get_property): use
accessor functions to get values; this has the side effect of
showing up which accessor functions were missing. Added those.
* gtk/gtktreeviewcolumn.h: Replace set_justification with
set_alignment, to be consistent with GtkLabel, GtkMisc
* gtk/gtktreeviewcolumn.c: Added code to display sort indicator
arrow.
* gtk/Makefile.am (gtk_public_h_sources): add gtktreesortable.h
* gtk/gtktreesortable.h: updates in here
2001-02-08 23:36:53 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (src_path)
|
|
|
|
gtk_tree_path_free (src_path);
|
2001-03-23 00:35:19 +00:00
|
|
|
|
|
|
|
return retval;
|
2001-01-31 00:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_tree_store_row_drop_possible (GtkTreeDragDest *drag_dest,
|
|
|
|
GtkTreeModel *src_model,
|
|
|
|
GtkTreePath *src_path,
|
|
|
|
GtkTreePath *dest_path)
|
|
|
|
{
|
|
|
|
/* can only drag to ourselves */
|
|
|
|
if (src_model != GTK_TREE_MODEL (drag_dest))
|
|
|
|
return FALSE;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
/* Can't drop into ourself. */
|
|
|
|
if (gtk_tree_path_is_ancestor (src_path,
|
|
|
|
dest_path))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* Can't drop if dest_path's parent doesn't exist */
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *tmp = gtk_tree_path_copy (dest_path);
|
|
|
|
|
|
|
|
/* if we can't go up, we know the parent exists, the root
|
|
|
|
* always exists.
|
|
|
|
*/
|
|
|
|
if (gtk_tree_path_up (tmp))
|
|
|
|
{
|
|
|
|
if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (drag_dest),
|
|
|
|
&iter, tmp))
|
|
|
|
{
|
|
|
|
if (tmp)
|
|
|
|
gtk_tree_path_free (tmp);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
if (tmp)
|
|
|
|
gtk_tree_path_free (tmp);
|
|
|
|
}
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
/* Can otherwise drop anywhere. */
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-03-23 00:35:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_store_get_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint *sort_column_id,
|
|
|
|
GtkTreeSortOrder *order)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_store_set_sort_column_id (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkTreeSortOrder order)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_tree_store_sort_column_id_set_func (GtkTreeSortable *sortable,
|
|
|
|
gint sort_column_id,
|
|
|
|
GtkTreeIterCompareFunc func,
|
|
|
|
gpointer data,
|
|
|
|
GtkDestroyNotify destroy)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
static void
|
|
|
|
validate_gnode (GNode* node)
|
|
|
|
{
|
|
|
|
GNode *iter;
|
2001-03-23 00:35:19 +00:00
|
|
|
|
2001-01-31 00:57:49 +00:00
|
|
|
iter = node->children;
|
|
|
|
while (iter != NULL)
|
|
|
|
{
|
|
|
|
g_assert (iter->parent == node);
|
|
|
|
if (iter->prev)
|
|
|
|
g_assert (iter->prev->next == iter);
|
|
|
|
validate_gnode (iter);
|
|
|
|
iter = iter->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|