gtk3 0.0.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (425) hide show
  1. data/Rakefile +32 -0
  2. data/ext/gtk3/conversions.c +34 -0
  3. data/ext/gtk3/depend +11 -0
  4. data/ext/gtk3/extconf.rb +108 -0
  5. data/ext/gtk3/gtk3.def +10 -0
  6. data/ext/gtk3/init.c +38 -0
  7. data/ext/gtk3/rbgdkdisplay.c +39 -0
  8. data/ext/gtk3/rbgdkdragcontext.c +108 -0
  9. data/ext/gtk3/rbgdkevent.c +38 -0
  10. data/ext/gtk3/rbgdkscreen.c +61 -0
  11. data/ext/gtk3/rbgtk.c +625 -0
  12. data/ext/gtk3/rbgtk3.h +57 -0
  13. data/ext/gtk3/rbgtk3conversions.h +347 -0
  14. data/ext/gtk3/rbgtk3private.h +282 -0
  15. data/ext/gtk3/rbgtk3util.c +67 -0
  16. data/ext/gtk3/rbgtk3util.h +32 -0
  17. data/ext/gtk3/rbgtkaboutdialog.c +117 -0
  18. data/ext/gtk3/rbgtkaccelerator.c +78 -0
  19. data/ext/gtk3/rbgtkaccelgroup.c +199 -0
  20. data/ext/gtk3/rbgtkaccelgroupentry.c +93 -0
  21. data/ext/gtk3/rbgtkaccelkey.c +119 -0
  22. data/ext/gtk3/rbgtkaccellabel.c +55 -0
  23. data/ext/gtk3/rbgtkaccelmap.c +135 -0
  24. data/ext/gtk3/rbgtkaccessible.c +56 -0
  25. data/ext/gtk3/rbgtkaction.c +205 -0
  26. data/ext/gtk3/rbgtkactiongroup.c +466 -0
  27. data/ext/gtk3/rbgtkactivatable.c +30 -0
  28. data/ext/gtk3/rbgtkadjustment.c +98 -0
  29. data/ext/gtk3/rbgtkalignment.c +75 -0
  30. data/ext/gtk3/rbgtkallocation.c +166 -0
  31. data/ext/gtk3/rbgtkappchooser.c +47 -0
  32. data/ext/gtk3/rbgtkappchooserbutton.c +70 -0
  33. data/ext/gtk3/rbgtkappchooserdialog.c +68 -0
  34. data/ext/gtk3/rbgtkappchooserwidget.c +40 -0
  35. data/ext/gtk3/rbgtkapplication.c +69 -0
  36. data/ext/gtk3/rbgtkarrow.c +56 -0
  37. data/ext/gtk3/rbgtkaspectframe.c +56 -0
  38. data/ext/gtk3/rbgtkassistant.c +218 -0
  39. data/ext/gtk3/rbgtkbin.c +42 -0
  40. data/ext/gtk3/rbgtkbindingset.c +164 -0
  41. data/ext/gtk3/rbgtkborder.c +119 -0
  42. data/ext/gtk3/rbgtkbox.c +146 -0
  43. data/ext/gtk3/rbgtkbuildable.c +96 -0
  44. data/ext/gtk3/rbgtkbuilder.c +166 -0
  45. data/ext/gtk3/rbgtkbutton.c +93 -0
  46. data/ext/gtk3/rbgtkbuttonbox.c +87 -0
  47. data/ext/gtk3/rbgtkcalendar.c +118 -0
  48. data/ext/gtk3/rbgtkcelleditable.c +57 -0
  49. data/ext/gtk3/rbgtkcelllayout.c +144 -0
  50. data/ext/gtk3/rbgtkcellrenderer.c +116 -0
  51. data/ext/gtk3/rbgtkcellrendereraccel.c +41 -0
  52. data/ext/gtk3/rbgtkcellrenderercombo.c +38 -0
  53. data/ext/gtk3/rbgtkcellrendererpixbuf.c +41 -0
  54. data/ext/gtk3/rbgtkcellrendererprogress.c +38 -0
  55. data/ext/gtk3/rbgtkcellrendererspin.c +39 -0
  56. data/ext/gtk3/rbgtkcellrendererspinner.c +38 -0
  57. data/ext/gtk3/rbgtkcellrenderertext.c +48 -0
  58. data/ext/gtk3/rbgtkcellrenderertoggle.c +39 -0
  59. data/ext/gtk3/rbgtkcellview.c +109 -0
  60. data/ext/gtk3/rbgtkcheckbutton.c +64 -0
  61. data/ext/gtk3/rbgtkcheckmenuitem.c +64 -0
  62. data/ext/gtk3/rbgtkclipboard.c +389 -0
  63. data/ext/gtk3/rbgtkcolorbutton.c +49 -0
  64. data/ext/gtk3/rbgtkcolorselection.c +219 -0
  65. data/ext/gtk3/rbgtkcolorselectiondialog.c +56 -0
  66. data/ext/gtk3/rbgtkcombobox.c +147 -0
  67. data/ext/gtk3/rbgtkcomboboxtext.c +138 -0
  68. data/ext/gtk3/rbgtkconst.c +79 -0
  69. data/ext/gtk3/rbgtkcontainer.c +784 -0
  70. data/ext/gtk3/rbgtkcssprovider.c +110 -0
  71. data/ext/gtk3/rbgtkdialog.c +186 -0
  72. data/ext/gtk3/rbgtkdrag.c +93 -0
  73. data/ext/gtk3/rbgtkdrawingarea.c +42 -0
  74. data/ext/gtk3/rbgtkeditable.c +149 -0
  75. data/ext/gtk3/rbgtkentry.c +198 -0
  76. data/ext/gtk3/rbgtkentrybuffer.c +87 -0
  77. data/ext/gtk3/rbgtkentrycompletion.c +122 -0
  78. data/ext/gtk3/rbgtkeventbox.c +42 -0
  79. data/ext/gtk3/rbgtkexpander.c +49 -0
  80. data/ext/gtk3/rbgtkfilechooser.c +384 -0
  81. data/ext/gtk3/rbgtkfilechooserbutton.c +50 -0
  82. data/ext/gtk3/rbgtkfilechooserdialog.c +62 -0
  83. data/ext/gtk3/rbgtkfilechooserwidget.c +40 -0
  84. data/ext/gtk3/rbgtkfilefilter.c +128 -0
  85. data/ext/gtk3/rbgtkfilesystemerror.c +48 -0
  86. data/ext/gtk3/rbgtkfixed.c +61 -0
  87. data/ext/gtk3/rbgtkfontbutton.c +49 -0
  88. data/ext/gtk3/rbgtkfontchooser.c +78 -0
  89. data/ext/gtk3/rbgtkfontchooserdialog.c +56 -0
  90. data/ext/gtk3/rbgtkfontchooserwidget.c +45 -0
  91. data/ext/gtk3/rbgtkframe.c +69 -0
  92. data/ext/gtk3/rbgtkgrid.c +105 -0
  93. data/ext/gtk3/rbgtkhandlebox.c +45 -0
  94. data/ext/gtk3/rbgtkhsv.c +102 -0
  95. data/ext/gtk3/rbgtkiconfactory.c +85 -0
  96. data/ext/gtk3/rbgtkiconinfo.c +115 -0
  97. data/ext/gtk3/rbgtkiconset.c +84 -0
  98. data/ext/gtk3/rbgtkiconsize.c +91 -0
  99. data/ext/gtk3/rbgtkiconsource.c +184 -0
  100. data/ext/gtk3/rbgtkicontheme.c +268 -0
  101. data/ext/gtk3/rbgtkiconview.c +270 -0
  102. data/ext/gtk3/rbgtkimage.c +96 -0
  103. data/ext/gtk3/rbgtkimagemenuitem.c +67 -0
  104. data/ext/gtk3/rbgtkimcontext.c +133 -0
  105. data/ext/gtk3/rbgtkimcontextsimple.c +69 -0
  106. data/ext/gtk3/rbgtkimmulticontext.c +48 -0
  107. data/ext/gtk3/rbgtkinfobar.c +121 -0
  108. data/ext/gtk3/rbgtkinvisible.c +49 -0
  109. data/ext/gtk3/rbgtklabel.c +139 -0
  110. data/ext/gtk3/rbgtklayout.c +93 -0
  111. data/ext/gtk3/rbgtklinkbutton.c +55 -0
  112. data/ext/gtk3/rbgtkliststore.c +408 -0
  113. data/ext/gtk3/rbgtklockbutton.c +50 -0
  114. data/ext/gtk3/rbgtkmenu.c +168 -0
  115. data/ext/gtk3/rbgtkmenubar.c +43 -0
  116. data/ext/gtk3/rbgtkmenuitem.c +95 -0
  117. data/ext/gtk3/rbgtkmenushell.c +106 -0
  118. data/ext/gtk3/rbgtkmenutoolbutton.c +81 -0
  119. data/ext/gtk3/rbgtkmessagedialog.c +74 -0
  120. data/ext/gtk3/rbgtkmisc.c +70 -0
  121. data/ext/gtk3/rbgtknotebook.c +383 -0
  122. data/ext/gtk3/rbgtknumerableicon.c +50 -0
  123. data/ext/gtk3/rbgtkorientable.c +27 -0
  124. data/ext/gtk3/rbgtkoverlay.c +53 -0
  125. data/ext/gtk3/rbgtkpagesetup.c +195 -0
  126. data/ext/gtk3/rbgtkpagesetupunixdialog.c +94 -0
  127. data/ext/gtk3/rbgtkpaned.c +114 -0
  128. data/ext/gtk3/rbgtkpapersize.c +179 -0
  129. data/ext/gtk3/rbgtkplug.c +85 -0
  130. data/ext/gtk3/rbgtkprintcontext.c +125 -0
  131. data/ext/gtk3/rbgtkprinter.c +155 -0
  132. data/ext/gtk3/rbgtkprintjob.c +148 -0
  133. data/ext/gtk3/rbgtkprintoperation.c +149 -0
  134. data/ext/gtk3/rbgtkprintoperationpreview.c +59 -0
  135. data/ext/gtk3/rbgtkprintsettings.c +807 -0
  136. data/ext/gtk3/rbgtkprintunixdialog.c +90 -0
  137. data/ext/gtk3/rbgtkprogressbar.c +72 -0
  138. data/ext/gtk3/rbgtkradioaction.c +122 -0
  139. data/ext/gtk3/rbgtkradiobutton.c +89 -0
  140. data/ext/gtk3/rbgtkradiomenuitem.c +147 -0
  141. data/ext/gtk3/rbgtkradiotoolbutton.c +131 -0
  142. data/ext/gtk3/rbgtkrange.c +68 -0
  143. data/ext/gtk3/rbgtkrecentaction.c +64 -0
  144. data/ext/gtk3/rbgtkrecentchooser.c +198 -0
  145. data/ext/gtk3/rbgtkrecentchooserdialog.c +66 -0
  146. data/ext/gtk3/rbgtkrecentchoosermenu.c +50 -0
  147. data/ext/gtk3/rbgtkrecentchooserwidget.c +48 -0
  148. data/ext/gtk3/rbgtkrecentdata.c +187 -0
  149. data/ext/gtk3/rbgtkrecentfilter.c +169 -0
  150. data/ext/gtk3/rbgtkrecentfilterinfo.c +200 -0
  151. data/ext/gtk3/rbgtkrecentinfo.c +213 -0
  152. data/ext/gtk3/rbgtkrecentmanager.c +134 -0
  153. data/ext/gtk3/rbgtkscale.c +97 -0
  154. data/ext/gtk3/rbgtkscalebutton.c +84 -0
  155. data/ext/gtk3/rbgtkscrollable.c +31 -0
  156. data/ext/gtk3/rbgtkscrollbar.c +52 -0
  157. data/ext/gtk3/rbgtkscrolledwindow.c +122 -0
  158. data/ext/gtk3/rbgtkselection.c +168 -0
  159. data/ext/gtk3/rbgtkselectiondata.c +282 -0
  160. data/ext/gtk3/rbgtkseparator.c +44 -0
  161. data/ext/gtk3/rbgtkseparatormenuitem.c +39 -0
  162. data/ext/gtk3/rbgtkseparatortoolitem.c +38 -0
  163. data/ext/gtk3/rbgtksettings.c +229 -0
  164. data/ext/gtk3/rbgtksizegroup.c +66 -0
  165. data/ext/gtk3/rbgtksocket.c +82 -0
  166. data/ext/gtk3/rbgtkspinbutton.c +132 -0
  167. data/ext/gtk3/rbgtkspinner.c +55 -0
  168. data/ext/gtk3/rbgtkstatusbar.c +77 -0
  169. data/ext/gtk3/rbgtkstatusicon.c +122 -0
  170. data/ext/gtk3/rbgtkstock.c +213 -0
  171. data/ext/gtk3/rbgtkstylecontext.c +411 -0
  172. data/ext/gtk3/rbgtkstyleproperties.c +119 -0
  173. data/ext/gtk3/rbgtkstyleprovider.c +68 -0
  174. data/ext/gtk3/rbgtkswitch.c +40 -0
  175. data/ext/gtk3/rbgtktable.c +190 -0
  176. data/ext/gtk3/rbgtktargetlist.c +125 -0
  177. data/ext/gtk3/rbgtktearoffmenuitem.c +41 -0
  178. data/ext/gtk3/rbgtktextappearance.c +236 -0
  179. data/ext/gtk3/rbgtktextattributes.c +326 -0
  180. data/ext/gtk3/rbgtktextbuffer.c +899 -0
  181. data/ext/gtk3/rbgtktextchildanchor.c +56 -0
  182. data/ext/gtk3/rbgtktextiter.c +732 -0
  183. data/ext/gtk3/rbgtktextmark.c +71 -0
  184. data/ext/gtk3/rbgtktexttag.c +68 -0
  185. data/ext/gtk3/rbgtktexttagtable.c +96 -0
  186. data/ext/gtk3/rbgtktextview.c +336 -0
  187. data/ext/gtk3/rbgtkthemingengine.c +257 -0
  188. data/ext/gtk3/rbgtktoggleaction.c +61 -0
  189. data/ext/gtk3/rbgtktogglebutton.c +87 -0
  190. data/ext/gtk3/rbgtktoggletoolbutton.c +61 -0
  191. data/ext/gtk3/rbgtktoolbar.c +118 -0
  192. data/ext/gtk3/rbgtktoolbutton.c +66 -0
  193. data/ext/gtk3/rbgtktoolitem.c +200 -0
  194. data/ext/gtk3/rbgtktoolitemgroup.c +70 -0
  195. data/ext/gtk3/rbgtktoolshell.c +96 -0
  196. data/ext/gtk3/rbgtktooltip.c +100 -0
  197. data/ext/gtk3/rbgtktreedragdest.c +28 -0
  198. data/ext/gtk3/rbgtktreedragsource.c +28 -0
  199. data/ext/gtk3/rbgtktreeiter.c +258 -0
  200. data/ext/gtk3/rbgtktreemodel.c +236 -0
  201. data/ext/gtk3/rbgtktreemodelfilter.c +197 -0
  202. data/ext/gtk3/rbgtktreemodelsort.c +111 -0
  203. data/ext/gtk3/rbgtktreepath.c +191 -0
  204. data/ext/gtk3/rbgtktreerowreference.c +140 -0
  205. data/ext/gtk3/rbgtktreeselection.c +205 -0
  206. data/ext/gtk3/rbgtktreesortable.c +122 -0
  207. data/ext/gtk3/rbgtktreestore.c +330 -0
  208. data/ext/gtk3/rbgtktreeview.c +715 -0
  209. data/ext/gtk3/rbgtktreeviewcolumn.c +256 -0
  210. data/ext/gtk3/rbgtkuimanager.c +189 -0
  211. data/ext/gtk3/rbgtkviewport.c +44 -0
  212. data/ext/gtk3/rbgtkvolumebutton.c +41 -0
  213. data/ext/gtk3/rbgtkwidget.c +1564 -0
  214. data/ext/gtk3/rbgtkwidgetpath.c +229 -0
  215. data/ext/gtk3/rbgtkwindow.c +557 -0
  216. data/ext/gtk3/rbgtkwindowgroup.c +80 -0
  217. data/extconf.rb +49 -0
  218. data/lib/gtk3.rb +10 -0
  219. data/lib/gtk3/base.rb +67 -0
  220. data/lib/gtk3/deprecated.rb +1001 -0
  221. data/sample/gtk-demo/README +7 -0
  222. data/sample/gtk-demo/alphatest.png +0 -0
  223. data/sample/gtk-demo/apple-red.png +0 -0
  224. data/sample/gtk-demo/appwindow.rb +233 -0
  225. data/sample/gtk-demo/background.jpg +0 -0
  226. data/sample/gtk-demo/builder.rb +51 -0
  227. data/sample/gtk-demo/button_box.rb +84 -0
  228. data/sample/gtk-demo/cairo-arc-negative.rb +41 -0
  229. data/sample/gtk-demo/cairo-arc.rb +41 -0
  230. data/sample/gtk-demo/cairo-clip-image.rb +51 -0
  231. data/sample/gtk-demo/cairo-clip-rectangle.rb +35 -0
  232. data/sample/gtk-demo/cairo-clip.rb +35 -0
  233. data/sample/gtk-demo/cairo-curve-rectangle.rb +76 -0
  234. data/sample/gtk-demo/cairo-curve-to.rb +43 -0
  235. data/sample/gtk-demo/cairo-dash.rb +39 -0
  236. data/sample/gtk-demo/cairo-fill-and-stroke.rb +32 -0
  237. data/sample/gtk-demo/cairo-fill-and-stroke2.rb +38 -0
  238. data/sample/gtk-demo/cairo-gradient.rb +35 -0
  239. data/sample/gtk-demo/cairo-image-pattern.rb +39 -0
  240. data/sample/gtk-demo/cairo-image.rb +49 -0
  241. data/sample/gtk-demo/cairo-line-cap.rb +53 -0
  242. data/sample/gtk-demo/cairo-line-join.rb +41 -0
  243. data/sample/gtk-demo/cairo-long-lines.rb +41 -0
  244. data/sample/gtk-demo/cairo-operator.rb +83 -0
  245. data/sample/gtk-demo/cairo-path.rb +28 -0
  246. data/sample/gtk-demo/cairo-pattern-fill.rb +88 -0
  247. data/sample/gtk-demo/cairo-self-intersect.rb +32 -0
  248. data/sample/gtk-demo/cairo-text-align-center.rb +45 -0
  249. data/sample/gtk-demo/cairo-text-extents.rb +46 -0
  250. data/sample/gtk-demo/cairo-text.rb +43 -0
  251. data/sample/gtk-demo/changedisplay.rb +408 -0
  252. data/sample/gtk-demo/clipboard.rb +72 -0
  253. data/sample/gtk-demo/colorsel.rb +84 -0
  254. data/sample/gtk-demo/common.rb +88 -0
  255. data/sample/gtk-demo/demo.ui +258 -0
  256. data/sample/gtk-demo/dialog.rb +137 -0
  257. data/sample/gtk-demo/drawingarea.rb +226 -0
  258. data/sample/gtk-demo/editable_cells.rb +172 -0
  259. data/sample/gtk-demo/entry_completion.rb +63 -0
  260. data/sample/gtk-demo/expander.rb +40 -0
  261. data/sample/gtk-demo/floppybuddy.gif +0 -0
  262. data/sample/gtk-demo/gnome-applets.png +0 -0
  263. data/sample/gtk-demo/gnome-calendar.png +0 -0
  264. data/sample/gtk-demo/gnome-foot.png +0 -0
  265. data/sample/gtk-demo/gnome-fs-directory.png +0 -0
  266. data/sample/gtk-demo/gnome-fs-regular.png +0 -0
  267. data/sample/gtk-demo/gnome-gimp.png +0 -0
  268. data/sample/gtk-demo/gnome-gmush.png +0 -0
  269. data/sample/gtk-demo/gnome-gsame.png +0 -0
  270. data/sample/gtk-demo/gnu-keys.png +0 -0
  271. data/sample/gtk-demo/gtk-logo-rgb.gif +0 -0
  272. data/sample/gtk-demo/hypertext.rb +211 -0
  273. data/sample/gtk-demo/iconview.rb +109 -0
  274. data/sample/gtk-demo/images.rb +197 -0
  275. data/sample/gtk-demo/item_factory.rb +94 -0
  276. data/sample/gtk-demo/list_store.rb +138 -0
  277. data/sample/gtk-demo/main.rb +382 -0
  278. data/sample/gtk-demo/menus.rb +172 -0
  279. data/sample/gtk-demo/panes.rb +156 -0
  280. data/sample/gtk-demo/pixbufs.rb +176 -0
  281. data/sample/gtk-demo/printing.rb +128 -0
  282. data/sample/gtk-demo/rotated_text.rb +84 -0
  283. data/sample/gtk-demo/ruby-gnome2-logo.png +0 -0
  284. data/sample/gtk-demo/sizegroup.rb +118 -0
  285. data/sample/gtk-demo/stock_browser.rb +235 -0
  286. data/sample/gtk-demo/textview.rb +436 -0
  287. data/sample/gtk-demo/tree_store.rb +270 -0
  288. data/sample/misc/aboutdialog.rb +42 -0
  289. data/sample/misc/aboutdialog2.rb +42 -0
  290. data/sample/misc/alpha-demo.rb +70 -0
  291. data/sample/misc/assistant.rb +347 -0
  292. data/sample/misc/bindings.rb +107 -0
  293. data/sample/misc/button.rb +69 -0
  294. data/sample/misc/button2.rb +28 -0
  295. data/sample/misc/buttonbox.rb +93 -0
  296. data/sample/misc/cairo-pong.rb +215 -0
  297. data/sample/misc/calendar.rb +66 -0
  298. data/sample/misc/checkbutton.rb +46 -0
  299. data/sample/misc/colorselection.rb +25 -0
  300. data/sample/misc/combo_check.rb +71 -0
  301. data/sample/misc/combobox.rb +86 -0
  302. data/sample/misc/composited-windows.rb +113 -0
  303. data/sample/misc/cursor.rb +32 -0
  304. data/sample/misc/dialog.rb +44 -0
  305. data/sample/misc/dialog2.rb +39 -0
  306. data/sample/misc/dnd.rb +64 -0
  307. data/sample/misc/dndtreeview.rb +56 -0
  308. data/sample/misc/drag-move.rb +131 -0
  309. data/sample/misc/drawing.rb +90 -0
  310. data/sample/misc/entry.rb +34 -0
  311. data/sample/misc/entrycompletion.rb +33 -0
  312. data/sample/misc/expander.rb +27 -0
  313. data/sample/misc/filechooser.rb +41 -0
  314. data/sample/misc/frame.rb +69 -0
  315. data/sample/misc/gdkscreen.rb +32 -0
  316. data/sample/misc/gnome-logo-icon.png +0 -0
  317. data/sample/misc/helloworld.rb +35 -0
  318. data/sample/misc/iconview.rb +38 -0
  319. data/sample/misc/image.rb +42 -0
  320. data/sample/misc/itemfactory.rb +73 -0
  321. data/sample/misc/itemfactory2.rb +74 -0
  322. data/sample/misc/keyboard_grab.rb +29 -0
  323. data/sample/misc/label.rb +33 -0
  324. data/sample/misc/linkbutton.rb +42 -0
  325. data/sample/misc/listview.rb +92 -0
  326. data/sample/misc/menu.rb +81 -0
  327. data/sample/misc/misc_button.rb +49 -0
  328. data/sample/misc/mouse-gesture.rb +465 -0
  329. data/sample/misc/pangorenderer.rb +66 -0
  330. data/sample/misc/pointer_grab.rb +34 -0
  331. data/sample/misc/print.rb +247 -0
  332. data/sample/misc/properties.rb +85 -0
  333. data/sample/misc/radiobutton.rb +47 -0
  334. data/sample/misc/recentchooserdialog.rb +52 -0
  335. data/sample/misc/rgtk+cairo.rb +42 -0
  336. data/sample/misc/scalebutton.rb +19 -0
  337. data/sample/misc/settings.rb +41 -0
  338. data/sample/misc/statusicon.rb +123 -0
  339. data/sample/misc/stock.rb +36 -0
  340. data/sample/misc/style_property.rb +67 -0
  341. data/sample/misc/style_property.rc +19 -0
  342. data/sample/misc/t-gtkplug.rb +58 -0
  343. data/sample/misc/t-gtksocket.rb +65 -0
  344. data/sample/misc/test.xpm +92 -0
  345. data/sample/misc/textbuffer_serialize.rb +130 -0
  346. data/sample/misc/threads.rb +72 -0
  347. data/sample/misc/to_drawable.rb +42 -0
  348. data/sample/misc/togglebutton.rb +34 -0
  349. data/sample/misc/toolbar.rb +55 -0
  350. data/sample/misc/tooltips.rb +204 -0
  351. data/sample/misc/tree_combo.rb +79 -0
  352. data/sample/misc/tree_progress.rb +63 -0
  353. data/sample/misc/treemodelfilter.rb +49 -0
  354. data/sample/misc/treeview.rb +71 -0
  355. data/sample/misc/uimanager.rb +148 -0
  356. data/sample/misc/uimanager2.rb +91 -0
  357. data/sample/misc/uimanager2.xml +36 -0
  358. data/sample/misc/window.rb +24 -0
  359. data/sample/misc/xbm_cursor.rb +43 -0
  360. data/sample/testgtk/3DRings.xpm +116 -0
  361. data/sample/testgtk/FilesQueue.xpm +98 -0
  362. data/sample/testgtk/Modeller.xpm +117 -0
  363. data/sample/testgtk/README +14 -0
  364. data/sample/testgtk/button.rb +124 -0
  365. data/sample/testgtk/buttonbox.rb +100 -0
  366. data/sample/testgtk/check-n.xpm +21 -0
  367. data/sample/testgtk/check-y.xpm +21 -0
  368. data/sample/testgtk/checkbutton.rb +67 -0
  369. data/sample/testgtk/circles.xbm +46 -0
  370. data/sample/testgtk/colorselect.rb +33 -0
  371. data/sample/testgtk/dialog.rb +48 -0
  372. data/sample/testgtk/entry.rb +73 -0
  373. data/sample/testgtk/filesel.rb +65 -0
  374. data/sample/testgtk/fontselection.rb +56 -0
  375. data/sample/testgtk/labels.rb +74 -0
  376. data/sample/testgtk/layout.rb +108 -0
  377. data/sample/testgtk/marble.xpm +408 -0
  378. data/sample/testgtk/menu.rb +79 -0
  379. data/sample/testgtk/notebook.rb +280 -0
  380. data/sample/testgtk/pixmap.rb +58 -0
  381. data/sample/testgtk/progressbar.rb +173 -0
  382. data/sample/testgtk/radiobutton.rb +61 -0
  383. data/sample/testgtk/range.rb +65 -0
  384. data/sample/testgtk/reparent.rb +91 -0
  385. data/sample/testgtk/sample.rb +80 -0
  386. data/sample/testgtk/savedposition.rb +87 -0
  387. data/sample/testgtk/scrolledwindow.rb +67 -0
  388. data/sample/testgtk/shapedwindow.rb +99 -0
  389. data/sample/testgtk/spinbutton.rb +181 -0
  390. data/sample/testgtk/statusbar.rb +89 -0
  391. data/sample/testgtk/test.xpm +92 -0
  392. data/sample/testgtk/testgtk.rb +176 -0
  393. data/sample/testgtk/testgtkrc +146 -0
  394. data/sample/testgtk/testgtkrc2 +21 -0
  395. data/sample/testgtk/togglebutton.rb +53 -0
  396. data/sample/testgtk/toolbar.rb +82 -0
  397. data/sample/testgtk/tooltips.rb +41 -0
  398. data/sample/testgtk/wmhints.rb +40 -0
  399. data/test/gtk-test-utils.rb +15 -0
  400. data/test/run-test.rb +32 -0
  401. data/test/test_gc.rb +25 -0
  402. data/test/test_gdk.rb +18 -0
  403. data/test/test_gdk_color.rb +10 -0
  404. data/test/test_gdk_display.rb +37 -0
  405. data/test/test_gdk_event.rb +11 -0
  406. data/test/test_gdk_gc.rb +7 -0
  407. data/test/test_gdk_keymap.rb +8 -0
  408. data/test/test_gdk_pango.rb +9 -0
  409. data/test/test_gdk_selection_data.rb +17 -0
  410. data/test/test_gdk_window.rb +29 -0
  411. data/test/test_gdk_window_attribute.rb +9 -0
  412. data/test/test_gtk_about_dialog.rb +14 -0
  413. data/test/test_gtk_buildable.rb +66 -0
  414. data/test/test_gtk_builder.rb +188 -0
  415. data/test/test_gtk_entry.rb +18 -0
  416. data/test/test_gtk_icon_theme.rb +30 -0
  417. data/test/test_gtk_image.rb +8 -0
  418. data/test/test_gtk_list_store.rb +65 -0
  419. data/test/test_gtk_menu_item.rb +13 -0
  420. data/test/test_gtk_rc_style.rb +14 -0
  421. data/test/test_gtk_tree_path.rb +20 -0
  422. data/test/test_gtk_unix_print.rb +14 -0
  423. data/test/test_gtk_widget.rb +32 -0
  424. metadata +553 -94
  425. data/LICENSE +0 -19
