aboutsummaryrefslogtreecommitdiffstats
path: root/ext/tk/lib
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-05 05:56:31 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-07-05 05:56:31 +0000
commite3849ae9878e78fd089d117f5bd2cb787a62e941 (patch)
tree4eb42beb78e9a7d85198c12948ac76486ccd4818 /ext/tk/lib
parent6556fb4f00f041e06cd53ca4eab20967c02ffee8 (diff)
downloadruby-e3849ae9878e78fd089d117f5bd2cb787a62e941.tar.gz
* ext/tk/tcltklib.c: bug fix on treating Unicode strings.
* ext/tk/tcltklib.c: add methods to treat encoding mode. * ext/tk/MANUAL_tcltklib.eng: add description of TclTkLib#encoding, encoding_system, and so on. * ext/tk/MANUAL_tcltklib.eucj: ditto. * ext/tk/tkutil/tkutil.c: fail to create a Tcl's list string from an array including multiple kind of encoded strings. * ext/tk/lib/tk.rb: ditto. * ext/tk/lib/multi-tk.rb: 2nd arg of _{to|from}UTF8 is omissible. * ext/tk/lib/remote-tk.rb: ditto. * ext/tk/lib/tk.rb: override TclTkLib#encoding and encoding= to use TkCore::INTERP.encoding and encoding=. * ext/tk/lib/tk.rb: when "require 'tk'" and $KCODE=='NONE', check DEFAULT_TK_ENCODING to decide Ruby/Tk's system encoding mode. * ext/tk/lib/tk/encodedstr.rb: check both of Tk.encoding and Tk.encoding_system. Tk.encoding has higher priority. * ext/tk/lib/tk/optiondb.rb: ditto. * ext/tk/lib/tk/spinbox.rb: ditto. * ext/tk/lib/tk/validation.rb: ditto. * ext/tk/lib/tk/namespace.rb: arguemnts for TclTkIp#_merge_tklist should be UTF-8 strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8722 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib')
-rw-r--r--ext/tk/lib/multi-tk.rb8
-rw-r--r--ext/tk/lib/remote-tk.rb4
-rw-r--r--ext/tk/lib/tk.rb51
-rw-r--r--ext/tk/lib/tk/encodedstr.rb8
-rw-r--r--ext/tk/lib/tk/namespace.rb12
-rw-r--r--ext/tk/lib/tk/optiondb.rb2
-rw-r--r--ext/tk/lib/tk/spinbox.rb3
-rw-r--r--ext/tk/lib/tk/validation.rb3
8 files changed, 69 insertions, 22 deletions
diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb
index 6d048e91bc..e8bbf67de1 100644
--- a/ext/tk/lib/multi-tk.rb
+++ b/ext/tk/lib/multi-tk.rb
@@ -1730,11 +1730,11 @@ class << MultiTkIp
__getip._invoke_with_enc(*args)
end
- def _toUTF8(str, encoding)
+ def _toUTF8(str, encoding=nil)
__getip._toUTF8(str, encoding)
end
- def _fromUTF8(str, encoding)
+ def _fromUTF8(str, encoding=nil)
__getip._fromUTF8(str, encoding)
end
@@ -2119,11 +2119,11 @@ class MultiTkIp
@interp._invoke_with_enc(*args)
end
- def _toUTF8(str, encoding)
+ def _toUTF8(str, encoding=nil)
@interp._toUTF8(str, encoding)
end
- def _fromUTF8(str, encoding)
+ def _fromUTF8(str, encoding=nil)
@interp._fromUTF8(str, encoding)
end
diff --git a/ext/tk/lib/remote-tk.rb b/ext/tk/lib/remote-tk.rb
index bb2a2c114a..ed7f75b336 100644
--- a/ext/tk/lib/remote-tk.rb
+++ b/ext/tk/lib/remote-tk.rb
@@ -321,11 +321,11 @@ class RemoteTkIp
_appsend(true, false, *args)
end
- def _toUTF8(str, encoding)
+ def _toUTF8(str, encoding=nil)
@interp._toUTF8(str, encoding)
end
- def _fromUTF8(str, encoding)
+ def _fromUTF8(str, encoding=nil)
@interp._fromUTF8(str, encoding)
end
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb
index 9daee2de54..4267b42a3e 100644
--- a/ext/tk/lib/tk.rb
+++ b/ext/tk/lib/tk.rb
@@ -309,19 +309,48 @@ if USE_TCLs_LIST_FUNCTIONS
def array2tk_list(ary, enc=nil)
return "" if ary.size == 0
+ sys_enc = TkCore::INTERP.encoding
+ sys_enc = TclTkLib.encoding_system unless sys_enc
+
+ dst_enc = (enc == nil)? sys_enc: enc
+
dst = ary.collect{|e|
if e.kind_of? Array
- array2tk_list(e, enc)
+ s = array2tk_list(e, enc)
elsif e.kind_of? Hash
tmp_ary = []
#e.each{|k,v| tmp_ary << k << v }
e.each{|k,v| tmp_ary << "-#{_get_eval_string(k)}" << v }
- array2tk_list(tmp_ary, enc)
+ s = array2tk_list(tmp_ary, enc)
else
- _get_eval_string(e, enc)
+ s = _get_eval_string(e, enc)
+ end
+
+ if dst_enc != true && dst_enc != false
+ if (s_enc = s.instance_variable_get(:@encoding))
+ s_enc = s_enc.to_s
+ else
+ s_enc = sys_enc
+ end
+ dst_enc = true if s_enc != dst_enc
end
+
+ s
}
- TkCore::INTERP._merge_tklist(*dst)
+
+ if sys_enc && dst_enc
+ dst.map!{|s| _toUTF8(s)}
+ ret = TkCore::INTERP._merge_tklist(*dst)
+ if dst_enc.kind_of?(String)
+ ret = _fromUTF8(ret, dst_enc)
+ ret.instance_variable_set(:@encoding, dst_enc)
+ else
+ ret.instance_variable_set(:@encoding, 'utf-8')
+ end
+ ret
+ else
+ TkCore::INTERP._merge_tklist(*dst)
+ end
end
else
@@ -2163,6 +2192,15 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
=end
end
+ module TclTkLib
+ def self.encoding=(name)
+ TkCore::INTERP.encoding = name
+ end
+ def self.encoding
+ TkCore::INTERP.encoding
+ end
+ end
+
module Tk
module Encoding
extend Encoding
@@ -2231,6 +2269,9 @@ if (/^(8\.[1-9]|9\.|[1-9][0-9])/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK)
Tk.encoding = 'utf-8'
Tk.encoding_system = 'utf-8'
else # NONE
+ if defined? DEFAULT_TK_ENCODING
+ Tk.encoding_system = DEFAULT_TK_ENCODING
+ end
begin
Tk.encoding = Tk.encoding_system
rescue StandardError, NameError
@@ -4153,7 +4194,7 @@ end
#Tk.freeze
module Tk
- RELEASE_DATE = '2005-06-24'.freeze
+ RELEASE_DATE = '2005-07-05'.freeze
autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable'
diff --git a/ext/tk/lib/tk/encodedstr.rb b/ext/tk/lib/tk/encodedstr.rb
index aed0e7524e..797e514a4c 100644
--- a/ext/tk/lib/tk/encodedstr.rb
+++ b/ext/tk/lib/tk/encodedstr.rb
@@ -67,9 +67,13 @@ module Tk
def initialize(str, enc = nil)
super(str)
+ # @encoding = ( enc ||
+ # ((self.class::Encoding)?
+ # self.class::Encoding : Tk.encoding_system) )
@encoding = ( enc ||
- ((self.class::Encoding)?
- self.class::Encoding : Tk.encoding_system) )
+ ((self.class::Encoding)?
+ self.class::Encoding :
+ ((Tk.encoding)? Tk.encoding : Tk.encoding_system) ) )
end
attr_reader :encoding
diff --git a/ext/tk/lib/tk/namespace.rb b/ext/tk/lib/tk/namespace.rb
index e0ef7c39dd..85a94372b9 100644
--- a/ext/tk/lib/tk/namespace.rb
+++ b/ext/tk/lib/tk/namespace.rb
@@ -115,19 +115,19 @@ class TkNamespace < TkObject
# alias __tk_call_with_enc tk_call_with_enc
def tk_call(*args)
#super('namespace', 'eval', @namespace, *args)
- args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''}
+ args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @namespace,
TkCore::INTERP._merge_tklist(*args))
end
def tk_call_without_enc(*args)
#super('namespace', 'eval', @namespace, *args)
- args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''}
+ args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @namespace,
TkCore::INTERP._merge_tklist(*args))
end
def tk_call_with_enc(*args)
#super('namespace', 'eval', @namespace, *args)
- args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''}
+ args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @namespace,
TkCore::INTERP._merge_tklist(*args))
end
@@ -159,19 +159,19 @@ class TkNamespace < TkObject
alias __tk_call_with_enc tk_call_with_enc
def tk_call(*args)
#super('namespace', 'eval', @fullname, *args)
- args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''}
+ args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
def tk_call_without_enc(*args)
#super('namespace', 'eval', @fullname, *args)
- args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''}
+ args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
def tk_call_with_enc(*args)
#super('namespace', 'eval', @fullname, *args)
- args = args.collect{|arg| (s = _get_eval_string(arg))? s: ''}
+ args = args.collect{|arg| (s = _get_eval_string(arg, true))? s: ''}
super('namespace', 'eval', @fullname,
TkCore::INTERP._merge_tklist(*args))
end
diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb
index fe79de123c..a806f3971d 100644
--- a/ext/tk/lib/tk/optiondb.rb
+++ b/ext/tk/lib/tk/optiondb.rb
@@ -44,7 +44,7 @@ module TkOptionDB
"can't call 'TkOptionDB.read_entries' on a safe interpreter"
end
- i_enc = Tk.encoding()
+ i_enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system)
unless f_enc
f_enc = i_enc
diff --git a/ext/tk/lib/tk/spinbox.rb b/ext/tk/lib/tk/spinbox.rb
index fe50d85e43..ac84e06cb3 100644
--- a/ext/tk/lib/tk/spinbox.rb
+++ b/ext/tk/lib/tk/spinbox.rb
@@ -25,7 +25,8 @@ class TkSpinbox<TkEntry
[ ?w, TkComm.method(:window) ],
[ ?e, proc{|val|
- enc = Tk.encoding
+ #enc = Tk.encoding
+ enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system)
if enc
Tk.fromUTF8(TkComm::string(val), enc)
else
diff --git a/ext/tk/lib/tk/validation.rb b/ext/tk/lib/tk/validation.rb
index eeb0163ee4..6755eef05f 100644
--- a/ext/tk/lib/tk/validation.rb
+++ b/ext/tk/lib/tk/validation.rb
@@ -226,7 +226,8 @@ class TkValidateCommand
[ ?w, TkComm.method(:window) ],
[ ?e, proc{|val|
- enc = Tk.encoding
+ #enc = Tk.encoding
+ enc = ((Tk.encoding)? Tk.encoding : Tk.encoding_system)
if enc
Tk.fromUTF8(TkComm::string(val), enc)
else