# # tkcanvas.rb - Tk canvas classes # $Date$ # by Yukihiro Matsumoto # $Date$ # by Hidetoshi Nagai require "tk" require 'tkfont' module TkTreatCItemFont include TkTreatItemFont ItemCMD = ['itemconfigure', TkComm::None] def __conf_cmd(idx) ItemCMD[idx] end def __item_pathname(tagOrId) if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) self.path + ';' + tagOrId.id.to_s else self.path + ';' + tagOrId.to_s end end end class TkCanvasvalue}) else tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value end end end # def itemconfigure(tagOrId, key, value=None) # if key.kind_of? Hash # tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key) # else # tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value # end # end # def itemconfigure(tagOrId, keys) # tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(keys) # end def itemconfiginfo(tagOrId, key=nil) if key case key.to_s when 'dash', 'activedash', 'disableddash' conf = tk_split_simplelist(tk_send('itemconfigure', tagid(tagOrId), "-#{key}")) if conf[3] && conf[3] =~ /^[0-9]/ conf[3] = list(conf[3]) end if conf[4] && conf[4] =~ /^[0-9]/ conf[4] = list(conf[4]) end when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile' conf = tk_split_simplelist(tk_send('itemconfigure', tagid(tagOrId), "-#{key}")) else conf = tk_split_list(tk_send('itemconfigure', tagid(tagOrId), "-#{key}")) end conf[0] = conf[0][1..-1] conf else tk_split_simplelist(tk_send('itemconfigure', tagid(tagOrId))).collect{|conflist| conf = tk_split_simplelist(conflist) conf[0] = conf[0][1..-1] case conf[0] when 'text', 'label', 'show', 'data', 'file', 'maskdata', 'maskfile' when 'dash', 'activedash', 'disableddash' if conf[3] && conf[3] =~ /^[0-9]/ conf[3] = list(conf[3]) end if conf[4] && conf[4] =~ /^[0-9]/ conf[4] = list(conf[4]) end 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 } end end def lower(tag, below=None) tk_send 'lower', tagid(tag), tagid(below) end def move(tag, x, y) tk_send 'move', tagid(tag), x, y end def postscript(keys) tk_send "postscript", *hash_kv(keys) end def raise(tag, above=None) tk_send 'raise', tagid(tag), tagid(above) end def scale(tag, x, y, xs, ys) tk_send 'scale', tagid(tag), x, y, xs, ys end def scan_mark(x, y) tk_send 'scan', 'mark', x, y end def scan_dragto(x, y) tk_send 'scan', 'dragto', x, y end def select(mode, *args) tk_send 'select', mode, *args end def select_adjust(tagOrId, index) select('adjust', tagid(tagOrId), index) end def select_clear select('clear') end def select_from(tagOrId, index) select('from', tagid(tagOrId), index) end def select_item select('item') end def select_to(tagOrId, index) select('to', tagid(tagOrId), index) end def itemtype(tag) TkcItem.type2class(tk_send('type', tagid(tag))) end end module TkcTagAccess include TkComm include TkTreatTagFont def addtag(tag) @c.addtag(tag, 'with', @id) end def bbox @c.bbox(@id) end def bind(seq, cmd=Proc.new, args=nil) @c.itembind @id, seq, cmd, args end def bindinfo(seq=nil) @c.itembindinfo @id, seq end def cget(option) @c.itemcget @id, option end def configure(key, value=None) @c.itemconfigure @id, key, value end # def configure(keys) # @c.itemconfigure @id, keys # end def configinfo(key=nil) @c.itemconfiginfo @id, key end def coords(*args) @c.coords @id, *args end def dchars(first, last=None) @c.dchars @id, first, last end def dtag(tag_to_del=None) @c.dtag @id, tag_to_del end def find @c.find 'withtag', @id end alias list find def focus @c.itemfocus @id end def gettags @c.gettags @id end def icursor(index) @c.icursor @id, index end def index(index) @c.index @id, index end def insert(beforethis, string) @c.insert @id, beforethis, string end def lower(belowthis=None) @c.lower @id, belowthis end def move(xamount, yamount) @c.move @id, xamount, yamount end def raise(abovethis=None) @c.raise @id, abovethis end def scale(xorigin, yorigin, xscale, yscale) @c.scale @id, xorigin, yorigin, xscale, yscale end def select_adjust(index) @c.select('adjust', @id, index) end def select_from(index) @c.select('from', @id, index) end def select_to(index) @c.select('to', @id, index) end def itemtype @c.itemtype @id end # Following operators support logical expressions of canvas tags # (for Tk8.3+). # If tag1.path is 't1' and tag2.path is 't2', then # ltag = tag1 & tag2; ltag.path => "(t1)&&(t2)" # ltag = tag1 | tag2; ltag.path => "(t1)||(t2)" # ltag = tag1 ^ tag2; ltag.path => "(t1)^(t2)" # ltag = - tag1; ltag.path => "!(t1)" def & (tag) if tag.kind_of? TkObject TkcTagString.new(@c, '(' + @id + ')&&(' + tag.path + ')') else TkcTagString.new(@c, '(' + @id + ')&&(' + tag.to_s + ')') end end def | (tag) if tag.kind_of? TkObject TkcTagString.new(@c, '(' + @id + ')||(' + tag.path + ')') else TkcTagString.new(@c, '(' + @id + ')||(' + tag.to_s + ')') end end def ^ (tag) if tag.kind_of? TkObject TkcTagString.new(@c, '(' + @id + ')^(' + tag.path + ')') else TkcTagString.new(@c, '(' + @id + ')^(' + tag.to_s + ')') end end def -@ TkcTagString.new(@c, '!(' + @id + ')') end end class TkcTag