wxruby 1.9.1-i386-mswin32 → 1.9.2-i386-mswin32

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,53 @@
1
+ wxRuby2
2
+ Copyright (c) 2004-2007 wxRuby Development Team
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+
22
+
23
+
24
+
25
+
26
+
27
+ ============================================================================
28
+ THE FOLLOWING IS NOT PART OF THE LICENSE, NOR IS IT LEGAL ADVICE!
29
+
30
+ wxRuby and wxWidgets
31
+ --------------------
32
+ Normally, wxRuby is distributed with a binary copy of wxWidgets. If you
33
+ distribute the wxRuby gem, you are bound to the requirements of the
34
+ copy of wxWidgets within. Fortunately, those requirements do not impose
35
+ any serious restrictions.
36
+
37
+
38
+ wxWidgets License Summary (from the wxWidgets README)
39
+ -----------------------------------------------------
40
+ In summary, the licence is LGPL plus a clause allowing unrestricted
41
+ distribution of application binaries. To answer a FAQ, you don't have to
42
+ distribute any source if you wish to write commercial applications using
43
+ wxWidgets.
44
+
45
+
46
+ Required Credits and Attribution
47
+ --------------------------------
48
+
49
+ Generally, neither wxWidgets nor wxRuby require attribution, beyond
50
+ retaining existing copyright notices. However, if you build your own
51
+ custom wxWidgets library, there may be portions that require specific
52
+ attributions or credits, such as TIFF or JPEG support. See the wxWidgets
53
+ README and license files for details.
data/README ADDED
@@ -0,0 +1,299 @@
1
+ README for wxruby2
2
+
3
+ Version 1.9.x
4
+
5
+ This is wxruby2, the second generation of wxRuby, a library
6
+ that allows Ruby programs to use the wxWidgets GUI toolkit.
7
+ It is released under a permissive MIT-style license
8
+ (see the LICENSE file for details).
9
+
10
+ This version is a beta release, in preparation for a stable release of
11
+ wxruby version 2.0.
12
+
13
+ ------------------------FAQ---------------------------
14
+
15
+ - What platforms and operating systems are supported in wxRuby2?
16
+
17
+ Currently the following are fully supported:
18
+
19
+ Windows NT/2000/XP/Vista (i686)
20
+ OS X 10.3+ (i686 and PowerPc)
21
+ Linux (i686 + AMD-64)
22
+
23
+ It is unlikely that support for old Windows OS's (3.1, 95, 98, ME)
24
+ will be added to wxRuby2 in the near future, as these operating
25
+ systems have very limited support for Unicode.
26
+
27
+ - Why would I choose wxruby over FXRuby, Ruby/GTK, or one of the other
28
+ GUI toolkits? Isn't wxruby arriving "too late"?
29
+
30
+ There are several great GUI toolkits available for Ruby, but we
31
+ like wxruby better because it has a combination of features that no
32
+ other toolkit has:
33
+
34
+ - Cross-platform (MSWindows, Mac OS X, Linux)
35
+ - Native widgets when possible
36
+ - Provides a wide selection of widgets
37
+ - Simple license that is compatible with proprietary and Free Software
38
+ - Mature foundation (wxWidgets has been around for over 10 years)
39
+
40
+ The really big feature is native widgets. The only other cross-platform
41
+ toolkits that use native widgets are either limited (Tk) or expensive if
42
+ you want to develop proprietary software (Qt). We are not saying that
43
+ those toolkits are bad! Just that wxruby offers a unique set of
44
+ features.
45
+
46
+ - Why are native widgets important or helpful?
47
+
48
+ For one thing, it means that end-users do not have to adjust to a
49
+ "foreign" interface. It also ensures maximum compatibility with
50
+ "assistive technology" such as screen readers for blind users.
51
+ It also allows apps to respect any themes the user may have chosen
52
+ through their operating system. No matter how hard a toolkit may try
53
+ to emulate a particular UI, there will always be differences in the
54
+ look or behavior.
55
+
56
+ - How does wxruby2 relate to wxruby (and the wxruby 0.6.0 release)?
57
+
58
+ wxruby2 is the "next generation" of wxruby. It is being developed
59
+ by the same wxruby team, and is intended to replace the older
60
+ code base. wxruby2 is built using SWIG, a powerful tool that makes
61
+ it much easier to create and maintain wrappers around C/C++ libraries.
62
+
63
+ - Why should I use wxruby2 instead of wxruby?
64
+
65
+ First, because development on the original wxruby codebase has stopped.
66
+ Everyone is working on wxruby2, so it will continue to improve. Beyond
67
+ that, wxruby2 has these advantages over wxruby 0.6.0:
68
+
69
+ - Available as binary gems for MSWindows, OS X, and Linux (GTK)
70
+ - Support for more classes, and more methods within classes
71
+ - Unicode support
72
+ - Vastly improved support for OS X
73
+ - Looks much better under Linux because it uses GTK+2
74
+ - Simpler and more permissive license
75
+ - Wraps wxWidgets 2.8.3 instead of the older 2.4 series
76
+
77
+ - Is wxruby2 ready for "production" use?
78
+
79
+ Yes, pretty much. This is a beta release, and there may be some bugs
80
+ in some methods, or memory leaks. This release includes all the
81
+ classes and features that are proposed for inclusion in wxruby 2.0.
82
+
83
+ It is considerably more stable and fully-featured than the old 0.6.0
84
+ release, which was never really stable enough for heavy-duty
85
+ production use.
86
+
87
+ - Does wxruby2 support the Xxx class?
88
+
89
+ See the "Documentation" section of the README file, or check the
90
+ wxruby web site: http://wxruby.org
91
+
92
+ - How are the wxruby 0.6.0 and wxruby2 licenses different?
93
+
94
+ wxruby 0.6.0 was released under the wxWindows license, which is a
95
+ modified LGPL. It is a good, fair license, allowing use in both Free
96
+ Software and proprietary applications. However, it is long and complex,
97
+ and is more appropriate for compiled code. wxruby2 is available under a
98
+ *very* simple MIT-style license, which allows just about any use with
99
+ very few restrictions.
100
+
101
+ - I am getting an error trying to compile wxruby2
102
+
103
+ Please double-check the requirements. You may be using the wrong
104
+ version of SWIG, wxWidgets, or some other tool. Double-check the
105
+ instructions on the wxRuby wiki (http://wxruby.rubyforge.org/)
106
+
107
+ If you need help, please ask your question on the wxruby mailing list
108
+ (see the link at http://wxruby.org).
109
+
110
+ - I am getting an error trying to run any wxruby2 application, such as
111
+ the samples that are included in the gem.
112
+
113
+ If you are using Linux, be sure you have configured your system to
114
+ have RUBYOPT=-rubygems. This can be done in .bashrc or /etc/environment,
115
+ depending on your distribution and preferences. [More details to follow].
116
+
117
+ - Why aren't the wx network, file, date, database and other non-GUI
118
+ classes supported?
119
+
120
+ Because Ruby has its own versions of each of them, providing
121
+ cross-platform abstractions of these functions with familiar syntax
122
+ and methods. We assume you are writing your application in Ruby, so it
123
+ makes sense to keep as much code as possible in Ruby. We have only
124
+ wrapped the wx classes that are necessary to write GUI code.
125
+
126
+ There may be some advantages to porting the Wx network classes into
127
+ ruby, if they work better with multi-(native)-threaded code. This is
128
+ currently under evaluation.
129
+
130
+ - Why has it taken so long for wxruby2 to be released?
131
+
132
+ Nobody is getting paid to develop wxruby, so each of the wxruby developers
133
+ are limited in the amount of time they can dedicate to the project. We are
134
+ always looking for more volunteers to help code, test, document, manage
135
+ the bug list, handle publicity, or do other necessary chores.
136
+
137
+ Wrapping wx is a big project that requires a wide variety of skills. As of
138
+ August 2006, the wxRuby project has about 30,000 lines of code, including
139
+ ruby, C++, and SWIG scripts. If we weren't using SWIG it would be far bigger.
140
+
141
+
142
+ For more details, see the project home page:
143
+ http://wxruby.org/
144
+
145
+
146
+ ------------------------USING WXRUBY---------------------------
147
+ INSTALLING:
148
+
149
+ wxRuby is available as binary gems for MS Windows, Mac OS X, and Linux
150
+ with GTK+ 2. Unless you wish to work on wxRuby itself, we strongly
151
+ recommend installing the gem rather than building from source.
152
+
153
+ REQUIREMENTS TO CREATE AND RUN WXRUBY APPS:
154
+
155
+ - Ruby 1.8
156
+ - MS Windows NT/2000/XP/Vista, Mac OS X 10.3+, or Linux with GTK+ 2,
157
+
158
+ SAMPLES:
159
+
160
+ There is a samples/ directory containing many small sample wxRuby apps
161
+ that demonstrate how to use various classes. A few samples do not work
162
+ across all platforms at this time.
163
+
164
+ The bigdemo sample is fairly comprehensive, but not all of the
165
+ sections work on all platforms.
166
+
167
+
168
+ WRITING YOUR OWN WXRUBY APP:
169
+
170
+ To use wxruby-swig in your app, use:
171
+ require 'wx'
172
+
173
+ samples/minimal.rb can be used as a template for creating your
174
+ own wxruby application.
175
+
176
+
177
+ DOCUMENTATION:
178
+
179
+ - wxRuby-specific API documentation can be found here:
180
+
181
+ http://wxruby.org/doc/
182
+
183
+ (Note: This documentation is auto-generated from the C++ wxWidgets API
184
+ docs. There are some broken links, some sample code in C++, and some
185
+ sections which do not apply to ruby. The documentation is continually
186
+ being improved.)
187
+
188
+ - The latest version of the documentation can be downloaded from the
189
+ wxRuby 'Files' section on Rubyforge.
190
+
191
+ http://www.rubyforge.org/frs/?group_id=35
192
+
193
+ - Tables summarizing which wx classes are and are not supported can
194
+ be found here:
195
+
196
+ http://wxruby.org/wiki/wiki.pl?ClassesSupportedByCategory
197
+
198
+ - Most wxWidgets and wxPython tutorials and references can also be used, if
199
+ you remember that wxRuby uses ruby_style_naming for methods and variables
200
+ instead of MixedCase as used by wxWidgets.
201
+
202
+
203
+
204
+ API DIFFERENCES FROM WXWIDGETS:
205
+ - In many cases, wxRuby follows the lead of wxPython (or in some cases,
206
+ wxPerl), adjusting certain method calls when the C++ style doesn't fit
207
+ dynamic languages.
208
+ - Since initialize is reserved in ruby, use SplitterWindow#init instead.
209
+ - Many wx classes have not been wrapped because native ruby classes work
210
+ as well or better. These include wxDateTime, wxString, networking
211
+ classes, database classes.
212
+ - log_message and log_status take a single string parameter,
213
+ rather than a format string followed by additional values
214
+ to be inserted. Use Ruby's sprintf if required.
215
+ - ScreenDC extends DC on all platforms, unlike in C++ wx.
216
+ This means that you cannot override any virtual methods that were
217
+ defined in PaintDC or WindowDC in a ruby subclass of ScreenDC.
218
+ [Need to verify if this is still true]
219
+ - BusyCursor can be used in a Ruby block to ensure the original cursor
220
+ is always restored.
221
+
222
+ ----------------------COMPILING WXRUBY--------------------------
223
+ REQUIREMENTS TO COMPILE/BUILD WXRUBY ITSELF
224
+
225
+ - rake
226
+ - SWIG, version 1.3.31. SWIG 1.3.29 or later may work; earlier version
227
+ definitely won't
228
+ - wxWidgets 2.8.x SDK. See further information on the wxruby website for
229
+ recommended compile-time options for wxWidgets.
230
+
231
+
232
+ OBTAINING THE SOURCE:
233
+
234
+ Source code is hosted in Subversion at rubyforge.org. See the links on
235
+ the wxruby web site (http://wxruby.org). Check out the wxruby2
236
+ Subversion module (not the old wxruby module).
237
+
238
+
239
+ BUILDING:
240
+
241
+ From the top-level directory (typically wxruby2/),
242
+ just start the rake build with the command:
243
+
244
+ rake
245
+
246
+ There is no ./configure step, nor do you need to run ruby extconf.rb.
247
+
248
+
249
+ INSTALLING THE LIBRARY:
250
+
251
+ You can install the library using:
252
+ rake install
253
+
254
+ Note that on some systems you may need to be "root" to do this.
255
+ To manually install, copy all the files in the lib/ subdirectory
256
+ to somewhere on your ruby library path, such as a ruby extensions
257
+ directory.
258
+
259
+
260
+ PORTING TO OTHER PLATFORMS
261
+
262
+ Platform-dependent rakefiles are used to set up compiler-specific
263
+ settings. The following platforms are currently fully supported:
264
+
265
+ Mac OSX (gcc): rakemacosx.rb
266
+ MS Windows (VC++): rakemswin.rb
267
+ Linux (GTK2 + gcc): rakelinux.rb
268
+
269
+ For other platforms, you may need to edit the appropriate
270
+ platform-dependent rake file if your system is not yet supported, or if
271
+ it is unusual. These files are found in the rake subdirectory:
272
+
273
+ MS Windows BC++: rakebccwin.rb
274
+ MS Windows MingGW: rakemingw.rb
275
+ MS Windows Cygwin: rakecygwin.rb
276
+ NetBSD: rakenetbsd.rb
277
+
278
+ When editing a platform-dependent rakefile, you might
279
+ merely need to set one or more of the following variables:
280
+
281
+ $extra_cppflags
282
+ $extra_ldflags
283
+ $extra_objs
284
+ $extra_libs
285
+
286
+
287
+ CREDITS
288
+
289
+ Kevin Smith set up the wxruby2 project using SWIG and did much of the
290
+ work that still forms the core of the library in its present form. Over
291
+ the years dozens of volunteers have contributed invaluable patches and
292
+ new functionality. The list is too long to give here, but their
293
+ contributions are recorded in the wxruby mailing list archives.
294
+
295
+ -----------------------------------------------------------
296
+
297
+ LEAD MAINTAINER:
298
+ Alex Fenton
299
+ alex at pressure dot to
@@ -1,13 +1,27 @@
1
1
  # Copyright 2004-2006 by Kevin Smith
2
2
  # released under the MIT-style wxruby2 license
3
3
 
4
+ # Controller class which creates and manages all windows.
4
5
  class Wx::App
6
+ # Convenience class method to create simple apps. Starts an
7
+ # application main_loop, setting up initial windows etc as specified
8
+ # in the passed block.
9
+ # block
10
+ def self.run(&block)
11
+ app_klass = Class.new(self)
12
+ app_klass.class_eval do
13
+ define_method(:on_init, &block)
14
+ end
15
+ the_app = app_klass.new
16
+ the_app.main_loop
17
+ end
18
+
5
19
  # This method handles failed assertions from within the WxWidgets C++
6
20
  # code. These messages are only generated by a DEBUG build of
7
21
  # WxRuby. Such messages usually indicate that the API is being used
8
22
  # incorrectly; the file/line reference points to the place in the
9
23
  # WxWidgets source code where the assertion was made.
10
- def on_assert_failure(file, line, condition, message)
24
+ define_method(:on_assert_failure) do | file, line, condition, message |
11
25
  warn "Wx WARNING: #{message} (#{file}:#{line})"
12
26
  end
13
27
 
@@ -15,9 +15,9 @@ class Wx::Bitmap
15
15
  # Accepts a block, which will be passed a device context which can be
16
16
  # used to draw upon the Bitmap
17
17
  def draw
18
- dc = MemoryDC.new
18
+ dc = Wx::MemoryDC.new
19
19
  dc.select_object(self)
20
20
  yield dc
21
- dc.select_object( NULL_BITMAP )
21
+ dc.select_object( Wx::NULL_BITMAP )
22
22
  end
23
23
  end
@@ -0,0 +1,30 @@
1
+ # Display a listbox with a checkbox for each item
2
+ class Wx::CheckListBox < Wx::ListBox
3
+
4
+ # According to the wxWidgets documentation: "wxCheckListBox uses
5
+ # client data in its implementation, and therefore this is not
6
+ # available to the application."
7
+ #
8
+ # So, rather than crashing, raise an Exception if this is attempted
9
+ def append(*args)
10
+ if args.length == 2
11
+ Kernel.raise "Cannot use item data with Wx::CheckListBox"
12
+ else
13
+ super
14
+ end
15
+ end
16
+
17
+ # As above
18
+ def insert(*args)
19
+ if args.length == 3
20
+ Kernel.raise "Cannot use item data with Wx::CheckListBox"
21
+ else
22
+ super
23
+ end
24
+ end
25
+
26
+ # As above
27
+ def set_item_data(index, data)
28
+ Kernel.raise "Cannot use item data with Wx::CheckListBox"
29
+ end
30
+ end
@@ -5,7 +5,7 @@ class Wx::ClientDC
5
5
  # always be used via Window#paint, which takes a block receiving the
6
6
  # DC. This ensures that the DC is cleaned up at the correct time,
7
7
  # avoiding errors and segfaults on exit.
8
- def initialize(*args)
8
+ define_method(:initialize) do | *args |
9
9
  Kernel.raise RuntimeError,
10
10
  "Do not instantiate ClientDC directly; use Window#paint",
11
11
  caller[1..-1]
@@ -0,0 +1,7 @@
1
+ # Class representing interactions with controls such as ListBox
2
+ class Wx::CommandEvent
3
+ # get_int and get_selection are already synonyms, but neither name
4
+ # accurately describes what the method does as the event may be a
5
+ # (de)selection or a check in a CheckListBox
6
+ alias :get_index :get_int
7
+ end
@@ -0,0 +1,10 @@
1
+ # Superclass of a variety of controls that display lists of items (eg
2
+ # Choice, ListBox, CheckListBox)
3
+ class Wx::ControlWithItems
4
+ # Make these ruby enumerables so find, find_all, map etc are available
5
+ include Enumerable
6
+ # Passes each valid item index into the passed block
7
+ def each
8
+ 0.upto(count - 1) { | i | yield i }
9
+ end
10
+ end
@@ -42,6 +42,7 @@ class Wx::EvtHandler
42
42
 
43
43
  # Given the Integer constant Wx::EVT_XXX, returns the convenience
44
44
  # handler method name associated with that type of event.
45
+
45
46
  def self.event_name_for_type(name)
46
47
  EVENT_NAME_TYPE_MAP.index(name)
47
48
  end
@@ -63,33 +64,85 @@ class Wx::EvtHandler
63
64
  end
64
65
 
65
66
  # Registers the event type +ev_type+, which should be an instance of
66
- # the Struct class +Wx::EvtHandler::EventType+.
67
+ # the Struct class +Wx::EvtHandler::EventType+. This sets up the
68
+ # mapping of events of that type (identified by integer id) to the
69
+ # appropriate ruby event class, and defines a convenience evt_xxx
70
+ # instance method in the class EvtHandler.
67
71
  def self.register_event_type(ev_type)
72
+ # set up the event type mapping
68
73
  EVENT_TYPE_CLASS_MAP[ev_type.const] = ev_type.evt_class
69
74
  EVENT_NAME_TYPE_MAP[ev_type.name.intern] = ev_type.const
70
75
 
71
76
  unless ev_type.arity and ev_type.name
72
77
  return
73
78
  end
79
+
80
+ # set up the evt_xxx method
74
81
  case ev_type.arity
75
82
  when 0 # events without an id
76
83
  class_eval %Q|
77
- def #{ev_type.name}(&block)
78
- connect(Wx::ID_ANY, Wx::ID_ANY, #{ev_type.const}, &block)
84
+ def #{ev_type.name}(meth = nil, &block)
85
+ handler = acquire_handler(meth, block)
86
+ connect(Wx::ID_ANY, Wx::ID_ANY, #{ev_type.const}, &handler)
79
87
  end |
80
88
  when 1 # events with an id
81
89
  class_eval %Q|
82
- def #{ev_type.name}(id, &block)
83
- connect(id, Wx::ID_ANY, #{ev_type.const}, &block)
90
+ def #{ev_type.name}(id, meth = nil, &block)
91
+ handler = acquire_handler(meth, block)
92
+ id = acquire_id(id)
93
+ connect(id, Wx::ID_ANY, #{ev_type.const}, &handler)
84
94
  end |
85
95
  when 2 # events with id range
86
96
  class_eval %Q|
87
- def #{ev_type.name}(first_id, last_id, &block)
88
- connect(first_id, last_id, #{ev_type.const}, &block)
97
+ def #{ev_type.name}(first_id, last_id, meth = nil, &block)
98
+ handler = acquire_handler(meth, block)
99
+ first_id = acquire_id(first_id)
100
+ last_id = acquire_id(last_id)
101
+ connect( first_id, last_id, #{ev_type.const}, &handler)
89
102
  end |
90
103
  end
91
104
  end
92
105
 
106
+ # Not for external use; determines whether to use a block or call a
107
+ # method in self to handle an event, passed to connect. Makes evt_xxx
108
+ # liberal about what it accepts - aside from a block, it can be a
109
+ # method name (as Symbol or String), a (bound) method object, or a
110
+ # Proc object
111
+ def acquire_handler(meth, block)
112
+ if block and not meth
113
+ return block
114
+ elsif meth and not block
115
+ h_meth = case meth
116
+ when Symbol, String : self.method(meth)
117
+ when Proc : meth
118
+ when Method : meth.to_proc
119
+ end
120
+ if h_meth.arity == 1
121
+ return lambda { | evt | h_meth.call(evt) }
122
+ else
123
+ return lambda { h_meth.call }
124
+ end
125
+ else
126
+ Kernel.raise ArgumentError,
127
+ "Specify event handler with a method, name, proc OR block"
128
+ caller
129
+ end
130
+ end
131
+
132
+ # Not for external use; acquires an id either from an explicit Fixnum
133
+ # parameter or by calling the wx_id method of a passed Window.
134
+ def acquire_id(window_or_id)
135
+ case window_or_id
136
+ when Fixnum : window_or_id
137
+ when Wx::Window, Wx::MenuItem : window_or_id.wx_id
138
+ else Kernel.raise ArgumentError,
139
+ "Must specify Wx::Window event source or its Wx id, " +
140
+ "not '#{window_or_id.inspect}'",
141
+ caller
142
+ end
143
+ end
144
+ private :acquire_id, :acquire_handler
145
+
93
146
  # Definitions for all event types that are part by core wxRuby. Events
94
147
  # that are mapped to class Wx::Event are TODO as they are not
95
148
  # currently wrapped by the correct class. All StyledTextCtrl
@@ -195,6 +248,9 @@ class Wx::EvtHandler
195
248
  EventType['evt_close', 0,
196
249
  Wx::EVT_CLOSE_WINDOW,
197
250
  Wx::CloseEvent],
251
+ EventType['evt_collapsiblepane_changed', 1,
252
+ Wx::EVT_COMMAND_COLLPANE_CHANGED,
253
+ Wx::CollapsiblePaneEvent],
198
254
  EventType['evt_combobox', 1,
199
255
  Wx::EVT_COMMAND_COMBOBOX_SELECTED,
200
256
  Wx::CommandEvent],
@@ -0,0 +1,9 @@
1
+ # Multi-item control with numerous possible view styles
2
+ class Wx::ListCtrl
3
+ # Make these ruby enumerables so find, find_all, map are available
4
+ include Enumerable
5
+ # Passes each valid item index into the passed block
6
+ def each
7
+ 0.upto(item_count - 1) { | i | yield i }
8
+ end
9
+ end
@@ -0,0 +1,62 @@
1
+ # A single labelled list within a drop-down menu, or a popup menu
2
+ class Wx::Menu
3
+
4
+ # In the standard WxWidgets API, the methods append, prepend, insert
5
+ # (and their variants) require a constant integer id as the identifier
6
+ # of the menu item. This is then used in event handling.
7
+ #
8
+ # In WxRuby the use of explicit ids can be avoided in most cases,
9
+ # being a most unruby-ish practice. So, by analogy with the general
10
+ # use of Wx::Window classes and event handlers, where the id is
11
+ # implicit in the constructor, and the window can be passed direct to
12
+ # the event handler setup method, the below sets up a similar facility
13
+ # for adding items to Wx::Menu.
14
+ #
15
+ # For all these methods, the only required argument is the string name
16
+ # of the menu item; a system-default id will be supplied if no
17
+ # explicit one is given. The return value of these methods in all
18
+ # cases is a Wx::MenuItem object, which can be passed directly as the
19
+ # first argument to an evt_menu handler.
20
+ def self.methods_with_optional_ids(*meth_names)
21
+ class_eval do
22
+ meth_names.each do | meth |
23
+ old_meth = instance_method(meth)
24
+ define_method(meth) do | *args |
25
+ case args.first
26
+ when Fixnum : old_meth.bind(self).call(*args)
27
+ when String : old_meth.bind(self).call(Wx::ID_ANY, *args)
28
+ when Wx::MenuItem : old_meth.bind(self).call(args.first)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ # Create the optional-id methods
36
+ methods_with_optional_ids :append, :prepend,
37
+ :append_check_item, :prepend_check_item,
38
+ :append_radio_item, :prepend_radio_item
39
+
40
+ # This is much the same as above, except for insert and variants,
41
+ # which take an additional first argument, the position at which to
42
+ # insert the new item.
43
+ def self.methods_with_optional_ids_and_pos(*meth_names)
44
+ class_eval do
45
+ meth_names.each do | meth |
46
+ old_meth = instance_method(meth)
47
+ define_method(meth) do | pos, *args |
48
+ case args.first
49
+ when Fixnum : old_meth.bind(self).call(pos, *args)
50
+ when String : old_meth.bind(self).call(pos, Wx::ID_ANY, *args)
51
+ when Wx::MenuItem : old_meth.bind(self).call(pos, args.first)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+
58
+ # Create the optional-id methods
59
+ methods_with_optional_ids_and_pos :insert,
60
+ :insert_check_item,
61
+ :insert_radio_item
62
+ end
@@ -0,0 +1,7 @@
1
+ # An individual item within a frame or popup menu
2
+ class Wx::MenuItem
3
+ # Get the Wx id, not Ruby's deprecated Object#id
4
+ alias :id :get_id
5
+ # In case a more explicit option is preferred.
6
+ alias :wx_id :get_id
7
+ end
@@ -4,7 +4,7 @@ class Wx::PaintDC
4
4
  # always be used via Window#paint, which takes a block receiving the
5
5
  # DC. This ensures that the DC is cleaned up at the correct time,
6
6
  # preventing serious errors on some platforms.
7
- def initialize(*args)
7
+ define_method(:initialize) do | *args |
8
8
  Kernel.raise RuntimeError,
9
9
  "Do not instantiate PaintDC directly; use Window#paint",
10
10
  caller[1..-1]
@@ -34,7 +34,7 @@ class Wx::Timer
34
34
  @@__unowned_timers__ ||= []
35
35
 
36
36
  # remove from list of previous owner
37
- if @__owner__
37
+ if defined?(@__owner__) and @__owner__
38
38
  @__owner__.instance_eval { @__owned_timers__.delete(this_timer) }
39
39
  end
40
40
 
@@ -51,7 +51,7 @@ class Wx::Timer
51
51
 
52
52
  # Then add to list of new owner, setting destructor hook if required
53
53
  new_owner.instance_eval do
54
- if not @__owned_timers__
54
+ if not defined?(@__owned_timers__)
55
55
  @__owned_timers__ = []
56
56
  unless self.kind_of?(Wx::App) # Don't set up hook on App
57
57
  evt_window_destroy do | evt |