diff options
author | suke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-12 12:58:47 +0000 |
---|---|---|
committer | suke <suke@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-08-12 12:58:47 +0000 |
commit | f50c302e77715fca67e96dd44a3ff9d344298271 (patch) | |
tree | fe49411f179b741ebc40d2efe63437f7a7b3ce0f | |
parent | e439bc27dc5f6814b49309b4ad32b8d3ca54e9a4 (diff) | |
download | ruby-f50c302e77715fca67e96dd44a3ff9d344298271.tar.gz |
* ext/win32ole/win32ole.c (WIN32OLE_EVENT#on_event): should set
only one event handler.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8974 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ext/win32ole/tests/testOLEEVENT.rb | 40 | ||||
-rw-r--r-- | ext/win32ole/win32ole.c | 49 |
2 files changed, 81 insertions, 8 deletions
diff --git a/ext/win32ole/tests/testOLEEVENT.rb b/ext/win32ole/tests/testOLEEVENT.rb index 15b7ca8413..368794b150 100644 --- a/ext/win32ole/tests/testOLEEVENT.rb +++ b/ext/win32ole/tests/testOLEEVENT.rb @@ -5,6 +5,7 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase def setup @excel = WIN32OLE.new("Excel.Application") @excel.visible = true + @event = "" end def test_on_event book = @excel.workbooks.Add @@ -24,6 +25,45 @@ class TestWIN32OLE_EVENT < RUNIT::TestCase end assert_equal("OK", value) end + + def handler1 + @event += "handler1" + end + def handler2 + @event += "handler2" + end + + def test_on_event2 + book = @excel.workbooks.Add + begin + ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents') + ev.on_event('SheetChange'){|arg1, arg2| + handler1 + } + ev.on_event('SheetChange'){|arg1, arg2| + handler2 + } + book.Worksheets(1).Range("A1").value = "OK" + ensure + book.saved = true + end + assert_equal("handler2", @event) + end + + def test_on_event3 + book = @excel.workbooks.Add + begin + ev = WIN32OLE_EVENT.new(book, 'WorkbookEvents') + ev.on_event{ handler1 } + ev.on_event{ handler2 } + book.Worksheets(1).Range("A1").value = "OK" + ensure + book.saved = true + end + assert_equal("handler2", @event) + end + + def teardown @excel.quit @excel = nil diff --git a/ext/win32ole/win32ole.c b/ext/win32ole/win32ole.c index d5bba47fae..fd7cb1a152 100644 --- a/ext/win32ole/win32ole.c +++ b/ext/win32ole/win32ole.c @@ -79,7 +79,7 @@ #define WC2VSTR(x) ole_wc2vstr((x), TRUE) -#define WIN32OLE_VERSION "0.6.6" +#define WIN32OLE_VERSION "0.6.7" typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); @@ -6050,6 +6050,33 @@ STDMETHODIMP EVENTSINK_GetIDsOfNames( return DISP_E_UNKNOWNNAME; } +static long +ole_search_event_at(ary, ev) + VALUE ary; + VALUE ev; +{ + VALUE event; + VALUE def_event; + VALUE event_name; + long i, len; + long ret = -1; + def_event = Qnil; + len = RARRAY(ary)->len; + for(i = 0; i < len; i++) { + event = rb_ary_entry(ary, i); + event_name = rb_ary_entry(event, 1); + if(NIL_P(event_name) && NIL_P(ev)) { + ret = i; + break; + } + else if (rb_str_cmp(ev, event_name) == 0) { + ret = i; + break; + } + } + return ret; +} + static VALUE ole_search_event(ary, ev, is_default) VALUE ary; @@ -6616,16 +6643,22 @@ fev_s_msg_loop(klass) static void -add_event_call_back(obj, data) +add_event_call_back(obj, event, data) VALUE obj; + VALUE event; VALUE data; { - VALUE ary = rb_ivar_get(obj, id_events); - if (NIL_P(ary) || TYPE(ary) != T_ARRAY) { - ary = rb_ary_new(); - rb_ivar_set(obj, id_events, ary); + long at; + VALUE events = rb_ivar_get(obj, id_events); + if (NIL_P(events) || TYPE(events) != T_ARRAY) { + events = rb_ary_new(); + rb_ivar_set(obj, id_events, events); + } + at = ole_search_event_at(events, event); + if (at >= -1) { + rb_ary_delete_at(events, at); } - rb_ary_push(ary, data); + rb_ary_push(events, data); } static VALUE @@ -6641,7 +6674,7 @@ ev_on_event(argc, argv, self, is_ary_arg) Check_SafeStr(event); } data = rb_ary_new3(4, rb_block_proc(), event, args, is_ary_arg); - add_event_call_back(self, data); + add_event_call_back(self, event, data); return Qnil; } |