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

  rbgtkitemfactory.c -

  $Author: mutoh $
  $Date: 2005/07/30 10:24:57 $

  Copyright (C) 2002,2003 Ruby-GNOME2 Project Team
  Copyright (C) 1998-2000 <NAME>,
                          dellin,
                          <NAME>
************************************************/

#include "global.h"
#include <gdk-pixbuf/gdk-pixdata.h>

#define _SELF(self) (GTK_ITEM_FACTORY(RVAL2GOBJ(self)))
#define RVAL2WIDGET(w) (GTK_WIDGET(RVAL2GOBJ(w)))
#define RVAL2ACCEL(a)  (GTK_ACCEL_GROUP(RVAL2GOBJ(a)))

static VALUE action_table;
static guint action_id = 0;

static VALUE
ifact_initialize(self, type, path, accel)
    VALUE self;
    VALUE type, path, accel;
{
    VALUE obj = rb_eval_string("eval('self', binding)");
    G_RELATIVE(obj, self);
    RBGTK_INITIALIZE(self, gtk_item_factory_new(FIX2INT(type), RVAL2CSTR(path),
                                                RVAL2ACCEL(accel)));
   
    return Qnil;
}

static VALUE
ifact_construct(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    VALUE type, path, accel;
    GtkItemFactory* ifact = _SELF(self);
    ifact->accel_group = NULL;

    rb_scan_args(argc, argv, "21", &type, &path, &accel);
    gtk_item_factory_construct(ifact, FIX2INT(type), 
                               RVAL2CSTR(path), RVAL2ACCEL(accel));
    return self;
}
 
static VALUE
ifact_s_from_widget(self, widget)
    VALUE self, widget;
{
    VALUE obj = GOBJ2RVAL(gtk_item_factory_from_widget(RVAL2WIDGET(widget)));
    G_RELATIVE(obj, self);
    return obj;
}

static VALUE
ifact_s_path_from_widget(self, widget)
    VALUE self, widget;
{
    return CSTR2RVAL(gtk_item_factory_path_from_widget(RVAL2WIDGET(widget)));
}

static VALUE
ifact_get_item(self, path)
    VALUE self, path;
{
    VALUE obj = Qnil;
    GtkWidget* widget = gtk_item_factory_get_item(_SELF(self), RVAL2CSTR(path));
    if (widget){
        obj = GOBJ2RVAL(widget);
        G_RELATIVE(obj, self);
    }
    return obj;
}

static VALUE
ifact_get_widget(self, path)
    VALUE self, path;
{
    VALUE obj = Qnil;
    GtkWidget* widget = gtk_item_factory_get_widget(_SELF(self), RVAL2CSTR(path));
    if (widget){
        obj = GOBJ2RVAL(widget);
        G_RELATIVE(obj, self);
    }
    return obj;
}

/* We can't implement them because actions are always 1.
GtkWidget*  gtk_item_factory_get_widget_by_action
                                            (GtkItemFactory *ifactory,
                                             guint action);
GtkWidget*  gtk_item_factory_get_item_by_action
                                            (GtkItemFactory *ifactory,
                                             guint action);
*/

static int
menuitem_type_check(item_type)
    char *item_type;
{
    if (item_type == NULL || strcmp(item_type, "<Branch>") == 0 
        || (strcmp(item_type, "<LastBranch>") == 0)
        || (strcmp(item_type, "<Separator>") == 0))
        return 0;
    else 
        return -1;
}

static void
items_exec_callback_wrap(callback_data, action_id, widget)
    VALUE callback_data, action_id;
    GtkWidget* widget;
{
    VALUE iter, data;
    VALUE action = rb_hash_aref(action_table, UINT2NUM(action_id));

    iter = RARRAY(action)->ptr[0];
    data = RARRAY(action)->ptr[1];
    if (!NIL_P(iter)) {
        rb_funcall(iter, id_call, 2, data, GOBJ2RVAL(widget));
    }
}<commit_msg>* src/rbgtkitemfactory.c: Fix segfault on amd64.<commit_after>/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/************************************************

  rbgtkitemfactory.c -

  $Author: mutoh $
  $Date: 2005/07/30 16:24:53 $

  Copyright (C) 2002,2003 Ruby-GNOME2 Project Team
  Copyright (C) 1998-2000 <NAME>,
                          dellin,
                          <NAME>
************************************************/

