1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
|
/*
* nodestore.c
*
* Copyright (c) 2003 Novell, Inc.
*
* Authors: Mike Kestner <mkestner@ximian.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the Lesser GNU General
* Public License as published by the Free Software Foundation.
*
* This program 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include <gtk/gtktreemodel.h>
typedef GtkTreeModelFlags (* GtkSharpNodeStoreGetFlagsFunc) (void);
typedef gint (* GtkSharpNodeStoreGetNColumnsFunc) (void);
typedef GType (* GtkSharpNodeStoreGetColumnTypeFunc) (gint col);
typedef gboolean (* GtkSharpNodeStoreGetNodeFunc) (gint *node_idx, GtkTreePath *path);
typedef GtkTreePath* (* GtkSharpNodeStoreGetPathFunc) (gint node_idx);
typedef void (* GtkSharpNodeStoreGetValueFunc) (gint node_idx, gint col, GValue *value);
typedef gboolean (* GtkSharpNodeStoreIterNextFunc) (gint *node_idx);
typedef gboolean (* GtkSharpNodeStoreIterChildrenFunc) (gint *first_child, gint parent);
typedef gboolean (* GtkSharpNodeStoreIterHasChildFunc) (gint node_idx);
typedef gint (* GtkSharpNodeStoreIterNChildrenFunc) (gint node_idx);
typedef gboolean (* GtkSharpNodeStoreIterNthChildFunc) (gint *child, gint parent, gint n);
typedef gboolean (* GtkSharpNodeStoreIterParentFunc) (gint *parent, gint child);
typedef struct _GtkSharpNodeStoreTreeModelIface {
GtkSharpNodeStoreGetFlagsFunc get_flags;
GtkSharpNodeStoreGetNColumnsFunc get_n_columns;
GtkSharpNodeStoreGetColumnTypeFunc get_column_type;
GtkSharpNodeStoreGetNodeFunc get_node;
GtkSharpNodeStoreGetPathFunc get_path;
GtkSharpNodeStoreGetValueFunc get_value;
GtkSharpNodeStoreIterNextFunc iter_next;
GtkSharpNodeStoreIterChildrenFunc iter_children;
GtkSharpNodeStoreIterHasChildFunc iter_has_child;
GtkSharpNodeStoreIterNChildrenFunc iter_n_children;
GtkSharpNodeStoreIterNthChildFunc iter_nth_child;
GtkSharpNodeStoreIterParentFunc iter_parent;
} GtkSharpNodeStoreTreeModelIface;
typedef struct _GtkSharpNodeStore {
GObject parent;
gint stamp;
GtkSharpNodeStoreTreeModelIface tree_model;
} GtkSharpNodeStore;
typedef struct _GtkSharpNodeStoreClass {
GObjectClass parent;
} GtkSharpNodeStoreClass;
GType gtksharp_node_store_get_type (void);
GObject * gtksharp_node_store_new (void);
void gtksharp_node_store_set_tree_model_callbacks (GtkSharpNodeStore *store, GtkSharpNodeStoreTreeModelIface *iface);
void gtksharp_node_store_emit_row_changed (GtkSharpNodeStore *store, GtkTreePath *path, gint node_idx);
void gtksharp_node_store_emit_row_inserted (GtkSharpNodeStore *store, GtkTreePath *path, gint node_idx);
void gtksharp_node_store_emit_row_deleted (GtkSharpNodeStore *store, GtkTreePath *path);
void gtksharp_node_store_emit_row_has_child_toggled (GtkSharpNodeStore *store, GtkTreePath *path, gint node_idx);
static GtkTreeModelFlags
gns_get_flags (GtkTreeModel *model)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
return store->tree_model.get_flags ();
}
static int
gns_get_n_columns (GtkTreeModel *model)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
return store->tree_model.get_n_columns ();
}
static GType
gns_get_column_type (GtkTreeModel *model, int col)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
return store->tree_model.get_column_type (col);
}
static gboolean
gns_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
gint node_idx;
if (!store->tree_model.get_node (&node_idx, path))
return FALSE;
iter->stamp = store->stamp;
iter->user_data = GINT_TO_POINTER (node_idx);
return TRUE;
}
static GtkTreePath *
gns_get_path (GtkTreeModel *model, GtkTreeIter *iter)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
return store->tree_model.get_path (GPOINTER_TO_INT (iter->user_data));
}
static void
gns_get_value (GtkTreeModel *model, GtkTreeIter *iter, int col, GValue *value)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
store->tree_model.get_value (GPOINTER_TO_INT (iter->user_data), col, value);
}
static gboolean
gns_iter_next (GtkTreeModel *model, GtkTreeIter *iter)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
gint node_idx;
if (store->stamp != iter->stamp)
return FALSE;
node_idx = GPOINTER_TO_INT (iter->user_data);
if (!store->tree_model.iter_next (&node_idx)) {
iter->stamp = -1;
return FALSE;
}
iter->user_data = GINT_TO_POINTER (node_idx);
return TRUE;
}
static gboolean
gns_iter_children (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
gint child_idx, parent_idx;
if (!parent)
parent_idx = -1;
else {
if (store->stamp != parent->stamp)
return FALSE;
parent_idx = GPOINTER_TO_INT (parent->user_data);
}
if (!store->tree_model.iter_children (&child_idx, parent_idx))
return FALSE;
iter->stamp = store->stamp;
iter->user_data = GINT_TO_POINTER (child_idx);
return TRUE;
}
static gboolean
gns_iter_has_child (GtkTreeModel *model, GtkTreeIter *iter)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
return store->tree_model.iter_has_child (GPOINTER_TO_INT (iter->user_data));
}
static int
gns_iter_n_children (GtkTreeModel *model, GtkTreeIter *iter)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
gint node_idx;
if (!iter)
node_idx = -1;
else {
if (store->stamp != iter->stamp)
return 0;
node_idx = GPOINTER_TO_INT (iter->user_data);
}
return store->tree_model.iter_n_children (node_idx);
}
static gboolean
gns_iter_nth_child (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *parent, int n)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
gint child_idx, parent_idx;
if (!parent)
parent_idx = -1;
else {
if (store->stamp != parent->stamp)
return FALSE;
parent_idx = GPOINTER_TO_INT (parent->user_data);
}
if (!store->tree_model.iter_nth_child (&child_idx, parent_idx, n))
return FALSE;
iter->stamp = store->stamp;
iter->user_data = GINT_TO_POINTER (child_idx);
return TRUE;
}
static gboolean
gns_iter_parent (GtkTreeModel *model, GtkTreeIter *iter, GtkTreeIter *child)
{
GtkSharpNodeStore *store = (GtkSharpNodeStore *) model;
gint parent;
if (store->stamp != child->stamp)
return FALSE;
if (!store->tree_model.iter_parent (&parent, GPOINTER_TO_INT (child->user_data)))
return FALSE;
iter->stamp = store->stamp;
iter->user_data = GINT_TO_POINTER (parent);
return TRUE;
}
static void
gns_tree_model_init (GtkTreeModelIface *iface)
{
iface->get_flags = gns_get_flags;
iface->get_n_columns = gns_get_n_columns;
iface->get_column_type = gns_get_column_type;
iface->get_iter = gns_get_iter;
iface->get_path = gns_get_path;
iface->get_value = gns_get_value;
iface->iter_next = gns_iter_next;
iface->iter_children = gns_iter_children;
iface->iter_has_child = gns_iter_has_child;
iface->iter_n_children = gns_iter_n_children;
iface->iter_nth_child = gns_iter_nth_child;
iface->iter_parent = gns_iter_parent;
}
static void
gns_class_init (GObjectClass *klass)
{
}
static void
gns_init (GtkSharpNodeStore *store)
{
store->stamp = 0;
store->tree_model.get_flags = NULL;
store->tree_model.get_n_columns = NULL;
store->tree_model.get_column_type = NULL;
store->tree_model.get_node = NULL;
store->tree_model.get_path = NULL;
store->tree_model.get_value = NULL;
store->tree_model.iter_next = NULL;
store->tree_model.iter_children = NULL;
store->tree_model.iter_has_child = NULL;
store->tree_model.iter_n_children = NULL;
store->tree_model.iter_nth_child = NULL;
store->tree_model.iter_parent = NULL;
}
GType
gtksharp_node_store_get_type (void)
{
static GType gns_type = 0;
if (!gns_type) {
static const GTypeInfo gns_info = {
sizeof (GtkSharpNodeStoreClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gns_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (GtkSharpNodeStore),
0,
(GInstanceInitFunc) gns_init };
static const GInterfaceInfo tree_model_info = {
(GInterfaceInitFunc) gns_tree_model_init,
NULL,
NULL };
gns_type = g_type_register_static (G_TYPE_OBJECT, "GtkSharpNodeStore", &gns_info, 0);
g_type_add_interface_static (gns_type, GTK_TYPE_TREE_MODEL, &tree_model_info);
}
return gns_type;
}
GObject *
gtksharp_node_store_new (void)
{
return g_object_new (gtksharp_node_store_get_type (), NULL);
}
void
gtksharp_node_store_set_tree_model_callbacks (GtkSharpNodeStore *store, GtkSharpNodeStoreTreeModelIface *iface)
{
store->tree_model = *iface;
}
void
gtksharp_node_store_emit_row_changed (GtkSharpNodeStore *store, GtkTreePath *path, gint node_idx)
{
GtkTreeIter iter;
iter.stamp = store->stamp;
iter.user_data = GINT_TO_POINTER (node_idx);
gtk_tree_model_row_changed (GTK_TREE_MODEL (store), path, &iter);
}
void
gtksharp_node_store_emit_row_inserted (GtkSharpNodeStore *store, GtkTreePath *path, gint node_idx)
{
GtkTreeIter iter;
iter.stamp = store->stamp;
iter.user_data = GINT_TO_POINTER (node_idx);
gtk_tree_model_row_inserted (GTK_TREE_MODEL (store), path, &iter);
}
void
gtksharp_node_store_emit_row_deleted (GtkSharpNodeStore *store, GtkTreePath *path)
{
gtk_tree_model_row_deleted (GTK_TREE_MODEL (store), path);
}
void
gtksharp_node_store_emit_row_has_child_toggled (GtkSharpNodeStore *store, GtkTreePath *path, gint node_idx)
{
GtkTreeIter iter;
iter.stamp = store->stamp;
iter.user_data = GINT_TO_POINTER (node_idx);
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (store), path, &iter);
}
|