diff --git a/lib/wx/core/enum.rb b/lib/wx/core/enum.rb index e7e0d43c..6ecee62d 100644 --- a/lib/wx/core/enum.rb +++ b/lib/wx/core/enum.rb @@ -10,10 +10,23 @@ class Wx::Enum class << self - def enumerators + def set_non_distinct(lst) + raise TypeError, 'Expected Array of Symbols' unless lst.is_a?(Array) && lst.all? { |e| e.is_a?(Symbol) } + @non_distinct = lst + end + alias :non_distinct= :set_non_distinct + + def non_distinct + @non_distinct || [] + end + + def enumerators(excludes = nil) + excludes ||= self.non_distinct self.constants(false).inject({}) do |tbl, cn| - cv = self.const_get(cn) - tbl[cv.to_i] = cn if self === cv + unless excludes&.include?(cn) + cv = self.const_get(cn) + tbl[cv.to_i] = cn if self === cv + end tbl end end diff --git a/lib/wx/core/hboxsizer.rb b/lib/wx/core/hboxsizer.rb index adba1e35..90e28e95 100644 --- a/lib/wx/core/hboxsizer.rb +++ b/lib/wx/core/hboxsizer.rb @@ -9,14 +9,34 @@ # Just a shortcut version for creating a horizontal box sizer class Wx::HBoxSizer < Wx::BoxSizer - def initialize - super(Wx::HORIZONTAL) + def initialize(&block) + super(Wx::HORIZONTAL, &nil) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end end # Just a shortcut version for creating a horizontal wrap sizer class Wx::HWrapSizer < Wx::WrapSizer - def initialize(flags=Wx::WRAPSIZER_DEFAULT_FLAGS) - super(Wx::HORIZONTAL) + def initialize(flags=Wx::WRAPSIZER_DEFAULT_FLAGS, &block) + super(Wx::HORIZONTAL, &nil) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end end diff --git a/lib/wx/core/sizer.rb b/lib/wx/core/sizer.rb index d6ccaa49..b979b003 100644 --- a/lib/wx/core/sizer.rb +++ b/lib/wx/core/sizer.rb @@ -6,57 +6,184 @@ # Copyright 2004-2007, wxRuby development team # released under the MIT-like wxRuby2 license -# Class for automatically managing layouts +# Classes for automatically managing layouts -class Wx::Sizer - # Generic method to add items, supporting positional and named - # arguments - ADD_ITEM_PARAMS = [ Wx::Parameter[ :index, -1 ], - Wx::Parameter[ :proportion, 0 ], - Wx::Parameter[ :flag, 0 ], - Wx::Parameter[ :border, 0 ] ] - - def add_item(item, *mixed_args) +module Wx + class Sizer + # Generic method to add items, supporting positional and named + # arguments + ADD_ITEM_PARAMS = [Wx::Parameter[:index, -1], + Wx::Parameter[:proportion, 0], + Wx::Parameter[:flag, 0], + Wx::Parameter[:border, 0]] - begin - args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args) - rescue => err - err.set_backtrace(caller) - Kernel.raise err + def add_item(item, *mixed_args) + + begin + args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args) + rescue => err + err.set_backtrace(caller) + Kernel.raise err + end + + full_args = [] + + # extract the width and the height in the case of a spacer + # defined as an array + if item.kind_of?(Array) + Kernel.raise ArgumentError, + "Invalid Sizer specification : [width, height] expected" if item.size != 2 + full_args << item[0] << item[1] + else + full_args << item + end + + # update the full arguments list with the optional arguments (except index) + idx = args.shift + full_args.concat(args) + + # Call add to append if default position + if idx == -1 + add(*full_args) + else + insert(idx, *full_args) + end + end + + # Overload to provide Enumerator without block + wx_each_child = instance_method :each_child + define_method :each_child do |&block| + if block + wx_each_child.bind(self).call(&block) + else + ::Enumerator.new { |y| wx_each_child.bind(self).call { |c| y << c } } + end + end + + end + + class BoxSizer < Sizer + + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end + end + + end + + class WrapSizer < BoxSizer + + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end - full_args = [] + end + + class StaticBoxSizer < BoxSizer - # extract the width and the height in the case of a spacer - # defined as an array - if item.kind_of?(Array) - Kernel.raise ArgumentError, - "Invalid Sizer specification : [width, height] expected" if item.size != 2 - full_args << item[0] << item[1] - else - full_args << item + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end - # update the full arguments list with the optional arguments (except index) - idx = args.shift - full_args.concat(args) + end - # Call add to append if default position - if idx == -1 - add(*full_args) - else - insert(idx, *full_args) + class StdDialogButtonSizer < BoxSizer + + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end + end - # Overload to provide Enumerator without block - wx_each_child = instance_method :each_child - define_method :each_child do |&block| - if block - wx_each_child.bind(self).call(&block) - else - ::Enumerator.new { |y| wx_each_child.bind(self).call { |c| y << c } } + class GridSizer < Sizer + + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + self.instance_eval(&block) if block end + + end + + class FlexGridSizer < GridSizer + + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end + end + + end + + class GridBagSizer < FlexGridSizer + + wx_initialize = instance_method :initialize + define_method :initialize do |*args, &block| + wx_initialize.bind(self).call(*args) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end + end + end end diff --git a/lib/wx/core/vboxsizer.rb b/lib/wx/core/vboxsizer.rb index 18ba2ffe..ecd83284 100644 --- a/lib/wx/core/vboxsizer.rb +++ b/lib/wx/core/vboxsizer.rb @@ -9,14 +9,34 @@ # Just a shortcut version for creating a vertical box sizer class Wx::VBoxSizer < Wx::BoxSizer - def initialize - super(Wx::VERTICAL) + def initialize(&block) + super(Wx::VERTICAL, &nil) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end end # Just a shortcut version for creating a vertical wrap sizer class Wx::VWrapSizer < Wx::WrapSizer - def initialize(flags=Wx::WRAPSIZER_DEFAULT_FLAGS) - super(Wx::VERTICAL) + def initialize(flags=Wx::WRAPSIZER_DEFAULT_FLAGS, &block) + super(Wx::VERTICAL, &nil) + if block + if block.arity == -1 or block.arity == 0 + self.instance_eval(&block) + elsif block.arity == 1 + block.call(self) + else + Kernel.raise ArgumentError, + "Block to initialize should accept a single argument or none" + end + end end end diff --git a/lib/wx/doc/enum.rb b/lib/wx/doc/enum.rb index bb37187f..c7661207 100644 --- a/lib/wx/doc/enum.rb +++ b/lib/wx/doc/enum.rb @@ -18,6 +18,32 @@ module Wx # type safety for arguments requiring the specific enum class. class Enum < Numeric + class << self + + # Sets a class specific list of enumerator ids (symbols) that should be considered + # non-distinctive enum values (examples would be convenience constants combining + # multiple distinctive enumerators or enumerators denoting the first/lowest and/or last/highest + # distinctive enumerators). + # @param [Array] lst + def set_non_distinct(lst) end + alias :non_distinct= :set_non_distinct + + # Returns the class specific list of enumerator ids (symbols) that should be considered + # non-distinctive enum values. Returns nil if not set. + # @see set_non_distinct + # @return [Array,nil] + def non_distinct; end + + # Returns a hash table with enumerator value : enumerator id (symbol) pairs for the enum class. + # @param [Array, nil] excludes list of enumerator ids (symbols) to exclude (by default the non_distinct list is used if defined) + # @return [Hash(Integer, Symbol)] + def enumerators(excludes = nil) end + + # Returns the enumerator for the given enumerator symbol or nil if no such enumerator exists. + # @return [Wx::Enum, nil] + def [](enum_name) end + end + # Initialize a new enum value. # @param [Integer] val enum integer value def initialize(val)end diff --git a/lib/wx/version.rb b/lib/wx/version.rb index bd442389..d5a95ff0 100644 --- a/lib/wx/version.rb +++ b/lib/wx/version.rb @@ -3,5 +3,5 @@ # This software is released under the MIT license. module Wx - WXRUBY_VERSION = '1.3.0' + WXRUBY_VERSION = '1.3.1' end diff --git a/rakelib/lib/director/textctrl.rb b/rakelib/lib/director/textctrl.rb index 4943dcd5..800b7b71 100644 --- a/rakelib/lib/director/textctrl.rb +++ b/rakelib/lib/director/textctrl.rb @@ -24,6 +24,13 @@ def setup spec.ignore 'wxTextCtrl::GTKGetTextBuffer', 'wxTextCtrl::GTKGetEditable' end + if Config.instance.wx_version >= '3.3.0' && Config.instance.wx_port == :wxmsw + spec.items << 'wxTextSearch' << 'wxTextSearchResult' + spec.regard 'wxTextSearchResult::m_start', 'wxTextSearchResult::m_end' + spec.make_readonly 'wxTextSearchResult::m_start', 'wxTextSearchResult::m_end' + spec.rename_for_ruby 'start' => 'wxTextSearchResult::m_start', + 'end' => 'wxTextSearchResult::m_end' + end if Config.instance.wx_port == :wxqt # not implemented spec.ignore 'wxTextCtrl::OnDropFiles' diff --git a/samples/dialogs/dialogs.rb b/samples/dialogs/dialogs.rb index db4733bd..e3c61be2 100755 --- a/samples/dialogs/dialogs.rb +++ b/samples/dialogs/dialogs.rb @@ -167,7 +167,7 @@ def initialize(parent, pref_type) end create(parent, -1, "Preferences") - create_buttons(Wx::ID_OK|Wx::ID_CANCEL) + create_buttons(Wx::OK|Wx::CANCEL) book_ctrl.set_images(imgs) book_ctrl.add_page(file_panel(book_ctrl), "File", false, img_id1) book_ctrl.add_page(cdrom_panel(book_ctrl), "CD ROM", false, img_id2)