wxruby3 1.8.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +20 -10
  3. data/README.md +3 -3
  4. data/ext/wxruby3/include/wxRubyApp.h +49 -3
  5. data/ext/wxruby3/include/wxruby-ComboPopup.h +17 -32
  6. data/ext/wxruby3/include/wxruby-Config.h +34 -11
  7. data/ext/wxruby3/include/wxruby-GCTracking.h +23 -5
  8. data/ext/wxruby3/include/wxruby-SharedEventHandler.h +7 -7
  9. data/ext/wxruby3/include/wxruby-runtime.h +65 -0
  10. data/ext/wxruby3/swig/common.i +6 -0
  11. data/ext/wxruby3/swig/custom/typed_data/rubyhead.swg +220 -0
  12. data/ext/wxruby3/swig/custom/typed_data/rubyprimtypes.swg +265 -0
  13. data/ext/wxruby3/swig/custom/typed_data/rubyrun.swg +243 -0
  14. data/ext/wxruby3/swig/custom/typed_data/swigrun.swg +689 -0
  15. data/ext/wxruby3/swig/custom/{rubyprimtypes.swg → untyped_data/rubyprimtypes.swg} +8 -0
  16. data/ext/wxruby3/swig/mark_free_impl.i +2 -2
  17. data/ext/wxruby3/swig/memory_management.i +1 -0
  18. data/ext/wxruby3/swig/wx.i +19 -6
  19. data/lib/wx/core/file_dialog.rb +3 -10
  20. data/lib/wx/doc/rbn/events.rb +32 -0
  21. data/lib/wx/doc/rbn/ribbon_backstage_mrulist.rb +25 -0
  22. data/lib/wx/keyword_ctors.rb +3 -13
  23. data/lib/wx/rbn/events.rb +18 -0
  24. data/lib/wx/rbn/require.rb +1 -0
  25. data/lib/wx/rbn/ribbon_backstage_mrulist.rb +39 -0
  26. data/lib/wx/version.rb +1 -1
  27. data/rakelib/lib/config.rb +3 -3
  28. data/rakelib/lib/core/include/typed_data/swigrubyrun.inc +629 -0
  29. data/rakelib/lib/core/include/typed_data/swigrun.inc +870 -0
  30. data/rakelib/lib/core/package.rb +2 -2
  31. data/rakelib/lib/director/app.rb +16 -0
  32. data/rakelib/lib/director/art_provider.rb +3 -3
  33. data/rakelib/lib/director/aui_mdi_child_frame.rb +24 -0
  34. data/rakelib/lib/director/aui_mdi_parent_frame.rb +0 -2
  35. data/rakelib/lib/director/aui_tab_ctrl.rb +3 -3
  36. data/rakelib/lib/director/comboctrl.rb +35 -2
  37. data/rakelib/lib/director/config_base.rb +79 -33
  38. data/rakelib/lib/director/data_object.rb +1 -1
  39. data/rakelib/lib/director/date_event.rb +10 -3
  40. data/rakelib/lib/director/event.rb +16 -7
  41. data/rakelib/lib/director/event_handler.rb +48 -10
  42. data/rakelib/lib/director/events.rb +4 -2
  43. data/rakelib/lib/director/file_history.rb +46 -0
  44. data/rakelib/lib/director/frame.rb +29 -0
  45. data/rakelib/lib/director/fs_file.rb +2 -4
  46. data/rakelib/lib/director/functions.rb +2 -2
  47. data/rakelib/lib/director/graphics_context.rb +6 -6
  48. data/rakelib/lib/director/grid_cell_editor.rb +1 -1
  49. data/rakelib/lib/director/grid_cell_renderer.rb +1 -1
  50. data/rakelib/lib/director/grid_ctrl.rb +39 -12
  51. data/rakelib/lib/director/help_controller.rb +17 -0
  52. data/rakelib/lib/director/html_help_data.rb +20 -2
  53. data/rakelib/lib/director/icon.rb +3 -0
  54. data/rakelib/lib/director/log.rb +25 -1
  55. data/rakelib/lib/director/menu.rb +38 -106
  56. data/rakelib/lib/director/menu_bar.rb +36 -70
  57. data/rakelib/lib/director/num_validator.rb +3 -3
  58. data/rakelib/lib/director/numeric_property_validator.rb +1 -1
  59. data/rakelib/lib/director/page_setup_dialog.rb +18 -1
  60. data/rakelib/lib/director/pgeditor.rb +1 -1
  61. data/rakelib/lib/director/pgvalidation_info.rb +1 -0
  62. data/rakelib/lib/director/popup_window.rb +7 -0
  63. data/rakelib/lib/director/preview_frame.rb +8 -1
  64. data/rakelib/lib/director/print_dialog.rb +17 -0
  65. data/rakelib/lib/director/printer.rb +1 -1
  66. data/rakelib/lib/director/property_grid_page.rb +2 -0
  67. data/rakelib/lib/director/region_iterator.rb +1 -1
  68. data/rakelib/lib/director/ribbon_backstage.rb +28 -0
  69. data/rakelib/lib/director/ribbon_backstage_button.rb +25 -0
  70. data/rakelib/lib/director/ribbon_backstage_callout.rb +26 -0
  71. data/rakelib/lib/director/ribbon_backstage_heading.rb +26 -0
  72. data/rakelib/lib/director/ribbon_backstage_itemlist.rb +27 -0
  73. data/rakelib/lib/director/ribbon_backstage_mrulist.rb +112 -0
  74. data/rakelib/lib/director/ribbon_bar.rb +14 -0
  75. data/rakelib/lib/director/ribbon_gallery.rb +6 -2
  76. data/rakelib/lib/director/ribbon_tool_bar.rb +6 -4
  77. data/rakelib/lib/director/richtext_composite_object.rb +4 -4
  78. data/rakelib/lib/director/richtext_paragraph_layout_box.rb +1 -1
  79. data/rakelib/lib/director/scrolled_t.rb +1 -1
  80. data/rakelib/lib/director/sizer.rb +7 -0
  81. data/rakelib/lib/director/sizer_item.rb +4 -1
  82. data/rakelib/lib/director/splitter_event.rb +2 -2
  83. data/rakelib/lib/director/task_bar_icon.rb +4 -1
  84. data/rakelib/lib/director/text_validator.rb +1 -1
  85. data/rakelib/lib/director/tree_event.rb +3 -3
  86. data/rakelib/lib/director/validator.rb +1 -1
  87. data/rakelib/lib/director/variant.rb +2 -2
  88. data/rakelib/lib/director/window.rb +27 -5
  89. data/rakelib/lib/director/window_disabler.rb +1 -1
  90. data/rakelib/lib/director/xml_resource.rb +33 -8
  91. data/rakelib/lib/extractor/class.rb +2 -1
  92. data/rakelib/lib/extractor.rb +3 -2
  93. data/rakelib/lib/generate/interface.rb +2 -3
  94. data/rakelib/lib/specs/interfaces.rb +7 -0
  95. data/rakelib/lib/swig_runner.rb +14 -3
  96. data/rakelib/lib/typemap/common.rb +2 -36
  97. data/rakelib/lib/typemap/config.rb +22 -0
  98. data/samples/ribbon/ribbon.rb +277 -20
  99. data/tests/test_shared_event_handler.rb +3 -3
  100. metadata +32 -16
  101. /data/ext/wxruby3/swig/custom/{director.swg → common/director.swg} +0 -0
  102. /data/ext/wxruby3/swig/custom/{rubyapi.swg → common/rubyapi.swg} +0 -0
  103. /data/ext/wxruby3/swig/custom/{rubyerrors.swg → common/rubyerrors.swg} +0 -0
  104. /data/ext/wxruby3/swig/custom/{rubytracking.swg → common/rubytracking.swg} +0 -0
  105. /data/ext/wxruby3/swig/custom/{swiglabels.swg → common/swiglabels.swg} +0 -0
  106. /data/ext/wxruby3/swig/custom/{typemaps → common/typemaps}/swigtypemaps.swg +0 -0
  107. /data/ext/wxruby3/swig/custom/{wx_ruby_shared_ptr.i → common/wx_ruby_shared_ptr.i} +0 -0
  108. /data/ext/wxruby3/swig/custom/{wx_shared_ptr.i → common/wx_shared_ptr.i} +0 -0
  109. /data/ext/wxruby3/swig/custom/{rubyhead.swg → untyped_data/rubyhead.swg} +0 -0
  110. /data/ext/wxruby3/swig/custom/{rubyrun.swg → untyped_data/rubyrun.swg} +0 -0
  111. /data/ext/wxruby3/swig/custom/{swigrun.swg → untyped_data/swigrun.swg} +0 -0
  112. /data/rakelib/lib/core/include/{swigrubyrun.inc → untyped_data/swigrubyrun.inc} +0 -0
  113. /data/rakelib/lib/core/include/{swigrun.inc → untyped_data/swigrun.inc} +0 -0
