wxruby3 0.9.0.pre.rc.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (656) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/ext/mkrf_conf_srcgem.rb +4 -1
  4. data/ext/wxruby3/include/wxruby-Config.h +953 -0
  5. data/ext/wxruby3/include/wxruby-ScaledDC.h +4 -1
  6. data/ext/wxruby3/include/wxruby-runtime.h +10 -1
  7. data/ext/wxruby3/swig/RubyStockObjects.i +5 -3
  8. data/ext/wxruby3/swig/common.i +8 -3
  9. data/ext/wxruby3/swig/mark_free_impl.i +6 -4
  10. data/ext/wxruby3/swig/memory_management.i +5 -3
  11. data/ext/wxruby3/swig/typedefs.i +5 -3
  12. data/ext/wxruby3/swig/wx.i +5 -0
  13. data/ext/wxruby3/swig/wx.rc +4 -2
  14. data/lib/wx/accessors.rb +10 -2
  15. data/lib/wx/aui/auifloatframe.rb +20 -0
  16. data/lib/wx/aui/auimanager.rb +3 -0
  17. data/lib/wx/aui/auinotebook.rb +17 -0
  18. data/lib/wx/aui/require.rb +5 -1
  19. data/lib/wx/aui.rb +4 -1
  20. data/lib/wx/core/acceleratortable.rb +8 -0
  21. data/lib/wx/core/animation.rb +8 -0
  22. data/lib/wx/core/app.rb +8 -0
  23. data/lib/wx/core/array_ext.rb +7 -0
  24. data/lib/wx/core/art_locator.rb +7 -0
  25. data/lib/wx/core/artprovider.rb +9 -0
  26. data/lib/wx/core/bitmap.rb +16 -4
  27. data/lib/wx/core/bitmap_combobox.rb +7 -0
  28. data/lib/wx/core/brush.rb +7 -0
  29. data/lib/wx/core/busycursor.rb +9 -0
  30. data/lib/wx/core/choice.rb +7 -0
  31. data/lib/wx/core/choicedlg.rb +7 -0
  32. data/lib/wx/core/clientdc.rb +9 -0
  33. data/lib/wx/core/clipboard.rb +8 -0
  34. data/lib/wx/core/collapsible_pane.rb +8 -1
  35. data/lib/wx/core/colour.rb +8 -0
  36. data/lib/wx/core/combo_ctrl.rb +110 -0
  37. data/lib/wx/core/combobox.rb +7 -0
  38. data/lib/wx/core/config.rb +303 -0
  39. data/lib/wx/core/controlwithitems.rb +12 -1
  40. data/lib/wx/core/cursor.rb +14 -4
  41. data/lib/wx/core/data_object.rb +7 -0
  42. data/lib/wx/core/dataformat.rb +9 -0
  43. data/lib/wx/core/datetime.rb +14 -0
  44. data/lib/wx/core/dc.rb +7 -0
  45. data/lib/wx/core/dialog.rb +18 -1
  46. data/lib/wx/core/enum.rb +7 -0
  47. data/lib/wx/core/event.rb +7 -0
  48. data/lib/wx/core/event_blocker.rb +7 -0
  49. data/lib/wx/core/event_loop.rb +7 -0
  50. data/lib/wx/core/evthandler.rb +8 -0
  51. data/lib/wx/core/ext.rb +7 -0
  52. data/lib/wx/core/file_dialog.rb +23 -0
  53. data/lib/wx/core/find_replace_dialog.rb +7 -0
  54. data/lib/wx/core/functions.rb +8 -0
  55. data/lib/wx/core/gauge.rb +10 -1
  56. data/lib/wx/core/genericdirctrl.rb +9 -0
  57. data/lib/wx/core/hboxsizer.rb +16 -0
  58. data/lib/wx/core/helpcontroller.rb +8 -0
  59. data/lib/wx/core/helpcontrollerhelpprovider.rb +9 -0
  60. data/lib/wx/core/helpprovider.rb +10 -1
  61. data/lib/wx/core/icon.rb +17 -6
  62. data/lib/wx/core/id_helper.rb +7 -0
  63. data/lib/wx/core/image.rb +16 -4
  64. data/lib/wx/core/imagelist.rb +8 -1
  65. data/lib/wx/core/listbox.rb +7 -0
  66. data/lib/wx/core/listctrl.rb +9 -0
  67. data/lib/wx/core/locale.rb +8 -0
  68. data/lib/wx/core/log.rb +24 -0
  69. data/lib/wx/core/menu.rb +9 -0
  70. data/lib/wx/core/menu_bar.rb +7 -0
  71. data/lib/wx/core/menuitem.rb +9 -0
  72. data/lib/wx/core/notebook.rb +9 -0
  73. data/lib/wx/core/object.rb +9 -0
  74. data/lib/wx/core/paintdc.rb +7 -0
  75. data/lib/wx/core/pen.rb +7 -0
  76. data/lib/wx/core/pen_info.rb +7 -0
  77. data/lib/wx/core/platform_info.rb +7 -0
  78. data/lib/wx/core/point.rb +8 -0
  79. data/lib/wx/core/real_point.rb +8 -0
  80. data/lib/wx/core/rect.rb +9 -0
  81. data/lib/wx/core/region_iterator.rb +7 -0
  82. data/lib/wx/core/simplehelpprovider.rb +9 -0
  83. data/lib/wx/core/size.rb +8 -0
  84. data/lib/wx/core/sizer.rb +9 -0
  85. data/lib/wx/core/splash_screen.rb +22 -2
  86. data/lib/wx/core/text_entry.rb +7 -0
  87. data/lib/wx/core/textctrl.rb +86 -5
  88. data/lib/wx/core/timer.rb +9 -0
  89. data/lib/wx/core/toolbar.rb +9 -0
  90. data/lib/wx/core/toolbartool.rb +8 -0
  91. data/lib/wx/core/treectrl.rb +9 -0
  92. data/lib/wx/core/v_list_box.rb +7 -0
  93. data/lib/wx/core/validator.rb +7 -0
  94. data/lib/wx/core/variant.rb +7 -0
  95. data/lib/wx/core/vboxsizer.rb +16 -0
  96. data/lib/wx/core/window.rb +8 -0
  97. data/lib/wx/core/window_update_locker.rb +9 -0
  98. data/lib/wx/core/xmlresource.rb +8 -0
  99. data/lib/wx/core.rb +4 -1
  100. data/lib/wx/doc/app.rb +7 -1
  101. data/lib/wx/doc/array_ext.rb +6 -0
  102. data/lib/wx/doc/art_locator.rb +7 -0
  103. data/lib/wx/doc/aui/auimanager.rb +6 -0
  104. data/lib/wx/doc/aui/auinotebook.rb +6 -0
  105. data/lib/wx/doc/bitmap.rb +12 -4
  106. data/lib/wx/doc/brush.rb +6 -0
  107. data/lib/wx/doc/busy_info.rb +6 -0
  108. data/lib/wx/doc/client_dc.rb +6 -0
  109. data/lib/wx/doc/clipboard.rb +6 -0
  110. data/lib/wx/doc/colour_dialog.rb +6 -0
  111. data/lib/wx/doc/config.rb +190 -0
  112. data/lib/wx/doc/const.rb +7 -0
  113. data/lib/wx/doc/controlwithitems.rb +6 -0
  114. data/lib/wx/doc/core.rb +6 -0
  115. data/lib/wx/doc/cursor.rb +13 -5
  116. data/lib/wx/doc/data_object.rb +6 -0
  117. data/lib/wx/doc/datetime.rb +16 -0
  118. data/lib/wx/doc/dc.rb +6 -0
  119. data/lib/wx/doc/enum.rb +8 -1
  120. data/lib/wx/doc/event.rb +12 -0
  121. data/lib/wx/doc/event_blocker.rb +6 -0
  122. data/lib/wx/doc/event_loop.rb +6 -0
  123. data/lib/wx/doc/events.rb +6 -0
  124. data/lib/wx/doc/evthandler.rb +8 -0
  125. data/lib/wx/doc/extra/01_packages.md +52 -51
  126. data/lib/wx/doc/extra/05_event-handling.md +37 -12
  127. data/lib/wx/doc/extra/06_geometry.md +5 -5
  128. data/lib/wx/doc/extra/07_colour_and_font.md +2 -2
  129. data/lib/wx/doc/extra/09_exceptions.md +1 -1
  130. data/lib/wx/doc/extra/10_art.md +18 -12
  131. data/lib/wx/doc/extra/11_drawing_and_dc.md +4 -4
  132. data/lib/wx/doc/font.rb +6 -0
  133. data/lib/wx/doc/font_data.rb +16 -0
  134. data/lib/wx/doc/functions.rb +9 -1
  135. data/lib/wx/doc/gc_dc.rb +6 -0
  136. data/lib/wx/doc/gdi_common.rb +8 -1
  137. data/lib/wx/doc/graphics_context.rb +59 -39
  138. data/lib/wx/doc/grid/grid.rb +16 -1
  139. data/lib/wx/doc/hboxsizer.rb +33 -0
  140. data/lib/wx/doc/help_controller.rb +6 -0
  141. data/lib/wx/doc/html/html_help_controller.rb +6 -0
  142. data/lib/wx/doc/icon.rb +13 -5
  143. data/lib/wx/doc/id_helper.rb +6 -0
  144. data/lib/wx/doc/image.rb +12 -4
  145. data/lib/wx/doc/list_ctrl.rb +6 -0
  146. data/lib/wx/doc/log.rb +17 -0
  147. data/lib/wx/doc/memory_dc.rb +6 -0
  148. data/lib/wx/doc/mirror_dc.rb +6 -0
  149. data/lib/wx/doc/pen.rb +6 -0
  150. data/lib/wx/doc/pg/events.rb +6 -0
  151. data/lib/wx/doc/pg/pg_property.rb +17 -0
  152. data/lib/wx/doc/pg/pgeditor.rb +6 -0
  153. data/lib/wx/doc/pg/property_grid.rb +6 -0
  154. data/lib/wx/doc/pg/property_grid_interface.rb +6 -0
  155. data/lib/wx/doc/progress_dialog.rb +6 -0
  156. data/lib/wx/doc/prt/page_setup_dialog.rb +6 -0
  157. data/lib/wx/doc/prt/print_data.rb +6 -0
  158. data/lib/wx/doc/prt/print_dialog.rb +6 -0
  159. data/lib/wx/doc/prt/printer.rb +6 -0
  160. data/lib/wx/doc/prt/printer_dc.rb +6 -0
  161. data/lib/wx/doc/radio_box.rb +6 -0
  162. data/lib/wx/doc/rbn/ribbon_bar.rb +6 -0
  163. data/lib/wx/doc/rbn/ribbon_button_bar.rb +6 -0
  164. data/lib/wx/doc/rbn/ribbon_gallery.rb +6 -0
  165. data/lib/wx/doc/rbn/ribbon_tool_bar.rb +6 -0
  166. data/lib/wx/doc/region_iterator.rb +6 -0
  167. data/lib/wx/doc/rtc/richtext_buffer.rb +28 -0
  168. data/lib/wx/doc/rtc/richtext_formatting_dialog.rb +68 -0
  169. data/lib/wx/doc/rtc/richtext_printing.rb +6 -0
  170. data/lib/wx/doc/rtc/richtext_style_sheet.rb +20 -0
  171. data/lib/wx/doc/scaled_dc.rb +6 -0
  172. data/lib/wx/doc/screen_dc.rb +6 -0
  173. data/lib/wx/doc/stock_objects.rb +6 -0
  174. data/lib/wx/doc/stream.rb +6 -0
  175. data/lib/wx/doc/svg_file_dc.rb +6 -0
  176. data/lib/wx/doc/system_settings.rb +6 -0
  177. data/lib/wx/doc/text_validator.rb +6 -0
  178. data/lib/wx/doc/textctrl.rb +89 -0
  179. data/lib/wx/doc/tree_event.rb +20 -0
  180. data/lib/wx/doc/treebook.rb +6 -0
  181. data/lib/wx/doc/v_list_box.rb +6 -0
  182. data/lib/wx/doc/variant.rb +6 -0
  183. data/lib/wx/doc/vboxsizer.rb +33 -0
  184. data/lib/wx/doc/window.rb +6 -0
  185. data/lib/wx/doc/window_disabler.rb +6 -0
  186. data/lib/wx/doc/xml_resource.rb +8 -0
  187. data/lib/wx/global_const.rb +4 -1
  188. data/lib/wx/grid/grid.rb +23 -3
  189. data/lib/wx/grid/keyword_defs.rb +8 -1
  190. data/lib/wx/grid/require.rb +4 -1
  191. data/lib/wx/grid.rb +4 -1
  192. data/lib/wx/helpers.rb +8 -1
  193. data/lib/wx/html/htmlhelpcontroller.rb +29 -3
  194. data/lib/wx/html/htmlwindow.rb +23 -12
  195. data/lib/wx/html/keyword_defs.rb +8 -1
  196. data/lib/wx/html/require.rb +4 -1
  197. data/lib/wx/html/simple_html_listbox.rb +3 -0
  198. data/lib/wx/html.rb +4 -1
  199. data/lib/wx/keyword_ctors.rb +22 -3
  200. data/lib/wx/keyword_defs.rb +55 -3
  201. data/lib/wx/pg/events.rb +4 -1
  202. data/lib/wx/pg/keyword_defs.rb +8 -1
  203. data/lib/wx/pg/pg_editor.rb +3 -0
  204. data/lib/wx/pg/pg_properties.rb +4 -1
  205. data/lib/wx/pg/pg_property.rb +18 -5
  206. data/lib/wx/pg/property_grid.rb +4 -1
  207. data/lib/wx/pg/property_grid_interface.rb +3 -0
  208. data/lib/wx/pg/require.rb +4 -1
  209. data/lib/wx/pg.rb +4 -1
  210. data/lib/wx/prt/keyword_defs.rb +8 -1
  211. data/lib/wx/prt/page_setup_dialog.rb +3 -0
  212. data/lib/wx/prt/previewframe.rb +5 -0
  213. data/lib/wx/prt/require.rb +4 -1
  214. data/lib/wx/prt.rb +4 -1
  215. data/lib/wx/rbn/events.rb +4 -1
  216. data/lib/wx/rbn/keyword_defs.rb +8 -1
  217. data/lib/wx/rbn/require.rb +5 -1
  218. data/lib/wx/rbn/ribbon_art_provider.rb +3 -1
  219. data/lib/wx/rbn/ribbon_bar.rb +3 -0
  220. data/lib/wx/rbn/ribbon_button_bar.rb +3 -0
  221. data/lib/wx/rbn/ribbon_control.rb +3 -0
  222. data/lib/wx/rbn/ribbon_gallery.rb +10 -0
  223. data/lib/wx/rbn/ribbon_page.rb +3 -0
  224. data/lib/wx/rbn/ribbon_panel.rb +3 -0
  225. data/lib/wx/rbn/ribbon_tool_bar.rb +3 -0
  226. data/lib/wx/rbn.rb +4 -1
  227. data/lib/wx/rtc/ext.rb +4 -1
  228. data/lib/wx/rtc/keyword_defs.rb +18 -7
  229. data/lib/wx/rtc/require.rb +8 -1
  230. data/lib/wx/rtc/richtext_buffer.rb +36 -0
  231. data/lib/wx/rtc/richtext_formatting_dialog.rb +88 -0
  232. data/lib/wx/rtc/richtext_style_organiser_dialog.rb +46 -0
  233. data/lib/wx/rtc/symbol_picker_dialog.rb +47 -0
  234. data/lib/wx/rtc.rb +5 -1
  235. data/lib/wx/stc/keyword_defs.rb +8 -1
  236. data/lib/wx/stc/require.rb +4 -1
  237. data/lib/wx/stc.rb +4 -1
  238. data/lib/wx/version.rb +5 -1
  239. data/lib/wx/wxruby/base.rb +4 -1
  240. data/lib/wx/wxruby/cmd/sampler.rb +4 -1
  241. data/lib/wx/wxruby/cmd/test.rb +4 -1
  242. data/lib/wx.rb +4 -1
  243. data/rakelib/build.rake +4 -1
  244. data/rakelib/build.rb +4 -1
  245. data/rakelib/config.rake +4 -1
  246. data/rakelib/configure.rb +4 -1
  247. data/rakelib/doc.rake +4 -1
  248. data/rakelib/doc.rb +5 -1
  249. data/rakelib/install.rake +4 -1
  250. data/rakelib/install.rb +4 -1
  251. data/rakelib/lib/config/cygwin.rb +4 -1
  252. data/rakelib/lib/config/linux.rb +4 -1
  253. data/rakelib/lib/config/macosx.rb +5 -2
  254. data/rakelib/lib/config/mingw.rb +4 -1
  255. data/rakelib/lib/config/netbsd.rb +4 -1
  256. data/rakelib/lib/config/unixish.rb +10 -7
  257. data/rakelib/lib/config.rb +7 -2
  258. data/rakelib/lib/core/include/enum.inc +4 -1
  259. data/rakelib/lib/core/include/funcall.inc +10 -64
  260. data/rakelib/lib/core/include/init.inc +3 -0
  261. data/rakelib/lib/core/mapping.rb +26 -46
  262. data/rakelib/lib/core/package.rb +17 -3
  263. data/rakelib/lib/core/parameter.rb +4 -1
  264. data/rakelib/lib/core/spec.rb +14 -8
  265. data/rakelib/lib/core/spec_helper.rb +32 -9
  266. data/rakelib/lib/director/about_dialog_info.rb +4 -1
  267. data/rakelib/lib/director/accelerator.rb +7 -2
  268. data/rakelib/lib/director/animation.rb +4 -1
  269. data/rakelib/lib/director/animation_ctrl.rb +4 -1
  270. data/rakelib/lib/director/any_button.rb +5 -2
  271. data/rakelib/lib/director/app.rb +16 -2
  272. data/rakelib/lib/director/app_traits.rb +71 -0
  273. data/rakelib/lib/director/art_provider.rb +4 -1
  274. data/rakelib/lib/director/aui_dock_art.rb +4 -1
  275. data/rakelib/lib/director/aui_floating_frame.rb +4 -1
  276. data/rakelib/lib/director/aui_manager.rb +12 -5
  277. data/rakelib/lib/director/aui_manager_event.rb +4 -1
  278. data/rakelib/lib/director/aui_mdi_child_frame.rb +25 -1
  279. data/rakelib/lib/director/aui_mdi_client_window.rb +4 -1
  280. data/rakelib/lib/director/aui_mdi_parent_frame.rb +4 -1
  281. data/rakelib/lib/director/aui_notebook.rb +12 -1
  282. data/rakelib/lib/director/aui_notebook_event.rb +4 -1
  283. data/rakelib/lib/director/aui_pane_info.rb +4 -1
  284. data/rakelib/lib/director/aui_tab_art.rb +52 -1
  285. data/rakelib/lib/director/aui_tab_ctrl.rb +14 -1
  286. data/rakelib/lib/director/aui_toolbar.rb +6 -3
  287. data/rakelib/lib/director/aui_toolbar_art.rb +52 -1
  288. data/rakelib/lib/director/aui_toolbar_event.rb +4 -1
  289. data/rakelib/lib/director/aui_toolbar_item.rb +4 -1
  290. data/rakelib/lib/director/banner_window.rb +26 -0
  291. data/rakelib/lib/director/bitmap.rb +11 -2
  292. data/rakelib/lib/director/bitmap_combobox.rb +5 -1
  293. data/rakelib/lib/director/book_ctrls.rb +13 -3
  294. data/rakelib/lib/director/brush.rb +4 -1
  295. data/rakelib/lib/director/busy_info.rb +4 -1
  296. data/rakelib/lib/director/button.rb +4 -1
  297. data/rakelib/lib/director/calendar_ctrl.rb +4 -1
  298. data/rakelib/lib/director/calendar_date_attr.rb +4 -1
  299. data/rakelib/lib/director/caret.rb +4 -1
  300. data/rakelib/lib/director/check_listbox.rb +4 -1
  301. data/rakelib/lib/director/choice.rb +4 -1
  302. data/rakelib/lib/director/clipboard.rb +4 -1
  303. data/rakelib/lib/director/collapsible_pane.rb +4 -1
  304. data/rakelib/lib/director/collapsible_pane_event.rb +4 -1
  305. data/rakelib/lib/director/colour.rb +9 -1
  306. data/rakelib/lib/director/colour_picker_ctrl.rb +4 -1
  307. data/rakelib/lib/director/combobox.rb +4 -1
  308. data/rakelib/lib/director/comboctrl.rb +94 -0
  309. data/rakelib/lib/director/config_base.rb +135 -0
  310. data/rakelib/lib/director/context_help_button.rb +4 -1
  311. data/rakelib/lib/director/control.rb +4 -1
  312. data/rakelib/lib/director/ctrl_with_items.rb +5 -1
  313. data/rakelib/lib/director/cursor.rb +6 -2
  314. data/rakelib/lib/director/data_format.rb +4 -1
  315. data/rakelib/lib/director/data_object.rb +4 -1
  316. data/rakelib/lib/director/data_object_simple_base.rb +4 -1
  317. data/rakelib/lib/director/date_event.rb +9 -2
  318. data/rakelib/lib/director/date_picker_ctrl.rb +4 -1
  319. data/rakelib/lib/director/dc.rb +19 -1
  320. data/rakelib/lib/director/defs.rb +4 -1
  321. data/rakelib/lib/director/derived_dc.rb +27 -20
  322. data/rakelib/lib/director/dialog.rb +24 -3
  323. data/rakelib/lib/director/dir_filterlist_ctrl.rb +4 -1
  324. data/rakelib/lib/director/dir_picker_ctrl.rb +4 -1
  325. data/rakelib/lib/director/drag_image.rb +9 -2
  326. data/rakelib/lib/director/dragdrop.rb +4 -1
  327. data/rakelib/lib/director/editable_listbox.rb +4 -1
  328. data/rakelib/lib/director/event.rb +11 -3
  329. data/rakelib/lib/director/event_blocker.rb +4 -1
  330. data/rakelib/lib/director/event_filter.rb +4 -1
  331. data/rakelib/lib/director/event_handler.rb +28 -11
  332. data/rakelib/lib/director/event_loop.rb +4 -1
  333. data/rakelib/lib/director/events.rb +5 -2
  334. data/rakelib/lib/director/file_dialog_custom_control.rb +28 -0
  335. data/rakelib/lib/director/file_dialog_customize_hook.rb +28 -0
  336. data/rakelib/lib/director/file_picker_ctrl.rb +4 -1
  337. data/rakelib/lib/director/file_system.rb +45 -0
  338. data/rakelib/lib/director/find_dialog_event.rb +4 -1
  339. data/rakelib/lib/director/find_replace_data.rb +4 -1
  340. data/rakelib/lib/director/font.rb +7 -3
  341. data/rakelib/lib/director/font_data.rb +9 -1
  342. data/rakelib/lib/director/font_picker_ctrl.rb +4 -1
  343. data/rakelib/lib/director/frame.rb +45 -33
  344. data/rakelib/lib/director/fs_file.rb +52 -1
  345. data/rakelib/lib/director/functions.rb +11 -5
  346. data/rakelib/lib/director/gdi_object.rb +4 -1
  347. data/rakelib/lib/director/gdicommon.rb +14 -9
  348. data/rakelib/lib/director/generic_dirctrl.rb +4 -1
  349. data/rakelib/lib/director/graphics_context.rb +113 -18
  350. data/rakelib/lib/director/graphics_object.rb +13 -2
  351. data/rakelib/lib/director/grid_cell_attr.rb +28 -4
  352. data/rakelib/lib/director/grid_cell_editor.rb +22 -5
  353. data/rakelib/lib/director/grid_cell_renderer.rb +16 -3
  354. data/rakelib/lib/director/grid_ctrl.rb +146 -5
  355. data/rakelib/lib/director/grid_range_select_event.rb +4 -1
  356. data/rakelib/lib/director/grid_table_base.rb +6 -1
  357. data/rakelib/lib/director/grid_table_message.rb +4 -1
  358. data/rakelib/lib/director/header_ctrl.rb +37 -0
  359. data/rakelib/lib/director/help_controller.rb +13 -6
  360. data/rakelib/lib/director/help_provider.rb +4 -1
  361. data/rakelib/lib/director/html_cell.rb +10 -3
  362. data/rakelib/lib/director/html_data_object.rb +4 -1
  363. data/rakelib/lib/director/html_easy_printing.rb +4 -1
  364. data/rakelib/lib/director/html_event.rb +4 -1
  365. data/rakelib/lib/director/html_help_data.rb +4 -1
  366. data/rakelib/lib/director/html_help_window.rb +30 -0
  367. data/rakelib/lib/director/html_listbox.rb +4 -1
  368. data/rakelib/lib/director/html_printout.rb +6 -1
  369. data/rakelib/lib/director/html_window.rb +10 -8
  370. data/rakelib/lib/director/hyperlink_ctrl.rb +32 -0
  371. data/rakelib/lib/director/hyperlink_event.rb +4 -1
  372. data/rakelib/lib/director/icon.rb +4 -1
  373. data/rakelib/lib/director/image.rb +26 -3
  374. data/rakelib/lib/director/image_list.rb +5 -1
  375. data/rakelib/lib/director/info_bar.rb +26 -0
  376. data/rakelib/lib/director/list_ctrl.rb +39 -7
  377. data/rakelib/lib/director/listbox.rb +4 -1
  378. data/rakelib/lib/director/locale.rb +7 -4
  379. data/rakelib/lib/director/log.rb +51 -6
  380. data/rakelib/lib/director/mdi_frame.rb +4 -1
  381. data/rakelib/lib/director/media_ctrl.rb +4 -1
  382. data/rakelib/lib/director/menu.rb +16 -3
  383. data/rakelib/lib/director/menu_bar.rb +13 -2
  384. data/rakelib/lib/director/menu_item.rb +6 -6
  385. data/rakelib/lib/director/mouse_state.rb +5 -2
  386. data/rakelib/lib/director/numeric_property_validator.rb +4 -1
  387. data/rakelib/lib/director/object.rb +5 -2
  388. data/rakelib/lib/director/page_setup_dialog.rb +4 -1
  389. data/rakelib/lib/director/palette.rb +54 -2
  390. data/rakelib/lib/director/panel.rb +4 -1
  391. data/rakelib/lib/director/pen.rb +5 -2
  392. data/rakelib/lib/director/pgarray_editor_dialog.rb +4 -1
  393. data/rakelib/lib/director/pgcell.rb +4 -1
  394. data/rakelib/lib/director/pgeditor.rb +4 -1
  395. data/rakelib/lib/director/pgmulti_button.rb +4 -1
  396. data/rakelib/lib/director/pgproperties.rb +4 -1
  397. data/rakelib/lib/director/pgproperty.rb +42 -3
  398. data/rakelib/lib/director/pgvalidation_info.rb +9 -1
  399. data/rakelib/lib/director/pickerbase.rb +4 -1
  400. data/rakelib/lib/director/platform_info.rb +9 -1
  401. data/rakelib/lib/director/popup_window.rb +14 -1
  402. data/rakelib/lib/director/preview_frame.rb +5 -2
  403. data/rakelib/lib/director/print_data.rb +4 -1
  404. data/rakelib/lib/director/print_dialog.rb +4 -1
  405. data/rakelib/lib/director/printer.rb +14 -6
  406. data/rakelib/lib/director/property_grid.rb +30 -1
  407. data/rakelib/lib/director/property_grid_event.rb +11 -1
  408. data/rakelib/lib/director/property_grid_interface.rb +20 -6
  409. data/rakelib/lib/director/property_grid_manager.rb +4 -1
  410. data/rakelib/lib/director/property_grid_page.rb +4 -1
  411. data/rakelib/lib/director/property_grid_page_state.rb +4 -1
  412. data/rakelib/lib/director/radio_box.rb +4 -1
  413. data/rakelib/lib/director/rearrange_list.rb +36 -0
  414. data/rakelib/lib/director/region.rb +5 -1
  415. data/rakelib/lib/director/region_iterator.rb +4 -1
  416. data/rakelib/lib/director/ribbon_art_provider.rb +9 -1
  417. data/rakelib/lib/director/ribbon_bar.rb +4 -1
  418. data/rakelib/lib/director/ribbon_bar_event.rb +4 -1
  419. data/rakelib/lib/director/ribbon_button_bar.rb +4 -1
  420. data/rakelib/lib/director/ribbon_button_bar_event.rb +4 -1
  421. data/rakelib/lib/director/ribbon_ctrl.rb +4 -1
  422. data/rakelib/lib/director/ribbon_gallery.rb +8 -3
  423. data/rakelib/lib/director/ribbon_gallery_event.rb +4 -1
  424. data/rakelib/lib/director/ribbon_page.rb +4 -1
  425. data/rakelib/lib/director/ribbon_panel.rb +4 -1
  426. data/rakelib/lib/director/ribbon_panel_event.rb +4 -1
  427. data/rakelib/lib/director/ribbon_tool_bar.rb +4 -1
  428. data/rakelib/lib/director/ribbon_tool_bar_event.rb +4 -1
  429. data/rakelib/lib/director/richtext_box.rb +61 -0
  430. data/rakelib/lib/director/richtext_buffer.rb +219 -22
  431. data/rakelib/lib/director/richtext_buffer_data_object.rb +4 -1
  432. data/rakelib/lib/director/richtext_composite_object.rb +174 -0
  433. data/rakelib/lib/director/richtext_ctrl.rb +157 -4
  434. data/rakelib/lib/director/richtext_event.rb +4 -1
  435. data/rakelib/lib/director/richtext_file_handler.rb +13 -1
  436. data/rakelib/lib/director/richtext_formatting_dialog.rb +44 -0
  437. data/rakelib/lib/director/richtext_header_footer_data.rb +4 -1
  438. data/rakelib/lib/director/richtext_image.rb +56 -0
  439. data/rakelib/lib/director/richtext_object.rb +272 -0
  440. data/rakelib/lib/director/richtext_paragraph_layout_box.rb +178 -0
  441. data/rakelib/lib/director/richtext_printing.rb +4 -1
  442. data/rakelib/lib/director/richtext_style_listbox.rb +37 -0
  443. data/rakelib/lib/director/richtext_style_organiser_dialog.rb +28 -0
  444. data/rakelib/lib/director/sash_layout_event.rb +4 -1
  445. data/rakelib/lib/director/sash_layout_window.rb +4 -1
  446. data/rakelib/lib/director/sash_window.rb +4 -1
  447. data/rakelib/lib/director/scroll_bar.rb +4 -1
  448. data/rakelib/lib/director/scrolled_t.rb +7 -4
  449. data/rakelib/lib/director/searchctrl.rb +4 -1
  450. data/rakelib/lib/director/sizer.rb +4 -1
  451. data/rakelib/lib/director/sizer_item.rb +9 -3
  452. data/rakelib/lib/director/slider.rb +4 -1
  453. data/rakelib/lib/director/splash_screen.rb +4 -1
  454. data/rakelib/lib/director/splitter_event.rb +4 -1
  455. data/rakelib/lib/director/splitter_window.rb +4 -1
  456. data/rakelib/lib/director/static_bitmap.rb +4 -1
  457. data/rakelib/lib/director/static_box.rb +5 -2
  458. data/rakelib/lib/director/status_bar.rb +5 -1
  459. data/rakelib/lib/director/styled_text_ctrl.rb +14 -2
  460. data/rakelib/lib/director/styled_text_event.rb +4 -1
  461. data/rakelib/lib/director/system_options.rb +4 -1
  462. data/rakelib/lib/director/system_settings.rb +4 -1
  463. data/rakelib/lib/director/task_bar_icon.rb +4 -1
  464. data/rakelib/lib/director/text_attr.rb +5 -2
  465. data/rakelib/lib/director/text_entry.rb +4 -1
  466. data/rakelib/lib/director/text_validator.rb +6 -1
  467. data/rakelib/lib/director/textctrl.rb +32 -3
  468. data/rakelib/lib/director/time_picker_ctrl.rb +4 -1
  469. data/rakelib/lib/director/timer.rb +4 -1
  470. data/rakelib/lib/director/tip_provider.rb +4 -1
  471. data/rakelib/lib/director/toggle_button.rb +4 -1
  472. data/rakelib/lib/director/tool_bar.rb +20 -1
  473. data/rakelib/lib/director/tool_tip.rb +5 -2
  474. data/rakelib/lib/director/top_level_window.rb +58 -51
  475. data/rakelib/lib/director/tree_ctrl.rb +5 -2
  476. data/rakelib/lib/director/tree_event.rb +28 -10
  477. data/rakelib/lib/director/uiaction_simulator.rb +4 -1
  478. data/rakelib/lib/director/utils.rb +9 -1
  479. data/rakelib/lib/director/validator.rb +4 -1
  480. data/rakelib/lib/director/variant.rb +5 -2
  481. data/rakelib/lib/director/vlistbox.rb +4 -1
  482. data/rakelib/lib/director/vscrolled_window.rb +4 -1
  483. data/rakelib/lib/director/window.rb +81 -82
  484. data/rakelib/lib/director/window_disabler.rb +4 -1
  485. data/rakelib/lib/director/with_images.rb +5 -2
  486. data/rakelib/lib/director/wizard_page.rb +4 -1
  487. data/rakelib/lib/director/xml_node.rb +4 -1
  488. data/rakelib/lib/director/xml_resource.rb +4 -1
  489. data/rakelib/lib/director.rb +27 -28
  490. data/rakelib/lib/ext/enum_chain.rb +4 -1
  491. data/rakelib/lib/extractor/class.rb +8 -6
  492. data/rakelib/lib/extractor/enum.rb +15 -2
  493. data/rakelib/lib/extractor/function.rb +12 -4
  494. data/rakelib/lib/extractor/module.rb +4 -1
  495. data/rakelib/lib/extractor/variable.rb +4 -1
  496. data/rakelib/lib/extractor.rb +7 -2
  497. data/rakelib/lib/generate/analyzer.rb +31 -21
  498. data/rakelib/lib/generate/base.rb +4 -1
  499. data/rakelib/lib/generate/doc/grid_cell_attr.yaml +21 -0
  500. data/rakelib/lib/generate/doc/grid_ctrl.yaml +25 -0
  501. data/rakelib/lib/generate/doc/html_cell.yaml +11 -0
  502. data/rakelib/lib/generate/doc/html_help_controller.yaml +23 -0
  503. data/rakelib/lib/generate/doc/html_help_window.yaml +21 -0
  504. data/rakelib/lib/generate/doc/html_window.yaml +47 -0
  505. data/rakelib/lib/generate/doc/pg_editor.yaml +11 -0
  506. data/rakelib/lib/generate/doc/pg_multi_button.yaml +78 -0
  507. data/rakelib/lib/generate/doc/pg_properties.yaml +244 -0
  508. data/rakelib/lib/generate/doc/pg_property.yaml +188 -0
  509. data/rakelib/lib/generate/doc/property_grid.yaml +23 -0
  510. data/rakelib/lib/generate/doc/property_grid_interface.yaml +30 -0
  511. data/rakelib/lib/generate/doc/property_grid_manager.yaml +40 -0
  512. data/rakelib/lib/generate/doc/rich_text_html_handler.yaml +11 -0
  513. data/rakelib/lib/generate/doc/styled_text_ctrl.yaml +18 -0
  514. data/rakelib/lib/generate/doc/symbol_picker_dialog.yaml +40 -0
  515. data/rakelib/lib/generate/doc.rb +19 -3
  516. data/rakelib/lib/generate/interface.rb +79 -110
  517. data/rakelib/lib/generate/rakedep.rb +4 -1
  518. data/rakelib/lib/specs/interfaces.rb +45 -20
  519. data/rakelib/lib/streams.rb +5 -1
  520. data/rakelib/lib/swig_runner.rb +34 -22
  521. data/rakelib/lib/typemap/array_int_selections.rb +4 -1
  522. data/rakelib/lib/typemap/common.rb +57 -2
  523. data/rakelib/lib/typemap/config.rb +55 -0
  524. data/rakelib/lib/typemap/data_format.rb +4 -1
  525. data/rakelib/lib/typemap/data_object_data.rb +4 -1
  526. data/rakelib/lib/typemap/datetime.rb +8 -1
  527. data/rakelib/lib/typemap/grid_client_data.rb +4 -1
  528. data/rakelib/lib/typemap/grid_coords.rb +37 -7
  529. data/rakelib/lib/typemap/html_cell.rb +4 -1
  530. data/rakelib/lib/typemap/io_streams.rb +4 -1
  531. data/rakelib/lib/typemap/pgcell.rb +4 -1
  532. data/rakelib/lib/typemap/pgeditor.rb +4 -1
  533. data/rakelib/lib/typemap/pgprop_arg.rb +4 -1
  534. data/rakelib/lib/typemap/pgproperty.rb +4 -1
  535. data/rakelib/lib/typemap/points_list.rb +4 -1
  536. data/rakelib/lib/typemap/richtext.rb +185 -11
  537. data/rakelib/lib/typemap/tree_itemid.rb +26 -1
  538. data/rakelib/lib/util/string.rb +4 -1
  539. data/rakelib/prepost.rake +4 -1
  540. data/rakelib/prepost.rb +4 -1
  541. data/rakelib/run.rake +4 -1
  542. data/samples/aui/aui.rb +8 -3
  543. data/samples/bigdemo/bigdemo.rb +9 -2
  544. data/samples/bigdemo/run.rb +9 -2
  545. data/samples/bigdemo/utils.rb +9 -1
  546. data/samples/calendar/calendar.rb +9 -4
  547. data/samples/caret/caret.rb +8 -3
  548. data/samples/controls/books.rb +8 -2
  549. data/samples/controls/controls.rb +33 -77
  550. data/samples/controls/get_item_sample.rb +8 -2
  551. data/samples/controls/htlbox.rb +10 -3
  552. data/samples/dialogs/dialogs.rb +9 -4
  553. data/samples/dialogs/wizard.rb +8 -3
  554. data/samples/dragdrop/dragdrop.rb +8 -3
  555. data/samples/drawing/bitmap.rb +8 -3
  556. data/samples/drawing/bitmap_image.rb +8 -3
  557. data/samples/drawing/graphics_drawing.rb +44 -33
  558. data/samples/drawing/image_prt.rb +8 -2
  559. data/samples/drawing/maths_images.rb +8 -3
  560. data/samples/drawing/rmagic_bitmap_image.rb +8 -3
  561. data/samples/etc/choice.rb +8 -3
  562. data/samples/etc/miniframe.rb +8 -3
  563. data/samples/etc/sash.rb +8 -3
  564. data/samples/etc/scrollwin.rb +8 -3
  565. data/samples/etc/system_settings.rb +8 -3
  566. data/samples/event/activation.rb +8 -3
  567. data/samples/event/event.rb +8 -3
  568. data/samples/event/threaded.rb +8 -3
  569. data/samples/event/update_ui_event.rb +8 -3
  570. data/samples/grid/grid.rb +9 -3
  571. data/samples/grid/gridtablebase.rb +8 -3
  572. data/samples/html/html.rb +8 -3
  573. data/samples/mdi/mdi.rb +8 -3
  574. data/samples/minimal/minimal.rb +8 -3
  575. data/samples/minimal/nothing.rb +8 -3
  576. data/samples/printing/printing.rb +8 -3
  577. data/samples/printing/printing2.rb +8 -2
  578. data/samples/propgrid/propgrid.rb +4 -1
  579. data/samples/propgrid/propgrid_minimal.rb +4 -2
  580. data/samples/propgrid/sample_props.rb +4 -1
  581. data/samples/ribbon/ribbon.rb +4 -1
  582. data/samples/sampler/editor.rb +4 -1
  583. data/samples/sampler/ext.rb +4 -1
  584. data/samples/sampler/sample.rb +13 -4
  585. data/samples/sampler/stc_editor.rb +4 -1
  586. data/samples/sampler/txt_editor.rb +4 -1
  587. data/samples/sampler.rb +11 -3
  588. data/samples/splash/splash.rb +4 -2
  589. data/samples/text/art/richtext/alignleft.xpm +24 -0
  590. data/samples/text/art/richtext/alignright.xpm +24 -0
  591. data/samples/text/art/richtext/bold.xpm +24 -0
  592. data/samples/text/art/richtext/centre.xpm +24 -0
  593. data/samples/text/art/richtext/copy.xpm +45 -0
  594. data/samples/text/art/richtext/cut.xpm +47 -0
  595. data/samples/text/art/richtext/font.xpm +25 -0
  596. data/samples/text/art/richtext/idea.xpm +47 -0
  597. data/samples/text/art/richtext/indentless.xpm +25 -0
  598. data/samples/text/art/richtext/indentmore.xpm +25 -0
  599. data/samples/text/art/richtext/italic.xpm +25 -0
  600. data/samples/text/art/richtext/open.xpm +58 -0
  601. data/samples/text/art/richtext/paste.xpm +47 -0
  602. data/samples/text/art/richtext/redo.xpm +59 -0
  603. data/samples/text/art/richtext/save.xpm +43 -0
  604. data/samples/text/art/richtext/smiley.xpm +42 -0
  605. data/samples/text/art/richtext/underline.xpm +25 -0
  606. data/samples/text/art/richtext/undo.xpm +59 -0
  607. data/samples/text/art/richtext/zebra.xpm +409 -0
  608. data/samples/text/rich_textctrl.rb +8 -3
  609. data/samples/text/richtext.rb +1824 -0
  610. data/samples/text/scintilla.rb +8 -3
  611. data/samples/text/textctrl.rb +21 -4
  612. data/samples/text/tn_richtext.png +0 -0
  613. data/samples/text/unicode.rb +9 -4
  614. data/samples/treectrl/treectrl.rb +10 -5
  615. data/samples/xrc/custom_xrc_sample.rb +8 -3
  616. data/samples/xrc/xrc_sample.rb +8 -3
  617. data/tests/art/test_art/bitmap/wxruby-128x128.png +0 -0
  618. data/tests/art/test_art/bitmap/wxruby-256x256.png +0 -0
  619. data/tests/art/test_art/bitmap/wxruby-64x64.png +0 -0
  620. data/tests/lib/item_container_tests.rb +3 -0
  621. data/tests/lib/text_entry_tests.rb +3 -0
  622. data/tests/lib/wxapp_runner.rb +3 -0
  623. data/tests/lib/wxframe_runner.rb +81 -3
  624. data/tests/test_app_event_filter.rb +3 -0
  625. data/tests/test_app_traits.rb +33 -0
  626. data/tests/test_art.rb +22 -0
  627. data/tests/test_art_provider.rb +3 -0
  628. data/tests/test_aui.rb +65 -0
  629. data/tests/test_basic.rb +5 -1
  630. data/tests/test_box_sizer.rb +5 -2
  631. data/tests/test_clipboard.rb +3 -0
  632. data/tests/test_config.rb +150 -0
  633. data/tests/test_dc.rb +3 -0
  634. data/tests/test_dialog.rb +3 -0
  635. data/tests/test_event_handling.rb +3 -0
  636. data/tests/test_events.rb +3 -0
  637. data/tests/test_ext_controls.rb +286 -3
  638. data/tests/test_file_dialog.rb +55 -0
  639. data/tests/test_font.rb +8 -5
  640. data/tests/test_gdi_object.rb +3 -0
  641. data/tests/test_geometry.rb +4 -0
  642. data/tests/test_grid_sizer.rb +7 -4
  643. data/tests/test_intl.rb +3 -0
  644. data/tests/test_item_data.rb +3 -0
  645. data/tests/test_list_ctrl.rb +4 -1
  646. data/tests/test_log.rb +63 -0
  647. data/tests/test_proof_check.rb +52 -0
  648. data/tests/test_richtext.rb +204 -0
  649. data/tests/test_std_controls.rb +45 -35
  650. data/tests/test_timer.rb +3 -0
  651. data/tests/test_variant.rb +3 -0
  652. data/tests/test_window.rb +10 -8
  653. data/tests/testapp.rb +4 -0
  654. data/tests/testapp_noframe.rb +4 -0
  655. metadata +89 -3
  656. data/rakelib/lib/director/html_help_frame.rb +0 -25
