/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */ /************************************************ rbgtktreestore.c - $Author: ggc $ $Date: 2007/07/10 08:07:15 $ Copyright (C) 2002-2006 Masao Mutoh ************************************************/ #include "global.h" #define _SELF(s) (GTK_TREE_STORE(RVAL2GOBJ(s))) static VALUE tstore_initialize(argc, argv, self) int argc; VALUE* argv; VALUE self; { gint cnt; GtkTreeStore* store; GType* buf; if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type."); buf = ALLOCA_N(GType, argc); for (cnt = 0; cnt < argc; cnt++) { buf[cnt] = CLASS2GTYPE(argv[cnt]); } store = gtk_tree_store_newv(argc, buf); G_INITIALIZE(self, store); return Qnil; } static VALUE tstore_set_column_types(argc, argv, self) int argc; VALUE* argv; VALUE self; { gint cnt; GType* buf; if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type."); buf = ALLOCA_N(GType, argc); for (cnt = 0; cnt < argc; cnt++) { buf[cnt] = CLASS2GTYPE(argv[cnt]); } gtk_tree_store_set_column_types(_SELF(self), argc, buf); return self; } static VALUE tstore_set_value(self, iter, column, value) VALUE self, iter, column, value; { GType gtype = gtk_tree_model_get_column_type(GTK_TREE_MODEL(RVAL2GOBJ(self)), NUM2INT(column)); GValue gval = {0,}; g_value_init(&gval, gtype); rbgobj_rvalue_to_gvalue(value, &gval); G_CHILD_ADD(self, iter); G_CHILD_ADD(iter, value); gtk_tree_store_set_value(_SELF(self), RVAL2GTKTREEITER(iter), NUM2INT(column), &gval); g_value_unset(&gval); return self; } /* void gtk_tree_store_set (GtkTreeStore *tree_store, GtkTreeIter *iter, ...); void gtk_tree_store_set_valist (GtkTreeStore *tree_store, GtkTreeIter *iter, va_list var_args); */ static VALUE tstore_remove(self, iter) VALUE self, iter; { G_CHILD_REMOVE(self, iter); #if GTK_CHECK_VERSION(2,2,0) return CBOOL2RVAL(gtk_tree_store_remove(_SELF(self), RVAL2GTKTREEITER(iter))); #else gtk_tree_store_remove(_SELF(self), RVAL2GTKTREEITER(iter)); return Qtrue; #endif } static VALUE tstore_insert(argc, argv, self) int argc; VALUE* argv; VALUE self; { VALUE parent, position, values, ret; GtkTreeIter iter; GtkTreeStore* model = _SELF(self); rb_scan_args(argc, argv, "21", &parent, &position, &values); if (NIL_P(values)){ gtk_tree_store_insert(model, &iter, NIL_P(parent) ? NULL : RVAL2GTKTREEITER(parent), NUM2INT(position)); iter.user_data3 = model; ret = GTKTREEITER2RVAL(&iter); G_CHILD_ADD(self, ret); } else { #if GTK_CHECK_VERSION(2,10,0) gint *c_columns; GValue *c_values; long size, i; size = NUM2INT(rb_funcall(values, rb_intern("size"), 0)); c_columns = ALLOCA_N(gint, size); c_values = ALLOCA_N(GValue, size); if(TYPE(values)==T_ARRAY) { for(i=0; i