# frozen_string_literal: false # # tk/menu.rb : treat menu and menubutton # require 'tk' require 'tk/itemconfig' require 'tk/menuspec' module TkMenuEntryConfig include TkItemConfigMethod def __item_cget_cmd(id) [self.path, 'entrycget', id] end private :__item_cget_cmd def __item_config_cmd(id) [self.path, 'entryconfigure', id] end private :__item_config_cmd def __item_strval_optkeys(id) super(id) << 'selectcolor' end private :__item_strval_optkeys def __item_listval_optkeys(id) [] end private :__item_listval_optkeys def __item_val2ruby_optkeys(id) # { key=>proc, ... } super(id).update('menu'=>proc{|i, v| window(v)}) end private :__item_val2ruby_optkeys alias entrycget_tkstring itemcget_tkstring alias entrycget itemcget alias entrycget_strict itemcget_strict alias entryconfigure itemconfigure alias entryconfiginfo itemconfiginfo alias current_entryconfiginfo current_itemconfiginfo private :itemcget_tkstring, :itemcget, :itemcget_strict private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo end class Tk::Menuval}) 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 end #TkMenu = Tk::Menu unless Object.const_defined? :TkMenu #Tk.__set_toplevel_aliases__(:Tk, Tk::Menu, :TkMenu) Tk.__set_loaded_toplevel_aliases__('tk/menu.rb', :Tk, Tk::Menu, :TkMenu) module Tk::Menu::TkInternalFunction; end class << Tk::Menu::TkInternalFunction # These methods calls internal functions of Tcl/Tk. # So, They may not work on your Tcl/Tk. def next_menu(menu, dir='next') dir = dir.to_s case dir when 'next', 'forward', 'down' dir = 'right' when 'previous', 'backward', 'up' dir = 'left' end Tk.tk_call('::tk::MenuNextMenu', menu, dir) end def next_entry(menu, delta) # delta is increment value of entry index. # For example, +1 denotes 'next entry' and -1 denotes 'previous entry'. Tk.tk_call('::tk::MenuNextEntry', menu, delta) end end class Tk::MenuClone return value of tk_optionMenu @path = path #TkComm::Tk_WINDOWS[@path] = self TkCore::INTERP.tk_windows[@path] = self end end def initialize(*args) # args :: [parent,] [var,] [value[, ...],] [keys] # parent --> TkWindow or nil # var --> TkVariable or nil # keys --> Hash # keys[:parent] or keys['parent'] --> parent # keys[:variable] or keys['variable'] --> var # keys[:values] or keys['values'] --> value, ... # other Hash keys are menubutton options keys = {} keys = args.pop if args[-1].kind_of?(Hash) keys = _symbolkey2str(keys) parent = nil if !args.empty? && (args[0].kind_of?(TkWindow) || args[0] == nil) keys.delete('parent') # ignore parent = args.shift else parent = keys.delete('parent') end @variable = nil if !args.empty? && (args[0].kind_of?(TkVariable) || args[0] == nil) keys.delete('variable') # ignore @variable = args.shift else @variable = keys.delete('variable') end @variable = TkVariable.new unless @variable (args = keys.delete('values') || []) if args.empty? if args.empty? args << @variable.value else @variable.value = args[0] end install_win(if parent then parent.path end) @menu = OptionMenu.new(tk_call('tk_optionMenu', @path, @variable.id, *args)) configure(keys) if keys end def value @variable.value end def value=(val) @variable.value = val 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.insert(index, 'radiobutton', 'variable'=>@variable, 'label'=>value, 'value'=>value) self end def delete(index, last=None) @menu.delete(index, last) self end def xposition(index) @menu.xposition(index) end def yposition(index) @menu.yposition(index) end def menu @menu end def menucget(key) @menu.cget(key) end def menucget_strict(key) @menu.cget_strict(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 entrycget_strict(index, key) @menu.entrycget_strict(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 Tk::OptionMenuButton = Tk::OptionMenubutton #TkOptionMenubutton = Tk::OptionMenubutton unless Object.const_defined? :TkOptionMenubutton #TkOptionMenuButton = Tk::OptionMenuButton unless Object.const_defined? :TkOptionMenuButton #Tk.__set_toplevel_aliases__(:Tk, Tk::OptionMenubutton, # :TkOptionMenubutton, :TkOptionMenuButton) Tk.__set_loaded_toplevel_aliases__('tk/menu.rb', :Tk, Tk::OptionMenubutton, :TkOptionMenubutton, :TkOptionMenuButton)