ruby-changes:35937
From: nagai <ko1@a...>
Date: Sun, 19 Oct 2014 17:38:45 +0900 (JST)
Subject: [ruby-changes:35937] nagai:r48018 (trunk): * ext/tk/tcltklib.c: support Tcl/Tk8.6.
nagai 2014-10-19 17:38:35 +0900 (Sun, 19 Oct 2014) New Revision: 48018 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48018 Log: * ext/tk/tcltklib.c: support Tcl/Tk8.6. * ext/tk/lib/tk.rb: ditto. * ext/tk/extconf.rb: ditto. * ext/tk/lib/tk_mac.rb: add new features of Tcl/Tk8.6. * ext/tk/lib/tkextlib/tile/treeview.rb: ditto. * ext/tk/lib/tkextlib/tile/fontchooser.rb: add an alias. * ext/tk/lib/tk/autoload.rb: ditto. * ext/tk/lib/tkextlib/tcllib/validator.rb: add a new feature of tklib extension. * ext/tk/lib/tkextlib/tkimg/dted.rb: a new supported format of Img extension. * ext/tk/lib/tkextlib/tkimg/raw.rb: ditto. Added files: trunk/ext/tk/lib/tk/tk_mac.rb trunk/ext/tk/lib/tkextlib/tcllib/validator.rb trunk/ext/tk/lib/tkextlib/tkimg/dted.rb trunk/ext/tk/lib/tkextlib/tkimg/raw.rb Modified files: trunk/ext/tk/extconf.rb trunk/ext/tk/lib/tk/autoload.rb trunk/ext/tk/lib/tk/fontchooser.rb trunk/ext/tk/lib/tk.rb trunk/ext/tk/lib/tkextlib/tile/treeview.rb trunk/ext/tk/tcltklib.c Index: ext/tk/tcltklib.c =================================================================== --- ext/tk/tcltklib.c (revision 48017) +++ ext/tk/tcltklib.c (revision 48018) @@ -6008,6 +6008,9 @@ ip_rb_replaceSlaveTkCmdsCommand(clientDa https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6008 return TCL_OK; } +#ifndef ORIG_NAMESPACE_CMD +#define ORIG_NAMESPACE_CMD "__orig_namespace_command__" +#endif #if TCL_MAJOR_VERSION >= 8 static int ip_rbNamespaceObjCmd _((ClientData, Tcl_Interp *, int, @@ -6026,8 +6029,8 @@ ip_rbNamespaceObjCmd(clientData, interp, https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6029 DUMP2("objc = %d", objc); DUMP2("objv[0] = '%s'", Tcl_GetString(objv[0])); DUMP2("objv[1] = '%s'", Tcl_GetString(objv[1])); - if (!Tcl_GetCommandInfo(interp, "__orig_namespace_command__", &(info))) { - DUMP1("fail to get __orig_namespace_command__"); + if (!Tcl_GetCommandInfo(interp, ORIG_NAMESPACE_CMD, &(info))) { + DUMP1("fail to get "ORIG_NAMESPACE_CMD); Tcl_ResetResult(interp); Tcl_AppendResult(interp, "invalid command name \"namespace\"", (char*)NULL); @@ -6045,7 +6048,7 @@ ip_rbNamespaceObjCmd(clientData, interp, https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6048 /* Tcl8.6 or later */ int i; Tcl_Obj **cp_objv; - char org_ns_cmd_name[] = "__orig_namespace_command__"; + char org_ns_cmd_name[] = ORIG_NAMESPACE_CMD; DUMP1("call a native-object-proc for tcl8.6 or later"); cp_objv = RbTk_ALLOC_N(Tcl_Obj *, (objc + 1)); @@ -6056,7 +6059,8 @@ ip_rbNamespaceObjCmd(clientData, interp, https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6059 } cp_objv[objc] = (Tcl_Obj *)NULL; - ret = Tcl_EvalObjv(interp, objc, cp_objv, TCL_EVAL_DIRECT); + /* ret = Tcl_EvalObjv(interp, objc, cp_objv, TCL_EVAL_DIRECT); */ + ret = Tcl_EvalObjv(interp, objc, cp_objv, 0); ckfree((char*)cp_objv); #endif @@ -6115,17 +6119,17 @@ ip_wrap_namespace_command(interp) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L6119 } if (orig_info.isNativeObjectProc) { - Tcl_CreateObjCommand(interp, "__orig_namespace_command__", + Tcl_CreateObjCommand(interp, ORIG_NAMESPACE_CMD, orig_info.objProc, orig_info.objClientData, orig_info.deleteProc); } else { - Tcl_CreateCommand(interp, "__orig_namespace_command__", + Tcl_CreateCommand(interp, ORIG_NAMESPACE_CMD, orig_info.proc, orig_info.clientData, orig_info.deleteProc); } #else /* tcl8.6 or later */ - Tcl_Eval(interp, "rename namespace __orig_namespace_command__"); + Tcl_Eval(interp, "rename namespace "ORIG_NAMESPACE_CMD); #endif @@ -8493,16 +8497,26 @@ invoke_tcl_proc(arg) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L8497 #endif { struct invoke_info *inf = (struct invoke_info *)arg; +#if TCL_MAJOR_VERSION >= 8 && TCL_MINOR_VERSION < 6 int i, len; -#if TCL_MAJOR_VERSION >= 8 int argc = inf->objc; char **argv = (char **)NULL; #endif DUMP1("call invoke_tcl_proc"); +#if TCL_MAJOR_VERSION > 8 || (TCL_MAJOR_VERSION == 8 && TCL_MINOR_VERSION >= 6) + /* Tcl/Tk 8.6 or later */ + + /* eval */ + inf->ptr->return_value = Tcl_EvalObjv(inf->ptr->ip, inf->objc, inf->objv, TCL_EVAL_DIRECT); + /* inf->ptr->return_value = Tcl_EvalObjv(inf->ptr->ip, inf->objc, inf->objv, 0); */ + +#else /* Tcl/Tk 7.x, 8.0 -- 8.5 */ + /* memory allocation for arguments of this command */ -#if TCL_MAJOR_VERSION >= 8 +#if TCL_MAJOR_VERSION == 8 + /* Tcl/Tk 8.0 -- 8.5 */ if (!inf->cmdinfo.isNativeObjectProc) { DUMP1("called proc is not a native-obj-proc"); /* string interface */ @@ -8522,7 +8536,8 @@ invoke_tcl_proc(arg) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L8536 Tcl_ResetResult(inf->ptr->ip); /* Invoke the C procedure */ -#if TCL_MAJOR_VERSION >= 8 +#if TCL_MAJOR_VERSION == 8 + /* Tcl/Tk 8.0 -- 8.5 */ if (inf->cmdinfo.isNativeObjectProc) { DUMP1("call tcl_proc as a native-obj-proc"); inf->ptr->return_value @@ -8532,7 +8547,8 @@ invoke_tcl_proc(arg) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L8547 else #endif { -#if TCL_MAJOR_VERSION >= 8 +#if TCL_MAJOR_VERSION == 8 + /* Tcl/Tk 8.0 -- 8.5 */ DUMP1("call tcl_proc as not a native-obj-proc"); inf->ptr->return_value = (*(inf->cmdinfo.proc))(inf->cmdinfo.clientData, inf->ptr->ip, @@ -8556,6 +8572,8 @@ invoke_tcl_proc(arg) https://github.com/ruby/ruby/blob/trunk/ext/tk/tcltklib.c#L8572 #endif } +#endif /* Tcl/Tk 8.6 or later || Tcl 7.x, 8.0 -- 8.5 */ + DUMP1("end of invoke_tcl_proc"); return Qnil; } Index: ext/tk/lib/tk.rb =================================================================== --- ext/tk/lib/tk.rb (revision 48017) +++ ext/tk/lib/tk.rb (revision 48018) @@ -1309,8 +1309,12 @@ EOS https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk.rb#L1309 end unless interp.deleted? - #Thread.current[:status].value = TclTkLib.mainloop(false) - Thread.current[:status].value = interp.mainloop(false) + begin + #Thread.current[:status].value = TclTkLib.mainloop(false) + Thread.current[:status].value = interp.mainloop(false) + rescue Exception=>e + puts "ignore exception on interp: #{e.inspect}\n" if $DEBUG + end end ensure @@ -1569,7 +1573,15 @@ EOS https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk.rb#L1573 EOL =end - at_exit{ INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) } + if !WITH_RUBY_VM || RUN_EVENTLOOP_ON_MAIN_THREAD ### check Ruby 1.9 !!!!!!! + at_exit{ INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) } + else + at_exit{ + Tk.root.destroy + INTERP.remove_tk_procs(TclTkLib::FINALIZE_PROC_NAME) + INTERP_THREAD.kill.join + } + end EventFlag = TclTkLib::EventFlag @@ -5197,6 +5209,8 @@ class TkWindow<TkObject https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk.rb#L5209 TkWinfo.exist?(self) end + alias subcommand tk_send + def bind_class @db_class || self.class() end @@ -5742,7 +5756,7 @@ TkWidget = TkWindow https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk.rb#L5756 #Tk.freeze module Tk - RELEASE_DATE = '2010-06-03'.freeze + RELEASE_DATE = '2014-10-19'.freeze autoload :AUTO_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable' Index: ext/tk/lib/tkextlib/tcllib/validator.rb =================================================================== --- ext/tk/lib/tkextlib/tcllib/validator.rb (revision 0) +++ ext/tk/lib/tkextlib/tcllib/validator.rb (revision 48018) @@ -0,0 +1,65 @@ https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tkextlib/tcllib/validator.rb#L1 +# +# tkextlib/tcllib/validator.rb +# by Hidetoshi NAGAI (nagai@a...) +# +# * Part of tcllib extension +# * Provides a unified validation API +# + +require 'tk' +require 'tkextlib/tcllib.rb' + +# TkPackage.require('widget::validator', '0.1') +TkPackage.require('widget::validator') + +module Tk::Tcllib + module Validator + PACKAGE_NAME = 'widget::validator'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('widget::validator') + rescue + '' + end + end + end +end + +module Tk::Tcllib::Validator + extend TkCore + + def self.attach(widget, color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'attach', widget, color, cmd) + nil + end + + def self.detach(widget) + tk_call_without_enc('::widget::validator', 'detach', widget) + nil + end + + def self.validate(widget) + tk_call_without_enc('::widget::validator', 'validate', widget) + nil + end + + def attach_validator(color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'attach', @path, color, cmd) + self + end + + def detach_validator(color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'detach', @path) + self + end + + def invoke_validator(color, cmd=Proc.new) + tk_call_without_enc('::widget::validator', 'validate', @path) + self + end + alias validate_validator invoke_validator +end Index: ext/tk/lib/tkextlib/tkimg/dted.rb =================================================================== --- ext/tk/lib/tkextlib/tkimg/dted.rb (revision 0) +++ ext/tk/lib/tkextlib/tkimg/dted.rb (revision 48018) @@ -0,0 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tkextlib/tkimg/dted.rb#L1 +# +# TkImg - format 'DTED' +# by Hidetoshi NAGAI (nagai@a...) +# +require 'tk' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/tkimg/setup.rb' + +# TkPackage.require('img::dted', '1.4') +TkPackage.require('img::dted') + +module Tk + module Img + module DTED + PACKAGE_NAME = 'img::dted'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('img::dted') + rescue + '' + end + end + end + end +end Index: ext/tk/lib/tkextlib/tkimg/raw.rb =================================================================== --- ext/tk/lib/tkextlib/tkimg/raw.rb (revision 0) +++ ext/tk/lib/tkextlib/tkimg/raw.rb (revision 48018) @@ -0,0 +1,33 @@ https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tkextlib/tkimg/raw.rb#L1 +# +# TkImg - format 'Raw Data' +# by Hidetoshi NAGAI (nagai@a...) +# +require 'tk' + +# call setup script for general 'tkextlib' libraries +require 'tkextlib/setup.rb' + +# call setup script +require 'tkextlib/tkimg/setup.rb' + +# TkPackage.require('img::raw', '1.4') +TkPackage.require('img::raw') + +module Tk + module Img + module Raw + PACKAGE_NAME = 'img::raw'.freeze + def self.package_name + PACKAGE_NAME + end + + def self.package_version + begin + TkPackage.require('img::raw') + rescue + '' + end + end + end + end +end Index: ext/tk/lib/tkextlib/tile/treeview.rb =================================================================== --- ext/tk/lib/tkextlib/tile/treeview.rb (revision 48017) +++ ext/tk/lib/tkextlib/tile/treeview.rb (revision 48018) @@ -986,6 +986,18 @@ class Tk::Tile::Treeview::Tag < TkObject https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tkextlib/tile/treeview.rb#L986 end alias added? tag_has? + def tag_has + @t.tag_has(@id) + end + + def add(*items) + @t.tag_add(@id, *items)) + end + + def remove(*items) + @t.tag_remove(@id, *items)) + end + def bind(seq, *args) if TkComm._callback_entry?(args[0]) || !block_given? cmd = args.shift @@ -1299,6 +1311,24 @@ class Tk::Tile::Treeview < TkWindow https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tkextlib/tile/treeview.rb#L1311 _bindinfo([@path, 'tag', 'bind', tag], context) end alias tagbindinfo tag_bindinfo + + def tag_names + tk_split_simplelist(tk_send('tag', 'names')).collect{|id| + Tk::Tile::Treeview::Tag.id2obj(self, id) + } + end + + def tag_add(tag, *items) + fail ArgumentError, "no target items" if items.empty? + tk_send('tag', 'add', tagid(tag), *(items.collect{|item| tagid(item)})) + self + end + + def tag_remove(tag, *items) + tk_send('tag', 'remove', tagid(tag), *(items.collect{|item| tagid(item)})) + self + end + end #Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Treeview, :TkTreeview) Index: ext/tk/lib/tk/fontchooser.rb =================================================================== --- ext/tk/lib/tk/fontchooser.rb (revision 48017) +++ ext/tk/lib/tk/fontchooser.rb (revision 48018) @@ -8,6 +8,10 @@ module TkFont::Chooser https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk/fontchooser.rb#L8 extend TkCore end +module Tk + Fontchooser = TkFont::Chooser +end + class << TkFont::Chooser def method_missing(id, *args) name = id.id2name Index: ext/tk/lib/tk/tk_mac.rb =================================================================== --- ext/tk/lib/tk/tk_mac.rb (revision 0) +++ ext/tk/lib/tk/tk_mac.rb (revision 48018) @@ -0,0 +1,158 @@ https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk/tk_mac.rb#L1 +# +# tk/tk_mac.rb : Access Mac-Specific functionality on OS X from Tk +# (supported by Tk8.6 or later) +# +# ATTENTION !! +# This is NOT TESTED. Because I have no test-environment. +# +require 'tk' + +module Tk + module Mac + end +end + +module Tk::Mac + extend TkCore + + # event handler callbacks + def self.def_ShowPreferences(cmd=Proc.new) + ip_eval("proc ::tk::mac::ShowPreferences {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OpenApplication(cmd=Proc.new) + ip_eval("proc ::tk::mac::OpenApplication {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_ReopenApplication(cmd=Proc.new) + ip_eval("proc ::tk::mac::ReopenApplication {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OpenDocument(cmd=Proc.new) + ip_eval("proc ::tk::mac::OpenDocument {args} { eval #{install_cmd(cmd)} $args }") + nil + end + + def self.def_PrintDocument(cmd=Proc.new) + ip_eval("proc ::tk::mac::PrintDocument {args} { eval #{install_cmd(cmd)} $args }") + nil + end + + def self.def_Quit(cmd=Proc.new) + ip_eval("proc ::tk::mac::Quit {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OnHide(cmd=Proc.new) + ip_eval("proc ::tk::mac::OnHide {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_OnShow(cmd=Proc.new) + ip_eval("proc ::tk::mac::OnShow {} { #{install_cmd(cmd)} }") + nil + end + + def self.def_ShowHelp(cmd=Proc.new) + ip_eval("proc ::tk::mac::ShowHelp {} { #{install_cmd(cmd)} }") + nil + end + + + # additional dialogs + def self.standardAboutPanel + tk_call('::tk::mac::standardAboutPanel') + nil + end + + + # system configuration + def self.useCompatibilityMetrics(mode) + tk_call('::tk::mac::useCompatibilityMetrics', mode) + nil + end + + def self.CGAntialiasLimit(limit) + tk_call('::tk::mac::CGAntialiasLimit', limit) + nil + end + + def self.antialiasedtext(num) + tk_call('::tk::mac::antialiasedtext', num) + nil + end + + def self.useThemedToplevel(mode) + tk_call('::tk::mac::useThemedToplevel', mode) + nil + end + +end + +class Tk::Mac::IconBitmap < TkImage + TkCommandNames = ['::tk::mac::iconBitmap'].freeze + + def self.new(width, height, keys) + if keys.kind_of?(Hash) + name = nil + if keys.key?(:imagename) + name = keys[:imagename] + elsif keys.key?('imagename') + name = keys['imagename'] + end + if name + if name.kind_of?(TkImage) + obj = name + else + name = _get_eval_string(name) + obj = nil + Tk_IMGTBL.mutex.synchronize{ + obj = Tk_IMGTBL[name] + } + end + if obj + if !(keys[:without_creating] || keys['without_creating']) + keys = _symbolkey2str(keys) + keys.delete('imagename') + keys.delete('without_creating') + obj.instance_eval{ + tk_call_without_enc('::tk::mac::iconBitmap', + @path, width, height, *hash_kv(keys, true)) + } + end + return obj + end + end + end + (obj = self.allocate).instance_eval{ + Tk_IMGTBL.mutex.synchronize{ + initialize(width, height, keys) + Tk_IMGTBL[@path] = self + } + } + obj + end + + def initialize(width, height, keys) + @path = nil + without_creating = false + if keys.kind_of?(Hash) + keys = _symbolkey2str(keys) + @path = keys.delete('imagename') + without_creating = keys.delete('without_creating') + end + unless @path + Tk_Image_ID.mutex.synchronize{ + @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_) + Tk_Image_ID[1].succ! + } + end + unless without_creating + tk_call_without_enc('::tk::mac::iconBitmap', + @path, width, height, *hash_kv(keys, true)) + end + end +end Index: ext/tk/lib/tk/autoload.rb =================================================================== --- ext/tk/lib/tk/autoload.rb (revision 48017) +++ ext/tk/lib/tk/autoload.rb (revision 48018) @@ -94,6 +94,8 @@ module Tk https://github.com/ruby/ruby/blob/trunk/ext/tk/lib/tk/autoload.rb#L94 autoload :Y_Scrollable, 'tk/scrollable' autoload :Scrollable, 'tk/scrollable' + autoload :Fontchooser, 'tk/fontchooser' + autoload :Wm, 'tk/wm' autoload :Wm_for_General, 'tk/wm' Index: ext/tk/extconf.rb =================================================================== --- ext/tk/extconf.rb (revision 48017) +++ ext/tk/extconf.rb (revision 48018) @@ -9,10 +9,10 @@ TkLib_Config['search_versions'] = https://github.com/ruby/ruby/blob/trunk/ext/tk/extconf.rb#L9 # %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.5 8.4 8.6] # Tcl/Tk8.6 support is experimental. + %w[8.6 8.5 8.4] TkLib_Config['unsupported_versions'] = - %w[8.8 8.7] # Tcl/Tk8.6 support is experimental. + %w[8.8 8.7] TkLib_Config['major_nums'] = '87' -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/