Skip to content

Commit

Permalink
Merge pull request #320 from mcorino/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
mcorino authored Nov 1, 2024
2 parents 494659a + 73eee1a commit e71e1fd
Showing 8 changed files with 265 additions and 52 deletions.
19 changes: 16 additions & 3 deletions lib/wx/core/enum.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 24 additions & 4 deletions lib/wx/core/hboxsizer.rb
Original file line number Diff line number Diff line change
@@ -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
205 changes: 166 additions & 39 deletions lib/wx/core/sizer.rb
Original file line number Diff line number Diff line change
@@ -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
28 changes: 24 additions & 4 deletions lib/wx/core/vboxsizer.rb
Original file line number Diff line number Diff line change
@@ -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
26 changes: 26 additions & 0 deletions lib/wx/doc/enum.rb
Original file line number Diff line number Diff line change
@@ -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<Symbol>] 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<Symbol>,nil]
def non_distinct; end

# Returns a hash table with enumerator value : enumerator id (symbol) pairs for the enum class.
# @param [Array<Symbol>, 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
2 changes: 1 addition & 1 deletion lib/wx/version.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions rakelib/lib/director/textctrl.rb
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion samples/dialogs/dialogs.rb
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit e71e1fd

Please sign in to comment.