wxruby3 0.9.2 → 0.9.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (379) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +35 -29
  3. data/README.md +24 -15
  4. data/ext/wxruby3/include/wxruby-ClientData.h +48 -0
  5. data/ext/wxruby3/include/wxruby-Config.h +23 -5
  6. data/ext/wxruby3/include/wxruby-Persistence.h +79 -0
  7. data/ext/wxruby3/include/wxruby-Validator.h +39 -0
  8. data/ext/wxruby3/include/wxruby-ValidatorBinding.h +64 -0
  9. data/ext/wxruby3/swig/custom/director.swg +8 -0
  10. data/ext/wxruby3/swig/mark_free_impl.i +0 -33
  11. data/ext/wxruby3/swig/memory_management.i +6 -0
  12. data/lib/wx/core/bitmap_combobox.rb +17 -21
  13. data/lib/wx/core/book_ctrl_base.rb +16 -0
  14. data/lib/wx/core/combobox.rb +13 -3
  15. data/lib/wx/core/config.rb +454 -83
  16. data/lib/wx/core/controlwithitems.rb +40 -130
  17. data/lib/wx/core/enum.rb +17 -1
  18. data/lib/wx/core/event.rb +6 -1
  19. data/lib/wx/core/evthandler.rb +8 -2
  20. data/lib/wx/core/generic_validator.rb +312 -0
  21. data/lib/wx/core/listbox.rb +2 -2
  22. data/lib/wx/core/log.rb +1 -1
  23. data/lib/wx/core/notebook.rb +10 -8
  24. data/lib/wx/core/owner_drawn_combobox.rb +45 -0
  25. data/lib/wx/core/peristent_object.rb +15 -0
  26. data/lib/wx/core/persistence_manager.rb +39 -0
  27. data/lib/wx/core/persistent_window.rb +16 -0
  28. data/lib/wx/core/size.rb +4 -0
  29. data/lib/wx/core/sizer.rb +1 -2
  30. data/lib/wx/core/standard_paths.rb +22 -0
  31. data/lib/wx/core/text_entry.rb +4 -1
  32. data/lib/wx/core/top_level_window.rb +16 -0
  33. data/lib/wx/core/treebook.rb +18 -0
  34. data/lib/wx/core/validator.rb +70 -5
  35. data/lib/wx/core/window.rb +3 -7
  36. data/lib/wx/core.rb +4 -0
  37. data/lib/wx/doc/art_locator.rb +1 -0
  38. data/lib/wx/doc/book_ctrl_base.rb +19 -0
  39. data/lib/wx/doc/comboctrl.rb +18 -0
  40. data/lib/wx/doc/config.rb +101 -41
  41. data/lib/wx/doc/controlwithitems.rb +16 -0
  42. data/lib/wx/doc/date_picker_ctrl.rb +23 -0
  43. data/lib/wx/doc/editable_listbox.rb +44 -0
  44. data/lib/wx/doc/enum.rb +15 -0
  45. data/lib/wx/doc/event.rb +12 -0
  46. data/lib/wx/doc/extra/12_client_data.md +89 -0
  47. data/lib/wx/doc/extra/13_validators.md +139 -0
  48. data/lib/wx/doc/extra/14_config.md +101 -0
  49. data/lib/wx/doc/extra/15_persistence.md +148 -0
  50. data/lib/wx/doc/gdi_common.rb +4 -0
  51. data/lib/wx/doc/generic_validator.rb +95 -0
  52. data/lib/wx/doc/html/simple_html_listbox.rb +22 -0
  53. data/lib/wx/doc/num_validator.rb +387 -0
  54. data/lib/wx/doc/owner_drawn_combobox.rb +96 -0
  55. data/lib/wx/doc/persistence_manager.rb +36 -0
  56. data/lib/wx/doc/persistent_object.rb +27 -0
  57. data/lib/wx/doc/pg/numeric_property_validator.rb +33 -0
  58. data/lib/wx/doc/static_bitmap.rb +25 -0
  59. data/lib/wx/doc/text_validator.rb +10 -0
  60. data/lib/wx/doc/top_level_window.rb +19 -0
  61. data/lib/wx/doc/treebook.rb +6 -1
  62. data/lib/wx/doc/validator.rb +113 -0
  63. data/lib/wx/doc/window.rb +30 -0
  64. data/lib/wx/html/simple_html_listbox.rb +24 -91
  65. data/lib/wx/keyword_defs.rb +34 -2
  66. data/lib/wx/rbn/ribbon_gallery.rb +0 -21
  67. data/lib/wx/version.rb +1 -1
  68. data/rakelib/build.rb +1 -1
  69. data/rakelib/lib/config/mingw.rb +12 -0
  70. data/rakelib/lib/core/include/client_data.inc +65 -0
  71. data/rakelib/lib/core/include/funcall.inc +1 -1
  72. data/rakelib/lib/core/package.rb +39 -3
  73. data/rakelib/lib/core/parameter.rb +1 -1
  74. data/rakelib/lib/core/spec.rb +10 -0
  75. data/rakelib/lib/core/spec_helper.rb +8 -2
  76. data/rakelib/lib/director/app.rb +18 -0
  77. data/rakelib/lib/director/app_traits.rb +3 -1
  78. data/rakelib/lib/director/bitmap_combobox.rb +2 -2
  79. data/rakelib/lib/director/combobox.rb +22 -0
  80. data/rakelib/lib/director/comboctrl.rb +1 -55
  81. data/rakelib/lib/director/config_base.rb +490 -19
  82. data/rakelib/lib/director/ctrl_with_items.rb +88 -21
  83. data/rakelib/lib/director/date_picker_ctrl.rb +8 -6
  84. data/rakelib/lib/director/editable_listbox.rb +30 -0
  85. data/rakelib/lib/director/event.rb +102 -12
  86. data/rakelib/lib/director/event_filter.rb +1 -1
  87. data/rakelib/lib/director/event_handler.rb +3 -2
  88. data/rakelib/lib/director/event_loop.rb +1 -1
  89. data/rakelib/lib/director/file_dialog_customize_hook.rb +2 -2
  90. data/rakelib/lib/director/functions.rb +4 -2
  91. data/rakelib/lib/director/generic_dirctrl.rb +17 -0
  92. data/rakelib/lib/director/grid_cell_attr.rb +1 -3
  93. data/rakelib/lib/director/grid_cell_editor.rb +1 -3
  94. data/rakelib/lib/director/grid_cell_renderer.rb +1 -3
  95. data/rakelib/lib/director/header_ctrl.rb +9 -1
  96. data/rakelib/lib/director/html_listbox.rb +97 -22
  97. data/rakelib/lib/director/num_validator.rb +495 -0
  98. data/rakelib/lib/director/numeric_property_validator.rb +131 -6
  99. data/rakelib/lib/director/owner_drawn_combobox.rb +192 -0
  100. data/rakelib/lib/director/persistence_manager.rb +410 -0
  101. data/rakelib/lib/director/persistent_object.rb +70 -0
  102. data/rakelib/lib/director/persistent_window.rb +73 -0
  103. data/rakelib/lib/director/pgproperty.rb +3 -29
  104. data/rakelib/lib/director/ribbon_button_bar.rb +3 -3
  105. data/rakelib/lib/director/ribbon_gallery.rb +3 -5
  106. data/rakelib/lib/director/sizer.rb +15 -4
  107. data/rakelib/lib/director/sizer_item.rb +13 -0
  108. data/rakelib/lib/director/static_bitmap.rb +32 -0
  109. data/rakelib/lib/director/text_entry.rb +5 -1
  110. data/rakelib/lib/director/text_validator.rb +124 -13
  111. data/rakelib/lib/director/toggle_button.rb +1 -0
  112. data/rakelib/lib/director/top_level_window.rb +0 -2
  113. data/rakelib/lib/director/tree_ctrl.rb +35 -0
  114. data/rakelib/lib/director/utils.rb +16 -2
  115. data/rakelib/lib/director/validator.rb +196 -21
  116. data/rakelib/lib/director/window.rb +16 -2
  117. data/rakelib/lib/extractor/function.rb +2 -1
  118. data/rakelib/lib/generate/analyzer.rb +44 -44
  119. data/rakelib/lib/generate/doc.rb +11 -5
  120. data/rakelib/lib/specs/interfaces.rb +5 -0
  121. data/rakelib/lib/swig_runner.rb +55 -9
  122. data/rakelib/lib/typemap/client_data.rb +67 -0
  123. data/rakelib/lib/typemap/common.rb +3 -3
  124. data/rakelib/lib/typemap/config.rb +8 -0
  125. data/rakelib/lib/typemap/datetime.rb +1 -1
  126. data/rakelib/lib/typemap/tree_itemid.rb +2 -2
  127. data/samples/aui/aui.rb +1237 -1233
  128. data/samples/calendar/calendar.rb +293 -289
  129. data/samples/controls/get_item_sample.rb +83 -79
  130. data/samples/controls/htlbox.rb +331 -327
  131. data/samples/dialogs/dialogs.rb +682 -694
  132. data/samples/dialogs/wizard.rb +52 -55
  133. data/samples/dragdrop/dragdrop.rb +146 -142
  134. data/samples/drawing/bitmap.rb +29 -26
  135. data/samples/drawing/bitmap_image.rb +84 -80
  136. data/samples/drawing/graphics_drawing.rb +209 -205
  137. data/samples/drawing/image_prt.rb +344 -340
  138. data/samples/drawing/maths_images.rb +18 -1
  139. data/samples/drawing/rmagic_bitmap_image.rb +88 -84
  140. data/samples/etc/caret.rb +306 -0
  141. data/samples/etc/miniframe.rb +65 -60
  142. data/samples/etc/sash.rb +109 -105
  143. data/samples/etc/scrollwin.rb +86 -80
  144. data/samples/etc/system_settings.rb +216 -209
  145. data/samples/event/activation.rb +72 -67
  146. data/samples/event/event.rb +160 -153
  147. data/samples/event/threaded.rb +8 -1
  148. data/samples/event/update_ui_event.rb +67 -60
  149. data/samples/grid/grid.rb +188 -181
  150. data/samples/grid/gridtablebase.rb +136 -129
  151. data/samples/html/html.rb +208 -204
  152. data/samples/mdi/mdi.rb +59 -54
  153. data/samples/minimal/minimal.rb +54 -51
  154. data/samples/minimal/nothing.rb +1 -0
  155. data/samples/printing/printing.rb +367 -377
  156. data/samples/printing/printing2.rb +203 -198
  157. data/samples/propgrid/propgrid.rb +2312 -2308
  158. data/samples/propgrid/propgrid_minimal.rb +57 -50
  159. data/samples/ribbon/ribbon.rb +780 -774
  160. data/samples/sampler/ext.rb +0 -33
  161. data/samples/sampler/sample.rb +4 -9
  162. data/samples/sampler.rb +1 -1
  163. data/samples/splash/splash.rb +118 -116
  164. data/samples/text/rich_textctrl.rb +207 -201
  165. data/samples/text/richtext.rb +1409 -1405
  166. data/samples/text/scintilla.rb +137 -128
  167. data/samples/text/textctrl.rb +89 -83
  168. data/samples/text/unicode.rb +175 -168
  169. data/samples/treectrl/treectrl.rb +1430 -1426
  170. data/samples/widgets/activityindicator.rb +95 -0
  171. data/samples/widgets/art/widgets/activityindicator.xpm +278 -0
  172. data/samples/widgets/art/widgets/bmpbtn.xpm +37 -0
  173. data/samples/widgets/art/widgets/bmpcombobox.xpm +54 -0
  174. data/samples/widgets/art/widgets/button.xpm +54 -0
  175. data/samples/widgets/art/widgets/checkbox.xpm +54 -0
  176. data/samples/{bigdemo/icons → widgets/art/widgets}/choice.xpm +1 -1
  177. data/samples/widgets/art/widgets/choicebk.xpm +54 -0
  178. data/samples/widgets/art/widgets/clrpicker.xpm +193 -0
  179. data/samples/widgets/art/widgets/combobox.xpm +54 -0
  180. data/samples/widgets/art/widgets/datepick.xpm +200 -0
  181. data/samples/widgets/art/widgets/dirctrl.xpm +54 -0
  182. data/samples/widgets/art/widgets/dirpicker.xpm +213 -0
  183. data/samples/widgets/art/widgets/filepicker.xpm +214 -0
  184. data/samples/widgets/art/widgets/fontpicker.xpm +185 -0
  185. data/samples/widgets/art/widgets/gauge.xpm +54 -0
  186. data/samples/widgets/art/widgets/header.xpm +54 -0
  187. data/samples/widgets/art/widgets/hyperlnk.xpm +54 -0
  188. data/samples/widgets/art/widgets/listbook.xpm +54 -0
  189. data/samples/widgets/art/widgets/listbox.xpm +54 -0
  190. data/samples/widgets/art/widgets/native.xpm +81 -0
  191. data/samples/widgets/art/widgets/notebook.xpm +54 -0
  192. data/samples/widgets/art/widgets/odcombobox.xpm +54 -0
  193. data/samples/widgets/art/widgets/radiobox.xpm +54 -0
  194. data/samples/widgets/art/widgets/scrolbar.xpm +54 -0
  195. data/samples/widgets/art/widgets/slider.xpm +54 -0
  196. data/samples/widgets/art/widgets/spinbtn.xpm +40 -0
  197. data/samples/widgets/art/widgets/statbmp.xpm +40 -0
  198. data/samples/widgets/art/widgets/statbox.xpm +54 -0
  199. data/samples/widgets/art/widgets/stattext.xpm +54 -0
  200. data/samples/widgets/art/widgets/text.xpm +54 -0
  201. data/samples/widgets/art/widgets/timepick.xpm +207 -0
  202. data/samples/widgets/art/widgets/toggle.xpm +54 -0
  203. data/samples/widgets/art/widgets/toucan.png +0 -0
  204. data/samples/widgets/bmpcombobox.rb +651 -0
  205. data/samples/widgets/button.rb +462 -0
  206. data/samples/widgets/checkbox.rb +211 -0
  207. data/samples/widgets/choice.rb +287 -0
  208. data/samples/widgets/clrpicker.rb +156 -0
  209. data/samples/widgets/combobox.rb +516 -0
  210. data/samples/widgets/datepick.rb +215 -0
  211. data/samples/widgets/dirctrl.rb +265 -0
  212. data/samples/widgets/dirpicker.rb +158 -0
  213. data/samples/widgets/editlbox.rb +122 -0
  214. data/samples/widgets/filectrl.rb +216 -0
  215. data/samples/widgets/filepicker.rb +214 -0
  216. data/samples/widgets/fontpicker.rb +135 -0
  217. data/samples/widgets/gauge.rb +311 -0
  218. data/samples/widgets/headerctrl.rb +236 -0
  219. data/samples/widgets/hyperlink.rb +203 -0
  220. data/samples/widgets/itemcontainer.rb +185 -0
  221. data/samples/widgets/listbox.rb +473 -0
  222. data/samples/widgets/notebook.rb +488 -0
  223. data/samples/widgets/odcombobox.rb +608 -0
  224. data/samples/widgets/radiobox.rb +328 -0
  225. data/samples/widgets/searchctrl.rb +159 -0
  226. data/samples/widgets/slider.rb +594 -0
  227. data/samples/widgets/spinbtn.rb +443 -0
  228. data/samples/widgets/statbmp.rb +130 -0
  229. data/samples/widgets/static.rb +436 -0
  230. data/samples/widgets/textctrl.rb +700 -0
  231. data/samples/widgets/timepick.rb +148 -0
  232. data/samples/widgets/tn_widgets.png +0 -0
  233. data/samples/widgets/toggle.rb +385 -0
  234. data/samples/widgets/widgets.rb +1229 -0
  235. data/samples/xrc/custom_xrc_sample.rb +47 -41
  236. data/samples/xrc/xrc_sample.rb +53 -47
  237. data/tests/test_config.rb +207 -42
  238. data/tests/test_event_handling.rb +52 -34
  239. data/tests/test_events.rb +7 -0
  240. data/tests/test_item_data.rb +24 -0
  241. data/tests/test_persistence.rb +142 -0
  242. data/tests/test_sizer.rb +44 -1
  243. data/tests/test_validators.rb +805 -0
  244. metadata +109 -138
  245. data/lib/wx/core/choice.rb +0 -14
  246. data/lib/wx/core/combo_ctrl.rb +0 -110
  247. data/rakelib/lib/typemap/grid_client_data.rb +0 -58
  248. data/samples/bigdemo/About.rbw +0 -39
  249. data/samples/bigdemo/ColorPanel.rbw +0 -23
  250. data/samples/bigdemo/GridSimple.rbw +0 -78
  251. data/samples/bigdemo/MDIDemo.rbw +0 -57
  252. data/samples/bigdemo/PopupMenu.rbw +0 -146
  253. data/samples/bigdemo/ShapedWindow.rbw +0 -128
  254. data/samples/bigdemo/Sizers.rbw +0 -541
  255. data/samples/bigdemo/bigdemo.rb +0 -817
  256. data/samples/bigdemo/demoTemplate.rbw +0 -33
  257. data/samples/bigdemo/helpfile.htb +0 -0
  258. data/samples/bigdemo/icons/Test 015.jpg +0 -0
  259. data/samples/bigdemo/icons/Test 015.png +0 -0
  260. data/samples/bigdemo/icons/choice.bmp +0 -0
  261. data/samples/bigdemo/icons/combo.bmp +0 -0
  262. data/samples/bigdemo/icons/combo.xpm +0 -27
  263. data/samples/bigdemo/icons/copy.xpm +0 -25
  264. data/samples/bigdemo/icons/cut.xpm +0 -24
  265. data/samples/bigdemo/icons/gauge.bmp +0 -0
  266. data/samples/bigdemo/icons/gauge.xpm +0 -27
  267. data/samples/bigdemo/icons/help.xpm +0 -25
  268. data/samples/bigdemo/icons/list.bmp +0 -0
  269. data/samples/bigdemo/icons/list.xpm +0 -27
  270. data/samples/bigdemo/icons/mondrian.ico +0 -0
  271. data/samples/bigdemo/icons/mondrian.xpm +0 -44
  272. data/samples/bigdemo/icons/new.xpm +0 -24
  273. data/samples/bigdemo/icons/ogl.ico +0 -0
  274. data/samples/bigdemo/icons/ogl.xpm +0 -45
  275. data/samples/bigdemo/icons/open.xpm +0 -26
  276. data/samples/bigdemo/icons/paste.bmp +0 -0
  277. data/samples/bigdemo/icons/paste.xpm +0 -38
  278. data/samples/bigdemo/icons/pointy.png +0 -0
  279. data/samples/bigdemo/icons/preview.xpm +0 -26
  280. data/samples/bigdemo/icons/print.xpm +0 -26
  281. data/samples/bigdemo/icons/radio.bmp +0 -0
  282. data/samples/bigdemo/icons/radio.xpm +0 -27
  283. data/samples/bigdemo/icons/robert.xpm +0 -415
  284. data/samples/bigdemo/icons/sashtest.ico +0 -0
  285. data/samples/bigdemo/icons/save.xpm +0 -25
  286. data/samples/bigdemo/icons/smiles.bmp +0 -0
  287. data/samples/bigdemo/icons/smiles.xpm +0 -39
  288. data/samples/bigdemo/icons/smiley.ico +0 -0
  289. data/samples/bigdemo/icons/smiley.xpm +0 -42
  290. data/samples/bigdemo/icons/stattext.xpm +0 -24
  291. data/samples/bigdemo/icons/test2.bmp +0 -0
  292. data/samples/bigdemo/icons/test2.png +0 -0
  293. data/samples/bigdemo/icons/test2.xpm +0 -79
  294. data/samples/bigdemo/icons/text.bmp +0 -0
  295. data/samples/bigdemo/icons/text.xpm +0 -27
  296. data/samples/bigdemo/icons/tog1.bmp +0 -0
  297. data/samples/bigdemo/icons/tog1.xpm +0 -38
  298. data/samples/bigdemo/icons/tog2.bmp +0 -0
  299. data/samples/bigdemo/icons/tog2.xpm +0 -38
  300. data/samples/bigdemo/icons/wxruby-128x128.png +0 -0
  301. data/samples/bigdemo/icons/wxwin.ico +0 -0
  302. data/samples/bigdemo/icons/wxwin16x16.png +0 -0
  303. data/samples/bigdemo/icons/wxwin16x16.xpm +0 -25
  304. data/samples/bigdemo/icons/wxwin32x32.png +0 -0
  305. data/samples/bigdemo/icons/wxwin48x48.png +0 -0
  306. data/samples/bigdemo/run.rb +0 -98
  307. data/samples/bigdemo/tips.txt +0 -7
  308. data/samples/bigdemo/utils.rb +0 -20
  309. data/samples/bigdemo/wxArtProvider.rbw +0 -282
  310. data/samples/bigdemo/wxBitmapButton.rbw +0 -65
  311. data/samples/bigdemo/wxButton.rbw +0 -64
  312. data/samples/bigdemo/wxCalendarCtrl.rbw +0 -59
  313. data/samples/bigdemo/wxCheckBox.rbw +0 -50
  314. data/samples/bigdemo/wxCheckListBox.rbw +0 -65
  315. data/samples/bigdemo/wxChoice.rbw +0 -47
  316. data/samples/bigdemo/wxChoicebook.rbw +0 -78
  317. data/samples/bigdemo/wxColourDialog.rbw +0 -33
  318. data/samples/bigdemo/wxComboBox.rbw +0 -77
  319. data/samples/bigdemo/wxCursor.rbw +0 -136
  320. data/samples/bigdemo/wxDialog.rbw +0 -74
  321. data/samples/bigdemo/wxDirDialog.rbw +0 -29
  322. data/samples/bigdemo/wxDragImage.rbw +0 -70
  323. data/samples/bigdemo/wxFileDialog.rbw +0 -37
  324. data/samples/bigdemo/wxFileDialog_Save.rbw +0 -35
  325. data/samples/bigdemo/wxFindReplaceDialog.rbw +0 -82
  326. data/samples/bigdemo/wxFontDialog.rbw +0 -200
  327. data/samples/bigdemo/wxFrame.rbw +0 -53
  328. data/samples/bigdemo/wxGauge.rbw +0 -65
  329. data/samples/bigdemo/wxGenericDirCtrl.rbw +0 -74
  330. data/samples/bigdemo/wxGrid.rbw +0 -66
  331. data/samples/bigdemo/wxHtmlHelpController.rbw +0 -52
  332. data/samples/bigdemo/wxListBox.rbw +0 -140
  333. data/samples/bigdemo/wxListCtrl_virtual.rbw +0 -112
  334. data/samples/bigdemo/wxMDIWindows.rbw +0 -50
  335. data/samples/bigdemo/wxMenu.rbw +0 -247
  336. data/samples/bigdemo/wxMessageDialog.rbw +0 -27
  337. data/samples/bigdemo/wxMiniFrame.rbw +0 -70
  338. data/samples/bigdemo/wxMultipleChoiceDialog.rbw +0 -29
  339. data/samples/bigdemo/wxNotebook.rbw +0 -136
  340. data/samples/bigdemo/wxProgressDialog.rbw +0 -43
  341. data/samples/bigdemo/wxRadioBox.rbw +0 -72
  342. data/samples/bigdemo/wxRadioButton.rbw +0 -125
  343. data/samples/bigdemo/wxSashWindow.rbw +0 -141
  344. data/samples/bigdemo/wxScrolledMessageDialog.rbw +0 -57
  345. data/samples/bigdemo/wxScrolledWindow.rbw +0 -199
  346. data/samples/bigdemo/wxSingleChoiceDialog.rbw +0 -33
  347. data/samples/bigdemo/wxSlider.rbw +0 -42
  348. data/samples/bigdemo/wxSpinButton.rbw +0 -50
  349. data/samples/bigdemo/wxSpinCtrl.rbw +0 -51
  350. data/samples/bigdemo/wxSplitterWindow.rbw +0 -63
  351. data/samples/bigdemo/wxStaticBitmap.rbw +0 -47
  352. data/samples/bigdemo/wxStaticText.rbw +0 -55
  353. data/samples/bigdemo/wxStatusBar.rbw +0 -126
  354. data/samples/bigdemo/wxTextCtrl.rbw +0 -149
  355. data/samples/bigdemo/wxTextEntryDialog.rbw +0 -31
  356. data/samples/bigdemo/wxToggleButton.rbw +0 -49
  357. data/samples/bigdemo/wxToolBar.rbw +0 -131
  358. data/samples/bigdemo/wxTreeCtrl.rbw +0 -191
  359. data/samples/caret/caret.rb +0 -298
  360. data/samples/caret/mondrian.xpm +0 -44
  361. data/samples/controls/books.rb +0 -189
  362. data/samples/controls/choice.xpm +0 -27
  363. data/samples/controls/combo.xpm +0 -27
  364. data/samples/controls/controls.rb +0 -1099
  365. data/samples/controls/gauge.xpm +0 -27
  366. data/samples/controls/list.xpm +0 -27
  367. data/samples/controls/mondrian.ico +0 -0
  368. data/samples/controls/mondrian.xpm +0 -44
  369. data/samples/controls/radio.xpm +0 -27
  370. data/samples/controls/stattext.xpm +0 -24
  371. data/samples/controls/test2.bmp +0 -0
  372. data/samples/controls/text.xpm +0 -27
  373. data/samples/controls/tn_books.png +0 -0
  374. data/samples/controls/tn_controls.png +0 -0
  375. data/samples/etc/choice.rb +0 -87
  376. data/samples/etc/tn_choice.png +0 -0
  377. data/samples/text/mondrian.ico +0 -0
  378. data/samples/text/mondrian.xpm +0 -44
  379. /data/samples/{caret → etc}/tn_caret.png +0 -0