@@ -0,0 +1,1824 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+ #
5
+ # Adapted for wxRuby from wxWidgets richtext sample
6
+ # Copyright (c) Julian Smart
7
+
8
+ require 'wx'
9
+ require 'stringio'
10
+
11
+ # A custom field type
12
+ class RichTextFieldTypePropertiesTest < Wx::RTC::RichTextFieldTypeStandard
13
+
14
+ def initialize(name, label_or_bmp, displayStyle = Wx::RTC::RICHTEXT_FIELD_STYLE_RECTANGLE)
15
+ super(name, label_or_bmp, displayStyle)
16
+ end
17
+
18
+ def can_edit_properties(_obj); true; end
19
+
20
+ def edit_properties(_obj, _parent, _buffer)
21
+ label = get_label
22
+ Wx.message_box("Editing #{label}")
23
+ true
24
+ end
25
+
26
+ def get_properties_menu_label(_obj)
27
+ get_label
28
+ end
29
+
30
+ end
31
+
32
+ # A custom composite field type
33
+ class RichTextFieldTypeCompositeTest < RichTextFieldTypePropertiesTest
34
+
35
+ def initialize(name, label)
36
+ super(name, label, Wx::RTC::RICHTEXT_FIELD_STYLE_COMPOSITE)
37
+ end
38
+
39
+ def update_field(buffer, obj)
40
+ if buffer
41
+ attr = Wx::RTC::RichTextAttr.new(buffer.get_attributes)
42
+ attr.get_text_box_attr.reset
43
+ attr.set_paragraph_spacing_after(0)
44
+ attr.set_line_spacing(10)
45
+ obj.set_attributes(attr)
46
+ end
47
+ obj.delete_children
48
+ para = Wx::RTC::RichTextParagraph.new
49
+ text = Wx::RTC::RichTextPlainText.new(get_label)
50
+ para.append_child(text)
51
+ obj.append_child(para)
52
+ true
53
+ end
54
+
55
+ end
56
+
57
+ # ----------------------------------------------------------------------------
58
+ # private classes
59
+ # ----------------------------------------------------------------------------
60
+
61
+
62
+ class RichTextEnhancedDrawingHandler < Wx::RTC::RichTextDrawingHandler
63
+
64
+ def initialize(name = nil)
65
+ super("enhanceddrawing")
66
+ @lockBackgroundColour = Wx::Colour.new(220, 220, 220)
67
+ end
68
+
69
+ # Returns @true if this object has virtual attributes that we can provide.
70
+ def has_virtual_attributes(obj)
71
+ obj.get_properties.has_property("Lock")
72
+ end
73
+
74
+ # Provides virtual attributes that we can provide.
75
+ def get_virtual_attributes(attr, obj)
76
+ if obj.get_properties.has_property("Lock")
77
+ attr.set_background_colour(@lockBackgroundColour)
78
+ true
79
+ else
80
+ false
81
+ end
82
+ end
83
+
84
+ # Gets the count for mixed virtual attributes for individual positions within the object.
85
+ # For example, individual characters within a text object may require special highlighting.
86
+ def get_virtual_subobject_attributes_count(_obj); 0; end
87
+
88
+ # Gets the mixed virtual attributes for individual positions within the object.
89
+ # For example, individual characters within a text object may require special highlighting.
90
+ # Returns the number of virtual attributes found.
91
+ def get_virtual_subobject_attributes(_obj, _positions, _attributes); 0; end
92
+
93
+ # Do we have virtual text for this object? Virtual text allows an application
94
+ # to replace characters in an object for editing and display purposes, for example
95
+ # for highlighting special characters.
96
+ def has_virtual_text(_obj); false; end
97
+
98
+ # Gets the virtual text for this object.
99
+ def get_virtual_text(_obj, _text); false; end
100
+
101
+ end
102
+
103
+ # Define a new application type, each program should derive a class from wxApp
104
+ class MyRichTextCtrl < Wx::RTC::RichTextCtrl
105
+
106
+ def initialize(parent, id: Wx::ID_ANY, value: '', pos: Wx::DEFAULT_POSITION, size: Wx::DEFAULT_SIZE,
107
+ style: Wx::RTC::RE_MULTILINE, validator: Wx::DEFAULT_VALIDATOR, name: 'myRichTextCtrl')
108
+ super(parent, id: id, value: value, pos: pos, size: size, style: style, validator: validator, name: name)
109
+ @lockId = 0
110
+ @locked = false
111
+ end
112
+
113
+ attr_accessor :lockId
114
+
115
+ def begin_lock; @lockId += 1; @locked = true; end
116
+ def end_lock; @locked = false; end
117
+ def is_locked?; @locked; end
118
+
119
+ def self.set_enhanced_drawing_handler
120
+ Wx::RTC::RichTextBuffer::add_drawing_handler(RichTextEnhancedDrawingHandler.new)
121
+ end
122
+
123
+ # Prepares the content just before insertion (or after buffer reset). Called by the same function in wxRichTextBuffer.
124
+ # Currently is only called if undo mode is on.
125
+ def prepare_content(container)
126
+ if is_locked?
127
+ # Lock all content that's about to be added to the control
128
+ container.get_children.each do |child|
129
+ if child.is_a?(Wx::RTC::RichTextParagraph)
130
+ child.get_children.each do |obj|
131
+ obj.get_properties.set_property("Lock", @lockId)
132
+ end
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ # Can we delete this range?
139
+ # Sends an event to the control.
140
+ def can_delete_range(container, range)
141
+ Range.new(range.begin, range.end, true).each do |i|
142
+ obj = container.get_leaf_object_at_position(i)
143
+ return false if obj && obj.get_properties.has_property("Lock")
144
+ end
145
+ true
146
+ end
147
+
148
+ # Can we insert content at this position?
149
+ # Sends an event to the control.
150
+ def can_insert_content(container, pos)
151
+ child1 = container.get_leaf_object_at_position(pos)
152
+ child2 = container.get_leaf_object_at_position(pos-1)
153
+
154
+ lock1 = lock2 = -1
155
+
156
+ if child1 && child1.get_properties.has_property("Lock")
157
+ lock1 = child1.get_properties.get_property_long("Lock")
158
+ end
159
+ if child2 && child2.get_properties.has_property("Lock")
160
+ lock2 = child2.get_properties.get_property_long("Lock")
161
+ end
162
+
163
+ return false if lock1 != -1 && lock1 == lock2
164
+
165
+ # Don't allow insertion before a locked object if it's at the beginning of the buffer.
166
+ return false if pos == 0 && lock1 != -1
167
+
168
+ true
169
+ end
170
+
171
+ # Finds a table, either selected or near the cursor
172
+ def find_table
173
+ obj = find_current_position
174
+
175
+ # It could be a table or a cell (or neither)
176
+ if obj.is_a?(Wx::RTC::RichTextTable)
177
+ return obj
178
+ end
179
+
180
+ while obj
181
+ obj = obj.get_parent
182
+ if obj.is_a?(Wx::RTC::RichTextTable)
183
+ return obj
184
+ end
185
+ end
186
+
187
+ nil
188
+ end
189
+
190
+ # Helper for FindTable()
191
+ def find_current_position
192
+ position = -1
193
+
194
+ if has_selection # First see if there's a selection
195
+ range = get_selection_range
196
+ if (range.size-1) == 1
197
+ position = range.begin
198
+ end
199
+ end
200
+ if position == -1 # Failing that, near cursor
201
+ position = get_adjusted_caret_position(get_caret_position)
202
+ end
203
+
204
+ get_focus_object.get_leaf_object_at_position(position)
205
+ end
206
+
207
+ end
208
+
209
+ # Define a new application type
210
+ class MyApp < Wx::App
211
+
212
+ def initialize
213
+ super
214
+ @styleSheet = nil
215
+ @printing =nil
216
+ end
217
+
218
+ # override base class virtuals
219
+ # ----------------------------
220
+
221
+ # this one is called on application startup and is a good place for the app
222
+ # initialization (doing it here and not in the ctor allows to have an error
223
+ # return: if on_init() returns false, the application terminates)
224
+ def on_init
225
+
226
+ if Wx.has_feature?(:USE_HELP)
227
+ Wx::HelpProvider.set(Wx::SimpleHelpProvider.new)
228
+ end
229
+
230
+ @styleSheet = Wx::RTC::RichTextStyleSheet.new
231
+ if Wx.has_feature?(:USE_PRINTING_ARCHITECTURE)
232
+ @printing = Wx::RTC::RichTextPrinting.new("Test Document")
233
+
234
+ @printing.set_footer_text("@TITLE@", Wx::RTC::RICHTEXT_PAGE_ALL, Wx::RTC::RICHTEXT_PAGE_CENTRE)
235
+ @printing.set_footer_text("Page @PAGENUM@", Wx::RTC::RICHTEXT_PAGE_ALL, Wx::RTC::RICHTEXT_PAGE_RIGHT)
236
+ end
237
+
238
+ create_styles
239
+
240
+ MyRichTextCtrl.set_enhanced_drawing_handler
241
+
242
+ # Add extra handlers (plain text is automatically added)
243
+ Wx::RTC::RichTextBuffer.add_handler(Wx::RTC::RichTextXMLHandler.new)
244
+ Wx::RTC::RichTextBuffer.add_handler(Wx::RTC::RichTextHTMLHandler.new)
245
+
246
+ # Add field types
247
+
248
+ Wx::RTC::RichTextBuffer.add_field_type(RichTextFieldTypePropertiesTest.new("rectangle", "RECTANGLE", Wx::RTC::RichTextFieldTypeStandard::RICHTEXT_FIELD_STYLE_RECTANGLE))
249
+
250
+ s1 = Wx::RTC::RichTextFieldTypeStandard.new("begin-section", "SECTION", Wx::RTC::RichTextFieldTypeStandard::RICHTEXT_FIELD_STYLE_START_TAG)
251
+ s1.set_background_colour(Wx::BLUE)
252
+
253
+ s2 = Wx::RTC::RichTextFieldTypeStandard.new("end-section", "SECTION", Wx::RTC::RichTextFieldTypeStandard::RICHTEXT_FIELD_STYLE_END_TAG)
254
+ s2.set_background_colour(Wx::BLUE)
255
+
256
+ s3 = Wx::RTC::RichTextFieldTypeStandard.new("bitmap", Wx.Bitmap(:paste), Wx::RTC::RichTextFieldTypeStandard::RICHTEXT_FIELD_STYLE_NO_BORDER)
257
+
258
+ Wx::RTC::RichTextBuffer.add_field_type(s1)
259
+ Wx::RTC::RichTextBuffer.add_field_type(s2)
260
+ Wx::RTC::RichTextBuffer.add_field_type(s3)
261
+
262
+ s4 = RichTextFieldTypeCompositeTest.new("composite", "This is a field value")
263
+ Wx::RTC::RichTextBuffer.add_field_type(s4)
264
+
265
+ if Wx.has_feature? :USE_FILESYSTEM
266
+ Wx::FileSystem.add_handler(Wx::MemoryFSHandler.new)
267
+ end
268
+
269
+ # create the main application window
270
+ size = Wx.get_display_size
271
+ size.scale(0.75, 0.75)
272
+ frame = MyFrame.new("Wx::RTC::RichTextCtrl Sample", size: size)
273
+
274
+ if Wx.has_feature?(:USE_PRINTING_ARCHITECTURE)
275
+ @printing.set_parent_window(frame)
276
+ end
277
+
278
+ # and show it (the frames, unlike simple controls, are not shown when
279
+ # created initially)
280
+ frame.show(true)
281
+
282
+ # success: wxApp::OnRun() will be called which will enter the main message
283
+ # loop and the application will run. If we returned false here, the
284
+ # application would exit immediately.
285
+ true
286
+ end
287
+
288
+ def create_styles
289
+ # Paragraph styles
290
+
291
+ romanFont = Wx::Font.new(Wx::FontInfo.new(12).family(Wx::FONTFAMILY_ROMAN))
292
+ swissFont = Wx::Font.new(Wx::FontInfo.new(12).family(Wx::FONTFAMILY_SWISS))
293
+
294
+ normalPara = Wx::RTC::RichTextParagraphStyleDefinition.new("Normal")
295
+ normalAttr = Wx::RTC::RichTextAttr.new
296
+ normalAttr.set_font_face_name(romanFont.get_face_name)
297
+ normalAttr.set_font_size(12)
298
+ # Let's set all attributes for this style
299
+ normalAttr.set_flags(Wx::TEXT_ATTR_FONT | Wx::TEXT_ATTR_BACKGROUND_COLOUR | Wx::TEXT_ATTR_TEXT_COLOUR|Wx::TEXT_ATTR_ALIGNMENT|Wx::TEXT_ATTR_LEFT_INDENT|Wx::TEXT_ATTR_RIGHT_INDENT|Wx::TEXT_ATTR_TABS|
300
+ Wx::TEXT_ATTR_PARA_SPACING_BEFORE|Wx::TEXT_ATTR_PARA_SPACING_AFTER|Wx::TEXT_ATTR_LINE_SPACING|
301
+ Wx::TEXT_ATTR_BULLET_STYLE|Wx::TEXT_ATTR_BULLET_NUMBER)
302
+ normalPara.set_style(normalAttr)
303
+
304
+ @styleSheet.add_paragraph_style(normalPara)
305
+
306
+ indentedPara = Wx::RTC::RichTextParagraphStyleDefinition.new("Indented")
307
+ indentedAttr = Wx::RTC::RichTextAttr.new
308
+ indentedAttr.set_font_face_name(romanFont.get_face_name)
309
+ indentedAttr.set_font_size(12)
310
+ indentedAttr.set_left_indent(100, 0)
311
+ # We only want to affect indentation
312
+ indentedAttr.set_flags(Wx::TEXT_ATTR_LEFT_INDENT|Wx::TEXT_ATTR_RIGHT_INDENT)
313
+ indentedPara.set_style(indentedAttr)
314
+
315
+ @styleSheet.add_paragraph_style(indentedPara)
316
+
317
+ indentedPara2 = Wx::RTC::RichTextParagraphStyleDefinition.new("Red Bold Indented")
318
+ indentedAttr2 = Wx::RTC::RichTextAttr.new
319
+ indentedAttr2.set_font_face_name(romanFont.get_face_name)
320
+ indentedAttr2.set_font_size(12)
321
+ indentedAttr2.set_font_weight(Wx::FONTWEIGHT_BOLD)
322
+ indentedAttr2.set_text_colour(Wx::RED)
323
+ indentedAttr2.set_font_size(12)
324
+ indentedAttr2.set_left_indent(100, 0)
325
+ # We want to affect indentation, font and text colour
326
+ indentedAttr2.set_flags(Wx::TEXT_ATTR_LEFT_INDENT|Wx::TEXT_ATTR_RIGHT_INDENT|Wx::TEXT_ATTR_FONT|Wx::TEXT_ATTR_TEXT_COLOUR)
327
+ indentedPara2.set_style(indentedAttr2)
328
+
329
+ @styleSheet.add_paragraph_style(indentedPara2)
330
+
331
+ flIndentedPara = Wx::RTC::RichTextParagraphStyleDefinition.new("First Line Indented")
332
+ flIndentedAttr = Wx::RTC::RichTextAttr.new
333
+ flIndentedAttr.set_font_face_name(swissFont.get_face_name)
334
+ flIndentedAttr.set_font_size(12)
335
+ flIndentedAttr.set_left_indent(100, -100)
336
+ # We only want to affect indentation
337
+ flIndentedAttr.set_flags(Wx::TEXT_ATTR_LEFT_INDENT|Wx::TEXT_ATTR_RIGHT_INDENT)
338
+ flIndentedPara.set_style(flIndentedAttr)
339
+
340
+ @styleSheet.add_paragraph_style(flIndentedPara)
341
+
342
+ # Character styles
343
+
344
+ boldDef = Wx::RTC::RichTextCharacterStyleDefinition.new("Bold")
345
+ boldAttr = Wx::RTC::RichTextAttr.new
346
+ boldAttr.set_font_face_name(romanFont.get_face_name)
347
+ boldAttr.set_font_size(12)
348
+ boldAttr.set_font_weight(Wx::FONTWEIGHT_BOLD)
349
+ # We only want to affect boldness
350
+ boldAttr.set_flags(Wx::TEXT_ATTR_FONT_WEIGHT)
351
+ boldDef.set_style(boldAttr)
352
+
353
+ @styleSheet.add_character_style(boldDef)
354
+
355
+ italicDef = Wx::RTC::RichTextCharacterStyleDefinition.new("Italic")
356
+ italicAttr = Wx::RTC::RichTextAttr.new
357
+ italicAttr.set_font_face_name(romanFont.get_face_name)
358
+ italicAttr.set_font_size(12)
359
+ italicAttr.set_font_style(Wx::FONTSTYLE_ITALIC)
360
+ # We only want to affect italics
361
+ italicAttr.set_flags(Wx::TEXT_ATTR_FONT_ITALIC)
362
+ italicDef.set_style(italicAttr)
363
+
364
+ @styleSheet.add_character_style(italicDef)
365
+
366
+ redDef = Wx::RTC::RichTextCharacterStyleDefinition.new("Red Bold")
367
+ redAttr = Wx::RTC::RichTextAttr.new
368
+ redAttr.set_font_face_name(romanFont.get_face_name)
369
+ redAttr.set_font_size(12)
370
+ redAttr.set_font_weight(Wx::FONTWEIGHT_BOLD)
371
+ redAttr.set_text_colour(Wx::RED)
372
+ # We only want to affect colour, weight and face
373
+ redAttr.set_flags(Wx::TEXT_ATTR_FONT_FACE|Wx::TEXT_ATTR_FONT_WEIGHT|Wx::TEXT_ATTR_TEXT_COLOUR)
374
+ redDef.set_style(redAttr)
375
+
376
+ @styleSheet.add_character_style(redDef)
377
+
378
+ bulletList = Wx::RTC::RichTextListStyleDefinition.new("Bullet List 1")
379
+ 10.times do |i|
380
+ if i == 0
381
+ bulletText = "standard/circle"
382
+ elsif i == 1
383
+ bulletText = "standard/square"
384
+ elsif i == 2
385
+ bulletText = "standard/circle"
386
+ elsif i == 3
387
+ bulletText = "standard/square"
388
+ else
389
+ bulletText = "standard/circle"
390
+ end
391
+ bulletList.set_attributes(i, (i+1)*60, 60, Wx::TEXT_ATTR_BULLET_STYLE_STANDARD, bulletText)
392
+ end
393
+
394
+ @styleSheet.add_list_style(bulletList)
395
+
396
+ numberedList = Wx::RTC::RichTextListStyleDefinition.new("Numbered List 1")
397
+ 10.times do |i|
398
+ if i == 0
399
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_ARABIC|Wx::TEXT_ATTR_BULLET_STYLE_PERIOD
400
+ elsif i == 1
401
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_LETTERS_LOWER|Wx::TEXT_ATTR_BULLET_STYLE_PARENTHESES
402
+ elsif i == 2
403
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_ROMAN_LOWER|Wx::TEXT_ATTR_BULLET_STYLE_PARENTHESES
404
+ elsif i == 3
405
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_ROMAN_UPPER|Wx::TEXT_ATTR_BULLET_STYLE_PARENTHESES
406
+ else
407
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_ARABIC|Wx::TEXT_ATTR_BULLET_STYLE_PERIOD
408
+ end
409
+
410
+ numberStyle |= Wx::TEXT_ATTR_BULLET_STYLE_ALIGN_RIGHT
411
+
412
+ numberedList.set_attributes(i, (i+1)*60, 60, numberStyle)
413
+ end
414
+
415
+ @styleSheet.add_list_style(numberedList)
416
+
417
+ outlineList = Wx::RTC::RichTextListStyleDefinition.new("Outline List 1")
418
+ 10.times do |i|
419
+ if i < 4
420
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_OUTLINE|Wx::TEXT_ATTR_BULLET_STYLE_PERIOD
421
+ else
422
+ numberStyle = Wx::TEXT_ATTR_BULLET_STYLE_ARABIC|Wx::TEXT_ATTR_BULLET_STYLE_PERIOD
423
+ end
424
+
425
+ outlineList.set_attributes(i, (i+1)*120, 120, numberStyle)
426
+ end
427
+
428
+ @styleSheet.add_list_style(outlineList)
429
+ end
430
+
431
+ def get_style_sheet
432
+ @styleSheet
433
+ end
434
+
435
+ if Wx.has_feature?(:USE_PRINTING_ARCHITECTURE)
436
+
437
+ def get_printing
438
+ @printing
439
+ end
440
+
441
+ end
442
+ end
443
+
444
+
445
+ # Define a new frame type: this is going to be our main frame
446
+ class MyFrame < Wx::Frame
447
+
448
+ # IDs for the controls and the menu commands
449
+ module ID
450
+ include Wx::IDHelper
451
+
452
+ # menu items
453
+ Quit = Wx::ID_EXIT
454
+ About = Wx::ID_ABOUT
455
+
456
+ FORMAT_BOLD = self.next_id
457
+ FORMAT_ITALIC = self.next_id
458
+ FORMAT_UNDERLINE = self.next_id
459
+ FORMAT_STRIKETHROUGH = self.next_id
460
+ FORMAT_SUPERSCRIPT = self.next_id
461
+ FORMAT_SUBSCRIPT = self.next_id
462
+ FORMAT_FONT = self.next_id
463
+ FORMAT_IMAGE = self.next_id
464
+ FORMAT_PARAGRAPH = self.next_id
465
+ FORMAT_CONTENT = self.next_id
466
+
467
+ RELOAD = self.next_id
468
+
469
+ INSERT_SYMBOL = self.next_id
470
+ INSERT_URL = self.next_id
471
+ INSERT_IMAGE = self.next_id
472
+
473
+ FORMAT_ALIGN_LEFT = self.next_id
474
+ FORMAT_ALIGN_CENTRE = self.next_id
475
+ FORMAT_ALIGN_RIGHT = self.next_id
476
+
477
+ FORMAT_INDENT_MORE = self.next_id
478
+ FORMAT_INDENT_LESS = self.next_id
479
+
480
+ FORMAT_PARAGRAPH_SPACING_MORE = self.next_id
481
+ FORMAT_PARAGRAPH_SPACING_LESS = self.next_id
482
+
483
+ FORMAT_LINE_SPACING_HALF = self.next_id
484
+ FORMAT_LINE_SPACING_DOUBLE = self.next_id
485
+ FORMAT_LINE_SPACING_SINGLE = self.next_id
486
+
487
+ FORMAT_NUMBER_LIST = self.next_id
488
+ FORMAT_BULLETS_AND_NUMBERING = self.next_id
489
+ FORMAT_ITEMIZE_LIST = self.next_id
490
+ FORMAT_RENUMBER_LIST = self.next_id
491
+ FORMAT_PROMOTE_LIST = self.next_id
492
+ FORMAT_DEMOTE_LIST = self.next_id
493
+ FORMAT_CLEAR_LIST = self.next_id
494
+
495
+ TABLE_ADD_COLUMN = self.next_id
496
+ TABLE_ADD_ROW = self.next_id
497
+ TABLE_DELETE_COLUMN = self.next_id
498
+ TABLE_DELETE_ROW = self.next_id
499
+
500
+ SET_FONT_SCALE = self.next_id
501
+ SET_DIMENSION_SCALE = self.next_id
502
+
503
+ VIEW_HTML = self.next_id
504
+ SWITCH_STYLE_SHEETS = self.next_id
505
+ MANAGE_STYLES = self.next_id
506
+
507
+ PRINT = self.next_id
508
+ PREVIEW = self.next_id
509
+ PAGE_SETUP = self.next_id
510
+
511
+ RICHTEXT_CTRL = self.next_id
512
+ RICHTEXT_STYLE_LIST = self.next_id
513
+ RICHTEXT_STYLE_COMBO = self.next_id
514
+ end
515
+
516
+ # ctor(s)
517
+ def initialize(title, id: Wx::ID_ANY, pos: Wx::DEFAULT_POSITION, size: Wx::DEFAULT_SIZE, style: Wx::DEFAULT_FRAME_STYLE)
518
+ super(nil, id: id, pos: pos, size: size, style: style)
519
+
520
+ @richTextCtrl = nil
521
+
522
+ if Wx::PLATFORM == 'WXMAC'
523
+ set_window_variant(Wx::WINDOW_VARIANT_SMALL)
524
+ end
525
+
526
+ self.icon = Wx::Icon.new(local_icon_file('../sample.xpm'))
527
+
528
+ # create a menu bar
529
+ fileMenu = Wx::Menu.new
530
+
531
+ # the "About" item should be in the help menu
532
+ helpMenu = Wx::Menu.new
533
+ helpMenu.append(ID::About, "&About\tF1", "Show about dialog")
534
+
535
+ fileMenu.append(Wx::ID_OPEN, "&Open\tCtrl+O", "Open a file")
536
+ fileMenu.append(Wx::ID_SAVE, "&Save\tCtrl+S", "Save a file")
537
+ fileMenu.append(Wx::ID_SAVEAS, "&Save As...\tF12", "Save to a new file")
538
+ fileMenu.append_separator
539
+ fileMenu.append(ID::RELOAD, "&Reload Text\tF2", "Reload the initial text")
540
+ fileMenu.append_separator
541
+ fileMenu.append(ID::PAGE_SETUP, "Page Set&up...", "Page setup")
542
+
543
+ if Wx.has_feature? :USE_PRINTING_ARCHITECTURE
544
+ fileMenu.append(ID::PRINT, "&Print...\tCtrl+P", "Print")
545
+ fileMenu.append(ID::PREVIEW, "Print Pre&view", "Print preview")
546
+ end
547
+
548
+ fileMenu.append_separator
549
+ fileMenu.append(ID::VIEW_HTML, "&View as HTML", "View HTML")
550
+ fileMenu.append_separator
551
+ fileMenu.append(ID::Quit, "E&xit\tAlt+X", "Quit this program")
552
+
553
+ editMenu = Wx::Menu.new
554
+ editMenu.append(Wx::ID_UNDO, "&Undo\tCtrl+Z")
555
+ editMenu.append(Wx::ID_REDO, "&Redo\tCtrl+Y")
556
+ editMenu.append_separator
557
+ editMenu.append(Wx::ID_CUT, "Cu&t\tCtrl+X")
558
+ editMenu.append(Wx::ID_COPY, "&Copy\tCtrl+C")
559
+ editMenu.append(Wx::ID_PASTE, "&Paste\tCtrl+V")
560
+
561
+ editMenu.append_separator
562
+ editMenu.append(Wx::ID_SELECTALL, "Select A&ll\tCtrl+A")
563
+ editMenu.append_separator
564
+ editMenu.append(ID::SET_FONT_SCALE, "Set &Text Scale...")
565
+ editMenu.append(ID::SET_DIMENSION_SCALE, "Set &Dimension Scale...")
566
+
567
+ formatMenu = Wx::Menu.new
568
+ formatMenu.append_check_item(ID::FORMAT_BOLD, "&Bold\tCtrl+B")
569
+ formatMenu.append_check_item(ID::FORMAT_ITALIC, "&Italic\tCtrl+I")
570
+ formatMenu.append_check_item(ID::FORMAT_UNDERLINE, "&Underline\tCtrl+U")
571
+ formatMenu.append_separator
572
+ formatMenu.append_check_item(ID::FORMAT_STRIKETHROUGH, "Stri&kethrough")
573
+ formatMenu.append_check_item(ID::FORMAT_SUPERSCRIPT, "Superscrip&t")
574
+ formatMenu.append_check_item(ID::FORMAT_SUBSCRIPT, "Subscrip&t")
575
+ formatMenu.append_separator
576
+ formatMenu.append_check_item(ID::FORMAT_ALIGN_LEFT, "L&eft Align")
577
+ formatMenu.append_check_item(ID::FORMAT_ALIGN_RIGHT, "&Right Align")
578
+ formatMenu.append_check_item(ID::FORMAT_ALIGN_CENTRE, "&Centre")
579
+ formatMenu.append_separator
580
+ formatMenu.append(ID::FORMAT_INDENT_MORE, "Indent &More")
581
+ formatMenu.append(ID::FORMAT_INDENT_LESS, "Indent &Less")
582
+ formatMenu.append_separator
583
+ formatMenu.append(ID::FORMAT_PARAGRAPH_SPACING_MORE, "Increase Paragraph &Spacing")
584
+ formatMenu.append(ID::FORMAT_PARAGRAPH_SPACING_LESS, "Decrease &Paragraph Spacing")
585
+ formatMenu.append_separator
586
+ formatMenu.append(ID::FORMAT_LINE_SPACING_SINGLE, "Normal Line Spacing")
587
+ formatMenu.append(ID::FORMAT_LINE_SPACING_HALF, "1.5 Line Spacing")
588
+ formatMenu.append(ID::FORMAT_LINE_SPACING_DOUBLE, "Double Line Spacing")
589
+ formatMenu.append_separator
590
+ formatMenu.append(ID::FORMAT_FONT, "&Font...")
591
+ formatMenu.append(ID::FORMAT_IMAGE, "Image Property")
592
+ formatMenu.append(ID::FORMAT_PARAGRAPH, "&Paragraph...")
593
+ formatMenu.append(ID::FORMAT_CONTENT, "Font and Pa&ragraph...\tShift+Ctrl+F")
594
+ formatMenu.append_separator
595
+ formatMenu.append(ID::SWITCH_STYLE_SHEETS, "&Switch Style Sheets")
596
+ formatMenu.append(ID::MANAGE_STYLES, "&Manage Styles")
597
+
598
+ listsMenu = Wx::Menu.new
599
+ listsMenu.append(ID::FORMAT_BULLETS_AND_NUMBERING, "Bullets and &Numbering...")
600
+ listsMenu.append_separator
601
+ listsMenu.append(ID::FORMAT_NUMBER_LIST, "Number List")
602
+ listsMenu.append(ID::FORMAT_ITEMIZE_LIST, "Itemize List")
603
+ listsMenu.append(ID::FORMAT_RENUMBER_LIST, "Renumber List")
604
+ listsMenu.append(ID::FORMAT_PROMOTE_LIST, "Promote List Items")
605
+ listsMenu.append(ID::FORMAT_DEMOTE_LIST, "Demote List Items")
606
+ listsMenu.append(ID::FORMAT_CLEAR_LIST, "Clear List Formatting")
607
+
608
+ tableMenu = Wx::Menu.new
609
+ tableMenu.append(ID::TABLE_ADD_COLUMN, "&Add Column")
610
+ tableMenu.append(ID::TABLE_ADD_ROW, "Add &Row")
611
+ tableMenu.append(ID::TABLE_DELETE_COLUMN, "Delete &Column")
612
+ tableMenu.append(ID::TABLE_DELETE_ROW, "&Delete Row")
613
+
614
+ insertMenu = Wx::Menu.new
615
+ insertMenu.append(ID::INSERT_SYMBOL, "&Symbol...\tCtrl+I")
616
+ insertMenu.append(ID::INSERT_URL, "&URL...")
617
+ insertMenu.append(ID::INSERT_IMAGE, "&Image...")
618
+
619
+ # now append the freshly created menu to the menu bar...
620
+ menuBar = Wx::MenuBar.new
621
+ menuBar.append(fileMenu, "&File")
622
+ menuBar.append(editMenu, "&Edit")
623
+ menuBar.append(formatMenu, "F&ormat")
624
+ menuBar.append(listsMenu, "&Lists")
625
+ menuBar.append(tableMenu, "&Tables")
626
+ menuBar.append(insertMenu, "&Insert")
627
+ menuBar.append(helpMenu, "&Help")
628
+
629
+ # ... and attach this menu bar to the frame
630
+ set_menu_bar(menuBar)
631
+
632
+ # create a status bar just for fun (by default with 1 pane only)
633
+ # but don't create it on limited screen space (mobile device)
634
+ is_pda = Wx::SystemSettings.get_screen_type <= Wx::SYS_SCREEN_PDA
635
+
636
+ if Wx.has_feature? :USE_STATUSBAR
637
+ unless is_pda
638
+ create_status_bar(2)
639
+ set_status_text("Welcome to wxRichTextCtrl!")
640
+ end
641
+ end
642
+
643
+ sizer = Wx::VBoxSizer.new
644
+ set_sizer(sizer)
645
+
646
+ # On Mac, don't create a 'native' wxToolBar because small bitmaps are not supported by native
647
+ # toolbars. On Mac, a non-native, small-bitmap toolbar doesn't show unless it is explicitly
648
+ # managed, hence the use of sizers. In a real application, use larger icons for the main
649
+ # toolbar to avoid the need for this workaround. Or, use the toolbar in a container window
650
+ # as part of a more complex hierarchy, and the toolbar will automatically be non-native.
651
+
652
+ Wx::SystemOptions.set_option("mac.toolbar.no-native", 1)
653
+
654
+ toolBar = Wx::ToolBar.new(self, style: Wx::NO_BORDER|Wx::TB_FLAT|Wx::TB_NODIVIDER|Wx::TB_NOALIGN)
655
+
656
+ sizer.add(toolBar, 0, Wx::EXPAND)
657
+
658
+ toolBar.add_tool(Wx::ID_OPEN, '', Wx.Bitmap(:open), "Open")
659
+ toolBar.add_tool(Wx::ID_SAVEAS, '', Wx.Bitmap(:save), "Save")
660
+ toolBar.add_separator
661
+ toolBar.add_tool(Wx::ID_CUT, '', Wx.Bitmap(:cut), "Cut")
662
+ toolBar.add_tool(Wx::ID_COPY, '', Wx.Bitmap(:copy), "Copy")
663
+ toolBar.add_tool(Wx::ID_PASTE, '', Wx.Bitmap(:paste), "Paste")
664
+ toolBar.add_separator
665
+ toolBar.add_tool(Wx::ID_UNDO, '', Wx.Bitmap(:undo), "Undo")
666
+ toolBar.add_tool(Wx::ID_REDO, '', Wx.Bitmap(:redo), "Redo")
667
+ toolBar.add_separator
668
+ toolBar.add_check_tool(ID::FORMAT_BOLD, '', Wx.Bitmap(:bold), nil, "Bold")
669
+ toolBar.add_check_tool(ID::FORMAT_ITALIC, '', Wx.Bitmap(:italic), nil, "Italic")
670
+ toolBar.add_check_tool(ID::FORMAT_UNDERLINE, '', Wx.Bitmap(:underline), nil, "Underline")
671
+ toolBar.add_separator
672
+ toolBar.add_check_tool(ID::FORMAT_ALIGN_LEFT, '', Wx.Bitmap(:alignleft), nil, "Align Left")
673
+ toolBar.add_check_tool(ID::FORMAT_ALIGN_CENTRE, '', Wx.Bitmap(:centre), nil, "Centre")
674
+ toolBar.add_check_tool(ID::FORMAT_ALIGN_RIGHT, '', Wx.Bitmap(:alignright), nil, "Align Right")
675
+ toolBar.add_separator
676
+ toolBar.add_tool(ID::FORMAT_INDENT_LESS, '', Wx.Bitmap(:indentless), "Indent Less")
677
+ toolBar.add_tool(ID::FORMAT_INDENT_MORE, '', Wx.Bitmap(:indentmore), "Indent More")
678
+ toolBar.add_separator
679
+ toolBar.add_tool(ID::FORMAT_FONT, '', Wx.Bitmap(:font), "Font")
680
+ toolBar.add_separator
681
+
682
+ combo = Wx::RTC::RichTextStyleComboCtrl.new(toolBar, ID::RICHTEXT_STYLE_COMBO, size: [160, -1], style: Wx::CB_READONLY)
683
+ toolBar.add_control(combo)
684
+
685
+ toolBar.realize
686
+
687
+ splitter = Wx::SplitterWindow.new(self, style: Wx::SP_LIVE_UPDATE)
688
+ sizer.add(splitter, 1, Wx::EXPAND)
689
+
690
+ @richTextCtrl = MyRichTextCtrl.new(splitter, id: ID::RICHTEXT_CTRL, style: Wx::VSCROLL|Wx::HSCROLL) # /*|wxWANTS_CHARS*/)
691
+ # @richTextCtrl = Wx::RTC::RichTextCtrl.new(splitter, id: ID::RICHTEXT_CTRL, style: Wx::VSCROLL|Wx::HSCROLL) # /*|wxWANTS_CHARS*/)
692
+ # wxASSERT(!m_richTextCtrl.GetBuffer().GetAttributes().HasFontPixelSize())
693
+
694
+ font = Wx::Font.new(Wx::FontInfo.new(12).family(Wx::FONTFAMILY_ROMAN))
695
+
696
+ @richTextCtrl.set_font(font)
697
+
698
+ # wxASSERT(!m_richTextCtrl.GetBuffer().GetAttributes().HasFontPixelSize())
699
+
700
+ @richTextCtrl.set_margins(10, 10)
701
+
702
+ @richTextCtrl.set_style_sheet(Wx.get_app.get_style_sheet)
703
+
704
+ combo.set_style_sheet(Wx.get_app.get_style_sheet)
705
+ combo.set_rich_text_ctrl(@richTextCtrl)
706
+ combo.update_styles
707
+
708
+ styleListCtrl = Wx::RTC::RichTextStyleListCtrl.new(splitter, ID::RICHTEXT_STYLE_LIST)
709
+
710
+ display = Wx.get_display_size
711
+ if is_pda && display.width < display.height
712
+ splitter.split_horizontally(@richTextCtrl, styleListCtrl)
713
+ else
714
+ width = get_client_size.width * 4 / 5
715
+ splitter.split_vertically(@richTextCtrl, styleListCtrl, width)
716
+ splitter.set_sash_gravity(0.8)
717
+ end
718
+
719
+ layout
720
+
721
+ splitter.update_size
722
+
723
+ styleListCtrl.set_style_sheet(Wx.get_app.get_style_sheet)
724
+ styleListCtrl.set_rich_text_ctrl(@richTextCtrl)
725
+ styleListCtrl.update_styles
726
+
727
+ # attach event handlers
728
+ evt_menu(ID::Quit, :on_quit)
729
+ evt_menu(ID::About, :on_about)
730
+
731
+ evt_menu(Wx::ID_OPEN, :on_open)
732
+ evt_menu(Wx::ID_SAVE, :on_save)
733
+ evt_menu(Wx::ID_SAVEAS, :on_save_as)
734
+
735
+ evt_menu(ID::FORMAT_BOLD, :on_bold)
736
+ evt_menu(ID::FORMAT_ITALIC, :on_italic)
737
+ evt_menu(ID::FORMAT_UNDERLINE, :on_underline)
738
+
739
+ evt_menu(ID::FORMAT_STRIKETHROUGH, :on_strikethrough)
740
+ evt_menu(ID::FORMAT_SUPERSCRIPT, :on_superscript)
741
+ evt_menu(ID::FORMAT_SUBSCRIPT, :on_subscript)
742
+
743
+ evt_update_ui(ID::FORMAT_BOLD, :on_update_bold)
744
+ evt_update_ui(ID::FORMAT_ITALIC, :on_update_italic)
745
+ evt_update_ui(ID::FORMAT_UNDERLINE, :on_update_underline)
746
+
747
+ evt_update_ui(ID::FORMAT_STRIKETHROUGH, :on_update_strikethrough)
748
+ evt_update_ui(ID::FORMAT_SUPERSCRIPT, :on_update_superscript)
749
+ evt_update_ui(ID::FORMAT_SUBSCRIPT, :on_update_subscript)
750
+
751
+ evt_menu(ID::FORMAT_ALIGN_LEFT, :on_align_left)
752
+ evt_menu(ID::FORMAT_ALIGN_CENTRE, :on_align_centre)
753
+ evt_menu(ID::FORMAT_ALIGN_RIGHT, :on_align_right)
754
+
755
+ evt_update_ui(ID::FORMAT_ALIGN_LEFT, :on_update_align_left)
756
+ evt_update_ui(ID::FORMAT_ALIGN_CENTRE, :on_update_align_centre)
757
+ evt_update_ui(ID::FORMAT_ALIGN_RIGHT, :on_update_align_right)
758
+
759
+ evt_menu(ID::FORMAT_FONT, :on_font)
760
+ evt_menu(ID::FORMAT_IMAGE, :on_image)
761
+ evt_menu(ID::FORMAT_PARAGRAPH, :on_paragraph)
762
+ evt_menu(ID::FORMAT_CONTENT, :on_format)
763
+ evt_update_ui(ID::FORMAT_CONTENT, :on_update_format)
764
+ evt_update_ui(ID::FORMAT_FONT, :on_update_format)
765
+ evt_update_ui(ID::FORMAT_IMAGE, :on_update_image)
766
+ evt_update_ui(ID::FORMAT_PARAGRAPH, :on_update_format)
767
+ evt_menu(ID::FORMAT_INDENT_MORE, :on_indent_more)
768
+ evt_menu(ID::FORMAT_INDENT_LESS, :on_indent_less)
769
+
770
+ evt_menu(ID::FORMAT_LINE_SPACING_HALF, :on_line_spacing_half)
771
+ evt_menu(ID::FORMAT_LINE_SPACING_SINGLE, :on_line_spacing_single)
772
+ evt_menu(ID::FORMAT_LINE_SPACING_DOUBLE, :on_line_spacing_double)
773
+
774
+ evt_menu(ID::FORMAT_PARAGRAPH_SPACING_MORE, :on_paragraph_spacing_more)
775
+ evt_menu(ID::FORMAT_PARAGRAPH_SPACING_LESS, :on_paragraph_spacing_less)
776
+
777
+ evt_menu(ID::RELOAD, :on_reload)
778
+
779
+ evt_menu(ID::INSERT_SYMBOL, :on_insert_symbol)
780
+ evt_menu(ID::INSERT_URL, :on_insert_url)
781
+ evt_menu(ID::INSERT_IMAGE, :on_insert_image)
782
+
783
+ evt_menu(ID::FORMAT_NUMBER_LIST, :on_number_list)
784
+ evt_menu(ID::FORMAT_BULLETS_AND_NUMBERING, :on_bullets_and_numbering)
785
+ evt_menu(ID::FORMAT_ITEMIZE_LIST, :on_itemize_list)
786
+ evt_menu(ID::FORMAT_RENUMBER_LIST, :on_renumber_list)
787
+ evt_menu(ID::FORMAT_PROMOTE_LIST, :on_promote_list)
788
+ evt_menu(ID::FORMAT_DEMOTE_LIST, :on_demote_list)
789
+ evt_menu(ID::FORMAT_CLEAR_LIST, :on_clear_list)
790
+
791
+ evt_menu(ID::TABLE_ADD_COLUMN, :on_table_add_column)
792
+ evt_menu(ID::TABLE_ADD_ROW, :on_table_add_row)
793
+ evt_menu(ID::TABLE_DELETE_COLUMN, :on_table_delete_column)
794
+ evt_menu(ID::TABLE_DELETE_ROW, :on_table_delete_row)
795
+ evt_update_ui_range(ID::TABLE_ADD_COLUMN, ID::TABLE_ADD_ROW, :on_table_focused_update_ui)
796
+ evt_update_ui_range(ID::TABLE_DELETE_COLUMN, ID::TABLE_DELETE_ROW, :on_table_has_cells_update_ui)
797
+
798
+ evt_menu(ID::VIEW_HTML, :on_view_html)
799
+ evt_menu(ID::SWITCH_STYLE_SHEETS, :on_switch_stylesheets)
800
+ evt_menu(ID::MANAGE_STYLES, :on_manage_styles)
801
+
802
+ if Wx.has_feature? :USE_PRINTING_ARCHITECTURE
803
+ evt_menu(ID::PRINT, :on_print)
804
+ evt_menu(ID::PREVIEW, :on_preview)
805
+ end
806
+ evt_menu(ID::PAGE_SETUP, :on_page_setup)
807
+
808
+ evt_text_url(Wx::ID_ANY, :on_url)
809
+ evt_richtext_stylesheet_replacing(Wx::ID_ANY, :on_stylesheet_replacing)
810
+
811
+ evt_menu(ID::SET_FONT_SCALE, :on_set_font_scale)
812
+ evt_menu(ID::SET_DIMENSION_SCALE, :on_set_dimension_scale)
813
+
814
+ write_initial_text
815
+ end
816
+
817
+ # utility function to find an icon relative to this ruby script
818
+ def local_icon_file(icon_name)
819
+ File.join(File.dirname(__FILE__), icon_name)
820
+ end
821
+
822
+ # event handlers
823
+ def on_quit(_event)
824
+ close(true)
825
+ end
826
+
827
+ def on_about(_event)
828
+ msg = "This is a demo for Wx::RTC::RichTextCtrl, a control for editing styled text.\nOriginal code (c) Julian Smart, 2005\nAdapted for wxRuby3 (c) Martin JN Corino, 2023"
829
+ Wx.message_box(msg, "About wxRichTextCtrl Sample", Wx::OK | Wx::ICON_INFORMATION, self)
830
+ end
831
+
832
+ def on_open(_event)
833
+ fileTypes = []
834
+ filter = Wx::RTC::RichTextBuffer.get_ext_wildcard(false, false, fileTypes)
835
+ filter += "|" unless filter.empty?
836
+
837
+ filter += "All files (*.*)|*.*"
838
+
839
+ Wx.FileDialog(self, "Choose a filename",
840
+ '',
841
+ '',
842
+ filter,
843
+ Wx::FD_OPEN) do |dialog|
844
+ if dialog.show_modal == Wx::ID_OK
845
+ path1 = dialog.path
846
+
847
+ unless path1.empty?
848
+ filterIndex = dialog.get_filter_index
849
+ fileType = filterIndex < fileTypes.size ? fileTypes[filterIndex] : Wx::RTC::RICHTEXT_TYPE_TEXT
850
+ @richTextCtrl.load_file(path1, fileType)
851
+ end
852
+ end
853
+ end
854
+ end
855
+
856
+ def on_save(event)
857
+ if @richTextCtrl.get_filename.empty?
858
+ on_save_as(event)
859
+ else
860
+ @richTextCtrl.save_file
861
+ end
862
+ end
863
+
864
+ def on_save_as(_event)
865
+ filter = Wx::RTC::RichTextBuffer.get_ext_wildcard(false, true)
866
+
867
+ Wx.FileDialog(self, "Choose a filename", '', '', filter, Wx::FD_SAVE) do |dialog|
868
+
869
+ if dialog.show_modal == Wx::ID_OK
870
+ path1 = dialog.path
871
+
872
+ unless path1.empty?
873
+ Wx::BusyCursor.busy do
874
+ start = Time.now
875
+
876
+ @richTextCtrl.save_file(path1)
877
+
878
+ td = Time.now-start
879
+ Wx.log_debug("Saving took #{td}s")
880
+ Wx.message_box("Saving took #{td}s")
881
+ end
882
+ end
883
+ end
884
+ end
885
+ end
886
+
887
+ def on_bold(_event)
888
+ @richTextCtrl.apply_bold_to_selection
889
+ end
890
+ def on_italic(_event)
891
+ @richTextCtrl.apply_italic_to_selection
892
+ end
893
+ def on_underline(_event)
894
+ @richTextCtrl.apply_underline_to_selection
895
+ end
896
+
897
+ def on_strikethrough(_event)
898
+ @richTextCtrl.apply_text_effect_to_selection(Wx::TEXT_ATTR_EFFECT_STRIKETHROUGH)
899
+ end
900
+ def on_superscript(_event)
901
+ @richTextCtrl.apply_text_effect_to_selection(Wx::TEXT_ATTR_EFFECT_SUPERSCRIPT)
902
+ end
903
+ def on_subscript(_event)
904
+ @richTextCtrl.apply_text_effect_to_selection(Wx::TEXT_ATTR_EFFECT_SUBSCRIPT)
905
+ end
906
+
907
+ def on_update_bold(event)
908
+ event.check(@richTextCtrl.is_selection_bold)
909
+ end
910
+ def on_update_italic(event)
911
+ event.check(@richTextCtrl.is_selection_italics)
912
+ end
913
+ def on_update_underline(event)
914
+ event.check(@richTextCtrl.is_selection_underlined)
915
+ end
916
+ def on_update_strikethrough(event)
917
+ event.check(@richTextCtrl.does_selection_have_text_effect_flag(Wx::TEXT_ATTR_EFFECT_STRIKETHROUGH))
918
+ end
919
+ def on_update_superscript(event)
920
+ event.check(@richTextCtrl.does_selection_have_text_effect_flag(Wx::TEXT_ATTR_EFFECT_SUPERSCRIPT))
921
+ end
922
+ def on_update_subscript(event)
923
+ event.check(@richTextCtrl.does_selection_have_text_effect_flag(Wx::TEXT_ATTR_EFFECT_SUBSCRIPT))
924
+ end
925
+
926
+ def on_align_left(_event)
927
+ @richTextCtrl.apply_alignment_to_selection(Wx::TEXT_ALIGNMENT_LEFT)
928
+ end
929
+ def on_align_centre(_event)
930
+ @richTextCtrl.apply_alignment_to_selection(Wx::TEXT_ALIGNMENT_CENTRE)
931
+ end
932
+ def on_align_right(_event)
933
+ @richTextCtrl.apply_alignment_to_selection(Wx::TEXT_ALIGNMENT_RIGHT)
934
+ end
935
+
936
+ def on_update_align_left(event)
937
+ event.check(@richTextCtrl.is_selection_aligned(Wx::TEXT_ALIGNMENT_LEFT))
938
+ end
939
+ def on_update_align_centre(event)
940
+ event.check(@richTextCtrl.is_selection_aligned(Wx::TEXT_ALIGNMENT_CENTRE))
941
+ end
942
+ def on_update_align_right(event)
943
+ event.check(@richTextCtrl.is_selection_aligned(Wx::TEXT_ALIGNMENT_RIGHT))
944
+ end
945
+
946
+ def on_indent_more(_event)
947
+ attr = Wx::RichTextAttr.new
948
+ attr.set_flags(Wx::TEXT_ATTR_LEFT_INDENT)
949
+
950
+ if @richTextCtrl.get_style(@richTextCtrl.get_insertion_point, attr)
951
+ range = @richTextCtrl.get_insertion_point..@richTextCtrl.get_insertion_point
952
+ range = @richTextCtrl.selection_range if @richTextCtrl.has_selection
953
+
954
+ attr.set_left_indent(attr.get_left_indent + 100)
955
+
956
+ attr.set_flags(Wx::TEXT_ATTR_LEFT_INDENT)
957
+ @richTextCtrl.set_style(range, attr)
958
+ end
959
+ end
960
+ def on_indent_less(_event)
961
+ attr = Wx::RichTextAttr.new
962
+ attr.set_flags(Wx::TEXT_ATTR_LEFT_INDENT)
963
+
964
+ if @richTextCtrl.get_style(@richTextCtrl.get_insertion_point, attr)
965
+ range = @richTextCtrl.get_insertion_point..@richTextCtrl.get_insertion_point
966
+ range = @richTextCtrl.selection_range if @richTextCtrl.has_selection
967
+
968
+ if attr.get_left_indent > 0
969
+ attr.set_left_indent([0, attr.get_left_indent - 100].max)
970
+
971
+ @richTextCtrl.set_style(range, attr)
972
+ end
973
+ end
974
+ end
975
+
976
+ def on_font(_event)
977
+ if @richTextCtrl.has_selection
978
+ range = @richTextCtrl.selection_range
979
+ else
980
+ range = 0..(@richTextCtrl.last_position+1)
981
+ end
982
+
983
+ pages = Wx::RTC::RICHTEXT_FORMAT_FONT
984
+
985
+ Wx::RTC.RichTextFormattingDialog(pages, self) do |formatDlg|
986
+ formatDlg.set_options(Wx::RTC::RichTextFormattingDialog::Option_AllowPixelFontSize)
987
+ formatDlg.get_style(@richTextCtrl, range)
988
+
989
+ if formatDlg.show_modal == Wx::ID_OK
990
+ formatDlg.apply_style(@richTextCtrl, range,
991
+ Wx::RTC::RICHTEXT_SETSTYLE_WITH_UNDO|
992
+ Wx::RTC::RICHTEXT_SETSTYLE_OPTIMIZE|
993
+ Wx::RTC::RICHTEXT_SETSTYLE_CHARACTERS_ONLY)
994
+ end
995
+ end
996
+ end
997
+ def on_image(_event)
998
+ if @richTextCtrl.has_selection
999
+ range = @richTextCtrl.selection_range
1000
+ if (range.begin...range.end).size == 1
1001
+ image = @richTextCtrl.get_focus_object.get_leaf_object_at_position(range.begin)
1002
+ if image.is_a?(Wx::RTC::RichTextImage)
1003
+ Wx::RTC.RichTextObjectPropertiesDialog(image, self) do |imageDlg|
1004
+ if imageDlg.show_modal == Wx::ID_OK
1005
+ imageDlg.apply_style(@richTextCtrl)
1006
+ end
1007
+ end
1008
+ end
1009
+ end
1010
+ end
1011
+ end
1012
+ def on_update_image(event)
1013
+ range = @richTextCtrl.selection_range
1014
+ if (range.begin...range.end).size == 1
1015
+ obj = @richTextCtrl.get_focus_object.get_leaf_object_at_position(range.begin)
1016
+ if obj && obj.is_a?(Wx::RTC::RichTextImage)
1017
+ event.enable(true)
1018
+ return
1019
+ end
1020
+ end
1021
+
1022
+ event.enable(false)
1023
+ end
1024
+
1025
+ def on_paragraph(_event)
1026
+ range = if @richTextCtrl.has_selection
1027
+ @richTextCtrl.selection_range
1028
+ else
1029
+ 0..(@richTextCtrl.last_position + 1)
1030
+ end
1031
+
1032
+ pages = Wx::RTC::RICHTEXT_FORMAT_INDENTS_SPACING|Wx::RTC::RICHTEXT_FORMAT_TABS|Wx::RTC::RICHTEXT_FORMAT_BULLETS
1033
+
1034
+ Wx::RTC.RichTextFormattingDialog(pages, self) do |formatDlg|
1035
+ formatDlg.get_style(@richTextCtrl, range)
1036
+
1037
+ formatDlg.apply_style(@richTextCtrl, range) if formatDlg.show_modal == Wx::ID_OK
1038
+ end
1039
+ end
1040
+ def on_format(_event)
1041
+ range = if @richTextCtrl.has_selection
1042
+ @richTextCtrl.selection_range
1043
+ else
1044
+ 0..(@richTextCtrl.last_position + 1)
1045
+ end
1046
+
1047
+ pages = Wx::RTC::RICHTEXT_FORMAT_FONT|Wx::RTC::RICHTEXT_FORMAT_INDENTS_SPACING|Wx::RTC::RICHTEXT_FORMAT_TABS|Wx::RTC::RICHTEXT_FORMAT_BULLETS
1048
+
1049
+ Wx::RTC.RichTextFormattingDialog(pages, self) do |formatDlg|
1050
+ formatDlg.get_style(@richTextCtrl, range)
1051
+
1052
+ formatDlg.apply_style(@richTextCtrl, range) if formatDlg.show_modal == Wx::ID_OK
1053
+ end
1054
+ end
1055
+ def on_update_format(event)
1056
+ event.enable(@richTextCtrl.has_selection)
1057
+ end
1058
+
1059
+ def on_insert_symbol(_event)
1060
+ attr = Wx::RTC::RichTextAttr.new
1061
+ attr.set_flags(Wx::TEXT_ATTR_FONT)
1062
+ @richTextCtrl.get_style(@richTextCtrl.insertion_point, attr)
1063
+
1064
+ currentFontName = ''
1065
+ currentFontName = attr.font.face_name if attr.has_font && attr.font.ok?
1066
+
1067
+ # Don't set the initial font in the dialog (so the user is choosing
1068
+ # 'normal text', i.e. the current font) but do tell the dialog
1069
+ # what 'normal text' is.
1070
+
1071
+ Wx::RTC.SymbolPickerDialog("*", '', currentFontName, self) do |dlg|
1072
+ if dlg.show_modal == Wx::ID_OK
1073
+ if dlg.has_selection
1074
+ insertionPoint = @richTextCtrl.insertion_point
1075
+
1076
+ @richTextCtrl.write_text(dlg.get_symbol)
1077
+
1078
+ unless dlg.use_normal_font
1079
+ font = Wx::Font.new(attr.font)
1080
+ font.set_face_name(dlg.font_name)
1081
+ attr.set_font(font)
1082
+ @richTextCtrl.set_style(insertionPoint, insertionPoint+1, attr)
1083
+ end
1084
+ end
1085
+ end
1086
+ end
1087
+ end
1088
+
1089
+ def set_selection_spacing(flag, &block)
1090
+ attr = Wx::RTC::RichTextAttr.new
1091
+ attr.set_flags(flag)
1092
+
1093
+ if @richTextCtrl.get_style(@richTextCtrl.insertion_point, attr)
1094
+ range = @richTextCtrl.insertion_point..@richTextCtrl.insertion_point
1095
+ range = @richTextCtrl.selection_range if @richTextCtrl.has_selection
1096
+
1097
+ block.call(attr)
1098
+
1099
+ attr.set_flags(flag)
1100
+ @richTextCtrl.set_style(range, attr)
1101
+ end
1102
+ end
1103
+ protected :set_selection_spacing
1104
+
1105
+ def on_line_spacing_half(_event)
1106
+ set_selection_spacing(Wx::TEXT_ATTR_LINE_SPACING) { |attr| attr.set_line_spacing(15) }
1107
+ end
1108
+ def on_line_spacing_double(_event)
1109
+ set_selection_spacing(Wx::TEXT_ATTR_LINE_SPACING) { |attr| attr.set_line_spacing(20) }
1110
+ end
1111
+ def on_line_spacing_single(_event)
1112
+ set_selection_spacing(Wx::TEXT_ATTR_LINE_SPACING) { |attr| attr.set_line_spacing(0) } # you could also use 10
1113
+ end
1114
+
1115
+ def on_paragraph_spacing_more(_event)
1116
+ set_selection_spacing(Wx::TEXT_ATTR_PARA_SPACING_AFTER) do |attr|
1117
+ attr.set_paragraph_spacing_after(attr.get_paragraph_spacing_after + 20)
1118
+ end
1119
+ end
1120
+ def on_paragraph_spacing_less(_event)
1121
+ set_selection_spacing(Wx::TEXT_ATTR_PARA_SPACING_AFTER) do |attr|
1122
+ if attr.get_paragraph_spacing_after >= 20
1123
+ attr.set_paragraph_spacing_after(attr.get_paragraph_spacing_after - 20)
1124
+ else
1125
+ attr.set_paragraph_spacing_after(0)
1126
+ end
1127
+ end
1128
+ end
1129
+
1130
+ def on_number_list(_event)
1131
+ if @richTextCtrl.has_selection
1132
+ range = @richTextCtrl.selection_range
1133
+ @richTextCtrl.set_list_style(range, 'Numbered List 1', Wx::RTC::RICHTEXT_SETSTYLE_WITH_UNDO|Wx::RTC::RICHTEXT_SETSTYLE_RENUMBER)
1134
+ end
1135
+ end
1136
+ def on_bullets_and_numbering(_event)
1137
+ sheet = @richTextCtrl.get_style_sheet
1138
+
1139
+ flags = Wx::RTC::RICHTEXT_ORGANISER_BROWSE_NUMBERING
1140
+
1141
+ Wx::RTC.RichTextStyleOrganiserDialog(flags, sheet, @richTextCtrl, self, Wx::ID_ANY, 'Bullets and Numbering') do |dlg|
1142
+ if dlg.show_modal == Wx::ID_OK
1143
+ dlg.apply_style if dlg.get_selected_style_definition
1144
+ end
1145
+ end
1146
+ end
1147
+ def on_itemize_list(_event)
1148
+ if @richTextCtrl.has_selection
1149
+ range = @richTextCtrl.get_selection_range
1150
+ @richTextCtrl.set_list_style(range, 'Bullet List 1')
1151
+ end
1152
+ end
1153
+ def on_renumber_list(_event)
1154
+ if @richTextCtrl.has_selection
1155
+ range = @richTextCtrl.get_selection_range
1156
+ @richTextCtrl.number_list(range, nil, Wx::RTC::RICHTEXT_SETSTYLE_WITH_UNDO|Wx::RTC::RICHTEXT_SETSTYLE_RENUMBER)
1157
+ end
1158
+ end
1159
+ def on_promote_list(_event)
1160
+ if @richTextCtrl.has_selection
1161
+ range = @richTextCtrl.get_selection_range
1162
+ @richTextCtrl.promote_list(1, range, nil)
1163
+ end
1164
+ end
1165
+ def on_demote_list(_event)
1166
+ if @richTextCtrl.has_selection
1167
+ range = @richTextCtrl.get_selection_range
1168
+ @richTextCtrl.promote_list(-1, range, nil)
1169
+ end
1170
+ end
1171
+ def on_clear_list(_event)
1172
+ if @richTextCtrl.has_selection
1173
+ range = @richTextCtrl.get_selection_range
1174
+ @richTextCtrl.clear_list_style(range)
1175
+ end
1176
+ end
1177
+
1178
+ def on_table_add_column(_event)
1179
+ table = @richTextCtrl.find_table
1180
+ if table.is_a?(Wx::RTC::RichTextTable)
1181
+ cellAttr = table.get_cell(0, 0).attributes
1182
+ table.add_columns(table.column_count, 1, cellAttr)
1183
+ end
1184
+ end
1185
+ def on_table_add_row(_event)
1186
+ table = @richTextCtrl.find_table
1187
+ if table.is_a?(Wx::RTC::RichTextTable)
1188
+ cellAttr = table.get_cell(0, 0).attributes
1189
+ table.add_rows(table.row_count, 1, cellAttr)
1190
+ end
1191
+ end
1192
+ def on_table_delete_column(_event)
1193
+ table = @richTextCtrl.find_table
1194
+ if table.is_a?(Wx::RTC::RichTextTable)
1195
+ _, col = table.get_focused_cell
1196
+ col = table.column_count-1 if col == -1
1197
+ table.delete_columns(col, 1)
1198
+ end
1199
+ end
1200
+ def on_table_delete_row(_event)
1201
+ table = @richTextCtrl.find_table
1202
+ if table.is_a?(Wx::RTC::RichTextTable)
1203
+ row, _ = table.get_focused_cell
1204
+ row = table.row_count-1 if row == -1
1205
+ table.delete_rows(row, 1)
1206
+ end
1207
+ end
1208
+ def on_table_focused_update_ui(event)
1209
+ event.enable(@richTextCtrl.find_table != nil)
1210
+ end
1211
+ def on_table_has_cells_update_ui(event)
1212
+ enable = false
1213
+ table = @richTextCtrl.find_table
1214
+ if table.is_a?(Wx::RTC::RichTextTable)
1215
+ if event.id == ID::TABLE_DELETE_COLUMN
1216
+ enable = table.column_count > 1
1217
+ else
1218
+ enable = table.row_count > 1
1219
+ end
1220
+ end
1221
+ event.enable(enable)
1222
+ end
1223
+
1224
+ def on_reload(_event)
1225
+ @richTextCtrl.clear
1226
+ write_initial_text
1227
+ end
1228
+
1229
+ def on_view_html(_event)
1230
+ dialog = Wx::Dialog.new(self, Wx::ID_ANY, 'HTML', Wx::DEFAULT_POSITION, [500, 400], Wx::DEFAULT_DIALOG_STYLE)
1231
+ begin
1232
+ boxSizer = Wx::VBoxSizer.new
1233
+ dialog.set_sizer(boxSizer)
1234
+
1235
+ win = Wx::HTML::HtmlWindow.new(dialog, size: [500, 400], style: Wx::SUNKEN_BORDER)
1236
+ boxSizer.add(win, 1, Wx::ALL, 5)
1237
+
1238
+ cancelButton = Wx::Button.new(dialog, Wx::ID_CANCEL, '&Close')
1239
+ boxSizer.add(cancelButton, 0, Wx::ALL|Wx::CENTRE, 5)
1240
+
1241
+ strStream = StringIO.new
1242
+
1243
+ htmlHandler = Wx::RTC::RichTextHTMLHandler.new
1244
+ htmlHandler.set_flags(Wx::RTC::RICHTEXT_HANDLER_SAVE_IMAGES_TO_MEMORY)
1245
+
1246
+ fontSizeMapping = [7,9,11,12,14,22,100]
1247
+
1248
+ htmlHandler.set_font_size_mapping(fontSizeMapping)
1249
+
1250
+ if htmlHandler.save_file(@richTextCtrl.buffer, strStream)
1251
+ strStream.rewind
1252
+ win.set_page(strStream.read || '')
1253
+ end
1254
+
1255
+ boxSizer.fit(dialog)
1256
+
1257
+ dialog.show_modal
1258
+
1259
+ # Now delete the temporary in-memory images
1260
+ htmlHandler.delete_temporary_images
1261
+ ensure
1262
+ dialog.destroy
1263
+ end
1264
+ end
1265
+
1266
+ class << self
1267
+ def alternate_style_sheet
1268
+ @alternate_style_sheet
1269
+ end
1270
+ def alternate_style_sheet=(alt)
1271
+ @alternate_style_sheet = alt
1272
+ end
1273
+ end
1274
+
1275
+ # Demonstrates how you can change the style sheets and have the changes
1276
+ # reflected in the control content without wiping out character formatting.
1277
+ def on_switch_stylesheets(_event)
1278
+ styleList = find_window_by_id(ID::RICHTEXT_STYLE_LIST)
1279
+ styleCombo = find_window_by_id(ID::RICHTEXT_STYLE_COMBO)
1280
+
1281
+ sheet = @richTextCtrl.get_style_sheet
1282
+
1283
+ # One-time creation of an alternate style sheet
1284
+ unless MyFrame.alternate_style_sheet
1285
+ MyFrame.alternate_style_sheet = Wx::RTC::RichTextStyleSheet.new(sheet)
1286
+
1287
+ # Make some modifications
1288
+ MyFrame.alternate_style_sheet.paragraph_style_count.times do |i|
1289
+ style_def = MyFrame.alternate_style_sheet.get_paragraph_style(i)
1290
+
1291
+ style_def.get_style.set_text_colour(:BLUE) if style_def.get_style.has_text_colour
1292
+
1293
+ if style_def.get_style.has_alignment
1294
+ if style_def.get_style.get_alignment == Wx::TEXT_ALIGNMENT_CENTRE
1295
+ style_def.get_style.set_alignment(Wx::TEXT_ALIGNMENT_RIGHT)
1296
+ elsif style_def.get_style.get_alignment == Wx::TEXT_ALIGNMENT_LEFT
1297
+ style_def.get_style.set_alignment(Wx::TEXT_ALIGNMENT_CENTRE)
1298
+ end
1299
+ end
1300
+ if style_def.get_style.has_left_indent
1301
+ style_def.get_style.set_left_indent(style_def.get_style.get_left_indent * 2)
1302
+ end
1303
+ end
1304
+ end
1305
+
1306
+ # Switch sheets
1307
+ tmp = MyFrame.alternate_style_sheet
1308
+ MyFrame.alternate_style_sheet = sheet
1309
+ sheet = tmp
1310
+
1311
+ @richTextCtrl.set_style_sheet(sheet)
1312
+ @richTextCtrl.apply_style_sheet(sheet) # Makes the control reflect the new style definitions
1313
+
1314
+ styleList.set_style_sheet(sheet)
1315
+ styleList.update_styles
1316
+
1317
+ styleCombo.set_style_sheet(sheet)
1318
+ styleCombo.update_styles
1319
+ end
1320
+ def on_manage_styles(_event)
1321
+ sheet = @richTextCtrl.get_style_sheet
1322
+
1323
+ flags = Wx::RTC::RICHTEXT_ORGANISER_CREATE_STYLES|Wx::RTC::RICHTEXT_ORGANISER_EDIT_STYLES
1324
+
1325
+ Wx::RTC.RichTextStyleOrganiserDialog(flags, sheet, nil, self, Wx::ID_ANY, 'Style Manager')
1326
+ end
1327
+
1328
+ def on_insert_url(_event)
1329
+ url = Wx.get_text_from_user('URL:', 'Insert URL')
1330
+ unless url.empty?
1331
+ # Make a style suitable for showing a URL
1332
+ urlStyle = Wx::RichTextAttr.new
1333
+ urlStyle.set_text_colour(:BLUE)
1334
+ urlStyle.set_font_underlined(true)
1335
+
1336
+ @richTextCtrl.begin_style(urlStyle)
1337
+ @richTextCtrl.begin_url(url)
1338
+ @richTextCtrl.write_text(url)
1339
+ @richTextCtrl.end_url
1340
+ @richTextCtrl.end_style
1341
+ end
1342
+ end
1343
+ def on_url(event)
1344
+ Wx.message_box(event.get_string)
1345
+ end
1346
+ def on_stylesheet_replacing(event)
1347
+ event.veto
1348
+ end
1349
+
1350
+ if Wx.has_feature? :USE_PRINTING_ARCHITECTURE
1351
+
1352
+ def on_print(_event)
1353
+ Wx.get_app.get_printing.print_buffer(@richTextCtrl.buffer)
1354
+ end
1355
+ def on_preview(_event)
1356
+ Wx.get_app.get_printing.preview_buffer(@richTextCtrl.buffer)
1357
+ end
1358
+
1359
+ end
1360
+
1361
+ def on_page_setup(_event)
1362
+ # dialog = Wx::Dialog.new(self, Wx::ID_ANY, 'Testing', [10, 10], [400, 300], Wx::DEFAULT_DIALOG_STYLE)
1363
+ # begin
1364
+ # nb = Wx::Notebook.new(dialog, pos: [5, 5], size: [300, 250])
1365
+ # panel = Wx::Panel.new(nb)
1366
+ # panel2 = Wx::Panel.new(nb)
1367
+ #
1368
+ # Wx::RichTextCtrl.new(panel, pos: [5, 5], size: [200, 150], style: Wx::VSCROLL|Wx::TE_READONLY)
1369
+ # nb.add_page(panel, 'Page 1')
1370
+ #
1371
+ # Wx::RichTextCtrl.new(panel2, pos: [5, 5], size: [200, 150], style: Wx::VSCROLL|Wx::TE_READONLY)
1372
+ # nb.add_page(panel2, 'Page 2')
1373
+ #
1374
+ # Wx::Button.new(dialog, Wx::ID_OK, 'OK', [5, 180])
1375
+ #
1376
+ # dialog.show_modal
1377
+ # ensure
1378
+ # dialog.destroy
1379
+ # end
1380
+ Wx.get_app.get_printing.page_setup
1381
+ end
1382
+
1383
+ def on_insert_image(_event)
1384
+ Wx.FileDialog(self, 'Choose an image', '', '',
1385
+ 'BMP and GIF files (*.bmp;*.gif)|*.bmp;*.gif|PNG files (*.png)|*.png|JPEG files (*.jpg;*.jpeg)|*.jpg;*.jpeg') do |dialog|
1386
+ if dialog.show_modal == Wx::ID_OK
1387
+ path = dialog.path
1388
+ image = Wx::Image.new
1389
+ if image.load_file(path) && image.type != Wx::BITMAP_TYPE_INVALID
1390
+ @richTextCtrl.write_image(path, image.type)
1391
+ end
1392
+ end
1393
+ end
1394
+ end
1395
+
1396
+ def on_set_font_scale(_event)
1397
+ value = "%g" % @richTextCtrl.get_font_scale
1398
+ text = Wx.get_text_from_user('Enter a text scale factor:', 'Text Scale Factor', value, Wx.get_top_level_parent(self))
1399
+ if !text.empty? && value != text
1400
+ scale = text.to_f
1401
+ scale = 1.0 if scale == 0.0
1402
+ @richTextCtrl.set_font_scale(scale, true)
1403
+ end
1404
+ end
1405
+ def on_set_dimension_scale(_event)
1406
+ value = "%g" % @richTextCtrl.get_dimension_scale
1407
+ text = Wx.get_text_from_user('Enter a dimension scale factor:', 'Dimension Scale Factor', value, Wx.get_top_level_parent(self))
1408
+ if !text.empty? && value != text
1409
+ scale = text.to_f
1410
+ scale = 1.0 if scale == 0.0
1411
+ @richTextCtrl.set_dimension_scale(scale, true)
1412
+ end
1413
+ end
1414
+
1415
+ protected
1416
+
1417
+ class << self
1418
+
1419
+ def event_type
1420
+ @event_type ||= 0
1421
+ end
1422
+ def event_type=(v)
1423
+ @event_type = v
1424
+ end
1425
+
1426
+ def win_id
1427
+ @win_id ||= 0
1428
+ end
1429
+ def win_id=(id)
1430
+ @win_id = id.to_i
1431
+ end
1432
+
1433
+ end
1434
+
1435
+ # Forward command events to the current rich text control, if any
1436
+ def try_before(event)
1437
+ if event.is_command_event && !event.is_a?(Wx::ChildFocusEvent)
1438
+ # Problem: we can get infinite recursion because the events
1439
+ # climb back up to this frame, and repeat.
1440
+ # Assume that command events don't cause another command event
1441
+ # to be called, so we can rely on inCommand not being overwritten
1442
+
1443
+ if MyFrame.win_id != event.id && MyFrame.event_type != event.event_type
1444
+ MyFrame.event_type = event.event_type
1445
+ MyFrame.win_id = event.id
1446
+ focusWin = Wx.find_focus_descendant(self)
1447
+ focusWin = @richTextCtrl unless focusWin
1448
+
1449
+ if focusWin && focusWin.get_event_handler.process_event(event)
1450
+ MyFrame.event_type = 0
1451
+ MyFrame.win_id = 0
1452
+ return true
1453
+ end
1454
+
1455
+ MyFrame.event_type = 0
1456
+ MyFrame.win_id = 0
1457
+ else
1458
+ return false
1459
+ end
1460
+ end
1461
+
1462
+ false
1463
+ end
1464
+
1465
+ # Write text
1466
+ def write_initial_text
1467
+ r = @richTextCtrl
1468
+
1469
+ r.set_default_style(Wx::RichTextAttr.new)
1470
+
1471
+ r.freeze
1472
+
1473
+ r.begin_suppress_undo
1474
+
1475
+ r.begin_paragraph_spacing(0, 20)
1476
+
1477
+ r.begin_alignment(Wx::TEXT_ALIGNMENT_CENTRE)
1478
+ r.begin_bold
1479
+
1480
+ r.begin_font_size(14)
1481
+
1482
+ lineBreak = ?\n
1483
+
1484
+ r.write_text("Welcome to wxRichTextCtrl, a wxWidgets control" + lineBreak + "for editing and presenting styled text and images\n")
1485
+ r.end_font_size
1486
+
1487
+ r.begin_italic
1488
+ r.write_text("by Julian Smart")
1489
+ r.end_italic
1490
+
1491
+ r.end_bold
1492
+ r.newline
1493
+
1494
+ r.write_image(Wx.Bitmap(:zebra))
1495
+
1496
+ r.newline
1497
+ r.newline
1498
+
1499
+ r.end_alignment
1500
+
1501
+ =begin
1502
+ r.begin_alignment(wxTEXT_ALIGNMENT_CENTRE)
1503
+ r.write_text("This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side.")
1504
+ r.newline
1505
+ r.end_alignment
1506
+ =end
1507
+
1508
+ r.begin_alignment(Wx::TEXT_ALIGNMENT_LEFT)
1509
+ imageAttr = Wx::RTC::RichTextAttr.new
1510
+ imageAttr.get_text_box_attr.set_float_mode(Wx::TEXT_BOX_ATTR_FLOAT_LEFT)
1511
+ r.write_text("This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side. This is a simple test for a floating left image test. The zebra image should be placed at the left side of the current buffer and all the text should flow around it at the right side.")
1512
+ r.write_image(Wx.Bitmap(:zebra), Wx::BITMAP_TYPE_PNG, imageAttr)
1513
+
1514
+ imageAttr.get_text_box_attr.top.set_value(200)
1515
+ imageAttr.get_text_box_attr.top.set_units(Wx::TEXT_ATTR_UNITS_PIXELS)
1516
+ imageAttr.get_text_box_attr.set_float_mode(Wx::TEXT_BOX_ATTR_FLOAT_RIGHT)
1517
+ r.write_image(Wx.Bitmap(:zebra), Wx::BITMAP_TYPE_PNG, imageAttr)
1518
+ r.write_text("This is a simple test for a floating right image test. The zebra image should be placed at the right side of the current buffer and all the text should flow around it at the left side. This is a simple test for a floating left image test. The zebra image should be placed at the right side of the current buffer and all the text should flow around it at the left side. This is a simple test for a floating left image test. The zebra image should be placed at the right side of the current buffer and all the text should flow around it at the left side.")
1519
+ r.end_alignment
1520
+ r.newline
1521
+
1522
+ r.write_text("What can you do with this thing? ")
1523
+
1524
+ r.write_image(Wx.Bitmap(:smiley))
1525
+ r.write_text(" Well, you can change text ")
1526
+
1527
+ r.begin_text_colour(Wx::RED)
1528
+ r.write_text("colour, like this red bit.")
1529
+ r.end_text_colour
1530
+
1531
+ backgroundColourAttr = Wx::RTC::RichTextAttr.new
1532
+ backgroundColourAttr.set_background_colour(Wx::GREEN)
1533
+ backgroundColourAttr.set_text_colour(:BLUE)
1534
+ r.begin_style(backgroundColourAttr)
1535
+ r.write_text(" And this blue on green bit.")
1536
+ r.end_style
1537
+
1538
+ r.write_text(" Naturally you can make things ")
1539
+ r.begin_bold
1540
+ r.write_text("bold ")
1541
+ r.end_bold
1542
+ r.begin_italic
1543
+ r.write_text("or italic ")
1544
+ r.end_italic
1545
+ r.begin_underline
1546
+ r.write_text("or underlined.")
1547
+ r.end_underline
1548
+
1549
+ r.begin_font_size(14)
1550
+ r.write_text(" Different font sizes on the same line is allowed, too.")
1551
+ r.end_font_size
1552
+
1553
+ r.write_text(" Next we'll show an indented paragraph.")
1554
+
1555
+ r.newline
1556
+
1557
+ r.begin_left_indent(60)
1558
+ r.write_text("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
1559
+ r.newline
1560
+
1561
+ r.end_left_indent
1562
+
1563
+ r.write_text("Next, we'll show a first-line indent, achieved using BeginLeftIndent(100, -40).")
1564
+
1565
+ r.newline
1566
+
1567
+ r.begin_left_indent(100, -40)
1568
+
1569
+ r.write_text("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
1570
+ r.newline
1571
+
1572
+ r.end_left_indent
1573
+
1574
+ r.write_text("Numbered bullets are possible, again using subindents:")
1575
+ r.newline
1576
+
1577
+ r.begin_numbered_bullet(1, 100, 60)
1578
+ r.write_text("This is my first item. Note that wxRichTextCtrl can apply numbering and bullets automatically based on list styles, but this list is formatted explicitly by setting indents.")
1579
+ r.newline
1580
+ r.end_numbered_bullet
1581
+
1582
+ r.begin_numbered_bullet(2, 100, 60)
1583
+ r.write_text("This is my second item.")
1584
+ r.newline
1585
+ r.end_numbered_bullet
1586
+
1587
+ r.write_text("The following paragraph is right-indented:")
1588
+ r.newline
1589
+
1590
+ r.begin_right_indent(200)
1591
+
1592
+ r.write_text("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
1593
+ r.newline
1594
+
1595
+ r.end_right_indent
1596
+
1597
+ r.write_text("The following paragraph is right-aligned with 1.5 line spacing:")
1598
+ r.newline
1599
+
1600
+ r.begin_alignment(Wx::TEXT_ALIGNMENT_RIGHT)
1601
+ r.begin_line_spacing(Wx::TEXT_ATTR_LINE_SPACING_HALF)
1602
+ r.write_text("It was in January, the most down-trodden month of an Edinburgh winter. An attractive woman came into the cafe, which is nothing remarkable.")
1603
+ r.newline
1604
+ r.end_line_spacing
1605
+ r.end_alignment
1606
+
1607
+ tabs = [400, 600, 800, 1000]
1608
+ attr = Wx::RichTextAttr.new
1609
+ attr.set_flags(Wx::TEXT_ATTR_TABS)
1610
+ attr.set_tabs(tabs)
1611
+ r.set_default_style(attr)
1612
+
1613
+ r.write_text("This line contains tabs:\tFirst tab\tSecond tab\tThird tab")
1614
+ r.newline
1615
+
1616
+ r.write_text("Other notable features of wxRichTextCtrl include:")
1617
+ r.newline
1618
+
1619
+ r.begin_symbol_bullet('*', 100, 60)
1620
+ r.write_text("Compatibility with wxTextCtrl API")
1621
+ r.newline
1622
+ r.end_symbol_bullet
1623
+
1624
+ r.begin_symbol_bullet('*', 100, 60)
1625
+ r.write_text("Easy stack-based BeginXXX()...EndXXX() style setting in addition to SetStyle()")
1626
+ r.newline
1627
+ r.end_symbol_bullet
1628
+
1629
+ r.begin_symbol_bullet('*', 100, 60)
1630
+ r.write_text("XML loading and saving")
1631
+ r.newline
1632
+ r.end_symbol_bullet
1633
+
1634
+ r.begin_symbol_bullet('*', 100, 60)
1635
+ r.write_text("Undo/Redo, with batching option and Undo suppressing")
1636
+ r.newline
1637
+ r.end_symbol_bullet
1638
+
1639
+ r.begin_symbol_bullet('*', 100, 60)
1640
+ r.write_text("Clipboard copy and paste")
1641
+ r.newline
1642
+ r.end_symbol_bullet
1643
+
1644
+ r.begin_symbol_bullet('*', 100, 60)
1645
+ r.write_text("wxRichTextStyleSheet with named character and paragraph styles, and control for applying named styles")
1646
+ r.newline
1647
+ r.end_symbol_bullet
1648
+
1649
+ r.begin_symbol_bullet('*', 100, 60)
1650
+ r.write_text("A design that can easily be extended to other content types, ultimately with text boxes, tables, controls, and so on")
1651
+ r.newline
1652
+ r.end_symbol_bullet
1653
+
1654
+ # Make a style suitable for showing a URL
1655
+ urlStyle = Wx::RichTextAttr.new
1656
+ urlStyle.set_text_colour(:BLUE)
1657
+ urlStyle.set_font_underlined(true)
1658
+
1659
+ r.write_text("wxRichTextCtrl can also display URLs, such as this one: ")
1660
+ r.begin_style(urlStyle)
1661
+ r.begin_url("http:#www.wxwidgets.org")
1662
+ r.write_text("The wxWidgets Web Site")
1663
+ r.end_url
1664
+ r.end_style
1665
+ r.write_text(". Click on the URL to generate an event.")
1666
+
1667
+ r.newline
1668
+
1669
+ r.write_text("Note: this sample content was generated programmatically from within the MyFrame constructor in the demo. The images were loaded from inline XPMs. Enjoy wxRichTextCtrl!\n")
1670
+
1671
+ r.end_paragraph_spacing
1672
+
1673
+ # Add a text box
1674
+
1675
+ r.newline
1676
+
1677
+ attr1 = Wx::RichTextAttr.new
1678
+ attr1.get_text_box_attr.margins.left.set_value(20, Wx::TEXT_ATTR_UNITS_PIXELS)
1679
+ attr1.get_text_box_attr.margins.top.set_value(20, Wx::TEXT_ATTR_UNITS_PIXELS)
1680
+ attr1.get_text_box_attr.margins.right.set_value(20, Wx::TEXT_ATTR_UNITS_PIXELS)
1681
+ attr1.get_text_box_attr.margins.bottom.set_value(20, Wx::TEXT_ATTR_UNITS_PIXELS)
1682
+
1683
+ attr1.get_text_box_attr.border.set_colour(:BLACK)
1684
+ attr1.get_text_box_attr.border.set_width(1, Wx::TEXT_ATTR_UNITS_PIXELS)
1685
+ attr1.get_text_box_attr.border.set_style(Wx::TEXT_BOX_ATTR_BORDER_SOLID)
1686
+
1687
+ textBox = r.write_text_box(attr1)
1688
+ r.set_focus_object(textBox)
1689
+
1690
+ r.write_text("This is a text box. Just testing! Once more unto the breach, dear friends, once more...")
1691
+
1692
+ r.set_focus_object(nil) # Set the focus back to the main buffer
1693
+ r.set_insertion_point_end
1694
+
1695
+ # Add a table
1696
+
1697
+ r.newline
1698
+
1699
+ attr1 = Wx::RichTextAttr.new
1700
+ attr1.get_text_box_attr.margins.left.set_value(5, Wx::TEXT_ATTR_UNITS_PIXELS)
1701
+ attr1.get_text_box_attr.margins.top.set_value(5, Wx::TEXT_ATTR_UNITS_PIXELS)
1702
+ attr1.get_text_box_attr.margins.right.set_value(5, Wx::TEXT_ATTR_UNITS_PIXELS)
1703
+ attr1.get_text_box_attr.margins.bottom.set_value(5, Wx::TEXT_ATTR_UNITS_PIXELS)
1704
+ attr1.get_text_box_attr.padding.apply(attr.get_text_box_attr.margins)
1705
+
1706
+ attr1.get_text_box_attr.border.set_colour(:BLACK)
1707
+ attr1.get_text_box_attr.border.set_width(1, Wx::TEXT_ATTR_UNITS_PIXELS)
1708
+ attr1.get_text_box_attr.border.set_style(Wx::TEXT_BOX_ATTR_BORDER_SOLID)
1709
+
1710
+ cellAttr = Wx::RichTextAttr.new(attr1)
1711
+ cellAttr.get_text_box_attr.width.set_value(200, Wx::TEXT_ATTR_UNITS_PIXELS)
1712
+ cellAttr.get_text_box_attr.height.set_value(150, Wx::TEXT_ATTR_UNITS_PIXELS)
1713
+
1714
+ table = r.write_table(6, 4, attr1, cellAttr)
1715
+
1716
+ table.get_row_count.times do |j|
1717
+ table.get_column_count.times do |i|
1718
+ msg = "This is cell %d, %d" % [(j+1), (i+1)]
1719
+ r.set_focus_object(table.cell(j, i))
1720
+ r.write_text(msg)
1721
+ end
1722
+ end
1723
+
1724
+ # Demonstrate colspan and rowspan
1725
+ cell = table.cell(1, 0)
1726
+ cell.set_col_span(2)
1727
+ r.set_focus_object(cell)
1728
+ cell.clear
1729
+ r.write_text("This cell spans 2 columns")
1730
+
1731
+ cell = table.cell(1, 3)
1732
+ cell.set_row_span(2)
1733
+ r.set_focus_object(cell)
1734
+ cell.clear
1735
+ r.write_text("This cell spans 2 rows")
1736
+
1737
+ cell = table.cell(2, 1)
1738
+ cell.set_col_span(2)
1739
+ cell.set_row_span(3)
1740
+ r.set_focus_object(cell)
1741
+ cell.clear
1742
+ r.write_text("This cell spans 2 columns and 3 rows")
1743
+
1744
+ r.set_focus_object(nil) # Set the focus back to the main buffer
1745
+ r.set_insertion_point_end
1746
+
1747
+ r.newline; r.newline
1748
+
1749
+ properties = Wx::RTC::RichTextProperties.new
1750
+ r.write_text("This is a rectangle field: ")
1751
+ r.write_field("rectangle", properties)
1752
+ r.write_text(" and a begin section field: ")
1753
+ r.write_field("begin-section", properties)
1754
+ r.write_text("This is text between the two tags.")
1755
+ r.write_field("end-section", properties)
1756
+ r.write_text(" Now a bitmap. ")
1757
+ r.write_field("bitmap", properties)
1758
+ r.write_text(" Before we go, here's a composite field: ***")
1759
+ field = r.write_field("composite", properties)
1760
+ field.update_field(r.get_buffer) # Creates the composite value (sort of a text box)
1761
+ r.write_text("*** End of composite field.")
1762
+
1763
+ r.newline
1764
+ r.end_suppress_undo
1765
+
1766
+ # Add some locked content first - needs Undo to be enabled
1767
+ r.begin_lock
1768
+ r.write_text("This is a locked object.")
1769
+ r.end_lock
1770
+
1771
+ r.write_text(" This is unlocked text. ")
1772
+
1773
+ r.begin_lock
1774
+ r.write_text("More locked content.")
1775
+ r.end_lock
1776
+ r.newline
1777
+
1778
+ # Flush the Undo buffer
1779
+ r.command_processor.clear_commands
1780
+
1781
+ r.thaw
1782
+ end
1783
+
1784
+ end
1785
+
1786
+ module RichTextExtSample
1787
+
1788
+ include WxRuby::Sample if defined? WxRuby::Sample
1789
+
1790
+ def self.describe
1791
+ { file: __FILE__,
1792
+ summary: 'wxRuby extended Wx::RichTextCtrl demo.',
1793
+ description: <<~__HEREDOC
1794
+ Extended wxRuby sample for Wx::RichTextCtrl
1795
+ It includes the following functionality:
1796
+
1797
+ * Text entry, paragraph wrapping
1798
+ * Scrolling, keyboard navigation
1799
+ * Application of character styles:
1800
+ bold, italic, underlined, font face, text colour
1801
+ * Application of paragraph styles:
1802
+ left/right indentation, sub-indentation (first-line indent),
1803
+ paragraph spacing (before and after), line spacing,
1804
+ left/centre/right alignment, numbered bullets
1805
+ * Insertion of images
1806
+ * Copy/paste
1807
+ * Undo/Redo with optional batching and undo history suppression
1808
+ * Named paragraph and character styles management and application
1809
+ * File handlers allow addition of file formats
1810
+ * Text saving and loading, XML saving and loading, HTML saving (unfinished)
1811
+ * etc.
1812
+ __HEREDOC
1813
+ }
1814
+ end
1815
+
1816
+ def self.run
1817
+ execute(__FILE__)
1818
+ end
1819
+
1820
+ if $0 == __FILE__
1821
+ MyApp.run
1822
+ end
1823
+
1824
+ end