From 5c2ddbb300e264d92fbaa580ca78e54c66850558 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 18 Oct 2024 14:01:48 +0200 Subject: [PATCH 1/8] add missing aliases and docs --- lib/wx/core/array_ext.rb | 1 + lib/wx/core/real_point.rb | 1 + lib/wx/doc/array_ext.rb | 1 + lib/wx/doc/gdi_common.rb | 1 + 4 files changed, 4 insertions(+) diff --git a/lib/wx/core/array_ext.rb b/lib/wx/core/array_ext.rb index 643c5588..6e89c78c 100644 --- a/lib/wx/core/array_ext.rb +++ b/lib/wx/core/array_ext.rb @@ -25,6 +25,7 @@ def to_real_point x, y = self Wx::RealPoint.new(x || Wx::DEFAULT_COORD, y || Wx::DEFAULT_COORD) end + alias :to_real :to_real_point end diff --git a/lib/wx/core/real_point.rb b/lib/wx/core/real_point.rb index 1413c038..4e3102a6 100644 --- a/lib/wx/core/real_point.rb +++ b/lib/wx/core/real_point.rb @@ -111,6 +111,7 @@ def to_point def to_real_point self end + alias :to_real :to_real_point def dup Wx::RealPoint.new(self.x, self.y) diff --git a/lib/wx/doc/array_ext.rb b/lib/wx/doc/array_ext.rb index 63bf9343..f590148c 100644 --- a/lib/wx/doc/array_ext.rb +++ b/lib/wx/doc/array_ext.rb @@ -27,6 +27,7 @@ def to_point; end # The array is not altered. # @return [Wx::RealPoint] def to_real_point; end + alias :to_real :to_real_point end diff --git a/lib/wx/doc/gdi_common.rb b/lib/wx/doc/gdi_common.rb index 7d6193e6..f2f4e918 100644 --- a/lib/wx/doc/gdi_common.rb +++ b/lib/wx/doc/gdi_common.rb @@ -209,6 +209,7 @@ def to_point; end # Returns self. # @return [self] def to_real_point; end + alias :to_real :to_real_point # Set this point to the given point's x,y values # @param [Wx::RealPoint] pt From 16a92a4a982080c47de6fee4fda7e95bdcded9b3 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 25 Oct 2024 11:20:48 +0200 Subject: [PATCH 2/8] fix typo in ignored ctor --- rakelib/lib/director/pgproperties.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rakelib/lib/director/pgproperties.rb b/rakelib/lib/director/pgproperties.rb index 0633cf73..27902ebc 100644 --- a/rakelib/lib/director/pgproperties.rb +++ b/rakelib/lib/director/pgproperties.rb @@ -162,7 +162,7 @@ def setup end else spec.ignore 'wxUIntProperty::wxUIntProperty(const wxString &, const wxString &, const wxULongLong &)', - 'wxIntProperty::wxUIntProperty(const wxString &, const wxString &, const wxLongLong &)' + 'wxIntProperty::wxIntProperty(const wxString &, const wxString &, const wxLongLong &)' end spec.new_object 'wxArrayStringProperty::CreateEditorDialog' spec.suppress_warning(473, 'wxArrayStringProperty::CreateEditorDialog') From e5799cda5931bf3fd7c48b3b70222e5353a02115 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 25 Oct 2024 11:36:53 +0200 Subject: [PATCH 3/8] fix backward compat for removal of USE_LONGLONG in wxw >= 3.3.0 --- rakelib/lib/director/pgproperties.rb | 2 +- rakelib/lib/director/property_grid_interface.rb | 7 ++++--- rakelib/lib/director/variant.rb | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/rakelib/lib/director/pgproperties.rb b/rakelib/lib/director/pgproperties.rb index 27902ebc..1c40d6a2 100644 --- a/rakelib/lib/director/pgproperties.rb +++ b/rakelib/lib/director/pgproperties.rb @@ -141,7 +141,7 @@ def setup spec.map_apply 'int * OUTPUT' => 'int* pIndex' end # for UIntProperty and IntProperty - if Config.instance.features_set?('USE_LONGLONG') + if Config.instance.features_set?('USE_LONGLONG') || Config.instance.wx_version >= '3.3.0' # wxLongLong mapping to be considered before considering 'long' (see typecheck precedence) spec.map 'const wxLongLong&' => 'Integer' do map_in temp: 'wxLongLong tmp', code: <<~__CODE diff --git a/rakelib/lib/director/property_grid_interface.rb b/rakelib/lib/director/property_grid_interface.rb index 79ba294d..0f08764c 100644 --- a/rakelib/lib/director/property_grid_interface.rb +++ b/rakelib/lib/director/property_grid_interface.rb @@ -39,9 +39,10 @@ def setup spec.extend_interface 'wxPropertyGridInterface', 'void SetPropertyValues(const wxVariant &list, const wxPGPropArgCls& defaultCategory = 0)' # optionals - spec.ignore_unless 'USE_LONGLONG', - 'wxPropertyGridInterface::GetPropertyValueAsLongLong', - 'wxPropertyGridInterface::GetPropertyValueAsULongLong' + unless Config.instance.features_set?('USE_LONGLONG') || Config.instance.wx_version >= '3.3.0' + spec.ignore_unless 'wxPropertyGridInterface::GetPropertyValueAsLongLong', + 'wxPropertyGridInterface::GetPropertyValueAsULongLong' + end spec.ignore_unless 'USE_DATETIME', 'wxPropertyGridInterface::GetPropertyValueAsDateTime' spec.ignore_unless 'USE_VALIDATORS', 'wxPropertyGridInterface::GetPropertyValidator' # fix incorrect XML documentation diff --git a/rakelib/lib/director/variant.rb b/rakelib/lib/director/variant.rb index a339201f..62c88b40 100644 --- a/rakelib/lib/director/variant.rb +++ b/rakelib/lib/director/variant.rb @@ -142,7 +142,7 @@ def setup { return wxVariant(TYPE(rbval) == T_TRUE); } - #ifdef wxUSE_LONGLONG + #if !defined(wxUSE_LONGLONG) || (wxUSE_LONGLONG == 1) if ((sizeof(long) < 8) && (TYPE(rbval) == T_BIGNUM) && (rb_big_sign(rbval) == 0)) { wxLongLong_t ll = rb_big2ll(rbval); @@ -227,7 +227,7 @@ def setup $1 = rb_obj_is_kind_of($input, rb_const_get(mWxPG, var_ColourPropertyValue_id())); __CODE end - if Config.instance.features_set?('USE_LONGLONG') + if Config.instance.features_set?('USE_LONGLONG') || Config.instance.wx_version >= '3.3.0' # wxLongLong mapping to be considered before considering 'long' (see typecheck precedence) spec.map 'wxLongLong' => 'Integer' do map_in code: <<~__CODE From 8e45a52d5ef69201db7178e40ac1ac929310428b Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 25 Oct 2024 14:39:07 +0200 Subject: [PATCH 4/8] fix typos --- rakelib/lib/typemap/common.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rakelib/lib/typemap/common.rb b/rakelib/lib/typemap/common.rb index 7e1f1800..50998f95 100644 --- a/rakelib/lib/typemap/common.rb +++ b/rakelib/lib/typemap/common.rb @@ -364,7 +364,7 @@ module Common } __CODE map_directorout code: <<~__CODE - if (TYPE($input) != T_ARRAY) + if (TYPE($input) == T_ARRAY) { for (int i = 0; i < RARRAY_LEN($input); i++) { @@ -398,7 +398,7 @@ module Common } __CODE map_directorout code: <<~__CODE - if (TYPE($input) != T_ARRAY) + if (TYPE($input) == T_ARRAY) { for (int i = 0; i < RARRAY_LEN($input); i++) { From e35931adb0819425df0dfca3e29ccac8124e44e2 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 25 Oct 2024 14:40:07 +0200 Subject: [PATCH 5/8] add support for Wx::AUI::AuiSerializer and Wx::AUI::AuiDeserializer for wxw >= 3.3.0 --- lib/wx/aui/auimanager.rb | 75 +++++++++++++---- lib/wx/doc/aui/auimanager.rb | 2 + rakelib/lib/director/aui_manager.rb | 121 +++++++++++++++++++++++++++- 3 files changed, 181 insertions(+), 17 deletions(-) diff --git a/lib/wx/aui/auimanager.rb b/lib/wx/aui/auimanager.rb index 2a6e6f09..5c1e1dc8 100644 --- a/lib/wx/aui/auimanager.rb +++ b/lib/wx/aui/auimanager.rb @@ -2,19 +2,66 @@ # # This software is released under the MIT license. -class Wx::AUI::AuiManager - def get_all_panes - ::Enumerator.new { |y| each_pane { |p| y << p } } - end - alias :all_panes :get_all_panes - - unless Wx::EvtHandler.event_type_for_name(:evt_aui_find_manager) - # missing from XML API refs - Wx::EvtHandler.register_event_type Wx::EvtHandler::EventType[ - 'evt_aui_find_manager', 0, - Wx::AUI::EVT_AUI_FIND_MANAGER, - Wx::AUI::AuiManagerEvent - ] if Wx::AUI.const_defined?(:EVT_AUI_FIND_MANAGER) - end +module Wx + module AUI + + class AuiManager + + wx_each_pane = instance_method(:each_pane) + define_method(:each_pane) do |&block| + if block + wx_each_pane.bind(self).call(&block) + else + ::Enumerator.new { |y| wx_each_pane.bind(self).call { |p| y << p } } + end + end + + def get_all_panes + each_pane.to_a + end + alias :all_panes :get_all_panes + + unless Wx::EvtHandler.event_type_for_name(:evt_aui_find_manager) + # missing from XML API refs + Wx::EvtHandler.register_event_type Wx::EvtHandler::EventType[ + 'evt_aui_find_manager', 0, + Wx::AUI::EVT_AUI_FIND_MANAGER, + Wx::AUI::AuiManagerEvent + ] if Wx::AUI.const_defined?(:EVT_AUI_FIND_MANAGER) + end + end + + if WXWIDGETS_VERSION >= '3.3.0' + + class AuiDockInfo + wx_each_pane = instance_method(:each_pane) + define_method(:each_pane) do |&block| + if block + wx_each_pane.bind(self).call(&block) + else + ::Enumerator.new { |y| wx_each_pane.bind(self).call { |p| y << p } } + end + end + + def get_panes + each_pane.to_a + end + alias :panes :get_panes + + end + + class AuiDeserializer + + wx_initialize = instance_method(:initialize) + define_method(:initialize) do |manager| + wx_initialize.bind(self).call(manager) + @manager = manager # prevent GC for lifetime of deserializer + end + + end + + end + + end end diff --git a/lib/wx/doc/aui/auimanager.rb b/lib/wx/doc/aui/auimanager.rb index a5ece6ed..4f2e8f4b 100644 --- a/lib/wx/doc/aui/auimanager.rb +++ b/lib/wx/doc/aui/auimanager.rb @@ -12,7 +12,9 @@ module AUI class AuiManager # Yield each pane to the given block. + # If no block passed returns an Enumerator. # @yieldparam [Wx::AUI::AuiPaneInfo] pane the Aui pane info yielded + # @return [::Object, ::Enumerator] result of last block execution or enumerator def each_pane; end # Returns an array of all panes managed by the frame manager. diff --git a/rakelib/lib/director/aui_manager.rb b/rakelib/lib/director/aui_manager.rb index 008bda8e..afab8b7e 100644 --- a/rakelib/lib/director/aui_manager.rb +++ b/rakelib/lib/director/aui_manager.rb @@ -16,7 +16,98 @@ class AuiManager < EvtHandler def setup super - spec.gc_as_object + spec.gc_as_object 'wxAuiManager' + if Config.instance.wx_version >= '3.3.0' + spec.items << 'wxAuiSerializer' << 'wxAuiDockInfo' << 'wxAuiDeserializer' + spec.gc_as_untracked 'wxAuiSerializer', 'wxAuiDockInfo' + spec.regard 'wxAuiDockInfo::rect', + 'wxAuiDockInfo::dock_direction', + 'wxAuiDockInfo::dock_layer', + 'wxAuiDockInfo::dock_row', + 'wxAuiDockInfo::size', + 'wxAuiDockInfo::min_size', + 'wxAuiDockInfo::resizable', + 'wxAuiDockInfo::toolbar', + 'wxAuiDockInfo::fixed', + 'wxAuiDockInfo::reserved1' + spec.make_readonly 'wxAuiDockInfo::rect', + 'wxAuiDockInfo::dock_direction', + 'wxAuiDockInfo::dock_layer', + 'wxAuiDockInfo::dock_row', + 'wxAuiDockInfo::size', + 'wxAuiDockInfo::min_size', + 'wxAuiDockInfo::resizable', + 'wxAuiDockInfo::toolbar', + 'wxAuiDockInfo::fixed', + 'wxAuiDockInfo::reserved1' + spec.add_extend_code 'wxAuiDockInfo', <<~__HEREDOC + VALUE each_pane() + { + wxAuiPaneInfoPtrArray panes = self->panes; + VALUE rc = Qnil; + for (wxAuiPaneInfo* pane : panes) + { + VALUE r_pane = SWIG_NewPointerObj(pane, SWIGTYPE_p_wxAuiPaneInfo, 0); + rc = rb_yield(r_pane); + } + return rc; + } + __HEREDOC + spec.map 'std::vector' => 'Array' do + map_out code: <<~__CODE + $result = rb_ary_new(); + std::vector& panes = (std::vector&)$1; + for (const wxAuiPaneInfo& pane : panes) + { + VALUE r_pane = SWIG_NewPointerObj(new wxAuiPaneInfo(pane), SWIGTYPE_p_wxAuiPaneInfo, SWIG_POINTER_OWN); + rb_ary_push($result, r_pane); + } + __CODE + map_directorout code: <<~__CODE + if (TYPE($input) == T_ARRAY) + { + for (int i = 0; i < RARRAY_LEN($input); i++) + { + void *ptr; + VALUE r_pane = rb_ary_entry($input, i); + int res = SWIG_ConvertPtr(r_pane, &ptr, SWIGTYPE_p_wxAuiPaneInfo, 0); + if (!SWIG_IsOK(res) || !ptr) { + Swig::DirectorTypeMismatchException::raise(swig_get_self(), "load_panes", rb_eTypeError, "in return value. Expected Array of Wx::AuiPaneInfo"); + } + wxAuiPaneInfo *pane = reinterpret_cast< wxAuiPaneInfo * >(ptr); + $result.push_back(*pane); + } + } + __CODE + end + spec.map 'std::vector' => 'Array' do + map_out code: <<~__CODE + $result = rb_ary_new(); + std::vector& docks = (std::vector&)$1; + for (const wxAuiDockInfo& dock : docks) + { + VALUE r_dock = SWIG_NewPointerObj(new wxAuiDockInfo(dock), SWIGTYPE_p_wxAuiDockInfo, SWIG_POINTER_OWN); + rb_ary_push($result, r_dock); + } + __CODE + map_directorout code: <<~__CODE + if (TYPE($input) == T_ARRAY) + { + for (int i = 0; i < RARRAY_LEN($input); i++) + { + void *ptr; + VALUE r_dock = rb_ary_entry($input, i); + int res = SWIG_ConvertPtr(r_dock, &ptr, SWIGTYPE_p_wxAuiDockInfo, 0); + if (!SWIG_IsOK(res) || !ptr) { + Swig::DirectorTypeMismatchException::raise(swig_get_self(), "load_docks", rb_eTypeError, "in return value. Expected Array of Wx::AuiDockInfo"); + } + wxAuiDockInfo *dock = reinterpret_cast< wxAuiDockInfo * >(ptr); + $result.push_back(*dock); + } + } + __CODE + end + end # need a custom implementation to handle (event handler proc) cleanup spec.add_header_code <<~__HEREDOC #include "wx/aui/aui.h" @@ -80,7 +171,7 @@ class WXRubyAuiManager : public wxAuiManager rb_gc_mark( rb_art_prov ); } } - __HEREDOC + __HEREDOC spec.add_swig_code '%markfunc wxAuiManager "GC_mark_wxAuiManager";' # provide pure Ruby implementation based on use custom alternative provided below spec.ignore('wxAuiManager::GetAllPanes') @@ -110,12 +201,36 @@ class WXRubyAuiManager : public wxAuiManager WXRubyAuiManager* aui_mng = dynamic_cast (self); managedWnd->Bind(wxEVT_CLOSE_WINDOW, &WXRubyAuiManager::OnManagedWindowClose, aui_mng); } - __HEREDOC + __HEREDOC spec.suppress_warning(473, 'wxAuiManager::CreateFloatingFrame') spec.do_not_generate(:variables, :defines, :enums, :functions) # with AuiPaneInfo end + + def doc_generator + AuiManagerDocGenerator.new(self) + end end # class AuiManager + class AuiManagerDocGenerator < DocGenerator + + def gen_class_doc_members(fdoc, clsdef, cls_members, alias_methods) + super + if Config.instance.wx_version >= '3.3.0' && clsdef.name == 'wxAuiDockInfo' + fdoc.doc.puts 'Yield each pane to the given block.' + fdoc.doc.puts 'If no block passed returns an Enumerator.' + fdoc.doc.puts '@yieldparam [Wx::AUI::AuiPaneInfo] pane the Aui pane info yielded' + fdoc.doc.puts '@return [::Object, ::Enumerator] result of last block execution or enumerator' + fdoc.puts 'def each_pane; end' + fdoc.puts + fdoc.doc.puts 'Returns an array of Wx::AuiPaneInfo for all panes managed by the frame manager.' + fdoc.doc.puts '@return [Array] info for all managed panes' + fdoc.puts 'def get_panes; end' + fdoc.puts 'alias_method :panes, :get_panes' + end + end + + end + end # class Director end # module WXRuby3 From 12766b6491c1025bcb7409581a87d183f97ca584 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 25 Oct 2024 16:13:16 +0200 Subject: [PATCH 6/8] fix backward compat --- rakelib/lib/director/dialog.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rakelib/lib/director/dialog.rb b/rakelib/lib/director/dialog.rb index 71219cc0..774973ff 100644 --- a/rakelib/lib/director/dialog.rb +++ b/rakelib/lib/director/dialog.rb @@ -230,8 +230,10 @@ def setup # regard protected methods spec.regard 'wxGenericAboutDialog::DoAddCustomControls', 'wxGenericAboutDialog::AddControl', - 'wxGenericAboutDialog::AddText', - 'wxGenericAboutDialog::GetCustomControlParent' + 'wxGenericAboutDialog::AddText' + if Config.instance.wx_version >= '3.3.0' + spec.regard 'wxGenericAboutDialog::GetCustomControlParent' + end if Config.instance.features_set?('USE_COLLPANE') spec.regard 'wxGenericAboutDialog::AddCollapsiblePane' end From c39aafc4ef4e228dc2b42af13df10f20c247e222 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Sat, 26 Oct 2024 10:58:11 +0200 Subject: [PATCH 7/8] fix SWIG backward compat for SWIG >= 4.3.0 --- ext/wxruby3/swig/custom/rubyapi.swg | 16 +++++++++++++++- rakelib/lib/core/include/swigrubyrun.inc | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ext/wxruby3/swig/custom/rubyapi.swg b/ext/wxruby3/swig/custom/rubyapi.swg index 7f3b9478..0c90bfca 100644 --- a/ext/wxruby3/swig/custom/rubyapi.swg +++ b/ext/wxruby3/swig/custom/rubyapi.swg @@ -12,8 +12,22 @@ extern "C" { #endif WXRUBY_EXPORT VALUE -SWIG_Ruby_AppendOutput(VALUE target, VALUE o); +SWIG_wxRuby_AppendOutput(VALUE target, VALUE o, int is_void); #ifdef __cplusplus } #endif + +/* SWIG >= 4.3.0 version */ +inline VALUE +SWIG_Ruby_AppendOutput(VALUE target, VALUE o, int is_void) +{ + return SWIG_wxRuby_AppendOutput(target, o, is_void); +} + +/* SWIG < 4.3.0 version */ +inline VALUE +SWIG_Ruby_AppendOutput(VALUE target, VALUE o) +{ + return SWIG_wxRuby_AppendOutput(target, o, -1); +} diff --git a/rakelib/lib/core/include/swigrubyrun.inc b/rakelib/lib/core/include/swigrubyrun.inc index e5638be1..4ef30383 100644 --- a/rakelib/lib/core/include/swigrubyrun.inc +++ b/rakelib/lib/core/include/swigrubyrun.inc @@ -59,9 +59,9 @@ extern "C" { #endif WXRB_EXPORT_FLAG VALUE -SWIG_Ruby_AppendOutput(VALUE target, VALUE o) +SWIG_wxRuby_AppendOutput(VALUE target, VALUE o, int is_void) { - if (NIL_P(target)) + if (NIL_P(target) && is_void != 0) { target = o; } From d26e05155d1bf10f6379b6784129f410eb4b1bc2 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Sat, 26 Oct 2024 11:32:15 +0200 Subject: [PATCH 8/8] fix SWIG backward compat for SWIG >= 4.3.0 --- ext/wxruby3/swig/custom/director.swg | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ext/wxruby3/swig/custom/director.swg b/ext/wxruby3/swig/custom/director.swg index 68a9f253..d5b431ed 100644 --- a/ext/wxruby3/swig/custom/director.swg +++ b/ext/wxruby3/swig/custom/director.swg @@ -189,6 +189,9 @@ namespace Swig { } }; +// SWIG < 4.3.0 +#if SWIG_VERSION < 0x040300 + /* Simple thread abstraction for pthreads on win32 */ #ifdef __THREAD__ # define __PTHREAD__ @@ -219,8 +222,14 @@ namespace Swig { } }; # define SWIG_GUARD(mutex) Guard _guard(mutex) +# define SWIG_GUARD_DEFINITION(_cls, _mutex) pthread_mutex_t _cls::_mutex +# define SWIG_GUARD_DECLARATION(_mutex) static pthread_mutex_t _mutex #else # define SWIG_GUARD(mutex) +# define SWIG_GUARD_DEFINITION(_cls, _mutex) +# define SWIG_GUARD_DECLARATION(_mutex) +#endif + #endif /* director base class */ @@ -258,9 +267,7 @@ namespace Swig { private: typedef std::map swig_ownership_map; mutable swig_ownership_map swig_owner; -#ifdef __PTHREAD__ - static pthread_mutex_t swig_mutex_own; -#endif + SWIG_GUARD_DECLARATION(swig_mutex_own); public: template @@ -287,4 +294,5 @@ namespace Swig { swig_ruby_owntype swig_release_ownership(void *vptr) const; }; + SWIG_GUARD_DEFINITION(Director, swig_mutex_own); }