diff options
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/extconf.rb | 68 | ||||
-rw-r--r-- | ext/tk/lib/tk/canvas.rb | 9 | ||||
-rw-r--r-- | ext/tk/lib/tk/msgcat.rb | 41 | ||||
-rw-r--r-- | ext/tk/lib/tk/namespace.rb | 7 | ||||
-rw-r--r-- | ext/tk/lib/tkextlib/tktable/tktable.rb | 2 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/tree.rb | 2 | ||||
-rw-r--r-- | ext/tk/sample/demos-en/widget | 6 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/tree.rb | 2 | ||||
-rw-r--r-- | ext/tk/sample/demos-jp/widget | 6 | ||||
-rw-r--r-- | ext/tk/sample/scrollframe.rb | 2 | ||||
-rw-r--r-- | ext/tk/stubs.c | 14 | ||||
-rw-r--r-- | ext/tk/tcltklib.c | 15 |
12 files changed, 112 insertions, 62 deletions
diff --git a/ext/tk/extconf.rb b/ext/tk/extconf.rb index 2f68d01e7f..3f8c50ff6d 100644 --- a/ext/tk/extconf.rb +++ b/ext/tk/extconf.rb @@ -8,12 +8,21 @@ TkLib_Config = {} TkLib_Config['search_versions'] = # %w[8.9 8.8 8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0 7.6 4.2] # %w[8.7 8.6 8.5 8.4 8.3 8.2 8.1 8.0] - %w[8.7 8.6 8.5 8.4 8.0] # to shorten search steps + # %w[8.7 8.6 8.5 8.4 8.0] # to shorten search steps + %w[8.5 8.4] # At present, Tcl/Tk8.6 is not supported. + +TkLib_Config['unsupported_versions'] = + %w[8.8 8.7 8.6] # At present, Tcl/Tk8.6 is not supported. TkLib_Config['major_nums'] = '87' ############################################################## + +TkLib_Config['enable-shared'] = enable_config("shared") + + +############################################################## # use old extconf.rb ? ############################################################## if with_config('tk-old-extconf') @@ -114,7 +123,7 @@ def is_macosx? end def maybe_64bit? - /64|universal/ =~ RUBY_PLATFORM + /64|universal|s390x/ =~ RUBY_PLATFORM end def check_tcltk_version(version) @@ -313,7 +322,9 @@ def find_macosx_framework paths.reverse! unless TkLib_Config["ActiveTcl"] # system has higher priority paths.map{|dir| dir.strip.chomp('/')}.each{|dir| + next unless File.exist?(File.join(dir, "Tcl.framework", "Headers")) next unless File.directory?(tcldir = File.join(dir, "Tcl.framework")) + next unless File.exist?(File.join(dir, "Tk.framework", "Headers")) next unless File.directory?(tkdir = File.join(dir, "Tk.framework")) TkLib_Config["tcltk-framework"] = dir return [tcldir, tkdir] @@ -540,13 +551,13 @@ end def get_ext_list() exts = [CONFIG['DLEXT']] - exts.concat %w(dll lib) if is_win32? + exts.concat %w(dll) if is_win32? exts.concat %w(bundle dylib) if is_macosx? || /nextstep|openstep|rhapsody/ =~ RUBY_PLATFORM - if enable_config("shared") == false - [CONFIG['LIBEXT'], "a"].concat exts - else - exts.concat [CONFIG['LIBEXT'], "a"] + if TkLib_Config["tcltk-stubs"] || TkLib_Config['enable-shared'] == false + exts.unshift "lib" if is_win32? + exts.unshift "a" + exts.unshift CONFIG['LIBEXT'] end if is_win32? @@ -734,6 +745,7 @@ def search_tclConfig(*paths) # libdir list or [tcl-libdir|file, tk-libdir|file] end conf = nil + progress_flag = false config_dir.uniq! config_dir.map{|dir| @@ -744,7 +756,7 @@ def search_tclConfig(*paths) # libdir list or [tcl-libdir|file, tk-libdir|file] dir.strip.chomp('/') end }.each{|dir| - print(".") # progress + print("."); progress_flag = true # progress # print("check #{dir} ==>"); if dir.kind_of? Array tcldir, tkdir = dir @@ -783,10 +795,36 @@ def search_tclConfig(*paths) # libdir list or [tcl-libdir|file, tk-libdir|file] # parse tclConfig.sh/tkConfig.sh tclconf = (tclpath)? parse_tclConfig(tclpath): nil - next if tclconf && tclver && ((tclver_major && tclver_major != tclconf['TCL_MAJOR_VERSION']) || (tclver_minor && tclver_minor != tclconf['TCL_MINOR_VERSION'])) + if tclconf + if tclver && ((tclver_major && tclver_major != tclconf['TCL_MAJOR_VERSION']) || (tclver_minor && tclver_minor != tclconf['TCL_MINOR_VERSION'])) + print("\n") if progress_flag + puts "Ignore \"#{tclpath}\" (unmatch with configured version)." + progress_flag = false + next + end + if TkLib_Config['unsupported_versions'].find{|ver| ver == "#{tclconf['TCL_MAJOR_VERSION']}.#{tclconf['TCL_MINOR_VERSION']}"} + print("\n") if progress_flag + puts "Ignore \"#{tclpath}\" (unsupported version of Tcl/Tk)." + progress_flag = false + next + end + end tkconf = (tkpath)? parse_tclConfig(tkpath): nil - next if tkconf && tkver && ((tkver_major && tkver_major != tkconf['TK_MAJOR_VERSION']) || (tkver_minor && tkver_minor != tkconf['TK_MINOR_VERSION'])) + if tkconf + if tkver && ((tkver_major && tkver_major != tkconf['TK_MAJOR_VERSION']) || (tkver_minor && tkver_minor != tkconf['TK_MINOR_VERSION'])) + print("\n") if progress_flag + puts "Ignore \"#{tkpath}\" (unmatch with configured version)." + progress_flag = false + next + end + if TkLib_Config['unsupported_versions'].find{|ver| ver == "#{tkconf['TK_MAJOR_VERSION']}.#{tkconf['TK_MINOR_VERSION']}"} + print("\n") if progress_flag + puts "Ignore \"#{tkpath}\" (unsupported version of Tcl/Tk)." + progress_flag = false + next + end + end # nativethread check if !TkLib_Config["ruby_with_thread"] @@ -1289,6 +1327,10 @@ end def find_tcltk_library(tcllib, tklib, stubs, tclversion, tkversion, tcl_opt_paths, tk_opt_paths) st,path,lib,libs,*inc = find_tcl(tcllib, stubs, tclversion, *tcl_opt_paths) + if !st && TkLib_Config['enable-shared'] == nil + TkLib_Config['enable-shared'] = false + st,path,lib,libs,*inc = find_tcl(tcllib, stubs, tclversion, *tcl_opt_paths) + end unless st puts("Warning:: cannot find Tcl library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options.") return false @@ -1301,6 +1343,10 @@ def find_tcltk_library(tcllib, tklib, stubs, tclversion, tkversion, end st,path,lib,libs,*inc = find_tk(tklib, stubs, tkversion, *tk_opt_paths) + if !st && TkLib_Config['enable-shared'] == nil + TkLib_Config['enable-shared'] = false + st,path,lib,libs,*inc = find_tk(tklib, stubs, tkversion, *tk_opt_paths) + end unless st puts("Warning:: cannot find Tk library. tcltklib will not be compiled (tcltklib is disabled on your Ruby. That is, Ruby/Tk will not work). Please check configure options.") return false @@ -2029,4 +2075,6 @@ if (TkLib_Config["tcltk-framework"] || puts "\nFind Tcl/Tk libraries. Make tcltklib.so which is required by Ruby/Tk." else puts "\nCan't find proper Tcl/Tk libraries. So, can't make tcltklib.so which is required by Ruby/Tk." + puts "If you have Tcl/Tk libraries on your environment, you may be able to use them with configure options (see ext/tk/README.tcltklib)." + puts "At present, Tcl/Tk8.6 is not supported. Although you can try to use Tcl/Tk8.6 with configure options, it will not work correctly. I recommend you to use Tcl/Tk8.5 or 8.4." end diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb index 7d3d71675c..af404213e7 100644 --- a/ext/tk/lib/tk/canvas.rb +++ b/ext/tk/lib/tk/canvas.rb @@ -85,11 +85,16 @@ class Tk::Canvas<TkWindow # create a canvas item without creating a TkcItem object def create(type, *args) - type = TkcItem.type2class(type.to_s) unless type.kind_of?(TkcItem) + if type.kind_of?(Class) && type < TkcItem + # do nothing + elsif TkcItem.type2class(type.to_s) + type = TkcItem.type2class(type.to_s) + else + fail ArgumentError, "type must a subclass of TkcItem class, or a string in CItemTypeToClass" + end type.create(self, *args) end - def addtag(tag, mode, *args) mode = mode.to_s if args[0] && mode =~ /^(above|below|with(tag)?)$/ diff --git a/ext/tk/lib/tk/msgcat.rb b/ext/tk/lib/tk/msgcat.rb index 4abbcad85e..f2d0653c69 100644 --- a/ext/tk/lib/tk/msgcat.rb +++ b/ext/tk/lib/tk/msgcat.rb @@ -125,6 +125,8 @@ class TkMsgCatalog < TkObject when 2 # src and trans, or, trans_list and enc if args[0].kind_of?(Array) + # trans_list + self.set_translation_list(loc, *args) else #self.set_translation(loc, args[0], Tk::UTF8_String.new(args[1])) self.set_translation(loc, *args) @@ -199,7 +201,11 @@ class TkMsgCatalog < TkObject file = File.join(dir, loc + self::MSGCAT_EXT) if File.readable?(file) count += 1 - eval(open(file){|f| f.read}) + if TkCore::WITH_ENCODING + eval(IO.read(file, :encoding=>"ASCII-8BIT")) + else + eval(IO.read(file)) + end end } count @@ -215,7 +221,11 @@ class TkMsgCatalog < TkObject file = File.join(dir, loc + @msgcat_ext) if File.readable?(file) count += 1 - @namespace.eval(open(file){|f| f.read}) + if TkCore::WITH_ENCODING + @namespace.eval(IO.read(file, :encoding=>"ASCII-8BIT")) + else + @namespace.eval(IO.read(file)) + end end } count @@ -229,30 +239,21 @@ class TkMsgCatalog < TkObject def self.set_translation(locale, src_str, trans_str=None, enc='utf-8') if trans_str && trans_str != None trans_str = Tk.UTF8_String(_toUTF8(trans_str, enc)) - Tk.UTF8_String(tk_call_without_enc('::msgcat::mcset', - locale, - _get_eval_string(src_str, true), - trans_str)) + Tk.UTF8_String(ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}} {#{trans_str}}")) else - Tk.UTF8_String(tk_call_without_enc('::msgcat::mcset', - locale, - _get_eval_string(src_str, true))) + Tk.UTF8_String(ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}}")) end end def set_translation(locale, src_str, trans_str=None, enc='utf-8') if trans_str && trans_str != None trans_str = Tk.UTF8_String(_toUTF8(trans_str, enc)) Tk.UTF8_String(@namespace.eval{ - tk_call_without_enc('::msgcat::mcset', - locale, - _get_eval_string(src_str, true), - trans_str) + ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}} {#{trans_str}}") }) else Tk.UTF8_String(@namespace.eval{ - tk_call_without_enc('::msgcat::mcset', - locale, - _get_eval_string(src_str, true))}) + ip_eval_without_enc("::msgcat::mcset {#{locale}} {#{_get_eval_string(src_str, true)}}") + }) end end @@ -262,12 +263,13 @@ class TkMsgCatalog < TkObject trans_list.each{|src, trans| if trans && trans != None list << _get_eval_string(src, true) - list << Tk.UTF8_Stirng(_toUTF8(trans, enc)) + list << Tk.UTF8_String(_toUTF8(trans, enc)) else list << _get_eval_string(src, true) << '' end } - number(tk_call_without_enc('::msgcat::mcmset', locale, list)) + #number(tk_call_without_enc('::msgcat::mcmset', locale, list)) + number(ip_eval_without_enc("::msgcat::mcmset {#{locale}} {#{_get_eval_string(list)}}")) end def set_translation_list(locale, trans_list, enc='utf-8') # trans_list ::= [ [src, trans], [src, trans], ... ] @@ -281,7 +283,8 @@ class TkMsgCatalog < TkObject end } number(@namespace.eval{ - tk_call_without_enc('::msgcat::mcmset', locale, list) + #tk_call_without_enc('::msgcat::mcmset', locale, list) + ip_eval_without_enc("::msgcat::mcmset {#{locale}} {#{_get_eval_string(list)}}") }) end diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb index 4af891995e..0119ba5ef7 100644 --- a/ext/tk/lib/tk/namespace.rb +++ b/ext/tk/lib/tk/namespace.rb @@ -325,12 +325,7 @@ class TkNamespace < TkObject def code(script = Proc.new) if script.kind_of?(String) cmd = proc{|*args| - if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! - obj = ScopeArgs.new(@fullname,*args) - ret = obj.instance_exec(obj, script) - else - ret = ScopeArgs.new(@fullname,*args).instance_eval(script) - end + ret = ScopeArgs.new(@fullname,*args).instance_eval(script) id = ret.object_id TkNamespace::Tk_NsCode_RetObjID_TBL[id] = ret id diff --git a/ext/tk/lib/tkextlib/tktable/tktable.rb b/ext/tk/lib/tkextlib/tktable/tktable.rb index bc7a6c9a2e..f7074655ed 100644 --- a/ext/tk/lib/tkextlib/tktable/tktable.rb +++ b/ext/tk/lib/tkextlib/tktable/tktable.rb @@ -70,7 +70,7 @@ module Tk::TkTable::ConfigMethod private :__item_strval_optkeys def __item_val2ruby_optkeys(id) # { key=>method, ... } - super(id).update('window'=>proc{|v| window(v)}) + super(id).update('window'=>proc{|k,v| window(v)}) end private :__item_val2ruby_optkeys diff --git a/ext/tk/sample/demos-en/tree.rb b/ext/tk/sample/demos-en/tree.rb index cd62ba8c9b..69154ee076 100644 --- a/ext/tk/sample/demos-en/tree.rb +++ b/ext/tk/sample/demos-en/tree.rb @@ -67,7 +67,7 @@ def populate_tree(tree, node) path = tree.get(node, :fullpath) tree.delete(tree.children(node)) Dir.glob("#{path}/*").sort.each{|f| - type = File.ftype(f) + type = File.ftype(f) rescue nil id = tree.insert(node, :end, :text=>File.basename(f), :values=>[f, type]).id if type == 'directory' diff --git a/ext/tk/sample/demos-en/widget b/ext/tk/sample/demos-en/widget index e6510c7e45..3778929d9c 100644 --- a/ext/tk/sample/demos-en/widget +++ b/ext/tk/sample/demos-en/widget @@ -683,7 +683,7 @@ def eval_samplecode(code, file=nil) end } } - Tk.update + Tk.update rescue nil end # invoke -- @@ -699,7 +699,7 @@ def invoke(txt, idx) cursor = txt.cget('cursor') txt.cursor('watch') - Tk.update + Tk.update rescue nil # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding) # Tk.update eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb') @@ -1058,7 +1058,7 @@ if ARGV[0] == '-n' no_launcher = true if ARGV.size > 0 else # show the root widget to make it lower then demo windows - Tk.update + Tk.update rescue nil end ARGV.each{|cmd| if cmd =~ /(.*).rb/ diff --git a/ext/tk/sample/demos-jp/tree.rb b/ext/tk/sample/demos-jp/tree.rb index 00d715282b..f6855445ca 100644 --- a/ext/tk/sample/demos-jp/tree.rb +++ b/ext/tk/sample/demos-jp/tree.rb @@ -68,7 +68,7 @@ def populate_tree(tree, node) path = tree.get(node, :fullpath) tree.delete(tree.children(node)) Dir.glob("#{path}/*").sort.each{|f| - type = File.ftype(f) + type = File.ftype(f) rescue nil id = tree.insert(node, :end, :text=>File.basename(f), :values=>[f, type]).id if type == 'directory' diff --git a/ext/tk/sample/demos-jp/widget b/ext/tk/sample/demos-jp/widget index fc3c084e9a..ae91031fb6 100644 --- a/ext/tk/sample/demos-jp/widget +++ b/ext/tk/sample/demos-jp/widget @@ -740,7 +740,7 @@ def eval_samplecode(code, file=nil) end } } - Tk.update + Tk.update rescue nil end # テキスト上での click に対する動作 @@ -750,7 +750,7 @@ def invoke(txt, idx) cursor = txt.cget('cursor') txt.cursor('watch') - Tk.update + Tk.update rescue nil # eval(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, _null_binding) # Tk.update eval_samplecode(IO.readlines("#{[$demo_dir, tag[5..-1]].join(File::Separator)}.rb").join, tag[5..-1] + '.rb') @@ -1094,7 +1094,7 @@ if ARGV[0] == '-n' no_launcher = true if ARGV.size > 0 else # show the root widget to make it lower then demo windows - Tk.update + Tk.update rescue nil end ARGV.each{|cmd| if cmd =~ /(.*).rb/ diff --git a/ext/tk/sample/scrollframe.rb b/ext/tk/sample/scrollframe.rb index e340e1da3c..e9d8af7ebf 100644 --- a/ext/tk/sample/scrollframe.rb +++ b/ext/tk/sample/scrollframe.rb @@ -13,6 +13,8 @@ # require 'tk' +module Tk::RbWidget; end + class Tk::RbWidget::ScrollFrame < TkFrame include TkComposite diff --git a/ext/tk/stubs.c b/ext/tk/stubs.c index dd475c3455..636bae0801 100644 --- a/ext/tk/stubs.c +++ b/ext/tk/stubs.c @@ -83,8 +83,8 @@ _nativethread_consistency_check(ip) # define DL_SYM GetProcAddress # define TCL_INDEX 4 # define TK_INDEX 3 -# define TCL_NAME "tcl89%s" -# define TK_NAME "tk89%s" +# define TCL_NAME "tcl89" +# define TK_NAME "tk89" # undef DLEXT # define DLEXT ".dll" #elif defined HAVE_DLOPEN @@ -94,8 +94,8 @@ _nativethread_consistency_check(ip) # define DL_SYM dlsym # define TCL_INDEX 8 # define TK_INDEX 7 -# define TCL_NAME "libtcl8.9%s" -# define TK_NAME "libtk8.9%s" +# define TCL_NAME "libtcl8.9" +# define TK_NAME "libtk8.9" # if defined(__APPLE__) && defined(__MACH__) /* Mac OS X */ # undef DLEXT # define DLEXT ".dylib" @@ -116,7 +116,6 @@ ruby_open_tcl_dll(appname) void (*p_Tcl_FindExecutable)(const char *); int n; char *ruby_tcl_dll = 0; - char tcl_name[20]; if (tcl_dll) return TCLTK_STUBS_OK; @@ -127,7 +126,7 @@ ruby_open_tcl_dll(appname) if (ruby_tcl_dll) { tcl_dll = (DL_HANDLE)DL_OPEN(ruby_tcl_dll); } else { - snprintf(tcl_name, sizeof tcl_name, TCL_NAME, DLEXT); + char tcl_name[] = TCL_NAME DLEXT; /* examine from 8.9 to 8.1 */ for (n = '9'; n > '0'; n--) { tcl_name[TCL_INDEX] = n; @@ -162,7 +161,6 @@ ruby_open_tk_dll() { int n; char *ruby_tk_dll = 0; - char tk_name[20]; if (!tcl_dll) { /* int ret = ruby_open_tcl_dll(RSTRING_PTR(rb_argv0)); */ @@ -176,7 +174,7 @@ ruby_open_tk_dll() if (ruby_tk_dll) { tk_dll = (DL_HANDLE)DL_OPEN(ruby_tk_dll); } else { - snprintf(tk_name, sizeof tk_name, TK_NAME, DLEXT); + char tk_name[] = TK_NAME DLEXT; /* examine from 8.9 to 8.1 */ for (n = '9'; n > '0'; n--) { tk_name[TK_INDEX] = n; diff --git a/ext/tk/tcltklib.c b/ext/tk/tcltklib.c index 312b0c05eb..068babfe93 100644 --- a/ext/tk/tcltklib.c +++ b/ext/tk/tcltklib.c @@ -839,15 +839,14 @@ create_ip_exc(interp, exc, fmt, va_alist) #endif { va_list args; - char buf[BUFSIZ]; + VALUE msg; VALUE einfo; struct tcltkip *ptr = get_ip(interp); va_init_list(args,fmt); - vsnprintf(buf, BUFSIZ, fmt, args); - buf[BUFSIZ - 1] = '\0'; + msg = rb_vsprintf(fmt, args); va_end(args); - einfo = rb_exc_new2(exc, buf); + einfo = rb_exc_new3(exc, msg); rb_ivar_set(einfo, ID_at_interp, interp); if (ptr) { Tcl_ResetResult(ptr->ip); @@ -6641,7 +6640,7 @@ ip_make_safe_core(interp, argc, argv) if (Tcl_MakeSafe(ptr->ip) == TCL_ERROR) { /* return rb_exc_new2(rb_eRuntimeError, Tcl_GetStringResult(ptr->ip)); */ - return create_ip_exc(interp, rb_eRuntimeError, + return create_ip_exc(interp, rb_eRuntimeError, "%s", Tcl_GetStringResult(ptr->ip)); } @@ -9331,7 +9330,7 @@ ip_get_variable2_core(interp, argc, argv) volatile VALUE exc; /* exc = rb_exc_new2(rb_eRuntimeError, Tcl_GetStringResult(ptr->ip)); */ - exc = create_ip_exc(interp, rb_eRuntimeError, + exc = create_ip_exc(interp, rb_eRuntimeError, "%s", Tcl_GetStringResult(ptr->ip)); /* Tcl_Release(ptr->ip); */ rbtk_release_ip(ptr); @@ -9470,7 +9469,7 @@ ip_set_variable2_core(interp, argc, argv) volatile VALUE exc; /* exc = rb_exc_new2(rb_eRuntimeError, Tcl_GetStringResult(ptr->ip)); */ - exc = create_ip_exc(interp, rb_eRuntimeError, + exc = create_ip_exc(interp, rb_eRuntimeError, "%s", Tcl_GetStringResult(ptr->ip)); /* Tcl_Release(ptr->ip); */ rbtk_release_ip(ptr); @@ -9590,7 +9589,7 @@ ip_unset_variable2_core(interp, argc, argv) if (FIX2INT(flag) & TCL_LEAVE_ERR_MSG) { /* return rb_exc_new2(rb_eRuntimeError, Tcl_GetStringResult(ptr->ip)); */ - return create_ip_exc(interp, rb_eRuntimeError, + return create_ip_exc(interp, rb_eRuntimeError, "%s", Tcl_GetStringResult(ptr->ip)); } return Qfalse; |