wxruby3 0.9.0.pre.beta.13 → 0.9.0.pre.rc.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +1 -0
  3. data/README.md +47 -4
  4. data/assets/hello_button.png +0 -0
  5. data/assets/hello_button_clicked.png +0 -0
  6. data/assets/hello_world.png +0 -0
  7. data/assets/repo-social-preview.png +0 -0
  8. data/ext/wxruby3/include/wxruby-runtime.h +1 -0
  9. data/ext/wxruby3/swig/memory_management.i +6 -10
  10. data/ext/wxruby3/swig/wx.i +17 -6
  11. data/lib/wx/accessors.rb +8 -2
  12. data/lib/wx/core/art_locator.rb +2 -2
  13. data/lib/wx/core/artprovider.rb +2 -2
  14. data/lib/wx/core/bitmap.rb +6 -5
  15. data/lib/wx/core/bitmap_combobox.rb +34 -0
  16. data/lib/wx/core/controlwithitems.rb +52 -14
  17. data/lib/wx/core/cursor.rb +1 -1
  18. data/lib/wx/core/dc.rb +0 -20
  19. data/lib/wx/core/event_blocker.rb +14 -0
  20. data/lib/wx/core/evthandler.rb +36 -0
  21. data/lib/wx/core/find_replace_dialog.rb +24 -0
  22. data/lib/wx/core/icon.rb +1 -1
  23. data/lib/wx/core/image.rb +1 -1
  24. data/lib/wx/core/paintdc.rb +8 -0
  25. data/lib/wx/core/text_entry.rb +15 -0
  26. data/lib/wx/core/v_list_box.rb +13 -0
  27. data/lib/wx/core/window.rb +1 -1
  28. data/lib/wx/doc/busy_info.rb +21 -0
  29. data/lib/wx/doc/client_dc.rb +28 -0
  30. data/lib/wx/doc/controlwithitems.rb +11 -0
  31. data/lib/wx/doc/dc.rb +0 -14
  32. data/lib/wx/doc/event_blocker.rb +27 -0
  33. data/lib/wx/doc/evthandler.rb +4 -0
  34. data/lib/wx/doc/extra/02_lifecycles.md +49 -0
  35. data/lib/wx/doc/extra/10_art.md +1 -1
  36. data/lib/wx/doc/extra/11_drawing_and_dc.md +62 -0
  37. data/lib/wx/doc/memory_dc.rb +75 -0
  38. data/lib/wx/doc/mirror_dc.rb +16 -0
  39. data/lib/wx/doc/prt/printer_dc.rb +26 -0
  40. data/lib/wx/doc/screen_dc.rb +10 -6
  41. data/lib/wx/doc/svg_file_dc.rb +20 -0
  42. data/lib/wx/doc/v_list_box.rb +9 -0
  43. data/lib/wx/doc/window_disabler.rb +10 -0
  44. data/lib/wx/global_const.rb +24 -18
  45. data/lib/wx/html/keyword_defs.rb +6 -7
  46. data/lib/wx/html/require.rb +1 -0
  47. data/lib/wx/html/simple_html_listbox.rb +105 -0
  48. data/lib/wx/keyword_defs.rb +7 -0
  49. data/lib/wx/version.rb +1 -1
  50. data/lib/wx/wxruby/cmd/test.rb +1 -1
  51. data/rakelib/install.rb +3 -1
  52. data/rakelib/lib/core/mapping.rb +5 -5
  53. data/rakelib/lib/core/spec.rb +7 -3
  54. data/rakelib/lib/core/spec_helper.rb +9 -1
  55. data/rakelib/lib/director/accelerator.rb +1 -1
  56. data/rakelib/lib/director/app.rb +25 -3
  57. data/rakelib/lib/director/art_provider.rb +5 -1
  58. data/rakelib/lib/director/aui_pane_info.rb +1 -1
  59. data/rakelib/lib/director/aui_tab_ctrl.rb +1 -1
  60. data/rakelib/lib/director/bitmap.rb +2 -1
  61. data/rakelib/lib/director/bitmap_combobox.rb +32 -0
  62. data/rakelib/lib/director/brush.rb +1 -0
  63. data/rakelib/lib/director/busy_info.rb +1 -1
  64. data/rakelib/lib/director/choice.rb +1 -0
  65. data/rakelib/lib/director/clipboard.rb +1 -1
  66. data/rakelib/lib/director/colour.rb +1 -0
  67. data/rakelib/lib/director/colour_picker_ctrl.rb +1 -1
  68. data/rakelib/lib/director/combobox.rb +1 -2
  69. data/rakelib/lib/director/ctrl_with_items.rb +3 -0
  70. data/rakelib/lib/director/cursor.rb +1 -0
  71. data/rakelib/lib/director/data_object.rb +5 -7
  72. data/rakelib/lib/director/dc.rb +5 -1
  73. data/rakelib/lib/director/defs.rb +3 -0
  74. data/rakelib/lib/director/derived_dc.rb +278 -27
  75. data/rakelib/lib/director/dialog.rb +4 -1
  76. data/rakelib/lib/director/dir_picker_ctrl.rb +1 -1
  77. data/rakelib/lib/director/event.rb +3 -3
  78. data/rakelib/lib/director/event_blocker.rb +41 -0
  79. data/rakelib/lib/director/event_filter.rb +20 -0
  80. data/rakelib/lib/director/event_handler.rb +29 -2
  81. data/rakelib/lib/director/file_picker_ctrl.rb +1 -1
  82. data/rakelib/lib/director/find_replace_data.rb +1 -0
  83. data/rakelib/lib/director/font.rb +2 -1
  84. data/rakelib/lib/director/font_data.rb +1 -0
  85. data/rakelib/lib/director/font_picker_ctrl.rb +1 -1
  86. data/rakelib/lib/director/gdi_object.rb +1 -0
  87. data/rakelib/lib/director/graphics_context.rb +6 -6
  88. data/rakelib/lib/director/grid_table_message.rb +1 -1
  89. data/rakelib/lib/director/html_cell.rb +1 -1
  90. data/rakelib/lib/director/html_data_object.rb +5 -7
  91. data/rakelib/lib/director/html_listbox.rb +65 -1
  92. data/rakelib/lib/director/icon.rb +2 -0
  93. data/rakelib/lib/director/listbox.rb +1 -0
  94. data/rakelib/lib/director/locale.rb +2 -1
  95. data/rakelib/lib/director/palette.rb +1 -0
  96. data/rakelib/lib/director/pen.rb +2 -1
  97. data/rakelib/lib/director/pgproperties.rb +1 -1
  98. data/rakelib/lib/director/pgproperty.rb +1 -1
  99. data/rakelib/lib/director/pgvalidation_info.rb +1 -1
  100. data/rakelib/lib/director/platform_info.rb +1 -1
  101. data/rakelib/lib/director/print_data.rb +1 -1
  102. data/rakelib/lib/director/property_grid_interface.rb +1 -1
  103. data/rakelib/lib/director/property_grid_page_state.rb +1 -1
  104. data/rakelib/lib/director/region.rb +1 -0
  105. data/rakelib/lib/director/ribbon_art_provider.rb +1 -1
  106. data/rakelib/lib/director/richtext_buffer_data_object.rb +5 -7
  107. data/rakelib/lib/director/richtext_header_footer_data.rb +1 -1
  108. data/rakelib/lib/director/searchctrl.rb +24 -0
  109. data/rakelib/lib/director/sizer.rb +2 -2
  110. data/rakelib/lib/director/styled_text_ctrl.rb +2 -0
  111. data/rakelib/lib/director/text_entry.rb +2 -2
  112. data/rakelib/lib/director/tree_ctrl.rb +6 -3
  113. data/rakelib/lib/director/uiaction_simulator.rb +20 -0
  114. data/rakelib/lib/director/variant.rb +1 -1
  115. data/rakelib/lib/director/vlistbox.rb +25 -0
  116. data/rakelib/lib/director/window.rb +0 -6
  117. data/rakelib/lib/director/with_images.rb +1 -1
  118. data/rakelib/lib/director/xml_node.rb +1 -1
  119. data/rakelib/lib/extractor/function.rb +5 -3
  120. data/rakelib/lib/generate/doc/about_dialog_info.yaml +46 -0
  121. data/rakelib/lib/generate/doc/accelerator.yaml +21 -0
  122. data/rakelib/lib/generate/doc/art_provider.yaml +35 -0
  123. data/rakelib/lib/generate/doc/bitmap.yaml +37 -0
  124. data/rakelib/lib/generate/doc/box_sizer.yaml +15 -0
  125. data/rakelib/lib/generate/doc/busy_info.yaml +74 -0
  126. data/rakelib/lib/generate/doc/client_dc.yaml +19 -0
  127. data/rakelib/lib/generate/doc/clipboard.yaml +43 -0
  128. data/rakelib/lib/generate/doc/collapsible_pane.yaml +21 -0
  129. data/rakelib/lib/generate/doc/colour_dialog.yaml +32 -0
  130. data/rakelib/lib/generate/doc/control.yaml +46 -0
  131. data/rakelib/lib/generate/doc/cursor.yaml +40 -0
  132. data/rakelib/lib/generate/doc/data_object.yaml +55 -0
  133. data/rakelib/lib/generate/doc/dc.yaml +14 -0
  134. data/rakelib/lib/generate/doc/dialog.yaml +36 -0
  135. data/rakelib/lib/generate/doc/dir_dialog.yaml +25 -0
  136. data/rakelib/lib/generate/doc/events.yaml +152 -0
  137. data/rakelib/lib/generate/doc/evt_handler.yaml +63 -0
  138. data/rakelib/lib/generate/doc.rb +77 -14
  139. data/rakelib/lib/generate/interface.rb +11 -0
  140. data/rakelib/lib/specs/interfaces.rb +5 -4
  141. data/rakelib/lib/swig_runner.rb +3 -3
  142. data/rakelib/lib/typemap/common.rb +15 -3
  143. data/rakelib/lib/util/string.rb +1 -0
  144. data/rakelib/yard/yard/relative_markdown_links.rb +5 -1
  145. data/samples/bigdemo/wxArtProvider.rbw +5 -4
  146. data/samples/controls/controls.rb +2 -2
  147. data/samples/controls/htlbox.rb +411 -0
  148. data/samples/controls/tn_htlbox.png +0 -0
  149. data/samples/drawing/graphics_drawing.rb +1 -2
  150. data/samples/drawing/{svgtest.rb → image_prt.rb} +49 -18
  151. data/samples/drawing/tn_image_prt.png +0 -0
  152. data/samples/propgrid/propgrid.rb +23 -21
  153. data/samples/ribbon/ribbon.rb +47 -46
  154. data/tests/lib/wxapp_runner.rb +3 -3
  155. data/tests/lib/wxframe_runner.rb +59 -0
  156. data/tests/test_app_event_filter.rb +74 -0
  157. data/tests/test_art_provider.rb +52 -0
  158. data/tests/test_clipboard.rb +2 -1
  159. data/tests/test_event_handling.rb +199 -16
  160. data/tests/test_events.rb +4 -11
  161. data/tests/test_gdi_object.rb +161 -0
  162. data/tests/test_intl.rb +11 -14
  163. data/tests/test_item_data.rb +33 -1
  164. data/tests/test_std_controls.rb +147 -0
  165. metadata +56 -4
  166. data/samples/drawing/tn_svgtest.png +0 -0
