やすしです。

%rubyで話にでたので書いてみました。APIがへぼいので、なんだかなぁ〜ですが
一応投げておきます。

こういうただの structってどう扱うべきなんでしょうか?

# イソキチ様に捧げます(笑)
--
             yashi

diff -u --new-file --recursive gtk/src/rbgdk.c gtk.new/src/rbgdk.c --- gtk/src/rbgdk.c Thu Mar 30 15:52:46 2000 +++ gtk.new/src/rbgdk.c Wed Apr 26 00:38:52 2000 @@ -807,6 +807,7 @@ extern void Init_gtk_gdk_region(); extern void Init_gtk_gdk_rgb(); extern void Init_gtk_gdk_window(); +extern void Init_gtk_gdk_geometry(); extern void Init_gtk_gdkkeysyms(); void @@ -826,8 +827,9 @@ Init_gtk_gdk_draw(); /* Gdk::Pixmap, Gdk::Bitmap */ Init_gtk_gdk_pixmap(); - /* Gdk::Window, Gdk::WindowAttr */ + /* Gdk::Window, Gdk::WindowAttr, Gdk::Geometry */ Init_gtk_gdk_window(); + Init_gtk_gdk_geometry(); /* Gdk::Point, Gdk::Rectangle, Gdk::Region */ Init_gtk_gdk_region(); /* Gdk::Cursor */ diff -u --new-file --recursive gtk/src/rbgdkconst.c gtk.new/src/rbgdkconst.c --- gtk/src/rbgdkconst.c Thu Mar 30 15:52:46 2000 +++ gtk.new/src/rbgdkconst.c Wed Apr 26 00:10:08 2000 @@ -65,11 +65,6 @@ rb_define_const(mGdk, "WA_WMCLASS", INT2FIX(GDK_WA_WMCLASS)); rb_define_const(mGdk, "WA_NOREDIR", INT2FIX(GDK_WA_NOREDIR)); - /* GdkWindowHints */ - rb_define_const(mGdk, "HINT_POS", INT2FIX(GDK_HINT_POS)); - rb_define_const(mGdk, "HINT_MIN_SIZE", INT2FIX(GDK_HINT_MIN_SIZE)); - rb_define_const(mGdk, "HINT_MAX_SIZE", INT2FIX(GDK_HINT_MAX_SIZE)); - /* GdkFunction */ rb_define_const(mGdk, "COPY", INT2FIX(GDK_COPY)); rb_define_const(mGdk, "INVERT", INT2FIX(GDK_INVERT)); diff -u --new-file --recursive gtk/src/rbgdkwindow.c gtk.new/src/rbgdkwindow.c --- gtk/src/rbgdkwindow.c Thu Mar 30 16:17:43 2000 +++ gtk.new/src/rbgdkwindow.c Wed Apr 26 02:33:16 2000 @@ -228,6 +228,22 @@ return self; } +static VALUE +gdkwin_get_geometry(self) + VALUE self; +{ + VALUE ary = rb_ary_new2(5); + int i; + gint *val[5]; + + gdk_window_get_geometry(get_gdkwindow(self), val[0], val[1], + val[2], val[3], val[4]); + + for (i=0; i<5; i++) + rb_ary_store(ary, i, INT2FIX(val[i])); + + return ary; +} /* * Gdk::WindowAttr @@ -267,8 +283,325 @@ rb_define_method(gdkWindow, "get_events", gdkwin_get_events, 0); rb_define_method(gdkWindow, "set_events", gdkwin_set_events, 1); rb_define_method(gdkWindow, "reparent", gdkwin_reparent, 3); + rb_define_method(gdkWindow, "get_geometry", gdkwin_get_geometry, 0); + + /* GdkWindowHints */ + rb_define_const(gdkWindow, "HINT_POS", INT2FIX(GDK_HINT_POS)); + rb_define_const(gdkWindow, "HINT_MIN_SIZE", INT2FIX(GDK_HINT_MIN_SIZE)); + rb_define_const(gdkWindow, "HINT_MAX_SIZE", INT2FIX(GDK_HINT_MAX_SIZE)); + rb_define_const(gdkWindow, "HINT_BASE_SIZE", INT2FIX(GDK_HINT_BASE_SIZE)); + rb_define_const(gdkWindow, "HINT_ASPECT", INT2FIX(GDK_HINT_ASPECT)); + rb_define_const(gdkWindow, "HINT_RESIZE_INC", INT2FIX(GDK_HINT_RESIZE_INC)); /* Gdk::WindowAttr */ gdkWindowAttr = rb_define_class_under(mGdk, "WindowAttr", rb_cData); +} + +/* + * Gdk::Geometry + */ + +VALUE gdkGeometry; + +GdkGeometry * +rbgdk_geometry_get(geo) + VALUE geo; +{ + GdkGeometry *ret; + + Data_Get_Struct(geo, GdkGeometry, ret); + return ret; +} + +VALUE +rbgdk_geometry_make(geo) + GdkGeometry *geo; +{ + VALUE obj; + + obj = Data_Wrap_Struct(gdkGeometry, 0, g_free, geo); + + return obj; +} + +static VALUE +geo_s_new(self) + VALUE self; +{ + VALUE obj; + GdkGeometry *geo; + + geo = g_new0(GdkGeometry, 1); + obj = rbgdk_geometry_make(geo); + + return obj; +} + +static VALUE +geo_min_width(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->min_width); +} + +static VALUE +geo_min_height(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->min_height); +} + +static VALUE +geo_max_width(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->max_width); +} + +static VALUE +geo_max_height(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->max_height); +} + +static VALUE +geo_base_width(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->base_width); +} + +static VALUE +geo_base_height(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->base_height); +} + +static VALUE +geo_width_inc(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->width_inc); +} + +static VALUE +geo_height_inc(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return INT2NUM(geo->height_inc); +} + +static VALUE +geo_min_aspect(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return rb_float_new(geo->min_aspect); +} + +static VALUE +geo_max_aspect(self) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + return rb_float_new(geo->max_aspect); +} + +static VALUE +geo_set(self, min_width, min_height, max_width, max_height, + base_width, base_height, width_inc, height_inc, min_aspect, max_aspect) + VALUE self, + min_width, min_height, max_width, max_height, + base_width, base_height, width_inc, height_inc, + min_aspect, max_aspect; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->min_width = NUM2INT(min_width); + geo->min_height = NUM2INT(min_height); + geo->max_width = NUM2INT(max_width); + geo->max_height = NUM2INT(max_height); + geo->base_width = NUM2INT(base_width); + geo->base_height = NUM2INT(base_height); + geo->width_inc = NUM2INT(width_inc); + geo->height_inc = NUM2INT(height_inc); + geo->min_aspect = NUM2DBL(min_aspect); + geo->max_aspect = NUM2DBL(max_aspect); + return self; +} + +static VALUE +geo_set_min_width(self, min_width) + VALUE self, min_width; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->min_width = NUM2INT(min_width); + return self; +} + +static VALUE +geo_set_min_height(self, min_height) + VALUE self, min_height; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->min_height = NUM2INT(min_height); + return self; +} + +static VALUE +geo_set_max_width(self, max_width) + VALUE self, max_width; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->max_width = NUM2INT(max_width); + return self; +} + +static VALUE +geo_set_max_height(self, max_height) + VALUE self, max_height; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->max_height = NUM2INT(max_height); + return self; +} + +static VALUE +geo_set_base_width(self, base_width) + VALUE self, base_width; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->base_width = NUM2INT(base_width); + return self; +} + +static VALUE +geo_set_base_height(self, base_height) + VALUE self; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->base_height = NUM2INT(base_height); + return self; +} + +static VALUE +geo_set_width_inc(self, width_inc) + VALUE self, width_inc; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->width_inc = NUM2INT(width_inc); + return self; +} + +static VALUE +geo_set_height_inc(self, height_inc) + VALUE self, height_inc; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->height_inc = NUM2INT(height_inc); + return self; +} + +static VALUE +geo_set_min_aspect(self, min_aspect) + VALUE self, min_aspect; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->min_aspect = NUM2DBL(min_aspect); + return self; +} + +static VALUE +geo_set_max_aspect(self, max_aspect) + VALUE self, max_aspect; +{ + GdkGeometry *geo; + + geo = rbgdk_geometry_get(self); + geo->max_aspect = NUM2DBL(max_aspect); + return self; +} + +Init_gtk_gdk_geometry() +{ + gdkGeometry = rb_define_class_under(mGdk, "Geometry", rb_cData); + + rb_define_singleton_method(gdkGeometry, "new", geo_s_new, 0); + + rb_define_method(gdkGeometry, "min_width", geo_min_width, 0); + rb_define_method(gdkGeometry, "min_height", geo_min_height, 0); + rb_define_method(gdkGeometry, "max_width", geo_max_width, 0); + rb_define_method(gdkGeometry, "max_height", geo_max_height, 0); + rb_define_method(gdkGeometry, "base_width", geo_base_width, 0); + rb_define_method(gdkGeometry, "base_height", geo_base_height, 0); + rb_define_method(gdkGeometry, "width_inc", geo_width_inc, 0); + rb_define_method(gdkGeometry, "height_inc", geo_height_inc, 0); + rb_define_method(gdkGeometry, "min_aspect", geo_min_aspect, 0); + rb_define_method(gdkGeometry, "max_aspect", geo_max_aspect, 0); + + /* once ruby gets parameterized arguments feature, setters should + * be changed. 2000-040-26 yashi */ + rb_define_method(gdkGeometry, "set", geo_set, 10); + + rb_define_method(gdkGeometry, "set_min_width", geo_set_min_width, 1); + rb_define_method(gdkGeometry, "set_min_height", geo_set_min_height, 1); + rb_define_method(gdkGeometry, "set_max_width", geo_set_max_width, 1); + rb_define_method(gdkGeometry, "set_max_height", geo_set_max_height, 1); + rb_define_method(gdkGeometry, "set_base_width", geo_set_base_width, 1); + rb_define_method(gdkGeometry, "set_base_height", geo_set_base_height, 1); + rb_define_method(gdkGeometry, "set_width_inc", geo_set_width_inc, 1); + rb_define_method(gdkGeometry, "set_height_inc", geo_set_height_inc, 1); + rb_define_method(gdkGeometry, "set_min_aspect", geo_set_min_aspect, 1); + rb_define_method(gdkGeometry, "set_max_aspect", geo_set_max_aspect, 1); + } diff -u --new-file --recursive gtk/src/rbgtk.h gtk.new/src/rbgtk.h --- gtk/src/rbgtk.h Thu Mar 30 17:19:28 2000 +++ gtk.new/src/rbgtk.h Wed Apr 26 08:24:39 2000 @@ -306,4 +306,7 @@ #define get_gdkic(a) ((GdkIC*)get_tobj(a, gdkIC)) #define get_gdkicattr(a) ((GdkICAttr*)get_tobj(a, gdkICAttr)) +extern VALUE rbgdk_geometry_make(GdkGeometry *geo); +extern GdkGeometry *rbgdk_geometry_get(VALUE geo); + #endif /* _RBGTK_H */ diff -u --new-file --recursive gtk/src/rbgtkwindow.c gtk.new/src/rbgtkwindow.c --- gtk/src/rbgtkwindow.c Thu Mar 30 17:39:36 2000 +++ gtk.new/src/rbgtkwindow.c Wed Apr 26 08:21:32 2000 @@ -165,6 +165,18 @@ return self; } +static VALUE +gwin_set_geometry_hints(self, geometry_widget, geometry, geom_mask) + VALUE self, geometry_widget, geometry, geom_mask; +{ + gtk_window_set_geometry_hints(GTK_WINDOW(get_widget(self)), + get_widget(geometry_widget), + rbgdk_geometry_get(geometry), + NUM2INT(geom_mask)); + + return self; +} + void Init_gtk_window() { gWindow = rb_define_class_under(mGtk, "Window", gBin); @@ -191,6 +203,7 @@ rb_define_method(gWindow, "grab_remove", gwin_grab_remove, 0); rb_define_method(gWindow, "set_modal", gwin_set_modal, 1); rb_define_method(gWindow, "set_transient_for", gwin_set_transient_for, 1); + rb_define_method(gWindow, "set_geometry_hints", gwin_set_geometry_hints, 3); /* child init */ Init_gtk_color_selection_dialog();