From dde62bcd2efbb3825d982326896ab774e73e4218 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 17 Jan 2000 08:37:53 +0000 Subject: 2000-01-17 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tk.rb | 196 +++++++++++++++++++++++++++++++++++-------------- ext/tk/lib/tkcanvas.rb | 18 ++--- ext/tk/lib/tktext.rb | 53 +++++++++++-- 3 files changed, 193 insertions(+), 74 deletions(-) (limited to 'ext/tk') diff --git a/ext/tk/lib/tk.rb b/ext/tk/lib/tk.rb index fd0a3bb2e4..931cb90819 100644 --- a/ext/tk/lib/tk.rb +++ b/ext/tk/lib/tk.rb @@ -235,7 +235,7 @@ module TkComm return format("rb_out %s", id); end def uninstall_cmd(id) - id = $1 if /rb_out (c\d+)/ + id = $1 if /rb_out (c\d+)/ =~ id Tk_CMDTBL[id] = nil end private :install_cmd, :uninstall_cmd @@ -347,15 +347,6 @@ module TkComm 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(['bind', 'all'], context, cmd, args) - end - - def bind_append_all(context, cmd=Proc.new, args=nil) - _bind_append(['bind', 'all'], context, cmd, args) - end def _bindinfo(what, context=nil) if context @@ -372,11 +363,33 @@ module TkComm } end end + private :install_bind, :tk_event_sequence, + :_bind_core, :_bind, :_bind_append, :_bindinfo + + def bind(tagOrClass, context, cmd=Proc.new, args=nil) + _bind(["bind", tagOrClass], context, cmd, args) + end + + def bind_append(tagOrClass, context, cmd=Proc.new, args=nil) + _bind_append(["bind", tagOrClass], context, cmd, args) + end def bindinfo(tagOrClass, context=nil) _bindinfo(['bind', tagOrClass], context) end + def bind_all(context, cmd=Proc.new, args=nil) + _bind(['bind', 'all'], context, cmd, args) + end + + def bind_append_all(context, cmd=Proc.new, args=nil) + _bind_append(['bind', 'all'], context, cmd, args) + end + + def bindinfo_all(context=nil) + _bindinfo(['bind', 'all'], context) + end + def pack(*args) TkPack.configure *args end @@ -401,7 +414,7 @@ module TkCore INTERP = TclTkIp.new - INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {return -code $st $ret} {return $ret}") + INTERP._invoke("proc", "rb_out", "args", "if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $args]} ret]] != 0} {if {[regsub -all {!} $args {\\!} newargs] == 0} {return -code $st $ret} {if {[set st [catch {ruby [format \"TkCore.callback %%Q!%s!\" $newargs]} ret]] != 0} {return -code $st $ret} {return $ret}}} {return $ret}") def callback_break raise TkCallbackBreak, "Tk callback returns 'break' status" @@ -575,8 +588,8 @@ module Tk module Wm include TkComm def aspect(*args) - w = window(tk_call('wm', 'grid', path, *args)) - w.split.collect{|s|s.to_i} if args.length == 0 + w = tk_call('wm', 'aspect', path, *args) + list(w) if args.length == 0 end def client(name=None) tk_call 'wm', 'client', path, name @@ -594,17 +607,18 @@ module Tk tk_call 'wm', 'focusmodel', path, *args end def frame - tk_call 'wm', 'frame', path + tk_call('wm', 'frame', path) end def geometry(*args) - list(tk_call('wm', 'geometry', path, *args)) + tk_call('wm', 'geometry', path, *args) end def grid(*args) w = tk_call('wm', 'grid', path, *args) list(w) if args.size == 0 end def group(*args) - tk_call 'wm', 'group', path, *args + w = tk_call 'wm', 'group', path, *args + window(w) if args.size == 0 end def iconbitmap(*args) tk_call 'wm', 'iconbitmap', path, *args @@ -628,7 +642,7 @@ module Tk end def maxsize(*args) w = tk_call('wm', 'maxsize', path, *args) - list(w) if not args.size == 0 + list(w) if args.size == 0 end def minsize(*args) w = tk_call('wm', 'minsize', path, *args) @@ -661,7 +675,7 @@ module Tk end end def sizefrom(*args) - list(tk_call('wm', 'sizefrom', path, *args)) + tk_call('wm', 'sizefrom', path, *args) end def state tk_call 'wm', 'state', path @@ -670,7 +684,7 @@ module Tk tk_call 'wm', 'title', path, *args end def transient(*args) - tk_call 'wm', 'transient', path, *args + window(tk_call 'wm', 'transient', path, *args) end def withdraw tk_call 'wm', 'withdraw', path @@ -678,6 +692,46 @@ module Tk end end +module TkBindCore + def bind(context, cmd=Proc.new, args=nil) + Tk.bind(to_eval, context, cmd, args) + end + + def bind_append(context, cmd=Proc.new, args=nil) + Tk.bind_append(to_eval, context, cmd, args) + end + + def bindinfo(context=nil) + Tk.bindinfo(to_eval, context) + end +end + +class TkBindTag + include TkBindCore + + BTagID_TBL = {} + Tk_BINDTAG_ID = ["btag00000"] + + def TkBindTag.id2obj(id) + BTagID_TBL[id]? BTagID_TBL[id]: id + end + + def initialize(*args) + @id = Tk_BINDTAG_ID[0] + Tk_BINDTAG_ID[0] = Tk_BINDTAG_ID[0].succ + BTagID_TBL[@id] = self + bind(*args) if args != [] + end + + def to_eval + @id + end + + def inspect + format "#", @id + end +end + class TkVariable include Tk extend TkCore @@ -790,7 +844,7 @@ class TkVariable end def inspect - format "", @id + format "#", @id end def ==(other) @@ -1063,19 +1117,19 @@ module TkWinfo include Tk extend Tk def TkWinfo.atom(name) - tk_call 'winfo', name + number(tk_call 'winfo', 'atom', name) end def winfo_atom(name) TkWinfo.atom name end def TkWinfo.atomname(id) - tk_call 'winfo', id + tk_call 'winfo', 'atomname', id end def winfo_atomname(id) TkWinfo.atomname id end def TkWinfo.cells(window) - number(tk_call('winfo', window.path)) + number(tk_call('winfo', 'cells', window.path)) end def winfo_cells TkWinfo.cells self @@ -1093,6 +1147,12 @@ module TkWinfo def winfo_classname TkWinfo.classname self end + def TkWinfo.colormapfull(window) + bool(tk_call('winfo', 'colormapfull', window.path)) + end + def winfo_colormapfull + TkWinfo.colormapfull self + end def TkWinfo.containing(rootX, rootY) path = tk_call('winfo', 'containing', rootX, rootY) window(path) @@ -1119,7 +1179,7 @@ module TkWinfo TkWinfo.fpixels self, number end def TkWinfo.geometry(window) - list(tk_call('winfo', 'geometry', window.path)) + tk_call('winfo', 'geometry', window.path) end def winfo_geometry TkWinfo.geometry self @@ -1131,15 +1191,15 @@ module TkWinfo TkWinfo.height self end def TkWinfo.id(window) - number(tk_call('winfo', 'id', window.path)) + tk_call('winfo', 'id', window.path) end def winfo_id TkWinfo.id self end def TkWinfo.interps(window=nil) if window - tk_split_simplelist(tk_call('winfo', '-displayof', window.path, - 'interps')) + tk_split_simplelist(tk_call('winfo', 'interps', + '-displayof', window.path)) else tk_split_simplelist(tk_call('winfo', 'interps')) end @@ -1153,8 +1213,14 @@ module TkWinfo def winfo_mapped? TkWinfo.mapped? self end + def TkWinfo.manager(window) + tk_call('winfo', 'manager', window.path) + end + def winfo_manager + TkWinfo.manager self + end def TkWinfo.appname(window) - bool(tk_call('winfo', 'name', window.path)) + tk_call('winfo', 'name', window.path) end def winfo_appname TkWinfo.appname self @@ -1255,6 +1321,12 @@ module TkWinfo def winfo_screenwidth TkWinfo.screenwidth self end + def TkWinfo.server(window) + tk_call 'winfo', 'server', window.path + end + def winfo_server + TkWinfo.server self + end def TkWinfo.toplevel(window) window(tk_call('winfo', 'toplevel', window.path)) end @@ -1267,7 +1339,24 @@ module TkWinfo def winfo_visual TkWinfo.visual self end - def TkWinfo.vrootheigh(window) + def TkWinfo.visualid(window) + tk_call 'winfo', 'visualid', window.path + end + def winfo_visualid + TkWinfo.visualid self + end + def TkWinfo.visualsavailable(window, includeids=false) + if includeids + v = tk_call('winfo', 'visualsavailable', window.path, "includeids") + else + v = tk_call('winfo', 'visualsavailable', window.path) + end + list(v) + end + def winfo_visualsavailable(includeids=false) + TkWinfo.visualsavailable self, includeids + end + def TkWinfo.vrootheight(window) number(tk_call('winfo', 'vrootheight', window.path)) end def winfo_vrootheight @@ -1540,6 +1629,7 @@ end class TkObject