@@ -0,0 +1,411 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) M.J.N. Corino, The Netherlands
3
+ ###
4
+
5
+ require 'wx'
6
+
7
+ # to use Wx::HtmlListBox you must derive a new class from it as you must
8
+ # implement virtual on_get_item
9
+ class MyHtmlListBox < Wx::HTML::HtmlListBox
10
+
11
+ def initialize(parent, multi = false)
12
+ super(parent, style: multi ? Wx::LB_MULTIPLE : 0)
13
+ # flag telling us whether we should use fg colour even for the selected
14
+ # item
15
+ @change = false
16
+ # flag which we toggle to update the first items text in on_get_item()
17
+ @first_item_updated = false
18
+ @link_clicked = false
19
+
20
+ set_margins(5, 5)
21
+
22
+ set_item_count(1000)
23
+
24
+ set_selection(3)
25
+ end
26
+
27
+ attr_accessor :link_clicked
28
+
29
+ def set_change_sel_fg(change)
30
+ @change = change
31
+ end
32
+
33
+ def update_first_item
34
+ @first_item_updated = !@first_item_updated
35
+
36
+ refresh_row(0)
37
+ end
38
+
39
+ protected
40
+
41
+ # override this method to return data to be shown in the listbox (this is
42
+ # mandatory)
43
+ def on_get_item(n)
44
+ return '<h1><b>Just updated</b></h1>' if n == 0 && @first_item_updated
45
+
46
+ level = n % 6 + 1
47
+
48
+ clr = Wx::Colour.new((n - 192).abs % 256,
49
+ (n - 256).abs % 256,
50
+ (n - 128).abs % 256)
51
+
52
+ label = "<h#{level}><font color=#{clr.get_as_string(Wx::C2S_HTML_SYNTAX)}>Item</font> <b>#{n}</b></h#{level}>"
53
+ if n == 1
54
+ if !@link_clicked
55
+ label += "<a href='1'>Click here...</a>"
56
+ else
57
+ label += "<font color='#9999ff'>Clicked here...</font>"
58
+ end
59
+ end
60
+
61
+ label
62
+ end
63
+
64
+ # change the appearance by overriding these functions (this is optional)
65
+ def on_draw_separator(dc, rect, _)
66
+ if get_parent.menu_bar.is_checked(MyFrame::ID::HtmlLbox_DrawSeparator)
67
+ dc.with_pen(Wx::BLACK_DASHED_PEN) do
68
+ dc.draw_line(rect.x, rect.y, rect.right, rect.y)
69
+ dc.draw_line(rect.x, rect.bottom, rect.right, rect.bottom)
70
+ end
71
+ end
72
+ end
73
+
74
+ def get_selected_text_colour(col_fg)
75
+ @change ? super : col_fg
76
+ end
77
+
78
+ end
79
+
80
+ class MyFrame < Wx::Frame
81
+
82
+ # IDs for the controls and the menu commands
83
+ module ID
84
+ include Wx::IDHelper
85
+ # menu items
86
+ HtmlLbox_CustomBox = self.next_id
87
+ HtmlLbox_SimpleBox = self.next_id
88
+ HtmlLbox_Quit = self.next_id
89
+
90
+ HtmlLbox_SetMargins = self.next_id
91
+ HtmlLbox_DrawSeparator = self.next_id
92
+ HtmlLbox_ToggleMulti = self.next_id
93
+ HtmlLbox_SelectAll = self.next_id
94
+ HtmlLbox_UpdateItem = self.next_id
95
+ HtmlLbox_GetItemRect = self.next_id
96
+
97
+ HtmlLbox_SetBgCol = self.next_id
98
+ HtmlLbox_SetSelBgCol = self.next_id
99
+ HtmlLbox_SetSelFgCol = self.next_id
100
+
101
+ HtmlLbox_Clear = self.next_id
102
+
103
+ # it is important for the id corresponding to the "About" command to have
104
+ # this standard value as otherwise it won't be handled properly under Mac
105
+ # (where it is special and put into the "Apple" menu)
106
+ HtmlLbox_About = Wx::ID_ABOUT
107
+ end
108
+
109
+ Wx::ArtLocator.add_search_path(File.dirname(__dir__))
110
+
111
+ def initialize
112
+ super(nil, title: 'HtmlLbox wxWidgets Sample',size: [500, 500])
113
+
114
+ # set the frame icon
115
+ set_icon(Wx::Icon(:sample))
116
+
117
+ if Wx.has_feature?(:USE_MENUS)
118
+
119
+ # create a menu bar
120
+ menu_file = Wx::Menu.new
121
+ menu_file.append_radio_item(ID::HtmlLbox_CustomBox, "Use custom box",
122
+ "Use a wxHtmlListBox virtual class control")
123
+ menu_file.append_radio_item(ID::HtmlLbox_SimpleBox, "Use simple box",
124
+ "Use a wxSimpleHtmlListBox control")
125
+ menu_file.append_separator
126
+ menu_file.append(ID::HtmlLbox_Quit, "E&xit\tAlt-X", "Quit this program")
127
+
128
+ # create our specific menu
129
+ menu_hl_box = Wx::Menu.new
130
+ menu_hl_box.append(ID::HtmlLbox_SetMargins, "Set &margins...\tCtrl-G", "Change the margins around the items")
131
+ menu_hl_box.append_check_item(ID::HtmlLbox_DrawSeparator,
132
+ "&Draw separators\tCtrl-D" ,
133
+ "Toggle drawing separators between cells")
134
+ menu_hl_box.append_separator
135
+ menu_hl_box.append_check_item(ID::HtmlLbox_ToggleMulti,
136
+ "&Multiple selection\tCtrl-M",
137
+ "Toggle multiple selection on/off")
138
+ menu_hl_box.append_separator
139
+ menu_hl_box.append(ID::HtmlLbox_SelectAll, "Select &all items\tCtrl-A")
140
+ menu_hl_box.append(ID::HtmlLbox_UpdateItem, "Update &first item\tCtrl-U")
141
+ menu_hl_box.append(ID::HtmlLbox_GetItemRect, "Show &rectangle of item #10\tCtrl-R")
142
+ menu_hl_box.append_separator
143
+ menu_hl_box.append(ID::HtmlLbox_SetBgCol, "Set &background...\tCtrl-B")
144
+ menu_hl_box.append(ID::HtmlLbox_SetSelBgCol,
145
+ "Set &selection background...\tCtrl-S")
146
+ menu_hl_box.append_check_item(ID::HtmlLbox_SetSelFgCol,
147
+ "Keep &foreground in selection\tCtrl-F")
148
+
149
+ menu_hl_box.append_separator
150
+ menu_hl_box.append(ID::HtmlLbox_Clear, "&Clear\tCtrl-L")
151
+
152
+ # the "About" item should be in the help menu
153
+ help_menu = Wx::Menu.new
154
+ help_menu.append(ID::HtmlLbox_About, "&About\tF1", "Show about dialog")
155
+
156
+ # now append the freshly created menu to the menu bar...
157
+ mbar = Wx::MenuBar.new
158
+ mbar.append(menu_file, "&File")
159
+ mbar.append(menu_hl_box, "&Listbox")
160
+ mbar.append(help_menu, "&Help")
161
+
162
+ mbar.check(ID::HtmlLbox_DrawSeparator, true)
163
+
164
+ # ... and attach this menu bar to the frame
165
+ self.menu_bar = mbar
166
+
167
+ end # USE_MENUS
168
+
169
+ if Wx.has_feature?(:USE_STATUSBAR)
170
+ # create a status bar just for fun (by default with 1 pane only)
171
+ create_status_bar(2)
172
+ set_status_text("Welcome to wxWidgets!")
173
+ end # USE_STATUSBAR
174
+
175
+ # create the child controls
176
+ create_box
177
+ text = Wx::TextCtrl.new(self, Wx::ID_ANY, "", style: Wx::TE_MULTILINE)
178
+ Wx::Log.set_active_target(Wx::LogTextCtrl.new(text))
179
+
180
+ # and lay them out
181
+ sizer = Wx::HBoxSizer.new
182
+ sizer.add(@hlbox, 2, Wx::GROW)
183
+ sizer.add(text, 3, Wx::GROW)
184
+
185
+ self.sizer = sizer
186
+
187
+ evt_menu ID::HtmlLbox_CustomBox, :on_simple_or_custom_box
188
+ evt_menu ID::HtmlLbox_SimpleBox, :on_simple_or_custom_box
189
+ evt_menu ID::HtmlLbox_Quit, :on_quit
190
+
191
+ evt_menu ID::HtmlLbox_SetMargins, :on_set_margins
192
+ evt_menu ID::HtmlLbox_DrawSeparator, :on_draw_separator
193
+ evt_menu ID::HtmlLbox_ToggleMulti, :on_toggle_multi
194
+ evt_menu ID::HtmlLbox_SelectAll, :on_select_all
195
+ evt_menu ID::HtmlLbox_UpdateItem, :on_update_item
196
+ evt_menu ID::HtmlLbox_GetItemRect, :on_get_item_rect
197
+
198
+ evt_menu ID::HtmlLbox_About, :on_about
199
+
200
+ evt_menu ID::HtmlLbox_SetBgCol, :on_set_bg_col
201
+ evt_menu ID::HtmlLbox_SetSelBgCol, :on_set_sel_bg_col
202
+ evt_menu ID::HtmlLbox_SetSelFgCol, :on_set_sel_fg_col
203
+
204
+ evt_menu ID::HtmlLbox_Clear, :on_clear
205
+
206
+ evt_update_ui ID::HtmlLbox_SelectAll, :on_update_ui_select_all
207
+
208
+ evt_listbox Wx::ID_ANY, :on_lbox_select
209
+ evt_listbox_dclick Wx::ID_ANY, :on_lbox_d_click
210
+
211
+ # the HTML listbox's events
212
+ evt_html_link_clicked Wx::ID_ANY, :on_html_link_clicked
213
+ evt_html_cell_hover Wx::ID_ANY, :on_html_cell_hover
214
+ evt_html_cell_clicked Wx::ID_ANY, :on_html_cell_clicked
215
+ end
216
+
217
+ # event handlers
218
+ def on_simple_or_custom_box(event)
219
+ old = @hlbox
220
+
221
+ # we need to recreate the listbox
222
+ create_box
223
+ get_sizer.replace(old, @hlbox)
224
+ old.destroy
225
+
226
+ get_sizer.layout
227
+ refresh
228
+ end
229
+ def on_quit(event)
230
+ # true is to force the frame to close
231
+ close(true)
232
+ end
233
+ def on_about(event)
234
+ Wx.message_box("This sample shows Wx::HtmlListBox class.\n"+
235
+ "\n"+
236
+ "(c) 2023 Martin Corino\n" +
237
+ "(original (c) 2003 Vadim Zeitlin)\n",
238
+ "About HtmlLbox",
239
+ Wx::OK | Wx::ICON_INFORMATION,
240
+ self)
241
+ end
242
+
243
+ def on_set_margins(event)
244
+ margin = Wx.get_number_from_user(
245
+ "Enter the margins to use for the listbox items.",
246
+ "Margin: ",
247
+ "HtmlLbox: Set the margins",
248
+ 0, 0, 20,
249
+ self)
250
+
251
+ if margin != -1
252
+ @hlbox.set_margins(margin, margin)
253
+ @hlbox.refresh_all
254
+ end
255
+ end
256
+ def on_draw_separator(_event)
257
+ @hlbox.refresh_all
258
+ end
259
+ def on_toggle_multi(event)
260
+ old = @hlbox
261
+
262
+ # we need to recreate the listbox
263
+ create_box
264
+ get_sizer.replace(old, @hlbox)
265
+ old.destroy
266
+
267
+ get_sizer.layout
268
+ end
269
+ def on_select_all(event)
270
+ @hlbox.select_all
271
+ end
272
+ def on_update_item(event)
273
+ @hlbox.update_first_item if @hlbox.is_a?(MyHtmlListBox)
274
+ end
275
+
276
+ def on_get_item_rect(event)
277
+ r = @hlbox.get_item_rect(10)
278
+ Wx.log_message("Rect of item %d: (%d, %d)-(%d, %d)",
279
+ 10, r.x, r.y, r.x + r.width, r.y + r.height)
280
+ end
281
+
282
+ def on_set_bg_col(event)
283
+ col = Wx.get_colour_from_user(self, @hlbox.get_background_colour)
284
+ if col.ok?
285
+ @hlbox.set_background_colour(col)
286
+ @hlbox.refresh
287
+
288
+ if Wx.has_feature?(:USE_STATUSBAR)
289
+ set_status_text("Background colour changed.")
290
+ end # wxUSE_STATUSBAR
291
+ end
292
+ end
293
+ def on_set_sel_bg_col(event)
294
+ col = Wx.get_colour_from_user(self, @hlbox.get_selection_background)
295
+ if col.ok?
296
+ @hlbox.set_selection_background(col)
297
+ @hlbox.refresh
298
+
299
+ if Wx.has_feature?(:USE_STATUSBAR)
300
+ set_status_text("Selection Background colour changed.")
301
+ end # wxUSE_STATUSBAR
302
+ end
303
+ end
304
+ def on_set_sel_fg_col(event)
305
+ if @hlbox.is_a?(MyHtmlListBox)
306
+ @hlbox.set_change_sel_fg(!event.checked?)
307
+ @hlbox.refresh
308
+ end
309
+ end
310
+
311
+ def on_clear(event)
312
+ @hlbox.clear
313
+ end
314
+
315
+ def on_update_ui_select_all(event)
316
+ event.enable(@hlbox && @hlbox.has_multiple_selection)
317
+ end
318
+
319
+ def on_lbox_select(event)
320
+ Wx.log_message("Listbox selection is now %d.", event.get_int)
321
+
322
+ if @hlbox.has_multiple_selection
323
+ s = ''
324
+ @hlbox.each_selected do |item|
325
+ s << ', ' unless s.empty?
326
+ s << item.to_s
327
+ end
328
+ Wx.log_message("Selected items: #{s}") unless s.empty?
329
+ end
330
+
331
+ if Wx.has_feature?(:USE_STATUSBAR)
332
+ set_status_text("# items selected = #{@hlbox.get_selected_count}")
333
+ end # wxUSE_STATUSBAR
334
+ end
335
+
336
+ def on_lbox_d_click(event)
337
+ Wx.log_message("Listbox item #{event.get_int} double clicked.")
338
+ end
339
+
340
+ def on_html_link_clicked(event)
341
+ Wx.log_message("The url '%s' has been clicked!", event.get_link_info.get_href)
342
+
343
+ if @hlbox.is_a?(MyHtmlListBox)
344
+ @hlbox.link_clicked = true
345
+ @hlbox.refresh_row(1)
346
+ end
347
+ end
348
+ def on_html_cell_hover(event)
349
+ Wx.log_message("Mouse moved over cell %s at %d;%d",
350
+ event.get_cell.id, event.get_point.x, event.get_point.y)
351
+ end
352
+ def on_html_cell_clicked(event)
353
+ Wx.log_message("Click over cell %s at %d;%d",
354
+ event.get_cell.id, event.get_point.x, event.get_point.y)
355
+
356
+ # if we don't skip the event, OnHtmlLinkClicked won't be called!
357
+ event.skip
358
+ end
359
+
360
+ def create_box
361
+ multi = get_menu_bar.is_checked(ID::HtmlLbox_ToggleMulti)
362
+
363
+ if get_menu_bar.is_checked(ID::HtmlLbox_CustomBox)
364
+ @hlbox = MyHtmlListBox.new(self, multi)
365
+ else # simple listbox
366
+ @hlbox = Wx::HTML::SimpleHtmlListBox.new(self, style: multi ? Wx::LB_MULTIPLE : 0)
367
+
368
+ # unlike Wx::HTML::HtmlListBox which is abstract, Wx::HTML::SimpleHtmlListBox is a
369
+ # concrete control and doesn't support virtual mode, this we need
370
+ # to add all of its items from the beginning
371
+ arr = []
372
+ 1000.times do |n|
373
+ clr = Wx::Colour.new((n - 192).abs % 256,
374
+ (n - 256).abs % 256,
375
+ (n - 128).abs % 256)
376
+ level = n % 6 + 1
377
+
378
+ label = "<h#{level}><font color=#{clr.get_as_string(Wx::C2S_HTML_SYNTAX)}>Item</font> <b>#{n}</b></h#{level}>"
379
+ arr << label
380
+ end
381
+
382
+ @hlbox.append(arr)
383
+ end
384
+ end
385
+
386
+ end
387
+
388
+ module HtmlListBoxSample
389
+
390
+ include WxRuby::Sample if defined? WxRuby::Sample
391
+
392
+ def self.describe
393
+ { file: __FILE__,
394
+ summary: 'wxRuby HtmlListBox control example.',
395
+ description: "wxRuby example showcasing the HtmlListBox controls.\n"+
396
+ " - Wx::HtmlListBox\n"+
397
+ " - Wx::SimpleHtmlListBox\n"
398
+ }
399
+ end
400
+
401
+ def self.activate
402
+ frame = MyFrame.new
403
+ frame.show
404
+ frame
405
+ end
406
+
407
+ if $0 == __FILE__
408
+ Wx::App.run { HtmlListBoxSample.activate }
409
+ end
410
+
411
+ end
Binary file
@@ -108,8 +108,7 @@ class GraphicsWindow < Wx::Window
108
108
  @rtxt[:font] = gdc.create_font(@font,Wx::RED); @rtxt[:txt] = "This is a red string"
