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,209 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtktextattributes.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:32 $
8
+
9
+ Copyright (C) 2002-2004 Ruby-GNOME2 Project Team
10
+ Copyright (C) 2002,2003 OGASAWARA, Takeshi
11
+ ************************************************/
12
+ #include "global.h"
13
+
14
+ #define _SELF(s) ((GtkTextAttributes*)RVAL2BOXED(s, GTK_TYPE_TEXT_ATTRIBUTES))
15
+
16
+ /***********************************************/
17
+ #define ATTR_INT(name)\
18
+ static VALUE \
19
+ txt_attr_int_ ## name (self)\
20
+ VALUE self;\
21
+ {\
22
+ return INT2NUM(_SELF(self)->name);\
23
+ }\
24
+ static VALUE \
25
+ txt_attr_int_set_ ## name (self, val)\
26
+ VALUE self, val;\
27
+ {\
28
+ _SELF(self)->name = NUM2INT(val); \
29
+ return self;\
30
+ }
31
+
32
+ #define ATTR_BOOL(name)\
33
+ static VALUE \
34
+ txt_attr_bool_ ## name (self)\
35
+ VALUE self;\
36
+ {\
37
+ return CBOOL2RVAL(_SELF(self)->name);\
38
+ }\
39
+ static VALUE \
40
+ txt_attr_bool_set_ ## name (self, val)\
41
+ VALUE self, val;\
42
+ {\
43
+ _SELF(self)->name = RVAL2CBOOL(val);\
44
+ return self;\
45
+ }
46
+
47
+ #define ATTR_FLAGS(name, gtype)\
48
+ static VALUE \
49
+ txt_attr_flags_ ## name (self)\
50
+ VALUE self;\
51
+ {\
52
+ return GFLAGS2RVAL(_SELF(self)->name, gtype);\
53
+ }\
54
+ static VALUE \
55
+ txt_attr_flags_set_ ## name (self, val)\
56
+ VALUE self, val;\
57
+ {\
58
+ _SELF(self)->name = RVAL2GFLAGS(val, gtype);\
59
+ return self;\
60
+ }
61
+
62
+ #define ATTR_ENUM(name, gtype)\
63
+ static VALUE \
64
+ txt_attr_enums_ ## name (self)\
65
+ VALUE self;\
66
+ {\
67
+ return GENUM2RVAL(_SELF(self)->name, gtype);\
68
+ }\
69
+ static VALUE \
70
+ txt_attr_enums_set_ ## name (self, val)\
71
+ VALUE self, val;\
72
+ {\
73
+ _SELF(self)->name = RVAL2GENUM(val, gtype);\
74
+ return self;\
75
+ }
76
+
77
+ #define ATTR_BOXED(name, gtype)\
78
+ static VALUE \
79
+ txt_attr_boxed_ ## name (self)\
80
+ VALUE self;\
81
+ {\
82
+ VALUE val; \
83
+ if (_SELF(self)->name == NULL) return Qnil;\
84
+ val = BOXED2RVAL(_SELF(self)->name, gtype);\
85
+ G_CHILD_SET(self, rb_intern(G_STRINGIFY(name)), val);\
86
+ return val;\
87
+ }\
88
+ static VALUE \
89
+ txt_attr_boxed_set_ ## name (self, val)\
90
+ VALUE self, val;\
91
+ {\
92
+ G_CHILD_SET(self, rb_intern(G_STRINGIFY(name)), val);\
93
+ _SELF(self)->name = RVAL2BOXED(val, gtype);\
94
+ return self;\
95
+ }
96
+
97
+ #define DEFINE_ACCESSOR(gt, type, name) \
98
+ rb_define_method(gt, G_STRINGIFY(name), txt_attr_ ## type ## _## name, 0);\
99
+ rb_define_method(gt, G_STRINGIFY(set_ ## name), txt_attr_ ## type ## _set_## name, 1);
100
+
101
+ /***********************************************/
102
+ static VALUE
103
+ txt_attr_boxed_appearance(self)
104
+ VALUE self;
105
+ {
106
+ GtkTextAppearance app = _SELF(self)->appearance;
107
+ return BOXED2RVAL(&app, GTK_TYPE_TEXT_APPEARANCE);
108
+ }
109
+ static VALUE
110
+ txt_attr_boxed_set_appearance(self, val)
111
+ VALUE self, val;
112
+ {
113
+ GtkTextAppearance* app = (GtkTextAppearance*)RVAL2BOXED(val, GTK_TYPE_TEXT_APPEARANCE);
114
+ _SELF(self)->appearance = *app;
115
+ return self;
116
+ }
117
+
118
+ ATTR_ENUM(justification, GTK_TYPE_JUSTIFICATION);
119
+ ATTR_ENUM(direction, GTK_TYPE_DIRECTION_TYPE);
120
+ ATTR_BOXED(font, PANGO_TYPE_FONT_DESCRIPTION);
121
+
122
+ static VALUE
123
+ txt_attr_double_font_scale(self)
124
+ VALUE self;
125
+ {
126
+ return rb_float_new(_SELF(self)->font_scale);
127
+ }
128
+ static VALUE
129
+ txt_attr_double_set_font_scale(self, val)
130
+ VALUE self, val;
131
+ {
132
+ _SELF(self)->font_scale = NUM2DBL(val);
133
+ return self;
134
+ }
135
+
136
+ ATTR_INT(left_margin);
137
+ ATTR_INT(indent);
138
+ ATTR_INT(right_margin);
139
+ ATTR_INT(pixels_above_lines);
140
+ ATTR_INT(pixels_below_lines);
141
+ ATTR_INT(pixels_inside_wrap);
142
+
143
+ ATTR_BOXED(tabs, PANGO_TYPE_TAB_ARRAY);
144
+
145
+ ATTR_ENUM(wrap_mode, GTK_TYPE_WRAP_MODE);
146
+ ATTR_BOXED(language, PANGO_TYPE_LANGUAGE);
147
+
148
+ ATTR_BOOL(invisible);
149
+ ATTR_BOOL(bg_full_height);
150
+ ATTR_BOOL(editable);
151
+ ATTR_BOOL(realized);
152
+
153
+ /***********************************************/
154
+
155
+ static VALUE
156
+ txt_attr_initialize(self)
157
+ VALUE self;
158
+ {
159
+ GtkTextAttributes *attr;
160
+
161
+ attr = gtk_text_attributes_new();
162
+ G_INITIALIZE(self, attr);
163
+ return Qnil;
164
+ }
165
+
166
+ static VALUE
167
+ txt_attr_copy_values(self, dest)
168
+ VALUE self;
169
+ {
170
+ gtk_text_attributes_copy_values(_SELF(self), _SELF(dest));
171
+ return self;
172
+ }
173
+
174
+ void
175
+ Init_txt_attr()
176
+ {
177
+ VALUE gTextAttributes = G_DEF_CLASS(GTK_TYPE_TEXT_ATTRIBUTES, "TextAttributes", mGtk);
178
+
179
+ rb_define_method(gTextAttributes, "initialize", txt_attr_initialize, 0);
180
+ rb_define_method(gTextAttributes, "copy_values", txt_attr_copy_values, 1);
181
+
182
+ DEFINE_ACCESSOR(gTextAttributes, boxed, appearance);
183
+ DEFINE_ACCESSOR(gTextAttributes, enums, justification);
184
+ DEFINE_ACCESSOR(gTextAttributes, enums, direction);
185
+ DEFINE_ACCESSOR(gTextAttributes, boxed, font);
186
+ DEFINE_ACCESSOR(gTextAttributes, double, font_scale);
187
+ DEFINE_ACCESSOR(gTextAttributes, int, left_margin);
188
+ DEFINE_ACCESSOR(gTextAttributes, int, indent);
189
+ DEFINE_ACCESSOR(gTextAttributes, int, right_margin);
190
+ DEFINE_ACCESSOR(gTextAttributes, int, pixels_above_lines);
191
+ DEFINE_ACCESSOR(gTextAttributes, int, pixels_below_lines);
192
+ DEFINE_ACCESSOR(gTextAttributes, int, pixels_inside_wrap);
193
+ DEFINE_ACCESSOR(gTextAttributes, boxed, tabs);
194
+ DEFINE_ACCESSOR(gTextAttributes, enums, wrap_mode);
195
+ DEFINE_ACCESSOR(gTextAttributes, boxed, language);
196
+
197
+ rb_define_method(gTextAttributes, "invisible?", txt_attr_bool_invisible, 0);
198
+ rb_define_method(gTextAttributes, "set_invisible", txt_attr_bool_set_invisible, 1);
199
+ rb_define_method(gTextAttributes, "bg_full_height?", txt_attr_bool_bg_full_height, 0);
200
+ rb_define_method(gTextAttributes, "set_bg_full_height", txt_attr_bool_set_bg_full_height, 1);
201
+ rb_define_method(gTextAttributes, "bg_full_height?", txt_attr_bool_bg_full_height, 0);
202
+ rb_define_method(gTextAttributes, "set_bg_full_height", txt_attr_bool_set_bg_full_height, 1);
203
+ rb_define_method(gTextAttributes, "editable?", txt_attr_bool_editable, 0);
204
+ rb_define_method(gTextAttributes, "set_editable", txt_attr_bool_set_editable, 1);
205
+ rb_define_method(gTextAttributes, "realized?", txt_attr_bool_realized, 0);
206
+ rb_define_method(gTextAttributes, "set_realized", txt_attr_bool_set_realized, 1);
207
+
208
+ G_DEF_SETTERS(gTextAttributes);
209
+ }
@@ -0,0 +1,993 @@
1
+ /* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
2
+ /************************************************
3
+
4
+ rbgtktextbuffer.c -
5
+
6
+ $Author: ggc $
7
+ $Date: 2007/07/13 16:07:32 $
8
+
9
+ Copyright (C) 2002-2005 Ruby-GNOME2 Project Team
10
+ Copyright (C) 2002,2003 Masahiro Sakai
11
+ ************************************************/
12
+
13
+ #include "global.h"
14
+
15
+ #define _SELF(s) (GTK_TEXT_BUFFER(RVAL2GOBJ(s)))
16
+ #define RVAL2ITR(i) (GtkTextIter*)RVAL2BOXED(i, GTK_TYPE_TEXT_ITER)
17
+ #define ITR2RVAL(i) (BOXED2RVAL(i, GTK_TYPE_TEXT_ITER))
18
+ #define RVAL2MARK(m) (GTK_TEXT_MARK(RVAL2GOBJ(m)))
19
+ #define N_RVAL2CSTR(text) (NIL_P(text) ? NULL : RVAL2CSTR(text))
20
+ #define RVAL2TAG(t) (GTK_TEXT_TAG(RVAL2GOBJ(t)))
21
+ #define RVAL2ANCHOR(a) (GTK_TEXT_CHILD_ANCHOR(RVAL2GOBJ(a)))
22
+ #define ATOM2RVAL(a) (BOXED2RVAL(a, GDK_TYPE_ATOM))
23
+
24
+ static ID id_tagtable;
25
+
26
+ static VALUE
27
+ txt_initialize(argc, argv, self)
28
+ int argc;
29
+ VALUE* argv;
30
+ VALUE self;
31
+ {
32
+ VALUE table;
33
+ rb_scan_args(argc, argv, "01", &table);
34
+ if (NIL_P(table))
35
+ G_INITIALIZE(self, gtk_text_buffer_new(NULL));
36
+ else {
37
+ G_CHILD_SET(self, id_tagtable, table);
38
+ G_INITIALIZE(self, gtk_text_buffer_new(GTK_TEXT_TAG_TABLE(RVAL2GOBJ(table))));
39
+ }
40
+ return Qnil;
41
+ }
42
+
43
+ static VALUE
44
+ txt_get_line_count(self)
45
+ VALUE self;
46
+ {
47
+ return INT2NUM(gtk_text_buffer_get_line_count(_SELF(self)));
48
+ }
49
+
50
+ static VALUE
51
+ txt_get_char_count(self)
52
+ VALUE self;
53
+ {
54
+ return INT2NUM(gtk_text_buffer_get_char_count(_SELF(self)));
55
+ }
56
+
57
+ static VALUE
58
+ txt_get_tag_table(self)
59
+ VALUE self;
60
+ {
61
+ return GOBJ2RVAL(gtk_text_buffer_get_tag_table(_SELF(self)));
62
+ }
63
+
64
+ static VALUE
65
+ txt_set_text(self, text)
66
+ VALUE self, text;
67
+ {
68
+ StringValue(text);
69
+ gtk_text_buffer_set_text(_SELF(self), RVAL2CSTR(text), RSTRING_LEN(text));
70
+ return self;
71
+ }
72
+
73
+ #if GTK_CHECK_VERSION(2,6,0)
74
+ static VALUE
75
+ txt_backspace(self, iter, interactive, default_editable)
76
+ VALUE self, iter, interactive, default_editable;
77
+ {
78
+ return CBOOL2RVAL(gtk_text_buffer_backspace(_SELF(self), RVAL2ITR(iter),
79
+ RVAL2CBOOL(interactive),
80
+ RVAL2CBOOL(default_editable)));
81
+ }
82
+ #endif
83
+
84
+ static VALUE
85
+ txt_insert_at_cursor(self, text)
86
+ VALUE self, text;
87
+ {
88
+ StringValue(text);
89
+ gtk_text_buffer_insert_at_cursor(_SELF(self),
90
+ RVAL2CSTR(text), RSTRING_LEN(text));
91
+ return self;
92
+ }
93
+
94
+ static VALUE
95
+ txt_insert_interactive(self, iter, text, editable)
96
+ VALUE self, iter, text, editable;
97
+ {
98
+ return CBOOL2RVAL(gtk_text_buffer_insert_interactive(_SELF(self),
99
+ RVAL2ITR(iter),
100
+ RVAL2CSTR(text),
101
+ RSTRING_LEN(text),
102
+ RVAL2CBOOL(editable)));
103
+ }
104
+
105
+ static VALUE
106
+ txt_insert_interactive_at_cursor(self, text, editable)
107
+ VALUE self, text, editable;
108
+ {
109
+ return CBOOL2RVAL(gtk_text_buffer_insert_interactive_at_cursor(_SELF(self),
110
+ RVAL2CSTR(text),
111
+ RSTRING_LEN(text),
112
+ RVAL2CBOOL(editable)));
113
+ }
114
+
115
+ static VALUE
116
+ txt_insert_range(self, iter, start, end)
117
+ VALUE self, iter, start, end;
118
+ {
119
+ gtk_text_buffer_insert_range(_SELF(self), RVAL2ITR(iter),
120
+ RVAL2ITR(start), RVAL2ITR(end));
121
+ return self;
122
+ }
123
+
124
+ static VALUE
125
+ txt_insert_range_interactive(self, iter, start, end, editable)
126
+ VALUE self, iter, start, end, editable;
127
+ {
128
+ return CBOOL2RVAL(gtk_text_buffer_insert_range_interactive(_SELF(self),
129
+ RVAL2ITR(iter),
130
+ RVAL2ITR(start),
131
+ RVAL2ITR(end),
132
+ RVAL2CBOOL(editable)));
133
+ }
134
+
135
+ static VALUE
136
+ txt_delete(self, start, end)
137
+ VALUE self, start, end;
138
+ {
139
+ gtk_text_buffer_delete(GTK_TEXT_BUFFER(RVAL2GOBJ(self)),
140
+ RVAL2ITR(start), RVAL2ITR(end));
141
+ return self;
142
+ }
143
+
144
+ static VALUE
145
+ txt_delete_interactive(self, start, end, editable)
146
+ VALUE self, start, end, editable;
147
+ {
148
+ return CBOOL2RVAL(gtk_text_buffer_delete_interactive(_SELF(self),
149
+ RVAL2ITR(start),
150
+ RVAL2ITR(end),
151
+ RVAL2CBOOL(editable)));
152
+ }
153
+
154
+ static VALUE
155
+ txt_get_text(argc, argv, self)
156
+ int argc;
157
+ VALUE *argv;
158
+ VALUE self;
159
+ {
160
+ VALUE start, end, include_hidden_chars;
161
+ GtkTextIter start_iter, end_iter;
162
+ GtkTextBuffer* buffer = _SELF(self);
163
+ gchar* ret;
164
+ VALUE result;
165
+
166
+ rb_scan_args(argc, argv, "03", &start, &end, &include_hidden_chars);
167
+
168
+ if (NIL_P(start)) gtk_text_buffer_get_start_iter(buffer, &start_iter);
169
+ if (NIL_P(end)) gtk_text_buffer_get_end_iter(buffer, &end_iter);
170
+ if (NIL_P(include_hidden_chars)) include_hidden_chars = Qfalse;
171
+
172
+ ret = gtk_text_buffer_get_text(
173
+ buffer,
174
+ NIL_P(start) ? &start_iter : RVAL2ITR(start),
175
+ NIL_P(end) ? &end_iter : RVAL2ITR(end),
176
+ RVAL2CBOOL(include_hidden_chars));
177
+ result = CSTR2RVAL(ret);
178
+ g_free(ret);
179
+
180
+ return result;
181
+ }
182
+
183
+ static VALUE
184
+ txt_get_text_all(self)
185
+ VALUE self;
186
+ {
187
+ return txt_get_text(0, NULL, self);
188
+ }
189
+
190
+ static VALUE
191
+ txt_get_slice(argc, argv, self)
192
+ int argc;
193
+ VALUE *argv;
194
+ VALUE self;
195
+ {
196
+ VALUE start, end, include_hidden_chars;
197
+ GtkTextIter start_iter, end_iter;
198
+ GtkTextBuffer* buffer = _SELF(self);
199
+ gchar* ret;
200
+ VALUE result;
201
+
202
+ rb_scan_args(argc, argv, "03", &start, &end, &include_hidden_chars);
203
+
204
+ if (NIL_P(start)) gtk_text_buffer_get_start_iter(buffer, &start_iter);
205
+ if (NIL_P(end)) gtk_text_buffer_get_end_iter(buffer, &end_iter);
206
+ if (NIL_P(include_hidden_chars)) include_hidden_chars = Qfalse;
207
+
208
+ ret = gtk_text_buffer_get_slice(
209
+ buffer,
210
+ NIL_P(start) ? &start_iter : RVAL2ITR(start),
211
+ NIL_P(end) ? &end_iter : RVAL2ITR(end),
212
+ RVAL2CBOOL(include_hidden_chars));
213
+ result = CSTR2RVAL(ret);
214
+ g_free(ret);
215
+
216
+ return result;
217
+ }
218
+
219
+ static VALUE
220
+ txt_get_slice_all(self)
221
+ VALUE self;
222
+ {
223
+ return txt_get_slice(0, NULL, self);
224
+ }
225
+
226
+ static VALUE
227
+ txt_insert_pixbuf(self, iter, pixbuf)
228
+ VALUE self, iter, pixbuf;
229
+ {
230
+ G_CHILD_ADD(self, iter);
231
+ G_CHILD_ADD(iter, pixbuf);
232
+
233
+ if (RVAL2CBOOL(ruby_debug))
234
+ rb_warning("Gtk::TextBuffer#insert_pixbuf is deprecated. Use Gtk::TextBuffer#insert instead.");
235
+ gtk_text_buffer_insert_pixbuf(_SELF(self), RVAL2ITR(iter),
236
+ GDK_PIXBUF(RVAL2GOBJ(pixbuf)));
237
+ return self;
238
+ }
239
+
240
+ static VALUE
241
+ txt_insert_child_anchor(self, iter, anchor)
242
+ VALUE self, iter, anchor;
243
+ {
244
+ G_CHILD_ADD(self, iter);
245
+ G_CHILD_ADD(iter, anchor);
246
+ if (RVAL2CBOOL(ruby_debug))
247
+ rb_warning("Gtk::TextBuffer#insert_child_anchor is deprecated. Use Gtk::TextBuffer#insert instead.");
248
+ gtk_text_buffer_insert_child_anchor(_SELF(self), RVAL2ITR(iter),
249
+ GTK_TEXT_CHILD_ANCHOR(RVAL2GOBJ(anchor)));
250
+ return self;
251
+ }
252
+
253
+ static VALUE
254
+ txt_create_child_anchor(self, iter)
255
+ VALUE self, iter;
256
+ {
257
+ VALUE ret = GOBJ2RVAL(gtk_text_buffer_create_child_anchor(_SELF(self), RVAL2ITR(iter)));
258
+ G_CHILD_ADD(self, ret);
259
+ return ret;
260
+ }
261
+
262
+ static VALUE
263
+ txt_create_mark(self, name, where, left_gravity)
264
+ VALUE self, name, where, left_gravity;
265
+ {
266
+ VALUE ret = GOBJ2RVAL(gtk_text_buffer_create_mark(_SELF(self),
267
+ NIL_P(name) ? NULL : RVAL2CSTR(name),
268
+ RVAL2ITR(where),
269
+ RVAL2CBOOL(left_gravity)));
270
+ G_CHILD_ADD(self, ret);
271
+ return ret;
272
+ }
273
+
274
+ #if GTK_CHECK_VERSION(2,12,0)
275
+ static VALUE
276
+ txt_add_mark(self, mark, where)
277
+ VALUE self, mark, where;
278
+ {
279
+ gtk_text_buffer_add_mark(_SELF(self), RVAL2MARK(mark), RVAL2ITR(where));
280
+ return self;
281
+ }
282
+ #endif
283
+
284
+ static VALUE
285
+ txt_delete_mark(self, mark)
286
+ VALUE self, mark;
287
+ {
288
+ if (rb_obj_is_kind_of(mark, GTYPE2CLASS(GTK_TYPE_TEXT_MARK))){
289
+ G_CHILD_REMOVE(self, mark);
290
+ gtk_text_buffer_delete_mark(_SELF(self), RVAL2MARK(mark));
291
+ } else {
292
+ G_CHILD_REMOVE(self, GOBJ2RVAL(gtk_text_buffer_get_mark(_SELF(self), RVAL2CSTR(mark))));
293
+ gtk_text_buffer_delete_mark_by_name(_SELF(self), RVAL2CSTR(mark));
294
+ }
295
+ return self;
296
+ }
297
+
298
+ static VALUE
299
+ txt_get_mark(self, name)
300
+ VALUE self, name;
301
+ {
302
+ return GOBJ2RVAL(gtk_text_buffer_get_mark(_SELF(self), RVAL2CSTR(name)));
303
+ }
304
+
305
+ /*
306
+ static VALUE
307
+ txt_get_insert(self)
308
+ VALUE self;
309
+ {
310
+ return GOBJ2RVAL(gtk_text_buffer_get_insert(_SELF(self)));
311
+ }
312
+ */
313
+
314
+ static VALUE
315
+ txt_get_selection_bound(self)
316
+ VALUE self;
317
+ {
318
+ return GOBJ2RVAL(gtk_text_buffer_get_selection_bound(_SELF(self)));
319
+ }
320
+
321
+ static VALUE
322
+ txt_place_cursor(self, where)
323
+ VALUE self, where;
324
+ {
325
+ gtk_text_buffer_place_cursor(_SELF(self), RVAL2ITR(where));
326
+ return self;
327
+ }
328
+
329
+ #if GTK_CHECK_VERSION(2,4,0)
330
+ static VALUE
331
+ txt_select_range(self, ins, bound)
332
+ VALUE self, ins, bound;
333
+ {
334
+ gtk_text_buffer_select_range(_SELF(self), RVAL2ITR(ins), RVAL2ITR(bound));
335
+ return self;
336
+ }
337
+ #endif
338
+
339
+ static VALUE
340
+ txt_get_iter_at_child_anchor(self, anchor)
341
+ VALUE self, anchor;
342
+ {
343
+ GtkTextIter iter;
344
+ gtk_text_buffer_get_iter_at_child_anchor(_SELF(self), &iter, RVAL2ANCHOR(anchor));
345
+ return ITR2RVAL(&iter);
346
+ }
347
+
348
+ static VALUE
349
+ txt_get_modified(self)
350
+ VALUE self;
351
+ {
352
+ return CBOOL2RVAL(gtk_text_buffer_get_modified(_SELF(self)));
353
+ }
354
+
355
+ static VALUE
356
+ txt_set_modified(self, setting)
357
+ VALUE self, setting;
358
+ {
359
+ gtk_text_buffer_set_modified(_SELF(self), RVAL2CBOOL(setting));
360
+ return setting;
361
+ }
362
+
363
+ static VALUE
364
+ txt_add_selection_clipboard(self, clipboard)
365
+ VALUE self, clipboard;
366
+ {
367
+ G_CHILD_ADD(self, clipboard);
368
+ gtk_text_buffer_add_selection_clipboard(_SELF(self), RVAL2CLIPBOARD(clipboard));
369
+ return self;
370
+ }
371
+
372
+ static VALUE
373
+ txt_remove_selection_clipboard(self, clipboard)
374
+ VALUE self, clipboard;
375
+ {
376
+ G_CHILD_REMOVE(self, clipboard);
377
+ gtk_text_buffer_remove_selection_clipboard(_SELF(self), RVAL2CLIPBOARD(clipboard));
378
+ return self;
379
+ }
380
+
381
+ #if GTK_CHECK_VERSION(2,10,0)
382
+ static VALUE
383
+ txt_deserialize(self, content_buffer, format, iter, data)
384
+ VALUE self, content_buffer, format, iter, data;
385
+ {
386
+ GError* error = NULL;
387
+ gboolean ret;
388
+
389
+ Check_Type(data, T_STRING);
390
+ ret = gtk_text_buffer_deserialize(_SELF(self), _SELF(content_buffer),
391
+ RVAL2ATOM(format),
392
+ RVAL2ITR(iter),
393
+ (const guint8*)RSTRING_PTR(data),
394
+ (gsize)RSTRING_LEN(data),
395
+ &error);
396
+ if (! ret) RAISE_GERROR(error);
397
+ return self;
398
+ }
399
+
400
+ static VALUE
401
+ txt_deserialize_get_can_create_tags(self, format)
402
+ VALUE self, format;
403
+ {
404
+ return CBOOL2RVAL(gtk_text_buffer_deserialize_get_can_create_tags(_SELF(self),
405
+ RVAL2ATOM(format)));
406
+
407
+ }
408
+
409
+ static VALUE
410
+ txt_deserialize_set_can_create_tags(self, format, can_create_tags)
411
+ VALUE self, format, can_create_tags;
412
+ {
413
+ gtk_text_buffer_deserialize_set_can_create_tags(_SELF(self),
414
+ RVAL2ATOM(format),
415
+ RVAL2CBOOL(can_create_tags));
416
+ return self;
417
+ }
418
+
419
+ /* Defined as Properties
420
+ GtkTargetList* gtk_text_buffer_get_copy_target_list
421
+ (GtkTextBuffer *buffer);
422
+ */
423
+
424
+ static VALUE
425
+ txt_get_deserialize_formats(self)
426
+ VALUE self;
427
+ {
428
+ gint i;
429
+ gint n_formats;
430
+ GdkAtom* atoms = gtk_text_buffer_get_deserialize_formats(_SELF(self), &n_formats);
431
+ VALUE ary = rb_ary_new();
432
+
433
+ for (i = 0; i < n_formats; i++){
434
+ rb_ary_push(ary, ATOM2RVAL(atoms[i]));
435
+ }
436
+ return ary;
437
+ }
438
+
439
+ /* Defined as Properties
440
+ GtkTargetList* gtk_text_buffer_get_paste_target_list
441
+ (GtkTextBuffer *buffer);
442
+ */
443
+
444
+ static VALUE
445
+ txt_get_serialize_formats(self)
446
+ VALUE self;
447
+ {
448
+ gint i;
449
+ gint n_formats;
450
+ GdkAtom* atoms = gtk_text_buffer_get_serialize_formats(_SELF(self), &n_formats);
451
+ VALUE ary = rb_ary_new();
452
+
453
+ for (i = 0; i < n_formats; i++){
454
+ rb_ary_push(ary, ATOM2RVAL(atoms[i]));
455
+ }
456
+ return ary;
457
+ }
458
+
459
+ struct callback_arg
460
+ {
461
+ VALUE callback;
462
+ int argc;
463
+ VALUE *argv;
464
+ };
465
+
466
+ static VALUE
467
+ invoke_callback(VALUE data)
468
+ {
469
+ struct callback_arg *arg = (struct callback_arg *)data;
470
+
471
+ return rb_funcall2(arg->callback, id_call, arg->argc, arg->argv);
472
+ }
473
+
474
+ static gboolean
475
+ deserialize_func(register_buffer, content_buffer, iter, data, length, create_tags, func, error)
476
+ GtkTextBuffer* register_buffer;
477
+ GtkTextBuffer* content_buffer;
478
+ GtkTextIter* iter;
479
+ const guint8 *data;
480
+ gsize length;
481
+ gboolean create_tags;
482
+ gpointer func;
483
+ GError** error;
484
+ {
485
+ VALUE result;
486
+ VALUE argv[5];
487
+ struct callback_arg arg;
488
+
489
+ argv[0] = GOBJ2RVAL(register_buffer);
490
+ argv[1] = GOBJ2RVAL(content_buffer);
491
+ argv[2] = ITR2RVAL(iter);
492
+ argv[3] = rb_str_new((char*)data, length);
493
+ argv[4] = CBOOL2RVAL(create_tags);
494
+
495
+ arg.callback = (VALUE)func;
496
+ arg.argc = 5;
497
+ arg.argv = argv;
498
+
499
+ result = G_PROTECT_CALLBACK(invoke_callback, &arg);
500
+ return NIL_P(rb_errinfo()) ? RVAL2CBOOL(result) : FALSE;
501
+ }
502
+
503
+ static void
504
+ remove_callback_reference(gpointer callback)
505
+ {
506
+ G_CHILD_REMOVE(mGtk, (VALUE)callback);
507
+ }
508
+
509
+ static VALUE
510
+ txt_register_deserialize_format(self, mime_type)
511
+ VALUE self, mime_type;
512
+ {
513
+ VALUE block = rb_block_proc();
514
+ GdkAtom atom;
515
+ G_CHILD_ADD(mGtk, block);
516
+ atom = gtk_text_buffer_register_deserialize_format(_SELF(self),
517
+ (const gchar*)RVAL2CSTR(mime_type),
518
+ (GtkTextBufferDeserializeFunc)deserialize_func,
519
+ (gpointer)block,
520
+ (GDestroyNotify)remove_callback_reference);
521
+ return ATOM2RVAL(atom);
522
+ }
523
+
524
+ static VALUE
525
+ txt_register_deserialize_target(self, tagset_name)
526
+ VALUE self, tagset_name;
527
+ {
528
+ return ATOM2RVAL(gtk_text_buffer_register_deserialize_tagset(_SELF(self),
529
+ (const gchar*)(NIL_P(tagset_name) ? NULL : RVAL2CSTR(tagset_name))));
530
+ }
531
+
532
+ static guint8*
533
+ serialize_func(register_buffer, content_buffer, start, end, length, func)
534
+ GtkTextBuffer* register_buffer;
535
+ GtkTextBuffer* content_buffer;
536
+ GtkTextIter* start;
537
+ GtkTextIter* end;
538
+ gsize* length;
539
+ gpointer func;
540
+ {
541
+ VALUE result;
542
+ VALUE argv[4];
543
+ struct callback_arg arg;
544
+
545
+ argv[0] = GOBJ2RVAL(register_buffer);
546
+ argv[1] = GOBJ2RVAL(content_buffer);
547
+ argv[2] = ITR2RVAL(start);
548
+ argv[3] = ITR2RVAL(end);
549
+
550
+ arg.callback = (VALUE)func;
551
+ arg.argc = 4;
552
+ arg.argv = argv;
553
+
554
+ /* This should return data as String */
555
+ result = G_PROTECT_CALLBACK(invoke_callback, &arg);
556
+ Check_Type(result, T_STRING);
557
+ *length = RSTRING_LEN(result);
558
+ return (guint8*)(NIL_P(rb_errinfo()) ? RSTRING_PTR(result) : NULL);
559
+ }
560
+
561
+ static VALUE
562
+ txt_register_serialize_format(self, mime_type)
563
+ VALUE self, mime_type;
564
+ {
565
+ VALUE block = rb_block_proc();
566
+ GdkAtom atom;
567
+ G_CHILD_ADD(mGtk, block);
568
+ atom = gtk_text_buffer_register_serialize_format(_SELF(self),
569
+ (const gchar*)RVAL2CSTR(mime_type),
570
+ (GtkTextBufferSerializeFunc)serialize_func,
571
+ (gpointer)block,
572
+ (GDestroyNotify)remove_callback_reference);
573
+ return ATOM2RVAL(atom);
574
+ }
575
+
576
+ static VALUE
577
+ txt_register_serialize_target(self, tagset_name)
578
+ VALUE self, tagset_name;
579
+ {
580
+ return ATOM2RVAL(gtk_text_buffer_register_serialize_tagset(_SELF(self),
581
+ NIL_P(tagset_name) ? NULL : RVAL2CSTR(tagset_name)));
582
+ }
583
+
584
+ static VALUE
585
+ txt_serialize(self, content_buffer, format, start, end)
586
+ VALUE self, content_buffer, format, start, end;
587
+ {
588
+ gsize length;
589
+ guint8* ret = gtk_text_buffer_serialize(_SELF(self), _SELF(self),
590
+ RVAL2ATOM(format),
591
+ RVAL2ITR(start), RVAL2ITR(end),
592
+ &length);
593
+ return rb_str_new((char*)ret, length);
594
+ }
595
+
596
+ static VALUE
597
+ txt_unregister_deserialize_format(self, format)
598
+ VALUE self, format;
599
+ {
600
+ gtk_text_buffer_unregister_deserialize_format(_SELF(self), RVAL2ATOM(format));
601
+ return self;
602
+ }
603
+
604
+ static VALUE
605
+ txt_unregister_serialize_format(self, format)
606
+ VALUE self, format;
607
+ {
608
+ gtk_text_buffer_unregister_serialize_format(_SELF(self), RVAL2ATOM(format));
609
+ return self;
610
+ }
611
+ #endif
612
+
613
+ static VALUE
614
+ txt_cut_clipboard(self, clipboard, default_editable)
615
+ VALUE self, clipboard, default_editable;
616
+ {
617
+ G_CHILD_ADD(self, clipboard);
618
+ gtk_text_buffer_cut_clipboard(_SELF(self), RVAL2CLIPBOARD(clipboard), RVAL2CBOOL(default_editable));
619
+ return self;
620
+ }
621
+
622
+ static VALUE
623
+ txt_copy_clipboard(self, clipboard)
624
+ VALUE self, clipboard;
625
+ {
626
+ G_CHILD_ADD(self, clipboard);
627
+ gtk_text_buffer_copy_clipboard(_SELF(self), RVAL2CLIPBOARD(clipboard));
628
+ return self;
629
+ }
630
+
631
+ static VALUE
632
+ txt_paste_clipboard(self, clipboard, location, default_editable)
633
+ VALUE self, clipboard, location, default_editable;
634
+ {
635
+ G_CHILD_ADD(self, clipboard);
636
+ gtk_text_buffer_paste_clipboard(_SELF(self), RVAL2CLIPBOARD(clipboard),
637
+ NIL_P(location) ? NULL : RVAL2ITR(location),
638
+ RVAL2CBOOL(default_editable));
639
+ return self;
640
+ }
641
+
642
+ static VALUE
643
+ txt_get_selection_bounds(self)
644
+ VALUE self;
645
+ {
646
+ GtkTextIter start, end;
647
+
648
+ gboolean ret = gtk_text_buffer_get_selection_bounds(_SELF(self), &start, &end);
649
+ return rb_ary_new3(3, ITR2RVAL(&start), ITR2RVAL(&end), CBOOL2RVAL(ret));
650
+ }
651
+
652
+ /* Defined as a proprety
653
+ gboolean gtk_text_buffer_get_has_selection
654
+ (GtkTextBuffer *buffer);
655
+ */
656
+
657
+ static VALUE
658
+ txt_delete_selection(argc, argv, self)
659
+ int argc;
660
+ VALUE* argv;
661
+ VALUE self;
662
+ {
663
+ VALUE interactive, default_editable;
664
+ rb_scan_args(argc, argv, "20", &interactive, &default_editable);
665
+ return CBOOL2RVAL(gtk_text_buffer_delete_selection(_SELF(self),
666
+ RVAL2CBOOL(interactive), RVAL2CBOOL(default_editable)));
667
+ }
668
+
669
+ static VALUE
670
+ txt_end_user_action(self)
671
+ VALUE self;
672
+ {
673
+ gtk_text_buffer_end_user_action(_SELF(self));
674
+ return self;
675
+ }
676
+
677
+ static VALUE
678
+ txt_begin_user_action(self)
679
+ VALUE self;
680
+ {
681
+ gtk_text_buffer_begin_user_action(_SELF(self));
682
+ if (rb_block_given_p())
683
+ rb_ensure(rb_yield, self, txt_end_user_action, self);
684
+ return self;
685
+ }
686
+
687
+ static VALUE
688
+ txt_get_start_iter(self)
689
+ VALUE self;
690
+ {
691
+ GtkTextIter iter;
692
+ gtk_text_buffer_get_start_iter(_SELF(self), &iter);
693
+ return ITR2RVAL(&iter);
694
+ }
695
+
696
+ static VALUE
697
+ txt_get_end_iter(self)
698
+ VALUE self;
699
+ {
700
+ GtkTextIter iter;
701
+ gtk_text_buffer_get_end_iter(_SELF(self), &iter);
702
+ return ITR2RVAL(&iter);
703
+ }
704
+
705
+ static VALUE
706
+ txt_move_mark(self, mark, where)
707
+ VALUE self, mark, where;
708
+ {
709
+ if (rb_obj_is_kind_of(mark, GTYPE2CLASS(GTK_TYPE_TEXT_MARK)))
710
+ gtk_text_buffer_move_mark(_SELF(self), RVAL2MARK(mark), RVAL2ITR(where));
711
+ else
712
+ gtk_text_buffer_move_mark_by_name(_SELF(self), RVAL2CSTR(mark), RVAL2ITR(where));
713
+ return self;
714
+ }
715
+
716
+ static VALUE
717
+ txt_create_tag(self, tag_name, properties)
718
+ VALUE self, tag_name, properties;
719
+ {
720
+ GtkTextTag *tag;
721
+ VALUE ret;
722
+
723
+ tag = gtk_text_tag_new(NIL_P(tag_name) ? (gchar*)NULL : RVAL2CSTR(tag_name));
724
+ gtk_text_tag_table_add (gtk_text_buffer_get_tag_table(_SELF(self)), tag);
725
+
726
+ G_SET_PROPERTIES(GOBJ2RVAL(tag), properties);
727
+
728
+ ret = GOBJ2RVAL(tag);
729
+
730
+ G_CHILD_ADD(self, ret);
731
+
732
+ return ret;
733
+ }
734
+
735
+ static VALUE
736
+ txt_insert(argc, argv, self)
737
+ int argc;
738
+ VALUE *argv;
739
+ VALUE self;
740
+ {
741
+ VALUE where, value, tags;
742
+ gint start_offset;
743
+ GtkTextIter start;
744
+ int i;
745
+
746
+ rb_scan_args(argc, argv, "2*", &where, &value, &tags);
747
+
748
+ G_CHILD_ADD(self, where);
749
+ G_CHILD_ADD(self, value);
750
+ if (rb_obj_is_kind_of(value, GTYPE2CLASS(GDK_TYPE_PIXBUF))){
751
+ gtk_text_buffer_insert_pixbuf(_SELF(self), RVAL2ITR(where),
752
+ GDK_PIXBUF(RVAL2GOBJ(value)));
753
+ } else if (rb_obj_is_kind_of(value, GTYPE2CLASS(GTK_TYPE_TEXT_CHILD_ANCHOR))){
754
+ gtk_text_buffer_insert_child_anchor(_SELF(self), RVAL2ITR(where),
755
+ GTK_TEXT_CHILD_ANCHOR(RVAL2GOBJ(value)));
756
+ } else {
757
+ start_offset = gtk_text_iter_get_offset(RVAL2ITR(where));
758
+ StringValue(value);
759
+ gtk_text_buffer_insert(_SELF(self), RVAL2ITR(where),
760
+ RVAL2CSTR(value), RSTRING_LEN(value));
761
+
762
+ if (RARRAY_LEN(tags) == 0)
763
+ return self;
764
+
765
+ G_CHILD_ADD(self, tags);
766
+
767
+ gtk_text_buffer_get_iter_at_offset(_SELF(self), &start, start_offset);
768
+
769
+ for(i = 0; i < RARRAY_LEN(tags); i++) {
770
+ GtkTextTag *tag;
771
+
772
+ if (rb_obj_is_kind_of(RARRAY_PTR(tags)[i], GTYPE2CLASS(GTK_TYPE_TEXT_TAG))) {
773
+ tag = RVAL2GOBJ(RARRAY_PTR(tags)[i]);
774
+ } else {
775
+ tag = gtk_text_tag_table_lookup(_SELF(self)->tag_table,
776
+ RVAL2CSTR(RARRAY_PTR(tags)[i]));
777
+ if (tag == NULL) {
778
+ g_warning ("%s: no tag with name '%s'!",
779
+ G_STRLOC, RVAL2CSTR(RARRAY_PTR(tags)[i]));
780
+ return self;
781
+ }
782
+ }
783
+ gtk_text_buffer_apply_tag(_SELF(self), tag, &start, RVAL2ITR(where));
784
+ }
785
+ }
786
+ return self;
787
+ }
788
+
789
+ static VALUE
790
+ txt_insert_with_tags(argc, argv, self)
791
+ int argc;
792
+ VALUE *argv;
793
+ VALUE self;
794
+ {
795
+ if (RVAL2CBOOL(ruby_debug))
796
+ rb_warning("Gtk::TextBuffer#insert_with_tags is deprecated. Use Gtk::TextBuffer#insert instead.");
797
+ txt_insert(argc, argv, self);
798
+ return self;
799
+ }
800
+
801
+ static VALUE
802
+ txt_apply_tag(self, tag, start, end)
803
+ VALUE self, tag, start, end;
804
+ {
805
+ if (rb_obj_is_kind_of(tag, GTYPE2CLASS(GTK_TYPE_TEXT_TAG)))
806
+ gtk_text_buffer_apply_tag(_SELF(self), RVAL2TAG(tag), RVAL2ITR(start), RVAL2ITR(end));
807
+ else
808
+ gtk_text_buffer_apply_tag_by_name(_SELF(self), RVAL2CSTR(tag), RVAL2ITR(start), RVAL2ITR(end));
809
+
810
+ return self;
811
+ }
812
+
813
+ static VALUE
814
+ txt_remove_tag(self, tag, start, end)
815
+ VALUE self, tag, start, end;
816
+ {
817
+ if (rb_obj_is_kind_of(tag, GTYPE2CLASS(GTK_TYPE_TEXT_TAG)))
818
+ gtk_text_buffer_remove_tag(_SELF(self), RVAL2TAG(tag), RVAL2ITR(start), RVAL2ITR(end));
819
+ else
820
+ gtk_text_buffer_remove_tag_by_name(_SELF(self), RVAL2CSTR(tag), RVAL2ITR(start), RVAL2ITR(end));
821
+
822
+ return self;
823
+ }
824
+
825
+ static VALUE
826
+ txt_remove_all_tags(self, start, end)
827
+ VALUE self, start, end;
828
+ {
829
+ gtk_text_buffer_remove_all_tags(_SELF(self), RVAL2ITR(start), RVAL2ITR(end));
830
+ return self;
831
+ }
832
+
833
+ static VALUE
834
+ txt_get_iter_at_line_offset(self, line_number, char_offset)
835
+ VALUE self, line_number, char_offset;
836
+ {
837
+ GtkTextIter iter;
838
+ gtk_text_buffer_get_iter_at_line_offset(_SELF(self), &iter, NUM2INT(line_number), NUM2INT(char_offset));
839
+ return ITR2RVAL(&iter);
840
+ }
841
+
842
+ static VALUE
843
+ txt_get_iter_at_line_index(self, line_number, byte_index)
844
+ VALUE self, line_number, byte_index;
845
+ {
846
+ GtkTextIter iter;
847
+ gtk_text_buffer_get_iter_at_line_index(_SELF(self), &iter, NUM2INT(line_number), NUM2INT(byte_index));
848
+ return ITR2RVAL(&iter);
849
+ }
850
+
851
+ static VALUE
852
+ txt_get_iter_at_offset(self, char_offset)
853
+ VALUE self, char_offset;
854
+ {
855
+ GtkTextIter iter;
856
+ gtk_text_buffer_get_iter_at_offset(_SELF(self), &iter, NUM2INT(char_offset));
857
+ return ITR2RVAL(&iter);
858
+ }
859
+
860
+ static VALUE
861
+ txt_get_iter_at_line(self, line_number)
862
+ VALUE self, line_number;
863
+ {
864
+ GtkTextIter iter;
865
+ gtk_text_buffer_get_iter_at_line(_SELF(self), &iter, NUM2INT(line_number));
866
+ return ITR2RVAL(&iter);
867
+ }
868
+
869
+ static VALUE
870
+ txt_get_bounds(self)
871
+ VALUE self;
872
+ {
873
+ GtkTextIter start, end;
874
+ VALUE result;
875
+
876
+ gtk_text_buffer_get_bounds(_SELF(self), &start, &end);
877
+ result = rb_ary_new();
878
+ rb_ary_push(result, ITR2RVAL(&start));
879
+ rb_ary_push(result, ITR2RVAL(&end));
880
+
881
+ return result;
882
+ }
883
+
884
+ static VALUE
885
+ txt_get_iter_at_mark(self, mark)
886
+ VALUE self, mark;
887
+ {
888
+ GtkTextIter iter;
889
+ gtk_text_buffer_get_iter_at_mark(_SELF(self), &iter, RVAL2MARK(mark));
890
+ return ITR2RVAL(&iter);
891
+ }
892
+
893
+
894
+ void
895
+ Init_gtk_textbuffer()
896
+ {
897
+ VALUE gTextBuffer = G_DEF_CLASS(GTK_TYPE_TEXT_BUFFER, "TextBuffer", mGtk);
898
+
899
+ id_tagtable = rb_intern("tagtable");
900
+
901
+ rb_define_method(gTextBuffer, "initialize", txt_initialize, -1);
902
+ rb_define_method(gTextBuffer, "line_count", txt_get_line_count, 0);
903
+ rb_define_method(gTextBuffer, "char_count", txt_get_char_count, 0);
904
+ rb_define_method(gTextBuffer, "tag_table", txt_get_tag_table, 0);
905
+
906
+ rb_define_method(gTextBuffer, "set_text", txt_set_text, 1);
907
+ rb_define_method(gTextBuffer, "insert", txt_insert, -1);
908
+ rb_define_method(gTextBuffer, "insert_with_tags", txt_insert_with_tags, -1);
909
+ #if GTK_CHECK_VERSION(2,6,0)
910
+ rb_define_method(gTextBuffer, "backspace", txt_backspace, 3);
911
+ #endif
912
+ rb_define_method(gTextBuffer, "insert_at_cursor", txt_insert_at_cursor, 1);
913
+ rb_define_method(gTextBuffer, "insert_interactive", txt_insert_interactive, 3);
914
+ rb_define_method(gTextBuffer, "insert_interactive_at_cursor", txt_insert_interactive_at_cursor, 2);
915
+ rb_define_method(gTextBuffer, "insert_range", txt_insert_range, 3);
916
+ rb_define_method(gTextBuffer, "insert_range_interactive", txt_insert_range_interactive, 4);
917
+
918
+ rb_define_method(gTextBuffer, "delete", txt_delete, 2);
919
+ rb_define_method(gTextBuffer, "delete_interactive", txt_delete_interactive, 3);
920
+
921
+ rb_define_method(gTextBuffer, "get_text", txt_get_text, -1);
922
+ rb_define_method(gTextBuffer, "text", txt_get_text_all, 0);
923
+ rb_define_method(gTextBuffer, "get_slice", txt_get_slice, -1);
924
+ rb_define_method(gTextBuffer, "slice", txt_get_slice_all, 0);
925
+
926
+ rb_define_method(gTextBuffer, "insert_pixbuf", txt_insert_pixbuf, 2);
927
+ rb_define_method(gTextBuffer, "insert_child_anchor", txt_insert_child_anchor, 2);
928
+ rb_define_method(gTextBuffer, "create_child_anchor", txt_create_child_anchor, 1);
929
+
930
+ rb_define_method(gTextBuffer, "create_mark", txt_create_mark, 3);
931
+ #if GTK_CHECK_VERSION(2,12,0)
932
+ rb_define_method(gTextBuffer, "add_mark", txt_add_mark, 2);
933
+ #endif
934
+ rb_define_method(gTextBuffer, "delete_mark", txt_delete_mark, 1);
935
+
936
+ rb_define_method(gTextBuffer, "get_mark", txt_get_mark, 1);
937
+ /* Comment out because this method's name is very bad.
938
+ Use Gtk::TextBuffer#get_mark("insert") instead.
939
+ rb_define_method(gTextBuffer, "get_insert", txt_get_insert, 0);
940
+ */
941
+ rb_define_method(gTextBuffer, "selection_bound", txt_get_selection_bound, 0);
942
+ rb_define_method(gTextBuffer, "place_cursor", txt_place_cursor, 1);
943
+ #if GTK_CHECK_VERSION(2,4,0)
944
+ rb_define_method(gTextBuffer, "select_range", txt_select_range, 2);
945
+ #endif
946
+ rb_define_method(gTextBuffer, "modified?", txt_get_modified, 0);
947
+ rb_define_method(gTextBuffer, "set_modified", txt_set_modified, 1);
948
+
949
+ rb_define_method(gTextBuffer, "add_selection_clipboard", txt_add_selection_clipboard, 1);
950
+ rb_define_method(gTextBuffer, "remove_selection_clipboard", txt_remove_selection_clipboard, 1);
951
+ #if GTK_CHECK_VERSION(2,10,0)
952
+ rb_define_method(gTextBuffer, "deserialize", txt_deserialize, 4);
953
+ rb_define_method(gTextBuffer, "deserialize_can_create_tags?", txt_deserialize_get_can_create_tags, 1);
954
+ rb_define_method(gTextBuffer, "deserialize_set_can_create_tags", txt_deserialize_set_can_create_tags, 2);
955
+ rb_define_method(gTextBuffer, "deserialize_formats", txt_get_deserialize_formats, 0);
956
+ rb_define_method(gTextBuffer, "serialize_formats", txt_get_serialize_formats, 0);
957
+ rb_define_method(gTextBuffer, "register_deserialize_format", txt_register_deserialize_format, 1);
958
+ rb_define_method(gTextBuffer, "register_deserialize_target", txt_register_deserialize_target, 1);
959
+ rb_define_method(gTextBuffer, "register_serialize_format", txt_register_serialize_format, 1);
960
+ rb_define_method(gTextBuffer, "register_serialize_target", txt_register_serialize_target, 1);
961
+ rb_define_method(gTextBuffer, "serialize", txt_serialize, 4);
962
+ rb_define_method(gTextBuffer, "unregister_deserialize_format", txt_unregister_deserialize_format, 1);
963
+ rb_define_method(gTextBuffer, "unregister_serialize_format", txt_unregister_serialize_format, 1);
964
+ #endif
965
+ rb_define_method(gTextBuffer, "cut_clipboard", txt_cut_clipboard, 2);
966
+ rb_define_method(gTextBuffer, "copy_clipboard", txt_copy_clipboard, 1);
967
+ rb_define_method(gTextBuffer, "paste_clipboard", txt_paste_clipboard, 3);
968
+
969
+ rb_define_method(gTextBuffer, "selection_bounds", txt_get_selection_bounds, 0);
970
+ rb_define_method(gTextBuffer, "delete_selection", txt_delete_selection, -1);
971
+
972
+ rb_define_method(gTextBuffer, "begin_user_action", txt_begin_user_action, 0);
973
+ rb_define_method(gTextBuffer, "end_user_action", txt_end_user_action, 0);
974
+
975
+ rb_define_method(gTextBuffer, "start_iter", txt_get_start_iter, 0);
976
+ rb_define_method(gTextBuffer, "end_iter", txt_get_end_iter, 0);
977
+ rb_define_method(gTextBuffer, "get_iter_at_line_offset", txt_get_iter_at_line_offset, 2);
978
+ rb_define_method(gTextBuffer, "get_iter_at_line_index", txt_get_iter_at_line_index, 2);
979
+ rb_define_method(gTextBuffer, "get_iter_at_offset", txt_get_iter_at_offset, 1);
980
+ rb_define_method(gTextBuffer, "get_iter_at_line", txt_get_iter_at_line, 1);
981
+ rb_define_method(gTextBuffer, "bounds", txt_get_bounds, 0);
982
+ rb_define_method(gTextBuffer, "get_iter_at_mark", txt_get_iter_at_mark, 1);
983
+ rb_define_method(gTextBuffer, "move_mark", txt_move_mark, 2);
984
+ rb_define_method(gTextBuffer, "get_iter_at_child_anchor", txt_get_iter_at_child_anchor, 1);
985
+
986
+ rb_define_method(gTextBuffer, "create_tag", txt_create_tag, 2);
987
+ rb_define_method(gTextBuffer, "apply_tag", txt_apply_tag, 3);
988
+ rb_define_method(gTextBuffer, "remove_tag", txt_remove_tag, 3);
989
+ rb_define_method(gTextBuffer, "remove_all_tags", txt_remove_all_tags, 2);
990
+
991
+ G_DEF_SETTERS(gTextBuffer);
992
+ }
993
+