#include "global.h"
#include <gdk-pixbuf/gdk-pixdata.h>

#define _SELF(self) (GTK_ITEM_FACTORY(RVAL2GOBJ(self)))
#define RVAL2WIDGET(w) (GTK_WIDGET(RVAL2GOBJ(w)))
#define RVAL2ACCEL(a)  (GTK_ACCEL_GROUP(RVAL2GOBJ(a)))

static VALUE action_table;
static guint action_id = 0;

static VALUE
ifact_initialize(self, type, path, accel)
    VALUE self;
    VALUE type, path, accel;
{
    VALUE obj = rb_eval_string("eval('self', binding)");
    G_RELATIVE(obj, self);
    RBGTK_INITIALIZE(self, gtk_item_factory_new(FIX2INT(type), RVAL2CSTR(path),
                                                RVAL2ACCEL(accel)));
   
    return Qnil;
}

static VALUE
ifact_construct(argc, argv, self)
    int argc;
    VALUE *argv;
    VALUE self;
{
    VALUE type, path, accel;
    GtkItemFactory* ifact = _SELF(self);
    ifact->accel_group = NULL;

    rb_scan_args(argc, argv, "21", &type, &path, &accel);
    gtk_item_factory_construct(ifact, FIX2INT(type), 
                               RVAL2CSTR(path), RVAL2ACCEL(accel));
    return self;
}
 
static VALUE
ifact_s_from_widget(self, widget)
    VALUE self, widget;
{
    VALUE obj = GOBJ2RVAL(gtk_item_factory_from_widget(RVAL2WIDGET(widget)));
    G_RELATIVE(obj, self);
    return obj;
}

static VALUE
ifact_s_path_from_widget(self, widget)
    VALUE self, widget;
{
    return CSTR2RVAL(gtk_item_factory_path_from_widget(RVAL2WIDGET(widget)));
}

static VALUE
ifact_get_item(self, path)
    VALUE self, path;
{
    VALUE obj = Qnil;
    GtkWidget* widget = gtk_item_factory_get_item(_SELF(self), RVAL2CSTR(path));
    if (widget){
        obj = GOBJ2RVAL(widget);
        G_RELATIVE(obj, self);
    }
    return obj;
}

static VALUE
ifact_get_widget(self, path)
    VALUE self, path;
{
    VALUE obj = Qnil;
    GtkWidget* widget = gtk_item_factory_get_widget(_SELF(self), RVAL2CSTR(path));
    if (widget){
        obj = GOBJ2RVAL(widget);
        G_RELATIVE(obj, self);
    }
    return obj;
}

/* We can't implement them because actions are always 1.
GtkWidget*  gtk_item_factory_get_widget_by_action
                                            (GtkItemFactory *ifactory,
                                             guint action);
GtkWidget*  gtk_item_factory_get_item_by_action
                                            (GtkItemFactory *ifactory,
                                             guint action);
*/

static int
menuitem_type_check(item_type)
    char *item_type;
{
    if (item_type == NULL || strcmp(item_type, "<Branch>") == 0 
        || (strcmp(item_type, "<LastBranch>") == 0)
        || (strcmp(item_type, "<Separator>") == 0))
        return 0;
    else 
        return -1;
}

static void
items_exec_callback_wrap(callback_data, action_id, widget)
    VALUE callback_data;
    guint action_id;
    GtkWidget* widget;
{
    VALUE iter, data;
    VALUE action = rb_hash_aref(action_table, UINT2NUM(action_id));

    iter = RARRAY(action)->ptr[0];
    data = RARRAY(action)->ptr[1];
    if (!NIL_P(iter)) {
        rb_funcall(iter, id_call, 2, data, GOBJ2RVAL(widget));
    }
}
{'fraction_non_alphanumeric': 0.14260994953136266, 'fraction_numerical': 0.018745493871665464, 'mean_word_length': 2.7736670293797605, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6480858', 'n_tokens_mistral': 2524, 'n_tokens_neox': 2383, 'n_words': 480}