wxruby3 1.3.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/INSTALL.md +16 -12
  3. data/README.md +4 -3
  4. data/ext/wxruby3/include/wxRubyApp.h +9 -9
  5. data/ext/wxruby3/swig/mark_free_impl.i +47 -11
  6. data/ext/wxruby3/swig/wx.i +30 -12
  7. data/lib/wx/aui/auifloatframe.rb +1 -1
  8. data/lib/wx/aui/auimanager.rb +5 -16
  9. data/lib/wx/aui/auinotebook.rb +1 -1
  10. data/lib/wx/aui/require.rb +0 -2
  11. data/lib/wx/core/acceleratortable.rb +1 -1
  12. data/lib/wx/core/animation.rb +2 -2
  13. data/lib/wx/core/app.rb +1 -1
  14. data/lib/wx/core/artprovider.rb +4 -4
  15. data/lib/wx/core/bitmap.rb +1 -1
  16. data/lib/wx/core/bitmap_combobox.rb +2 -2
  17. data/lib/wx/core/clientdc.rb +1 -1
  18. data/lib/wx/core/clipboard.rb +4 -4
  19. data/lib/wx/core/colour.rb +1 -1
  20. data/lib/wx/core/combobox.rb +1 -1
  21. data/lib/wx/core/config.rb +7 -7
  22. data/lib/wx/core/controlwithitems.rb +3 -3
  23. data/lib/wx/core/data_object.rb +4 -4
  24. data/lib/wx/core/dataformat.rb +9 -3
  25. data/lib/wx/core/dialog.rb +3 -2
  26. data/lib/wx/core/event.rb +3 -3
  27. data/lib/wx/core/evthandler.rb +325 -289
  28. data/lib/wx/core/file_dialog.rb +1 -1
  29. data/lib/wx/core/find_replace_dialog.rb +2 -2
  30. data/lib/wx/core/functions.rb +1 -1
  31. data/lib/wx/core/genericdirctrl.rb +1 -1
  32. data/lib/wx/core/geometry.rb +2 -2
  33. data/lib/wx/core/graphics_pen_info.rb +1 -1
  34. data/lib/wx/core/helpprovider.rb +1 -1
  35. data/lib/wx/core/icon.rb +1 -1
  36. data/lib/wx/core/image.rb +2 -2
  37. data/lib/wx/core/imagelist.rb +1 -1
  38. data/lib/wx/core/locale.rb +5 -5
  39. data/lib/wx/core/log.rb +8 -8
  40. data/lib/wx/core/menu.rb +3 -3
  41. data/lib/wx/core/module_ext.rb +16 -0
  42. data/lib/wx/core/owner_drawn_combobox.rb +3 -3
  43. data/lib/wx/core/pen_info.rb +1 -1
  44. data/lib/wx/core/persistence_manager.rb +2 -2
  45. data/lib/wx/core/rect.rb +1 -1
  46. data/lib/wx/core/secret_store.rb +1 -1
  47. data/lib/wx/core/simplehelpprovider.rb +1 -1
  48. data/lib/wx/core/sizer.rb +8 -8
  49. data/lib/wx/core/splash_screen.rb +1 -1
  50. data/lib/wx/core/standard_paths.rb +1 -1
  51. data/lib/wx/core/task_bar_button.rb +1 -1
  52. data/lib/wx/core/text_entry.rb +1 -1
  53. data/lib/wx/core/textctrl.rb +2 -2
  54. data/lib/wx/core/timer.rb +2 -2
  55. data/lib/wx/core/tree_ctrl.rb +1 -1
  56. data/lib/wx/core/v_list_box.rb +1 -1
  57. data/lib/wx/core/validator.rb +2 -2
  58. data/lib/wx/core/variant.rb +2 -2
  59. data/lib/wx/core/window.rb +48 -2
  60. data/lib/wx/core/xmlresource.rb +4 -4
  61. data/lib/wx/core.rb +2 -0
  62. data/lib/wx/doc/evthandler.rb +1 -23
  63. data/lib/wx/doc/tip_window.rb +22 -0
  64. data/lib/wx/grid/grid.rb +3 -3
  65. data/lib/wx/grid/require.rb +0 -2
  66. data/lib/wx/html/htmlhelpcontroller.rb +1 -1
  67. data/lib/wx/html/htmlwindow.rb +1 -1
  68. data/lib/wx/html/require.rb +0 -2
  69. data/lib/wx/html/simple_html_listbox.rb +3 -3
  70. data/lib/wx/keyword_ctors.rb +14 -7
  71. data/lib/wx/keyword_defs.rb +7 -7
  72. data/lib/wx/pg/pg_properties.rb +1 -1
  73. data/lib/wx/pg/pg_property.rb +3 -3
  74. data/lib/wx/pg/property_grid.rb +2 -2
  75. data/lib/wx/pg/property_grid_interface.rb +2 -2
  76. data/lib/wx/pg/require.rb +0 -2
  77. data/lib/wx/prt/previewframe.rb +1 -1
  78. data/lib/wx/prt/require.rb +0 -2
  79. data/lib/wx/rbn/ribbon_control.rb +1 -1
  80. data/lib/wx/rbn/ribbon_page.rb +1 -1
  81. data/lib/wx/rbn/ribbon_panel.rb +1 -1
  82. data/lib/wx/rtc/require.rb +0 -2
  83. data/lib/wx/rtc/rich_text_composite_object.rb +1 -1
  84. data/lib/wx/rtc/rich_text_ctrl.rb +1 -1
  85. data/lib/wx/rtc/rich_text_paragraph.rb +1 -1
  86. data/lib/wx/rtc/richtext_buffer.rb +3 -3
  87. data/lib/wx/rtc/richtext_formatting_dialog.rb +2 -2
  88. data/lib/wx/rtc/richtext_style_organiser_dialog.rb +1 -1
  89. data/lib/wx/rtc/symbol_picker_dialog.rb +1 -1
  90. data/lib/wx/stc/require.rb +0 -2
  91. data/lib/wx/stc/styled_text_ctrl.rb +1 -1
  92. data/lib/wx/version.rb +1 -1
  93. data/lib/wx/wxruby/base.rb +8 -2
  94. data/lib/wx/wxruby/cmd/setup.rb +61 -37
  95. data/rakelib/gem.rb +8 -4
  96. data/rakelib/lib/config/macosx.rb +31 -4
  97. data/rakelib/lib/config/mingw.rb +1 -1
  98. data/rakelib/lib/config/pkgman/linux.rb +9 -1
  99. data/rakelib/lib/core/package.rb +68 -49
  100. data/rakelib/lib/director/about_dialog_info.rb +1 -0
  101. data/rakelib/lib/director/aui_manager.rb +63 -57
  102. data/rakelib/lib/director/aui_notebook.rb +7 -0
  103. data/rakelib/lib/director/colour.rb +1 -1
  104. data/rakelib/lib/director/data_format.rb +1 -1
  105. data/rakelib/lib/director/event.rb +1 -0
  106. data/rakelib/lib/director/event_handler.rb +82 -46
  107. data/rakelib/lib/director/events.rb +5 -3
  108. data/rakelib/lib/director/functions.rb +0 -3
  109. data/rakelib/lib/director/grid_ctrl.rb +24 -0
  110. data/rakelib/lib/director/html_printout.rb +2 -0
  111. data/rakelib/lib/director/list_ctrl.rb +14 -10
  112. data/rakelib/lib/director/locale.rb +2 -0
  113. data/rakelib/lib/director/num_validator.rb +7 -0
  114. data/rakelib/lib/director/print_data.rb +7 -0
  115. data/rakelib/lib/director/printer.rb +2 -0
  116. data/rakelib/lib/director/richtext_printing.rb +2 -0
  117. data/rakelib/lib/director/splitter_window.rb +17 -0
  118. data/rakelib/lib/director/textctrl.rb +21 -4
  119. data/rakelib/lib/director/tip_window.rb +34 -0
  120. data/rakelib/lib/director/window.rb +9 -1
  121. data/rakelib/lib/director.rb +0 -1
  122. data/rakelib/lib/generate/doc/evt_handler.yaml +31 -12
  123. data/rakelib/lib/specs/interfaces.rb +9 -0
  124. data/rakelib/lib/typemap/print_page_range.rb +97 -0
  125. data/tests/test_combo_ctrl.rb +1 -0
  126. data/tests/test_event_handling.rb +158 -31
  127. metadata +7 -5