@@ -17,1693 +17,1697 @@ require 'wx'
17
17
  # Also, some items remain to be implemented - for example, setting item
18
18
  # icons and item data.
19
19
 
20
- # Just some event ids for the numerous menu items
21
- TreeTest_TogButtons,
22
- TreeTest_TogTwist,
23
- TreeTest_TogLines,
24
- TreeTest_TogEdit,
25
- TreeTest_TogHideRoot,
26
- TreeTest_TogRootLines,
27
- TreeTest_TogBorder,
28
- TreeTest_TogFullHighlight,
29
- TreeTest_SetFgColour,
30
- TreeTest_SetBgColour,
31
- TreeTest_ResetStyle,
32
- TreeTest_Highlight,
33
- TreeTest_Dump,
34
- TreeTest_DumpSelected,
35
- TreeTest_Count,
36
- TreeTest_CountRec,
37
- TreeTest_Sort,
38
- TreeTest_SortRev,
39
- TreeTest_SetBold,
40
- TreeTest_ClearBold,
41
- TreeTest_Rename,
42
- TreeTest_Delete,
43
- TreeTest_DeleteChildren,
44
- TreeTest_DeleteAll,
45
- TreeTest_SelectRoot,
46
- TreeTest_SetFocusedRoot,
47
- TreeTest_ClearFocused,
48
- TreeTest_FreezeThaw,
49
- TreeTest_Recreate,
50
- TreeTest_ToggleImages,
51
- TreeTest_ToggleStates,
52
- TreeTest_ToggleBell,
53
- TreeTest_ToggleAlternateImages,
54
- TreeTest_ToggleAlternateStates,
55
- TreeTest_ToggleButtons,
56
- TreeTest_SetImageSize,
57
- TreeTest_ToggleSel,
58
- TreeTest_CollapseAndReset,
59
- TreeTest_EnsureVisible,
60
- TreeTest_SetFocus,
61
- TreeTest_AddItem,
62
- TreeTest_AddManyItems,
63
- TreeTest_InsertItem,
64
- TreeTest_IncIndent,
65
- TreeTest_DecIndent,
66
- TreeTest_IncSpacing,
67
- TreeTest_DecSpacing,
68
- TreeTest_ToggleIcon,
69
- TreeTest_ToggleState,
70
- TreeTest_ShowFirstVisible,
71
- TreeTest_ShowLastVisible,
72
- TreeTest_ShowNextVisible,
73
- TreeTest_ShowPrevVisible,
74
- TreeTest_ShowParent,
75
- TreeTest_ShowPrevSibling,
76
- TreeTest_ShowNextSibling,
77
- TreeTest_ScrollTo,
78
- TreeTest_SelectLast,
79
- TreeTest_Select,
80
- TreeTest_Unselect,
81
- TreeTest_SelectChildren = (Wx::ID_HIGHEST..Wx::ID_HIGHEST + 61).to_a
82
-
83
- TreeCtrlIcon_File,
84
- TreeCtrlIcon_FileSelected,
85
- TreeCtrlIcon_Folder,
86
- TreeCtrlIcon_FolderSelected,
87
- TreeCtrlIcon_FolderOpened = 0, 1, 2, 3, 4
88
-
89
- class MyTreeCtrl < Wx::TreeCtrl
90
- def initialize(parent, *args)
91
- super(parent, *args)
92
-
93
- @alternate_images = false
94
- @alternate_states = false
95
- @reverse_sort = false
96
-
97
- create_image_list(16)
98
- create_state_imageList
99
-
100
- # add some items to the tree
101
- add_test_items_to_tree(5, 2)
102
-
103
- # TreeCtrl supports a large number of different events...
104
- evt_tree_begin_drag self, :on_begin_drag
105
- evt_tree_begin_rdrag self, :on_begin_rdrag
106
- evt_tree_end_drag self, :on_end_drag
107
- evt_tree_begin_label_edit self, :on_begin_label_edit
108
- evt_tree_end_label_edit self, :on_end_label_edit
109
- evt_tree_delete_item self, :on_delete_item
110
- #evt_tree_set_info self, :on_set_info
111
- evt_tree_item_expanded self, :on_item_expanded
112
- evt_tree_item_expanding self, :on_item_expanding
113
- evt_tree_item_collapsed self, :on_item_collapsed
114
- evt_tree_item_collapsing self, :on_item_collapsing
115
- evt_tree_sel_changed self, :on_sel_changed
116
- evt_tree_sel_changing self, :on_sel_changing
117
- evt_tree_key_down self, :on_tree_key_down
118
- evt_tree_item_activated self, :on_item_activated
119
- evt_tree_state_image_click self, :on_item_state_clicked
120
-
121
- # EVT_TREE_ITEM_MENU is the preferred event for creating context menus
122
- # on a tree control, because it includes the point of the click or item,
123
- # meaning that no additional placement calculations are required.
124
- evt_tree_item_menu self, :on_item_menu
125
- evt_tree_item_right_click self, :on_item_rclick
126
-
127
- evt_context_menu :on_context_menu
128
-
129
- evt_right_dclick :on_rmouse_dclick
130
- evt_right_down :on_rmouse_down
131
- evt_right_up :on_rmouse_up
132
- end
133
-
134
- attr_accessor :alternate_images, :alternate_states, :reverse_sort
135
-
136
- def reset_broken_state_images
137
- count = self.state_image_list.get_image_count
138
- state = count > 0 ? count - 1 : Wx::TREE_ITEMSTATE_NONE
139
- do_reset_broken_state_images(self.root_item, nil, state)
140
- end
141
-
142
- def do_reset_broken_state_images(parent, cookie, state)
143
- unless cookie
144
- id, cookie = get_first_child(parent)
145
- else
146
- id, cookie = get_next_child(parent, cookie)
20
+ module TreeCtrl
21
+
22
+ # Just some event ids for the numerous menu items
23
+ TreeTest_TogButtons,
24
+ TreeTest_TogTwist,
25
+ TreeTest_TogLines,
26
+ TreeTest_TogEdit,
27
+ TreeTest_TogHideRoot,
28
+ TreeTest_TogRootLines,
29
+ TreeTest_TogBorder,
30
+ TreeTest_TogFullHighlight,
31
+ TreeTest_SetFgColour,
32
+ TreeTest_SetBgColour,
33
+ TreeTest_ResetStyle,
34
+ TreeTest_Highlight,
35
+ TreeTest_Dump,
36
+ TreeTest_DumpSelected,
37
+ TreeTest_Count,
38
+ TreeTest_CountRec,
39
+ TreeTest_Sort,
40
+ TreeTest_SortRev,
41
+ TreeTest_SetBold,
42
+ TreeTest_ClearBold,
43
+ TreeTest_Rename,
44
+ TreeTest_Delete,
45
+ TreeTest_DeleteChildren,
46
+ TreeTest_DeleteAll,
47
+ TreeTest_SelectRoot,
48
+ TreeTest_SetFocusedRoot,
49
+ TreeTest_ClearFocused,
50
+ TreeTest_FreezeThaw,
51
+ TreeTest_Recreate,
52
+ TreeTest_ToggleImages,
53
+ TreeTest_ToggleStates,
54
+ TreeTest_ToggleBell,
55
+ TreeTest_ToggleAlternateImages,
56
+ TreeTest_ToggleAlternateStates,
57
+ TreeTest_ToggleButtons,
58
+ TreeTest_SetImageSize,
59
+ TreeTest_ToggleSel,
60
+ TreeTest_CollapseAndReset,
61
+ TreeTest_EnsureVisible,
62
+ TreeTest_SetFocus,
63
+ TreeTest_AddItem,
64
+ TreeTest_AddManyItems,
65
+ TreeTest_InsertItem,
66
+ TreeTest_IncIndent,
67
+ TreeTest_DecIndent,
68
+ TreeTest_IncSpacing,
69
+ TreeTest_DecSpacing,
70
+ TreeTest_ToggleIcon,
71
+ TreeTest_ToggleState,
72
+ TreeTest_ShowFirstVisible,
73
+ TreeTest_ShowLastVisible,
74
+ TreeTest_ShowNextVisible,
75
+ TreeTest_ShowPrevVisible,
76
+ TreeTest_ShowParent,
77
+ TreeTest_ShowPrevSibling,
78
+ TreeTest_ShowNextSibling,
79
+ TreeTest_ScrollTo,
80
+ TreeTest_SelectLast,
81
+ TreeTest_Select,
82
+ TreeTest_Unselect,
83
+ TreeTest_SelectChildren = (Wx::ID_HIGHEST..Wx::ID_HIGHEST + 61).to_a
84
+
85
+ TreeCtrlIcon_File,
86
+ TreeCtrlIcon_FileSelected,
87
+ TreeCtrlIcon_Folder,
88
+ TreeCtrlIcon_FolderSelected,
89
+ TreeCtrlIcon_FolderOpened = 0, 1, 2, 3, 4
90
+
91
+ class MyTreeCtrl < Wx::TreeCtrl
92
+ def initialize(parent, *args)
93
+ super(parent, *args)
94
+
95
+ @alternate_images = false
96
+ @alternate_states = false
97
+ @reverse_sort = false
98
+
99
+ create_image_list(16)
100
+ create_state_imageList
101
+
102
+ # add some items to the tree
103
+ add_test_items_to_tree(5, 2)
104
+
105
+ # TreeCtrl supports a large number of different events...
106
+ evt_tree_begin_drag self, :on_begin_drag
107
+ evt_tree_begin_rdrag self, :on_begin_rdrag
108
+ evt_tree_end_drag self, :on_end_drag
109
+ evt_tree_begin_label_edit self, :on_begin_label_edit
110
+ evt_tree_end_label_edit self, :on_end_label_edit
111
+ evt_tree_delete_item self, :on_delete_item
112
+ #evt_tree_set_info self, :on_set_info
113
+ evt_tree_item_expanded self, :on_item_expanded
114
+ evt_tree_item_expanding self, :on_item_expanding
115
+ evt_tree_item_collapsed self, :on_item_collapsed
116
+ evt_tree_item_collapsing self, :on_item_collapsing
117
+ evt_tree_sel_changed self, :on_sel_changed
118
+ evt_tree_sel_changing self, :on_sel_changing
119
+ evt_tree_key_down self, :on_tree_key_down
120
+ evt_tree_item_activated self, :on_item_activated
121
+ evt_tree_state_image_click self, :on_item_state_clicked
122
+
123
+ # EVT_TREE_ITEM_MENU is the preferred event for creating context menus
124
+ # on a tree control, because it includes the point of the click or item,
125
+ # meaning that no additional placement calculations are required.
126
+ evt_tree_item_menu self, :on_item_menu
127
+ evt_tree_item_right_click self, :on_item_rclick
128
+
129
+ evt_context_menu :on_context_menu
130
+
131
+ evt_right_dclick :on_rmouse_dclick
132
+ evt_right_down :on_rmouse_down
133
+ evt_right_up :on_rmouse_up
147
134
  end
148
135
 
149
- return unless id.ok?
150
-
151
- curState = get_item_state(id)
136
+ attr_accessor :alternate_images, :alternate_states, :reverse_sort
152
137
 
153
- set_item_state(id, state) if curState != Wx::TREE_ITEMSTATE_NONE && curState > state
154
-
155
- do_reset_broken_state_images(id, nil, state) if item_has_children(id)
156
-
157
- do_reset_broken_state_images(parent, cookie, state)
158
- end
159
-
160
- def show_info(id)
161
- Wx::log_message("Item '%s': %sselected, %sexpanded, %sbold,\n" +
162
- "%d children (%d immediately under selected item).",
163
- get_item_text(id),
164
- bool_to_str(is_selected(id)),
165
- bool_to_str(is_expanded(id)),
166
- bool_to_str(is_bold(id)),
167
- get_children_count(id),
168
- get_children_count(id, false))
169
- end
138
+ def reset_broken_state_images
139
+ count = self.state_image_list.get_image_count
140
+ state = count > 0 ? count - 1 : Wx::TREE_ITEMSTATE_NONE
141
+ do_reset_broken_state_images(self.root_item, nil, state)
142
+ end
170
143
 
171
- def bool_to_str(bool)
172
- bool ? " " : "not "
173
- end
144
+ def do_reset_broken_state_images(parent, cookie, state)
145
+ unless cookie
146
+ id, cookie = get_first_child(parent)
147
+ else
148
+ id, cookie = get_next_child(parent, cookie)
149
+ end
174
150
 
175
- def do_sort_children(item, reverse = false)
176
- @reverse_sort = reverse
177
- sort_children(item)
178
- end
151
+ return unless id.ok?
179
152
 
180
- def do_ensure_visible
181
- ensure_visible(@last_item)
182
- end
153
+ curState = get_item_state(id)
183
154
 
184
- def image_size
185
- return @image_size
186
- end
155
+ set_item_state(id, state) if curState != Wx::TREE_ITEMSTATE_NONE && curState > state
187
156
 
188
- def is_test_item(item)
189
- # the test item is the first child folder
190
- return item_parent(item) == root_item && !prev_sibling(item)
191
- end
157
+ do_reset_broken_state_images(id, nil, state) if item_has_children(id)
192
158
 
193
- def create_image_list(size)
194
- if size < 0
195
- unset_image_list
196
- return
197
- elsif size == 0
198
- size = @image_size
199
- else
200
- @image_size = size
201
- end
202
-
203
- Wx::BusyCursor.busy do
204
- # should correspond to TreeCtrlIcon_xxx enum
205
- icons = if @alternate_images
206
- [Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon1.xpm'), Wx::BITMAP_TYPE_XPM),
207
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon2.xpm'), Wx::BITMAP_TYPE_XPM),
208
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon3.xpm'), Wx::BITMAP_TYPE_XPM),
209
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon4.xpm'), Wx::BITMAP_TYPE_XPM),
210
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon5.xpm'), Wx::BITMAP_TYPE_XPM),
211
- ]
212
- else
213
- icon_size = Wx::Size.new(@image_size, @image_size)
214
- ic1 = Wx::ArtProvider::get_icon(Wx::ART_NORMAL_FILE, Wx::ART_LIST, icon_size)
215
- ic2 = Wx::ArtProvider::get_icon(Wx::ART_FOLDER, Wx::ART_LIST, icon_size)
216
- [ic1, ic1, ic2, ic2, ic2]
217
- end
218
-
219
- # Make an image list containing small icons
220
- images = Wx::ImageList.new(@image_size, @image_size, true)
221
- icons.each do |ic|
222
- orig_size = ic.get_width
223
- ic = if @image_size == orig_size
224
- ic
225
- else
226
- Wx::Bitmap.new(ic.convert_to_image.rescale(@image_size, @image_size))
227
- end
228
- images.add(ic)
229
- end
230
- self.image_list = images
159
+ do_reset_broken_state_images(parent, cookie, state)
231
160
  end
