* ext/tk/tkutil/tkutil.c: improve handling callback-subst-keys.

Now, support longnam-keys (e.g. '%CTT' on tkdnd-2.0; however, still
  not support tkdnd-2.0 on tkextlib), and symbols of parameters (e.g. 
  :widget=>'%W', :keycode=>'%k', '%x'=>:x, '%X'=>:root_x, and so on; 
  those are attributes of event object). It means that Ruby/Tk accepts
  not only "widget.bind(ev, '%W', '%k', ...){|w, k, ...| ... }", but 
  also "widget.bind(ev, :widget, :keycode, ...){|w, k, ...| ... }". 
  It is potentially incompatible, when user passes symbols to the
  arguments of the callback block (the block receives the symbols as
  strings). I think that is very rare case (probably, used by Ruby/Tk
  experts only). When causes such trouble, please give strings instead
  of such symbol parameters (e.g. call Symbol#to_s method).

* ext/tk/lib/tk/event.rb, ext/tk/lib/tk/validation.rb, 
  ext/tk/lib/tkextlib/blt/treeview.rb, 
  ext/tk/lib/tkextlib/winico/winico.rb: ditto.

* ext/tk/tkutil/tkutil.c: strings are available on subst_tables on 
  TkUtil::CallbackSubst class (it is useful on Ruby 1.9). 

* ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tkextlib/iwidgets/hierarchy.rb, 
  ext/tk/lib/tkextlib/iwidgets/spinner.rb, 
  ext/tk/lib/tkextlib/iwidgets/entryfield.rb, 
  ext/tk/lib/tkextlib/iwidgets/calendar.rb, 
  ext/tk/lib/tkextlib/blt/dragdrop.rb, 
  ext/tk/lib/tkextlib/tkDND/tkdnd.rb, 
  ext/tk/lib/tkextlib/treectrl/tktreectrl.rb, 
  ext/tk/lib/tkextlib/tktable/tktable.rb: disable code piece became 
  unnecessary by reason of the changes of ext/tk/tkutil/tkutil.c.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16410 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nagai 2008-05-14 00:54:31 +00:00
parent 8cf1995901
commit d37d14c0a5
17 changed files with 410 additions and 166 deletions

View file

@ -1,3 +1,35 @@
Wed May 14 09:52:02 2008 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/tkutil/tkutil.c: improve handling callback-subst-keys.
Now, support longnam-keys (e.g. '%CTT' on tkdnd-2.0; however, still
not support tkdnd-2.0 on tkextlib), and symbols of parameters (e.g.
:widget=>'%W', :keycode=>'%k', '%x'=>:x, '%X'=>:root_x, and so on;
those are attributes of event object). It means that Ruby/Tk accepts
not only "widget.bind(ev, '%W', '%k', ...){|w, k, ...| ... }", but
also "widget.bind(ev, :widget, :keycode, ...){|w, k, ...| ... }".
It is potentially incompatible, when user passes symbols to the
arguments of the callback block (the block receives the symbols as
strings). I think that is very rare case (probably, used by Ruby/Tk
experts only). When causes such trouble, please give strings instead
of such symbol parameters (e.g. call Symbol#to_s method).
* ext/tk/lib/tk/event.rb, ext/tk/lib/tk/validation.rb,
ext/tk/lib/tkextlib/blt/treeview.rb,
ext/tk/lib/tkextlib/winico/winico.rb: ditto.
* ext/tk/tkutil/tkutil.c: strings are available on subst_tables on
TkUtil::CallbackSubst class (it is useful on Ruby 1.9).
* ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tkextlib/iwidgets/hierarchy.rb,
ext/tk/lib/tkextlib/iwidgets/spinner.rb,
ext/tk/lib/tkextlib/iwidgets/entryfield.rb,
ext/tk/lib/tkextlib/iwidgets/calendar.rb,
ext/tk/lib/tkextlib/blt/dragdrop.rb,
ext/tk/lib/tkextlib/tkDND/tkdnd.rb,
ext/tk/lib/tkextlib/treectrl/tktreectrl.rb,
ext/tk/lib/tkextlib/tktable/tktable.rb: disable code piece became
unnecessary by reason of the changes of ext/tk/tkutil/tkutil.c.
Tue May 13 15:10:50 2008 Akinori MUSHA <knu@iDaemons.org> Tue May 13 15:10:50 2008 Akinori MUSHA <knu@iDaemons.org>
* enumerator.c: Update rdoc. * enumerator.c: Update rdoc.

View file

@ -5359,7 +5359,7 @@ TkWidget = TkWindow
#Tk.freeze #Tk.freeze
module Tk module Tk
RELEASE_DATE = '2008-05-12'.freeze RELEASE_DATE = '2008-05-14'.freeze
autoload :AUTO_PATH, 'tk/variable' autoload :AUTO_PATH, 'tk/variable'
autoload :TCL_PACKAGE_PATH, 'tk/variable' autoload :TCL_PACKAGE_PATH, 'tk/variable'

View file

@ -352,6 +352,14 @@ module TkEvent
nil nil
] ]
# [ <'%' subst-key str>, <proc type char>, <instance var (accessor) name>]
# the subst-key string will be converted to a bytecode (128+idx).
LONGKEY_TBL = [
# for example, for %CTT and %CST subst-key on tkdnd-2.0
# ['CTT', ?l, :drop_target_type],
# ['CST', ?l, :drop_source_type],
]
# [ <proc type char>, <proc/method to convert tcl-str to ruby-obj>] # [ <proc type char>, <proc/method to convert tcl-str to ruby-obj>]
PROC_TBL = [ PROC_TBL = [
[ ?n, TkComm.method(:num_or_str) ], [ ?n, TkComm.method(:num_or_str) ],
@ -371,6 +379,7 @@ module TkEvent
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -386,6 +395,7 @@ module TkEvent
end end
inf inf
} }
=end
# setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys # setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys
# #
@ -399,7 +409,8 @@ module TkEvent
# ( which are Tcl strings ) to ruby objects based on the key string # ( which are Tcl strings ) to ruby objects based on the key string
# that is generated by _get_subst_key() or _get_all_subst_keys(). # that is generated by _get_subst_key() or _get_all_subst_keys().
# #
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL)
# _setup_subst_table(KEY_TBL, LONGKEY_TBL, PROC_TBL) # if use longname-keys
# #
# NOTE: The order of parameters which passed to callback procedure is # NOTE: The order of parameters which passed to callback procedure is
@ -447,6 +458,7 @@ module TkEvent
extra_args_tbl = klass._get_extra_args_tbl extra_args_tbl = klass._get_extra_args_tbl
if args.compact.size > 0 if args.compact.size > 0
args.map!{|arg| klass._sym2subst(arg)}
args = args.join(' ') args = args.join(' ')
keys = klass._get_subst_key(args) keys = klass._get_subst_key(args)