@@ -0,0 +1,46 @@
1
+ # Copyright (c) 2023 M.J.N. Corino, The Netherlands
2
+ #
3
+ # This software is released under the MIT license.
4
+
5
+ ###
6
+ # wxRuby3 wxWidgets interface director
7
+ ###
8
+
9
+ module WXRuby3
10
+
11
+ class Director
12
+
13
+ class FileHistory < Director
14
+
15
+ include Typemap::ConfigBase
16
+
17
+ def setup
18
+ super
19
+ spec.gc_as_untracked 'wxFileHistory'
20
+ spec.ignore 'wxFileHistory::GetMenus',
21
+ ignore_doc: false
22
+ spec.map 'const wxList&' => 'Array<Wx::Menu>', swig: false do
23
+ map_out
24
+ end
25
+ spec.add_extend_code 'wxFileHistory', <<~__CODE
26
+ VALUE get_menus()
27
+ {
28
+ VALUE ary = rb_ary_new();
29
+ const wxList& lst = $self->GetMenus();
30
+ for (wxList::compatibility_iterator node = lst.GetFirst();
31
+ node; node = node->GetNext())
32
+ {
33
+ wxMenu *menu = (wxMenu *) node->GetData();
34
+ VALUE rb_menu = SWIG_NewPointerObj(SWIG_as_voidptr(menu),
35
+ SWIGTYPE_p_wxMenu, 0);
36
+ rb_ary_push(ary, rb_menu);
37
+ }
38
+ return ary;
39
+ }
40
+ __CODE
41
+ end
42
+ end # class FileHistory
43
+
44
+ end # class Director
45
+
46
+ end # module WXRuby3
@@ -33,6 +33,34 @@ module WXRuby3
33
33
  'wxFrame::GetMenuBar',
34
34
  'wxFrame::GetStatusBar',
35
35
  'wxFrame::GetToolBar')