232
- end
233
161
 
234
- def unset_image_list
235
- self.image_list = nil
236
- end
237
-
238
- def create_state_imageList(del = false)
239
- if del
240
- self.state_image_list = nil
241
- return
162
+ def show_info(id)
163
+ Wx::log_message("Item '%s': %sselected, %sexpanded, %sbold,\n" +
164
+ "%d children (%d immediately under selected item).",
165
+ get_item_text(id),
166
+ bool_to_str(is_selected(id)),
167
+ bool_to_str(is_expanded(id)),
168
+ bool_to_str(is_bold(id)),
169
+ get_children_count(id),
170
+ get_children_count(id, false))
242
171
  end
243
172
 
244
- Wx::BusyCursor.busy do
245
- icons = if @alternate_states
246
- [Wx::Icon.new(File.join(File.dirname(__FILE__), 'state1.xpm'), Wx::BITMAP_TYPE_XPM),
247
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'state2.xpm'), Wx::BITMAP_TYPE_XPM),
248
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'state3.xpm'), Wx::BITMAP_TYPE_XPM),
249
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'state4.xpm'), Wx::BITMAP_TYPE_XPM),
250
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'state5.xpm'), Wx::BITMAP_TYPE_XPM)]
251
-
252
- else
253
- [Wx::Icon.new(File.join(File.dirname(__FILE__), 'unchecked.xpm'), Wx::BITMAP_TYPE_XPM),
254
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'checked.xpm'), Wx::BITMAP_TYPE_XPM)]
255
- end
173
+ def bool_to_str(bool)
174
+ bool ? " " : "not "
175
+ end
256
176
 
257
- width = icons[0].width
258
- height = icons[0].height
177
+ def do_sort_children(item, reverse = false)
178
+ @reverse_sort = reverse
179
+ sort_children(item)
180
+ end
259
181
 
260
- # Make a state image list containing small icons
261
- states = Wx::ImageList.new(width, height, true)
182
+ def do_ensure_visible
183
+ ensure_visible(@last_item)
184
+ end
262
185
 
263
- icons.each { |ic| states.add(ic) }
186
+ def image_size
187
+ return @image_size
188
+ end
264
189
 
265
- self.state_image_list = states
190
+ def is_test_item(item)
191
+ # the test item is the first child folder
192
+ return item_parent(item) == root_item && !prev_sibling(item)
266
193
  end
267
- end
268
194
 
269
- def create_buttons_image_list(size)
270
- unless Wx::PLATFORM == 'WXMSW'
195
+ def create_image_list(size)
271
196
  if size < 0
272
- self.buttons_image_list = nil
197
+ unset_image_list
273
198
  return
199
+ elsif size == 0
200
+ size = @image_size
201
+ else
202
+ @image_size = size
274
203
  end
275
204
 
276
- # Make an image list containing small icons
277
- images = Wx::ImageList.new(size, size, true)
278
-
279
- # should correspond to TreeCtrlIcon_xxx enum
280
205
  Wx::BusyCursor.busy do
206
+ # should correspond to TreeCtrlIcon_xxx enum
281
207
  icons = if @alternate_images
282
- [Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon3.xpm'), Wx::BITMAP_TYPE_XPM),
208
+ [Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon1.xpm'), Wx::BITMAP_TYPE_XPM),
209
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon2.xpm'), Wx::BITMAP_TYPE_XPM),
283
210
  Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon3.xpm'), Wx::BITMAP_TYPE_XPM),
211
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon4.xpm'), Wx::BITMAP_TYPE_XPM),
284
212
  Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon5.xpm'), Wx::BITMAP_TYPE_XPM),
285
- Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon5.xpm'), Wx::BITMAP_TYPE_XPM)
286
213
  ]
287
214
  else
288
215
  icon_size = Wx::Size.new(@image_size, @image_size)
289
- ic1 = Wx::ArtProvider::get_icon(Wx::ART_FOLDER, Wx::ART_LIST, icon_size)
290
- ic2 = Wx::ArtProvider::get_icon(Wx::ART_FOLDER_OPEN, Wx::ART_LIST, icon_size)
291
- [ic1, ic1, ic2, ic2]
216
+ ic1 = Wx::ArtProvider::get_icon(Wx::ART_NORMAL_FILE, Wx::ART_LIST, icon_size)
217
+ ic2 = Wx::ArtProvider::get_icon(Wx::ART_FOLDER, Wx::ART_LIST, icon_size)
218
+ [ic1, ic1, ic2, ic2, ic2]
292
219
  end
293
220
 
221
+ # Make an image list containing small icons
222
+ images = Wx::ImageList.new(@image_size, @image_size, true)
294
223
  icons.each do |ic|
295
- if ic.width == size
296
- images.add(ic)
297
- else
298
- resized = ic.convert_to_image.rescale(size, size)
299
- images.add(Wx::Bitmap.new(resized))
300
- end
224
+ orig_size = ic.get_width
225
+ ic = if @image_size == orig_size
226
+ ic
227
+ else
228
+ Wx::Bitmap.new(ic.convert_to_image.rescale(@image_size, @image_size))
229
+ end
230
+ images.add(ic)
301
231
  end
302
-
303
- self.buttons_image_list = images
232
+ self.image_list = images
304
233
  end
305
234
  end
306
- end
307
235
 
308
- def on_compare_items(item1, item2)
309
- if @reverse_sort
310
- # just exchange 1st and 2nd items
311
- return super(item2, item1)
312
- else
313
- return super(item1, item2)
236
+ def unset_image_list
237
+ self.image_list = nil
314
238
  end
315
- end
316
239
 
317
- def add_items_recursively(parent_id, num_children, depth, folder)
318
- if depth > 0
319
- has_children = depth > 1
240
+ def create_state_imageList(del = false)
241
+ if del
242
+ self.state_image_list = nil
243
+ return
244
+ end
320
245
 
321
- (0...num_children).each do |n|
322
- # at depth 1 elements won't have any more children
323
- if has_children
324
- str = "Folder child #{n + 1}"
325
- else
326
- str = "File child #{folder}.#{n + 1}"
327
- end
328
- # here we pass to append_item normal and selected item images (we
329
- # suppose that selected image follows the normal one in the enum)
330
- if Wx::THE_APP.show_images
331
- image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder
332
- imageSel = image + 1
333
- else
334
- image = imageSel = -1
335
- end
336
- id = append_item(parent_id, str, image, imageSel)
246
+ Wx::BusyCursor.busy do
247
+ icons = if @alternate_states
248
+ [Wx::Icon.new(File.join(File.dirname(__FILE__), 'state1.xpm'), Wx::BITMAP_TYPE_XPM),
249
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'state2.xpm'), Wx::BITMAP_TYPE_XPM),
250
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'state3.xpm'), Wx::BITMAP_TYPE_XPM),
251
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'state4.xpm'), Wx::BITMAP_TYPE_XPM),
252
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'state5.xpm'), Wx::BITMAP_TYPE_XPM)]
337
253
 
338
- set_item_state(id, 0) if Wx::THE_APP.show_states
254
+ else
255
+ [Wx::Icon.new(File.join(File.dirname(__FILE__), 'unchecked.xpm'), Wx::BITMAP_TYPE_XPM),
256
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'checked.xpm'), Wx::BITMAP_TYPE_XPM)]
257
+ end
339
258
 
340
- # and now we also set the expanded one (only for the folders)
341
- if has_children && Wx::get_app.show_images
342
- set_item_image(id, TreeCtrlIcon_FolderOpened, Wx::TreeItemIcon_Expanded)
343
- end
259
+ width = icons[0].width
260
+ height = icons[0].height
344
261
 
345
- # remember the last child for OnEnsureVisible()
346
- if !has_children && n == num_children - 1
347
- @last_item = id
348
- end
262
+ # Make a state image list containing small icons
263
+ states = Wx::ImageList.new(width, height, true)
264
+
265
+ icons.each { |ic| states.add(ic) }
349
266
 
350
- add_items_recursively(id, num_children, depth - 1, n + 1)
267
+ self.state_image_list = states
351
268
  end
352
269
  end
353
- end
354
270
 
355
- def add_test_items_to_tree(num_children, depth)
356
- image = Wx::THE_APP.show_images ? TreeCtrlIcon_Folder : -1
357
- root_id = add_root("Root", image, image, 'Root item')
358
- if !self.has_flag(Wx::TR_HIDE_ROOT) && image != -1
359
- set_item_image(root_id, TreeCtrlIcon_FolderOpened, Wx::TreeItemIcon_Expanded)
360
- end
271
+ def create_buttons_image_list(size)
272
+ unless Wx::PLATFORM == 'WXMSW'
273
+ if size < 0
274
+ self.buttons_image_list = nil
275
+ return
276
+ end
361
277
 
362
- add_items_recursively(root_id, num_children, depth, 0)
278
+ # Make an image list containing small icons
279
+ images = Wx::ImageList.new(size, size, true)
280
+
281
+ # should correspond to TreeCtrlIcon_xxx enum
282
+ Wx::BusyCursor.busy do
283
+ icons = if @alternate_images
284
+ [Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon3.xpm'), Wx::BITMAP_TYPE_XPM),
285
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon3.xpm'), Wx::BITMAP_TYPE_XPM),
286
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon5.xpm'), Wx::BITMAP_TYPE_XPM),
287
+ Wx::Icon.new(File.join(File.dirname(__FILE__), 'icon5.xpm'), Wx::BITMAP_TYPE_XPM)
288
+ ]
289
+ else
290
+ icon_size = Wx::Size.new(@image_size, @image_size)
291
+ ic1 = Wx::ArtProvider::get_icon(Wx::ART_FOLDER, Wx::ART_LIST, icon_size)
292
+ ic2 = Wx::ArtProvider::get_icon(Wx::ART_FOLDER_OPEN, Wx::ART_LIST, icon_size)
293
+ [ic1, ic1, ic2, ic2]
294
+ end
295
+
296
+ icons.each do |ic|
297
+ if ic.width == size
298
+ images.add(ic)
299
+ else
300
+ resized = ic.convert_to_image.rescale(size, size)
301
+ images.add(Wx::Bitmap.new(resized))
302
+ end
303
+ end
363
304
 
364
- # set some colours/fonts for testing
365
- # note that font sizes can also be varied, but only on platforms
366
- # that use the generic TreeCtrl - OS X and GTK, and only if
367
- # Wx::TR_HAS_VARIABLE_ROW_HEIGHT style was used in the constructor
368
- if !self.has_flag(Wx::TR_HIDE_ROOT)
369
- set_item_font(root_id, Wx::ITALIC_FONT)
305
+ self.buttons_image_list = images
306
+ end
307
+ end
370
308
  end
371
309
 
372
- ids = get_item_children(root_id)
310
+ def on_compare_items(item1, item2)
311
+ if @reverse_sort
312
+ # just exchange 1st and 2nd items
313
+ return super(item2, item1)
314
+ else
315
+ return super(item1, item2)
316
+ end
317
+ end
373
318
 
374
- # make the first item blue
375
- set_item_text_colour(ids[0], Wx::BLUE)
319
+ def add_items_recursively(parent_id, num_children, depth, folder)
320
+ if depth > 0
321
+ has_children = depth > 1
376
322
 
377
- # make the third item red on grey
378
- set_item_text_colour(ids[2], Wx::RED)
379
- set_item_background_colour(ids[2], Wx::LIGHT_GREY)
380
- end
323
+ (0...num_children).each do |n|
324
+ # at depth 1 elements won't have any more children
325
+ if has_children
326
+ str = "Folder child #{n + 1}"
327
+ else
328
+ str = "File child #{folder}.#{n + 1}"
329
+ end
330
+ # here we pass to append_item normal and selected item images (we
331
+ # suppose that selected image follows the normal one in the enum)
332
+ if Wx::THE_APP.show_images
333
+ image = depth == 1 ? TreeCtrlIcon_File : TreeCtrlIcon_Folder
334
+ imageSel = image + 1
335
+ else
336
+ image = imageSel = -1
337
+ end
338
+ id = append_item(parent_id, str, image, imageSel)
381
339
 
382
- def get_last_tree_item
383
- item = self.root_item
384
- while item.ok?
385
- itemChild = get_last_child(item)
386
- break unless itemChild.ok?
340
+ set_item_state(id, 0) if Wx::THE_APP.show_states
387
341
 
388
- item = itemChild
389
- end
342
+ # and now we also set the expanded one (only for the folders)
343
+ if has_children && Wx::get_app.show_images
344
+ set_item_image(id, TreeCtrlIcon_FolderOpened, Wx::TreeItemIcon_Expanded)
345
+ end
390
346
 
391
- item
392
- end
393
- alias :last_tree_item :get_last_tree_item
347
+ # remember the last child for OnEnsureVisible()
348
+ if !has_children && n == num_children - 1
349
+ @last_item = id
350
+ end
394
351
 
395
- def get_items_recursively(parent_id, cookie)
396
- if cookie == -1
397
- id, cookie = get_first_child(parent_id)
398
- else
399
- id, cookie = get_next_child(parent_id, cookie)
400
- end
401
- unless id.ok?
402
- return nil
352
+ add_items_recursively(id, num_children, depth - 1, n + 1)
353
+ end
354
+ end
403
355
  end
404
356
 
405
- text = item_text(id)
406
- Wx::log_message(text)
357
+ def add_test_items_to_tree(num_children, depth)
358
+ image = Wx::THE_APP.show_images ? TreeCtrlIcon_Folder : -1
359
+ root_id = add_root("Root", image, image, 'Root item')
360
+ if !self.has_flag(Wx::TR_HIDE_ROOT) && image != -1
361
+ set_item_image(root_id, TreeCtrlIcon_FolderOpened, Wx::TreeItemIcon_Expanded)
362
+ end
407
363
 
408
- if item_has_children(id)
409
- get_items_recursively(id, -1)
410
- end
411
- get_items_recursively(parent_id, cookie)
412
- end
364
+ add_items_recursively(root_id, num_children, depth, 0)
413
365
 
414
- def do_toggle_icon(item)
415
- old_img = get_item_image(item)
416
- if old_img == TreeCtrlIcon_Folder
417
- new_img = TreeCtrlIcon_File
418
- else
419
- new_img = TreeCtrlIcon_Folder
420
- end
366
+ # set some colours/fonts for testing
367
+ # note that font sizes can also be varied, but only on platforms
368
+ # that use the generic TreeCtrl - OS X and GTK, and only if
369
+ # Wx::TR_HAS_VARIABLE_ROW_HEIGHT style was used in the constructor
370
+ if !self.has_flag(Wx::TR_HIDE_ROOT)
371
+ set_item_font(root_id, Wx::ITALIC_FONT)
372
+ end
421
373
 
422
- set_item_image(item, new_img, Wx::TreeItemIcon_Normal)
374
+ ids = get_item_children(root_id)
423
375
 
424
- old_img = get_item_image(item, Wx::TreeItemIcon_Selected)
425
- if old_img == TreeCtrlIcon_Folder
426
- new_img = TreeCtrlIcon_File
427
- else
428
- new_img = TreeCtrlIcon_Folder
429
- end
376
+ # make the first item blue
377
+ set_item_text_colour(ids[0], Wx::BLUE)
430
378
 
431
- set_item_image(item, new_img, Wx::TreeItemIcon_Selected)
432
- end
379
+ # make the third item red on grey
380
+ set_item_text_colour(ids[2], Wx::RED)
381
+ set_item_background_colour(ids[2], Wx::LIGHT_GREY)
382
+ end
433
383
 
434
- def do_toggle_state(item)
435
- if @alternate_states
436
- # sets random state unlike current
437
- nState = state = get_item_state(item)
384
+ def get_last_tree_item
385
+ item = self.root_item
386
+ while item.ok?
387
+ itemChild = get_last_child(item)
388
+ break unless itemChild.ok?
438
389
 
439
- nimg = state_image_list.image_count
440
- nState = (rand(::Time.now.to_i) % nimg) until nState != state
390
+ item = itemChild
391
+ end
441
392
 
442
- set_item_state(item, nState)
443
- else
444
- # we have only 2 checkbox states, so next state will be reversed
445
- set_item_state(item, Wx::TREE_ITEMSTATE_NEXT)
393
+ item
446
394
  end
447
- end
395
+ alias :last_tree_item :get_last_tree_item
448
396
 
449
- def on_begin_rdrag(event)
450
- Wx::log_message("OnBeginRDrag")
451
- event.skip
452
- end
397
+ def get_items_recursively(parent_id, cookie)
398
+ if cookie == -1
399
+ id, cookie = get_first_child(parent_id)
400
+ else
401
+ id, cookie = get_next_child(parent_id, cookie)
402
+ end
403
+ unless id.ok?
404
+ return nil
405
+ end
453
406
 
454
- def on_delete_item(event)
455
- Wx::log_message("OnDeleteItem")
456
- event.skip
457
- end
407
+ text = item_text(id)
408
+ Wx::log_message(text)
458
409
 
459
- def on_get_info(event)
460
- Wx::log_message("OnGetInfo")
461
- event.skip
462
- end
410
+ if item_has_children(id)
411
+ get_items_recursively(id, -1)
412
+ end
413
+ get_items_recursively(parent_id, cookie)
414
+ end
463
415
 
464
- def on_set_info(event)
465
- Wx::log_message("OnSetInfo")
466
- event.skip
467
- end
416
+ def do_toggle_icon(item)
417
+ old_img = get_item_image(item)
418
+ if old_img == TreeCtrlIcon_Folder
419
+ new_img = TreeCtrlIcon_File
420
+ else
421
+ new_img = TreeCtrlIcon_Folder
422
+ end
468
423
 
469
- def on_item_expanded(event)
470
- Wx::log_message("OnItemExpanded")
471
- event.skip
472
- end
424
+ set_item_image(item, new_img, Wx::TreeItemIcon_Normal)
473
425
 
474
- def on_item_expanding(event)
475
- Wx::log_message("OnItemExpanding")
476
- event.skip
477
- end
426
+ old_img = get_item_image(item, Wx::TreeItemIcon_Selected)
427
+ if old_img == TreeCtrlIcon_Folder
428
+ new_img = TreeCtrlIcon_File
429
+ else
430
+ new_img = TreeCtrlIcon_Folder
431
+ end
478
432
 
479
- def on_item_collapsed(event)
480
- Wx::log_message("OnItemCollapsed")
481
- event.skip
482
- end
433
+ set_item_image(item, new_img, Wx::TreeItemIcon_Selected)
434
+ end
483
435
 
484
- def on_sel_changed(event)
485
- Wx::log_message("OnSelChanged")
486
- event.skip
487
- end
436
+ def do_toggle_state(item)
437
+ if @alternate_states
438
+ # sets random state unlike current
439
+ nState = state = get_item_state(item)
488
440
 
489
- def on_sel_changing(event)
490
- Wx::log_message("OnSelChanging")
491
- event.skip
492
- end
441
+ nimg = state_image_list.image_count
442
+ nState = (rand(::Time.now.to_i) % nimg) until nState != state
493
443
 
