summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-01-16 12:19:09 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-01-16 12:19:09 +0000
commit62e41d3f2e48422bbdf1bb2db83ae60b255b1a1a (patch)
tree4d0edb1c1986e1578b181ebe2441acfee27f1fab /ext
parent3db12e8b236ac8f88db8eb4690d10e4a3b8dbcd4 (diff)
Initial revision
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/gtk/MANIFEST18
-rw-r--r--ext/gtk/extconf.rb6
-rw-r--r--ext/gtk/gtk.c5904
-rw-r--r--ext/gtk/test.rb96
-rw-r--r--ext/gtk/test.xpm92
-rw-r--r--ext/gtk/test0.rb13
-rw-r--r--ext/gtk/test1.rb41
-rw-r--r--ext/gtk/test2.rb89
-rw-r--r--ext/gtk/test3.rb16
-rw-r--r--ext/gtk/test4.rb77
-rw-r--r--ext/gtk/test5.rb63
-rw-r--r--ext/gtk/test6.rb49
-rw-r--r--ext/gtk/test7.rb49
-rw-r--r--ext/gtk/test8.rb49
-rw-r--r--ext/gtk/test9.rb98
-rw-r--r--ext/gtk/testa.rb78
-rw-r--r--ext/gtk/testb.rb78
-rw-r--r--ext/gtk/testc.rb64
-rw-r--r--ext/tcltklib/MANIFEST15
-rw-r--r--ext/tcltklib/MANUAL.euc124
-rw-r--r--ext/tcltklib/README.euc133
-rw-r--r--ext/tcltklib/demo/lines0.tcl42
-rw-r--r--ext/tcltklib/demo/lines1.rb54
-rw-r--r--ext/tcltklib/demo/lines2.rb50
-rw-r--r--ext/tcltklib/depend1
-rw-r--r--ext/tcltklib/extconf.rb79
-rw-r--r--ext/tcltklib/lib/tcltk.rb388
-rw-r--r--ext/tcltklib/sample/batsu.gifbin0 -> 538 bytes
-rw-r--r--ext/tcltklib/sample/maru.gifbin0 -> 481 bytes
-rw-r--r--ext/tcltklib/sample/sample0.rb39
-rw-r--r--ext/tcltklib/sample/sample1.rb634
-rw-r--r--ext/tcltklib/sample/sample2.rb449
-rw-r--r--ext/tcltklib/tcltklib.c216
33 files changed, 9104 insertions, 0 deletions
diff --git a/ext/gtk/MANIFEST b/ext/gtk/MANIFEST
new file mode 100644
index 0000000..3e1962e
--- /dev/null
+++ b/ext/gtk/MANIFEST
@@ -0,0 +1,18 @@
+MANIFEST
+extconf.rb
+gtk.c
+test.rb
+test.xpm
+test0.rb
+test1.rb
+test2.rb
+test3.rb
+test4.rb
+test5.rb
+test6.rb
+test7.rb
+test8.rb
+test9.rb
+testa.rb
+testb.rb
+testc.rb
diff --git a/ext/gtk/extconf.rb b/ext/gtk/extconf.rb
new file mode 100644
index 0000000..621e073
--- /dev/null
+++ b/ext/gtk/extconf.rb
@@ -0,0 +1,6 @@
+require "mkmf"
+if have_library("glib", "g_print") and
+ have_library("gdk", "gdk_init") and
+ have_library("gtk", "gtk_init")
+ create_makefile("gtk")
+end
diff --git a/ext/gtk/gtk.c b/ext/gtk/gtk.c
new file mode 100644
index 0000000..9114312
--- /dev/null
+++ b/ext/gtk/gtk.c
@@ -0,0 +1,5904 @@
+/************************************************
+
+ gtk.c -
+
+ $Author$
+ $Date$
+ created at: Wed Jan 7 23:55:11 JST 1998
+
+************************************************/
+
+#include "ruby.h"
+#include "sig.h"
+#include <gtk/gtk.h>
+#include <signal.h>
+
+extern VALUE rb_argv, rb_argv0;
+extern VALUE cData;
+
+static VALUE mGtk;
+
+static VALUE gObject;
+static VALUE gWidget;
+static VALUE gContainer;
+static VALUE gBin;
+static VALUE gAlignment;
+static VALUE gMisc;
+static VALUE gArrow;
+static VALUE gFrame;
+static VALUE gAspectFrame;
+static VALUE gData;
+static VALUE gAdjustment;
+static VALUE gBox;
+static VALUE gButton;
+static VALUE gTButton;
+static VALUE gCButton;
+static VALUE gRButton;
+static VALUE gBBox;
+static VALUE gCList;
+static VALUE gWindow;
+static VALUE gDialog;
+static VALUE gFileSel;
+static VALUE gVBox;
+static VALUE gColorSel;
+static VALUE gColorSelDialog;
+static VALUE gImage;
+static VALUE gDrawArea;
+static VALUE gEntry;
+static VALUE gEventBox;
+static VALUE gFixed;
+static VALUE gGamma;
+static VALUE gHBBox;
+static VALUE gVBBox;
+static VALUE gHBox;
+static VALUE gPaned;
+static VALUE gHPaned;
+static VALUE gVPaned;
+static VALUE gRuler;
+static VALUE gHRuler;
+static VALUE gVRuler;
+static VALUE gRange;
+static VALUE gScale;
+static VALUE gHScale;
+static VALUE gVScale;
+static VALUE gScrollbar;
+static VALUE gHScrollbar;
+static VALUE gVScrollbar;
+static VALUE gSeparator;
+static VALUE gHSeparator;
+static VALUE gVSeparator;
+static VALUE gInputDialog;
+static VALUE gLabel;
+static VALUE gList;
+static VALUE gItem;
+static VALUE gListItem;
+static VALUE gMenuShell;
+static VALUE gMenu;
+static VALUE gMenuBar;
+static VALUE gMenuItem;
+static VALUE gCMenuItem;
+static VALUE gRMenuItem;
+static VALUE gNotebook;
+static VALUE gOptionMenu;
+static VALUE gPixmap;
+static VALUE gPreview;
+static VALUE gProgressBar;
+static VALUE gScrolledWin;
+static VALUE gTable;
+static VALUE gText;
+static VALUE gToolbar;
+static VALUE gTooltips;
+static VALUE gTree;
+static VALUE gTreeItem;
+static VALUE gViewPort;
+
+static VALUE gAcceleratorTable;
+static VALUE gStyle;
+static VALUE gPreviewInfo;
+static VALUE gAllocation;
+static VALUE gRequisiton;
+
+static VALUE mGdk;
+
+static VALUE gdkFont;
+static VALUE gdkColor;
+static VALUE gdkColormap;
+static VALUE gdkPixmap;
+static VALUE gdkBitmap;
+static VALUE gdkWindow;
+static VALUE gdkImage;
+static VALUE gdkVisual;
+static VALUE gdkGC;
+static VALUE gdkRectangle;
+static VALUE gdkGCValues;
+static VALUE gdkRectangle;
+static VALUE gdkSegment;
+static VALUE gdkWindowAttr;
+static VALUE gdkCursor;
+static VALUE gdkAtom;
+static VALUE gdkColorContext;
+static VALUE gdkEvent;
+
+ID id_gtkdata, id_relatives, id_call;
+
+static void gobj_free();
+
+static char*
+get_cstring(str)
+ VALUE str;
+{
+ if (NIL_P(str)) return NULL;
+ Check_Type(str, T_STRING);
+ return RSTRING(str)->ptr;
+}
+
+static GtkObject*
+get_gobject(obj)
+ VALUE obj;
+{
+ struct RData *data;
+ GtkObject *gtkp;
+
+ if (NIL_P(obj)) return NULL;
+
+ Check_Type(obj, T_OBJECT);
+ data = RDATA(rb_ivar_get(obj, id_gtkdata));
+ if (NIL_P(data) || data->dfree != gobj_free) {
+ TypeError("not a Gtk object");
+ }
+ Data_Get_Struct(data, GtkObject, gtkp);
+ if (!GTK_IS_OBJECT(gtkp)) {
+ TypeError("not a GtkObject");
+ }
+
+ return gtkp;
+}
+
+static GtkWidget*
+get_widget(obj)
+ VALUE obj;
+{
+ GtkObject *data = get_gobject(obj);
+
+ return GTK_WIDGET(data);
+}
+
+static VALUE
+get_value_from_gobject(obj)
+ GtkObject *obj;
+{
+ return (VALUE)gtk_object_get_user_data(obj);
+}
+
+static void
+clear_gobject(obj)
+ VALUE obj;
+{
+ rb_ivar_set(obj, id_relatives, Qnil);
+}
+
+static void
+add_relative(obj, relative)
+ VALUE obj, relative;
+{
+ VALUE ary = rb_ivar_get(obj, id_relatives);
+
+ if (TYPE(ary) != T_ARRAY) {
+ ary = ary_new();
+ rb_ivar_set(obj, id_relatives, ary);
+ }
+ ary_push(ary, relative);
+}
+
+static VALUE gtk_object_list;
+
+static void
+gobj_free(obj)
+ GtkObject *obj;
+{
+ VALUE self = get_value_from_gobject(obj);
+
+ if (GTK_OBJECT_NEED_DESTROY(obj)) {
+ gtk_object_destroy(obj);
+ }
+ rb_ivar_set(self, id_relatives, Qnil);
+}
+
+static void
+delete_gobject(obj)
+ GtkObject *obj;
+{
+ ary_delete(gtk_object_list, get_value_from_gobject(obj));
+}
+
+static VALUE
+make_gobject(klass, gtkobj)
+ VALUE klass;
+ GtkObject *gtkobj;
+{
+ VALUE obj = obj_alloc(klass);
+ VALUE data;
+
+ data = Data_Wrap_Struct(cData, 0, gobj_free, gtkobj);
+ gtk_object_set_user_data(gtkobj, (gpointer)obj);
+
+ rb_ivar_set(obj, id_gtkdata, data);
+ gtk_signal_connect(gtkobj, "destroy", (GtkSignalFunc)delete_gobject, 0);
+ ary_push(gtk_object_list, obj);
+ return obj;
+}
+
+static VALUE
+make_widget(klass, widget)
+ VALUE klass;
+ GtkWidget *widget;
+{
+ return make_gobject(klass, GTK_OBJECT(widget));
+}
+
+static void
+free_gstyle(style)
+ GtkStyle *style;
+{
+ gtk_style_unref(style);
+}
+
+static VALUE
+make_gstyle(style)
+ GtkStyle *style;
+{
+ gtk_style_ref(style);
+ return Data_Wrap_Struct(gStyle, 0, free_gstyle, style);
+}
+
+static GtkStyle*
+get_gstyle(style)
+ VALUE style;
+{
+ GtkStyle *gstyle;
+
+ if (NIL_P(style)) return NULL;
+ if (!obj_is_instance_of(style, gStyle)) {
+ TypeError("not a GtkStyle");
+ }
+ Data_Get_Struct(style, GtkStyle, gstyle);
+
+ return gstyle;
+}
+
+static void
+free_gaccel(tbl)
+ GtkAcceleratorTable *tbl;
+{
+ gtk_accelerator_table_unref(tbl);
+}
+
+static VALUE
+make_gtkacceltbl(tbl)
+ GtkAcceleratorTable *tbl;
+{
+ gtk_accelerator_table_ref(tbl);
+ return Data_Wrap_Struct(gAcceleratorTable, 0, free_gaccel, tbl);
+}
+
+static GtkAcceleratorTable*
+get_gtkacceltbl(value)
+ VALUE value;
+{
+ GtkAcceleratorTable *tbl;
+
+ if (NIL_P(value)) return NULL;
+
+ if (!obj_is_instance_of(value, gAcceleratorTable)) {
+ TypeError("not an AcceleratorTable");
+ }
+ Data_Get_Struct(value, GtkAcceleratorTable, tbl);
+
+ return tbl;
+}
+
+static VALUE
+make_gtkprevinfo(info)
+ GtkPreviewInfo *info;
+{
+ return Data_Wrap_Struct(gAcceleratorTable, 0, 0, info);
+}
+
+static GtkPreviewInfo*
+get_gtkprevinfo(value)
+ VALUE value;
+{
+ GtkPreviewInfo *info;
+
+ if (NIL_P(value)) return NULL;
+
+ if (!obj_is_instance_of(value, gPreviewInfo)) {
+ TypeError("not a PreviewInfo");
+ }
+ Data_Get_Struct(value, GtkPreviewInfo, info);
+
+ return info;
+}
+
+static void
+exec_callback(widget, data, nparams, params)
+ GtkWidget *widget;
+ VALUE data;
+ int nparams;
+ GtkType *params;
+{
+ VALUE self = get_value_from_gobject(GTK_OBJECT(widget));
+ VALUE proc = RARRAY(data)->ptr[0];
+ VALUE event = RARRAY(data)->ptr[1];
+ ID id = NUM2INT(event);
+
+ if (NIL_P(proc) && rb_respond_to(self, id)) {
+ rb_funcall(self, id, 3, self,
+ INT2FIX(nparams), INT2NUM((INT)params));
+ }
+ else {
+ rb_funcall(proc, id_call, 1, self);
+ }
+}
+
+static void
+free_ttips(tips)
+ GtkTooltips *tips;
+{
+ gtk_tooltips_unref(tips);
+}
+
+static VALUE
+make_ttips(klass, tips)
+ VALUE klass;
+ GtkTooltips *tips;
+{
+ gtk_tooltips_ref(tips);
+ return Data_Wrap_Struct(klass, 0, free_ttips, tips);
+}
+
+static GtkTooltips*
+get_ttips(tips)
+ VALUE tips;
+{
+ GtkTooltips *gtips;
+
+ if (NIL_P(tips)) return NULL;
+
+ if (!obj_is_instance_of(tips, gTooltips)) {
+ TypeError("not a GtkTooltips");
+ }
+ Data_Get_Struct(tips, GtkTooltips, gtips);
+
+ return gtips;
+}
+
+static void
+free_gdkfont(font)
+ GdkFont *font;
+{
+ gdk_font_unref(font);
+}
+
+static VALUE
+make_gdkfont(font)
+ GdkFont *font;
+{
+ gdk_font_ref(font);
+ return Data_Wrap_Struct(gdkFont, 0, free_gdkfont, font);
+}
+
+static GdkFont*
+get_gdkfont(font)
+ VALUE font;
+{
+ GdkFont *gfont;
+
+ if (NIL_P(font)) return NULL;
+
+ if (!obj_is_instance_of(font, gdkFont)) {
+ TypeError("not a GdkFont");
+ }
+ Data_Get_Struct(font, GdkFont, gfont);
+
+ return gfont;
+}
+
+static VALUE
+gdkfnt_equal(fn1, fn2)
+ VALUE fn1, fn2;
+{
+ if (gdk_font_equal(get_gdkfont(fn1), get_gdkfont(fn2)))
+ return TRUE;
+ return FALSE;
+}
+
+static void
+free_tobj(obj)
+ gpointer obj;
+{
+ free(obj);
+}
+
+static VALUE
+make_tobj(obj, klass, size)
+ gpointer obj;
+ VALUE klass;
+ int size;
+{
+ gpointer copy;
+ VALUE data;
+
+ copy = xmalloc(size);
+ memcpy(copy, obj, size);
+ data = Data_Wrap_Struct(klass, 0, free_tobj, copy);
+
+ return data;
+}
+
+static gpointer
+get_tobj(obj, klass)
+ VALUE obj, klass;
+{
+ void *ptr;
+
+ if (NIL_P(obj)) return NULL;
+
+ if (!obj_is_instance_of(obj, klass)) {
+ TypeError("not a %s", rb_class2name(klass));
+ }
+ Data_Get_Struct(obj, void, ptr);
+
+ return ptr;
+}
+
+#define make_gdkcolor(c) make_tobj(c, gdkColor, sizeof(GdkColor))
+#define get_gdkcolor(c) ((GdkColor*)get_tobj(c, gdkColor))
+
+#define make_gdkrect(c) make_tobj(c, gdkRectangle, sizeof(GdkRectangle))
+#define get_gdkrect(c) ((GdkRectangle*)get_tobj(c, gdkRectangle))
+
+#define make_gdksegment(c) make_tobj(c, gdkSegment, sizeof(GdkSegment))
+#define get_gdksegment(c) ((GdkSegment*)get_tobj(c, gdkSegment))
+
+#define make_gdkwinattr(c) make_tobj(c, gdkWindowAttr, sizeof(GdkWindowAttr))
+#define get_gdkwinattr(c) ((GdkWindowAttr*)get_tobj(c, gdkWindowAttr))
+
+#define make_gdkwinattr(c) make_tobj(c, gdkWindowAttr, sizeof(GdkWindowAttr))
+#define get_gdkwinattr(c) ((GdkWindowAttr*)get_tobj(c, gdkWindowAttr))
+
+#define make_gallocation(c) make_tobj(c, gAllocation, sizeof(GtkAllocation))
+#define get_gallocation(c) ((GtkAllocation*)get_tobj(c, gAllocation))
+
+#define make_grequisiton(c) make_tobj(c, gRequisiton, sizeof(GtkRequisition))
+#define get_grequisiton(c) ((GtkRequisition*)get_tobj(c, gRequisiton))
+
+#define make_gdkrectangle(r) make_tobj(r, gdkRectangle, sizeof(GdkRectangle))
+#define get_gdkrectangle(r) ((GdkRectangle*)get_tobj(r, gdkRectangle))
+
+static void
+free_gdkcmap(cmap)
+ GdkColormap *cmap;
+{
+ gdk_colormap_unref(cmap);
+}
+
+static VALUE
+make_gdkcmap(cmap)
+ GdkColormap *cmap;
+{
+ gdk_colormap_ref(cmap);
+ return Data_Wrap_Struct(gdkColormap, 0, free_gdkcmap, cmap);
+}
+
+static GdkColormap*
+get_gdkcmap(cmap)
+ VALUE cmap;
+{
+ GdkColormap *gcmap;
+
+ if (NIL_P(cmap)) return NULL;
+
+ if (!obj_is_kind_of(cmap, gdkColormap)) {
+ TypeError("not a GdkColormap");
+ }
+ Data_Get_Struct(cmap, GdkColormap, gcmap);
+
+ return gcmap;
+}
+
+static VALUE
+make_gdkvisual(visual)
+ GdkVisual *visual;
+{
+ return Data_Wrap_Struct(gdkVisual, 0, 0, visual);
+}
+
+static GdkVisual*
+get_gdkvisual(visual)
+ VALUE visual;
+{
+ GdkVisual *gvisual;
+
+ if (NIL_P(visual)) return NULL;
+
+ if (!obj_is_kind_of(visual, gdkVisual)) {
+ TypeError("not a GdkVisual");
+ }
+ Data_Get_Struct(visual, GdkVisual, gvisual);
+
+ return gvisual;
+}
+
+static void
+free_gdkwindow(window)
+ GdkWindow *window;
+{
+ gdk_window_unref(window);
+}
+
+static VALUE
+make_gdkwindow(window)
+ GdkWindow *window;
+{
+ gdk_window_ref(window);
+ return Data_Wrap_Struct(gdkWindow, 0, free_gdkwindow, window);
+}
+
+static GdkWindow*
+get_gdkwindow(window)
+ VALUE window;
+{
+ GdkWindow *gwindow;
+
+ if (NIL_P(window)) return NULL;
+
+ if (!obj_is_kind_of(window, gdkWindow)) {
+ TypeError("not a GdkWindow");
+ }
+ Data_Get_Struct(window, GdkWindow, gwindow);
+
+ return gwindow;
+}
+
+static void
+free_gdkpixmap(pixmap)
+ GdkPixmap *pixmap;
+{
+ gdk_pixmap_unref(pixmap);
+}
+
+static VALUE
+make_gdkpixmap(klass, pixmap)
+ VALUE klass;
+ GdkPixmap *pixmap;
+{
+ gdk_pixmap_ref(pixmap);
+ return Data_Wrap_Struct(klass, 0, free_gdkpixmap, pixmap);
+}
+
+static GdkPixmap*
+get_gdkpixmap(pixmap)
+ VALUE pixmap;
+{
+ GdkPixmap *gpixmap;
+
+ if (NIL_P(pixmap)) return NULL;
+
+ if (!obj_is_kind_of(pixmap, gdkPixmap)) {
+ TypeError("not a GdkPixmap");
+ }
+ Data_Get_Struct(pixmap, GdkPixmap, gpixmap);
+
+ return gpixmap;
+}
+
+static VALUE
+gdkpmap_s_new(self, win, w, h, depth)
+ VALUE self, win, w, h, depth;
+{
+ GdkPixmap *new;
+ GdkWindow *window = get_gdkwindow(win);
+
+ new = gdk_pixmap_new(window, NUM2INT(w), NUM2INT(h), NUM2INT(depth));
+ return make_gdkpixmap(self, new);
+}
+
+static VALUE
+gdkpmap_create_from_data(self, win, data, w, h, depth, fg, bg)
+ VALUE self, win, data, w, h, depth, fg, bg;
+{
+ GdkPixmap *new;
+ GdkWindow *window = get_gdkwindow(win);
+
+ Check_Type(data, T_STRING);
+ new = gdk_pixmap_create_from_data(window,
+ RSTRING(data)->ptr,
+ NUM2INT(w), NUM2INT(h),
+ NUM2INT(depth),
+ get_gdkcolor(fg),
+ get_gdkcolor(bg));
+ return make_gdkpixmap(self, new);
+}
+
+static VALUE
+gdkpmap_create_from_xpm(self, win, tcolor, fname)
+ VALUE self, win, tcolor, fname;
+{
+ GdkPixmap *new;
+ GdkBitmap *mask;
+ GdkWindow *window = get_gdkwindow(win);
+
+ Check_Type(fname, T_STRING);
+ new = gdk_pixmap_create_from_xpm(window, &mask,
+ get_gdkcolor(tcolor),
+ RSTRING(fname)->ptr);
+ if (!new) {
+ ArgError("Pixmap not created from %s", RSTRING(fname)->ptr);
+ }
+ return assoc_new(make_gdkpixmap(self, new),
+ make_gdkpixmap(gdkBitmap, mask));
+}
+
+static VALUE
+gdkpmap_create_from_xpm_d(self, win, tcolor, data)
+ VALUE self, win, tcolor, data;
+{
+ GdkPixmap *new;
+ GdkBitmap *mask;
+ GdkWindow *window = get_gdkwindow(win);
+ int i;
+ gchar **buf;
+
+ Check_Type(data, T_ARRAY);
+ buf = ALLOCA_N(char*, RARRAY(data)->len);
+ for (i=0; i<RARRAY(data)->len; i++) {
+ Check_Type(RARRAY(data)->ptr[i], T_STRING);
+ buf[i] = RSTRING(RARRAY(data)->ptr[i])->ptr;
+ }
+
+ new = gdk_pixmap_create_from_xpm_d(window, &mask,
+ get_gdkcolor(tcolor),
+ buf);
+
+ return assoc_new(make_gdkpixmap(self, new),
+ make_gdkpixmap(gdkBitmap, mask));
+}
+
+static VALUE
+gdkbmap_s_new(self, win, w, h)
+ VALUE self, win, w, h;
+{
+ GdkPixmap *new;
+ GdkWindow *window = get_gdkwindow(win);
+
+ new = gdk_pixmap_new(window, NUM2INT(w), NUM2INT(h), 1);
+ return make_gdkpixmap(self, new);
+}
+
+static VALUE
+gdkbmap_create_from_data(self, win, data, w, h)
+ VALUE self, win, data, w, h;
+{
+ GdkBitmap *new;
+ GdkWindow *window = get_gdkwindow(win);
+
+ Check_Type(data, T_STRING);
+ new = gdk_bitmap_create_from_data(window,
+ RSTRING(data)->ptr,
+ NUM2INT(w), NUM2INT(h));
+ return make_gdkpixmap(self, (GdkPixmap*)new);
+}
+
+static void
+free_gdkimage(image)
+ GdkImage *image;
+{
+ gdk_image_destroy(image);
+}
+
+static VALUE
+make_gdkimage(image)
+ GdkImage *image;
+{
+ return Data_Wrap_Struct(gdkImage, 0, free_gdkimage, image);
+}
+
+static GdkImage*
+get_gdkimage(image)
+ VALUE image;
+{
+ GdkImage *gimage;
+
+ if (NIL_P(image)) return NULL;
+
+ if (!obj_is_instance_of(image, gdkImage)) {
+ TypeError("not a GdkImage");
+ }
+ Data_Get_Struct(image, GdkImage, gimage);
+
+ return gimage;
+}
+
+static void
+free_gdkevent(event)
+ GdkEvent *event;
+{
+ gdk_event_free(event);
+}
+
+static VALUE
+make_gdkevent(event)
+ GdkEvent *event;
+{
+ event = gdk_event_copy(event);
+ return Data_Wrap_Struct(gdkEvent, 0, free_gdkevent, event);
+}
+
+static GdkEvent*
+get_gdkevent(event)
+ VALUE event;
+{
+ GdkEvent *gevent;
+
+ if (NIL_P(event)) return NULL;
+
+ if (!obj_is_instance_of(event, gdkEvent)) {
+ TypeError("not a GdkEvent");
+ }
+ Data_Get_Struct(event, GdkEvent, gevent);
+
+ return gevent;
+}
+
+static VALUE
+glist2ary(list)
+ GList *list;
+{
+ VALUE ary = ary_new();
+
+ while (list) {
+ ary_push(ary, get_value_from_gobject(GTK_OBJECT(list->data)));
+ list = list->next;
+ }
+
+ return ary;
+}
+
+static GList*
+ary2glist(ary)
+ VALUE ary;
+{
+ int i;
+ GList *glist = NULL;
+
+ Check_Type(ary, T_ARRAY);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ glist = g_list_prepend(glist,get_widget(RARRAY(ary)->ptr[i]));
+ }
+
+ return g_list_reverse(glist);
+}
+
+static GSList*
+ary2gslist(ary)
+ VALUE ary;
+{
+ int i;
+ GSList *glist = NULL;
+
+ if (NIL_P(ary)) return NULL;
+ Check_Type(ary, T_ARRAY);
+ for (i=0; i<RARRAY(ary)->len; i++) {
+ glist = g_slist_append(glist,get_widget(RARRAY(ary)->ptr[i]));
+ }
+
+ return glist;
+}
+
+static VALUE
+gslist2ary(list)
+ GSList *list;
+{
+ VALUE ary = ary_new();
+
+ while (list) {
+ ary_push(ary, get_value_from_gobject(GTK_OBJECT(list->data)));
+ list = list->next;
+ }
+
+ return ary;
+}
+
+static VALUE
+gobj_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ Fail("can't instantiate class %s", rb_class2name(self));
+}
+
+static VALUE
+gobj_smethod_added(self, id)
+ VALUE self, id;
+{
+ GtkObject *obj = get_gobject(self);
+ char *name = rb_id2name(NUM2INT(id));
+
+
+ if (gtk_signal_lookup(name, GTK_OBJECT_TYPE(obj))) {
+ VALUE handler = assoc_new(Qnil, id);
+
+ add_relative(self, handler);
+ gtk_signal_connect_interp(obj, name,
+ exec_callback, (gpointer)handler,
+ NULL, 0);
+ }
+ return Qnil;
+}
+
+static VALUE
+gobj_destroy(self)
+ VALUE self;
+{
+ printf("a\n");
+ gtk_object_destroy(get_gobject(self));
+ printf("b\n");
+ clear_gobject(self);
+ return Qnil;
+}
+
+static VALUE
+gobj_set_flags(self, flags)
+ VALUE self, flags;
+{
+ GtkObject *object = get_gobject(self);
+ GTK_OBJECT_SET_FLAGS(object, NUM2INT(flags));
+ return self;
+}
+
+static VALUE
+gobj_unset_flags(self, flags)
+ VALUE self, flags;
+{
+ GtkObject *object = get_gobject(self);
+ GTK_OBJECT_UNSET_FLAGS(object, NUM2INT(flags));
+ return self;
+}
+
+static VALUE
+gobj_sig_connect(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE sig, handler;
+ GtkWidget *widget = get_widget(self);
+ ID id = 0;
+ int n;
+
+ rb_scan_args(argc, argv, "11", &sig, &handler);
+ Check_Type(sig, T_STRING);
+ if (NIL_P(handler) && iterator_p()) {
+ handler = f_lambda();
+ id = rb_intern(RSTRING(sig)->ptr);
+ }
+ handler = assoc_new(handler, INT2NUM(id));
+ add_relative(self, handler);
+ n = gtk_signal_connect_interp(GTK_OBJECT(widget), RSTRING(sig)->ptr,
+ exec_callback, (gpointer)handler,
+ NULL, 0);
+
+ return INT2FIX(n);
+}
+
+static VALUE
+gobj_sig_connect_after(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE sig, handler;
+ GtkWidget *widget = get_widget(self);
+ ID id = 0;
+ int n;
+
+ rb_scan_args(argc, argv, "11", &sig, &handler);
+ Check_Type(sig, T_STRING);
+ if (NIL_P(handler) && iterator_p()) {
+ handler = f_lambda();
+ id = rb_intern(RSTRING(sig)->ptr);
+ }
+ add_relative(self, handler);
+ n = gtk_signal_connect_interp(GTK_OBJECT(widget), RSTRING(sig)->ptr,
+ exec_callback, (gpointer)handler,
+ NULL, 1);
+
+ return INT2FIX(n);
+}
+
+static VALUE
+cont_bwidth(self, width)
+ VALUE self, width;
+{
+ GtkWidget *widget = get_widget(self);
+ gtk_container_border_width(GTK_CONTAINER(widget), NUM2INT(width));
+ return self;
+}
+
+static VALUE
+cont_add(self, other)
+ VALUE self, other;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_add(GTK_CONTAINER(widget), get_widget(other));
+ return self;
+}
+
+static VALUE
+cont_disable_resize(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_disable_resize(GTK_CONTAINER(widget));
+ return self;
+}
+
+static VALUE
+cont_enable_resize(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_enable_resize(GTK_CONTAINER(widget));
+ return self;
+}
+
+static VALUE
+cont_block_resize(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_block_resize(GTK_CONTAINER(widget));
+ return self;
+}
+
+static VALUE
+cont_unblock_resize(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_unblock_resize(GTK_CONTAINER(widget));
+ return self;
+}
+
+static VALUE
+cont_need_resize(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_need_resize(GTK_CONTAINER(widget));
+ return self;
+}
+
+static VALUE
+cont_foreach(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE callback;
+ GtkWidget *widget = get_widget(self);
+
+ rb_scan_args(argc, argv, "01", &callback);
+ if (NIL_P(callback)) {
+ callback = f_lambda();
+ }
+ gtk_container_foreach(GTK_CONTAINER(widget),
+ exec_callback, (gpointer)callback);
+ return self;
+}
+
+static void
+yield_callback(widget)
+ GtkWidget *widget;
+{
+ rb_yield(get_value_from_gobject(GTK_OBJECT(widget)));
+}
+
+static VALUE
+cont_each(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_foreach(GTK_CONTAINER(widget),
+ yield_callback, 0);
+ return self;
+}
+
+static VALUE
+cont_focus(self, direction)
+ VALUE self, direction;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_container_focus(GTK_CONTAINER(widget),
+ (GtkDirectionType)NUM2INT(direction));
+ return self;
+}
+
+static void
+cont_children_callback(widget, data)
+ GtkWidget *widget;
+ gpointer data;
+{
+ VALUE ary = (VALUE)data;
+
+ ary_push(ary, get_value_from_gobject(GTK_OBJECT(widget)));
+}
+
+static VALUE
+cont_children(self, direction)
+ VALUE self, direction;
+{
+ GtkWidget *widget = get_widget(self);
+ VALUE ary = ary_new();
+
+ gtk_container_foreach(GTK_CONTAINER(widget),
+ cont_children_callback,
+ (gpointer)ary);
+ return ary;
+}
+
+static VALUE
+align_s_new(self, xalign, yalign, xscale, yscale)
+ VALUE self, xalign, yalign, xscale, yscale;
+{
+ return make_widget(self, gtk_alignment_new(NUM2DBL(xalign),
+ NUM2DBL(yalign),
+ NUM2DBL(xscale),
+ NUM2DBL(yscale)));
+}
+
+static VALUE
+align_set(self, xalign, yalign, xscale, yscale)
+ VALUE self, xalign, yalign, xscale, yscale;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_alignment_set(GTK_ALIGNMENT(widget),
+ NUM2DBL(xalign), NUM2DBL(yalign),
+ NUM2DBL(xscale), NUM2DBL(yscale));
+ return self;
+}
+
+static VALUE
+misc_set_align(self, xalign, yalign)
+ VALUE self, xalign, yalign;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_misc_set_alignment(GTK_MISC(widget),
+ NUM2DBL(xalign), NUM2DBL(yalign));
+ return self;
+}
+
+static VALUE
+misc_set_padding(self, xpad, ypad)
+ VALUE self, xpad, ypad;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_misc_set_padding(GTK_MISC(widget),
+ NUM2DBL(xpad), NUM2DBL(ypad));
+ return self;
+}
+
+static VALUE
+arrow_s_new(self, arrow_t, shadow_t)
+ VALUE self, arrow_t, shadow_t;
+{
+ return make_widget(self, gtk_arrow_new((GtkArrowType)NUM2INT(arrow_t),
+ (GtkShadowType)NUM2INT(shadow_t)));
+}
+
+static VALUE
+arrow_set(self, arrow_t, shadow_t)
+ VALUE self, arrow_t, shadow_t;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_arrow_set(GTK_ARROW(widget),
+ (GtkArrowType)NUM2INT(arrow_t),
+ (GtkShadowType)NUM2INT(shadow_t));
+ return self;
+}
+
+static VALUE
+frame_s_new(self, label)
+ VALUE self, label;
+{
+ return make_widget(self, gtk_frame_new(get_cstring(label)));
+}
+
+static VALUE
+frame_set_label(self, label)
+ VALUE self, label;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_frame_set_label(GTK_FRAME(widget), get_cstring(label));
+ return self;
+}
+
+static VALUE
+frame_set_label_align(self, xalign, yalign)
+ VALUE self, xalign, yalign;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_frame_set_label_align(GTK_FRAME(widget),
+ NUM2DBL(xalign),
+ NUM2DBL(yalign));
+
+ return self;
+}
+
+static VALUE
+frame_set_shadow_type(self, type)
+ VALUE self, type;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_frame_set_shadow_type(GTK_FRAME(widget),
+ (GtkShadowType)NUM2INT(type));
+ return self;
+}
+
+static VALUE
+aframe_s_new(self, label, xalign, yalign, ratio, obey_child)
+ VALUE self, label, xalign, yalign, ratio, obey_child;
+{
+ return make_widget(self, gtk_aspect_frame_new(get_cstring(label),
+ NUM2DBL(xalign),
+ NUM2DBL(yalign),
+ NUM2DBL(ratio),
+ RTEST(obey_child)));
+}
+
+static VALUE
+aframe_set(self, xalign, yalign, ratio, obey_child)
+ VALUE self, xalign, yalign, ratio, obey_child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_aspect_frame_set(GTK_ASPECT_FRAME(widget),
+ NUM2DBL(xalign), NUM2DBL(yalign),
+ NUM2DBL(ratio), RTEST(obey_child));
+ return self;
+}
+
+static VALUE
+adj_s_new(self, value, lower, upper, step_inc, page_inc, page_size)
+ VALUE self, value, lower, upper, step_inc, page_inc, page_size;
+{
+ return make_widget(self, gtk_adjustment_new(NUM2DBL(value),
+ NUM2DBL(lower),
+ NUM2DBL(upper),
+ NUM2DBL(step_inc),
+ NUM2DBL(page_inc),
+ NUM2DBL(page_size)));
+}
+
+static VALUE
+widget_destroy(self)
+ VALUE self;
+{
+ gtk_widget_destroy(get_widget(self));
+ clear_gobject(self);
+
+ return Qnil;
+}
+
+static VALUE
+widget_show(self)
+ VALUE self;
+{
+ gtk_widget_show(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_show_all(self)
+ VALUE self;
+{
+ gtk_widget_show_all(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_hide(self)
+ VALUE self;
+{
+ gtk_widget_hide(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_hide_all(self)
+ VALUE self;
+{
+ gtk_widget_hide_all(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_map(self)
+ VALUE self;
+{
+ gtk_widget_map(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_unmap(self)
+ VALUE self;
+{
+ gtk_widget_unmap(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_realize(self)
+ VALUE self;
+{
+ gtk_widget_realize(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_unrealize(self)
+ VALUE self;
+{
+ gtk_widget_unrealize(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_queue_draw(self)
+ VALUE self;
+{
+ gtk_widget_queue_draw(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_queue_resize(self)
+ VALUE self;
+{
+ gtk_widget_queue_resize(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_draw(self, rect)
+ VALUE self, rect;
+{
+ gtk_widget_draw(get_widget(self), get_gdkrectangle(rect));
+ return self;
+}
+
+static VALUE
+widget_draw_focus(self)
+ VALUE self;
+{
+ gtk_widget_draw_focus(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_draw_default(self)
+ VALUE self;
+{
+ gtk_widget_draw_default(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_draw_children(self)
+ VALUE self;
+{
+ gtk_widget_draw_children(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_size_request(self, req)
+ VALUE self, req;
+{
+ gtk_widget_size_request(get_widget(self), get_grequisiton(req));
+ return self;
+}
+
+static VALUE
+widget_size_allocate(self, alloc)
+ VALUE self, alloc;
+{
+ gtk_widget_size_allocate(get_widget(self), get_gallocation(alloc));
+ return self;
+}
+
+static VALUE
+widget_inst_accel(self, accel, sig, key, mod)
+ VALUE self, accel, sig, key, mod;
+{
+ gtk_widget_install_accelerator(get_widget(self),
+ get_gtkacceltbl(accel),
+ get_cstring(sig),
+ NUM2INT(key),
+ (guint8)NUM2INT(mod));
+ return self;
+}
+
+static VALUE
+widget_rm_accel(self, accel, sig)
+ VALUE self, accel, sig;
+{
+ gtk_widget_remove_accelerator(get_widget(self),
+ get_gtkacceltbl(accel),
+ get_cstring(sig));
+ return self;
+}
+
+static VALUE
+widget_event(self, event)
+ VALUE self, event;
+{
+ int n = gtk_widget_event(get_widget(self), get_gdkevent(event));
+ return NUM2INT(n);
+}
+
+static VALUE
+widget_activate(self)
+ VALUE self;
+{
+ gtk_widget_activate(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_grab_focus(self)
+ VALUE self;
+{
+ gtk_widget_grab_focus(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_grab_default(self)
+ VALUE self;
+{
+ gtk_widget_grab_default(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_restore_state(self)
+ VALUE self;
+{
+ gtk_widget_restore_state(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_visible(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ if (GTK_WIDGET_VISIBLE(widget))
+ return TRUE;
+ return FALSE;
+}
+
+static VALUE
+widget_reparent(self, parent)
+ VALUE self, parent;
+{
+ gtk_widget_reparent(get_widget(self), get_widget(parent));
+ return self;
+}
+
+static VALUE
+widget_popup(self, x, y)
+ VALUE self, x, y;
+{
+ gtk_widget_popup(get_widget(self), NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+widget_intersect(self, area, intersect)
+ VALUE self, area, intersect;
+{
+ int n = gtk_widget_intersect(get_widget(self),
+ get_gdkrectangle(area),
+ get_gdkrectangle(intersect));
+ return NUM2INT(n);
+}
+
+static VALUE
+widget_basic(self)
+ VALUE self;
+{
+ int n = gtk_widget_basic(get_widget(self));
+ return NUM2INT(n);
+}
+
+static VALUE
+widget_set_state(self, state)
+ VALUE self, state;
+{
+ gtk_widget_set_state(get_widget(self), (GtkStateType)NUM2INT(state));
+ return self;
+}
+
+static VALUE
+widget_set_style(self, style)
+ VALUE self, style;
+{
+ gtk_widget_set_style(get_widget(self),
+ get_gstyle(style));
+ return self;
+}
+
+static VALUE
+widget_set_parent(self, parent)
+ VALUE self, parent;
+{
+ gtk_widget_set_parent(get_widget(self), get_widget(parent));
+ return self;
+}
+
+static VALUE
+widget_set_name(self, name)
+ VALUE self, name;
+{
+ gtk_widget_set_name(get_widget(self), get_cstring(name));
+ return self;
+}
+
+static VALUE
+widget_get_name(self)
+ VALUE self;
+{
+ char *name = gtk_widget_get_name(get_widget(self));
+
+ return str_new2(name);
+}
+
+static VALUE
+widget_set_sensitive(self, sensitive)
+ VALUE self, sensitive;
+{
+ gtk_widget_set_sensitive(get_widget(self), RTEST(sensitive));
+ return self;
+}
+
+static VALUE
+widget_set_uposition(self, x, y)
+ VALUE self, x, y;
+{
+ gtk_widget_set_uposition(get_widget(self), NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+widget_set_usize(self, w, h)
+ VALUE self, w, h;
+{
+ gtk_widget_set_usize(get_widget(self), NUM2INT(w), NUM2INT(h));
+ return self;
+}
+
+static VALUE
+widget_set_events(self, events)
+ VALUE self, events;
+{
+ gtk_widget_set_events(get_widget(self), NUM2INT(events));
+ return self;
+}
+
+static VALUE
+widget_set_eevents(self, mode)
+ VALUE self, mode;
+{
+ gtk_widget_set_extension_events(get_widget(self),
+ (GdkExtensionMode)NUM2INT(mode));
+ return self;
+}
+
+static VALUE
+widget_unparent(self)
+ VALUE self;
+{
+ gtk_widget_unparent(get_widget(self));
+ return self;
+}
+
+static VALUE
+widget_window(self)
+ VALUE self;
+{
+ return make_gdkwindow(get_widget(self)->window);
+}
+
+static VALUE
+widget_get_toplevel(self)
+ VALUE self;
+{
+ return get_value_from_gobject(gtk_widget_get_toplevel(get_widget(self)));
+}
+
+static VALUE
+widget_get_ancestor(self, type)
+ VALUE self, type;
+{
+ GtkWidget *widget = get_widget(self);
+#if 0
+ if (obj_is_kind_of(type, cClass)) {
+ }
+#endif
+ widget = gtk_widget_get_ancestor(widget, NUM2INT(type));
+
+ return get_value_from_gobject(widget);
+}
+
+static VALUE
+widget_get_colormap(self)
+ VALUE self;
+{
+ GdkColormap *cmap = gtk_widget_get_colormap(get_widget(self));
+
+ return make_gdkcmap(cmap);
+}
+
+static VALUE
+widget_get_visual(self)
+ VALUE self;
+{
+ GdkVisual *v = gtk_widget_get_visual(get_widget(self));
+
+ return make_gdkvisual(v);
+}
+
+static VALUE
+widget_get_style(self)
+ VALUE self;
+{
+ GtkStyle *s = gtk_widget_get_style(get_widget(self));
+
+ return make_gstyle(s);
+}
+
+static VALUE
+widget_get_pointer(self)
+ VALUE self;
+{
+ int x, y;
+
+ gtk_widget_get_pointer(get_widget(self), &x, &y);
+ return assoc_new(INT2FIX(x), INT2FIX(y));
+}
+
+static VALUE
+widget_is_ancestor(self, ancestor)
+ VALUE self, ancestor;
+{
+ if (gtk_widget_is_ancestor(get_widget(self), get_widget(ancestor))) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static VALUE
+widget_is_child(self, child)
+ VALUE self, child;
+{
+ if (gtk_widget_is_child(get_widget(self), get_widget(child))) {
+ return TRUE;
+ }
+ return FALSE;
+}
+
+static VALUE
+widget_get_events(self)
+ VALUE self;
+{
+ int n = gtk_widget_get_events(get_widget(self));
+ return NUM2INT(n);
+}
+
+static VALUE
+widget_get_eevents(self)
+ VALUE self;
+{
+ GdkExtensionMode m;
+ m = gtk_widget_get_extension_events(get_widget(self));
+ return NUM2INT((int)m);
+}
+
+static VALUE
+widget_push_cmap(self, cmap)
+ VALUE self, cmap;
+{
+ gtk_widget_push_colormap(get_gdkcmap(cmap));
+ return Qnil;
+}
+
+static VALUE
+widget_push_visual(self, visual)
+ VALUE self, visual;
+{
+ gtk_widget_push_visual(get_gdkvisual(visual));
+ return make_gdkcmap(visual);
+}
+
+static VALUE
+widget_push_style(self, style)
+ VALUE self, style;
+{
+ gtk_widget_push_style(get_gstyle(style));
+ return Qnil;
+}
+
+static VALUE
+widget_pop_cmap(self, cmap)
+ VALUE self, cmap;
+{
+ gtk_widget_pop_colormap();
+ return Qnil;
+}
+
+static VALUE
+widget_pop_visual(self, visual)
+ VALUE self, visual;
+{
+ gtk_widget_pop_visual();
+ return Qnil;
+}
+
+static VALUE
+widget_pop_style(self, style)
+ VALUE self, style;
+{
+ gtk_widget_pop_style();
+ return Qnil;
+}
+
+static VALUE
+widget_set_default_cmap(self, cmap)
+ VALUE self, cmap;
+{
+ gtk_widget_set_default_colormap(get_gdkcmap(cmap));
+ return Qnil;
+}
+
+static VALUE
+widget_set_default_visual(self, visual)
+ VALUE self, visual;
+{
+ gtk_widget_set_default_visual(get_gdkvisual(visual));
+ return make_gdkcmap(visual);
+}
+
+static VALUE
+widget_set_default_style(self, style)
+ VALUE self, style;
+{
+ gtk_widget_set_default_style(get_gstyle(style));
+ return Qnil;
+}
+
+static VALUE
+widget_get_default_cmap(self)
+ VALUE self;
+{
+ GdkColormap *cmap = gtk_widget_get_default_colormap();
+
+ return make_gdkcmap(cmap);
+}
+
+static VALUE
+widget_get_default_visual(self)
+ VALUE self;
+{
+ GdkVisual *v = gtk_widget_get_default_visual();
+
+ return make_gdkvisual(v);
+}
+
+static VALUE
+widget_get_default_style(self)
+ VALUE self;
+{
+ GtkStyle *s = gtk_widget_get_default_style();
+
+ return make_gstyle(s);
+}
+
+static VALUE
+widget_propagate_default_style(self)
+ VALUE self;
+{
+ gtk_widget_propagate_default_style();
+ return Qnil;
+}
+
+static VALUE
+bbox_get_child_size_default(self)
+ VALUE self;
+{
+ int min_width, max_width;
+
+ gtk_button_box_get_child_size_default(&min_width, &max_width);
+
+ return assoc_new(INT2FIX(min_width), INT2FIX(max_width));
+}
+
+static VALUE
+bbox_get_child_ipadding_default(self)
+ VALUE self;
+{
+ int ipad_x, ipad_y;
+
+ gtk_button_box_get_child_ipadding_default(&ipad_x, &ipad_y);
+ return assoc_new(INT2FIX(ipad_x), INT2FIX(ipad_y));
+}
+
+static VALUE
+bbox_set_child_size_default(self, min_width, max_width)
+ VALUE self, min_width, max_width;
+{
+ gtk_button_box_set_child_size_default(NUM2INT(min_width),
+ NUM2INT(max_width));
+ return Qnil;
+}
+
+static VALUE
+bbox_set_child_ipadding_default(self, ipad_x, ipad_y)
+ VALUE self, ipad_x, ipad_y;
+{
+ gtk_button_box_set_child_ipadding_default(NUM2INT(ipad_x),
+ NUM2INT(ipad_y));
+ return Qnil;
+}
+
+static VALUE
+bbox_get_spacing(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int n = gtk_button_box_get_spacing(GTK_BUTTON_BOX(widget));
+
+ return INT2FIX(n);
+}
+
+static VALUE
+bbox_get_layout(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int n = gtk_button_box_get_layout(GTK_BUTTON_BOX(widget));
+
+ return INT2FIX(n);
+}
+
+static VALUE
+bbox_get_child_size(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int min_width, max_width;
+
+ gtk_button_box_get_child_size(GTK_BUTTON_BOX(widget),
+ &min_width, &max_width);
+ return assoc_new(INT2FIX(min_width), INT2FIX(max_width));
+}
+
+static VALUE
+bbox_get_child_ipadding(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int ipad_x, ipad_y;
+
+ gtk_button_box_get_child_ipadding(GTK_BUTTON_BOX(widget),
+ &ipad_x, &ipad_y);
+ return assoc_new(INT2FIX(ipad_x), INT2FIX(ipad_y));
+}
+
+static VALUE
+bbox_set_spacing(self, spacing)
+ VALUE self, spacing;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_box_set_spacing(GTK_BUTTON_BOX(widget),
+ NUM2INT(spacing));
+ return self;
+}
+
+static VALUE
+bbox_set_layout(self, layout)
+ VALUE self, layout;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_box_set_layout(GTK_BUTTON_BOX(widget),
+ NUM2INT(layout));
+ return self;
+}
+
+static VALUE
+bbox_set_child_size(self, min_width, max_width)
+ VALUE self, min_width, max_width;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_box_set_child_size(GTK_BUTTON_BOX(widget),
+ NUM2INT(min_width),
+ NUM2INT(max_width));
+ return self;
+}
+
+static VALUE
+bbox_set_child_ipadding(self, ipad_x, ipad_y)
+ VALUE self, ipad_x, ipad_y;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_box_set_child_ipadding(GTK_BUTTON_BOX(widget),
+ NUM2INT(ipad_x),
+ NUM2INT(ipad_y));
+ return self;
+}
+
+static VALUE
+clist_s_new(self, titles)
+ VALUE self, titles;
+{
+ char **buf;
+ int i, len;
+
+ Check_Type(titles, T_ARRAY);
+ len = RARRAY(titles)->len;
+ buf = ALLOCA_N(char*, len);
+ for (i=0; i<len; i++) {
+ Check_Type(RARRAY(titles)->ptr[i], T_STRING);
+ buf[i] = RSTRING(RARRAY(titles)->ptr[i])->ptr;
+ }
+ return make_widget(self, gtk_clist_new(len, buf));
+}
+
+static VALUE
+clist_set_border(self, border)
+ VALUE self, border;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_border(GTK_CLIST(widget), (GtkShadowType)NUM2INT(border));
+ return self;
+}
+
+static VALUE
+clist_set_sel_mode(self, mode)
+ VALUE self, mode;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_selection_mode(GTK_CLIST(widget),
+ (GtkSelectionMode)NUM2INT(mode));
+ return self;
+}
+
+static VALUE
+clist_set_policy(self, vpolicy, hpolicy)
+ VALUE self, vpolicy, hpolicy;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_policy(GTK_CLIST(widget),
+ (GtkPolicyType)NUM2INT(vpolicy),
+ (GtkPolicyType)NUM2INT(hpolicy));
+ return self;
+}
+
+static VALUE
+clist_freeze(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_freeze(GTK_CLIST(widget));
+ return self;
+}
+
+static VALUE
+clist_thaw(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_thaw(GTK_CLIST(widget));
+ return self;
+}
+
+static VALUE
+clist_set_col_title(self, col, title)
+ VALUE self, col, title;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_column_title(GTK_CLIST(widget),
+ NUM2INT(col),
+ get_cstring(title));
+ return self;
+}
+
+static VALUE
+clist_set_col_wigdet(self, col, win)
+ VALUE self, col, win;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_column_widget(GTK_CLIST(widget),
+ NUM2INT(col),
+ get_widget(win));
+ return self;
+}
+
+static VALUE
+clist_set_col_just(self, col, just)
+ VALUE self, col, just;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_column_justification(GTK_CLIST(widget),
+ NUM2INT(col),
+ (GtkJustification)NUM2INT(just));
+ return self;
+}
+
+static VALUE
+clist_set_col_width(self, col, width)
+ VALUE self, col, width;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_column_width(GTK_CLIST(widget),
+ NUM2INT(col), NUM2INT(width));
+ return self;
+}
+
+static VALUE
+clist_set_row_height(self, height)
+ VALUE self, height;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_row_height(GTK_CLIST(widget), NUM2INT(height));
+ return self;
+}
+
+static VALUE
+clist_moveto(self, row, col, row_align, col_align)
+ VALUE self, row, col, row_align, col_align;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_moveto(GTK_CLIST(widget),
+ NUM2INT(row), NUM2INT(col),
+ NUM2INT(row_align), NUM2INT(col_align));
+ return self;
+}
+
+static VALUE
+clist_set_text(self, row, col, text)
+ VALUE self, row, col, text;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_text(GTK_CLIST(widget),
+ NUM2INT(row), NUM2INT(col),
+ get_cstring(text));
+ return self;
+}
+
+static VALUE
+clist_set_pixmap(self, row, col, pixmap, mask)
+ VALUE self, row, col, pixmap, mask;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_pixmap(GTK_CLIST(widget),
+ NUM2INT(row), NUM2INT(col),
+ get_gdkpixmap(pixmap),
+ (GdkBitmap*)get_gdkpixmap(mask));
+ return self;
+}
+
+static VALUE
+clist_set_pixtext(self, row, col, text, spacing, pixmap, mask)
+ VALUE self, row, col, text, spacing, pixmap, mask;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_pixtext(GTK_CLIST(widget),
+ NUM2INT(row), NUM2INT(col),
+ get_cstring(text),
+ NUM2INT(spacing),
+ get_gdkpixmap(pixmap),
+ (GdkBitmap*)get_gdkpixmap(mask));
+ return self;
+}
+
+static VALUE
+clist_set_foreground(self, row, color)
+ VALUE self, row, color;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_foreground(GTK_CLIST(widget),
+ NUM2INT(row), get_gdkcolor(color));
+ return self;
+}
+
+static VALUE
+clist_set_background(self, row, color)
+ VALUE self, row, color;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_background(GTK_CLIST(widget),
+ NUM2INT(row), get_gdkcolor(color));
+ return self;
+}
+
+static VALUE
+clist_set_shift(self, row, col, verticle, horizontal)
+ VALUE self, row, col, verticle, horizontal;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_set_shift(GTK_CLIST(widget),
+ NUM2INT(row), NUM2INT(col),
+ NUM2INT(verticle), NUM2INT(horizontal));
+ return self;
+}
+
+static VALUE
+clist_append(self, text)
+ VALUE self, text;
+{
+ GtkWidget *widget = get_widget(self);
+ char **buf;
+ int i, len;
+
+ Check_Type(text, T_ARRAY);
+ len = GTK_CLIST(widget)->columns;
+ if (len > RARRAY(text)->len) {
+ ArgError("text too short");
+ }
+ buf = ALLOCA_N(char*, len);
+ for (i=0; i<len; i++) {
+ Check_Type(RARRAY(text)->ptr[i], T_STRING);
+ buf[i] = RSTRING(RARRAY(text)->ptr[i])->ptr;
+ }
+ i = gtk_clist_append(GTK_CLIST(widget), buf);
+ return INT2FIX(i);
+}
+
+static VALUE
+clist_insert(self, row, text)
+ VALUE self, row, text;
+{
+ GtkWidget *widget = get_widget(self);
+ char **buf;
+ int i, len;
+
+ Check_Type(text, T_ARRAY);
+ len = GTK_CLIST(widget)->columns;
+ if (len > RARRAY(text)->len) {
+ ArgError("text too short");
+ }
+ buf = ALLOCA_N(char*, len);
+ for (i=0; i<len; i++) {
+ Check_Type(RARRAY(text)->ptr[i], T_STRING);
+ buf[i] = RSTRING(RARRAY(text)->ptr[i])->ptr;
+ }
+ gtk_clist_insert(GTK_CLIST(widget), NUM2INT(row), buf);
+ return self;
+}
+
+static VALUE
+clist_remove(self, row)
+ VALUE self, row;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_remove(GTK_CLIST(widget), NUM2INT(row));
+ return self;
+}
+
+static VALUE
+clist_set_row_data(self, row, data)
+ VALUE self, row, data;
+{
+ GtkWidget *widget = get_widget(self);
+
+ add_relative(self, data);
+ gtk_clist_set_row_data(GTK_CLIST(widget), NUM2INT(row), (gpointer)data);
+ return self;
+}
+
+static VALUE
+clist_get_row_data(self, row)
+ VALUE self, row;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return (VALUE)gtk_clist_get_row_data(GTK_CLIST(widget), NUM2INT(row));
+}
+
+static VALUE
+clist_select_row(self, row, col)
+ VALUE self, row, col;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_select_row(GTK_CLIST(widget), NUM2INT(row), NUM2INT(col));
+ return self;
+}
+
+static VALUE
+clist_unselect_row(self, row, col)
+ VALUE self, row, col;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_unselect_row(GTK_CLIST(widget), NUM2INT(row), NUM2INT(col));
+ return self;
+}
+
+static VALUE
+clist_clear(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_clist_clear(GTK_CLIST(widget));
+ return self;
+}
+
+static VALUE
+gwin_s_new(self, type)
+ VALUE self, type;
+{
+ return make_widget(self, gtk_window_new(NUM2INT(type)));
+}
+
+static VALUE
+gwin_set_policy(self, shrink, grow, auto_shrink)
+ VALUE self, shrink, grow, auto_shrink;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_set_policy(GTK_WINDOW(widget),
+ RTEST(shrink), RTEST(grow), RTEST(auto_shrink));
+ return self;
+}
+
+static VALUE
+gwin_set_title(self, title)
+ VALUE self, title;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_set_title(GTK_WINDOW(widget), get_cstring(title));
+ return self;
+}
+
+static VALUE
+gwin_position(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_position(GTK_WINDOW(widget),
+ (GtkWindowPosition)NUM2INT(pos));
+
+ return self;
+}
+
+static VALUE
+gwin_set_wmclass(self, wmclass1, wmclass2)
+ VALUE self, wmclass1, wmclass2;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_set_wmclass(GTK_WINDOW(widget),
+ get_cstring(wmclass1),
+ get_cstring(wmclass2));
+ return self;
+}
+
+static VALUE
+gwin_set_focus(self, win)
+ VALUE self, win;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_set_focus(GTK_WINDOW(widget), get_widget(win));
+ return self;
+}
+
+static VALUE
+gwin_set_default(self, win)
+ VALUE self, win;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_set_default(GTK_WINDOW(widget), get_widget(win));
+ return self;
+}
+
+static VALUE
+gwin_add_accel(self, accel)
+ VALUE self, accel;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_add_accelerator_table(GTK_WINDOW(widget),
+ get_gtkacceltbl(accel));
+ return self;
+}
+
+static VALUE
+gwin_rm_accel(self, accel)
+ VALUE self, accel;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_window_remove_accelerator_table(GTK_WINDOW(widget),
+ get_gtkacceltbl(accel));
+ return self;
+}
+
+static VALUE
+dialog_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_dialog_new());
+}
+
+static VALUE
+fsel_s_new(self, title)
+ VALUE self, title;
+{
+ return make_widget(self, gtk_file_selection_new(get_cstring(title)));
+}
+
+static VALUE
+fsel_set_fname(self, fname)
+ VALUE self, fname;
+{
+ GtkWidget *widget = get_widget(self);
+
+ Check_Type(fname, T_STRING);
+ gtk_file_selection_set_filename(GTK_FILE_SELECTION(widget),
+ RSTRING(fname)->ptr);
+
+ return self;
+}
+
+static VALUE
+fsel_get_fname(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ gchar *fname;
+
+ fname = gtk_file_selection_get_filename(GTK_FILE_SELECTION(widget));
+
+ return str_new2(fname);
+}
+
+static VALUE
+fsel_ok_button(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ VALUE b = rb_iv_get(self, "ok_button");
+
+ if (NIL_P(b)) {
+ GtkWidget *w = GTK_FILE_SELECTION(widget)->ok_button;
+ b = make_widget(gButton, w);
+ rb_iv_set(self, "ok_button", b);
+ }
+
+ return b;
+}
+
+static VALUE
+fsel_cancel_button(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ VALUE b = rb_iv_get(self, "cancel_button");
+
+ if (NIL_P(b)) {
+ GtkWidget *w = GTK_FILE_SELECTION(widget)->cancel_button;
+ b = make_widget(gButton, w);
+ rb_iv_set(self, "cancel_button", b);
+ }
+
+ return b;
+}
+
+static VALUE
+fsel_help_button(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ VALUE b = rb_iv_get(self, "help_button");
+
+ if (NIL_P(b)) {
+ GtkWidget *w = GTK_FILE_SELECTION(widget)->help_button;
+ b = make_widget(gButton, w);
+ rb_iv_set(self, "help_button", b);
+ }
+
+ return b;
+}
+
+static VALUE
+label_s_new(self, label)
+ VALUE self, label;
+{
+ return make_widget(self, gtk_label_new(get_cstring(label)));
+}
+
+static VALUE
+list_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_list_new());
+}
+
+static VALUE
+list_set_sel_mode(self, mode)
+ VALUE self, mode;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_list_set_selection_mode(GTK_LIST(widget),
+ (GtkSelectionMode)NUM2INT(mode));
+ return self;
+}
+
+static VALUE
+list_sel_mode(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return INT2FIX(GTK_LIST(widget)->selection_mode);
+}
+
+static VALUE
+list_selection(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ return glist2ary(GTK_LIST(widget)->selection);
+}
+
+static VALUE
+list_insert_items(self, items, pos)
+ VALUE self, items, pos;
+{
+ GtkWidget *widget = get_widget(self);
+ GList *glist;
+
+ glist = ary2glist(items);
+
+ gtk_list_insert_items(GTK_LIST(widget), glist, NUM2INT(pos));
+ g_list_free(glist);
+
+ return self;
+}
+
+static VALUE
+list_append_items(self, items)
+ VALUE self, items;
+{
+ GtkWidget *widget = get_widget(self);
+ GList *glist;
+
+ glist = ary2glist(items);
+
+ gtk_list_append_items(GTK_LIST(widget), glist);
+ g_list_free(glist);
+
+ return self;
+}
+
+static VALUE
+list_prepend_items(self, items)
+ VALUE self, items;
+{
+ GtkWidget *widget = get_widget(self);
+ GList *glist;
+
+ glist = ary2glist(items);
+ gtk_list_prepend_items(GTK_LIST(widget), glist);
+ g_list_free(glist);
+
+ return self;
+}
+
+static VALUE
+list_remove_items(self, items)
+ VALUE self, items;
+{
+ GtkWidget *widget = get_widget(self);
+ GList *glist;
+
+ glist = ary2glist(items);
+ gtk_list_remove_items(GTK_LIST(widget), glist);
+ g_list_free(glist);
+
+ return self;
+}
+
+static VALUE
+list_clear_items(self, start, end)
+ VALUE self, start, end;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_list_clear_items(GTK_LIST(widget), NUM2INT(start), NUM2INT(end));
+ return self;
+}
+
+static VALUE
+list_select_item(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_list_select_item(GTK_LIST(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+list_unselect_item(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_list_unselect_item(GTK_LIST(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+list_select_child(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_list_select_child(GTK_LIST(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+list_unselect_child(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_list_unselect_child(GTK_LIST(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+list_child_position(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+ gint pos;
+
+ pos = gtk_list_child_position(GTK_LIST(widget), get_widget(child));
+ return INT2FIX(pos);
+}
+
+static VALUE
+item_select(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_item_select(GTK_ITEM(widget));
+ return self;
+}
+
+static VALUE
+item_deselect(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_item_deselect(GTK_ITEM(widget));
+ return self;
+}
+
+static VALUE
+item_toggle(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_item_toggle(GTK_ITEM(widget));
+ return self;
+}
+
+static VALUE
+litem_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ widget = gtk_list_item_new_with_label(get_cstring(label));
+ }
+ else {
+ widget = gtk_list_item_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+mshell_append(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_shell_append(GTK_MENU_SHELL(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+mshell_prepend(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_shell_prepend(GTK_MENU_SHELL(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+mshell_insert(self, child, pos)
+ VALUE self, child, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_shell_insert(GTK_MENU_SHELL(widget), get_widget(child),
+ NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+mshell_deactivate(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_shell_deactivate(GTK_MENU_SHELL(widget));
+ return self;
+}
+
+static VALUE
+menu_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_menu_new());
+}
+
+static VALUE
+menu_append(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_append(GTK_MENU(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+menu_prepend(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_prepend(GTK_MENU(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+menu_insert(self, child, pos)
+ VALUE self, child, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_insert(GTK_MENU(widget), get_widget(child), NUM2INT(pos));
+ return self;
+}
+
+static void
+menu_pos_func(menu, x, y, data)
+ GtkMenu *menu;
+ gint x, y;
+ gpointer data;
+{
+ VALUE m = get_value_from_gobject(GTK_OBJECT(menu));
+
+ rb_funcall((VALUE)data, 3, m, INT2FIX(x), INT2FIX(y));
+}
+
+static VALUE
+menu_popup(self, pshell, pitem, func, button, activate_time)
+ VALUE self, pshell, pitem, func, button, activate_time;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkMenuPositionFunc pfunc = NULL;
+ gpointer data = NULL;
+
+ if (!NIL_P(func)) {
+ pfunc = menu_pos_func;
+ data = (gpointer)func;
+ add_relative(self, func);
+ }
+ gtk_menu_popup(GTK_MENU(widget),
+ get_widget(pshell), get_widget(pitem),
+ pfunc,
+ data,
+ NUM2INT(button),
+ NUM2INT(activate_time));
+ return self;
+}
+
+static VALUE
+menu_popdown(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_popdown(GTK_MENU(widget));
+ return self;
+}
+
+static VALUE
+menu_get_active(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkWidget *mitem = gtk_menu_get_active(GTK_MENU(widget));
+
+ return make_widget(gMenuItem, mitem);
+}
+
+static VALUE
+menu_set_active(self, active)
+ VALUE self, active;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_set_active(GTK_MENU(widget), NUM2INT(active));
+ return self;
+}
+
+static VALUE
+menu_set_acceltbl(self, table)
+ VALUE self, table;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_set_accelerator_table(GTK_MENU(widget),
+ get_gtkacceltbl(table));
+ return self;
+}
+
+static VALUE
+mbar_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_menu_bar_new());
+}
+
+static VALUE
+mbar_append(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_bar_append(GTK_MENU_BAR(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+mbar_prepend(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_bar_prepend(GTK_MENU_BAR(widget), get_widget(child));
+ return self;
+}
+static VALUE
+mbar_insert(self, child, pos)
+ VALUE self, child, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_bar_insert(GTK_MENU_BAR(widget),
+ get_widget(child), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+mitem_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ widget = gtk_menu_item_new_with_label(get_cstring(label));
+ }
+ else {
+ widget = gtk_menu_item_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+mitem_set_submenu(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_set_submenu(GTK_MENU_ITEM(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+mitem_set_placement(self, place)
+ VALUE self, place;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_set_placement(GTK_MENU_ITEM(widget),
+ (GtkSubmenuPlacement)NUM2INT(place));
+ return self;
+}
+
+static VALUE
+mitem_accelerator_size(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_accelerator_size(GTK_MENU_ITEM(widget));
+ return self;
+}
+
+static VALUE
+mitem_accelerator_text(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ char buf[1024]; /* enough? */
+
+ gtk_menu_item_accelerator_text(GTK_MENU_ITEM(widget), buf);
+ return str_new2(buf);
+}
+
+static VALUE
+mitem_configure(self, show_toggle, show_submenu)
+ VALUE self, show_toggle, show_submenu;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_configure(GTK_MENU_ITEM(widget),
+ NUM2INT(show_toggle),
+ NUM2INT(show_submenu));
+ return self;
+}
+
+static VALUE
+mitem_select(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_select(GTK_MENU_ITEM(widget));
+ return self;
+}
+
+static VALUE
+mitem_deselect(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_deselect(GTK_MENU_ITEM(widget));
+ return self;
+}
+
+static VALUE
+mitem_activate(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_activate(GTK_MENU_ITEM(widget));
+ return self;
+}
+
+static VALUE
+mitem_right_justify(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_menu_item_right_justify(GTK_MENU_ITEM(widget));
+ return self;
+}
+
+static VALUE
+cmitem_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ widget = gtk_check_menu_item_new_with_label(get_cstring(label));
+ }
+ else {
+ widget = gtk_check_menu_item_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+cmitem_set_state(self, state)
+ VALUE self, state;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_check_menu_item_set_state(GTK_CHECK_MENU_ITEM(widget),
+ NUM2INT(state));
+ return self;
+}
+
+static VALUE
+cmitem_set_show_toggle(self, always)
+ VALUE self, always;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_check_menu_item_set_show_toggle(GTK_CHECK_MENU_ITEM(widget),
+ (gboolean)RTEST(always));
+ return self;
+}
+
+static VALUE
+cmitem_toggled(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_check_menu_item_toggled(GTK_CHECK_MENU_ITEM(widget));
+ return self;
+}
+
+static VALUE
+rmitem_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE arg1, arg2;
+ GtkWidget *widget;
+ GSList *list = NULL;
+ char *label = NULL;
+
+ if (rb_scan_args(argc, argv, "02", &arg1, &arg2) == 1 &&
+ TYPE(arg1) == T_STRING) {
+ label = RSTRING(arg1)->ptr;
+ }
+ else {
+ if (!NIL_P(arg2)) {
+ Check_Type(arg2, T_STRING);
+ label = RSTRING(arg2)->ptr;
+ }
+ if (obj_is_kind_of(arg1, gRMenuItem)) {
+ GtkWidget *b = get_widget(arg1);
+ list = GTK_RADIO_MENU_ITEM(b)->group;
+ }
+ else {
+ list = ary2gslist(arg1);
+ }
+ }
+ if (label) {
+ widget = gtk_radio_menu_item_new_with_label(list, label);
+ }
+ else {
+ widget = gtk_radio_menu_item_new(list);
+ }
+ return make_widget(self, widget);
+}
+
+static VALUE
+rmitem_group(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return gslist2ary(gtk_radio_menu_item_group(GTK_RADIO_MENU_ITEM(widget)));
+}
+
+static VALUE
+note_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_notebook_new());
+}
+
+static VALUE
+note_append_page(self, child, label)
+ VALUE self, child, label;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_append_page(GTK_NOTEBOOK(widget),
+ get_widget(child),
+ get_widget(label));
+ return self;
+}
+
+static VALUE
+note_prepend_page(self, child, label)
+ VALUE self, child, label;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_prepend_page(GTK_NOTEBOOK(widget),
+ get_widget(child),
+ get_widget(label));
+ return self;
+}
+
+static VALUE
+note_insert_page(self, child, label, pos)
+ VALUE self, child, label, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_insert_page(GTK_NOTEBOOK(widget),
+ get_widget(child),
+ get_widget(label),
+ NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+note_remove_page(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_remove_page(GTK_NOTEBOOK(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+note_set_page(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_set_page(GTK_NOTEBOOK(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+note_cur_page(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return INT2FIX(GTK_NOTEBOOK(widget)->cur_page);
+}
+
+static VALUE
+note_next_page(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_next_page(GTK_NOTEBOOK(widget));
+ return self;
+}
+
+static VALUE
+note_prev_page(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_prev_page(GTK_NOTEBOOK(widget));
+ return self;
+}
+
+static VALUE
+note_set_tab_pos(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_set_tab_pos(GTK_NOTEBOOK(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+note_tab_pos(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return INT2FIX(GTK_NOTEBOOK(widget)->tab_pos);
+}
+
+static VALUE
+note_set_show_tabs(self, show_tabs)
+ VALUE self, show_tabs;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_set_tab_pos(GTK_NOTEBOOK(widget), RTEST(show_tabs));
+ return self;
+}
+
+static VALUE
+note_show_tabs(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return GTK_NOTEBOOK(widget)->show_tabs?TRUE:FALSE;
+}
+
+static VALUE
+note_set_show_border(self, show_border)
+ VALUE self, show_border;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_notebook_set_tab_pos(GTK_NOTEBOOK(widget), RTEST(show_border));
+ return self;
+}
+
+static VALUE
+note_show_border(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return GTK_NOTEBOOK(widget)->show_border?TRUE:FALSE;
+}
+
+static VALUE
+omenu_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_option_menu_new());
+}
+
+static VALUE
+omenu_set_menu(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ rb_iv_set(self, "option_menu", child);
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+omenu_get_menu(self)
+ VALUE self;
+{
+ return rb_iv_get(self, "option_menu");
+}
+
+static VALUE
+omenu_remove_menu(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_option_menu_remove_menu(GTK_OPTION_MENU(widget));
+ return self;
+}
+
+static VALUE
+omenu_set_history(self, index)
+ VALUE self, index;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_option_menu_set_history(GTK_OPTION_MENU(widget), NUM2INT(index));
+ return self;
+}
+
+static VALUE
+image_s_new(self, val, mask)
+ VALUE self, val, mask;
+{
+ return make_widget(self, gtk_image_new(get_gdkimage(val),
+ (GdkBitmap*)get_gdkpixmap(mask)));
+}
+
+static VALUE
+image_set(self, val, mask)
+ VALUE self, val, mask;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_image_set(GTK_IMAGE(widget), get_gdkimage(val), get_gdkpixmap(mask));
+ return self;
+}
+
+static VALUE
+image_get(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ GdkImage *val;
+ GdkBitmap *mask;
+
+ gtk_image_get(GTK_IMAGE(widget), &val, &mask);
+
+ return assoc_new(make_gdkimage(self, val),
+ make_gdkpixmap(self, mask));
+}
+
+static VALUE
+preview_s_new(self, type)
+ VALUE self, type;
+{
+ return make_widget(self, gtk_preview_new((GtkPreviewType)NUM2INT(type)));
+}
+
+
+static VALUE
+preview_size(self, w, h)
+ VALUE self, w, h;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_preview_size(GTK_PREVIEW(widget), NUM2INT(w), NUM2INT(h));
+ return self;
+}
+
+#if 0
+ rb_define_method(gPixmap, "put", preview_size, 8);
+ rb_define_method(gPixmap, "put_row", preview_size, 5);
+ rb_define_method(gPixmap, "draw_row", preview_size, 4);
+#endif
+
+static VALUE
+preview_set_expand(self, expand)
+ VALUE self, expand;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_preview_set_expand(GTK_PREVIEW(widget), NUM2INT(expand));
+ return self;
+}
+
+static VALUE
+preview_set_gamma(self, gamma)
+ VALUE self, gamma;
+{
+ gtk_preview_set_gamma(NUM2DBL(gamma));
+ return Qnil;
+}
+
+static VALUE
+preview_set_color_cube(self, nred, ngreen, nblue, ngray)
+ VALUE self, nred, ngreen, nblue, ngray;
+{
+ gtk_preview_set_color_cube(NUM2INT(nred),
+ NUM2INT(ngreen),
+ NUM2INT(nblue),
+ NUM2INT(ngray));
+ return Qnil;
+}
+
+static VALUE
+preview_set_install_cmap(self, cmap)
+ VALUE self, cmap;
+{
+ gtk_preview_set_install_cmap(NUM2INT(cmap));
+ return Qnil;
+}
+
+static VALUE
+preview_set_reserved(self, nreserved)
+ VALUE self, nreserved;
+{
+ gtk_preview_set_reserved(NUM2INT(nreserved));
+ return Qnil;
+}
+
+static VALUE
+preview_get_visual(self)
+ VALUE self;
+{
+ GdkVisual *v = gtk_preview_get_visual();
+ return make_gdkvisual(v);
+}
+
+static VALUE
+preview_get_cmap(self)
+ VALUE self;
+{
+ GdkColormap *c = gtk_preview_get_cmap();
+ return make_gdkcmap(c);
+}
+
+static VALUE
+preview_get_info(self)
+ VALUE self;
+{
+ GtkPreviewInfo *i = gtk_preview_get_info();
+ return make_gtkprevinfo(i);
+}
+
+static VALUE
+pbar_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_progress_bar_new());
+}
+
+static VALUE
+pbar_update(self, percentage)
+ VALUE self, percentage;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_progress_bar_update(GTK_PROGRESS_BAR(widget),
+ NUM2DBL(percentage));
+ return self;
+}
+
+static VALUE
+scwin_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1, arg2;
+ GtkAdjustment *h_adj = NULL;
+ GtkAdjustment *v_adj = NULL;
+
+ rb_scan_args(argc, argv, "02", &arg1, &arg2);
+ if (!NIL_P(arg1)) h_adj = (GtkAdjustment*)get_gobject(arg1);
+ if (!NIL_P(arg2)) v_adj = (GtkAdjustment*)get_gobject(arg2);
+
+ return make_widget(self, gtk_scrolled_window_new(h_adj, v_adj));
+}
+
+static VALUE
+scwin_set_policy(self, hpolicy, vpolicy)
+ VALUE self, hpolicy, vpolicy;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget),
+ (GtkPolicyType)NUM2INT(hpolicy),
+ (GtkPolicyType)NUM2INT(vpolicy));
+ return self;
+}
+
+
+static VALUE
+tbl_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE row, col, homogeneous;
+
+ rb_scan_args(argc, argv, "21", &row, &col, &homogeneous);
+ return make_widget(self, gtk_table_new(NUM2INT(row),
+ NUM2INT(col),
+ RTEST(homogeneous)));
+}
+
+static VALUE
+tbl_attach(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ VALUE child, left, right, top, bottom;
+ VALUE arg0, arg1, arg2, arg3;
+ int xopt, yopt, xspc, yspc;
+
+ xopt = yopt = GTK_EXPAND | GTK_FILL;
+ xspc = yspc = 0;
+ rb_scan_args(argc, argv, "54",
+ &child, &left, &right, &top, &bottom,
+ &arg0, &arg1, &arg2, &arg3);
+ if (!NIL_P(arg0)) xopt = NUM2INT(arg0);
+ if (!NIL_P(arg1)) yopt = NUM2INT(arg1);
+ if (!NIL_P(arg2)) xspc = NUM2INT(arg2);
+ if (!NIL_P(arg3)) yspc = NUM2INT(arg3);
+
+ gtk_table_attach(GTK_TABLE(widget),
+ get_widget(child),
+ NUM2INT(left),NUM2INT(right),
+ NUM2INT(top),NUM2INT(bottom),
+ xopt, yopt, xspc, yspc);
+
+ return self;
+}
+
+static VALUE
+tbl_set_row_spacing(self, row, spc)
+ VALUE self, row, spc;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_table_set_row_spacing(GTK_TABLE(widget), NUM2INT(row), NUM2INT(spc));
+ return self;
+}
+
+static VALUE
+tbl_set_col_spacing(self, col, spc)
+ VALUE self, col, spc;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_table_set_col_spacing(GTK_TABLE(widget), NUM2INT(col), NUM2INT(spc));
+ return self;
+}
+
+static VALUE
+tbl_set_row_spacings(self, spc)
+ VALUE self, spc;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_table_set_row_spacings(GTK_TABLE(widget), NUM2INT(spc));
+ return self;
+}
+
+static VALUE
+tbl_set_col_spacings(self, spc)
+ VALUE self, spc;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_table_set_col_spacings(GTK_TABLE(widget), NUM2INT(spc));
+ return self;
+}
+
+static VALUE
+txt_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1, arg2;
+ GtkAdjustment *h_adj = NULL;
+ GtkAdjustment *v_adj = NULL;
+
+ rb_scan_args(argc, argv, "02", &arg1, &arg2);
+ if (!NIL_P(arg1)) h_adj = (GtkAdjustment*)get_gobject(arg1);
+ if (!NIL_P(arg2)) v_adj = (GtkAdjustment*)get_gobject(arg2);
+
+ return make_widget(self, gtk_text_new(h_adj, v_adj));
+}
+
+static VALUE
+txt_set_editable(self, editable)
+ VALUE self, editable;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_set_editable(GTK_TEXT(widget), RTEST(editable));
+ return self;
+}
+
+static VALUE
+txt_set_adjustment(self, h_adj, v_adj)
+ VALUE self, h_adj, v_adj;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_set_adjustments(GTK_TEXT(widget),
+ (GtkAdjustment*)get_gobject(h_adj),
+ (GtkAdjustment*)get_gobject(v_adj));
+
+ return self;
+}
+
+static VALUE
+txt_set_point(self, index)
+ VALUE self, index;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_set_point(GTK_TEXT(widget), NUM2INT(index));
+ return self;
+}
+
+static VALUE
+txt_get_point(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int index = gtk_text_get_point(GTK_TEXT(widget));
+
+ return INT2FIX(index);
+}
+
+static VALUE
+txt_get_length(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int len = gtk_text_get_length(GTK_TEXT(widget));
+
+ return INT2FIX(len);
+}
+
+static VALUE
+txt_freeze(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_freeze(GTK_TEXT(widget));
+ return self;
+}
+
+static VALUE
+txt_thaw(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_thaw(GTK_TEXT(widget));
+ return self;
+}
+
+static VALUE
+txt_insert(self, font, fore, back, str)
+ VALUE self, font, fore, back, str;
+{
+ GtkWidget *widget = get_widget(self);
+
+ Check_Type(str, T_STRING);
+ gtk_text_insert(GTK_TEXT(widget),
+ get_gdkfont(font),
+ get_gdkcolor(fore),
+ get_gdkcolor(back),
+ RSTRING(str)->ptr,
+ RSTRING(str)->len);
+
+ return self;
+}
+
+static VALUE
+txt_backward_delete(self, nchars)
+ VALUE self, nchars;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_backward_delete(GTK_TEXT(widget), NUM2INT(nchars));
+ return self;
+}
+
+static VALUE
+txt_forward_delete(self, nchars)
+ VALUE self, nchars;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_text_forward_delete(GTK_TEXT(widget), NUM2INT(nchars));
+ return self;
+}
+
+static VALUE
+tbar_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1, arg2;
+ GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
+ GtkToolbarStyle style = GTK_TOOLBAR_BOTH;
+
+ rb_scan_args(argc, argv, "02", &arg1, &arg2);
+ if (!NIL_P(arg1)) orientation = (GtkOrientation)NUM2INT(arg1);
+ if (!NIL_P(arg2)) style = (GtkToolbarStyle)NUM2INT(arg2);
+
+ return make_widget(self, gtk_toolbar_new(orientation, style));
+}
+
+static VALUE
+tbar_append_item(self, text, ttext, icon, func)
+ VALUE self, text, ttext, icon, func;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkObject *pixmap = get_gobject(icon);
+
+ if (NIL_P(func)) {
+ func = f_lambda();
+ }
+ gtk_toolbar_append_item(GTK_TOOLBAR(widget),
+ get_cstring(text),
+ get_cstring(ttext),
+ GTK_PIXMAP(pixmap),
+ exec_callback,
+ (gpointer)ary_new3(1, func));
+ return self;
+}
+
+static VALUE
+tbar_prepend_item(self, text, ttext, icon, func)
+ VALUE self, text, ttext, icon, func;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkObject *pixmap = get_gobject(icon);
+
+ if (NIL_P(func)) {
+ func = f_lambda();
+ }
+ gtk_toolbar_prepend_item(GTK_TOOLBAR(widget),
+ get_cstring(text),
+ get_cstring(ttext),
+ GTK_PIXMAP(pixmap),
+ exec_callback,
+ (gpointer)ary_new3(1, func));
+ return self;
+}
+
+static VALUE
+tbar_insert_item(self, text, ttext, icon, func, pos)
+ VALUE self, text, ttext, icon, func, pos;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkObject *pixmap = get_gobject(icon);
+
+ if (NIL_P(func)) {
+ func = f_lambda();
+ }
+ gtk_toolbar_insert_item(GTK_TOOLBAR(widget),
+ get_cstring(text),
+ get_cstring(ttext),
+ GTK_PIXMAP(pixmap),
+ exec_callback,
+ (gpointer)ary_new3(1, func),
+ NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+tbar_append_space(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_append_space(GTK_TOOLBAR(widget));
+ return self;
+}
+
+static VALUE
+tbar_prepend_space(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_prepend_space(GTK_TOOLBAR(widget));
+ return self;
+}
+
+static VALUE
+tbar_insert_space(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_insert_space(GTK_TOOLBAR(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+tbar_set_orientation(self, orientation)
+ VALUE self, orientation;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_set_orientation(GTK_TOOLBAR(widget),
+ (GtkOrientation)NUM2INT(orientation));
+ return self;
+}
+
+static VALUE
+tbar_set_style(self, style)
+ VALUE self, style;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_set_style(GTK_TOOLBAR(widget),
+ (GtkToolbarStyle)NUM2INT(style));
+ return self;
+}
+
+static VALUE
+tbar_set_space_size(self, size)
+ VALUE self, size;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_set_space_size(GTK_TOOLBAR(widget), NUM2INT(size));
+ return self;
+}
+
+static VALUE
+tbar_set_tooltips(self, enable)
+ VALUE self, enable;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toolbar_set_tooltips(GTK_TOOLBAR(widget), RTEST(enable));
+ return self;
+}
+
+static VALUE
+ttips_s_new(self)
+ VALUE self;
+{
+ return make_ttips(self, gtk_tooltips_new());
+}
+
+static VALUE
+ttips_set_tips(self, win, text)
+ VALUE self, win, text;
+{
+ Check_Type(text, T_STRING);
+ gtk_tooltips_set_tips(get_ttips(self),
+ get_widget(win),
+ RSTRING(text)->ptr);
+
+ return self;
+}
+
+static VALUE
+ttips_set_delay(self, delay)
+ VALUE self, delay;
+{
+ gtk_tooltips_set_delay(get_ttips(self), NUM2INT(delay));
+
+ return self;
+}
+
+static VALUE
+ttips_enable(self)
+ VALUE self;
+{
+ gtk_tooltips_enable(get_ttips(self));
+ return self;
+}
+
+static VALUE
+ttips_disable(self)
+ VALUE self;
+{
+ gtk_tooltips_enable(get_ttips(self));
+ return self;
+}
+
+static VALUE
+tree_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_tree_new());
+}
+
+static VALUE
+tree_append(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_append(GTK_TREE(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+tree_prepend(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_prepend(GTK_TREE(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+tree_insert(self, child, pos)
+ VALUE self, child, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_insert(GTK_TREE(widget), get_widget(child), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+titem_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ Check_Type(label, T_STRING);
+ widget = gtk_tree_item_new_with_label(RSTRING(label)->ptr);
+ }
+ else {
+ widget = gtk_tree_item_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+titem_set_subtree(self, subtree)
+ VALUE self, subtree;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_item_set_subtree(GTK_TREE_ITEM(widget), get_widget(subtree));
+ return self;
+}
+
+static VALUE
+titem_select(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_item_select(GTK_TREE_ITEM(widget));
+ return self;
+}
+
+static VALUE
+titem_deselect(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_item_deselect(GTK_TREE_ITEM(widget));
+ return self;
+}
+
+static VALUE
+titem_expand(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_item_expand(GTK_TREE_ITEM(widget));
+ return self;
+}
+
+static VALUE
+titem_collapse(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_tree_item_collapse(GTK_TREE_ITEM(widget));
+ return self;
+}
+
+static VALUE
+vport_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1, arg2;
+ GtkAdjustment *h_adj = NULL;
+ GtkAdjustment *v_adj = NULL;
+
+ rb_scan_args(argc, argv, "02", &arg1, &arg2);
+ if (!NIL_P(arg1)) h_adj = (GtkAdjustment*)get_gobject(arg1);
+ if (!NIL_P(arg2)) v_adj = (GtkAdjustment*)get_gobject(arg2);
+
+ return make_widget(self, gtk_viewport_new(h_adj, v_adj));
+}
+
+static VALUE
+vport_get_hadj(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkAdjustment *adj = gtk_viewport_get_hadjustment(GTK_VIEWPORT(widget));
+
+ return make_gobject(gAdjustment, GTK_OBJECT(adj));
+}
+
+static VALUE
+vport_get_vadj(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkAdjustment *adj = gtk_viewport_get_vadjustment(GTK_VIEWPORT(widget));
+
+ return make_gobject(gAdjustment, GTK_OBJECT(adj));
+}
+
+static VALUE
+vport_set_vadj(self, adj)
+ VALUE self, adj;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkObject *adjustment = get_gobject(adj);
+
+ gtk_viewport_set_vadjustment(GTK_VIEWPORT(widget),
+ GTK_ADJUSTMENT(adj));
+
+ return self;
+}
+
+static VALUE
+vport_set_hadj(self, adj)
+ VALUE self, adj;
+{
+ GtkWidget *widget = get_widget(self);
+ GtkObject *adjustment = get_gobject(adj);
+
+ gtk_viewport_set_hadjustment(GTK_VIEWPORT(widget),
+ GTK_ADJUSTMENT(adj));
+
+ return self;
+}
+
+static VALUE
+vport_set_shadow(self, type)
+ VALUE self, type;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_viewport_set_shadow_type(GTK_VIEWPORT(widget),
+ (GtkShadowType)NUM2INT(type));
+
+ return self;
+}
+
+static VALUE
+button_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ Check_Type(label, T_STRING);
+ widget = gtk_button_new_with_label(RSTRING(label)->ptr);
+ }
+ else {
+ widget = gtk_button_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+button_pressed(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_pressed(GTK_BUTTON(widget));
+ return self;
+}
+
+static VALUE
+button_released(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_released(GTK_BUTTON(widget));
+ return self;
+}
+
+static VALUE
+button_clicked(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_clicked(GTK_BUTTON(widget));
+ return self;
+}
+
+static VALUE
+button_enter(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_enter(GTK_BUTTON(widget));
+ return self;
+}
+
+static VALUE
+button_leave(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_button_leave(GTK_BUTTON(widget));
+ return self;
+}
+
+static VALUE
+tbtn_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ Check_Type(label, T_STRING);
+ widget = gtk_toggle_button_new_with_label(RSTRING(label)->ptr);
+ }
+ else {
+ widget = gtk_toggle_button_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+tbtn_set_mode(self, mode)
+ VALUE self, mode;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(widget), NUM2INT(mode));
+ return self;
+}
+
+static VALUE
+tbtn_set_state(self, state)
+ VALUE self, state;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(widget), NUM2INT(state));
+ return self;
+}
+
+static VALUE
+tbtn_toggled(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(widget));
+ return self;
+}
+
+static VALUE
+cbtn_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE label;
+ GtkWidget *widget;
+
+ if (rb_scan_args(argc, argv, "01", &label) == 1) {
+ Check_Type(label, T_STRING);
+ widget = gtk_check_button_new_with_label(RSTRING(label)->ptr);
+ }
+ else {
+ widget = gtk_check_button_new();
+ }
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+rbtn_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+{
+ VALUE arg1, arg2;
+ GtkWidget *widget;
+ GSList *list = NULL;
+ char *label = NULL;
+
+ if (rb_scan_args(argc, argv, "02", &arg1, &arg2) == 1 &&
+ TYPE(arg1) == T_STRING) {
+ label = RSTRING(arg1)->ptr;
+ }
+ else {
+ if (!NIL_P(arg2)) {
+ Check_Type(arg2, T_STRING);
+ label = RSTRING(arg2)->ptr;
+ }
+ if (obj_is_kind_of(arg1, gRButton)) {
+ GtkWidget *b = get_widget(arg1);
+ list = GTK_RADIO_BUTTON(b)->group;
+ }
+ else {
+ list = ary2gslist(arg1);
+ }
+ }
+ if (label) {
+ widget = gtk_radio_button_new_with_label(list, label);
+ }
+ else {
+ widget = gtk_radio_button_new(list);
+ }
+ return make_widget(self, widget);
+}
+
+static VALUE
+rbtn_group(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return gslist2ary(gtk_radio_button_group(GTK_RADIO_BUTTON(widget)));
+}
+
+static void
+box_pack_start_or_end(argc, argv, self, start)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+ int start;
+{
+ VALUE arg0, arg1, arg2, arg3;
+ gint expand, fill, padding;
+ GtkWidget *widget, *child;
+
+ expand = fill = TRUE; padding = 0;
+ switch (rb_scan_args(argc, argv, "13", &arg0, &arg1, &arg2, &arg3)) {
+ case 4:
+ padding = NUM2INT(arg3);
+ case 3:
+ fill = RTEST(arg2);
+ case 2:
+ expand = RTEST(arg1);
+ default:
+ child = get_widget(arg0);
+ break;
+ }
+ widget = get_widget(self);
+
+ if (start)
+ gtk_box_pack_start(GTK_BOX(widget), child, expand, fill, padding);
+ else
+ gtk_box_pack_end(GTK_BOX(widget), child, expand, fill, padding);
+}
+
+static VALUE
+box_pack_start(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ box_pack_start_or_end(argc, argv, self, 1);
+ return self;
+}
+
+static VALUE
+box_pack_end(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ box_pack_start_or_end(argc, argv, self, 0);
+ return self;
+}
+
+static VALUE
+vbox_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE homogeneous, spacing;
+ GtkWidget *widget;
+
+ rb_scan_args(argc, argv, "02", &homogeneous, &spacing);
+ widget = gtk_vbox_new(RTEST(homogeneous), NUM2INT(spacing));
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+colorsel_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_color_selection_new());
+}
+
+static VALUE
+colorsel_set_update_policy(self, policy)
+ VALUE self, policy;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_color_selection_set_update_policy(GTK_COLOR_SELECTION(widget),
+ (GtkUpdateType)NUM2INT(policy));
+ return self;
+}
+
+static VALUE
+colorsel_set_opacity(self, opacity)
+ VALUE self, opacity;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_color_selection_set_opacity(GTK_COLOR_SELECTION(widget),
+ RTEST(opacity));
+ return self;
+}
+
+static VALUE
+colorsel_set_color(self, color)
+ VALUE self, color;
+{
+ GtkWidget *widget = get_widget(self);
+ double buf[3];
+
+ Check_Type(color, T_ARRAY);
+ if (RARRAY(color)->len < 3) {
+ ArgError("color array too small");
+ }
+ buf[0] = NUM2DBL(RARRAY(color)->ptr[0]);
+ buf[1] = NUM2DBL(RARRAY(color)->ptr[1]);
+ buf[2] = NUM2DBL(RARRAY(color)->ptr[2]);
+
+ gtk_color_selection_set_color(GTK_COLOR_SELECTION(widget), buf);
+ return self;
+}
+
+static VALUE
+colorsel_get_color(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ double buf[3];
+ VALUE ary;
+
+ gtk_color_selection_get_color(GTK_COLOR_SELECTION(widget), buf);
+ ary = ary_new2(3);
+ ary_push(ary, NUM2DBL(buf[0]));
+ ary_push(ary, NUM2DBL(buf[1]));
+ ary_push(ary, NUM2DBL(buf[2]));
+ return ary;
+}
+
+static VALUE
+cdialog_s_new(self, title)
+ VALUE self;
+{
+ char *t;
+
+ Check_Type(title, T_STRING);
+ t = RSTRING(title)->ptr;
+ return make_widget(self, gtk_color_selection_dialog_new(t));
+}
+
+static VALUE
+pixmap_s_new(self, val, mask)
+ VALUE self, val, mask;
+{
+ return make_widget(self, gtk_pixmap_new(get_gdkpixmap(val),
+ get_gdkpixmap(mask)));
+}
+
+static VALUE
+pixmap_set(self, val, mask)
+ VALUE self, val, mask;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_pixmap_set(GTK_PIXMAP(widget),
+ get_gdkpixmap(val), get_gdkpixmap(mask));
+ return self;
+}
+
+static VALUE
+pixmap_get(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ GdkPixmap *val;
+ GdkBitmap *mask;
+
+ gtk_pixmap_get(GTK_PIXMAP(widget), &val, &mask);
+
+ return assoc_new(make_gdkpixmap(self, val),
+ make_gdkpixmap(self, mask));
+}
+
+static VALUE
+darea_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_drawing_area_new());
+}
+
+static VALUE
+darea_size(self, w, h)
+ VALUE self, w, h;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_drawing_area_size(GTK_DRAWING_AREA(widget), NUM2INT(w), NUM2INT(h));
+ return self;
+}
+
+static VALUE
+entry_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_entry_new());
+}
+
+static VALUE
+entry_set_text(self, text)
+ VALUE self, text;
+{
+ GtkWidget *widget = get_widget(self);
+
+ Check_Type(text, T_STRING);
+ gtk_entry_set_text(GTK_ENTRY(widget), RSTRING(text)->ptr);
+
+ return self;
+}
+
+static VALUE
+eventbox_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_event_box_new());
+}
+
+static VALUE
+fixed_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_fixed_new());
+}
+
+static VALUE
+fixed_put(self, win, x, y)
+ VALUE self, win, x, y;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_fixed_put(GTK_FIXED(widget), get_widget(win), NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+fixed_move(self, win, x, y)
+ VALUE self, win, x, y;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_fixed_move(GTK_FIXED(widget), get_widget(win), NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+gamma_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_gamma_curve_new());
+}
+
+static VALUE
+gamma_gamma(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ return float_new(GTK_GAMMA_CURVE(widget)->gamma);
+}
+
+static VALUE
+hbbox_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_hbutton_box_new());
+}
+
+static VALUE
+hbbox_get_spacing_default(self)
+ VALUE self;
+{
+ int n = gtk_hbutton_box_get_spacing_default();
+
+ return INT2FIX(n);
+}
+
+static VALUE
+hbbox_get_layout_default(self)
+ VALUE self;
+{
+ int n = gtk_hbutton_box_get_layout_default();
+
+ return INT2FIX(n);
+}
+
+static VALUE
+hbbox_set_spacing_default(self, spacing)
+ VALUE self, spacing;
+{
+ gtk_hbutton_box_set_spacing_default(NUM2INT(spacing));
+ return Qnil;
+}
+
+static VALUE
+hbbox_set_layout_default(self, layout)
+ VALUE self, layout;
+{
+ gtk_hbutton_box_set_layout_default(NUM2INT(layout));
+ return Qnil;
+}
+
+static VALUE
+vbbox_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_vbutton_box_new());
+}
+
+static VALUE
+vbbox_get_spacing_default(self)
+ VALUE self;
+{
+ int n = gtk_vbutton_box_get_spacing_default();
+
+ return INT2FIX(n);
+}
+
+static VALUE
+vbbox_get_layout_default(self)
+ VALUE self;
+{
+ int n = gtk_vbutton_box_get_layout_default();
+
+ return INT2FIX(n);
+}
+
+static VALUE
+vbbox_set_spacing_default(self, spacing)
+ VALUE self, spacing;
+{
+ gtk_vbutton_box_set_spacing_default(NUM2INT(spacing));
+ return Qnil;
+}
+
+static VALUE
+vbbox_set_layout_default(self, layout)
+ VALUE self, layout;
+{
+ gtk_vbutton_box_set_layout_default(NUM2INT(layout));
+ return Qnil;
+}
+
+static VALUE
+hbox_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE homogeneous, spacing;
+ GtkWidget *widget;
+
+ rb_scan_args(argc, argv, "02", &homogeneous, &spacing);
+ widget = gtk_hbox_new(RTEST(homogeneous), NUM2INT(spacing));
+
+ return make_widget(self, widget);
+}
+
+static VALUE
+paned_add1(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_paned_add1(GTK_PANED(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+paned_add2(self, child)
+ VALUE self, child;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_paned_add2(GTK_PANED(widget), get_widget(child));
+ return self;
+}
+
+static VALUE
+paned_handle_size(self, size)
+ VALUE self, size;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_paned_handle_size(GTK_PANED(widget), NUM2INT(size));
+ return self;
+}
+
+static VALUE
+paned_gutter_size(self, size)
+ VALUE self, size;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_paned_gutter_size(GTK_PANED(widget), NUM2INT(size));
+ return self;
+}
+
+static VALUE
+hpaned_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_hpaned_new());
+}
+
+static VALUE
+vpaned_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_vpaned_new());
+}
+
+static VALUE
+ruler_set_metric(self, metric)
+ VALUE self, metric;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_ruler_set_metric(GTK_RULER(widget),
+ (GtkMetricType)NUM2INT(metric));
+
+ return self;
+}
+
+static VALUE
+ruler_set_range(self, lower, upper, position, max_size)
+ VALUE self, lower, upper, position, max_size;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_ruler_set_range(GTK_RULER(widget),
+ NUM2DBL(lower), NUM2DBL(upper),
+ NUM2DBL(position), NUM2DBL(max_size));
+
+ return self;
+}
+
+static VALUE
+ruler_draw_ticks(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_ruler_draw_ticks(GTK_RULER(widget));
+ return self;
+}
+
+static VALUE
+ruler_draw_pos(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_ruler_draw_pos(GTK_RULER(widget));
+ return self;
+}
+
+static VALUE
+hruler_s_new(self)
+{
+ return make_widget(self, gtk_hruler_new());
+}
+
+static VALUE
+vruler_s_new(self)
+{
+ return make_widget(self, gtk_vruler_new());
+}
+
+static VALUE
+range_get_adj(self)
+{
+ GtkWidget *widget = get_widget(self);
+ GtkAdjustment *adj = gtk_range_get_adjustment(GTK_RANGE(widget));
+
+ return make_gobject(gAdjustment, GTK_OBJECT(adj));
+}
+
+static VALUE
+range_set_update_policy(self, policy)
+ VALUE self, policy;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_set_update_policy(GTK_RANGE(widget),
+ (GtkUpdateType)NUM2INT(policy));
+ return self;
+}
+
+static VALUE
+range_set_adj(self, adj)
+ VALUE self, adj;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_set_adjustment(GTK_RANGE(widget),
+ (GtkAdjustment*)get_gobject(adj));
+
+ return self;
+}
+
+static VALUE
+range_draw_bg(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_draw_background(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_draw_trough(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_draw_trough(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_draw_slider(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_draw_slider(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_draw_step_forw(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_draw_step_forw(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_draw_step_back(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_draw_step_back(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_slider_update(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_slider_update(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_trough_click(self, x, y)
+ VALUE self, x, y;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_trough_click(GTK_RANGE(widget), NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+range_default_hslider_update(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_default_hslider_update(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_default_vslider_update(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_default_vslider_update(GTK_RANGE(widget));
+ return self;
+}
+
+static VALUE
+range_default_htrough_click(self, x, y)
+ VALUE self, x, y;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_default_htrough_click(GTK_RANGE(widget),
+ NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+range_default_vtrough_click(self, x, y)
+ VALUE self, x, y;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_default_vtrough_click(GTK_RANGE(widget),
+ NUM2INT(x), NUM2INT(y));
+ return self;
+}
+
+static VALUE
+range_default_hmotion(self, xdelta, ydelta)
+ VALUE self, xdelta, ydelta;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_default_hmotion(GTK_RANGE(widget),
+ NUM2INT(xdelta), NUM2INT(ydelta));
+ return self;
+}
+
+static VALUE
+range_default_vmotion(self, xdelta, ydelta)
+ VALUE self, xdelta, ydelta;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_default_vmotion(GTK_RANGE(widget),
+ NUM2INT(xdelta), NUM2INT(ydelta));
+ return self;
+}
+
+static VALUE
+range_calc_value(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_range_calc_value(GTK_RANGE(widget), NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+scale_set_digits(self, digits)
+ VALUE self, digits;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_scale_set_digits(GTK_SCALE(widget), NUM2INT(digits));
+ return self;
+}
+
+static VALUE
+scale_set_draw_value(self, draw_value)
+ VALUE self, draw_value;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_scale_set_draw_value(GTK_SCALE(widget), NUM2INT(draw_value));
+ return self;
+}
+
+static VALUE
+scale_set_value_pos(self, pos)
+ VALUE self, pos;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_scale_set_value_pos(GTK_SCALE(widget),
+ (GtkPositionType)NUM2INT(pos));
+ return self;
+}
+
+static VALUE
+scale_value_width(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+ int i = gtk_scale_value_width(GTK_SCALE(widget));
+
+ return INT2FIX(i);
+}
+
+static VALUE
+scale_draw_value(self)
+ VALUE self;
+{
+ GtkWidget *widget = get_widget(self);
+
+ gtk_scale_draw_value(GTK_SCALE(widget));
+ return self;
+}
+
+static VALUE
+hscale_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1;
+ GtkAdjustment *adj = NULL;
+
+ rb_scan_args(argc, argv, "01", &arg1);
+ if (!NIL_P(arg1)) adj = (GtkAdjustment*)get_gobject(arg1);
+
+ return make_widget(self, gtk_hscale_new(adj));
+}
+
+static VALUE
+vscale_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1;
+ GtkAdjustment *adj = NULL;
+
+ rb_scan_args(argc, argv, "01", &arg1);
+ if (!NIL_P(arg1)) adj = (GtkAdjustment*)get_gobject(arg1);
+
+ return make_widget(self, gtk_vscale_new(adj));
+}
+
+static VALUE
+hscrollbar_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1;
+ GtkAdjustment *adj = NULL;
+
+ rb_scan_args(argc, argv, "01", &arg1);
+ if (!NIL_P(arg1)) adj = (GtkAdjustment*)get_gobject(arg1);
+
+ return make_widget(self, gtk_hscrollbar_new(adj));
+}
+
+static VALUE
+vscrollbar_s_new(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE arg1;
+ GtkAdjustment *adj = NULL;
+
+ rb_scan_args(argc, argv, "01", &arg1);
+ if (!NIL_P(arg1)) adj = (GtkAdjustment*)get_gobject(arg1);
+
+ return make_widget(self, gtk_vscrollbar_new(adj));
+}
+
+static VALUE
+hsep_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_hseparator_new());
+}
+
+static VALUE
+vsep_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_vseparator_new());
+}
+
+static VALUE
+idiag_s_new(self)
+ VALUE self;
+{
+ return make_widget(self, gtk_input_dialog_new());
+}
+
+static VALUE
+gtk_m_main(self)
+ VALUE self;
+{
+ gtk_main();
+ return Qnil;
+}
+
+static gint
+idle()
+{
+ CHECK_INTS;
+ return TRUE;
+}
+
+static void
+exec_interval(proc)
+ VALUE proc;
+{
+ rb_funcall(proc, id_call, 0);
+}
+
+static VALUE
+timeout_add(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE interval, func;
+ int id;
+
+ rb_scan_args(argc, argv, "11", &interval, &func);
+ if (NIL_P(func)) {
+ func = f_lambda();
+ }
+ id = gtk_timeout_add_interp(NUM2INT(interval), exec_interval,
+ (gpointer)func, 0);
+ return INT2FIX(id);
+}
+
+static VALUE
+timeout_remove(self, id)
+ VALUE self, id;
+{
+ gtk_timeout_remove(NUM2INT(id));
+ return Qnil;
+}
+
+static VALUE
+idle_add(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE func;
+ int id;
+
+ rb_scan_args(argc, argv, "01", &func);
+ if (NIL_P(func)) {
+ func = f_lambda();
+ }
+ id = gtk_idle_add_interp(exec_interval, (gpointer)func, 0);
+ return INT2FIX(id);
+}
+
+static VALUE
+idle_remove(self, id)
+ VALUE self, id;
+{
+ gtk_idle_remove(NUM2INT(id));
+ return Qnil;
+}
+
+static VALUE warn_handler;
+static VALUE mesg_handler;
+static VALUE print_handler;
+
+static void
+gtkwarn(mesg)
+ char *mesg;
+{
+ rb_funcall(warn_handler, id_call, 1, str_new2(mesg));
+}
+
+static void
+gtkmesg(mesg)
+ char *mesg;
+{
+ rb_funcall(mesg_handler, id_call, 1, str_new2(mesg));
+}
+
+static void
+gtkprint(mesg)
+ char *mesg;
+{
+ rb_funcall(print_handler, id_call, 1, str_new2(mesg));
+}
+
+static VALUE
+set_warning_handler(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE handler;
+
+ rb_scan_args(argc, argv, "01", &handler);
+ if (NIL_P(handler)) {
+ handler = f_lambda();
+ }
+ g_set_warning_handler(gtkwarn);
+}
+
+static VALUE
+set_message_handler(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE handler;
+
+ rb_scan_args(argc, argv, "01", &handler);
+ if (NIL_P(handler)) {
+ handler = f_lambda();
+ }
+ g_set_message_handler(gtkmesg);
+}
+
+static VALUE
+set_print_handler(argc, argv, self)
+ int argc;
+ VALUE *argv;
+ VALUE self;
+{
+ VALUE handler;
+
+ rb_scan_args(argc, argv, "01", &handler);
+ if (NIL_P(handler)) {
+ handler = f_lambda();
+ }
+ g_set_print_handler(gtkprint);
+}
+
+static void
+gtkerr(mesg)
+ char *mesg;
+{
+ Fail("%s", mesg);
+}
+
+void
+Init_gtk()
+{
+ int argc, i;
+ char **argv;
+
+ gtk_object_list = ary_new();
+ rb_global_variable(&gtk_object_list);
+
+ mGtk = rb_define_module("Gtk");
+
+ gObject = rb_define_class_under(mGtk, "GtkObject", cObject);
+ gWidget = rb_define_class_under(mGtk, "Widget", gObject);
+ gContainer = rb_define_class_under(mGtk, "Container", gWidget);
+ gBin = rb_define_class_under(mGtk, "Bin", gContainer);
+ gAlignment = rb_define_class_under(mGtk, "Alignment", gBin);
+ gMisc = rb_define_class_under(mGtk, "Misc", gWidget);
+ gArrow = rb_define_class_under(mGtk, "Arrow", gMisc);
+ gFrame = rb_define_class_under(mGtk, "Frame", gBin);
+ gAspectFrame = rb_define_class_under(mGtk, "AspectFrame", gFrame);
+ gData = rb_define_class_under(mGtk, "Data", gObject);
+ gAdjustment = rb_define_class_under(mGtk, "Adjustment", gData);
+ gBox = rb_define_class_under(mGtk, "Box", gContainer);
+ gButton = rb_define_class_under(mGtk, "Button", gContainer);
+ gTButton = rb_define_class_under(mGtk, "ToggleButton", gButton);
+ gCButton = rb_define_class_under(mGtk, "CheckButton", gTButton);
+ gRButton = rb_define_class_under(mGtk, "RadioButton", gCButton);
+ gBBox = rb_define_class_under(mGtk, "ButtonBox", gBox);
+ gCList = rb_define_class_under(mGtk, "CList", gContainer);
+ gWindow = rb_define_class_under(mGtk, "Window", gBin);
+ gDialog = rb_define_class_under(mGtk, "Dialog", gWindow);
+ gFileSel = rb_define_class_under(mGtk, "FileSelection", gWindow);
+ gVBox = rb_define_class_under(mGtk, "VBox", gBox);
+ gColorSel = rb_define_class_under(mGtk, "ColorSelection", gVBox);
+ gColorSelDialog = rb_define_class_under(mGtk, "ColorSelectionDialog", gWindow);
+ gImage = rb_define_class_under(mGtk, "Image", gMisc);
+ gDrawArea = rb_define_class_under(mGtk, "DrawingArea", gWidget);
+ gEntry = rb_define_class_under(mGtk, "Entry", gWidget);
+ gEventBox = rb_define_class_under(mGtk, "EventBox", gBin);
+ gFixed = rb_define_class_under(mGtk, "Fixed", gContainer);
+ gGamma = rb_define_class_under(mGtk, "GammaCurve", gVBox);
+ gHBBox = rb_define_class_under(mGtk, "HButtonBox", gBBox);
+ gVBBox = rb_define_class_under(mGtk, "VButtonBox", gBBox);
+ gHBox = rb_define_class_under(mGtk, "HBox", gBox);
+ gPaned = rb_define_class_under(mGtk, "Paned", gContainer);
+ gHPaned = rb_define_class_under(mGtk, "HPaned", gPaned);
+ gVPaned = rb_define_class_under(mGtk, "VPaned", gPaned);
+ gRuler = rb_define_class_under(mGtk, "Ruler", gWidget);
+ gHRuler = rb_define_class_under(mGtk, "HRuler", gRuler);
+ gVRuler = rb_define_class_under(mGtk, "VRuler", gRuler);
+ gRange = rb_define_class_under(mGtk, "Range", gWidget);
+ gScale = rb_define_class_under(mGtk, "Scale", gRange);
+ gHScale = rb_define_class_under(mGtk, "HScale", gScale);
+ gVScale = rb_define_class_under(mGtk, "VScale", gScale);
+ gScrollbar = rb_define_class_under(mGtk, "Scrollbar", gRange);
+ gHScrollbar = rb_define_class_under(mGtk, "HScrollbar", gScrollbar);
+ gVScrollbar = rb_define_class_under(mGtk, "VScrollbar", gScrollbar);
+ gSeparator = rb_define_class_under(mGtk, "Separator", gWidget);
+ gHSeparator = rb_define_class_under(mGtk, "HSeparator", gSeparator);
+ gVSeparator = rb_define_class_under(mGtk, "VSeparator", gSeparator);
+ gInputDialog = rb_define_class_under(mGtk, "InputDialog", gDialog);
+ gLabel = rb_define_class_under(mGtk, "Label", gMisc);
+ gList = rb_define_class_under(mGtk, "List", gContainer);
+ gItem = rb_define_class_under(mGtk, "Item", gBin);
+ gListItem = rb_define_class_under(mGtk, "ListItem", gItem);
+ gMenuShell = rb_define_class_under(mGtk, "MenuShell", gContainer);
+ gMenu = rb_define_class_under(mGtk, "Menu", gMenuShell);
+ gMenuBar = rb_define_class_under(mGtk, "MenuBar", gMenuShell);
+ gMenuItem = rb_define_class_under(mGtk, "MenuItem", gItem);
+ gCMenuItem = rb_define_class_under(mGtk, "CheckMenuItem", gMenuItem);
+ gRMenuItem = rb_define_class_under(mGtk, "RadioMenuItem", gCMenuItem);
+ gNotebook = rb_define_class_under(mGtk, "Notebook", gContainer);
+ gOptionMenu = rb_define_class_under(mGtk, "OptionMenu", gButton);
+ gPixmap = rb_define_class_under(mGtk, "Pixmap", gMisc);
+ gPreview = rb_define_class_under(mGtk, "Preview", gWidget);
+ gProgressBar = rb_define_class_under(mGtk, "ProgressBar", gWidget);
+ gScrolledWin = rb_define_class_under(mGtk, "ScrolledWindow", gContainer);
+ gTable = rb_define_class_under(mGtk, "Table", gContainer);
+ gText = rb_define_class_under(mGtk, "Text", gWidget);
+ gToolbar = rb_define_class_under(mGtk, "Toolbar", gContainer);
+ gTooltips = rb_define_class_under(mGtk, "Tooltips", cObject);
+ gTree = rb_define_class_under(mGtk, "Tree", gContainer);
+ gTreeItem = rb_define_class_under(mGtk, "TreeItem", gItem);
+ gViewPort = rb_define_class_under(mGtk, "ViewPort", gBin);
+
+ gAcceleratorTable = rb_define_class_under(mGtk, "AcceleratorTable", cObject);
+ gStyle = rb_define_class_under(mGtk, "Style", cObject);
+ gPreviewInfo = rb_define_class_under(mGtk, "PreviewInfo", cObject);
+ gRequisiton = rb_define_class_under(mGtk, "Requisiton", cObject);
+ gAllocation = rb_define_class_under(mGtk, "Allocation", cObject);
+
+ mGdk = rb_define_module("Gdk");
+
+ gdkFont = rb_define_class_under(mGdk, "Font", cObject);
+ gdkColor = rb_define_class_under(mGdk, "Color", cObject);
+ gdkPixmap = rb_define_class_under(mGdk, "Pixmap", cObject);
+ gdkBitmap = rb_define_class_under(mGdk, "Bitmap", gdkPixmap);
+ gdkWindow = rb_define_class_under(mGdk, "Window", cObject);
+ gdkImage = rb_define_class_under(mGdk, "Image", cObject);
+ gdkVisual = rb_define_class_under(mGdk, "Visual", cObject);
+ gdkGC = rb_define_class_under(mGdk, "GC", cObject);
+ gdkGCValues = rb_define_class_under(mGdk, "GCValues", cObject);
+ gdkRectangle = rb_define_class_under(mGdk, "Rectangle", cObject);
+ gdkSegment = rb_define_class_under(mGdk, "Segment", cObject);
+ gdkWindowAttr = rb_define_class_under(mGdk, "WindowAttr", cObject);
+ gdkCursor = rb_define_class_under(mGdk, "Cursor", cObject);
+ gdkAtom = rb_define_class_under(mGdk, "Atom", cObject);
+ gdkColorContext = rb_define_class_under(mGdk, "ColotContext", cObject);
+ gdkEvent = rb_define_class_under(mGdk, "gdkEvent", cObject);
+
+ /* GtkObject */
+ rb_define_singleton_method(gObject, "new", gobj_s_new, -1);
+ rb_define_method(gObject, "set_flags", gobj_set_flags, 1);
+ rb_define_method(gObject, "unset_flags", gobj_unset_flags, 1);
+ rb_define_method(gObject, "destroy", gobj_destroy, 0);
+ rb_define_method(gObject, "signal_connect", gobj_sig_connect, -1);
+ rb_define_method(gObject, "signal_connect_after", gobj_sig_connect_after, -1);
+ rb_define_method(gObject, "singleton_method_added", gobj_smethod_added, 1);
+
+ /* Widget */
+ rb_define_method(gWidget, "destroy", widget_destroy, 0);
+ rb_define_method(gWidget, "show", widget_show, 0);
+ rb_define_method(gWidget, "show_all", widget_show_all, 0);
+ rb_define_method(gWidget, "hide", widget_hide, 0);
+ rb_define_method(gWidget, "hide_all", widget_hide_all, 0);
+ rb_define_method(gWidget, "map", widget_map, 0);
+ rb_define_method(gWidget, "unmap", widget_unmap, 0);
+ rb_define_method(gWidget, "realize", widget_realize, 0);
+ rb_define_method(gWidget, "unrealize", widget_unrealize, 0);
+ rb_define_method(gWidget, "queue_draw", widget_queue_draw, 0);
+ rb_define_method(gWidget, "queue_resize", widget_queue_resize, 0);
+ rb_define_method(gWidget, "draw", widget_draw, 1);
+ rb_define_method(gWidget, "draw_focus", widget_draw_focus, 0);
+ rb_define_method(gWidget, "draw_default", widget_draw_default, 0);
+ rb_define_method(gWidget, "draw_children", widget_draw_children, 0);
+ rb_define_method(gWidget, "size_request", widget_size_request, 1);
+ rb_define_method(gWidget, "size_alocate", widget_size_allocate, 1);
+ rb_define_method(gWidget, "install_accelerator", widget_inst_accel, 4);
+ rb_define_method(gWidget, "remove_accelerator", widget_rm_accel, 4);
+ rb_define_method(gWidget, "event", widget_event, 1);
+ rb_define_method(gWidget, "activate", widget_activate, 0);
+ rb_define_method(gWidget, "grab_focus", widget_grab_focus, 0);
+ rb_define_method(gWidget, "grab_default", widget_grab_default, 0);
+ rb_define_method(gWidget, "restore_state", widget_restore_state, 0);
+ rb_define_method(gWidget, "visible?", widget_visible, 0);
+ rb_define_method(gWidget, "reparent", widget_reparent, 1);
+ rb_define_method(gWidget, "popup", widget_popup, 2);
+ rb_define_method(gWidget, "intersect", widget_intersect, 2);
+ rb_define_method(gWidget, "basic", widget_basic, 0);
+ rb_define_method(gWidget, "get_name", widget_set_name, 0);
+ rb_define_method(gWidget, "set_name", widget_set_name, 1);
+ rb_define_method(gWidget, "set_parent", widget_set_parent, 1);
+ rb_define_method(gWidget, "set_sensitive", widget_set_sensitive, 1);
+ rb_define_method(gWidget, "set_usize", widget_set_usize, 2);
+ rb_define_method(gWidget, "set_uposition", widget_set_uposition, 2);
+ rb_define_method(gWidget, "set_style", widget_set_style, 1);
+ rb_define_method(gWidget, "set_events", widget_set_events, 1);
+ rb_define_method(gWidget, "set_extension_events", widget_set_eevents, 1);
+ rb_define_method(gWidget, "unparent", widget_unparent, 0);
+ rb_define_method(gWidget, "get_toplevel", widget_get_toplevel, 0);
+ rb_define_method(gWidget, "get_ancestor", widget_get_ancestor, 1);
+ rb_define_method(gWidget, "get_colormap", widget_get_colormap, 0);
+ rb_define_method(gWidget, "get_visual", widget_get_visual, 0);
+ rb_define_method(gWidget, "get_style", widget_get_style, 0);
+ rb_define_method(gWidget, "style", widget_get_style, 0);
+ rb_define_method(gWidget, "get_events", widget_get_events, 0);
+ rb_define_method(gWidget, "get_extension_events", widget_get_eevents, 0);
+ rb_define_method(gWidget, "get_pointer", widget_get_eevents, 0);
+ rb_define_method(gWidget, "ancestor?", widget_is_ancestor, 1);
+ rb_define_method(gWidget, "child?", widget_is_child, 1);
+ rb_define_method(gWidget, "window", widget_window, 0);
+
+ rb_define_singleton_method(gWidget, "push_colomap", widget_push_cmap, 1);
+ rb_define_singleton_method(gWidget, "push_visual", widget_push_visual, 1);
+ rb_define_singleton_method(gWidget, "push_style", widget_push_style, 1);
+ rb_define_singleton_method(gWidget, "pop_colomap", widget_pop_cmap, 0);
+ rb_define_singleton_method(gWidget, "pop_visual", widget_pop_visual, 0);
+ rb_define_singleton_method(gWidget, "pop_style", widget_pop_style, 0);
+
+ rb_define_singleton_method(gWidget, "set_default_colomap",
+ widget_set_default_cmap, 1);
+ rb_define_singleton_method(gWidget, "set_default_visual",
+ widget_set_default_visual, 1);
+ rb_define_singleton_method(gWidget, "set_default_style",
+ widget_set_default_style, 1);
+ rb_define_singleton_method(gWidget, "get_default_colomap",
+ widget_get_default_cmap, 0);
+ rb_define_singleton_method(gWidget, "get_default_visual",
+ widget_get_default_visual, 0);
+ rb_define_singleton_method(gWidget, "get_default_style",
+ widget_get_default_style, 0);
+ rb_define_singleton_method(gWidget, "set_default_colomap",
+ widget_set_default_cmap, 1);
+ rb_define_singleton_method(gWidget, "set_default_visual",
+ widget_set_default_visual, 1);
+ rb_define_singleton_method(gWidget, "set_default_style",
+ widget_set_default_style, 1);
+ rb_define_singleton_method(gWidget, "set_default_colomap",
+ widget_set_default_cmap, 1);
+ rb_define_singleton_method(gWidget, "set_default_visual",
+ widget_set_default_visual, 1);
+ rb_define_singleton_method(gWidget, "propagage_default_style",
+ widget_propagate_default_style, 0);
+
+ /* Container */
+ rb_define_method(gContainer, "border_width", cont_bwidth, 1);
+ rb_define_method(gContainer, "add", cont_add, 1);
+ rb_define_method(gContainer, "disable_resize", cont_disable_resize, 0);
+ rb_define_method(gContainer, "enable_resize", cont_enable_resize, 0);
+ rb_define_method(gContainer, "block_resize", cont_block_resize, 0);
+ rb_define_method(gContainer, "unblock_resize", cont_unblock_resize, 0);
+ rb_define_method(gContainer, "need_resize", cont_need_resize, 0);
+ rb_define_method(gContainer, "foreach", cont_foreach, -1);
+ rb_define_method(gContainer, "each", cont_each, 0);
+ rb_define_method(gContainer, "focus", cont_focus, 1);
+ rb_define_method(gContainer, "children", cont_children, 0);
+
+ /* Bin */
+ /* -- */
+
+ /* Alignment */
+ rb_define_singleton_method(gAlignment, "new", align_s_new, 4);
+ rb_define_method(gAlignment, "set", align_set, 4);
+
+ /* Misc */
+ rb_define_method(gMisc, "set_alignment", misc_set_align, 2);
+ rb_define_method(gMisc, "set_padding", misc_set_padding, 2);
+
+ /* Arrow */
+ rb_define_singleton_method(gArrow, "new", arrow_s_new, 2);
+ rb_define_method(gArrow, "set", arrow_s_new, 2);
+
+ /* Frame */
+ rb_define_singleton_method(gFrame, "new", frame_s_new, 1);
+ rb_define_method(gFrame, "set_label", frame_set_label, 1);
+ rb_define_method(gFrame, "set_label_align", frame_set_label_align, 2);
+ rb_define_method(gFrame, "set_shadow_type", frame_set_shadow_type, 1);
+
+ /* AspectFrame */
+ rb_define_singleton_method(gAspectFrame, "new", aframe_s_new, 5);
+ rb_define_method(gAspectFrame, "set", aframe_set, 4);
+
+ /* Data */
+ /* -- */
+
+ /* Adjustment */
+ rb_define_singleton_method(gAdjustment, "new", adj_s_new, 6);
+
+ /* Box */
+ rb_define_method(gBox, "pack_start", box_pack_start, -1);
+ rb_define_method(gBox, "pack_end", box_pack_end, -1);
+
+ /* Button */
+ rb_define_singleton_method(gButton, "new", button_s_new, -1);
+ rb_define_method(gButton, "pressed", button_pressed, 0);
+ rb_define_method(gButton, "released", button_released, 0);
+ rb_define_method(gButton, "clicked", button_clicked, 0);
+ rb_define_method(gButton, "enter", button_enter, 0);
+ rb_define_method(gButton, "leave", button_leave, 0);
+
+ /* ToggleButton */
+ rb_define_singleton_method(gTButton, "new", tbtn_s_new, -1);
+ rb_define_method(gTButton, "set_mode", tbtn_set_mode, 1);
+ rb_define_method(gTButton, "set_state", tbtn_set_state, 1);
+ rb_define_method(gTButton, "toggled", tbtn_toggled, 0);
+
+ /* CheckButton */
+ rb_define_singleton_method(gCButton, "new", cbtn_s_new, -1);
+
+ /* RadioButton */
+ rb_define_singleton_method(gCButton, "new", rbtn_s_new, -1);
+ rb_define_method(gCButton, "group", rbtn_group, 0);
+
+ /* ButtonBox */
+ rb_define_singleton_method(gBBox, "get_child_size_default",
+ bbox_get_child_size_default, 0);
+ rb_define_singleton_method(gBBox, "get_child_ipadding_default",
+ bbox_get_child_ipadding_default, 0);
+ rb_define_singleton_method(gBBox, "set_child_size_default",
+ bbox_set_child_size_default, 2);
+ rb_define_singleton_method(gBBox, "set_child_ipadding_default",
+ bbox_set_child_ipadding_default, 2);
+ rb_define_method(gBBox, "get_spacing", bbox_get_spacing, 0);
+ rb_define_method(gBBox, "get_layout", bbox_get_layout, 0);
+ rb_define_method(gBBox, "get_child_size", bbox_get_child_size, 0);
+ rb_define_method(gBBox, "get_child_ipadding", bbox_get_child_ipadding, 0);
+ rb_define_method(gBBox, "set_spacing", bbox_set_spacing, 1);
+ rb_define_method(gBBox, "set_layout", bbox_set_layout, 1);
+ rb_define_method(gBBox, "set_child_size", bbox_set_child_size, 2);
+ rb_define_method(gBBox, "set_child_ipadding", bbox_set_child_ipadding, 2);
+
+ /* CList */
+ rb_define_singleton_method(gCList, "new", clist_s_new, 1);
+ rb_define_method(gCList, "set_border", clist_set_border, 1);
+ rb_define_method(gCList, "set_selection_mode", clist_set_sel_mode, 1);
+ rb_define_method(gCList, "set_policy", clist_set_policy, 2);
+ rb_define_method(gCList, "freeze", clist_freeze, 0);
+ rb_define_method(gCList, "thaw", clist_thaw, 0);
+ rb_define_method(gCList, "set_column_title", clist_set_col_title, 2);
+ rb_define_method(gCList, "set_column_widget", clist_set_col_wigdet, 2);
+ rb_define_method(gCList, "set_column_justification", clist_set_col_just, 2);
+ rb_define_method(gCList, "set_column_width", clist_set_col_width, 2);
+ rb_define_method(gCList, "set_row_height", clist_set_row_height, 1);
+ rb_define_method(gCList, "moveto", clist_moveto, 4);
+ rb_define_method(gCList, "set_text", clist_set_text, 3);
+ rb_define_method(gCList, "set_pixmap", clist_set_text, 4);
+ rb_define_method(gCList, "set_pixtext", clist_set_pixtext, 6);
+ rb_define_method(gCList, "set_foreground", clist_set_foreground, 2);
+ rb_define_method(gCList, "set_background", clist_set_background, 2);
+ rb_define_method(gCList, "set_shift", clist_set_shift, 4);
+ rb_define_method(gCList, "append", clist_append, 1);
+ rb_define_method(gCList, "insert", clist_insert, 2);
+ rb_define_method(gCList, "remove", clist_remove, 1);
+ rb_define_method(gCList, "set_row_data", clist_set_row_data, 2);
+ rb_define_method(gCList, "get_row_data", clist_set_row_data, 1);
+ rb_define_method(gCList, "select_row", clist_select_row, 2);
+ rb_define_method(gCList, "unselect_row", clist_unselect_row, 2);
+ rb_define_method(gCList, "clear", clist_clear, 0);
+
+ /* Window */
+ rb_define_singleton_method(gWindow, "new", gwin_s_new, 1);
+ rb_define_method(gWindow, "set_title", gwin_set_title, 1);
+ rb_define_method(gWindow, "set_policy", gwin_set_policy, 3);
+ rb_define_method(gWindow, "set_wmclass", gwin_set_wmclass, 1);
+ rb_define_method(gWindow, "set_focus", gwin_set_focus, 1);
+ rb_define_method(gWindow, "set_default", gwin_set_focus, 1);
+ rb_define_method(gWindow, "add_accelerator_table", gwin_add_accel, 1);
+ rb_define_method(gWindow, "remove_accelerator_table", gwin_rm_accel, 1);
+ rb_define_method(gWindow, "position", gwin_position, 1);
+
+ /* Dialog */
+ rb_define_singleton_method(gDialog, "new", dialog_s_new, 0);
+
+ /* FileSelection */
+ rb_define_singleton_method(gFileSel, "new", fsel_s_new, 1);
+ rb_define_method(gFileSel, "set_filename", fsel_set_fname, 1);
+ rb_define_method(gFileSel, "get_filename", fsel_get_fname, 0);
+ rb_define_method(gFileSel, "ok_button", fsel_ok_button, 0);
+ rb_define_method(gFileSel, "cancel_button", fsel_cancel_button, 0);
+ rb_define_method(gFileSel, "help_button", fsel_help_button, 0);
+
+ /* VBox */
+ rb_define_singleton_method(gVBox, "new", vbox_s_new, -1);
+
+ /* ColorSelection */
+ rb_define_singleton_method(gColorSel, "new", colorsel_s_new, 0);
+ rb_define_method(gColorSel, "set_update_policy", colorsel_set_update_policy, 1);
+ rb_define_method(gColorSel, "set_opacity", colorsel_set_opacity, 1);
+ rb_define_method(gColorSel, "set_color", colorsel_set_color, 1);
+ rb_define_method(gColorSel, "get_color", colorsel_get_color, 0);
+
+ /* ColorSelectionDialog */
+ rb_define_singleton_method(gColorSelDialog, "new", cdialog_s_new, 1);
+
+ /* Image */
+ rb_define_singleton_method(gImage, "new", image_s_new, 2);
+ rb_define_method(gImage, "set", image_set, 2);
+ rb_define_method(gImage, "get", image_get, 0);
+
+ /* DrawingArea */
+ rb_define_singleton_method(gDrawArea, "new", darea_s_new, 0);
+ rb_define_method(gDrawArea, "size", darea_size, 2);
+
+ /* Entry */
+ rb_define_singleton_method(gEntry, "new", entry_s_new, 0);
+ rb_define_method(gEntry, "set_text", entry_set_text, 1);
+
+ /* EventBox */
+ rb_define_singleton_method(gEventBox, "new", eventbox_s_new, 0);
+
+ /* Fixed */
+ rb_define_singleton_method(gFixed, "new", fixed_s_new, 0);
+ rb_define_method(gFixed, "put", fixed_put, 3);
+ rb_define_method(gFixed, "move", fixed_move, 3);
+
+ /* GammaCurve */
+ rb_define_singleton_method(gGamma, "new", gamma_s_new, 0);
+ rb_define_method(gGamma, "gamma", gamma_gamma, 0);
+
+ /* HButtonBox */
+ rb_define_singleton_method(gHBBox, "new", hbbox_s_new, 0);
+ rb_define_singleton_method(gHBBox, "get_spacing_default",
+ hbbox_get_spacing_default, 0);
+ rb_define_singleton_method(gHBBox, "get_layout_default",
+ hbbox_get_spacing_default, 0);
+ rb_define_singleton_method(gHBBox, "set_spacing_default",
+ hbbox_set_spacing_default, 1);
+ rb_define_singleton_method(gHBBox, "set_layout_default",
+ hbbox_set_layout_default, 1);
+
+ /* VButtonBox */
+ rb_define_singleton_method(gVBBox, "new", vbbox_s_new, 0);
+ rb_define_singleton_method(gVBBox, "get_spacing_default",
+ vbbox_get_spacing_default, 0);
+ rb_define_singleton_method(gVBBox, "get_layout_default",
+ vbbox_get_spacing_default, 0);
+ rb_define_singleton_method(gVBBox, "set_spacing_default",
+ vbbox_set_spacing_default, 1);
+ rb_define_singleton_method(gVBBox, "set_layout_default",
+ vbbox_set_layout_default, 1);
+
+ /* HBox */
+ rb_define_singleton_method(gHBox, "new", hbox_s_new, -1);
+
+ /* Paned */
+ rb_define_method(gPaned, "add1", paned_add1, 1);
+ rb_define_method(gPaned, "add2", paned_add1, 1);
+ rb_define_method(gPaned, "handle_size", paned_handle_size, 1);
+ rb_define_method(gPaned, "gutter_size", paned_gutter_size, 1);
+
+ /* HPaned */
+ rb_define_singleton_method(gHPaned, "new", hpaned_s_new, 0);
+
+ /* VPaned */
+ rb_define_singleton_method(gVPaned, "new", vpaned_s_new, 0);
+
+ /* Ruler */
+ rb_define_method(gRuler, "set_metric", ruler_set_metric, 1);
+ rb_define_method(gRuler, "set_range", ruler_set_range, 4);
+ rb_define_method(gRuler, "draw_ticks", ruler_draw_ticks, 0);
+ rb_define_method(gRuler, "draw_pos", ruler_draw_pos, 0);
+
+ /* HRuler */
+ rb_define_singleton_method(gHRuler, "new", hruler_s_new, 0);
+
+ /* VRuler */
+ rb_define_singleton_method(gVRuler, "new", vruler_s_new, 0);
+
+ /* Range */
+ rb_define_method(gRange, "get_adjustment", range_get_adj, 0);
+ rb_define_method(gRange, "set_update_policy", range_set_update_policy, 1);
+ rb_define_method(gRange, "set_adjustment", range_set_adj, 1);
+ rb_define_method(gRange, "draw_background", range_draw_bg, 0);
+ rb_define_method(gRange, "draw_trough", range_draw_trough, 0);
+ rb_define_method(gRange, "draw_slider", range_draw_slider, 0);
+ rb_define_method(gRange, "draw_step_forw", range_draw_step_forw, 0);
+ rb_define_method(gRange, "draw_step_back", range_draw_step_back, 0);
+ rb_define_method(gRange, "slider_update", range_slider_update, 0);
+ rb_define_method(gRange, "trough_click", range_trough_click, 2);
+ rb_define_method(gRange, "draw_background", range_draw_bg, 2);
+ rb_define_method(gRange, "default_hslider_update", range_default_hslider_update, 0);
+ rb_define_method(gRange, "default_vslider_update", range_default_vslider_update, 0);
+ rb_define_method(gRange, "default_htrough_click", range_default_htrough_click, 2);
+ rb_define_method(gRange, "default_vtrough_click", range_default_vtrough_click, 2);
+ rb_define_method(gRange, "default_hmotion", range_default_hmotion, 2);
+ rb_define_method(gRange, "default_vmotion", range_default_vmotion, 2);
+ rb_define_method(gRange, "calc_value", range_calc_value, 1);
+
+ /* Scale */
+ rb_define_method(gScale, "set_digits", scale_set_digits, 1);
+ rb_define_method(gScale, "set_draw_value", scale_set_draw_value, 1);
+ rb_define_method(gScale, "set_value_pos", scale_set_value_pos, 1);
+ rb_define_method(gScale, "value_width", scale_value_width, 0);
+ rb_define_method(gScale, "draw_value", scale_draw_value, 0);
+
+ /* HScale */
+ rb_define_singleton_method(gHScale, "new", hscale_s_new, -1);
+
+ /* VScale */
+ rb_define_singleton_method(gVScale, "new", vscale_s_new, -1);
+
+ /* Scrollbar */
+ /* -- */
+
+ /* HScrollbar */
+ rb_define_singleton_method(gHScrollbar, "new", hscrollbar_s_new, -1);
+
+ /* VScrollbar */
+ rb_define_singleton_method(gVScrollbar, "new", vscrollbar_s_new, -1);
+
+ /* Separator */
+ /* -- */
+
+ /* HSeparator */
+ rb_define_singleton_method(gHSeparator, "new", hsep_s_new, 0);
+
+ /* VSeparator */
+ rb_define_singleton_method(gVSeparator, "new", vsep_s_new, 0);
+
+ /* InputDialog */
+ rb_define_singleton_method(gInputDialog, "new", idiag_s_new, 0);
+
+ /* Label */
+ rb_define_singleton_method(gLabel, "new", label_s_new, 1);
+
+ /* List */
+ rb_define_singleton_method(gList, "new", list_s_new, 0);
+ rb_define_method(gList, "set_selection_mode", list_set_sel_mode, 1);
+ rb_define_method(gList, "selection_mode", list_sel_mode, 1);
+ rb_define_method(gList, "selection", list_selection, 0);
+ rb_define_method(gList, "insert_items", list_insert_items, 2);
+ rb_define_method(gList, "append_items", list_append_items, 1);
+ rb_define_method(gList, "prepend_items", list_prepend_items, 1);
+ rb_define_method(gList, "remove_items", list_remove_items, 1);
+ rb_define_method(gList, "clear_items", list_clear_items, 2);
+ rb_define_method(gList, "select_item", list_select_item, 1);
+ rb_define_method(gList, "unselect_item", list_unselect_item, 1);
+ rb_define_method(gList, "select_child", list_select_child, 1);
+ rb_define_method(gList, "unselect_child", list_unselect_child, 1);
+ rb_define_method(gList, "child_position", list_child_position, 1);
+
+ /* Item */
+ rb_define_method(gItem, "select", item_select, 0);
+ rb_define_method(gItem, "deselect", item_deselect, 0);
+ rb_define_method(gItem, "toggle", item_toggle, 0);
+
+ /* ListItem */
+ rb_define_singleton_method(gListItem, "new", litem_s_new, -1);
+
+ /* MenuShell */
+ rb_define_method(gMenuShell, "append", mshell_append, 1);
+ rb_define_method(gMenuShell, "prepend", mshell_prepend, 1);
+ rb_define_method(gMenuShell, "insert", mshell_insert, 2);
+ rb_define_method(gMenuShell, "deactivate", mshell_deactivate, 0);
+
+ /* Menu */
+ rb_define_singleton_method(gMenu, "new", menu_s_new, 0);
+ rb_define_method(gMenu, "append", menu_append, 1);
+ rb_define_method(gMenu, "prepend", menu_prepend, 1);
+ rb_define_method(gMenu, "insert", menu_insert, 2);
+ rb_define_method(gMenu, "popup", menu_popup, 6);
+ rb_define_method(gMenu, "popdown", menu_popup, 0);
+ rb_define_method(gMenu, "get_active", menu_get_active, 0);
+ rb_define_method(gMenu, "set_active", menu_set_active, 1);
+ rb_define_method(gMenu, "set_accelerator_table", menu_set_acceltbl, 1);
+
+ /* MenuBar */
+ rb_define_singleton_method(gMenuBar, "new", mbar_s_new, 0);
+ rb_define_method(gMenuBar, "append", mbar_append, 1);
+ rb_define_method(gMenuBar, "prepend", mbar_prepend, 1);
+ rb_define_method(gMenuBar, "insert", mbar_insert, 2);
+
+ /* MenuItem */
+ rb_define_singleton_method(gMenuItem, "new", mitem_s_new, -1);
+ rb_define_method(gMenuItem, "set_submenu", mitem_set_submenu, 1);
+ rb_define_method(gMenuItem, "set_placement", mitem_set_placement, 1);
+ rb_define_method(gMenuItem, "accelerator_size", mitem_accelerator_size, 0);
+ rb_define_method(gMenuItem, "accelerator_text", mitem_accelerator_text, 0);
+ rb_define_method(gMenuItem, "configure", mitem_configure, 2);
+ rb_define_method(gMenuItem, "select", mitem_select, 0);
+ rb_define_method(gMenuItem, "deselect", mitem_deselect, 0);
+ rb_define_method(gMenuItem, "activate", mitem_activate, 0);
+ rb_define_method(gMenuItem, "right_justify", mitem_right_justify, 0);
+
+ /* CheckMenuItem */
+ rb_define_singleton_method(gCMenuItem, "new", cmitem_s_new, -1);
+ rb_define_method(gCMenuItem, "set_state", cmitem_set_state, 1);
+ rb_define_method(gCMenuItem, "set_show_toggle", cmitem_set_show_toggle, 1);
+ rb_define_method(gCMenuItem, "toggled", cmitem_toggled, 0);
+
+ /* RadioMenuItem */
+ rb_define_singleton_method(gRMenuItem, "new", rmitem_s_new, -1);
+ rb_define_method(gRMenuItem, "group", rmitem_group, 0);
+
+ /* NoteBook */
+ rb_define_singleton_method(gNotebook, "new", note_s_new, 0);
+ rb_define_method(gNotebook, "append_page", note_append_page, 2);
+ rb_define_method(gNotebook, "prepend_page", note_prepend_page, 2);
+ rb_define_method(gNotebook, "insert_page", note_insert_page, 3);
+ rb_define_method(gNotebook, "remove_page", note_remove_page, 1);
+ rb_define_method(gNotebook, "set_page", note_set_page, 1);
+ rb_define_method(gNotebook, "cur_page", note_cur_page, 0);
+ rb_define_method(gNotebook, "page", note_cur_page, 0);
+ rb_define_method(gNotebook, "next_page", note_next_page, 0);
+ rb_define_method(gNotebook, "prev_page", note_prev_page, 0);
+ rb_define_method(gNotebook, "set_tab_pos", note_set_tab_pos, 1);
+ rb_define_method(gNotebook, "tab_pos", note_tab_pos, 0);
+ rb_define_method(gNotebook, "set_show_tabs", note_set_show_tabs, 1);
+ rb_define_method(gNotebook, "show_tabs", note_show_tabs, 0);
+ rb_define_method(gNotebook, "set_show_border", note_set_show_border, 1);
+ rb_define_method(gNotebook, "show_border", note_show_border, 0);
+
+ /* OptionMenu */
+ rb_define_singleton_method(gOptionMenu, "new", omenu_s_new, 0);
+ rb_define_method(gOptionMenu, "get_menu", omenu_get_menu, 0);
+ rb_define_method(gOptionMenu, "set_menu", omenu_set_menu, 1);
+ rb_define_method(gOptionMenu, "remove_menu", omenu_set_menu, 0);
+ rb_define_method(gOptionMenu, "set_history", omenu_set_history, 1);
+
+ /* Pixmap */
+ rb_define_singleton_method(gPixmap, "new", pixmap_s_new, 2);
+ rb_define_method(gPixmap, "set", pixmap_set, 2);
+ rb_define_method(gPixmap, "get", pixmap_get, 0);
+
+ /* Preview */
+ rb_define_singleton_method(gPreview, "new", preview_s_new, 1);
+ rb_define_method(gPreview, "size", preview_size, 2);
+ rb_define_method(gPreview, "put", preview_size, 8);
+ rb_define_method(gPreview, "put_row", preview_size, 5);
+ rb_define_method(gPreview, "draw_row", preview_size, 4);
+ rb_define_method(gPreview, "set_expand", preview_set_expand, 1);
+ rb_define_singleton_method(gPreview, "set_gamma", preview_set_gamma, 1);
+ rb_define_singleton_method(gPreview, "set_color_cube",
+ preview_set_color_cube, 4);
+ rb_define_singleton_method(gPreview, "set_install_cmap",
+ preview_set_install_cmap, 1);
+ rb_define_singleton_method(gPreview, "set_reserved",
+ preview_set_reserved, 1);
+ rb_define_singleton_method(gPreview, "get_visual", preview_get_visual, 0);
+ rb_define_singleton_method(gPreview, "get_cmap", preview_get_cmap, 0);
+ rb_define_singleton_method(gPreview, "get_info", preview_get_info, 0);
+
+ /* ProgressBar */
+ rb_define_singleton_method(gProgressBar, "new", pbar_s_new, 0);
+ rb_define_method(gProgressBar, "update", pbar_update, 1);
+
+ /* ScrolledWindow */
+ rb_define_singleton_method(gScrolledWin, "new", scwin_s_new, -1);
+ rb_define_method(gScrolledWin, "set_policy", scwin_set_policy, 2);
+
+ /* Table */
+ rb_define_singleton_method(gTable, "new", tbl_s_new, -1);
+ rb_define_method(gTable, "attach", tbl_attach, -1);
+ rb_define_method(gTable, "set_row_spacing", tbl_set_row_spacing, 2);
+ rb_define_method(gTable, "set_col_spacing", tbl_set_col_spacing, 2);
+ rb_define_method(gTable, "set_row_spacings", tbl_set_row_spacings, 1);
+ rb_define_method(gTable, "set_col_spacings", tbl_set_col_spacings, 1);
+
+ /* Text */
+ rb_define_singleton_method(gText, "new", txt_s_new, -1);
+ rb_define_method(gText, "set_editable", txt_set_editable, 1);
+ rb_define_method(gText, "set_adjustment", txt_set_adjustment, 2);
+ rb_define_method(gText, "set_point", txt_set_point, 1);
+ rb_define_method(gText, "get_point", txt_get_point, 0);
+ rb_define_method(gText, "get_length", txt_get_length, 0);
+ rb_define_method(gText, "freeze", txt_freeze, 0);
+ rb_define_method(gText, "thaw", txt_thaw, 0);
+ rb_define_method(gText, "insert", txt_insert, 4);
+ rb_define_method(gText, "backward_delete", txt_backward_delete, 1);
+ rb_define_method(gText, "forward_delete", txt_forward_delete, 1);
+
+ /* Toolbar */
+ rb_define_singleton_method(gToolbar, "new", tbar_s_new, -1);
+ rb_define_method(gToolbar, "append_item", tbar_append_item, 4);
+ rb_define_method(gToolbar, "prepend_item", tbar_prepend_item, 4);
+ rb_define_method(gToolbar, "insert_item", tbar_append_item, 5);
+ rb_define_method(gToolbar, "append_space", tbar_append_space, 0);
+ rb_define_method(gToolbar, "prepend_space", tbar_prepend_space, 0);
+ rb_define_method(gToolbar, "insert_space", tbar_append_space, 1);
+ rb_define_method(gToolbar, "set_orientation", tbar_set_orientation, 1);
+ rb_define_method(gToolbar, "set_style", tbar_set_style, 1);
+ rb_define_method(gToolbar, "set_space_size", tbar_set_space_size, 1);
+ rb_define_method(gToolbar, "set_tooltips", tbar_set_tooltips, 1);
+
+ /* Tooltips */
+ rb_define_singleton_method(gTooltips, "new", ttips_s_new, 0);
+ rb_define_method(gTooltips, "set_tips", ttips_set_tips, 2);
+ rb_define_method(gTooltips, "set_delay", ttips_set_delay, 1);
+ rb_define_method(gTooltips, "enable", ttips_enable, 0);
+ rb_define_method(gTooltips, "disable", ttips_disable, 0);
+
+ /* Tree */
+ rb_define_singleton_method(gTree, "new", tree_s_new, 0);
+ rb_define_method(gTree, "append", tree_append, 1);
+ rb_define_method(gTree, "prepend", tree_prepend, 1);
+ rb_define_method(gTree, "insert", tree_insert, 2);
+
+ /* TreeItem */
+ rb_define_singleton_method(gTreeItem, "new", titem_s_new, -1);
+ rb_define_method(gTreeItem, "set_subtree", titem_set_subtree, 1);
+ rb_define_method(gTreeItem, "select", titem_select, 0);
+ rb_define_method(gTreeItem, "deselect", titem_deselect, 0);
+ rb_define_method(gTreeItem, "expand", titem_expand, 0);
+ rb_define_method(gTreeItem, "collapse", titem_collapse, 0);
+
+ /* ViewPort */
+ rb_define_singleton_method(gViewPort, "new", vport_s_new, -1);
+ rb_define_method(gViewPort, "get_hadjustment", vport_get_hadj, 0);
+ rb_define_method(gViewPort, "get_vadjustment", vport_get_vadj, 0);
+ rb_define_method(gViewPort, "set_hadjustment", vport_set_hadj, 1);
+ rb_define_method(gViewPort, "set_vadjustment", vport_set_vadj, 1);
+ rb_define_method(gViewPort, "set_shadow_type", vport_set_shadow, 1);
+
+ /* AcceleratorTable */
+ /* Style */
+
+ /* Gtk module */
+ rb_define_module_function(mGtk, "main", gtk_m_main, 0);
+ rb_define_module_function(mGtk, "timeout_add", timeout_add, -1);
+ rb_define_module_function(mGtk, "timeout_remove", timeout_remove, 1);
+ rb_define_module_function(mGtk, "idle_add", idle_add, -1);
+ rb_define_module_function(mGtk, "idle_remove", idle_remove, 1);
+
+ rb_define_module_function(mGtk, "set_warning_handler",
+ set_warning_handler, -1);
+ rb_define_module_function(mGtk, "set_message_handler",
+ set_message_handler, -1);
+ rb_define_module_function(mGtk, "set_print_handler",
+ set_print_handler, -1);
+
+ /* Gdk module */
+ /* GdkFont */
+ rb_define_method(gdkFont, "==", gdkfnt_equal, 1);
+
+ /* GdkBitmap */
+ rb_define_singleton_method(gdkBitmap, "new", gdkbmap_s_new, 3);
+ rb_define_singleton_method(gdkBitmap, "create_from_data",
+ gdkbmap_create_from_data, 4);
+
+ /* GdkPixmap */
+ rb_define_singleton_method(gdkPixmap, "new", gdkpmap_s_new, 4);
+ rb_define_singleton_method(gdkPixmap, "create_from_xpm",
+ gdkpmap_create_from_xpm, 3);
+ rb_define_singleton_method(gdkPixmap, "create_from_xpm_d",
+ gdkpmap_create_from_xpm, 3);
+
+ /* GdkWindow */
+
+ /* GdkImage */
+
+ rb_define_const(mGtk, "VISIBLE", INT2FIX(GTK_VISIBLE));
+ rb_define_const(mGtk, "MAPPED", INT2FIX(GTK_MAPPED));
+ rb_define_const(mGtk, "UNMAPPED", INT2FIX(GTK_UNMAPPED));
+ rb_define_const(mGtk, "REALIZED", INT2FIX(GTK_REALIZED));
+ rb_define_const(mGtk, "SENSITIVE", INT2FIX(GTK_SENSITIVE));
+ rb_define_const(mGtk, "PARENT_SENSITIVE", INT2FIX(GTK_PARENT_SENSITIVE));
+ rb_define_const(mGtk, "NO_WINDOW", INT2FIX(GTK_NO_WINDOW));
+ rb_define_const(mGtk, "HAS_FOCUS", INT2FIX(GTK_HAS_FOCUS));
+ rb_define_const(mGtk, "CAN_FOCUS", INT2FIX(GTK_CAN_FOCUS));
+ rb_define_const(mGtk, "HAS_DEFAULT", INT2FIX(GTK_HAS_DEFAULT));
+ rb_define_const(mGtk, "CAN_DEFAULT", INT2FIX(GTK_CAN_DEFAULT));
+ rb_define_const(mGtk, "PROPAGATE_STATE", INT2FIX(GTK_PROPAGATE_STATE));
+ rb_define_const(mGtk, "ANCHORED", INT2FIX(GTK_ANCHORED));
+ rb_define_const(mGtk, "BASIC", INT2FIX(GTK_BASIC));
+ rb_define_const(mGtk, "USER_STYLE", INT2FIX(GTK_USER_STYLE));
+ rb_define_const(mGtk, "GRAB_ALL", INT2FIX(GTK_GRAB_ALL));
+ rb_define_const(mGtk, "REDRAW_PENDING", INT2FIX(GTK_REDRAW_PENDING));
+ rb_define_const(mGtk, "RESIZE_PENDING", INT2FIX(GTK_RESIZE_PENDING));
+ rb_define_const(mGtk, "RESIZE_NEEDED", INT2FIX(GTK_RESIZE_NEEDED));
+ rb_define_const(mGtk, "HAS_SHAPE_MASK", INT2FIX(GTK_HAS_SHAPE_MASK));
+
+ /* GtkWindowType */
+ rb_define_const(mGtk, "WINDOW_TOPLEVEL", INT2FIX(GTK_WINDOW_TOPLEVEL));
+ rb_define_const(mGtk, "WINDOW_DIALOG", INT2FIX(GTK_WINDOW_DIALOG));
+ rb_define_const(mGtk, "WIN_POS_NONE", INT2FIX(GTK_WIN_POS_NONE));
+ rb_define_const(mGtk, "WIN_POS_CENTER", INT2FIX(GTK_WIN_POS_CENTER));
+ rb_define_const(mGtk, "WIN_POS_MOUSE", INT2FIX(GTK_WIN_POS_MOUSE));
+
+ /* GtkDirectionType */
+ rb_define_const(mGtk, "DIR_TAB_FORWARD", INT2FIX(GTK_DIR_TAB_FORWARD));
+ rb_define_const(mGtk, "DIR_TAB_BACKWARD", INT2FIX(GTK_DIR_TAB_BACKWARD));
+ rb_define_const(mGtk, "DIR_UP", INT2FIX(GTK_DIR_UP));
+ rb_define_const(mGtk, "DIR_DOWN", INT2FIX(GTK_DIR_DOWN));
+ rb_define_const(mGtk, "DIR_LEFT", INT2FIX(GTK_DIR_LEFT));
+ rb_define_const(mGtk, "DIR_RIGHT", INT2FIX(GTK_DIR_RIGHT));
+
+ /* GtkPolicyType */
+ rb_define_const(mGtk, "POLICY_ALWAYS", INT2FIX(GTK_POLICY_ALWAYS));
+ rb_define_const(mGtk, "POLICY_AUTOMATIC", INT2FIX(GTK_POLICY_AUTOMATIC));
+
+ /* GtkSelectionMode */
+ rb_define_const(mGtk, "SELECTION_SINGLE", INT2FIX(GTK_SELECTION_SINGLE));
+ rb_define_const(mGtk, "SELECTION_BROWSE", INT2FIX(GTK_SELECTION_BROWSE));
+ rb_define_const(mGtk, "SELECTION_MULTIPLE", INT2FIX(GTK_SELECTION_MULTIPLE));
+ rb_define_const(mGtk, "SELECTION_EXTENDED", INT2FIX(GTK_SELECTION_EXTENDED));
+ /* GtkPositionType */
+ rb_define_const(mGtk, "POS_LEFT", INT2FIX(GTK_POS_LEFT));
+ rb_define_const(mGtk, "POS_RIGHT", INT2FIX(GTK_POS_RIGHT));
+ rb_define_const(mGtk, "POS_TOP", INT2FIX(GTK_POS_TOP));
+ rb_define_const(mGtk, "POS_BOTTOM", INT2FIX(GTK_POS_BOTTOM));
+
+ /* GtkShadowType */
+ rb_define_const(mGtk, "SHADOW_NONE", INT2FIX(GTK_SHADOW_NONE));
+ rb_define_const(mGtk, "SHADOW_IN", INT2FIX(GTK_SHADOW_IN));
+ rb_define_const(mGtk, "SHADOW_OUT", INT2FIX(GTK_SHADOW_OUT));
+ rb_define_const(mGtk, "SHADOW_ETCHED_IN", INT2FIX(GTK_SHADOW_ETCHED_IN));
+ rb_define_const(mGtk, "SHADOW_ETCHED_OUT", INT2FIX(GTK_SHADOW_ETCHED_OUT));
+ /* GtkStateType */
+ rb_define_const(mGtk, "STATE_NORMAL", INT2FIX(GTK_STATE_NORMAL));
+ rb_define_const(mGtk, "STATE_ACTIVE", INT2FIX(GTK_STATE_ACTIVE));
+ rb_define_const(mGtk, "STATE_PRELIGHT", INT2FIX(GTK_STATE_PRELIGHT));
+ rb_define_const(mGtk, "STATE_SELECTED", INT2FIX(GTK_STATE_SELECTED));
+ rb_define_const(mGtk, "STATE_INSENSITIVE", INT2FIX(GTK_STATE_INSENSITIVE));
+ /* GtkAttachOptions */
+ rb_define_const(mGtk, "EXPAND", INT2FIX(GTK_EXPAND));
+ rb_define_const(mGtk, "SHRINK", INT2FIX(GTK_SHRINK));
+ rb_define_const(mGtk, "FILL", INT2FIX(GTK_FILL));
+ /* GtkSubmenuDirection */
+ rb_define_const(mGtk, "DIRECTION_LEFT", INT2FIX(GTK_DIRECTION_LEFT));
+ rb_define_const(mGtk, "DIRECTION_RIGHT", INT2FIX(GTK_DIRECTION_RIGHT));
+ /* GtkSubmenuPlacement */
+ rb_define_const(mGtk, "TOP_BOTTOM", INT2FIX(GTK_TOP_BOTTOM));
+ rb_define_const(mGtk, "LEFT_RIGHT", INT2FIX(GTK_LEFT_RIGHT));
+ /* GtkMetricType */
+ rb_define_const(mGtk, "PIXELS", INT2FIX(GTK_PIXELS));
+ rb_define_const(mGtk, "INCHES", INT2FIX(GTK_INCHES));
+ rb_define_const(mGtk, "CENTIMETERS", INT2FIX(GTK_CENTIMETERS));
+
+ /* GtkArrowType */
+ rb_define_const(mGtk, "ARROW_UP", INT2FIX(GTK_ARROW_UP));
+ rb_define_const(mGtk, "ARROW_DOWN", INT2FIX(GTK_ARROW_DOWN));
+ rb_define_const(mGtk, "ARROW_LEFT", INT2FIX(GTK_ARROW_LEFT));
+ rb_define_const(mGtk, "ARROW_RIGHT", INT2FIX(GTK_ARROW_RIGHT));
+
+ /* GtkPreviewType */
+ rb_define_const(mGtk, "PREVIEW_COLOR", INT2FIX(GTK_PREVIEW_COLOR));
+ rb_define_const(mGtk, "PREVIEW_GRAYSCALE", INT2FIX(GTK_PREVIEW_GRAYSCALE));
+
+ rb_define_const(mGtk, "BUTTONBOX_DEFAULT", INT2FIX(GTK_BUTTONBOX_DEFAULT));
+ rb_define_const(mGtk, "BUTTONBOX_SPREAD", INT2FIX(GTK_BUTTONBOX_SPREAD));
+ rb_define_const(mGtk, "BUTTONBOX_EDGE", INT2FIX(GTK_BUTTONBOX_EDGE));
+ rb_define_const(mGtk, "BUTTONBOX_START", INT2FIX(GTK_BUTTONBOX_START));
+ rb_define_const(mGtk, "BUTTONBOX_END", INT2FIX(GTK_BUTTONBOX_END));
+
+ /* GtkToolbarStyle */
+ rb_define_const(mGtk, "TOOLBAR_ICONS", INT2FIX(GTK_TOOLBAR_ICONS));
+ rb_define_const(mGtk, "TOOLBAR_TEXT", INT2FIX(GTK_TOOLBAR_TEXT));
+ rb_define_const(mGtk, "TOOLBAR_BOTH", INT2FIX(GTK_TOOLBAR_BOTH));
+
+ /* GtkOrientation */
+ rb_define_const(mGtk, "ORIENTATION_HORIZONTAL", INT2FIX(GTK_ORIENTATION_HORIZONTAL));
+ rb_define_const(mGtk, "ORIENTATION_VERTICAL", INT2FIX(GTK_ORIENTATION_VERTICAL));
+
+ /* GdkExtensionMode */
+ rb_define_const(mGdk, "EXTENSION_EVENTS_NONE", INT2FIX(GDK_EXTENSION_EVENTS_NONE));
+ rb_define_const(mGdk, "EXTENSION_EVENTS_ALL", INT2FIX(GDK_EXTENSION_EVENTS_ALL));
+ rb_define_const(mGdk, "EXTENSION_EVENTS_CURSOR", INT2FIX(GDK_EXTENSION_EVENTS_CURSOR));
+
+ argc = RARRAY(rb_argv)->len;
+ argv = ALLOCA_N(char*,argc+1);
+ argv[0] = RSTRING(rb_argv0)->ptr;
+ for (i=0;i<argc;i++) {
+ if (TYPE(RARRAY(rb_argv)->ptr[i]) == T_STRING) {
+ argv[i+1] = RSTRING(RARRAY(rb_argv)->ptr[i])->ptr;
+ }
+ else {
+ argv[i+1] = "";
+ }
+ }
+ argc++;
+ {
+ /* Gdk modifies sighandlers, sigh */
+ RETSIGTYPE (*sigfunc[7])();
+
+ sigfunc[0] = signal(SIGHUP, SIG_IGN);
+ sigfunc[1] = signal(SIGINT, SIG_IGN);
+ sigfunc[2] = signal(SIGQUIT, SIG_IGN);
+ sigfunc[3] = signal(SIGBUS, SIG_IGN);
+ sigfunc[4] = signal(SIGSEGV, SIG_IGN);
+ sigfunc[5] = signal(SIGPIPE, SIG_IGN);
+ sigfunc[6] = signal(SIGTERM, SIG_IGN);
+
+ gdk_init(&argc, &argv);
+
+ signal(SIGHUP, sigfunc[0]);
+ signal(SIGINT, sigfunc[1]);
+ signal(SIGQUIT, sigfunc[2]);
+ signal(SIGBUS, sigfunc[3]);
+ signal(SIGSEGV, sigfunc[4]);
+ signal(SIGPIPE, sigfunc[5]);
+ signal(SIGTERM, sigfunc[6]);
+ }
+
+ for (i=1;i<argc;i++) {
+ RARRAY(rb_argv)->ptr[i] = str_taint(str_new2(argv[i]));
+ }
+ RARRAY(rb_argv)->len = argc-1;
+
+ id_gtkdata = rb_intern("gtkdata");
+ id_relatives = rb_intern("relatives");
+ id_call = rb_intern("call");
+ gtk_idle_add((GtkFunction)idle, 0);
+
+ g_set_error_handler(gtkerr);
+ g_set_warning_handler(gtkerr);
+ rb_global_variable(&warn_handler);
+ rb_global_variable(&mesg_handler);
+ rb_global_variable(&print_handler);
+}
diff --git a/ext/gtk/test.rb b/ext/gtk/test.rb
new file mode 100644
index 0000000..52ce5db
--- /dev/null
+++ b/ext/gtk/test.rb
@@ -0,0 +1,96 @@
+require 'gtk'
+
+def create_menu(depth)
+ return nil if depth < 1
+
+ menu = Gtk::Menu::new()
+ group = nil
+ submenu = nil
+
+ for i in 0..4
+ buf = sprintf("item %2d - %d", depth, i+1)
+# menuitem = Gtk::MenuItem::new(buf)
+ menuitem = Gtk::RadioMenuItem.new(group, buf)
+ group = menuitem.group
+ if depth % 2
+ menuitem.set_show_toggle TRUE
+ end
+ menu.append menuitem
+ menuitem.show
+ if depth > 0
+ unless submenu
+ submenu = create_menu(depth - 1)
+ end
+ menuitem.set_submenu submenu
+ end
+ end
+ return menu
+end
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.signal_connect("destroy") do
+ exit
+end
+window.signal_connect("delete_event") do
+ exit
+end
+window.set_title("menus")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add box1
+box1.show
+
+menubar = Gtk::MenuBar::new()
+box1.pack_start menubar, FALSE, TRUE, 0
+menubar.show
+
+menu = create_menu(2)
+menuitem = Gtk::MenuItem::new("test\nline2")
+menuitem.set_submenu menu
+menubar.append menuitem
+menuitem.show
+
+menuitem = Gtk::MenuItem::new("foo")
+menuitem.set_submenu menu
+menubar.append menuitem
+menuitem.show
+
+menuitem = Gtk::MenuItem::new("bar")
+menuitem.set_submenu menu
+menubar.append menuitem
+menuitem.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width 10
+box1.pack_start box2, TRUE, TRUE, 0
+box2.show
+
+optionmenu = Gtk::OptionMenu::new()
+optionmenu.set_menu create_menu(1)
+optionmenu.set_history 4
+box2.pack_start optionmenu, TRUE, TRUE, 0
+optionmenu.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::HBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+button = Gtk::Button::new("close")
+button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.set_flags(Gtk::CAN_DEFAULT);
+button.grab_default
+button.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test.xpm b/ext/gtk/test.xpm
new file mode 100644
index 0000000..9b0d2ef
--- /dev/null
+++ b/ext/gtk/test.xpm
@@ -0,0 +1,92 @@
+/* XPM */
+static char *openfile[] = {
+/* width height num_colors chars_per_pixel */
+" 20 19 66 2",
+/* colors */
+".. c None",
+".# c #000000",
+".a c #dfdfdf",
+".b c #7f7f7f",
+".c c #006f6f",
+".d c #00efef",
+".e c #009f9f",
+".f c #004040",
+".g c #00bfbf",
+".h c #ff0000",
+".i c #ffffff",
+".j c #7f0000",
+".k c #007070",
+".l c #00ffff",
+".m c #00a0a0",
+".n c #004f4f",
+".o c #00cfcf",
+".p c #8f8f8f",
+".q c #6f6f6f",
+".r c #a0a0a0",
+".s c #7f7f00",
+".t c #007f7f",
+".u c #5f5f5f",
+".v c #707070",
+".w c #00f0f0",
+".x c #009090",
+".y c #ffff00",
+".z c #0000ff",
+".A c #00afaf",
+".B c #00d0d0",
+".C c #00dfdf",
+".D c #005f5f",
+".E c #00b0b0",
+".F c #001010",
+".G c #00c0c0",
+".H c #000f0f",
+".I c #00007f",
+".J c #005050",
+".K c #002f2f",
+".L c #dfcfcf",
+".M c #dfd0d0",
+".N c #006060",
+".O c #00e0e0",
+".P c #00ff00",
+".Q c #002020",
+".R c #dfc0c0",
+".S c #008080",
+".T c #001f1f",
+".U c #003f3f",
+".V c #007f00",
+".W c #00000f",
+".X c #000010",
+".Y c #00001f",
+".Z c #000020",
+".0 c #00002f",
+".1 c #000030",
+".2 c #00003f",
+".3 c #000040",
+".4 c #00004f",
+".5 c #000050",
+".6 c #00005f",
+".7 c #000060",
+".8 c #00006f",
+".9 c #000070",
+"#. c #7f7f80",
+"## c #9f9f9f",
+/* pixels */
+"........................................",
+"........................................",
+"........................................",
+".......................#.#.#............",
+".....................#.......#...#......",
+"...............................#.#......",
+".......#.#.#.................#.#.#......",
+".....#.y.i.y.#.#.#.#.#.#.#..............",
+".....#.i.y.i.y.i.y.i.y.i.#..............",
+".....#.y.i.y.i.y.i.y.i.y.#..............",
+".....#.i.y.i.y.#.#.#.#.#.#.#.#.#.#.#....",
+".....#.y.i.y.#.s.s.s.s.s.s.s.s.s.#......",
+".....#.i.y.#.s.s.s.s.s.s.s.s.s.#........",
+".....#.y.#.s.s.s.s.s.s.s.s.s.#..........",
+".....#.#.s.s.s.s.s.s.s.s.s.#............",
+".....#.#.#.#.#.#.#.#.#.#.#..............",
+"........................................",
+"........................................",
+"........................................"
+};
diff --git a/ext/gtk/test0.rb b/ext/gtk/test0.rb
new file mode 100644
index 0000000..4ff802d
--- /dev/null
+++ b/ext/gtk/test0.rb
@@ -0,0 +1,13 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.border_width(10)
+button = Gtk::Button::new("Hello World")
+button.signal_connect("clicked") do
+ print "hello world\n"
+ exit
+end
+window.add(button)
+button.show
+window.show
+Gtk::main()
diff --git a/ext/gtk/test1.rb b/ext/gtk/test1.rb
new file mode 100644
index 0000000..7d24199
--- /dev/null
+++ b/ext/gtk/test1.rb
@@ -0,0 +1,41 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("entry")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, TRUE, TRUE, 0)
+box2.show
+
+entry = Gtk::Entry::new()
+entry.set_text("hello world")
+box2.pack_start(entry, TRUE, TRUE, 0)
+entry.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+button = Gtk::Button::new("close")
+button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.set_flags(Gtk::CAN_DEFAULT);
+button.grab_default
+button.show
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test2.rb b/ext/gtk/test2.rb
new file mode 100644
index 0000000..170de96
--- /dev/null
+++ b/ext/gtk/test2.rb
@@ -0,0 +1,89 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("list")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, TRUE, TRUE, 0)
+box2.show
+
+scrolled_win = Gtk::ScrolledWindow::new()
+scrolled_win.set_policy(Gtk::POLICY_AUTOMATIC,Gtk::POLICY_AUTOMATIC)
+box2.pack_start(scrolled_win, TRUE, TRUE, 0)
+scrolled_win.show
+
+list = Gtk::List::new()
+list.set_selection_mode(Gtk::SELECTION_MULTIPLE)
+list.set_selection_mode(Gtk::SELECTION_BROWSE)
+scrolled_win.add(list)
+list.show
+
+for i in [
+ "hello",
+ "world",
+ "blah",
+ "foo",
+ "bar",
+ "argh",
+ "spencer",
+ "is a",
+ "wussy",
+ "programmer",
+ ]
+ list_item = Gtk::ListItem::new(i)
+ list.add(list_item)
+ list_item.show
+end
+
+button = Gtk::Button::new("add")
+button.set_flags(Gtk::CAN_FOCUS);
+i = 1
+button.signal_connect("clicked") do
+ list_item = Gtk::ListItem::new(format("added item %d", i))
+ list.add(list_item)
+ list_item.show
+ i += 1
+end
+box2.pack_start(button, FALSE, TRUE, 0)
+button.show
+
+button = Gtk::Button::new("remove")
+button.set_flags(Gtk::CAN_FOCUS);
+button.signal_connect("clicked") do
+ tmp_list = list.selection
+ list.remove_items(tmp_list)
+ for i in tmp_list
+ i.destroy
+ end
+end
+box2.pack_start(button, FALSE, TRUE, 0)
+button.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+button = Gtk::Button::new("close")
+button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.set_flags(Gtk::CAN_DEFAULT);
+button.grab_default
+button.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test3.rb b/ext/gtk/test3.rb
new file mode 100644
index 0000000..d73f72f
--- /dev/null
+++ b/ext/gtk/test3.rb
@@ -0,0 +1,16 @@
+require 'gtk'
+
+window = Gtk::FileSelection::new("file selection dialog")
+window.position(Gtk::WIN_POS_MOUSE)
+window.border_width(0)
+
+window.ok_button.signal_connect("clicked") do
+ print window.get_filename, "\n"
+end
+window.cancel_button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test4.rb b/ext/gtk/test4.rb
new file mode 100644
index 0000000..da0000c
--- /dev/null
+++ b/ext/gtk/test4.rb
@@ -0,0 +1,77 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("notebook")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, TRUE, TRUE, 0)
+box2.show
+
+notebook = Gtk::Notebook::new()
+notebook.set_tab_pos(Gtk::POS_TOP)
+box2.pack_start(notebook, TRUE, TRUE, 0)
+notebook.show
+
+for i in 1..5
+ frame = Gtk::Frame::new(format("Page %d", i))
+ frame.border_width(10)
+ frame.set_usize(200, 150)
+ frame.show
+
+ label = Gtk::Label::new(format("Box %d", i))
+ frame.add label
+ label.show
+
+ label = Gtk::Label::new(format("Tab %d", i))
+ notebook.append_page frame, label
+end
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::HBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+button = Gtk::Button::new("close")
+button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.set_flags(Gtk::CAN_DEFAULT);
+button.grab_default
+button.show
+
+button = Gtk::Button::new("next")
+button.signal_connect("clicked") do
+ notebook.next_page
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::Button::new("prev")
+button.signal_connect("clicked") do
+ notebook.prev_page
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::Button::new("rotate")
+button.signal_connect("clicked") do
+ notebook.set_tab_pos((notebook.tab_pos+1)%4)
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test5.rb b/ext/gtk/test5.rb
new file mode 100644
index 0000000..7142320
--- /dev/null
+++ b/ext/gtk/test5.rb
@@ -0,0 +1,63 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("buttons")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+table = Gtk::Table::new(3, 3, FALSE)
+table.set_row_spacings(5)
+table.set_col_spacings(5)
+table.border_width(10)
+box1.pack_start(table, TRUE, TRUE, 0)
+table.show
+
+button = []
+0.upto(8) do |i|
+ button.push Gtk::Button::new("button"+(i+1))
+end
+0.upto(8) do |i|
+ button[i].signal_connect("clicked") do |w|
+ if button[i+1].visible?
+ button[i+1].hide
+ else
+ button[i+1].show
+ end
+ end
+ button[i].show
+end
+table.attach(button[0], 0, 1, 0, 1, nil, nil, 0, 0)
+table.attach(button[1], 1, 2, 1, 2, nil, nil, 0, 0)
+table.attach(button[2], 2, 3, 2, 3, nil, nil, 0, 0)
+table.attach(button[3], 0, 1, 2, 3, nil, nil, 0, 0)
+table.attach(button[4], 2, 3, 0, 1, nil, nil, 0, 0)
+table.attach(button[5], 1, 2, 2, 3, nil, nil, 0, 0)
+table.attach(button[6], 1, 2, 0, 1, nil, nil, 0, 0)
+table.attach(button[7], 2, 3, 1, 2, nil, nil, 0, 0)
+table.attach(button[8], 0, 1, 1, 2, nil, nil, 0, 0)
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+close = Gtk::Button::new("close")
+close.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(close, TRUE, TRUE, 0)
+close.set_flags(Gtk::CAN_DEFAULT);
+close.grab_default
+close.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test6.rb b/ext/gtk/test6.rb
new file mode 100644
index 0000000..a589530
--- /dev/null
+++ b/ext/gtk/test6.rb
@@ -0,0 +1,49 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("toggle buttons")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, TRUE, TRUE, 0)
+box2.show
+
+button = Gtk::ToggleButton::new("button1")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::ToggleButton::new("button2")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::ToggleButton::new("button3")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+close = Gtk::Button::new("close")
+close.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(close, TRUE, TRUE, 0)
+close.set_flags(Gtk::CAN_DEFAULT);
+close.grab_default
+close.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test7.rb b/ext/gtk/test7.rb
new file mode 100644
index 0000000..4d78648
--- /dev/null
+++ b/ext/gtk/test7.rb
@@ -0,0 +1,49 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("check buttons")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, TRUE, TRUE, 0)
+box2.show
+
+button = Gtk::CheckButton::new("button1")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::CheckButton::new("button2")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::CheckButton::new("button3")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+close = Gtk::Button::new("close")
+close.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(close, TRUE, TRUE, 0)
+close.set_flags(Gtk::CAN_DEFAULT);
+close.grab_default
+close.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test8.rb b/ext/gtk/test8.rb
new file mode 100644
index 0000000..4ac4b0b
--- /dev/null
+++ b/ext/gtk/test8.rb
@@ -0,0 +1,49 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("radio buttons")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add(box1)
+box1.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width 10
+box1.pack_start(box2, TRUE, TRUE, 0)
+box2.show
+
+button = Gtk::RadioButton::new("button1")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::RadioButton::new(button, "button2")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+button = Gtk::RadioButton::new(button, "button3")
+box2.pack_start(button, TRUE, TRUE, 0)
+button.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::VBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+close = Gtk::Button::new("close")
+close.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(close, TRUE, TRUE, 0)
+close.set_flags(Gtk::CAN_DEFAULT);
+close.grab_default
+close.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/test9.rb b/ext/gtk/test9.rb
new file mode 100644
index 0000000..7bb3bf3
--- /dev/null
+++ b/ext/gtk/test9.rb
@@ -0,0 +1,98 @@
+require 'gtk'
+
+def create_bbox_window(horizontal, title, pos, spacing, cw, ch, layout)
+ window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+ window.set_title(title)
+ window.signal_connect("destroy") do
+ window.destroy
+ end
+ window.signal_connect("delete_event") do
+ window.hide
+ window.destroy
+ end
+ if horizontal
+ window.set_usize(550, 60)
+ window.set_uposition(150, pos)
+ else
+ window.set_usize(150, 400)
+ window.set_uposition(pos, 200)
+ end
+ box1 = Gtk::VBox::new(FALSE, 0)
+ window.add box1
+ box1.show
+ if horizontal
+ bbox = Gtk::HButtonBox::new()
+ else
+ bbox = Gtk::VButtonBox::new()
+ end
+ bbox.set_layout layout
+ bbox.set_spacing spacing
+ bbox.set_child_size cw, ch
+ bbox.show
+ box1.border_width 25
+ box1.pack_start(bbox, TRUE, TRUE, 0)
+ button = Gtk::Button::new("OK")
+ bbox.add button
+ button.signal_connect("clicked") do
+ window.hide
+ window.destroy
+ end
+ button.show
+
+ button = Gtk::Button::new("Cancel")
+ bbox.add button
+ button.signal_connect("clicked") do
+ window.hide
+ window.destroy
+ end
+ button.show
+
+ button = Gtk::Button::new("Help")
+ bbox.add button
+ button.show
+
+ window.show
+end
+
+def test_hbbox
+ create_bbox_window(TRUE, "Spread", 50, 40, 85, 25, Gtk::BUTTONBOX_SPREAD);
+ create_bbox_window(TRUE, "Edge", 250, 40, 85, 28, Gtk::BUTTONBOX_EDGE);
+ create_bbox_window(TRUE, "Start", 450, 40, 85, 25, Gtk::BUTTONBOX_START);
+ create_bbox_window(TRUE, "End", 650, 15, 30, 25, Gtk::BUTTONBOX_END);
+end
+
+def test_vbbox
+ create_bbox_window(FALSE, "Spread", 50, 40, 85, 25, Gtk::BUTTONBOX_SPREAD);
+ create_bbox_window(FALSE, "Edge", 250, 40, 85, 28, Gtk::BUTTONBOX_EDGE);
+ create_bbox_window(FALSE, "Start", 450, 40, 85, 25, Gtk::BUTTONBOX_START);
+ create_bbox_window(FALSE, "End", 650, 15, 30, 25, Gtk::BUTTONBOX_END);
+end
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.signal_connect("delete_event") do
+ window.destroy
+ exit
+end
+window.set_title("button box")
+window.border_width(20)
+
+bbox = Gtk::HButtonBox::new()
+window.add(bbox)
+bbox.show
+
+button = Gtk::Button::new("Horizontal")
+def button.clicked(*args)
+ test_hbbox
+end
+bbox.add button
+button.show
+
+button = Gtk::Button::new("Vertical")
+def button.clicked(*args)
+ test_vbbox
+end
+bbox.add button
+button.show
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/testa.rb b/ext/gtk/testa.rb
new file mode 100644
index 0000000..00a6603
--- /dev/null
+++ b/ext/gtk/testa.rb
@@ -0,0 +1,78 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.set_title("toolbar test")
+window.set_policy(TRUE, TRUE, TRUE)
+window.signal_connect("destroy") do
+ exit
+end
+window.signal_connect("delete_event") do
+ exit
+end
+window.border_width(0)
+window.realize
+
+toolbar = Gtk::Toolbar::new(Gtk::ORIENTATION_HORIZONTAL, Gtk::TOOLBAR_BOTH)
+toolbar.append_item "Horizontal", "Horizontal toolbar layout",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil,
+ #window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_orientation Gtk::ORIENTATION_HORIZONTAL
+end
+toolbar.append_item "Vertival", "Vertical toolbar layout",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil, #window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_orientation Gtk::ORIENTATION_VERTICAL
+end
+toolbar.append_space
+toolbar.append_item "Icons", "Only show toolbar icons",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil, #window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_style Gtk::TOOLBAR_ICONS
+end
+toolbar.append_item "Text", "Only show toolbar text",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil,#window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_style Gtk::TOOLBAR_TEXT
+end
+toolbar.append_item "Both", "Show toolbar icons and text",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil, #window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_style Gtk::TOOLBAR_BOTH
+end
+toolbar.append_space
+toolbar.append_item "Small", "User small spaces",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil,#window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_space_size 5
+end
+toolbar.append_item "Big", "User big spaces",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil,#window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_space_size 10
+end
+toolbar.append_space
+toolbar.append_item "Enable", "Enable tooltips",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil,#window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_tooltips TRUE
+end
+toolbar.append_item "Disable", "Disable tooltips",
+ Gtk::Pixmap::new(*Gdk::Pixmap::create_from_xpm(window.window,
+ nil,#window.style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")), nil do
+ toolbar.set_tooltips FALSE
+end
+window.add toolbar
+toolbar.show
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/testb.rb b/ext/gtk/testb.rb
new file mode 100644
index 0000000..4e707bc
--- /dev/null
+++ b/ext/gtk/testb.rb
@@ -0,0 +1,78 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.signal_connect("destroy") do
+ exit
+end
+window.signal_connect("delete_event") do
+ exit
+end
+window.set_title("buttons")
+window.border_width(0)
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add box1
+box1.show
+
+box2 = Gtk::HBox::new(FALSE, 5)
+box2.border_width 10
+box1.pack_start box2, TRUE, TRUE, 0
+box2.show
+
+label = Gtk::Label::new("Hello World")
+frame = Gtk::Frame::new("Frame 1")
+box2.pack_start frame, TRUE, TRUE, 0
+frame.show
+
+box3 = Gtk::VBox::new(FALSE, 5)
+box3.border_width 5
+frame.add box3
+box3.show
+
+button = Gtk::Button::new("switch")
+button.signal_connect("clicked") do
+ label.reparent box3
+end
+box3.pack_start button, FALSE, TRUE, 0
+button.show
+box3.pack_start label, FALSE, TRUE, 0
+label.show
+
+frame = Gtk::Frame::new("Frame 2")
+box2.pack_start frame, TRUE, TRUE, 0
+frame.show
+
+box4 = Gtk::VBox::new(FALSE, 5)
+box4.border_width 5
+frame.add box4
+box4.show
+
+button = Gtk::Button::new("switch")
+button.signal_connect("clicked") do
+ label.reparent box4
+end
+box4.pack_start button, FALSE, TRUE, 0
+button.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::HBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+button = Gtk::Button::new("close")
+button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.set_flags(Gtk::CAN_DEFAULT);
+button.grab_default
+button.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/gtk/testc.rb b/ext/gtk/testc.rb
new file mode 100644
index 0000000..98c6466
--- /dev/null
+++ b/ext/gtk/testc.rb
@@ -0,0 +1,64 @@
+require 'gtk'
+
+window = Gtk::Window::new(Gtk::WINDOW_TOPLEVEL)
+window.signal_connect("destroy") do
+ exit
+end
+window.signal_connect("delete_event") do
+ exit
+end
+window.set_title("pixmap")
+window.border_width(0)
+window.realize
+
+box1 = Gtk::VBox::new(FALSE, 0)
+window.add box1
+box1.show
+
+box2 = Gtk::HBox::new(FALSE, 10)
+box2.border_width 10
+box1.pack_start box2, TRUE, TRUE, 0
+box2.show
+
+button = Gtk::Button::new()
+box2.pack_start button, FALSE, FALSE, 0
+button.show
+
+style = button.style
+pixmap, mask = Gdk::Pixmap::create_from_xpm(window.window,
+ nil,
+ #style.bg[Gtk::STATE_NORMAL],
+ "test.xpm")
+pixmapwid = Gtk::Pixmap::new(pixmap, mask)
+label = Gtk::Label::new("Pixmap\ntest")
+box3 = Gtk::HBox::new(FALSE, 0)
+box3.border_width 2
+box3.add pixmapwid
+box3.add label
+button.add box3
+pixmapwid.show
+label.show
+box3.show
+
+separator = Gtk::HSeparator::new()
+box1.pack_start(separator, FALSE, TRUE, 0)
+separator.show
+
+box2 = Gtk::HBox::new(FALSE, 10)
+box2.border_width(10)
+box1.pack_start(box2, FALSE, TRUE, 0)
+box2.show
+
+button = Gtk::Button::new("close")
+button.signal_connect("clicked") do
+ window.destroy
+ exit
+end
+box2.pack_start(button, TRUE, TRUE, 0)
+button.set_flags(Gtk::CAN_DEFAULT);
+button.grab_default
+button.show
+
+window.show
+
+Gtk::main()
diff --git a/ext/tcltklib/MANIFEST b/ext/tcltklib/MANIFEST
new file mode 100644
index 0000000..b5e8827
--- /dev/null
+++ b/ext/tcltklib/MANIFEST
@@ -0,0 +1,15 @@
+MANIFEST
+README.euc
+MANUAL.euc
+tcltklib.c
+depend
+extconf.rb
+lib/tcltk.rb
+demo/lines1.rb
+demo/lines0.tcl
+demo/lines2.rb
+sample/sample1.rb
+sample/sample2.rb
+sample/maru.gif
+sample/batsu.gif
+sample/sample0.rb
diff --git a/ext/tcltklib/MANUAL.euc b/ext/tcltklib/MANUAL.euc
new file mode 100644
index 0000000..789e85a
--- /dev/null
+++ b/ext/tcltklib/MANUAL.euc
@@ -0,0 +1,124 @@
+(tof)
+ MANUAL.euc
+ Sep. 19, 1997 Y. Shigehiro
+
+以下, 「tcl/tk」という表記は, tclsh や wish を実現している, 一般でいう
+ところの tcl/tk を指します. 「tcltk ライブラリ」, 「tcltklib ライブラ
+リ」という表記は, 本パッケージに含まれる ruby 用のライブラリを指します.
+
+<< tcltk ライブラリ >>
+
+tcl/tk の C ライブラリを利用するための高(中?)水準インターフェースを提
+供します.
+
+このライブラリは ruby から tcl/tk ライブラリを利用するためのもので, 内
+部で tcltklib ライブラリを利用しています.
+
+[説明]
+
+tcl/tk インタプリタでは, ウィジェットに何か指示を送るには, ウィジェッ
+ト名に続いてパラメータを書きます. したがって, ウィジェットがオブジェク
+トであり, それに対してメソッドを送っている, とみなすことができます. さ
+て, tcl/tk インタプリタでは, 組み込みコマンドも, 前述のウィジェットと
+同じような書式の命令で実行されます. すなわち, コマンドもオブジェクトで
+あると考えることができます.
+
+このような考えに基づき, tcltk ライブラリでは, tcl/tk のコマンドやウィ
+ジェットに対応するオブジェクトを生成します. オブジェクトに対するメソッ
+ド呼び出しは, e() メソッドにより実行されます. 例えば, tcl/tk の info
+コマンドに対応する ruby のオブジェクトが info という名前であるとすると,
+tcl/tk の
+ info commands
+という命令は tcltk ライブラリでは
+ info.e("commands")
+と記述されます. また, 「.」というウィジェット (wish 実行時に自動的に生
+成されるルートウィジェット) に対応する ruby のオブジェクトが root とい
+う名前であるとすると,
+ . configure -height 300 -width 300
+という tcl/tk の命令は
+ root.e("configure -height 300 -width 300")
+と記述されます. このような記述は, 見ためには美しくありませんが, そして,
+スクリプトを読む人には見づらいかも知れませんが, 実際にスクリプトを書い
+てみると予想外に手軽です.
+
+[使用法]
+
+1. ライブラリを読み込む.
+ require "tcltk"
+
+2. tcl/tk インタプリタを生成する.
+ ip = TclTkInterpreter.new()
+
+3. tcl/tk のコマンドに対応するオブジェクトを変数に代入しておく.
+ # コマンドに対応するオブジェクトが入った Hash を取り出す.
+ c = ip.commands()
+ # 使いたいコマンドに対応するオブジェクトを個別の変数に代入する.
+ bind, button, info, wm = c.indexes("bind", "button", "info", "wm")
+
+4. 必要な処理を行う.
+ 詳しくは, サンプルを参照のこと.
+
+5. 準備ができたら, イベントループに入る.
+ TclTk.mainloop()
+
+(( 以下, モジュール, クラス等の説明を書く予定.))
+
+
+
+<< tcltklib ライブラリ >>
+
+tcl/tk の C ライブラリを利用するための低水準インターフェースを提供しま
+す.
+
+コンパイル/実行には, tcl/tk の C ライブラリが必要です.
+
+[説明]
+
+このライブラリを用いると, ruby から tcl/tk の C ライブラリを利用できま
+す. 具体的には, ruby インタプリタから tcl/tk インタプリタを呼び出すこ
+とができます. さらに, その(ruby インタプリタから呼び出した) tcl/tk イ
+ンタプリタから, 逆に ruby インタプリタを呼び出すこともできます.
+
+[使用法]
+
+require "tcltklib" すると, 以下のモジュール, クラスが利用可能です.
+
+モジュール TclTkLib
+ tcl/tk ライブラリを呼び出すメソッドを集めたモジュールです. ただし,
+ tcl/tk インタプリタ関係のメソッドはクラス TclTkIp にあります.
+
+ モジュールメソッド mainloop()
+ Tk_MainLoop を実行します. 全ての tk のウインドウが無くなると終了
+ します(例えば, tcl/tk で書くところの "destroy ." をした場合等).
+ 引数: 無し
+ 戻り値: nil
+
+クラス TclTkIp
+ インスタンスが tcl/tk のインタプリタに対応します. tcl/tk のライブ
+ ラリの仕様通り, インスタンスを複数個生成しても正しく動作します(そ
+ んなことをする必要はあまり無いはずですが). インタプリタは wish の
+ tcl/tk コマンドを実行できます. さらに, 以下のコマンドを実行できま
+ す.
+ コマンド ruby
+ 引数を ruby で実行します(ruby_eval_string を実行します). 引数
+ は 1 つでなければなりません. 戻り値は ruby の実行結果です.
+ ruby の実行結果は nil か String でなければなりません.
+
+ クラスメソッド new()
+ TclTkIp クラスのインスタンスを生成します
+ 引数: 無し
+ 戻り値 (TclTkIp): 生成されたインスタンス
+
+ メソッド _eval(script)
+ インタプリタで script を評価します(Tcl_Eval を実行します). 前述
+ のように, ruby コマンドにより script 内から ruby スクリプトを実
+ 行できます.
+ 引数: script (String) - インタプリタで評価するスクリプト文字列
+ 戻り値 (String): 評価結果 ((Tcl_Interp *)->result)
+
+ メソッド _return_value()
+ 直前の Tcl_Eval の戻り値を返します. 0(TCL_OK) で正常終了です.
+ 引数: 無し
+ 戻り値 (Fixnum): 直前の Tcl_Eval() が返した値.
+
+(eof)
diff --git a/ext/tcltklib/README.euc b/ext/tcltklib/README.euc
new file mode 100644
index 0000000..290ffb0
--- /dev/null
+++ b/ext/tcltklib/README.euc
@@ -0,0 +1,133 @@
+(tof)
+ tcltk ライブラリ
+ tcltklib ライブラリ
+ Sep. 19, 1997 Y. Shigehiro
+
+以下, 「tcl/tk」という表記は, tclsh や wish を実現している, 一般でいう
+ところの tcl/tk を指します. 「tcltk ライブラリ」, 「tcltklib ライブラ
+リ」という表記は, 本パッケージに含まれる ruby 用のライブラリを指します.
+
+[ファイルについて]
+
+README.euc : このファイル(注意, 特徴, インストールの方法).
+MANUAL.euc : マニュアル.
+
+lib/, ext/ : ライブラリの実体.
+
+sample/ : マニュアル代わりのサンプルプログラム.
+sample/sample0.rb : tcltklib ライブラリのテスト.
+sample/sample1.rb : tcltk ライブラリのテスト.
+ tcl/tk (wish) でできそうなことを一通り書いてみました.
+sample/sample2.rb : tcltk ライブラリのサンプル.
+ maeda shugo (shugo@po.aianet.ne.jp) 氏による
+ (`rb.tk' で書かれていた) ruby のサンプルプログラム
+ http://www.aianet.or.jp/~shugo/ruby/othello.rb.gz
+ を tcltk ライブラリを使うように, 機械的に変更してみました.
+
+demo/ : 100 本の線を 100 回描くデモプログラム.
+ 最初に空ループの時間を測定し, 続いて実際に線を引く時間を測定します.
+ tcl/tk は(再)描画のときに backing store を使わずに律義に 10000 本(?)
+ 線を引くので, (再)描画を始めると, マシンがかなり重くなります.
+demo/lines0.tcl : wish 用のスクリプト.
+demo/lines1.rb : `tk.rb' 用のスクリプト.
+demo/lines2.rb : tcltk ライブラリ用のスクリプト.
+
+[注意]
+
+コンパイル/実行には, tcl/tk の C ライブラリが必要です.
+
+このライブラリは,
+
+ ruby-1.0-970701, ruby-1.0-970911, ruby-1.0-970919
+ FreeBSD 2.2.2-RELEASE
+ およびそのパッケージ jp-tcl-7.6.tgz, jp-tk-4.2.tgz
+
+で作成/動作確認しました. 他の環境では動作するかどうかわかりません.
+
+TclTkLib.mainloop を実行中に Control-C が効かないのは不便なので, ruby
+のソースを参考に, #include "sig.h" して trap_immediate を操作していま
+すが, ruby の README.EXT にも書いてないのに, こんなことをして良いのか
+どうかわかりません.
+
+-d オプションでデバッグ情報を表示させるために, ruby のソースを参考に,
+debug という大域変数を参照していますが, ruby の README.EXT にも書いて
+ないのに, こんなことをして良いのかどうかわかりません.
+
+extconf.rb は書きましたが, (いろいろな意味で)これで良いのか良く分かり
+ません.
+
+[特徴]
+
+ruby から tcl/tk ライブラリを利用できます.
+
+tcl/tk インタプリタのスクリプトは, 機械的に tcltk ライブラリ用の ruby
+スクリプトに変換できます.
+
+(`tk.rb' との違い)
+
+1. tcl/tk インタプリタのスクリプトが, どのように, tcltk ライブラリ用の
+ ruby スクリプトに変換されるかが理解できれば, マニュアル類が無いに等
+ しい `tk.rb' とは異なり
+
+ tcl/tk のマニュアルやオンラインドキュメントを用いて
+
+ 効率良くプログラミングを行うことができます.
+ 記述方法がわからない, コマンドに与えるパラメータがわからない...
+ - Canvas.new { ... } と, なぜイテレータブロックを書けるの??
+ - Canvas の bbox は数値のリストを返すのに, xview は文字列を返すの??
+ と, いちいち, ライブラリのソースを追いかける必要はありません.
+
+2. 個々の機能(オプション)を個別処理によりサポートしており, そのためサ
+ ポートしていない機能は使うことができない(本当は使えないこともないの
+ ですが) `tk.rb' とは異なり, tcl/tk インタプリタで可能なことは
+
+ ほとんど
+
+ ruby からも実行できます. 現在, ruby から実行できないことが確認され
+ ているのは,
+
+ bind コマンドでスクリプトを追加する構文
+ 「bind tag sequence +script」
+ ^
+
+ のみです.
+ - `. configure -width' をしようとして, `Tk.root.height()' と書い
+ たのに, `undefined method `height'' と怒られてしまった. tk.rb を
+ 読んでみて, ガーン. できないのか...
+ ということはありません.
+
+3. wish プロセスを起動しプロセス間通信で wish を利用する `tk.rb' とは
+ 異なり, tcl/tk の C ライブラリをリンクし
+
+ より高速に (といっても, 思った程は速くないですが)
+
+ 処理を行います.
+
+4. `tk.rb' ほど, 高水準なインターフェースを備えていないため, tcl/tk イ
+ ンタプリタの生成等
+
+ 何から何まで自分で記述
+
+ しなければなりません(その代わり, tcl/tk ライブラリの仕様通り,
+ tcl/tk インタプリタを複数生成することもできますが).
+ インターフェースは(おそらく) ruby の思想に沿ったものではありません.
+ また, スクリプトの記述は
+
+ ダサダサ
+
+ です. スクリプトは, 一見, 読みづらいものとなります. が, 書く人にとっ
+ ては, それほど煩わしいものではないと思います.
+
+[インストールの方法]
+
+0. ruby のソースファイル(ruby-1.0-なんたら.tgz)を展開しておきます.
+
+1. ruby-1.0-なんたら/ext に ext/tcltklib をコピーします.
+ cp -r ext/tcltklib ???/ruby-1.0-なんたら/ext/
+
+2. ruby のインストール法に従い make 等をします.
+
+3. ruby のライブラリ置場に lib/* をコピーします.
+ cp lib/* /usr/local/lib/ruby/
+
+(eof)
diff --git a/ext/tcltklib/demo/lines0.tcl b/ext/tcltklib/demo/lines0.tcl
new file mode 100644
index 0000000..8ed3c5e
--- /dev/null
+++ b/ext/tcltklib/demo/lines0.tcl
@@ -0,0 +1,42 @@
+#! /usr/local/bin/wish
+
+proc drawlines {} {
+ puts [clock format [clock seconds]]
+
+ for {set j 0} {$j < 100} {incr j} {
+ puts -nonewline "*"
+ flush stdout
+ if {$j & 1} {
+ set c "blue"
+ } {
+ set c "red"
+ }
+ for {set i 0} {$i < 100} {incr i} {
+# .a create line $i 0 0 [expr 500 - $i] -fill $c
+ }
+ }
+
+ puts [clock format [clock seconds]]
+
+ for {set j 0} {$j < 100} {incr j} {
+ puts -nonewline "*"
+ flush stdout
+ if {$j & 1} {
+ set c "blue"
+ } {
+ set c "red"
+ }
+ for {set i 0} {$i < 100} {incr i} {
+ .a create line $i 0 0 [expr 500 - $i] -fill $c
+ }
+ }
+
+ puts [clock format [clock seconds]]
+# destroy .
+}
+
+canvas .a -height 500 -width 500
+button .b -text draw -command drawlines
+pack .a .b -side left
+
+# eof
diff --git a/ext/tcltklib/demo/lines1.rb b/ext/tcltklib/demo/lines1.rb
new file mode 100644
index 0000000..e459589
--- /dev/null
+++ b/ext/tcltklib/demo/lines1.rb
@@ -0,0 +1,54 @@
+#! /usr/local/bin/ruby
+
+require "tk"
+
+def drawlines()
+ print Time.now, "\n"
+
+ for j in 0 .. 99
+ print "*"
+ $stdout.flush
+ if (j & 1) != 0
+ col = "blue"
+ else
+ col = "red"
+ end
+ for i in 0 .. 99
+# TkcLine.new($a, i, 0, 0, 500 - i, "-fill", col)
+ end
+ end
+
+ print Time.now, "\n"
+
+ for j in 0 .. 99
+ print "*"
+ $stdout.flush
+ if (j & 1) != 0
+ col = "blue"
+ else
+ col = "red"
+ end
+ for i in 0 .. 99
+ TkcLine.new($a, i, 0, 0, 500 - i, "-fill", col)
+ end
+ end
+
+ print Time.now, "\n"
+# Tk.root.destroy
+end
+
+$a = TkCanvas.new{
+ height(500)
+ width(500)
+}
+
+$b = TkButton.new{
+ text("draw")
+ command(proc{drawlines()})
+}
+
+TkPack.configure($a, $b, {"side"=>"left"})
+
+Tk.mainloop
+
+# eof
diff --git a/ext/tcltklib/demo/lines2.rb b/ext/tcltklib/demo/lines2.rb
new file mode 100644
index 0000000..9f21ae6
--- /dev/null
+++ b/ext/tcltklib/demo/lines2.rb
@@ -0,0 +1,50 @@
+#! /usr/local/bin/ruby
+
+require "tcltk"
+
+def drawlines()
+ print Time.now, "\n"
+
+ for j in 0 .. 99
+ print "*"
+ $stdout.flush
+ if (j & 1) != 0
+ col = "blue"
+ else
+ col = "red"
+ end
+ for i in 0 .. 99
+# $a.e("create line", i, 0, 0, 500 - i, "-fill", col)
+ end
+ end
+
+ print Time.now, "\n"
+
+ for j in 0 .. 99
+ print "*"
+ $stdout.flush
+ if (j & 1) != 0
+ col = "blue"
+ else
+ col = "red"
+ end
+ for i in 0 .. 99
+ $a.e("create line", i, 0, 0, 500 - i, "-fill", col)
+ end
+ end
+
+ print Time.now, "\n"
+# $ip.commands()["destroy"].e($root)
+end
+
+$ip = TclTkInterpreter.new()
+$root = $ip.rootwidget()
+$a = TclTkWidget.new($ip, $root, "canvas", "-height 500 -width 500")
+$c = TclTkCallback.new($ip, proc{drawlines()})
+$b = TclTkWidget.new($ip, $root, "button", "-text draw -command", $c)
+
+$ip.commands()["pack"].e($a, $b, "-side left")
+
+TclTk.mainloop
+
+# eof
diff --git a/ext/tcltklib/depend b/ext/tcltklib/depend
new file mode 100644
index 0000000..71d9f20
--- /dev/null
+++ b/ext/tcltklib/depend
@@ -0,0 +1 @@
+tcltklib.o: tcltklib.c $(hdrdir)/ruby.h $(hdrdir)/config.h $(hdrdir)/defines.h
diff --git a/ext/tcltklib/extconf.rb b/ext/tcltklib/extconf.rb
new file mode 100644
index 0000000..26e7fe7
--- /dev/null
+++ b/ext/tcltklib/extconf.rb
@@ -0,0 +1,79 @@
+# extconf.rb for tcltklib
+
+have_library("socket", "socket")
+have_library("nsl", "gethostbyname")
+
+def search_file(var, include, *path)
+ pwd = Dir.getwd
+ begin
+ for i in path.reverse!
+ dir = Dir[i]
+ for path in dir
+ Dir.chdir path
+ files = Dir[include]
+ if files.size > 0
+ var << path
+ return files.pop
+ end
+ end
+ end
+ ensure
+ Dir.chdir pwd
+ end
+end
+
+$includes = []
+search_file($includes,
+ "tcl.h",
+ "/usr/include/tcl*",
+ "/usr/include",
+ "/usr/local/include/tcl*",
+ "/usr/local/include")
+search_file($includes,
+ "tk.h",
+ "/usr/include/tk*",
+ "/usr/include",
+ "/usr/local/include/tk*",
+ "/usr/local/include")
+search_file($includes,
+ "X11/Xlib.h",
+ "/usr/include",
+ "/usr/X11*/include",
+ "/usr/include",
+ "/usr/X11*/include")
+
+$CFLAGS = "-Wall " + $includes.collect{|path| "-I" + path}.join(" ")
+
+$libraries = []
+tcllibfile = search_file($libraries,
+ "libtcl{,7*,8*}.{a,so}",
+ "/usr/lib",
+ "/usr/local/lib")
+if tcllibfile
+ tcllibfile.sub!(/^lib/, '')
+ tcllibfile.sub!(/\.(a|so)$/, '')
+end
+tklibfile = search_file($libraries,
+ "libtk{,4*,8*}.{a,so}",
+ "/usr/lib",
+ "/usr/local/lib")
+if tklibfile
+ tklibfile.sub!(/^lib/, '')
+ tklibfile.sub!(/\.(a|so)$/, '')
+end
+search_file($libraries,
+ "libX11.{a,so}",
+ "/usr/lib",
+ "/usr/X11*/lib")
+
+$LDFLAGS = $libraries.collect{|path| "-L" + path}.join(" ")
+
+have_library("dl", "dlopen")
+if have_header("tcl.h") &&
+ have_header("tk.h") &&
+ have_library("X11", "XOpenDisplay") &&
+ have_library("m", "log") &&
+ have_library(tcllibfile, "Tcl_FindExecutable") &&
+ have_library(tklibfile, "Tk_Init")
+ create_makefile("tcltklib")
+end
diff --git a/ext/tcltklib/lib/tcltk.rb b/ext/tcltklib/lib/tcltk.rb
new file mode 100644
index 0000000..81d01f9
--- /dev/null
+++ b/ext/tcltklib/lib/tcltk.rb
@@ -0,0 +1,388 @@
+# tof
+
+#### tcltk ライブラリ
+#### Sep. 5, 1997 Y. Shigehiro
+
+require "tcltklib"
+
+################
+
+# module TclTk: tcl/tk のライブラリ全体で必要になるものを集めたもの
+# (主に, 名前空間の点から module にする使う.)
+module TclTk
+
+ # 単にここに書けば最初に 1 度実行されるのか??
+
+ # 生成した一意な名前を保持しておく連想配列を初期化する.
+ @namecnt = {}
+
+ # コールバックを保持しておく連想配列を初期化する.
+ @callback = {}
+end
+
+# TclTk.mainloop(): TclTkLib.mainloop() を呼ぶ.
+def TclTk.mainloop()
+ print("mainloop: start\n") if $DEBUG
+ TclTkLib.mainloop()
+ print("mainloop: end\n") if $DEBUG
+end
+
+# TclTk.deletecallbackkey(ca): コールバックを TclTk module から取り除く.
+# tcl/tk インタプリタにおいてコールバックが取り消されるわけではない.
+# これをしないと, 最後に TclTkInterpreter が GC できない.
+# (GC したくなければ, 別に, これをしなくても良い.)
+# ca: コールバック(TclTkCallback)
+def TclTk.deletecallbackkey(ca)
+ print("deletecallbackkey: ", ca.to_s(), "\n") if $DEBUG
+ @callback.delete(ca.to_s)
+end
+
+# TclTk.dcb(ca, wid, W): 配列に入っている複数のコールバックに対して
+# TclTk.deletecallbackkey() を呼ぶ.
+# トップレベルの <Destroy> イベントのコールバックとして呼ぶためのもの.
+# ca: コールバック(TclTkCallback) の Array
+# wid: トップレベルのウィジェット(TclTkWidget)
+# w: コールバックに %W で与えられる, ウインドウに関するパラメータ(String)
+def TclTk.dcb(ca, wid, w)
+ if wid.to_s() == w
+ ca.each{|i|
+ TclTk.deletecallbackkey(i)
+ }
+ end
+end
+
+# TclTk._addcallback(ca): コールバックを登録する.
+# ca: コールバック(TclTkCallback)
+def TclTk._addcallback(ca)
+ print("_addcallback: ", ca.to_s(), "\n") if $DEBUG
+ @callback[ca.to_s()] = ca
+end
+
+# TclTk._callcallback(key, arg): 登録したコールバックを呼び出す.
+# key: コールバックを選択するキー (TclTkCallback が to_s() で返す値)
+# arg: tcl/tk インタプリタからのパラメータ
+def TclTk._callcallback(key, arg)
+ print("_callcallback: ", @callback[key].inspect, "\n") if $DEBUG
+ @callback[key]._call(arg)
+ # コールバックからの返り値はどうせ捨てられる.
+ # String を返さないと, rb_eval_string() がエラーになる.
+ return ""
+end
+
+# TclTk._newname(prefix): 一意な名前(String)を生成して返す.
+# prefix: 名前の接頭語
+def TclTk._newname(prefix)
+ # 生成した名前のカウンタは @namecnt に入っているので, 調べる.
+ if !@namecnt.key?(prefix)
+ # 初めて使う接頭語なので初期化する.
+ @namecnt[prefix] = 1
+ else
+ # 使ったことのある接頭語なので, 次の名前にする.
+ @namecnt[prefix] += 1
+ end
+ return "#{prefix}#{@namecnt[prefix]}"
+end
+
+################
+
+# class TclTkInterpreter: tcl/tk のインタプリタ
+class TclTkInterpreter
+
+ # initialize(): 初期化.
+ def initialize()
+ # インタプリタを生成する.
+ @ip = TclTkIp.new()
+
+ # インタプリタに ruby_fmt コマンドを追加する.
+ # ruby_fmt コマンドとは, 後ろの引数を format コマンドで処理して
+ # ruby コマンドに渡すものである.
+ # (なお, ruby コマンドは, 引数を 1 つしかとれない.)
+ if $DEBUG
+ @ip._eval("proc ruby_fmt {fmt args} { puts \"ruby_fmt: $fmt $args\" ; ruby [format $fmt $args] }")
+ else
+ @ip._eval("proc ruby_fmt {fmt args} { ruby [format $fmt $args] }")
+ end
+
+ # @ip._get_eval_string(*args): tcl/tk インタプリタで評価する
+ # 文字列(String)を生成して返す.
+ # *args: tcl/tk で評価するスクリプト(に対応するオブジェクト列)
+ def @ip._get_eval_string(*args)
+ argstr = ""
+ args.each{|arg|
+ argstr += " " if argstr != ""
+ # もし to_eval() メソッドが
+ if (arg.respond_to?(:to_eval))
+ # 定義されていればそれを呼ぶ.
+ argstr += arg.to_eval()
+ else
+ # 定義されていなければ to_s() を呼ぶ.
+ argstr += arg.to_s()
+ end
+ }
+ return argstr
+ end
+
+ # @ip._eval_args(*args): tcl/tk インタプリタで評価し,
+ # その結果(String)を返す.
+ # *args: tcl/tk で評価するスクリプト(に対応するオブジェクト列)
+ def @ip._eval_args(*args)
+ # インタプリタで評価する文字列を求める.
+ argstr = _get_eval_string(*args)
+
+ # インタプリタで評価する.
+ print("_eval: \"", argstr, "\"") if $DEBUG
+ res = _eval(argstr)
+ if $DEBUG
+ print(" -> \"", res, "\"\n")
+ elsif _return_value() != 0
+ print(res, "\n")
+ end
+ fail(%Q/can't eval "#{argstr}"/) if _return_value() != 0
+ return res
+ end
+
+ # tcl/tk のコマンドに対応するオブジェクトを生成し, 連想配列に入れておく.
+ @commands = {}
+ # tcl/tk インタプリタに登録されているすべてのコマンドに対して,
+ @ip._eval("info command").split(/ /).each{|comname|
+ if comname =~ /^[.]/
+ # コマンドがウィジェット(のパス名)の場合は
+ # TclTkWidget のインスタンスを作って連想配列に入れる.
+ @commands[comname] = TclTkWidget.new(@ip, comname)
+ else
+ # そうでない場合は
+ # TclTkCommand のインスタンスを作って連想配列に入れる.
+ @commands[comname] = TclTkCommand.new(@ip, comname)
+ end
+ }
+ end
+
+ # commands(): tcl/tk のコマンドに対応するオブジェクトを Hash に
+ # 入れたものを返す.
+ def commands()
+ return @commands
+ end
+
+ # rootwidget(): ルートウィジェット(TclTkWidget)を返す.
+ def rootwidget()
+ return @commands["."]
+ end
+
+ # _tcltkip(): @ip(TclTkIp) を返す.
+ def _tcltkip()
+ return @ip
+ end
+
+ # method_missing(id, *args): 未定義のメソッドは tcl/tk のコマンドとみなして
+ # 実行し, その結果(String)を返す.
+ # id: メソッドのシンボル
+ # *args: コマンドの引数
+ def method_missing(id, *args)
+ # もし, メソッドの tcl/tk コマンドが
+ if @commands.key?(id.id2name)
+ # あれば, 実行して結果を返す.
+ return @commands[id.id2name].e(*args)
+ else
+ # 無ければもともとの処理.
+ super
+ end
+ end
+end
+
+# class TclTkObject: tcl/tk のオブジェクト
+# (基底クラスとして使う.
+# tcltk ライブラリを使う人が TclTkObject.new() することはないはず.)
+class TclTkObject
+
+ # initialize(ip, exp): 初期化.
+ # ip: インタプリタ(TclTkIp)
+ # exp: tcl/tk での表現形
+ def initialize(ip, exp)
+ fail("type is not TclTkIp") if !ip.kind_of?(TclTkIp)
+ @ip = ip
+ @exp = exp
+ end
+
+ # to_s(): tcl/tk での表現形(String)を返す.
+ def to_s()
+ return @exp
+ end
+end
+
+# class TclTkCommand: tcl/tk のコマンド
+# (tcltk ライブラリを使う人が TclTkCommand.new() することはないはず.
+# TclTkInterpreter:initialize() から new() される.)
+class TclTkCommand < TclTkObject
+
+ # e(*args): コマンドを実行し, その結果(String)を返す.
+ # (e は exec または eval の e.)
+ # *args: コマンドの引数
+ def e(*args)
+ return @ip._eval_args(to_s(), *args)
+ end
+end
+
+# class TclTkLibCommand: tcl/tk のコマンド
+# (ライブラリにより実現されるコマンドで, tcl/tk インタプリタに最初から
+# 存在しないものは, インタプリタの commands() では生成できない.
+# そのようなものに対し, コマンドの名前から TclTkCommand オブジェクトを
+# 生成する.
+class TclTkLibCommand < TclTkCommand
+
+ # initialize(ip, name): 初期化
+ # ip: インタプリタ(TclTkInterpreter)
+ # name: コマンド名 (String)
+ def initialize(ip, name)
+ super(ip._tcltkip, name)
+ end
+end
+
+# class TclTkVariable: tcl/tk の変数
+class TclTkVariable < TclTkObject
+
+ # initialize(interp, dat): 初期化.
+ # interp: インタプリタ(TclTkInterpreter)
+ # dat: 設定する値(String)
+ # nil なら, 設定しない.
+ def initialize(interp, dat)
+ # tcl/tk での表現形(変数名)を自動生成する.
+ exp = TclTk._newname("v_")
+ # TclTkObject を初期化する.
+ super(interp._tcltkip(), exp)
+ # set コマンドを使うのでとっておく.
+ @set = interp.commands()["set"]
+ # 値を設定する.
+ set(dat) if dat
+ end
+
+ # tcl/tk の set を使えば, 値の設定/参照はできるが,
+ # それだけではなんなので, 一応, メソッドをかぶせたものも用意しておく.
+
+ # set(data): tcl/tk の変数に set を用いて値を設定する.
+ # data: 設定する値
+ def set(data)
+ @set.e(to_s(), data.to_s())
+ end
+
+ # get(): tcl/tk の変数の値(String)を set を用いて読みだし返す.
+ def get()
+ return @set.e(to_s())
+ end
+end
+
+# class TclTkWidget: tcl/tk のウィジェット
+class TclTkWidget < TclTkCommand
+
+ # initialize(*args): 初期化.
+ # *args: パラメータ
+ def initialize(*args)
+ if args[0].kind_of?(TclTkIp)
+ # 最初の引数が TclTkIp の場合:
+
+ # 既に tcl/tk に定義されているウィジェットに TclTkWidget の構造を
+ # かぶせる. (TclTkInterpreter:initialize() から使われる.)
+
+ # パラメータ数が 2 でなければエラー.
+ fail("illegal # of parameter") if args.size != 2
+
+ # ip: インタプリタ(TclTkIp)
+ # exp: tcl/tk での表現形
+ ip, exp = args
+
+ # TclTkObject を初期化する.
+ super(ip, exp)
+ elsif args[0].kind_of?(TclTkInterpreter)
+ # 最初の引数が TclTkInterpreter の場合:
+
+ # 親ウィジェットから新たなウィジェトを生成する.
+
+ # interp: インタプリタ(TclTkInterpreter)
+ # parent: 親ウィジェット
+ # command: ウィジェットを生成するコマンド(label 等)
+ # *args: command に渡す引数
+ interp, parent, command, *args = args
+
+ # ウィジェットの名前を作る.
+ exp = parent.to_s()
+ exp += "." if exp !~ /[.]$/
+ exp += TclTk._newname("w_")
+ # TclTkObject を初期化する.
+ super(interp._tcltkip(), exp)
+ # ウィジェットを生成する.
+ res = @ip._eval_args(command, exp, *args)
+# fail("can't create Widget") if res != exp
+ # tk_optionMenu では, ボタン名を exp で指定すると
+ # res にメニュー名を返すので res != exp となる.
+ else
+ fail("first parameter is not TclTkInterpreter")
+ end
+ end
+end
+
+# class TclTkCallback: tcl/tk のコールバック
+class TclTkCallback < TclTkObject
+
+ # initialize(interp, pr, arg): 初期化.
+ # interp: インタプリタ(TclTkInterpreter)
+ # pr: コールバック手続き(Proc)
+ # arg: pr のイテレータ変数に渡す文字列
+ # tcl/tk の bind コマンドではパラメータを受け取るために % 置換を
+ # 用いるが, pr の内部で % を書いてもうまくいかない.
+ # arg に文字列を書いておくと, その置換結果を, pr で
+ # イテレータ変数を通して受け取ることができる.
+ # scrollbar コマンドの -command オプションのように
+ # 何も指定しなくてもパラメータが付くコマンドに対しては,
+ # arg を指定してはならない.
+ def initialize(interp, pr, arg = nil)
+ # tcl/tk での表現形(変数名)を自動生成する.
+ exp = TclTk._newname("c_")
+ # TclTkObject を初期化する.
+ super(interp._tcltkip(), exp)
+ # パラメータをとっておく.
+ @pr = pr
+ @arg = arg
+ # モジュールに登録しておく.
+ TclTk._addcallback(self)
+ end
+
+ # to_eval(): @ip._eval_args で評価するときの表現形(String)を返す.
+ def to_eval()
+ if @arg
+ # %s は ruby_fmt より前に bind により置換されてしまうので
+ # %%s としてある. したがって, これは bind 専用.
+ s = %Q/{ruby_fmt {TclTk._callcallback("#{to_s()}", "%%s")} #{@arg}}/
+ else
+ s = %Q/{ruby_fmt {TclTk._callcallback("#{to_s()}", "%s")}}/
+ end
+
+ return s
+ end
+
+ # _call(arg): コールバックを呼び出す.
+ # arg: コールバックに渡されるパラメータ
+ def _call(arg)
+ @pr.call(arg)
+ end
+end
+
+# class TclTkImage: tcl/tk のイメージ
+class TclTkImage < TclTkCommand
+
+ # initialize(interp, t, *args): 初期化.
+ # イメージの生成は TclTkImage.new() で行うが,
+ # 破壊は image delete で行う. (いまいちだけど仕方が無い.)
+ # interp: インタプリタ(TclTkInterpreter)
+ # t: イメージのタイプ (photo, bitmap, etc.)
+ # *args: コマンドの引数
+ def initialize(interp, t, *args)
+ # tcl/tk での表現形(変数名)を自動生成する.
+ exp = TclTk._newname("i_")
+ # TclTkObject を初期化する.
+ super(interp._tcltkip(), exp)
+ # イメージを生成する.
+ res = @ip._eval_args("image create", t, exp, *args)
+ fail("can't create Image") if res != exp
+ end
+end
+
+# eof
diff --git a/ext/tcltklib/sample/batsu.gif b/ext/tcltklib/sample/batsu.gif
new file mode 100644
index 0000000..880cc73
--- /dev/null
+++ b/ext/tcltklib/sample/batsu.gif
Binary files differ
diff --git a/ext/tcltklib/sample/maru.gif b/ext/tcltklib/sample/maru.gif
new file mode 100644
index 0000000..2c02028
--- /dev/null
+++ b/ext/tcltklib/sample/maru.gif
Binary files differ
diff --git a/ext/tcltklib/sample/sample0.rb b/ext/tcltklib/sample/sample0.rb
new file mode 100644
index 0000000..cd4c806
--- /dev/null
+++ b/ext/tcltklib/sample/sample0.rb
@@ -0,0 +1,39 @@
+#! /usr/local/bin/ruby -vd
+
+# tcltklib ライブラリのテスト
+
+require "tcltklib"
+
+def test
+ # インタプリタを生成する
+ ip1 = TclTkIp.new()
+
+ # 評価してみる
+ print ip1._return_value().inspect, "\n"
+ print ip1._eval("puts {abc}").inspect, "\n"
+
+ # ボタンを作ってみる
+ print ip1._return_value().inspect, "\n"
+ print ip1._eval("button .lab -text exit -command \"destroy .\"").inspect,
+ "\n"
+ print ip1._return_value().inspect, "\n"
+ print ip1._eval("pack .lab").inspect, "\n"
+ print ip1._return_value().inspect, "\n"
+
+ # インタプリタから ruby コマンドを評価してみる
+# print ip1._eval(%q/ruby {print "print by ruby\n"}/).inspect, "\n"
+ print ip1._eval(%q+puts [ruby {print "print by ruby\n"; "puts by tcl/tk"}]+).inspect, "\n"
+ print ip1._return_value().inspect, "\n"
+
+ # もう一つインタプリタを生成してみる
+ ip2 = TclTkIp.new()
+ ip2._eval("button .lab -text test -command \"puts test ; destroy .\"")
+ ip2._eval("pack .lab")
+
+ TclTkLib.mainloop
+end
+
+test
+GC.start
+
+print "exit\n"
diff --git a/ext/tcltklib/sample/sample1.rb b/ext/tcltklib/sample/sample1.rb
new file mode 100644
index 0000000..28ba7b5
--- /dev/null
+++ b/ext/tcltklib/sample/sample1.rb
@@ -0,0 +1,634 @@
+#! /usr/local/bin/ruby -d
+#! /usr/local/bin/ruby
+# -d オプションを付けると, デバッグ情報を表示する.
+
+# tcltk ライブラリのサンプル
+
+# まず, ライブラリを require する.
+require "tcltk"
+
+# 以下は, Test1 のインスタンスの initialize() で,
+# tcl/tk に関する処理を行う例である.
+# 必ずしもそのようにする必要は無く,
+# (もし, そうしたければ) class の外で tcl/tk に関する処理を行っても良い.
+
+class Test1
+ # 初期化(インタプリタを生成してウィジェットを生成する).
+ def initialize()
+
+ #### 使う前のおまじない
+
+ # インタプリタの生成.
+ ip = TclTkInterpreter.new()
+ # コマンドに対応するオブジェクトを c に設定しておく.
+ c = ip.commands()
+ # 使用するコマンドに対応するオブジェクトは変数に入れておく.
+ append, bind, button, destroy, incr, info, label, place, set, wm =
+ c.indexes(
+ "append", "bind", "button", "destroy", "incr", "info", "label", "place",
+ "set", "wm")
+
+ #### tcl/tk のコマンドに対応するオブジェクト(TclTkCommand)の操作
+
+ # 実行する時は, e() メソッドを使う.
+ # (以下は, tcl/tk における info command r* を実行.)
+ print info.e("command", "r*"), "\n"
+ # 引数は, まとめた文字列にしても同じ.
+ print info.e("command r*"), "\n"
+ # 変数を用いなくとも実行できるが, 見ためが悪い.
+ print c["info"].e("command", "r*"), "\n"
+ # インタプリタのメソッドとしても実行できるが, 効率が悪い.
+ print ip.info("command", "r*"), "\n"
+
+ ####
+
+ # 以下, 生成したオブジェクトは変数に代入しておかないと
+ # GC の対象になってしまう.
+
+ #### tcl/tk の変数に対応するオブジェクト(TclTkVariable)の操作
+
+ # 生成と同時に値を設定する.
+ v1 = TclTkVariable.new(ip, "20")
+ # 読み出しは get メソッドを使う.
+ print v1.get(), "\n"
+ # 設定は set メソッドを使う.
+ v1.set(40)
+ print v1.get(), "\n"
+ # set コマンドを使って読み出し, 設定は可能だが見ためが悪い.
+ # e() メソッド等の引数に直接 TclTkObject や数値を書いても良い.
+ set.e(v1, 30)
+ print set.e(v1), "\n"
+ # tcl/tk のコマンドで変数を操作できる.
+ incr.e(v1)
+ print v1.get(), "\n"
+ append.e(v1, 10)
+ print v1.get(), "\n"
+
+ #### tcl/tk のウィジェットに対応するオブジェクト(TclTkWidget)の操作
+
+ # ルートウィジェットを取り出す.
+ root = ip.rootwidget()
+ # ウィジェットの操作.
+ root.e("configure -height 300 -width 300")
+ # タイトルを付けるときは wm を使う.
+ wm.e("title", root, $0)
+ # 親ウィジェットとコマンドを指定して, ウィジェットを作る.
+ l1 = TclTkWidget.new(ip, root, label, "-text {type `x' to print}")
+ # place すると表示される.
+ place.e(l1, "-x 0 -rely 0.0 -relwidth 1 -relheight 0.1")
+ # コマンド名は文字列で指定しても良いが, 見ためが悪い.
+ # (コマンド名は独立した引数でなければならない.)
+ l2 = TclTkWidget.new(ip, root, "label")
+ # ウィジェットの操作.
+ l2.e("configure -text {type `q' to exit}")
+ place.e(l2, "-x 0 -rely 0.1 -relwidth 1 -relheight 0.1")
+
+ #### tcl/tk のコールバックに対応するオブジェクト(TclTkCallback)の操作
+
+ # コールバックを生成する.
+ c1 = TclTkCallback.new(ip, proc{sample(ip, root)})
+ # コールバックを持つウィジェットを生成する.
+ b1 = TclTkWidget.new(ip, root, button, "-text sample -command", c1)
+ place.e(b1, "-x 0 -rely 0.2 -relwidth 1 -relheight 0.1")
+ # イベントループを抜けるには destroy.e(root) する.
+ c2 = TclTkCallback.new(ip, proc{destroy.e(root)})
+ b2 = TclTkWidget.new(ip, root, button, "-text exit -command", c2)
+ place.e(b2, "-x 0 -rely 0.3 -relwidth 1 -relheight 0.1")
+
+ #### イベントのバインド
+ # script の追加 (bind tag sequence +script) は今のところできない.
+ # (イテレータ変数の設定がうまくいかない.)
+
+ # 基本的にはウィジェットに対するコールバックと同じ.
+ c3 = TclTkCallback.new(ip, proc{print("q pressed\n"); destroy.e(root)})
+ bind.e(root, "q", c3)
+ # bind コマンドで % 置換によりパラメータを受け取りたいときは,
+ # proc{} の後ろに文字列で指定すると,
+ # 置換結果をイテレータ変数を通して受け取ることができる.
+ # ただし proc{} の後ろの文字列は,
+ # bind コマンドに与えるコールバック以外で指定してはいけない.
+ c4 = TclTkCallback.new(ip, proc{|i| print("#{i} pressed\n")}, "%A")
+ bind.e(root, "x", c4)
+ # TclTkCallback を GC の対象にしたければ,
+ # dcb() (または deletecallbackkeys()) する必要がある.
+ cb = [c1, c2, c3, c4]
+ c5 = TclTkCallback.new(ip, proc{|w| TclTk.dcb(cb, root, w)}, "%W")
+ bind.e(root, "<Destroy>", c5)
+ cb.push(c5)
+
+ #### tcl/tk のイメージに対応するオブジェクト(TclTkImage)の操作
+
+ # データを指定して生成する.
+ i1 = TclTkImage.new(ip, "photo", "-file maru.gif")
+ # ラベルに張り付けてみる.
+ l3 = TclTkWidget.new(ip, root, label, "-relief raised -image", i1)
+ place.e(l3, "-x 0 -rely 0.4 -relwidth 0.2 -relheight 0.2")
+ # 空のイメージを生成して後で操作する.
+ i2 = TclTkImage.new(ip, "photo")
+ # イメージを操作する.
+ i2.e("copy", i1)
+ i2.e("configure -gamma 0.5")
+ l4 = TclTkWidget.new(ip, root, label, "-relief raised -image", i2)
+ place.e(l4, "-relx 0.2 -rely 0.4 -relwidth 0.2 -relheight 0.2")
+
+ ####
+ end
+
+ # サンプルのためのウィジェットを生成する.
+ def sample(ip, parent)
+ bind, button, destroy, grid, toplevel, wm = ip.commands().indexes(
+ "bind", "button", "destroy", "grid", "toplevel", "wm")
+
+ ## toplevel
+
+ # 新しいウインドウを開くには, toplevel を使う.
+ t1 = TclTkWidget.new(ip, parent, toplevel)
+ # タイトルを付けておく
+ wm.e("title", t1, "sample")
+
+ # ウィジェットが破壊されたとき, コールバックが GC の対象になるようにする.
+ cb = []
+ cb.push(c = TclTkCallback.new(ip, proc{|w| TclTk.dcb(cb, t1, w)}, "%W"))
+ bind.e(t1, "<Destroy>", c)
+
+ # ボタンの生成.
+ wid = []
+ # toplevel ウィジェットを破壊するには destroy する.
+ cb.push(c = TclTkCallback.new(ip, proc{destroy.e(t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text close -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_label(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text label -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_button(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text button -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_checkbutton(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text checkbutton -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_radiobutton(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text radiobutton -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_scale(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text scale -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_entry(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text entry -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_text(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text text -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_raise(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text raise/lower -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_modal(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text message/modal -command",
+ c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_menu(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text menu -command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_listbox(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text listbox/scrollbar",
+ "-command", c))
+ cb.push(c = TclTkCallback.new(ip, proc{test_canvas(ip, t1)}))
+ wid.push(TclTkWidget.new(ip, t1, button, "-text canvas -command", c))
+
+ # grid で表示する.
+ ro = co = 0
+ wid.each{|w|
+ grid.e(w, "-row", ro, "-column", co, "-sticky news")
+ ro += 1
+ if ro == 7
+ ro = 0
+ co += 1
+ end
+ }
+ end
+
+ # inittoplevel(ip, parent, title)
+ # 以下の処理をまとめて行う.
+ # 1. toplevel ウィジェットを作成する.
+ # 2. コールバックを登録する配列を用意し, toplevel ウィジェットの
+ # <Destroy> イベントにコールバックを削除する手続きを登録する.
+ # 3. クローズボタンを作る.
+ # 作成した toplevel ウィジェット, クローズボタン, コールバック登録用変数
+ # を返す.
+ # ip: インタプリタ
+ # parent: 親ウィジェット
+ # title: toplevel ウィジェットのウインドウのタイトル
+ def inittoplevel(ip, parent, title)
+ bind, button, destroy, toplevel, wm = ip.commands().indexes(
+ "bind", "button", "destroy", "toplevel", "wm")
+
+ # 新しいウインドウを開くには, toplevel を使う.
+ t1 = TclTkWidget.new(ip, parent, toplevel)
+ # タイトルを付けておく
+ wm.e("title", t1, title)
+
+ # ウィジェットが破壊されたとき, コールバックが GC の対象になるようにする.
+ cb = []
+ cb.push(c = TclTkCallback.new(ip, proc{|w| TclTk.dcb(cb, t1, w)}, "%W"))
+ bind.e(t1, "<Destroy>", c)
+ # close ボタンを作っておく.
+ # toplevel ウィジェットを破壊するには destroy する.
+ cb.push(c = TclTkCallback.new(ip, proc{destroy.e(t1)}))
+ b1 = TclTkWidget.new(ip, t1, button, "-text close -command", c)
+
+ return t1, b1, cb
+ end
+
+ # label のサンプル.
+ def test_label(ip, parent)
+ button, global, label, pack = ip.commands().indexes(
+ "button", "global", "label", "pack")
+ t1, b1, cb = inittoplevel(ip, parent, "label")
+
+ ## label
+
+ # いろいろな形のラベル.
+ l1 = TclTkWidget.new(ip, t1, label, "-text {default(flat)}")
+ l2 = TclTkWidget.new(ip, t1, label, "-text raised -relief raised")
+ l3 = TclTkWidget.new(ip, t1, label, "-text sunken -relief sunken")
+ l4 = TclTkWidget.new(ip, t1, label, "-text groove -relief groove")
+ l5 = TclTkWidget.new(ip, t1, label, "-text ridge -relief ridge")
+ l6 = TclTkWidget.new(ip, t1, label, "-bitmap error")
+ l7 = TclTkWidget.new(ip, t1, label, "-bitmap questhead")
+
+ # pack しても表示される.
+ pack.e(b1, l1, l2, l3, l4, l5, l6, l7, "-pady 3")
+
+ ## -textvariable
+
+ # tcltk ライブラリの実装では, コールバックは tcl/tk の``手続き''を通して
+ # 呼ばれる. したがって, コールバックの中で(大域)変数にアクセスするときは,
+ # global する必要がある.
+ # global する前に変数に値を設定してしまうとエラーになるので,
+ # tcl/tk における表現形だけ生成して, 実際に値を設定しないように,
+ # 2 番目の引数には nil を与える.
+ v1 = TclTkVariable.new(ip, nil)
+ global.e(v1)
+ v1.set(100)
+ # -textvariable で変数を設定する.
+ l6 = TclTkWidget.new(ip, t1, label, "-textvariable", v1)
+ # コールバックの中から変数を操作する.
+ cb.push(c = TclTkCallback.new(ip, proc{
+ global.e(v1); v1.set(v1.get().to_i + 10)}))
+ b2 = TclTkWidget.new(ip, t1, button, "-text +10 -command", c)
+ cb.push(c = TclTkCallback.new(ip, proc{
+ global.e(v1); v1.set(v1.get().to_i - 10)}))
+ b3 = TclTkWidget.new(ip, t1, button, "-text -10 -command", c)
+ pack.e(l6, b2, b3)
+ end
+
+ # button のサンプル.
+ def test_button(ip, parent)
+ button, pack = ip.commands().indexes("button", "pack")
+ t1, b1, cb = inittoplevel(ip, parent, "button")
+
+ ## button
+
+ # コールバック内で参照する変数は先に宣言しておかなければならない.
+ b3 = b4 = nil
+ cb.push(c = TclTkCallback.new(ip, proc{b3.e("flash"); b4.e("flash")}))
+ b2 = TclTkWidget.new(ip, t1, button, "-text flash -command", c)
+ cb.push(c = TclTkCallback.new(ip, proc{b2.e("configure -state normal")}))
+ b3 = TclTkWidget.new(ip, t1, button, "-text normal -command", c)
+ cb.push(c = TclTkCallback.new(ip, proc{b2.e("configure -state disabled")}))
+ b4 = TclTkWidget.new(ip, t1, button, "-text disable -command", c)
+ pack.e(b1, b2, b3, b4)
+ end
+
+ # checkbutton のサンプル.
+ def test_checkbutton(ip, parent)
+ checkbutton, global, pack = ip.commands().indexes(
+ "checkbutton", "global", "pack")
+ t1, b1, cb = inittoplevel(ip, parent, "checkbutton")
+
+ ## checkbutton
+
+ v1 = TclTkVariable.new(ip, nil)
+ global.e(v1)
+ # -variable で変数を設定する.
+ ch1 = TclTkWidget.new(ip, t1, checkbutton, "-onvalue on -offvalue off",
+ "-textvariable", v1, "-variable", v1)
+ pack.e(b1, ch1)
+ end
+
+ # radiobutton のサンプル.
+ def test_radiobutton(ip, parent)
+ global, label, pack, radiobutton = ip.commands().indexes(
+ "global", "label", "pack", "radiobutton")
+ t1, b1, cb = inittoplevel(ip, parent, "radiobutton")
+
+ ## radiobutton
+
+ v1 = TclTkVariable.new(ip, nil)
+ global.e(v1)
+ # ヌルストリングは "{}" で指定する.
+ v1.set("{}")
+ l1 = TclTkWidget.new(ip, t1, label, "-textvariable", v1)
+ # -variable で同じ変数を指定すると同じグループになる.
+ ra1 = TclTkWidget.new(ip, t1, radiobutton,
+ "-text radio1 -value r1 -variable", v1)
+ ra2 = TclTkWidget.new(ip, t1, radiobutton,
+ "-text radio2 -value r2 -variable", v1)
+ cb.push(c = TclTkCallback.new(ip, proc{global.e(v1); v1.set("{}")}))
+ ra3 = TclTkWidget.new(ip, t1, radiobutton,
+ "-text clear -value r3 -variable", v1, "-command", c)
+ pack.e(b1, l1, ra1, ra2, ra3)
+ end
+
+ # scale のサンプル.
+ def test_scale(ip, parent)
+ global, pack, scale = ip.commands().indexes(
+ "global", "pack", "scale")
+ t1, b1, cb = inittoplevel(ip, parent, "scale")
+
+ ## scale
+
+ v1 = TclTkVariable.new(ip, nil)
+ global.e(v1)
+ v1.set(219)
+ # コールバック内で参照する変数は先に宣言しておかなければならない.
+ sca1 = nil
+ cb.push(c = TclTkCallback.new(ip, proc{global.e(v1); v = v1.get();
+ sca1.e("configure -background", format("#%02x%02x%02x", v, v, v))}))
+ sca1 = TclTkWidget.new(ip, t1, scale,
+ "-label scale -orient h -from 0 -to 255 -variable", v1, "-command", c)
+ pack.e(b1, sca1)
+ end
+
+ # entry のサンプル.
+ def test_entry(ip, parent)
+ button, entry, global, pack = ip.commands().indexes(
+ "button", "entry", "global", "pack")
+ t1, b1, cb = inittoplevel(ip, parent, "entry")
+
+ ## entry
+
+ v1 = TclTkVariable.new(ip, nil)
+ global.e(v1)
+ # ヌルストリングは "{}" で指定する.
+ v1.set("{}")
+ en1 = TclTkWidget.new(ip, t1, entry, "-textvariable", v1)
+ cb.push(c = TclTkCallback.new(ip, proc{
+ global.e(v1); print(v1.get(), "\n"); v1.set("{}")}))
+ b2 = TclTkWidget.new(ip, t1, button, "-text print -command", c)
+ pack.e(b1, en1, b2)
+ end
+
+ # text のサンプル.
+ def test_text(ip, parent)
+ button, pack, text = ip.commands().indexes(
+ "button", "pack", "text")
+ t1, b1, cb = inittoplevel(ip, parent, "text")
+
+ ## text
+
+ te1 = TclTkWidget.new(ip, t1, text)
+ cb.push(c = TclTkCallback.new(ip, proc{
+ # 1 行目の 0 文字目から最後までを表示し, 削除する.
+ print(te1.e("get 1.0 end")); te1.e("delete 1.0 end")}))
+ b2 = TclTkWidget.new(ip, t1, button, "-text print -command", c)
+ pack.e(b1, te1, b2)
+ end
+
+ # raise/lower のサンプル.
+ def test_raise(ip, parent)
+ button, frame, lower, pack, raise = ip.commands().indexes(
+ "button", "frame", "lower", "pack", "raise")
+ t1, b1, cb = inittoplevel(ip, parent, "raise/lower")
+
+ ## raise/lower
+
+ # button を隠すテストのために, frame を使う.
+ f1 = TclTkWidget.new(ip, t1, frame)
+ # コールバック内で参照する変数は先に宣言しておかなければならない.
+ b2 = nil
+ cb.push(c = TclTkCallback.new(ip, proc{raise.e(f1, b2)}))
+ b2 = TclTkWidget.new(ip, t1, button, "-text raise -command", c)
+ cb.push(c = TclTkCallback.new(ip, proc{lower.e(f1, b2)}))
+ b3 = TclTkWidget.new(ip, t1, button, "-text lower -command", c)
+ lower.e(f1, b3)
+
+ pack.e(b2, b3, "-in", f1)
+ pack.e(b1, f1)
+ end
+
+ # modal なウィジェットのサンプル.
+ def test_modal(ip, parent)
+ button, frame, message, pack, tk_chooseColor, tk_getOpenFile,
+ tk_messageBox = ip.commands().indexes(
+ "button", "frame", "message", "pack", "tk_chooseColor",
+ "tk_getOpenFile", "tk_messageBox")
+ # 最初に load されていないライブラリは ip.commands() に存在しないので,
+ # TclTkLibCommand を生成する必要がある.
+ tk_dialog = TclTkLibCommand.new(ip, "tk_dialog")
+ t1, b1, cb = inittoplevel(ip, parent, "message/modal")
+
+ ## message
+
+ mes = "これは message ウィジェットのテストです."
+ mes += "以下は modal なウィジェットのテストです."
+ me1 = TclTkWidget.new(ip, t1, message, "-text {#{mes}}")
+
+ ## modal
+
+ # tk_messageBox
+ cb.push(c = TclTkCallback.new(ip, proc{
+ print tk_messageBox.e("-type yesnocancel -message messageBox",
+ "-icon error -default cancel -title messageBox"), "\n"}))
+ b2 = TclTkWidget.new(ip, t1, button, "-text messageBox -command", c)
+ # tk_dialog
+ cb.push(c = TclTkCallback.new(ip, proc{
+ # ウィジェット名を生成するためにダミーの frame を生成.
+ print tk_dialog.e(TclTkWidget.new(ip, t1, frame),
+ "dialog dialog error 2 yes no cancel"), "\n"}))
+ b3 = TclTkWidget.new(ip, t1, button, "-text dialog -command", c)
+ # tk_chooseColor
+ cb.push(c = TclTkCallback.new(ip, proc{
+ print tk_chooseColor.e("-title chooseColor"), "\n"}))
+ b4 = TclTkWidget.new(ip, t1, button, "-text chooseColor -command", c)
+ # tk_getOpenFile
+ cb.push(c = TclTkCallback.new(ip, proc{
+ print tk_getOpenFile.e("-defaultextension .rb",
+ "-filetypes {{{Ruby Script} {.rb}} {{All Files} {*}}}",
+ "-title getOpenFile"), "\n"}))
+ b5 = TclTkWidget.new(ip, t1, button, "-text getOpenFile -command", c)
+
+ pack.e(b1, me1, b2, b3, b4, b5)
+ end
+
+ # menu のサンプル.
+ def test_menu(ip, parent)
+ global, menu, menubutton, pack = ip.commands().indexes(
+ "global", "menu", "menubutton", "pack")
+ tk_optionMenu = TclTkLibCommand.new(ip, "tk_optionMenu")
+ t1, b1, cb = inittoplevel(ip, parent, "menu")
+
+ ## menu
+
+ # menubutton を生成する.
+ mb1 = TclTkWidget.new(ip, t1, menubutton, "-text menu")
+ # menu を生成する.
+ me1 = TclTkWidget.new(ip, mb1, menu)
+ # mb1 から me1 が起動されるようにする.
+ mb1.e("configure -menu", me1)
+
+ # cascade で起動される menu を生成する.
+ me11 = TclTkWidget.new(ip, me1, menu)
+ # radiobutton のサンプル.
+ v1 = TclTkVariable.new(ip, nil); global.e(v1); v1.set("r1")
+ me11.e("add radiobutton -label radio1 -value r1 -variable", v1)
+ me11.e("add radiobutton -label radio2 -value r2 -variable", v1)
+ me11.e("add radiobutton -label radio3 -value r3 -variable", v1)
+ # cascade により mb11 が起動されるようにする.
+ me1.e("add cascade -label cascade -menu", me11)
+
+ # checkbutton のサンプル.
+ v2 = TclTkVariable.new(ip, nil); global.e(v2); v2.set("none")
+ me1.e("add checkbutton -label check -variable", v2)
+ # separator のサンプル.
+ me1.e("add separator")
+ # command のサンプル.
+ v3 = nil
+ cb.push(c = TclTkCallback.new(ip, proc{
+ global.e(v1, v2, v3); print "v1: ", v1.get(), ", v2: ", v2.get(),
+ ", v3: ", v3.get(), "\n"}))
+ me1.e("add command -label print -command", c)
+
+ ## tk_optionMenu
+
+ v3 = TclTkVariable.new(ip, nil); global.e(v3); v3.set("opt2")
+ om1 = TclTkWidget.new(ip, t1, tk_optionMenu, v3, "opt1 opt2 opt3 opt4")
+
+ pack.e(b1, mb1, om1, "-side left")
+ end
+
+ # listbox のサンプル.
+ def test_listbox(ip, parent)
+ clipboard, frame, grid, listbox, lower, menu, menubutton, pack, scrollbar,
+ selection = ip.commands().indexes(
+ "clipboard", "frame", "grid", "listbox", "lower", "menu", "menubutton",
+ "pack", "scrollbar", "selection")
+ t1, b1, cb = inittoplevel(ip, parent, "listbox")
+
+ ## listbox/scrollbar
+
+ f1 = TclTkWidget.new(ip, t1, frame)
+ # コールバック内で参照する変数は先に宣言しておかなければならない.
+ li1 = sc1 = sc2 = nil
+ # 実行時に, 後ろにパラメータがつくコールバックは,
+ # イテレータ変数でそのパラメータを受け取ることができる.
+ # (複数のパラメータはひとつの文字列にまとめられる.)
+ cb.push(c1 = TclTkCallback.new(ip, proc{|i| li1.e("xview", i)}))
+ cb.push(c2 = TclTkCallback.new(ip, proc{|i| li1.e("yview", i)}))
+ cb.push(c3 = TclTkCallback.new(ip, proc{|i| sc1.e("set", i)}))
+ cb.push(c4 = TclTkCallback.new(ip, proc{|i| sc2.e("set", i)}))
+ # listbox
+ li1 = TclTkWidget.new(ip, f1, listbox,
+ "-xscrollcommand", c3, "-yscrollcommand", c4,
+ "-selectmode extended -exportselection true")
+ for i in 1..20
+ li1.e("insert end {line #{i} line #{i} line #{i} line #{i} line #{i}}")
+ end
+ # scrollbar
+ sc1 = TclTkWidget.new(ip, f1, scrollbar, "-orient horizontal -command", c1)
+ sc2 = TclTkWidget.new(ip, f1, scrollbar, "-orient vertical -command", c2)
+
+ ## selection/clipboard
+
+ mb1 = TclTkWidget.new(ip, t1, menubutton, "-text edit")
+ me1 = TclTkWidget.new(ip, mb1, menu)
+ mb1.e("configure -menu", me1)
+ cb.push(c = TclTkCallback.new(ip, proc{
+ # clipboard をクリア.
+ clipboard.e("clear")
+ # selection から文字列を読み込み clipboard に追加する.
+ clipboard.e("append {#{selection.e(\"get\")}}")}))
+ me1.e("add command -label {selection -> clipboard} -command",c)
+ cb.push(c = TclTkCallback.new(ip, proc{
+ # li1 をクリア.
+ li1.e("delete 0 end")
+ # clipboard から文字列を取り出し, 1 行ずつ
+ selection.e("get -selection CLIPBOARD").split(/\n/).each{|line|
+ # li1 に挿入する.
+ li1.e("insert end {#{line}}")}}))
+ me1.e("add command -label {clipboard -> listbox} -command",c)
+
+ grid.e(li1, "-row 0 -column 0 -sticky news")
+ grid.e(sc1, "-row 1 -column 0 -sticky ew")
+ grid.e(sc2, "-row 0 -column 1 -sticky ns")
+ grid.e("rowconfigure", f1, "0 -weight 100")
+ grid.e("columnconfigure", f1, "0 -weight 100")
+ f2 = TclTkWidget.new(ip, t1, frame)
+ lower.e(f2, b1)
+ pack.e(b1, mb1, "-in", f2, "-side left")
+ pack.e(f2, f1)
+ end
+
+ # canvas のサンプル.
+ def test_canvas(ip, parent)
+ canvas, lower, pack = ip.commands().indexes("canvas", "lower", "pack")
+ t1, b1, cb = inittoplevel(ip, parent, "canvas")
+
+ ## canvas
+
+ ca1 = TclTkWidget.new(ip, t1, canvas, "-width 400 -height 300")
+ lower.e(ca1, b1)
+ # rectangle を作る.
+ idr = ca1.e("create rectangle 10 10 20 20")
+ # oval を作る.
+ ca1.e("create oval 60 10 100 50")
+ # polygon を作る.
+ ca1.e("create polygon 110 10 110 30 140 10")
+ # line を作る.
+ ca1.e("create line 150 10 150 30 190 10")
+ # arc を作る.
+ ca1.e("create arc 200 10 250 50 -start 0 -extent 90 -style pieslice")
+ # i1 は本当は, どこかで破壊しなければならないが, 面倒なので放ってある.
+ i1 = TclTkImage.new(ip, "photo", "-file maru.gif")
+ # image を作る.
+ ca1.e("create image 100 100 -image", i1)
+ # bitmap を作る.
+ ca1.e("create bitmap 260 50 -bitmap questhead")
+ # text を作る.
+ ca1.e("create text 320 50 -text {drag rectangle}")
+ # window を作る(クローズボタン).
+ ca1.e("create window 200 200 -window", b1)
+
+ # bind により rectangle を drag できるようにする.
+ cb.push(c = TclTkCallback.new(ip, proc{|i|
+ # i に x と y を受け取るので, 取り出す.
+ x, y = i.split(/ /); x = x.to_f; y = y.to_f
+ # 座標を変更する.
+ ca1.e("coords current #{x - 5} #{y - 5} #{x + 5} #{y + 5}")},
+ # x, y 座標を空白で区切ったものをイテレータ変数へ渡すように指定.
+ "%x %y"))
+ # rectangle に bind する.
+ ca1.e("bind", idr, "<B1-Motion>", c)
+
+ pack.e(ca1)
+ end
+end
+
+# test driver
+
+if ARGV.size == 0
+ print "#{$0} n で, n 個のインタプリタを起動します.\n"
+ n = 1
+else
+ n = ARGV[0].to_i
+end
+
+print "start\n"
+ip = []
+
+# インタプリタ, ウィジェット等の生成.
+for i in 1 .. n
+ ip.push(Test1.new())
+end
+
+# 用意ができたらイベントループに入る.
+TclTk.mainloop()
+print "exit from mainloop\n"
+
+# インタプリタが GC されるかのテスト.
+ip = []
+print "GC.start\n" if $DEBUG
+GC.start() if $DEBUG
+print "end\n"
+
+exit
+
+# end
diff --git a/ext/tcltklib/sample/sample2.rb b/ext/tcltklib/sample/sample2.rb
new file mode 100644
index 0000000..969d8de
--- /dev/null
+++ b/ext/tcltklib/sample/sample2.rb
@@ -0,0 +1,449 @@
+#!/usr/local/bin/ruby
+#----------------------> pretty simple othello game <-----------------------
+# othello.rb
+#
+# version 0.3
+# maeda shugo (shuto@po.aianet.ne.jp)
+#---------------------------------------------------------------------------
+
+# Sep. 17, 1997 modified by Y. Shigehiro for tcltk library
+# maeda shugo (shugo@po.aianet.ne.jp) 氏による
+# (ruby/tk で書かれていた) ruby のサンプルプログラム
+# http://www.aianet.or.jp/~shugo/ruby/othello.rb.gz
+# を tcltk ライブラリを使うように, 機械的に変更してみました.
+#
+# なるべくオリジナルと同じになるようにしてあります.
+
+require "observer"
+require "tcltk"
+$ip = TclTkInterpreter.new()
+$root = $ip.rootwidget()
+$button, $canvas, $checkbutton, $frame, $label, $pack, $update, $wm =
+ $ip.commands().indexes(
+ "button", "canvas", "checkbutton", "frame", "label", "pack", "update", "wm")
+
+class Othello
+
+ EMPTY = 0
+ BLACK = 1
+ WHITE = - BLACK
+
+ attr :in_com_turn
+ attr :game_over
+
+ class Board
+
+ include Observable
+
+ DIRECTIONS = [
+ [-1, -1], [-1, 0], [-1, 1],
+ [ 0, -1], [ 0, 1],
+ [ 1, -1], [ 1, 0], [ 1, 1]
+ ]
+
+ attr :com_disk, TRUE
+
+ def initialize(othello)
+ @othello = othello
+ reset
+ end
+
+ def notify_observers(*arg)
+ if @observer_peers != nil
+ super(*arg)
+ end
+ end
+
+ def reset
+ @data = [
+ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, WHITE, BLACK, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, BLACK, WHITE, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY],
+ [EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY, EMPTY]
+ ]
+ changed
+ notify_observers
+ end
+
+ def man_disk
+ return - @com_disk
+ end
+
+ def other_disk(disk)
+ return - disk
+ end
+
+ def get_disk(row, col)
+ return @data[row][col]
+ end
+
+ def reverse_to(row, col, my_disk, dir_y, dir_x)
+ y = row
+ x = col
+ begin
+ y += dir_y
+ x += dir_x
+ if y < 0 || x < 0 || y > 7 || x > 7 ||
+ @data[y][x] == EMPTY
+ return
+ end
+ end until @data[y][x] == my_disk
+ begin
+ @data[y][x] = my_disk
+ changed
+ notify_observers(y, x)
+ y -= dir_y
+ x -= dir_x
+ end until y == row && x == col
+ end
+
+ def put_disk(row, col, disk)
+ @data[row][col] = disk
+ changed
+ notify_observers(row, col)
+ DIRECTIONS.each do |dir|
+ reverse_to(row, col, disk, *dir)
+ end
+ end
+
+ def count_disk(disk)
+ num = 0
+ @data.each do |rows|
+ rows.each do |d|
+ if d == disk
+ num += 1
+ end
+ end
+ end
+ return num
+ end
+
+ def count_point_to(row, col, my_disk, dir_y, dir_x)
+ return 0 if @data[row][col] != EMPTY
+ count = 0
+ loop do
+ row += dir_y
+ col += dir_x
+ break if row < 0 || col < 0 || row > 7 || col > 7
+ case @data[row][col]
+ when my_disk
+ return count
+ when other_disk(my_disk)
+ count += 1
+ when EMPTY
+ break
+ end
+ end
+ return 0
+ end
+
+ def count_point(row, col, my_disk)
+ count = 0
+ DIRECTIONS.each do |dir|
+ count += count_point_to(row, col, my_disk, *dir)
+ end
+ return count
+ end
+
+ def corner?(row, col)
+ return (row == 0 && col == 0) ||
+ (row == 0 && col == 7) ||
+ (row == 7 && col == 0) ||
+ (row == 7 && col == 7)
+ end
+
+ def search(my_disk)
+ max = 0
+ max_row = nil
+ max_col = nil
+ for row in 0 .. 7
+ for col in 0 .. 7
+ buf = count_point(row, col, my_disk)
+ if (corner?(row, col) && buf > 0) || max < buf
+ max = buf
+ max_row = row
+ max_col = col
+ end
+ end
+ end
+ return max_row, max_col
+ end
+ end #--------------------------> class Board ends here
+
+ class BoardView < TclTkWidget
+
+ BACK_GROUND_COLOR = "DarkGreen"
+ HILIT_BG_COLOR = "green"
+ BORDER_COLOR = "black"
+ BLACK_COLOR = "black"
+ WHITE_COLOR = "white"
+ STOP_COLOR = "red"
+
+ attr :left
+ attr :top
+ attr :right
+ attr :bottom
+
+ class Square
+
+ attr :oval, TRUE
+ attr :row
+ attr :col
+
+ def initialize(view, row, col)
+ @view = view
+ @id = @view.e("create rectangle", *view.tk_rect(view.left + col,
+ view.top + row,
+ view.left + col + 1,
+ view.top + row + 1))
+ @row = row
+ @col = col
+ @view.e("itemconfigure", @id,
+ "-width 0.5m -outline #{BORDER_COLOR}")
+ @view.e("bind", @id, "<Any-Enter>", TclTkCallback.new($ip, proc{
+ if @oval == nil
+ view.e("itemconfigure", @id, "-fill #{HILIT_BG_COLOR}")
+ end
+ }))
+ @view.e("bind", @id, "<Any-Leave>", TclTkCallback.new($ip, proc{
+ view.e("itemconfigure", @id, "-fill #{BACK_GROUND_COLOR}")
+ }))
+ @view.e("bind", @id, "<ButtonRelease-1>", TclTkCallback.new($ip,
+ proc{
+ view.click_square(self)
+ }))
+ end
+
+ def blink(color)
+ @view.e("itemconfigure", @id, "-fill #{color}")
+ $update.e()
+ sleep(0.1)
+ @view.e("itemconfigure", @id, "-fill #{BACK_GROUND_COLOR}")
+ end
+ end #-----------------------> class Square ends here
+
+ def initialize(othello, board)
+ super($ip, $root, $canvas)
+ @othello = othello
+ @board = board
+ @board.add_observer(self)
+
+ @squares = Array.new(8)
+ for i in 0 .. 7
+ @squares[i] = Array.new(8)
+ end
+ @left = 1
+ @top = 0.5
+ @right = @left + 8
+ @bottom = @top + 8
+
+ i = self.e("create rectangle", *tk_rect(@left, @top, @right, @bottom))
+ self.e("itemconfigure", i,
+ "-width 1m -outline #{BORDER_COLOR} -fill #{BACK_GROUND_COLOR}")
+
+ for row in 0 .. 7
+ for col in 0 .. 7
+ @squares[row][col] = Square.new(self, row, col)
+ end
+ end
+
+ update
+ end
+
+ def tk_rect(left, top, right, bottom)
+ return left.to_s + "c", top.to_s + "c",
+ right.to_s + "c", bottom.to_s + "c"
+ end
+
+ def clear
+ each_square do |square|
+ if square.oval != nil
+ self.e("delete", square.oval)
+ square.oval = nil
+ end
+ end
+ end
+
+ def draw_disk(row, col, disk)
+ if disk == EMPTY
+ if @squares[row][col].oval != nil
+ self.e("delete", @squares[row][col].oval)
+ @squares[row][col].oval = nil
+ end
+ return
+ end
+
+ $update.e()
+ sleep(0.05)
+ oval = @squares[row][col].oval
+ if oval == nil
+ oval = self.e("create oval", *tk_rect(@left + col + 0.2,
+ @top + row + 0.2,
+ @left + col + 0.8,
+ @top + row + 0.8))
+ @squares[row][col].oval = oval
+ end
+ case disk
+ when BLACK
+ color = BLACK_COLOR
+ when WHITE
+ color = WHITE_COLOR
+ else
+ fail format("Unknown disk type: %d", disk)
+ end
+ self.e("itemconfigure", oval, "-outline #{color} -fill #{color}")
+ end
+
+ def update(row = nil, col = nil)
+ if row && col
+ draw_disk(row, col, @board.get_disk(row, col))
+ else
+ each_square do |square|
+ draw_disk(square.row, square.col,
+ @board.get_disk(square.row, square.col))
+ end
+ end
+ @othello.show_point
+ end
+
+ def each_square
+ @squares.each do |rows|
+ rows.each do |square|
+ yield(square)
+ end
+ end
+ end
+
+ def click_square(square)
+ if @othello.in_com_turn || @othello.game_over ||
+ @board.count_point(square.row,
+ square.col,
+ @board.man_disk) == 0
+ square.blink(STOP_COLOR)
+ return
+ end
+ @board.put_disk(square.row, square.col, @board.man_disk)
+ @othello.com_turn
+ end
+
+ private :draw_disk
+ public :update
+ end #----------------------> class BoardView ends here
+
+ def initialize
+ @msg_label = TclTkWidget.new($ip, $root, $label)
+ $pack.e(@msg_label)
+
+ @board = Board.new(self)
+ @board_view = BoardView.new(self, @board)
+ #### added by Y. Shigehiro
+ ## board_view の大きさを設定する.
+ x1, y1, x2, y2 = @board_view.e("bbox all").split(/ /).collect{|i| i.to_f}
+ @board_view.e("configure -width", x2 - x1)
+ @board_view.e("configure -height", y2 - y1)
+ ## scrollregion を設定する.
+ @board_view.e("configure -scrollregion {", @board_view.e("bbox all"),
+ "}")
+ #### ここまで
+ $pack.e(@board_view, "-fill both -expand true")
+
+ panel = TclTkWidget.new($ip, $root, $frame)
+
+ @play_black = TclTkWidget.new($ip, panel, $checkbutton,
+ "-text {com is black} -command", TclTkCallback.new($ip, proc{
+ switch_side
+ }))
+ $pack.e(@play_black, "-side left")
+
+ quit = TclTkWidget.new($ip, panel, $button, "-text Quit -command",
+ TclTkCallback.new($ip, proc{
+ exit
+ }))
+ $pack.e(quit, "-side right -fill x")
+
+ reset = TclTkWidget.new($ip, panel, $button, "-text Reset -command",
+ TclTkCallback.new($ip, proc{
+ reset_game
+ }))
+ $pack.e(reset, "-side right -fill x")
+
+ $pack.e(panel, "-side bottom -fill x")
+
+# root = Tk.root
+ $wm.e("title", $root, "Othello")
+ $wm.e("iconname", $root, "Othello")
+
+ @board.com_disk = WHITE
+ @game_over = FALSE
+
+ TclTk.mainloop
+ end
+
+ def switch_side
+ if @in_com_turn
+ @play_black.e("toggle")
+ else
+ @board.com_disk = @board.man_disk
+ com_turn unless @game_over
+ end
+ end
+
+ def reset_game
+ if @board.com_disk == BLACK
+ @board.com_disk = WHITE
+ @play_black.e("toggle")
+ end
+ @board_view.clear
+ @board.reset
+ $wm.e("title", $root, "Othello")
+ @game_over = FALSE
+ end
+
+ def com_turn
+ @in_com_turn = TRUE
+ $update.e()
+ sleep(0.5)
+ begin
+ com_disk = @board.count_disk(@board.com_disk)
+ man_disk = @board.count_disk(@board.man_disk)
+ if @board.count_disk(EMPTY) == 0
+ if man_disk == com_disk
+ $wm.e("title", $root, "{Othello - Draw!}")
+ elsif man_disk > com_disk
+ $wm.e("title", $root, "{Othello - You Win!}")
+ else
+ $wm.e("title", $root, "{Othello - You Loose!}")
+ end
+ @game_over = TRUE
+ break
+ elsif com_disk == 0
+ $wm.e("title", $root, "{Othello - You Win!}")
+ @game_over = TRUE
+ break
+ elsif man_disk == 0
+ $wm.e("title", $root, "{Othello - You Loose!}")
+ @game_over = TRUE
+ break
+ end
+ row, col = @board.search(@board.com_disk)
+ break if row == nil || col == nil
+ @board.put_disk(row, col, @board.com_disk)
+ end while @board.search(@board.man_disk) == [nil, nil]
+ @in_com_turn = FALSE
+ end
+
+ def show_point
+ black = @board.count_disk(BLACK)
+ white = @board.count_disk(WHITE)
+ @msg_label.e("configure -text",
+ %Q/{#{format("BLACK: %.2d WHITE: %.2d", black, white)}}/)
+ end
+end #----------------------> class Othello ends here
+
+Othello.new
+
+#----------------------------------------------> othello.rb ends here
diff --git a/ext/tcltklib/tcltklib.c b/ext/tcltklib/tcltklib.c
new file mode 100644
index 0000000..e7fe77d
--- /dev/null
+++ b/ext/tcltklib/tcltklib.c
@@ -0,0 +1,216 @@
+/*
+ * tcltklib.c
+ * Aug. 27, 1997 Y. Shigehiro
+ * Oct. 24, 1997 Y. Matsumoto
+ */
+
+#include "ruby.h"
+#include "sig.h"
+#include <stdio.h>
+#include <string.h>
+#include <tcl.h>
+#include <tk.h>
+
+/* for debug */
+
+#define DUMP1(ARG1) if (debug) { fprintf(stderr, "tcltklib: %s\n", ARG1);}
+#define DUMP2(ARG1, ARG2) if (debug) { fprintf(stderr, "tcltklib: ");\
+fprintf(stderr, ARG1, ARG2); fprintf(stderr, "\n"); }
+/*
+#define DUMP1(ARG1)
+#define DUMP2(ARG1, ARG2)
+*/
+
+/* from tkAppInit.c */
+
+/*
+ * The following variable is a special hack that is needed in order for
+ * Sun shared libraries to be used for Tcl.
+ */
+
+extern int matherr();
+int *tclDummyMathPtr = (int *) matherr;
+
+/*---- module TclTkLib ----*/
+
+static VALUE thread_safe = Qnil;
+
+/* execute Tk_MainLoop */
+static VALUE
+lib_mainloop(VALUE self)
+{
+ int old_trapflg;
+ int flags = RTEST(thread_safe)?TCL_DONT_WAIT:0;
+
+ DUMP1("start Tk_Mainloop");
+ while (Tk_GetNumMainWindows() > 0) {
+ old_trapflg = trap_immediate;
+ trap_immediate = 1;
+ Tcl_DoOneEvent(flags);
+ trap_immediate = old_trapflg;
+ CHECK_INTS;
+ flags = (thread_safe == 0 || thread_safe == Qnil)?0:TCL_DONT_WAIT;
+ }
+ DUMP1("stop Tk_Mainloop");
+
+ return Qnil;
+}
+
+/*---- class TclTkIp ----*/
+struct tcltkip {
+ Tcl_Interp *ip; /* the interpreter */
+ int return_value; /* return value */
+};
+
+/* Tcl command `ruby' */
+static VALUE
+ip_eval_rescue(VALUE *failed, VALUE einfo)
+{
+ *failed = einfo;
+ return Qnil;
+}
+
+static int
+ip_ruby(ClientData clientData, Tcl_Interp *interp, int argc, char *argv[])
+{
+ VALUE res;
+ int old_trapflg;
+ VALUE failed = 0;
+
+ /* ruby command has 1 arg. */
+ if (argc != 2) {
+ ArgError("wrong # of arguments (%d for 1)", argc);
+ }
+
+ /* evaluate the argument string by ruby */
+ DUMP2("rb_eval_string(%s)", argv[1]);
+ old_trapflg = trap_immediate;
+ trap_immediate = 0;
+ res = rb_rescue(rb_eval_string, argv[1], ip_eval_rescue, &failed);
+ trap_immediate = old_trapflg;
+
+ if (failed) {
+ Tcl_AppendResult(interp, RSTRING(failed)->ptr, (char*)NULL);
+ return TCL_ERROR;
+ }
+
+ /* result must be string or nil */
+ if (NIL_P(res)) {
+ DUMP1("(rb_eval_string result) nil");
+ return TCL_OK;
+ }
+ Check_Type(res, T_STRING);
+
+ /* copy result to the tcl interpreter */
+ DUMP2("(rb_eval_string result) %s", RSTRING(res)->ptr);
+ DUMP1("Tcl_AppendResult");
+ Tcl_AppendResult(interp, RSTRING(res)->ptr, (char *)NULL);
+
+ return TCL_OK;
+}
+
+/* destroy interpreter */
+static void
+ip_free(struct tcltkip *ptr)
+{
+ DUMP1("Tcl_DeleteInterp");
+ Tcl_DeleteInterp(ptr->ip);
+}
+
+/* create and initialize interpreter */
+static VALUE
+ip_new(VALUE self)
+{
+ struct tcltkip *ptr; /* tcltkip data struct */
+ VALUE obj; /* newly created object */
+
+ /* create object */
+ obj = Data_Make_Struct(self, struct tcltkip, 0, ip_free, ptr);
+ ptr->return_value = 0;
+
+ /* from Tk_Main() */
+ DUMP1("Tcl_CreateInterp");
+ ptr->ip = Tcl_CreateInterp();
+
+ /* from Tcl_AppInit() */
+ DUMP1("Tcl_Init");
+ if (Tcl_Init(ptr->ip) == TCL_ERROR) {
+ Fail("Tcl_Init");
+ }
+ DUMP1("Tk_Init");
+ if (Tk_Init(ptr->ip) == TCL_ERROR) {
+ Fail("Tk_Init");
+ }
+ DUMP1("Tcl_StaticPackage(\"Tk\")");
+ Tcl_StaticPackage(ptr->ip, "Tk", Tk_Init,
+ (Tcl_PackageInitProc *) NULL);
+
+ /* add ruby command to the interpreter */
+ DUMP1("Tcl_CreateCommand(\"ruby\")");
+ Tcl_CreateCommand(ptr->ip, "ruby", ip_ruby, (ClientData *)NULL,
+ (Tcl_CmdDeleteProc *)NULL);
+
+ return obj;
+}
+
+/* eval string in tcl by Tcl_Eval() */
+static VALUE
+ip_eval(VALUE self, VALUE str)
+{
+ char *buf; /* Tcl_Eval requires re-writable string region */
+ struct tcltkip *ptr; /* tcltkip data struct */
+
+ /* get the data struct */
+ Data_Get_Struct(self, struct tcltkip, ptr);
+
+ /* call Tcl_Eval() */
+ Check_Type(str, T_STRING);
+ buf = ALLOCA_N(char,RSTRING(str)->len+1);
+ strcpy(buf, RSTRING(str)->ptr);
+ DUMP2("Tcl_Eval(%s)", buf);
+ ptr->return_value = Tcl_Eval(ptr->ip, buf);
+ if (ptr->return_value == TCL_ERROR) {
+ Fail(ptr->ip->result);
+ }
+ DUMP2("(TCL_Eval result) %d", ptr->return_value);
+
+ /* pass back the result (as string) */
+ return(str_new2(ptr->ip->result));
+}
+
+/* get return code from Tcl_Eval() */
+static VALUE
+ip_retval(VALUE self)
+{
+ struct tcltkip *ptr; /* tcltkip data struct */
+
+ /* get the data strcut */
+ Data_Get_Struct(self, struct tcltkip, ptr);
+
+ return (INT2FIX(ptr->return_value));
+}
+
+/*---- initialization ----*/
+void Init_tcltklib()
+{
+ extern VALUE rb_argv0; /* the argv[0] */
+
+ VALUE lib = rb_define_module("TclTkLib");
+ VALUE ip = rb_define_class("TclTkIp", cObject);
+
+ rb_define_module_function(lib, "mainloop", lib_mainloop, 0);
+
+ rb_define_singleton_method(ip, "new", ip_new, 0);
+ rb_define_method(ip, "_eval", ip_eval, 1);
+ rb_define_method(ip, "_return_value", ip_retval, 0);
+ rb_define_method(ip, "mainloop", lib_mainloop, 0);
+
+ /*---- initialize tcl/tk libraries ----*/
+ /* from Tk_Main() */
+ DUMP1("Tcl_FindExecutable");
+ Tcl_FindExecutable(RSTRING(rb_argv0)->ptr);
+
+ rb_define_variable("$tk_thread_safe", &thread_safe);
+}
+
+/* eof */