From 2018ddf072d64797531691f0bb27c5d50f88405d Mon Sep 17 00:00:00 2001 From: nagai Date: Sat, 12 Jun 2004 15:25:49 +0000 Subject: * ext/tcltklib/extconf.rb: [EXPERIMENTAL] MacOS X (darwin) support * ext/tcltklib/tcltklib.c: fix thread trouble on callback proc, and eliminate warning about instance variable access * ext/tk/lib/tk/menubar.rb: improve supported menu_spec * ext/tk/lib/tk/menuspec.rb: [add] menu_spec support library * ext/tk/lib/tk/root.rb: add menu_spec support * ext/tk/lib/tk/text.rb: bug fix * ext/tk/lib/tk/toplevel.rb: add menu_spec support * ext/tk/sample/menubar?.rb: [add] sample of menu_spec usage git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6454 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/multi-tk.rb | 3 +- ext/tk/lib/tk.rb | 89 +++++++++++++++++++++----------- ext/tk/lib/tk/grid.rb | 48 ++++++++++++++---- ext/tk/lib/tk/menubar.rb | 127 +++++++++++++++++++++------------------------- ext/tk/lib/tk/optiondb.rb | 3 +- ext/tk/lib/tk/place.rb | 39 ++++++++++---- ext/tk/lib/tk/root.rb | 21 ++++++++ ext/tk/lib/tk/text.rb | 80 ++++++++++++++++++----------- ext/tk/lib/tk/toplevel.rb | 21 ++++++++ ext/tk/lib/tk/variable.rb | 18 ++++--- 10 files changed, 290 insertions(+), 159 deletions(-) (limited to 'ext/tk/lib') diff --git a/ext/tk/lib/multi-tk.rb b/ext/tk/lib/multi-tk.rb index ba1dc733c..7957e0b3c 100644 --- a/ext/tk/lib/multi-tk.rb +++ b/ext/tk/lib/multi-tk.rb @@ -1324,7 +1324,8 @@ class MultiTkIp else list.push str[0..i-1] end - list += _lst2ary(str[i+1..-1]) + #list += _lst2ary(str[i+1..-1]) + list.concat(_lst2ary(str[i+1..-1])) list end private :_lst2ary diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index 12d60245e..5ac6724b8 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -114,7 +114,7 @@ module TkComm private :_genobj_for_tkwidget module_function :_genobj_for_tkwidget - def tk_tcl2ruby(val, enc_mode = nil) + def tk_tcl2ruby(val, enc_mode = nil, listobj = true) if val =~ /^rb_out\S* (c(_\d+_)?\d+)/ #return Tk_CMDTBL[$1] return TkCore::INTERP.tk_cmd_tbl[$1] @@ -141,12 +141,18 @@ module TkComm TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val when /^-?\d+\.?\d*(e[-+]?\d+)?$/ val.to_f - when /[^\\] / - tk_split_escstr(val).collect{|elt| - tk_tcl2ruby(elt) - } when /\\ / val.gsub(/\\ /, ' ') + when /[^\\] / + if listobj + tk_split_escstr(val).collect{|elt| + tk_tcl2ruby(elt, enc_mode, listobj) + } + elsif enc_mode + _fromUTF8(val) + else + val + end else if enc_mode _fromUTF8(val) @@ -157,6 +163,8 @@ module TkComm end private :tk_tcl2ruby + module_function :tk_tcl2ruby + private_class_method :tk_tcl2ruby unless const_defined?(:USE_TCLs_LIST_FUNCTIONS) USE_TCLs_LIST_FUNCTIONS = true @@ -171,19 +179,28 @@ if USE_TCLs_LIST_FUNCTIONS TkCore::INTERP._split_tklist(str) end - def tk_split_sublist(str) - return [] if str == "" - list = TkCore::INTERP._split_tklist(str) + def tk_split_sublist(str, depth=-1) + # return [] if str == "" + # list = TkCore::INTERP._split_tklist(str) + if depth == 0 + return "" if str == "" + list = [str] + else + return [] if str == "" + list = TkCore::INTERP._split_tklist(str) + end if list.size == 1 - tk_tcl2ruby(list[0]) + tk_tcl2ruby(list[0], nil, false) else - list.collect{|token| tk_split_sublist(token)} + list.collect{|token| tk_split_sublist(token, depth - 1)} end end - def tk_split_list(str) + def tk_split_list(str, depth=0) return [] if str == "" - TkCore::INTERP._split_tklist(str).collect{|token| tk_split_sublist(token)} + TkCore::INTERP._split_tklist(str).collect{|token| + tk_split_sublist(token, depth - 1) + } end def tk_split_simplelist(str) @@ -239,20 +256,29 @@ else list end - def tk_split_sublist(str) - return [] if str == "" - return [tk_split_sublist(str[1..-2])] if str =~ /^\{.*\}$/ - list = tk_split_escstr(str) + def tk_split_sublist(str, depth=-1) + #return [] if str == "" + #return [tk_split_sublist(str[1..-2])] if str =~ /^\{.*\}$/ + #list = tk_split_escstr(str) + if depth == 0 + return "" if str == "" + str = str[1..-2] if str =~ /^\{.*\}$/ + list = [str] + else + return [] if str == [] + return [tk_split_sublist(str[1..-2], depth - 1)] if str =~ /^\{.*\}$/ + list = tk_split_escstr(str) + end if list.size == 1 - tk_tcl2ruby(list[0]) + tk_tcl2ruby(list[0], nil, false) else - list.collect{|token| tk_split_sublist(token)} + list.collect{|token| tk_split_sublist(token, depth - 1)} end end - def tk_split_list(str) + def tk_split_list(str, depth=0) return [] if str == "" - tk_split_escstr(str).collect{|token| tk_split_sublist(token)} + tk_split_escstr(str).collect{|token| tk_split_sublist(token, depth - 1)} end =begin def tk_split_list(str) @@ -425,8 +451,8 @@ end end =end - def list(val) - tk_split_list(val) + def list(val, depth=0) + tk_split_list(val, depth) end def simplelist(val) tk_split_simplelist(val) @@ -457,9 +483,10 @@ end val end end - private :bool, :number, :string, :list, :simplelist, :window, :procedure - module_function :bool, :number, :num_or_str, :string, :list, :simplelist - module_function :window, :image_obj, :procedure + private :bool, :number, :string, :num_or_str + private :list, :simplelist, :window, :procedure + module_function :bool, :number, :num_or_str, :string + module_function :list, :simplelist, :window, :image_obj, :procedure def _toUTF8(str, encoding = nil) TkCore::INTERP._toUTF8(str, encoding) @@ -2035,9 +2062,10 @@ class TkObject definition is moved to TkUtil module +# def path +# @path +# end def epath @path @@ -2433,6 +2461,7 @@ class TkWindowvalue) end end + alias pack_configure pack_config def pack_info() #ilist = list(tk_call('pack', 'info', epath)) @@ -2510,6 +2539,7 @@ class TkWindowvalue) end end + alias grid_configure grid_config def grid_columnconfig(index, keys) #tk_call('grid', 'columnconfigure', epath, index, *hash_kv(keys)) @@ -2625,6 +2655,7 @@ class TkWindow= Tk8.4a2 ? @@ -2640,7 +2671,7 @@ class TkWindow'top', 'fill'=>'x') - -# The format of the menu_spec is: -# [ -# [ -# [button text, underline, accelerator], -# [menu label, command, underline, accelerator], -# '---', # separator -# ... -# ], -# ... +# +# +# OR +# +# radio_var = TkVariable.new('y') +# menu_spec = [ +# [['File', 0], +# {:label=>'Open', :command=>proc{puts('Open clicked')}, :underline=>0}, +# '---', +# ['Check_A', TkVariable.new(true), 6], +# {:type=>'checkbutton', :label=>'Check_B', +# :variable=>TkVariable.new, :underline=>6}, +# '---', +# ['Radio_X', [radio_var, 'x'], 6], +# ['Radio_Y', [radio_var, 'y'], 6], +# ['Radio_Z', [radio_var, 'z'], 6], +# '---', +# ['cascade', [ +# ['sss', proc{p 'sss'}, 0], +# ['ttt', proc{p 'ttt'}, 0], +# ['uuu', proc{p 'uuu'}, 0], +# ['vvv', proc{p 'vvv'}, 0], +# ], 0], +# '---', +# ['Quit', proc{exit}, 0]], +# [['Edit', 0], +# ['Cut', proc{puts('Cut clicked')}, 2], +# ['Copy', proc{puts('Copy clicked')}, 0], +# ['Paste', proc{puts('Paste clicked')}, 0]] # ] +# menubar = TkMenubar.new(nil, menu_spec, +# 'tearoff'=>false, +# 'foreground'=>'grey40', +# 'activeforeground'=>'red', +# 'font'=>'Helvetia 12 bold') +# menubar.pack('side'=>'top', 'fill'=>'x') -# underline and accelerator are optional parameters. -# Hashes are OK instead of Arrays. +# See tk/menuspce.rb about the format of the menu_spec # To use add_menu, configuration must be done by calling configure after # adding all menus by add_menu, not by the constructor arguments. require 'tk' require 'tk/frame' +require 'tk/composite' +require 'tk/menuspec' class TkMenubar item_info) - end - end - - mbtn.menu(menu) + mbtn, menu = _create_menubutton(@frame, menu_info) + + submenus = _get_cascade_menus(menu).flatten + @menus.push([mbtn, menu]) - delegate('tearoff', menu) - delegate('foreground', mbtn, menu) - delegate('background', mbtn, menu) - delegate('disabledforeground', mbtn, menu) - delegate('activeforeground', mbtn, menu) - delegate('activebackground', mbtn, menu) - delegate('font', mbtn, menu) - delegate('kanjifont', mbtn, menu) - mbtn.pack('side' => 'left') + delegate('tearoff', menu, *submenus) + delegate('foreground', mbtn, menu, *submenus) + delegate('background', mbtn, menu, *submenus) + delegate('disabledforeground', mbtn, menu, *submenus) + delegate('activeforeground', mbtn, menu, *submenus) + delegate('activebackground', mbtn, menu, *submenus) + delegate('font', mbtn, menu, *submenus) + delegate('kanjifont', mbtn, menu, *submenus) end def [](index) diff --git a/ext/tk/lib/tk/optiondb.rb b/ext/tk/lib/tk/optiondb.rb index 588c94644..46d17a202 100644 --- a/ext/tk/lib/tk/optiondb.rb +++ b/ext/tk/lib/tk/optiondb.rb @@ -52,7 +52,8 @@ module TkOptionDB cline = '' open(file, 'r') {|f| while line = f.gets - cline += line.chomp! + #cline += line.chomp! + cline.concat(line.chomp!) case cline when /\\$/ # continue cline.chop! diff --git a/ext/tk/lib/tk/place.rb b/ext/tk/lib/tk/place.rb index 5c2f890e0..433c1077e 100644 --- a/ext/tk/lib/tk/place.rb +++ b/ext/tk/lib/tk/place.rb @@ -34,14 +34,21 @@ module TkPlace # win = win.epath if win.kind_of?(TkObject) win = _epath(win) if slot - conf = tk_split_list(tk_call_without_enc('place', 'configure', - win, "-#{slot}") ) + #conf = tk_split_list(tk_call_without_enc('place', 'configure', + # win, "-#{slot}") ) + conf = tk_split_simplelist(tk_call_without_enc('place', 'configure', + win, "-#{slot}") ) conf[0] = conf[0][1..-1] + conf[1] = tk_tcl2ruby(conf[1]) + conf[2] = tk_tcl2ruby(conf[1]) + conf[3] = tk_tcl2ruby(conf[1]) + conf[4] = tk_tcl2ruby(conf[1]) conf else tk_split_simplelist(tk_call_without_enc('place', 'configure', win)).collect{|conflist| - conf = list(conflist) + #conf = list(conflist) + conf = simplelist(conflist).collect!{|inf| tk_tcl2ruby(inf)} conf[0] = conf[0][1..-1] conf } @@ -55,13 +62,20 @@ module TkPlace # win = win.epath if win.kind_of?(TkObject) win = _epath(win) if slot - conf = tk_split_list(tk_call_without_enc('place', 'configure', - win, "-#{slot}") ) - { conf[0][1..-1] => conf[1] } + #conf = tk_split_list(tk_call_without_enc('place', 'configure', + # win, "-#{slot}") ) + conf = tk_split_simplelist(tk_call_without_enc('place', 'configure', + win, "-#{slot}") ) + # { conf[0][1..-1] => conf[1] } + { conf[0][1..-1] => tk_tcl2ruby(conf[4]) } else ret = {} - tk_split_list(tk_call_without_enc('place','configure',win)).each{|conf| - ret[conf[0][1..-1]] = conf[1] + #tk_split_list(tk_call_without_enc('place','configure',win)).each{|conf| + tk_split_simplelist(tk_call_without_enc('place', 'configure', + win)).each{|conf_list| + #ret[conf[0][1..-1]] = conf[1] + conf = simplelist(conf_list) + ret[conf[0][1..-1]] = tk_tcl2ruby(conf[4]) } ret end @@ -76,10 +90,12 @@ module TkPlace def info(win) # win = win.epath if win.kind_of?(TkObject) win = _epath(win) - ilist = list(tk_call_without_enc('place', 'info', win)) + #ilist = list(tk_call_without_enc('place', 'info', win)) + ilist = simplelist(tk_call_without_enc('place', 'info', win)) info = {} while key = ilist.shift - info[key[1..-1]] = ilist.shift + #info[key[1..-1]] = ilist.shift + info[key[1..-1]] = tk_tcl2ruby(ilist.shift) end return info end @@ -90,7 +106,8 @@ module TkPlace list(tk_call('place', 'slaves', master)) end - module_function :configure, :configinfo, :forget, :info, :slaves + module_function :configure, :configinfo, :current_configinfo + module_function :forget, :info, :slaves end =begin def TkPlace(win, slot, value=None) diff --git a/ext/tk/lib/tk/root.rb b/ext/tk/lib/tk/root.rb index a32972561..6e16fb198 100644 --- a/ext/tk/lib/tk/root.rb +++ b/ext/tk/lib/tk/root.rb @@ -3,9 +3,11 @@ # require 'tk' require 'tk/wm' +require 'tk/menuspec' class TkRoot] [] - # must be a regular expression of Tcl - all_mode = false - opts = args.shift - if opts.kind_of?(Array) - opts = opts.collect{|opt| - opt = opt.to_s - all_mode = true if opt == 'all' - opt - } + # If is regexp, then it must be a regular expression of Tcl + if args[0].kind_of?(Array) + opts = args.shift.collect{|opt| '-' + opt.to_s } else - args.unshift(opts) opts = [] end opts << '--' - if all_mode - tk_split_simplelist(tk_send(*(opts + args))) + ret = tk_send('search', *(opts + args)) + if ret == "" + nil else - tk_send(*(opts + args)) + ret end end def tksearch_with_count(*args) # call 'search' subcommand of text widget # args ::= [] [] - # must be a regular expression of Tcl - all_mode = false - opts = args.shift - if opts.kind_of?(Array) - opts = opts.collect{|opt| - opt = opt.to_s - all_mode = true if opt == 'all' - opt - } - var = args.shift + # If is regexp, then it must be a regular expression of Tcl + if args[0].kind_of?(Array) + opts = args.shift.collect{|opt| '-' + opt.to_s } else - var = opts opts = [] end - opts << '-count' << var << '--' + opts << '-count' << args.shift << '--' - if all_mode - tk_split_simplelist(tk_send(*(opts + args))) + ret = tk_send('search', *(opts + args)) + if ret == "" + nil else - tk_send(*(opts + args)) + ret end end diff --git a/ext/tk/lib/tk/toplevel.rb b/ext/tk/lib/tk/toplevel.rb index b7f9bed74..c95002dbe 100644 --- a/ext/tk/lib/tk/toplevel.rb +++ b/ext/tk/lib/tk/toplevel.rb @@ -3,9 +3,11 @@ # require 'tk' require 'tk/wm' +require 'tk/menuspec' class TkToplevel= 0 @trace_var.delete_at(idx) @@ -694,7 +697,8 @@ end @trace_elem.each{|elem| @trace_elem[elem].each{|e| - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} + # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} + e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)} } } @@ -751,11 +755,13 @@ end newopts = '' @trace_var.each{|e| - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} + # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} + e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)} } @trace_elem.each{|elem| @trace_elem[elem].each{|e| - e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} + # e[0].each_byte{|c| newopts += c.chr unless newopts.index(c)} + e[0].each_byte{|c| newopts.concat(c.chr) unless newopts.index(c)} } } -- cgit