wxruby3 1.7.0 → 1.8.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.
- checksums.yaml +4 -4
- data/INSTALL.md +27 -2
- data/README.md +15 -15
- data/ext/wxruby3/include/wxRubyApp.h +145 -46
- data/ext/wxruby3/include/wxruby-ComboPopup.h +25 -8
- data/ext/wxruby3/include/wxruby-GCTracking.h +262 -0
- data/ext/wxruby3/include/wxruby-MBConv.h +190 -0
- data/ext/wxruby3/include/wxruby-SharedEventHandler.h +183 -0
- data/ext/wxruby3/include/wxruby-SharedPtr.h +104 -0
- data/ext/wxruby3/include/wxruby-runtime.h +29 -0
- data/ext/wxruby3/swig/custom/rubytracking.swg +8 -22
- data/ext/wxruby3/swig/custom/wx_ruby_shared_ptr.i +434 -0
- data/ext/wxruby3/swig/custom/wx_shared_ptr.i +431 -0
- data/ext/wxruby3/swig/mark_free_impl.i +7 -132
- data/ext/wxruby3/swig/memory_management.i +8 -44
- data/ext/wxruby3/swig/wx.i +46 -73
- data/lib/wx/core/const.rb +0 -1
- data/lib/wx/core/context_help.rb +17 -0
- data/lib/wx/core/cursor.rb +1 -0
- data/lib/wx/core/helpcontrollerhelpprovider.rb +10 -2
- data/lib/wx/core/mbconv.rb +11 -0
- data/lib/wx/core/media_ctrl.rb +31 -0
- data/lib/wx/core/top_level_window.rb +7 -0
- data/lib/wx/core.rb +6 -0
- data/lib/wx/doc/art_provider.rb +17 -0
- data/lib/wx/doc/context_help.rb +42 -0
- data/lib/wx/doc/core.rb +0 -5
- data/lib/wx/doc/functions.rb +10 -0
- data/lib/wx/doc/gen/affine_matrix2d.rb +2 -0
- data/lib/wx/doc/gen/art_provider.rb +12 -0
- data/lib/wx/doc/gen/aui/aui_notebook_event.rb +15 -15
- data/lib/wx/doc/gen/aui/aui_pane_info.rb +8 -8
- data/lib/wx/doc/gen/aui/aui_tool_bar_event.rb +5 -5
- data/lib/wx/doc/gen/book_ctrl_base.rb +2 -1
- data/lib/wx/doc/gen/calendar_event.rb +5 -5
- data/lib/wx/doc/gen/choicebook.rb +2 -2
- data/lib/wx/doc/gen/collapsible_pane.rb +1 -1
- data/lib/wx/doc/gen/colour_dialog.rb +1 -1
- data/lib/wx/doc/gen/colour_picker_event.rb +3 -3
- data/lib/wx/doc/gen/context_help_button.rb +0 -53
- data/lib/wx/doc/gen/core.rb +4 -4
- data/lib/wx/doc/gen/credential_entry_dialog.rb +2 -2
- data/lib/wx/doc/gen/date_event.rb +2 -2
- data/lib/wx/doc/gen/dial_up_event.rb +2 -2
- data/lib/wx/doc/gen/dir_filter_list_ctrl.rb +2 -2
- data/lib/wx/doc/gen/event.rb +58 -58
- data/lib/wx/doc/gen/ext_help_controller.rb +62 -16
- data/lib/wx/doc/gen/file_ctrl.rb +4 -4
- data/lib/wx/doc/gen/file_dir_picker_event.rb +2 -2
- data/lib/wx/doc/gen/file_system.rb +1 -1
- data/lib/wx/doc/gen/find_dialog_event.rb +5 -5
- data/lib/wx/doc/gen/font_picker_event.rb +1 -1
- data/lib/wx/doc/gen/grid/grid_ctrl.rb +67 -32
- data/lib/wx/doc/gen/header_ctrl_event.rb +13 -13
- data/lib/wx/doc/gen/help_controller.rb +45 -2
- data/lib/wx/doc/gen/html/html_help_controller.rb +74 -32
- data/lib/wx/doc/gen/html/html_help_window.rb +3 -3
- data/lib/wx/doc/gen/html/html_window.rb +4 -4
- data/lib/wx/doc/gen/hyperlink_ctrl.rb +1 -1
- data/lib/wx/doc/gen/list_ctrl.rb +22 -22
- data/lib/wx/doc/gen/listbook.rb +2 -2
- data/lib/wx/doc/gen/mb_conv.rb +10 -0
- data/lib/wx/doc/gen/media_event.rb +6 -6
- data/lib/wx/doc/gen/notebook.rb +2 -2
- data/lib/wx/doc/gen/pg/pg_validation_info.rb +14 -14
- data/lib/wx/doc/gen/pg/property_grid_interface.rb +2 -2
- data/lib/wx/doc/gen/rbn/ribbon_art_provider.rb +19 -9
- data/lib/wx/doc/gen/rbn/ribbon_button_bar.rb +2 -2
- data/lib/wx/doc/gen/rbn/ribbon_gallery.rb +3 -3
- data/lib/wx/doc/gen/rbn/ribbon_panel.rb +2 -2
- data/lib/wx/doc/gen/rbn/ribbon_tool_bar.rb +2 -2
- data/lib/wx/doc/gen/rt/event_list.rb +17 -0
- data/lib/wx/doc/gen/rt/shared_evt_handler.rb +14 -0
- data/lib/wx/doc/gen/rt/thread_event.rb +71 -0
- data/lib/wx/doc/gen/rtc/rich_text_ctrl.rb +19 -19
- data/lib/wx/doc/gen/sash_event.rb +2 -2
- data/lib/wx/doc/gen/sash_layout_window.rb +2 -2
- data/lib/wx/doc/gen/search_ctrl.rb +2 -2
- data/lib/wx/doc/gen/spin_ctrl.rb +2 -2
- data/lib/wx/doc/gen/splitter_window.rb +6 -6
- data/lib/wx/doc/gen/stc/styled_text_event.rb +34 -34
- data/lib/wx/doc/gen/task_bar_icon_event.rb +10 -10
- data/lib/wx/doc/gen/text_ctrl.rb +4 -4
- data/lib/wx/doc/gen/toggle_button.rb +1 -1
- data/lib/wx/doc/gen/toolbook.rb +2 -2
- data/lib/wx/doc/gen/top_level_window.rb +19 -0
- data/lib/wx/doc/gen/tree_ctrl.rb +21 -21
- data/lib/wx/doc/gen/treebook.rb +4 -4
- data/lib/wx/doc/gen/utils.rb +2 -2
- data/lib/wx/doc/gen/web/event_list.rb +95 -0
- data/lib/wx/doc/gen/web/web_view.rb +1136 -0
- data/lib/wx/doc/gen/web/web_view_event.rb +210 -0
- data/lib/wx/doc/gen/web/web_view_handler.rb +318 -0
- data/lib/wx/doc/gen/window.rb +1 -1
- data/lib/wx/doc/gen/wizard_event.rb +7 -7
- data/lib/wx/doc/html/html_help_controller.rb +23 -1
- data/lib/wx/doc/mbconv.rb +108 -0
- data/lib/wx/doc/rt/shared_event_handler.rb +49 -0
- data/lib/wx/doc/rt/thread_event.rb +28 -0
- data/lib/wx/doc/webview.rb +40 -0
- data/lib/wx/helpers.rb +1 -1
- data/lib/wx/html/htmlhelpcontroller.rb +10 -0
- data/lib/wx/keyword_defs.rb +11 -0
- data/lib/wx/rt/events/evt_list.rb +8 -0
- data/lib/wx/rt/require.rb +8 -0
- data/lib/wx/rt/thread_event.rb +14 -0
- data/lib/wx/rt.rb +16 -0
- data/lib/wx/version.rb +1 -1
- data/lib/wx/web/events/evt_list.rb +74 -0
- data/lib/wx/web/require.rb +8 -0
- data/lib/wx/web/webview.rb +106 -0
- data/lib/wx/web.rb +17 -0
- data/lib/wx/wxruby/cmd/setup.rb +15 -0
- data/lib/wx.rb +2 -0
- data/rakelib/configure.rb +24 -0
- data/rakelib/gem.rb +3 -2
- data/rakelib/install.rb +54 -27
- data/rakelib/lib/config/macosx.rb +7 -5
- data/rakelib/lib/config/mingw.rb +66 -5
- data/rakelib/lib/config/pkgman/mingw.rb +1 -1
- data/rakelib/lib/config/unixish.rb +4 -2
- data/rakelib/lib/config.rb +37 -3
- data/rakelib/lib/core/include/client_data.inc +38 -17
- data/rakelib/lib/core/include/funcall.inc +1 -1
- data/rakelib/lib/core/include/swigdirector.inc +3 -3
- data/rakelib/lib/core/include/swigrubyrun.inc +14 -26
- data/rakelib/lib/core/package.rb +0 -2
- data/rakelib/lib/director/app.rb +1 -8
- data/rakelib/lib/director/art_provider.rb +7 -3
- data/rakelib/lib/director/comboctrl.rb +0 -7
- data/rakelib/lib/director/context_help_button.rb +35 -2
- data/rakelib/lib/director/event_handler.rb +32 -28
- data/rakelib/lib/director/fs_file.rb +15 -10
- data/rakelib/lib/director/functions.rb +8 -0
- data/rakelib/lib/director/grid_cell_attr.rb +1 -3
- data/rakelib/lib/director/grid_cell_editor.rb +14 -12
- data/rakelib/lib/director/grid_cell_renderer.rb +11 -8
- data/rakelib/lib/director/grid_ctrl.rb +140 -121
- data/rakelib/lib/director/help_controller.rb +70 -2
- data/rakelib/lib/director/mb_conv.rb +30 -0
- data/rakelib/lib/director/menu.rb +92 -42
- data/rakelib/lib/director/menu_bar.rb +84 -45
- data/rakelib/lib/director/menu_item.rb +2 -2
- data/rakelib/lib/director/persistence_manager.rb +3 -2
- data/rakelib/lib/director/preview_frame.rb +2 -2
- data/rakelib/lib/director/richtext_buffer.rb +5 -2
- data/rakelib/lib/director/shared_evt_handler.rb +30 -0
- data/rakelib/lib/director/sizer.rb +8 -17
- data/rakelib/lib/director/sizer_item.rb +3 -4
- data/rakelib/lib/director/task_bar_icon.rb +7 -7
- data/rakelib/lib/director/thread_event.rb +33 -0
- data/rakelib/lib/director/validator.rb +3 -1
- data/rakelib/lib/director/variant.rb +16 -12
- data/rakelib/lib/director/webview.rb +166 -0
- data/rakelib/lib/director/webview_event.rb +37 -0
- data/rakelib/lib/director/webview_handler.rb +63 -0
- data/rakelib/lib/generate/doc/thread_event.yaml +20 -0
- data/rakelib/lib/generate/doc/web_view.yaml +135 -0
- data/rakelib/lib/generate/doc/web_view_event.yaml +38 -0
- data/rakelib/lib/generate/doc/web_view_handler.yaml +58 -0
- data/rakelib/lib/specs/interfaces.rb +12 -0
- data/rakelib/lib/typemap/common.rb +34 -1
- data/rakelib/lib/typemap/mb_conv.rb +58 -0
- data/rakelib/prepost.rake +23 -31
- data/rakelib/prepost.rb +20 -0
- data/samples/event/threaded.rb +295 -42
- data/samples/event/tn_threaded.png +0 -0
- data/samples/help/doc/back.gif +0 -0
- data/samples/help/doc/contents.gif +0 -0
- data/samples/help/doc/cshelp.txt +9 -0
- data/samples/help/doc/doc.chm +0 -0
- data/samples/help/doc/doc.cnt +8 -0
- data/samples/help/doc/doc.h +7 -0
- data/samples/help/doc/doc.hhc +40 -0
- data/samples/help/doc/doc.hhk +31 -0
- data/samples/help/doc/doc.hhp +33 -0
- data/samples/help/doc/doc.hpj +21 -0
- data/samples/help/doc/doc.htm +27 -0
- data/samples/help/doc/doc1.htm +24 -0
- data/samples/help/doc/doc2.htm +12 -0
- data/samples/help/doc/doc3.htm +12 -0
- data/samples/help/doc/doc4.htm +12 -0
- data/samples/help/doc/doc5.htm +14 -0
- data/samples/help/doc/forward.gif +0 -0
- data/samples/help/doc/up.gif +0 -0
- data/samples/help/doc.chm +0 -0
- data/samples/help/doc.chw +0 -0
- data/samples/help/doc.zip +0 -0
- data/samples/help/help.rb +352 -0
- data/samples/help/tn_help.png +0 -0
- data/samples/webview/handler_advanced.html +55 -0
- data/samples/webview/tn_webview.png +0 -0
- data/samples/webview/webview.rb +1264 -0
- data/tests/assets/handler_advanced.html +55 -0
- data/tests/assets/test.css +1 -0
- data/tests/assets/test.html +9 -0
- data/tests/assets/test.zip +0 -0
- data/tests/lib/text_entry_tests.rb +2 -2
- data/tests/lib/wxapp_runner.rb +40 -0
- data/tests/lib/wxframe_runner.rb +17 -2
- data/tests/test_art.rb +8 -8
- data/tests/test_clipboard.rb +4 -4
- data/tests/test_config.rb +6 -6
- data/tests/test_exceptions.rb +8 -6
- data/tests/test_ext_controls.rb +3 -3
- data/tests/test_file_dialog.rb +5 -5
- data/tests/test_font.rb +7 -7
- data/tests/test_grid_ctrl.rb +133 -0
- data/tests/test_help.rb +88 -0
- data/tests/test_intl.rb +1 -1
- data/tests/test_media_ctrl.rb +14 -6
- data/tests/test_menu.rb +94 -86
- data/tests/test_persistence.rb +1 -1
- data/tests/test_proof_check.rb +5 -5
- data/tests/test_propgrid.rb +1 -1
- data/tests/test_shared_event_handler.rb +141 -0
- data/tests/test_std_controls.rb +5 -5
- data/tests/test_webview.rb +492 -0
- data/tests/test_window.rb +3 -3
- metadata +78 -2
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
// Copyright (c) 2023 M.J.N. Corino, The Netherlands
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT license.
|
|
4
|
+
|
|
5
|
+
#include <wx/thread.h>
|
|
6
|
+
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
|
|
10
|
+
typedef std::unordered_map<void*, VALUE> TGCTrackingValueMap;
|
|
11
|
+
typedef void (* TGCMarkerFunction)(const TGCTrackingValueMap&);
|
|
12
|
+
|
|
13
|
+
typedef struct
|
|
14
|
+
{
|
|
15
|
+
TGCMarkerFunction marker_ {};
|
|
16
|
+
TGCTrackingValueMap values_ {};
|
|
17
|
+
// false by default causing the marker function to be always called
|
|
18
|
+
// can become true if actual values are added/removed in which case
|
|
19
|
+
// the marker will only be called if there any values tracked
|
|
20
|
+
bool has_data_ {true};
|
|
21
|
+
} TGCTrackingItem;
|
|
22
|
+
|
|
23
|
+
typedef std::unordered_map<std::string, TGCTrackingItem> TGCTrackingTable;
|
|
24
|
+
|
|
25
|
+
static void __wxruby_mark_SWIG_objects(const TGCTrackingValueMap& values);
|
|
26
|
+
|
|
27
|
+
class SGCTracking
|
|
28
|
+
{
|
|
29
|
+
private:
|
|
30
|
+
static const std::string SWIG_TRACKING;
|
|
31
|
+
|
|
32
|
+
TGCTrackingItem& tracking_item(const std::string& cat) { return this->map_[cat]; }
|
|
33
|
+
TGCTrackingValueMap& tracking_map(const std::string& cat) { return this->map_[cat].values_; }
|
|
34
|
+
|
|
35
|
+
wxCriticalSection lock_ {};
|
|
36
|
+
|
|
37
|
+
TGCTrackingTable map_ {};
|
|
38
|
+
|
|
39
|
+
public:
|
|
40
|
+
SGCTracking()
|
|
41
|
+
{
|
|
42
|
+
// create a tracking entry for SWIG objects with the appropriate marker
|
|
43
|
+
this->map_[SWIG_TRACKING].marker_ = __wxruby_mark_SWIG_objects;
|
|
44
|
+
this->map_[SWIG_TRACKING].has_data_ = true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
void add_category(std::string cat, TGCMarkerFunction marker, bool has_data = false)
|
|
48
|
+
{
|
|
49
|
+
wxCriticalSectionLocker guard(this->lock_);
|
|
50
|
+
this->map_[cat].marker_ = marker;
|
|
51
|
+
this->map_[cat].has_data_ = has_data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
void add_tracking(const std::string& cat, void* ptr, VALUE object)
|
|
55
|
+
{
|
|
56
|
+
wxCriticalSectionLocker guard(this->lock_);
|
|
57
|
+
auto& ti = tracking_item(cat);
|
|
58
|
+
ti.values_[ptr] = object;
|
|
59
|
+
if (!ti.has_data_) ti.has_data_ = true;
|
|
60
|
+
}
|
|
61
|
+
void remove_tracking(const std::string& cat, void* ptr)
|
|
62
|
+
{
|
|
63
|
+
wxCriticalSectionLocker guard(this->lock_);
|
|
64
|
+
auto& ti = tracking_item(cat);
|
|
65
|
+
ti.values_.erase(ptr);
|
|
66
|
+
}
|
|
67
|
+
VALUE find_tracking(const std::string& cat, void* ptr)
|
|
68
|
+
{
|
|
69
|
+
wxCriticalSectionLocker guard(this->lock_);
|
|
70
|
+
auto& map = tracking_map(cat);
|
|
71
|
+
auto it = map.find(ptr);
|
|
72
|
+
return it == map.end() ? Qnil : it->second;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
void swig_add_tracking(void* ptr, VALUE object)
|
|
76
|
+
{
|
|
77
|
+
add_tracking(SWIG_TRACKING, ptr, object);
|
|
78
|
+
}
|
|
79
|
+
void swig_remove_tracking(void* ptr)
|
|
80
|
+
{
|
|
81
|
+
remove_tracking(SWIG_TRACKING, ptr);
|
|
82
|
+
}
|
|
83
|
+
VALUE swig_find_tracking(void* ptr)
|
|
84
|
+
{
|
|
85
|
+
return find_tracking(SWIG_TRACKING, ptr);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
void run_markers()
|
|
89
|
+
{
|
|
90
|
+
wxCriticalSectionLocker guard(this->lock_);
|
|
91
|
+
for (const auto& gti : this->map_)
|
|
92
|
+
{
|
|
93
|
+
if (!gti.second.has_data_ || !gti.second.values_.empty())
|
|
94
|
+
(*gti.second.marker_)(gti.second.values_);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const std::string SGCTracking::SWIG_TRACKING = {"SWIG_TRACKING"};
|
|
100
|
+
|
|
101
|
+
static SGCTracking __g_GCTracking {};
|
|
102
|
+
|
|
103
|
+
WXRUBY_TRACE_GUARD(WxRubyTraceGCTrackSWIG, "GC_TRACK_SWIG")
|
|
104
|
+
WXRUBY_TRACE_GUARD(WxRubyTraceGCTrackRegistry, "GC_TRACK_REGISTRY")
|
|
105
|
+
|
|
106
|
+
// When ruby's garbage collection runs, if the app is still active, it
|
|
107
|
+
// the marking phase on currently known SWIG objects which calls this
|
|
108
|
+
// function on each to preserve still active Wx::Windows, and also
|
|
109
|
+
// pending Wx::Events which have been queued from the Ruby side (the
|
|
110
|
+
// only sort of events that will be in the tracking hash).
|
|
111
|
+
static void __wxruby_mark_SWIG_objects(const TGCTrackingValueMap& values)
|
|
112
|
+
{
|
|
113
|
+
for (const auto& vp : values)
|
|
114
|
+
{
|
|
115
|
+
// Check if it's a valid object (sometimes SWIG doesn't return what we're
|
|
116
|
+
// expecting), a descendant of Wx::Window or Wx::Event; if so, mark it.
|
|
117
|
+
if ( TYPE(vp.second) == T_DATA )
|
|
118
|
+
{
|
|
119
|
+
if ( rb_obj_is_kind_of(vp.second, wxRuby_GetWindowClass()) )
|
|
120
|
+
{
|
|
121
|
+
rb_gc_mark(vp.second);
|
|
122
|
+
}
|
|
123
|
+
else if (rb_obj_is_kind_of(vp.second, wxRuby_GetDefaultEventClass()) )
|
|
124
|
+
{
|
|
125
|
+
rb_gc_mark(vp.second);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#ifdef __cplusplus
|
|
132
|
+
extern "C" {
|
|
133
|
+
#endif
|
|
134
|
+
|
|
135
|
+
// Add a tracking from ptr -> object
|
|
136
|
+
WXRUBY_EXPORT void wxRuby_AddTracking(void* ptr, VALUE object)
|
|
137
|
+
{
|
|
138
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackSWIG, 2)
|
|
139
|
+
WXRUBY_TRACE("> wxRuby_AddTracking" << std::flush <<
|
|
140
|
+
"(" << ptr << ":{"
|
|
141
|
+
<< rb_class2name(CLASS_OF(object))
|
|
142
|
+
<< "}, " << object << ")")
|
|
143
|
+
WXRUBY_TRACE_END
|
|
144
|
+
|
|
145
|
+
// Check if an 'old' tracking registry exists.
|
|
146
|
+
VALUE old_obj = __g_GCTracking.swig_find_tracking(ptr);
|
|
147
|
+
if (!RB_NIL_P(old_obj))
|
|
148
|
+
{
|
|
149
|
+
// This can happen if the C++ referenced by a Ruby object is managed by
|
|
150
|
+
// a wxWidgets object and deleted without unlinking the Ruby object.
|
|
151
|
+
// In these cases we unlink the previously linked Ruby object here
|
|
152
|
+
// (if not the same Ruby object which should not be possible).
|
|
153
|
+
// This will prevent SIGSEGV when attempting to call anything for
|
|
154
|
+
// these objects but instead cause more informative exceptions.
|
|
155
|
+
if (old_obj != object)
|
|
156
|
+
{
|
|
157
|
+
DATA_PTR(old_obj) = 0;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
}
|
|
161
|
+
__g_GCTracking.swig_add_tracking(ptr, object);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// Return the ruby object for ptr
|
|
165
|
+
WXRUBY_EXPORT VALUE wxRuby_FindTracking(void* ptr)
|
|
166
|
+
{
|
|
167
|
+
return __g_GCTracking.swig_find_tracking(ptr);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Remove the tracking for ptr
|
|
171
|
+
WXRUBY_EXPORT void wxRuby_RemoveTracking(void* ptr)
|
|
172
|
+
{
|
|
173
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackSWIG, 2)
|
|
174
|
+
WXRUBY_TRACE("< wxRuby_RemoveTracking(" << ptr << ") -> " << __g_GCTracking.swig_find_tracking(ptr))
|
|
175
|
+
WXRUBY_TRACE_END
|
|
176
|
+
|
|
177
|
+
__g_GCTracking.swig_remove_tracking(ptr);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
WXRUBY_EXPORT void wxRuby_UnlinkObject(void* ptr)
|
|
181
|
+
{
|
|
182
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackSWIG, 2)
|
|
183
|
+
WXRUBY_TRACE("< wxRuby_UnlinkObject(" << ptr << ") -> " << __g_GCTracking.swig_find_tracking(ptr))
|
|
184
|
+
WXRUBY_TRACE_END
|
|
185
|
+
|
|
186
|
+
VALUE object = __g_GCTracking.swig_find_tracking(ptr);
|
|
187
|
+
if (object != Qnil)
|
|
188
|
+
{
|
|
189
|
+
DATA_PTR(object) = 0;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
#ifdef __cplusplus
|
|
194
|
+
}
|
|
195
|
+
#endif
|
|
196
|
+
|
|
197
|
+
WXRUBY_EXPORT void wxRuby_MarkTracked()
|
|
198
|
+
{
|
|
199
|
+
__g_GCTracking.run_markers();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
WXRUBY_EXPORT void wxRuby_RegisterTrackingCategory(std::string category, TGCMarkerFunction marker, bool has_data)
|
|
203
|
+
{
|
|
204
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackRegistry, 2)
|
|
205
|
+
WXRUBY_TRACE("< wxRuby_RegisterTrackingCategory(" << category.c_str() << ", " << marker << ")")
|
|
206
|
+
WXRUBY_TRACE_END
|
|
207
|
+
|
|
208
|
+
// create a tracking entry
|
|
209
|
+
__g_GCTracking.add_category(category, marker, has_data);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
WXRUBY_EXPORT void wxRuby_RegisterCategoryValue(const std::string &category, void *ptr, VALUE object)
|
|
213
|
+
{
|
|
214
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackRegistry, 2)
|
|
215
|
+
WXRUBY_TRACE("> wxRuby_RegisterCategoryValue" << std::flush <<
|
|
216
|
+
"(" << category.c_str() << ", "
|
|
217
|
+
<< ptr << ":{"
|
|
218
|
+
<< rb_class2name(CLASS_OF(object))
|
|
219
|
+
<< "}, " << object << ")")
|
|
220
|
+
WXRUBY_TRACE_END
|
|
221
|
+
|
|
222
|
+
// Check if an 'old' tracking registry exists (should never happen but still
|
|
223
|
+
// let's be paranoid).
|
|
224
|
+
VALUE old_obj = __g_GCTracking.find_tracking(category, ptr);
|
|
225
|
+
if (!RB_NIL_P(old_obj))
|
|
226
|
+
{
|
|
227
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackRegistry, 2)
|
|
228
|
+
WXRUBY_TRACE("> wxRuby_RegisterCategoryValue : found stale VALUE " << old_obj)
|
|
229
|
+
WXRUBY_TRACE_END
|
|
230
|
+
|
|
231
|
+
if (old_obj != object)
|
|
232
|
+
{
|
|
233
|
+
DATA_PTR(old_obj) = 0;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
__g_GCTracking.add_tracking(category, ptr, object);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
WXRUBY_EXPORT void wxRuby_UnregisterCategoryValue(const std::string &category, void *ptr)
|
|
241
|
+
{
|
|
242
|
+
WXRUBY_TRACE_IF(WxRubyTraceGCTrackRegistry, 2)
|
|
243
|
+
WXRUBY_TRACE("> wxRuby_UnregisterCategoryValue" << std::flush <<
|
|
244
|
+
"(" << category.c_str() << ", " << ptr << ")")
|
|
245
|
+
WXRUBY_TRACE_END
|
|
246
|
+
|
|
247
|
+
__g_GCTracking.remove_tracking(category, ptr);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
WXRUBY_EXPORT VALUE wxRuby_FindCategoryValue(const std::string &category, void *ptr)
|
|
251
|
+
{
|
|
252
|
+
return __g_GCTracking.find_tracking(category, ptr);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
WXRUBY_EXPORT void wxRuby_UnlinkCategoryValue(const std::string &category, void* ptr)
|
|
256
|
+
{
|
|
257
|
+
VALUE object = __g_GCTracking.find_tracking(category, ptr);
|
|
258
|
+
if (object != Qnil)
|
|
259
|
+
{
|
|
260
|
+
DATA_PTR(object) = 0;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// Copyright (c) 2023 M.J.N. Corino, The Netherlands
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT license.
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* WxRuby3 Wx::MBConv classes
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#include <wx/strconv.h>
|
|
10
|
+
#include <wx/convauto.h>
|
|
11
|
+
#include <memory>
|
|
12
|
+
|
|
13
|
+
static VALUE cWxMBConv;
|
|
14
|
+
|
|
15
|
+
// instance variable for MBConv classes
|
|
16
|
+
static const char * __iv_cMBConv_conv_id = "@conv_id";
|
|
17
|
+
|
|
18
|
+
static VALUE wx_MBConv_initialize(int argc, VALUE *argv, VALUE self)
|
|
19
|
+
{
|
|
20
|
+
static const std::string classname {"Wx::MBConv"};
|
|
21
|
+
if (classname == rb_obj_classname(self))
|
|
22
|
+
{
|
|
23
|
+
rb_raise(rb_eNameError,"accessing abstract class or protected constructor");
|
|
24
|
+
return Qnil;
|
|
25
|
+
}
|
|
26
|
+
if (argc > 0)
|
|
27
|
+
{
|
|
28
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)", argc);
|
|
29
|
+
return Qnil;
|
|
30
|
+
}
|
|
31
|
+
return self;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// instance variable for derived Wx::CSConv and Wx::ConvAuto classes
|
|
35
|
+
static const char * __iv_csconv_encoding = "@encoding"; // Wx::FontEncoding enum or string
|
|
36
|
+
|
|
37
|
+
static VALUE wx_CSConv_initialize(int argc, VALUE *argv, VALUE self)
|
|
38
|
+
{
|
|
39
|
+
if (argc != 1)
|
|
40
|
+
{
|
|
41
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
|
|
42
|
+
return Qnil;
|
|
43
|
+
}
|
|
44
|
+
if (!wxRuby_IsEnumValue("FontEncoding", argv[0]) && TYPE(argv[0]) != T_STRING)
|
|
45
|
+
{
|
|
46
|
+
VALUE msg = rb_inspect(argv[0]);
|
|
47
|
+
rb_raise(rb_eTypeError, "expected Wx::FontEncoding or String for 1 but got %s", StringValuePtr(msg));
|
|
48
|
+
return Qnil;
|
|
49
|
+
}
|
|
50
|
+
rb_iv_set(self, __iv_csconv_encoding, argv[0]);
|
|
51
|
+
return self;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
static VALUE wx_ConvAuto_initialize(int argc, VALUE *argv, VALUE self)
|
|
55
|
+
{
|
|
56
|
+
if (argc != 1)
|
|
57
|
+
{
|
|
58
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
|
|
59
|
+
return Qnil;
|
|
60
|
+
}
|
|
61
|
+
if (!wxRuby_IsEnumValue("FontEncoding", argv[0]))
|
|
62
|
+
{
|
|
63
|
+
VALUE msg = rb_inspect(argv[0]);
|
|
64
|
+
rb_raise(rb_eTypeError, "expected Wx::FontEncoding for 1 but got %s", StringValuePtr(msg));
|
|
65
|
+
return Qnil;
|
|
66
|
+
}
|
|
67
|
+
rb_iv_set(self, __iv_csconv_encoding, argv[0]);
|
|
68
|
+
return self;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static VALUE wxConvAuto_disable_fallback_encoding(int argc, VALUE* argv, VALUE self)
|
|
72
|
+
{
|
|
73
|
+
if (argc > 0)
|
|
74
|
+
{
|
|
75
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)", argc);
|
|
76
|
+
return Qnil;
|
|
77
|
+
}
|
|
78
|
+
wxConvAuto::DisableFallbackEncoding();
|
|
79
|
+
return Qnil;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
static VALUE wxConvAuto_get_fallback_encoding(int argc, VALUE* argv, VALUE self)
|
|
83
|
+
{
|
|
84
|
+
if (argc > 0)
|
|
85
|
+
{
|
|
86
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 0)", argc);
|
|
87
|
+
return Qnil;
|
|
88
|
+
}
|
|
89
|
+
wxFontEncoding enc = wxConvAuto::GetFallbackEncoding();
|
|
90
|
+
return wxRuby_GetEnumValueObject("FontEncoding", static_cast<int>(enc));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
static VALUE wxConvAuto_set_fallback_encoding(int argc, VALUE* argv, VALUE self)
|
|
94
|
+
{
|
|
95
|
+
if (argc != 1)
|
|
96
|
+
{
|
|
97
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)", argc);
|
|
98
|
+
return Qnil;
|
|
99
|
+
}
|
|
100
|
+
int eval;
|
|
101
|
+
if (!wxRuby_GetEnumValue("FontEncoding", argv[0], eval))
|
|
102
|
+
{
|
|
103
|
+
VALUE msg = rb_inspect(argv[0]);
|
|
104
|
+
rb_raise(rb_eTypeError, "expected Wx::FontEncoding for 1 but got %s", StringValuePtr(msg));
|
|
105
|
+
return Qnil;
|
|
106
|
+
}
|
|
107
|
+
wxConvAuto::SetFallbackEncoding(static_cast<wxFontEncoding> (eval));
|
|
108
|
+
return Qnil;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static WxRuby_ID mbconv_cs_id("CSConv");
|
|
112
|
+
static WxRuby_ID mbconv_auto_id("ConvAuto");
|
|
113
|
+
static WxRuby_ID mbconv_utf16_id("ConvUTF16");
|
|
114
|
+
static WxRuby_ID mbconv_utf32_id("ConvUTF32");
|
|
115
|
+
static WxRuby_ID mbconv_utf7_id("ConvUTF7");
|
|
116
|
+
static WxRuby_ID mbconv_utf8_id("ConvUTF8");
|
|
117
|
+
|
|
118
|
+
static void wx_setup_MBConv()
|
|
119
|
+
{
|
|
120
|
+
cWxMBConv = rb_define_class_under(mWxCore, "MBConv", rb_cObject);
|
|
121
|
+
rb_define_method(cWxMBConv, "initialize", VALUEFUNC(wx_MBConv_initialize), -1);
|
|
122
|
+
|
|
123
|
+
VALUE cWxCSConv = rb_define_class_under(mWxCore, "CSConv", cWxMBConv);
|
|
124
|
+
rb_iv_set(cWxCSConv, __iv_cMBConv_conv_id, ID2SYM(mbconv_cs_id()));
|
|
125
|
+
rb_define_method(cWxCSConv, "initialize", VALUEFUNC(wx_CSConv_initialize), -1);
|
|
126
|
+
|
|
127
|
+
VALUE cWxConvAuto = rb_define_class_under(mWxCore, "ConvAuto", cWxMBConv);
|
|
128
|
+
rb_iv_set(cWxCSConv, __iv_cMBConv_conv_id, ID2SYM(mbconv_auto_id()));
|
|
129
|
+
rb_define_method(cWxConvAuto, "initialize", VALUEFUNC(wx_ConvAuto_initialize), -1);
|
|
130
|
+
rb_define_module_function(cWxConvAuto, "disable_fallback_encoding", VALUEFUNC(wxConvAuto_disable_fallback_encoding), -1);
|
|
131
|
+
rb_define_module_function(cWxConvAuto, "disable_get_encoding", VALUEFUNC(wxConvAuto_get_fallback_encoding), -1);
|
|
132
|
+
rb_define_module_function(cWxConvAuto, "disable_set_encoding", VALUEFUNC(wxConvAuto_set_fallback_encoding), -1);
|
|
133
|
+
|
|
134
|
+
VALUE cWxMBConvUTF16 = rb_define_class_under(mWxCore, "MBConvUTF16", cWxMBConv);
|
|
135
|
+
rb_iv_set(cWxMBConvUTF16, __iv_cMBConv_conv_id, ID2SYM(mbconv_utf16_id()));
|
|
136
|
+
|
|
137
|
+
VALUE cWxMBConvUTF32 = rb_define_class_under(mWxCore, "MBConvUTF32", cWxMBConv);
|
|
138
|
+
rb_iv_set(cWxMBConvUTF32, __iv_cMBConv_conv_id, ID2SYM(mbconv_utf32_id()));
|
|
139
|
+
|
|
140
|
+
VALUE cWxMBConvUTF7 = rb_define_class_under(mWxCore, "MBConvUTF7", cWxMBConv);
|
|
141
|
+
rb_iv_set(cWxMBConvUTF7, __iv_cMBConv_conv_id, ID2SYM(mbconv_utf7_id()));
|
|
142
|
+
|
|
143
|
+
VALUE cWxMBConvUTF8 = rb_define_class_under(mWxCore, "MBConvUTF8", cWxMBConv);
|
|
144
|
+
rb_iv_set(cWxMBConvUTF8, __iv_cMBConv_conv_id, ID2SYM(mbconv_utf8_id()));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
WXRB_EXPORT_FLAG std::unique_ptr<wxMBConv> wxRuby_MBConv2wxMBConv(VALUE rb_val)
|
|
148
|
+
{
|
|
149
|
+
if (rb_obj_is_kind_of(rb_val, cWxMBConv))
|
|
150
|
+
{
|
|
151
|
+
// get id for derived MBConv class
|
|
152
|
+
ID mbconv_id = SYM2ID(rb_iv_get(CLASS_OF(rb_val), __iv_cMBConv_conv_id));
|
|
153
|
+
if (mbconv_id == mbconv_cs_id())
|
|
154
|
+
{
|
|
155
|
+
VALUE encoding = rb_iv_get(rb_val, __iv_csconv_encoding);
|
|
156
|
+
if (TYPE(encoding) == T_STRING)
|
|
157
|
+
return std::make_unique<wxCSConv> (RSTR_TO_WXSTR(encoding));
|
|
158
|
+
else
|
|
159
|
+
{
|
|
160
|
+
int enc_val;
|
|
161
|
+
wxRuby_GetEnumValue("FontEncoding", encoding, enc_val);
|
|
162
|
+
return std::make_unique<wxCSConv> (static_cast<wxFontEncoding> (enc_val));
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
else if (mbconv_id == mbconv_auto_id())
|
|
166
|
+
{
|
|
167
|
+
VALUE encoding = rb_iv_get(rb_val, __iv_csconv_encoding);
|
|
168
|
+
int enc_val;
|
|
169
|
+
wxRuby_GetEnumValue("FontEncoding", encoding, enc_val);
|
|
170
|
+
return std::make_unique<wxConvAuto> (static_cast<wxFontEncoding> (enc_val));
|
|
171
|
+
}
|
|
172
|
+
else if (mbconv_id == mbconv_utf16_id())
|
|
173
|
+
{
|
|
174
|
+
return std::make_unique<wxMBConvUTF16> ();
|
|
175
|
+
}
|
|
176
|
+
else if (mbconv_id == mbconv_utf32_id())
|
|
177
|
+
{
|
|
178
|
+
return std::make_unique<wxMBConvUTF32> ();
|
|
179
|
+
}
|
|
180
|
+
else if (mbconv_id == mbconv_utf7_id())
|
|
181
|
+
{
|
|
182
|
+
return std::make_unique<wxMBConvUTF7> ();
|
|
183
|
+
}
|
|
184
|
+
else if (mbconv_id == mbconv_utf8_id())
|
|
185
|
+
{
|
|
186
|
+
return std::make_unique<wxMBConvUTF8> ();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return {};
|
|
190
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
// Copyright (c) 2023 M.J.N. Corino, The Netherlands
|
|
2
|
+
//
|
|
3
|
+
// This software is released under the MIT license.
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* WxRuby3 SharedEvtHandler class
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
#ifndef _WXRUBY_SHARED_EVTHANDLER_H
|
|
10
|
+
#define _WXRUBY_SHARED_EVTHANDLER_H
|
|
11
|
+
|
|
12
|
+
#include <wx/object.h>
|
|
13
|
+
#include <wx/event.h>
|
|
14
|
+
|
|
15
|
+
class WxRubySharedEvtHandler
|
|
16
|
+
{
|
|
17
|
+
public:
|
|
18
|
+
WxRubySharedEvtHandler(wxEvtHandler* evt_handler)
|
|
19
|
+
: evt_handler_(evt_handler) {}
|
|
20
|
+
~WxRubySharedEvtHandler() = default;
|
|
21
|
+
|
|
22
|
+
wxEvtHandler* get_evt_handler() { return this->evt_handler_; }
|
|
23
|
+
|
|
24
|
+
VALUE get_rb_shared_evt_handler() { return this->rb_shared_evt_handler_; }
|
|
25
|
+
void set_rb_shared_evt_handler(VALUE h) { this->rb_shared_evt_handler_ = h; }
|
|
26
|
+
|
|
27
|
+
WxRubySharedEvtHandler* clone()
|
|
28
|
+
{
|
|
29
|
+
if (this->evt_handler_)
|
|
30
|
+
{
|
|
31
|
+
WxRubySharedEvtHandler* clone_ = new WxRubySharedEvtHandler(this->evt_handler_);
|
|
32
|
+
return clone_;
|
|
33
|
+
}
|
|
34
|
+
return nullptr;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
private:
|
|
38
|
+
wxEvtHandler* evt_handler_ {};
|
|
39
|
+
VALUE rb_shared_evt_handler_ {Qnil};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// WxRubySharedEvtHandler wrapper class definition and helper functions
|
|
43
|
+
static size_t __WxRubySharedEvtHandler_size(const void* data)
|
|
44
|
+
{
|
|
45
|
+
return 0;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static void __WxRubySharedEvtHandler_free(void* data)
|
|
49
|
+
{
|
|
50
|
+
if (data)
|
|
51
|
+
delete (WxRubySharedEvtHandler*)data;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#include <ruby/version.h>
|
|
55
|
+
|
|
56
|
+
static const rb_data_type_t __WxRubySharedEvtHandler_type = {
|
|
57
|
+
"TreeItemId",
|
|
58
|
+
#if RUBY_API_VERSION_MAJOR >= 3
|
|
59
|
+
{ NULL, __WxRubySharedEvtHandler_free, __WxRubySharedEvtHandler_size, 0, {}},
|
|
60
|
+
#else
|
|
61
|
+
{ NULL, __WxRubySharedEvtHandler_free, __WxRubySharedEvtHandler_size, {}},
|
|
62
|
+
#endif
|
|
63
|
+
NULL, NULL, RUBY_TYPED_FROZEN_SHAREABLE
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
VALUE cWxRubySharedEvtHandler;
|
|
67
|
+
|
|
68
|
+
static VALUE WxRuby_get_EvtHandlerClass()
|
|
69
|
+
{
|
|
70
|
+
static VALUE cEvtHandler = Qnil;
|
|
71
|
+
if (RB_NIL_P(cEvtHandler))
|
|
72
|
+
{
|
|
73
|
+
cEvtHandler = rb_const_get(wxRuby_Core(), rb_intern("EvtHandler"));
|
|
74
|
+
}
|
|
75
|
+
return cEvtHandler;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
static VALUE WxRuby_MakeSharedEvtHandler(wxEvtHandler* wxeh)
|
|
79
|
+
{
|
|
80
|
+
if (wxeh)
|
|
81
|
+
{
|
|
82
|
+
// create new shared handler
|
|
83
|
+
WxRubySharedEvtHandler* seh = new WxRubySharedEvtHandler(wxeh);
|
|
84
|
+
// create Ruby wrapper object
|
|
85
|
+
VALUE rb_shared_eh =TypedData_Wrap_Struct(cWxRubySharedEvtHandler,
|
|
86
|
+
&__WxRubySharedEvtHandler_type,
|
|
87
|
+
seh);
|
|
88
|
+
rb_shared_eh = rb_obj_freeze(rb_shared_eh);
|
|
89
|
+
seh->set_rb_shared_evt_handler(rb_shared_eh);
|
|
90
|
+
return rb_shared_eh;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return Qnil;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
static wxEvtHandler* WxRuby_GetSharedEvtHandler(VALUE rb_shared_eh)
|
|
97
|
+
{
|
|
98
|
+
if (rb_typeddata_is_kind_of(rb_shared_eh, &__WxRubySharedEvtHandler_type) == 1)
|
|
99
|
+
{
|
|
100
|
+
WxRubySharedEvtHandler* shared_eh = (WxRubySharedEvtHandler*)RTYPEDDATA_DATA(rb_shared_eh);
|
|
101
|
+
if (shared_eh)
|
|
102
|
+
{
|
|
103
|
+
wxEvtHandler* wxeh = shared_eh->get_evt_handler();
|
|
104
|
+
VALUE rb_eh = wxRuby_FindTracking(wxeh);
|
|
105
|
+
if (rb_obj_is_kind_of(rb_eh, WxRuby_get_EvtHandlerClass()))
|
|
106
|
+
return wxeh;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return nullptr;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static VALUE WxRubySharedEvtHandler_clone(VALUE self)
|
|
113
|
+
{
|
|
114
|
+
WxRubySharedEvtHandler* shared_eh = (WxRubySharedEvtHandler*)RTYPEDDATA_DATA(self);
|
|
115
|
+
// create new Ruby SharedEvtHandler wrapper object with cloned WxRubySharedEvtHandler
|
|
116
|
+
VALUE clone = TypedData_Wrap_Struct(cWxRubySharedEvtHandler,
|
|
117
|
+
&__WxRubySharedEvtHandler_type,
|
|
118
|
+
shared_eh->clone());
|
|
119
|
+
return rb_obj_freeze(clone);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static VALUE WxRubySharedEvtHandler_queue_event(int argc, VALUE* argv, VALUE self)
|
|
123
|
+
{
|
|
124
|
+
// check argument count
|
|
125
|
+
if (argc != 1)
|
|
126
|
+
{
|
|
127
|
+
rb_raise(rb_eArgError, "wrong # of arguments(%d for 1)",argc);
|
|
128
|
+
return Qnil;
|
|
129
|
+
}
|
|
130
|
+
// dereference shared event handler
|
|
131
|
+
wxEvtHandler* wxeh = WxRuby_GetSharedEvtHandler(self);
|
|
132
|
+
if (wxeh)
|
|
133
|
+
{
|
|
134
|
+
// get C++ event
|
|
135
|
+
wxEvent* wxevt = (wxEvent*)DATA_PTR(argv[0]);
|
|
136
|
+
RDATA(argv[0])->dfree = 0; // disown
|
|
137
|
+
DATA_PTR(argv[0]) = nullptr; // unlink
|
|
138
|
+
// no need to remove tracking as all Ractor safe events are untracked
|
|
139
|
+
// queue event
|
|
140
|
+
wxeh->QueueEvent(wxevt);
|
|
141
|
+
}
|
|
142
|
+
else
|
|
143
|
+
{
|
|
144
|
+
rb_raise(rb_eRuntimeError, "Event handler already deleted.");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return Qnil;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
static VALUE wxRuby_EvtHandler_make_shared(VALUE self)
|
|
151
|
+
{
|
|
152
|
+
void *ptr;
|
|
153
|
+
wxEvtHandler *wxeh = nullptr;
|
|
154
|
+
ptr = DATA_PTR(self);
|
|
155
|
+
wxeh = reinterpret_cast< wxEvtHandler * >(ptr);
|
|
156
|
+
if (wxeh)
|
|
157
|
+
{
|
|
158
|
+
VALUE rb_shared_eh = WxRuby_MakeSharedEvtHandler(wxeh);
|
|
159
|
+
if (RB_NIL_P(rb_shared_eh)) rb_raise(rb_eRuntimeError, "Unable to create shared event handler");
|
|
160
|
+
return rb_shared_eh;
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
{
|
|
164
|
+
rb_raise(rb_eRuntimeError, "Object already deleted.");
|
|
165
|
+
return Qnil;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static void wx_setup_WxRubySharedEvtHandler(VALUE mWxExt)
|
|
170
|
+
{
|
|
171
|
+
// mark this extension Ractor safe
|
|
172
|
+
rb_ext_ractor_safe(true);
|
|
173
|
+
|
|
174
|
+
cWxRubySharedEvtHandler = rb_define_class_under(mWxExt, "SharedEvtHandler", rb_cObject);
|
|
175
|
+
rb_undef_alloc_func(cWxRubySharedEvtHandler);
|
|
176
|
+
rb_define_method(cWxRubySharedEvtHandler, "clone", VALUEFUNC(WxRubySharedEvtHandler_clone), 0);
|
|
177
|
+
rb_define_method(cWxRubySharedEvtHandler, "queue_event", VALUEFUNC(WxRubySharedEvtHandler_queue_event), -1);
|
|
178
|
+
|
|
179
|
+
VALUE klass = WxRuby_get_EvtHandlerClass();
|
|
180
|
+
rb_define_method(klass, "make_shared", VALUEFUNC(wxRuby_EvtHandler_make_shared), 0);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
#endif
|