nobody at rubyforge.org
2007-Jun-28 00:28 UTC
[Wxruby-development] [1092] trunk/wxruby2/swig/classes/App.i: Pass correctly typed Events into filter_event, if defined (bug 10797);
<!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>[1092] trunk/wxruby2/swig/classes/App.i: Pass correctly typed Events into filter_event, if defined (bug 10797);</title> </head> <body> <div id="msg"> <dl> <dt>Revision</dt> <dd>1092</dd> <dt>Author</dt> <dd>brokentoy</dd> <dt>Date</dt> <dd>2007-06-27 20:28:03 -0400 (Wed, 27 Jun 2007)</dd> </dl> <h3>Log Message</h3> <pre>Pass correctly typed Events into filter_event, if defined (bug 10797); also check return value to avoid segfault (bug 11747)</pre> <h3>Modified Paths</h3> <ul> <li><a href="#trunkwxruby2swigclassesAppi">trunk/wxruby2/swig/classes/App.i</a></li> </ul> </div> <div id="patch"> <h3>Diff</h3> <a id="trunkwxruby2swigclassesAppi"></a> <div class="modfile"><h4>Modified: trunk/wxruby2/swig/classes/App.i (1091 => 1092)</h4> <pre class="diff"><span> <span class="info">--- trunk/wxruby2/swig/classes/App.i        2007-06-28 00:09:11 UTC (rev 1091) +++ trunk/wxruby2/swig/classes/App.i        2007-06-28 00:28:03 UTC (rev 1092) </span><span class="lines">@@ -10,12 +10,16 @@ </span><span class="cx"> %} </span><span class="cx"> </span><span class="cx"> </span><ins>+// Not supported </ins><span class="cx"> %ignore GetAuto3D; </span><span class="cx"> %ignore OnQueryEndSession; </span><span class="cx"> %ignore ProcessMessage; </span><span class="cx"> %ignore SetAuto3D; </span><span class="cx"> </span><ins>+// Redefined below </ins><span class="cx"> %ignore MainLoop; </span><ins>+%ignore FilterEvent; + </ins><span class="cx"> %rename(wx_initialize) Initialize; </span><span class="cx"> </span><span class="cx"> #////////////////////////////////// </span><span class="lines">@@ -36,6 +40,8 @@ </span><span class="cx"> extern swig_class cWxEvent; </span><span class="cx"> extern "C" void Init_wxRubyStockObjects(); </span><span class="cx"> </span><ins>+// Pre-fetched id because it''s called very frequently in wxRubyApp::FilterEvent +static VALUE filter_event_sym = rb_intern("filter_event"); </ins><span class="cx"> </span><span class="cx"> class wxRubyApp : public wxApp </span><span class="cx"> { </span><span class="lines">@@ -189,7 +195,33 @@ </span><span class="cx"> return 0; </span><span class="cx">                  </span><span class="cx"> } </span><del>-         </del><ins>+ + + int FilterEvent(wxEvent& event) { +        VALUE rb_self = SWIG_RubyInstanceFor(this); +        // Just proceed if no ruby filter_event method is defined in App class +        // filter_event_sym defined above +        if ( ! rb_respond_to(rb_self, filter_event_sym) ) +         { return -1; } +        // else wrap the event and pass into that method +        VALUE event_type_id = INT2NUM(event.GetEventType()); +        VALUE event_klass = rb_funcall(cWxEvtHandler.klass, +                                                                 rb_intern("event_class_for_type"), +                                                                 1, event_type_id );          + +        VALUE rb_event = Data_Wrap_Struct(event_klass, 0, 0, 0); +        DATA_PTR(rb_event) = &event; + +        VALUE rb_ret_val = rb_funcall(rb_self, filter_event_sym, 1, rb_event); +        if ( ! FIXNUM_P(rb_ret_val) ) +         { rb_raise(rb_eTypeError, "filter_event must return an integer"); } +        int ret_val = FIX2INT(rb_ret_val); +        if ( ret_val < -1 || ret_val > 1 ) +         { rb_raise(rb_eRuntimeError, "filter_event must return -1, 0, or 1"); } + +        return ret_val; + } + </ins><span class="cx"> // actually implemented in ruby in classes/app.rb </span><span class="cx">         virtual void OnAssertFailure(const wxChar *file, int line, const wxChar *cond, const wxChar *msg) </span><span class="cx">         { </span><span class="lines">@@ -197,7 +229,6 @@ </span><span class="cx">         } </span><span class="cx"> </span><span class="cx"> }; </span><del>- </del><span class="cx"> %} </span><span class="cx"> </span><span class="cx"> %markfunc wxRubyApp "wxRubyApp::mark_wxRubyApp"; </span></span></pre> </div> </div> </body> </html>
Possibly Parallel Threads
- [ wxruby-Bugs-10797 ] App#filter_event always passes Wx::Event
- [1110] trunk/wxruby2/swig/classes/App.i: Remove director method from App#filter_event to fix meth routing error on Linux
- [1022] trunk/wxruby2/swig/classes/App.i: Memory mgmt: use Wx::App to mark still-alive Windows, set up Wx::THE_APP const
- [1136] trunk/wxruby2/swig/classes/App.i: Note when the Wx::App is exiting and avoid doing GC if in process of
- [744] trunk/wxruby2: get_data support & mem mgmt to all ControlWithItems types, using more