@@ -9,339 +9,375 @@
9
9
  # All classes which are capable of handling events inherit from
10
10
  # EvtHandler. This includes all Wx::Window subclasses and Wx::App.
11
11
 
12
- class Wx::EvtHandler
13
-
14
- alias :set_client_data :set_client_object
15
- alias :client_data= :set_client_object
16
- alias :get_client_data :get_client_object
17
- alias :client_data :get_client_object
18
-
19
- # EventType is an internal class that's used to set up event handlers
20
- # and mappings.
21
- # * 'name' is the name of the event handler method in ruby
22
- # * 'arity' is the number of id arguments that method should accept
23
- # * 'const' is the Wx EventType constant that identifies the event
24
- # * 'evt_class' is the WxRuby event class which is passed to the event
25
- # handler block
26
- #
27
- # NB: Some event types currently pass a Wx::Event into the event
28
- # handler block; when the appropriate classes are added to wxRuby, the
29
- # binding can be updated here.
30
- EventType = Struct.new(:name, :arity, :const, :evt_class)
31
-
32
- # Fast look-up hash to map event type ids to ruby event classes
33
- EVENT_TYPE_CLASS_MAP = {}
34
- private_constant :EVENT_TYPE_CLASS_MAP
35
- # Hash to look up EVT constants from symbol names of evt handler
36
- # methods; used internally by disconnect (see EvtHandler.i)
37
- EVENT_NAME_TYPE_MAP = {}
38
- private_constant :EVENT_NAME_TYPE_MAP
39
- # Hash to look up event handler arity from symbol names of evt handler
40
- # methods; internal use
41
- EVENT_NAME_EVENT_ARITY_MAP = {}
42
- private_constant :EVENT_NAME_EVENT_ARITY_MAP
43
-
44
- class << self
45
-
46
- def event_type_arity(name)
47
- EVENT_NAME_EVENT_ARITY_MAP[name.to_sym] || 0
48
- end
12
+ module Wx
49
13
 