109
109
  @gtxt[:font] = gdc.create_font(@font,Wx::GREEN); @gtxt[:txt] = "This is a green string"
110
110
  @btxt[:font] = gdc.create_font(@font,Wx::BLUE); @btxt[:txt] = "This is a blue string"
111
- # Create the GraphicsContext resources. For some reason, unable to utilize
112
- # GraphicsContext#create(wxWindow) to create these resources in initialize.
111
+ # Create the GraphicsContext resources.
113
112
  @rbrush = gdc.create_brush(RED_BRUSH)
114
113
  @gbrush = gdc.create_brush(GREEN_BRUSH)
115
114
  @bbrush = gdc.create_brush(BLUE_BRUSH)
@@ -4,7 +4,7 @@
4
4
 
5
5
  require 'wx'
6
6
 
7
- class SVGPage < Wx::ScrolledWindow
7
+ class ImagePage < Wx::ScrolledWindow
8
8
 
9
9
  PAGES = [
10
10
  'Lines',
@@ -41,9 +41,36 @@ class SVGPage < Wx::ScrolledWindow
41
41
  end
42
42
 
43
43
  def on_save(filename)
44
- svgDC = Wx::SVGFileDC.new(filename, 600, 650)
45
- on_draw(svgDC)
46
- svgDC.ok?
44
+ case File.extname(filename)
45
+ when '.svg'
46
+ Wx::SVGFileDC.draw_on(filename, 600, 650) do |svgDC|
47
+ on_draw(svgDC)
48
+ svgDC.ok?
49
+ end
50
+ when '.ps'
51
+ print_data = Wx::PRT::PrintData.new
52
+ print_data.set_print_mode(Wx::PRINT_MODE_FILE)
53
+ print_data.set_filename(filename)
54
+ print_data.set_orientation(Wx::PrintOrientation::PORTRAIT)
55
+ print_data.set_paper_id(Wx::PaperSize::PAPER_A4)
56
+ screen_ppi = printer_ppi = nil
57
+ Wx::ScreenDC.draw_on do |dc|
58
+ screen_ppi = dc.get_ppi
59
+ end
60
+ Wx::PRT::PostScriptDC.draw_on(print_data) do |dc|
61
+ printer_ppi = dc.get_ppi
62
+ scale = printer_ppi.x.to_f / screen_ppi.x.to_f
63
+ dc.start_doc("Drawing sample")
64
+ # Define default font.
65
+ dc.set_font(Wx::FontInfo.new(10).family(Wx::FontFamily::FONTFAMILY_MODERN))
66
+ dc.start_page
67
+ Wx::ScaledDC.draw_on(dc, scale) do |sdc|
68
+ on_draw(sdc)
69
+ end
70
+ dc.end_page
71
+ dc.end_doc
72
+ end
73
+ end
47
74
  end
48
75
 
49
76
  def on_paint
@@ -278,10 +305,10 @@ class SVGPage < Wx::ScrolledWindow
278
305
 
279
306
  end
280
307
 
281
- class SVGFrame < Wx::Frame
308
+ class ImageFrame < Wx::Frame
282
309
 
283
310
  def initialize
284
- super(nil, title: 'SVG Demo', size: [500, 400])
311
+ super(nil, title: 'ImagePrint Demo', size: [500, 400])
285
312
 
286
313
  icon_file = File.join(__dir__,'..', 'art', "wxruby.png")
287
314
  self.icon = Wx::Icon.new(icon_file)
@@ -310,8 +337,8 @@ class SVGFrame < Wx::Frame
310
337
  @notebook = Wx::Notebook.new(self, style: Wx::BK_TOP)
311
338
 
312
339
  # Add SVG Windows to a notebook
313
- SVGPage::PAGES.each_with_index do |title, index|
314
- @notebook.add_page(SVGPage.new(@notebook, index), title)
340
+ ImagePage::PAGES.each_with_index do |title, index|
341
+ @notebook.add_page(ImagePage.new(@notebook, index), title)
315
342
  end
316
343
 
317
344
  evt_menu Wx::ID_SAVE, :file_save_picture
@@ -322,9 +349,13 @@ class SVGFrame < Wx::Frame
322
349
  def file_save_picture(event)
323
350
  page = @notebook.current_page
324
351
 
352
+ wildcard = 'SVG vector picture files (*.svg)|*.svg'
353
+ if Wx.has_feature?(:USE_PRINTING_ARCHITECTURE)
354
+ wildcard << '|PostScript files (*.ps)|*.ps'
355
+ end
325
356
  Wx::FileDialog(self, 'Save Picture as', '',
326
357
  @notebook.get_page_text(@notebook.get_selection),
327
- 'SVG vector picture files (*.svg)|*.svg',
358
+ wildcard,
328
359
  Wx::FD_SAVE|Wx::FD_OVERWRITE_PROMPT) do |dlg|
329
360
  if dlg.show_modal == Wx::ID_OK
330
361
  page.on_save(dlg.get_path)
@@ -334,14 +365,14 @@ class SVGFrame < Wx::Frame
334
365
 
335
366
  def on_about(event)
336
367
  Wx.message_box(
337
- "wxRuby SVG sample\n" +
338
- "(converted from wxWidgets)\n" +
368
+ "wxRuby ImagePrint sample\n" +
369
+ "(converted from wxWidgets SVGTest)\n" +
339
370
  "Authors:\n" +
340
371
  " Chris Elliott (c) 2002-2009\n" +
341
372
  " Prashant Kumar Nirmal (c) 2017\n" +
342
373
  " Martin Corino (c) 2023\n" +
343
- 'Usage: click File|Save to Save the Selected SVG Test',
344
- 'About SVG Test')
374
+ 'Usage: click File|Save to Save the Selected Image page',
375
+ 'About ImagePrint Test')
345
376
  end