494
- def log_key_event(name, event)
495
- keycode = event.key_code
496
-
497
- case keycode
498
- when Wx::K_BACK
499
- key = "BACK"
500
- when Wx::K_TAB
501
- key = "TAB"
502
- when Wx::K_RETURN
503
- key = "RETURN"
504
- when Wx::K_ESCAPE
505
- key = "ESCAPE"
506
- when Wx::K_SPACE
507
- key = "SPACE"
508
- when Wx::K_DELETE
509
- key = "DELETE"
510
- when Wx::K_START
511
- key = "START"
512
- when Wx::K_LBUTTON
513
- key = "LBUTTON"
514
- when Wx::K_RBUTTON
515
- key = "RBUTTON"
516
- when Wx::K_CANCEL
517
- key = "CANCEL"
518
- when Wx::K_MBUTTON
519
- key = "MBUTTON"
520
- when Wx::K_CLEAR
521
- key = "CLEAR"
522
- when Wx::K_SHIFT
523
- key = "SHIFT"
524
- when Wx::K_ALT
525
- key = "ALT"
526
- when Wx::K_CONTROL
527
- key = "CONTROL"
528
- when Wx::K_MENU
529
- key = "MENU"
530
- when Wx::K_PAUSE
531
- key = "PAUSE"
532
- when Wx::K_CAPITAL
533
- key = "CAPITAL"
534
- when Wx::K_END
535
- key = "END"
536
- when Wx::K_HOME
537
- key = "HOME"
538
- when Wx::K_LEFT
539
- key = "LEFT"
540
- when Wx::K_UP
541
- key = "UP"
542
- when Wx::K_RIGHT
543
- key = "RIGHT"
544
- when Wx::K_DOWN
545
- key = "DOWN"
546
- when Wx::K_SELECT
547
- key = "SELECT"
548
- when Wx::K_PRINT
549
- key = "PRINT"
550
- when Wx::K_EXECUTE
551
- key = "EXECUTE"
552
- when Wx::K_SNAPSHOT
553
- key = "SNAPSHOT"
554
- when Wx::K_INSERT
555
- key = "INSERT"
556
- when Wx::K_HELP
557
- key = "HELP"
558
- when Wx::K_NUMPAD0
559
- key = "NUMPAD0"
560
- when Wx::K_NUMPAD1
561
- key = "NUMPAD1"
562
- when Wx::K_NUMPAD2
563
- key = "NUMPAD2"
564
- when Wx::K_NUMPAD3
565
- key = "NUMPAD3"
566
- when Wx::K_NUMPAD4
567
- key = "NUMPAD4"
568
- when Wx::K_NUMPAD5
569
- key = "NUMPAD5"
570
- when Wx::K_NUMPAD6
571
- key = "NUMPAD6"
572
- when Wx::K_NUMPAD7
573
- key = "NUMPAD7"
574
- when Wx::K_NUMPAD8
575
- key = "NUMPAD8"
576
- when Wx::K_NUMPAD9
577
- key = "NUMPAD9"
578
- when Wx::K_MULTIPLY
579
- key = "MULTIPLY"
580
- when Wx::K_ADD
581
- key = "ADD"
582
- when Wx::K_SEPARATOR
583
- key = "SEPARATOR"
584
- when Wx::K_SUBTRACT
585
- key = "SUBTRACT"
586
- when Wx::K_DECIMAL
587
- key = "DECIMAL"
588
- when Wx::K_DIVIDE
589
- key = "DIVIDE"
590
- when Wx::K_F1
591
- key = "F1"
592
- when Wx::K_F2
593
- key = "F2"
594
- when Wx::K_F3
595
- key = "F3"
596
- when Wx::K_F4
597
- key = "F4"
598
- when Wx::K_F5
599
- key = "F5"
600
- when Wx::K_F6
601
- key = "F6"
602
- when Wx::K_F7
603
- key = "F7"
604
- when Wx::K_F8
605
- key = "F8"
606
- when Wx::K_F9
607
- key = "F9"
608
- when Wx::K_F10
609
- key = "F10"
610
- when Wx::K_F11
611
- key = "F11"
612
- when Wx::K_F12
613
- key = "F12"
614
- when Wx::K_F13
615
- key = "F13"
616
- when Wx::K_F14
617
- key = "F14"
618
- when Wx::K_F15
619
- key = "F15"
620
- when Wx::K_F16
621
- key = "F16"
622
- when Wx::K_F17
623
- key = "F17"
624
- when Wx::K_F18
625
- key = "F18"
626
- when Wx::K_F19
627
- key = "F19"
628
- when Wx::K_F20
629
- key = "F20"
630
- when Wx::K_F21
631
- key = "F21"
632
- when Wx::K_F22
633
- key = "F22"
634
- when Wx::K_F23
635
- key = "F23"
636
- when Wx::K_F24
637
- key = "F24"
638
- when Wx::K_NUMLOCK
639
- key = "NUMLOCK"
640
- when Wx::K_SCROLL
641
- key = "SCROLL"
642
- when Wx::K_PAGEUP
643
- key = "PAGEUP"
644
- when Wx::K_PAGEDOWN
645
- key = "PAGEDOWN"
646
- when Wx::K_NUMPAD_SPACE
647
- key = "NUMPAD_SPACE"
648
- when Wx::K_NUMPAD_TAB
649
- key = "NUMPAD_TAB"
650
- when Wx::K_NUMPAD_ENTER
651
- key = "NUMPAD_ENTER"
652
- when Wx::K_NUMPAD_F1
653
- key = "NUMPAD_F1"
654
- when Wx::K_NUMPAD_F2
655
- key = "NUMPAD_F2"
656
- when Wx::K_NUMPAD_F3
657
- key = "NUMPAD_F3"
658
- when Wx::K_NUMPAD_F4
659
- key = "NUMPAD_F4"
660
- when Wx::K_NUMPAD_HOME
661
- key = "NUMPAD_HOME"
662
- when Wx::K_NUMPAD_LEFT
663
- key = "NUMPAD_LEFT"
664
- when Wx::K_NUMPAD_UP
665
- key = "NUMPAD_UP"
666
- when Wx::K_NUMPAD_RIGHT
667
- key = "NUMPAD_RIGHT"
668
- when Wx::K_NUMPAD_DOWN
669
- key = "NUMPAD_DOWN"
670
- when Wx::K_NUMPAD_PAGEUP
671
- key = "NUMPAD_PAGEUP"
672
- when Wx::K_NUMPAD_PAGEDOWN
673
- key = "NUMPAD_PAGEDOWN"
674
- when Wx::K_NUMPAD_END
675
- key = "NUMPAD_END"
676
- when Wx::K_NUMPAD_BEGIN
677
- key = "NUMPAD_BEGIN"
678
- when Wx::K_NUMPAD_INSERT
679
- key = "NUMPAD_INSERT"
680
- when Wx::K_NUMPAD_DELETE
681
- key = "NUMPAD_DELETE"
682
- when Wx::K_NUMPAD_EQUAL
683
- key = "NUMPAD_EQUAL"
684
- when Wx::K_NUMPAD_MULTIPLY
685
- key = "NUMPAD_MULTIPLY"
686
- when Wx::K_NUMPAD_ADD
687
- key = "NUMPAD_ADD"
688
- when Wx::K_NUMPAD_SEPARATOR
689
- key = "NUMPAD_SEPARATOR"
690
- when Wx::K_NUMPAD_SUBTRACT
691
- key = "NUMPAD_SUBTRACT"
692
- when Wx::K_NUMPAD_DECIMAL
693
- key = "NUMPAD_DECIMAL"
694
- when Wx::K_BROWSER_BACK
695
- key = "BROWSER_BACK"
696
- when Wx::K_BROWSER_FORWARD
697
- key = "BROWSER_FORWARD"
698
- when Wx::K_BROWSER_REFRESH
699
- key = "BROWSER_REFRESH"
700
- when Wx::K_BROWSER_STOP
701
- key = "BROWSER_STOP"
702
- when Wx::K_BROWSER_SEARCH
703
- key = "BROWSER_SEARCH"
704
- when Wx::K_BROWSER_FAVORITES
705
- key = "BROWSER_FAVORITES"
706
- when Wx::K_BROWSER_HOME
707
- key = "BROWSER_HOME"
708
- when Wx::K_VOLUME_MUTE
709
- key = "VOLUME_MUTE"
710
- when Wx::K_VOLUME_DOWN
711
- key = "VOLUME_DOWN"
712
- when Wx::K_VOLUME_UP
713
- key = "VOLUME_UP"
714
- when Wx::K_MEDIA_NEXT_TRACK
715
- key = "MEDIA_NEXT_TRACK"
716
- when Wx::K_MEDIA_PREV_TRACK
717
- key = "MEDIA_PREV_TRACK"
718
- when Wx::K_MEDIA_STOP
719
- key = "MEDIA_STOP"
720
- when Wx::K_MEDIA_PLAY_PAUSE
721
- key = "MEDIA_PLAY_PAUSE"
722
- when Wx::K_LAUNCH_MAIL
723
- key = "LAUNCH_MAIL"
724
- when Wx::K_LAUNCH_APP1
725
- key = "LAUNCH_APP1"
726
- when Wx::K_LAUNCH_APP2
727
- key = "LAUNCH_APP2"
728
- else
729
- if keycode >= 32 && keycode < 127
730
- key = "'#{keycode.chr}'"
731
- elsif keycode > 0 && keycode < 27
732
- key = "Ctrl-#{?A + keycode - 1}"
444
+ set_item_state(item, nState)
733
445
  else
734
- key = "unknown (#{keycode})"
446
+ # we have only 2 checkbox states, so next state will be reversed
447
+ set_item_state(item, Wx::TREE_ITEMSTATE_NEXT)
735
448
  end
736
449
  end
737
450
 
738
- Wx::log_message("#{name} event: #{key} (flags = %s%s%s%s)" %
739
- [event.control_down ? 'C' : '-',
740
- event.alt_down ? 'A' : '-',
741
- event.shift_down ? 'S' : '-',
742
- event.meta_down ? 'M' : '-'])
743
- end
744
-
745
- def on_tree_key_down(event)
746
- log_key_event("Tree key down ", event.key_event)
747
- event.skip
748
- end
451
+ def on_begin_rdrag(event)
452
+ Wx::log_message("OnBeginRDrag")
453
+ event.skip
454
+ end
749
455
 
750
- def on_begin_drag(event)
751
- # need to explicitly allow drag
752
- if event.item != root_item
753
- @dragged_item = event.item
456
+ def on_delete_item(event)
457
+ Wx::log_message("OnDeleteItem")
458
+ event.skip
459
+ end
754
460
 
755
- clientpt = event.point
756
- screenpt = client_to_screen(clientpt)
757
- Wx::log_message("OnBeginDrag: started dragging %s at screen coords (%i,%i)" %
758
- [item_text(@dragged_item), screenpt.x, screenpt.y])
759
- event.allow
760
- else
761
- Wx::log_message("OnBeginDrag: selected item can't be dragged.")
461
+ def on_get_info(event)
462
+ Wx::log_message("OnGetInfo")
463
+ event.skip
762
464
  end
763
- end
764
465
 
765
- def on_end_drag(event)
766
- src_item = @dragged_item
767
- dest_item = event.item
768
- @dragged_item = nil
466
+ def on_set_info(event)
467
+ Wx::log_message("OnSetInfo")
468
+ event.skip
469
+ end
769
470
 
770
- if dest_item.ok? && !item_has_children(dest_item)
771
- # copy to the parent then
772
- dest_item = get_item_parent(dest_item)
471
+ def on_item_expanded(event)
472
+ Wx::log_message("OnItemExpanded")
473
+ event.skip
773
474
  end
774
475
 
775
- unless dest_item.ok?
776
- Wx::log_message("OnEndDrag: can't drop here.")
777
- return nil
476
+ def on_item_expanding(event)
477
+ Wx::log_message("OnItemExpanding")
478
+ event.skip
778
479
  end
779
480
 
780
- text = item_text(src_item)
781
- Wx::log_message("OnEndDrag: '%s' copied to '%s'.",
782
- text, item_text(dest_item))
481
+ def on_item_collapsed(event)
482
+ Wx::log_message("OnItemCollapsed")
483
+ event.skip
484
+ end
783
485
 
784
- # just do append here - we could also insert it just before/after the item
785
- # on which it was dropped, but self requires slightly more work... we also
786
- # completely ignore the client data and icon of the old item but could
787
- # copy them as well.
788
- #
789
- # Finally, we only copy one item here but we might copy the entire tree if
790
- # we were dragging a folder.
791
- image = Wx::THE_APP.show_images ? TreeCtrlIcon_File : -1
792
- new_id = append_item(dest_item, text, image)
486
+ def on_sel_changed(event)
487
+ Wx::log_message("OnSelChanged")
488
+ event.skip
489
+ end
793
490
 
794
- set_item_state(new_id, get_item_state(src_item)) if Wx::THE_APP.show_states
795
- end
491
+ def on_sel_changing(event)
492
+ Wx::log_message("OnSelChanging")
493
+ event.skip
494
+ end
796
495
 
797
- def on_begin_label_edit(event)
798
- Wx::log_message("OnBeginLabelEdit")
496
+ def log_key_event(name, event)
497
+ keycode = event.key_code
498
+
499
+ case keycode
500
+ when Wx::K_BACK
501
+ key = "BACK"
502
+ when Wx::K_TAB
503
+ key = "TAB"
504
+ when Wx::K_RETURN
505
+ key = "RETURN"
506
+ when Wx::K_ESCAPE
507
+ key = "ESCAPE"
508
+ when Wx::K_SPACE
509
+ key = "SPACE"
510
+ when Wx::K_DELETE
511
+ key = "DELETE"
512
+ when Wx::K_START
513
+ key = "START"
514
+ when Wx::K_LBUTTON
515
+ key = "LBUTTON"
516
+ when Wx::K_RBUTTON
517
+ key = "RBUTTON"
518
+ when Wx::K_CANCEL
519
+ key = "CANCEL"
520
+ when Wx::K_MBUTTON
521
+ key = "MBUTTON"
522
+ when Wx::K_CLEAR
523
+ key = "CLEAR"
524
+ when Wx::K_SHIFT
525
+ key = "SHIFT"
526
+ when Wx::K_ALT
527
+ key = "ALT"
528
+ when Wx::K_CONTROL
529
+ key = "CONTROL"
530
+ when Wx::K_MENU
531
+ key = "MENU"
532
+ when Wx::K_PAUSE
533
+ key = "PAUSE"
534
+ when Wx::K_CAPITAL
535
+ key = "CAPITAL"
536
+ when Wx::K_END
537
+ key = "END"
538
+ when Wx::K_HOME
539
+ key = "HOME"
540
+ when Wx::K_LEFT
541
+ key = "LEFT"
542
+ when Wx::K_UP
543
+ key = "UP"
544
+ when Wx::K_RIGHT
545
+ key = "RIGHT"
546
+ when Wx::K_DOWN
547
+ key = "DOWN"
548
+ when Wx::K_SELECT
549
+ key = "SELECT"
550
+ when Wx::K_PRINT
551
+ key = "PRINT"
552
+ when Wx::K_EXECUTE
553
+ key = "EXECUTE"
554
+ when Wx::K_SNAPSHOT
555
+ key = "SNAPSHOT"
556
+ when Wx::K_INSERT
557
+ key = "INSERT"
558
+ when Wx::K_HELP
559
+ key = "HELP"
560
+ when Wx::K_NUMPAD0
561
+ key = "NUMPAD0"
562
+ when Wx::K_NUMPAD1
563
+ key = "NUMPAD1"
564
+ when Wx::K_NUMPAD2
565
+ key = "NUMPAD2"
566
+ when Wx::K_NUMPAD3
567
+ key = "NUMPAD3"
568
+ when Wx::K_NUMPAD4
569
+ key = "NUMPAD4"
570
+ when Wx::K_NUMPAD5
571
+ key = "NUMPAD5"
572
+ when Wx::K_NUMPAD6
573
+ key = "NUMPAD6"
574
+ when Wx::K_NUMPAD7
575
+ key = "NUMPAD7"
576
+ when Wx::K_NUMPAD8
577
+ key = "NUMPAD8"
578
+ when Wx::K_NUMPAD9
579
+ key = "NUMPAD9"
580
+ when Wx::K_MULTIPLY
581
+ key = "MULTIPLY"
582
+ when Wx::K_ADD
583
+ key = "ADD"
584
+ when Wx::K_SEPARATOR
585
+ key = "SEPARATOR"
586
+ when Wx::K_SUBTRACT
587
+ key = "SUBTRACT"
588
+ when Wx::K_DECIMAL
589
+ key = "DECIMAL"
590
+ when Wx::K_DIVIDE
591
+ key = "DIVIDE"
592
+ when Wx::K_F1
593
+ key = "F1"
594
+ when Wx::K_F2
595
+ key = "F2"
596
+ when Wx::K_F3
597
+ key = "F3"
598
+ when Wx::K_F4
599
+ key = "F4"
600
+ when Wx::K_F5
601
+ key = "F5"
602
+ when Wx::K_F6
603
+ key = "F6"
604
+ when Wx::K_F7
605
+ key = "F7"
606
+ when Wx::K_F8
607
+ key = "F8"
608
+ when Wx::K_F9
609
+ key = "F9"
610
+ when Wx::K_F10
611
+ key = "F10"
612
+ when Wx::K_F11
613
+ key = "F11"
614
+ when Wx::K_F12
615
+ key = "F12"
616
+ when Wx::K_F13
617
+ key = "F13"
618
+ when Wx::K_F14
619
+ key = "F14"
620
+ when Wx::K_F15
621
+ key = "F15"
622
+ when Wx::K_F16
623
+ key = "F16"
624
+ when Wx::K_F17
625
+ key = "F17"
626
+ when Wx::K_F18
627
+ key = "F18"
628
+ when Wx::K_F19
629
+ key = "F19"
630
+ when Wx::K_F20
631
+ key = "F20"
632
+ when Wx::K_F21
633
+ key = "F21"
634
+ when Wx::K_F22
635
+ key = "F22"
636
+ when Wx::K_F23
637
+ key = "F23"
638
+ when Wx::K_F24
639
+ key = "F24"
640
+ when Wx::K_NUMLOCK
641
+ key = "NUMLOCK"
642
+ when Wx::K_SCROLL
643
+ key = "SCROLL"
644
+ when Wx::K_PAGEUP
645
+ key = "PAGEUP"
646
+ when Wx::K_PAGEDOWN
647
+ key = "PAGEDOWN"
648
+ when Wx::K_NUMPAD_SPACE
649
+ key = "NUMPAD_SPACE"
650
+ when Wx::K_NUMPAD_TAB
651
+ key = "NUMPAD_TAB"
652
+ when Wx::K_NUMPAD_ENTER
653
+ key = "NUMPAD_ENTER"
654
+ when Wx::K_NUMPAD_F1
655
+ key = "NUMPAD_F1"
656
+ when Wx::K_NUMPAD_F2
657
+ key = "NUMPAD_F2"
658
+ when Wx::K_NUMPAD_F3
659
+ key = "NUMPAD_F3"
660
+ when Wx::K_NUMPAD_F4
661
+ key = "NUMPAD_F4"
662
+ when Wx::K_NUMPAD_HOME
663
+ key = "NUMPAD_HOME"
664
+ when Wx::K_NUMPAD_LEFT
665
+ key = "NUMPAD_LEFT"
666
+ when Wx::K_NUMPAD_UP
667
+ key = "NUMPAD_UP"
668
+ when Wx::K_NUMPAD_RIGHT
669
+ key = "NUMPAD_RIGHT"
670
+ when Wx::K_NUMPAD_DOWN
671
+ key = "NUMPAD_DOWN"
672
+ when Wx::K_NUMPAD_PAGEUP
673
+ key = "NUMPAD_PAGEUP"
674
+ when Wx::K_NUMPAD_PAGEDOWN
675
+ key = "NUMPAD_PAGEDOWN"
676
+ when Wx::K_NUMPAD_END
677
+ key = "NUMPAD_END"
678
+ when Wx::K_NUMPAD_BEGIN
679
+ key = "NUMPAD_BEGIN"
680
+ when Wx::K_NUMPAD_INSERT
681
+ key = "NUMPAD_INSERT"
682
+ when Wx::K_NUMPAD_DELETE
683
+ key = "NUMPAD_DELETE"
684
+ when Wx::K_NUMPAD_EQUAL
685
+ key = "NUMPAD_EQUAL"
686
+ when Wx::K_NUMPAD_MULTIPLY
687
+ key = "NUMPAD_MULTIPLY"
688
+ when Wx::K_NUMPAD_ADD
689
+ key = "NUMPAD_ADD"
690
+ when Wx::K_NUMPAD_SEPARATOR
691
+ key = "NUMPAD_SEPARATOR"
692
+ when Wx::K_NUMPAD_SUBTRACT
693
+ key = "NUMPAD_SUBTRACT"
694
+ when Wx::K_NUMPAD_DECIMAL
695
+ key = "NUMPAD_DECIMAL"
696
+ when Wx::K_BROWSER_BACK
697
+ key = "BROWSER_BACK"
698
+ when Wx::K_BROWSER_FORWARD
699
+ key = "BROWSER_FORWARD"
700
+ when Wx::K_BROWSER_REFRESH
701
+ key = "BROWSER_REFRESH"
702
+ when Wx::K_BROWSER_STOP
703
+ key = "BROWSER_STOP"
704
+ when Wx::K_BROWSER_SEARCH
705
+ key = "BROWSER_SEARCH"
706
+ when Wx::K_BROWSER_FAVORITES
707
+ key = "BROWSER_FAVORITES"
708
+ when Wx::K_BROWSER_HOME
709
+ key = "BROWSER_HOME"
710
+ when Wx::K_VOLUME_MUTE
711
+ key = "VOLUME_MUTE"
712
+ when Wx::K_VOLUME_DOWN
713
+ key = "VOLUME_DOWN"
714
+ when Wx::K_VOLUME_UP
715
+ key = "VOLUME_UP"
716
+ when Wx::K_MEDIA_NEXT_TRACK
717
+ key = "MEDIA_NEXT_TRACK"
718
+ when Wx::K_MEDIA_PREV_TRACK
719
+ key = "MEDIA_PREV_TRACK"
720
+ when Wx::K_MEDIA_STOP
721
+ key = "MEDIA_STOP"
722
+ when Wx::K_MEDIA_PLAY_PAUSE
723
+ key = "MEDIA_PLAY_PAUSE"
724
+ when Wx::K_LAUNCH_MAIL
725
+ key = "LAUNCH_MAIL"
726
+ when Wx::K_LAUNCH_APP1
727
+ key = "LAUNCH_APP1"
728
+ when Wx::K_LAUNCH_APP2
729
+ key = "LAUNCH_APP2"
730
+ else
731
+ if keycode >= 32 && keycode < 127
732
+ key = "'#{keycode.chr}'"
733
+ elsif keycode > 0 && keycode < 27
734
+ key = "Ctrl-#{?A + keycode - 1}"
735
+ else
736
+ key = "unknown (#{keycode})"
737
+ end
738
+ end
799
739
 
