<commit_before>/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/************************************************

  rbgtktreeviewcolumn.c -

  $Author: mutoh $
  $Date: 2003/01/19 14:28:25 $

  Copyright (C) 2002,2003 <NAME>
************************************************/

#include "global.h"

#define _SELF(s) (GTK_TREE_VIEW_COLUMN(RVAL2GOBJ(s)))
#define RVAL2CELLRENDERER(c) (GTK_CELL_RENDERER(RVAL2GOBJ(c)))

static VALUE
tvc_initialize(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    int i;
    int col;
    GtkTreeViewColumn* tvc;
    GtkCellRenderer* renderer;
    gchar* name;
    VALUE ary, val;
 
    tvc = gtk_tree_view_column_new();
    if (argc > 1){
        gtk_tree_view_column_set_title(tvc, RVAL2CSTR(argv[0]));
        gtk_tree_view_column_pack_start(tvc, RVAL2CELLRENDERER(argv[1]), TRUE);
    }

    RBGTK_INITIALIZE(self, tvc);

    if (argc == 3){
        ary = rb_funcall(argv[2], rb_intern("to_a"), 0);
        renderer = RVAL2CELLRENDERER(argv[1]);
        for (i = 0; i < RARRAY(ary)->len; i++) {
            val = RARRAY(RARRAY(ary)->ptr[i])->ptr[0];
            if (SYMBOL_P(val)) {
                name = rb_id2name(SYM2ID(val));
            } else {
                name = RVAL2CSTR(val);
            }
            col = NUM2INT(RARRAY(RARRAY(ary)->ptr[i])->ptr[1]);
            gtk_tree_view_column_add_attribute(_SELF(self), renderer, name, col);
        }       
    }

    return Qnil;
}

static VALUE
tvc_pack_start(self, cell, expand)
    VALUE self, cell, expand;
{
    gtk_tree_view_column_pack_start(_SELF(self), RVAL2CELLRENDERER(cell), RTEST(expand));
    return self;
}

static VALUE
tvc_pack_end(self, cell, expand)
    VALUE self, cell, expand;
{
    gtk_tree_view_column_pack_end(_SELF(self), RVAL2CELLRENDERER(cell), RTEST(expand));
    return self;
}

static VALUE
tvc_clear(self)
    VALUE self;
{
    gtk_tree_view_column_clear(_SELF(self));
    return self;
}

static VALUE
tvc_get_cell_renderers(self)
    VALUE self;
{
    return GLIST2ARY(gtk_tree_view_column_get_cell_renderers(_SELF(self)));
}

static VALUE
tvc_add_attribute(self, cell, attribute, column)
    VALUE self, cell, attribute, column;
{
    gtk_tree_view_column_add_attribute(_SELF(self), RVAL2CELLRENDERER(cell), 
                                       RVAL2CSTR(attribute), NUM2INT(column));
    return self;
}

/* XXX
   void        gtk_tree_view_column_set_attributes
   (GtkTreeViewColumn *tree_column,
   GtkCellRenderer *cell_renderer,
   ...);
*/
static void
cell_data_func(tree_column, cell, model, iter, func)
    GtkTreeViewColumn* tree_column;
    GtkCellRenderer*   cell;
    GtkTreeModel*      model;
    GtkTreeIter*       iter;
    gpointer           func;
{
    iter->user_data3 = model;
    rb_funcall((VALUE)func, id_call, 4, GOBJ2RVAL(tree_column),
               GOBJ2RVAL(cell), GOBJ2RVAL(model), 
               BOXED2RVAL(iter, GTK_TYPE_TREE_ITER));
}

static VALUE
tvc_set_cell_data_func(self, renderer)
    VALUE self, renderer;
{
    VALUE func = rb_f_lambda();
    G_RELATIVE(self, func);
    gtk_tree_view_column_set_cell_data_func(_SELF(self), RVAL2CELLRENDERER(renderer),
                                            cell_data_func, (gpointer)func, NULL);
    return self;
}

static VALUE
tvc_clear_attributes(self, cell)
    VALUE self, cell;
{
    gtk_tree_view_column_clear_attributes(_SELF(self), RVAL2CELLRENDERER(cell));
    return self;
}

static VALUE
tvc_set_spacing(self, spacing)
    VALUE self, spacing;
{
    gtk_tree_view_column_set_spacing(_SELF(self), NUM2INT(spacing));
    return self;
}

static VALUE
tvc_get_spacing(self)
    VALUE self;
{
    return INT2NUM(gtk_tree_view_column_get_spacing(_SELF(self)));
}

static VALUE
tvc_clicked(self)
    VALUE self;
{
    gtk_tree_view_column_clicked(_SELF(self));
    return self;
}

static VALUE
tvc_set_sort_column_id(self, sort_column_id)
    VALUE self, sort_column_id;
{
    gtk_tree_view_column_set_sort_column_id(_SELF(self), 
                                            NUM2INT(sort_column_id));
    return self;
}

static VALUE
tvc_get_sort_column_id(self)
    VALUE self;
{
    return gtk_tree_view_column_get_sort_column_id(_SELF(self));
}

