зеркало из https://github.com/github/ruby.git
* ext/win32ole/win32ole.c (foletype_s_ole_classes,
foletype_s_typelibs): refactoring. * test/win32ole/test_win32ole_type.rb: add some test. * ext/win32ole/win32ole.c (Init_win32ole): change method name WIN32OLE_TYPELIB.ole_types from WIN32OLE_TYPELIB.ole_classes. * test/win32ole/test_win32ole_typelib.rb: ditto. * test/win32ole/test_folderitem2_invokeverb.rb: check create shortcut string more strictly (This test is invoked in Japanese Windows environment). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13690 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
e0a6ff2aa6
Коммит
31c764ff7f
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
Sat Oct 13 21:23:21 2007 Masaki Suketa <masaki.suketa@nifty.ne.jp>
|
||||
|
||||
* ext/win32ole/win32ole.c (foletype_s_ole_classes,
|
||||
foletype_s_typelibs): refactoring.
|
||||
|
||||
* test/win32ole/test_win32ole_type.rb: add some test.
|
||||
|
||||
* ext/win32ole/win32ole.c (Init_win32ole): change method name
|
||||
WIN32OLE_TYPELIB.ole_types from WIN32OLE_TYPELIB.ole_classes.
|
||||
|
||||
* test/win32ole/test_win32ole_typelib.rb: ditto.
|
||||
|
||||
* test/win32ole/test_folderitem2_invokeverb.rb: check create
|
||||
shortcut string more strictly (This test is invoked in Japanese
|
||||
Windows environment).
|
||||
|
||||
Sat Oct 13 09:11:58 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* parse.y (set_file_encoding): case-insensitive search, a patch from
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
|
||||
#define WC2VSTR(x) ole_wc2vstr((x), TRUE)
|
||||
|
||||
#define WIN32OLE_VERSION "1.1.0"
|
||||
#define WIN32OLE_VERSION "1.1.1"
|
||||
|
||||
typedef HRESULT (STDAPICALLTYPE FNCOCREATEINSTANCEEX)
|
||||
(REFCLSID, IUnknown*, DWORD, COSERVERINFO*, DWORD, MULTI_QI*);
|
||||
|
@ -306,7 +306,7 @@ static VALUE ole_create_dcom(int argc, VALUE *argv, VALUE self);
|
|||
static VALUE ole_bind_obj(VALUE moniker, int argc, VALUE *argv, VALUE self);
|
||||
static VALUE fole_s_connect(int argc, VALUE *argv, VALUE self);
|
||||
static VALUE fole_s_const_load(int argc, VALUE *argv, VALUE self);
|
||||
static VALUE ole_classes_from_typelib(ITypeLib *pTypeLib, VALUE classes);
|
||||
static VALUE ole_types_from_typelib(ITypeLib *pTypeLib, VALUE classes);
|
||||
static ULONG reference_count(struct oledata * pole);
|
||||
static VALUE fole_s_reference_count(VALUE self, VALUE obj);
|
||||
static VALUE fole_s_free(VALUE self, VALUE obj);
|
||||
|
@ -384,7 +384,7 @@ static VALUE foletypelib_path(VALUE self);
|
|||
static void oletypelib2itypelib(VALUE self, ITypeLib **ppTypeLib);
|
||||
static VALUE foletypelib_visible(VALUE self);
|
||||
static VALUE foletypelib_library_name(VALUE self);
|
||||
static VALUE foletypelib_ole_classes(VALUE self);
|
||||
static VALUE foletypelib_ole_types(VALUE self);
|
||||
static VALUE foletypelib_inspect(VALUE self);
|
||||
static VALUE foletype_initialize(VALUE self, VALUE typelib, VALUE oleclass);
|
||||
static VALUE foletype_name(VALUE self);
|
||||
|
@ -2425,7 +2425,7 @@ fole_s_const_load(int argc, VALUE *argv, VALUE self)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
ole_classes_from_typelib(ITypeLib *pTypeLib, VALUE classes)
|
||||
ole_types_from_typelib(ITypeLib *pTypeLib, VALUE classes)
|
||||
{
|
||||
|
||||
long count;
|
||||
|
@ -4343,34 +4343,15 @@ fole_activex_initialize(VALUE self)
|
|||
static VALUE
|
||||
foletype_s_ole_classes(VALUE self, VALUE typelib)
|
||||
{
|
||||
VALUE file, classes;
|
||||
OLECHAR * pbuf;
|
||||
ITypeLib *pTypeLib;
|
||||
HRESULT hr;
|
||||
VALUE obj;
|
||||
|
||||
/*
|
||||
rb_warn("%s is obsolete; use %s instead.",
|
||||
"WIN32OLE_TYPE.ole_classes",
|
||||
"WIN32OLE_TYPELIB.new(typelib).ole_classes");
|
||||
"WIN32OLE_TYPELIB.new(typelib).ole_types");
|
||||
*/
|
||||
rb_secure(4);
|
||||
classes = rb_ary_new();
|
||||
if(TYPE(typelib) == T_STRING) {
|
||||
file = typelib_file(typelib);
|
||||
if (file == Qnil) {
|
||||
file = typelib;
|
||||
}
|
||||
pbuf = ole_mb2wc(StringValuePtr(file), -1);
|
||||
hr = LoadTypeLibEx(pbuf, REGKIND_NONE, &pTypeLib);
|
||||
if (FAILED(hr))
|
||||
ole_raise(hr, eWIN32OLERuntimeError, "failed to LoadTypeLibEx");
|
||||
SysFreeString(pbuf);
|
||||
ole_classes_from_typelib(pTypeLib, classes);
|
||||
OLE_RELEASE(pTypeLib);
|
||||
} else {
|
||||
rb_raise(rb_eTypeError, "1st argument should be TypeLib string");
|
||||
}
|
||||
return classes;
|
||||
obj = rb_funcall(cWIN32OLE_TYPELIB, rb_intern("new"), 1, typelib);
|
||||
return rb_funcall(obj, rb_intern("ole_types"), 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -4384,47 +4365,12 @@ foletype_s_ole_classes(VALUE self, VALUE typelib)
|
|||
static VALUE
|
||||
foletype_s_typelibs(VALUE self)
|
||||
{
|
||||
HKEY htypelib, hclsid;
|
||||
double fversion;
|
||||
DWORD i, j;
|
||||
LONG err;
|
||||
VALUE clsid;
|
||||
VALUE ver;
|
||||
VALUE v = Qnil;
|
||||
VALUE typelibs = rb_ary_new();
|
||||
|
||||
/*
|
||||
rb_warn("%s is obsolete. use %s instead.",
|
||||
"WIN32OLE_TYPE.typelibs",
|
||||
"WIN32OLE_TYPELIB.typelibs.collect{t|t.name}");
|
||||
*/
|
||||
err = reg_open_key(HKEY_CLASSES_ROOT, "TypeLib", &htypelib);
|
||||
if(err != ERROR_SUCCESS) {
|
||||
return typelibs;
|
||||
}
|
||||
for(i = 0; ; i++) {
|
||||
clsid = reg_enum_key(htypelib, i);
|
||||
if (clsid == Qnil)
|
||||
break;
|
||||
err = reg_open_vkey(htypelib, clsid, &hclsid);
|
||||
if (err != ERROR_SUCCESS)
|
||||
continue;
|
||||
fversion = 0;
|
||||
for(j = 0; ; j++) {
|
||||
ver = reg_enum_key(hclsid, j);
|
||||
if (ver == Qnil)
|
||||
break;
|
||||
if (fversion > atof(StringValuePtr(ver)))
|
||||
continue;
|
||||
fversion = atof(StringValuePtr(ver));
|
||||
if ( (v = reg_get_val(hclsid, StringValuePtr(ver))) != Qnil ) {
|
||||
rb_ary_push(typelibs, v);
|
||||
}
|
||||
}
|
||||
RegCloseKey(hclsid);
|
||||
}
|
||||
RegCloseKey(htypelib);
|
||||
return typelibs;
|
||||
return rb_eval_string("WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}");
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -5007,20 +4953,20 @@ foletypelib_library_name(VALUE self)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* WIN32OLE_TYPELIB#ole_classes -> The array of WIN32OLE_TYPE object included the type library.
|
||||
* WIN32OLE_TYPELIB#ole_types -> The array of WIN32OLE_TYPE object included the type library.
|
||||
*
|
||||
* Returns the type library file path.
|
||||
*
|
||||
* tlib = WIN32OLE_TYPELIB.new('Microsoft Excel 9.0 Object Library')
|
||||
* classes = tlib.ole_classes.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
|
||||
* classes = tlib.ole_types.collect{|k| k.name} # -> ['AddIn', 'AddIns' ...]
|
||||
*/
|
||||
static VALUE
|
||||
foletypelib_ole_classes(VALUE self)
|
||||
foletypelib_ole_types(VALUE self)
|
||||
{
|
||||
ITypeLib *pTypeLib = NULL;
|
||||
VALUE classes = rb_ary_new();
|
||||
oletypelib2itypelib(self, &pTypeLib);
|
||||
ole_classes_from_typelib(pTypeLib, classes);
|
||||
ole_types_from_typelib(pTypeLib, classes);
|
||||
OLE_RELEASE(pTypeLib);
|
||||
return classes;
|
||||
}
|
||||
|
@ -8122,7 +8068,8 @@ Init_win32ole()
|
|||
rb_define_method(cWIN32OLE_TYPELIB, "major_version", foletypelib_major_version, 0);
|
||||
rb_define_method(cWIN32OLE_TYPELIB, "minor_version", foletypelib_minor_version, 0);
|
||||
rb_define_method(cWIN32OLE_TYPELIB, "path", foletypelib_path, 0);
|
||||
rb_define_method(cWIN32OLE_TYPELIB, "ole_classes", foletypelib_ole_classes, 0);
|
||||
rb_define_method(cWIN32OLE_TYPELIB, "ole_types", foletypelib_ole_types, 0);
|
||||
rb_define_alias(cWIN32OLE_TYPELIB, "ole_classes", "ole_types");
|
||||
rb_define_method(cWIN32OLE_TYPELIB, "visible?", foletypelib_visible, 0);
|
||||
rb_define_method(cWIN32OLE_TYPELIB, "library_name", foletypelib_library_name, 0);
|
||||
rb_define_alias(cWIN32OLE_TYPELIB, "to_s", "name");
|
||||
|
|
|
@ -29,7 +29,7 @@ if defined?(WIN32OLE)
|
|||
@shortcut = nil
|
||||
|
||||
#
|
||||
# Search the 'Create Shortcut (&S)' string.
|
||||
# Search the 'Create Shortcut (&S)' string in Japanese.
|
||||
# Yes, I know the string in the Windows 2000 Japanese Edition.
|
||||
# But I do not know about the string in any other Windows.
|
||||
#
|
||||
|
@ -38,7 +38,8 @@ if defined?(WIN32OLE)
|
|||
@shortcut = verbs.collect{|verb|
|
||||
verb.name
|
||||
}.find {|name|
|
||||
/.*\(\&S\)$/ =~ name
|
||||
name.unpack("C*") == [131, 86, 131, 135, 129, 91, 131, 103, 131, 74, 131, 98, 131, 103, 130, 204, 141, 236, 144, 172, 40, 38, 83, 41]
|
||||
# /.*\(\&S\)$/ =~ name
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -158,6 +158,20 @@ if defined?(WIN32OLE_TYPE)
|
|||
def test_inspect
|
||||
assert_equal("#<WIN32OLE_TYPE:Shell>", @ole_type.inspect)
|
||||
end
|
||||
# WIN32OLE_TYPE.typelibs will be obsoleted.
|
||||
def test_s_typelibs
|
||||
tlibs = WIN32OLE_TYPE.typelibs.sort
|
||||
tlibs2 = WIN32OLE_TYPELIB.typelibs.collect{|t|t.name}.sort
|
||||
assert_equal(tlibs2, tlibs)
|
||||
end
|
||||
|
||||
# WIN32OLE_TYPE.ole_classes will be obsoleted.
|
||||
def test_s_ole_classes
|
||||
ots1 = WIN32OLE_TYPE.ole_classes("Microsoft Shell Controls And Automation")
|
||||
ots2 = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation").ole_types
|
||||
otns1 = ots1.collect{|t| t.name}.sort
|
||||
otns2 = ots2.collect{|t| t.name}.sort
|
||||
assert_equal(otns2, otns1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -88,12 +88,12 @@ if defined?(WIN32OLE_TYPELIB)
|
|||
assert_equal("Microsoft Shell Controls And Automation", tlib.to_s)
|
||||
end
|
||||
|
||||
def test_ole_classes
|
||||
def test_ole_types
|
||||
tlib = WIN32OLE_TYPELIB.new("Microsoft Shell Controls And Automation")
|
||||
ole_classes = tlib.ole_classes
|
||||
assert_instance_of(Array, ole_classes)
|
||||
assert(ole_classes.size > 0)
|
||||
assert_instance_of(WIN32OLE_TYPE, ole_classes[0])
|
||||
ole_types = tlib.ole_types
|
||||
assert_instance_of(Array, ole_types)
|
||||
assert(ole_types.size > 0)
|
||||
assert_instance_of(WIN32OLE_TYPE, ole_types[0])
|
||||
end
|
||||
|
||||
def test_inspect
|
||||
|
|
Загрузка…
Ссылка в новой задаче