800
- # for testing, prevent self item's label editing
801
- item = event.item
802
- if is_test_item(item)
803
- Wx::message_box("The demo prevents you editing this item.")
804
- event.veto
805
- elsif item == self.root_item
806
- # test that it is possible to change the text of the item being edited
807
- set_item_text(item, "Editing root item")
740
+ Wx::log_message("#{name} event: #{key} (flags = %s%s%s%s)" %
741
+ [event.control_down ? 'C' : '-',
742
+ event.alt_down ? 'A' : '-',
743
+ event.shift_down ? 'S' : '-',
744
+ event.meta_down ? 'M' : '-'])
808
745
  end
809
- end
810
746
 
811
- def on_end_label_edit(event)
812
- Wx::log_message("OnEndLabelEdit")
813
- if event.edit_cancelled?
814
- Wx::log_message("Label edit was cancelled by user")
815
- return
747
+ def on_tree_key_down(event)
748
+ log_key_event("Tree key down ", event.key_event)
749
+ event.skip
816
750
  end
817
751
 
818
- # For a demo, don't allow anything except letters in the labels
819
- unless event.label =~ /^\w+/
820
- msg = "The new label should be a single word."
821
- Wx::message_box(msg)
822
- Wx::log_message("Label edit was cancelled by demo")
823
- event.veto
752
+ def on_begin_drag(event)
753
+ # need to explicitly allow drag
754
+ if event.item != root_item
755
+ @dragged_item = event.item
756
+
757
+ clientpt = event.point
758
+ screenpt = client_to_screen(clientpt)
759
+ Wx::log_message("OnBeginDrag: started dragging %s at screen coords (%i,%i)" %
760
+ [item_text(@dragged_item), screenpt.x, screenpt.y])
761
+ event.allow
762
+ else
763
+ Wx::log_message("OnBeginDrag: selected item can't be dragged.")
764
+ end
824
765
  end
825
- end
826
766
 
827
- def on_item_collapsing(event)
828
- Wx::log_message("OnItemCollapsing")
767
+ def on_end_drag(event)
768
+ src_item = @dragged_item
769
+ dest_item = event.item
770
+ @dragged_item = nil
829
771
 
830
- # for testing, prevent the user from collapsing the first child folder
831
- if is_test_item(event.item)
832
- Wx::message_box("You can't collapse self item.")
833
- event.veto
772
+ if dest_item.ok? && !item_has_children(dest_item)
773
+ # copy to the parent then
774
+ dest_item = get_item_parent(dest_item)
775
+ end
776
+
777
+ unless dest_item.ok?
778
+ Wx::log_message("OnEndDrag: can't drop here.")
779
+ return nil
780
+ end
781
+
782
+ text = item_text(src_item)
783
+ Wx::log_message("OnEndDrag: '%s' copied to '%s'.",
784
+ text, item_text(dest_item))
785
+
786
+ # just do append here - we could also insert it just before/after the item
787
+ # on which it was dropped, but self requires slightly more work... we also
788
+ # completely ignore the client data and icon of the old item but could
789
+ # copy them as well.
790
+ #
791
+ # Finally, we only copy one item here but we might copy the entire tree if
792
+ # we were dragging a folder.
793
+ image = Wx::THE_APP.show_images ? TreeCtrlIcon_File : -1
794
+ new_id = append_item(dest_item, text, image)
795
+
796
+ set_item_state(new_id, get_item_state(src_item)) if Wx::THE_APP.show_states
834
797
  end
835
- end
836
798
 
837
- # show some info about activated item
838
- def on_item_activated(event)
839
- if (item_id = event.item).ok?
840
- show_info(item_id)
799
+ def on_begin_label_edit(event)
800
+ Wx::log_message("OnBeginLabelEdit")
801
+
802
+ # for testing, prevent self item's label editing
803
+ item = event.item
804
+ if is_test_item(item)
805
+ Wx::message_box("The demo prevents you editing this item.")
806
+ event.veto
807
+ elsif item == self.root_item
808
+ # test that it is possible to change the text of the item being edited
809
+ set_item_text(item, "Editing root item")
810
+ end
841
811
  end
842
- Wx::log_message("OnItemActivated")
843
- end
844
812
 
845
- def on_item_state_clicked(event)
846
- if (item_id = event.item).ok?
847
- do_toggle_state(item_id)
813
+ def on_end_label_edit(event)
814
+ Wx::log_message("OnEndLabelEdit")
815
+ if event.edit_cancelled?
816
+ Wx::log_message("Label edit was cancelled by user")
817
+ return
818
+ end
819
+
820
+ # For a demo, don't allow anything except letters in the labels
821
+ unless event.label =~ /^\w+/
822
+ msg = "The new label should be a single word."
823
+ Wx::message_box(msg)
824
+ Wx::log_message("Label edit was cancelled by demo")
825
+ event.veto
826
+ end
848
827
  end
849
- Wx::log_message("Item \"#{get_item_text(item_id)}\" state changed to #{get_item_state(item_id)}")
850
- end
851
828
 
852
- def on_item_menu(event)
853
- return unless (item = event.item).ok?
829
+ def on_item_collapsing(event)
830
+ Wx::log_message("OnItemCollapsing")
854
831
 
855
- item_data = get_item_data(item)
856
- clientpt = event.get_point
857
- screenpt = client_to_screen(clientpt)
832
+ # for testing, prevent the user from collapsing the first child folder
833
+ if is_test_item(event.item)
834
+ Wx::message_box("You can't collapse self item.")
835
+ event.veto
836
+ end
837
+ end
858
838
 
859
- Wx::log_message(
860
- "OnItemMenu for item \"#{item_data ? item_data : 'unknown'}\" at screen coords (#{screenpt.x}, #{screenpt.y})")
839
+ # show some info about activated item
840
+ def on_item_activated(event)
841
+ if (item_id = event.item).ok?
842
+ show_info(item_id)
843
+ end
844
+ Wx::log_message("OnItemActivated")
845
+ end
861
846
 
862
- show_popup_menu(item, clientpt)
863
- end
847
+ def on_item_state_clicked(event)
848
+ if (item_id = event.item).ok?
849
+ do_toggle_state(item_id)
850
+ end
851
+ Wx::log_message("Item \"#{get_item_text(item_id)}\" state changed to #{get_item_state(item_id)}")
852
+ end
864
853
 
865
- def on_context_menu(event)
866
- pt = event.position
854
+ def on_item_menu(event)
855
+ return unless (item = event.item).ok?
867
856
 
868
- Wx::log_message("OnContextMenu at screen coords (#{pt.x}, #{pt.y})")
857
+ item_data = get_item_data(item)
858
+ clientpt = event.get_point
859
+ screenpt = client_to_screen(clientpt)
869
860
 
870
- event.skip
871
- end
861
+ Wx::log_message(
862
+ "OnItemMenu for item \"#{item_data ? item_data : 'unknown'}\" at screen coords (#{screenpt.x}, #{screenpt.y})")
872
863
 
873
- def show_popup_menu(id, pos)
874
- title = ""
875
- if id.ok?
876
- title << "Menu for " << get_item_text(id)
877
- else
878
- title = "Menu for no particular item"
864
+ show_popup_menu(item, clientpt)
879
865
  end
880
866
 
881
- menu = Wx::Menu.new(title)
882
- menu.append(Wx::ID_ABOUT, "&About...")
883
- menu.append_separator
884
- menu.append(TreeTest_Highlight, "&Highlight item")
885
- menu.append(TreeTest_Dump, "&Dump")
886
- popup_menu(menu, pos)
887
- end
888
-
889
- def on_rmouse_down(event)
890
- Wx::log_message("Right mouse button down")
867
+ def on_context_menu(event)
868
+ pt = event.position
891
869
 
892
- event.skip
893
- end
870
+ Wx::log_message("OnContextMenu at screen coords (#{pt.x}, #{pt.y})")
894
871
 
895
- def on_item_rclick(event)
896
- unless (itemId = event.item).ok?
897
- Wx::log_message("on_item_rclick: event should have a valid item")
898
- return
872
+ event.skip
899
873
  end
900
874
 
901
- item_data = get_item_data(itemId)
902
- Wx::log_message("Item \"#{item_data ? item_data : 'unknown'}\" right clicked")
875
+ def show_popup_menu(id, pos)
876
+ title = ""
877
+ if id.ok?
878
+ title << "Menu for " << get_item_text(id)
879
+ else
880
+ title = "Menu for no particular item"
881
+ end
903
882
 
904
- event.skip
905
- end
883
+ menu = Wx::Menu.new(title)
884
+ menu.append(Wx::ID_ABOUT, "&About...")
885
+ menu.append_separator
886
+ menu.append(TreeTest_Highlight, "&Highlight item")
887
+ menu.append(TreeTest_Dump, "&Dump")
888
+ popup_menu(menu, pos)
889
+ end
906
890
 
907
- def on_rmouse_up(event)
908
- Wx::log_message("Right mouse button up")
891
+ def on_rmouse_down(event)
892
+ Wx::log_message("Right mouse button down")
909
893
 
910
- event.skip
911
- end
894
+ event.skip
895
+ end
912
896
 
913
- def on_rmouse_dclick(event)
914
- id = hit_test(event.get_position)
915
- unless id.ok?
916
- Wx::log_message("No item under mouse")
917
- else
918
- item_data = get_item_data(id)
919
- if item_data
920
- Wx::log_message("Item '#{item_data}' under mouse")
897
+ def on_item_rclick(event)
898
+ unless (itemId = event.item).ok?
899
+ Wx::log_message("on_item_rclick: event should have a valid item")
900
+ return
921
901
  end
902
+
903
+ item_data = get_item_data(itemId)
904
+ Wx::log_message("Item \"#{item_data ? item_data : 'unknown'}\" right clicked")
905
+
906
+ event.skip
922
907
  end
923
- end
924
908
 
925
- end
909
+ def on_rmouse_up(event)
910
+ Wx::log_message("Right mouse button up")
926
911
 
927
- class MyFrame < Wx::Frame
928
- def initialize(title, x, y, w, h)
929
- super(nil, :title => title, :pos => [x, y], :size => [w, h])
930
- @panel = nil
931
- #@splitter = nil
932
- @treectrl = nil
933
- @textctrl = nil
934
- @s_num = 0
935
-
936
- # This reduces flicker effects - even better would be to define
937
- # OnEraseBackground to do nothing. When the tree control's scrollbars are
938
- # show or hidden, the frame is sent a background erase event.
939
- self.background_colour = Wx::WHITE
940
-
941
- # Give it an icon
942
- self.icon = Wx::Icon.new(File.join(File.dirname(__FILE__), '..', 'sample.xpm'), Wx::BITMAP_TYPE_XPM)
943
-
944
- # Make a menubar
945
- file_menu = Wx::Menu.new
946
- style_menu = Wx::Menu.new
947
- tree_menu = Wx::Menu.new
948
- item_menu = Wx::Menu.new
949
-
950
- file_menu.append(Wx::ID_CLEAR, "&Clear log\tCtrl-L");
951
- file_menu.append_separator
952
- file_menu.append(Wx::ID_ABOUT, "&About...")
953
- file_menu.append_separator
954
- file_menu.append(Wx::ID_EXIT, "E&xit\tAlt-X")
955
-
956
- style_menu.append(TreeTest_TogButtons,
957
- "Toggle &normal buttons", "", Wx::ITEM_CHECK)
958
- style_menu.append(TreeTest_TogTwist,
959
- "Toggle &twister buttons", "", Wx::ITEM_CHECK)
960
- style_menu.append(TreeTest_ToggleButtons,
961
- "Toggle image &buttons", "", Wx::ITEM_CHECK)
962
- style_menu.append_separator
963
- style_menu.append(TreeTest_TogLines,
964
- "Toggle &no lines", "", Wx::ITEM_CHECK)
965
- style_menu.append(TreeTest_TogRootLines,
966
- "Toggle &lines at root", "", Wx::ITEM_CHECK)
967
- style_menu.append(TreeTest_TogHideRoot,
968
- "Toggle &hidden root", "", Wx::ITEM_CHECK)
969
- style_menu.append(TreeTest_TogBorder,
970
- "Toggle &item border", "", Wx::ITEM_CHECK)
971
- style_menu.append(TreeTest_TogFullHighlight,
972
- "Toggle &full row highlight", "", Wx::ITEM_CHECK)
973
- style_menu.append(TreeTest_TogEdit,
974
- "Toggle &edit mode", "", Wx::ITEM_CHECK)
975
- style_menu.append(TreeTest_ToggleSel,
976
- "Toggle multiple &selection", "", Wx::ITEM_CHECK)
977
- style_menu.append(TreeTest_ToggleImages,
978
- "Toggle show ima&ges", "", Wx::ITEM_CHECK)
979
- style_menu.append(TreeTest_ToggleStates,
980
- "Toggle show st&ates", "", Wx::ITEM_CHECK)
981
- style_menu.append(TreeTest_ToggleBell,
982
- "Toggle &bell on no match", "", Wx::ITEM_CHECK)
983
- style_menu.append(TreeTest_ToggleAlternateImages,
984
- "Toggle alternate images", "", Wx::ITEM_CHECK)
985
- style_menu.append(TreeTest_ToggleAlternateStates,
986
- "Toggle alternate state images", "", Wx::ITEM_CHECK)
987
- style_menu.append(TreeTest_SetImageSize, "Set image si&ze...")
988
- style_menu.append_separator
989
- style_menu.append(TreeTest_SetFgColour, "Set &foreground colour...")
990
- style_menu.append(TreeTest_SetBgColour, "Set &background colour...")
991
- style_menu.append_separator
992
- style_menu.append(TreeTest_ResetStyle, "&Reset to default\tF10")
993
-
994
- tree_menu.append(TreeTest_FreezeThaw,
995
- "&Freeze the tree", "", Wx::ITEM_CHECK)
996
- tree_menu.append(TreeTest_Recreate, "&Recreate the tree")
997
- tree_menu.append(TreeTest_CollapseAndReset, "C&ollapse and reset")
998
- tree_menu.append_separator
999
- tree_menu.append(TreeTest_AddItem, "Append a &new item")
1000
- tree_menu.append(TreeTest_AddManyItems, "Appends &many items")
1001
- tree_menu.append(TreeTest_InsertItem, "&Insert a new item")
1002
- tree_menu.append(TreeTest_Delete, "&Delete selected item")
1003
- tree_menu.append(TreeTest_DeleteChildren, "Delete &children")
1004
- tree_menu.append(TreeTest_DeleteAll, "Delete &all items")
1005
- tree_menu.append(TreeTest_SelectRoot, "Select root item")
1006
- tree_menu.append_separator
1007
- tree_menu.append(TreeTest_SetFocusedRoot, "Set focus to root item")
1008
- tree_menu.append(TreeTest_ClearFocused, "Reset focus")
1009
-
1010
- tree_menu.append_separator
1011
- tree_menu.append(TreeTest_Count, "Count children of current item")
1012
- tree_menu.append(TreeTest_CountRec, "Recursively count children of current item")
1013
- tree_menu.append_separator
1014
- tree_menu.append(TreeTest_Sort, "Sort children of current item")
1015
- tree_menu.append(TreeTest_SortRev, "Sort in reversed order")
1016
- tree_menu.append_separator
1017
- tree_menu.append(TreeTest_EnsureVisible, "Make the last item &visible")
1018
- tree_menu.append(TreeTest_SetFocus, "Set &focus to the tree")
1019
- tree_menu.append_separator
1020
- tree_menu.append(TreeTest_IncIndent, "Add 5 points to indentation\tAlt-I")
1021
- tree_menu.append(TreeTest_DecIndent, "Reduce indentation by 5 points\tAlt-R")
1022
- tree_menu.append_separator
1023
- tree_menu.append(TreeTest_IncSpacing, "Add 5 points to spacing\tCtrl-I")
1024
- tree_menu.append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R")
1025
-
1026
- item_menu.append(TreeTest_Dump, "&Dump item children")
1027
- item_menu.append(TreeTest_Rename, "&Rename item...")
1028
-
1029
- item_menu.append_separator
1030
- item_menu.append(TreeTest_SetBold, "Make item &bold")
1031
- item_menu.append(TreeTest_ClearBold, "Make item &not bold")
1032
- item_menu.append_separator
1033
- item_menu.append(TreeTest_ToggleIcon, "Toggle the item's &icon")
1034
- item_menu.append(TreeTest_ToggleState, "Toggle the item's &state")
1035
-
1036
- item_menu.append_separator
1037
- item_menu.append(TreeTest_ShowFirstVisible, "Show &first visible")
1038
- if Wx.has_feature?(:HAS_LAST_VISIBLE)
1039
- item_menu.append(TreeTest_ShowLastVisible, "Show &last visible")
1040
- end
1041
- item_menu.append(TreeTest_ShowNextVisible, "Show &next visible")
1042
- item_menu.append(TreeTest_ShowPrevVisible, "Show &previous visible")
1043
- item_menu.append_separator
1044
- item_menu.append(TreeTest_ShowParent, "Show pa&rent")
1045
- item_menu.append(TreeTest_ShowPrevSibling, "Show &previous sibling")
1046
- item_menu.append(TreeTest_ShowNextSibling, "Show &next sibling")
1047
- item_menu.append_separator
1048
- item_menu.append(TreeTest_ScrollTo, "Scroll &to item",
1049
- "Scroll to the last by one top level child")
1050
- item_menu.append(TreeTest_SelectLast, "Select &last item",
1051
- "Select the last item")
1052
-
1053
- item_menu.append_separator
1054
- item_menu.append(TreeTest_DumpSelected, "Dump selected items\tAlt-D")
1055
- item_menu.append(TreeTest_Select, "Select current item\tAlt-S")
1056
- item_menu.append(TreeTest_Unselect, "Unselect everything\tAlt-U")
1057
- item_menu.append(TreeTest_SelectChildren, "Select all children\tCtrl-A")
1058
-
1059
- menu_bar = Wx::MenuBar.new
1060
- menu_bar.append(file_menu, "&File")
1061
- menu_bar.append(style_menu, "&Style")
1062
- menu_bar.append(tree_menu, "&Tree")
1063
- menu_bar.append(item_menu, "&Item")
1064
- self.menu_bar = menu_bar
1065
-
1066
- @panel = Wx::Panel.new(self)
1067
-
1068
- # create the controls
1069
- @textctrl = Wx::TextCtrl.new(@panel,
1070
- :value => "Log text\n",
1071
- :style => Wx::TE_MULTILINE | Wx::SUNKEN_BORDER)
1072
-
1073
- create_tree_with_default_style
1074
-
1075
- menu_bar.check(TreeTest_ToggleImages, true)
1076
- menu_bar.check(TreeTest_ToggleStates, true)
1077
- menu_bar.check(TreeTest_ToggleAlternateImages, false)
1078
- menu_bar.check(TreeTest_ToggleAlternateStates, false)
1079
-
1080
- # create a status bar with 3 panes
1081
- create_status_bar(2)
1082
-
1083
- set_status_text("", 0)
1084
-
1085
- # set our text control as the log target
1086
- logWindow = Wx::LogTextCtrl.new(@textctrl)
1087
- @old_log_tgt = Wx::Log::set_active_target(logWindow)
1088
-
1089
- # @splitter.split_horizontally(@treectrl, @textctrl, 500)
1090
-
1091
- evt_close :on_close
1092
- evt_size :on_size
1093
- evt_idle :on_idle
1094
-
1095
- evt_menu Wx::ID_EXIT, :on_quit
1096
- evt_menu Wx::ID_ABOUT, :on_about
1097
- evt_menu Wx::ID_CLEAR, :on_clear_log
1098
-
1099
- evt_menu TreeTest_TogButtons, :on_tog_buttons
1100
- evt_menu TreeTest_TogTwist, :on_tog_twist
1101
- evt_menu TreeTest_TogLines, :on_tog_lines
1102
- evt_menu TreeTest_TogEdit, :on_tog_edit
1103
- evt_menu TreeTest_TogHideRoot, :on_tog_hide_root
1104
- evt_menu TreeTest_TogRootLines, :on_tog_root_lines
1105
- evt_menu TreeTest_TogBorder, :on_tog_border
1106
- evt_menu TreeTest_TogFullHighlight, :on_tog_full_highlight
1107
- evt_menu TreeTest_SetFgColour, :on_set_fg_colour
1108
- evt_menu TreeTest_SetBgColour, :on_set_bg_colour
1109
- evt_menu TreeTest_ResetStyle, :on_reset_style
1110
-
1111
- evt_menu TreeTest_Highlight, :on_highlight
1112
- evt_menu TreeTest_Dump, :on_dump
1113
- evt_menu TreeTest_DumpSelected, :on_dump_selected
1114
- evt_menu TreeTest_Select, :on_select
1115
- evt_menu TreeTest_Unselect, :on_unselect
1116
- evt_menu TreeTest_ToggleSel, :on_toggle_sel
1117
- evt_menu TreeTest_SelectChildren, :on_select_children
1118
- evt_menu TreeTest_Rename, :on_rename
1119
- evt_menu TreeTest_Count, :on_count
1120
- evt_menu TreeTest_CountRec, :on_count_rec
1121
- evt_menu TreeTest_Sort, :on_sort
1122
- evt_menu TreeTest_SortRev, :on_sort_rev
1123
- evt_menu TreeTest_SetBold, :on_set_bold
1124
- evt_menu TreeTest_ClearBold, :on_clear_bold
1125
- evt_menu TreeTest_Delete, :on_delete
1126
- evt_menu TreeTest_DeleteChildren, :on_delete_children
1127
- evt_menu TreeTest_DeleteAll, :on_delete_all
1128
- evt_menu TreeTest_Recreate, :on_recreate
1129
- evt_menu TreeTest_FreezeThaw, :on_freeze_thaw
1130
- evt_menu TreeTest_ToggleImages, :on_toggle_images
1131
- evt_menu TreeTest_ToggleStates, :on_toggle_states
1132
- evt_menu TreeTest_ToggleBell, :on_toggle_bell
1133
- evt_menu TreeTest_ToggleAlternateImages, :on_toggle_alternate_images
1134
- evt_menu TreeTest_ToggleAlternateStates, :on_toggle_alternate_states
1135
- unless Wx.has_feature?(:WXMSW)
1136
- evt_menu TreeTest_ToggleButtons, :on_toggle_buttons
1137
- end
1138
- evt_menu TreeTest_SetImageSize, :on_set_image_size
1139
- evt_menu TreeTest_CollapseAndReset, :on_collapse_and_reset
1140
- evt_menu TreeTest_EnsureVisible, :on_ensure_visible
1141
- evt_menu TreeTest_SetFocus, :on_set_focus
1142
- evt_menu TreeTest_AddItem, :on_add_item
1143
- evt_menu TreeTest_AddManyItems, :on_add_many_items
1144
- evt_menu TreeTest_InsertItem, :on_insert_item
1145
- evt_menu TreeTest_IncIndent, :on_inc_indent
1146
- evt_menu TreeTest_DecIndent, :on_dec_indent
1147
- evt_menu TreeTest_IncSpacing, :on_inc_spacing
1148
- evt_menu TreeTest_DecSpacing, :on_dec_spacing
1149
- evt_menu TreeTest_ToggleIcon, :on_toggle_icon
1150
- evt_menu TreeTest_ToggleState, :on_toggle_state
1151
- evt_menu TreeTest_SelectRoot, :on_select_root
1152
- evt_menu TreeTest_SetFocusedRoot, :on_set_focused_root
1153
- evt_menu TreeTest_ClearFocused, :on_clear_focused
1154
-
1155
- evt_menu TreeTest_ShowFirstVisible, :on_show_first_visible
1156
- if Wx.has_feature?(:HAS_LAST_VISIBLE)
1157
- evt_menu TreeTest_ShowLastVisible, :on_show_last_visible
1158
- end
1159
- evt_menu TreeTest_ShowNextVisible, :on_show_next_visible
1160
- evt_menu TreeTest_ShowPrevVisible, :on_show_prev_visible
1161
- evt_menu TreeTest_ShowParent, :on_show_parent
1162
- evt_menu TreeTest_ShowPrevSibling, :on_show_prev_sibling
1163
- evt_menu TreeTest_ShowNextSibling, :on_show_next_sibling
1164
- evt_menu TreeTest_ScrollTo, :on_scroll_to
1165
- evt_menu TreeTest_SelectLast, :on_select_last
1166
- end
912
+ event.skip
913
+ end
914
+
915
+ def on_rmouse_dclick(event)
916
+ id = hit_test(event.get_position)
917
+ unless id.ok?
918
+ Wx::log_message("No item under mouse")
919
+ else
920
+ item_data = get_item_data(id)
921
+ if item_data
922
+ Wx::log_message("Item '#{item_data}' under mouse")
923
+ end
924
+ end
925
+ end
1167
926
 
