Skip to content

Commit

Permalink
Merge pull request #319 from mcorino/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mcorino authored Oct 26, 2024
2 parents 75aacb6 + d26e051 commit 494659a
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 34 deletions.
14 changes: 11 additions & 3 deletions ext/wxruby3/swig/custom/director.swg
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -258,9 +267,7 @@ namespace Swig {
private:
typedef std::map<void *, GCItem_var> 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 <typename Type>
Expand All @@ -287,4 +294,5 @@ namespace Swig {

swig_ruby_owntype swig_release_ownership(void *vptr) const;
};
SWIG_GUARD_DEFINITION(Director, swig_mutex_own);
}
16 changes: 15 additions & 1 deletion ext/wxruby3/swig/custom/rubyapi.swg
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
75 changes: 61 additions & 14 deletions lib/wx/aui/auimanager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/wx/core/array_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions lib/wx/core/real_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/wx/doc/array_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions lib/wx/doc/aui/auimanager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/wx/doc/gdi_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rakelib/lib/core/include/swigrubyrun.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
121 changes: 118 additions & 3 deletions rakelib/lib/director/aui_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<wxAuiPaneInfo>' => 'Array<Wx::AuiPaneInfo>' do
map_out code: <<~__CODE
$result = rb_ary_new();
std::vector<wxAuiPaneInfo>& panes = (std::vector<wxAuiPaneInfo>&)$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<wxAuiDockInfo>' => 'Array<Wx::AuiDockInfo>' do
map_out code: <<~__CODE
$result = rb_ary_new();
std::vector<wxAuiDockInfo>& docks = (std::vector<wxAuiDockInfo>&)$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"
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -110,12 +201,36 @@ class WXRubyAuiManager : public wxAuiManager
WXRubyAuiManager* aui_mng = dynamic_cast<WXRubyAuiManager*> (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<Wx::AUI::AuiPaneInfo>] 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
6 changes: 4 additions & 2 deletions rakelib/lib/director/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rakelib/lib/director/pgproperties.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand Down
7 changes: 4 additions & 3 deletions rakelib/lib/director/property_grid_interface.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 494659a

Please sign in to comment.