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 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798
|
#include "Graphics/UI/Gtk/ModelView/Gtk2HsStore.h"
/* #define DEBUG */
#ifdef DEBUG
#define WHEN_DEBUG(a) a
#else
#define WHEN_DEBUG(a)
#endif
static void gtk2hs_store_init (Gtk2HsStore *pkg_tree);
static void gtk2hs_store_class_init (Gtk2HsStoreClass *klass);
static void gtk2hs_store_tree_model_init (GtkTreeModelIface *iface);
static void gtk2hs_store_tree_sortable_init (GtkTreeSortableIface *iface);
static void gtk2hs_store_tree_drag_source_init (GtkTreeDragSourceIface *iface);
static void gtk2hs_store_tree_drag_dest_init (GtkTreeDragDestIface *iface);
static void gtk2hs_store_finalize (GObject *object);
static GtkTreeModelFlags gtk2hs_store_get_flags (GtkTreeModel *tree_model);
static gint gtk2hs_store_get_n_columns (GtkTreeModel *tree_model);
static GType gtk2hs_store_get_column_type (GtkTreeModel *tree_model,
gint index);
static gboolean gtk2hs_store_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreePath *path);
static GtkTreePath *gtk2hs_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk2hs_store_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter,
gint column,
GValue *value);
static gboolean gtk2hs_store_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk2hs_store_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent);
static gboolean gtk2hs_store_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gint gtk2hs_store_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static gboolean gtk2hs_store_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *parent,
gint n);
static gboolean gtk2hs_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter,
GtkTreeIter *child);
static void gtk2hs_store_ref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
static void gtk2hs_store_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter);
/* The TreeSortable interface is currently not implemented and may never be. */
static gboolean gtk2hs_store_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkSortType *order);
static void gtk2hs_store_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkSortType order);
static void gtk2hs_store_set_sort_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
static void gtk2hs_store_set_default_sort_func (GtkTreeSortable *sortable,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy);
static gboolean gtk2hs_store_has_default_sort_func (GtkTreeSortable *sortable);
static gboolean gtk2hs_store_row_draggable (GtkTreeDragSource *drag_source,
GtkTreePath *path);
static gboolean gtk2hs_store_drag_data_get (GtkTreeDragSource *drag_source,
GtkTreePath *path,
GtkSelectionData *selection_data);
static gboolean gtk2hs_store_drag_data_delete (GtkTreeDragSource *drag_source,
GtkTreePath *path);
static gboolean gtk2hs_store_drag_data_received (GtkTreeDragDest *drag_dest,
GtkTreePath *dest_path,
GtkSelectionData *selection_data);
static gboolean gtk2hs_store_row_drop_possible (GtkTreeDragDest *drag_dest,
GtkTreePath *dest_path,
GtkSelectionData *selection_data);
static GObjectClass *parent_class = NULL;
/**
*
* gtk2hs_store_get_type: here we register our new type and its interfaces
* with the type system. If you want to implement
* additional interfaces like GtkTreeSortable, you
* will need to do it here.
*
**/
GType
gtk2hs_store_get_type (void)
{
static GType gtk2hs_store_type = 0;
if (!gtk2hs_store_type)
{
static const GTypeInfo gtk2hs_store_info =
{
sizeof (Gtk2HsStoreClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) gtk2hs_store_class_init,
NULL, /* class finalize */
NULL, /* class_data */
sizeof (Gtk2HsStore),
0, /* n_preallocs */
(GInstanceInitFunc) gtk2hs_store_init
};
static const GInterfaceInfo tree_model_info =
{
(GInterfaceInitFunc) gtk2hs_store_tree_model_init,
NULL,
NULL
};
/* The TreeSortable interface is currently not implemented. */
static const GInterfaceInfo tree_sortable_info =
{
(GInterfaceInitFunc) gtk2hs_store_tree_sortable_init,
NULL,
NULL
};
static const GInterfaceInfo tree_drag_source_info =
{
(GInterfaceInitFunc) gtk2hs_store_tree_drag_source_init,
NULL,
NULL
};
static const GInterfaceInfo tree_drag_dest_info =
{
(GInterfaceInitFunc) gtk2hs_store_tree_drag_dest_init,
NULL,
NULL
};
gtk2hs_store_type = g_type_register_static (G_TYPE_OBJECT, "Gtk2HsStore",
>k2hs_store_info,
(GTypeFlags) 0);
g_type_add_interface_static (gtk2hs_store_type, GTK_TYPE_TREE_MODEL,
&tree_model_info);
/* The TreeSortable interface is currently not implemented. Uncomment to
add it. */
/* g_type_add_interface_static (gtk2hs_store_type,
GTK_TYPE_TREE_SORTABLE,
&tree_sortable_info);
*/
g_type_add_interface_static (gtk2hs_store_type,
GTK_TYPE_TREE_DRAG_SOURCE,
&tree_drag_source_info);
g_type_add_interface_static (gtk2hs_store_type,
GTK_TYPE_TREE_DRAG_DEST,
&tree_drag_dest_info);
}
return gtk2hs_store_type;
}
/**
*
* gtk2hs_store_class_init: more boilerplate GObject/GType stuff.
* Init callback for the type system,
* called once when our new class is created.
*
**/
static void
gtk2hs_store_class_init (Gtk2HsStoreClass *class)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_class_init\t\t(%p)\n", class));
GObjectClass *object_class;
parent_class = g_type_class_peek_parent (class);
object_class = (GObjectClass*) class;
object_class->finalize = gtk2hs_store_finalize;
}
/**
*
* gtk2hs_store_tree_model_init: init callback for the interface registration
* in gtk2hs_store_get_type. Here we override
* the GtkTreeModel interface functions that
* we implement.
*
**/
static void
gtk2hs_store_tree_model_init (GtkTreeModelIface *iface)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_tree_model_init\t(%p)\n", iface));
iface->get_flags = gtk2hs_store_get_flags;
iface->get_n_columns = gtk2hs_store_get_n_columns;
iface->get_column_type = gtk2hs_store_get_column_type;
iface->get_iter = gtk2hs_store_get_iter;
iface->get_path = gtk2hs_store_get_path;
iface->get_value = gtk2hs_store_get_value;
iface->iter_next = gtk2hs_store_iter_next;
iface->iter_children = gtk2hs_store_iter_children;
iface->iter_has_child = gtk2hs_store_iter_has_child;
iface->iter_n_children = gtk2hs_store_iter_n_children;
iface->iter_nth_child = gtk2hs_store_iter_nth_child;
iface->iter_parent = gtk2hs_store_iter_parent;
iface->ref_node = gtk2hs_store_ref_node;
iface->unref_node = gtk2hs_store_unref_node;
}
/**
*
* gtk2hs_store_tree_sortable_init: init callback for the interface registration
* in gtk2hs_store_get_type. Here we override
* the GtkTreeSortable interface functions that
* we implement.
*
**/
/* The TreeSortable interface is currently not implemented. */
static void
gtk2hs_store_tree_sortable_init (GtkTreeSortableIface *iface)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_tree_sortable_init\t(%p)\n", iface));
iface->get_sort_column_id = gtk2hs_store_get_sort_column_id;
iface->set_sort_column_id = gtk2hs_store_set_sort_column_id;
iface->set_sort_func = gtk2hs_store_set_sort_func;
iface->set_default_sort_func = gtk2hs_store_set_default_sort_func;
iface->has_default_sort_func = gtk2hs_store_has_default_sort_func;
}
/**
*
* gtk2hs_store_tree_drag_source_init: init callback for the interface registration
* in gtk2hs_store_get_type. Here we override
* the GtkTreeDragSource interface functions that
* we implement.
*
**/
static void
gtk2hs_store_tree_drag_source_init (GtkTreeDragSourceIface *iface)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_tree_drag_source_init\t(%p)\n", iface));
iface->row_draggable = gtk2hs_store_row_draggable;
iface->drag_data_get = gtk2hs_store_drag_data_get;
iface->drag_data_delete = gtk2hs_store_drag_data_delete;
}
/**
*
* gtk2hs_store_tree_drag_dest_init: init callback for the interface registration
* in gtk2hs_store_get_type. Here we override
* the GtkTreeDragDest interface functions that
* we implement.
*
**/
static void
gtk2hs_store_tree_drag_dest_init (GtkTreeDragDestIface *iface)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_tree_drag_dest_init\t(%p)\n", iface));
iface->drag_data_received = gtk2hs_store_drag_data_received;
iface->row_drop_possible = gtk2hs_store_row_drop_possible;
}
/**
*
* gtk2hs_store_init: this is called everytime a new custom list object
* instance is created (we do that in gtk2hs_store_new).
* Initialise the list structure's fields here.
*
**/
static void
gtk2hs_store_init (Gtk2HsStore *store)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_init\t\t(%p)\n", store));
store->stamp = g_random_int(); /* Random int to check whether an iter belongs to our model */
}
/**
*
* gtk2hs_store_finalize: this is called just before a custom list is
* destroyed. Free dynamically allocated memory here.
*
**/
static void
gtk2hs_store_finalize (GObject *object)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_finalize\t(%p)\n", object));
Gtk2HsStore *store = (Gtk2HsStore *) object;
g_return_if_fail(GTK2HS_IS_STORE (object));
/* free all memory used by the store */
hs_free_stable_ptr(store->impl);
hs_free_stable_ptr(store->priv);
/* must chain up - finalize parent */
(* parent_class->finalize) (object);
}
/**
*
* gtk2hs_store_get_flags: tells the rest of the world whether our tree model
* has any special characteristics. In our case,
* we have a list model (instead of a tree), and each
* tree iter is valid as long as the row in question
* exists, as it only contains a pointer to our struct.
*
**/
static GtkTreeModelFlags
gtk2hs_store_get_flags (GtkTreeModel *tree_model)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_get_flags\t\t(%p)\n", tree_model));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), 0);
GtkTreeModelFlags result = gtk2hs_store_get_flags_impl(store->impl);
WHEN_DEBUG(g_debug("return gtk2hs_store_get_flags\t\t=%#x\n", result));
return result;
}
/**
*
* gtk2hs_store_get_n_columns: tells the rest of the world how many data
* columns we export via the tree model interface
*
**/
static gint
gtk2hs_store_get_n_columns (GtkTreeModel *tree_model)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_get_n_columns\t(%p)\n", tree_model));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), 0);
gint result = gtk2hs_store_get_n_columns_impl(store->impl);
WHEN_DEBUG(g_debug("return gtk2hs_store_get_n_columns\t=%d\n", result));
return result;
}
/**
*
* gtk2hs_store_get_column_type: tells the rest of the world which type of
* data an exported model column contains
*
**/
static GType
gtk2hs_store_get_column_type (GtkTreeModel *tree_model,
gint index)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_get_column_type\t(%p, %d)\n", tree_model, index));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), G_TYPE_INVALID);
GType result = gtk2hs_store_get_column_type_impl(store->impl, index);
WHEN_DEBUG(g_debug("return gtk2hs_store_get_column_type\t=%s\n", g_type_name(result)));
return result;
}
/**
*
* gtk2hs_store_get_iter: converts a tree path (physical position) into a
* tree iter structure (the content of the iter
* fields will only be used internally by our model).
*
**/
static gboolean
gtk2hs_store_get_iter (GtkTreeModel *tree_model,
GtkTreeIter *iter, /* out */
GtkTreePath *path /* in */)
{
WHEN_DEBUG(
gchar *path_str = gtk_tree_path_to_string(path);
g_debug("calling gtk2hs_store_get_iter\t\t(%p, %p, \"%s\")\n", tree_model, iter, path_str);
g_free(path_str);
)
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), FALSE);
gboolean result = gtk2hs_store_get_iter_impl(store->impl, iter, path);
if (result) iter->stamp = store->stamp;
WHEN_DEBUG(g_debug("return gtk2hs_store_get_iter\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
/**
*
* gtk2hs_store_get_path: converts a tree iter into a tree path (ie. the
* physical position of that row in the list).
*
**/
static GtkTreePath *
gtk2hs_store_get_path (GtkTreeModel *tree_model,
GtkTreeIter *iter /* in */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_get_path\t\t(%p, %p)\n", tree_model, iter));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), NULL);
g_return_val_if_fail (iter->stamp == store->stamp, NULL);
GtkTreePath * result = gtk2hs_store_get_path_impl(store->impl, iter);
WHEN_DEBUG(
gchar *result_str = gtk_tree_path_to_string(result);
g_debug("return gtk2hs_store_get_path\t\t=\"%s\"\n", result_str);
g_free(result_str);
)
return result;
}
/**
*
* gtk2hs_store_get_value: Returns a row's exported data columns
* (_get_value is what gtk_tree_model_get uses)
*
**/
static void
gtk2hs_store_get_value (GtkTreeModel *tree_model,
GtkTreeIter *iter, /* in */
gint column,
GValue *value /* out */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_get_value\t\t(%p, %p, %d, %p)\n", tree_model, iter, column, value));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_if_fail (GTK2HS_IS_STORE (tree_model));
g_return_if_fail (iter->stamp == store->stamp);
gtk2hs_store_get_value_impl(store->impl, iter, column, value);
WHEN_DEBUG(
gchar *result = g_strdup_value_contents(value);
g_debug("return gtk2hs_store_get_value\t\t=%s\n", result);
g_free(result);
)
}
/**
*
* gtk2hs_store_iter_next: Takes an iter structure and sets it to point
* to the next row.
*
**/
static gboolean
gtk2hs_store_iter_next (GtkTreeModel *tree_model,
GtkTreeIter *iter /* in+out */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_iter_next\t\t(%p, %p)\n", tree_model, iter));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), FALSE);
g_return_val_if_fail (iter->stamp == store->stamp, FALSE);
gboolean result = gtk2hs_store_iter_next_impl(store->impl, iter);
if (result) iter->stamp = store->stamp;
WHEN_DEBUG(g_debug("return gtk2hs_store_iter_next\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
/**
*
* gtk2hs_store_iter_children: Returns TRUE or FALSE depending on whether
* the row specified by 'parent' has any children.
* If it has children, then 'iter' is set to
* point to the first child. Special case: if
* 'parent' is NULL, then the first top-level
* row should be returned if it exists.
*
**/
static gboolean
gtk2hs_store_iter_children (GtkTreeModel *tree_model,
GtkTreeIter *iter, /* out */
GtkTreeIter *parent /* in, maybe NULL */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_iter_children\t(%p, %p, %p)\n", tree_model, iter, parent));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), FALSE);
g_return_val_if_fail (parent == NULL || parent->stamp == store->stamp, FALSE);
gboolean result = gtk2hs_store_iter_children_impl(store->impl, iter, parent);
if (result) iter->stamp = store->stamp;
WHEN_DEBUG(g_debug("return gtk2hs_store_iter_children\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
/**
*
* gtk2hs_store_iter_has_child: Returns TRUE or FALSE depending on whether
* the row specified by 'iter' has any children.
*
**/
static gboolean
gtk2hs_store_iter_has_child (GtkTreeModel *tree_model,
GtkTreeIter *iter /* in */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_iter_has_child\t(%p, %p)\n", tree_model, iter));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), FALSE);
g_return_val_if_fail (iter->stamp == store->stamp, FALSE);
gboolean result = gtk2hs_store_iter_has_child_impl(store->impl, iter);
WHEN_DEBUG(g_debug("return gtk2hs_store_iter_has_child\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
/**
*
* gtk2hs_store_iter_n_children: Returns the number of children the row
* specified by 'iter' has. This is usually 0,
* as we only have a list and thus do not have
* any children to any rows. A special case is
* when 'iter' is NULL, in which case we need
* to return the number of top-level nodes,
* ie. the number of rows in our list.
*
**/
static gint
gtk2hs_store_iter_n_children (GtkTreeModel *tree_model,
GtkTreeIter *iter /* in, maybe NULL */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_iter_n_children\t(%p, %p)\n", tree_model, iter));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), 0);
g_return_val_if_fail (iter == NULL || iter->stamp == store->stamp, 0);
gboolean result = gtk2hs_store_iter_n_children_impl(store->impl, iter);
WHEN_DEBUG(g_debug("return gtk2hs_store_iter_n_children\t=%d\n", result));
return result;
}
/**
*
* gtk2hs_store_iter_nth_child: If the row specified by 'parent' has any
* children, set 'iter' to the n-th child and
* return TRUE if it exists, otherwise FALSE.
* A special case is when 'parent' is NULL, in
* which case we need to set 'iter' to the n-th
* row if it exists.
*
**/
static gboolean
gtk2hs_store_iter_nth_child (GtkTreeModel *tree_model,
GtkTreeIter *iter, /* out */
GtkTreeIter *parent, /* in, maybe NULL */
gint n)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_iter_nth_child\t(%p, %p, %p, %d)\n", tree_model, iter, parent, n));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), FALSE);
g_return_val_if_fail (parent == NULL || parent->stamp == store->stamp, FALSE);
gboolean result = gtk2hs_store_iter_nth_child_impl(store->impl, iter, parent, n);
if (result) iter->stamp = store->stamp;
WHEN_DEBUG(g_debug("return gtk2hs_store_iter_nth_child\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
/**
*
* gtk2hs_store_iter_parent: Point 'iter' to the parent node of 'child'.
*
**/
static gboolean
gtk2hs_store_iter_parent (GtkTreeModel *tree_model,
GtkTreeIter *iter, /* out */
GtkTreeIter *child /* in */)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_iter_parent\t\t(%p, %p, %p)\n", tree_model, iter, child));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_val_if_fail (GTK2HS_IS_STORE (tree_model), FALSE);
g_return_val_if_fail (child != NULL, FALSE);
g_return_val_if_fail (child->stamp == store->stamp, FALSE);
gboolean result = gtk2hs_store_iter_parent_impl(store->impl, iter, child);
if (result) iter->stamp = store->stamp;
WHEN_DEBUG(g_debug("return gtk2hs_store_iter_parent\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
static void
gtk2hs_store_ref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_ref_node\t\t(%p, %p)\n", tree_model, iter));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_if_fail (GTK2HS_IS_STORE (tree_model));
g_return_if_fail (iter->stamp == store->stamp);
gtk2hs_store_ref_node_impl(store->impl, iter);
}
static void
gtk2hs_store_unref_node (GtkTreeModel *tree_model,
GtkTreeIter *iter)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_unref_node\t\t(%p, %p)\n", tree_model, iter));
Gtk2HsStore *store = (Gtk2HsStore *) tree_model;
g_return_if_fail (GTK2HS_IS_STORE (tree_model));
g_return_if_fail (iter->stamp == store->stamp);
gtk2hs_store_unref_node_impl(store->impl, iter);
}
static gboolean
gtk2hs_store_get_sort_column_id (GtkTreeSortable *sortable,
gint *sort_column_id,
GtkSortType *order)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_get_sort_column_id\t\t(%p)\n", sortable));
return 0;
}
static void
gtk2hs_store_set_sort_column_id (GtkTreeSortable *sortable,
gint sort_column_id,
GtkSortType order)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_set_sort_column_id\t\t(%p)\n", sortable));
return;
}
static void
gtk2hs_store_set_sort_func (GtkTreeSortable *sortable,
gint sort_column_id,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_set_sort_func\t\t(%p)\n", sortable));
return;
}
static void
gtk2hs_store_set_default_sort_func (GtkTreeSortable *sortable,
GtkTreeIterCompareFunc func,
gpointer data,
GtkDestroyNotify destroy)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_set_default_sort_func\t\t(%p)\n", sortable));
return;
}
static gboolean
gtk2hs_store_has_default_sort_func (GtkTreeSortable *sortable)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_has_default_sort_func\t\t(%p)\n", sortable));
return 0;
}
static gboolean
gtk2hs_store_row_draggable (GtkTreeDragSource *drag_source,
GtkTreePath *path) {
WHEN_DEBUG(
gchar *path_str = gtk_tree_path_to_string(path);
g_debug("calling gtk2hs_store_row_draggable\t\t(%p, \"%s\")\n", drag_source, path_str);
g_free(path_str);
)
Gtk2HsStore *store = (Gtk2HsStore *) drag_source;
g_return_val_if_fail (GTK2HS_IS_STORE (drag_source), FALSE);
gboolean result = gtk2hs_store_row_draggable_impl(drag_source, store->impl, path);
WHEN_DEBUG(g_debug("return gtk2hs_store_row_draggable\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
static gboolean
gtk2hs_store_drag_data_get (GtkTreeDragSource *drag_source,
GtkTreePath *path,
GtkSelectionData *selection_data) {
WHEN_DEBUG(
gchar *path_str = gtk_tree_path_to_string(path);
g_debug("calling gtk2hs_store_drag_data_get\t\t(%p, \"%s\", %p)\n", drag_source, path_str, selection_data);
g_free(path_str);
)
Gtk2HsStore *store = (Gtk2HsStore *) drag_source;
g_return_val_if_fail (GTK2HS_IS_STORE (drag_source), FALSE);
g_return_val_if_fail (selection_data!=NULL, FALSE);
gboolean result = gtk2hs_store_drag_data_get_impl(drag_source, store->impl, path, selection_data);
WHEN_DEBUG(g_debug("return gtk2hs_store_drag_data_get\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
static gboolean
gtk2hs_store_drag_data_delete (GtkTreeDragSource *drag_source,
GtkTreePath *path) {
WHEN_DEBUG(
gchar *path_str = gtk_tree_path_to_string(path);
g_debug("calling gtk2hs_store_drag_data_delete\t\t(%p, \"%s\")\n", drag_source, path_str);
g_free(path_str);
)
Gtk2HsStore *store = (Gtk2HsStore *) drag_source;
g_return_val_if_fail (GTK2HS_IS_STORE (drag_source), FALSE);
gboolean result = gtk2hs_store_drag_data_delete_impl(drag_source, store->impl, path);
WHEN_DEBUG(g_debug("return gtk2hs_store_drag_data_delete\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
static gboolean
gtk2hs_store_drag_data_received (GtkTreeDragDest *drag_dest,
GtkTreePath *dest_path,
GtkSelectionData *selection_data) {
WHEN_DEBUG(
gchar *path_str = gtk_tree_path_to_string(dest_path);
g_debug("calling gtk2hs_store_drag_data_received\t\t(%p, \"%s\", %p)\n", drag_dest, path_str, selection_data);
g_free(path_str);
)
Gtk2HsStore *store = (Gtk2HsStore *) drag_dest;
g_return_val_if_fail (GTK2HS_IS_STORE (drag_dest), FALSE);
g_return_val_if_fail (selection_data!=NULL, FALSE);
gboolean result = gtk2hs_store_drag_data_received_impl(drag_dest, store->impl, dest_path, selection_data);
WHEN_DEBUG(g_debug("return gtk2hs_store_drag_data_received\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
static gboolean
gtk2hs_store_row_drop_possible (GtkTreeDragDest *drag_dest,
GtkTreePath *dest_path,
GtkSelectionData *selection_data) {
WHEN_DEBUG(
gchar *path_str = gtk_tree_path_to_string(dest_path);
g_debug("calling gtk2hs_store_row_drop_possible\t\t(%p, \"%s\", %p)\n", drag_dest, path_str, selection_data);
g_free(path_str);
)
Gtk2HsStore *store = (Gtk2HsStore *) drag_dest;
g_return_val_if_fail (GTK2HS_IS_STORE (drag_dest), FALSE);
g_return_val_if_fail (selection_data!=NULL, FALSE);
gboolean result = gtk2hs_store_row_drop_possible_impl(drag_dest, store->impl, dest_path, selection_data);
WHEN_DEBUG(g_debug("return gtk2hs_store_row_drop_possible\t\t=%s\n", result ? "TRUE" : "FALSE"));
return result;
}
/**
*
* gtk2hs_store_new: Create a new custom tree model which delegates to a
* Haskell implementation.
*
**/
Gtk2HsStore *
gtk2hs_store_new (HsStablePtr impl, HsStablePtr priv)
{
WHEN_DEBUG(g_debug("calling gtk2hs_store_new\t\t(%p)\n", impl));
Gtk2HsStore *newstore = (Gtk2HsStore*) g_object_new (GTK2HS_TYPE_STORE, NULL);
newstore->impl = impl;
newstore->priv = priv;
WHEN_DEBUG(g_debug("return gtk2hs_store_new\t\t=%p\n", newstore));
return newstore;
}
HsStablePtr gtk2hs_store_get_impl (Gtk2HsStore *store)
{
g_return_val_if_fail(GTK2HS_IS_STORE(store), NULL);
return store->impl;
}
HsStablePtr gtk2hs_store_get_priv (Gtk2HsStore *store)
{
g_return_val_if_fail(GTK2HS_IS_STORE(store), NULL);
return store->priv;
}
gint
gtk2hs_store_get_stamp (Gtk2HsStore *store)
{
g_return_val_if_fail(GTK2HS_IS_STORE(store), 0);
return store->stamp;
}
void
gtk2hs_store_increment_stamp (Gtk2HsStore *store)
{
g_return_if_fail(GTK2HS_IS_STORE(store));
do
{
store->stamp++;
}
while (store->stamp == 0);
}
|