50
- def get_event_type_class_map
51
- EVENT_TYPE_CLASS_MAP
52
- end
53
- private :get_event_type_class_map
14
+ class AsyncProcCallEvent < Event; end
54
15
 
55
- # Add caching for added event filters as we need to keep these alive
56
- # for as long as they are registered
16
+ class EvtHandler
57
17
 
58
- def event_filters
59
- @event_filters ||= []
60
- end
61
- private :event_filters
18
+ alias :set_client_data :set_client_object
19
+ alias :client_data= :set_client_object
20
+ alias :get_client_data :get_client_object
21
+ alias :client_data :get_client_object
62
22
 
63
- wx_add_filter = instance_method :add_filter
64
- define_method :add_filter do |filter|
65
- wx_add_filter.bind(self).call(filter)
66
- event_filters << filter
67
- end
23
+ # Simplify event chaining for wxRuby by handling double linking internally in Ruby code.
24
+ #
25
+ wx_set_next_handler = instance_method :set_next_handler
26
+ wx_set_previous_handler = instance_method :set_previous_handler
68
27
 
69
- wx_remove_filter = instance_method :remove_filter
70
- define_method :remove_filter do |filter|
71
- wx_remove_filter.bind(self).call(filter)
72
- event_filters.delete(filter)
28
+ wx_redefine_method :set_next_handler do |evthnd|
29
+ # check if we have a different existing next handler
30
+ cur_next = get_next_handler
31
+ if cur_next && cur_next != evthnd
32
+ # cut the 'old' next handler from the chain
33
+ cur_next.unlink
34
+ end
35
+ wx_set_next_handler.bind(self).call(evthnd)
36
+ wx_set_previous_handler.bind(evthnd).call(self) if evthnd
73
37
  end
38
+ alias :next_handler= :set_next_handler
74
39
 
75
- def clear_filters
76
- event_filters.each { |f| remove_filter(f) }
77
- event_filters.clear
40
+ # disable this in Ruby; set_next_handler handles double linking
41
+ wx_redefine_method :set_previous_handler do |evthnd|
42
+ raise NoMethodError
78
43
  end
44
+ alias :previous_handler= :set_previous_handler
45
+
46
+ # EventType is an internal class that's used to set up event handlers
47
+ # and mappings.
48
+ # * 'name' is the name of the event handler method in ruby
49
+ # * 'arity' is the number of id arguments that method should accept
50
+ # * 'const' is the Wx EventType constant that identifies the event
51
+ # * 'evt_class' is the WxRuby event class which is passed to the event
52
+ # handler block
53
+ #
54
+ # NB: Some event types currently pass a Wx::Event into the event
55
+ # handler block; when the appropriate classes are added to wxRuby, the
56
+ # binding can be updated here.
57
+ EventType = Struct.new(:name, :arity, :const, :evt_class)
58
+
59
+ # Fast look-up hash to map event type ids to ruby event classes
60
+ EVENT_TYPE_CLASS_MAP = {}
61
+ private_constant :EVENT_TYPE_CLASS_MAP
62
+ # Hash to look up EVT constants from symbol names of evt handler
63
+ # methods; used internally by disconnect (see EvtHandler.i)
64
+ EVENT_NAME_TYPE_MAP = {}
65
+ private_constant :EVENT_NAME_TYPE_MAP
66
+ # Hash to look up event handler arity from symbol names of evt handler
67
+ # methods; internal use
68
+ EVENT_NAME_EVENT_ARITY_MAP = {}
69
+ private_constant :EVENT_NAME_EVENT_ARITY_MAP
70
+
71
+ class << self
72
+
73
+ def event_type_arity(name)
74
+ EVENT_NAME_EVENT_ARITY_MAP[name.to_sym] || 0
75
+ end
79
76
 
80
- end
77
+ def get_event_type_class_map
78
+ EVENT_TYPE_CLASS_MAP
79
+ end
80
+ private :get_event_type_class_map
81
+
82
+ # Add caching for added event filters as we need to keep these alive
83
+ # for as long as they are registered
81
84
 
82
- # Given a Wx EventType id (eg Wx::EVT_MENU), returns a WxRuby Event
83
- # class which should be passed to event handler blocks. The actual
84
- # EVT_XXX constants themselves are in the compiled libraries.
85
- def self.event_class_for_type(id)
86
- if evt_klass = EVENT_TYPE_CLASS_MAP[id]
87
- return evt_klass
88
- else
89
- if Wx::DEBUG
90
- warn "No event class defined for event type #{id}"
85
+ def event_filters
86
+ @event_filters ||= []
91
87
  end
