# # tk/menu.rb : treat menu and menubutton # require 'tk' module TkTreatMenuEntryFont include TkTreatItemFont ItemCMD = ['entryconfigure'.freeze, TkComm::None].freeze def __conf_cmd(idx) ItemCMD[idx] end def __item_pathname(tagOrId) self.path + ';' + tagOrId.to_s end private :__conf_cmd, :__item_pathname end class TkMenuval}) end else tk_call('entryconfigure', index, "-#{key}", val) end end self end def entryconfiginfo(index, key=nil) if TkComm::GET_CONFIGINFO_AS_ARRAY if key case key.to_s when 'text', 'label', 'show' conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('entryconfigure',_get_eval_enc_str(index),"-#{key}"))) when 'font', 'kanjifont' conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('entryconfigure',_get_eval_enc_str(index),"-#{key}"))) conf[4] = tagfont_configinfo(index, conf[4]) else conf = tk_split_list(_fromUTF8(tk_send_without_enc('entryconfigure',_get_eval_enc_str(index),"-#{key}"))) end conf[0] = conf[0][1..-1] conf else ret = tk_split_simplelist(_fromUTF8(tk_send_without_enc('entryconfigure', _get_eval_enc_str(index)))).collect{|conflist| conf = tk_split_simplelist(conflist) conf[0] = conf[0][1..-1] case conf[0] when 'text', 'label', 'show' else if conf[3] if conf[3].index('{') conf[3] = tk_split_list(conf[3]) else conf[3] = tk_tcl2ruby(conf[3]) end end if conf[4] if conf[4].index('{') conf[4] = tk_split_list(conf[4]) else conf[4] = tk_tcl2ruby(conf[4]) end end end conf[1] = conf[1][1..-1] if conf.size == 2 # alias info conf } if fontconf ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'} fontconf[4] = tagfont_configinfo(index, fontconf[4]) ret.push(fontconf) else ret end end else # ! TkComm::GET_CONFIGINFO_AS_ARRAY if key case key.to_s when 'text', 'label', 'show' conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('entryconfigure',_get_eval_enc_str(index),"-#{key}"))) when 'font', 'kanjifont' conf = tk_split_simplelist(_fromUTF8(tk_send_without_enc('entryconfigure',_get_eval_enc_str(index),"-#{key}"))) conf[4] = tagfont_configinfo(index, conf[4]) else conf = tk_split_list(_fromUTF8(tk_send_without_enc('entryconfigure',_get_eval_enc_str(index),"-#{key}"))) end key = conf.shift[1..-1] { key => conf } else ret = {} tk_split_simplelist(_fromUTF8(tk_send_without_enc('entryconfigure', _get_eval_enc_str(index)))).each{|conflist| conf = tk_split_simplelist(conflist) key = conf.shift[1..-1] case key when 'text', 'label', 'show' else if conf[2] if conf[2].index('{') conf[2] = tk_split_list(conf[2]) else conf[2] = tk_tcl2ruby(conf[2]) end end if conf[3] if conf[3].index('{') conf[3] = tk_split_list(conf[3]) else conf[3] = tk_tcl2ruby(conf[3]) end end end if conf.size == 1 ret[key] = conf[0][1..-1] # alias info else ret[key] = conf end } fontconf = ret['font'] if fontconf ret.delete('font') ret.delete('kanjifont') fontconf[3] = tagfont_configinfo(index, fontconf[3]) ret['font'] = fontconf end ret end end end def current_entryconfiginfo(index, key=nil) if TkComm::GET_CONFIGINFO_AS_ARRAY if key conf = entryconfiginfo(index, key) {conf[0] => conf[4]} else ret = {} entryconfiginfo(index).each{|conf| ret[conf[0]] = conf[4] if conf.size > 2 } ret end else # ! TkComm::GET_CONFIGINFO_AS_ARRAY ret = {} entryconfiginfo(index, key).each{|k, conf| ret[k] = conf[-1] if conf.kind_of?(Array) } ret end end end class TkMenuClone return value of tk_optionMenu @path = path #TkComm::Tk_WINDOWS[@path] = self TkCore::INTERP.tk_windows[@path] = self end end def initialize(parent=nil, var=TkVariable.new, firstval=nil, *vals) if parent.kind_of? Hash keys = _symbolkey2str(parent) parent = keys['parent'] var = keys['variable'] if keys['variable'] firstval, *vals = keys['values'] end fail 'variable option must be TkVariable' unless var.kind_of? TkVariable @variable = var firstval = @variable.value unless firstval @variable.value = firstval install_win(if parent then parent.path end) @menu = OptionMenu.new(tk_call('tk_optionMenu', @path, @variable.id, firstval, *vals)) end def value @variable.value end def activate(index) @menu.activate(index) self end def add(value) @menu.add('radiobutton', 'variable'=>@variable, 'label'=>value, 'value'=>value) self end def index(index) @menu.index(index) end def invoke(index) @menu.invoke(index) end def insert(index, value) @menu.add(index, 'radiobutton', 'variable'=>@variable, 'label'=>value, 'value'=>value) self end def delete(index, last=None) @menu.delete(index, last) self end def yposition(index) @menu.yposition(index) end def menu @menu end def menucget(key) @menu.cget(key) end def menuconfigure(key, val=None) @menu.configure(key, val) self end def menuconfiginfo(key=nil) @menu.configinfo(key) end def current_menuconfiginfo(key=nil) @menu.current_configinfo(key) end def entrycget(index, key) @menu.entrycget(index, key) end def entryconfigure(index, key, val=None) @menu.entryconfigure(index, key, val) self end def entryconfiginfo(index, key=nil) @menu.entryconfiginfo(index, key) end def current_entryconfiginfo(index, key=nil) @menu.current_entryconfiginfo(index, key) end end