36
+ spec.add_wrapper_code <<~__HEREDOC
37
+ extern VALUE wxRuby_GetFrameClass() {
38
+ return SwigClassWxFrame.klass;
39
+ }
40
+ __HEREDOC
41
+ spec.add_header_code <<~__HEREDOC
42
+ WXRUBY_TRACE_GUARD(WxRubyTraceMarkFrame, "GC_MARK_FRAME")
43
+ WXRUBY_EXPORT void GC_mark_wxFrame(void* ptr)
44
+ {
45
+ WXRUBY_TRACE_IF(WxRubyTraceMarkFrame, 2)
46
+ WXRUBY_TRACE("> GC_mark_wxFrame : " << ptr)
47
+ WXRUBY_TRACE_END
48
+
49
+ if (GC_IsWindowDeleted(ptr)) return;
50
+
51
+ GC_mark_wxWindow(ptr);
52
+
53
+ wxFrame* wx_frame = reinterpret_cast<wxFrame*> (ptr);
54
+
55
+ // Mark attached menu bars
56
+ wxMenuBar* wx_mb = wx_frame->GetMenuBar();
57
+ rb_gc_mark(SWIG_RubyInstanceFor(wx_mb));
58
+
59
+ WXRUBY_TRACE_IF(WxRubyTraceMarkFrame, 2)
60
+ WXRUBY_TRACE("< GC_mark_wxFrame : " << ptr)
61
+ WXRUBY_TRACE_END
62
+ }
63
+ __HEREDOC
36
64
  end
37
65
  # for SetStatusWidths
38
66
  spec.map 'int n, int * widths_field' do
@@ -62,6 +90,7 @@ module WXRuby3
62
90
  spec.items.each do |citem|
63
91
  def_item = defmod.find_item(citem)
64
92
  if Extractor::ClassDef === def_item && (citem == 'wxFrame' || spec.is_derived_from?(def_item, 'wxFrame'))
93
+ spec.add_swig_code "%markfunc #{spec.class_name(citem)} \"GC_mark_wxFrame\";"
65
94
  spec.no_proxy %W[
66
95
  #{spec.class_name(citem)}::CreateStatusBar
67
96
  #{spec.class_name(citem)}::CreateToolBar
@@ -346,8 +346,7 @@ module WXRuby3
346
346
  {
347
347
  if (wxRuby_IsInputStream(rbis))
348
348
  {
349
- void *ptr;
350
- Data_Get_Struct(rbis, void, ptr);
349
+ void *ptr = WXRUBY_WRAPPER_DATA_GET(rbis, void);
351
350
  return static_cast<wxInputStream*>(ptr);
352
351
  }
353
352
  return 0;
@@ -382,8 +381,7 @@ module WXRuby3
382
381
  {
383
382
  if (wxRuby_IsOutputStream(rbos))
384
383
  {
385
- void *ptr;
386
- Data_Get_Struct(rbos, void, ptr);
384
+ void *ptr = WXRUBY_WRAPPER_DATA_GET(rbos, void);
387
385
  return static_cast<wxOutputStream*>(ptr);
388
386
  }
389
387
  return 0;
@@ -147,7 +147,7 @@ module WXRuby3
147
147
  // To a specific window's status bar
148
148
  if( TYPE(argv[0]) == T_DATA ) {
149
149
  log_msg = rb_f_sprintf(argc-1, &argv[1]);
150
- Data_Get_Struct(argv[0], wxFrame, log_frame);
150
+ log_frame = WXRUBY_WRAPPER_DATA_GET(argv[0], wxFrame);
151
151
  }
152
152
  // To the application main window's status bar
153
153
  else {
@@ -190,7 +190,7 @@ module WXRuby3
190
190
  {
191
191
  static WxRuby_ID sprintf_id("sprintf");
192
192
 
193
- size_t ptr = (size_t)DATA_PTR(obj);
193
+ size_t ptr = (size_t)WXRUBY_WRAPPER_DATA_PTR(obj);
194
194
  return rb_funcall( rb_mKernel, sprintf_id(), 2,
195
195
  rb_str_new2("0x%x"), OFFT2NUM(ptr) );
196
196
  }
@@ -244,7 +244,7 @@ module WXRuby3
244
244
  VALUE rb_gc = SWIG_NewPointerObj(SWIG_as_voidptr(p_gc), SWIGTYPE_p_wxGraphicsContext, 1);
245
245
  rc = rb_yield(rb_gc);
246
246
  SWIG_RubyRemoveTracking((void *)p_gc);
247
- DATA_PTR(rb_gc) = NULL;
247
+ WXRUBY_WRAPPER_DATA_PTR_RESET(rb_gc);
248
248
  delete p_gc;
249
249
  }
250
250
  return rc;
@@ -261,7 +261,7 @@ module WXRuby3
261
261
  VALUE rb_gc = SWIG_NewPointerObj(SWIG_as_voidptr(p_gc), SWIGTYPE_p_wxGraphicsContext, 1);
262
262
  rc = rb_yield(rb_gc);
263
263
  SWIG_RubyRemoveTracking((void *)p_gc);
264
- DATA_PTR(rb_gc) = NULL;
264
+ WXRUBY_WRAPPER_DATA_PTR_RESET(rb_gc);
265
265
  delete p_gc;
266
266
  }
267
267
  return rc;
@@ -275,7 +275,7 @@ module WXRuby3
275
275
  VALUE rb_gc = SWIG_NewPointerObj(SWIG_as_voidptr(p_gc), SWIGTYPE_p_wxGraphicsContext, 1);
276
276
  rc = rb_yield(rb_gc);
277
277
  SWIG_RubyRemoveTracking((void *)p_gc);
278
- DATA_PTR(rb_gc) = NULL;
278
+ WXRUBY_WRAPPER_DATA_PTR_RESET(rb_gc);
279
279
  delete p_gc;
280
280
  }
281
281
  return rc;
@@ -289,7 +289,7 @@ module WXRuby3
289
289
  VALUE rb_gc = SWIG_NewPointerObj(SWIG_as_voidptr(p_gc), SWIGTYPE_p_wxGraphicsContext, 1);
290
290
  rc = rb_yield(rb_gc);
291
291
  SWIG_RubyRemoveTracking((void *)p_gc);
292
- DATA_PTR(rb_gc) = NULL;
292
+ WXRUBY_WRAPPER_DATA_PTR_RESET(rb_gc);
293
293
  delete p_gc;
294
294
  }