92
- return Wx::Event
93
- end
94
- end
88
+ private :event_filters
95
89
 
96
- # Given the symbol name of an evt_xxx handler method, returns the
97
- # Integer Wx::EVT_XXX constant associated with that handler.
98
- def self.event_type_for_name(name)
99
- EVENT_NAME_TYPE_MAP[name]
100
- end
90
+ wx_add_filter = instance_method :add_filter
91
+ wx_redefine_method :add_filter do |filter|
92
+ wx_add_filter.bind(self).call(filter)
93
+ event_filters << filter
94
+ end
101
95
 
102
- # Given the Integer constant Wx::EVT_XXX, returns the convenience
103
- # handler method name associated with that type of event.
104
- def self.event_name_for_type(evt_id)
105
- EVENT_NAME_TYPE_MAP.key(evt_id)
106
- end
96
+ wx_remove_filter = instance_method :remove_filter
97
+ wx_redefine_method :remove_filter do |filter|
98
+ wx_remove_filter.bind(self).call(filter)
99
+ event_filters.delete(filter)
100
+ end
101
+
102
+ def clear_filters
103
+ event_filters.each { |f| remove_filter(f) }
104
+ event_filters.clear
105
+ end
107
106
 
108
- # Given an integer value +int_val+, returns the name of the EVT_xxx
109
- # constant which points to it. Mainly useful for debugging.
110
- def self.const_to_name(int_val)
111
- Wx::constants.grep(/^EVT/).find do | c_name |
112
- Wx::const_get(c_name) == int_val
113
107
  end
114
- end
115
108
 
116
- # Public method to register the mapping of a custom event type
117
- # +konstant+ (which should be a unique integer; one will be created if
118
- # not supplied) to a custom event class +klass+. If +meth+ and +arity+
119
- # are given, a convenience evt_handler method called +meth+ will be
120
- # created, which accepts +arity+ arguments.
121
- def self.register_class( klass, konstant = nil,
122
- meth = nil, arity = nil)
123
- konstant ||= Wx::Event.new_user_event_type
124
- unless klass < Wx::Event
125
- Kernel.raise TypeError, "Event class should be a subclass of Wx::Event"
109
+ # Given a Wx EventType id (eg Wx::EVT_MENU), returns a WxRuby Event
110
+ # class which should be passed to event handler blocks. The actual
111
+ # EVT_XXX constants themselves are in the compiled libraries.
112
+ def self.event_class_for_type(id)
113
+ if evt_klass = EVENT_TYPE_CLASS_MAP[id]
114
+ return evt_klass
115
+ else
116
+ if Wx::DEBUG
117
+ warn "No event class defined for event type #{id}"
118
+ end
119
+ return Wx::Event
120
+ end
126
121
  end
127
- ev_type = EventType.new(meth, arity, konstant, klass)
128
- register_event_type(ev_type)
129
- return konstant
130
- end
131
122
 
132
- # Registers the event type +ev_type+, which should be an instance of
133
- # the Struct class +Wx::EvtHandler::EventType+. This sets up the
134
- # mapping of events of that type (identified by integer id) to the
135
- # appropriate ruby event class, and defines a convenience evt_xxx
136
- # instance method in the class EvtHandler.
137
- def self.register_event_type(ev_type)
138
- # set up the event type mapping
139
- EVENT_TYPE_CLASS_MAP[ev_type.const] = ev_type.evt_class
140
- EVENT_NAME_TYPE_MAP[ev_type.name.intern] = ev_type.const
141
-
142
- unless ev_type.arity and ev_type.name
143
- return
123
+ # Given the symbol name of an evt_xxx handler method, returns the
124
+ # Integer Wx::EVT_XXX constant associated with that handler.
125
+ def self.event_type_for_name(name)
126
+ EVENT_NAME_TYPE_MAP[name]
144
127
  end
145
128
 
