Skip to content

Commit

Permalink
Merge pull request #308 from mcorino/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mcorino authored Oct 5, 2024
2 parents a7363a3 + aa31bd9 commit 3e922f7
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 7 deletions.
18 changes: 18 additions & 0 deletions lib/wx/core/file_dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,22 @@ class FileDialog

end

class FileDialogCustomizeHook

# prevent construction of abstract base
def self.new(*)
raise NotImplementedError, 'Wx::FileDialogCustomizeHook is an abstract class.' if self == Wx::FileDialogCustomizeHook
super
end

# provide default no-ops

def add_custom_controls(customizer) end

def update_custom_controls; end

def transfer_data_from_custom_controls; end

end

end
78 changes: 77 additions & 1 deletion rakelib/lib/director/file_dialog_customize_hook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,85 @@ class FileDialogCustomizeHook < Director
def setup
super
spec.items << 'wxFileDialogCustomize'
spec.gc_as_marked 'wxFileDialogCustomizeHook' # not tracked but cached in Ruby
spec.gc_as_object 'wxFileDialogCustomizeHook'
spec.gc_as_untracked 'wxFileDialogCustomize'
spec.make_abstract 'wxFileDialogCustomize'
spec.map_apply 'int n, const wxString* choices' => 'size_t n, const wxString *strings'
# make Ruby director and wrappers use custom implementation
spec.use_class_implementation('wxFileDialogCustomizeHook', 'wxRubyFileDialogCustomizeHook')
spec.make_concrete('wxFileDialogCustomizeHook')
# prevent director overload; custom impl handles this
spec.no_proxy 'wxFileDialogCustomizeHook::AddCustomControls',
'wxFileDialogCustomizeHook::UpdateCustomControls',
'wxFileDialogCustomizeHook::TransferDataFromCustomControls'
# do not wrap these
spec.ignore 'wxFileDialogCustomizeHook::AddCustomControls',
'wxFileDialogCustomizeHook::UpdateCustomControls',
'wxFileDialogCustomizeHook::TransferDataFromCustomControls',
ignore_doc: false
spec.add_header_code <<~__HEREDOC
class wxRubyFileDialogCustomizeHook : public wxFileDialogCustomizeHook
{
public:
wxRubyFileDialogCustomizeHook() : wxFileDialogCustomizeHook() {}
~wxRubyFileDialogCustomizeHook() {};
// from virtual void wxFileDialogCustomizeHook::AddCustomControls
virtual void AddCustomControls(wxFileDialogCustomize &customizer) override
{
VALUE obj0 = Qnil ;
VALUE SWIGUNUSED result;
obj0 = SWIG_NewPointerObj(SWIG_as_voidptr(&customizer), SWIGTYPE_p_wxFileDialogCustomize, 0 );
VALUE self = SWIG_RubyInstanceFor(this);
bool ex = false;
result = wxRuby_Funcall(ex, self, rb_intern("add_custom_controls"), 1,obj0);
if (ex)
{
wxRuby_PrintException(result);
}
}
// from virtual void wxFileDialogCustomizeHook::UpdateCustomControls
virtual void UpdateCustomControls() override
{
VALUE SWIGUNUSED result;
if (!this->finished_)
{
VALUE self = SWIG_RubyInstanceFor(this);
bool ex = false;
result = wxRuby_Funcall(ex, self, rb_intern("update_custom_controls"), 0, NULL);
if (ex)
{
wxRuby_PrintException(result);
}
}
}
// from virtual void wxFileDialogCustomizeHook::TransferDataFromCustomControls
virtual void TransferDataFromCustomControls() override
{
VALUE SWIGUNUSED result;
if (!this->finished_)
{
this->finished_ = true;
VALUE self = SWIG_RubyInstanceFor(this);
bool ex = false;
result = wxRuby_Funcall(ex, self, rb_intern("transfer_data_from_custom_controls"), 0, NULL);
if (ex)
{
wxRuby_PrintException(result);
}
}
}
private:
bool finished_ {};
};
__HEREDOC
end
end # class FileDialogCustomizeHook

Expand Down
13 changes: 7 additions & 6 deletions rakelib/lib/util/string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ def rb_constant_value(name)
end

def rb_constant_expression(exp, const_xref)
exp.gsub(/(\w+(::\w+)*)(\s*\()?/) do |s|
exp.gsub(/(\w+(::\w+)*)(\s*\((\))?)?/) do |s|
idstr = $1
is_call = !!$3
call_bracket = $3
is_empty_call = !!$4
is_scoped = false
ids = idstr.split('::')
if ids.size > 1
Expand All @@ -120,18 +121,18 @@ def rb_constant_expression(exp, const_xref)
end
end
idstr = ids.shift
if is_call
if call_bracket
# object ctor or static method call
if is_scoped
# static method
"#{scoped_name}.#{rb_method_name(idstr)}("
"#{scoped_name}.#{rb_method_name(idstr)}#{call_bracket}"
else
# ctor
case idstr
when 'wxString'
'('
is_empty_call ? "''" : call_bracket
else
"#{idstr.start_with?('wx') ? 'Wx::' : ''}#{rb_wx_name(idstr)}.new("
"#{idstr.start_with?('wx') ? 'Wx::' : ''}#{rb_wx_name(idstr)}.new#{call_bracket}"
end
end
else
Expand Down

0 comments on commit 3e922f7

Please sign in to comment.