gtk2 0.20.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (281) hide show
  1. data/ChangeLog +6664 -0
  2. data/README +33 -0
  3. data/Rakefile +71 -0
  4. data/extconf.rb +116 -0
  5. data/src/global.h +33 -0
  6. data/src/init.c +39 -0
  7. data/src/lib/gtk2.rb +13 -0
  8. data/src/lib/gtk2/base.rb +95 -0
  9. data/src/makeinits.rb +57 -0
  10. data/src/makekeysyms.rb +5 -0
  11. data/src/rbgdk.c +395 -0
  12. data/src/rbgdk.h +50 -0
  13. data/src/rbgdkatom.c +122 -0
  14. data/src/rbgdkcairo.c +100 -0
  15. data/src/rbgdkcolor.c +151 -0
  16. data/src/rbgdkcolormap.c +142 -0
  17. data/src/rbgdkconst.c +29 -0
  18. data/src/rbgdkconversions.h +18 -0
  19. data/src/rbgdkcursor.c +115 -0
  20. data/src/rbgdkdevice.c +235 -0
  21. data/src/rbgdkdisplay.c +634 -0
  22. data/src/rbgdkdisplaymanager.c +50 -0
  23. data/src/rbgdkdragcontext.c +280 -0
  24. data/src/rbgdkdraw.c +487 -0
  25. data/src/rbgdkevent.c +1020 -0
  26. data/src/rbgdkgc.c +456 -0
  27. data/src/rbgdkgeometry.c +272 -0
  28. data/src/rbgdkimage.c +155 -0
  29. data/src/rbgdkinput.c +70 -0
  30. data/src/rbgdkkeymap.c +153 -0
  31. data/src/rbgdkkeysyms.h +2174 -0
  32. data/src/rbgdkkeyval.c +105 -0
  33. data/src/rbgdkpango.c +171 -0
  34. data/src/rbgdkpangorenderer.c +132 -0
  35. data/src/rbgdkpixbuf.c +178 -0
  36. data/src/rbgdkpixmap.c +255 -0
  37. data/src/rbgdkproperty.c +342 -0
  38. data/src/rbgdkrectangle.c +146 -0
  39. data/src/rbgdkregion.c +242 -0
  40. data/src/rbgdkrgb.c +197 -0
  41. data/src/rbgdkscreen.c +535 -0
  42. data/src/rbgdkselection.c +161 -0
  43. data/src/rbgdkthreads.c +68 -0
  44. data/src/rbgdktimecoord.c +118 -0
  45. data/src/rbgdkvisual.c +273 -0
  46. data/src/rbgdkwindow.c +1302 -0
  47. data/src/rbgdkwindowattr.c +213 -0
  48. data/src/rbgdkx11.c +256 -0
  49. data/src/rbgtk.c +93 -0
  50. data/src/rbgtk.h +121 -0
  51. data/src/rbgtkaboutdialog.c +195 -0
  52. data/src/rbgtkaccelerator.c +78 -0
  53. data/src/rbgtkaccelgroup.c +216 -0
  54. data/src/rbgtkaccelgroupentry.c +85 -0
  55. data/src/rbgtkaccelkey.c +116 -0
  56. data/src/rbgtkaccellabel.c +46 -0
  57. data/src/rbgtkaccelmap.c +162 -0
  58. data/src/rbgtkaccessible.c +29 -0
  59. data/src/rbgtkaction.c +277 -0
  60. data/src/rbgtkactiongroup.c +377 -0
  61. data/src/rbgtkadjustment.c +153 -0
  62. data/src/rbgtkalignment.c +71 -0
  63. data/src/rbgtkallocation.c +171 -0
  64. data/src/rbgtkarrow.c +47 -0
  65. data/src/rbgtkaspectframe.c +46 -0
  66. data/src/rbgtkassistant.c +230 -0
  67. data/src/rbgtkbbox.c +47 -0
  68. data/src/rbgtkbin.c +31 -0
  69. data/src/rbgtkbindingset.c +192 -0
  70. data/src/rbgtkborder.c +80 -0
  71. data/src/rbgtkbox.c +142 -0
  72. data/src/rbgtkbuildable.c +115 -0
  73. data/src/rbgtkbuilder.c +154 -0
  74. data/src/rbgtkbutton.c +151 -0
  75. data/src/rbgtkcalendar.c +159 -0
  76. data/src/rbgtkcelleditable.c +49 -0
  77. data/src/rbgtkcelllayout.c +144 -0
  78. data/src/rbgtkcellrenderer.c +139 -0
  79. data/src/rbgtkcellrendereraccel.c +42 -0
  80. data/src/rbgtkcellrenderercombo.c +37 -0
  81. data/src/rbgtkcellrendererpixbuf.c +33 -0
  82. data/src/rbgtkcellrendererprogress.c +37 -0
  83. data/src/rbgtkcellrendererspin.c +38 -0
  84. data/src/rbgtkcellrenderertext.c +45 -0
  85. data/src/rbgtkcellrenderertoggle.c +32 -0
  86. data/src/rbgtkcellview.c +134 -0
  87. data/src/rbgtkcheckbutton.c +55 -0
  88. data/src/rbgtkcheckmenuitem.c +56 -0
  89. data/src/rbgtkclipboard.c +473 -0
  90. data/src/rbgtkcolorbutton.c +63 -0
  91. data/src/rbgtkcolorsel.c +175 -0
  92. data/src/rbgtkcolorselectiondialog.c +72 -0
  93. data/src/rbgtkcombo.c +117 -0
  94. data/src/rbgtkcombobox.c +240 -0
  95. data/src/rbgtkcomboboxentry.c +60 -0
  96. data/src/rbgtkconst.c +163 -0
  97. data/src/rbgtkcontainer.c +776 -0
  98. data/src/rbgtkconversions.h +26 -0
  99. data/src/rbgtkcurve.c +105 -0
  100. data/src/rbgtkdialog.c +244 -0
  101. data/src/rbgtkdrag.c +436 -0
  102. data/src/rbgtkdrawingarea.c +31 -0
  103. data/src/rbgtkeditable.c +152 -0
  104. data/src/rbgtkentry.c +161 -0
  105. data/src/rbgtkentrycompletion.c +167 -0
  106. data/src/rbgtkeventbox.c +31 -0
  107. data/src/rbgtkexpander.c +67 -0
  108. data/src/rbgtkfilechooser.c +403 -0
  109. data/src/rbgtkfilechooserbutton.c +72 -0
  110. data/src/rbgtkfilechooserdialog.c +58 -0
  111. data/src/rbgtkfilechooserwidget.c +50 -0
  112. data/src/rbgtkfilefilter.c +139 -0
  113. data/src/rbgtkfilesel.c +155 -0
  114. data/src/rbgtkfixed.c +72 -0
  115. data/src/rbgtkfontbutton.c +69 -0
  116. data/src/rbgtkfontselection.c +30 -0
  117. data/src/rbgtkfontselectiondialog.c +106 -0
  118. data/src/rbgtkframe.c +64 -0
  119. data/src/rbgtkgamma.c +47 -0
  120. data/src/rbgtkhandlebox.c +42 -0
  121. data/src/rbgtkhbbox.c +31 -0
  122. data/src/rbgtkhbox.c +38 -0
  123. data/src/rbgtkhpaned.c +31 -0
  124. data/src/rbgtkhruler.c +31 -0
  125. data/src/rbgtkhscale.c +45 -0
  126. data/src/rbgtkhscrollbar.c +38 -0
  127. data/src/rbgtkhseparator.c +30 -0
  128. data/src/rbgtkiconfactory.c +80 -0
  129. data/src/rbgtkiconinfo.c +118 -0
  130. data/src/rbgtkiconset.c +87 -0
  131. data/src/rbgtkiconsize.c +90 -0
  132. data/src/rbgtkiconsource.c +176 -0
  133. data/src/rbgtkicontheme.c +309 -0
  134. data/src/rbgtkiconview.c +351 -0
  135. data/src/rbgtkimage.c +152 -0
  136. data/src/rbgtkimagemenuitem.c +52 -0
  137. data/src/rbgtkimcontext.c +134 -0
  138. data/src/rbgtkimcontextsimple.c +48 -0
  139. data/src/rbgtkimmulticontext.c +38 -0
  140. data/src/rbgtkinits.c +473 -0
  141. data/src/rbgtkinputdialog.c +30 -0
  142. data/src/rbgtkinvisible.c +68 -0
  143. data/src/rbgtkitem.c +51 -0
  144. data/src/rbgtkitemfactory.c +312 -0
  145. data/src/rbgtklabel.c +168 -0
  146. data/src/rbgtklayout.c +91 -0
  147. data/src/rbgtklinkbutton.c +68 -0
  148. data/src/rbgtkliststore.c +412 -0
  149. data/src/rbgtkmacros.h +26 -0
  150. data/src/rbgtkmain.c +532 -0
  151. data/src/rbgtkmenu.c +272 -0
  152. data/src/rbgtkmenubar.c +48 -0
  153. data/src/rbgtkmenuitem.c +171 -0
  154. data/src/rbgtkmenushell.c +128 -0
  155. data/src/rbgtkmenutoolbutton.c +74 -0
  156. data/src/rbgtkmessagedialog.c +102 -0
  157. data/src/rbgtkmisc.c +63 -0
  158. data/src/rbgtknotebook.c +484 -0
  159. data/src/rbgtkobject.c +186 -0
  160. data/src/rbgtkoptionmenu.c +65 -0
  161. data/src/rbgtkpagesetup.c +196 -0
  162. data/src/rbgtkpagesetupunixdialog.c +80 -0
  163. data/src/rbgtkpaned.c +114 -0
  164. data/src/rbgtkpapersize.c +186 -0
  165. data/src/rbgtkplug.c +84 -0
  166. data/src/rbgtkprintcontext.c +124 -0
  167. data/src/rbgtkprinter.c +155 -0
  168. data/src/rbgtkprintjob.c +151 -0
  169. data/src/rbgtkprintoperation.c +152 -0
  170. data/src/rbgtkprintoperationpreview.c +54 -0
  171. data/src/rbgtkprintsettings.c +794 -0
  172. data/src/rbgtkprintunixdialog.c +98 -0
  173. data/src/rbgtkprogress.c +21 -0
  174. data/src/rbgtkprogressbar.c +72 -0
  175. data/src/rbgtkradioaction.c +102 -0
  176. data/src/rbgtkradiobutton.c +83 -0
  177. data/src/rbgtkradiomenuitem.c +115 -0
  178. data/src/rbgtkradiotoolbutton.c +99 -0
  179. data/src/rbgtkrange.c +98 -0
  180. data/src/rbgtkrc.c +228 -0
  181. data/src/rbgtkrcstyle.c +184 -0
  182. data/src/rbgtkrecentaction.c +52 -0
  183. data/src/rbgtkrecentchooser.c +276 -0
  184. data/src/rbgtkrecentchooserdialog.c +59 -0
  185. data/src/rbgtkrecentchoosermenu.c +55 -0
  186. data/src/rbgtkrecentchooserwidget.c +45 -0
  187. data/src/rbgtkrecentdata.c +152 -0
  188. data/src/rbgtkrecentfilter.c +180 -0
  189. data/src/rbgtkrecentfilterinfo.c +197 -0
  190. data/src/rbgtkrecentinfo.c +232 -0
  191. data/src/rbgtkrecentmanager.c +164 -0
  192. data/src/rbgtkruler.c +82 -0
  193. data/src/rbgtkscale.c +47 -0
  194. data/src/rbgtkscalebutton.c +115 -0
  195. data/src/rbgtkscrollbar.c +21 -0
  196. data/src/rbgtkscrolledwindow.c +160 -0
  197. data/src/rbgtkselection.c +171 -0
  198. data/src/rbgtkselectiondata.c +333 -0
  199. data/src/rbgtkseparator.c +21 -0
  200. data/src/rbgtkseparatormenuitem.c +28 -0
  201. data/src/rbgtkseparatortoolitem.c +40 -0
  202. data/src/rbgtksettings.c +225 -0
  203. data/src/rbgtksizegroup.c +74 -0
  204. data/src/rbgtksocket.c +72 -0
  205. data/src/rbgtkspinbutton.c +138 -0
  206. data/src/rbgtkstatusbar.c +90 -0
  207. data/src/rbgtkstatusicon.c +120 -0
  208. data/src/rbgtkstock.c +264 -0
  209. data/src/rbgtkstyle.c +722 -0
  210. data/src/rbgtktable.c +190 -0
  211. data/src/rbgtktargetlist.c +148 -0
  212. data/src/rbgtktearoffmenuitem.c +30 -0
  213. data/src/rbgtktextappearance.c +173 -0
  214. data/src/rbgtktextattributes.c +209 -0
  215. data/src/rbgtktextbuffer.c +993 -0
  216. data/src/rbgtktextchild.c +49 -0
  217. data/src/rbgtktextiter.c +553 -0
  218. data/src/rbgtktextmark.c +87 -0
  219. data/src/rbgtktexttag.c +66 -0
  220. data/src/rbgtktexttagtable.c +94 -0
  221. data/src/rbgtktextview.c +351 -0
  222. data/src/rbgtktoggleaction.c +76 -0
  223. data/src/rbgtktogglebutton.c +84 -0
  224. data/src/rbgtktoggletoolbutton.c +70 -0
  225. data/src/rbgtktoolbar.c +373 -0
  226. data/src/rbgtktoolbutton.c +75 -0
  227. data/src/rbgtktoolitem.c +184 -0
  228. data/src/rbgtktooltip.c +76 -0
  229. data/src/rbgtktooltips.c +107 -0
  230. data/src/rbgtktreedragdest.c +19 -0
  231. data/src/rbgtktreedragsource.c +19 -0
  232. data/src/rbgtktreeiter.c +259 -0
  233. data/src/rbgtktreemodel.c +256 -0
  234. data/src/rbgtktreemodelfilter.c +214 -0
  235. data/src/rbgtktreemodelsort.c +113 -0
  236. data/src/rbgtktreepath.c +195 -0
  237. data/src/rbgtktreerowreference.c +168 -0
  238. data/src/rbgtktreeselection.c +235 -0
  239. data/src/rbgtktreesortable.c +127 -0
  240. data/src/rbgtktreestore.c +379 -0
  241. data/src/rbgtktreeview.c +881 -0
  242. data/src/rbgtktreeviewcolumn.c +331 -0
  243. data/src/rbgtkuimanager.c +210 -0
  244. data/src/rbgtkvbbox.c +31 -0
  245. data/src/rbgtkvbox.c +38 -0
  246. data/src/rbgtkviewport.c +33 -0
  247. data/src/rbgtkvolumebutton.c +36 -0
  248. data/src/rbgtkvpaned.c +31 -0
  249. data/src/rbgtkvruler.c +30 -0
  250. data/src/rbgtkvscale.c +45 -0
  251. data/src/rbgtkvscrollbar.c +38 -0
  252. data/src/rbgtkvseparator.c +30 -0
  253. data/src/rbgtkwidget.c +1414 -0
  254. data/src/rbgtkwindow.c +822 -0
  255. data/src/rbgtkwindowgroup.c +48 -0
  256. data/test/gtk-test-utils.rb +15 -0
  257. data/test/run-test.rb +30 -0
  258. data/test/test_gc.rb +25 -0
  259. data/test/test_gdk.rb +18 -0
  260. data/test/test_gdk_color.rb +10 -0
  261. data/test/test_gdk_display.rb +37 -0
  262. data/test/test_gdk_event.rb +11 -0
  263. data/test/test_gdk_gc.rb +7 -0
  264. data/test/test_gdk_keymap.rb +8 -0
  265. data/test/test_gdk_pango.rb +9 -0
  266. data/test/test_gdk_selection_data.rb +17 -0
  267. data/test/test_gdk_window.rb +29 -0
  268. data/test/test_gdk_window_attribute.rb +9 -0
  269. data/test/test_gtk_about_dialog.rb +14 -0
  270. data/test/test_gtk_buildable.rb +66 -0
  271. data/test/test_gtk_builder.rb +188 -0
  272. data/test/test_gtk_entry.rb +18 -0
  273. data/test/test_gtk_icon_theme.rb +30 -0
  274. data/test/test_gtk_image.rb +8 -0
  275. data/test/test_gtk_list_store.rb +65 -0
  276. data/test/test_gtk_menu_item.rb +13 -0
  277. data/test/test_gtk_rc_style.rb +14 -0
  278. data/test/test_gtk_tree_path.rb +20 -0
  279. data/test/test_gtk_unix_print.rb +14 -0
  280. data/test/test_gtk_widget.rb +32 -0
  281. metadata +393 -0
