# # tkcanvas.rb - Tk canvas classes # $Date$ # by Yukihiro Matsumoto # $Date$ # by Hidetoshi Nagai require "tk" require 'tkfont' module TkTreatCItemFont def tagfont_configinfo(tagOrId) if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) pathname = self.path + ';' + tagOrId.id.to_s else pathname = self.path + ';' + tagOrId.to_s end ret = TkFont.used_on(pathname) if ret == nil ret = TkFont.init_widget_font(pathname, self.path, 'itemconfigure', tagOrId) end ret end alias tagfontobj tagfont_configinfo def tagfont_configure(tagOrId, slot) if tagOrId.kind_of?(TkcItem) || tagOrId.kind_of?(TkcTag) pathname = self.path + ';' + tagOrId.id.to_s else pathname = self.path + ';' + tagOrId.to_s end if (fnt = slot['font']) slot['font'] = nil if fnt.kind_of? TkFont return fnt.call_font_configure(pathname, self.path,'itemconfigure',tagOrId,slot) else latintagfont_configure(tagOrId, fnt) if fnt end end if (ltn = slot['latinfont']) slot['latinfont'] = nil latintagfont_configure(tagOrId, ltn) if ltn end if (ltn = slot['asciifont']) slot['asciifont'] = nil latintagfont_configure(tagOrId, ltn) if ltn end if (knj = slot['kanjifont']) slot['kanjifont'] = nil kanjitagfont_configure(tagOrId, knj) if knj end tk_call(self.path, 'itemconfigure', tagOrId, *hash_kv(slot)) if slot != {} self end def latintagfont_configure(tagOrId, ltn, keys=nil) fobj = tagfontobj(tagOrId) if ltn.kind_of? TkFont conf = {} ltn.latin_configinfo.each{|key,val| conf[key] = val if val != []} if conf == {} fobj.latin_replace(ltn) fobj.latin_configure(keys) if keys elsif keys fobj.latin_configure(conf.update(keys)) else fobj.latin_configure(conf) end else fobj.latin_replace(ltn) end end alias asciitagfont_configure latintagfont_configure def kanjitagfont_configure(tagOrId, knj, keys=nil) fobj = tagfontobj(tagOrId) if knj.kind_of? TkFont conf = {} knj.kanji_configinfo.each{|key,val| conf[key] = val if val != []} if conf == {} fobj.kanji_replace(knj) fobj.kanji_configure(keys) if keys elsif keys fobj.kanji_configure(conf.update(keys)) else fobj.kanji_configure(conf) end else fobj.kanji_replace(knj) end end def tagfont_copy(tagOrId, window, wintag=nil) if wintag window.tagfontobj(wintag).configinfo.each{|key,value| tagfontobj(tagOrId).configure(key,value) } tagfontobj(tagOrId).replace(window.tagfontobj(wintag).latin_font, window.tagfontobj(wintag).kanji_font) else window.tagfont(tagOrId).configinfo.each{|key,value| tagfontobj(tagOrId).configure(key,value) } tagfontobj(tagOrId).replace(window.fontobj.latin_font, window.fontobj.kanji_font) end end def latintagfont_copy(tagOrId, window, wintag=nil) if wintag tagfontobj(tagOrId).latin_replace(window.tagfontobj(wintag).latin_font) else tagfontobj(tagOrId).latin_replace(window.fontobj.latin_font) end end alias asciitagfont_copy latintagfont_copy def kanjitagfont_copy(tagOrId, window, wintag=nil) if wintag tagfontobj(tagOrId).kanji_replace(window.tagfontobj(wintag).kanji_font) else tagfontobj(tagOrId).kanji_replace(window.fontobj.kanji_font) end end end class TkCanvas", id rescue uninstall_cmd(cmd) fail end # @cmdtbl.push id end def itembindinfo(tag, context=nil) if context (tk_send('bind', tagid(tag), "<#{tk_event_sequence(context)}>")).collect{|cmdline| if cmdline =~ /^rb_out (c\d+)\s+(.*)$/ [Tk_CMDTBL[$1], $2] else cmdline end } else tk_split_list(tk_send 'bind', tagid(tag)).filter{|seq| seq[1..-2].gsub(/>value}) else tk_call '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 conf = tk_split_list(tk_send 'itemconfigure', tagid(tagOrId), "-#{key}") conf[0] = conf[0][1..-1] conf else tk_split_list(tk_send 'itemconfigure', tagid(tagOrId)).collect{|conf| conf[0] = conf[0][1..-1] conf } end end def lower(tag, below=None) tk_send 'lower', tagid(tag), 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), 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 def xview(*index) tk_send 'xview', *index end def yview(*index) tk_send 'yview', *index 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 end class TkcTag