diff options
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/lib/tk.rb | 347 | ||||
-rw-r--r-- | ext/tk/lib/tkafter.rb | 22 | ||||
-rw-r--r-- | ext/tk/lib/tkbgerror.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkcanvas.rb | 45 | ||||
-rw-r--r-- | ext/tk/lib/tkconsole.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkdialog.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkentry.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkfont.rb | 17 | ||||
-rw-r--r-- | ext/tk/lib/tkmacpkg.rb | 2 | ||||
-rw-r--r-- | ext/tk/lib/tkmngfocus.rb | 6 | ||||
-rw-r--r-- | ext/tk/lib/tkpalette.rb | 6 | ||||
-rw-r--r-- | ext/tk/lib/tktext.rb | 29 | ||||
-rw-r--r-- | ext/tk/lib/tkvirtevent.rb | 15 | ||||
-rw-r--r-- | ext/tk/lib/tkwinpkg.rb | 4 |
14 files changed, 317 insertions, 184 deletions
diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index ec69fb04ce..e0c11c1c0d 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -15,32 +15,18 @@ module TkComm 'None' end - Tk_CMDTBL = {} - Tk_WINDOWS = {} - Tk_IDs = [0, 0] # [0]-cmdid, [1]-winid + #Tk_CMDTBL = {} + #Tk_WINDOWS = {} + Tk_IDs = ["00000", "00000"] # [0]-cmdid, [1]-winid - INITIALIZE_TARGETS = [self] - - def self.__init_tables__ - Tk_WINDOWS.clear + # for backward compatibility + Tk_CMDTBL = Object.new + def Tk_CMDTBL.method_missing(id, *args) + TkCore::INTERP.tk_cmd_tbl.send(id, *args) end - - def self.__add_target_for_init__(target) - INITIALIZE_TARGETS << target - - if target.const_defined? :TkINTERP_SETUP_SCRIPTS - target::TkINTERP_SETUP_SCRIPTS.collect{|script| - if script.kind_of? Proc - script.call - elsif script.kind_of? Array - Tk.ip_invoke(*script) - else - Tk.ip_eval(script) - end - } - else - nil - end + Tk_WINDOWS = Object.new + def Tk_WINDOWS.method_missing(id, *args) + TkCore::INTERP.tk_windows.send(id, *args) end def error_at @@ -80,7 +66,8 @@ module TkComm #{classname_def} def initialize(path) @path=path - Tk_WINDOWS[@path] = self + #Tk_WINDOWS[@path] = self + TkCore::INTERP.tk_windows[@path] = self end end" end @@ -91,7 +78,8 @@ module TkComm def tk_tcl2ruby(val) if val =~ /^rb_out (c\d+)/ - return Tk_CMDTBL[$1] + #return Tk_CMDTBL[$1] + return TkCore::INTERP.tk_cmd_tbl[$1] end if val.include? ?\s return val.split.collect{|v| tk_tcl2ruby(v)} @@ -102,7 +90,9 @@ module TkComm when /^-?\d+$/ val.to_i when /^\./ - Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val) + #Tk_WINDOWS[val] ? Tk_WINDOWS[val] : _genobj_for_tkwidget(val) + TkCore::INTERP.tk_windows[val]? + TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val) when /^i\d+$/ TkImage::Tk_IMGTBL[val]? TkImage::Tk_IMGTBL[val] : val when / / @@ -251,14 +241,17 @@ module TkComm end def window(val) if val =~ /^\./ - Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val) + #Tk_WINDOWS[val]? Tk_WINDOWS[val] : _genobj_for_tkwidget(val) + TkCore::INTERP.tk_windows[val]? + TkCore::INTERP.tk_windows[val] : _genobj_for_tkwidget(val) else nil end end def procedure(val) if val =~ /^rb_out (c\d+)/ - Tk_CMDTBL[$1] + #Tk_CMDTBL[$1] + TkCore::INTERP.tk_cmd_tbl[$1] else #nil val @@ -311,11 +304,13 @@ module TkComm private :ruby2tcl def _curr_cmd_id - id = format("c%.4d", Tk_IDs[0]) + #id = format("c%.4d", Tk_IDs[0]) + id = "c" + Tk_IDs[0] end def _next_cmd_id id = _curr_cmd_id - Tk_IDs[0] += 1 + #Tk_IDs[0] += 1 + Tk_IDs[0].succ! id end private :_curr_cmd_id, :_next_cmd_id @@ -323,21 +318,25 @@ module TkComm def install_cmd(cmd) return '' if cmd == '' id = _next_cmd_id - Tk_CMDTBL[id] = cmd + #Tk_CMDTBL[id] = cmd + TkCore::INTERP.tk_cmd_tbl[id] = cmd @cmdtbl = [] unless defined? @cmdtbl @cmdtbl.push id return format("rb_out %s", id); end def uninstall_cmd(id) id = $1 if /rb_out (c\d+)/ =~ id - Tk_CMDTBL.delete(id) + #Tk_CMDTBL.delete(id) + TkCore::INTERP.tk_cmd_tbl.delete(id) end private :install_cmd, :uninstall_cmd def install_win(ppath,name=nil) if !name or name == '' - name = format("w%.4d", Tk_IDs[1]) - Tk_IDs[1] += 1 + #name = format("w%.4d", Tk_IDs[1]) + #Tk_IDs[1] += 1 + name = "w" + Tk_IDs[1] + Tk_IDs[1].succ! end if name[0] == ?. @path = name.dup @@ -346,11 +345,13 @@ module TkComm else @path = format("%s.%s", ppath, name) end - Tk_WINDOWS[@path] = self + #Tk_WINDOWS[@path] = self + TkCore::INTERP.tk_windows[@path] = self end def uninstall_win() - Tk_WINDOWS.delete(@path) + #Tk_WINDOWS.delete(@path) + TkCore::INTERP.tk_windows.delete(@path) end private :install_win, :uninstall_win @@ -552,7 +553,8 @@ module TkComm if context tk_call(*what+["<#{tk_event_sequence(context)}>"]).collect {|cmdline| if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ - [Tk_CMDTBL[$1], $2] + #[Tk_CMDTBL[$1], $2] + [TkCore::INTERP.tk_cmd_tbl[$1], $2] else cmdline end @@ -636,9 +638,75 @@ module TkCore include TkComm extend TkComm - INTERP = TclTkIp.new unless self.const_defined? :INTERP + unless self.const_defined? :INTERP + if self.const_defined? :IP_NAME + name = IP_NAME.to_s + else + name = nil + end + if self.const_defined? :IP_OPTS + if IP_OPTS.kind_of?(Hash) + opts = hash_kv(IP_OPTS).join(' ') + else + opts = IP_OPTS.to_s + end + else + opts = '' + end + + INTERP = TclTkIp.new(name, opts) + + def INTERP.__ip_id + nil + end + + INTERP.instance_eval{ + @tk_cmd_tbl = {} + @tk_windows = {} + + @tk_table_list = [] + + @init_ip_env = [] # table of Procs + @add_tk_procs = [] # table of [name, body] + } + def INTERP.tk_cmd_tbl + @tk_cmd_tbl + end + def INTERP.tk_windows + @tk_windows + end + + def INTERP.tk_object_table(id) + @tk_table_list[id] + end + def INTERP.create_table + id = @tk_table_list.size + @tk_table_list << {} + obj = Object.new + obj.instance_eval <<-EOD + def self.method_missing(m, *args) + TkCore::INTERP.tk_object_table(#{id}).send(m, *args) + end + EOD + return obj + end + + def INTERP.init_ip_env(script = Proc.new) + @init_ip_env << script + script.call(self) + end + def INTERP.add_tk_procs(name, args, body) + @add_tk_procs << [name, args, body] + self._invoke('proc', name, args, body) + end + def INTERP.init_ip_internal + ip = self + @init_ip_env.each{|script| script.call(ip)} + @add_tk_procs.each{|name,args,body| ip._invoke('proc',name,args,body)} + end + end - INTERP._invoke("proc", "rb_out", "args", <<-'EOL') + INTERP.add_tk_procs('rb_out', 'args', <<-'EOL') regsub -all {!} $args {\\!} args regsub -all "{" $args "\\{" args if {[set st [catch {ruby [format "TkCore.callback %%Q!%s!" $args]} ret]] != 0} { @@ -729,7 +797,9 @@ module TkCore def TkCore.callback(arg) # arg = tk_split_list(arg) arg = tk_split_simplelist(arg) - _get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg)) + #_get_eval_string(TkUtil.eval_cmd(Tk_CMDTBL[arg.shift], *arg)) + _get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.tk_cmd_tbl[arg.shift], + *arg)) end def windowingsystem @@ -824,13 +894,13 @@ module TkCore TclTkLib.get_eventloop_weight end - def restart(app_name = nil, use = nil) - TkComm::INITIALIZE_TARGETS.each{|m| m.__init_tables__ } + def restart(app_name = nil, keys = {}) + TkCore::INTERP.init_ip_internal tk_call('set', 'argv0', app_name) if app_name - if use - tk_call('set', 'argc', 2) - tk_call('set', 'argv', "-use #{use}") + if keys.kind_of?(Hash) && keys.size > 0 + # tk_call('set', 'argc', keys.size * 2) + tk_call('set', 'argv', hash_kv(keys).join(' ')) end INTERP.restart @@ -919,6 +989,8 @@ module TkPackage include TkCore extend TkPackage + TkCommandNames = ['package'.freeze].freeze + def add_path(path) Tk::AUTO_PATH.value = Tk::AUTO_PATH.to_a << path end @@ -1136,6 +1208,9 @@ module Tk module Wm include TkComm + + TkCommandNames = ['wm'.freeze].freeze + def aspect(*args) w = tk_call('wm', 'aspect', path, *args) if args.length == 0 @@ -1403,25 +1478,33 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK end module Tk - def encoding=(name) - INTERP.encoding = name - end + module Encoding + extend Encoding - def encoding - INTERP.encoding - end + TkCommandNames = ['encoding'.freeze].freeze - def encoding_names - tk_split_simplelist(tk_call('encoding', 'names')) - end + def encoding=(name) + INTERP.encoding = name + end - def encoding_system - tk_call('encoding', 'system') - end + def encoding + INTERP.encoding + end - def encoding_system=(enc) - tk_call('encoding', 'system', enc) + def encoding_names + tk_split_simplelist(tk_call('encoding', 'names')) + end + + def encoding_system + tk_call('encoding', 'system') + end + + def encoding_system=(enc) + tk_call('encoding', 'system', enc) + end end + + extend Encoding end # estimate encoding @@ -1443,21 +1526,27 @@ if /^8\.[1-9]/ =~ Tk::TCL_VERSION && !Tk::JAPANIZED_TK else # dummy methods module Tk - def encoding=(name) - nil - end - def encoding - nil - end - def encoding_names - nil - end - def encoding_system - nil - end - def encoding_system=(enc) - nil + module Encoding + extend Encoding + + def encoding=(name) + nil + end + def encoding + nil + end + def encoding_names + nil + end + def encoding_system + nil + end + def encoding_system=(enc) + nil + end end + + extend Encoding end end @@ -1482,15 +1571,11 @@ end class TkBindTag include TkBindCore - BTagID_TBL = {} - Tk_BINDTAG_ID = ["btag00000"] - - TkComm.__add_target_for_init__(self) + #BTagID_TBL = {} + BTagID_TBL = TkCore::INTERP.create_table + Tk_BINDTAG_ID = ["btag".freeze, "00000"] - def self.__init_tables__ - BTagID_TBL.clear - Tk_BINDTAG_ID[0] = "btag00000" - end + TkCore::INTERP.init_ip_env{ BTagID_TBL.clear } def TkBindTag.id2obj(id) BTagID_TBL[id]? BTagID_TBL[id]: id @@ -1506,8 +1591,8 @@ class TkBindTag end def initialize(*args, &b) - @id = Tk_BINDTAG_ID[0] - Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ + @id = Tk_BINDTAG_ID.join + Tk_BINDTAG_ID[1].succ! BTagID_TBL[@id] = self bind(*args, &b) if args != [] end @@ -1557,22 +1642,16 @@ class TkVariable include Tk extend TkCore - TkVar_CB_TBL = {} - TkVar_ID_TBL = {} - Tk_VARIABLE_ID = ["v00000"] + TkCommandNames = ['tkwait'.freeze].freeze - # this constant must be defined befor calling __add_target_for_init__ - TkINTERP_SETUP_SCRIPTS = [ - ["proc", "rb_var", "args", - "ruby [format \"TkVariable.callback %%Q!%s!\" $args]"] - ] + #TkVar_CB_TBL = {} + #TkVar_ID_TBL = {} + TkVar_CB_TBL = TkCore::INTERP.create_table + TkVar_ID_TBL = TkCore::INTERP.create_table + Tk_VARIABLE_ID = ["v".freeze, "00000"] - TkComm.__add_target_for_init__(self) - - def self.__init_tables__ - # cannot clear - # Tcl interpreter may keeps callbacks - end + TkCore::INTERP.add_tk_procs('rb_var', 'args', + "ruby [format \"TkVariable.callback %%Q!%s!\" $args]") def TkVariable.callback(args) name1,name2,op = tk_split_list(args) @@ -1584,8 +1663,8 @@ class TkVariable end def initialize(val="") - @id = Tk_VARIABLE_ID[0] - Tk_VARIABLE_ID[0] = Tk_VARIABLE_ID[0].succ + @id = Tk_VARIABLE_ID.join + Tk_VARIABLE_ID[1].succ! TkVar_ID_TBL[@id] = self if val == [] INTERP._eval(format('global %s; set %s(0) 0; unset %s(0)', @@ -1885,6 +1964,8 @@ module TkSelection include Tk extend Tk + TkCommandNames = ['selection'.freeze].freeze + def self.clear(sel=nil) if sel tk_call 'selection', 'clear', '-selection', sel @@ -1960,6 +2041,12 @@ module TkKinput include Tk extend Tk + TkCommandNames = [ + 'kinput_start'.freeze, + 'kinput_send_spot'.freeze, + 'kanjiInput'.freeze + ].freeze + def TkKinput.start(window, style=None) tk_call 'kinput_start', window.path, style end @@ -2022,6 +2109,8 @@ module TkXIM include Tk extend Tk + TkCommandNames = ['imconfigure'.freeze].freeze + def TkXIM.useinputmethods(window=nil, value=nil) if window if value @@ -2107,6 +2196,8 @@ module TkWinfo include Tk extend Tk + TkCommandNames = ['winfo'.freeze].freeze + def TkWinfo.atom(name, win=nil) if win number(tk_call('winfo', 'atom', '-displayof', win, name)) @@ -2481,6 +2572,9 @@ end module TkPack include Tk extend Tk + + TkCommandNames = ['pack'.freeze].freeze + def configure(win, *args) if args[-1].kind_of?(Hash) keys = args.pop @@ -2524,6 +2618,8 @@ module TkGrid include Tk extend Tk + TkCommandNames = ['grid'.freeze].freeze + def bbox(*args) list(tk_call('grid', 'bbox', *args)) end @@ -2619,6 +2715,8 @@ module TkPlace include Tk extend Tk + TkCommandNames = ['place'.freeze].freeze + def configure(win, slot, value=None) if slot.kind_of? Hash tk_call 'place', 'configure', win.epath, *hash_kv(slot) @@ -2668,6 +2766,8 @@ module TkOptionDB include Tk extend Tk + TkCommandNames = ['option'.freeze].freeze + module Priority WidgetDefault = 20 StartupFile = 40 @@ -2695,7 +2795,7 @@ module TkOptionDB private :new CARRIER = '.'.freeze - METHOD_TBL = {} + METHOD_TBL = TkCore::INTERP.create_table ADD_METHOD = false SAFE_MODE = 4 @@ -2765,7 +2865,7 @@ module TkOptionDB body = <<-"EOD" class #{klass} < TkOptionDB.module_eval('@@resource_proc_class') CARRIER = '#{carrier}'.freeze - METHOD_TBL = {} + METHOD_TBL = TkCore::INTERP.create_table ADD_METHOD = #{add} SAFE_MODE = #{safe} %w(#{func_str}).each{|f| METHOD_TBL[f.intern] = nil } @@ -3654,6 +3754,8 @@ end class TkRoot<TkWindow include Wm + +=begin ROOT = [] def TkRoot.new(keys=nil) if ROOT[0] @@ -3673,6 +3775,24 @@ class TkRoot<TkWindow ROOT[0] = new Tk_WINDOWS["."] = new end +=end + def TkRoot.new(keys=nil) + unless TkCore::INTERP.tk_windows['.'] + TkCore::INTERP.tk_windows['.'] = + super(:without_creating=>true, :widgetname=>'.') + end + root = TkCore::INTERP.tk_windows['.'] + if keys # wm commands + keys.each{|k,v| + if v.kind_of? Array + root.send(k,*v) + else + root.send(k,v) + end + } + end + return root + end WidgetClassName = 'Tk'.freeze WidgetClassNames[WidgetClassName] = self @@ -3688,6 +3808,7 @@ end class TkToplevel<TkWindow include Wm + TkCommandNames = ['toplevel'.freeze].freeze WidgetClassName = 'Toplevel'.freeze WidgetClassNames[WidgetClassName] = self @@ -3890,6 +4011,7 @@ class TkToplevel<TkWindow end class TkFrame<TkWindow + TkCommandNames = ['frame'.freeze].freeze WidgetClassName = 'Frame'.freeze WidgetClassNames[WidgetClassName] = self @@ -4017,6 +4139,7 @@ class TkLabelFrame<TkFrame end class TkPanedWindow<TkWindow + TkCommandNames = ['panedwindow'.freeze].freeze WidgetClassName = 'Panedwindow'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4128,6 +4251,7 @@ end TkPanedwindow = TkPanedWindow class TkLabel<TkWindow + TkCommandNames = ['label'.freeze].freeze WidgetClassName = 'Label'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4143,6 +4267,7 @@ class TkLabel<TkWindow end class TkButton<TkLabel + TkCommandNames = ['button'.freeze].freeze WidgetClassName = 'Button'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4162,6 +4287,7 @@ class TkButton<TkLabel end class TkRadioButton<TkButton + TkCommandNames = ['radiobutton'.freeze].freeze WidgetClassName = 'Radiobutton'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4186,6 +4312,7 @@ end TkRadiobutton = TkRadioButton class TkCheckButton<TkRadioButton + TkCommandNames = ['checkbutton'.freeze].freeze WidgetClassName = 'Checkbutton'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4203,6 +4330,7 @@ end TkCheckbutton = TkCheckButton class TkMessage<TkLabel + TkCommandNames = ['message'.freeze].freeze WidgetClassName = 'Message'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4215,6 +4343,7 @@ class TkMessage<TkLabel end class TkScale<TkWindow + TkCommandNames = ['scale'.freeze].freeze WidgetClassName = 'Scale'.freeze WidgetClassNames[WidgetClassName] = self @@ -4252,6 +4381,7 @@ class TkScale<TkWindow end class TkScrollbar<TkWindow + TkCommandNames = ['scrollbar'.freeze].freeze WidgetClassName = 'Scrollbar'.freeze WidgetClassNames[WidgetClassName] = self @@ -4344,6 +4474,7 @@ class TkListbox<TkTextWin include TkTreatListItemFont include Scrollable + TkCommandNames = ['listbox'.freeze].freeze WidgetClassName = 'Listbox'.freeze WidgetClassNames[WidgetClassName] = self @@ -4482,6 +4613,7 @@ end class TkMenu<TkWindow include TkTreatMenuEntryFont + TkCommandNames = ['menu'.freeze].freeze WidgetClassName = 'Menu'.freeze WidgetClassNames[WidgetClassName] = self @@ -4657,7 +4789,8 @@ module TkSystemMenu fail ArgumentError, "parent must be a TkMenu object" end @path = format("%s.%s", parent.path, self.class::SYSMENU_NAME) - TkComm::Tk_WINDOWS[@path] = self + #TkComm::Tk_WINDOWS[@path] = self + TkCore::INTERP.tk_windows[@path] = self if self.method(:create_self).arity == 0 p 'create_self has no arg' if $DEBUG create_self @@ -4688,6 +4821,7 @@ class TkSysMenu_Apple<TkMenu end class TkMenubutton<TkLabel + TkCommandNames = ['menubutton'.freeze].freeze WidgetClassName = 'Menubutton'.freeze WidgetClassNames[WidgetClassName] = self def create_self(keys) @@ -4700,10 +4834,13 @@ class TkMenubutton<TkLabel end class TkOptionMenubutton<TkMenubutton + TkCommandNames = ['tk_optionMenu'.freeze].freeze + class OptionMenu<TkMenu def initialize(path) #==> return value of tk_optionMenu @path = path - TkComm::Tk_WINDOWS[@path] = self + #TkComm::Tk_WINDOWS[@path] = self + TkCore::INTERP.tk_windows[@path] = self end end @@ -4843,6 +4980,8 @@ module TkClipboard include Tk extend Tk + TkCommandNames = ['clipboard'.freeze].freeze + def self.clear(win=nil) if win tk_call 'clipboard', 'clear', '-displayof', win diff --git a/ext/tk/lib/tkafter.rb b/ext/tk/lib/tkafter.rb index fec93a6a04..4401bce719 100644 --- a/ext/tk/lib/tkafter.rb +++ b/ext/tk/lib/tkafter.rb @@ -9,21 +9,13 @@ class TkTimer include TkCore extend TkCore - Tk_CBID = [0] - Tk_CBTBL = {} + TkCommandNames = ['after'.freeze].freeze - # this constant must be defined befor calling __add_target_for_init__ - TkINTERP_SETUP_SCRIPTS = [ - ["proc", "rb_after", "id", - "ruby [format \"#{self.name}.callback %%Q!%s!\" $id]"] - ] + Tk_CBID = ['a'.freeze, '00000'] + Tk_CBTBL = TkCore::INTERP.create_table - TkComm.__add_target_for_init__(self) - - def self.__init_tables__ - # cannot clear - # Tcl interpreter may keep callbacks - end + TkCore::INTERP.add_tk_procs('rb_after', 'id', + "ruby [format \"#{self.name}.callback %%Q!%s!\" $id]") ############################### @@ -108,8 +100,8 @@ class TkTimer end def initialize(*args) - @id = format("a%.4d", Tk_CBID[0]) - Tk_CBID[0] += 1 + @id = Tk_CBID.join + Tk_CBID[1].succ! @set_next = true diff --git a/ext/tk/lib/tkbgerror.rb b/ext/tk/lib/tkbgerror.rb index e068155b1c..760a3901b3 100644 --- a/ext/tk/lib/tkbgerror.rb +++ b/ext/tk/lib/tkbgerror.rb @@ -7,6 +7,8 @@ require 'tk' module TkBgError extend Tk + TkCommandNames = ['bgerror'.freeze].freeze + def bgerror(message) tk_call 'bgerror', message end diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb index a98d770ccd..cbe4f89043 100644 --- a/ext/tk/lib/tkcanvas.rb +++ b/ext/tk/lib/tkcanvas.rb @@ -29,6 +29,7 @@ class TkCanvas<TkWindow include TkTreatCItemFont include Scrollable + TkCommandNames = ['canvas'.freeze].freeze WidgetClassName = 'Canvas'.freeze WidgetClassNames[WidgetClassName] = self @@ -527,15 +528,10 @@ end class TkcTag<TkObject include TkcTagAccess - CTagID_TBL = {} - Tk_CanvasTag_ID = ['ctag0000'] + CTagID_TBL = TkCore::INTERP.create_table + Tk_CanvasTag_ID = ['ctag', '00000'] - TkComm.__add_target_for_init__(self) - - def self.__init_tables__ - CTagID_TBL.clear - Tk_CanvasTag_ID[0] = 'ctag0000' - end + TkCore::INTERP.init_ip_env{ CTagID_TBL.clear } def TkcTag.id2obj(canvas, id) cpath = canvas.path @@ -549,10 +545,10 @@ class TkcTag<TkObject end @c = parent @cpath = parent.path - @path = @id = Tk_CanvasTag_ID[0] + @path = @id = Tk_CanvasTag_ID.join CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] CTagID_TBL[@cpath][@id] = self - Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ + Tk_CanvasTag_ID[1] = Tk_CanvasTag_ID[1].succ if mode tk_call @c.path, "addtag", @id, mode, *args end @@ -664,17 +660,17 @@ class TkcTagCurrent<TkcTag end class TkcGroup<TkcTag - Tk_cGroup_ID = ['tkcg00000'] + Tk_cGroup_ID = ['tkcg', '00000'] def create_self(parent, *args) if not parent.kind_of?(TkCanvas) fail format("%s need to be TkCanvas", parent.inspect) end @c = parent @cpath = parent.path - @path = @id = Tk_cGroup_ID[0] + @path = @id = Tk_cGroup_ID.join CTagID_TBL[@cpath] = {} unless CTagID_TBL[@cpath] CTagID_TBL[@cpath][@id] = self - Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ + Tk_cGroup_ID[1] = Tk_cGroup_ID[1].succ add(*args) if args != [] end @@ -697,13 +693,9 @@ class TkcItem<TkObject include TkcTagAccess CItemTypeToClass = {} - CItemID_TBL = {} + CItemID_TBL = TkCore::INTERP.create_table - TkComm.__add_target_for_init__(self) - - def self.__init_tables__ - CItemID_TBL.clear - end + TkCore::INTERP.init_ip_env{ CItemID_TBL.clear } def TkcItem.type2class(type) CItemTypeToClass[type] @@ -828,19 +820,16 @@ end class TkImage<TkObject include Tk - Tk_IMGTBL = {} - Tk_Image_ID = ['i00000'] + TkCommandNames = ['image'.freeze].freeze - TkComm.__add_target_for_init__(self) + Tk_IMGTBL = TkCore::INTERP.create_table + Tk_Image_ID = ['i', '00000'] - def self.__init_tables__ - Tk_IMGTBL.clear - Tk_Image_ID[0] = 'i00000' - end + TkCore::INTERP.init_ip_env{ Tk_IMGTBL.clear } def initialize(keys=nil) - @path = Tk_Image_ID[0] - Tk_Image_ID[0] = Tk_Image_ID[0].succ + @path = Tk_Image_ID.join + Tk_Image_ID[1] = Tk_Image_ID[1].succ tk_call 'image', 'create', @type, @path, *hash_kv(keys) Tk_IMGTBL[@path] = self end diff --git a/ext/tk/lib/tkconsole.rb b/ext/tk/lib/tkconsole.rb index 0129501bee..d97df159fc 100644 --- a/ext/tk/lib/tkconsole.rb +++ b/ext/tk/lib/tkconsole.rb @@ -7,6 +7,8 @@ module TkConsole include Tk extend Tk + TkCommandNames = ['console'.freeze].freeze + def self.title(str=None) tk_call 'console', str end diff --git a/ext/tk/lib/tkdialog.rb b/ext/tk/lib/tkdialog.rb index fd6e041576..2c280d5618 100644 --- a/ext/tk/lib/tkdialog.rb +++ b/ext/tk/lib/tkdialog.rb @@ -3,6 +3,8 @@ require "tk" class TkDialog2 < TkWindow extend Tk + TkCommandNames = ['tk_dialog'.freeze].freeze + def self.show(*args) dlog = self.new(*args) dlog.show diff --git a/ext/tk/lib/tkentry.rb b/ext/tk/lib/tkentry.rb index 20cca6bec7..62b6535ef3 100644 --- a/ext/tk/lib/tkentry.rb +++ b/ext/tk/lib/tkentry.rb @@ -8,6 +8,7 @@ require 'tk.rb' class TkEntry<TkLabel include Scrollable + TkCommandNames = ['entry'.freeze].freeze WidgetClassName = 'Entry'.freeze WidgetClassNames[WidgetClassName] = self @@ -221,6 +222,7 @@ class TkEntry<TkLabel end class TkSpinbox<TkEntry + TkCommandNames = ['spinbox'.freeze].freeze WidgetClassName = 'Spinbox'.freeze WidgetClassNames[WidgetClassName] = self diff --git a/ext/tk/lib/tkfont.rb b/ext/tk/lib/tkfont.rb index 4dfdd7a71c..68eb91039b 100644 --- a/ext/tk/lib/tkfont.rb +++ b/ext/tk/lib/tkfont.rb @@ -9,17 +9,16 @@ class TkFont include Tk extend TkCore - Tk_FontID = [0] - Tk_FontNameTBL = {} - Tk_FontUseTBL = {} + TkCommandNames = ['font'.freeze].freeze - TkComm.__add_target_for_init__(self) + Tk_FontID = ["@font".freeze, "00000"] + Tk_FontNameTBL = TkCore::INTERP.create_table + Tk_FontUseTBL = TkCore::INTERP.create_table - def self.__init_tables__ + TkCore::INTERP.init_ip_env{ Tk_FontNameTBL.clear Tk_FontUseTBL.clear - Tk_FontID[0] = 0 - end + } # set default font case Tk::TK_VERSION @@ -222,8 +221,8 @@ class TkFont private ################################### def initialize(ltn=DEFAULT_LATIN_FONT_NAME, knj=nil, keys=nil) - @id = format("@font%.4d", Tk_FontID[0]) - Tk_FontID[0] += 1 + @id = Tk_FontID.join + Tk_FontID[1].succ! Tk_FontNameTBL[@id] = self knj = DEFAULT_KANJI_FONT_NAME if JAPANIZED_TK && !knj create_compoundfont(ltn, knj, keys) diff --git a/ext/tk/lib/tkmacpkg.rb b/ext/tk/lib/tkmacpkg.rb index 1bd2d711b6..3bac5e6c3e 100644 --- a/ext/tk/lib/tkmacpkg.rb +++ b/ext/tk/lib/tkmacpkg.rb @@ -12,6 +12,8 @@ module TkMacResource extend Tk extend TkMacResource + TkCommandNames = ['resource'.freeze].freeze + tk_call('package', 'require', 'resource') def close(rsrcRef) diff --git a/ext/tk/lib/tkmngfocus.rb b/ext/tk/lib/tkmngfocus.rb index f76855ed9f..461525009f 100644 --- a/ext/tk/lib/tkmngfocus.rb +++ b/ext/tk/lib/tkmngfocus.rb @@ -7,6 +7,12 @@ require 'tk' module TkManageFocus extend Tk + TkCommandNames = [ + 'tk_focusFollowMouse'.freeze, + 'tk_focusNext'.freeze, + 'tk_focusPrev'.freeze + ].freeze + def TkManageFocus.followsMouse tk_call 'tk_focusFollowsMouse' end diff --git a/ext/tk/lib/tkpalette.rb b/ext/tk/lib/tkpalette.rb index a2dc7c87cb..dc2fd47e5c 100644 --- a/ext/tk/lib/tkpalette.rb +++ b/ext/tk/lib/tkpalette.rb @@ -8,6 +8,12 @@ module TkPalette include Tk extend Tk + TkCommandNames = [ + 'tk_setPalette'.freeze, + 'tk_bisque'.freeze, + 'tkDarken'.freeze + ].freeze + def TkPalette.set(*args) args = args.to_a.flatten if args.kind_of? Hash tk_call 'tk_setPalette', *args diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index f23744af22..34663f35b4 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -28,6 +28,7 @@ class TkText<TkTextWin include TkTreatTextTagFont include Scrollable + TkCommandNames = ['text'.freeze].freeze WidgetClassName = 'Text'.freeze WidgetClassNames[WidgetClassName] = self @@ -765,15 +766,10 @@ end class TkTextTag<TkObject include TkTreatTagFont - TTagID_TBL = {} - Tk_TextTag_ID = ['tag0000'] + TTagID_TBL = TkCore::INTERP.create_table + Tk_TextTag_ID = ['tag', '00000'] - TkComm.__add_target_for_init__(self) - - def self.__init_tables__ - TTagID_TBL.clear - Tk_TextTag_ID[0] = 'tag0000' - end + TkCore::INTERP.init_ip_env{ TTagID_TBL.clear } def TkTextTag.id2obj(text, id) tpath = text.path @@ -787,11 +783,11 @@ class TkTextTag<TkObject end @parent = @t = parent @tpath = parent.path - @path = @id = Tk_TextTag_ID[0] + @path = @id = Tk_TextTag_ID.join TTagID_TBL[@id] = self TTagID_TBL[@tpath] = {} unless TTagID_TBL[@tpath] TTagID_TBL[@tpath][@id] = self - Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ + Tk_TextTag_ID[1].succ! #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) if args != [] then keys = args.pop @@ -974,15 +970,10 @@ class TkTextTagSel<TkTextNamedTag end class TkTextMark<TkObject - TMarkID_TBL = {} - Tk_TextMark_ID = ['mark0000'] + TMarkID_TBL = TkCore::INTERP.create_table + Tk_TextMark_ID = ['mark', '00000'] - TkComm.__add_target_for_init__(self) - - def self.__init_tables__ - TMarkID_TBL.clear - Tk_TextMark_ID[0] = 'mark0000' - end + TkCore::INTERP.init_ip_env{ TMarkID_TBL.clear } def TkTextMark.id2obj(text, id) tpath = text.path @@ -996,7 +987,7 @@ class TkTextMark<TkObject end @parent = @t = parent @tpath = parent.path - @path = @id = Tk_TextMark_ID[0] + @path = @id = Tk_TextMark_ID.join TMarkID_TBL[@id] = self TMarkID_TBL[@tpath] = {} unless TMarkID_TBL[@tpath] TMarkID_TBL[@tpath][@id] = self diff --git a/ext/tk/lib/tkvirtevent.rb b/ext/tk/lib/tkvirtevent.rb index aa37d626e7..c594d4716f 100644 --- a/ext/tk/lib/tkvirtevent.rb +++ b/ext/tk/lib/tkvirtevent.rb @@ -7,15 +7,12 @@ require 'tk' class TkVirtualEvent<TkObject extend Tk - TkVirtualEventID = [0] - TkVirtualEventTBL = {} + TkCommandNames = ['event'.freeze].freeze - TkComm.__add_target_for_init__(self) + TkVirtualEventID = ["<VirtEvent".freeze, "00000", ">".freeze] + TkVirtualEventTBL = TkCore::INTERP.create_table - def self.__init_tables__ - TkVirtualEventTBL.clear - TkVirtualEventID[0] = 0 - end + TkCore::INTERP.init_ip_env{ TkVirtualEventTBL.clear } class PreDefVirtEvent<self def initialize(event) @@ -44,8 +41,8 @@ class TkVirtualEvent<TkObject end def initialize(*sequences) - @path = @id = format("<VirtEvent%.4d>", TkVirtualEventID[0]) - TkVirtualEventID[0] += 1 + @path = @id = TkVirtualEventID.join + TkVirtualEventID[1].succ! add(*sequences) end diff --git a/ext/tk/lib/tkwinpkg.rb b/ext/tk/lib/tkwinpkg.rb index a5ac5c7a1b..7762b3a596 100644 --- a/ext/tk/lib/tkwinpkg.rb +++ b/ext/tk/lib/tkwinpkg.rb @@ -12,6 +12,8 @@ module TkWinDDE extend Tk extend TkWinDDE + TkCommandNames = ['dde'.freeze].freeze + tk_call('package', 'require', 'dde') def servername(topic=nil) @@ -50,6 +52,8 @@ module TkWinRegistry extend Tk extend TkWinRegistry + TkCommandNames = ['registry'.freeze].freeze + tk_call('package', 'require', 'registry') def delete(keynam, valnam=nil) |