From aeb066503409062fc8fe8b241e512f5f6aebb128 Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 24 Aug 1999 08:21:56 +0000 Subject: 1.4.1 to be git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 99 ++++++++++++++++++-------------------------------- ext/tk/lib/tkcanvas.rb | 30 ++++----------- ext/tk/lib/tkentry.rb | 2 +- ext/tk/lib/tktext.rb | 65 ++++++--------------------------- 4 files changed, 55 insertions(+), 141 deletions(-) (limited to 'ext/tk') diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 2b4b504b0..f831dbc78 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -8,6 +8,8 @@ require "tcltklib" require "tkutil" module TkComm + WidgetClassNames = {} + None = Object.new def None.to_s 'None' @@ -34,7 +36,7 @@ module TkComm return path end - ruby_class = TkClassBind::WidgetClassNameTBL[tk_class] + ruby_class = WidgetClassNames[tk_class] gen_class_name = ruby_class.name + 'GeneratedOnTk' unless Object.const_defined? gen_class_name eval "class #{gen_class_name}<#{ruby_class.name} @@ -328,45 +330,36 @@ module TkComm end end - def _bind_core(mode, path, context, cmd, args=nil) - id = install_bind(cmd, args) + def _bind_core(mode, what, context, cmd, args=nil) + id = install_bind(cmd, args) if cmd begin - tk_call 'bind', path, "<#{tk_event_sequence(context)}>", mode + id + tk_call(*(what + ["<#{tk_event_sequence(context)}>", mode + id])) rescue - uninstall_cmd(id) + uninstall_cmd(id) if cmd fail end end - def _bind(path, context, cmd, args=nil) - _bind_core('', path, context, cmd, args) + def _bind(what, context, cmd, args=nil) + _bind_core('', what, context, cmd, args) end - def _bind_append(path, context, cmd, args=nil) - _bind_core('+', path, context, cmd, args) + def _bind_append(what, context, cmd, args=nil) + _bind_core('+', what, context, cmd, args) end private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append def bind_all(context, cmd=Proc.new, args=nil) - _bind 'all', context, cmd, args + _bind(['bind', 'all'], context, cmd, args) end def bind_append_all(context, cmd=Proc.new, args=nil) - _bind_append 'all', context, cmd, args - end - - def bind(tagOrClass, context, cmd=Proc.new, args=nil) - _bind tagOrClass, context, cmd, args - end - - def bind_append(tagOrClass, context, cmd=Proc.new, args=nil) - _bind_append tagOrClass, context, cmd, args + _bind_append(['bind', 'all'], context, cmd, args) end - def _bindinfo(tagOrClass, context=nil) + def _bindinfo(what, context=nil) if context - (tk_call('bind', tagOrClass, - "<#{tk_event_sequence(context)}>")).collect{|cmdline| + tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline| if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ [Tk_CMDTBL[$1], $2] else @@ -374,14 +367,14 @@ module TkComm end } else - tk_split_list(tk_call 'bind', tagOrClass).collect{|seq| + tk_split_list(tk_call(*what)).collect{|seq| seq[1..-2].gsub(/>", id - rescue - uninstall_cmd(cmd) - fail - end - # @cmdtbl.push id + _bind([path, "bind", tagid(tag)], context, cmd, args) + end + + def itembind_append(tag, context, cmd=Proc.new, args=nil) + _bind_append([path, "bind", tagid(tag)], context, cmd, args) end def itembindinfo(tag, context=nil) - if context - (tk_send('bind', tagid(tag), - "<#{tk_event_sequence(context)}>")).collect{|cmdline| - if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ - [Tk_CMDTBL[$1], $2] - else - cmdline - end - } - else - tk_split_list(tk_send 'bind', tagid(tag)).filter{|seq| - seq[1..-2].gsub(/>", mode + id - # _addcmd cmd - end - private :_tag_bind_core - def tag_bind(tag, seq, cmd=Proc.new, args=nil) - _tag_bind_core('', tag, seq, cmd, args=nil) + _bind(['tag', 'bind', tag], seq, cmd, args) end def tag_bind_append(tag, seq, cmd=Proc.new, args=nil) - _tag_bind_core('+', tag, seq, cmd, args=nil) + _bind_append(['tag', 'bind', tag], seq, cmd, args) end def tag_bindinfo(tag, context=nil) - if context - (tk_send('tag', 'bind', tag, - "<#{tk_event_sequence(context)}>")).collect{|cmdline| - if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ - [Tk_CMDTBL[$1], $2] - else - cmdline - end - } - else - tk_split_list(tk_send('tag', 'bind', tag)).filter{|seq| - seq[1..-2].gsub(/>", id - # @t._addcmd cmd + _bind([@t.path, 'tag', 'bind', @id], seq, cmd, args) + end + + def bind_append(seq, cmd=Proc.new, args=nil) + _bind_append([@t.path, 'tag', 'bind', @id], seq, cmd, args) end def bindinfo(context=nil) - if context - (tk_call(@t.path, 'tag', 'bind', @id, - "<#{tk_event_sequence(context)}>")).collect{|cmdline| - if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ - [Tk_CMDTBL[$1], $2] - else - cmdline - end - } - else - tk_split_list(tk_call(@t.path, 'tag', 'bind', @id)).filter{|seq| - seq[1..-2].gsub(/>