static VALUE
tvc_cell_set_cell_data(self, model, iter, is_expander, is_expanded)
    VALUE self, model, iter, is_expander, is_expanded;
{<commit_msg>fixed the return convertion of Gtk::TreeViewColumn#sort_column_id.<commit_after>/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/************************************************

  rbgtktreeviewcolumn.c -

  $Author: pcppopper $
  $Date: 2003/03/26 17:19:33 $

  Copyright (C) 2002,2003 <NAME>
************************************************/

#include "global.h"

#define _SELF(s) (GTK_TREE_VIEW_COLUMN(RVAL2GOBJ(s)))
#define RVAL2CELLRENDERER(c) (GTK_CELL_RENDERER(RVAL2GOBJ(c)))

static VALUE
tvc_initialize(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    int i;
    int col;
    GtkTreeViewColumn* tvc;
    GtkCellRenderer* renderer;
    gchar* name;
    VALUE ary, val;
 
    tvc = gtk_tree_view_column_new();
    if (argc > 1){
        gtk_tree_view_column_set_title(tvc, RVAL2CSTR(argv[0]));
        gtk_tree_view_column_pack_start(tvc, RVAL2CELLRENDERER(argv[1]), TRUE);
    }

    RBGTK_INITIALIZE(self, tvc);

    if (argc == 3){
        ary = rb_funcall(argv[2], rb_intern("to_a"), 0);
        renderer = RVAL2CELLRENDERER(argv[1]);
        for (i = 0; i < RARRAY(ary)->len; i++) {
            val = RARRAY(RARRAY(ary)->ptr[i])->ptr[0];
            if (SYMBOL_P(val)) {
                name = rb_id2name(SYM2ID(val));
            } else {
                name = RVAL2CSTR(val);
            }
            col = NUM2INT(RARRAY(RARRAY(ary)->ptr[i])->ptr[1]);
            gtk_tree_view_column_add_attribute(_SELF(self), renderer, name, col);
        }       
    }

    return Qnil;
}

static VALUE
tvc_pack_start(self, cell, expand)
    VALUE self, cell, expand;
{
    gtk_tree_view_column_pack_start(_SELF(self), RVAL2CELLRENDERER(cell), RTEST(expand));
    return self;
}

static VALUE
tvc_pack_end(self, cell, expand)
    VALUE self, cell, expand;
{
    gtk_tree_view_column_pack_end(_SELF(self), RVAL2CELLRENDERER(cell), RTEST(expand));
    return self;
}

static VALUE
tvc_clear(self)
    VALUE self;
{
    gtk_tree_view_column_clear(_SELF(self));
    return self;
}

static VALUE
tvc_get_cell_renderers(self)
    VALUE self;
{
    return GLIST2ARY(gtk_tree_view_column_get_cell_renderers(_SELF(self)));
}

static VALUE
tvc_add_attribute(self, cell, attribute, column)
    VALUE self, cell, attribute, column;
{
    gtk_tree_view_column_add_attribute(_SELF(self), RVAL2CELLRENDERER(cell), 
                                       RVAL2CSTR(attribute), NUM2INT(column));
    return self;
}

/* XXX
   void        gtk_tree_view_column_set_attributes
   (GtkTreeViewColumn *tree_column,
   GtkCellRenderer *cell_renderer,
   ...);
*/
static void
cell_data_func(tree_column, cell, model, iter, func)
    GtkTreeViewColumn* tree_column;
    GtkCellRenderer*   cell;
    GtkTreeModel*      model;
    GtkTreeIter*       iter;
    gpointer           func;
{
    iter->user_data3 = model;
    rb_funcall((VALUE)func, id_call, 4, GOBJ2RVAL(tree_column),
               GOBJ2RVAL(cell), GOBJ2RVAL(model), 
               BOXED2RVAL(iter, GTK_TYPE_TREE_ITER));
}

static VALUE
tvc_set_cell_data_func(self, renderer)
    VALUE self, renderer;
{
    VALUE func = rb_f_lambda();
    G_RELATIVE(self, func);
    gtk_tree_view_column_set_cell_data_func(_SELF(self), RVAL2CELLRENDERER(renderer),
                                            cell_data_func, (gpointer)func, NULL);
    return self;
}

static VALUE
tvc_clear_attributes(self, cell)
    VALUE self, cell;
{
    gtk_tree_view_column_clear_attributes(_SELF(self), RVAL2CELLRENDERER(cell));
    return self;
}

static VALUE
tvc_set_spacing(self, spacing)
    VALUE self, spacing;
{
    gtk_tree_view_column_set_spacing(_SELF(self), NUM2INT(spacing));
    return self;
}

static VALUE
tvc_get_spacing(self)
    VALUE self;
{
    return INT2NUM(gtk_tree_view_column_get_spacing(_SELF(self)));
}

static VALUE
tvc_clicked(self)
    VALUE self;
{
    gtk_tree_view_column_clicked(_SELF(self));
    return self;
}

static VALUE
tvc_set_sort_column_id(self, sort_column_id)
    VALUE self, sort_column_id;
{
    gtk_tree_view_column_set_sort_column_id(_SELF(self), 
                                            NUM2INT(sort_column_id));
    return self;
}

static VALUE
tvc_get_sort_column_id(self)
    VALUE self;
{
    return INT2NUM(gtk_tree_view_column_get_sort_column_id(_SELF(self)));
}

static VALUE
tvc_cell_set_cell_data(self, model, iter, is_expander, is_expanded)
    VALUE self, model, iter, is_expander, is_expanded;
{
{'fraction_non_alphanumeric': 0.13130851792646722, 'fraction_numerical': 0.013587577072390956, 'mean_word_length': 3.4081529944640163, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6174885', 'n_tokens_mistral': 3388, 'n_tokens_neox': 3220, 'n_words': 549}