View file

@ -37,6 +37,7 @@ class Tk::Spinbox<Tk::Entry
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -52,6 +53,7 @@ class Tk::Spinbox<Tk::Entry
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);

View file

@ -50,7 +50,8 @@ module Tk
key2class.each{|key, klass| key2class.each{|key, klass|
if keys[key].kind_of?(Array) if keys[key].kind_of?(Array)
cmd, *args = keys[key] cmd, *args = keys[key]
keys[key] = klass.new(cmd, args.join(' ')) #keys[key] = klass.new(cmd, args.join(' '))
keys[key] = klass.new(cmd, *args)
# elsif keys[key].kind_of?(Proc) || keys[key].kind_of?(Method) # elsif keys[key].kind_of?(Proc) || keys[key].kind_of?(Method)
elsif TkComm._callback_entry?(keys[key]) elsif TkComm._callback_entry?(keys[key])
keys[key] = klass.new(keys[key]) keys[key] = klass.new(keys[key])
@ -151,7 +152,8 @@ module Tk
key2class.each{|key, klass| key2class.each{|key, klass|
if keys[key].kind_of?(Array) if keys[key].kind_of?(Array)
cmd, *args = keys[key] cmd, *args = keys[key]
keys[key] = klass.new(cmd, args.join(' ')) #keys[key] = klass.new(cmd, args.join(' '))
keys[key] = klass.new(cmd, *args)
# elsif keys[key].kind_of?(Proc) || keys[key].kind_of?(Method) # elsif keys[key].kind_of?(Proc) || keys[key].kind_of?(Method)
elsif TkComm._callback_entry?(keys[key]) elsif TkComm._callback_entry?(keys[key])
keys[key] = klass.new(keys[key]) keys[key] = klass.new(keys[key])
@ -249,6 +251,7 @@ class TkValidateCommand
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -264,6 +267,7 @@ class TkValidateCommand
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -293,6 +297,7 @@ class TkValidateCommand
extra_args_tbl = klass._get_extra_args_tbl extra_args_tbl = klass._get_extra_args_tbl
if args.compact.size > 0 if args.compact.size > 0
args.map!{|arg| klass._sym2subst(arg)}
args = args.join(' ') args = args.join(' ')
keys = klass._get_subst_key(args) keys = klass._get_subst_key(args)
if cmd.kind_of?(String) if cmd.kind_of?(String)

View file

@ -81,6 +81,7 @@ module Tk::BLT
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -96,6 +97,7 @@ module Tk::BLT
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL) _setup_subst_table(KEY_TBL, PROC_TBL)
@ -123,6 +125,7 @@ module Tk::BLT
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -138,6 +141,7 @@ module Tk::BLT
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL) _setup_subst_table(KEY_TBL, PROC_TBL)
@ -177,6 +181,7 @@ module Tk::BLT
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -192,6 +197,7 @@ module Tk::BLT
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL) _setup_subst_table(KEY_TBL, PROC_TBL)
end end

View file

@ -239,6 +239,7 @@ class Tk::BLT::Treeview
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -254,6 +255,7 @@ class Tk::BLT::Treeview
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -492,6 +494,7 @@ class Tk::BLT::Treeview
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -507,6 +510,7 @@ class Tk::BLT::Treeview
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -523,7 +527,8 @@ class Tk::BLT::Treeview
def _find_exec_flag_value(val) def _find_exec_flag_value(val)
if val.kind_of?(Array) if val.kind_of?(Array)
cmd, *args = val cmd, *args = val
FindExecFlagValue.new(cmd, args.join(' ')) #FindExecFlagValue.new(cmd, args.join(' '))
FindExecFlagValue.new(cmd, *args)
elsif TkComm._callback_entry?(val) elsif TkComm._callback_entry?(val)
FindExecFlagValue.new(val) FindExecFlagValue.new(val)
else else

View file

@ -46,6 +46,7 @@ class Tk::Iwidgets::Calendar
KEY_TBL = [ [?d, ?s, :date], nil ] KEY_TBL = [ [?d, ?s, :date], nil ]
PROC_TBL = [ [?s, TkComm.method(:string) ], nil ] PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -61,6 +62,7 @@ class Tk::Iwidgets::Calendar
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);

