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,379 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtktreestore.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/10 08:07:15 $
8
+
9
+ Copyright (C) 2002-2006 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "global.h"
13
+
14
+ #define _SELF(s) (GTK_TREE_STORE(RVAL2GOBJ(s)))
15
+
16
+ static VALUE
17
+ tstore_initialize(argc, argv, self)
18
+ int argc;
19
+ VALUE* argv;
20
+ VALUE self;
21
+ {
22
+ gint cnt;
23
+ GtkTreeStore* store;
24
+ GType* buf;
25
+
26
+ if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type.");
27
+
28
+ buf = ALLOCA_N(GType, argc);
29
+ for (cnt = 0; cnt < argc; cnt++) {
30
+ buf[cnt] = CLASS2GTYPE(argv[cnt]);
31
+ }
32
+
33
+ store = gtk_tree_store_newv(argc, buf);
34
+
35
+ G_INITIALIZE(self, store);
36
+
37
+ return Qnil;
38
+ }
39
+
40
+ static VALUE
41
+ tstore_set_column_types(argc, argv, self)
42
+ int argc;
43
+ VALUE* argv;
44
+ VALUE self;
45
+ {
46
+ gint cnt;
47
+ GType* buf;
48
+
49
+ if (argc == 0) rb_raise(rb_eArgError, "need more than 1 class type.");
50
+ buf = ALLOCA_N(GType, argc);
51
+ for (cnt = 0; cnt < argc; cnt++) {
52
+ buf[cnt] = CLASS2GTYPE(argv[cnt]);
53
+ }
54
+
55
+ gtk_tree_store_set_column_types(_SELF(self), argc, buf);
56
+
57
+ return self;
58
+ }
59
+
60
+ static VALUE
61
+ tstore_set_value(self, iter, column, value)
62
+ VALUE self, iter, column, value;
63
+ {
64
+ GType gtype = gtk_tree_model_get_column_type(GTK_TREE_MODEL(RVAL2GOBJ(self)), NUM2INT(column));
65
+ GValue gval = {0,};
66
+ g_value_init(&gval, gtype);
67
+
68
+ rbgobj_rvalue_to_gvalue(value, &gval);
69
+
70
+ G_CHILD_ADD(self, iter);
71
+ G_CHILD_ADD(iter, value);
72
+
73
+ gtk_tree_store_set_value(_SELF(self), RVAL2GTKTREEITER(iter), NUM2INT(column), &gval);
74
+
75
+ g_value_unset(&gval);
76
+ return self;
77
+ }
78
+
79
+ /*
80
+ void gtk_tree_store_set (GtkTreeStore *tree_store,
81
+ GtkTreeIter *iter,
82
+ ...);
83
+
84
+ void gtk_tree_store_set_valist (GtkTreeStore *tree_store,
85
+ GtkTreeIter *iter,
86
+ va_list var_args);
87
+ */
88
+
89
+ static VALUE
90
+ tstore_remove(self, iter)
91
+ VALUE self, iter;
92
+ {
93
+ G_CHILD_REMOVE(self, iter);
94
+ #if GTK_CHECK_VERSION(2,2,0)
95
+ return CBOOL2RVAL(gtk_tree_store_remove(_SELF(self), RVAL2GTKTREEITER(iter)));
96
+ #else
97
+ gtk_tree_store_remove(_SELF(self), RVAL2GTKTREEITER(iter));
98
+ return Qtrue;
99
+ #endif
100
+ }
101
+
102
+ static VALUE
103
+ tstore_insert(argc, argv, self)
104
+ int argc;
105
+ VALUE* argv;
106
+ VALUE self;
107
+ {
108
+ VALUE parent, position, values, ret;
109
+ GtkTreeIter iter;
110
+ GtkTreeStore* model = _SELF(self);
111
+
112
+ rb_scan_args(argc, argv, "21", &parent, &position, &values);
113
+
114
+ if (NIL_P(values)){
115
+ gtk_tree_store_insert(model, &iter,
116
+ NIL_P(parent) ? NULL : RVAL2GTKTREEITER(parent),
117
+ NUM2INT(position));
118
+ iter.user_data3 = model;
119
+ ret = GTKTREEITER2RVAL(&iter);
120
+ G_CHILD_ADD(self, ret);
121
+ } else {
122
+ #if GTK_CHECK_VERSION(2,10,0)
123
+ gint *c_columns;
124
+ GValue *c_values;
125
+ long size, i;
126
+
127
+ size = NUM2INT(rb_funcall(values, rb_intern("size"), 0));
128
+ c_columns = ALLOCA_N(gint, size);
129
+ c_values = ALLOCA_N(GValue, size);
130
+
131
+ if(TYPE(values)==T_ARRAY) {
132
+ for(i=0; i<size; i++) {
133
+ c_columns[i] = i;
134
+ GType gtype = gtk_tree_model_get_column_type(GTK_TREE_MODEL(RVAL2GOBJ(self)),
135
+ c_columns[i]);
136
+
137
+ GValue gval = {0,};
138
+ g_value_init(&gval, gtype);
139
+ rbgobj_rvalue_to_gvalue(rb_ary_shift(values), &gval);
140
+ c_values[i] = gval;
141
+ }
142
+ } else if(TYPE(values)==T_HASH) {
143
+ VALUE r_columns;
144
+ r_columns = rb_funcall(values, rb_intern("keys"), 0);
145
+
146
+ for(i=0; i<size; i++) {
147
+ c_columns[i] = NUM2INT (rb_ary_entry(r_columns, i));
148
+
149
+ GType gtype = gtk_tree_model_get_column_type(GTK_TREE_MODEL(RVAL2GOBJ(self)),
150
+ c_columns[i]);
151
+
152
+ GValue gval = {0,};
153
+ g_value_init(&gval, gtype);
154
+ rbgobj_rvalue_to_gvalue(rb_hash_aref(values, INT2NUM(c_columns[i])), &gval);
155
+ c_values[i] = gval;
156
+ }
157
+ } else {
158
+ rb_raise(rb_eArgError, "values must be of type Hash or Array");
159
+ }
160
+
161
+ gtk_tree_store_insert_with_valuesv(model, &iter,
162
+ NIL_P(parent) ? NULL : RVAL2GTKTREEITER(parent),
163
+ NUM2INT(position),
164
+ c_columns,
165
+ c_values,
166
+ size);
167
+ iter.user_data3 = model;
168
+
169
+ ret = GTKTREEITER2RVAL(&iter);
170
+ G_CHILD_ADD(self, ret);
171
+
172
+ for(i=0; i<size; i++) {
173
+ G_CHILD_ADD(ret, rbgobj_gvalue_to_rvalue(&(c_values[i])));
174
+ g_value_unset(&(c_values[i]));
175
+ }
176
+ #else
177
+ rb_warn("Gtk::TreeStore#insert(parent, position, values) requires GTK+-2.10.0 or later");
178
+ gtk_tree_store_insert(model, &iter,
179
+ NIL_P(parent) ? NULL : RVAL2GTKTREEITER(parent),
180
+ NUM2INT(position));
181
+ iter.user_data3 = model;
182
+ ret = GTKTREEITER2RVAL(&iter);
183
+ G_CHILD_ADD(self, ret);
184
+ #endif
185
+ }
186
+
187
+ return ret;
188
+ }
189
+
190
+
191
+ static VALUE
192
+ tstore_insert_before(self, parent, sibling)
193
+ VALUE self, parent, sibling;
194
+ {
195
+ VALUE ret;
196
+ GtkTreeIter iter;
197
+ GtkTreeStore* model = _SELF(self);
198
+ gtk_tree_store_insert_before(model, &iter,
199
+ NIL_P(parent) ? NULL : RVAL2GTKTREEITER(parent),
200
+ NIL_P(sibling) ? NULL : RVAL2GTKTREEITER(sibling));
201
+ iter.user_data3 = model;
202
+ ret = GTKTREEITER2RVAL(&iter);
203
+ G_CHILD_ADD(self, ret);
204
+ return ret;
205
+ }
206
+
207
+ static VALUE
208
+ tstore_insert_after(self, parent, sibling)
209
+ VALUE self, parent, sibling;
210
+ {
211
+ VALUE ret;
212
+ GtkTreeIter iter;
213
+ GtkTreeStore* model = _SELF(self);
214
+ gtk_tree_store_insert_after(model, &iter,
215
+ NIL_P(parent) ? NULL : RVAL2GTKTREEITER(parent),
216
+ NIL_P(sibling) ? NULL : RVAL2GTKTREEITER(sibling));
217
+ iter.user_data3 = model;
218
+
219
+ ret = GTKTREEITER2RVAL(&iter);
220
+ G_CHILD_ADD(self, ret);
221
+ return ret;
222
+ }
223
+
224
+ /* The 2 following functions where implemented as TreeStore#insert
225
+ which will use a Hash instead of pairs of parameters
226
+
227
+ void gtk_tree_store_insert_with_values
228
+ (GtkTreeStore *tree_store,
229
+ GtkTreeIter *iter,
230
+ GtkTreeIter *parent,
231
+ gint position,
232
+ ...);
233
+
234
+ void gtk_tree_store_insert_with_valuesv
235
+ (GtkTreeStore *tree_store,
236
+ GtkTreeIter *iter,
237
+ GtkTreeIter *parent,
238
+ gint position,
239
+ gint *columns,
240
+ GValue *values,
241
+ gint n_values);
242
+
243
+ */
244
+
245
+ static VALUE
246
+ tstore_prepend(self, parent)
247
+ VALUE self, parent;
248
+ {
249
+ VALUE ret;
250
+ GtkTreeIter iter;
251
+ GtkTreeStore* model = _SELF(self);
252
+ gtk_tree_store_prepend(model, &iter,
253
+ NIL_P(parent)?NULL:RVAL2GTKTREEITER(parent));
254
+ iter.user_data3 = model;
255
+
256
+ ret = GTKTREEITER2RVAL(&iter);
257
+ G_CHILD_ADD(self, ret);
258
+ return ret;
259
+ }
260
+
261
+ static VALUE
262
+ tstore_append(self, parent)
263
+ VALUE self, parent;
264
+ {
265
+ VALUE ret;
266
+ GtkTreeIter iter;
267
+ GtkTreeStore* model = _SELF(self);
268
+ gtk_tree_store_append(model, &iter,
269
+ NIL_P(parent)?NULL:RVAL2GTKTREEITER(parent));
270
+ iter.user_data3 = model;
271
+
272
+ ret = GTKTREEITER2RVAL(&iter);
273
+ G_CHILD_ADD(self, ret);
274
+ return ret;
275
+ }
276
+
277
+ static VALUE
278
+ tstore_is_ancestor(self, iter, descendant)
279
+ VALUE self, iter, descendant;
280
+ {
281
+ return gtk_tree_store_is_ancestor(_SELF(self), RVAL2GTKTREEITER(iter),
282
+ RVAL2GTKTREEITER(descendant));
283
+ }
284
+
285
+ static VALUE
286
+ tstore_iter_depth(self, iter)
287
+ VALUE self, iter;
288
+ {
289
+ return INT2NUM(gtk_tree_store_iter_depth(_SELF(self), RVAL2GTKTREEITER(iter)));
290
+ }
291
+
292
+ static VALUE
293
+ tstore_clear(self)
294
+ VALUE self;
295
+ {
296
+ G_CHILD_REMOVE_ALL(self);
297
+ gtk_tree_store_clear(_SELF(self));
298
+ return self;
299
+ }
300
+ #if GTK_CHECK_VERSION(2,2,0)
301
+ static VALUE
302
+ tstore_iter_is_valid(self, iter)
303
+ VALUE self, iter;
304
+ {
305
+ return (NIL_P(iter)) ? Qfalse :
306
+ CBOOL2RVAL(gtk_tree_store_iter_is_valid(_SELF(self), RVAL2GTKTREEITER(iter)));
307
+ }
308
+ static VALUE
309
+ tstore_reorder(self, parent, new_order)
310
+ VALUE self, parent, new_order;
311
+ {
312
+ gint i;
313
+ gint len = RARRAY_LEN(new_order);
314
+ gint* gnew_order = g_new(gint, len);
315
+
316
+ for (i = 0; i < len; i++){
317
+ gnew_order[i] = NUM2INT(RARRAY_PTR(new_order)[i]);
318
+ }
319
+
320
+ gtk_tree_store_reorder(_SELF(self), RVAL2GTKTREEITER(parent), gnew_order);
321
+ g_free(gnew_order);
322
+ return self;
323
+ }
324
+ static VALUE
325
+ tstore_swap(self, iter1, iter2)
326
+ VALUE self, iter1, iter2;
327
+ {
328
+ gtk_tree_store_swap(_SELF(self), RVAL2GTKTREEITER(iter1), RVAL2GTKTREEITER(iter2));
329
+ return self;
330
+ }
331
+ static VALUE
332
+ tstore_move_before(self, iter, position)
333
+ VALUE self, iter, position;
334
+ {
335
+ gtk_tree_store_move_before(_SELF(self), RVAL2GTKTREEITER(iter),
336
+ NIL_P(position) ? NULL : RVAL2GTKTREEITER(position));
337
+ return self;
338
+ }
339
+ static VALUE
340
+ tstore_move_after(self, iter, position)
341
+ VALUE self, iter, position;
342
+ {
343
+ gtk_tree_store_move_after(_SELF(self), RVAL2GTKTREEITER(iter),
344
+ NIL_P(position) ? NULL : RVAL2GTKTREEITER(position));
345
+ return self;
346
+ }
347
+ #endif
348
+
349
+ void
350
+ Init_gtk_tree_store()
351
+ {
352
+ VALUE ts = G_DEF_CLASS(GTK_TYPE_TREE_STORE, "TreeStore", mGtk);
353
+
354
+ rbgtk_register_treeiter_set_value_func(GTK_TYPE_TREE_STORE,
355
+ (rbgtkiter_set_value_func)&gtk_tree_store_set_value);
356
+
357
+ rb_define_method(ts, "initialize", tstore_initialize, -1);
358
+ rb_define_method(ts, "set_column_types", tstore_set_column_types, -1);
359
+ rb_define_method(ts, "set_value", tstore_set_value, 3);
360
+ rb_define_method(ts, "remove", tstore_remove, 1);
361
+ rb_define_method(ts, "insert", tstore_insert, -1);
362
+ rb_define_method(ts, "insert_before", tstore_insert_before, 2);
363
+ rb_define_method(ts, "insert_after", tstore_insert_after, 2);
364
+ rb_define_method(ts, "prepend", tstore_prepend, 1);
365
+ rb_define_method(ts, "append", tstore_append, 1);
366
+ rb_define_method(ts, "ancestor?", tstore_is_ancestor, 2);
367
+ rb_define_method(ts, "iter_depth", tstore_iter_depth, 1);
368
+ rb_define_method(ts, "clear", tstore_clear, 0);
369
+ #if GTK_CHECK_VERSION(2,2,0)
370
+ rb_define_method(ts, "iter_is_valid?", tstore_iter_is_valid, 1);
371
+ rb_define_method(ts, "reorder", tstore_reorder, 2);
372
+ rb_define_method(ts, "swap", tstore_swap, 2);
373
+ rb_define_method(ts, "move_before", tstore_move_before, 2);
374
+ rb_define_method(ts, "move_after", tstore_move_after, 2);
375
+ #endif
376
+
377
+ }
378
+
379
+
@@ -0,0 +1,881 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtktreeview.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:32 $
8
+
9
+ Copyright (C) 2002-2005 Masao Mutoh
10
+ ************************************************/
11
+
12
+ #include "global.h"
13
+
14
+ #define _SELF(s) (GTK_TREE_VIEW(RVAL2GOBJ(s)))
15
+ #define TREEVIEW_COL(c) (GTK_TREE_VIEW_COLUMN(RVAL2GOBJ(c)))
16
+ #define RVAL2CELLRENDERER(c) (GTK_CELL_RENDERER(RVAL2GOBJ(c)))
17
+
18
+ static ID id_model;
19
+ static ID id_selection;
20
+
21
+ static VALUE
22
+ treeview_initialize(argc, argv, self)
23
+ int argc;
24
+ VALUE *argv;
25
+ VALUE self;
26
+ {
27
+ VALUE model;
28
+ GtkWidget *widget;
29
+
30
+ if (rb_scan_args(argc, argv, "01", &model) == 1) {
31
+ G_CHILD_SET(self, id_model, model);
32
+ widget = gtk_tree_view_new_with_model(GTK_TREE_MODEL(RVAL2GOBJ(model)));
33
+ }
34
+ else {
35
+ widget = gtk_tree_view_new();
36
+ }
37
+
38
+ RBGTK_INITIALIZE(self, widget);
39
+ return Qnil;
40
+ }
41
+
42
+ static VALUE
43
+ treeview_get_selection(self)
44
+ VALUE self;
45
+ {
46
+ VALUE ret = GOBJ2RVAL(gtk_tree_view_get_selection(_SELF(self)));
47
+ G_CHILD_SET(self, id_selection, ret);
48
+ return ret;
49
+ }
50
+
51
+ static VALUE
52
+ treeview_columns_autosize(self)
53
+ VALUE self;
54
+ {
55
+ gtk_tree_view_columns_autosize(_SELF(self));
56
+ return self;
57
+ }
58
+
59
+ static VALUE
60
+ treeview_append_column(self, column)
61
+ VALUE self, column;
62
+ {
63
+ G_CHILD_ADD(self, column);
64
+ return INT2NUM(gtk_tree_view_append_column(_SELF(self),
65
+ TREEVIEW_COL(column)));
66
+ }
67
+
68
+ static VALUE
69
+ treeview_remove_column(self, column)
70
+ VALUE self, column;
71
+ {
72
+ G_CHILD_REMOVE(self, column);
73
+ return INT2NUM(gtk_tree_view_remove_column(_SELF(self),
74
+ TREEVIEW_COL(column)));
75
+ }
76
+
77
+ static void
78
+ cell_data_func(column, cell, model, iter, func)
79
+ GtkTreeViewColumn* column;
80
+ GtkCellRenderer* cell;
81
+ GtkTreeModel* model;
82
+ GtkTreeIter* iter;
83
+ gpointer func;
84
+ {
85
+ iter->user_data3 = model;
86
+ rb_funcall((VALUE)func, id_call, 4, GOBJ2RVAL(column),
87
+ GOBJ2RVAL(cell), GOBJ2RVAL(model),
88
+ GTKTREEITER2RVAL(iter));
89
+ }
90
+
91
+ static VALUE
92
+ treeview_insert_column(argc, argv, self)
93
+ int argc;
94
+ VALUE* argv;
95
+ VALUE self;
96
+ {
97
+ VALUE args[4];
98
+
99
+ rb_scan_args(argc, argv, "22", /* NORMAL ATTRIBUTES DATA_FUNC */
100
+ &args[0], /* column position position */
101
+ &args[1], /* position title title */
102
+ &args[2], /* renderer renderer */
103
+ &args[3]); /* attributes */
104
+
105
+ if (argc == 2) {
106
+ G_CHILD_ADD(self, args[0]);
107
+ return INT2NUM(gtk_tree_view_insert_column(_SELF(self),
108
+ TREEVIEW_COL(args[0]),
109
+ NUM2INT(args[1])));
110
+ } else if (argc == 3) {
111
+ int ret;
112
+ VALUE func = rb_block_proc();
113
+
114
+ G_RELATIVE(self, func);
115
+ ret = gtk_tree_view_insert_column_with_data_func(_SELF(self),
116
+ NUM2INT(args[0]),
117
+ RVAL2CSTR(args[1]),
118
+ RVAL2CELLRENDERER(args[2]),
119
+ (GtkTreeCellDataFunc)cell_data_func,
120
+ (gpointer)func,
121
+ NULL);
122
+ return INT2NUM(ret);
123
+ } else if (argc == 4) {
124
+ int i;
125
+ int col;
126
+ int ret;
127
+ const gchar *name;
128
+ VALUE ary;
129
+ GtkCellRenderer* renderer = RVAL2CELLRENDERER(args[2]);
130
+
131
+ GtkTreeViewColumn* column = gtk_tree_view_column_new();
132
+
133
+ Check_Type(args[3], T_HASH);
134
+
135
+ G_CHILD_ADD(self, args[2]);
136
+ G_CHILD_ADD(self, args[3]);
137
+
138
+ gtk_tree_view_column_set_title(column, RVAL2CSTR(args[1]));
139
+ gtk_tree_view_column_pack_start(column, renderer, TRUE);
140
+
141
+ ret = gtk_tree_view_insert_column(_SELF(self), column, NUM2INT(args[0]));
142
+ ary = rb_funcall(args[3], rb_intern("to_a"), 0);
143
+ for (i = 0; i < RARRAY_LEN(ary); i++) {
144
+ VALUE val = RARRAY_PTR(RARRAY_PTR(ary)[i])[0];
145
+ if (SYMBOL_P(val)) {
146
+ name = rb_id2name(SYM2ID(val));
147
+ } else {
148
+ name = RVAL2CSTR(val);
149
+ }
150
+ col = NUM2INT(RARRAY_PTR(RARRAY_PTR(ary)[i])[1]);
151
+ gtk_tree_view_column_add_attribute(column,
152
+ renderer,
153
+ name, col);
154
+ }
155
+ return INT2NUM(ret);
156
+ } else {
157
+ rb_raise(rb_eArgError, "Wrong number of arguments: %d", argc);
158
+ }
159
+
160
+ return Qnil;
161
+ }
162
+
163
+ static VALUE
164
+ treeview_get_column(self, num)
165
+ VALUE self, num;
166
+ {
167
+ return GOBJ2RVAL(gtk_tree_view_get_column(_SELF(self), NUM2INT(num)));
168
+ }
169
+
170
+ static VALUE
171
+ treeview_get_columns(self)
172
+ VALUE self;
173
+ {
174
+ return GLIST2ARYF(gtk_tree_view_get_columns(_SELF(self)));
175
+ }
176
+
177
+ static VALUE
178
+ treeview_move_column_after(self, column, base_column)
179
+ VALUE self, column, base_column;
180
+ {
181
+ gtk_tree_view_move_column_after(_SELF(self), TREEVIEW_COL(column),
182
+ NIL_P(base_column) ? NULL : TREEVIEW_COL(base_column));
183
+ return self;
184
+ }
185
+
186
+ static gboolean
187
+ column_drop_func(treeview, column, prev_column, next_column, func)
188
+ GtkTreeView* treeview;
189
+ GtkTreeViewColumn* column;
190
+ GtkTreeViewColumn* prev_column;
191
+ GtkTreeViewColumn* next_column;
192
+ gpointer func;
193
+ {
194
+ return RVAL2CBOOL(rb_funcall((VALUE)func, id_call, 4, GOBJ2RVAL(treeview),
195
+ GOBJ2RVAL(column), GOBJ2RVAL(prev_column),
196
+ GOBJ2RVAL(next_column)));
197
+ }
198
+
199
+ static VALUE
200
+ treeview_set_column_drag_function(self)
201
+ VALUE self;
202
+ {
203
+ VALUE func = rb_block_proc();
204
+ G_RELATIVE(self, func);
205
+ gtk_tree_view_set_column_drag_function(_SELF(self),
206
+ (GtkTreeViewColumnDropFunc)column_drop_func,
207
+ (gpointer)func, NULL);
208
+ return self;
209
+ }
210
+
211
+ static VALUE
212
+ treeview_scroll_to_point(self, x, y)
213
+ VALUE self, x, y;
214
+ {
215
+ gtk_tree_view_scroll_to_point(_SELF(self), NUM2INT(x), NUM2INT(y));
216
+ return self;
217
+ }
218
+
219
+ static VALUE
220
+ treeview_scroll_to_cell(self, path, column, use_align, row_align, col_align)
221
+ VALUE self, path, column, use_align, row_align, col_align;
222
+ {
223
+ gtk_tree_view_scroll_to_cell(_SELF(self),
224
+ NIL_P(path) ? NULL : RVAL2GTKTREEPATH(path),
225
+ NIL_P(column) ? NULL : TREEVIEW_COL(column),
226
+ RVAL2CBOOL(use_align),
227
+ NUM2DBL(row_align), NUM2DBL(col_align));
228
+ return self;
229
+ }
230
+
231
+ static VALUE
232
+ treeview_set_cursor(self, path, focus_column, start_editing)
233
+ VALUE self, path, focus_column, start_editing;
234
+ {
235
+ gtk_tree_view_set_cursor(_SELF(self), RVAL2GTKTREEPATH(path),
236
+ NIL_P(focus_column) ? NULL : TREEVIEW_COL(focus_column),
237
+ RVAL2CBOOL(start_editing));
238
+ return self;
239
+ }
240
+
241
+ static VALUE
242
+ treeview_get_cursor(self)
243
+ VALUE self;
244
+ {
245
+ GtkTreePath* path;
246
+ GtkTreeViewColumn* focus_column;
247
+
248
+ gtk_tree_view_get_cursor(_SELF(self), &path, &focus_column);
249
+ return rb_ary_new3(2, path ? GTKTREEPATH2RVAL(path) : Qnil,
250
+ GOBJ2RVAL(focus_column));
251
+ }
252
+
253
+ static VALUE
254
+ treeview_row_activated(self, path, column)
255
+ VALUE self, path, column;
256
+ {
257
+ gtk_tree_view_row_activated(_SELF(self), RVAL2GTKTREEPATH(path),
258
+ TREEVIEW_COL(column));
259
+ return self;
260
+ }
261
+
262
+ static VALUE
263
+ treeview_expand_all(self)
264
+ VALUE self;
265
+ {
266
+ gtk_tree_view_expand_all(_SELF(self));
267
+ return self;
268
+ }
269
+
270
+ static VALUE
271
+ treeview_collapse_all(self)
272
+ VALUE self;
273
+ {
274
+ gtk_tree_view_collapse_all(_SELF(self));
275
+ return self;
276
+ }
277
+
278
+ static VALUE
279
+ treeview_expand_row(self, path, open_all)
280
+ VALUE self, path, open_all;
281
+ {
282
+ return CBOOL2RVAL(gtk_tree_view_expand_row(_SELF(self),
283
+ RVAL2GTKTREEPATH(path),
284
+ RVAL2CBOOL(open_all)));
285
+ }
286
+
287
+ #if GTK_CHECK_VERSION(2,2,0)
288
+ static VALUE
289
+ treeview_expand_to_path(self, path)
290
+ VALUE self, path;
291
+ {
292
+ gtk_tree_view_expand_to_path(_SELF(self), RVAL2GTKTREEPATH(path));
293
+ return self;
294
+ }
295
+ #endif
296
+
297
+ static VALUE
298
+ treeview_collapse_row(self, path)
299
+ VALUE self, path;
300
+ {
301
+ return CBOOL2RVAL(gtk_tree_view_collapse_row(_SELF(self),
302
+ RVAL2GTKTREEPATH(path)));
303
+ }
304
+
305
+ static void
306
+ mapping_func(treeview, path, func)
307
+ GtkTreeView* treeview;
308
+ GtkTreePath* path;
309
+ gpointer func;
310
+ {
311
+ rb_funcall((VALUE)func, id_call, 2, GOBJ2RVAL(treeview),
312
+ GTKTREEPATH2RVAL(path));
313
+ }
314
+
315
+ static VALUE
316
+ treeview_map_expanded_rows(self)
317
+ VALUE self;
318
+ {
319
+ VALUE func = rb_block_proc();
320
+ G_RELATIVE(self, func);
321
+ gtk_tree_view_map_expanded_rows(_SELF(self),
322
+ (GtkTreeViewMappingFunc)mapping_func,
323
+ (gpointer)func);
324
+ return self;
325
+ }
326
+
327
+ static VALUE
328
+ treeview_row_expanded(self, path)
329
+ VALUE self, path;
330
+ {
331
+ return CBOOL2RVAL(gtk_tree_view_row_expanded(_SELF(self),
332
+ RVAL2GTKTREEPATH(path)));
333
+ }
334
+
335
+ static VALUE
336
+ treeview_get_path_at_pos(self, x, y)
337
+ VALUE self, x, y;
338
+ {
339
+ GtkTreePath* path;
340
+ GtkTreeViewColumn* column;
341
+ gint cell_x, cell_y;
342
+ gboolean ret;
343
+
344
+ ret = gtk_tree_view_get_path_at_pos(_SELF(self),
345
+ NUM2INT(x), NUM2INT(y),
346
+ &path, &column, &cell_x, &cell_y);
347
+ return ret ? rb_ary_new3(4,
348
+ path ? GTKTREEPATH2RVAL(path) : Qnil,
349
+ column ? GOBJ2RVAL(column) : Qnil,
350
+ INT2NUM(cell_x), INT2NUM(cell_y)) : Qnil;
351
+ }
352
+
353
+ static VALUE
354
+ treeview_get_cell_area(self, path, column)
355
+ VALUE self, path, column;
356
+ {
357
+ GdkRectangle rect;
358
+ gtk_tree_view_get_cell_area(_SELF(self),
359
+ NIL_P(path) ? NULL : RVAL2GTKTREEPATH(path),
360
+ NIL_P(column) ? NULL : TREEVIEW_COL(column),
361
+ &rect);
362
+ return BOXED2RVAL(&rect, GDK_TYPE_RECTANGLE);
363
+ }
364
+
365
+ static VALUE
366
+ treeview_get_background_area(self, path, column)
367
+ VALUE self, path, column;
368
+ {
369
+ GdkRectangle rect;
370
+ gtk_tree_view_get_background_area(_SELF(self),
371
+ NIL_P(path) ? NULL : RVAL2GTKTREEPATH(path),
372
+ NIL_P(column) ? NULL : TREEVIEW_COL(column),
373
+ &rect);
374
+ return BOXED2RVAL(&rect, GDK_TYPE_RECTANGLE);
375
+ }
376
+
377
+ static VALUE
378
+ treeview_get_visible_rect(self)
379
+ VALUE self;
380
+ {
381
+ GdkRectangle rect;
382
+ gtk_tree_view_get_visible_rect(_SELF(self), &rect);
383
+ return BOXED2RVAL(&rect, GDK_TYPE_RECTANGLE);
384
+ }
385
+
386
+ #if GTK_CHECK_VERSION(2,8,0)
387
+ static VALUE
388
+ treeview_get_visible_range(self)
389
+ VALUE self;
390
+ {
391
+ GtkTreePath* start_path;
392
+ GtkTreePath* end_path;
393
+
394
+ gboolean valid_paths = gtk_tree_view_get_visible_range(_SELF(self), &start_path, &end_path);
395
+
396
+ return valid_paths ? rb_assoc_new(GTKTREEPATH2RVAL(start_path),
397
+ GTKTREEPATH2RVAL(end_path)) : Qnil;
398
+ }
399
+ #endif
400
+
401
+ static VALUE
402
+ treeview_get_bin_window(self)
403
+ VALUE self;
404
+ {
405
+ return GOBJ2RVAL(gtk_tree_view_get_bin_window(_SELF(self)));
406
+ }
407
+
408
+ static VALUE
409
+ treeview_widget_to_tree_coords(self, wx, wy)
410
+ VALUE self, wx, wy;
411
+ {
412
+ gint tx, ty;
413
+ gtk_tree_view_widget_to_tree_coords(_SELF(self),
414
+ NUM2INT(wx), NUM2INT(wy),
415
+ &tx, &ty);
416
+ return rb_ary_new3(2, INT2NUM(tx), INT2NUM(ty));
417
+ }
418
+
419
+ static VALUE
420
+ treeview_tree_to_widget_coords(self, tx, ty)
421
+ VALUE self, tx, ty;
422
+ {
423
+ gint wx, wy;
424
+ gtk_tree_view_tree_to_widget_coords(_SELF(self),
425
+ NUM2INT(tx), NUM2INT(ty),
426
+ &wx, &wy);
427
+ return rb_ary_new3(2, INT2NUM(wx), INT2NUM(wy));
428
+ }
429
+
430
+ #if GTK_CHECK_VERSION(2,12,0)
431
+ static VALUE
432
+ treeview_convert_bin_window_to_tree_coords(self, bx, by)
433
+ VALUE self, bx, by;
434
+ {
435
+ gint tx, ty;
436
+ gtk_tree_view_convert_bin_window_to_tree_coords(_SELF(self),
437
+ NUM2INT(bx), NUM2INT(by),
438
+ &tx, &ty);
439
+ return rb_ary_new3(2, INT2NUM(tx), INT2NUM(ty));
440
+ }
441
+ static VALUE
442
+ treeview_convert_bin_window_to_widget_coords(self, bx, by)
443
+ VALUE self, bx, by;
444
+ {
445
+ gint wx, wy;
446
+ gtk_tree_view_convert_bin_window_to_widget_coords(_SELF(self),
447
+ NUM2INT(bx), NUM2INT(by),
448
+ &wx, &wy);
449
+ return rb_ary_new3(2, INT2NUM(wx), INT2NUM(wy));
450
+ }
451
+
452
+ static VALUE
453
+ treeview_convert_tree_to_bin_window_coords(self, tx, ty)
454
+ VALUE self, tx, ty;
455
+ {
456
+ gint bx, by;
457
+ gtk_tree_view_convert_tree_to_bin_window_coords(_SELF(self),
458
+ NUM2INT(tx), NUM2INT(ty),
459
+ &bx, &by);
460
+ return rb_ary_new3(2, INT2NUM(bx), INT2NUM(by));
461
+ }
462
+ static VALUE
463
+ treeview_convert_tree_to_widget_coords(self, tx, ty)
464
+ VALUE self, tx, ty;
465
+ {
466
+ gint wx, wy;
467
+ gtk_tree_view_convert_tree_to_widget_coords(_SELF(self),
468
+ NUM2INT(tx), NUM2INT(ty),
469
+ &wx, &wy);
470
+ return rb_ary_new3(2, INT2NUM(wx), INT2NUM(wy));
471
+ }
472
+
473
+ static VALUE
474
+ treeview_convert_widget_to_bin_window_coords(self, wx, wy)
475
+ VALUE self, wx, wy;
476
+ {
477
+ gint bx, by;
478
+ gtk_tree_view_convert_widget_to_bin_window_coords(_SELF(self),
479
+ NUM2INT(wx), NUM2INT(wy),
480
+ &bx, &by);
481
+ return rb_ary_new3(2, INT2NUM(bx), INT2NUM(by));
482
+ }
483
+ static VALUE
484
+ treeview_convert_widget_to_tree_coords(self, wx, wy)
485
+ VALUE self, wx, wy;
486
+ {
487
+ gint tx, ty;
488
+ gtk_tree_view_convert_widget_to_tree_coords(_SELF(self),
489
+ NUM2INT(wx), NUM2INT(wy),
490
+ &tx, &ty);
491
+ return rb_ary_new3(2, INT2NUM(tx), INT2NUM(ty));
492
+ }
493
+ #endif
494
+
495
+ static VALUE
496
+ treeview_enable_model_drag_dest(self, targets, actions)
497
+ VALUE self, targets, actions;
498
+ {
499
+ const GtkTargetEntry* entries = rbgtk_get_target_entry(targets);
500
+ int num = RARRAY_LEN(targets);
501
+
502
+ gtk_tree_view_enable_model_drag_dest(_SELF(self), entries,
503
+ num, RVAL2GFLAGS(actions, GDK_TYPE_DRAG_ACTION));
504
+ return self;
505
+ }
506
+
507
+ static VALUE
508
+ treeview_enable_model_drag_source(self, start_button_mask, targets, actions)
509
+ VALUE self, start_button_mask, targets, actions;
510
+ {
511
+ GtkTargetEntry* entries = rbgtk_get_target_entry(targets);
512
+ if (entries){
513
+ gint num = RARRAY_LEN(targets);
514
+
515
+ gtk_tree_view_enable_model_drag_source(_SELF(self),
516
+ RVAL2GFLAGS(start_button_mask, GDK_TYPE_MODIFIER_TYPE),
517
+ entries, num,
518
+ RVAL2GFLAGS(actions, GDK_TYPE_DRAG_ACTION));
519
+ }
520
+ return self;
521
+ }
522
+
523
+ static VALUE
524
+ treeview_unset_rows_drag_source(self)
525
+ VALUE self;
526
+ {
527
+ gtk_tree_view_unset_rows_drag_source(_SELF(self));
528
+ return self;
529
+ }
530
+
531
+ static VALUE
532
+ treeview_unset_rows_drag_dest(self)
533
+ VALUE self;
534
+ {
535
+ gtk_tree_view_unset_rows_drag_dest(_SELF(self));
536
+ return self;
537
+ }
538
+
539
+ static VALUE
540
+ treeview_set_drag_dest_row(self, path, pos)
541
+ VALUE self, path, pos;
542
+ {
543
+ gtk_tree_view_set_drag_dest_row(_SELF(self),
544
+ NIL_P(path)?NULL:RVAL2GTKTREEPATH(path),
545
+ RVAL2GENUM(pos, GTK_TYPE_TREE_VIEW_DROP_POSITION));
546
+ return self;
547
+ }
548
+
549
+ static VALUE
550
+ treeview_get_drag_dest_row(self)
551
+ VALUE self;
552
+ {
553
+ GtkTreePath* path = NULL;
554
+ GtkTreeViewDropPosition pos;
555
+ gtk_tree_view_get_drag_dest_row(_SELF(self), &path, &pos);
556
+ return rb_ary_new3(2, path ? GTKTREEPATH2RVAL(path) : Qnil,
557
+ GENUM2RVAL(pos, GTK_TYPE_TREE_VIEW_DROP_POSITION));
558
+ }
559
+
560
+ static VALUE
561
+ treeview_get_dest_row_at_pos(self, drag_x, drag_y)
562
+ VALUE self;
563
+ {
564
+ GtkTreePath* path;
565
+ GtkTreeViewDropPosition pos;
566
+ gboolean ret;
567
+
568
+ ret = gtk_tree_view_get_dest_row_at_pos(_SELF(self),
569
+ NUM2INT(drag_x), NUM2INT(drag_y),
570
+ &path, &pos);
571
+ return ret ? rb_ary_new3(2, path ? GTKTREEPATH2RVAL(path) : Qnil,
572
+ GENUM2RVAL(pos, GTK_TYPE_TREE_VIEW_DROP_POSITION)) : Qnil;
573
+ }
574
+
575
+ static VALUE
576
+ treeview_create_row_drag_icon(self, path)
577
+ VALUE self, path;
578
+ {
579
+ return GOBJ2RVAL(gtk_tree_view_create_row_drag_icon(_SELF(self),
580
+ RVAL2GTKTREEPATH(path)));
581
+ }
582
+
583
+ /*
584
+ We don't need this.
585
+ GtkTreeViewSearchEqualFunc gtk_tree_view_get_search_equal_func
586
+ (GtkTreeView *tree_view);
587
+ */
588
+
589
+ static gboolean
590
+ search_equal_func(model, column, key, iter, func)
591
+ GtkTreeModel* model;
592
+ gint column;
593
+ const gchar* key;
594
+ GtkTreeIter* iter;
595
+ gpointer func;
596
+ {
597
+ iter->user_data3 = model;
598
+ return RVAL2CBOOL(rb_funcall((VALUE)func, id_call, 4,
599
+ GOBJ2RVAL(model), INT2NUM(column),
600
+ CSTR2RVAL(key), GTKTREEITER2RVAL(iter)));
601
+ }
602
+
603
+ static VALUE
604
+ treeview_set_search_equal_func(self)
605
+ VALUE self;
606
+ {
607
+ VALUE func = rb_block_proc();
608
+ G_RELATIVE(self, func);
609
+ gtk_tree_view_set_search_equal_func(_SELF(self),
610
+ (GtkTreeViewSearchEqualFunc)search_equal_func,
611
+ (gpointer)func, NULL);
612
+ return self;
613
+ }
614
+
615
+
616
+
617
+ /*
618
+ * Optional Signals
619
+ */
620
+ static VALUE
621
+ treeview_signal_func(num, values)
622
+ guint num;
623
+ const GValue* values;
624
+ {
625
+ GtkTreeView* view = g_value_get_object(&values[0]);
626
+ GtkTreeIter* iter = g_value_get_boxed(&values[1]);
627
+ iter->user_data3 = gtk_tree_view_get_model(view);
628
+
629
+ return rb_ary_new3(3, GOBJ2RVAL(view), GTKTREEITER2RVAL(iter), GVAL2RVAL(&values[2]));
630
+ }
631
+
632
+ #if GTK_CHECK_VERSION(2,2,0)
633
+ static VALUE
634
+ treeview_set_cursor_on_cell(self, path, focus_column, focus_cell, start_editing)
635
+ VALUE self, path, focus_column, focus_cell, start_editing;
636
+ {
637
+ gtk_tree_view_set_cursor_on_cell(_SELF(self), RVAL2GTKTREEPATH(path),
638
+ NIL_P(focus_column) ? NULL : TREEVIEW_COL(focus_column),
639
+ NIL_P(focus_cell) ? NULL : GTK_CELL_RENDERER(RVAL2GOBJ(focus_cell)),
640
+ RVAL2CBOOL(start_editing));
641
+ return self;
642
+ }
643
+ #endif
644
+
645
+ /* Defined as Property.
646
+ gboolean gtk_tree_view_get_fixed_height_mode
647
+ (GtkTreeView *tree_view);
648
+ void gtk_tree_view_set_fixed_height_mode
649
+ (GtkTreeView *tree_view,
650
+ gboolean enable);
651
+ gboolean gtk_tree_view_get_hover_selection
652
+ (GtkTreeView *tree_view);
653
+ void gtk_tree_view_set_hover_selection
654
+ (GtkTreeView *tree_view,
655
+ gboolean hover);
656
+ gboolean gtk_tree_view_get_hover_expand (GtkTreeView *tree_view);
657
+ void gtk_tree_view_set_hover_expand (GtkTreeView *tree_view,
658
+ gboolean expand);
659
+ */
660
+
661
+ /* How can I implement this?
662
+ GtkTreeViewRowSeparatorFunc gtk_tree_view_get_row_separator_func
663
+ (GtkTreeView *tree_view);
664
+ */
665
+
666
+ #if GTK_CHECK_VERSION(2,6,0)
667
+ static gboolean
668
+ row_separator_func(model, iter, func)
669
+ GtkTreeModel* model;
670
+ GtkTreeIter* iter;
671
+ gpointer* func;
672
+ {
673
+ VALUE ret;
674
+ iter->user_data3 = model;
675
+ ret = rb_funcall((VALUE)func, id_call, 2, GOBJ2RVAL(model),
676
+ GTKTREEITER2RVAL(iter));
677
+ return CBOOL2RVAL(ret);
678
+ }
679
+
680
+ static VALUE
681
+ treeview_set_row_separator_func(self)
682
+ VALUE self;
683
+ {
684
+ VALUE func = rb_block_proc();
685
+
686
+ G_RELATIVE(self, func);
687
+ gtk_tree_view_set_row_separator_func(_SELF(self),
688
+ (GtkTreeViewRowSeparatorFunc)row_separator_func,
689
+ (gpointer)func,
690
+ (GtkDestroyNotify)NULL);
691
+ return self;
692
+ }
693
+ #endif
694
+
695
+ #if GTK_CHECK_VERSION(2,10,0)
696
+ static VALUE
697
+ treeview_get_search_entry(self)
698
+ VALUE self;
699
+ {
700
+ return GOBJ2RVAL(gtk_tree_view_get_search_entry(_SELF(self)));
701
+ }
702
+
703
+ static VALUE
704
+ treeview_set_search_entry(self, entry)
705
+ VALUE self, entry;
706
+ {
707
+ gtk_tree_view_set_search_entry(_SELF(self), RVAL2GOBJ(entry));
708
+ return self;
709
+ }
710
+
711
+ /* Can't define this.
712
+ GtkTreeViewSearchPositionFunc gtk_tree_view_get_search_position_func
713
+ (GtkTreeView *tree_view);
714
+ */
715
+
716
+ struct callback_arg
717
+ {
718
+ VALUE callback;
719
+ VALUE tree_view;
720
+ VALUE search_dialog;
721
+ };
722
+
723
+ static VALUE
724
+ invoke_callback(VALUE data)
725
+ {
726
+ struct callback_arg *arg = (struct callback_arg *)data;
727
+ rb_funcall(arg->callback, id_call, 2, arg->tree_view, arg->search_dialog);
728
+ return Qnil;
729
+ }
730
+
731
+ static void
732
+ search_position_func(tree_view, search_dialog, func)
733
+ GtkTreeView* tree_view;
734
+ GtkWidget* search_dialog;
735
+ gpointer func;
736
+ {
737
+ struct callback_arg arg;
738
+
739
+ arg.callback = (VALUE)func;
740
+ arg.tree_view = GOBJ2RVAL(tree_view);
741
+ arg.search_dialog = GOBJ2RVAL(search_dialog);
742
+ G_PROTECT_CALLBACK(invoke_callback, &arg);
743
+ }
744
+
745
+ static void
746
+ remove_callback_reference(gpointer data)
747
+ {
748
+ G_CHILD_REMOVE(mGtk, (VALUE)data);
749
+ }
750
+
751
+
752
+ static VALUE
753
+ treeview_set_search_position_func(self)
754
+ VALUE self;
755
+ {
756
+ VALUE func = rb_block_proc();
757
+ G_CHILD_ADD(mGtk, func);
758
+ gtk_tree_view_set_search_position_func(_SELF(self),
759
+ (GtkTreeViewSearchPositionFunc)search_position_func,
760
+ (gpointer)func,
761
+ (GDestroyNotify)remove_callback_reference);
762
+ return self;
763
+ }
764
+
765
+ #endif
766
+ /* Defined as properties
767
+ gboolean gtk_tree_view_get_headers_clickable
768
+ (GtkTreeView *tree_view);
769
+ void gtk_tree_view_set_headers_clickable
770
+ (GtkTreeView *tree_view,
771
+ gboolean setting);
772
+ gboolean gtk_tree_view_get_rubber_banding
773
+ (GtkTreeView *tree_view);
774
+ void gtk_tree_view_set_rubber_banding
775
+ (GtkTreeView *tree_view,
776
+ gboolean enable);
777
+ gboolean gtk_tree_view_get_enable_tree_lines
778
+ (GtkTreeView *tree_view);
779
+ void gtk_tree_view_set_enable_tree_lines
780
+ (GtkTreeView *tree_view,
781
+ gboolean enabled);
782
+
783
+ // Use Gtk::TreeView#enable_grid_lines, #set_enable_grid_lines instead.
784
+ GtkTreeViewGridLines gtk_tree_view_get_grid_lines
785
+ (GtkTreeView *tree_view);
786
+
787
+ void gtk_tree_view_set_grid_lines (GtkTreeView *tree_view,
788
+ GtkTreeViewGridLines grid_lines);
789
+ */
790
+
791
+ void
792
+ Init_gtk_treeview()
793
+ {
794
+ VALUE gTv = G_DEF_CLASS(GTK_TYPE_TREE_VIEW, "TreeView", mGtk);
795
+
796
+ id_selection = rb_intern("selection");
797
+ id_model = rb_intern("model");
798
+
799
+ rb_define_method(gTv, "initialize", treeview_initialize, -1);
800
+ rb_define_method(gTv, "selection", treeview_get_selection, 0);
801
+ rb_define_method(gTv, "columns_autosize", treeview_columns_autosize, 0);
802
+ rb_define_method(gTv, "append_column", treeview_append_column, 1);
803
+ rb_define_method(gTv, "remove_column", treeview_remove_column, 1);
804
+ rb_define_method(gTv, "insert_column", treeview_insert_column, -1);
805
+ rb_define_method(gTv, "get_column", treeview_get_column, 1);
806
+ rb_define_method(gTv, "columns", treeview_get_columns, 0);
807
+ rb_define_method(gTv, "move_column_after", treeview_move_column_after, 2);
808
+ rb_define_method(gTv, "set_column_drag_function", treeview_set_column_drag_function, 0);
809
+ rb_define_method(gTv, "scroll_to_point", treeview_scroll_to_point, 2);
810
+ rb_define_method(gTv, "scroll_to_cell", treeview_scroll_to_cell, 5);
811
+ rb_define_method(gTv, "set_cursor", treeview_set_cursor, 3);
812
+ rb_define_method(gTv, "cursor", treeview_get_cursor, 0);
813
+ rb_define_method(gTv, "row_activated", treeview_row_activated, 2);
814
+ rb_define_method(gTv, "expand_all", treeview_expand_all, 0);
815
+ rb_define_method(gTv, "collapse_all", treeview_collapse_all, 0);
816
+ rb_define_method(gTv, "expand_row", treeview_expand_row, 2);
817
+ rb_define_method(gTv, "collapse_row", treeview_collapse_row, 1);
818
+ #if GTK_CHECK_VERSION(2,2,0)
819
+ rb_define_method(gTv, "expand_to_path", treeview_expand_to_path, 1);
820
+ #endif
821
+ rb_define_method(gTv, "map_expanded_rows", treeview_map_expanded_rows, 0);
822
+ rb_define_method(gTv, "row_expanded?", treeview_row_expanded, 1);
823
+ rb_define_method(gTv, "get_path_at_pos", treeview_get_path_at_pos, 2);
824
+ rb_define_alias(gTv, "get_path", "get_path_at_pos");
825
+ rb_define_method(gTv, "get_cell_area", treeview_get_cell_area, 2);
826
+ rb_define_method(gTv, "get_background_area", treeview_get_background_area, 2);
827
+ rb_define_method(gTv, "visible_rect", treeview_get_visible_rect, 0);
828
+ #if GTK_CHECK_VERSION(2,8,0)
829
+ rb_define_method(gTv, "visible_range", treeview_get_visible_range, 0);
830
+ #endif
831
+
832
+ rb_define_method(gTv, "bin_window", treeview_get_bin_window, 0);
833
+ rb_define_method(gTv, "widget_to_tree_coords", treeview_widget_to_tree_coords, 2);
834
+ rb_define_method(gTv, "tree_to_widget_coords", treeview_tree_to_widget_coords, 2);
835
+ #if GTK_CHECK_VERSION(2,12,0)
836
+ rb_define_method(gTv, "convert_bin_window_to_tree_coords", treeview_convert_bin_window_to_tree_coords, 2);
837
+ rb_define_method(gTv, "convert_bin_window_to_widget_coords", treeview_convert_bin_window_to_widget_coords, 2);
838
+ rb_define_method(gTv, "convert_tree_to_bin_window_coords", treeview_convert_tree_to_bin_window_coords, 2);
839
+ rb_define_method(gTv, "convert_tree_to_widget_coords", treeview_convert_tree_to_widget_coords, 2);
840
+ rb_define_method(gTv, "convert_widget_to_bin_window_coords", treeview_convert_widget_to_bin_window_coords, 2);
841
+ rb_define_method(gTv, "convert_widget_to_tree_coords", treeview_convert_widget_to_tree_coords, 2);
842
+ #endif
843
+ rb_define_method(gTv, "enable_model_drag_dest", treeview_enable_model_drag_dest, 2);
844
+ rb_define_method(gTv, "enable_model_drag_source", treeview_enable_model_drag_source, 3);
845
+ rb_define_method(gTv, "unset_rows_drag_source", treeview_unset_rows_drag_source, 0);
846
+ rb_define_method(gTv, "unset_rows_drag_dest", treeview_unset_rows_drag_dest, 0);
847
+ rb_define_method(gTv, "set_drag_dest_row", treeview_set_drag_dest_row, 2);
848
+ rb_define_method(gTv, "drag_dest_row", treeview_get_drag_dest_row, 0);
849
+ rb_define_method(gTv, "get_dest_row_at_pos", treeview_get_dest_row_at_pos, 2);
850
+ rb_define_alias(gTv, "get_dest_row", "get_dest_row_at_pos");
851
+ rb_define_method(gTv, "create_row_drag_icon", treeview_create_row_drag_icon, 1);
852
+ rb_define_method(gTv, "set_search_equal_func", treeview_set_search_equal_func, 0);
853
+ #if GTK_CHECK_VERSION(2,2,0)
854
+ rb_define_method(gTv, "set_cursor_on_cell", treeview_set_cursor_on_cell, 4);
855
+ #endif
856
+
857
+ #if GTK_CHECK_VERSION(2,6,0)
858
+ rb_define_method(gTv, "set_row_separator_func", treeview_set_row_separator_func, 0);
859
+ #endif
860
+ #if GTK_CHECK_VERSION(2,10,0)
861
+ rb_define_method(gTv, "search_entry", treeview_get_search_entry, 0);
862
+ rb_define_method(gTv, "set_search_entry", treeview_set_search_entry, 1);
863
+ rb_define_method(gTv, "set_search_position_func", treeview_set_search_position_func, 0);
864
+ #endif
865
+
866
+ /* Constants */
867
+ G_DEF_CLASS(GTK_TYPE_TREE_VIEW_DROP_POSITION, "DropPosition", gTv);
868
+ G_DEF_CONSTANTS(gTv, GTK_TYPE_TREE_VIEW_DROP_POSITION, "GTK_TREE_VIEW_");
869
+
870
+ #if GTK_CHECK_VERSION(2,10,0)
871
+ /* GtkTreeViewGridLines */
872
+ G_DEF_CLASS(GTK_TYPE_TREE_VIEW_GRID_LINES, "GridLines", gTv);
873
+ G_DEF_CONSTANTS(gTv, GTK_TYPE_TREE_VIEW_GRID_LINES, "GTK_TREE_VIEW_");
874
+ #endif
875
+
876
+ /* Option Signals */
877
+ G_DEF_SIGNAL_FUNC(gTv, "row-collapsed", (GValToRValSignalFunc)treeview_signal_func);
878
+ G_DEF_SIGNAL_FUNC(gTv, "row-expanded", (GValToRValSignalFunc)treeview_signal_func);
879
+ G_DEF_SIGNAL_FUNC(gTv, "test-collapse-row", (GValToRValSignalFunc)treeview_signal_func);
880
+ G_DEF_SIGNAL_FUNC(gTv, "test-expand-row", (GValToRValSignalFunc)treeview_signal_func);
881
+ }