295
295
  return rc;
@@ -303,7 +303,7 @@ module WXRuby3
303
303
  VALUE rb_gc = SWIG_NewPointerObj(SWIG_as_voidptr(p_gc), SWIGTYPE_p_wxGraphicsContext, 1);
304
304
  rc = rb_yield(rb_gc);
305
305
  SWIG_RubyRemoveTracking((void *)p_gc);
306
- DATA_PTR(rb_gc) = NULL;
306
+ WXRUBY_WRAPPER_DATA_PTR_RESET(rb_gc);
307
307
  delete p_gc;
308
308
  }
309
309
  return rc;
@@ -317,7 +317,7 @@ module WXRuby3
317
317
  VALUE rb_gc = SWIG_NewPointerObj(SWIG_as_voidptr(p_gc), SWIGTYPE_p_wxGraphicsContext, 1);
318
318
  rc = rb_yield(rb_gc);
319
319
  SWIG_RubyRemoveTracking((void *)p_gc);
320
- DATA_PTR(rb_gc) = NULL;
320
+ WXRUBY_WRAPPER_DATA_PTR_RESET(rb_gc);
321
321
  delete p_gc;
322
322
  }
323
323
  return rc;
@@ -280,7 +280,7 @@ module WXRuby3
280
280
  }
281
281
  else if (rbEvt != Qnil)
282
282
  {
283
- const wxEvent* evt = (const wxEvent*)DATA_PTR(rbEvt);
283
+ const wxEvent* evt = (const wxEvent*)WXRUBY_WRAPPER_DATA_PTR(rbEvt);
284
284
  if (SYM2ID(rbOrg) == ga_key_id())
285
285
  return wxGridActivationSource::From(*(const wxKeyEvent*)evt);
286
286
  else if (SYM2ID(rbOrg) == ga_mouse_id())
@@ -113,7 +113,7 @@ module WXRuby3
113
113
 
114
114
  extern void GC_free_GridCellRenderer(void *ptr)
115
115
  {
116
- wxGridCellRenderer* gc_rdr = (wxGridCellRenderer*)ptr;
116
+ wxGridCellRenderer* gc_rdr = (wxGridCellRenderer*)ptr;
117
117
  if (ptr)
118
118
  gc_rdr->DecRef();
119
119
  }
@@ -64,8 +64,7 @@ module WXRuby3
64
64
  #define FOREACH_FUNC(x) reinterpret_cast<rb_foreach_func>((void*)&(x))
65
65
  static int _wxrb_cvt_custom_sizes(VALUE key, VALUE value, VALUE rbWxMap)
66
66
  {
67
- wxUnsignedToIntHashMap* wxMap;
68
- Data_Get_Struct(rbWxMap, wxUnsignedToIntHashMap, wxMap);
67
+ wxUnsignedToIntHashMap* wxMap = WXRUBY_WRAPPER_DATA_GET(rbWxMap, wxUnsignedToIntHashMap);
69
68
  (*wxMap)[NUM2UINT(key)] = NUM2INT(value);
70
69
  return ST_CONTINUE;
71
70
  }
@@ -74,7 +73,15 @@ module WXRuby3
74
73
  if (TYPE($input) == T_HASH)
75
74
  {
76
75
  void* ptr = &($1);
77
- VALUE rbWxMap = Data_Wrap_Struct(rb_cObject, 0, 0, ptr);
76
+ VALUE rbWxMap;
77
+ // wrap anonymously as we only want to pass the hashmap in to convert
78
+ #ifdef WXRUBY_SWIG_UNTYPED_DATA
79
+ rbWxMap = Data_Wrap_Struct(rb_cObject, 0, 0, ptr);
80
+ #else
81
+ struct swig_ruby_wrapped_object *wrobj;
82
+ rbWxMap = TypedData_Make_Struct(rb_cObject, struct swig_ruby_wrapped_object, &swig_type_data_type, wrobj);
83
+ wrobj->data = ptr;
84
+ #endif
78
85
  rb_hash_foreach($input, FOREACH_FUNC(_wxrb_cvt_custom_sizes), rbWxMap);
79
86
  }
80
87
  else
@@ -252,10 +259,10 @@ module WXRuby3
252
259
 
253
260
  static const rb_data_type_t __wxGridWindow_type = {
254
261
  "GridWindow",
255
- #if RUBY_API_VERSION_MAJOR >= 3
256
- { NULL, NULL, __wxGridWindow_size, 0, {}},
262
+ #if RUBY_API_VERSION_MAJOR > 4 || (RUBY_API_VERSION_MAJOR == 4 && RUBY_API_VERSION_MINOR >= 1)
263
+ { NULL, NULL, __wxGridWindow_size, 0, 0, {}},
257
264
  #else
258
- { NULL, NULL, __wxGridWindow_size, {}},
265
+ { NULL, NULL, __wxGridWindow_size, 0, {}},
259
266
  #endif
260
267
  NULL, NULL, RUBY_TYPED_FREE_IMMEDIATELY
261
268
  };
@@ -330,7 +337,7 @@ module WXRuby3
330
337
  VALUE obj = ti.second;
331
338
 
332
339
  WXRUBY_TRACE_IF(WxRubyTraceGCMarkGridCellAttr, 2)
333
- WXRUBY_TRACE_WITH(void *c_ptr = (TYPE(obj) == T_DATA ? DATA_PTR(obj) : 0))
340
+ WXRUBY_TRACE_WITH(void *c_ptr = (WXRUBY_HAS_WRAPPED_DATA(obj) ? WXRUBY_WRAPPER_DATA_PTR(obj) : 0))
334
341
  WXRUBY_TRACE("| wxRuby_markGridCellAttr : " << ti.first << "|" << (void*)c_ptr)
335
342
  WXRUBY_TRACE_END
336
343
 
@@ -401,7 +408,7 @@ module WXRuby3
401
408
 
402
409
  // either a new Ruby created instance or an unwrapped C++ created instance
403
410
  // always disown; wxWidgets takes over or keeps ownership of reference count
404
- RDATA(rb_attr)->dfree = 0;
411
+ WXRUBY_WRAPPER_DATA_DFREE_RESET(rb_attr);
405
412
 
406
413
  wx_attr->SetClientObject(new WXRBGridCellAttrMonitor(wx_attr, rb_attr));
407
414
  }