1168
- def check_item(id)
1169
- Wx::message_box("Please select some item first!",
1170
- "Tree sample error",
1171
- Wx::OK | Wx::ICON_EXCLAMATION,
1172
- self) unless id && id.ok?
1173
- id && id.ok?
1174
927
  end
1175
928
 
1176
- def create_tree_with_default_style
929
+ class MyFrame < Wx::Frame
930
+ def initialize(title, x, y, w, h)
931
+ super(nil, :title => title, :pos => [x, y], :size => [w, h])
932
+ @panel = nil
933
+ #@splitter = nil
934
+ @treectrl = nil
935
+ @textctrl = nil
936
+ @s_num = 0
937
+
938
+ # This reduces flicker effects - even better would be to define
939
+ # OnEraseBackground to do nothing. When the tree control's scrollbars are
940
+ # show or hidden, the frame is sent a background erase event.
941
+ self.background_colour = Wx::WHITE
942
+
943
+ # Give it an icon
944
+ self.icon = Wx.Icon(:sample, Wx::BITMAP_TYPE_XPM, art_path: File.join(__dir__, '..'))
945
+
946
+ # Make a menubar
947
+ file_menu = Wx::Menu.new
948
+ style_menu = Wx::Menu.new
949
+ tree_menu = Wx::Menu.new
950
+ item_menu = Wx::Menu.new
951
+
952
+ file_menu.append(Wx::ID_CLEAR, "&Clear log\tCtrl-L");
953
+ file_menu.append_separator
954
+ file_menu.append(Wx::ID_ABOUT, "&About...")
955
+ file_menu.append_separator
956
+ file_menu.append(Wx::ID_EXIT, "E&xit\tAlt-X")
957
+
958
+ style_menu.append(TreeTest_TogButtons,
959
+ "Toggle &normal buttons", "", Wx::ITEM_CHECK)
960
+ style_menu.append(TreeTest_TogTwist,
961
+ "Toggle &twister buttons", "", Wx::ITEM_CHECK)
962
+ style_menu.append(TreeTest_ToggleButtons,
963
+ "Toggle image &buttons", "", Wx::ITEM_CHECK)
964
+ style_menu.append_separator
965
+ style_menu.append(TreeTest_TogLines,
966
+ "Toggle &no lines", "", Wx::ITEM_CHECK)
967
+ style_menu.append(TreeTest_TogRootLines,
968
+ "Toggle &lines at root", "", Wx::ITEM_CHECK)
969
+ style_menu.append(TreeTest_TogHideRoot,
970
+ "Toggle &hidden root", "", Wx::ITEM_CHECK)
971
+ style_menu.append(TreeTest_TogBorder,
972
+ "Toggle &item border", "", Wx::ITEM_CHECK)
973
+ style_menu.append(TreeTest_TogFullHighlight,
974
+ "Toggle &full row highlight", "", Wx::ITEM_CHECK)
975
+ style_menu.append(TreeTest_TogEdit,
976
+ "Toggle &edit mode", "", Wx::ITEM_CHECK)
977
+ style_menu.append(TreeTest_ToggleSel,
978
+ "Toggle multiple &selection", "", Wx::ITEM_CHECK)
979
+ style_menu.append(TreeTest_ToggleImages,
980
+ "Toggle show ima&ges", "", Wx::ITEM_CHECK)
981
+ style_menu.append(TreeTest_ToggleStates,
982
+ "Toggle show st&ates", "", Wx::ITEM_CHECK)
983
+ style_menu.append(TreeTest_ToggleBell,
984
+ "Toggle &bell on no match", "", Wx::ITEM_CHECK)
985
+ style_menu.append(TreeTest_ToggleAlternateImages,
986
+ "Toggle alternate images", "", Wx::ITEM_CHECK)
987
+ style_menu.append(TreeTest_ToggleAlternateStates,
988
+ "Toggle alternate state images", "", Wx::ITEM_CHECK)
989
+ style_menu.append(TreeTest_SetImageSize, "Set image si&ze...")
990
+ style_menu.append_separator
991
+ style_menu.append(TreeTest_SetFgColour, "Set &foreground colour...")
992
+ style_menu.append(TreeTest_SetBgColour, "Set &background colour...")
993
+ style_menu.append_separator
994
+ style_menu.append(TreeTest_ResetStyle, "&Reset to default\tF10")
995
+
996
+ tree_menu.append(TreeTest_FreezeThaw,
997
+ "&Freeze the tree", "", Wx::ITEM_CHECK)
998
+ tree_menu.append(TreeTest_Recreate, "&Recreate the tree")
999
+ tree_menu.append(TreeTest_CollapseAndReset, "C&ollapse and reset")
1000
+ tree_menu.append_separator
1001
+ tree_menu.append(TreeTest_AddItem, "Append a &new item")
1002
+ tree_menu.append(TreeTest_AddManyItems, "Appends &many items")
1003
+ tree_menu.append(TreeTest_InsertItem, "&Insert a new item")
1004
+ tree_menu.append(TreeTest_Delete, "&Delete selected item")
1005
+ tree_menu.append(TreeTest_DeleteChildren, "Delete &children")
1006
+ tree_menu.append(TreeTest_DeleteAll, "Delete &all items")
1007
+ tree_menu.append(TreeTest_SelectRoot, "Select root item")
1008
+ tree_menu.append_separator
1009
+ tree_menu.append(TreeTest_SetFocusedRoot, "Set focus to root item")
1010
+ tree_menu.append(TreeTest_ClearFocused, "Reset focus")
1011
+
1012
+ tree_menu.append_separator
1013
+ tree_menu.append(TreeTest_Count, "Count children of current item")
1014
+ tree_menu.append(TreeTest_CountRec, "Recursively count children of current item")
1015
+ tree_menu.append_separator
1016
+ tree_menu.append(TreeTest_Sort, "Sort children of current item")
1017
+ tree_menu.append(TreeTest_SortRev, "Sort in reversed order")
1018
+ tree_menu.append_separator
1019
+ tree_menu.append(TreeTest_EnsureVisible, "Make the last item &visible")
1020
+ tree_menu.append(TreeTest_SetFocus, "Set &focus to the tree")
1021
+ tree_menu.append_separator
1022
+ tree_menu.append(TreeTest_IncIndent, "Add 5 points to indentation\tAlt-I")
1023
+ tree_menu.append(TreeTest_DecIndent, "Reduce indentation by 5 points\tAlt-R")
1024
+ tree_menu.append_separator
1025
+ tree_menu.append(TreeTest_IncSpacing, "Add 5 points to spacing\tCtrl-I")
1026
+ tree_menu.append(TreeTest_DecSpacing, "Reduce spacing by 5 points\tCtrl-R")
1027
+
1028
+ item_menu.append(TreeTest_Dump, "&Dump item children")
1029
+ item_menu.append(TreeTest_Rename, "&Rename item...")
1030
+
1031
+ item_menu.append_separator
1032
+ item_menu.append(TreeTest_SetBold, "Make item &bold")
1033
+ item_menu.append(TreeTest_ClearBold, "Make item &not bold")
1034
+ item_menu.append_separator
1035
+ item_menu.append(TreeTest_ToggleIcon, "Toggle the item's &icon")
1036
+ item_menu.append(TreeTest_ToggleState, "Toggle the item's &state")
1037
+
1038
+ item_menu.append_separator
1039
+ item_menu.append(TreeTest_ShowFirstVisible, "Show &first visible")
1040
+ if Wx.has_feature?(:HAS_LAST_VISIBLE)
1041
+ item_menu.append(TreeTest_ShowLastVisible, "Show &last visible")
1042
+ end
1043
+ item_menu.append(TreeTest_ShowNextVisible, "Show &next visible")
1044
+ item_menu.append(TreeTest_ShowPrevVisible, "Show &previous visible")
1045
+ item_menu.append_separator
1046
+ item_menu.append(TreeTest_ShowParent, "Show pa&rent")
1047
+ item_menu.append(TreeTest_ShowPrevSibling, "Show &previous sibling")
1048
+ item_menu.append(TreeTest_ShowNextSibling, "Show &next sibling")
1049
+ item_menu.append_separator
1050
+ item_menu.append(TreeTest_ScrollTo, "Scroll &to item",
1051
+ "Scroll to the last by one top level child")
1052
+ item_menu.append(TreeTest_SelectLast, "Select &last item",
1053
+ "Select the last item")
1054
+
1055
+ item_menu.append_separator
1056
+ item_menu.append(TreeTest_DumpSelected, "Dump selected items\tAlt-D")
1057
+ item_menu.append(TreeTest_Select, "Select current item\tAlt-S")
1058
+ item_menu.append(TreeTest_Unselect, "Unselect everything\tAlt-U")
1059
+ item_menu.append(TreeTest_SelectChildren, "Select all children\tCtrl-A")
1060
+
1061
+ menu_bar = Wx::MenuBar.new
1062
+ menu_bar.append(file_menu, "&File")
1063
+ menu_bar.append(style_menu, "&Style")
1064
+ menu_bar.append(tree_menu, "&Tree")
1065
+ menu_bar.append(item_menu, "&Item")
1066
+ self.menu_bar = menu_bar
1067
+
1068
+ @panel = Wx::Panel.new(self)
1069
+
1070
+ # create the controls
1071
+ @textctrl = Wx::TextCtrl.new(@panel,
1072
+ :value => "Log text\n",
1073
+ :style => Wx::TE_MULTILINE | Wx::SUNKEN_BORDER)
1074
+
1075
+ create_tree_with_default_style
1076
+
1077
+ menu_bar.check(TreeTest_ToggleImages, true)
1078
+ menu_bar.check(TreeTest_ToggleStates, true)
1079
+ menu_bar.check(TreeTest_ToggleAlternateImages, false)
1080
+ menu_bar.check(TreeTest_ToggleAlternateStates, false)
1081
+
1082
+ # create a status bar with 3 panes
1083
+ create_status_bar(2)
1084
+
1085
+ set_status_text("", 0)
1086
+
1087
+ # set our text control as the log target
1088
+ logWindow = Wx::LogTextCtrl.new(@textctrl)
1089
+ @old_log_tgt = Wx::Log::set_active_target(logWindow)
1090
+
1091
+ # @splitter.split_horizontally(@treectrl, @textctrl, 500)
1092
+
1093
+ evt_close :on_close
1094
+ evt_size :on_size
1095
+ evt_idle :on_idle
1096
+
1097
+ evt_menu Wx::ID_EXIT, :on_quit
1098
+ evt_menu Wx::ID_ABOUT, :on_about
1099
+ evt_menu Wx::ID_CLEAR, :on_clear_log
1100
+
1101
+ evt_menu TreeTest_TogButtons, :on_tog_buttons
1102
+ evt_menu TreeTest_TogTwist, :on_tog_twist
1103
+ evt_menu TreeTest_TogLines, :on_tog_lines
1104
+ evt_menu TreeTest_TogEdit, :on_tog_edit
1105
+ evt_menu TreeTest_TogHideRoot, :on_tog_hide_root
1106
+ evt_menu TreeTest_TogRootLines, :on_tog_root_lines
1107
+ evt_menu TreeTest_TogBorder, :on_tog_border
1108
+ evt_menu TreeTest_TogFullHighlight, :on_tog_full_highlight
1109
+ evt_menu TreeTest_SetFgColour, :on_set_fg_colour
1110
+ evt_menu TreeTest_SetBgColour, :on_set_bg_colour
1111
+ evt_menu TreeTest_ResetStyle, :on_reset_style
1112
+
1113
+ evt_menu TreeTest_Highlight, :on_highlight
1114
+ evt_menu TreeTest_Dump, :on_dump
1115
+ evt_menu TreeTest_DumpSelected, :on_dump_selected
1116
+ evt_menu TreeTest_Select, :on_select
1117
+ evt_menu TreeTest_Unselect, :on_unselect
1118
+ evt_menu TreeTest_ToggleSel, :on_toggle_sel
1119
+ evt_menu TreeTest_SelectChildren, :on_select_children
1120
+ evt_menu TreeTest_Rename, :on_rename
1121
+ evt_menu TreeTest_Count, :on_count
1122
+ evt_menu TreeTest_CountRec, :on_count_rec
1123
+ evt_menu TreeTest_Sort, :on_sort
1124
+ evt_menu TreeTest_SortRev, :on_sort_rev
1125
+ evt_menu TreeTest_SetBold, :on_set_bold
1126
+ evt_menu TreeTest_ClearBold, :on_clear_bold
1127
+ evt_menu TreeTest_Delete, :on_delete
1128
+ evt_menu TreeTest_DeleteChildren, :on_delete_children
1129
+ evt_menu TreeTest_DeleteAll, :on_delete_all
1130
+ evt_menu TreeTest_Recreate, :on_recreate
1131
+ evt_menu TreeTest_FreezeThaw, :on_freeze_thaw
1132
+ evt_menu TreeTest_ToggleImages, :on_toggle_images
1133
+ evt_menu TreeTest_ToggleStates, :on_toggle_states
1134
+ evt_menu TreeTest_ToggleBell, :on_toggle_bell
1135
+ evt_menu TreeTest_ToggleAlternateImages, :on_toggle_alternate_images
1136
+ evt_menu TreeTest_ToggleAlternateStates, :on_toggle_alternate_states
1137
+ unless Wx.has_feature?(:WXMSW)
1138
+ evt_menu TreeTest_ToggleButtons, :on_toggle_buttons
1139
+ end
1140
+ evt_menu TreeTest_SetImageSize, :on_set_image_size
1141
+ evt_menu TreeTest_CollapseAndReset, :on_collapse_and_reset
1142
+ evt_menu TreeTest_EnsureVisible, :on_ensure_visible
1143
+ evt_menu TreeTest_SetFocus, :on_set_focus
1144
+ evt_menu TreeTest_AddItem, :on_add_item
1145
+ evt_menu TreeTest_AddManyItems, :on_add_many_items
1146
+ evt_menu TreeTest_InsertItem, :on_insert_item
1147
+ evt_menu TreeTest_IncIndent, :on_inc_indent
1148
+ evt_menu TreeTest_DecIndent, :on_dec_indent
1149
+ evt_menu TreeTest_IncSpacing, :on_inc_spacing
1150
+ evt_menu TreeTest_DecSpacing, :on_dec_spacing
1151
+ evt_menu TreeTest_ToggleIcon, :on_toggle_icon
1152
+ evt_menu TreeTest_ToggleState, :on_toggle_state
1153
+ evt_menu TreeTest_SelectRoot, :on_select_root
1154
+ evt_menu TreeTest_SetFocusedRoot, :on_set_focused_root
1155
+ evt_menu TreeTest_ClearFocused, :on_clear_focused
1156
+
1157
+ evt_menu TreeTest_ShowFirstVisible, :on_show_first_visible
1158
+ if Wx.has_feature?(:HAS_LAST_VISIBLE)
1159
+ evt_menu TreeTest_ShowLastVisible, :on_show_last_visible
1160
+ end
1161
+ evt_menu TreeTest_ShowNextVisible, :on_show_next_visible
1162
+ evt_menu TreeTest_ShowPrevVisible, :on_show_prev_visible
1163
+ evt_menu TreeTest_ShowParent, :on_show_parent
1164
+ evt_menu TreeTest_ShowPrevSibling, :on_show_prev_sibling
1165
+ evt_menu TreeTest_ShowNextSibling, :on_show_next_sibling
1166
+ evt_menu TreeTest_ScrollTo, :on_scroll_to
1167
+ evt_menu TreeTest_SelectLast, :on_select_last
1168
+ end
1177
1169
 