346
377
 
347
378
  def on_quit(event)
@@ -350,24 +381,24 @@ class SVGFrame < Wx::Frame
350
381
 
351
382
  end
352
383
 
353
- module SVGTestSample
384
+ module ImagePrintSample
354
385
 
355
386
  include WxRuby::Sample if defined? WxRuby::Sample
356
387
 
357
388
  def self.describe
358
389
  { file: __FILE__,
359
- summary: 'wxRuby SVGFileDC example.',
360
- description: 'wxRuby example showcasing Wx::SVGFileDC to create SVG files.' }
390
+ summary: 'wxRuby Image printing example.',
391
+ description: 'wxRuby example showcasing Wx::SVGFileDC/Wx::PostScriptDC to create SVG/PS files.' }
361
392
  end
362
393
 
363
394
  def self.activate
364
- frame = SVGFrame.new
395
+ frame = ImageFrame.new
365
396
  frame.show
366
397
  frame
367
398
  end
368
399
 
369
400
  if $0 == __FILE__
370
- Wx::App.run { SVGTestSample.activate }
401
+ Wx::App.run { ImagePrintSample.activate }
371
402
  end
372
403
 
373
404
  end
Binary file
@@ -1384,29 +1384,31 @@ class FormMain < Wx::Frame
1384
1384
  Wx::PG::PG_LABEL,