@@ -0,0 +1,197 @@
1
+ # Copyright (c) 2003-2005 Ruby-GNOME2 Project Team
2
+ # This program is licenced under the same licence as Ruby-GNOME2.
3
+ #
4
+ # $Id: images.rb,v 1.5 2006/04/08 12:30:03 mutoh Exp $
5
+ =begin
6
+ = Images
7
+
8
+ Gtk::Image is used to display an image; the image can be in a number of formats.
9
+ Typically, you load an image into a Gdk::Pixbuf, then display the pixbuf.
10
+
11
+ This demo code shows some of the more obscure cases, in the simple
12
+ case a call to Gtk::Image.new is all you need.
13
+
14
+ If you want to put image data in your program as a String variable,
15
+ use the make-inline-pixbuf program that comes with GTK+.
16
+ This way you won't need to depend on loading external files, your
17
+ application binary can be self-contained.
18
+ =end
19
+ require 'common'
20
+
21
+ module Demo
22
+ class Images < BasicWindow
23
+ def initialize
24
+ @pixbuf_loader = nil
25
+ @load_timeout = 0
26
+ @image_stream = nil
27
+
28
+ super('Images')
29
+ signal_connect('destroy') do
30
+ cleanup_callback
31
+ end
32
+
33
+ self.border_width = 8
34
+
35
+ vbox = Gtk::VBox.new(false, 8)
36
+ vbox.border_width = 8
37
+ add(vbox)
38
+
39
+ label = Gtk::Label.new
40
+ label.set_markup('<u>Image loaded from a file</u>')
41
+ vbox.pack_start(label, false, false, 0)
42
+
43
+ frame = Gtk::Frame.new
44
+ frame.shadow_type = Gtk::SHADOW_IN
45
+
46
+ # The alignment keeps the frame from growing when users resize
47
+ # the window
48
+ align = Gtk::Alignment.new(0.5, 0.5, 0, 0)
49
+ align.add(frame)
50
+ vbox.pack_start(align, false, false, 0)
51
+
52
+ # demo_find_file looks in the the current directory first,
53
+ # so you can run gtk-demo without installing GTK, then looks
54
+ # in the location where the file is installed.
55
+ pixbuf = nil
56
+ begin
57
+ filename = Demo.find_file('gtk-logo-rgb.gif')
58
+ pixbuf = Gdk::Pixbuf.new(filename)
59
+ rescue
60
+ # This code shows off error handling. You can just use
61
+ # Gtk::Image.new instead if you don't want to report
62
+ # errors to the user. If the file doesn't load when using
63
+ # Gtk::Image.new, a 'missing image' icon will
64
+ # be displayed instead.
65
+ dialog = Gtk::MessageDialog.new(self,
66
+ Gtk::Dialog::DESTROY_WITH_PARENT,
67
+ Gtk::MessageDialog::ERROR,
68
+ Gtk::MessageDialog::BUTTONS_CLOSE,
69
+ "Unable to open image file 'gtk-logo-rgb.gif': #{$1}")
70
+
71
+ dialog.signal_connect('response') do |widget, data|
72
+ widget.destroy
73
+ end
74
+ dialog.show
75
+ end
76
+
77
+ image = Gtk::Image.new(pixbuf)
78
+ frame.add(image)
79
+
80
+
81
+ # Animation
82
+ label = Gtk::Label.new
83
+ label.set_markup('<u>Animation loaded from a file</u>')
84
+ vbox.pack_start(label, false, false, 0)
85
+
86
+ frame = Gtk::Frame.new
87
+ frame.shadow_type = Gtk::SHADOW_IN
88
+
89
+ # The alignment keeps the frame from growing when users resize
90
+ # the window
91
+ align = Gtk::Alignment.new(0.5, 0.5, 0, 0)
92
+ align.add(frame)
93
+ vbox.pack_start(align, false, false, 0)
94
+
95
+ filename = Demo.find_file('floppybuddy.gif')
96
+ image = Gtk::Image.new(filename)
97
+ frame.add(image)
98
+
99
+
100
+ # Progressive
101
+ label = Gtk::Label.new
102
+ label.set_markup('<u>Progressive image loading</u>')
103
+ vbox.pack_start(label, false, false, 0)
104
+
105
+ frame = Gtk::Frame.new(nil)
106
+ frame.shadow_type = Gtk::SHADOW_IN
107
+
108
+ # The alignment keeps the frame from growing when users resize
109
+ # the window
110
+ align = Gtk::Alignment.new(0.5, 0.5, 0, 0)
111
+ align.add(frame)
112
+ vbox.pack_start(align, false, false, 0)
113
+
114
+ # Create an empty image for now; the progressive loader
115
+ # will create the pixbuf and fill it in.
116
+ image = Gtk::Image.new
117
+ frame.add(image)
118
+
119
+ start_progressive_loading(image)
120
+
121
+ # Sensitivity control
122
+ button = Gtk::ToggleButton.new('_Insensitive', true)
123
+ vbox.pack_start(button, false, false, 0)
124
+
125
+ button.signal_connect('toggled') do |widget|
126
+ vbox.children.each do |widget|
127
+ if widget != button
128
+ widget.sensitive = ! button.active?
129
+ end
130
+ end
131
+ end
132
+ end
133
+
134
+ def start_progressive_loading(image)
135
+ @load_timeout = Gtk.timeout_add(150) do
136
+ progressive_timeout(image)
137
+ end
138
+ end
139
+
140
+ def progressive_timeout(image)
141
+ if @image_stream
142
+ buf = @image_stream.read(256)
143
+
144
+ @pixbuf_loader.write(buf)
145
+
146
+ if @image_stream.eof?
147
+ @image_stream.close
148
+ @image_stream = nil
149
+
150
+ @pixbuf_loader.close
151
+ @pixbuf_loader = nil
152
+ end
153
+ else
154
+ filename = Demo.find_file('alphatest.png')
155
+ @image_stream = File.open(filename, 'rb')
156
+
157
+ if @pixbuf_loader != nil
158
+ @pixbuf_loader.close
159
+ @pixbuf_loader = nil
160
+ end
161
+
162
+ @pixbuf_loader = Gdk::PixbufLoader.new
163
+
164
+ @pixbuf_loader.signal_connect('area_prepared') do |loader|
165
+ pixbuf = loader.pixbuf
166
+
167
+ # Avoid displaying random memory contents, since the pixbuf
168
+ # isn't filled in yet.
169
+ pixbuf.fill!(0xaaaaaaff)
170
+
171
+ image.pixbuf = pixbuf
172
+ end
173
+
174
+ @pixbuf_loader.signal_connect('area_updated') do
175
+ # We know the pixbuf inside the Gtk::Image has changed, but the image
176
+ # itself doesn't know this; so queue a redraw. If we wanted to be
177
+ # really efficient, we could use a drawing area or something
178
+ # instead of a Gtk::Image, so we could control the exact position of
179
+ # the pixbuf on the display, then we could queue a draw for only
180
+ # the updated area of the image.
181
+ image.queue_draw
182
+ end
183
+ end
184
+
185
+ # leave timeout installed
186
+ return true
187
+ end
188
+
189
+ def cleanup_callback
190
+ @pixbuf_loader.close if @pixbuf_loader
191
+ @pixbuf_loader = nil
192
+ if @load_timeout != 0
193
+ Gtk.timeout_remove(@load_timeout)
194
+ end
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,94 @@
1
+ # Copyright (c) 2003-2005 Ruby-GNOME2 Project Team
2
+ # This program is licenced under the same licence as Ruby-GNOME2.
3
+ #
4
+ # $Id: item_factory.rb,v 1.4 2005/02/12 23:02:43 kzys Exp $
5
+ =begin
6
+ = Item Factory
7
+
8
+ The Gtk::ItemFactory object allows the easy creation of menus
9
+ from an array of descriptions of menu items.
10
+ =end
11
+ require 'common'
12
+
13
+ module Demo
14
+ class ItemFactory < BasicWindow
15
+ def initialize
16
+ super('Item Factory')
17
+
18
+ accel_group = Gtk::AccelGroup.new
19
+ item_factory = Gtk::ItemFactory.new(Gtk::ItemFactory::TYPE_MENU_BAR,
20
+ '<main>', accel_group)
21
+
22
+ add_accel_group(accel_group)
23
+ set_border_width(0)
24
+ ifactory_cb = proc do |data, widget|
25
+ puts "ItemFactory: activated \"#{Gtk::ItemFactory.path_from_widget(widget)}\""
26
+ end
27
+ menu_items = [
28
+ ['/_File'],
29
+ ['/File/tearoff1',
30
+ '<Tearoff>', nil, nil, ifactory_cb],
31
+ ['/File/_New',
32
+ '<Item>', '<control>N', nil, ifactory_cb],
33
+ ['/File/_Open',
34
+ '<Item>', '<control>O', nil, ifactory_cb],
35
+ ['/File/_Save',
36
+ '<Item>', '<control>S', nil, ifactory_cb],
37
+ ['/File/Save _As...',
38
+ '<Item>', nil, nil, ifactory_cb],
39
+ ['/File/sep1', '<Separator>'],
40
+ ['/File/_Quit',
41
+ '<Item>', '<control>Q', nil, ifactory_cb],
42
+
43
+ ['/_Preferences'],
44
+ ['/_Preferences/_Color'],
45
+ [ '/_Preferences/Color/_Red',
46
+ '<RadioItem>', nil, nil, ifactory_cb],
47
+ ['/_Preferences/Color/_Green',
48
+ '/Preferences/Color/Red', nil, nil, ifactory_cb],
49
+ ['/_Preferences/Color/_Blue',
50
+ '/Preferences/Color/Red', nil, nil, ifactory_cb],
51
+ ['/_Preferences/_Shape'],
52
+ ['/_Preferences/Shape/_Square',
53
+ '<RadioItem>', nil, nil, ifactory_cb],
54
+ [ '/_Preferences/Shape/_Rectangle',
55
+ '/Preferences/Shape/Square', nil, nil, ifactory_cb],
56
+ [ '/_Preferences/Shape/_Oval',
57
+ '/Preferences/Shape/Rectangle', nil, nil, ifactory_cb],
58
+
59
+ [ '/_Help', '<LastBranch>'],
60
+ [ '/Help/_About', '<Item>', nil, nil, ifactory_cb],
61
+ ]
62
+ item_factory.create_items(menu_items)
63
+
64
+ item_factory.get_item('/Preferences/Shape/Oval').set_active(true)
65
+
66
+ box1 = Gtk::VBox.new(false, 0)
67
+ add(box1)
68
+
69
+ box1.pack_start(item_factory.get_widget('<main>'), false, false, 0)
70
+
71
+ label = Gtk::Label.new("Type\n<alt>\nto start")
72
+ label.set_size_request(200, 200)
73
+ label.set_alignment(0.5, 0.5)
74
+ box1.pack_start(label, true, true, 0)
75
+
76
+ separator = Gtk::HSeparator.new
77
+ box1.pack_start(separator)
78
+
79
+
80
+ box2 = Gtk::VBox.new(false, 10)
81
+ box2.set_border_width(10)
82
+ box1.pack_start(box2, false, true, 0)
83
+
84
+ button = Gtk::Button.new('close')
85
+ # TODO: Need signal_connect_swapped?
86
+ button.signal_connect('clicked') do
87
+ quit
88
+ end
89
+ box2.pack_start(button, true, true, 0)
90
+ button.set_flags(Gtk::Widget::CAN_DEFAULT)
91
+ button.grab_default
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,138 @@
1
+ # Copyright (c) 2003-2005 Ruby-GNOME2 Project Team
2
+ # This program is licenced under the same licence as Ruby-GNOME2.
3
+ #
4
+ # $Id: list_store.rb,v 1.5 2005/02/06 18:25:13 kzys Exp $
5
+ =begin
6
+ = Tree View/List Store
7
+
8
+ The Gtk::ListStore is used to store data in list form, to be used
9
+ later on by a Gtk::TreeView to display it. This demo builds a
10
+ simple Gtk::ListStore and displays it. See the Stock Browser
11
+ demo for a more advanced example.
12
+ =end
13
+ require 'common'
14
+
15
+ module Demo
16
+ class ListStore < BasicWindow
17
+ Bug = Struct.new('Bug', :fixed, :number, :severity, :description)
18
+ COLUMN_FIXED, COLUMN_NUMBER, COLUMN_SEVERITY, COLUMN_DESCRIPTION,
19
+ NUM_COLUMNS = *(0..5).to_a
20
+ DATA = [
21
+ [ false, 60482, 'Normal', 'scrollable notebooks and hidden tabs' ],
22
+ [ false, 60620, 'Critical', 'gdk_window_clear_area (gdkwindow-win32.c) is not thread-safe' ],
23
+ [ false, 50214, 'Major', 'Xft support does not clean up correctly' ],
24
+ [ true, 52877, 'Major', 'GtkFileSelection needs a refresh method. ' ],
25
+ [ false, 56070, 'Normal', "Can't click button after setting in sensitive" ],
26
+ [ true, 56355, 'Normal', 'GtkLabel - Not all changes propagate correctly' ],
27
+ [ false, 50055, 'Normal', 'Rework width/height computations for TreeView' ],
28
+ [ false, 58278, 'Normal', "gtk_dialog_set_response_sensitive doesn't work" ],
29
+ [ false, 55767, 'Normal', 'Getters for all setters' ],
30
+ [ false, 56925, 'Normal', 'Gtkcalender size' ],
31
+ [ false, 56221, 'Normal', 'Selectable label needs right-click copy menu' ],
32
+ [ true, 50939, 'Normal', 'Add shift clicking to GtkTextView' ],
33
+ [ false, 6112, 'Enhancement','netscape-like collapsable toolbars' ],
34
+ [ false, 1, 'Normal', 'First bug :=)' ],
35
+ ].collect do |ary|
36
+ Bug.new(*ary)
37
+ end
38
+ def initialize
39
+ super('GtkListStore demo')
40
+ self.border_width = 8
41
+
42
+ vbox = Gtk::VBox.new(false, 8)
43
+ add(vbox)
44
+
45
+ label = Gtk::Label.new('This is the bug list (note: not based on real data, it would be nice to have a nice ODBC interface to bugzilla or so, though).')
46
+ vbox.pack_start(label, false, false, 0)
47
+
48
+ sw = Gtk::ScrolledWindow.new(nil, nil)
49
+ sw.shadow_type = Gtk::SHADOW_ETCHED_IN
50
+ sw.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC)
51
+ vbox.pack_start(sw, true, true, 0)
52
+
53
+ # create tree model
54
+ model = create_model
55
+
56
+ # create tree view
57
+ treeview = Gtk::TreeView.new(model)
58
+ treeview.rules_hint = true
59
+ treeview.search_column = COLUMN_DESCRIPTION
60
+
61
+ sw.add(treeview)
62
+
63
+ # add columns to the tree view
64
+ add_columns(treeview)
65
+
66
+ set_default_size(280, 250)
67
+ end
68
+
69
+ def create_model
70
+ # create list store
71
+ store = Gtk::ListStore.new(TrueClass, Integer, String, String)
72
+
73
+ # add data to the list store
74
+ DATA.each do |bug|
75
+ iter = store.append
76
+ bug.each_with_index do |value, index|
77
+ iter[index] = value
78
+ end
79
+ end
80
+ return store
81
+ end
82
+
83
+ def add_columns(treeview)
84
+ # column for fixed toggles
85
+ renderer = Gtk::CellRendererToggle.new
86
+ renderer.signal_connect('toggled') do |cell, path|
87
+ fixed_toggled(treeview.model, path)
88
+ end
89
+
90
+ column = Gtk::TreeViewColumn.new('Fixed?',
91
+ renderer,
92
+ 'active' => COLUMN_FIXED)
93
+
94
+ # set this column to a fixed sizing (of 50 pixels)
95
+ column.sizing = Gtk::TreeViewColumn::FIXED
96
+ column.fixed_width = 50
97
+ treeview.append_column(column)
98
+
99
+ # column for bug numbers
100
+ renderer = Gtk::CellRendererText.new
101
+ column = Gtk::TreeViewColumn.new('Bug number',
102
+ renderer,
103
+ 'text' => COLUMN_NUMBER)
104
+ column.set_sort_column_id(COLUMN_NUMBER)
105
+ treeview.append_column(column)
106
+
107
+ # column for severities
108
+ renderer = Gtk::CellRendererText.new
109
+ column = Gtk::TreeViewColumn.new('Severity',
110
+ renderer,
111
+ 'text' => COLUMN_SEVERITY)
112
+ column.set_sort_column_id(COLUMN_SEVERITY)
113
+ treeview.append_column(column)
114
+
115
+ # column for description
116
+ renderer = Gtk::CellRendererText.new
117
+ column = Gtk::TreeViewColumn.new('Description',
118
+ renderer,
119
+ 'text' => COLUMN_DESCRIPTION)
120
+ column.set_sort_column_id(COLUMN_DESCRIPTION)
121
+ treeview.append_column(column)
122
+ end
123
+
124
+ def fixed_toggled(model, path_str)
125
+ path = Gtk::TreePath.new(path_str)
126
+
127
+ # get toggled iter
128
+ iter = model.get_iter(path)
129
+ fixed =iter[COLUMN_FIXED]
130
+
131
+ # do something with the value
132
+ fixed ^= 1
133
+
134
+ # set new value
135
+ iter[COLUMN_FIXED] = fixed
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,382 @@
1
+ #! /usr/bin/env ruby
2
+ =begin
3
+ main.rb - Main class of gtk-demo.
4
+
5
+ Copyright (c) 2003-2006 Ruby-GNOME2 Project Team
6
+ This program is licenced under the same licence as Ruby-GNOME2.
7
+
8
+ $Id: main.rb,v 1.20 2007/07/09 13:21:54 ggc Exp $
9
+ =end
10
+
11
+ require 'gtk3'
12
+
13
+ $:.unshift(File.dirname(__FILE__))
14
+
15
+ module Demo
16
+
17
+ class Main < Gtk::Window
18
+ TITLE_COLUMN, FILENAME_COLUMN, CLASS_COLUMN, ITALIC_COLUMN = 0, 1, 2, 3
19
+
20
+ def initialize
21
+ super()
22
+
23
+ @current_file = nil
24
+
25
+ @info_buffer = Gtk::TextBuffer.new
26
+ @source_buffer = Gtk::TextBuffer.new
27
+
28
+ set_title('Ruby/GTK+ Code Demos')
29
+ signal_connect('destroy') do
30
+ Gtk.main_quit
31
+ end
32
+
33
+ signal_connect("key_press_event") do |widget, event|
34
+ if event.state.control_mask? and event.keyval == Gdk::Keyval::GDK_q
35
+ destroy
36
+ true
37
+ else
38
+ false
39
+ end
40
+ end
41
+
42
+ hbox = Gtk::HBox.new
43
+ add(hbox)
44
+
45
+ tree = create_tree
46
+ scrolled_window = Gtk::ScrolledWindow.new
47
+ scrolled_window.add(tree)
48
+ hbox.pack_start(scrolled_window, false, false, 0)
49
+
50
+ notebook = Gtk::Notebook.new
51
+ hbox.pack_start(notebook, true, true, 0)
52
+
53
+ notebook.append_page(create_text(@info_buffer, false),
54
+ Gtk::Label.new('_Info', true))
55
+
56
+ notebook.append_page(create_text(@source_buffer, true),
57
+ Gtk::Label.new('_Source', true))
58
+
59
+ @info_buffer.create_tag('title',
60
+ {'font' => 'Sans 18'})
61
+
62
+ @source_buffer.create_tag('comment',
63
+ {'foreground' => 'red'})
64
+ @source_buffer.create_tag('const',
65
+ {'foreground' => 'ForestGreen'})
66
+ @source_buffer.create_tag('string',
67
+ {
68
+ 'foreground' => 'RosyBrown',
69
+ 'weight' => Pango::FontDescription::WEIGHT_BOLD
70
+ })
71
+ @source_buffer.create_tag('reserved',
72
+ {'foreground' => 'purple'})
73
+ end
74
+
75
+ def script_info(path)
76
+ title = nil
77
+ klass = nil
78
+ depend = nil
79
+
80
+ file = File.open(path)
81
+ file.each do |ln|
82
+ if not title and ln =~ /^=\s+(.*)$/
83
+ title = $1
84
+ if title =~ /^(.*)\((.+?)\)$/
85
+ title = $1
86
+ depend = $2
87
+ end
88
+ elsif not klass and ln =~ /\s*class\s+([A-Z][A-Za-z0-9_]*)/
89
+ klass = $1
90
+ end
91
+
92
+ if title and klass
93
+ break
94
+ end
95
+ end
96
+
97
+ if not klass
98
+ raise "File not found: #{path}. This script should be run from its directory."
99
+ end
100
+
101
+ return title, klass.intern, depend
102
+ end
103
+
104
+ def generate_index
105
+ # Target scripts
106
+ scripts = Dir.glob('*.rb') - %w(common.rb main.rb)
107
+
108
+ # Generate index tree
109
+ children = {}
110
+ index = []
111
+
112
+ scripts.each do |fn|
113
+ title, klass, depend = script_info(fn)
114
+
115
+ if depend and not Gtk.const_defined?(depend)
116
+ next
117
+ end
118
+
119
+ if title =~ %r{^(.+?)/(.+)$}
120
+ parent = $1
121
+ child = $2
122
+
123
+ unless children[parent]
124
+ children[parent] = []
125
+ index += [[parent, nil, nil, []]]
126
+ end
127
+
128
+ children[parent] += [[child, fn, klass]]
129
+ else
130
+ index += [[title, fn, klass]]
131
+ end
132
+ end
133
+
134
+ # Sort children
135
+ children.each_key do |parent|
136
+ children[parent].sort! do |a, b|
137
+ a[0] <=> b[0]
138
+ end
139
+ end
140
+
141
+ # Expand children
142
+ index.collect! do |row|
143
+ if row[3]
144
+ row[3] = children[row[0]]
145
+ end
146
+
147
+ row
148
+ end
149
+
150
+ index.sort! do |a, b|
151
+ a[0] <=> b[0]
152
+ end
153
+
154
+ index
155
+ end
156
+
157
+ def create_tree
158
+ model = Gtk::TreeStore.new(String, String, String, TrueClass)
159
+
160
+ tree_view = Gtk::TreeView.new
161
+ tree_view.set_model(model)
162
+ selection = tree_view.selection
163
+
164
+ selection.set_mode(Gtk::SELECTION_BROWSE)
165
+ tree_view.set_size_request(200, -1)
166
+
167
+ append_children(model, generate_index)
168
+
169
+ cell = Gtk::CellRendererText.new
170
+ cell.style = Pango::FontDescription::STYLE_ITALIC
171
+ column = Gtk::TreeViewColumn.new("Widget (double click for demo)", cell,
172
+ {
173
+ 'text' => TITLE_COLUMN,
174
+ 'style_set' => ITALIC_COLUMN,
175
+ })
176
+
177
+ tree_view.append_column(column)
178
+
179
+ selection.signal_connect('changed') do |selection|
180
+ iter = selection.selected
181
+ load_file(iter.get_value(FILENAME_COLUMN)) if iter
182
+ end
183
+ tree_view.signal_connect('row_activated') do |tree_view, path, column|
184
+ row_activated_cb(tree_view.model, path)
185
+ end
186
+
187
+ tree_view.expand_all
188
+ return tree_view
189
+ end
190
+
191
+ def append_children(model, source, parent = nil)
192
+ source.each do |title, filename, klass, children|
193
+ iter = model.append(parent)
194
+
195
+ [title, filename, klass].each_with_index do |value, i|
196
+ if value
197
+ iter.set_value(i, value)
198
+ end
199
+ end
200
+ iter.set_value(ITALIC_COLUMN, false)
201
+
202
+ if children
203
+ append_children(model, children, iter)
204
+ end
205
+ end
206
+ end
207
+
208
+ def row_activated_cb(model, path)
209
+ iter = model.get_iter(path)
210
+ iter.set_value(ITALIC_COLUMN, true)
211
+
212
+ lib = iter.get_value(FILENAME_COLUMN)
213
+ if lib
214
+ require(lib)
215
+
216
+ klass = Demo.const_get(iter.get_value(CLASS_COLUMN))
217
+ window = klass.new
218
+ window.signal_connect('destroy') do
219
+ iter.set_value(ITALIC_COLUMN, false)
220
+ end
221
+ window.show_all
222
+ @window = window
223
+ end
224
+ end
225
+
226
+ def create_text(buffer, is_source)
227
+ scrolled_window = Gtk::ScrolledWindow.new
228
+ scrolled_window.set_policy(Gtk::POLICY_AUTOMATIC,
229
+ Gtk::POLICY_AUTOMATIC)
230
+ scrolled_window.set_shadow_type(Gtk::SHADOW_IN)
231
+
232
+ text_view = Gtk::TextView.new
233
+
234
+ text_view.set_buffer(buffer)
235
+ text_view.set_editable(false)
236
+ text_view.set_cursor_visible(false)
237
+
238
+ scrolled_window.add(text_view)
239
+
240
+ if is_source
241
+ font_desc = Pango::FontDescription.new('Monospace 12')
242
+ text_view.modify_font(font_desc)
243
+
244
+ text_view.set_wrap_mode(Gtk::TextTag::WRAP_NONE)
245
+ else
246
+ text_view.set_wrap_mode(Gtk::TextTag::WRAP_WORD)
247
+ text_view.set_pixels_above_lines(2)
248
+ text_view.set_pixels_below_lines(2)
249
+ end
250
+
251
+ return scrolled_window
252
+ end
253
+
254
+ def fontify(start_iter = @source_buffer.start_iter,
255
+ end_iter = @source_buffer.end_iter)
256
+ str = @source_buffer.get_text(start_iter, end_iter, true)
257
+
258
+ tokenizer = RubyTokonizer.new
259
+ tokenizer.tokenize(str, start_iter.offset) do |tag, start, last|
260
+ @source_buffer.apply_tag(tag.to_s,
261
+ @source_buffer.get_iter_at_offset(start),
262
+ @source_buffer.get_iter_at_offset(last))
263
+ end
264
+ end
265
+
266
+
267
+ def load_file(filename)
268
+ if filename == @current_file
269
+ return
270
+ end
271
+
272
+ @info_buffer.delete(*@info_buffer.bounds)
273
+
274
+ @source_buffer.delete(*@source_buffer.bounds)
275
+
276
+ file = begin
277
+ File.open(filename)
278
+ rescue
279
+ $stderr.puts "Cannot open: #{$!}" if $DEBUG
280
+ return
281
+ end
282
+ start = @info_buffer.get_iter_at_offset(0)
283
+ state = :before_header
284
+
285
+ file.each do |line|
286
+ case state
287
+ when :before_header
288
+ if line =~ /^=begin$/
289
+ state = :in_header
290
+ end
291
+ when :in_header
292
+ if line =~ /^=end$/
293
+ state = :body
294
+ start = @source_buffer.get_iter_at_offset(0)
295
+ elsif line =~ /^=\s+(.*)$/
296
+ title = $1
297
+ title.gsub!(/\s*\(.*\)$/, '') # Delete depend field
298
+
299
+ last = start
300
+
301
+ @info_buffer.insert(last, title)
302
+ start = last.clone
303
+
304
+ start.backward_chars(title.length)
305
+ @info_buffer.apply_tag('title', start, last)
306
+
307
+ start = last
308
+ else
309
+ @info_buffer.insert(start, line)
310
+ end
311
+ when :body # Reading program body
312
+ @source_buffer.insert(start, line)
313
+ end
314
+ end
315
+
316
+ fontify
317
+
318
+ @current_file = filename
319
+ end
320
+ end
321
+
322
+ class RubyTokonizer
323
+ RESERVED_WORDS = %w(begin end module class def if then else while unless do case when require yield)
324
+ RESERVED_WORDS_PATTERN = Regexp.compile(/(^|\s+)(#{RESERVED_WORDS.collect do |pat| Regexp.quote(pat) end.join('|')})(\s+|$)/)
325
+
326
+ def tokenize(str, index = 0)
327
+ until str.empty?
328
+ tag = nil
329
+
330
+ case str
331
+ when /".+?"/, /'.+?'/
332
+ tag = :string
333
+ when /#.*$/
334
+ tag = :comment
335
+ when RESERVED_WORDS_PATTERN
336
+ tag = :reserved
337
+ when /[A-Z][A-Za-z0-9_]+/
338
+ tag = :const
339
+ end
340
+
341
+ if tag
342
+ tokenize($~.pre_match, index) do |*args|
343
+ yield(*args)
344
+ end
345
+ yield(tag, index + $~.begin(0), index + $~.end(0))
346
+ index += (str.length - $~.post_match.length)
347
+ str = $~.post_match
348
+ else
349
+ index += str.length
350
+ str = ''
351
+ end
352
+ end
353
+ end
354
+ end
355
+ end
356
+
357
+
358
+ target = ARGV.shift
359
+ if target
360
+ Demo::INDEX.each do |title, filename, klass_symbol, children|
361
+ if target == filename or target == klass_symbol.id2name
362
+ require filename
363
+
364
+ window = Demo.const_get(klass_symbol).new
365
+ window.show_all
366
+
367
+ class << window
368
+ def quit
369
+ Gtk.main_quit
370
+ end
371
+ end
372
+
373
+ break
374
+ end
375
+ end
376
+ else
377
+ main = Demo::Main.new
378
+ main.set_default_size(600, 400)
379
+ main.show_all
380
+ end
381
+
382
+ Gtk.main