1178
- style = Wx::TR_DEFAULT_STYLE | Wx::TR_HAS_VARIABLE_ROW_HEIGHT | Wx::TR_EDIT_LABELS
1170
+ def check_item(id)
1171
+ Wx::message_box("Please select some item first!",
1172
+ "Tree sample error",
1173
+ Wx::OK | Wx::ICON_EXCLAMATION,
1174
+ self) unless id && id.ok?
1175
+ id && id.ok?
1176
+ end
1179
1177
 
1180
- create_tree(style | Wx::SUNKEN_BORDER)
1178
+ def create_tree_with_default_style
1181
1179
 
1182
- # as we don't know what Wx::TR_DEFAULT_STYLE could contain, test for
1183
- # everything
1184
- mbar = menu_bar
1185
- mbar.check(TreeTest_TogButtons, (style & Wx::TR_HAS_BUTTONS) != 0)
1186
- mbar.check(TreeTest_TogButtons, (style & Wx::TR_TWIST_BUTTONS) != 0)
1187
- mbar.check(TreeTest_TogLines, (style & Wx::TR_NO_LINES) != 0)
1188
- mbar.check(TreeTest_TogRootLines, (style & Wx::TR_LINES_AT_ROOT) != 0)
1189
- mbar.check(TreeTest_TogHideRoot, (style & Wx::TR_HIDE_ROOT) != 0)
1190
- mbar.check(TreeTest_TogEdit, (style & Wx::TR_EDIT_LABELS) != 0)
1191
- mbar.check(TreeTest_TogBorder, (style & Wx::TR_ROW_LINES) != 0)
1192
- mbar.check(TreeTest_TogFullHighlight, (style & Wx::TR_FULL_ROW_HIGHLIGHT) != 0)
1193
- end
1180
+ style = Wx::TR_DEFAULT_STYLE | Wx::TR_HAS_VARIABLE_ROW_HEIGHT | Wx::TR_EDIT_LABELS
1194
1181
 
1195
- def create_tree(style)
1196
- @treectrl = MyTreeCtrl.new(@panel, :style => style)
1182
+ create_tree(style | Wx::SUNKEN_BORDER)
1197
1183
 
1198
- menu_bar.enable(TreeTest_SelectRoot, (style & Wx::TR_HIDE_ROOT) == 0)
1184
+ # as we don't know what Wx::TR_DEFAULT_STYLE could contain, test for
1185
+ # everything
1186
+ mbar = menu_bar
1187
+ mbar.check(TreeTest_TogButtons, (style & Wx::TR_HAS_BUTTONS) != 0)
1188
+ mbar.check(TreeTest_TogButtons, (style & Wx::TR_TWIST_BUTTONS) != 0)
1189
+ mbar.check(TreeTest_TogLines, (style & Wx::TR_NO_LINES) != 0)
1190
+ mbar.check(TreeTest_TogRootLines, (style & Wx::TR_LINES_AT_ROOT) != 0)
1191
+ mbar.check(TreeTest_TogHideRoot, (style & Wx::TR_HIDE_ROOT) != 0)
1192
+ mbar.check(TreeTest_TogEdit, (style & Wx::TR_EDIT_LABELS) != 0)
1193
+ mbar.check(TreeTest_TogBorder, (style & Wx::TR_ROW_LINES) != 0)
1194
+ mbar.check(TreeTest_TogFullHighlight, (style & Wx::TR_FULL_ROW_HIGHLIGHT) != 0)
1195
+ end
1199
1196
 
1200
- resize
1201
- end
1197
+ def create_tree(style)
1198
+ @treectrl = MyTreeCtrl.new(@panel, :style => style)
1202
1199
 
1203
- def tog_style(id, flag)
1204
- style = @treectrl.get_window_style ^ flag
1200
+ menu_bar.enable(TreeTest_SelectRoot, (style & Wx::TR_HIDE_ROOT) == 0)
1205
1201
 
1206
- if Wx.has_feature?(:WXMSW)
1207
- # treectrl styles can't be changed on the fly using the native
1208
- # control and the tree must be recreated
1209
- @treectrl.destroy
1210
- create_tree(style)
1211
- else
1212
- @treectrl.set_window_style(style)
1202
+ resize
1213
1203
  end
1214
1204
 
1215
- menu_bar.check(id, (style & flag) != 0)
1216
- end
1217
-
1218
- def resize
1219
- size = get_client_size
1220
- @treectrl.set_size(Wx::Rect.new(0, 0, size.width, size.height * 2 / 3)) if @treectrl
1221
- @textctrl.set_size(Wx::Rect.new(0, 2 * size.height / 3, size.width, size.height / 3)) if @textctrl
1222
- end
1205
+ def tog_style(id, flag)
1206
+ style = @treectrl.get_window_style ^ flag
1223
1207
 
1224
- def on_idle(evt)
1225
- if @treectrl
1226
- idRoot = @treectrl.root_item
1227
- if idRoot.ok?
1228
- idLast = @treectrl.get_last_tree_item
1229
- status = "Root/last item is %svisible/%svisible" %
1230
- [@treectrl.is_visible(idRoot) ? '' : 'not ',
1231
- idLast.ok? && @treectrl.is_visible(idLast) ? '' : 'not ']
1208
+ if Wx.has_feature?(:WXMSW)
1209
+ # treectrl styles can't be changed on the fly using the native
1210
+ # control and the tree must be recreated
1211
+ @treectrl.destroy
1212
+ create_tree(style)
1232
1213
  else
1233
- status = "No root item";
1214
+ @treectrl.set_window_style(style)
1234
1215
  end
1235
1216
 
1236
- set_status_text(status, 1)
1217
+ menu_bar.check(id, (style & flag) != 0)
1237
1218
  end
1238
1219
 
1239
- evt.skip
1240
- end
1220
+ def resize
1221
+ size = get_client_size
1222
+ @treectrl.set_size(Wx::Rect.new(0, 0, size.width, size.height * 2 / 3)) if @treectrl
1223
+ @textctrl.set_size(Wx::Rect.new(0, 2 * size.height / 3, size.width, size.height / 3)) if @textctrl
1224
+ end
1241
1225
 
1242
- def on_size(evt)
1243
- resize if (@treectrl && @textctrl)
1244
- evt.skip
1245
- end
1226
+ def on_idle(evt)
1227
+ if @treectrl
1228
+ idRoot = @treectrl.root_item
1229
+ if idRoot.ok?
1230
+ idLast = @treectrl.get_last_tree_item
1231
+ status = "Root/last item is %svisible/%svisible" %
1232
+ [@treectrl.is_visible(idRoot) ? '' : 'not ',
1233
+ idLast.ok? && @treectrl.is_visible(idLast) ? '' : 'not ']
1234
+ else
1235
+ status = "No root item";
1236
+ end
1246
1237
 
1247
- def on_quit(event)
1248
- close(true)
1249
- end
1238
+ set_status_text(status, 1)
1239
+ end
1250
1240
 
1251
- def on_about(event)
1252
- Wx::message_box("Tree test sample\n" +
1253
- "(c) Julian Smart 1997, Vadim Zeitlin 1998, Martin Corino 2022",
1254
- "About wxRuby tree test",
1255
- Wx::OK | Wx::ICON_INFORMATION, self)
1256
- end
1241
+ evt.skip
1242
+ end
1257
1243
 
1258
- def on_clear_log(event)
1259
- @textctrl.clear
1260
- end
1244
+ def on_size(evt)
1245
+ resize if (@treectrl && @textctrl)
1246
+ evt.skip
1247
+ end
1261
1248
 
1262
- def on_rename(event)
1263
- item = @treectrl.selection
1264
- return unless check_item(item)
1265
- # TODO demonstrate creating a custom edit control...
1266
- @treectrl.edit_label(item)
1267
- end
1249
+ def on_quit(event)
1250
+ close(true)
1251
+ end
1268
1252
 
1269
- def on_count(event)
1270
- item = @treectrl.selection
1271
- return unless check_item(item)
1272
- i = @treectrl.children_count(item, false)
1273
- Wx::log_message("%d children", i)
1274
- end
1253
+ def on_about(event)
1254
+ Wx::message_box("Tree test sample\n" +
1255
+ "(c) Julian Smart 1997, Vadim Zeitlin 1998, Martin Corino 2022",
1256
+ "About wxRuby tree test",
1257
+ Wx::OK | Wx::ICON_INFORMATION, self)
1258
+ end
1275
1259
 
1276
- def on_count_rec(event)
1277
- item = @treectrl.selection
1278
- return unless check_item(item)
1279
- Wx::log_message("%d children", @treectrl.children_count(item))
1280
- end
1260
+ def on_clear_log(event)
1261
+ @textctrl.clear
1262
+ end
1281
1263
 
1282
- def do_sort(reverse = false)
1283
- item = @treectrl.selection
1284
- return unless check_item(item)
1285
- @treectrl.do_sort_children(item, reverse)
1286
- end
1264
+ def on_rename(event)
1265
+ item = @treectrl.selection
1266
+ return unless check_item(item)
1267
+ # TODO demonstrate creating a custom edit control...
1268
+ @treectrl.edit_label(item)
1269
+ end
1287
1270
 
1288
- def on_highlight(_event)
1289
- id = @treectrl.get_focused_item
1271
+ def on_count(event)
1272
+ item = @treectrl.selection
1273
+ return unless check_item(item)
1274
+ i = @treectrl.children_count(item, false)
1275
+ Wx::log_message("%d children", i)
1276
+ end
1290
1277
 
1291
- return unless check_item(id)
1278
+ def on_count_rec(event)
1279
+ item = @treectrl.selection
1280
+ return unless check_item(item)
1281
+ Wx::log_message("%d children", @treectrl.children_count(item))
1282
+ end
1292
1283
 
1293
- r = Wx::Rect.new
1294
- if !@treectrl.get_bounding_rect(id, r, true) # text, not full row
1295
- Wx::LogMessage("Failed to get bounding item rect")
1296
- return
1284
+ def do_sort(reverse = false)
1285
+ item = @treectrl.selection
1286
+ return unless check_item(item)
1287
+ @treectrl.do_sort_children(item, reverse)
1297
1288
  end
1298
- @treectrl.paint do |dc|
1299
- dc.set_brush(Wx::RED_BRUSH)
1300
- dc.set_pen(Wx::TRANSPARENT_PEN)
1301
- dc.draw_rectangle(r)
1302
- @treectrl.update
1289
+
1290
+ def on_highlight(_event)
1291
+ id = @treectrl.get_focused_item
1292
+
1293
+ return unless check_item(id)
1294
+
1295
+ r = Wx::Rect.new
1296
+ if !@treectrl.get_bounding_rect(id, r, true) # text, not full row
1297
+ Wx::LogMessage("Failed to get bounding item rect")
1298
+ return
1299
+ end
1300
+ @treectrl.paint do |dc|
1301
+ dc.set_brush(Wx::RED_BRUSH)
1302
+ dc.set_pen(Wx::TRANSPARENT_PEN)
1303
+ dc.draw_rectangle(r)
1304
+ @treectrl.update
1305
+ end
1303
1306
  end
1304
- end
1305
1307
 
1306
- def on_dump(event)
1307
- root = @treectrl.selection
1308
- return unless check_item(root)
1309
- @treectrl.get_items_recursively(root, -1)
1310
- end
1308
+ def on_dump(event)
1309
+ root = @treectrl.selection
1310
+ return unless check_item(root)
1311
+ @treectrl.get_items_recursively(root, -1)
1312
+ end
1311
1313
 
1312
- def on_toggle_sel(event)
1313
- tog_style(event.id, Wx::TR_MULTIPLE)
1314
- end
1314
+ def on_toggle_sel(event)
1315
+ tog_style(event.id, Wx::TR_MULTIPLE)
1316
+ end
1315
1317
 
1316
- def on_dump_selected(event)
1317
- if (@treectrl.window_style & Wx::TR_MULTIPLE) == 0
1318
- item_id = @treectrl.selection
1319
- if item_id.ok?
1320
- Wx::log_message("<TreeItem '%s'>",
1321
- @treectrl.get_item_text(item_id))
1318
+ def on_dump_selected(event)
1319
+ if (@treectrl.window_style & Wx::TR_MULTIPLE) == 0
1320
+ item_id = @treectrl.selection
1321
+ if item_id.ok?
1322
+ Wx::log_message("<TreeItem '%s'>",
1323
+ @treectrl.get_item_text(item_id))
1324
+ else
1325
+ Wx::log_message("No tree item selected")
1326
+ end
1322
1327
  else
1323
- Wx::log_message("No tree item selected")
1328
+ Wx::log_message("NOT IMPLEMENTED: Multiple selections not available")
1329
+ # Requires Wx::List - Ruby Array typemap, pointer handling, 29/08/2006
1330
+ # Currently raises incorrect number of args, 1 for 0
1331
+ # selected = @treectrl.get_selections
1332
+ # selected_items.each do | item_id |
1333
+ # Wx::log_message("\t%s", @treectrl.get_item_text(item_id))
1334
+ # end
1324
1335
  end
1325
- else
1326
- Wx::log_message("NOT IMPLEMENTED: Multiple selections not available")
1327
- # Requires Wx::List - Ruby Array typemap, pointer handling, 29/08/2006
1328
- # Currently raises incorrect number of args, 1 for 0
1329
- # selected = @treectrl.get_selections
1330
- # selected_items.each do | item_id |
1331
- # Wx::log_message("\t%s", @treectrl.get_item_text(item_id))
1332
- # end
1333
1336
  end
1334
- end
1335
-
1336
- def on_select(event)
1337
- @treectrl.select_item(@treectrl.selection)
1338
- end
1339
1337
 
1340
- def on_select_root(event)
1341
- unless @treectrl.has_flag(Wx::TR_HIDE_ROOT)
1342
- @treectrl.select_item(@treectrl.root_item)
1338
+ def on_select(event)
1339
+ @treectrl.select_item(@treectrl.selection)
1343
1340
  end
1344
- end
1345
1341
 
1346
- def on_set_focused_root(event)
1347
- unless @treectrl.has_flag(Wx::TR_HIDE_ROOT)
1348
- @treectrl.set_focused_item(@treectrl.root_item)
1342
+ def on_select_root(event)
1343
+ unless @treectrl.has_flag(Wx::TR_HIDE_ROOT)
1344
+ @treectrl.select_item(@treectrl.root_item)
1345
+ end
1349
1346
  end
1350
- end
1351
1347
 
1352
- def on_clear_focused(event)
1353
- @treectrl.clear_focused_item
1354
- end
1348
+ def on_set_focused_root(event)
1349
+ unless @treectrl.has_flag(Wx::TR_HIDE_ROOT)
1350
+ @treectrl.set_focused_item(@treectrl.root_item)
1351
+ end
1352
+ end
1355
1353
 
1356
- def on_unselect(event)
1357
- @treectrl.unselect_all
1358
- end
1354
+ def on_clear_focused(event)
1355
+ @treectrl.clear_focused_item
1356
+ end
1359
1357
 
1360
- def on_select_children(event)
1361
- item = @treectrl.get_focused_item
1358
+ def on_unselect(event)
1359
+ @treectrl.unselect_all
1360
+ end
1362
1361
 
1363
- item = @treectrl.root_item unless item.ok?
1362
+ def on_select_children(event)
1363
+ item = @treectrl.get_focused_item
1364
1364
 
1365
- @treectrl.select_children(item)
1366
- end
1365
+ item = @treectrl.root_item unless item.ok?
1367
1366
 
1368
- def do_set_bold(bold = true)
1369
- item = @treectrl.selection
1370
- return unless check_item(item)
1371
- @treectrl.set_item_bold(item, bold)
1372
- end
1367
+ @treectrl.select_children(item)
1368
+ end
1373
1369
 
1374
- def on_delete(event)
1375
- item = @treectrl.selection
1376
- return unless check_item(item)
1377
- @treectrl.delete(item)
1378
- end
1370
+ def do_set_bold(bold = true)
1371
+ item = @treectrl.selection
1372
+ return unless check_item(item)
1373
+ @treectrl.set_item_bold(item, bold)
1374
+ end
1379
1375
 
1380
- def on_delete_children(event)
1381
- item = @treectrl.selection
1382
- return unless check_item(item)
1383
- @treectrl.delete_children(item)
1384
- end
1376
+ def on_delete(event)
1377
+ item = @treectrl.selection
1378
+ return unless check_item(item)
1379
+ @treectrl.delete(item)
1380
+ end
1385
1381
 
1386
- def on_delete_all(event)
1387
- @treectrl.delete_all_items
1388
- end
1382
+ def on_delete_children(event)
1383
+ item = @treectrl.selection
1384
+ return unless check_item(item)
1385
+ @treectrl.delete_children(item)
1386
+ end
1389
1387
 
1390
- def on_freeze_thaw(event)
1391
- if event.is_checked
1392
- @treectrl.freeze
1393
- else
1394
- @treectrl.thaw
1388
+ def on_delete_all(event)
1389
+ @treectrl.delete_all_items
1395
1390
  end
1396
1391
 
1397
- Wx::log_message("The tree is %sfrozen", @treectrl.is_frozen ? '' : 'not ')
1398
- end
1392
+ def on_freeze_thaw(event)
1393
+ if event.is_checked
1394
+ @treectrl.freeze
1395
+ else
1396
+ @treectrl.thaw
1397
+ end
1399
1398
 
1400
- def on_recreate(event)
1401
- on_delete_all(event)
1402
- @treectrl.add_test_items_to_tree(5, 2)
1403
- end
1399
+ Wx::log_message("The tree is %sfrozen", @treectrl.is_frozen ? '' : 'not ')
1400
+ end
1404
1401
 
1405
- def on_set_image_size(event)
1406
- size = Wx.get_number_from_user("Enter the size for the images to use",
1407
- "Size: ",
1408
- "TreeCtrl sample",
1409
- @treectrl.image_size)
1410
- if size == -1
1411
- return
1402
+ def on_recreate(event)
1403
+ on_delete_all(event)
1404
+ @treectrl.add_test_items_to_tree(5, 2)
1412
1405
  end
