nobody at rubyforge.org
2007-Jun-23 12:42 UTC
[Wxruby-development] [1060] trunk/wxruby2/swig/fixevents.rb: Include some previously missing events, rehash and simplify
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!-- #msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; } #msg dt { float: left; width: 6em; font-weight: bold; } #msg dt:after { content:'':'';} #msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; } #msg dl a { font-weight: bold} #msg dl a:link { color:#fc3; } #msg dl a:active { color:#ff0; } #msg dl a:visited { color:#cc6; } h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; } #msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; } #msg ul, pre { overflow: auto; } #header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; } #patch { width: 100%; } #patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;} #patch .propset h4, #patch .binary h4 {margin:0;} #patch pre {padding:0;line-height:1.2em;margin:0;} #patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;} #patch .propset .diff, #patch .binary .diff {padding:10px 0;} #patch span {display:block;padding:0 10px;} #patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;} #patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;} #patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;} #patch .lines, .info {color:#888;background:#fff;} --></style> <title>[1060] trunk/wxruby2/swig/fixevents.rb: Include some previously missing events, rehash and simplify</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1060</dd> <dt>Author</dt> <dd>brokentoy</dd> <dt>Date</dt> <dd>2007-06-23 08:42:20 -0400 (Sat, 23 Jun 2007)</dd> </dl> <h3>Log Message</h3> <pre>Include some previously missing events, rehash and simplify</pre> <h3>Modified Paths</h3> <ul> <li><a href="#trunkwxruby2swigfixeventsrb">trunk/wxruby2/swig/fixevents.rb</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="trunkwxruby2swigfixeventsrb"></a> <div class="modfile"><h4>Modified: trunk/wxruby2/swig/fixevents.rb (1059 => 1060)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/swig/fixevents.rb        2007-06-22 19:39:31 UTC (rev 1059) +++ trunk/wxruby2/swig/fixevents.rb        2007-06-23 12:42:20 UTC (rev 1060) </span><span class="lines">@@ -7,38 +7,43 @@ </span><span class="cx"> # definitions for every event type, and adds the relevant methods to the </span><span class="cx"> # EvtHandler class. </span><span class="cx"> </span><ins>+# Load the $events global array of type definitions </ins><span class="cx"> require ''swig/classes/include/events'' </span><span class="cx"> </span><del>-$exclude = [ -        ''EVT_COMMAND'', -        ''EVT_TAB'', -] </del><ins>+# Little class to make accessing Event Type info a bit easier below +class WxEventType < Struct.new(:name, :type, :wx_const) + # Events in Wx but not exposed in WxRuby (b/c they cause problems) + EXCLUDED = [ /^EVT_TAB/, ''EVT_COMMAND'' ] + # These event types only work on Windows + WINDOWS_ONLY = [ /^EVT_DIALUP/ ] </ins><span class="cx"> </span><del>-$windows_only = [ -        ''EVT_DIALUP'' -] </del><ins>+ def initialize(*args) + super + @excluded = true if EXCLUDED.any? { | x | x === name } + @win_only = true if WINDOWS_ONLY.any? { | x | x === name } + end </ins><span class="cx"> </span><del>-File.open(ARGV[0], "a") do | out | </del><ins>+ def excluded? + @excluded + end </ins><span class="cx"> </span><ins>+ def windows_only? + @win_only + end +end </ins><span class="cx"> </span><del>-        $events.each do |evt| -                exclude = false -                windows = false -                $windows_only.each do |name| -                        if (evt[0].index(name) != nil) -                                windows = true -                        end -                end -                $exclude.each do |name| -                        if (evt[0].index(name) != nil) -                                exclude = true -                        end -                end -                next if exclude         - if(evt[0]=="EVT_MOUSE_EVENTS") -                out.puts "#ifdef __WXMSW__" if windows -                 -                out.puts <<FUNC_DEF </del><ins>+# Convert the raw arrays into informative event type objects +$events.map! { | x | WxEventType[ *x ] } + +# Append this stuff to the default SWIG Events.i file +File.open(ARGV[0], "a") do | out | + # First we loop over the events creating short C++ functions to hook + # up events for each + $events.each do | evt | + next if evt.excluded? + + if evt.name =="EVT_MOUSE_EVENTS" + out.puts <<FUNC_DEF </ins><span class="cx"> static VALUE evt_mouse_events(int argc, VALUE *argv, VALUE self) </span><span class="cx"> { </span><span class="cx"> evt_left_down(argc,argv,self); </span><span class="lines">@@ -56,66 +61,40 @@ </span><span class="cx"> return evt_mousewheel(argc,argv,self); </span><span class="cx"> } </span><span class="cx"> FUNC_DEF </span><ins>+ next + end </ins><span class="cx"> </span><del>-                out.puts "#endif //__WXMSW__" if windows - next - end -                func = "" -                case evt[1] -                when 1 -                        func = "internal_evt_no_parameters" -                when 2 -                        func = "internal_evt_with_id" -                when 3 -                        func = "internal_evt_with_id_range" -                end </del><ins>+ func = case evt.type + when 1 : "internal_evt_no_parameters" + when 2 : "internal_evt_with_id" + when 3 : "internal_evt_with_id_range" + end </ins><span class="cx"> </span><del>-                out.puts "#ifdef __WXMSW__" if windows -                 -                out.puts <<FUNC_DEF -static VALUE #{evt[0].downcase}(int argc, VALUE *argv, VALUE self) -{ -        return #{func}(argc,argv,self,#{evt[2]}); -} </del><ins>+ out.puts "#ifdef __WXMSW__" if evt.windows_only? + out.puts <<FUNC_DEF +static VALUE #{evt.name.downcase}(int argc, VALUE *argv, VALUE self) + { return #{func}(argc, argv, self, #{evt.wx_const}); } </ins><span class="cx"> </span><span class="cx"> FUNC_DEF </span><ins>+ out.puts "#endif //__WXMSW__" if evt.windows_only? + end </ins><span class="cx"> </span><del>-                out.puts "#endif //__WXMSW__" if windows - -        end - -        out.puts <<INIT_FUNC </del><ins>+ # Then we loop over the events and register the ruby method for each + out.puts <<INIT_FUNC </ins><span class="cx"> extern "C" { </span><span class="cx"> void Init_wxEvents2() </span><span class="cx"> { </span><span class="cx"> INIT_FUNC </span><del>-        $events.each do |evt| -                windows = false -                exclude = false -                $windows_only.each do |name| -                        if (evt[0].index(name) != nil) -                                windows = true -                        end -                end -                $exclude.each do |name| -                        if (evt[0].index(name) != nil) -                                exclude = true -                        end -                end -                next if exclude         </del><ins>+ $events.each do | evt | + next if evt.excluded? </ins><span class="cx"> </span><del>- -                out.puts "#ifdef __WXMSW__" if windows - -                out.puts <<REGISTER_FUNC -        rb_define_method(cWxEvtHandler.klass, \"#{evt[0].downcase}\", VALUEFUNC(#{evt[0].downcase}),-1); </del><ins>+ out.puts "#ifdef __WXMSW__" if evt.windows_only? + out.puts <<REGISTER_FUNC +        rb_define_method(cWxEvtHandler.klass, \"#{evt.name.downcase}\", VALUEFUNC(#{evt.name.downcase}),-1); </ins><span class="cx"> REGISTER_FUNC </span><ins>+ out.puts "#endif //__WXMSW__" if evt.windows_only? + end </ins><span class="cx"> </span><del>-                out.puts "#endif //__WXMSW__" if windows - -        end - -        out.puts "}" -        out.puts "}" - </del><ins>+ out.puts "}" + out.puts "}" </ins><span class="cx"> end </span></span></pre> </div> </div> </body> </html>
Seemingly Similar Threads
- [1067] trunk/wxruby2: Set up event handlers in Ruby rather than by post-processing SWIG output
- [886] branches/wxruby2/wxwidgets_282/swig/fixevents.rb: Mouse events fix for Win32 (Artur Kuptel)
- [742] trunk/wxruby2/swig/fixevents.rb: Un-disable evt_togglebutton on Linux and Mac; don''t seem to be any probs
- [ wxruby-Patches-9297 ] Patch to compile wxruby 0.0.39 on windows (vc2003, swig 1.3.31, wxwidgets 2.8.0)
- [1086] trunk/wxruby2/lib/wx/classes/evthandler.rb: Restore evt_mouse_events convenience handler, fixing bug in printing sample