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: refactoring. move some methods

into win32ole_type.c / win32ole_method.c
* ext/win32ole/win32ole.h: ditto.
* ext/win32ole/win32ole_method.c: ditto.
* ext/win32ole/win32ole_method.h: ditto.
* ext/win32ole/win32ole_type.h: ditto.
* ext/win32ole/win32ole_type.h: ditto.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
suke 2014-08-12 14:21:22 +00:00
parent 7bf7bb84d3
commit aeb8791dab
7 changed files with 81 additions and 61 deletions

View file

@ -1,3 +1,13 @@
Tue Aug 12 23:17:47 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: refactoring. move some methods
into win32ole_type.c / win32ole_method.c
* ext/win32ole/win32ole.h: ditto.
* ext/win32ole/win32ole_method.c: ditto.
* ext/win32ole/win32ole_method.h: ditto.
* ext/win32ole/win32ole_type.h: ditto.
* ext/win32ole/win32ole_type.h: ditto.
Tue Aug 12 22:59:48 2014 Masaki Suketa <masaki.suketa@nifty.ne.jp>
* ext/win32ole/win32ole.c: refactoring. move

View file

@ -103,7 +103,6 @@ typedef struct tagIEVENTSINKOBJ {
}IEVENTSINKOBJ, *PIEVENTSINKOBJ;
VALUE cWIN32OLE;
VALUE cWIN32OLE_METHOD;
VALUE cWIN32OLE_PARAM;
VALUE cWIN32OLE_EVENT;
VALUE cWIN32OLE_VARIANT;
@ -3752,35 +3751,6 @@ fole_missing(int argc, VALUE *argv, VALUE self)
}
}
VALUE
ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask)
{
HRESULT hr;
TYPEATTR *pTypeAttr;
WORD i;
HREFTYPE href;
ITypeInfo *pRefTypeInfo;
VALUE methods = rb_ary_new();
hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr);
if (FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError, "failed to GetTypeAttr");
}
ole_methods_sub(0, pTypeInfo, methods, mask);
for(i=0; i < pTypeAttr->cImplTypes; i++){
hr = pTypeInfo->lpVtbl->GetRefTypeOfImplType(pTypeInfo, i, &href);
if(FAILED(hr))
continue;
hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo);
if (FAILED(hr))
continue;
ole_methods_sub(pTypeInfo, pRefTypeInfo, methods, mask);
OLE_RELEASE(pRefTypeInfo);
}
OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
return methods;
}
static HRESULT
typeinfo_from_ole(struct oledata *pole, ITypeInfo **ppti)
{
@ -3907,29 +3877,6 @@ fole_func_methods(VALUE self)
return ole_methods( self, INVOKE_FUNC);
}
VALUE
ole_type_from_itypeinfo(ITypeInfo *pTypeInfo)
{
ITypeLib *pTypeLib;
VALUE type = Qnil;
HRESULT hr;
unsigned int index;
BSTR bstr;
hr = pTypeInfo->lpVtbl->GetContainingTypeLib( pTypeInfo, &pTypeLib, &index );
if(FAILED(hr)) {
return Qnil;
}
hr = pTypeLib->lpVtbl->GetDocumentation( pTypeLib, index,
&bstr, NULL, NULL, NULL);
OLE_RELEASE(pTypeLib);
if (FAILED(hr)) {
return Qnil;
}
type = create_win32ole_type(pTypeInfo, WC2VSTR(bstr));
return type;
}
/*
* call-seq:
* WIN32OLE#ole_type
@ -4268,7 +4215,7 @@ fole_method_help(VALUE self, VALUE cmdname)
ITypeInfo *pTypeInfo;
HRESULT hr;
struct oledata *pole;
VALUE method, obj;
VALUE obj;
SafeStringValue(cmdname);
OLEData_Get_Struct(self, pole);
@ -4276,8 +4223,7 @@ fole_method_help(VALUE self, VALUE cmdname)
if(FAILED(hr))
ole_raise(hr, rb_eRuntimeError, "failed to get ITypeInfo");
method = folemethod_s_allocate(cWIN32OLE_METHOD);
obj = olemethod_from_typeinfo(method, pTypeInfo, cmdname);
obj = create_win32ole_method(pTypeInfo, cmdname);
OLE_RELEASE(pTypeInfo);
if (obj == Qnil)

View file

@ -115,11 +115,10 @@ VALUE ole_wc2vstr(LPWSTR pw, BOOL isfree);
BOOL ole_initialized();
HRESULT ole_docinfo_from_type(ITypeInfo *pTypeInfo, BSTR *name, BSTR *helpstr, DWORD *helpcontext, BSTR *helpfile);
VALUE ole_typedesc2val(ITypeInfo *pTypeInfo, TYPEDESC *pTypeDesc, VALUE typedetails);
VALUE ole_type_from_itypeinfo(ITypeInfo *pTypeInfo);
VALUE make_inspect(const char *class_name, VALUE detail);
VALUE ole_variant2val(VARIANT *pvar);
VALUE ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask);
VALUE create_win32ole_param(ITypeInfo *pTypeInfo, UINT method_index, UINT index, VALUE name);
#include "win32ole_variant_m.h"
#include "win32ole_typelib.h"
#include "win32ole_type.h"

View file

@ -1,6 +1,8 @@
#include "win32ole.h"
static VALUE ole_method_sub(VALUE self, ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE name);
static VALUE olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name);
static VALUE ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask);
static void olemethod_free(struct olemethoddata *polemethod);
static VALUE olemethod_set_member(VALUE self, ITypeInfo *pTypeInfo, ITypeInfo *pOwnerTypeInfo, int index, VALUE name);
static VALUE folemethod_initialize(VALUE self, VALUE oletype, VALUE method);
@ -85,6 +87,35 @@ ole_method_sub(VALUE self, ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALU
}
VALUE
ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask)
{
HRESULT hr;
TYPEATTR *pTypeAttr;
WORD i;
HREFTYPE href;
ITypeInfo *pRefTypeInfo;
VALUE methods = rb_ary_new();
hr = OLE_GET_TYPEATTR(pTypeInfo, &pTypeAttr);
if (FAILED(hr)) {
ole_raise(hr, eWIN32OLERuntimeError, "failed to GetTypeAttr");
}
ole_methods_sub(0, pTypeInfo, methods, mask);
for(i=0; i < pTypeAttr->cImplTypes; i++){
hr = pTypeInfo->lpVtbl->GetRefTypeOfImplType(pTypeInfo, i, &href);
if(FAILED(hr))
continue;
hr = pTypeInfo->lpVtbl->GetRefTypeInfo(pTypeInfo, href, &pRefTypeInfo);
if (FAILED(hr))
continue;
ole_methods_sub(pTypeInfo, pRefTypeInfo, methods, mask);
OLE_RELEASE(pRefTypeInfo);
}
OLE_RELEASE_TYPEATTR(pTypeInfo, pTypeAttr);
return methods;
}
static VALUE
olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name)
{
HRESULT hr;
@ -115,7 +146,7 @@ olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name)
return method;
}
VALUE
static VALUE
ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask)
{
HRESULT hr;
@ -153,6 +184,15 @@ ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods,
return methods;
}
VALUE
create_win32ole_method(ITypeInfo *pTypeInfo, VALUE name)
{
VALUE method = folemethod_s_allocate(cWIN32OLE_METHOD);
VALUE obj = olemethod_from_typeinfo(method, pTypeInfo, name);
return obj;
}
/*
* Document-class: WIN32OLE_METHOD
*

View file

@ -9,7 +9,7 @@ struct olemethoddata {
VALUE cWIN32OLE_METHOD;
VALUE folemethod_s_allocate(VALUE klass);
VALUE olemethod_from_typeinfo(VALUE self, ITypeInfo *pTypeInfo, VALUE name);
VALUE ole_methods_sub(ITypeInfo *pOwnerTypeInfo, ITypeInfo *pTypeInfo, VALUE methods, int mask);
VALUE ole_methods_from_typeinfo(ITypeInfo *pTypeInfo, int mask);
VALUE create_win32ole_method(ITypeInfo *pTypeInfo, VALUE name);
void Init_win32ole_method();
#endif

View file

@ -66,6 +66,30 @@ ITypeInfo *itypeinfo(VALUE self)
return ptype->pTypeInfo;
}
VALUE
ole_type_from_itypeinfo(ITypeInfo *pTypeInfo)
{
ITypeLib *pTypeLib;
VALUE type = Qnil;
HRESULT hr;
unsigned int index;
BSTR bstr;
hr = pTypeInfo->lpVtbl->GetContainingTypeLib( pTypeInfo, &pTypeLib, &index );
if(FAILED(hr)) {
return Qnil;
}
hr = pTypeLib->lpVtbl->GetDocumentation( pTypeLib, index,
&bstr, NULL, NULL, NULL);
OLE_RELEASE(pTypeLib);
if (FAILED(hr)) {
return Qnil;
}
type = create_win32ole_type(pTypeInfo, WC2VSTR(bstr));
return type;
}
/*
* call-seq:
* WIN32OLE_TYPE.ole_classes(typelib)

View file

@ -3,5 +3,6 @@
VALUE cWIN32OLE_TYPE;
VALUE create_win32ole_type(ITypeInfo *pTypeInfo, VALUE name);
ITypeInfo *itypeinfo(VALUE self);
VALUE ole_type_from_itypeinfo(ITypeInfo *pTypeInfo);
void Init_win32ole_type();
#endif