1413
1406
 
1414
- @treectrl.create_image_list(size)
1415
- @treectrl.refresh
1416
- Wx::THE_APP.show_images = true
1417
- end
1407
+ def on_set_image_size(event)
1408
+ size = Wx.get_number_from_user("Enter the size for the images to use",
1409
+ "Size: ",
1410
+ "TreeCtrl sample",
1411
+ @treectrl.image_size)
1412
+ if size == -1
1413
+ return
1414
+ end
1418
1415
 
1419
- def on_toggle_images(event)
1420
- if Wx::get_app.show_images
1421
- @treectrl.unset_image_list
1422
- Wx::get_app.show_images = false
1423
- else
1424
- @treectrl.create_image_list(@treectrl.image_size)
1425
- Wx::get_app.show_images = true
1416
+ @treectrl.create_image_list(size)
1417
+ @treectrl.refresh
1418
+ Wx::THE_APP.show_images = true
1426
1419
  end
1427
- end
1428
1420
 
1429
- def on_toggle_states(event)
1430
- if Wx::get_app.show_states
1431
- @treectrl.create_state_imageList(true)
1432
- Wx::get_app.show_states = false
1433
- else
1434
- @treectrl.create_state_imageList
1435
- Wx::get_app.show_states = true
1421
+ def on_toggle_images(event)
1422
+ if Wx::get_app.show_images
1423
+ @treectrl.unset_image_list
1424
+ Wx::get_app.show_images = false
1425
+ else
1426
+ @treectrl.create_image_list(@treectrl.image_size)
1427
+ Wx::get_app.show_images = true
1428
+ end
1436
1429
  end
1437
- end
1438
1430
 
1439
- def on_toggle_bell(event)
1440
- @treectrl.enable_bell_on_no_match(event.checked?)
1441
- end
1431
+ def on_toggle_states(event)
1432
+ if Wx::get_app.show_states
1433
+ @treectrl.create_state_imageList(true)
1434
+ Wx::get_app.show_states = false
1435
+ else
1436
+ @treectrl.create_state_imageList
1437
+ Wx::get_app.show_states = true
1438
+ end
1439
+ end
1442
1440
 
1443
- def on_toggle_alternate_images(event)
1444
- alternateImages = @treectrl.alternate_images
1441
+ def on_toggle_bell(event)
1442
+ @treectrl.enable_bell_on_no_match(event.checked?)
1443
+ end
1445
1444
 
1446
- @treectrl.alternate_images = !alternateImages
1447
- @treectrl.create_image_list(0)
1448
- end
1445
+ def on_toggle_alternate_images(event)
1446
+ alternateImages = @treectrl.alternate_images
1449
1447
 
1450
- def on_toggle_alternate_states(event)
1451
- alternateStates = @treectrl.alternate_states
1448
+ @treectrl.alternate_images = !alternateImages
1449
+ @treectrl.create_image_list(0)
1450
+ end
1452
1451
 
1453
- @treectrl.alternate_states = !alternateStates
1454
- @treectrl.create_state_imageList
1452
+ def on_toggle_alternate_states(event)
1453
+ alternateStates = @treectrl.alternate_states
1455
1454
 
1456
- # normal states < alternate states
1457
- # so we must reset broken states
1458
- if alternateStates
1459
- @treectrl.reset_broken_state_images
1455
+ @treectrl.alternate_states = !alternateStates
1456
+ @treectrl.create_state_imageList
1457
+
1458
+ # normal states < alternate states
1459
+ # so we must reset broken states
1460
+ if alternateStates
1461
+ @treectrl.reset_broken_state_images
1462
+ end
1460
1463
  end
1461
- end
1462
1464
 
1463
- def on_toggle_buttons(event)
1464
- unless Wx::PLATFORM == 'WXMSW'
1465
- if Wx::THE_APP.show_buttons
1466
- @treectrl.create_buttons_image_list(-1)
1467
- Wx::get_app.show_buttons = false
1468
- else
1469
- @treectrl.create_buttons_image_list(15)
1470
- Wx::get_app.show_buttons = true
1465
+ def on_toggle_buttons(event)
1466
+ unless Wx::PLATFORM == 'WXMSW'
1467
+ if Wx::THE_APP.show_buttons
1468
+ @treectrl.create_buttons_image_list(-1)
1469
+ Wx::get_app.show_buttons = false
1470
+ else
1471
+ @treectrl.create_buttons_image_list(15)
1472
+ Wx::get_app.show_buttons = true
1473
+ end
1471
1474
  end
1472
1475
  end
1473
- end
1474
1476
 
1475
- def on_collapse_and_reset(event)
1476
- @treectrl.collapse_and_reset(@treectrl.get_root_item)
1477
- end
1477
+ def on_collapse_and_reset(event)
1478
+ @treectrl.collapse_and_reset(@treectrl.get_root_item)
1479
+ end
1478
1480
 
1479
- def on_ensure_visible(event)
1480
- @treectrl.do_ensure_visible
1481
- end
1481
+ def on_ensure_visible(event)
1482
+ @treectrl.do_ensure_visible
1483
+ end
1482
1484
 
1483
- def on_set_focus(event)
1484
- @treectrl.set_focus
1485
- end
1485
+ def on_set_focus(event)
1486
+ @treectrl.set_focus
1487
+ end
1486
1488
 
1487
- def on_insert_item(event)
1488
- image = Wx::THE_APP.show_images ? TreeCtrlIcon_File : -1
1489
- @treectrl.insert_item(@treectrl.root_item, -1, "2nd item", image)
1490
- end
1489
+ def on_insert_item(event)
1490
+ image = Wx::THE_APP.show_images ? TreeCtrlIcon_File : -1
1491
+ @treectrl.insert_item(@treectrl.root_item, -1, "2nd item", image)
1492
+ end
1491
1493
 
1492
- def on_add_item(event)
1493
- @s_num += 1
1494
- text = sprintf("Item #%d", @s_num)
1495
- @treectrl.append_item(@treectrl.root_item, text)
1496
- end
1494
+ def on_add_item(event)
1495
+ @s_num += 1
1496
+ text = sprintf("Item #%d", @s_num)
1497
+ @treectrl.append_item(@treectrl.root_item, text)
1498
+ end
1497
1499
 
1498
- def on_add_many_items(event)
1499
- Wx::WindowUpdateLocker.update(@treectrl) do
1500
- root = @treectrl.root_item
1501
- 1000.times {|n| @treectrl.append_item(root, "Item #%03d" % [n]) }
1500
+ def on_add_many_items(event)
1501
+ Wx::WindowUpdateLocker.update(@treectrl) do
1502
+ root = @treectrl.root_item
1503
+ 1000.times {|n| @treectrl.append_item(root, "Item #%03d" % [n]) }
1504
+ end
1502
1505
  end
1503
- end
1504
1506
 
1505
- def on_inc_indent(event)
1506
- if @treectrl.indent < 100
1507
- @treectrl.indent += 5
1507
+ def on_inc_indent(event)
1508
+ if @treectrl.indent < 100
1509
+ @treectrl.indent += 5
1510
+ end
1508
1511
  end
1509
- end
1510
1512
 
1511
- def on_dec_indent(event)
1512
- if @treectrl.indent > 10
1513
- @treectrl.indent -= 5
1513
+ def on_dec_indent(event)
1514
+ if @treectrl.indent > 10
1515
+ @treectrl.indent -= 5
1516
+ end
1514
1517
  end
1515
- end
1516
1518
 
1517
- def on_inc_spacing(event)
1518
- if @treectrl.spacing < 100
1519
- @treectrl.spacing += 5
1519
+ def on_inc_spacing(event)
1520
+ if @treectrl.spacing < 100
1521
+ @treectrl.spacing += 5
1522
+ end
1520
1523
  end
1521
- end
1522
1524
 
1523
- def on_dec_spacing(event)
1524
- if @treectrl.spacing > 10
1525
- @treectrl.spacing -= 5
1525
+ def on_dec_spacing(event)
1526
+ if @treectrl.spacing > 10
1527
+ @treectrl.spacing -= 5
1528
+ end
1526
1529
  end
1527
- end
1528
1530
 
1529
- def on_toggle_icon(event)
1530
- item = @treectrl.focused_item
1531
- return unless check_item(item)
1532
- @treectrl.do_toggle_icon(item)
1533
- end
1531
+ def on_toggle_icon(event)
1532
+ item = @treectrl.focused_item
1533
+ return unless check_item(item)
1534
+ @treectrl.do_toggle_icon(item)
1535
+ end
1534
1536
 
1535
- def on_toggle_state(event)
1536
- item = @treectrl.focused_item
1537
- return unless check_item(item)
1538
- @treectrl.do_toggle_state(item)
1539
- end
1537
+ def on_toggle_state(event)
1538
+ item = @treectrl.focused_item
1539
+ return unless check_item(item)
1540
+ @treectrl.do_toggle_state(item)
1541
+ end
1540
1542
 
1541
- def do_show_first_or_last(label)
1542
- item = yield
1543
- unless item.ok?
1544
- Wx::log_message("There is no %s item" % label)
1545
- else
1546
- Wx::log_message("The %s item is \"%s\"" %
1547
- [label, @treectrl.item_text(item)])
1543
+ def do_show_first_or_last(label)
1544
+ item = yield
1545
+ unless item.ok?
1546
+ Wx::log_message("There is no %s item" % label)
1547
+ else
1548
+ Wx::log_message("The %s item is \"%s\"" %
1549
+ [label, @treectrl.item_text(item)])
1550
+ end
1548
1551
  end
1549
- end
1550
1552
 
1551
- def do_show_relative_item(label)
1552
- item = @treectrl.focused_item
1553
+ def do_show_relative_item(label)
1554
+ item = @treectrl.focused_item
1553
1555
 
1554
- return unless item.ok?
1555
- unless !label['visible'] || @treectrl.visible?(item)
1556
- Wx::log_message("The selected item must be visible.")
1557
- return
1558
- end
1556
+ return unless item.ok?
1557
+ unless !label['visible'] || @treectrl.visible?(item)
1558
+ Wx::log_message("The selected item must be visible.")
1559
+ return
1560
+ end
1559
1561
 
1560
- item = yield(item)
1562
+ item = yield(item)
1561
1563
 
1562
- unless item.ok?
1563
- Wx::log_message("There is no %s item" % label)
1564
- else
1565
- Wx::log_message("The %s item is \"%s\"" %
1566
- [label, @treectrl.item_text(item)])
1564
+ unless item.ok?
1565
+ Wx::log_message("There is no %s item" % label)
1566
+ else
1567
+ Wx::log_message("The %s item is \"%s\"" %
1568
+ [label, @treectrl.item_text(item)])
1569
+ end
1567
1570
  end
1568
- end
1569
1571
 
1570
- def on_show_first_visible(event)
1571
- do_show_first_or_last("first visible") { @treectrl.first_visible_item }
1572
- end
1572
+ def on_show_first_visible(event)
1573
+ do_show_first_or_last("first visible") { @treectrl.first_visible_item }
1574
+ end
1573
1575
 
1574
- def on_show_last_visible(event)
1575
- if Wx.has_feature?(:HAS_LAST_VISIBLE)
1576
- do_show_first_or_last("last visible") { @treectrl.last_visible_item }
1576
+ def on_show_last_visible(event)
1577
+ if Wx.has_feature?(:HAS_LAST_VISIBLE)
1578
+ do_show_first_or_last("last visible") { @treectrl.last_visible_item }
1579
+ end
1577
1580
  end
1578
- end
1579
1581
 
1580
- def on_show_next_visible(event)
1581
- do_show_relative_item("next visible") { |itm| @treectrl.next_visible(itm) }
1582
- end
1582
+ def on_show_next_visible(event)
1583
+ do_show_relative_item("next visible") { |itm| @treectrl.next_visible(itm) }
1584
+ end
1583
1585
 
1584
- def on_show_prev_visible(event)
1585
- do_show_relative_item("prev visible") { |itm| @treectrl.prev_visible(itm) }
1586
- end
1586
+ def on_show_prev_visible(event)
1587
+ do_show_relative_item("prev visible") { |itm| @treectrl.prev_visible(itm) }
1588
+ end
1587
1589
 
1588
- def on_show_parent(event)
1589
- do_show_relative_item("parent") { |itm| @treectrl.item_parent(itm) }
1590
- end
1590
+ def on_show_parent(event)
1591
+ do_show_relative_item("parent") { |itm| @treectrl.item_parent(itm) }
1592
+ end
1591
1593
 
1592
- def on_show_prev_sibling(event)
1593
- do_show_relative_item("previous sibling") { |itm| @treectrl.prev_sibling(itm) }
1594
- end
1594
+ def on_show_prev_sibling(event)
1595
+ do_show_relative_item("previous sibling") { |itm| @treectrl.prev_sibling(itm) }
1596
+ end
1595
1597
 
1596
- def on_show_next_sibling(event)
1597
- do_show_relative_item("next sibling") { |itm| @treectrl.next_sibling(itm) }
1598
- end
1598
+ def on_show_next_sibling(event)
1599
+ do_show_relative_item("next sibling") { |itm| @treectrl.next_sibling(itm) }
1600
+ end
1599
1601
 
1600
- def on_scroll_to(event)
1601
- # scroll to the last but one top level child
1602
- item = @treectrl.get_prev_sibling(
1603
- @treectrl.get_last_child(
1604
- @treectrl.root_item))
1605
- return unless item.ok?
1602
+ def on_scroll_to(event)
1603
+ # scroll to the last but one top level child
1604
+ item = @treectrl.get_prev_sibling(
1605
+ @treectrl.get_last_child(
1606
+ @treectrl.root_item))
1607
+ return unless item.ok?
1606
1608
 
1607
- @treectrl.scroll_to(item)
1608
- end
1609
+ @treectrl.scroll_to(item)
1610
+ end
1609
1611
 
1610
- def on_select_last(event)
1611
- item = @treectrl.last_tree_item
1612
+ def on_select_last(event)
1613
+ item = @treectrl.last_tree_item
1612
1614
 
1613
- return unless item.ok?
1615
+ return unless item.ok?
1614
1616
 
1615
- @treectrl.select_item(item)
1616
- end
1617
+ @treectrl.select_item(item)
1618
+ end
1617
1619
 
1618
- def on_set_fg_colour(event)
1619
- col = Wx::get_colour_from_user(self, @treectrl.foreground_colour)
1620
- if col.ok?
1621
- @treectrl.foreground_colour = col
1620
+ def on_set_fg_colour(event)
1621
+ col = Wx::get_colour_from_user(self, @treectrl.foreground_colour)
1622
+ if col.ok?
1623
+ @treectrl.foreground_colour = col
1624
+ end
1622
1625
  end
1623
- end
1624
1626
 
1625
- def on_set_bg_colour(event)
1626
- col = Wx::get_colour_from_user(self, @treectrl.background_colour)
1627
- if col.ok?
1628
- @treectrl.background_colour = col
1627
+ def on_set_bg_colour(event)
1628
+ col = Wx::get_colour_from_user(self, @treectrl.background_colour)
1629
+ if col.ok?
1630
+ @treectrl.background_colour = col
1631
+ end
1629
1632
  end
1630
- end
1631
1633
 
1632
- def on_tog_buttons(event)
1633
- tog_style(event.id, Wx::TR_HAS_BUTTONS)
1634
- end
1634
+ def on_tog_buttons(event)
1635
+ tog_style(event.id, Wx::TR_HAS_BUTTONS)
1636
+ end
1635
1637
 
1636
- def on_tog_twist(event)
1637
- tog_style(event.id, Wx::TR_TWIST_BUTTONS)
1638
- end
1638
+ def on_tog_twist(event)
1639
+ tog_style(event.id, Wx::TR_TWIST_BUTTONS)
1640
+ end
1639
1641
 
1640
- def on_tog_lines(event)
1641
- tog_style(event.id, Wx::TR_NO_LINES)
1642
- end
1642
+ def on_tog_lines(event)
1643
+ tog_style(event.id, Wx::TR_NO_LINES)
1644
+ end
1643
1645
 
1644
- def on_tog_edit(event)
1645
- tog_style(event.id, Wx::TR_EDIT_LABELS)
1646
- end
1646
+ def on_tog_edit(event)
1647
+ tog_style(event.id, Wx::TR_EDIT_LABELS)
1648
+ end
1647
1649
 
1648
- def on_tog_hide_root(event)
1649
- tog_style(event.id, Wx::TR_HIDE_ROOT)
1650
- end
1650
+ def on_tog_hide_root(event)
1651
+ tog_style(event.id, Wx::TR_HIDE_ROOT)
1652
+ end
1651
1653
 
1652
- def on_tog_root_lines(event)
1653
- tog_style(event.id, Wx::TR_LINES_AT_ROOT)
1654
- end
1654
+ def on_tog_root_lines(event)
1655
+ tog_style(event.id, Wx::TR_LINES_AT_ROOT)
1656
+ end
1655
1657
 
1656
- def on_tog_border(event)
1657
- tog_style(event.id, Wx::TR_ROW_LINES)
1658
- end
1658
+ def on_tog_border(event)
1659
+ tog_style(event.id, Wx::TR_ROW_LINES)
1660
+ end
1659
1661
 
1660
- def on_tog_full_highlight(event)
1661
- tog_style(event.id, Wx::TR_FULL_ROW_HIGHLIGHT)
1662
- end
1662
+ def on_tog_full_highlight(event)
1663
+ tog_style(event.id, Wx::TR_FULL_ROW_HIGHLIGHT)
1664
+ end
1663
1665
 
1664
- def on_reset_style(event)
1665
- create_tree_with_default_style
1666
- end
1666
+ def on_reset_style(event)
1667
+ create_tree_with_default_style
1668
+ end
1667
1669
 
1668
- def on_set_bold(event)
1669
- do_set_bold(true)
1670
- end
1670
+ def on_set_bold(event)
1671
+ do_set_bold(true)
1672
+ end
1671
1673
 
1672
- def on_clear_bold(event)
1673
- do_set_bold(false)
1674
- end
1674
+ def on_clear_bold(event)
1675
+ do_set_bold(false)
1676
+ end
1675
1677
 
1676
- def on_sort(event)
1677
- do_sort
1678
- end
1678
+ def on_sort(event)
1679
+ do_sort
1680
+ end
1679
1681
 
1680
- def on_sort_rev(event)
1681
- do_sort(true)
1682
- end
1682
+ def on_sort_rev(event)
1683
+ do_sort(true)
1684
+ end
1685
+
1686
+ def on_close(event)
1687
+ Wx::Log::active_target = @old_log_tgt
1688
+ destroy
1689
+ end
1683
1690
 
1684
- def on_close(event)
1685
- Wx::Log::active_target = @old_log_tgt
1686
- destroy
1687
1691
  end
1688
1692
 
1689
- end
1693
+ class MyApp < Wx::App
1694
+ attr_accessor :show_images, :show_buttons, :show_states
1690
1695
 
1691
- class MyApp < Wx::App
1692
- attr_accessor :show_images, :show_buttons, :show_states
1696
+ def initialize
1697
+ self.show_images = true
1698
+ self.show_buttons = false
1699
+ self.show_states = true
1700
+ super
1701
+ end
1693
1702
 
1694
- def initialize
1695
- self.show_images = true
1696
- self.show_buttons = false
1697
- self.show_states = true
1698
- super
1703
+ def on_init
1704
+ # Create the main frame window
1705
+ frame = MyFrame.new("TreeCtrl Test", 50, 50, 450, 600)
1706
+ # show the frame
1707
+ frame.show(true)
1708
+ end
1699
1709
  end
1700
1710
 
1701
- def on_init
1702
- # Create the main frame window
1703
- frame = MyFrame.new("TreeCtrl Test", 50, 50, 450, 600)
1704
- # show the frame
1705
- frame.show(true)
1706
- end
1707
1711
  end
1708
1712
 
1709
1713
  module TreeCtrlSample
@@ -1721,7 +1725,7 @@ module TreeCtrlSample
1721
1725
  end
1722
1726
 
1723
1727
  if $0 == __FILE__
1724
- MyApp.run
1728
+ TreeCtrl::MyApp.run
1725
1729
  end
1726
1730
 
1727
1731
  end