@@ -431,7 +438,7 @@ module WXRuby3
431
438
  VALUE obj = ti.second;
432
439
 
433
440
  WXRUBY_TRACE_IF(WxRubyTraceGCTrackGridCellEditor, 2)
434
- WXRUBY_TRACE_WITH(void *c_ptr = (TYPE(obj) == T_DATA ? DATA_PTR(obj) : 0))
441
+ WXRUBY_TRACE_WITH(void *c_ptr = (WXRUBY_HAS_WRAPPED_DATA(obj) ? WXRUBY_WRAPPER_DATA_PTR(obj) : 0))
435
442
  WXRUBY_TRACE("| wxRuby_markGridCellEditor : " << ti.first << "|" << (void*)c_ptr)
436
443
  WXRUBY_TRACE_END
437
444
 
@@ -502,7 +509,7 @@ module WXRuby3
502
509
 
503
510
  // either a new Ruby created instance or an unwrapped C++ created instance
504
511
  // always disown; wxWidgets takes over or keeps ownership of reference count
505
- RDATA(rb_edt)->dfree = 0;
512
+ WXRUBY_WRAPPER_DATA_DFREE_RESET(rb_edt);
506
513
 
507
514
  wx_edt->SetClientObject(new WXRBGridCellEditorMonitor(wx_edt, rb_edt));
508
515
  }
@@ -532,7 +539,7 @@ module WXRuby3
532
539
  VALUE obj = ti.second;
533
540
 
534
541
  WXRUBY_TRACE_IF(WxRubyTraceGCTrackGridCellRenderer, 2)
535
- WXRUBY_TRACE_WITH(void *c_ptr = (TYPE(obj) == T_DATA ? DATA_PTR(obj) : 0))
542
+ WXRUBY_TRACE_WITH(void *c_ptr = (WXRUBY_HAS_WRAPPED_DATA(obj) ? WXRUBY_WRAPPER_DATA_PTR(obj) : 0))
536
543
  WXRUBY_TRACE("| wxRuby_markGridCellRenderer : " << ti.first << "|" << (void*)c_ptr)
537
544
  WXRUBY_TRACE_END
538
545
 
@@ -603,7 +610,7 @@ module WXRuby3
603
610
 
604
611
  // either a new Ruby created instance or an unwrapped C++ created instance
605
612
  // always disown; wxWidgets takes over or keeps ownership of reference count
606
- RDATA(rb_rnd)->dfree = 0;
613
+ WXRUBY_WRAPPER_DATA_DFREE_RESET(rb_rnd);
607
614
 
608
615
  wx_rnd->SetClientObject(new WXRBGridCellRendererMonitor(wx_rnd, rb_rnd));
609
616
  }
@@ -653,10 +660,30 @@ module WXRuby3
653
660
  add_header_code 'extern VALUE wxRuby_WrapWxGridCellEditorInRuby(const wxGridCellEditor *wx_gce);'
654
661
  map_out code: '$result = wxRuby_WrapWxGridCellEditorInRuby($1);'
655
662
  map_check code: 'wxRuby_RegisterGridCellEditor($1, argv[$argnum-2]);'
663
+ map_directorout code: <<~__CODE
664
+ void* swig_argp;
665
+ swig_owntype own;
666
+ int swig_res = SWIG_ConvertPtrAndOwn(result, &swig_argp, $1_descriptor, SWIG_POINTER_DISOWN, &own);
667
+ if (!SWIG_IsOK(swig_res)) {
668
+ Swig::DirectorTypeMismatchException::raise(swig_get_self(), "$symname", SWIG_ErrorType(SWIG_ArgError(swig_res)), "in output value of type '""wxGridCellEditor *""'");
669
+ }
670
+ $result = reinterpret_cast< wxGridCellEditor * >(swig_argp);
671
+ $result->IncRef();
672
+ __CODE
656
673
  end
657
674
  spec.map 'wxGridCellRenderer *' => 'Wx::GRID::GridCellRenderer' do
658
675
  add_header_code 'extern VALUE wxRuby_WrapWxGridCellRendererInRuby(const wxGridCellRenderer *wx_gcr);'
659
676
  map_out code: '$result = wxRuby_WrapWxGridCellRendererInRuby($1);'
677
+ map_directorout code: <<~__CODE
678
+ void* swig_argp;
679
+ swig_owntype own;
680
+ int swig_res = SWIG_ConvertPtrAndOwn(result, &swig_argp, $1_descriptor, SWIG_POINTER_DISOWN, &own);
681
+ if (!SWIG_IsOK(swig_res)) {
682
+ Swig::DirectorTypeMismatchException::raise(swig_get_self(), "$symname", SWIG_ErrorType(SWIG_ArgError(swig_res)), "in output value of type '""wxGridCellRenderer *""'");
683
+ }
684
+ $result = reinterpret_cast< wxGridCellRenderer * >(swig_argp);
685
+ $result->IncRef();
686
+ __CODE
660
687
  map_check code: 'wxRuby_RegisterGridCellRenderer($1, argv[$argnum-2]);'
