Example #1
0
static VALUE
rg_match_set_cursor(VALUE self, VALUE tag, VALUE cursor)
{
    if (NIL_P(cursor) || RVAL2GTYPE(cursor) == GDK_TYPE_CURSOR) {
        vte_terminal_match_set_cursor(_SELF(self), NUM2INT(tag), RVAL2GDKCURSOR(cursor));
    } else if (RVAL2GTYPE(cursor) == GDK_TYPE_CURSOR_TYPE) {
        vte_terminal_match_set_cursor_type(_SELF(self), NUM2INT(tag), RVAL2GDKCURSORTYPE(cursor));
    } else {
        vte_terminal_match_set_cursor_name(_SELF(self), NUM2INT(tag), RVAL2CSTR(cursor));
    }

    return self;
}
Example #2
0
static VALUE
rg_match_set_cursor(VALUE self, VALUE tag, VALUE cursor)
{
    if (NIL_P(cursor) || RVAL2GTYPE(cursor) == GDK_TYPE_CURSOR) {
        vte_terminal_match_set_cursor(RVAL2TERM(self), NUM2INT(tag), RVAL2GOBJ(cursor));
    } else if (RVAL2GTYPE(cursor) == GDK_TYPE_CURSOR_TYPE) {
        vte_terminal_match_set_cursor_type(RVAL2TERM(self), NUM2INT(tag), RVAL2CT(cursor));
#if VTE_CHECK_VERSION(0, 17, 1)
    } else {
        vte_terminal_match_set_cursor_name(_SELF(self), NUM2INT(tag), RVAL2CSTR(cursor));
#endif
    }

    return self;
}
Example #3
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE points_or_rectangle, rbfill_rule;
    GdkRegion *region;

    rb_scan_args(argc, argv, "02", &points_or_rectangle, &rbfill_rule);
    if (NIL_P(points_or_rectangle)) {
        region = gdk_region_new();
    } else if (TYPE(points_or_rectangle) == T_ARRAY) {
        GdkFillRule fill_rule = RVAL2GENUM(rbfill_rule, GDK_TYPE_FILL_RULE);
        long n;
        GdkPoint *points = RVAL2GDKPOINTS(points_or_rectangle, &n);

        region = gdk_region_polygon(points, n, fill_rule);

        g_free(points);
    } else if (RVAL2GTYPE(points_or_rectangle) == GDK_TYPE_RECTANGLE) {
        region = gdk_region_rectangle((GdkRectangle*)RVAL2BOXED(points_or_rectangle, 
                                                                GDK_TYPE_RECTANGLE));
    } else {
        rb_raise(rb_eArgError, 
                 "invalid argument %s (expect array of Gdk::Point or Gdk::Rectangle, nil)",
                 rb_class2name(CLASS_OF(points_or_rectangle)));
    }

    G_INITIALIZE(self, region);

    return Qnil;
}
Example #4
0
gpointer
rbgobj_instance_from_ruby_object(VALUE obj)
{
    GType type;

    if (NIL_P(obj))
    	return NULL;

    type = RVAL2GTYPE(obj);
    if (rbgobj_convert_has_type(type)) {
        gpointer instance;
        if (rbgobj_convert_robj2instance(type, obj, &instance))
            return instance;
    }

    type = G_TYPE_FUNDAMENTAL(type);
    switch (type){
    case G_TYPE_OBJECT:
        return rbgobj_get_gobject(obj);
    case G_TYPE_PARAM:
        return rbgobj_get_param_spec(obj);
    default:
      {
        gpointer instance;
        if (!rbgobj_convert_robj2instance(type, obj, &instance)) {
            rb_raise(rb_eTypeError, "%s isn't supported",
                     rb_class2name(CLASS_OF(obj)));
        }
        return instance;
      }
    }
}
Example #5
0
static VALUE
rg_style_get_property(VALUE self, VALUE prop_name)
{
    GParamSpec* pspec = NULL;
    const char* name;

    if (SYMBOL_P(prop_name)) {
        name = rb_id2name(SYM2ID(prop_name));
    } else {
        name = RVAL2CSTR(prop_name);
    }
    pspec = gtk_widget_class_find_style_property((GtkWidgetClass*)g_type_class_ref(RVAL2GTYPE(self)), name);

    if (!pspec)
        rb_raise(rb_eval_string("GLib::NoPropertyError"), "No such property: %s", name);
    else {
        // FIXME: use rb_ensure to call g_value_unset()
        GValue gval = G_VALUE_INIT;
        VALUE ret;
        g_value_init(&gval, G_PARAM_SPEC_VALUE_TYPE(pspec));
        gtk_widget_style_get_property(GTK_WIDGET(RVAL2GOBJ(self)), name, &gval);
        ret = GVAL2RVAL(&gval);
        g_value_unset(&gval);
        return ret;
    }
}
Example #6
0
void
rbgobj_initialize_object(VALUE obj, gpointer cobj)
{
    GType type;
    GType parent_type;

    if (!cobj)
        rb_raise(rb_eRuntimeError, "failed to initialize");

    type = RVAL2GTYPE(obj);

    for (parent_type = type;
         parent_type != G_TYPE_INVALID;
         parent_type = g_type_parent(parent_type)) {

         if (rbgobj_convert_initialize(parent_type, obj, cobj))
             return;
    }

    type = G_TYPE_FUNDAMENTAL(type);
    switch (type){
    case G_TYPE_OBJECT:
        rbgobj_gobject_initialize(obj, cobj);
        break;
    case G_TYPE_PARAM:
        rbgobj_param_spec_initialize(obj, cobj);
        break;
    case G_TYPE_BOXED:
        rbgobj_boxed_initialize(obj, cobj);
        break;
    default:
        rbgobj_convert_initialize(type, obj, cobj);
    }
}
Example #7
0
static VALUE
rg_union(VALUE self, VALUE other)
{
    if (RVAL2GTYPE(other) == GDK_TYPE_RECTANGLE){
        gdk_region_union_with_rect(_SELF(self),
                                   (GdkRectangle*)RVAL2BOXED(other, GDK_TYPE_RECTANGLE));
    } else {
        gdk_region_union(_SELF(self), _SELF(other));
    }
    return self;
}
Example #8
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE image;
    GtkWidget *widget = NULL;

    rb_scan_args(argc, argv, "01", &image);
    if (NIL_P(image)) {
        widget = gtk_image_new();
    } else if (TYPE(image) == T_HASH) {
        VALUE stock, icon_name, icon_set, gicon, file, pixbuf, animation, size, buffer;
        rbg_scan_options(image,
                         "stock", &stock,
                         "icon_name", &icon_name,
                         "icon_set", &icon_set,
                         "gicon", &gicon,
                         "file", &file,
                         "pixbuf", &pixbuf,
                         "animation", &animation,
                         "size", &size,
                         NULL);

        if (!NIL_P(stock))
            widget = gtk_image_new_from_stock(RVAL2GLIBID(stock, buffer), RVAL2GTKICONSIZE(size));
        else if (!NIL_P(icon_name))
            widget = gtk_image_new_from_icon_name(RVAL2CSTR(icon_name), RVAL2GTKICONSIZE(size));
        else if (!NIL_P(icon_set))
            widget = gtk_image_new_from_icon_set(RVAL2GTKICONSET(icon_set), RVAL2GTKICONSIZE(size));
        else if (!NIL_P(gicon))
            widget = gtk_image_new_from_gicon(RVAL2GICON(gicon), RVAL2GTKICONSIZE(size));
        else if (!NIL_P(file))
            widget = gtk_image_new_from_file(RVAL2CSTR(file));
        else if (!NIL_P(pixbuf))
            widget = gtk_image_new_from_pixbuf(RVAL2GDKPIXBUF(pixbuf));
        else if (!NIL_P(animation))
            widget = gtk_image_new_from_animation(RVAL2GDKPIXBUFANIMATION(animation));
    } else {
        GType gtype = RVAL2GTYPE(image);

        if (gtype == GDK_TYPE_PIXBUF)
            widget = gtk_image_new_from_pixbuf(RVAL2GDKPIXBUF(image));
        else if (g_type_is_a(gtype, GDK_TYPE_PIXBUF_ANIMATION))
            widget = gtk_image_new_from_animation(RVAL2GDKPIXBUFANIMATION(image));
    }
    if (!widget)
        rb_raise(rb_eArgError, "Invalid arguments.");

    RBGTK_INITIALIZE(self, widget);

    return Qnil;
}
Example #9
0
static VALUE
rbclt_layout_manager_child_set_property (VALUE self, VALUE container, VALUE actor, VALUE property, VALUE value)
{
  ClutterLayoutManager *manager = CLUTTER_LAYOUT_MANAGER (RVAL2GOBJ (self));
  ClutterContainer *g_container = CLUTTER_CONTAINER (RVAL2GOBJ (container));
  ClutterActor *g_actor = CLUTTER_ACTOR (RVAL2GOBJ (actor));
  GValue g_value;
  g_value_init (&g_value, RVAL2GTYPE (value));

  rbgobj_rvalue_to_gvalue (value, &g_value);
  clutter_layout_manager_child_set_property (manager, g_container, g_actor, RVAL2CSTR (property), &g_value);
  g_value_unset (&g_value);
  return Qnil;
}
Example #10
0
static VALUE
settings_set_property_value(VALUE self, VALUE name, VALUE value, VALUE origin)
{
    GtkSettingsValue svalue = { NULL, { 0, }, };
    g_value_init(&svalue.value, RVAL2GTYPE(value));
    rbgobj_rvalue_to_gvalue(value, &svalue.value);

    svalue.origin = (char *)RVAL2CSTR(origin);
    gtk_settings_set_property_value(GTK_SETTINGS(RVAL2GOBJ(self)), 
                                    RVAL2CSTR(name), &svalue);
    g_value_unset(&svalue.value);

    return self;
}
Example #11
0
static VALUE
rg_set_current(VALUE self, VALUE value)
{
    GValue gval = G_VALUE_INIT;
    g_value_init(&gval, RVAL2GTYPE(value));

    rbgobj_rvalue_to_gvalue(value, &gval);

    if (! atk_value_set_current_value(_SELF(self), &gval)){
        rb_raise(rb_eRuntimeError, "Can't set the current value.");
    }

    return self;
}
static VALUE
value_array_from_ruby_body(VALUE value)
{
    long i;
    struct value_array_from_ruby_args *args = (struct value_array_from_ruby_args *)value;

    for (i = 0; i < args->n; i++) {
        GValue v = G_VALUE_INIT;

        g_value_init(&v, RVAL2GTYPE(RARRAY_PTR(args->ary)[i]));
        rbgobj_rvalue_to_gvalue(RARRAY_PTR(args->ary)[i], &v);

        g_value_array_append(args->result, &v);
    }

    return Qnil;
}
Example #13
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE arg1, arg2, arg3;
    GtkAdjustment *adj = NULL;
    GtkWidget *widget;

    rb_scan_args(argc, argv, "03", &arg1, &arg2, &arg3);

    if (NIL_P(arg1) || RVAL2GTYPE(arg1) == GTK_TYPE_ADJUSTMENT){
        if (!NIL_P(arg1)) adj = GTK_ADJUSTMENT(RVAL2GOBJ(arg1));
        widget = gtk_hscale_new(adj);
    } else {
        widget = gtk_hscale_new_with_range(NUM2DBL(arg1), 
                                           NUM2DBL(arg2), NUM2DBL(arg3));
    }
    RBGTK_INITIALIZE(self, widget);
    return Qnil;
}
Example #14
0
static VALUE
rbclt_model_do_action (VALUE arg)
{
    ActionData *data = (ActionData *) arg;
    ClutterModel *model = CLUTTER_MODEL (RVAL2GOBJ (data->self));
    int i;

    for (i = 0; i < data->argc / 2; i++)
    {
        data->colnums[i] = NUM2UINT (data->argv[i * 2]);
        g_value_init (data->gvalues + i, RVAL2GTYPE (data->argv[i * 2 + 1]));
        data->gvalues_inited++;
        rbgobj_rvalue_to_gvalue (data->argv[i * 2 + 1], data->gvalues + i);
    }

    switch (data->action)
    {
    case RBCLT_MODEL_APPEND:
        clutter_model_appendv (model, data->argc / 2, data->colnums,
                               data->gvalues);
        break;

    case RBCLT_MODEL_PREPEND:
        clutter_model_prependv (model, data->argc / 2, data->colnums,
                                data->gvalues);
        break;

    case RBCLT_MODEL_INSERT:
        clutter_model_insertv (model, data->row, data->argc / 2, data->colnums,
                               data->gvalues);
        break;

    case RBCLT_MODEL_INSERT_VALUE:
        clutter_model_insert_value (model, data->row, data->colnums[0],
                                    data->gvalues);
        break;
    }

    return data->self;
}
Example #15
0
static void
create_factory_entry(GtkItemFactoryEntry *entry, VALUE self, VALUE path, VALUE item_type, VALUE accel, VALUE extdata, VALUE func, VALUE data)
{
    VALUE action;

    entry->path = NIL_P(path) ? NULL : RVAL2CSTR(path);
    entry->item_type = NIL_P(item_type) ? "<Branch>" : RVAL2CSTR(item_type);
    entry->accelerator = NIL_P(accel) ? NULL : RVAL2CSTR(accel);
        
    if (menuitem_type_check(entry->item_type) == 0) {
        entry->callback = NULL;
    } else {
        if (NIL_P(func)) {
            entry->callback = NULL;
        } else {
            entry->callback = items_exec_callback_wrap;
        }
    }
    action = rb_ary_new3(2, func, data);
    G_RELATIVE(self, action);
    rb_hash_aset(action_table, UINT2NUM(action_id), action);
    entry->callback_action = action_id;
    action_id++;

    if (NIL_P(extdata)){
        entry->extra_data = NULL;
    } else if (TYPE(extdata) == T_STRING){
        entry->extra_data = RVAL2CSTR(extdata);
    } else if (TYPE(extdata) == T_SYMBOL){
        entry->extra_data = rb_id2name(SYM2ID(extdata));
    } else if (RVAL2GTYPE(extdata) == GDK_TYPE_PIXBUF){
        GdkPixdata pixdata;
        guint stream_length_p;
        gdk_pixdata_from_pixbuf(&pixdata, GDK_PIXBUF(RVAL2GOBJ(extdata)), TRUE);
        entry->extra_data = gdk_pixdata_serialize(&pixdata, &stream_length_p);
    } else {
        entry->extra_data = NULL;
    }
}  
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE color;
    GtkWidget* widget;

    rb_scan_args(argc, argv, "01", &color);

    if (NIL_P(color)){
        widget = gtk_color_button_new();
    } else {
        GType gtype = RVAL2GTYPE(color);

        if (gtype == GDK_TYPE_COLOR) {
            widget = gtk_color_button_new_with_color(RVAL2GDKCOLOR(color));
        } else {
            widget = gtk_color_button_new_with_rgba(RVAL2GDKRGBA(color));
        }
    }

    RBGTK_INITIALIZE(self, widget);
    return Qnil;
}
Example #17
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE arg1, arg2, arg3;
    GtkAdjustment *adj = NULL;
    gfloat climb_rate;
    gint digits;
    GtkWidget *widget;

    rb_scan_args(argc, argv, "03", &arg1, &arg2, &arg3);

    if (NIL_P(arg1) || RVAL2GTYPE(arg1) == GTK_TYPE_ADJUSTMENT){
        if (!NIL_P(arg1)) adj = GTK_ADJUSTMENT(RVAL2GOBJ(arg1));
        climb_rate = (NIL_P(arg2))? 0.0: NUM2DBL(arg2);
        digits     = (NIL_P(arg3))?   0: NUM2UINT(arg3);
        widget = gtk_spin_button_new(adj, climb_rate, digits);
    } else {
        widget = gtk_spin_button_new_with_range(NUM2DBL(arg1), 
                                                NUM2DBL(arg2), NUM2DBL(arg3));
    }
    RBGTK_INITIALIZE(self, widget);
    return Qnil;
}
Example #18
0
static VALUE
gobj_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE params_hash;
    GObject* gobj;
    
    rb_scan_args(argc, argv, "01", &params_hash);

    if (!NIL_P(params_hash))
        Check_Type(params_hash, T_HASH);

    gobj = rbgobj_gobject_new(RVAL2GTYPE(self), params_hash);

    if (is_gtkobject(gobj)){
        gobj = g_object_ref(gobj);
        // We can't call gtk_object_sink() here.
        // But hopefully someone will call it in the future.
        //gtk_object_sink(gobj);
    }

    G_INITIALIZE(self, gobj);
    return Qnil;
}
Example #19
0
static void
value_array_from_ruby(VALUE from, GValue* to)
{
    int i;
    GValueArray * array;

    if (NIL_P(from)) {
        g_value_set_boxed(to, NULL);
        return;
    }

    Check_Type(from, T_ARRAY);

    array = g_value_array_new(0);

    for (i = 0; i < RARRAY_LEN(from); i++) {
      GValue v = { 0, };
      g_value_init(&v, RVAL2GTYPE(RARRAY_PTR(from)[i]));
      rbgobj_rvalue_to_gvalue(RARRAY_PTR(from)[i], &v);
      g_value_array_append(array, &v);
    }
    g_value_set_boxed(to, array);
}
Example #20
0
static VALUE
rg_initialize(int argc, VALUE *argv, VALUE self)
{
    GType gtype;
    VALUE params_hash;
    GObject* gobj;

    gtype = CLASS2GTYPE(CLASS_OF(self));
    if (G_TYPE_IS_ABSTRACT(gtype)) {
        rb_raise(rb_eTypeError,
                 "initializing abstract class: %s",
                 RBG_INSPECT(CLASS_OF(self)));
    }

    rb_scan_args(argc, argv, "01", &params_hash);

    if (!NIL_P(params_hash))
        Check_Type(params_hash, RUBY_T_HASH);

    gobj = rbgobj_gobject_new(RVAL2GTYPE(self), params_hash);

    G_INITIALIZE(self, gobj);
    return Qnil;
}
Example #21
0
static VALUE
gdkregion_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE points_or_rectangle, fill_rule;
    GdkRegion* region;
    GdkPoint *gpoints;
    int i;

    rb_scan_args(argc, argv, "02", &points_or_rectangle, &fill_rule);
    if (NIL_P(points_or_rectangle)){
        region = gdk_region_new();
    } else if (TYPE(points_or_rectangle) == T_ARRAY){
        gpoints = ALLOCA_N(GdkPoint, RARRAY_LEN(points_or_rectangle));

        for (i = 0; i < RARRAY_LEN(points_or_rectangle); i++) {
            Check_Type(RARRAY_PTR(points_or_rectangle)[i], T_ARRAY);
            if (RARRAY_LEN(RARRAY_PTR(points_or_rectangle)[i]) < 2) {
                rb_raise(rb_eArgError, "point %d should be array of size 2", i);
            }
            gpoints[i].x = NUM2INT(RARRAY_PTR(RARRAY_PTR(points_or_rectangle)[i])[0]);
            gpoints[i].y = NUM2INT(RARRAY_PTR(RARRAY_PTR(points_or_rectangle)[i])[1]);
        }
        region = gdk_region_polygon(gpoints, RARRAY_LEN(points_or_rectangle),
                                    RVAL2GENUM(fill_rule, GDK_TYPE_FILL_RULE));
    } else if (RVAL2GTYPE(points_or_rectangle) == GDK_TYPE_RECTANGLE){
        region = gdk_region_rectangle((GdkRectangle*)RVAL2BOXED(points_or_rectangle, 
                                                                GDK_TYPE_RECTANGLE));
    } else {
        rb_raise(rb_eArgError, 
                 "invalid argument %s (expect array of Gdk::Point or Gdk::Rectangle, nil)",
                 rb_class2name(CLASS_OF(points_or_rectangle)));
    }

    G_INITIALIZE(self, region);
    return Qnil;
}