wxruby-ruby19 1.9.8-x86-darwin-9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/lib/wx.rb +53 -0
  2. data/lib/wx/accessors.rb +52 -0
  3. data/lib/wx/classes/acceleratortable.rb +28 -0
  4. data/lib/wx/classes/animation.rb +18 -0
  5. data/lib/wx/classes/app.rb +45 -0
  6. data/lib/wx/classes/artprovider.rb +31 -0
  7. data/lib/wx/classes/auinotebook.rb +9 -0
  8. data/lib/wx/classes/bitmap.rb +28 -0
  9. data/lib/wx/classes/busycursor.rb +12 -0
  10. data/lib/wx/classes/checklistbox.rb +45 -0
  11. data/lib/wx/classes/choice.rb +4 -0
  12. data/lib/wx/classes/clientdc.rb +13 -0
  13. data/lib/wx/classes/clipboard.rb +16 -0
  14. data/lib/wx/classes/colour.rb +47 -0
  15. data/lib/wx/classes/combobox.rb +4 -0
  16. data/lib/wx/classes/commandevent.rb +7 -0
  17. data/lib/wx/classes/controlwithitems.rb +10 -0
  18. data/lib/wx/classes/dc.rb +57 -0
  19. data/lib/wx/classes/event.rb +5 -0
  20. data/lib/wx/classes/evthandler.rb +964 -0
  21. data/lib/wx/classes/font.rb +118 -0
  22. data/lib/wx/classes/functions.rb +44 -0
  23. data/lib/wx/classes/gauge.rb +12 -0
  24. data/lib/wx/classes/grid.rb +138 -0
  25. data/lib/wx/classes/helpcontroller.rb +5 -0
  26. data/lib/wx/classes/helpcontrollerhelpprovider.rb +23 -0
  27. data/lib/wx/classes/helpprovider.rb +15 -0
  28. data/lib/wx/classes/htmlhelpcontroller.rb +5 -0
  29. data/lib/wx/classes/htmlwindow.rb +14 -0
  30. data/lib/wx/classes/icon.rb +21 -0
  31. data/lib/wx/classes/iconbundle.rb +3 -0
  32. data/lib/wx/classes/image.rb +31 -0
  33. data/lib/wx/classes/imagelist.rb +3 -0
  34. data/lib/wx/classes/listbox.rb +4 -0
  35. data/lib/wx/classes/listctrl.rb +21 -0
  36. data/lib/wx/classes/locale.rb +28 -0
  37. data/lib/wx/classes/mediactrl.rb +48 -0
  38. data/lib/wx/classes/menu.rb +62 -0
  39. data/lib/wx/classes/menuitem.rb +7 -0
  40. data/lib/wx/classes/notebook.rb +9 -0
  41. data/lib/wx/classes/object.rb +14 -0
  42. data/lib/wx/classes/paintdc.rb +12 -0
  43. data/lib/wx/classes/point.rb +48 -0
  44. data/lib/wx/classes/previewframe.rb +13 -0
  45. data/lib/wx/classes/rect.rb +10 -0
  46. data/lib/wx/classes/simplehelpprovider.rb +38 -0
  47. data/lib/wx/classes/size.rb +49 -0
  48. data/lib/wx/classes/sizer.rb +22 -0
  49. data/lib/wx/classes/sound.rb +23 -0
  50. data/lib/wx/classes/styledtextctrl.rb +92 -0
  51. data/lib/wx/classes/textctrl.rb +14 -0
  52. data/lib/wx/classes/texturlevent.rb +6 -0
  53. data/lib/wx/classes/timer.rb +94 -0
  54. data/lib/wx/classes/toolbar.rb +29 -0
  55. data/lib/wx/classes/toolbartool.rb +4 -0
  56. data/lib/wx/classes/treectrl.rb +44 -0
  57. data/lib/wx/classes/window.rb +82 -0
  58. data/lib/wx/classes/xmlresource.rb +37 -0
  59. data/lib/wx/helpers.rb +30 -0
  60. data/lib/wx/keyword_ctors.rb +203 -0
  61. data/lib/wx/keyword_defs.rb +507 -0
  62. data/lib/wx/version.rb +3 -0
  63. data/lib/wxruby2.bundle +0 -0
  64. metadata +323 -0
