1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/win32ole/win32ole.c(Init_win32ole): add

WIN32OLE_TYPE#source_ole_types, WIN32OLE_TYPE#default_ole_types,
  WIN32OLE_TYPE#default_event_sources.

* test/win32ole/test_win32ole_type.rb: ditto.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2008-07-07 11:49:14 +00:00
parent 1d6e2caf10
commit 6aff4b8eaa
3 changed files with 144 additions and 16 deletions

View file

@ -1,3 +1,11 @@
Mon Jul 7 20:39:28 2008 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c(Init_win32ole): add
WIN32OLE_TYPE#source_ole_types, WIN32OLE_TYPE#default_ole_types,
WIN32OLE_TYPE#default_event_sources.
* test/win32ole/test_win32ole_type.rb: ditto.
Mon Jul 7 19:45:22 2008 NARUSE, Yui <naruse@ruby-lang.org> Mon Jul 7 19:45:22 2008 NARUSE, Yui <naruse@ruby-lang.org>
* test/ruby/test_dir.rb (test_chroot_nodir): add Errno::EPERM. * test/ruby/test_dir.rb (test_chroot_nodir): add Errno::EPERM.

View file

@ -118,7 +118,7 @@
#define WC2VSTR(x) ole_wc2vstr((x), TRUE) #define WC2VSTR(x) ole_wc2vstr((x), TRUE)
#define WIN32OLE_VERSION "1.2.0" #define WIN32OLE_VERSION "1.2.1"
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX) typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*); (REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
@ -424,8 +424,11 @@ static VALUE foletype_helpfile(VALUE self);
static VALUE ole_type_helpcontext(ITypeInfo *pTypeInfo); static VALUE ole_type_helpcontext(ITypeInfo *pTypeInfo);
static VALUE foletype_helpcontext(VALUE self); static VALUE foletype_helpcontext(VALUE self);
static VALUE foletype_ole_typelib(VALUE self); static VALUE foletype_ole_typelib(VALUE self);
static VALUE ole_type_impl_ole_types(ITypeInfo *pTypeInfo); static VALUE ole_type_impl_ole_types(ITypeInfo *pTypeInfo, int implflags);
static VALUE foletype_impl_ole_types(VALUE self); static VALUE foletype_impl_ole_types(VALUE self);
static VALUE foletype_source_ole_types(VALUE self);
static VALUE foletype_default_event_sources(VALUE self);
static VALUE foletype_default_ole_types(VALUE self);
static VALUE foletype_inspect(VALUE self); static VALUE foletype_inspect(VALUE self);
static VALUE ole_variables(ITypeInfo *pTypeInfo); static VALUE ole_variables(ITypeInfo *pTypeInfo);
static VALUE foletype_variables(VALUE self); static VALUE foletype_variables(VALUE self);
@ -5756,7 +5759,7 @@ foletype_ole_typelib(VALUE self)
} }
static VALUE static VALUE
ole_type_impl_ole_types(ITypeInfo *pTypeInfo) ole_type_impl_ole_types(ITypeInfo *pTypeInfo, int implflags)
{ {
HRESULT hr; HRESULT hr;
ITypeInfo *pRefTypeInfo; ITypeInfo *pRefTypeInfo;
@ -5782,9 +5785,12 @@ ole_type_impl_ole_types(ITypeInfo *pTypeInfo)
hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo); hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo);
if (FAILED(hr)) if (FAILED(hr))
continue; continue;
type = ole_type_from_itypeinfo(pRefTypeInfo);
if (type != Qnil) { if ((flags & implflags) == implflags) {
rb_ary_push(types, type); type = ole_type_from_itypeinfo(pRefTypeInfo);
if (type != Qnil) {
rb_ary_push(types, type);
}
} }
OLE_RELEASE(pRefTypeInfo); OLE_RELEASE(pRefTypeInfo);
@ -5807,7 +5813,60 @@ foletype_impl_ole_types(VALUE self)
{ {
struct oletypedata *ptype; struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype); Data_Get_Struct(self, struct oletypedata, ptype);
return ole_type_impl_ole_types(ptype->pTypeInfo); return ole_type_impl_ole_types(ptype->pTypeInfo, 0);
}
/*
* call-seq:
* WIN32OLE_TYPE#source_ole_types
*
* Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE
* object and having IMPLTYPEFLAG_FSOURCE.
* tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', "InternetExplorer")
* p tobj.source_ole_types
* # => [#<WIN32OLE_TYPE:DWebBrowserEvents2>, #<WIN32OLE_TYPE:DWebBrowserEvents>]
*/
static VALUE
foletype_source_ole_types(VALUE self)
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
return ole_type_impl_ole_types(ptype->pTypeInfo, IMPLTYPEFLAG_FSOURCE);
}
/*
* call-seq:
* WIN32OLE_TYPE#default_event_sources
*
* Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE
* object and having IMPLTYPEFLAG_FSOURCE and IMPLTYPEFLAG_FDEFAULT.
* tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', "InternetExplorer")
* p tobj.default_event_sources # => [#<WIN32OLE_TYPE:DWebBrowserEvents2>]
*/
static VALUE
foletype_default_event_sources(VALUE self)
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
return ole_type_impl_ole_types(ptype->pTypeInfo, IMPLTYPEFLAG_FSOURCE|IMPLTYPEFLAG_FDEFAULT);
}
/*
* call-seq:
* WIN32OLE_TYPE#default_ole_types
*
* Returns the array of WIN32OLE_TYPE object which is implemented by the WIN32OLE_TYPE
* object and having IMPLTYPEFLAG_FDEFAULT.
* tobj = WIN32OLE_TYPE.new('Microsoft Internet Controls', "InternetExplorer")
* p tobj.default_ole_types
* # => [#<WIN32OLE_TYPE:IWebBrowser2>, #<WIN32OLE_TYPE:DWebBrowserEvents2>]
*/
static VALUE
foletype_default_ole_types(VALUE self)
{
struct oletypedata *ptype;
Data_Get_Struct(self, struct oletypedata, ptype);
return ole_type_impl_ole_types(ptype->pTypeInfo, IMPLTYPEFLAG_FDEFAULT);
} }
static VALUE static VALUE
@ -7564,20 +7623,27 @@ find_default_source(VALUE ole, IID *piid, ITypeInfo **ppTypeInfo)
GUIDKIND_DEFAULT_SOURCE_DISP_IID, GUIDKIND_DEFAULT_SOURCE_DISP_IID,
piid); piid);
OLE_RELEASE(pProvideClassInfo2); OLE_RELEASE(pProvideClassInfo2);
return find_iid(ole, NULL, piid, ppTypeInfo); if (SUCCEEDED(hr)) {
hr = find_iid(ole, NULL, piid, ppTypeInfo);
}
}
if (SUCCEEDED(hr)) {
return hr;
} }
hr = pDispatch->lpVtbl->QueryInterface(pDispatch, hr = pDispatch->lpVtbl->QueryInterface(pDispatch,
&IID_IProvideClassInfo, &IID_IProvideClassInfo,
(void**)&pProvideClassInfo); (void**)&pProvideClassInfo);
if (SUCCEEDED(hr)) {
hr = pProvideClassInfo->lpVtbl->GetClassInfo(pProvideClassInfo,
&pTypeInfo);
OLE_RELEASE(pProvideClassInfo);
}
if (FAILED(hr)) {
hr = pDispatch->lpVtbl->GetTypeInfo(pDispatch, 0, cWIN32OLE_lcid, &pTypeInfo );
}
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
hr = pProvideClassInfo->lpVtbl->GetClassInfo(pProvideClassInfo,
&pTypeInfo);
OLE_RELEASE(pProvideClassInfo);
if (FAILED(hr))
return hr;
hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr); hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr);
if (FAILED(hr)) { if (FAILED(hr)) {
OLE_RELEASE(pTypeInfo); OLE_RELEASE(pTypeInfo);
@ -8443,6 +8509,9 @@ Init_win32ole()
rb_define_method(cWIN32OLE_TYPE, "ole_methods", foletype_methods, 0); rb_define_method(cWIN32OLE_TYPE, "ole_methods", foletype_methods, 0);
rb_define_method(cWIN32OLE_TYPE, "ole_typelib", foletype_ole_typelib, 0); rb_define_method(cWIN32OLE_TYPE, "ole_typelib", foletype_ole_typelib, 0);
rb_define_method(cWIN32OLE_TYPE, "implemented_ole_types", foletype_impl_ole_types, 0); rb_define_method(cWIN32OLE_TYPE, "implemented_ole_types", foletype_impl_ole_types, 0);
rb_define_method(cWIN32OLE_TYPE, "source_ole_types", foletype_source_ole_types, 0);
rb_define_method(cWIN32OLE_TYPE, "default_event_sources", foletype_default_event_sources, 0);
rb_define_method(cWIN32OLE_TYPE, "default_ole_types", foletype_default_ole_types, 0);
rb_define_method(cWIN32OLE_TYPE, "inspect", foletype_inspect, 0); rb_define_method(cWIN32OLE_TYPE, "inspect", foletype_inspect, 0);
cWIN32OLE_VARIABLE = rb_define_class("WIN32OLE_VARIABLE", rb_cObject); cWIN32OLE_VARIABLE = rb_define_class("WIN32OLE_VARIABLE", rb_cObject);

View file

@ -166,8 +166,59 @@ if defined?(WIN32OLE_TYPE)
def test_implemented_ole_types def test_implemented_ole_types
ole_types = @ole_type.implemented_ole_types ole_types = @ole_type.implemented_ole_types
assert_instance_of(Array, ole_types) assert_instance_of(Array, ole_types)
assert(ole_types.size > 0) assert_equal(1, ole_types.size)
assert_match(/^IShellDispatch5{0,1}$/, ole_types[0].name) assert_match(/^IShellDispatch5{0,1}$/, ole_types[0].name)
ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
ole_types = ie_otype.implemented_ole_types
assert_equal(4, ole_types.size)
otype = ole_types.select{|t| t.name == "IWebBrowser2"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
assert_equal(1, otype.size)
end
def test_default_ole_types
ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
ole_types = ie_otype.default_ole_types
otype = ole_types.select{|t| t.name == "IWebBrowser2"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
assert_equal(0, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
assert_equal(0, otype.size)
end
def test_source_ole_types
ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
ole_types = ie_otype.source_ole_types
otype = ole_types.select{|t| t.name == "IWebBrowser2"}
assert_equal(0, otype.size)
otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
assert_equal(0, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
assert_equal(1, otype.size)
end
def test_default_event_sources
ie_otype = WIN32OLE_TYPE.new("Microsoft Internet Controls", "InternetExplorer")
ole_types = ie_otype.default_event_sources
otype = ole_types.select{|t| t.name == "IWebBrowser2"}
assert_equal(0, otype.size)
otype = ole_types.select{|t| t.name == "IWebBrowserApp"}
assert_equal(0, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents2"}
assert_equal(1, otype.size)
otype = ole_types.select{|t| t.name == "DWebBrowserEvents"}
assert_equal(0, otype.size)
end end
def test_inspect def test_inspect