diff --git a/lib/wx/keyword_defs.rb b/lib/wx/keyword_defs.rb index 2d763b97..c52ed14a 100644 --- a/lib/wx/keyword_defs.rb +++ b/lib/wx/keyword_defs.rb @@ -520,5 +520,15 @@ wx_ctor_params :id end +Wx::define_keyword_ctors(Wx::RearrangeList) do + wx_ctor_params :id, :pos, :size, :order, :items, :style + wx_ctor_params :validator, :name => 'rearrangeList' +end + +Wx::define_keyword_ctors(Wx::RearrangeCtrl) do + wx_ctor_params :id, :pos, :size, :order, :items, :style + wx_ctor_params :validator, :name => 'rearrangeCtrl' +end + # FIXME - SymbolPickerDialog is hard to because the parent argument is # in a strange place. diff --git a/rakelib/lib/director/rearrange_list.rb b/rakelib/lib/director/rearrange_list.rb new file mode 100644 index 00000000..8e59fa60 --- /dev/null +++ b/rakelib/lib/director/rearrange_list.rb @@ -0,0 +1,33 @@ +### +# wxRuby3 wxWidgets interface director +# Copyright (c) M.J.N. Corino, The Netherlands +### + +require_relative './ctrl_with_items' + +module WXRuby3 + + class Director + + class RearrangeList < ControlWithItems + + include Typemap::ArrayIntSelections + + def setup + super + setup_ctrl_with_items('wxRearrangeList') + spec.override_inheritance_chain('wxRearrangeList', + %w[wxCheckListBox + wxListBox + wxControlWithItems + wxControl + wxWindow + wxEvtHandler + wxObject]) + end + + end # class RearrangeList + + end # class Director + +end # module WXRuby3 diff --git a/rakelib/lib/specs/interfaces.rb b/rakelib/lib/specs/interfaces.rb index b39aba11..ff5729f0 100644 --- a/rakelib/lib/specs/interfaces.rb +++ b/rakelib/lib/specs/interfaces.rb @@ -177,6 +177,8 @@ module WXRuby3 Director.Spec(pkg, 'wxWizardPageSimple', director: Director::WizardPage, requirements: %w[wxUSE_WIZARDDLG]) Director.Spec(pkg, 'wxWizard', director: Director::Dialog, requirements: %w[wxUSE_WIZARDDLG]) Director.Spec(pkg, 'wxCheckListBox', requirements: %w[wxUSE_CHECKLISTBOX]) + Director.Spec(pkg, 'wxRearrangeList', requirements: %w[wxUSE_CHECKLISTBOX]) + Director.Spec(pkg, 'wxRearrangeCtrl', director: Director::Window, requirements: %w[wxUSE_CHECKLISTBOX]) Director.Spec(pkg, 'wxDataFormat', requirements: %w[wxUSE_CLIPBOARD]) Director.Spec(pkg, 'wxDataObject', requirements: %w[wxUSE_CLIPBOARD]) Director.Spec(pkg, 'wxDataObjectSimpleBase', requirements: %w[wxUSE_CLIPBOARD]) diff --git a/rakelib/lib/typemap/common.rb b/rakelib/lib/typemap/common.rb index 80a4dc39..3e9825ba 100644 --- a/rakelib/lib/typemap/common.rb +++ b/rakelib/lib/typemap/common.rb @@ -374,7 +374,7 @@ module Common map_typecheck precedence: 'INT32_ARRAY', code: '$1 = (TYPE($input) == T_ARRAY);' end - # input reference + # input reference (out by value) map 'wxArrayInt&' => 'Array' do map_in temp: 'wxArrayInt tmp', code: <<~__CODE if (($input == Qnil) || (TYPE($input) != T_ARRAY)) @@ -391,6 +391,13 @@ module Common $1 = &tmp; } __CODE + map_out code: <<~__CODE + $result = rb_ary_new(); + for (size_t i = 0; i < $1->GetCount(); i++) + { + rb_ary_push($result,INT2NUM( $1->Item(i) ) ); + } + __CODE map_directorin code: <<~__CODE $input = rb_ary_new(); for (size_t i = 0; i < $1.GetCount(); i++) @@ -399,6 +406,8 @@ module Common } __CODE map_typecheck precedence: 'INT32_ARRAY', code: '$1 = (TYPE($input) == T_ARRAY);' + # no directorout mapping as returning a reference would cause trouble; luckily there + # do not seem to be virtual methods returning that end # various enumerator type mappings diff --git a/tests/lib/wxframe_runner.rb b/tests/lib/wxframe_runner.rb index c3e7ffaf..c143f3cf 100644 --- a/tests/lib/wxframe_runner.rb +++ b/tests/lib/wxframe_runner.rb @@ -77,6 +77,7 @@ def base_setup cleanup def base_cleanup 10.times { Wx.get_app.yield } + GC.start end def frame_win diff --git a/tests/test_ext_controls.rb b/tests/test_ext_controls.rb index 62213ba6..3f09a2bd 100644 --- a/tests/test_ext_controls.rb +++ b/tests/test_ext_controls.rb @@ -256,3 +256,53 @@ def test_arrows end end + +class RearrangeListTests < WxRuby::Test::GUITests + + def setup + super + @list = Wx::RearrangeList.new(frame_win, items: %w[first second third], order: [~1, ~2, 0]) + end + + def cleanup + @list.destroy + super + end + + attr_reader :list + + def test_rearrange_list + assert_equal([~1, ~2, 0], list.get_current_order) + list.set_focus + list.set_selection(0) + Wx.get_app.yield + assert_true(list.move_current_down) + assert_equal([~2, ~1, 0], list.get_current_order) + end + +end + +class RearrangeCtrlTests < WxRuby::Test::GUITests + + def setup + super + @ra_ctrl = Wx::RearrangeCtrl.new(frame_win, items: %w[first second third], order: [~1, ~2, 0]) + end + + def cleanup + @ra_ctrl.destroy + super + end + + attr_reader :ra_ctrl + + def test_rearrange_ctrl + assert_equal([~1, ~2, 0], ra_ctrl.list.get_current_order) + ra_ctrl.set_focus + ra_ctrl.list.set_selection(0) + Wx.get_app.yield + assert_true(ra_ctrl.list.move_current_down) + assert_equal([~2, ~1, 0], ra_ctrl.list.get_current_order) + end + +end