View file

@ -43,6 +43,7 @@ class Tk::Iwidgets::Entryfield
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -58,6 +59,7 @@ class Tk::Iwidgets::Entryfield
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
end end

View file

@ -31,6 +31,7 @@ class Tk::Iwidgets::Hierarchy
KEY_TBL = [ [?n, ?s, :node], nil ] KEY_TBL = [ [?n, ?s, :node], nil ]
PROC_TBL = [ [?s, TkComm.method(:string) ], nil ] PROC_TBL = [ [?s, TkComm.method(:string) ], nil ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -46,6 +47,7 @@ class Tk::Iwidgets::Hierarchy
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -74,6 +76,7 @@ class Tk::Iwidgets::Hierarchy
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -89,6 +92,7 @@ class Tk::Iwidgets::Hierarchy
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -112,6 +116,7 @@ class Tk::Iwidgets::Hierarchy
] ]
PROC_TBL = [ [ ?s, TkComm.method(:string) ], nil ] PROC_TBL = [ [ ?s, TkComm.method(:string) ], nil ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -127,6 +132,7 @@ class Tk::Iwidgets::Hierarchy
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);

View file

@ -38,6 +38,7 @@ class Tk::Iwidgets::Spinner
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -53,6 +54,7 @@ class Tk::Iwidgets::Spinner
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
end end

View file

@ -57,6 +57,7 @@ module Tk
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -72,6 +73,7 @@ module Tk
end end
inf inf
} }
=end
# setup tables # setup tables
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);

View file

@ -291,6 +291,7 @@ class Tk::TkTable
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -306,6 +307,7 @@ class Tk::TkTable
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -340,6 +342,7 @@ class Tk::TkTable
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -355,6 +358,7 @@ class Tk::TkTable
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -387,6 +391,7 @@ class Tk::TkTable
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -402,6 +407,7 @@ class Tk::TkTable
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -437,6 +443,7 @@ class Tk::TkTable
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -452,6 +459,7 @@ class Tk::TkTable
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
end end

View file

@ -137,6 +137,7 @@ class Tk::TreeCtrl::NotifyEvent
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -152,6 +153,7 @@ class Tk::TreeCtrl::NotifyEvent
end end
inf inf
} }
=end
# setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys # setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys
# #

View file

@ -2,5 +2,5 @@
# release date of tkextlib # release date of tkextlib
# #
module Tk module Tk
Tkextlib_RELEASE_DATE = '2008-05-12'.freeze Tkextlib_RELEASE_DATE = '2008-05-14'.freeze
end end

View file

