wxruby3 1.3.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/INSTALL.md +16 -12
- data/README.md +4 -3
- data/ext/wxruby3/include/wxRubyApp.h +9 -9
- data/ext/wxruby3/swig/mark_free_impl.i +47 -11
- data/ext/wxruby3/swig/wx.i +30 -12
- data/lib/wx/aui/auifloatframe.rb +1 -1
- data/lib/wx/aui/auimanager.rb +5 -16
- data/lib/wx/aui/auinotebook.rb +1 -1
- data/lib/wx/aui/require.rb +0 -2
- data/lib/wx/core/acceleratortable.rb +1 -1
- data/lib/wx/core/animation.rb +2 -2
- data/lib/wx/core/app.rb +1 -1
- data/lib/wx/core/artprovider.rb +4 -4
- data/lib/wx/core/bitmap.rb +1 -1
- data/lib/wx/core/bitmap_combobox.rb +2 -2
- data/lib/wx/core/clientdc.rb +1 -1
- data/lib/wx/core/clipboard.rb +4 -4
- data/lib/wx/core/colour.rb +1 -1
- data/lib/wx/core/combobox.rb +1 -1
- data/lib/wx/core/config.rb +7 -7
- data/lib/wx/core/controlwithitems.rb +3 -3
- data/lib/wx/core/data_object.rb +4 -4
- data/lib/wx/core/dataformat.rb +9 -3
- data/lib/wx/core/dialog.rb +3 -2
- data/lib/wx/core/event.rb +3 -3
- data/lib/wx/core/evthandler.rb +317 -289
- data/lib/wx/core/file_dialog.rb +1 -1
- data/lib/wx/core/find_replace_dialog.rb +2 -2
- data/lib/wx/core/functions.rb +1 -1
- data/lib/wx/core/genericdirctrl.rb +1 -1
- data/lib/wx/core/geometry.rb +2 -2
- data/lib/wx/core/graphics_pen_info.rb +1 -1
- data/lib/wx/core/helpprovider.rb +1 -1
- data/lib/wx/core/icon.rb +1 -1
- data/lib/wx/core/image.rb +2 -2
- data/lib/wx/core/imagelist.rb +1 -1
- data/lib/wx/core/locale.rb +5 -5
- data/lib/wx/core/log.rb +8 -8
- data/lib/wx/core/menu.rb +3 -3
- data/lib/wx/core/module_ext.rb +16 -0
- data/lib/wx/core/owner_drawn_combobox.rb +3 -3
- data/lib/wx/core/pen_info.rb +1 -1
- data/lib/wx/core/persistence_manager.rb +2 -2
- data/lib/wx/core/rect.rb +1 -1
- data/lib/wx/core/secret_store.rb +1 -1
- data/lib/wx/core/simplehelpprovider.rb +1 -1
- data/lib/wx/core/sizer.rb +8 -8
- data/lib/wx/core/splash_screen.rb +1 -1
- data/lib/wx/core/standard_paths.rb +1 -1
- data/lib/wx/core/task_bar_button.rb +1 -1
- data/lib/wx/core/text_entry.rb +1 -1
- data/lib/wx/core/textctrl.rb +2 -2
- data/lib/wx/core/timer.rb +2 -2
- data/lib/wx/core/tree_ctrl.rb +1 -1
- data/lib/wx/core/v_list_box.rb +1 -1
- data/lib/wx/core/validator.rb +2 -2
- data/lib/wx/core/variant.rb +2 -2
- data/lib/wx/core/window.rb +48 -2
- data/lib/wx/core/xmlresource.rb +4 -4
- data/lib/wx/core.rb +2 -0
- data/lib/wx/doc/evthandler.rb +1 -0
- data/lib/wx/doc/tip_window.rb +22 -0
- data/lib/wx/grid/grid.rb +3 -3
- data/lib/wx/grid/require.rb +0 -2
- data/lib/wx/html/htmlhelpcontroller.rb +1 -1
- data/lib/wx/html/htmlwindow.rb +1 -1
- data/lib/wx/html/require.rb +0 -2
- data/lib/wx/html/simple_html_listbox.rb +3 -3
- data/lib/wx/keyword_ctors.rb +14 -7
- data/lib/wx/keyword_defs.rb +7 -7
- data/lib/wx/pg/pg_properties.rb +1 -1
- data/lib/wx/pg/pg_property.rb +3 -3
- data/lib/wx/pg/property_grid.rb +2 -2
- data/lib/wx/pg/property_grid_interface.rb +2 -2
- data/lib/wx/pg/require.rb +0 -2
- data/lib/wx/prt/previewframe.rb +1 -1
- data/lib/wx/prt/require.rb +0 -2
- data/lib/wx/rbn/ribbon_control.rb +1 -1
- data/lib/wx/rbn/ribbon_page.rb +1 -1
- data/lib/wx/rbn/ribbon_panel.rb +1 -1
- data/lib/wx/rtc/require.rb +0 -2
- data/lib/wx/rtc/rich_text_composite_object.rb +1 -1
- data/lib/wx/rtc/rich_text_ctrl.rb +1 -1
- data/lib/wx/rtc/rich_text_paragraph.rb +1 -1
- data/lib/wx/rtc/richtext_buffer.rb +3 -3
- data/lib/wx/rtc/richtext_formatting_dialog.rb +2 -2
- data/lib/wx/rtc/richtext_style_organiser_dialog.rb +1 -1
- data/lib/wx/rtc/symbol_picker_dialog.rb +1 -1
- data/lib/wx/stc/require.rb +0 -2
- data/lib/wx/stc/styled_text_ctrl.rb +1 -1
- data/lib/wx/version.rb +1 -1
- data/lib/wx/wxruby/base.rb +8 -2
- data/lib/wx/wxruby/cmd/setup.rb +61 -37
- data/rakelib/gem.rb +8 -4
- data/rakelib/lib/config/mingw.rb +1 -1
- data/rakelib/lib/director/about_dialog_info.rb +1 -0
- data/rakelib/lib/director/aui_manager.rb +63 -57
- data/rakelib/lib/director/aui_notebook.rb +7 -0
- data/rakelib/lib/director/colour.rb +1 -1
- data/rakelib/lib/director/data_format.rb +1 -1
- data/rakelib/lib/director/event.rb +1 -0
- data/rakelib/lib/director/event_handler.rb +82 -46
- data/rakelib/lib/director/functions.rb +0 -3
- data/rakelib/lib/director/list_ctrl.rb +14 -10
- data/rakelib/lib/director/locale.rb +2 -0
- data/rakelib/lib/director/num_validator.rb +7 -0
- data/rakelib/lib/director/tip_window.rb +34 -0
- data/rakelib/lib/director/window.rb +9 -1
- data/rakelib/lib/director.rb +0 -1
- data/rakelib/lib/generate/doc/evt_handler.yaml +31 -12
- data/rakelib/lib/specs/interfaces.rb +1 -0
- data/tests/test_combo_ctrl.rb +1 -0
- data/tests/test_event_handling.rb +158 -31
- metadata +6 -5
data/lib/wx/core/evthandler.rb
CHANGED
@@ -9,339 +9,367 @@
|
|
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
|
-
|
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
|
-
|
51
|
-
EVENT_TYPE_CLASS_MAP
|
52
|
-
end
|
53
|
-
private :get_event_type_class_map
|
14
|
+
class AsyncProcCallEvent < Event; end
|
54
15
|
|
55
|
-
|
56
|
-
# for as long as they are registered
|
16
|
+
class EvtHandler
|
57
17
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
-
|
76
|
-
|
77
|
-
|
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
|
-
|
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
|
-
|
83
|
-
|
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
|
-
|
93
|
-
end
|
94
|
-
end
|
88
|
+
private :event_filters
|
95
89
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
140
|
+
end
|
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 |
|
193
198
|
end
|
194
|
-
|
195
|
-
|
196
|
-
|
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
|
-
|
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
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
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
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
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
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
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
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
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
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
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
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
301
|
+
# Convenience evt handler to listen to all scrollwin events.
|
302
|
+
def evt_scrollwin(meth = nil, &block)
|
303
|
+
evt_scrollwin_top(meth, &block)
|
304
|
+
evt_scrollwin_bottom(meth, &block)
|
305
|
+
evt_scrollwin_lineup(meth, &block)
|
306
|
+
evt_scrollwin_linedown(meth, &block)
|
307
|
+
evt_scrollwin_pageup(meth, &block)
|
308
|
+
evt_scrollwin_pagedown(meth, &block)
|
309
|
+
evt_scrollwin_thumbtrack(meth, &block)
|
310
|
+
evt_scrollwin_thumbrelease(meth, &block)
|
311
|
+
end
|
285
312
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
313
|
+
# Convenience evt handler to listen to all scroll events (Wx::Slider and Wx::ScrollBar)
|
314
|
+
def evt_scroll(meth = nil, &block)
|
315
|
+
evt_scroll_top(meth, &block)
|
316
|
+
evt_scroll_bottom(meth, &block)
|
317
|
+
evt_scroll_lineup(meth, &block)
|
318
|
+
evt_scroll_linedown(meth, &block)
|
319
|
+
evt_scroll_pageup(meth, &block)
|
320
|
+
evt_scroll_pagedown(meth, &block)
|
321
|
+
evt_scroll_thumbtrack(meth, &block)
|
322
|
+
evt_scroll_thumbrelease(meth, &block)
|
323
|
+
evt_scroll_changed(meth, &block)
|
324
|
+
end
|
298
325
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
326
|
+
# Convenience evt handler to listen to all scroll command events.
|
327
|
+
def evt_command_scroll(id, meth = nil, &block)
|
328
|
+
evt_command_scroll_top(id, meth, &block)
|
329
|
+
evt_command_scroll_bottom(id, meth, &block)
|
330
|
+
evt_command_scroll_lineup(id, meth, &block)
|
331
|
+
evt_command_scroll_linedown(id, meth, &block)
|
332
|
+
evt_command_scroll_pageup(id, meth, &block)
|
333
|
+
evt_command_scroll_pagedown(id, meth, &block)
|
334
|
+
evt_command_scroll_thumbtrack(id, meth, &block)
|
335
|
+
evt_command_scroll_thumbrelease(id, meth, &block)
|
336
|
+
evt_command_scroll_changed(id, meth, &block)
|
337
|
+
end
|
311
338
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
339
|
+
# add missing constants (these are redefinitions of other constants which are not documented themselves)
|
340
|
+
%i[EVT_COMMAND_SCROLL_TOP
|
341
|
+
EVT_COMMAND_SCROLL_BOTTOM
|
342
|
+
EVT_COMMAND_SCROLL_LINEUP
|
343
|
+
EVT_COMMAND_SCROLL_LINEDOWN
|
344
|
+
EVT_COMMAND_SCROLL_PAGEUP
|
345
|
+
EVT_COMMAND_SCROLL_PAGEDOWN
|
346
|
+
EVT_COMMAND_SCROLL_THUMBTRACK
|
347
|
+
EVT_COMMAND_SCROLL_THUMBRELEASE
|
348
|
+
EVT_COMMAND_SCROLL_CHANGED].each do |const|
|
349
|
+
unless Wx.const_defined?(const)
|
350
|
+
Wx.const_set(const, Wx.const_get(const.to_s.sub('EVT_COMMAND_', 'EVT_').to_sym))
|
351
|
+
end
|
324
352
|
end
|
325
|
-
end
|
326
353
|
|
327
|
-
|
354
|
+
if Wx.const_defined?(:EVT_DESTROY)
|
328
355
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
356
|
+
# evt_window_destroy is a special case in that evt.skip
|
357
|
+
# should always be called when handling the event
|
358
|
+
# as otherwise the OnWindowDestroy handler of Wx::App will not
|
359
|
+
# be called to deregister the windows on destruction which
|
360
|
+
# may lead to segfaults during the GC marking phase.
|
361
|
+
# Thus we register the event here explicitly as well as the
|
362
|
+
# event hook method.
|
336
363
|
|
337
|
-
|
338
|
-
|
364
|
+
EVENT_TYPE_CLASS_MAP[Wx::EVT_DESTROY] = Wx::WindowDestroyEvent
|
365
|
+
EVENT_NAME_TYPE_MAP['evt_window_destroy'.intern] = Wx::EVT_DESTROY
|
339
366
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
367
|
+
def evt_window_destroy(meth = nil, &block)
|
368
|
+
handler = acquire_handler(meth, block)
|
369
|
+
connect(Wx::ID_ANY, Wx::ID_ANY, Wx::EVT_DESTROY, Proc.new { |evt| handler.call(evt); evt.skip })
|
370
|
+
end
|
344
371
|
|
372
|
+
end
|
345
373
|
end
|
346
374
|
end
|
347
375
|
|