1385
1385
  "Test Text"))
1386
1386
  myTestBitmap1x = Wx::Bitmap.new(60, 15, 32)
1387
- mdc = Wx::MemoryDC.new(myTestBitmap1x)
1388
- mdc.set_background(Wx::WHITE_BRUSH)
1389
- mdc.clear
1390
- mdc.set_pen(Wx::BLACK_PEN)
1391
- mdc.set_brush(Wx::WHITE_BRUSH)
1392
- mdc.draw_rectangle(0, 0, 60, 15)
1393
- mdc.draw_line(0, 0, 59, 14)
1394
- mdc.set_text_foreground(Wx::BLACK)
1395
- mdc.draw_text("x1", 0, 0)
1387
+ Wx::MemoryDC.draw_on(myTestBitmap1x) do |mdc|
1388
+ mdc.set_background(Wx::WHITE_BRUSH)
1389
+ mdc.clear
1390
+ mdc.set_pen(Wx::BLACK_PEN)
1391
+ mdc.set_brush(Wx::WHITE_BRUSH)
1392
+ mdc.draw_rectangle(0, 0, 60, 15)
1393
+ mdc.draw_line(0, 0, 59, 14)
1394
+ mdc.set_text_foreground(Wx::BLACK)
1395
+ mdc.draw_text("x1", 0, 0)
1396
+ end
1396
1397
 