@ -150,6 +150,7 @@ class Tk::Winico
nil nil
] ]
=begin
# for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) )
KEY_TBL.map!{|inf| KEY_TBL.map!{|inf|
if inf.kind_of?(Array) if inf.kind_of?(Array)
@ -165,6 +166,7 @@ class Tk::Winico
end end
inf inf
} }
=end
_setup_subst_table(KEY_TBL, PROC_TBL); _setup_subst_table(KEY_TBL, PROC_TBL);
@ -185,7 +187,8 @@ class Tk::Winico
Winico_callback._config_keys.each{|k| Winico_callback._config_keys.each{|k|
if keys[k].kind_of?(Array) if keys[k].kind_of?(Array)
cmd, *args = keys[k] cmd, *args = keys[k]
keys[k] = Winico_callback.new(cmd, args.join(' ')) #keys[k] = Winico_callback.new(cmd, args.join(' '))
keys[k] = Winico_callback.new(cmd, *args)
# elsif keys[k].kind_of?(Proc) # elsif keys[k].kind_of?(Proc)
elsif TkComm._callback_entry?(keys[k]) elsif TkComm._callback_entry?(keys[k])
keys[k] = Winico_callback.new(keys[k]) keys[k] = Winico_callback.new(keys[k])
@ -201,7 +204,8 @@ class Tk::Winico
Winico_callback._config_keys.each{|k| Winico_callback._config_keys.each{|k|
if keys[k].kind_of?(Array) if keys[k].kind_of?(Array)
cmd, *args = keys[k] cmd, *args = keys[k]
keys[k] = Winico_callback.new(cmd, args.join(' ')) #keys[k] = Winico_callback.new(cmd, args.join(' '))
keys[k] = Winico_callback.new(cmd, *args)
# elsif keys[k].kind_of?(Proc) # elsif keys[k].kind_of?(Proc)
elsif TkComm._callback_entry?(keys[k]) elsif TkComm._callback_entry?(keys[k])
keys[k] = Winico_callback.new(keys[k]) keys[k] = Winico_callback.new(keys[k])

View file

@ -7,7 +7,7 @@
************************************************/ ************************************************/
#define TKUTIL_RELEASE_DATE "2008-03-29" #define TKUTIL_RELEASE_DATE "2008-05-14"
#include "ruby.h" #include "ruby.h"
@ -1073,11 +1073,13 @@ tcl2rb_num_or_str(self, value)
/*************************************/ /*************************************/
#define CBSUBST_TBL_MAX (256)
struct cbsubst_info { struct cbsubst_info {
int size; int full_subst_length;
char *key; int keylen[CBSUBST_TBL_MAX];
char *type; unsigned char *key[CBSUBST_TBL_MAX];
ID *ivar; unsigned char type[CBSUBST_TBL_MAX];
ID ivar[CBSUBST_TBL_MAX];
VALUE proc; VALUE proc;
VALUE aliases; VALUE aliases;
}; };
@ -1094,33 +1096,33 @@ static void
subst_free(ptr) subst_free(ptr)
struct cbsubst_info *ptr; struct cbsubst_info *ptr;
{ {
int i;
if (ptr) { if (ptr) {
if (ptr->key != (char*)NULL) free(ptr->key); for(i = 0; i < CBSUBST_TBL_MAX; i++) {
if (ptr->type != (char*)NULL) free(ptr->type); if (ptr->key[i] != (unsigned char *)NULL) free(ptr->key[i]);
if (ptr->ivar != (ID*)NULL) free(ptr->ivar); }
free(ptr); free(ptr);
} }
} }
static void static struct cbsubst_info *
cbsubst_init() allocate_cbsubst_info()
{ {
struct cbsubst_info *inf; struct cbsubst_info *inf;
ID *ivar;
volatile VALUE proc, aliases; volatile VALUE proc, aliases;
int idx;
inf = ALLOC(struct cbsubst_info); inf = ALLOC(struct cbsubst_info);
inf->size = 0; inf->full_subst_length = 0;
inf->key = ALLOC_N(char, 1); for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
inf->key[0] = '\0'; inf->keylen[idx] = 0;
inf->key[idx] = (unsigned char *) NULL;
inf->type = ALLOC_N(char, 1); inf->type[idx] = '\0';
inf->type[0] = '\0'; inf->ivar[idx] = (ID) 0;
}
ivar = ALLOC_N(ID, 1);
inf->ivar = ivar;
proc = rb_hash_new(); proc = rb_hash_new();
inf->proc = proc; inf->proc = proc;
@ -1128,8 +1130,15 @@ cbsubst_init()
aliases = rb_hash_new(); aliases = rb_hash_new();
inf->aliases = aliases; inf->aliases = aliases;
return inf;
}
static void
cbsubst_init()
{
rb_const_set(cCB_SUBST, ID_SUBST_INFO, rb_const_set(cCB_SUBST, ID_SUBST_INFO,
Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free, inf)); Data_Wrap_Struct(cSUBST_INFO, subst_mark, subst_free,
allocate_cbsubst_info()));
} }
static VALUE static VALUE
@ -1139,24 +1148,29 @@ cbsubst_initialize(argc, argv, self)
VALUE self; VALUE self;
{ {
struct cbsubst_info *inf; struct cbsubst_info *inf;
int idx; int idx, iv_idx;
Data_Get_Struct(rb_const_get(rb_obj_class(self), ID_SUBST_INFO), Data_Get_Struct(rb_const_get(rb_obj_class(self), ID_SUBST_INFO),
struct cbsubst_info, inf); struct cbsubst_info, inf);
for(idx = 0; idx < argc; idx++) { idx = 0;
rb_ivar_set(self, inf->ivar[idx], argv[idx]); for(iv_idx = 0; iv_idx < CBSUBST_TBL_MAX; iv_idx++) {
if ( inf->ivar[iv_idx] == (ID) 0 ) continue;
rb_ivar_set(self, inf->ivar[iv_idx], argv[idx++]);
if (idx >= argc) break;
} }
return self; return self;
} }
static VALUE static VALUE
cbsubst_ret_val(self, val) cbsubst_ret_val(self, val)
VALUE self; VALUE self;
VALUE val; VALUE val;
{ {
/* This method may be overwritten on some sub-classes. */
/* This method is used for converting from ruby's callback-return-value */
/* to tcl's value (e.g. validation procedure of entry widget). */
return val; return val;
} }
@ -1216,6 +1230,59 @@ cbsubst_def_attr_aliases(self, tbl)
return rb_funcall(inf->aliases, rb_intern("update"), 1, tbl); return rb_funcall(inf->aliases, rb_intern("update"), 1, tbl);
} }
static VALUE
cbsubst_sym_to_subst(self, sym)
VALUE self;
VALUE sym;
{
struct cbsubst_info *inf;
const char *str;
unsigned char *buf, *ptr;
int idx, len;
ID id;
volatile VALUE ret;
if (TYPE(sym) != T_SYMBOL) return sym;
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf);
if (!NIL_P(ret = rb_hash_aref(inf->aliases, sym))) {
str = rb_id2name(SYM2ID(ret));
} else {
str = rb_id2name(SYM2ID(sym));
}
id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
if (inf->ivar[idx] == id) break;
}
if (idx >= CBSUBST_TBL_MAX) return sym;
ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
*(ptr++) = '%';
if (len = inf->keylen[idx]) {
/* longname */
strncpy(ptr, inf->key[idx], len);
ptr += len;
} else {
/* single char */
*(ptr++) = idx;
}
*(ptr++) = ' ';
*(ptr++) = '\0';
ret = rb_str_new2(buf);
free(buf);
return ret;
}
static VALUE static VALUE
cbsubst_get_subst_arg(argc, argv, self) cbsubst_get_subst_arg(argc, argv, self)
int argc; int argc;
@ -1224,17 +1291,15 @@ cbsubst_get_subst_arg(argc, argv, self)
{ {
struct cbsubst_info *inf; struct cbsubst_info *inf;
const char *str; const char *str;
char *buf, *ptr; unsigned char *buf, *ptr;
int i, j, len; int i, idx, len;
ID id; ID id;
volatile VALUE arg_sym, ret; volatile VALUE arg_sym, ret;
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf); struct cbsubst_info, inf);
buf = ALLOC_N(char, 3*argc + 1); ptr = buf = ALLOC_N(char, inf->full_subst_length + 1);
ptr = buf;
len = strlen(inf->key);
for(i = 0; i < argc; i++) { for(i = 0; i < argc; i++) {
switch(TYPE(argv[i])) { switch(TYPE(argv[i])) {
@ -1256,16 +1321,24 @@ cbsubst_get_subst_arg(argc, argv, self)
id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str))); id = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), str)));
for(j = 0; j < len; j++) { for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
if (inf->ivar[j] == id) break; if (inf->ivar[idx] == id) break;
} }
if (idx >= CBSUBST_TBL_MAX) {
if (j >= len) {
rb_raise(rb_eArgError, "cannot find attribute :%s", str); rb_raise(rb_eArgError, "cannot find attribute :%s", str);
} }
*(ptr++) = '%'; *(ptr++) = '%';
*(ptr++) = *(inf->key + j);
if (len = inf->keylen[idx]) {
/* longname */
strncpy(ptr, inf->key[idx], len);
ptr += len;
} else {
/* single char */
*(ptr++) = idx;
}
*(ptr++) = ' '; *(ptr++) = ' ';
} }
@ -1283,27 +1356,50 @@ cbsubst_get_subst_key(self, str)
VALUE self; VALUE self;
VALUE str; VALUE str;
{ {
struct cbsubst_info *inf;
volatile VALUE list; volatile VALUE list;
volatile VALUE ret; volatile VALUE ret;
int i, len; VALUE keyval;
char *buf, *ptr; int i, len, keylen, idx;
unsigned char *buf, *ptr, *key;
list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str); list = rb_funcall(cTclTkLib, ID_split_tklist, 1, str);
len = RARRAY_LEN(list); len = RARRAY_LEN(list);
buf = ALLOC_N(char, len + 1);
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf);
ptr = buf = ALLOC_N(unsigned char, inf->full_subst_length + len + 1);
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
ptr = RSTRING_PTR(RARRAY_PTR(list)[i]); keyval = RARRAY_PTR(list)[i];
if (*ptr == '%' && *(ptr + 2) == '\0') { key = (unsigned char*)RSTRING_PTR(keyval);
*(buf + i) = *(ptr + 1); if (*key == '%') {
if (*(key + 2) == '\0') {
/* single char */
*(ptr++) = *(key + 1);
} else { } else {
*(buf + i) = ' '; /* search longname-key */
keylen = RSTRING_LEN(keyval) - 1;
for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
if (inf->keylen[idx] != keylen) continue;
if (inf->key[idx][0] != *(key + 1)) continue;
if (strncmp(inf->key[idx], key + 1, keylen)) continue;
break;
}
if (idx < CBSUBST_TBL_MAX) {
*(ptr++) = (unsigned char)idx;
} else {
*(ptr++) = ' ';
} }
} }
*(buf + len) = '\0'; } else {
*(ptr++) = ' ';
}
}
*ptr = '\0';
ret = rb_str_new2(buf); ret = rb_str_new2((const char*)buf);
free(buf); free(buf);
return ret; return ret;
} }
@ -1313,24 +1409,40 @@ cbsubst_get_all_subst_keys(self)
VALUE self; VALUE self;
{ {
struct cbsubst_info *inf; struct cbsubst_info *inf;
char *buf, *ptr; unsigned char *buf, *ptr;
int i, len; unsigned char *keys_buf, *keys_ptr;
int idx, len;
volatile VALUE ret; volatile VALUE ret;
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf); struct cbsubst_info, inf);
len = strlen(inf->key); ptr = buf = ALLOC_N(unsigned char, inf->full_subst_length + 1);
buf = ALLOC_N(char, 3*len + 1); keys_ptr = keys_buf = ALLOC_N(unsigned char, CBSUBST_TBL_MAX + 1);
ptr = buf;
for(i = 0; i < len; i++) { for(idx = 0; idx < CBSUBST_TBL_MAX; idx++) {
if (inf->ivar[idx] == (ID) 0) continue;
*(keys_ptr++) = (unsigned char)idx;
*(ptr++) = '%'; *(ptr++) = '%';
*(ptr++) = *(inf->key + i);
if (len = inf->keylen[idx]) {
/* longname */
strncpy(ptr, inf->key[idx], len);
ptr += len;
} else {
/* single char */
*(ptr++) = (unsigned char)idx;
}
*(ptr++) = ' '; *(ptr++) = ' ';
} }
*(buf + 3*len) = '\0';
ret = rb_ary_new3(2, rb_str_new2(inf->key), rb_str_new2(buf)); *ptr = '\0';
*keys_ptr = '\0';
ret = rb_ary_new3(2, rb_str_new2(keys_buf), rb_str_new2((const char*)buf));
free(buf); free(buf);
@ -1338,68 +1450,108 @@ cbsubst_get_all_subst_keys(self)
} }
static VALUE static VALUE
cbsubst_table_setup(self, key_inf, proc_inf) cbsubst_table_setup(argc, argv, self)
int argc;
VALUE *argv;
VALUE self; VALUE self;
VALUE key_inf;
VALUE proc_inf;
{ {
volatile VALUE key_inf;
volatile VALUE longkey_inf;
volatile VALUE proc_inf;
VALUE inf;
ID id;
struct cbsubst_info *subst_inf; struct cbsubst_info *subst_inf;
int idx; int idx, len;
int len = RARRAY_LEN(key_inf); unsigned char chr;
int real_len = 0;
char *key = ALLOC_N(char, len + 1); /* accept (key_inf, proc_inf) or (key_inf, longkey_inf, procinf) */
char *type = ALLOC_N(char, len + 1); if (rb_scan_args(argc, argv, "21", &key_inf, &longkey_inf, &proc_inf) == 2) {
ID *ivar = ALLOC_N(ID, len + 1); proc_inf = longkey_inf;
volatile VALUE proc = rb_hash_new(); longkey_inf = rb_ary_new();
volatile VALUE aliases = rb_hash_new(); }
volatile VALUE inf;
/* check the number of longkeys */
if (RARRAY_LEN(longkey_inf) > 125 /* from 0x80 to 0xFD */) {
rb_raise(rb_eArgError, "too many longname-key definitions");
}
/* init */ /* init */
subst_inf = ALLOC(struct cbsubst_info); subst_inf = allocate_cbsubst_info();
/* subst_inf->size = len; */
subst_inf->key = key;
subst_inf->type = type;
subst_inf->ivar = ivar;
subst_inf->proc = proc;
subst_inf->aliases = aliases;
/* /*
* keys : array of [subst, type, ivar] * keys : array of [subst, type, ivar]
* subst ==> char code * subst ==> char code or string
* type ==> char code * type ==> char code or string
* ivar ==> symbol * ivar ==> symbol
*/ */
len = RARRAY_LEN(key_inf);
for(idx = 0; idx < len; idx++) { for(idx = 0; idx < len; idx++) {
inf = RARRAY_PTR(key_inf)[idx]; inf = RARRAY_PTR(key_inf)[idx];
if (TYPE(inf) != T_ARRAY) continue; if (TYPE(inf) != T_ARRAY) continue;
*(key + real_len) = NUM2CHR(RARRAY_PTR(inf)[0]);
*(type + real_len) = NUM2CHR(RARRAY_PTR(inf)[1]);
*(ivar + real_len) if (TYPE(RARRAY_PTR(inf)[0]) == T_STRING) {
= rb_intern( chr = *(RSTRING_PTR(RARRAY_PTR(inf)[0]));
RSTRING_PTR( } else {
rb_str_cat2(rb_str_new2("@"), chr = NUM2CHR(RARRAY_PTR(inf)[0]);
rb_id2name(SYM2ID(RARRAY_PTR(inf)[2]))) }
) if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
); subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
} else {
rb_attr(self, SYM2ID(RARRAY_PTR(inf)[2]), 1, 0, Qtrue); subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]);
real_len++; }
subst_inf->full_subst_length += 3;
id = SYM2ID(RARRAY_PTR(inf)[2]);
subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id))));
rb_attr(self, id, 1, 0, Qtrue);
}
/*
* longkeys : array of [name, type, ivar]
* name ==> longname key string
* type ==> char code or string
* ivar ==> symbol
*/
len = RARRAY_LEN(longkey_inf);
for(idx = 0; idx < len; idx++) {
inf = RARRAY_PTR(longkey_inf)[idx];
if (TYPE(inf) != T_ARRAY) continue;
chr = (unsigned char)(0x80 + idx);
subst_inf->keylen[chr] = RSTRING_LEN(RARRAY_PTR(inf)[0]);
subst_inf->key[chr] = strndup(RSTRING_PTR(RARRAY_PTR(inf)[0]),
RSTRING_LEN(RARRAY_PTR(inf)[0]));
if (TYPE(RARRAY_PTR(inf)[1]) == T_STRING) {
subst_inf->type[chr] = *(RSTRING_PTR(RARRAY_PTR(inf)[1]));
} else {
subst_inf->type[chr] = NUM2CHR(RARRAY_PTR(inf)[1]);
}
subst_inf->full_subst_length += (subst_inf->keylen[chr] + 2);
id = SYM2ID(RARRAY_PTR(inf)[2]);
subst_inf->ivar[chr] = rb_intern(RSTRING_PTR(rb_str_cat2(rb_str_new2("@"), rb_id2name(id))));
rb_attr(self, id, 1, 0, Qtrue);
} }
*(key + real_len) = '\0';
*(type + real_len) = '\0';
subst_inf->size = real_len;
/* /*
* procs : array of [type, proc] * procs : array of [type, proc]
* type ==> char code * type ==> char code or string
* proc ==> proc/method/obj (must respond to 'call') * proc ==> proc/method/obj (must respond to 'call')
*/ */
len = RARRAY_LEN(proc_inf); len = RARRAY_LEN(proc_inf);
for(idx = 0; idx < len; idx++) { for(idx = 0; idx < len; idx++) {
inf = RARRAY_PTR(proc_inf)[idx]; inf = RARRAY_PTR(proc_inf)[idx];
if (TYPE(inf) != T_ARRAY) continue; if (TYPE(inf) != T_ARRAY) continue;
rb_hash_aset(proc, RARRAY_PTR(inf)[0], RARRAY_PTR(inf)[1]); rb_hash_aset(subst_inf->proc,
((TYPE(RARRAY_PTR(inf)[0]) == T_STRING)?
INT2FIX(*(RSTRING_PTR(RARRAY_PTR(inf)[0]))) :
RARRAY_PTR(inf)[0]),
RARRAY_PTR(inf)[1]);
} }
rb_const_set(self, ID_SUBST_INFO, rb_const_set(self, ID_SUBST_INFO,
@ -1424,10 +1576,11 @@ cbsubst_scan_args(self, arg_key, val_ary)
{ {
struct cbsubst_info *inf; struct cbsubst_info *inf;
int idx; int idx;
int len = RARRAY_LEN(val_ary); unsigned char *keyptr = (unsigned char*)RSTRING_PTR(arg_key);
char c; int keylen = RSTRING_LEN(arg_key);
char *ptr; int vallen = RARRAY_LEN(val_ary);
volatile VALUE dst = rb_ary_new2(len); unsigned char type_chr;
volatile VALUE dst = rb_ary_new2(vallen);
volatile VALUE proc; volatile VALUE proc;
int thr_crit_bup; int thr_crit_bup;
VALUE old_gc; VALUE old_gc;
@ -1440,25 +1593,24 @@ cbsubst_scan_args(self, arg_key, val_ary)
Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO), Data_Get_Struct(rb_const_get(self, ID_SUBST_INFO),
struct cbsubst_info, inf); struct cbsubst_info, inf);
for(idx = 0; idx < len; idx++) { for(idx = 0; idx < vallen; idx++) {
if (idx >= RSTRING_LEN(arg_key)) { if (idx >= keylen) {
proc = Qnil; proc = Qnil;
} else if (*(RSTRING_PTR(arg_key) + idx) == ' ') { } else if (*(keyptr + idx) == ' ') {
proc = Qnil; proc = Qnil;
} else { } else {
ptr = strchr(inf->key, *(RSTRING_PTR(arg_key) + idx)); if (type_chr = inf->type[*(keyptr + idx)]) {
if (ptr == (char*)NULL) { proc = rb_hash_aref(inf->proc, INT2FIX((int)type_chr));
proc = Qnil;
} else { } else {
c = *(inf->type + (ptr - inf->key)); proc = Qnil;
proc = rb_hash_aref(inf->proc, INT2FIX(c));
} }
} }
if (NIL_P(proc)) { if (NIL_P(proc)) {
rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]); rb_ary_push(dst, RARRAY_PTR(val_ary)[idx]);
} else { } else {
rb_ary_push(dst, rb_funcall(proc, ID_call, 1, RARRAY_PTR(val_ary)[idx])); rb_ary_push(dst, rb_funcall(proc, ID_call, 1,
RARRAY_PTR(val_ary)[idx]));
} }
} }
@ -1543,6 +1695,8 @@ Init_tkutil()
ID_SUBST_INFO = rb_intern("SUBST_INFO"); ID_SUBST_INFO = rb_intern("SUBST_INFO");
rb_define_singleton_method(cCB_SUBST, "ret_val", cbsubst_ret_val, 1); rb_define_singleton_method(cCB_SUBST, "ret_val", cbsubst_ret_val, 1);
rb_define_singleton_method(cCB_SUBST, "scan_args", cbsubst_scan_args, 2); rb_define_singleton_method(cCB_SUBST, "scan_args", cbsubst_scan_args, 2);
rb_define_singleton_method(cCB_SUBST, "_sym2subst",
cbsubst_sym_to_subst, 1);
rb_define_singleton_method(cCB_SUBST, "subst_arg", rb_define_singleton_method(cCB_SUBST, "subst_arg",
cbsubst_get_subst_arg, -1); cbsubst_get_subst_arg, -1);
rb_define_singleton_method(cCB_SUBST, "_get_subst_key", rb_define_singleton_method(cCB_SUBST, "_get_subst_key",
@ -1550,7 +1704,7 @@ Init_tkutil()
rb_define_singleton_method(cCB_SUBST, "_get_all_subst_keys", rb_define_singleton_method(cCB_SUBST, "_get_all_subst_keys",
cbsubst_get_all_subst_keys, 0); cbsubst_get_all_subst_keys, 0);
rb_define_singleton_method(cCB_SUBST, "_setup_subst_table", rb_define_singleton_method(cCB_SUBST, "_setup_subst_table",
cbsubst_table_setup, 2); cbsubst_table_setup, -1);
rb_define_singleton_method(cCB_SUBST, "_get_extra_args_tbl", rb_define_singleton_method(cCB_SUBST, "_get_extra_args_tbl",
cbsubst_get_extra_args_tbl, 0); cbsubst_get_extra_args_tbl, 0);
rb_define_singleton_method(cCB_SUBST, "_define_attribute_aliases", rb_define_singleton_method(cCB_SUBST, "_define_attribute_aliases",