diff options
| author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-08-02 04:54:21 +0000 |
|---|---|---|
| committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-08-02 04:54:21 +0000 |
| commit | 2f592086532d3d9bb03288bd5d51a7baf46836df (patch) | |
| tree | 20a1bebec983543fb38b5809a75228ff1136a4a7 /ext/tk/lib/tk.rb | |
| parent | 672eb338535e5a7cb4395cd96c155d8de3c34cd3 (diff) | |
| download | ruby-2f592086532d3d9bb03288bd5d51a7baf46836df.tar.gz ruby-2f592086532d3d9bb03288bd5d51a7baf46836df.tar.xz ruby-2f592086532d3d9bb03288bd5d51a7baf46836df.zip | |
matz
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk.rb')
| -rw-r--r-- | ext/tk/lib/tk.rb | 92 |
1 files changed, 91 insertions, 1 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 4b1c21f40..d3b3714a2 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -311,7 +311,7 @@ module TkComm def install_bind(cmd, args=nil) if args - id = install_cmd(proc{|arg| + id = install_cmd(proc{|*arg| TkUtil.eval_cmd cmd, *arg }) id + " " + args @@ -784,6 +784,96 @@ module Tk end end +########################################### +# convert kanji string to/from utf-8 +########################################### +if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK + class TclTkIp + # from tkencoding.rb by ttate@jaist.ac.jp + alias __eval _eval + alias __invoke _invoke + private :__eval + private :__invoke + + attr_accessor :encoding + + def _eval(cmd) + if @encoding + _fromUTF8(__eval(_toUTF8(cmd, @encoding)), @encoding) + else + __eval(cmd) + end + end + + def _invoke(*cmds) + if @encoding + cmds = cmds.collect{|cmd| _toUTF8(cmd, @encoding)} + _fromUTF8(__invoke(*cmds), @encoding) + else + __invoke(*cmds) + end + end + end + + module Tk + def encoding=(name) + INTERP.encoding = name + end + + def encoding + INTERP.encoding + end + + def encoding_names + tk_split_simplelist(tk_call('encoding', 'names')) + end + + def encoding_system + tk_call('encoding', 'system') + end + + def encoding_system=(enc) + tk_call('encoding', 'system', enc) + end + end + + # estimate encoding + case $KCODE + when /^e/i # EUC + Tk.encoding = 'euc-jp' + when /^s/i # SJIS + Tk.encoding = 'shiftjis' + when /^u/i # UTF8 + Tk.encoding = 'utf-8' + else # NONE + begin + Tk.encoding = Tk.encoding_system + rescue StandardError, NameError + Tk.encoding = 'utf-8' + end + end + +else + # dummy methods + module Tk + def encoding=(name) + nil + end + def encoding + nil + end + def encoding_names + nil + end + def encoding_system + nil + end + def encoding_system=(enc) + nil + end + end +end + module TkBindCore def bind(context, cmd=Proc.new, args=nil) Tk.bind(to_eval, context, cmd, args) |
