ruby-changes:6698
From: suke <ko1@a...>
Date: Fri, 25 Jul 2008 20:49:44 +0900 (JST)
Subject: [ruby-changes:6698] Ruby:r18214 (trunk): * ext/win32ole/win32ole.c (Init_win32ole): add
suke 2008-07-25 20:49:28 +0900 (Fri, 25 Jul 2008) New Revision: 18214 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18214 Log: * ext/win32ole/win32ole.c (Init_win32ole): add WIN32OLE_EVENT#off_event. * test/win32ole/test_win32ole_event.rb: ditto. * test/win32ole/test_win32ole_event.rb: some refactoring. Modified files: trunk/ChangeLog trunk/ext/win32ole/win32ole.c trunk/test/win32ole/test_win32ole_event.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 18213) +++ ChangeLog (revision 18214) @@ -1,3 +1,12 @@ +Fri Jul 25 20:43:57 2008 Masaki Suketa <masaki.suketa@n...> + + * ext/win32ole/win32ole.c (Init_win32ole): add + WIN32OLE_EVENT#off_event. + + * test/win32ole/test_win32ole_event.rb: ditto. + + * test/win32ole/test_win32ole_event.rb: some refactoring. + Fri Jul 25 19:50:49 2008 Nobuyoshi Nakada <nobu@r...> * regint.c (xmalloc, xrealloc, xfree): not to use ruby managed memory. Index: ext/win32ole/win32ole.c =================================================================== --- ext/win32ole/win32ole.c (revision 18213) +++ ext/win32ole/win32ole.c (revision 18214) @@ -118,7 +118,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "1.2.7" +#define WIN32OLE_VERSION "1.2.8" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -499,6 +499,7 @@ static VALUE foleparam_inspect(VALUE self); static long ole_search_event_at(VALUE ary, VALUE ev); static VALUE ole_search_event(VALUE ary, VALUE ev, BOOL *is_default); +static void ole_delete_event(VALUE ary, VALUE ev); static void hash2ptr_dispparams(VALUE hash, ITypeInfo *pTypeInfo, DISPID dispid, DISPPARAMS *pdispparams); static VALUE hash2result(VALUE hash); static void ary2ptr_dispparams(VALUE ary, DISPPARAMS *pdispparams); @@ -517,6 +518,7 @@ static VALUE ev_on_event(int argc, VALUE *argv, VALUE self, VALUE is_ary_arg); static VALUE fev_on_event(int argc, VALUE *argv, VALUE self); static VALUE fev_on_event_with_outargs(int argc, VALUE *argv, VALUE self); +static VALUE fev_off_event(int argc, VALUE *argv, VALUE self); static VALUE fev_unadvise(VALUE self); static VALUE evs_push(VALUE ev); static VALUE evs_delete(long i); @@ -7433,6 +7435,16 @@ return def_event; } +static void +ole_delete_event(VALUE ary, VALUE ev) +{ + long at = -1; + at = ole_search_event_at(ary, ev); + if (at >= 0) { + rb_ary_delete_at(ary, at); + } +} + static void hash2ptr_dispparams(VALUE hash, ITypeInfo *pTypeInfo, DISPID dispid, DISPPARAMS *pdispparams) { @@ -8167,6 +8179,40 @@ /* * call-seq: + * WIN32OLE_EVENT#off_event([event]) + * + * removes the callback of event. + * + * ie = WIN32OLE.new('InternetExplorer.Application') + * ev = WIN32OLE_EVENT.new(ie) + * ev.on_event('BeforeNavigate2') {|*args| + * args.last[6] = true + * } + * ... + * ev.off_event('BeforeNavigate2') + * ... + */ +static VALUE +fev_off_event(int argc, VALUE *argv, VALUE self) +{ + VALUE event = Qnil; + VALUE events; + + rb_secure(4); + rb_scan_args(argc, argv, "01", &event); + if(!NIL_P(event)) { + Check_SafeStr(event); + } + events = rb_ivar_get(self, id_events); + if (NIL_P(events)) { + return Qnil; + } + ole_delete_event(events, event); + return Qnil; +} + +/* + * call-seq: * WIN32OLE_EVENT#unadvise -> nil * * disconnects OLE server. If this method called, then the WIN32OLE_EVENT object @@ -8854,6 +8900,7 @@ rb_define_method(cWIN32OLE_EVENT, "initialize", fev_initialize, -1); rb_define_method(cWIN32OLE_EVENT, "on_event", fev_on_event, -1); rb_define_method(cWIN32OLE_EVENT, "on_event_with_outargs", fev_on_event_with_outargs, -1); + rb_define_method(cWIN32OLE_EVENT, "off_event", fev_off_event, -1); rb_define_method(cWIN32OLE_EVENT, "unadvise", fev_unadvise, 0); cWIN32OLE_VARIANT = rb_define_class("WIN32OLE_VARIANT", rb_cObject); Index: test/win32ole/test_win32ole_event.rb =================================================================== --- test/win32ole/test_win32ole_event.rb (revision 18213) +++ test/win32ole/test_win32ole_event.rb (revision 18214) @@ -17,9 +17,17 @@ dummy_path end + def message_loop + WIN32OLE_EVENT.message_loop + sleep 0.1 + end + def setup + WIN32OLE_EVENT.message_loop @ie = WIN32OLE.new("InternetExplorer.Application") + message_loop @ie.visible = true + message_loop @event = "" @event2 = "" @event3 = "" @@ -43,8 +51,7 @@ while @ie.busy WIN32OLE_EVENT.new(@ie) GC.start - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert_match(/BeforeNavigate/, @event) assert_match(/NavigateComplete/, @event) @@ -57,7 +64,7 @@ while @ie.busy WIN32OLE_EVENT.new(@ie, 'DWebBrowserEvents') GC.start - sleep 0.1 + message_loop end assert_match(/BeforeNavigate/, @event) assert_match(/NavigateComplete/, @event) @@ -69,8 +76,7 @@ ev.on_event('BeforeNavigate') {|*args| handler2} @ie.navigate("file:///#{@f}") while @ie.busy - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert_equal("handler2", @event2) end @@ -81,8 +87,7 @@ ev.on_event {|*args| handler2} @ie.navigate("file:///#{@f}") while @ie.busy - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert_equal("handler2", @event2) end @@ -94,8 +99,7 @@ ev.on_event('NavigateComplete'){|*args| handler3(*args)} @ie.navigate("file:///#{@f}") while @ie.busy - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert(@event3!="") assert("handler2", @event2) @@ -107,8 +111,7 @@ ev.on_event('NavigateComplete'){|*args| handler3(*args)} @ie.navigate("file:///#{@f}") while @ie.busy - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert_match(/BeforeNavigate/, @event) assert(/NavigateComplete/ !~ @event) @@ -120,16 +123,14 @@ ev.on_event {|*args| default_handler(*args)} @ie.navigate("file:///#{@f}") while @ie.busy - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert_match(/BeforeNavigate/, @event) ev.unadvise @event = "" @ie.navigate("file:///#{@f}") while @ie.busy - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end assert_equal("", @event); assert_raise(WIN32OLERuntimeError) { @@ -158,8 +159,7 @@ bl = @ie.locationURL @ie.navigate("file:///#{@f}") while @ie.busy - sleep 0.1 - WIN32OLE_EVENT.message_loop + message_loop end assert_equal(bl, @ie.locationURL) end @@ -172,8 +172,7 @@ bl = @ie.locationURL @ie.navigate("file:///#{@f}") while @ie.busy - sleep 0.1 - WIN32OLE_EVENT.message_loop + message_loop end assert_equal(bl, @ie.locationURL) end @@ -186,8 +185,7 @@ bl = @ie.locationURL @ie.navigate("file:///#{@f}") while @ie.busy - sleep 0.1 - WIN32OLE_EVENT.message_loop + message_loop end assert_equal(bl, @ie.locationURL) end @@ -200,8 +198,7 @@ bl = @ie.locationURL @ie.navigate("file:///#{@f}") while @ie.busy - sleep 0.1 - WIN32OLE_EVENT.message_loop + message_loop end assert_equal(bl, @ie.locationURL) end @@ -214,8 +211,7 @@ bl = @ie.locationURL @ie.navigate("file:///#{@f}") while @ie.busy - sleep 0.1 - WIN32OLE_EVENT.message_loop + message_loop end assert_equal(bl, @ie.locationURL) end @@ -228,12 +224,35 @@ bl = @ie.locationURL @ie.navigate("file:///#{@f}") while @ie.busy - sleep 0.1 - WIN32OLE_EVENT.message_loop + message_loop end assert_equal(bl, @ie.locationURL) end + def test_off_event + ev = WIN32OLE_EVENT.new(@ie) + ev.on_event{handler1} + ev.off_event + @ie.navigate("file:///#{@f}") + while @ie.busy + message_loop + end + WIN32OLE_EVENT.message_loop + assert_equal("", @event2) + end + + def test_off_event_arg + ev = WIN32OLE_EVENT.new(@ie) + ev.on_event('BeforeNavigate2'){handler1} + ev.off_event('BeforeNavigate2') + @ie.navigate("file:///#{@f}") + while @ie.busy + message_loop + end + WIN32OLE_EVENT.message_loop + assert_equal("", @event2) + end + def handler1 @event2 = "handler1" end @@ -248,21 +267,18 @@ def teardown @ie.quit - WIN32OLE_EVENT.message_loop @ie = nil - WIN32OLE_EVENT.message_loop - sleep 0.1 + i = 0 begin - File.unlink(@f) + i += 1 + File.unlink(@f) if i < 10 rescue Errno::EACCES - WIN32OLE_EVENT.message_loop - sleep 0.1 - File.unlink(@f) + message_loop + retry end - + message_loop GC.start - WIN32OLE_EVENT.message_loop - sleep 0.1 + message_loop end end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/