Skip to content

Commit

Permalink
Merge pull request #173 from mcorino/fix-162
Browse files Browse the repository at this point in the history
Fix #162
  • Loading branch information
mcorino authored Sep 8, 2023
2 parents 157d88b + 6722018 commit e62ffe2
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 1 deletion.
10 changes: 10 additions & 0 deletions lib/wx/keyword_defs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
33 changes: 33 additions & 0 deletions rakelib/lib/director/rearrange_list.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions rakelib/lib/specs/interfaces.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
11 changes: 10 additions & 1 deletion rakelib/lib/typemap/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Integer>' do
map_in temp: 'wxArrayInt tmp', code: <<~__CODE
if (($input == Qnil) || (TYPE($input) != T_ARRAY))
Expand All @@ -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++)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/lib/wxframe_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def base_setup
cleanup
def base_cleanup
10.times { Wx.get_app.yield }
GC.start
end

def frame_win
Expand Down
50 changes: 50 additions & 0 deletions tests/test_ext_controls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e62ffe2

Please sign in to comment.