661
688
  end
662
689
  # add constants missing from documentation
@@ -18,6 +18,23 @@ module WXRuby3
18
18
  super
19
19
  spec.items << 'wxHelpControllerBase' << 'helpfrm.h'
20
20
  spec.fold_bases(spec.module_name => 'wxHelpControllerBase')
21
+ # make all HelpController classes GC-safe
22
+ spec.add_header_code <<~__HEREDOC
23
+ static void wxRuby_delete_#{spec.module_name}(void *self)
24
+ {
25
+ #{spec.module_name} *arg1 = (#{spec.module_name} *)self;
26
+ SWIG_RubyRemoveTracking(arg1);
27
+ delete arg1;
28
+ }
29
+
30
+ static void GC_free_#{spec.module_name}(void* object)
31
+ {
32
+ wxRuby_RegisterDeferredObjectDestroy(object, wxRuby_delete_#{spec.module_name});
33
+ }
34
+ __HEREDOC
35
+ # a HelpController is not window but it does manage windows which it will delete on destruction,,
36
+ # so it needs a deferred destroy.
37
+ spec.add_swig_code "%feature(\"freefunc\") #{spec.module_name} \"GC_free_#{spec.module_name}\";"
21
38
  spec.rename_for_ruby('Init' => "#{spec.module_name}::Initialize")
22
39
  # ignore these (pure virtual) decls
23
40
  spec.ignore %w[
@@ -22,7 +22,16 @@ module WXRuby3
22
22
  for (size_t n=0; n<$1->GetCount() ;++n)
23
23
  {
24
24
  wxHtmlBookRecord* hbr_ptr = &($1->Item(n));
25
- VALUE rb_hbr = Data_Wrap_Struct(rb_cObject, 0, 0, hbr_ptr);
25
+ swig_class *sklass = (swig_class *)SWIGTYPE_p_wxHtmlBookRecord->clientdata;
26
+ VALUE rb_hbr;
27
+ #ifdef WXRUBY_SWIG_UNTYPED_DATA
28
+ rb_hbr = Data_Wrap_Struct(sklass->klass, 0, 0, hbr_ptr);
29
+ #else
30
+ struct swig_ruby_wrapped_object *wrobj;
31
+ rb_hbr = TypedData_Make_Struct(sklass->klass, struct swig_ruby_wrapped_object, &sklass->cext_type, wrobj);
32
+ wrobj->data = hbr_ptr;
33
+ #endif
34
+ rb_iv_set(rb_hbr, "@__swigtype__", rb_str_new2(SWIGTYPE_p_wxHtmlBookRecord->name));
26
35
  rb_ary_push($result, rb_hbr);
27
36
  }
28
37
  __CODE
@@ -33,7 +42,16 @@ module WXRuby3
33
42
  for (size_t n=0; n<$1->GetCount() ;++n)
34
43
  {
35
44
  wxHtmlHelpDataItem* hdi_ptr = &($1->Item(n));
36
- VALUE rb_hdi = Data_Wrap_Struct(rb_cObject, 0, 0, hdi_ptr);
45
+ swig_class *sklass = (swig_class *)SWIGTYPE_p_wxHtmlHelpDataItem->clientdata;
46
+ VALUE rb_hdi;
47
+ #ifdef WXRUBY_SWIG_UNTYPED_DATA
48
+ rb_hdi = Data_Wrap_Struct(sklass->klass, 0, 0, hdi_ptr);
49
+ #else
50
+ struct swig_ruby_wrapped_object *wrobj;
51
+ rb_hdi = TypedData_Make_Struct(sklass->klass, struct swig_ruby_wrapped_object, &sklass->cext_type, wrobj);
52
+ wrobj->data = hdi_ptr;
53
+ #endif
54
+ rb_iv_set(rb_hdi, "@__swigtype__", rb_str_new2(SWIGTYPE_p_wxHtmlHelpDataItem->name));
37
55
  rb_ary_push($result, rb_hdi);
38
56
  }
39
57
  __CODE
@@ -29,6 +29,9 @@ module WXRuby3
29
29
  spec.ignore 'wxIconBundle::wxIconBundle(const wxString &, WXHINSTANCE)',
30
30
  'wxIconBundle::AddIcon(const wxString&,WXHINSTANCE)',
31
31
  'wxIcon::CreateFromHICON'
32
+ if Config.instance.wx_version_check('3.3.4') >= 0
33
+ spec.ignore 'wxIcon::GetHICON'
34
+ end
32
35
  else
33
36
  spec.override_inheritance_chain('wxIcon', %w[wxBitmap wxGDIObject wxObject])
34
37
  end
@@ -17,6 +17,30 @@ module WXRuby3
17
17
  spec.items.concat(%w[wxLogBuffer wxLogChain wxLogGui wxLogStderr wxLogTextCtrl wxLogInterposer wxLogWindow wxLogNull wxLogRecordInfo])
18
18
  spec.no_proxy(%w[wxLogBuffer wxLogGui wxLogStderr wxLogTextCtrl wxLogWindow])
19
19
  spec.force_proxy(%w[wxLogInterposer])
20
+ # make loggers GC-safe
21
+ spec.add_header_code <<~__HEREDOC
22
+ static void wxRuby_delete_wxLog(void *self)
23
+ {
24
+ wxLog *arg1 = (wxLog *)self;
25
+ SWIG_RubyRemoveTracking(arg1);
26
+ delete arg1;
27
+ }
28
+
29
+ static void GC_free_wxLog(void* object)
30
+ {
31
+ wxRuby_RegisterDeferredObjectDestroy(object, wxRuby_delete_wxLog);
32
+ }
33
+ __HEREDOC
34
+ # defer destroying log objects because they otherwise trigger Ruby object allocations during GC
35
+ spec.add_swig_code '%feature("freefunc") wxLog "GC_free_wxLog";'
36
+ spec.add_swig_code '%feature("freefunc") wxLogBuffer "GC_free_wxLog";'
37
+ spec.add_swig_code '%feature("freefunc") wxLogChain "GC_free_wxLog";'
38
+ spec.add_swig_code '%feature("freefunc") wxLogGui "GC_free_wxLog";'
39
+ spec.add_swig_code '%feature("freefunc") wxLogStderr "GC_free_wxLog";'
40
+ spec.add_swig_code '%feature("freefunc") wxLogTextCtrl "GC_free_wxLog";'
41
+ spec.add_swig_code '%feature("freefunc") wxLogInterposer "GC_free_wxLog";'
42
+ spec.add_swig_code '%feature("freefunc") wxLogWindow "GC_free_wxLog";'
43
+ spec.add_swig_code '%feature("freefunc") wxLogNull "GC_free_wxLog";'
20
44
  spec.ignore 'wxLog::SetFormatter'
21
45
  spec.regard %w[wxLog::DoLogRecord wxLog::DoLogTextAtLevel wxLog::DoLogText]
22
46
  spec.ignore 'wxLogBuffer::Flush'
@@ -49,7 +73,7 @@ module WXRuby3
49
73
  if (!NIL_P(rb_self))
50
74
  {
51
75
  swig_type_info* swig_type = wxRuby_GetSwigTypeForClass(CLASS_OF(rb_self));
52
- RDATA(rb_self)->dfree = ((swig_class *)swig_type->clientdata)->destroy;
76
+ WXRUBY_WRAPPER_DATA_DFREE_SET(rb_self, ((swig_class *)swig_type->clientdata)->destroy);
53
77
  }
54
78
  }
55
79
  __CODE
@@ -13,52 +13,12 @@ module WXRuby3
13
13
  class Menu < Director
14
14
 
15
15
  def setup
16
- spec.gc_as_marked
16
+ spec.gc_as_object
17
+ spec.add_swig_code '%markfunc wxMenu "GC_mark_wxMenu";'
17
18
  spec.ignore 'wxMenu::wxMenu(long)'
18
19
  spec.no_proxy 'wxMenu' # do not support derived wxMenu classes
19
- spec.add_header_code <<~__HEREDOC
20
- static void GC_mark_wxMenu(const TGCTrackingValueMap& values);
21
-
22
- // Custom subclass implementation.
23
- // Provides proper support for Ruby GC in destructor.
24
- class wxRubyMenu : public wxMenu
25
- {
26
- public:
27
- static const std::string TRACKING_CAT;
28
-
29
- wxRubyMenu() : wxMenu() {}
30
- wxRubyMenu(const wxString &title, long style=0) : wxMenu(title, style) {}
31
- virtual ~wxRubyMenu()
32
- {
33
- wxRuby_ReleaseEvtHandlerProcs(this);
34
- wxruby_unregister();
35
- }
36
-
37
- void wxruby_register(VALUE rb_menu)
38
- {
39
- if (!is_registered_)
40
- {
41
- wxRuby_RegisterTrackingCategory(TRACKING_CAT, GC_mark_wxMenu, true);
42
- is_registered_ = true;
43
- }
44
- if (RB_NIL_P(wxRuby_FindCategoryValue(TRACKING_CAT, this)))
45
- wxRuby_RegisterCategoryValue(TRACKING_CAT, this, rb_menu);
46
- }
47
- private:
48
- static bool is_registered_;
49
- void wxruby_unregister()
50
- {
51
- wxRuby_UnregisterCategoryValue(TRACKING_CAT, this);
52
- }
53
- };
54
-
55
- const std::string wxRubyMenu::TRACKING_CAT = { "WXRUBY_MENU" };
56
- bool wxRubyMenu::is_registered_ {};
57
- __HEREDOC
58
- # make Ruby director and wrappers use custom implementation
59
- spec.use_class_implementation('wxMenu', 'wxRubyMenu')
60
- # GC handling
61
- spec.disown 'wxMenu *submenu'
20
+ # submenu handling
21
+ spec.disown 'wxMenu *subMenu', 'wxMenu *submenu'
62
22
  # not wanted
63
23
  spec.ignore 'wxMenu::SetParent',
64
24
  'wxMenu::Attach',
@@ -87,7 +47,9 @@ module WXRuby3
87
47
  spec.map 'wxMenu **' => 'Wx::Menu' do
88
48
  map_in ignore: true, temp: 'wxMenu *tmp', code: '$1 = &tmp;'
89
49
  map_argout code: <<~__CODE
90
- $result = SWIG_Ruby_AppendOutput($result, wxRuby_WrapWxMenuInRuby(tmp$argnum));
50
+ VALUE rb_menu = SWIG_NewPointerObj(SWIG_as_voidptr(tmp$argnum),
51
+ SWIGTYPE_p_wxMenu, 0);
52
+ $result = SWIG_Ruby_AppendOutput($result, rb_menu);
91
53
  __CODE
92
54
  end
93
55
  # for FindChildItem
@@ -95,87 +57,57 @@ module WXRuby3
95
57
  spec.add_header_code <<~__HEREDOC
96
58
  WXRUBY_TRACE_GUARD(WxRubyTraceMarkMenu, "GC_MARK_MENU")
97
59
 
98
- // forward decl
99
- SWIGINTERN void free_wxMenu(void *self);
60
+ // Custom subclass implementation.
61
+ // Provides proper support for Ruby GC in destructor.
62
+ class wxRubyMenu : public wxMenu
63
+ {
64
+ public:
65
+ wxRubyMenu() : wxMenu() {}
66
+ wxRubyMenu(const wxString &title, long style=0) : wxMenu(title, style) {}
67
+ virtual ~wxRubyMenu()
68
+ {
69
+ VALUE rb_menu = SWIG_RubyInstanceFor(this);
70
+ if (!RB_NIL_P(rb_menu))
71
+ {
72
+ // delete from C++ code as the Ruby GC free func removes tracking before delete
73
+
74
+ // make sure to unlink and remove any tracked Ruby wrapper
75
+ SWIG_RubyUnlinkObjects(this);
76
+ SWIG_RubyRemoveTracking(this);
77
+ }
78
+ }
79
+ };
100
80
 
101
- static void _gc_mark_single_wxMenu(wxMenu *wx_menu, VALUE rb_menu)
81
+ static void GC_mark_wxMenu(void* ptr)
102
82
  {
103
83
  WXRUBY_TRACE_IF(WxRubyTraceMarkMenu, 2)
104
- WXRUBY_TRACE("> GC_mark_attached_wxMenu : " << wx_menu)
84
+ WXRUBY_TRACE("> GC_mark_wxMenu : " << ptr)
105
85
  WXRUBY_TRACE_END
106
-
107
- rb_gc_mark(rb_menu);
86
+
87
+ if (!ptr) return;
88
+
89
+ wxMenu* wx_menu = reinterpret_cast<wxMenu*> (ptr);
108
90
 
109
91
  wxMenuItemList wx_menu_items = wx_menu->GetMenuItems();
110
92
  wxMenuItemList::iterator iter;
111
93
  for (iter = wx_menu_items.begin(); iter != wx_menu_items.end(); ++iter)
112
94
  {
113
95
  wxMenuItem *wx_item = *iter;
114
- rb_gc_mark(SWIG_RubyInstanceFor(wx_item) );
96
+ rb_gc_mark(SWIG_RubyInstanceFor(wx_item));
115
97
  wxMenu* wx_sub_menu = wx_item->GetSubMenu();
116
98
  if (wx_sub_menu)
117
99
  {
118
- VALUE rb_sub_menu = wxRuby_FindCategoryValue(wxRubyMenu::TRACKING_CAT, wx_sub_menu);
119
- _gc_mark_single_wxMenu(wx_sub_menu, rb_sub_menu);
100
+ rb_gc_mark(SWIG_RubyInstanceFor(wx_sub_menu));
120
101
  }
121
102
  }
122
103
 
123
104
  WXRUBY_TRACE_IF(WxRubyTraceMarkMenu, 2)
124
- WXRUBY_TRACE("< GC_mark_attached_wxMenu : " << wx_menu)
125
- WXRUBY_TRACE_END
126
- }
127
-
128
- // Mark Function
129
- // Need to protect MenuItems which are included in the Menu, including
130
- // their associated sub-menus, recursively.
131
- static void GC_mark_wxMenu(const TGCTrackingValueMap& values)
132
- {
133
- WXRUBY_TRACE_IF(WxRubyTraceMarkMenu, 2)
134
- WXRUBY_TRACE("> GC_mark_wxMenu")
135
- WXRUBY_TRACE_END
136
-
137
- for (const auto& ti : values)
138
- {
139
- _gc_mark_single_wxMenu(static_cast<wxMenu*> (ti.first), ti.second);
140
- }
141
-
142
- WXRUBY_TRACE_IF(WxRubyTraceMarkMenu, 2)
143
- WXRUBY_TRACE("< GC_mark_wxMenu")
105
+ WXRUBY_TRACE("< GC_mark_wxMenu : " << wx_menu)
144
106
  WXRUBY_TRACE_END
145
107
  }
146
-
147
- WXRUBY_EXPORT VALUE wxRuby_WrapWxMenuInRuby(wxMenu* wx_menu)
148
- {
149
- VALUE rb_menu = Qnil;
150
- if (wx_menu)
151
- {
152
- rb_menu = wxRuby_FindCategoryValue(wxRubyMenu::TRACKING_CAT, wx_menu); // check for already registered instance
153
- if (NIL_P(rb_menu))
154
- {
155
- // newly created
156
- wxRubyMenu* wxrb_menu = dynamic_cast<wxRubyMenu*> (wx_menu);
157
- if (wxrb_menu)
158
- {
159
- // convert and own
160
- rb_menu = SWIG_NewPointerObj(SWIG_as_voidptr(wxrb_menu), SWIGTYPE_p_wxMenu, SWIG_POINTER_OWN);
161
- wxrb_menu->wxruby_register(rb_menu);
162
- }
163
- else
164
- {
165
- // created internally by wxWidgets; no tracking and no ownership
166
- rb_menu = SWIG_NewPointerObj(SWIG_as_voidptr(wx_menu), SWIGTYPE_p_wxMenu, 0);
167
- }
168
- }
169
- }
170
- return rb_menu;
171
- }
172
-
173
- WXRUBY_EXPORT void wxRuby_RegisterWxMenu(wxMenu* wx_menu, VALUE rb_menu)
174
- {
175
- wxRubyMenu* wxrb_menu = dynamic_cast<wxRubyMenu*> (wx_menu);
176
- if (wxrb_menu) wxrb_menu->wxruby_register(rb_menu);
177
- }
178
108
  __HEREDOC
109
+ # make Ruby director and wrappers use custom implementation
110
+ spec.use_class_implementation('wxMenu', 'wxRubyMenu')
179
111
  # ignore MSW specific method
180
112
  spec.ignore 'wxMenu::MSWCommand'
181
113
  # fix SWIG's problems with const& return value