From: "D.Kanda" Date: 1998-08-17T18:33:43+09:00 Subject: [ruby-list:9168] Re: gtk ----Next_Part(Mon_Aug_17_18:31:43_1998_809)-- Content-Type: Text/Plain; charset=iso-2022-jp Content-Transfer-Encoding: 7bit かんだです。 > > あっという間にバージョンが上がってしまいましたが(^^;、0.09 用にいくつか > 追加したのでパッチ流しときます。 > ただ、これが原因かどうか分からないのですが、gtk とスレッドを使うと GC 周 > りで落ちてしまってます。バグ追跡にハマっているので、パッチに怪しそうなとこ > ろがあったらご指摘下さい。 追加に失敗してしまいました。改めて。 ----Next_Part(Mon_Aug_17_18:31:43_1998_809)-- Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit *** gtk.c-0.09 Mon Aug 17 09:50:23 1998 --- gtk.c Mon Aug 17 17:34:40 1998 *************** *** 99,105 **** static VALUE gStyle; static VALUE gPreviewInfo; static VALUE gAllocation; ! static VALUE gRequisiton; static VALUE mRC; --- 99,105 ---- static VALUE gStyle; static VALUE gPreviewInfo; static VALUE gAllocation; ! static VALUE gRequisition; static VALUE mRC; *************** *** 380,385 **** --- 380,435 ---- } static VALUE + gdkfnt_load_font(self, name) + VALUE self, name; + { + GdkFont *font; + + font = gdk_font_load(STR2CSTR(name)); + return Data_Wrap_Struct(gdkFont, 0, gdk_font_unref, font); + /* return make_gdkfont(new); */ + } + static VALUE + gdkfnt_load_fontset(self, name) + VALUE self, name; + { + GdkFont *new; + + new = gdk_fontset_load(STR2CSTR(name)); + return make_gdkfont(new); + } + static VALUE + gdkfnt_new(self, name) + VALUE self, name; + { + char *cname = STR2CSTR(name); + return (strchr(cname, ',') == NULL) + ? gdkfnt_load_font(self, name) + : gdkfnt_load_fontset(self, name); + } + static VALUE + gdkfnt_string_width(self, str) + VALUE self, str; + { + int w; + + w = gdk_string_width(get_gdkfont(self), STR2CSTR(str)); + return INT2NUM(w); + } + static VALUE + gdkfnt_ascent(self) + VALUE self; + { + return INT2NUM(get_gdkfont(self)->ascent); + } + static VALUE + gdkfnt_descent(self) + VALUE self; + { + return INT2NUM(get_gdkfont(self)->descent); + } + + static VALUE gdkfnt_equal(fn1, fn2) VALUE fn1, fn2; { *************** *** 435,442 **** #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)) --- 485,492 ---- #define make_gallocation(c) make_tobj(c, gAllocation, sizeof(GtkAllocation)) #define get_gallocation(c) ((GtkAllocation*)get_tobj(c, gAllocation)) ! #define make_grequisition(c) make_tobj(c, gRequisition, sizeof(GtkRequisition)) ! #define get_grequisition(c) ((GtkRequisition*)get_tobj(c, gRequisition)) #define make_gdkrectangle(r) make_tobj(r, gdkRectangle, sizeof(GdkRectangle)) #define get_gdkrectangle(r) ((GdkRectangle*)get_tobj(r, gdkRectangle)) *************** *** 775,780 **** --- 825,873 ---- return INT2NUM(GDK_ROOT_WINDOW() ); } + static VALUE + gdkwin_clear(self) + VALUE self; + { + gdk_window_clear(get_gdkwindow(self)); + return self; + } + static VALUE + gdkwin_clear_area(self, x,y,w,h) + VALUE self,x,y,w,h; + { + gdk_window_clear_area(get_gdkwindow(self), + NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h)); + return self; + } + static VALUE + gdkwin_clear_area_e(self, x,y,w,h) + VALUE self,x,y,w,h; + { + gdk_window_clear_area_e(get_gdkwindow(self), + NUM2INT(x), NUM2INT(y), NUM2INT(w), NUM2INT(h)); + return self; + } + + static VALUE + gdkwin_set_background(self, c) + VALUE self, c; + { + GdkColor color; + color.pixel = NUM2INT(c); + gdk_window_set_background(get_gdkwindow(self), &color); + return self; + } + + static VALUE + gdkwin_set_back_pixmap(self, pixmap, parent_relative) + VALUE self, pixmap, parent_relative; + { + gdk_window_set_back_pixmap(get_gdkwindow(self), get_gdkpixmap(pixmap), + NUM2INT(parent_relative)); + return self; + } + static VALUE make_gdkevent(event) *************** *** 867,872 **** --- 960,1027 ---- } static VALUE + gdkgc_set_function(self, func) + VALUE func; + { + GdkFunction f; + f = (GdkFunction) NUM2INT(func); + if (f != GDK_COPY && f != GDK_INVERT && f != GDK_XOR) + ArgError("function out of range"); + + gdk_gc_set_function(get_gdkgc(self), f); + return func; + } + + static VALUE + gdkgc_set_foreground(self, pix) + VALUE pix; + { + GdkColor c; + c.pixel = NUM2INT(pix); + gdk_gc_set_foreground(get_gdkgc(self), &c); + return pix; + } + static VALUE + gdkgc_set_background(self, pix) + VALUE pix; + { + GdkColor c; + c.pixel = NUM2INT(pix); + gdk_gc_set_background(get_gdkgc(self), &c); + return pix; + } + static VALUE + gdkgc_set_clip_mask(self, mask) + VALUE mask; + { + gdk_gc_set_clip_mask(get_gdkgc(self), get_gdkbitmap(mask)); + return mask; + } + static VALUE + gdkgc_set_clip_origin(self, x, y) + VALUE x, y; + { + gdk_gc_set_clip_origin(get_gdkgc(self), NUM2INT(x), NUM2INT(y)); + return self; + } + static VALUE + gdkgc_set_clip_rectangle(self, rectangle) + VALUE rectangle; + { + gdk_gc_set_clip_rectangle(get_gdkgc(self), get_gdkrectangle(rectangle)); + return rectangle; + } + /* + static VALUE + gdkgc_set_clip_region(self, region) + VALUE region; + { + gdk_gc_set_clip_region(get_gdkgc(self), get_gdkregion(region)); + return region; + } + */ + + static VALUE glist2ary(list) GList *list; { *************** *** 1046,1052 **** return; } if (strcmp(signame, "size_request") == 0) { ! ary_push(args, make_grequisiton(GTK_VALUE_POINTER(params[0]))); return; } if (strcmp(signame, "size_allocate") == 0) { --- 1201,1207 ---- return; } if (strcmp(signame, "size_request") == 0) { ! ary_push(args, make_grequisition(GTK_VALUE_POINTER(params[0]))); return; } if (strcmp(signame, "size_allocate") == 0) { *************** *** 1536,1541 **** --- 1691,1721 ---- } static VALUE + misc_get_xalign(self) + VALUE self; + { + return float_new(GTK_MISC(get_widget(self))->xalign); + } + static VALUE + misc_get_yalign(self) + VALUE self; + { + return float_new(GTK_MISC(get_widget(self))->yalign); + } + static VALUE + misc_get_xpad(self) + VALUE self; + { + return INT2NUM(GTK_MISC(get_widget(self))->xpad); + } + static VALUE + misc_get_ypad(self) + VALUE self; + { + return INT2NUM(GTK_MISC(get_widget(self))->ypad); + } + + static VALUE arrow_initialize(self, arrow_t, shadow_t) VALUE self, arrow_t, shadow_t; { *************** *** 1741,1747 **** widget_size_request(self, req) VALUE self, req; { ! gtk_widget_size_request(get_widget(self), get_grequisiton(req)); return self; } --- 1921,1927 ---- widget_size_request(self, req) VALUE self, req; { ! gtk_widget_size_request(get_widget(self), get_grequisition(req)); return self; } *************** *** 1815,1820 **** --- 1995,2008 ---- return TRUE; return FALSE; } + static VALUE + widget_mapped(self) + VALUE self; + { + if (GTK_WIDGET_MAPPED(get_widget(self))) + return TRUE; + return FALSE; + } static VALUE widget_reparent(self, parent) *************** *** 2168,2173 **** --- 2356,2378 ---- } static VALUE + widget_get_requisition(self) + VALUE self; + { + return make_grequisition(&(get_widget(self)->requisition)); + } + + static VALUE + widget_set_requisition(self, w,h) + VALUE self,w,h; + { + GtkRequisition *r = &(get_widget(self)->requisition); + r->width = NUM2INT(w); + r->height = NUM2INT(h); + return self; + } + + static VALUE widget_state(self) VALUE self; { *************** *** 2817,2822 **** --- 3022,3042 ---- set_widget(self, gtk_label_new(STR2CSTR(label))); return Qnil; } + static VALUE + label_get_jtype(self) + VALUE self; + { + return(INT2FIX(GTK_LABEL(get_widget(self))->jtype)); + } + static VALUE + label_set_jtype(self, jtype) + VALUE self, jtype; + { + GtkJustification j; + j = (GtkJustification) NUM2INT(jtype); + gtk_label_set_justify(GTK_LABEL(get_widget(self)), j); + return self; + } static VALUE list_initialize(self) *************** *** 5422,5427 **** --- 5642,5654 ---- } static VALUE + style_copy(self) + VALUE self; + { + return make_gstyle(gtk_style_copy(get_gstyle(self))); + } + + static VALUE style_attach(self, win) VALUE self, win; { *************** *** 5436,5442 **** } static VALUE ! style_set_bg(self, win, state_type) VALUE self, win, state_type; { gtk_style_set_background(get_gstyle(self), get_gdkwindow(win), --- 5663,5669 ---- } static VALUE ! style_set_background(self, win, state_type) VALUE self, win, state_type; { gtk_style_set_background(get_gstyle(self), get_gdkwindow(win), *************** *** 5514,5519 **** --- 5741,5773 ---- return make_gdkcolor(get_gstyle(self)->base[i]); } + #define DEFINE_STYLE_SET_COLOR(FUNC, TYPE) \ + static VALUE \ + FUNC(self, idx, r, g, b) \ + VALUE self, idx, r, g, b; \ + { \ + GtkStyle *style; \ + GdkColor *color; \ + int i = NUM2INT(idx); \ + \ + if (i < 0 || 5 < i) ArgError("state out of range"); \ + style = get_gstyle(self); \ + if (style->fg_gc[0] != NULL) ArgError("you must not change widget style."); \ + color = &(style-> TYPE [i]); \ + color->red = NUM2INT(r); \ + color->green = NUM2INT(g); \ + color->blue = NUM2INT(b); \ + return(make_gdkcolor(*color)); \ + } \ + + DEFINE_STYLE_SET_COLOR(style_set_fg, fg) + DEFINE_STYLE_SET_COLOR(style_set_bg, bg) + DEFINE_STYLE_SET_COLOR(style_set_light, light) + DEFINE_STYLE_SET_COLOR(style_set_dark, dark) + DEFINE_STYLE_SET_COLOR(style_set_mid, mid) + DEFINE_STYLE_SET_COLOR(style_set_text, text) + DEFINE_STYLE_SET_COLOR(style_set_base, base) + static VALUE style_black(self) { *************** *** 5533,5538 **** --- 5787,5809 ---- } static VALUE + style_set_font(self, f) + VALUE f; + { + GdkFont *font = get_gdkfont(f); + GtkStyle *style = get_gstyle(self); + + if (style->fg_gc[0] != NULL) ArgError("you must not change widget style."); + if (style->font != NULL) + gdk_font_unref(style->font); + + gdk_font_ref(font); + style->font = font; + + return self; + } + + static VALUE style_fg_gc(self, idx) VALUE self, idx; { *************** *** 5735,5740 **** --- 6006,6037 ---- return INT2NUM(get_gallocation(self)->height); } + static VALUE + grequisition_w(self) + { + return INT2NUM(get_grequisition(self)->width); + } + static VALUE + grequisition_h(self) + { + return INT2NUM(get_grequisition(self)->height); + } + /* + static VALUE + grequisition_set_w(self, w) + VALUE self, w; + { + get_grequisition(self)->width = NUM2INT(w); + return self; + } + static VALUE + grequisition_set_h(self, h) + VALUE self, h; + { + get_grequisition(self)->height = NUM2INT(h); + return self; + } + */ static VALUE gtk_m_main(self) *************** *** 6269,6275 **** gAcceleratorTable = rb_define_class_under(mGtk, "AcceleratorTable", cData); gStyle = rb_define_class_under(mGtk, "Style", cData); gPreviewInfo = rb_define_class_under(mGtk, "PreviewInfo", cData); ! gRequisiton = rb_define_class_under(mGtk, "Requisiton", cData); gAllocation = rb_define_class_under(mGtk, "Allocation", cData); mRC = rb_define_module_under(mGtk, "RC"); --- 6566,6572 ---- gAcceleratorTable = rb_define_class_under(mGtk, "AcceleratorTable", cData); gStyle = rb_define_class_under(mGtk, "Style", cData); gPreviewInfo = rb_define_class_under(mGtk, "PreviewInfo", cData); ! gRequisition = rb_define_class_under(mGtk, "Requisition", cData); gAllocation = rb_define_class_under(mGtk, "Allocation", cData); mRC = rb_define_module_under(mGtk, "RC"); *************** *** 6353,6358 **** --- 6650,6656 ---- rb_define_method(gWidget, "grab_default", widget_grab_default, 0); rb_define_method(gWidget, "set_state", widget_set_state, 1); rb_define_method(gWidget, "visible?", widget_visible, 0); + rb_define_method(gWidget, "mapped?", widget_mapped, 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); *************** *** 6368,6373 **** --- 6666,6673 ---- rb_define_method(gWidget, "set_extension_events", widget_set_eevents, 1); rb_define_method(gWidget, "unparent", widget_unparent, 0); rb_define_method(gWidget, "allocation", widget_get_alloc, 0); + rb_define_method(gWidget, "requisition", widget_get_requisition, 0); + rb_define_method(gWidget, "set_requisition", widget_set_requisition, 2); rb_define_method(gWidget, "state", widget_state, 0); rb_define_method(gWidget, "get_toplevel", widget_get_toplevel, 0); rb_define_method(gWidget, "get_ancestor", widget_get_ancestor, 1); *************** *** 6438,6443 **** --- 6738,6747 ---- /* Misc */ rb_define_method(gMisc, "set_alignment", misc_set_align, 2); rb_define_method(gMisc, "set_padding", misc_set_padding, 2); + rb_define_method(gMisc, "xalign", misc_get_xalign, 0); + rb_define_method(gMisc, "yalign", misc_get_yalign, 0); + rb_define_method(gMisc, "xpad", misc_get_xpad, 0); + rb_define_method(gMisc, "ypad", misc_get_ypad, 0); /* Arrow */ rb_define_method(gArrow, "initialize", arrow_initialize, 2); *************** *** 6738,6743 **** --- 7042,7049 ---- /* Label */ rb_define_method(gLabel, "initialize", label_initialize, 1); + rb_define_method(gLabel, "jtype", label_get_jtype, 0); + rb_define_method(gLabel, "jtype=", label_set_jtype, 1); /* List */ rb_define_method(gList, "initialize", list_initialize, 0); *************** *** 6931,6939 **** /* AcceleratorTable */ /* Style */ rb_define_singleton_method(gStyle, "new", style_s_new, 0); rb_define_method(gStyle, "attach", style_attach, 1); rb_define_method(gStyle, "detach", style_detach, 0); ! rb_define_method(gStyle, "set_background", style_set_bg, 0); rb_define_method(gStyle, "fg", style_fg, 1); rb_define_method(gStyle, "bg", style_bg, 1); rb_define_method(gStyle, "light", style_light, 1); --- 7237,7248 ---- /* AcceleratorTable */ /* Style */ rb_define_singleton_method(gStyle, "new", style_s_new, 0); + rb_define_method(gStyle, "copy", style_copy, 0); + rb_define_method(gStyle, "clone", style_copy, 0); + rb_define_method(gStyle, "dup", style_copy, 0); rb_define_method(gStyle, "attach", style_attach, 1); rb_define_method(gStyle, "detach", style_detach, 0); ! rb_define_method(gStyle, "set_background", style_set_background, 1); rb_define_method(gStyle, "fg", style_fg, 1); rb_define_method(gStyle, "bg", style_bg, 1); rb_define_method(gStyle, "light", style_light, 1); *************** *** 6941,6949 **** --- 7250,7267 ---- rb_define_method(gStyle, "mid", style_mid, 1); rb_define_method(gStyle, "text", style_text, 1); rb_define_method(gStyle, "base", style_base, 1); + rb_define_method(gStyle, "set_fg", style_set_fg, 4); + rb_define_method(gStyle, "set_bg", style_set_bg, 4); + rb_define_method(gStyle, "set_light", style_set_light, 4); + rb_define_method(gStyle, "set_dark", style_set_dark, 4); + rb_define_method(gStyle, "set_mid", style_set_mid, 4); + rb_define_method(gStyle, "set_text", style_set_text, 4); + rb_define_method(gStyle, "set_base", style_set_base, 4); + rb_define_method(gStyle, "black", style_black, 0); rb_define_method(gStyle, "white", style_white, 0); rb_define_method(gStyle, "font", style_font, 0); + rb_define_method(gStyle, "set_font", style_set_font, 1); rb_define_method(gStyle, "fg_gc", style_fg_gc, 1); rb_define_method(gStyle, "bg_gc", style_bg_gc, 1); rb_define_method(gStyle, "light_gc", style_light_gc, 1); *************** *** 6970,6975 **** --- 7288,7300 ---- rb_define_method(gAllocation, "width", gallocation_w, 0); rb_define_method(gAllocation, "height", gallocation_h, 0); + rb_define_method(gRequisition, "width", grequisition_w, 0); + rb_define_method(gRequisition, "height", grequisition_h, 0); + /* + rb_define_method(gRequisition, "width=", grequisition_set_w, 1); + rb_define_method(gRequisition, "height=", grequisition_set_h, 1); + */ + /* Gtk module */ rb_define_module_function(mGtk, "main", gtk_m_main, 0); rb_define_module_function(mGtk, "timeout_add", timeout_add, 1); *************** *** 6995,7000 **** --- 7320,7331 ---- /* Gdk module */ /* GdkFont */ + rb_define_singleton_method(gdkFont, "load_font", gdkfnt_load_font, 1); + rb_define_singleton_method(gdkFont, "new", gdkfnt_new, 1); + rb_define_singleton_method(gdkFont, "load_fontset", gdkfnt_load_fontset, 1); + rb_define_method(gdkFont, "string_width", gdkfnt_string_width, 1); + rb_define_method(gdkFont, "ascent", gdkfnt_ascent, 0); + rb_define_method(gdkFont, "descent", gdkfnt_descent, 0); rb_define_method(gdkFont, "==", gdkfnt_equal, 1); /* GdkDrawable */ *************** *** 7032,7042 **** --- 7363,7385 ---- rb_define_method(gdkWindow, "pointer_ungrab", gdkwin_pointer_ungrab, 1); rb_define_singleton_method(gdkWindow, "foreign_new", gdkwin_foreign_new, 1); rb_define_singleton_method(gdkWindow, "root_window", gdkwin_root_window, 0); + rb_define_method(gdkWindow, "clear", gdkwin_clear, 0); + rb_define_method(gdkWindow, "clear_area", gdkwin_clear_area, 4); + rb_define_method(gdkWindow, "clear_area_e", gdkwin_clear, 4); + rb_define_method(gdkWindow, "set_background", gdkwin_set_background, 1); + rb_define_method(gdkWindow, "set_back_pixmap", gdkwin_set_back_pixmap, 2); /* GdkGC */ rb_define_singleton_method(gdkGC, "new", gdkgc_s_new, 1); rb_define_method(gdkGC, "copy", gdkgc_copy, 1); rb_define_method(gdkGC, "destroy", gdkgc_destroy, 0); + rb_define_method(gdkGC, "set_function", gdkgc_set_function, 1); + rb_define_method(gdkGC, "set_foreground", gdkgc_set_foreground, 1); + rb_define_method(gdkGC, "set_background", gdkgc_set_background, 1); + rb_define_method(gdkGC, "set_clip_mask", gdkgc_set_clip_mask, 1); + rb_define_method(gdkGC, "set_clip_origin", gdkgc_set_clip_origin, 2); + rb_define_method(gdkGC, "set_clip_rectangle", gdkgc_set_clip_rectangle, 1); + /* rb_define_method(gdkGC, "set_clip_region", gdkgc_set_clip_region, 1); */ /* GdkImage */ rb_define_singleton_method(gdkImage, "new_bitmap", gdkimage_s_newbmap, 4); *************** *** 7105,7110 **** --- 7448,7459 ---- rb_define_const(mGtk, "POLICY_ALWAYS", INT2FIX(GTK_POLICY_ALWAYS)); rb_define_const(mGtk, "POLICY_AUTOMATIC", INT2FIX(GTK_POLICY_AUTOMATIC)); + /* GtkJustification */ + rb_define_const(mGtk, "JUSTIFY_LEFT", INT2FIX(GTK_JUSTIFY_LEFT)); + rb_define_const(mGtk, "JUSTIFY_RIGHT", INT2FIX(GTK_JUSTIFY_RIGHT)); + rb_define_const(mGtk, "JUSTIFY_CENTER", INT2FIX(GTK_JUSTIFY_CENTER)); + rb_define_const(mGtk, "JUSTIFY_FILL", INT2FIX(GTK_JUSTIFY_FILL)); + /* GtkSelectionMode */ rb_define_const(mGtk, "SELECTION_SINGLE", INT2FIX(GTK_SELECTION_SINGLE)); rb_define_const(mGtk, "SELECTION_BROWSE", INT2FIX(GTK_SELECTION_BROWSE)); *************** *** 7167,7172 **** --- 7516,7526 ---- /* GtkOrientation */ rb_define_const(mGtk, "ORIENTATION_HORIZONTAL", INT2FIX(GTK_ORIENTATION_HORIZONTAL)); rb_define_const(mGtk, "ORIENTATION_VERTICAL", INT2FIX(GTK_ORIENTATION_VERTICAL)); + + /* GdkMiscMode */ + rb_define_const(mGdk, "FUNCTION_COPY", INT2FIX(GDK_COPY)); + rb_define_const(mGdk, "FUNCTION_INVERT", INT2FIX(GDK_INVERT)); + rb_define_const(mGdk, "FUNCTION_XOR", INT2FIX(GDK_XOR)); /* GdkExtensionMode */ rb_define_const(mGdk, "EXTENSION_EVENTS_NONE", INT2FIX(GDK_EXTENSION_EVENTS_NONE)); ----Next_Part(Mon_Aug_17_18:31:43_1998_809)----