@@ -0,0 +1,14 @@
1
+ class Wx::TextCtrl
2
+ # Fix position_to_xy so it returns a two-element array - the internal
3
+ # version returns a three-element array with a Boolean that doesn't
4
+ # really make sense in Ruby
5
+ wx_position_to_xy = instance_method(:position_to_xy)
6
+ define_method(:position_to_xy) do | pos |
7
+ retval, x, y = wx_position_to_xy.bind(self).call(pos)
8
+ if retval
9
+ return [x, y]
10
+ else
11
+ return nil
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ class Wx::TextUrlEvent
2
+ # Returns the string URL that is being interacted with in this event
3
+ def get_url
4
+ get_event_object.get_value[get_url_start .. get_url_end]
5
+ end
6
+ end
@@ -0,0 +1,94 @@
1
+ # Class allowing periodic or timed events to be fired
2
+ class Wx::Timer
3
+ # Convenience method to trigger a one-off action after +interval+
4
+ # milliseconds have passed. The action is specified by the passed
5
+ # block. The Timer is owned by the global App object, and is returned
6
+ # by the method.
7
+ def self.after(interval, &block)
8
+ timer = new(Wx::THE_APP, Wx::ID_ANY)
9
+ Wx::THE_APP.evt_timer(timer.get_id, block)
10
+ timer.start(interval, true)
11
+ timer
12
+ end
13
+
14
+ # Convenience method to trigger a repeating action every +interval+
15
+ # milliseconds. The action is specified by the passed block. The Timer
16
+ # is owned by the global App object, and is returned by the method.
17
+ def self.every(interval, &block)
18
+ timer = new(Wx::THE_APP, Wx::ID_ANY)
19
+ Wx::THE_APP.evt_timer(timer.get_id, block)
20
+ timer.start(interval)
21
+ timer
22
+ end
23
+
24
+ # In common with other classes, make the id method refer to the
25
+ # wxWidgets id, not ruby's deprecated name for object_id
26
+ alias :id :get_id
27
+
28
+ # This class can be linked to an owner - an instance of a class
29
+ # derived from EvtHandler which will receive Timer events. However,
30
+ # event if a Wx::Timer is attached to a Wx::Window, it is (unlike most
31
+ # classes) NOT automatically deleted when the window is destroyed. If
32
+ # the Timer continues ticking, it will send events to the
33
+ # now-destroyed window, causing segfaults. So the little acrobatics
34
+ # below set up a hook when a Timer's owner is set, and then ensure the
35
+ # timer is stopped when the window is destroyed.
36
+
37
+ # Redefine initialize
38
+ wx_init = self.instance_method(:initialize)
39
+ define_method(:initialize) do | *args |
40
+ setup_owner_destruction_hook(args[0])
41
+ wx_init.bind(self).call(*args)
42
+ end
43
+
44
+ # Redefine set_owner
45
+ wx_set_owner = self.instance_method(:set_owner)
46
+ define_method(:set_owner) do | *args |
47
+ setup_owner_destruction_hook(args[0])
48
+ wx_set_owner.bind(self).call(*args)
49
+ end
50
+
51
+ private
52
+ # This method notes in Ruby the ownership of the timer, from both
53
+ # sides, and sets up an event hook if needed for the window's
54
+ # destruction.
55
+ def setup_owner_destruction_hook(new_owner)
56
+ this_timer = self
57
+
58
+ # Class-wide list of global (unowned) timers
59
+ @@__unowned_timers__ ||= []
60
+
61
+ # remove from list of previous owner
62
+ if defined?(@__owner__) and @__owner__
63
+ @__owner__.instance_eval { @__owned_timers__.delete(this_timer) }
64
+ end
65
+
66
+ # If becoming global unowned timer, add to list of those timers
67
+ if not new_owner
68
+ @__owner__ = nil
69
+ @@__unowned_timers__ << self
70
+ return
71
+ end
72
+
73
+ # Otherwise, if previously unowned, remove from global owned
74
+ @@__unowned_timers__.delete(self)
75
+ @__owner__ = new_owner
76
+
77
+ # Then add to list of new owner, setting destructor hook if required
78
+ new_owner.instance_eval do
79
+ if not defined?(@__owned_timers__)
80
+ @__owned_timers__ = []
81
+ unless self.kind_of?(Wx::App) # Don't set up hook on App
82
+ evt_window_destroy do | evt |
83
+ # If it's the owning window being destroyed...
84
+ if evt.get_event_object == self
85
+ @__owned_timers__.each { | timer | timer.stop }
86
+ end
87
+ evt.skip
88
+ end
89
+ end
90
+ end
91
+ @__owned_timers__ << this_timer
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,29 @@
1
+ # A set of buttons and controls attached to one edge of a Wx::Frame
2
+ class Wx::ToolBar
3
+ # Generic method to add items, supporting positional and named
4
+ # arguments
5
+ ADD_ITEM_PARAMS = [ Wx::Parameter[ :position, -1 ],
6
+ Wx::Parameter[ :id, -1 ],
7
+ Wx::Parameter[ :label, "" ],
8
+ Wx::Parameter[ :bitmap, Wx::NULL_BITMAP ],
9
+ Wx::Parameter[ :bitmap2, Wx::NULL_BITMAP ],
10
+ Wx::Parameter[ :kind, Wx::ITEM_NORMAL ],
11
+ Wx::Parameter[ :short_help, "" ],
12
+ Wx::Parameter[ :long_help, "" ],
13
+ Wx::Parameter[ :client_data, nil ] ]
14
+
15
+ def add_item(*mixed_args)
16
+ args = Wx::args_as_list(ADD_ITEM_PARAMS, *mixed_args)
17
+ if args[3] == Wx::NULL_BITMAP
18
+ Kernel.raise ArgumentError, "Main button bitmap may not be NULL"
19
+ end
20
+
21
+ # Call add_tool to append if default position
22
+ pos = args.shift
23
+ if pos == -1
24
+ add_tool(*args)
25
+ else
26
+ insert_tool(pos, *args)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,4 @@
1
+ class Wx::ToolBarTool
2
+ alias :id :get_id
3
+ alias :wx_id :get_id
4
+ end
@@ -0,0 +1,44 @@
1
+ # Hierarchical control with items
2
+ class Wx::TreeCtrl
3
+ # Make these ruby enumerables so find, find_all, map etc are available
4
+ include Enumerable
5
+ # Iterate over all items
6
+ alias :each :traverse
7
+
8
+ # Return the children of +parent+ as an array of TreeItemIDs.
9
+ def get_children(parent)
10
+ kids = [ get_first_child(parent) ]
11
+ return [] if kids[0].zero?
12
+
13
+ while kid = get_next_sibling(kids.last) and not kid.zero?
14
+ kids << kid
15
+ end
16
+ kids
17
+ end
18
+
19
+ # Returns a Wx::Rect corresponding to the edges of an individual tree
20
+ # item, including the button, identified by id. The standard wxWidgets
21
+ # API for getting the pixel location of an item is unrubyish, using an
22
+ # input/output parameter. But since the underlying get_bounding_rect
23
+ # method works, it's easier to fix the API in Ruby than adding more to
24
+ # the already-toxic swig interface TreeCtrl.i file.
25
+ def get_item_rect(tree_item_id)
26
+ rect = Wx::Rect.new
27
+ if get_bounding_rect(tree_item_id, rect, false)
28
+ return rect
29
+ else
30
+ return nil
31
+ end
32
+ end
33
+
34
+ # Returns a Wx::Rect corresponding to the edges of an individual tree
35
+ # item's text label. See above.
36
+ def get_label_rect(tree_item_id)
37
+ rect = Wx::Rect.new
38
+ if get_bounding_rect(tree_item_id, rect, true)
39
+ return rect
40
+ else
41
+ nil
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,82 @@
1
+ # Copyright 2004-2007 by Kevin Smith
2
+ # released under the MIT-style wxruby2 license
3
+
4
+ # The base class for all things displayed on screen
5
+ class Wx::Window
6
+
7
+ # Ruby's Object#id is deprecated and will be removed in 1.9; therefore
8
+ # for classes inheriting from Wx::Window, the id method returns the
9
+ # wxRuby Window id
10
+ alias :id :get_id
11
+ # In case a more explicit option is preferred.
12
+ alias :wx_id :get_id
13
+
14
+
15
+ # Recursively searches all windows below +self+ and returns the first
16
+ # window which has the id +an_id+. This corresponds to the find_window
17
+ # method method in WxWidgets when called with an integer.
18
+ def find_window_by_id(an_id)
19
+ Wx::Window.find_window_by_id(an_id, self)
20
+ end
21
+
22
+ # Searches all windows below +self+ and returns the first window which
23
+ # has the name +a_name+ This corresponds to the find_window method method
24
+ # in WxWidgets when called with an string.
25
+ def find_window_by_name(a_name)
26
+ Wx::Window.find_window_by_name(a_name, self)
27
+ end
28
+
29
+ # Searches all windows below +self+ and returns the first window which
30
+ # has the label +a_label+.
31
+ def find_window_by_label(a_label)
32
+ Wx:Window.find_window_by_label(a_label, self)
33
+ end
34
+
35
+ alias :__old_evt_paint :evt_paint
36
+ # This modified version of evt_paint sets a variable indicating that a
37
+ # paint event is being handled just before running the event
38
+ # handler. This ensures that any call to Window#paint within the
39
+ # handler will supply a Wx::PaintDC (see swig/Window.i).
40
+ def evt_paint(meth = nil, &block)
41
+ paint_proc = acquire_handler(meth, block)
42
+ wrapped_block = proc do | event |
43
+ instance_variable_set("@__painting__", true)
44
+ paint_proc.call(event)
45
+ remove_instance_variable("@__painting__")
46
+ end
47
+ __old_evt_paint(&wrapped_block)
48
+ end
49
+
50
+ # Provides bufferd drawing facility to reduce flicker for complex
51
+ # drawing commands. Works similar to BufferedDC and BufferedPaintDC in
52
+ # the wxWidgets API, by doing drawing on an in-memory Bitmap, then
53
+ # copying the result in bulk to the screen.
54
+ #
55
+ # The method may be passed an existing Wx::Bitmap as the +buffer+,
56
+ # otherwise one will be created.
57
+ #
58
+ # Works like wxAutoBufferedDC in that additional buffering will only
59
+ # be done on platforms that do not already natively support buffering
60
+ # for the standard PaintDC / ClientDC - Windows, in particular.
61
+ def paint_buffered(buffer = nil)
62
+ # OS X and GTK do double-buffering natively
63
+ if self.double_buffered?
64
+ paint { | dc | yield dc }
65
+ else
66
+ # client_size is the window area available for drawing upon
67
+ c_size = client_size
68
+ # Create an in-memory buffer if none supplied
69
+ buffer ||= Wx::Bitmap.new(c_size.width, c_size.height)
70
+ buffer.draw do | mem_dc |
71
+ mem_dc.background = Wx::TRANSPARENT_BRUSH
72
+ mem_dc.clear
73
+ # Yield the bitmap for the user code to draw upon
74
+ yield mem_dc
75
+ paint do | dc |
76
+ # Copy the buffer to the window
77
+ dc.blit(0, 0, c_size.width, c_size.height, mem_dc, 0, 0)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,37 @@
1
+ class Wx::XmlResource
2
+ # XRC_NO_SUBCLASSING should always be in place in wxRuby - we can't
3
+ # currently link directly to wxRuby subclasses.
4
+ class << self
5
+ wx_get = self.instance_method(:get)
6
+ define_method(:get) do
7
+ res = wx_get.bind(self).call
8
+ res.flags |= Wx::XRC_NO_SUBCLASSING
9
+ res
10
+ end
11
+ end
12
+
13
+ # WxRuby already has all XRC handlers built in so there's no way to
14
+ # control init_all_handlers to reduce binary size. So save users
15
+ # having to call it.
16
+ wx_init = self.instance_method(:initialize)
17
+ define_method(:initialize) do | *args |
18
+ result = wx_init.bind(self).call(*args)
19
+ result.flags |= Wx::XRC_NO_SUBCLASSING
20
+ result.init_all_handlers
21
+ end
22
+
23
+ # The standard .load method returns a boolean indicating success or
24
+ # failure. Failure might result from bad XML, or a non-existent
25
+ # file. In ruby, in these circumstances, it's more natural to raise an
26
+ # Exception than expect the user to test the return value.
27
+ wx_load = self.instance_method(:load)
28
+ define_method(:load) do | fname |
29
+ result = wx_load.bind(self).call(fname)
30
+ if not result
31
+ Kernel.raise( RuntimeError,
32
+ "Failed to load XRC from '#{fname}'; " +
33
+ "check the file exists and is valid XML")
34
+ end
35
+ fname
36
+ end
37
+ end
data/lib/wx/helpers.rb ADDED
@@ -0,0 +1,30 @@
1
+ # Various non-GUI helper functions
2
+ module Wx
3
+ # A named parameter in a Wx named-arg parameter list
4
+ Parameter = Struct.new( :name, :default )
5
+
6
+ # Convert mixed positional / named args into a list to be passed to
7
+ # an underlying API method. +param_spec+ is an Array of Parameter
8
+ # structs containing the keyword name and default value for each
9
+ # possible argument. +mixed_args+ is an array which may optionally end
10
+ # with a set of named arguments
11
+
12
+ def self.args_as_list(param_spec, *mixed_args)
13
+ # get keyword arguments from mixed args if supplied, else empty
14
+ kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
15
+ out_args = []
16
+ param_spec.each_with_index do | param, i |
17
+ if arg = mixed_args[i] # use the supplied list arg
18
+ out_args << arg
19
+ elsif kwa.key?(param.name) # use the keyword arg
20
+ out_args << kwa[param.name]
21
+ else # use the default argument
22
+ out_args << param.default
23
+ end
24
+ end
25
+ out_args
26
+ rescue
27
+ Kernel.raise ArgumentError,
28
+ "Bad arg composition of #{mixed_args.inspect}"
29
+ end
30
+ end
@@ -0,0 +1,203 @@
1
+ # = WxRuby Extensions - Keyword Constructors
2
+ #
3
+ # The *Keyword Constructors* extension allows the use of Ruby hash-style
4
+ # keyword arguments in constructors of common WxWidgets Windows, Frame,
5
+ # Dialog and Control classes.
6
+ #
7
+ # == Introduction
8
+ #
9
+ # Building a GUI in WxWidgets involves lots of calls to +new+, but
10
+ # these methods often have long parameter lists. Often the default
11
+ # values for many of these parameters are correct. For example, if
12
+ # you're using a sizer-based layout, you usually don't want to specify a
13
+ # size for widgets, but you still have to type
14
+ #
15
+ # Wx::TreeCtrl.new( parent, -1, Wx::DEFAULT_POSITION, Wx::DEFAULT_SIZE,
16
+ # Wx::NO_BUTTONS )
17
+ #
18
+ # just to create a standard TreeCtrl with the 'no buttons' style. If you
19
+ # want to specify the 'NO BUTTONS' style, you can't avoid all the typing
20
+ # of DEFAULT_POSITION etc.
21
+ #
22
+ # == Basic Keyword Constructors
23
+ #
24
+ # With keyword_constructors, you could write the above as
25
+ #
26
+ # TreeCtrl.new(parent, :style => Wx::NO_BUTTONS)
27
+ #
28
+ # And it will assume you want the default id (-1), and the default size
29
+ # and position. If you want to specify an explicit size, you can do so:
30
+ #
31
+ # TreeCtrl.new(parent, :size => Wx::Size.new(100, 300))
32
+ #
33
+ # For brevity, this module also allows you to specify positions and
34
+ # sizes using a a two-element array:
35
+ #
36
+ # TreeCtrl.new(parent, :size => [100, 300])
37
+ #
38
+ # Similarly with position:
39
+ #
40
+ # TreeCtrl.new(parent, :pos => Wx::Point.new(5, 25))
41
+ #
42
+ # TreeCtrl.new(parent, :pos => [5, 25])
43
+ #
44
+ # You can have multiple keyword arguments:
45
+ #
46
+ # TreeCtrl.new(parent, :pos => [5, 25], :size => [100, 300] )
47
+ #
48
+ # == No ID required
49
+ #
50
+ # As with position and size, you usually don't want to deal with
51
+ # assigning unique ids to every widget and frame you create - it's a C++
52
+ # hangover that often seems clunky in Ruby. The *Event Connectors*
53
+ # extension allows you to set up event handling without having to use
54
+ # ids, and if no :id argument is supplied to a constructor, the default
55
+ # (-1) will be passed.
56
+ #
57
+ # There are occasions when a specific ID does need to be used - for
58
+ # example, to tell WxWidgets that a button is a 'stock' item, so that it
59
+ # can be displayed using platform-standard text and icon. To do this,
60
+ # simply pass an :id argument to the constructor - here, the system's
61
+ # standard 'preview' button
62
+ #
63
+ # Wx::Button.new(parent, :id => Wx::ID_PREVIEW)
64
+ #
65
+ # == Class-specific arguments
66
+ #
67
+ # The arguments :size, :pos and :style are common to many WxWidgets
68
+ # window classes. The +new+ methods of these classes also have
69
+ # parameters that are specific to those classes; for example, the text
70
+ # label on a button, or the initial value of a text control.
71
+ #
72
+ # Wx::Button.new(parent, :label => 'press me')
73
+ # Wx::TextCtrl.new(parent, :value => 'type some text here')
74
+ #
75
+ # The keyword names of these arguments can be found by looking at the
76
+ # WxRuby documentation, in the relevant class's +new+ method. You can
77
+ # also get a string description of the class's +new+ method parameters
78
+ # within Ruby by doing:
79
+ #
80
+ # puts Wx::TextCtrl.describe_constructor()
81
+ #
82
+ # This will print a list of the argument names expected by the class's
83
+ # +new+ method, and the correct type for them.
84
+ #
85
+ # == Mixing positional and keyword arguments
86
+ #
87
+ # To support existing code, and to avoid forcing the use of more verbose
88
+ # keyword-style arguments where they're not desired, you can mix
89
+ # positional and keyword arguments, omitting or including +id+s as
90
+ # desired.
91
+ #
92
+ # Wx::Button.new(parent, 'press me', :style => Wx::BU_RIGHT)
93
+
94
+ module Wx
95
+ module KeywordConstructor
96
+ module ClassMethods
97
+
98
+ # Common Wx constructor argument keywords, with their default values.
99
+ STANDARD_DEFAULTS = {
100
+ :id => -1,
101
+ :size => Wx::DEFAULT_SIZE,
102
+ :pos => Wx::DEFAULT_POSITION,
103
+ :style => 0,
104
+ :title => '',
105
+ :validator => Wx::DEFAULT_VALIDATOR,
106
+ :choices => [] # for Choice, ComboBox etc
107
+ }
108
+
109
+ attr_writer :param_spec
110
+ def param_spec
111
+ @param_spec ||= []
112
+ end
113
+
114
+ # Adds a list of named parameters *params* to the parameter
115
+ # specification for this Wx class's constructor. Each parameter
116
+ # should be specified as a either a common known symbol, such as
117
+ # +:size+ or +:pos:+ or +:style:+ (corresponding to the common
118
+ # constructor arguments in WxWidgets API), or a single-key with the
119
+ # key the name of the argument, and the value a default value.
120
+ #
121
+ # Parameters should be specified in the order they occur in the Wx
122
+ # API constructor
123
+ def wx_ctor_params(*params)
124
+ self.param_spec += params.map do | param |
125
+ param.kind_of?(Hash) ? Parameter[*param.to_a.flatten] :
126
+ Parameter[param, STANDARD_DEFAULTS[param] ]
127
+ end
128
+ end
129
+
130
+ def args_as_list(*mixed_args)
131
+ Wx::args_as_list(param_spec, *mixed_args)
132
+ end
133
+
134
+ def args_as_hash(*mixed_args)
135
+ kwa = mixed_args.last.kind_of?(Hash) ? mixed_args.pop : {}
136
+ param_spec.zip(mixed_args) do | param, arg |
137
+ kwa[param.name] = arg if arg
138
+ end
139
+ kwa
140
+ end
141
+
142
+ def describe_constructor()
143
+ param_spec.inject("") do | desc, param |
144
+ desc << ":#{param.name} => (#{param.default.class.name})\n"
145
+ end
146
+ end
147
+ end
148
+
149
+ def self.included(klass)
150
+ klass.extend ClassMethods
151
+ klass.module_eval do
152
+
153
+ alias :pre_wx_kwctor_init :initialize
154
+
155
+ # The new definition of initialize; accepts a parent arg
156
+ # mixed_args, which may zero or more position args, optionally
157
+ # terminated with hash keyword args, and an optional block
158
+ def initialize(parent = :default_ctor, *mixed_args, &block)
159
+ # allow zero-args ctor for use with XRC
160
+ if parent == :default_ctor
161
+ pre_wx_kwctor_init()
162
+ return
163
+ end
164
+
165
+ real_args = [ parent ] + self.class.args_as_list(*mixed_args)
166
+ begin
167
+ pre_wx_kwctor_init(*real_args)
168
+ rescue => err
169
+ msg = "Error initializing #{self.inspect}\n"+
170
+ " : #{err.message} \n" +
171
+ "Correct parameters for #{self.class.name}.new are:\n" +
172
+ self.class.describe_constructor()
173
+
174
+ new_err = err.class.new(msg)
175
+ new_err.set_backtrace(caller)
176
+ Kernel.raise new_err
177
+ end
178
+
179
+ # If a block was given, pass the newly created Window instance
180
+ # into it; use block
181
+ if block
182
+ if block.arity == -1 or block.arity == 0
183
+ self.instance_eval(&block)
184
+ elsif block.arity == 1
185
+ block.call(self)
186
+ else
187
+ Kernel.raise ArgumentError,
188
+ "Block to initialize accepts zero or one arg"
189
+ end
190
+ end
191
+ end
192
+ end
193
+
194
+ # Any class inheriting from a class including this module must have
195
+ # its own copy of the param_spec
196
+ def klass.inherited(sub_klass)
197
+ sub_klass.instance_variable_set(:@param_spec,
198
+ instance_variable_get(:@param_spec) )
199
+ end
200
+ end
201
+ end
202
+ end
203
+