146
- EVENT_NAME_EVENT_ARITY_MAP[ev_type.name.to_sym] = ev_type.arity
147
-
148
- # set up the evt_xxx method
149
- case ev_type.arity
150
- when 0 # events without an id
151
- class_eval %Q|
152
- def #{ev_type.name}(meth = nil, &block)
153
- handler = acquire_handler(meth, block)
154
- connect(Wx::ID_ANY, Wx::ID_ANY, #{ev_type.const}, handler)
155
- end |
156
- when 1 # events with an id
157
- class_eval %Q|
158
- def #{ev_type.name}(id, meth = nil, &block)
159
- handler = acquire_handler(meth, block)
160
- id = acquire_id(id)
161
- connect(id, Wx::ID_ANY, #{ev_type.const}, handler)
162
- end |
163
- when 2 # events with id range
164
- class_eval %Q|
165
- def #{ev_type.name}(first_id, last_id, meth = nil, &block)
166
- handler = acquire_handler(meth, block)
167
- first_id = acquire_id(first_id)
168
- last_id = acquire_id(last_id)
169
- connect(first_id, last_id, #{ev_type.const}, handler)
170
- end |
129
+ # Given the Integer constant Wx::EVT_XXX, returns the convenience
130
+ # handler method name associated with that type of event.
131
+ def self.event_name_for_type(evt_id)
132
+ EVENT_NAME_TYPE_MAP.key(evt_id)
171
133
  end
172
- end
173
134
 
174
- # Not for external use; determines whether to use a block or call a
175
- # method in self to handle an event, passed to connect. Makes evt_xxx
176
- # liberal about what it accepts - aside from a block, it can be a
177
- # method name (as Symbol or String), a (bound) method object, or a
178
- # Proc object
179
- def acquire_handler(meth, block)
180
- if block and not meth
181
- return block
182
- elsif meth and not block
183
- h_meth = case meth
184
- when Symbol, String then self.method(meth)
185
- when Proc then meth
186
- when Method then meth
187
- end
188
- # check arity <= 1
189
- if h_meth.arity>1
190
- Kernel.raise ArgumentError,
191
- "Event handler should not accept more than at most a single argument",
192
- caller
135
+ # Given an integer value +int_val+, returns the name of the EVT_xxx
136
+ # constant which points to it. Mainly useful for debugging.
137
+ def self.const_to_name(int_val)
138
+ Wx::constants.grep(/^EVT/).find do | c_name |
139
+ Wx::const_get(c_name) == int_val
193
140
  end
194
- # wrap method without any argument in anonymous proc to prevent strict argument checking
195
- if Method === h_meth && h_meth.arity == 0
196
- Proc.new { h_meth.call }
141
+ end
142
+
143
+ # Public method to register the mapping of a custom event type
144
+ # +konstant+ (which should be a unique integer; one will be created if
145
+ # not supplied) to a custom event class +klass+. If +meth+ and +arity+
146
+ # are given, a convenience evt_handler method called +meth+ will be
147
+ # created, which accepts +arity+ arguments.
148
+ def self.register_class( klass, konstant = nil,
149
+ meth = nil, arity = nil)
150
+ konstant ||= Wx::Event.new_user_event_type
151
+ unless klass < Wx::Event
152
+ Kernel.raise TypeError, "Event class should be a subclass of Wx::Event"
153
+ end
154
+ ev_type = EventType.new(meth, arity, konstant, klass)
155
+ register_event_type(ev_type)
156
+ return konstant
157
+ end
158
+
159
+ # Registers the event type +ev_type+, which should be an instance of
160
+ # the Struct class +Wx::EvtHandler::EventType+. This sets up the
161
+ # mapping of events of that type (identified by integer id) to the
162
+ # appropriate ruby event class, and defines a convenience evt_xxx
163
+ # instance method in the class EvtHandler.
164
+ def self.register_event_type(ev_type)
165
+ # set up the event type mapping
166
+ EVENT_TYPE_CLASS_MAP[ev_type.const] = ev_type.evt_class
167
+ EVENT_NAME_TYPE_MAP[ev_type.name.intern] = ev_type.const
168
+
169
+ unless ev_type.arity and ev_type.name
170
+ return
171
+ end
172
+
173
+ EVENT_NAME_EVENT_ARITY_MAP[ev_type.name.to_sym] = ev_type.arity
174
+
175
+ # set up the evt_xxx method
176
+ case ev_type.arity
177
+ when 0 # events without an id
178
+ class_eval %Q|
179
+ def #{ev_type.name}(meth = nil, &block)
180
+ handler = acquire_handler(meth, block)
181
+ connect(Wx::ID_ANY, Wx::ID_ANY, #{ev_type.const}, handler)
182
+ end |
183
+ when 1 # events with an id
184
+ class_eval %Q|
185
+ def #{ev_type.name}(id, meth = nil, &block)
186
+ handler = acquire_handler(meth, block)
187
+ id = acquire_id(id)
188
+ connect(id, Wx::ID_ANY, #{ev_type.const}, handler)
189
+ end |
190
+ when 2 # events with id range
191
+ class_eval %Q|
192
+ def #{ev_type.name}(first_id, last_id, meth = nil, &block)
193
+ handler = acquire_handler(meth, block)
194
+ first_id = acquire_id(first_id)
195
+ last_id = acquire_id(last_id)
196
+ connect(first_id, last_id, #{ev_type.const}, handler)
197
+ end |
198
+ end
199
+ end
200
+
201
+ # Not for external use; determines whether to use a block or call a
202
+ # method in self to handle an event, passed to connect. Makes evt_xxx
203
+ # liberal about what it accepts - aside from a block, it can be a
204
+ # method name (as Symbol or String), a (bound) method object, or a
205
+ # Proc object
206
+ def acquire_handler(meth, block)
207
+ if block and not meth
208
+ return block
209
+ elsif meth and not block
210
+ h_meth = case meth
211
+ when Symbol, String then self.method(meth)
212
+ when Proc then meth
213
+ when Method then meth
214
+ end
215
+ # check arity <= 1
216
+ if h_meth.arity>1
217
+ Kernel.raise ArgumentError,
218
+ "Event handler should not accept more than at most a single argument",
219
+ caller
220
+ end
221
+ # wrap method without any argument in anonymous proc to prevent strict argument checking
222
+ if Method === h_meth && h_meth.arity == 0
223
+ Proc.new { h_meth.call }
224
+ else
225
+ h_meth
226
+ end
197
227
  else
198
- h_meth
228
+ Kernel.raise ArgumentError,
229
+ "Specify event handler with a method, name, proc OR block",
230
+ caller
199
231
  end
200
- else
201
- Kernel.raise ArgumentError,
202
- "Specify event handler with a method, name, proc OR block",
203
- caller
204
232
  end
205
- end
206
233
 
207
- # Not for external use; acquires an id either from an explicit Fixnum
208
- # parameter or by calling the wx_id method of a passed Window.
209
- def acquire_id(window_or_id)
210
- case window_or_id
211
- when ::Integer, Wx::Enum
212
- window_or_id
213
- when Wx::Window, Wx::MenuItem, Wx::ToolBarTool, Wx::Timer
214
- window_or_id.wx_id
215
- else
216
- Kernel.raise ArgumentError,
217
- "Must specify Wx::Window event source or its Wx id, " +
218
- "not '#{window_or_id.inspect}'",
219
- caller
234
+ # Not for external use; acquires an id either from an explicit Fixnum
235
+ # parameter or by calling the wx_id method of a passed Window.
236
+ def acquire_id(window_or_id)
237
+ case window_or_id
238
+ when ::Integer, Wx::Enum
239
+ window_or_id
240
+ when Wx::Window, Wx::MenuItem, Wx::ToolBarTool, Wx::Timer
241
+ window_or_id.wx_id
242
+ else
243
+ Kernel.raise ArgumentError,
244
+ "Must specify Wx::Window event source or its Wx id, " +
245
+ "not '#{window_or_id.inspect}'",
246
+ caller
247
+ end
220
248
  end
221
- end
222
- private :acquire_id, :acquire_handler
223
-
224
- wx_call_after = instance_method(:call_after)
225
- define_method(:call_after) do |*args, &block|
226
- async_proc = if block
227
- block
228
- elsif !args.empty?
229
- case args.first
230
- when Symbol, String then self.method(args.shift)
231
- when Proc then args.shift
232
- when Method then args.shift
249
+ private :acquire_id, :acquire_handler
250
+
251
+ wx_call_after = instance_method(:call_after)
252
+ wx_redefine_method(:call_after) do |*args, &block|
253
+ async_proc = if block
254
+ block
255
+ elsif !args.empty?
256
+ case args.first
257
+ when Symbol, String then self.method(args.shift)
258
+ when Proc then args.shift
259
+ when Method then args.shift
260
+ else
261
+ nil
262
+ end
233
263
  else
234
264
  nil
235
265
  end
236
- else
237
- nil
238
- end
239
- Kernel.raise ArgumentError, 'Missing async call handler' unless async_proc
240
- wx_call_after.bind(self).call(args.unshift(async_proc))
241
- end
266
+ Kernel.raise ArgumentError, 'Missing async call handler' unless async_proc
267
+ wx_call_after.bind(self).call(args.unshift(async_proc))
268
+ end
242
269
 
243
- # Process a command, supplying the window identifier, command event identifier, and member function or proc.
244
- def evt_command(id, evt_id, meth = nil, &block)
245
- handler = acquire_handler(meth, block)
246
- id = acquire_id(id)
247
- connect(id, Wx::ID_ANY, evt_id, handler)
248
- end
270
+ # Process a command, supplying the window identifier, command event identifier, and member function or proc.
271
+ def evt_command(id, evt_id, meth = nil, &block)
272
+ handler = acquire_handler(meth, block)
273
+ id = acquire_id(id)
274
+ connect(id, Wx::ID_ANY, evt_id, handler)
275
+ end
249
276
 
250
- # Process a command for a range of window identifiers, supplying the minimum and maximum window identifiers, command event identifier, and member function or proc.
251
- def evt_command_range(id1, id2, evt_id, meth = nil, &block)
252
- handler = acquire_handler(meth, block)
253
- id = acquire_id(id)
254
- connect(id, Wx::ID_ANY, evt_id, handler)
255
- end
277
+ # Process a command for a range of window identifiers, supplying the minimum and maximum window identifiers, command event identifier, and member function or proc.
278
+ def evt_command_range(id1, id2, evt_id, meth = nil, &block)
279
+ handler = acquire_handler(meth, block)
280
+ id = acquire_id(id)
281
+ connect(id, Wx::ID_ANY, evt_id, handler)
282
+ end
256
283
 
257
- # Convenience evt_handler to listen to all mouse events.
258
- def evt_mouse_events(*args, &block)
259
- evt_left_down(*args, &block)
260
- evt_left_up(*args, &block)
261
- evt_middle_down(*args, &block)
262
- evt_middle_up(*args, &block)
263
- evt_right_down(*args, &block)
264
- evt_right_up(*args, &block)
265
- evt_motion(*args, &block)
266
- evt_left_dclick(*args, &block)
267
- evt_middle_dclick(*args, &block)
268
- evt_right_dclick(*args, &block)
269
- evt_leave_window(*args, &block)
270
- evt_enter_window(*args, &block)
271
- evt_mousewheel(*args, &block)
272
- end
284
+ # Convenience evt_handler to listen to all mouse events.
285
+ def evt_mouse_events(*args, &block)
286
+ evt_left_down(*args, &block)
287
+ evt_left_up(*args, &block)
288
+ evt_middle_down(*args, &block)
289
+ evt_middle_up(*args, &block)
290
+ evt_right_down(*args, &block)
291
+ evt_right_up(*args, &block)
292
+ evt_motion(*args, &block)
293
+ evt_left_dclick(*args, &block)
294
+ evt_middle_dclick(*args, &block)
295
+ evt_right_dclick(*args, &block)
296
+ evt_leave_window(*args, &block)
297
+ evt_enter_window(*args, &block)
298
+ evt_mousewheel(*args, &block)
299
+ end
273
300
 
274
- # Convenience evt handler to listen to all scrollwin events.
275
- def evt_scrollwin(meth = nil, &block)
276
- evt_scrollwin_top(meth, &block)
277
- evt_scrollwin_bottom(meth, &block)
278
- evt_scrollwin_lineup(meth, &block)
279
- evt_scrollwin_linedown(meth, &block)
280
- evt_scrollwin_pageup(meth, &block)
281
- evt_scrollwin_pagedown(meth, &block)
282
- evt_scrollwin_thumbtrack(meth, &block)
283
- evt_scrollwin_thumbrelease(meth, &block)
284
- end
301
+ # Convenience evt_handler to listen to all joystick events.
302
+ def evt_joystick_events(*args, &block)
303
+ evt_joy_button_down(*args, &block)
304
+ evt_joy_button_up(*args, &block)
305
+ evt_joy_move(*args, &block)
306
+ evt_joy_zmove(*args, &block)
307
+ end
285
308
 
286
- # Convenience evt handler to listen to all scroll events (Wx::Slider and Wx::ScrollBar)
287
- def evt_scroll(meth = nil, &block)
288
- evt_scroll_top(meth, &block)
289
- evt_scroll_bottom(meth, &block)
290
- evt_scroll_lineup(meth, &block)
291
- evt_scroll_linedown(meth, &block)
292
- evt_scroll_pageup(meth, &block)
293
- evt_scroll_pagedown(meth, &block)
294
- evt_scroll_thumbtrack(meth, &block)
295
- evt_scroll_thumbrelease(meth, &block)
296
- evt_scroll_changed(meth, &block)
297
- end
309
+ # Convenience evt handler to listen to all scrollwin events.
310
+ def evt_scrollwin(meth = nil, &block)
311
+ evt_scrollwin_top(meth, &block)
312
+ evt_scrollwin_bottom(meth, &block)
313
+ evt_scrollwin_lineup(meth, &block)
314
+ evt_scrollwin_linedown(meth, &block)
315
+ evt_scrollwin_pageup(meth, &block)
316
+ evt_scrollwin_pagedown(meth, &block)
317
+ evt_scrollwin_thumbtrack(meth, &block)
318
+ evt_scrollwin_thumbrelease(meth, &block)
319
+ end
298
320
 
299
- # Convenience evt handler to listen to all scroll command events.
300
- def evt_command_scroll(id, meth = nil, &block)
301
- evt_command_scroll_top(id, meth, &block)
302
- evt_command_scroll_bottom(id, meth, &block)
303
- evt_command_scroll_lineup(id, meth, &block)
304
- evt_command_scroll_linedown(id, meth, &block)
305
- evt_command_scroll_pageup(id, meth, &block)
306
- evt_command_scroll_pagedown(id, meth, &block)
307
- evt_command_scroll_thumbtrack(id, meth, &block)
308
- evt_command_scroll_thumbrelease(id, meth, &block)
309
- evt_command_scroll_changed(id, meth, &block)
310
- end
321
+ # Convenience evt handler to listen to all scroll events (Wx::Slider and Wx::ScrollBar)
322
+ def evt_scroll(meth = nil, &block)
323
+ evt_scroll_top(meth, &block)
324
+ evt_scroll_bottom(meth, &block)
325
+ evt_scroll_lineup(meth, &block)
326
+ evt_scroll_linedown(meth, &block)
327
+ evt_scroll_pageup(meth, &block)
328
+ evt_scroll_pagedown(meth, &block)
329
+ evt_scroll_thumbtrack(meth, &block)
330
+ evt_scroll_thumbrelease(meth, &block)
331
+ evt_scroll_changed(meth, &block)
332
+ end
311
333
 
312
- # add missing constants (these are redefinitions of other constants which are not documented themselves)
313
- %i[EVT_COMMAND_SCROLL_TOP
314
- EVT_COMMAND_SCROLL_BOTTOM
315
- EVT_COMMAND_SCROLL_LINEUP
316
- EVT_COMMAND_SCROLL_LINEDOWN
317
- EVT_COMMAND_SCROLL_PAGEUP
318
- EVT_COMMAND_SCROLL_PAGEDOWN
319
- EVT_COMMAND_SCROLL_THUMBTRACK
320
- EVT_COMMAND_SCROLL_THUMBRELEASE
321
- EVT_COMMAND_SCROLL_CHANGED].each do |const|
322
- unless Wx.const_defined?(const)
323
- Wx.const_set(const, Wx.const_get(const.to_s.sub('EVT_COMMAND_', 'EVT_').to_sym))
334
+ # Convenience evt handler to listen to all scroll command events.
335
+ def evt_command_scroll(id, meth = nil, &block)
336
+ evt_command_scroll_top(id, meth, &block)
337
+ evt_command_scroll_bottom(id, meth, &block)
338
+ evt_command_scroll_lineup(id, meth, &block)
339
+ evt_command_scroll_linedown(id, meth, &block)
340
+ evt_command_scroll_pageup(id, meth, &block)
341
+ evt_command_scroll_pagedown(id, meth, &block)
342
+ evt_command_scroll_thumbtrack(id, meth, &block)
343
+ evt_command_scroll_thumbrelease(id, meth, &block)
344
+ evt_command_scroll_changed(id, meth, &block)
324
345
  end
325
- end
326
346
 
327
- if Wx.const_defined?(:EVT_DESTROY)
347
+ # add missing constants (these are redefinitions of other constants which are not documented themselves)
348
+ %i[EVT_COMMAND_SCROLL_TOP
349
+ EVT_COMMAND_SCROLL_BOTTOM
350
+ EVT_COMMAND_SCROLL_LINEUP
351
+ EVT_COMMAND_SCROLL_LINEDOWN
352
+ EVT_COMMAND_SCROLL_PAGEUP
353
+ EVT_COMMAND_SCROLL_PAGEDOWN
354
+ EVT_COMMAND_SCROLL_THUMBTRACK
355
+ EVT_COMMAND_SCROLL_THUMBRELEASE
356
+ EVT_COMMAND_SCROLL_CHANGED].each do |const|
357
+ unless Wx.const_defined?(const)
358
+ Wx.const_set(const, Wx.const_get(const.to_s.sub('EVT_COMMAND_', 'EVT_').to_sym))
359
+ end
360
+ end
328
361
 
329
- # evt_window_destroy is a special case in that evt.skip
330
- # should always be called when handling the event
331
- # as otherwise the OnWindowDestroy handler of Wx::App will not
332
- # be called to deregister the windows on destruction which
333
- # may lead to segfaults during the GC marking phase.
334
- # Thus we register the event here explicitly as well as the
335
- # event hook method.
362
+ if Wx.const_defined?(:EVT_DESTROY)
336
363
 
337
- EVENT_TYPE_CLASS_MAP[Wx::EVT_DESTROY] = Wx::WindowDestroyEvent
338
- EVENT_NAME_TYPE_MAP['evt_window_destroy'.intern] = Wx::EVT_DESTROY
364
+ # evt_window_destroy is a special case in that evt.skip
365
+ # should always be called when handling the event
366
+ # as otherwise the OnWindowDestroy handler of Wx::App will not
367
+ # be called to deregister the windows on destruction which
368
+ # may lead to segfaults during the GC marking phase.
369
+ # Thus we register the event here explicitly as well as the
370
+ # event hook method.
339
371
 
340
- def evt_window_destroy(meth = nil, &block)
341
- handler = acquire_handler(meth, block)
342
- connect(Wx::ID_ANY, Wx::ID_ANY, Wx::EVT_DESTROY, Proc.new { |evt| handler.call(evt); evt.skip })
343
- end
372
+ EVENT_TYPE_CLASS_MAP[Wx::EVT_DESTROY] = Wx::WindowDestroyEvent
373
+ EVENT_NAME_TYPE_MAP['evt_window_destroy'.intern] = Wx::EVT_DESTROY
374
+
375
+ def evt_window_destroy(meth = nil, &block)
376
+ handler = acquire_handler(meth, block)
377
+ connect(Wx::ID_ANY, Wx::ID_ANY, Wx::EVT_DESTROY, Proc.new { |evt| handler.call(evt); evt.skip })
378
+ end
344
379
 
380
+ end
345
381
  end
346
382
  end
347
383