summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/matrix.rb10
-rw-r--r--lib/pstore.rb3
-rw-r--r--lib/tk.rb175
-rw-r--r--lib/tkcanvas.rb150
-rw-r--r--lib/tkfont.rb445
-rw-r--r--lib/tktext.rb216
-rw-r--r--lib/weakref.rb4
7 files changed, 863 insertions, 140 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 6639fe72ea..3924e93ecb 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -2,8 +2,8 @@
#
# matrix.rb -
# $Release Version: 1.0$
-# $Revision: 1.4 $
-# $Date: 1998/07/08 06:39:13 $
+# $Revision: 1.5 $
+# $Date: 1998/07/14 14:35:18 $
# Original Version from Smalltalk-80 version
# on July 23, 1985 at 8:37:17 am
# by Keiju ISHITSUKA
@@ -180,8 +180,8 @@ module ExceptionForMatrix
end
class Matrix
- @RCS_ID='-$Id: matrix.rb,v 1.4 1998/07/08 06:39:13 keiju Exp keiju $-'
-
+ @RCS_ID='-$Id: matrix.rb,v 1.5 1998/07/14 14:35:18 keiju Exp keiju $-'
+
include ExceptionForMatrix
# instance creations
@@ -857,7 +857,7 @@ class Vector
end
def clone
- Vector.elements(@rows)
+ Vector.elements(@elements)
end
def hash
diff --git a/lib/pstore.rb b/lib/pstore.rb
index 3f95e8c059..743b1da5d0 100644
--- a/lib/pstore.rb
+++ b/lib/pstore.rb
@@ -89,6 +89,9 @@ class PStore
catch(:pstore_abort_transaction) do
value = yield(self)
end
+ rescue Exception
+ @abort = true
+ raise
ensure
unless @abort
begin
diff --git a/lib/tk.rb b/lib/tk.rb
index 34f42ac390..87a5cf19cf 100644
--- a/lib/tk.rb
+++ b/lib/tk.rb
@@ -33,6 +33,8 @@ module TkComm
return val.split.collect{|v| tk_tcl2ruby(v)}
end
case val
+ when /^@font/
+ TkFont.get_obj(val)
when /^-?\d+$/
val.to_i
when /^\./
@@ -277,11 +279,11 @@ module TkComm
end
def _bind(path, context, cmd, args=nil)
- _bind_core('', path, context, cmd, args=nil)
+ _bind_core('', path, context, cmd, args)
end
def _bind_append(path, context, cmd, args=nil)
- _bind_core('+', path, context, cmd, args=nil)
+ _bind_core('+', path, context, cmd, args)
end
private :install_bind, :tk_event_sequence, :_bind_core, :_bind, :_bind_append
@@ -412,6 +414,10 @@ module TkCore
TclTkLib.mainloop
end
+ def messageBox(keys)
+ tk_call 'tk_messageBox', *hash_kv(keys)
+ end
+
def tk_call(*args)
print args.join(" "), "\n" if $DEBUG
args.filter {|x|_get_eval_string(x)}
@@ -443,6 +449,7 @@ module Tk
TCL_VERSION = INTERP._invoke("info", "tclversion")
TK_VERSION = INTERP._invoke("set", "tk_version")
+ JAPANIZED_TK = (INTERP._invoke("info", "commands", "kanji") != "")
def root
TkRoot.new
@@ -452,6 +459,14 @@ module Tk
tk_call 'bell'
end
+ def toUTF8(str,encoding)
+ INTERP._toUTF8(str,encoding)
+ end
+
+ def fromUTF8(str,encoding)
+ INTERP._fromUTF8(str,encoding)
+ end
+
module Scrollable
def xscrollcommand(cmd=Proc.new)
configure_cmd 'xscrollcommand', cmd
@@ -1312,8 +1327,109 @@ module TkOption
module_function :add, :clear, :get, :readfile
end
+module TkTreatFont
+ def font_configinfo
+ ret = TkFont.used_on(self.path)
+ if ret == nil
+ ret = TkFont.init_widget_font(self.path, self.path, 'configure')
+ end
+ ret
+ end
+ alias fontobj font_configinfo
+
+ def font_configure(slot)
+ if (fnt = slot['font'])
+ slot['font'] = nil
+ if fnt.kind_of? TkFont
+ return fnt.call_font_configure(self.path, self.path,'configure',slot)
+ else
+ latinfont_configure(fnt) if fnt
+ end
+ end
+ if (ltn = slot['latinfont'])
+ slot['latinfont'] = nil
+ latinfont_configure(ltn) if ltn
+ end
+ if (ltn = slot['asciifont'])
+ slot['asciifont'] = nil
+ latinfont_configure(ltn) if ltn
+ end
+ if (knj = slot['kanjifont'])
+ slot['kanjifont'] = nil
+ kanjifont_configure(knj) if knj
+ end
+
+ tk_call(self.path, 'configure', *hash_kv(slot)) if slot != {}
+ self
+ end
+
+ def latinfont_configure(ltn, keys=nil)
+ fobj = fontobj
+ if ltn.kind_of? TkFont
+ conf = {}
+ ltn.latin_configinfo.each{|key,val| conf[key] = val}
+ if keys
+ fobj.latin_configure(conf.update(keys))
+ else
+ fobj.latin_configure(conf)
+ end
+ else
+ fobj.latin_replace(ltn)
+ end
+ end
+ alias asciifont_configure latinfont_configure
+
+ def kanjifont_configure(knj, keys=nil)
+ fobj = fontobj
+ if knj.kind_of? TkFont
+ conf = {}
+ knj.kanji_configinfo.each{|key,val| conf[key] = val}
+ if keys
+ fobj.kanji_configure(conf.update(keys))
+ else
+ fobj.kanji_configure(cond)
+ end
+ else
+ fobj.kanji_replace(knj)
+ end
+ end
+
+ def font_copy(window, tag=nil)
+ if tag
+ window.tagfontobj(tag).configinfo.each{|key,value|
+ fontobj.configure(key,value)
+ }
+ fontobj.replace(window.tagfontobj(tag).latin_font,
+ window.tagfontobj(tag).kanji_font)
+ else
+ window.fontobj.configinfo.each{|key,value|
+ fontobj.configure(key,value)
+ }
+ fontobj.replace(window.fontobj.latin_font, window.fontobj.kanji_font)
+ end
+ end
+
+ def latinfont_copy(window, tag=nil)
+ if tag
+ fontobj.latin_replace(window.tagfontobj(tag).latin_font)
+ else
+ fontobj.latin_replace(window.fontobj.latin_font)
+ end
+ end
+ alias asciifont_copy latinfont_copy
+
+ def kanjifont_copy(window, tag=nil)
+ if tag
+ fontobj.kanji_replace(window.tagfontobj(tag).kanji_font)
+ else
+ fontobj.kanji_replace(window.fontobj.kanji_font)
+ end
+ end
+end
+
class TkObject<TkKernel
include Tk
+ include TkTreatFont
def path
return @path
@@ -1356,12 +1472,23 @@ class TkObject<TkKernel
tk_tcl2ruby tk_call path, 'cget', "-#{slot}"
end
- def configure(slot, value=None)
- if slot.kind_of? Hash
- tk_call path, 'configure', *hash_kv(slot)
- else
- tk_call path, 'configure', "-#{slot}", value
- end
+ def configure(slot, value=None)
+ if slot.kind_of? Hash
+ if ( slot['font'] || slot['kanjifont'] \
+ || slot['latinfont'] || slot['asciifont'] )
+ font_configure(slot.dup)
+ else
+ tk_call path, 'configure', *hash_kv(slot)
+ end
+
+ else
+ if ( slot == 'font' || slot == 'kanjifont' \
+ || slot == 'latinfont' || slot == 'asciifont' )
+ font_configure({slot=>value})
+ else
+ tk_call path, 'configure', "-#{slot}", value
+ end
+ end
end
def configure_cmd(slot, value)
@@ -1369,15 +1496,27 @@ class TkObject<TkKernel
end
def configinfo(slot = nil)
- if slot
- conf = tk_split_list(tk_send('configure', "-#{slot}") )
- conf[0] = conf[0][1..-1]
- conf
+ if slot == 'font' || slot == 'kanjifont'
+ fontobj
+
else
- tk_split_list(tk_send('configure') ).collect{|conf|
- conf[0] = conf[0][1..-1]
- conf
- }
+ if slot
+ conf = tk_split_list(tk_send('configure', "-#{slot}") )
+ conf[0] = conf[0][1..-1]
+ conf
+
+ else
+ ret = tk_split_list(tk_send('configure') ).collect{|conf|
+ conf[0] = conf[0][1..-1]
+ conf
+ }
+ if ret.assoc('font')
+ ret.delete_if{|item| item[0] == 'font' || item[0] == 'kanjifont'}
+ ret.push(['font', fontobj])
+ else
+ ret
+ end
+ end
end
end
@@ -1429,7 +1568,8 @@ class TkWindow<TkObject
install_win(if parent then parent.path end)
create_self
if keys
- tk_call @path, 'configure', *hash_kv(keys)
+ # tk_call @path, 'configure', *hash_kv(keys)
+ configure(keys)
end
end
@@ -1996,3 +2136,4 @@ autoload :TkDialog, 'tkdialog'
autoload :TkMenubar, 'tkmenubar'
autoload :TkAfter, 'tkafter'
autoload :TkPalette, 'tkpalette'
+autoload :TkFont, 'tkfont'
diff --git a/lib/tkcanvas.rb b/lib/tkcanvas.rb
index 4ee0c3cd48..613e97af38 100644
--- a/lib/tkcanvas.rb
+++ b/lib/tkcanvas.rb
@@ -6,8 +6,124 @@
# by Hidetoshi Nagai <nagai@ai.kyutech.ac.jp>
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 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 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<TkWindow
+ include TkTreatCItemFont
+
WidgetClassName = 'Canvas'.freeze
TkClassBind::WidgetClassNameTBL[WidgetClassName] = self
def self.to_eval
@@ -171,16 +287,34 @@ class TkCanvas<TkWindow
end
def itemcget(tagOrId, option)
- tk_send 'itemcget', tagid(tagOrId), option
+ tk_send 'itemcget', tagid(tagOrId), "-#{option}"
end
def itemconfigure(tagOrId, key, value=None)
if key.kind_of? Hash
- tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key)
+ if ( key['font'] || key['kanjifont'] \
+ || key['latinfont'] || key['asciifont'] )
+ tagfont_configure(tagOrId, key.dup)
+ else
+ tk_send 'itemconfigure', tagid(tagOrId), *hash_kv(key)
+ end
+
else
- tk_send 'itemconfigure', tagid(tagOrId), "-#{key}", value
+ if ( key == 'font' || key == 'kanjifont' \
+ || key == 'latinfont' || key == 'asciifont' )
+ tagfont_configure(tagid(tagOrId), {key=>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
@@ -258,6 +392,7 @@ end
module TkcTagAccess
include TkComm
+ include TkTreatTagFont
def addtag(tag)
@c.addtag(tag, 'with', @id)
@@ -286,8 +421,8 @@ module TkcTagAccess
# @c.itemconfigure @id, keys
# end
- def configinfo
- @c.itemconfigure @id
+ def configinfo(key=nil)
+ @c.itemconfiginfo @id, key
end
def coords(*args)
@@ -494,7 +629,7 @@ class TkcItem<TkObject
if not parent.kind_of?(TkCanvas)
fail format("%s need to be TkCanvas", parent.inspect)
end
- @c = parent
+ @parent = @c = parent
@path = parent.path
if args[-1].kind_of? Hash
keys = args.pop
@@ -502,7 +637,8 @@ class TkcItem<TkObject
@id = create_self(*args).to_i ;# 'canvas item id' is integer number
CItemID_TBL[@id] = self
if keys
- tk_call @path, 'itemconfigure', @id, *hash_kv(keys)
+ # tk_call @path, 'itemconfigure', @id, *hash_kv(keys)
+ configure(keys) if keys
end
end
def create_self(*args); end
diff --git a/lib/tkfont.rb b/lib/tkfont.rb
index 5e20359523..0d926f00c8 100644
--- a/lib/tkfont.rb
+++ b/lib/tkfont.rb
@@ -1,3 +1,10 @@
+#
+# tkfont.rb - the class to treat fonts on Ruby/Tk
+#
+# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
+#
+require 'tk'
+
class TkFont
include Tk
extend TkCore
@@ -14,10 +21,10 @@ class TkFont
###################################
def TkFont.families(window=nil)
case (Tk::TK_VERSION)
- when /^4.*/
+ when /^4\.*/
['fixed']
- when /^8.*/
+ when /^8\.*/
if window
list(tk_call('font', 'families', '-displayof', window))
else
@@ -27,21 +34,69 @@ class TkFont
end
def TkFont.names
- r = []
case (Tk::TK_VERSION)
- when /^4.*/
- r += ['fixed', 'a14', 'k14']
+ when /^4\.*/
+ r = ['fixed']
+ r += ['a14', 'k14'] if JAPANIZED_TK
Tk_FontNameTBL.each_value{|obj| r.push(obj)}
- when /^8.*/
- list(tk_call('font', 'names')).each{|f|
- if f =~ /^(@font[0-9]+)(c|l|k)$/
- r.push(Tk_FontNameTBL[$1]) if $2 == 'c'
+ r | []
+
+ when /^8\.*/
+ list(tk_call('font', 'names'))
+
+ end
+ end
+
+ def TkFont.create_copy(font)
+ keys = {}
+ font.configure.each{|key,value| keys[key] = value }
+ new_font = TkFont.new(font.latin_font, font.kanji_font, keys)
+ end
+
+ def TkFont.get_obj(name)
+ if name =~ /^(@font[0-9]+)(|c|l|k)$/
+ Tk_FontNameTBL[$1]
+ else
+ nil
+ end
+ end
+
+ def TkFont.init_widget_font(path, *args)
+ case (Tk::TK_VERSION)
+ when /^4\.*/
+ conf = tk_split_list(tk_call(*args))
+ ltn = conf.assoc('font')[4]
+ ltn = nil if ltn == []
+ knj = conf.assoc('kanjifont')[4]
+ knj = nil if knj == []
+ TkFont.new(ltn, knj).call_font_configure(path, *args)
+
+ when /^8\.*/
+ fnt = tk_split_list(tk_call(*(args + ['-font'])))[4]
+ if fnt == []
+ TkFont.new(nil, nil).call_font_configure(path, *(args + [{}]))
+ else
+ compound = Hash[*list(tk_call('font', 'configure',
+ fnt))].collect{|key,value|
+ [key[1..-1], value]
+ }.assoc('compound')[1]
+ if compound == []
+ TkFont.new(fnt, DEFAULT_KANJI_FONT_NAME) \
+ .call_font_configure(path, *(args + [{}]))
else
- r.push(f)
+ TkFont.new(compound[0], compound[1]) \
+ .call_font_configure(path, *(args + [{}]))
end
- }
+ end
+ end
+ end
+
+ def TkFont.used_on(path=nil)
+ if path
+ Tk_FontUseTBL[path]
+ else
+ Tk_FontUseTBL.values | []
end
- r
end
###################################
@@ -81,7 +136,7 @@ class TkFont
pixels, points, resx, resy, space, avgWidth, charset, encoding])
end
- def create_latinfont_tk4x(font=nil)
+ def create_latinfont_tk4x(font)
if font.kind_of? Hash
@latinfont = '-' + _get_font_info_from_hash(font).join('-') + '-'
@@ -119,7 +174,12 @@ class TkFont
end
end
- def create_kanjifont_tk4x(font=nil)
+ def create_kanjifont_tk4x(font)
+ unless JAPANIZED_TK
+ @kanjifont = ""
+ return
+ end
+
if font.kind_of? Hash
@kanjifont = '-' + _get_font_info_from_hash(font).join('-') + '-'
@@ -160,25 +220,51 @@ class TkFont
end
def create_compoundfont_tk4x(keys)
- @compoundfont = [[@latinfont], [@kanjifont]]
- @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
+ if JAPANIZED_TK
+ @compoundfont = [[@latinfont], [@kanjifont]]
+ @fontslot = {'font'=>@latinfont, 'kanjifont'=>@kanjifont}
+ else
+ @compoundfont = @latinfont
+ @fontslot = {'font'=>@latinfont}
+ end
end
- def create_latinfont_tk80(font=nil)
+ def create_latinfont_tk8x(font)
@latinfont = @id + 'l'
- if font.kind_of? Hash
- tk_call('font', 'create', @latinfont, *hash_kv(font))
- elsif font.kind_of? Array
- tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font))
- elsif font.kind_of? TkFont
- tk_call('font', 'create', @latinfont, '-copy', font.latin_font)
+ if JAPANIZED_TK
+ if font.kind_of? Hash
+ tk_call('font', 'create', @latinfont, *hash_kv(font))
+ elsif font.kind_of? Array
+ tk_call('font', 'create', @latinfont, '-copy', array2tk_list(font))
+ elsif font.kind_of? TkFont
+ tk_call('font', 'create', @latinfont, '-copy', font.latin_font)
+ else
+ tk_call('font', 'create', @latinfont, '-copy', font)
+ end
else
- tk_call('font', 'create', @latinfont, '-copy', font)
+ if font.kind_of? Hash
+ tk_call('font', 'create', @latinfont, *hash_kv(font))
+ else
+ keys = {}
+ if font.kind_of? Array
+ actual_core(array2tk_list(font)).each{|key,val| keys[key] = val}
+ elsif font.kind_of? TkFont
+ actual_core(font.latin_font).each{|key,val| keys[key] = val}
+ else
+ actual_core(font).each{|key,val| keys[key] = val}
+ end
+ tk_call('font', 'create', @latinfont, *hash_kv(keys))
+ end
end
end
- def create_kanjifont_tk80(font=nil)
+ def create_kanjifont_tk80(font)
+ unless JAPANIZED_TK
+ @kanjifont = ""
+ return
+ end
+
@kanjifont = @id + 'k'
if font.kind_of? Hash
@@ -202,20 +288,79 @@ class TkFont
end
end
+ def create_kanjifont_tk81(font)
+ @kanjifont = @id + 'k'
+
+ if font.kind_of? Hash
+ tk_call('font', 'create', @kanjifont, *hash_kv(font))
+ else
+ keys = {}
+ if font.kind_of? Array
+ actual_core(array2tk_list(font)).each{|key,val| keys[key] = val}
+ elsif font.kind_of? TkFont
+ actual_core(font.kanji_font).each{|key,val| keys[key] = val}
+ else
+ actual_core(font).each{|key,val| keys[key] = val}
+ end
+ tk_call('font', 'create', @kanjifont, *hash_kv(keys))
+ end
+
+ keys = {}
+ actual_core(@kanjifont).each{|key,val| keys[key] = val}
+ begin
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
+ rescue
+ end
+ end
+
def create_compoundfont_tk80(keys)
@compoundfont = @id + 'c'
- @fontslot = {'font'=>@compoundfont}
- tk_call('font', 'create', @compoundfont,
- '-compound', "#{@latinfont} #{@kanjifont}", *hash_kv(keys))
+ if JAPANIZED_TK
+ @fontslot = {'font'=>@compoundfont}
+ tk_call('font', 'create', @compoundfont,
+ '-compound', "#{@latinfont} #{@kanjifont}", *hash_kv(keys))
+ else
+ tk_call('font', 'create', @compoundfont)
+ latinkeys = {}
+ begin
+ actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
+ rescue
+ latinkeys {}
+ end
+ if latinkeys != {}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
+ end
+ @fontslot = {'font'=>@compoundfont}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
+ end
end
- def set_font_core_tk4x(window)
- Tk_FontUseTBL[window.path] = @id
- window.configure(@fontslot)
- end
+ def create_compoundfont_tk81(keys)
+ @compoundfont = @id + 'c'
+ tk_call('font', 'create', @compoundfont)
- def set_font_core_tk80(window)
- window.configure(@fontslot)
+ latinkeys = {}
+ begin
+ actual_core(@latinfont).each{|key,val| latinkeys[key] = val}
+ rescue
+ latinkeys {}
+ end
+ if latinkeys != {}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(latinkeys))
+ end
+
+ kanjikeys = {}
+ begin
+ actual_core(@kanjifont).each{|key,val| kanjikeys[key] = val}
+ rescue
+ kanjikeys {}
+ end
+ if kanjikeys != {}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(kanjikeys))
+ end
+
+ @fontslot = {'font'=>@compoundfont}
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
end
def actual_core_tk4x(font, window=nil, option=nil)
@@ -229,7 +374,7 @@ class TkFont
end
end
- def actual_core_tk80(font, window=nil, option=nil)
+ def actual_core_tk8x(font, window=nil, option=nil)
if option == 'compound'
""
elsif option
@@ -271,7 +416,7 @@ class TkFont
end
end
- def configure_core_tk80(font, slot, value=None)
+ def configure_core_tk8x(font, slot, value=None)
if slot.kind_of? Hash
tk_call 'font', 'configure', font, *hash_kv(slot)
else
@@ -279,7 +424,7 @@ class TkFont
end
end
- def configinfo_core_tk80(font, option=nil)
+ def configinfo_core_tk8x(font, option=nil)
if option == 'compound'
""
elsif option
@@ -300,12 +445,18 @@ class TkFont
def latin_replace_core_tk4x(ltn)
create_latinfont_tk4x(ltn)
- @compoundfont[0] = [@latinfont]
+ @compoundfont[0] = [@latinfont] if JAPANIZED_TK
@fontslot['font'] = @latinfont
- Tk_FontUseTBL.dup.each{|w, id|
- if id == @id
+ Tk_FontUseTBL.dup.each{|w, fobj|
+ if self == fobj
begin
- w.configure('font', @latinfont)
+ if w.include?(';')
+ win, tag = w.split(';')
+ winobj = tk_tcl2ruby(win)
+ winobj.tagfont_configure(tag, {'font'=>@latinfont})
+ else
+ tk_tcl2ruby(w).configure('font', @latinfont)
+ end
rescue
Tk_FontUseTBL[w] = nil
end
@@ -315,13 +466,21 @@ class TkFont
end
def kanji_replace_core_tk4x(knj)
+ return self unless JAPANIZED_TK
+
create_kanjifont_tk4x(knj)
@compoundfont[1] = [@kanjifont]
@fontslot['kanjifont'] = @kanjifont
- Tk_FontUseTBL.dup.each{|w, id|
- if id == @id
+ Tk_FontUseTBL.dup.each{|w, fobj|
+ if self == fobj
begin
- w.configure('kanjifont', @kanjifont)
+ if w.include?(';')
+ win, tag = w.split(';')
+ winobj = tk_tcl2ruby(win)
+ winobj.tagfont_configure(tag, {'kanjifont'=>@kanjifont})
+ else
+ tk_tcl2ruby(w).configure('kanjifont', @kanjifont)
+ end
rescue
Tk_FontUseTBL[w] = nil
end
@@ -330,15 +489,34 @@ class TkFont
self
end
- def latin_replace_core_tk80(ltn)
+ def latin_replace_core_tk8x(ltn)
tk_call('font', 'delete', @latinfont)
- create_latinfont_tk80(ltn)
+ create_latinfont(ltn)
self
end
def kanji_replace_core_tk80(knj)
+ return self unless JAPANIZED_TK
+
tk_call('font', 'delete', @kanjifont)
- create_kanjifont_tk80(knj)
+ create_kanjifont(knj)
+ self
+ end
+
+ def kanji_replace_core_tk81(knj)
+ if font.kind_of? Hash
+ tk_call('font', 'configure', @compoundfont, *hash_kv(font))
+ else
+ keys = {}
+ if font.kind_of? Array
+ actual_core(array2tk_list(font)).each{|key,val| keys[key] = val}
+ elsif font.kind_of? TkFont
+ actual_core(font.latin_font).each{|key,val| keys[key] = val}
+ else
+ actual_core(font).each{|key,val| keys[key] = val}
+ end
+ tk_call('font', 'configure', @compoundfont, *hash_kv(keys))
+ end
self
end
@@ -346,7 +524,7 @@ class TkFont
0
end
- def measure_core_tk80(window, text)
+ def measure_core_tk8x(window, text)
if window
number(tk_call('font', 'measure', @compoundfont,
'-displayof', window, text))
@@ -364,7 +542,7 @@ class TkFont
end
end
- def metrics_core_tk80(font, window, option=nil)
+ def metrics_core_tk8x(font, window, option=nil)
if option
if window
number(tk_call('font', 'metrics', font, "-#{option}"))
@@ -390,11 +568,10 @@ class TkFont
# private alias
###################################
case (Tk::TK_VERSION)
- when /^4.*/
+ when /^4\.*/
alias create_latinfont create_latinfont_tk4x
alias create_kanjifont create_kanjifont_tk4x
alias create_compoundfont create_compoundfont_tk4x
- alias set_font_core set_font_core_tk4x
alias actual_core actual_core_tk4x
alias configure_core configure_core_tk4x
alias configinfo_core configinfo_core_tk4x
@@ -404,25 +581,77 @@ class TkFont
alias metrics_core metrics_core_tk4x
when /^8\.0/
- alias create_latinfont create_latinfont_tk80
+ alias create_latinfont create_latinfont_tk8x
alias create_kanjifont create_kanjifont_tk80
alias create_compoundfont create_compoundfont_tk80
- alias set_font_core set_font_core_tk80
- alias actual_core actual_core_tk80
- alias configure_core configure_core_tk80
- alias configinfo_core configinfo_core_tk80
- alias latin_replace_core latin_replace_core_tk80
+ alias actual_core actual_core_tk8x
+ alias configure_core configure_core_tk8x
+ alias configinfo_core configinfo_core_tk8x
+ alias latin_replace_core latin_replace_core_tk8x
alias kanji_replace_core kanji_replace_core_tk80
- alias measure_core measure_core_tk80
- alias metrics_core metrics_core_tk80
+ alias measure_core measure_core_tk8x
+ alias metrics_core metrics_core_tk8x
+
+ when /^8\.1/
+ alias create_latinfont create_latinfont_tk8x
+ alias create_kanjifont create_kanjifont_tk81
+ alias create_compoundfont create_compoundfont_tk81
+ alias actual_core actual_core_tk8x
+ alias configure_core configure_core_tk8x
+ alias configinfo_core configinfo_core_tk8x
+ alias latin_replace_core latin_replace_core_tk8x
+ alias kanji_replace_core kanji_replace_core_tk81
+ alias measure_core measure_core_tk8x
+ alias metrics_core metrics_core_tk8x
end
###################################
public
###################################
- def set_font(window)
- set_font_core(window)
+ def call_font_configure(path, *args)
+ args += hash_kv(args.pop.update(@fontslot))
+ tk_call *args
+ Tk_FontUseTBL[path] = self
+ self
+ end
+
+ def used
+ ret = []
+ Tk_FontUseTBL.each{|key,value|
+ if key.include?(';')
+ win, tag = key.split(';')
+ winobj = tk_tcl2ruby(win)
+ if winobj.kind_of? TkText
+ ret.push([winobj, winobj.tagid2obj(tag)])
+ elsif winobj.kind_of? TkCanvas
+ if (tagobj = TkcTag.id2obj(tag)).kind_of? TkcTag
+ ret.push([winobj, tagobj])
+ elsif (tagobj = TkcItem.id2obj(tag)).kind_of? TkcItem
+ ret.push([winobj, tagobj])
+ else
+ ret.push([winobj, tag])
+ end
+ else
+ ret.push([win, tag])
+ end
+ else
+ ret.push(tk_tcl2ruby(key)) if value == self
+ end
+ }
+ ret
+ end
+
+ def id
+ @id
+ end
+
+ def to_eval
+ font
+ end
+
+ def font
+ @compoundfont
end
def latin_font
@@ -452,12 +681,22 @@ class TkFont
end
def kanji_actual(option=nil)
- actual_core(@kanjifont, nil, option)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ actual_core(@kanjifont, nil, option)
+ else
+ actual_core_tk4x(nil, nil, option)
+ end
end
def kanji_actual_displayof(window, option=nil)
- window = '.' unless window
- actual_core(@kanjifont, window, option)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ window = '.' unless window
+ actual_core(@kanjifont, window, option)
+ else
+ actual_core_tk4x(nil, window, option)
+ end
end
def [](slot)
@@ -477,24 +716,45 @@ class TkFont
end
def latin_configure(slot, value=None)
- configure_core(@latinfont, slot, value)
+ if JAPANIZED_TK
+ configure_core(@latinfont, slot, value)
+ else
+ configure(slot, value)
+ end
end
def latin_configinfo(slot=nil)
- configinfo_core(@latinfont, slot)
+ if JAPANIZED_TK
+ configinfo_core(@latinfont, slot)
+ else
+ configure(slot, value)
+ end
end
def kanji_configure(slot, value=None)
- configure_core(@kanjifont, slot, value)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ configure_core(@kanjifont, slot, value)
+ else
+ #""
+ configure(slot, value)
+ end
end
def kanji_configinfo(slot=nil)
- configinfo_core(@kanjifont, slot)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ configinfo_core(@kanjifont, slot)
+ else
+ #[]
+ configinfo(slot)
+ end
end
def replace(ltn, knj)
latin_replace(ltn)
- kanji_replace(ltn)
+ kanji_replace(knj)
+ self
end
def latin_replace(ltn)
@@ -533,12 +793,20 @@ class TkFont
end
def kanji_metrics(option=nil)
- metrics_core(@kanjifont, nil, option)
+ if JAPANIZED_TK
+ metrics_core(@kanjifont, nil, option)
+ else
+ metrics_core_tk4x(nil, nil, option)
+ end
end
def kanji_metrics_displayof(window, option=nil)
- window = '.' unless window
- metrics_core(@kanjifont, window, option)
+ if JAPANIZED_TK
+ window = '.' unless window
+ metrics_core(@kanjifont, window, option)
+ else
+ metrics_core_tk4x(nil, window, option)
+ end
end
###################################
@@ -554,3 +822,36 @@ class TkFont
alias ascii_metrics latin_metrics
end
+
+module TkTreatTagFont
+ def font_configinfo
+ @parent.tagfont_configinfo(@id)
+ end
+ alias font font_configinfo
+
+ def font_configure(slot)
+ @parent.tagfont_configure(@id, slot)
+ end
+
+ def latinfont_configure(ltn, keys=nil)
+ @parent.latintagfont_configure(@id, ltn, keys)
+ end
+ alias asciifont_configure latinfont_configure
+
+ def kanjifont_configure(knj, keys=nil)
+ @parent.kanjitagfont_configure(@id, ltn, keys)
+ end
+
+ def font_copy(window, wintag=nil)
+ @parent.tagfont_copy(@id, window, wintag)
+ end
+
+ def latinfont_copy(window, wintag=nil)
+ @parent.latintagfont_copy(@id, window, wintag)
+ end
+ alias asciifont_copy latinfont_copy
+
+ def kanjifont_copy(window, wintag=nil)
+ @parent.kanjitagfont_copy(@id, window, wintag)
+ end
+end
diff --git a/lib/tktext.rb b/lib/tktext.rb
index 7b5cea5c72..8ffc626046 100644
--- a/lib/tktext.rb
+++ b/lib/tktext.rb
@@ -4,8 +4,124 @@
# by Yukihiro Matsumoto <matz@caelum.co.jp>
require 'tk.rb'
+require 'tkfont'
+
+module TkTreatTextTagFont
+ def tagfont_configinfo(tag)
+ if tag.kind_of? TkTextTag
+ pathname = self.path + ';' + tag.id
+ else
+ pathname = self.path + ';' + tag
+ end
+ ret = TkFont.used_on(pathname)
+ if ret == nil
+ ret = TkFont.init_widget_font(pathname,
+ self.path, 'tag', 'configure', tag)
+ end
+ ret
+ end
+ alias tagfontobj tagfont_configinfo
+
+ def tagfont_configure(tag, slot)
+ if tag.kind_of? TkTextTag
+ pathname = self.path + ';' + tag.id
+ else
+ pathname = self.path + ';' + tag
+ end
+ if (fnt = slot['font'])
+ slot['font'] = nil
+ if fnt.kind_of? TkFont
+ return fnt.call_font_configure(pathname,
+ self.path,'tag','configure',tag,slot)
+ else
+ latintagfont_configure(tag, fnt) if fnt
+ end
+ end
+ if (ltn = slot['latinfont'])
+ slot['latinfont'] = nil
+ latintagfont_configure(tag, ltn) if ltn
+ end
+ if (ltn = slot['asciifont'])
+ slot['asciifont'] = nil
+ latintagfont_configure(tag, ltn) if ltn
+ end
+ if (knj = slot['kanjifont'])
+ slot['kanjifont'] = nil
+ kanjitagfont_configure(tag, knj) if knj
+ end
+
+ tk_call(self.path, 'tag', 'configure', tag, *hash_kv(slot)) if slot != {}
+ self
+ end
+
+ def latintagfont_configure(tag, ltn, keys=nil)
+ fobj = tagfontobj(tag)
+ if ltn.kind_of? TkFont
+ conf = {}
+ ltn.latin_configinfo.each{|key,val| conf[key] = val}
+ if 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(tag, knj, keys=nil)
+ fobj = tagfontobj(tag)
+ if knj.kind_of? TkFont
+ conf = {}
+ knj.kanji_configinfo.each{|key,val| conf[key] = val}
+ if keys
+ fobj.kanji_configure(conf.update(keys))
+ else
+ fobj.kanji_configure(conf)
+ end
+ else
+ fobj.kanji_replace(knj)
+ end
+ end
+
+ def tagfont_copy(tag, window, wintag=nil)
+ if wintag
+ window.tagfontobj(wintag).configinfo.each{|key,value|
+ tagfontobj(tag).configure(key,value)
+ }
+ tagfontobj(tag).replace(window.tagfontobj(wintag).latin_font,
+ window.tagfontobj(wintag).kanji_font)
+ else
+ window.tagfont(tag).configinfo.each{|key,value|
+ tagfontobj(tag).configure(key,value)
+ }
+ tagfontobj(tag).replace(window.fontobj.latin_font,
+ window.fontobj.kanji_font)
+ end
+ end
+
+ def latintagfont_copy(tag, window, wintag=nil)
+ if wintag
+ tagfontobj(tag).latin_replace(window.tagfontobj(wintag).latin_font)
+ else
+ tagfontobj(tag).latin_replace(window.fontobj.latin_font)
+ end
+ end
+ alias asciitagfont_copy latintagfont_copy
+
+ def kanjitagfont_copy(tag, window, wintag=nil)
+ if wintag
+ tagfontobj(tag).kanji_replace(window.tagfontobj(wintag).kanji_font)
+ else
+ tagfontobj(tag).kanji_replace(window.fontobj.kanji_font)
+ end
+ end
+end
class TkText<TkTextWin
+ include TkTreatTextTagFont
+
WidgetClassName = 'Text'.freeze
TkClassBind::WidgetClassNameTBL[WidgetClassName] = self
def self.to_eval
@@ -32,31 +148,28 @@ class TkText<TkTextWin
def _addtag(name, obj)
@tags[name] = obj
end
+
+ def tagid2obj(tagid)
+ if not @tags[tagid]
+ tagid
+ else
+ @tags[tagid]
+ end
+ end
+
def tag_names(index=None)
tk_split_list(tk_send('tag', 'names', index)).collect{|elt|
- if not @tags[elt]
- elt
- else
- @tags[elt]
- end
+ tagid2obj(elt)
}
end
def window_names
tk_send('window', 'names').collect{|elt|
- if not @tags[elt]
- elt
- else
- @tags[elt]
- end
+ tagid2obj(elt)
}
end
def image_names
tk_send('image', 'names').collect{|elt|
- if not @tags[elt]
- elt
- else
- @tags[elt]
- end
+ tagid2obj(elt)
}
end
@@ -158,13 +271,24 @@ class TkText<TkTextWin
def tag_configure(tag, key, val=None)
if key.kind_of? Hash
- tk_send 'tag', 'configure', tag, *hash_kv(key)
+ if ( key['font'] || key['kanjifont'] \
+ || key['latinfont'] || key['asciifont'] )
+ tagfont_configure(tag, key.dup)
+ else
+ tk_send 'tag', 'configure', tag, *hash_kv(key)
+ end
+
else
- tk_send 'tag', 'configure', tag, "-#{key}", val
+ if ( key == 'font' || key == 'kanjifont' \
+ || key == 'latinfont' || key == 'asciifont' )
+ tagfont_configure({key=>val})
+ else
+ tk_call 'tag', 'configure', tag, "-#{key}", val
+ end
end
end
- def configinfo(tag, key=nil)
+ def tag_configinfo(tag, key=nil)
if key
conf = tk_split_list(tk_send('tag','configure',tag,"-#{key}"))
conf[0] = conf[0][1..-1]
@@ -296,21 +420,32 @@ class TkText<TkTextWin
end
class TkTextTag<TkObject
+ include TkTreatTagFont
+
$tk_text_tag = 'tag0000'
def initialize(parent, keys=nil)
if not parent.kind_of?(TkText)
fail format("%s need to be TkText", parent.inspect)
end
- @t = parent
+ @parent = @t = parent
@path = @id = $tk_text_tag
$tk_text_tag = $tk_text_tag.succ
- tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
+ #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
+ configure(keys) if keys
@t._addtag id, self
end
def id
return @id
end
+ def first
+ @id + '.first'
+ end
+
+ def last
+ @id + '.last'
+ end
+
def add(*index)
tk_call @t.path, 'tag', 'add', @id, *index
end
@@ -349,12 +484,15 @@ class TkTextTag<TkObject
end
def configure(key, val=None)
- if key.kind_of? Hash
- tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key)
- else
- tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val
- end
+ @t.tag_configure @id, key, val
end
+# def configure(key, val=None)
+# if key.kind_of? Hash
+# tk_call @t.path, 'tag', 'configure', @id, *hash_kv(key)
+# else
+# tk_call @t.path, 'tag', 'configure', @id, "-#{key}", val
+# end
+# end
# def configure(key, value)
# if value == FALSE
# value = "0"
@@ -365,17 +503,20 @@ class TkTextTag<TkObject
# end
def configinfo(key=nil)
- if key
- conf = tk_split_list(tk_call(@t.path, 'tag','configure',@id,"-#{key}"))
- conf[0] = conf[0][1..-1]
- conf
- else
- tk_split_list(tk_call(@t.path, 'tag', 'configure', @id)).collect{|conf|
- conf[0] = conf[0][1..-1]
- conf
- }
- end
- end
+ @t.tag_configinfo @id, key
+ end
+# def configinfo(key=nil)
+# if key
+# conf = tk_split_list(tk_call(@t.path, 'tag','configure',@id,"-#{key}"))
+# conf[0] = conf[0][1..-1]
+# conf
+# else
+# tk_split_list(tk_call(@t.path, 'tag', 'configure', @id)).collect{|conf|
+# conf[0] = conf[0][1..-1]
+# conf
+# }
+# end
+# end
def bind(seq, cmd=Proc.new, args=nil)
id = install_bind(cmd, args)
@@ -420,7 +561,8 @@ class TkTextTagSel<TkTextTag
end
@t = parent
@path = @id = 'sel'
- tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
+ #tk_call @t.path, "tag", "configure", @id, *hash_kv(keys)
+ configure(keys) if keys
@t._addtag id, self
end
end
diff --git a/lib/weakref.rb b/lib/weakref.rb
index 539bb9336c..c31e959e74 100644
--- a/lib/weakref.rb
+++ b/lib/weakref.rb
@@ -32,10 +32,10 @@ class WeakRef<Delegator
def initialize(orig)
super
- @__id = orig.id
+ @__id = orig.__id__
ObjectSpace.call_finalizer orig
ObjectSpace.call_finalizer self
- ID_MAP[@__id] = self.id
+ ID_MAP[@__id] = self.__id__
ID_REV_MAP[self.id] = @__id
end