From 65e835baec9874f5febf04c0b5820584d5ad4f9b Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 8 Sep 2023 12:05:55 +0200 Subject: [PATCH 1/5] add Wx::RearrangeList and test --- lib/wx/keyword_defs.rb | 5 ++++ rakelib/lib/director/rearrange_list.rb | 33 ++++++++++++++++++++++++++ rakelib/lib/specs/interfaces.rb | 1 + rakelib/lib/typemap/common.rb | 11 ++++++++- tests/test_ext_controls.rb | 23 ++++++++++++++++++ 5 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 rakelib/lib/director/rearrange_list.rb diff --git a/lib/wx/keyword_defs.rb b/lib/wx/keyword_defs.rb index 2d763b97..b6d8880e 100644 --- a/lib/wx/keyword_defs.rb +++ b/lib/wx/keyword_defs.rb @@ -520,5 +520,10 @@ 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 + # 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..a4fbfe44 100644 --- a/rakelib/lib/specs/interfaces.rb +++ b/rakelib/lib/specs/interfaces.rb @@ -177,6 +177,7 @@ 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, '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/test_ext_controls.rb b/tests/test_ext_controls.rb index 62213ba6..647d17b5 100644 --- a/tests/test_ext_controls.rb +++ b/tests/test_ext_controls.rb @@ -256,3 +256,26 @@ 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 + assert_true(list.move_current_down) + assert_equal([~2, ~1, 0], list.get_current_order) + end + +end From e179a54dd5b013fc76093bd36d43f5d4ff604e07 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 8 Sep 2023 12:06:30 +0200 Subject: [PATCH 2/5] always run GC after cleanup --- tests/lib/wxframe_runner.rb | 1 + 1 file changed, 1 insertion(+) 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 From 29c0a2c3a41a893c6dd45675c8494ebac4264d05 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 8 Sep 2023 12:17:36 +0200 Subject: [PATCH 3/5] add Wx::RearrangeCtrl and test --- lib/wx/keyword_defs.rb | 7 ++++++- rakelib/lib/specs/interfaces.rb | 1 + tests/test_ext_controls.rb | 23 +++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/wx/keyword_defs.rb b/lib/wx/keyword_defs.rb index b6d8880e..c52ed14a 100644 --- a/lib/wx/keyword_defs.rb +++ b/lib/wx/keyword_defs.rb @@ -522,7 +522,12 @@ Wx::define_keyword_ctors(Wx::RearrangeList) do wx_ctor_params :id, :pos, :size, :order, :items, :style - wx_ctor_params :validator, :name => 'reArrangeList' + 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 diff --git a/rakelib/lib/specs/interfaces.rb b/rakelib/lib/specs/interfaces.rb index a4fbfe44..ff5729f0 100644 --- a/rakelib/lib/specs/interfaces.rb +++ b/rakelib/lib/specs/interfaces.rb @@ -178,6 +178,7 @@ module WXRuby3 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/tests/test_ext_controls.rb b/tests/test_ext_controls.rb index 647d17b5..b11bad30 100644 --- a/tests/test_ext_controls.rb +++ b/tests/test_ext_controls.rb @@ -279,3 +279,26 @@ def test_rearrange_list 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_list + assert_equal([~1, ~2, 0], ra_ctrl.list.get_current_order) + ra_ctrl.set_focus + assert_true(ra_ctrl.list.move_current_down) + assert_equal([~2, ~1, 0], ra_ctrl.list.get_current_order) + end + +end From 5075d68a754fe74f401a8a30815570ce4fbaa128 Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 8 Sep 2023 13:29:51 +0200 Subject: [PATCH 4/5] add Wx::RearrangeCtrl and test --- tests/test_ext_controls.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_ext_controls.rb b/tests/test_ext_controls.rb index b11bad30..ddbf2631 100644 --- a/tests/test_ext_controls.rb +++ b/tests/test_ext_controls.rb @@ -274,6 +274,7 @@ def cleanup def test_rearrange_list assert_equal([~1, ~2, 0], list.get_current_order) list.set_focus + Wx.get_app.yield assert_true(list.move_current_down) assert_equal([~2, ~1, 0], list.get_current_order) end @@ -294,9 +295,10 @@ def cleanup attr_reader :ra_ctrl - def test_rearrange_list + def test_rearrange_ctrl assert_equal([~1, ~2, 0], ra_ctrl.list.get_current_order) ra_ctrl.set_focus + Wx.get_app.yield assert_true(ra_ctrl.list.move_current_down) assert_equal([~2, ~1, 0], ra_ctrl.list.get_current_order) end From 6722018afe1410f24c1f2854a0e40de0781f5c7e Mon Sep 17 00:00:00 2001 From: Martin Corino Date: Fri, 8 Sep 2023 14:39:44 +0200 Subject: [PATCH 5/5] explicitly set initial selected item --- tests/test_ext_controls.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_ext_controls.rb b/tests/test_ext_controls.rb index ddbf2631..3f09a2bd 100644 --- a/tests/test_ext_controls.rb +++ b/tests/test_ext_controls.rb @@ -274,6 +274,7 @@ def cleanup 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) @@ -298,6 +299,7 @@ def cleanup 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)