diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-01-17 08:37:53 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2000-01-17 08:37:53 +0000 |
commit | dde62bcd2efbb3825d982326896ab774e73e4218 (patch) | |
tree | 6a421d3818dd390cf8f6b2c5544726a8950e1401 /ext/tk | |
parent | e43877719bd4bbd12e493e896a0f98c5b349937b (diff) |
2000-01-17
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk')
-rw-r--r-- | ext/tk/lib/tk.rb | 196 | ||||
-rw-r--r-- | ext/tk/lib/tkcanvas.rb | 18 | ||||
-rw-r--r-- | ext/tk/lib/tktext.rb | 53 |
3 files changed, 193 insertions, 74 deletions
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 "#<TkBindTag: %s>", @id + end +end + class TkVariable include Tk extend TkCore @@ -790,7 +844,7 @@ class TkVariable end def inspect - format "<TkVariable: %s>", @id + format "#<TkVariable: %s>", @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<TkKernel include Tk include TkTreatFont + include TkBindCore def path return @path @@ -1636,18 +1726,6 @@ class TkObject<TkKernel end end - def bind(context, cmd=Proc.new, args=nil) - _bind(["bind", to_eval], context, cmd, args) - end - - def bind_append(context, cmd=Proc.new, args=nil) - _bind_append(["bind", to_eval], context, cmd, args) - end - - def bindinfo(context=nil) - _bindinfo(['bind', to_eval], context) - end - def event_generate(context, keys=nil) if keys tk_call('event', 'generate', path, @@ -1671,7 +1749,7 @@ class TkObject<TkKernel end class TkWindow<TkObject -# extend TkClassBind + extend TkBindCore def initialize(parent=nil, keys=nil) install_win(if parent then parent.path end) @@ -1819,11 +1897,15 @@ class TkWindow<TkObject fail unless taglist.kind_of? Array tk_call('bindtags', path, taglist) else - tk_split_list(tk_call('bindtags', path)).collect{|tag| - if tag == nil - '.' - elsif tag.kind_of?(String) && (cls = WidgetClassNames[tag]) - cls + list(tk_call('bindtags', path)).collect{|tag| + if tag.kind_of?(String) + if cls = WidgetClassNames[tag] + cls + elsif btag = TkBindTag.id2obj(tag) + btag + else + tag + end else tag end @@ -1874,12 +1956,12 @@ class TkToplevel<TkWindow @classname = classname if keys.kind_of? Hash keys = keys.dup - @classname = keys.delete('classname') - @colormap = keys.delete('colormap') - @container = keys.delete('container') - @screen = keys.delete('screen') - @use = keys.delete('use') - @visual = keys.delete('visual') + @classname = keys.delete('classname') if keys.key?('classname') + @colormap = keys.delete('colormap') if keys.key?('colormap') + @container = keys.delete('container') if keys.key?('container') + @screen = keys.delete('screen') if keys.key?('screen') + @use = keys.delete('use') if keys.key?('use') + @visual = keys.delete('visual') if keys.key?('visual') end super(parent, keys) end @@ -1910,10 +1992,10 @@ class TkFrame<TkWindow def initialize(parent=nil, keys=nil) if keys.kind_of? Hash keys = keys.dup - @classname = keys.delete('classname') - @colormap = keys.delete('colormap') - @container = keys.delete('container') - @visual = keys.delete('visual') + @classname = keys.delete('classname') if keys.key?('classname') + @colormap = keys.delete('colormap') if keys.key?('colormap') + @container = keys.delete('container') if keys.key?('container') + @visual = keys.delete('visual') if keys.key?('visual') end super(parent, keys) end diff --git a/ext/tk/lib/tkcanvas.rb b/ext/tk/lib/tkcanvas.rb index 5f03b0f3a9..80c36f6ed8 100644 --- a/ext/tk/lib/tkcanvas.rb +++ b/ext/tk/lib/tkcanvas.rb @@ -489,15 +489,15 @@ class TkcTag<TkObject CTagID_TBL[id]? CTagID_TBL[id]: id end - $tk_canvas_tag = 'ctag0000' + Tk_CanvasTag_ID = ['ctag0000'] def initialize(parent, mode=nil, *args) if not parent.kind_of?(TkCanvas) fail format("%s need to be TkCanvas", parent.inspect) end @c = parent - @path = @id = $tk_canvas_tag + @path = @id = Tk_CanvasTag_ID[0] CTagID_TBL[@id] = self - $tk_canvas_tag = $tk_canvas_tag.succ + Tk_CanvasTag_ID[0] = Tk_CanvasTag_ID[0].succ if mode tk_call @c.path, "addtag", @id, mode, *args end @@ -572,15 +572,15 @@ class TkcTagCurrent<TkcTag end class TkcGroup<TkcTag - $tk_group_id = 'tkg00000' + Tk_cGroup_ID = ['tkcg00000'] def create_self(parent, *args) if not parent.kind_of?(TkCanvas) fail format("%s need to be TkCanvas", parent.inspect) end @c = parent - @path = @id = $tk_group_id + @path = @id = Tk_cGroup_ID[0] CTagID_TBL[@id] = self - $tk_group_id = $tk_group_id.succ + Tk_cGroup_ID[0] = Tk_cGroup_ID[0].succ add(*args) if args != [] end @@ -702,10 +702,10 @@ class TkImage<TkObject Tk_IMGTBL = {} - $tk_image_id = 'i00000' + Tk_Image_ID = ['i00000'] def initialize(keys=nil) - @path = $tk_image_id - $tk_image_id = $tk_image_id.succ + @path = Tk_Image_ID[0] + Tk_Image_ID[0] = Tk_Image_ID[0].succ tk_call 'image', 'create', @type, @path, *hash_kv(keys) Tk_IMGTBL[@path] = self end diff --git a/ext/tk/lib/tktext.rb b/ext/tk/lib/tktext.rb index 9d5037e4e2..7872e6a078 100644 --- a/ext/tk/lib/tktext.rb +++ b/ext/tk/lib/tktext.rb @@ -123,30 +123,48 @@ end class TkText<TkTextWin include TkTreatTextTagFont + include Scrollable WidgetClassName = 'Text'.freeze WidgetClassNames[WidgetClassName] = self + def self.to_eval WidgetClassName end - include Scrollable + + def self.new(*args) + obj = super(*args){} + obj.init_instance_variable + obj.instance_eval &block if defined? yield + obj + end + + def init_instance_variable + @tags = {} + end + def create_self tk_call 'text', @path - @tags = {} + init_instance_variable end + def index(index) tk_send 'index', index end + def value tk_send 'get', "1.0", "end - 1 char" end + def value= (val) tk_send 'delete', "1.0", 'end' tk_send 'insert', "1.0", val end + def _addcmd(cmd) @cmdtbl.push cmd end + def _addtag(name, obj) @tags[name] = obj end @@ -164,11 +182,19 @@ class TkText<TkTextWin tagid2obj(elt) } end + + def mark_names + tk_split_list(tk_send('mark', 'names')).collect{|elt| + tagid2obj(elt) + } + end + def window_names tk_send('window', 'names').collect{|elt| tagid2obj(elt) } end + def image_names tk_send('image', 'names').collect{|elt| tagid2obj(elt) @@ -178,6 +204,7 @@ class TkText<TkTextWin def set_insert(index) tk_send 'mark', 'set', 'insert', index end + def set_current(index) tk_send 'mark', 'set', 'current', index end @@ -187,6 +214,7 @@ class TkText<TkTextWin end def destroy + @tags = {} unless @tags @tags.each_value do |t| t.destroy end @@ -404,14 +432,15 @@ end class TkTextTag<TkObject include TkTreatTagFont - $tk_text_tag = 'tag0000' + Tk_TextTag_ID = ['tag0000'] + def initialize(parent, *args) if not parent.kind_of?(TkText) fail format("%s need to be TkText", parent.inspect) end @parent = @t = parent - @path = @id = $tk_text_tag - $tk_text_tag = $tk_text_tag.succ + @path = @id = Tk_TextTag_ID[0] + Tk_TextTag_ID[0] = Tk_TextTag_ID[0].succ #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys) if args != [] then keys = args.pop @@ -537,14 +566,14 @@ class TkTextTagSel<TkTextTag end class TkTextMark<TkObject - $tk_text_mark = 'mark0000' + Tk_TextMark_ID = ['mark0000'] def initialize(parent, index) if not parent.kind_of?(TkText) fail format("%s need to be TkText", parent.inspect) end @t = parent - @path = @id = $tk_text_mark - $tk_text_mark = $tk_text_mark.succ + @path = @id = Tk_TextMark_ID[0] + Tk_TextMark_ID[0] = Tk_TextMark_ID[0].succ tk_call @t.path, 'mark', 'set', @id, index @t._addtag id, self end @@ -568,6 +597,14 @@ class TkTextMark<TkObject def gravity=(direction) tk_call @t.path, 'mark', 'gravity', @id, direction end + + def next(index) + @t.tagid2obj(tk_call(@t.path, 'mark', 'next', index)) + end + + def previous(index) + @t.tagid2obj(tk_call(@t.path, 'mark', 'previous', index)) + end end class TkTextMarkInsert<TkTextMark |