1397
1398
  myTestBitmap2x = Wx::Bitmap.new(120, 30, 32)
1398
- mdc = Wx::MemoryDC.new(myTestBitmap2x)
1399
- mdc.set_background(Wx::WHITE_BRUSH)
1400
- mdc.clear
1401
- mdc.set_pen(Wx::Pen.new(Wx::BLUE, 2))
1402
- mdc.set_brush(Wx::WHITE_BRUSH)
1403
- mdc.draw_rectangle(0, 0, 120, 30)
1404
- mdc.draw_line(0, 0, 119, 31)
1405
- mdc.set_text_foreground(Wx::BLUE)
1406
- f = mdc.font
1407
- f.set_pixel_size(f.get_pixel_size * 2)
1408
- mdc.set_font(f)
1409
- mdc.draw_text("x2", 0, 0)
1399
+ Wx::MemoryDC.draw_on(myTestBitmap2x) do |mdc|
1400
+ mdc.set_background(Wx::WHITE_BRUSH)
1401
+ mdc.clear
1402
+ mdc.set_pen(Wx::Pen.new(Wx::BLUE, 2))
1403
+ mdc.set_brush(Wx::WHITE_BRUSH)
1404
+ mdc.draw_rectangle(0, 0, 120, 30)
1405
+ mdc.draw_line(0, 0, 119, 31)
1406
+ mdc.set_text_foreground(Wx::BLUE)
1407
+ f = mdc.font
1408
+ f.set_pixel_size(f.get_pixel_size * 2)
1409
+ mdc.set_font(f)
1410
+ mdc.draw_text("x2", 0, 0)
1411
+ end
1410
1412
 
1411
1413
  myTestBitmap2x.set_scale_factor(2)
1412
1414
  pg.set_property_image("StringPropertyWithBitmap", Wx::BitmapBundle.from_bitmaps(myTestBitmap1x, myTestBitmap2x))