@@ -0,0 +1,60 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtkcomboboxentry.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2004/05/30 16:41:13 $
8
+
9
+ Copyright (C) 2004 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "global.h"
13
+
14
+ #if GTK_CHECK_VERSION(2,4,0)
15
+
16
+ static VALUE
17
+ comboboxentry_initialize(argc, argv, self)
18
+ int argc;
19
+ VALUE* argv;
20
+ VALUE self;
21
+ {
22
+ VALUE model_or_false, text_column;
23
+ GtkWidget* widget;
24
+
25
+ rb_scan_args(argc, argv, "02", &model_or_false, &text_column);
26
+
27
+ if (rb_obj_is_kind_of(model_or_false, GTYPE2CLASS(GTK_TYPE_TREE_MODEL))){
28
+ widget = gtk_combo_box_entry_new_with_model(
29
+ GTK_TREE_MODEL(RVAL2GOBJ(model_or_false)),
30
+ NUM2INT(text_column));
31
+ } else if (NIL_P(model_or_false) || TYPE(model_or_false) == T_TRUE){
32
+ widget = gtk_combo_box_entry_new_text();
33
+ } else if (TYPE(model_or_false) == T_FALSE){
34
+ widget = gtk_combo_box_entry_new();
35
+ } else {
36
+ rb_raise(rb_eArgError, "invalid 2nd argument %s (except true/false or Gtk::TreeModel)",
37
+ rb_class2name(CLASS_OF(model_or_false)));
38
+ }
39
+
40
+ RBGTK_INITIALIZE(self, widget);
41
+ return Qnil;
42
+ }
43
+
44
+ /* Defined as property.
45
+ void gtk_combo_box_entry_set_text_column
46
+ (GtkComboBoxEntry *entry_box,
47
+ gint text_column);
48
+ gint gtk_combo_box_entry_get_text_column
49
+ (GtkComboBoxEntry *entry_box);
50
+ */
51
+ #endif
52
+
53
+ void
54
+ Init_gtk_comboboxentry()
55
+ {
56
+ #if GTK_CHECK_VERSION(2,4,0)
57
+ VALUE gComboboxentry = G_DEF_CLASS(GTK_TYPE_COMBO_BOX_ENTRY, "ComboBoxEntry", mGtk);
58
+ rb_define_method(gComboboxentry, "initialize", comboboxentry_initialize, -1);
59
+ #endif
60
+ }
@@ -0,0 +1,163 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtkconst.c -
5
+
6
+ $Author: mutoh $
7
+ $Date: 2005/09/28 17:54:00 $
8
+
9
+ Copyright (C) 2002,2003 Ruby-GNOME2 Project Team
10
+ Copyright (C) 1998-2000 Yukihiro Matsumoto,
11
+ Daisuke Kanda,
12
+ Hiroshi Igarashi
13
+ ************************************************/
14
+
15
+ #include "global.h"
16
+
17
+ /*
18
+ * constants
19
+ */
20
+ void
21
+ Init_gtk_const()
22
+ {
23
+ /*
24
+ * version information
25
+ */
26
+ rb_define_const(mGtk, "BINDING_VERSION",
27
+ rb_ary_new3(3, INT2FIX(RBGTK_MAJOR_VERSION),
28
+ INT2FIX(RBGTK_MINOR_VERSION),
29
+ INT2FIX(RBGTK_MICRO_VERSION)));
30
+
31
+ rb_define_const(mGtk, "BUILD_VERSION",
32
+ rb_ary_new3(3, INT2FIX(GTK_MAJOR_VERSION),
33
+ INT2FIX(GTK_MINOR_VERSION),
34
+ INT2FIX(GTK_MICRO_VERSION)));
35
+
36
+ rb_define_const(mGtk, "VERSION",
37
+ rb_ary_new3(3, INT2FIX(gtk_major_version),
38
+ INT2FIX(gtk_minor_version),
39
+ INT2FIX(gtk_micro_version)));
40
+ rb_define_const(mGtk, "MAJOR_VERSION", INT2FIX(gtk_major_version));
41
+ rb_define_const(mGtk, "MINOR_VERSION", INT2FIX(gtk_minor_version));
42
+ rb_define_const(mGtk, "MICRO_VERSION", INT2FIX(gtk_micro_version));
43
+ rb_define_const(mGtk, "BINARY_AGE", INT2FIX(gtk_binary_age));
44
+ rb_define_const(mGtk, "INTERFACE_AGE", INT2FIX(gtk_interface_age));
45
+
46
+ /*
47
+ * standard enumeration
48
+ */
49
+
50
+ /* GtkAccelFlags */
51
+ G_DEF_CLASS(GTK_TYPE_ACCEL_FLAGS, "AccelFlags", mGtk);
52
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_ACCEL_FLAGS, "GTK_");
53
+
54
+ /* GtkAnchorType */
55
+ G_DEF_CLASS(GTK_TYPE_ANCHOR_TYPE, "AnchorType", mGtk);
56
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_ANCHOR_TYPE, "GTK_");
57
+
58
+ /* GtkAttachOptions */
59
+ G_DEF_CLASS(GTK_TYPE_ATTACH_OPTIONS, "AttachOptions", mGtk);
60
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_ATTACH_OPTIONS, "GTK_");
61
+
62
+ /* GtkCornerType */
63
+ G_DEF_CLASS(GTK_TYPE_CORNER_TYPE, "CornerType", mGtk);
64
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_CORNER_TYPE, "GTK_");
65
+
66
+ /* GtkDeleteType */
67
+ G_DEF_CLASS(GTK_TYPE_DELETE_TYPE, "DeleteType", mGtk);
68
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_DELETE_TYPE, "GTK_");
69
+
70
+ /* GtkDirectionType */
71
+ G_DEF_CLASS(GTK_TYPE_DIRECTION_TYPE, "DirectionType", mGtk);
72
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_DIRECTION_TYPE, "GTK_");
73
+
74
+ /* GtkExpanderStyle */
75
+ G_DEF_CLASS(GTK_TYPE_EXPANDER_STYLE, "ExpanderStyle", mGtk);
76
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_EXPANDER_STYLE, "GTK_");
77
+
78
+ /* GtkJustification */
79
+ G_DEF_CLASS(GTK_TYPE_JUSTIFICATION, "Justification", mGtk);
80
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_JUSTIFICATION, "GTK_");
81
+
82
+ /* GtkMetricType */
83
+ G_DEF_CLASS(GTK_TYPE_METRIC_TYPE, "MetricType", mGtk);
84
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_METRIC_TYPE, "GTK_");
85
+
86
+ /* GtkMovementStep */
87
+ G_DEF_CLASS(GTK_TYPE_MOVEMENT_STEP, "MovementStep", mGtk);
88
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_MOVEMENT_STEP, "GTK_");
89
+
90
+ /* GtkOrientation */
91
+ G_DEF_CLASS(GTK_TYPE_ORIENTATION, "Orientation", mGtk);
92
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_ORIENTATION, "GTK_");
93
+
94
+ /* GtkPackType */
95
+ G_DEF_CLASS(GTK_TYPE_PACK_TYPE, "PackType", mGtk);
96
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_PACK_TYPE, "GTK_");
97
+
98
+ /* GtkPathPriorityType */
99
+ G_DEF_CLASS(GTK_TYPE_PATH_PRIORITY_TYPE, "PathPriorityType", mGtk);
100
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_PATH_PRIORITY_TYPE, "GTK_");
101
+
102
+ /* GtkPathType */
103
+ G_DEF_CLASS(GTK_TYPE_PATH_TYPE, "PathType", mGtk);
104
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_PATH_TYPE, "GTK_");
105
+
106
+ /* GtkPolicyType */
107
+ G_DEF_CLASS(GTK_TYPE_POLICY_TYPE, "PolicyType", mGtk);
108
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_POLICY_TYPE, "GTK_");
109
+
110
+ /* GtkPositionType */
111
+ G_DEF_CLASS(GTK_TYPE_POSITION_TYPE, "PositionType", mGtk);
112
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_POSITION_TYPE, "GTK_");
113
+
114
+ /* GtkReliefStyle */
115
+ G_DEF_CLASS(GTK_TYPE_RELIEF_STYLE, "ReliefStyle", mGtk);
116
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_RELIEF_STYLE, "GTK_");
117
+
118
+ /* GtkResizeMode */
119
+ G_DEF_CLASS(GTK_TYPE_RESIZE_MODE, "ResizeMode", mGtk);
120
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_RESIZE_MODE, "GTK_");
121
+
122
+ /* GtkScrollStep */
123
+ #if GTK_CHECK_VERSION(2,4,0)
124
+ G_DEF_CLASS(GTK_TYPE_SCROLL_STEP, "ScrollStep", mGtk);
125
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SCROLL_STEP, "GTK_");
126
+ #endif
127
+
128
+ /* GtkScrollType */
129
+ G_DEF_CLASS(GTK_TYPE_SCROLL_TYPE, "ScrollType", mGtk);
130
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SCROLL_TYPE, "GTK_");
131
+
132
+ /* GtkSelectionMode */
133
+ G_DEF_CLASS(GTK_TYPE_SELECTION_MODE, "SelectionMode", mGtk);
134
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SELECTION_MODE, "GTK_");
135
+
136
+ /* GtkShadowType */
137
+ G_DEF_CLASS(GTK_TYPE_SHADOW_TYPE, "ShadowType", mGtk);
138
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SHADOW_TYPE, "GTK_");
139
+
140
+ /* GtkStateType */
141
+ G_DEF_CLASS(GTK_TYPE_STATE_TYPE, "StateType", mGtk);
142
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_STATE_TYPE, "GTK_");
143
+
144
+ /* GtkSubmenuDirection */
145
+ G_DEF_CLASS(GTK_TYPE_SUBMENU_DIRECTION, "SubmenuDirection", mGtk);
146
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SUBMENU_DIRECTION, "GTK_");
147
+
148
+ /* GtkSubmenuPlacement */
149
+ G_DEF_CLASS(GTK_TYPE_SUBMENU_PLACEMENT, "SubmenuPlacement", mGtk);
150
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SUBMENU_PLACEMENT, "GTK_");
151
+
152
+ /* GtkUpdateType */
153
+ G_DEF_CLASS(GTK_TYPE_UPDATE_TYPE, "UpdateType", mGtk);
154
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_UPDATE_TYPE, "GTK_");
155
+
156
+ /* GtkVisibility */
157
+ G_DEF_CLASS(GTK_TYPE_VISIBILITY, "Visibility", mGtk);
158
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_VISIBILITY, "GTK_");
159
+
160
+ /* GtkSortType */
161
+ G_DEF_CLASS(GTK_TYPE_SORT_TYPE, "SortType", mGtk);
162
+ G_DEF_CONSTANTS(mGtk, GTK_TYPE_SORT_TYPE, "GTK_");
163
+ }
@@ -0,0 +1,776 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtkcontainer.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:31 $
8
+
9
+ Copyright (C) 2002-2006 Ruby-GNOME2 Project Team
10
+ Copyright (C) 1998-2000 Yukihiro Matsumoto,
11
+ Daisuke Kanda,
12
+ Hiroshi Igarashi
13
+ ************************************************/
14
+
15
+ #include "global.h"
16
+
17
+ #define _SELF(s) (GTK_CONTAINER(RVAL2GOBJ(self)))
18
+
19
+ /*
20
+ We don't need this.
21
+ #define GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID(object, property_id, pspec)
22
+ */
23
+
24
+ static VALUE type_to_prop_setter_table;
25
+ static VALUE type_to_prop_getter_table;
26
+
27
+ static VALUE
28
+ cont_is_resize_container(self)
29
+ VALUE self;
30
+ {
31
+ return CBOOL2RVAL(GTK_IS_RESIZE_CONTAINER(_SELF(self)));
32
+ }
33
+
34
+ static VALUE
35
+ cont_remove(self, other)
36
+ VALUE self, other;
37
+ {
38
+ G_CHILD_REMOVE(self, other);
39
+ gtk_container_remove(_SELF(self), GTK_WIDGET(RVAL2GOBJ(other)));
40
+ return self;
41
+ }
42
+
43
+ static VALUE
44
+ cont_check_resize(self)
45
+ VALUE self;
46
+ {
47
+ gtk_container_check_resize(_SELF(self));
48
+ return self;
49
+ }
50
+
51
+ static VALUE
52
+ cont_foreach(argc, argv, self)
53
+ int argc;
54
+ VALUE *argv;
55
+ VALUE self;
56
+ {
57
+ VALUE callback;
58
+
59
+ rb_scan_args(argc, argv, "01", &callback);
60
+ if (NIL_P(callback)) {
61
+ callback = rb_block_proc();
62
+ }
63
+ gtk_container_foreach(_SELF(self), exec_callback, (gpointer)callback);
64
+ return self;
65
+ }
66
+
67
+ static VALUE
68
+ cont_forall(argc, argv, self)
69
+ int argc;
70
+ VALUE *argv;
71
+ VALUE self;
72
+ {
73
+ VALUE callback;
74
+
75
+ rb_scan_args(argc, argv, "01", &callback);
76
+ if (NIL_P(callback)) {
77
+ callback = rb_block_proc();
78
+ }
79
+ gtk_container_forall(_SELF(self), exec_callback, (gpointer)callback);
80
+ return self;
81
+ }
82
+
83
+ static VALUE
84
+ cont_get_children(self)
85
+ VALUE self;
86
+ {
87
+ return GLIST2ARYF(gtk_container_get_children(_SELF(self)));
88
+ }
89
+
90
+ static VALUE
91
+ cont_set_reallocate_redraws(self, needs_redraws)
92
+ VALUE self, needs_redraws;
93
+ {
94
+ gtk_container_set_reallocate_redraws(_SELF(self), RVAL2CBOOL(needs_redraws));
95
+ return self;
96
+ }
97
+
98
+
99
+ static VALUE
100
+ cont_set_focus_child(self, child)
101
+ VALUE self, child;
102
+ {
103
+ gtk_container_set_focus_child(_SELF(self), GTK_WIDGET(RVAL2GOBJ(child)));
104
+ return self;
105
+ }
106
+
107
+ static VALUE
108
+ cont_set_focus_vadjustment(self, adjustment)
109
+ VALUE self, adjustment;
110
+ {
111
+ gtk_container_set_focus_vadjustment(_SELF(self),
112
+ NIL_P(adjustment) ? NULL : GTK_ADJUSTMENT(RVAL2GOBJ(adjustment)));
113
+ return self;
114
+ }
115
+
116
+ static VALUE
117
+ cont_set_focus_hadjustment(self, adjustment)
118
+ VALUE self, adjustment;
119
+ {
120
+ gtk_container_set_focus_hadjustment(_SELF(self),
121
+ NIL_P(adjustment) ? NULL : GTK_ADJUSTMENT(RVAL2GOBJ(adjustment)));
122
+ return self;
123
+ }
124
+
125
+ static VALUE
126
+ cont_get_focus_vadjustment(self)
127
+ VALUE self;
128
+ {
129
+ GtkAdjustment* adj = gtk_container_get_focus_vadjustment(_SELF(self));
130
+ return adj ? GOBJ2RVAL(adj) : Qnil;
131
+ }
132
+
133
+ static VALUE
134
+ cont_get_focus_hadjustment(self)
135
+ VALUE self;
136
+ {
137
+ GtkAdjustment* adj = gtk_container_get_focus_hadjustment(_SELF(self));
138
+ return adj ? GOBJ2RVAL(adj) : Qnil;
139
+ }
140
+
141
+ static VALUE
142
+ cont_get_resize_children(self)
143
+ VALUE self;
144
+ {
145
+ gtk_container_resize_children(_SELF(self));
146
+ return self;
147
+ }
148
+
149
+ static VALUE
150
+ cont_get_child_type(self)
151
+ VALUE self;
152
+ {
153
+ return GTYPE2CLASS(gtk_container_child_type(_SELF(self)));
154
+ }
155
+
156
+ /*
157
+ void gtk_container_child_get (GtkContainer *container,
158
+ GtkWidget *child,
159
+ const gchar *first_prop_name,
160
+ ...);
161
+ void gtk_container_child_set (GtkContainer *container,
162
+ GtkWidget *child,
163
+ const gchar *first_prop_name,
164
+ ...);
165
+ */
166
+
167
+ void
168
+ rbgtkcontainer_register_child_property_setter(gtype, name, func)
169
+ GType gtype;
170
+ const char* name;
171
+ RValueToGValueFunc func;
172
+ {
173
+ GObjectClass* oclass;
174
+ GParamSpec* pspec;
175
+
176
+ VALUE table = rb_hash_aref(type_to_prop_setter_table, INT2FIX(gtype));
177
+ if (NIL_P(table)){
178
+ table = rb_hash_new();
179
+ rb_hash_aset(type_to_prop_setter_table, INT2FIX(gtype), table);
180
+ }
181
+
182
+ oclass = g_type_class_ref(gtype);
183
+ pspec = gtk_container_class_find_child_property(oclass, name);
184
+
185
+ rb_hash_aset(table, rb_intern(g_param_spec_get_name(pspec)),
186
+ Data_Wrap_Struct(rb_cData, NULL, NULL, func));
187
+
188
+ g_type_class_unref(oclass);
189
+ }
190
+
191
+ void
192
+ rbgtkcontainer_register_child_property_getter(gtype, name, func)
193
+ GType gtype;
194
+ const char* name;
195
+ GValueToRValueFunc func;
196
+ {
197
+ GObjectClass* oclass;
198
+ GParamSpec* pspec;
199
+
200
+ VALUE table = rb_hash_aref(type_to_prop_getter_table, INT2FIX(gtype));
201
+ if (NIL_P(table)){
202
+ table = rb_hash_new();
203
+ rb_hash_aset(type_to_prop_getter_table, INT2FIX(gtype), table);
204
+ }
205
+
206
+ oclass = g_type_class_ref(gtype);
207
+ pspec = gtk_container_class_find_child_property(oclass, name);
208
+
209
+ rb_hash_aset(table, rb_intern(g_param_spec_get_name(pspec)),
210
+ Data_Wrap_Struct(rb_cData, NULL, NULL, func));
211
+ }
212
+
213
+ static VALUE
214
+ cont_child_get_property(self, child, prop_name)
215
+ VALUE self, child, prop_name;
216
+ {
217
+ GParamSpec* pspec;
218
+ const char* name;
219
+
220
+ if (SYMBOL_P(prop_name)) {
221
+ name = rb_id2name(SYM2ID(prop_name));
222
+ } else {
223
+ StringValue(prop_name);
224
+ name = StringValuePtr(prop_name);
225
+ }
226
+
227
+ pspec = gtk_container_class_find_child_property(
228
+ G_OBJECT_GET_CLASS(RVAL2GOBJ(self)), name);
229
+
230
+ if (!pspec)
231
+ rb_raise(rb_eArgError, "No such property: %s", name);
232
+ else {
233
+ GValueToRValueFunc getter = NULL;
234
+ GValue gval = {0,};
235
+ VALUE ret;
236
+
237
+ {
238
+ VALUE table = rb_hash_aref(type_to_prop_getter_table,
239
+ INT2FIX(pspec->owner_type));
240
+ if (!NIL_P(table)){
241
+ VALUE obj = rb_hash_aref(table, rb_intern(g_param_spec_get_name(pspec)));
242
+ if (!NIL_P(obj))
243
+ Data_Get_Struct(obj, void, getter);
244
+ }
245
+ }
246
+ g_value_init(&gval, G_PARAM_SPEC_VALUE_TYPE(pspec));
247
+ gtk_container_child_get_property(GTK_CONTAINER(RVAL2GOBJ(self)),
248
+ GTK_WIDGET(RVAL2GOBJ(child)),
249
+ name , &gval);
250
+ ret = getter ? getter(&gval) : GVAL2RVAL(&gval);
251
+
252
+ G_CHILD_ADD(child, ret);
253
+
254
+ g_value_unset(&gval);
255
+ return ret;
256
+ }
257
+ }
258
+
259
+ static VALUE
260
+ cont_child_set_property(self, child, prop_name, val)
261
+ VALUE self, child, prop_name, val;
262
+ {
263
+ GParamSpec* pspec;
264
+ const char* name;
265
+
266
+ if (SYMBOL_P(prop_name)) {
267
+ name = rb_id2name(SYM2ID(prop_name));
268
+ } else {
269
+ StringValue(prop_name);
270
+ name = StringValuePtr(prop_name);
271
+ }
272
+
273
+ pspec = gtk_container_class_find_child_property(
274
+ G_OBJECT_GET_CLASS(RVAL2GOBJ(self)), name);
275
+
276
+ if (!pspec)
277
+ rb_raise(rb_eArgError, "No such property: %s", name);
278
+ else {
279
+ RValueToGValueFunc setter = NULL;
280
+ GValue gval = {0,};
281
+ g_value_init(&gval, G_PARAM_SPEC_VALUE_TYPE(pspec));
282
+
283
+ {
284
+ VALUE table = rb_hash_aref(type_to_prop_setter_table,
285
+ INT2FIX(pspec->owner_type));
286
+ if (!NIL_P(table)){
287
+ VALUE obj = rb_hash_aref(table, rb_intern(g_param_spec_get_name(pspec)));
288
+ if (!NIL_P(obj))
289
+ Data_Get_Struct(obj, void, setter);
290
+ }
291
+ }
292
+
293
+ if (setter)
294
+ setter(val, &gval);
295
+ else {
296
+ if (!NIL_P(val))
297
+ rbgobj_rvalue_to_gvalue(val, &gval);
298
+ }
299
+
300
+ G_CHILD_ADD(child, val);
301
+
302
+ gtk_container_child_set_property(GTK_CONTAINER(RVAL2GOBJ(self)),
303
+ GTK_WIDGET(RVAL2GOBJ(child)), name, &gval);
304
+
305
+ g_value_unset(&gval);
306
+ return self;
307
+ }
308
+ }
309
+
310
+ static VALUE
311
+ cont_add(argc, argv, self)
312
+ int argc;
313
+ VALUE *argv;
314
+ VALUE self;
315
+ {
316
+ VALUE other, properties;
317
+ GtkWidget *child;
318
+
319
+ rb_scan_args(argc, argv, "11", &other, &properties);
320
+
321
+ child = GTK_WIDGET(RVAL2GOBJ(other));
322
+ gtk_widget_freeze_child_notify(child);
323
+ gtk_container_add(_SELF(self), child);
324
+
325
+ G_CHILD_ADD(self, other);
326
+
327
+ if (child->parent && (! NIL_P(properties))){
328
+ int i;
329
+ VALUE ary;
330
+ GObject* obj;
331
+
332
+ Check_Type(properties, T_HASH);
333
+ ary = rb_funcall(properties, rb_intern("to_a"), 0);
334
+ obj = RVAL2GOBJ(self);
335
+
336
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
337
+ cont_child_set_property(self, other,
338
+ RARRAY_PTR(RARRAY_PTR(ary)[i])[0],
339
+ RARRAY_PTR(RARRAY_PTR(ary)[i])[1]);
340
+ }
341
+ }
342
+ gtk_widget_thaw_child_notify(child);
343
+ return self;
344
+ }
345
+
346
+ /*
347
+ void gtk_container_child_get_valist (GtkContainer *container,
348
+ GtkWidget *child,
349
+ const gchar *first_property_name,
350
+ va_list var_args);
351
+ void gtk_container_child_set_valist (GtkContainer *container,
352
+ GtkWidget *child,
353
+ const gchar *first_property_name,
354
+ va_list var_args);
355
+ */
356
+
357
+ static VALUE
358
+ cont_propagate_expose(self, child, event)
359
+ VALUE self, child, event;
360
+ {
361
+ gtk_container_propagate_expose(_SELF(self), GTK_WIDGET(RVAL2GOBJ(child)),
362
+ (GdkEventExpose *)RVAL2GEV(event));
363
+ return self;
364
+ }
365
+
366
+ static VALUE
367
+ cont_get_focus_chain(self)
368
+ VALUE self;
369
+ {
370
+ gboolean ret;
371
+ GList *glist = NULL;
372
+ ret = gtk_container_get_focus_chain(_SELF(self), &glist);
373
+ return GLIST2ARYF(glist);
374
+ }
375
+
376
+ static VALUE
377
+ cont_set_focus_chain(self, focusable_widgets)
378
+ VALUE self, focusable_widgets;
379
+ {
380
+ int i;
381
+ GList *glist = NULL;
382
+
383
+ Check_Type(focusable_widgets, T_ARRAY);
384
+ for (i = 0; i < RARRAY_LEN(focusable_widgets); i++) {
385
+ glist = g_list_append(glist, RVAL2GOBJ(RARRAY_PTR(focusable_widgets)[i]));
386
+ }
387
+ gtk_container_set_focus_chain(_SELF(self), glist);
388
+ g_list_free(glist);
389
+
390
+ return self;
391
+ }
392
+
393
+ static VALUE
394
+ cont_unset_focus_chain(self)
395
+ VALUE self;
396
+ {
397
+ gtk_container_unset_focus_chain(_SELF(self));
398
+ return self;
399
+ }
400
+
401
+ static VALUE
402
+ cont_s_child_property(self, property_name)
403
+ VALUE self, property_name;
404
+ {
405
+ GObjectClass* oclass;
406
+ const char* name;
407
+ GParamSpec* prop;
408
+ VALUE result;
409
+
410
+ if (SYMBOL_P(property_name)) {
411
+ name = rb_id2name(SYM2ID(property_name));
412
+ } else {
413
+ StringValue(property_name);
414
+ name = StringValuePtr(property_name);
415
+ }
416
+
417
+ oclass = g_type_class_ref(CLASS2GTYPE(self));
418
+
419
+ prop = gtk_container_class_find_child_property(oclass, name);
420
+ if (!prop){
421
+ g_type_class_unref(oclass);
422
+ rb_raise(rb_eNameError, "no such property: %s", name);
423
+ }
424
+
425
+ result = GOBJ2RVAL(prop);
426
+ g_type_class_unref(oclass);
427
+ return result;
428
+ }
429
+
430
+ static VALUE
431
+ cont_s_install_child_property(argc, argv, self)
432
+ int argc;
433
+ VALUE* argv;
434
+ VALUE self;
435
+ {
436
+ const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
437
+ GtkContainerClass* gclass;
438
+ VALUE spec, prop_id;
439
+ GParamSpec* pspec;
440
+
441
+ rb_scan_args(argc, argv, "11", &spec, &prop_id);
442
+
443
+ pspec = G_PARAM_SPEC(RVAL2GOBJ(spec));
444
+
445
+ if (cinfo->klass != self)
446
+ rb_raise(rb_eTypeError, "%s isn't registerd class",
447
+ rb_class2name(self));
448
+
449
+ gclass = GTK_CONTAINER_CLASS(g_type_class_ref(cinfo->gtype));
450
+ gtk_container_class_install_child_property(gclass,
451
+ NIL_P(prop_id) ? 1 : NUM2UINT(prop_id),
452
+ pspec);
453
+
454
+ return self;
455
+ }
456
+
457
+ static VALUE
458
+ cont_s_child_properties(argc, argv, self)
459
+ int argc;
460
+ VALUE* argv;
461
+ VALUE self;
462
+ {
463
+ GObjectClass* oclass = g_type_class_ref(CLASS2GTYPE(self));
464
+ guint n_properties;
465
+ GParamSpec** props;
466
+ VALUE inherited_too;
467
+ VALUE ary;
468
+ int i;
469
+
470
+ if (rb_scan_args(argc, argv, "01", &inherited_too) == 0)
471
+ inherited_too = Qtrue;
472
+
473
+ props = gtk_container_class_list_child_properties(oclass, &n_properties);
474
+
475
+ ary = rb_ary_new();
476
+ for (i = 0; i < n_properties; i++){
477
+ if (RVAL2CBOOL(inherited_too)
478
+ || GTYPE2CLASS(props[i]->owner_type) == self)
479
+ rb_ary_push(ary, CSTR2RVAL(props[i]->name));
480
+ }
481
+ g_free(props);
482
+ g_type_class_unref(oclass);
483
+ return ary;
484
+ }
485
+
486
+ /**********************************************************************/
487
+
488
+ static VALUE proc_mod_eval;
489
+ static GQuark q_ruby_setter;
490
+ static GQuark q_ruby_getter;
491
+
492
+ static VALUE
493
+ cont_initialize(argc, argv, self)
494
+ int argc;
495
+ VALUE *argv;
496
+ VALUE self;
497
+ {
498
+ VALUE params_hash;
499
+ GObject* gobj;
500
+
501
+ rb_scan_args(argc, argv, "01", &params_hash);
502
+
503
+ if (!NIL_P(params_hash))
504
+ Check_Type(params_hash, T_HASH);
505
+
506
+ gobj = rbgobj_gobject_new(RVAL2GTYPE(self), params_hash);
507
+
508
+ RBGTK_INITIALIZE(self, gobj);
509
+ return Qnil;
510
+ }
511
+
512
+ // FIXME: use rb_protect
513
+ static void
514
+ get_prop_func(GObject* object,
515
+ guint property_id,
516
+ GValue* value,
517
+ GParamSpec* pspec)
518
+ {
519
+ ID ruby_getter = (ID)g_param_spec_get_qdata(pspec, q_ruby_getter);
520
+ if (!ruby_getter) {
521
+ gchar* name = g_strdup(g_param_spec_get_name(pspec));
522
+ gchar* p;
523
+ for (p = name; *p; p++) {
524
+ if (*p == '-')
525
+ *p = '_';
526
+ }
527
+ ruby_getter = rb_intern(name);
528
+ g_param_spec_set_qdata(pspec, q_ruby_getter, (gpointer)ruby_getter);
529
+ g_free(name);
530
+ }
531
+
532
+ {
533
+ VALUE ret = rb_funcall(GOBJ2RVAL(object), ruby_getter, 0);
534
+ rbgobj_rvalue_to_gvalue(ret, value);
535
+ }
536
+ }
537
+
538
+ // FIXME: use rb_protect
539
+ static void
540
+ set_prop_func(GObject* object,
541
+ guint property_id,
542
+ const GValue* value,
543
+ GParamSpec* pspec)
544
+ {
545
+ ID ruby_setter = (ID)g_param_spec_get_qdata(pspec, q_ruby_setter);
546
+ if (!ruby_setter) {
547
+ gchar* name = g_strconcat(g_param_spec_get_name(pspec), "=", NULL);
548
+ gchar* p;
549
+ for (p = name; *p; p++) {
550
+ if (*p == '-')
551
+ *p = '_';
552
+ }
553
+ ruby_setter = rb_intern(name);
554
+ g_param_spec_set_qdata(pspec, q_ruby_setter, (gpointer)ruby_setter);
555
+ g_free(name);
556
+ }
557
+
558
+ rb_funcall(GOBJ2RVAL(object), ruby_setter, 1, GVAL2RVAL(value));
559
+ }
560
+
561
+ // FIXME: use rb_protect
562
+ static void
563
+ get_child_prop_func(GtkContainer* container,
564
+ GtkWidget* child,
565
+ guint property_id,
566
+ GValue* value,
567
+ GParamSpec* pspec)
568
+ {
569
+ ID ruby_getter = (ID)g_param_spec_get_qdata(pspec, q_ruby_getter);
570
+ if (!ruby_getter) {
571
+ gchar* name = g_strconcat("get_", g_param_spec_get_name(pspec), NULL);
572
+ gchar* p;
573
+ for (p = name; *p; p++) {
574
+ if (*p == '-')
575
+ *p = '_';
576
+ }
577
+ ruby_getter = rb_intern(name);
578
+ g_param_spec_set_qdata(pspec, q_ruby_getter, (gpointer)ruby_getter);
579
+ g_free(name);
580
+ }
581
+
582
+ {
583
+ VALUE ret = rb_funcall(GOBJ2RVAL(container), ruby_getter, 1, GOBJ2RVAL(child));
584
+ rbgobj_rvalue_to_gvalue(ret, value);
585
+ }
586
+ }
587
+
588
+ // FIXME: use rb_protect
589
+ static void
590
+ set_child_prop_func(GtkContainer* container,
591
+ GtkWidget* child,
592
+ guint property_id,
593
+ const GValue* value,
594
+ GParamSpec* pspec)
595
+ {
596
+ ID ruby_setter = (ID)g_param_spec_get_qdata(pspec, q_ruby_setter);
597
+ if (!ruby_setter) {
598
+ gchar* name = g_strconcat("set_", g_param_spec_get_name(pspec), NULL);
599
+ gchar* p;
600
+ for (p = name; *p; p++) {
601
+ if (*p == '-')
602
+ *p = '_';
603
+ }
604
+ ruby_setter = rb_intern(name);
605
+ g_param_spec_set_qdata(pspec, q_ruby_setter, (gpointer)ruby_setter);
606
+ g_free(name);
607
+ }
608
+
609
+ rb_funcall(GOBJ2RVAL(container), ruby_setter, 2, GOBJ2RVAL(child), GVAL2RVAL(value));
610
+ }
611
+
612
+ // FIXME: use rb_protect
613
+ static void
614
+ class_init_func(gpointer g_class, gpointer class_data)
615
+ {
616
+ GObjectClass* g_class1 = G_OBJECT_CLASS(g_class);
617
+ GtkContainerClass* g_class2 = GTK_CONTAINER_CLASS(g_class);
618
+
619
+ g_class1->set_property = set_prop_func;
620
+ g_class1->get_property = get_prop_func;
621
+
622
+ g_class2->set_child_property = set_child_prop_func;
623
+ g_class2->get_child_property = get_child_prop_func;
624
+
625
+ #if 0
626
+ VALUE class_init_proc = (VALUE)class_data;
627
+ rb_funcall(proc_mod_eval, rb_intern("call"), 2,
628
+ GTYPE2CLASS(G_TYPE_FROM_CLASS(g_class)), class_init_proc);
629
+ #endif
630
+ }
631
+
632
+ static VALUE
633
+ type_register(int argc, VALUE* argv, VALUE self)
634
+ {
635
+ VALUE type_name, flags;
636
+ volatile VALUE class_init_proc = Qnil;
637
+ GType parent_type;
638
+ GTypeInfo* info;
639
+
640
+ rb_scan_args(argc, argv, "03", &type_name, &info, &flags);
641
+
642
+ {
643
+ const RGObjClassInfo* cinfo = rbgobj_lookup_class(self);
644
+ if (cinfo->klass == self)
645
+ rb_raise(rb_eTypeError, "already registered");
646
+ }
647
+
648
+ {
649
+ VALUE superclass = rb_funcall(self, rb_intern("superclass"), 0);
650
+ const RGObjClassInfo* cinfo = CLASS2CINFO(superclass);
651
+ if (cinfo->klass != superclass)
652
+ rb_raise(rb_eTypeError, "super class must be registered to GLib");
653
+ parent_type = cinfo->gtype;
654
+ }
655
+
656
+ if (NIL_P(type_name)){
657
+ VALUE s = rb_funcall(self, rb_intern("name"), 0);
658
+
659
+ if (strlen(StringValuePtr(s)) == 0)
660
+ rb_raise(rb_eTypeError, "can't determine type name");
661
+
662
+ type_name = rb_funcall(
663
+ rb_eval_string("lambda{|x| x.gsub(/::/,'') }"),
664
+ rb_intern("call"), 1, s);
665
+ }
666
+
667
+ {
668
+ GTypeQuery query;
669
+ g_type_query(parent_type, &query);
670
+
671
+ info = g_new0(GTypeInfo, 1);
672
+ info->class_size = query.class_size;
673
+ info->base_init = NULL;
674
+ info->base_finalize = NULL;
675
+ info->class_init = class_init_func;
676
+ info->class_finalize = NULL;
677
+ info->class_data = (gpointer)class_init_proc;
678
+ info->instance_size = query.instance_size;
679
+ info->n_preallocs = 0;
680
+ info->instance_init = NULL;
681
+ info->value_table = NULL;
682
+ }
683
+
684
+ {
685
+ GType type = g_type_register_static(parent_type,
686
+ StringValuePtr(type_name),
687
+ info,
688
+ NIL_P(flags) ? 0 : NUM2INT(flags));
689
+ G_RELATIVE(self, class_init_proc);
690
+
691
+ rbgobj_register_class(self, type, TRUE, TRUE);
692
+
693
+ {
694
+ RGObjClassInfo* cinfo = (RGObjClassInfo*)rbgobj_lookup_class(self);
695
+ cinfo->flags |= RBGOBJ_DEFINED_BY_RUBY;
696
+ }
697
+
698
+ {
699
+ GType parent = g_type_parent(type);
700
+ const RGObjClassInfo* cinfo = GTYPE2CINFO(parent);
701
+ VALUE m = rb_define_module_under(self, RubyGtkContainerHookModule);
702
+
703
+ if (! (cinfo->flags & RBGOBJ_DEFINED_BY_RUBY)) {
704
+ rb_define_method(m, "initialize", cont_initialize, -1);
705
+ }
706
+
707
+ rb_include_module(self, m);
708
+ }
709
+
710
+ return Qnil;
711
+ }
712
+ }
713
+ /**********************************************************************/
714
+
715
+ static void
716
+ cont_mark_callback(GtkWidget* w, gpointer data)
717
+ {
718
+ rbgobj_gc_mark_instance(w);
719
+ }
720
+
721
+ static void
722
+ cont_mark(void* p)
723
+ {
724
+ gtk_container_forall(GTK_CONTAINER(p), cont_mark_callback, NULL);
725
+ }
726
+
727
+ /**********************************************************************/
728
+
729
+ void
730
+ Init_gtk_container()
731
+ {
732
+ VALUE gContainer;
733
+
734
+ gContainer = G_DEF_CLASS_WITH_GC_FUNC(GTK_TYPE_CONTAINER, "Container",
735
+ mGtk, cont_mark, NULL);
736
+ rb_define_method(gContainer, "resize_container?", cont_is_resize_container, 0);
737
+ rb_define_method(gContainer, "add", cont_add, -1);
738
+ rb_define_alias(gContainer, "<<", "add");
739
+ rb_define_method(gContainer, "remove", cont_remove, 1);
740
+ rb_define_method(gContainer, "check_resize", cont_check_resize, 0);
741
+ rb_define_method(gContainer, "each", cont_foreach, -1);
742
+ rb_define_method(gContainer, "each_forall", cont_forall, -1);
743
+ rb_define_method(gContainer, "children", cont_get_children, 0);
744
+ rb_define_method(gContainer, "set_reallocate_redraws", cont_set_reallocate_redraws, 1);
745
+ rb_define_method(gContainer, "set_focus_child", cont_set_focus_child, 1);
746
+ rb_define_method(gContainer, "set_focus_vadjustment", cont_set_focus_vadjustment, 1);
747
+ rb_define_method(gContainer, "set_focus_hadjustment", cont_set_focus_hadjustment, 1);
748
+ rb_define_method(gContainer, "focus_vadjustment", cont_get_focus_vadjustment, 0);
749
+ rb_define_method(gContainer, "focus_hadjustment", cont_get_focus_hadjustment, 0);
750
+ rb_define_method(gContainer, "resize_children", cont_get_resize_children, 0);
751
+ rb_define_method(gContainer, "child_type", cont_get_child_type, 0);
752
+ rb_define_method(gContainer, "child_get_property", cont_child_get_property, 2);
753
+ rb_define_method(gContainer, "child_set_property", cont_child_set_property, 3);
754
+ rb_define_method(gContainer, "propagate_expose", cont_propagate_expose, 2);
755
+ rb_define_method(gContainer, "focus_chain", cont_get_focus_chain, 0);
756
+ rb_define_method(gContainer, "set_focus_chain", cont_set_focus_chain, 1);
757
+ rb_define_method(gContainer, "unset_focus_chain", cont_unset_focus_chain, 0);
758
+ rb_define_singleton_method(gContainer, "child_property", cont_s_child_property, 1);
759
+ rb_define_singleton_method(gContainer, "child_properties", cont_s_child_properties, -1);
760
+ rb_define_singleton_method(gContainer, "install_child_property", cont_s_install_child_property, -1);
761
+
762
+ q_ruby_getter = g_quark_from_static_string("__ruby_getter");
763
+ q_ruby_setter = g_quark_from_static_string("__ruby_setter");
764
+
765
+ rb_define_singleton_method(gContainer, "type_register", type_register, -1);
766
+
767
+ rb_global_variable(&proc_mod_eval);
768
+ proc_mod_eval = rb_eval_string("lambda{|obj,proc| obj.module_eval(&proc)}");
769
+
770
+ G_DEF_SETTERS(gContainer);
771
+
772
+ rb_global_variable(&type_to_prop_setter_table);
773
+ rb_global_variable(&type_to_prop_getter_table);
774
+ type_to_prop_setter_table = rb_hash_new();
775
+ type_to_prop_getter_table = rb_hash_new();
776
+ }