summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-18 15:43:42 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-03-18 15:43:42 +0000
commitb5994506c73fb3d3a82b665c3f141b18dffa4988 (patch)
treec0acd838980da8aa1cb229409c1e3b9019534e53
parent7619ce34f1930def7ae7213351c21c9bda270fa5 (diff)
* ext/tk/lib/tk/font.rb: add some TkFont class methods to get font
information without creating a TkFont object. * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix and define some classes for components of Tk::TreeCtrl git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/tk/ChangeLog.tkextlib7
-rw-r--r--ext/tk/lib/tk/font.rb842
-rw-r--r--ext/tk/lib/tk/menuspec.rb12
-rw-r--r--ext/tk/lib/tkextlib/treectrl/tktreectrl.rb859
5 files changed, 1294 insertions, 434 deletions
diff --git a/ChangeLog b/ChangeLog
index a06f20a903..d346f5907f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Sat Mar 19 00:41:02 2005 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * ext/tk/lib/tk/font.rb: add some TkFont class methods to get font
+ information without creating a TkFont object.
+
+ * ext/tk/lib/tkextlib/treectrl/tktreectrl.rb: bug fix and define some
+ classes for components of Tk::TreeCtrl
+
Thu Mar 17 17:42:13 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (make_struct): allow non local-id field
diff --git a/ext/tk/ChangeLog.tkextlib b/ext/tk/ChangeLog.tkextlib
index 2e76d523f0..c27ada6d01 100644
--- a/ext/tk/ChangeLog.tkextlib
+++ b/ext/tk/ChangeLog.tkextlib
@@ -1,7 +1,12 @@
+2005-03-18 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
+
+ * lib/tkextlib/treectrl/tktreectrl.rb: bug fix and define some
+ classes for components of Tk::TreeCtrl
+
2005-03-17 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/tkextlib/treectrl/tktreectrl.rb: call wrong method in
- Tk::TreeCtrl#*_configinfo and current_*_configinfo method
+ Tk::TreeCtrl#*_configinfo and current_*_configinfo method
2005-03-16 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
diff --git a/ext/tk/lib/tk/font.rb b/ext/tk/lib/tk/font.rb
index 92f3a82434..389f001f44 100644
--- a/ext/tk/lib/tk/font.rb
+++ b/ext/tk/lib/tk/font.rb
@@ -163,6 +163,82 @@ class TkFont
###################################
# class methods
###################################
+ def TkFont.actual(fnt, option=nil)
+ if fnt.kind_of?(TkFont)
+ fnt.actual(option)
+ else
+ actual_core(fnt, nil, option)
+ end
+ end
+
+ def TkFont.actual_displayof(fnt, win, option=nil)
+ if fnt.kind_of?(TkFont)
+ fnt.actual_displayof(win, option)
+ else
+ win = '.' unless win
+ actual_core(fnt, win, option)
+ end
+ end
+
+ def TkFont.configure(fnt, slot, value=None)
+ if fnt.kind_of?(TkFont)
+ fnt.configure(fnt, slot, value)
+ else
+ configure_core(fnt, slot, value)
+ end
+ fnt
+ end
+
+ def TkFont.configinfo(fnt, slot=nil)
+ if fnt.kind_of?(TkFont)
+ fnt.configinfo(fnt, slot)
+ else
+ configinfo_core(fnt, slot)
+ end
+ end
+
+ def TkFont.current_configinfo(fnt, slot=nil)
+ if fnt.kind_of?(TkFont)
+ fnt.current_configinfo(fnt, slot)
+ else
+ current_configinfo_core(fnt, slot)
+ end
+ end
+
+ def TkFont.measure(fnt, text)
+ if fnt.kind_of?(TkFont)
+ fnt.measure(text)
+ else
+ measure_core(fnt, nil, text)
+ end
+ end
+
+ def TkFont.measure_displayof(fnt, win, text)
+ if fnt.kind_of?(TkFont)
+ fnt.measure_displayof(win, text)
+ else
+ win = '.' unless win
+ measure_core(fnt, win, text)
+ end
+ end
+
+ def TkFont.metrics(fnt, option=nil)
+ if fnt.kind_of?(TkFont)
+ fnt.metrics(option)
+ else
+ metrics_core(fnt, nil, option)
+ end
+ end
+
+ def TkFont.metrics_displayof(fnt, win, option=nil)
+ if fnt.kind_of?(TkFont)
+ font.metrics_displayof(win, option=nil)
+ else
+ win = '.' unless win
+ metrics_core(fnt, win, option)
+ end
+ end
+
def TkFont.families(win=nil)
case (Tk::TK_VERSION)
when /^4\.*/
@@ -675,12 +751,380 @@ class TkFont
end
end
+ ###################################
+ public
+ ###################################
+ def method_missing(id, *args)
+ name = id.id2name
+ case args.length
+ when 1
+ configure name, args[0]
+ when 0
+ begin
+ configinfo name
+ rescue
+ fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at
+ end
+ else
+ fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
+ end
+ end
+
+ def call_font_configure(path, *args)
+ if path.kind_of?(Array)
+ # [path, optkey]
+ win, tag = path[0].split(';')
+ optkey = path[1].to_s
+ else
+ win, tag, optkey = path.split(';')
+ end
+
+ fontslot = _symbolkey2str(@fontslot)
+ if optkey && optkey != ""
+ ltn = fontslot.delete('font')
+ knj = fontslot.delete('kanjifont')
+ fontslot[optkey] = ltn if ltn
+ fontslot["kanji#{optkey}"] = knj if knj
+ end
+
+ keys = _symbolkey2str(args.pop).update(fontslot)
+ args.concat(hash_kv(keys))
+ tk_call(*args)
+ Tk_FontUseTBL[[win, tag, optkey].join(';')] = self
+ self
+ end
+
+ def used
+ ret = []
+ Tk_FontUseTBL.each{|key,value|
+ next unless self == value
+ if key.include?(';')
+ win, tag, optkey = key.split(';')
+ winobj = tk_tcl2ruby(win)
+ if winobj.kind_of? TkText
+ if optkey
+ ret.push([winobj, winobj.tagid2obj(tag), optkey])
+ else
+ ret.push([winobj, winobj.tagid2obj(tag)])
+ end
+ elsif winobj.kind_of? TkCanvas
+ if (tagobj = TkcTag.id2obj(winobj, tag)).kind_of? TkcTag
+ if optkey
+ ret.push([winobj, tagobj, optkey])
+ else
+ ret.push([winobj, tagobj])
+ end
+ elsif (tagobj = TkcItem.id2obj(winobj, tag)).kind_of? TkcItem
+ if optkey
+ ret.push([winobj, tagobj, optkey])
+ else
+ ret.push([winobj, tagobj])
+ end
+ else
+ if optkey
+ ret.push([winobj, tag, optkey])
+ else
+ ret.push([winobj, tag])
+ end
+ end
+ elsif winobj.kind_of? TkMenu
+ if optkey
+ ret.push([winobj, tag, optkey])
+ else
+ ret.push([winobj, tag])
+ end
+ else
+ if optkey
+ ret.push([win, tag, optkey])
+ else
+ ret.push([win, tag])
+ end
+ end
+ else
+ ret.push(tk_tcl2ruby(key))
+ end
+ }
+ ret
+ end
+
+ def id
+ @id
+ end
+
+ def to_eval
+ font
+ end
+
+ def font
+ @compoundfont
+ end
+ alias font_id font
+
+ def latin_font_id
+ @latinfont
+ end
+
+ def latin_font
+ # @latinfont
+ if @latin_descendant
+ @latin_descendant
+ else
+ @latin_descendant = DescendantFont.new(self, 'latin')
+ end
+ end
+ alias latinfont latin_font
+
+ def kanji_font_id
+ @kanjifont
+ end
+
+ def kanji_font
+ # @kanjifont
+ if @kanji_descendant
+ @kanji_descendant
+ else
+ @kanji_descendant = DescendantFont.new(self, 'kanji')
+ end
+ end
+ alias kanjifont kanji_font
+
+ def actual(option=nil)
+ actual_core(@compoundfont, nil, option)
+ end
+
+ def actual_displayof(win, option=nil)
+ win = '.' unless win
+ actual_core(@compoundfont, win, option)
+ end
+
+ def latin_actual(option=nil)
+ actual_core(@latinfont, nil, option)
+ end
+
+ def latin_actual_displayof(win, option=nil)
+ win = '.' unless win
+ actual_core(@latinfont, win, option)
+ end
+
+ def kanji_actual(option=nil)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ actual_core(@kanjifont, nil, option)
+ else
+ actual_core_tk4x(nil, nil, option)
+ end
+ end
+
+ def kanji_actual_displayof(win, option=nil)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ win = '.' unless win
+ actual_core(@kanjifont, win, option)
+ else
+ actual_core_tk4x(nil, win, option)
+ end
+ end
+
+ def [](slot)
+ configinfo slot
+ end
+
+ def []=(slot, val)
+ configure slot, val
+ val
+ end
+
+ def configure(slot, value=None)
+ configure_core(@compoundfont, slot, value)
+ self
+ end
+
+ def configinfo(slot=nil)
+ configinfo_core(@compoundfont, slot)
+ end
+
+ def current_configinfo(slot=nil)
+ current_configinfo_core(@compoundfont, slot)
+ end
+
+ def delete
+ delete_core
+ end
+
+ def latin_configure(slot, value=None)
+ if JAPANIZED_TK
+ configure_core(@latinfont, slot, value)
+ else
+ configure(slot, value)
+ end
+ self
+ end
+
+ def latin_configinfo(slot=nil)
+ if JAPANIZED_TK
+ configinfo_core(@latinfont, slot)
+ else
+ configinfo(slot)
+ end
+ end
+
+ def kanji_configure(slot, value=None)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ configure_core(@kanjifont, slot, value)
+ configure('size'=>configinfo('size')) # to reflect new configuration
+ else
+ #""
+ configure(slot, value)
+ end
+ self
+ end
+
+ def kanji_configinfo(slot=nil)
+ #if JAPANIZED_TK
+ if @kanjifont != ""
+ configinfo_core(@kanjifont, slot)
+ else
+ #[]
+ configinfo(slot)
+ end
+ end
+
+ def replace(ltn, knj=None)
+ knj = ltn if knj == None
+ latin_replace(ltn)
+ kanji_replace(knj)
+ self
+ end
+
+ def latin_replace(ltn)
+ latin_replace_core(ltn)
+ reset_pointadjust
+ self
+ end
+
+ def kanji_replace(knj)
+ kanji_replace_core(knj)
+ reset_pointadjust
+ self
+ end
+
+ def measure(text)
+ measure_core(@compoundfont, nil, text)
+ end
+
+ def measure_displayof(win, text)
+ win = '.' unless win
+ measure_core(@compoundfont, win, text)
+ end
+
+ def metrics(option=nil)
+ metrics_core(@compoundfont, nil, option)
+ end
+
+ def metrics_displayof(win, option=nil)
+ win = '.' unless win
+ metrics_core(@compoundfont, win, option)
+ end
+
+ def latin_metrics(option=nil)
+ metrics_core(@latinfont, nil, option)
+ end
+
+ def latin_metrics_displayof(win, option=nil)
+ win = '.' unless win
+ metrics_core(@latinfont, win, option)
+ end
+
+ def kanji_metrics(option=nil)
+ if JAPANIZED_TK
+ metrics_core(@kanjifont, nil, option)
+ else
+ metrics_core_tk4x(nil, nil, option)
+ end
+ end
+
+ def kanji_metrics_displayof(win, option=nil)
+ if JAPANIZED_TK
+ win = '.' unless win
+ metrics_core(@kanjifont, win, option)
+ else
+ metrics_core_tk4x(nil, win, option)
+ end
+ end
+
+ def reset_pointadjust
+ begin
+ if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
+ configure('pointadjust' => latin_actual.assoc('size')[1].to_f /
+ kanji_actual.assoc('size')[1].to_f )
+ end
+ rescue
+ end
+ self
+ end
+
+ ###################################
+ # private alias
+ ###################################
+ case (Tk::TK_VERSION)
+ when /^4\.*/
+ alias create_latinfont create_latinfont_tk4x
+ alias create_kanjifont create_kanjifont_tk4x
+ alias create_compoundfont create_compoundfont_tk4x
+
+ when /^8\.[0-5]/
+ alias create_latinfont create_latinfont_tk8x
+ alias create_kanjifont create_kanjifont_tk8x
+ alias create_compoundfont create_compoundfont_tk8x
+
+ else
+ alias create_latinfont create_latinfont_tk8x
+ alias create_kanjifont create_kanjifont_tk8x
+ alias create_compoundfont create_compoundfont_tk8x
+
+ end
+
+ ###################################
+ # public alias
+ ###################################
+ alias ascii_font latin_font
+ alias asciifont latinfont
+ alias create_asciifont create_latinfont
+ alias ascii_actual latin_actual
+ alias ascii_actual_displayof latin_actual_displayof
+ alias ascii_configure latin_configure
+ alias ascii_configinfo latin_configinfo
+ alias ascii_replace latin_replace
+ alias ascii_metrics latin_metrics
+
+ ###################################
+ def dup
+ src = self
+ obj = super()
+ obj.instance_eval{ initialize(src) }
+ obj
+ end
+ def clone
+ src = self
+ obj = super()
+ obj.instance_eval{ initialize(src) }
+ obj
+ end
+end
+
+module TkFont::CoreMethods
+ include Tk
+ extend TkCore
+
+ private
+
def actual_core_tk4x(font, win=nil, option=nil)
# dummy
if option == 'pointadjust' || option == :pointadjust
1.0
elsif option
- case OptionType[option.to_s]
+ case TkFont::OptionType[option.to_s]
when ?n
0
when ?b
@@ -705,7 +1149,7 @@ class TkFont
else
val = tk_call('font', 'actual', font, "-#{option}")
end
- case OptionType[option.to_s]
+ case TkFont::OptionType[option.to_s]
when ?n
num_or_str(val)
when ?b
@@ -727,7 +1171,7 @@ class TkFont
else
key = key[1..-1]
val = l.shift
- case OptionType[key]
+ case TkFont::OptionType[key]
when ?n
r.push [key, num_or_str(val)]
when ?b
@@ -752,7 +1196,7 @@ class TkFont
if option == 'pointadjust' || option == :pointadjust
1.0
elsif option
- case OptionType[option.to_s]
+ case TkFont::OptionType[option.to_s]
when ?n
0
when ?b
@@ -772,7 +1216,7 @@ class TkFont
def current_configinfo_core_tk4x(font, option=nil)
if option
- case OptionType[option.to_s]
+ case TkFont::OptionType[option.to_s]
when ?n
0
when ?b
@@ -860,7 +1304,7 @@ class TkFont
""
elsif option
val = tk_call('font', 'configure', font, "-#{option}")
- case OptionType[option.to_s]
+ case TkFont::OptionType[option.to_s]
when ?n
num_or_str(val)
when ?b
@@ -877,7 +1321,7 @@ class TkFont
else
key = key[1..-1]
val = l.shift
- case OptionType[key]
+ case TkFont::OptionType[key]
when ?n
r.push [key, num_or_str(val)]
when ?b
@@ -899,7 +1343,7 @@ class TkFont
""
elsif option
val = tk_call('font', 'configure', font, "-#{option}")
- case OptionType[option.to_s]
+ case TkFont::OptionType[option.to_s]
when ?n
num_or_str(val)
when ?b
@@ -916,7 +1360,7 @@ class TkFont
else
key = key[1..-1]
val = l.shift
- case OptionType[key]
+ case TkFont::OptionType[key]
when ?n
r.push [key, num_or_str(val)]
when ?b
@@ -931,8 +1375,8 @@ class TkFont
end
def delete_core_tk4x
- Tk_FontNameTBL.delete(@id)
- Tk_FontUseTBL.delete_if{|key,value| value == self}
+ TkFont::Tk_FontNameTBL.delete(@id)
+ TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
end
def delete_core_tk8x
@@ -948,15 +1392,15 @@ class TkFont
tk_call('font', 'delete', @compoundfont)
rescue
end
- Tk_FontNameTBL.delete(@id)
- Tk_FontUseTBL.delete_if{|key,value| value == self}
+ TkFont::Tk_FontNameTBL.delete(@id)
+ TkFont::Tk_FontUseTBL.delete_if{|key,value| value == self}
end
def latin_replace_core_tk4x(ltn)
create_latinfont_tk4x(ltn)
@compoundfont[0] = [@latinfont] if JAPANIZED_TK
@fontslot['font'] = @latinfont
- Tk_FontUseTBL.dup.each{|w, fobj|
+ TkFont::Tk_FontUseTBL.dup.each{|w, fobj|
if self == fobj
begin
if w.include?(';')
@@ -978,7 +1422,7 @@ class TkFont
tk_call(w, 'configure', '-font', @latinfont)
end
rescue
- Tk_FontUseTBL.delete(w)
+ TkFont::Tk_FontUseTBL.delete(w)
end
end
}
@@ -991,7 +1435,7 @@ class TkFont
create_kanjifont_tk4x(knj)
@compoundfont[1] = [@kanjifont]
@fontslot['kanjifont'] = @kanjifont
- Tk_FontUseTBL.dup.each{|w, fobj|
+ TkFont::Tk_FontUseTBL.dup.each{|w, fobj|
if self == fobj
begin
if w.include?(';')
@@ -1013,7 +1457,7 @@ class TkFont
tk_call(w, 'configure', '-kanjifont', @kanjifont)
end
rescue
- Tk_FontUseTBL.delete(w)
+ TkFont::Tk_FontUseTBL.delete(w)
end
end
}
@@ -1030,7 +1474,7 @@ class TkFont
fnt_bup = tk_call('font', 'create', '@font_tmp', '-copy', @latinfont)
rescue
#fnt_bup = ''
- fnt_bup = DEFAULT_LATIN_FONT_NAME
+ fnt_bup = TkFont::DEFAULT_LATIN_FONT_NAME
end
end
@@ -1093,7 +1537,7 @@ class TkFont
fnt_bup = tk_call('font', 'create', '@font_tmp', '-copy', @kanjifont)
rescue
#fnt_bup = ''
- fnt_bup = DEFAULT_KANJI_FONT_NAME
+ fnt_bup = TkFont::DEFAULT_KANJI_FONT_NAME
end
end
@@ -1124,16 +1568,16 @@ class TkFont
self
end
- def measure_core_tk4x(win, text)
+ def measure_core_tk4x(font, win, text)
0
end
- def measure_core_tk8x(win, text)
+ def measure_core_tk8x(font, win, text)
if win
- number(tk_call('font', 'measure', @compoundfont,
+ number(tk_call('font', 'measure', font,
'-displayof', win, text))
else
- number(tk_call('font', 'measure', @compoundfont, text))
+ number(tk_call('font', 'measure', font, text))
end
end
@@ -1173,9 +1617,6 @@ class TkFont
###################################
case (Tk::TK_VERSION)
when /^4\.*/
- alias create_latinfont create_latinfont_tk4x
- alias create_kanjifont create_kanjifont_tk4x
- alias create_compoundfont create_compoundfont_tk4x
alias actual_core actual_core_tk4x
alias configure_core configure_core_tk4x
alias configinfo_core configinfo_core_tk4x
@@ -1187,9 +1628,6 @@ class TkFont
alias metrics_core metrics_core_tk4x
when /^8\.[0-5]/
- alias create_latinfont create_latinfont_tk8x
- alias create_kanjifont create_kanjifont_tk8x
- alias create_compoundfont create_compoundfont_tk8x
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
@@ -1201,9 +1639,6 @@ class TkFont
alias metrics_core metrics_core_tk8x
else
- alias create_latinfont create_latinfont_tk8x
- alias create_kanjifont create_kanjifont_tk8x
- alias create_compoundfont create_compoundfont_tk8x
alias actual_core actual_core_tk8x
alias configure_core configure_core_tk8x
alias configinfo_core configinfo_core_tk8x
@@ -1215,344 +1650,9 @@ class TkFont
alias metrics_core metrics_core_tk8x
end
+end
- ###################################
- public
- ###################################
- def method_missing(id, *args)
- name = id.id2name
- case args.length
- when 1
- configure name, args[0]
- when 0
- begin
- configinfo name
- rescue
- fail NameError, "undefined local variable or method `#{name}' for #{self.to_s}", error_at
- end
- else
- fail NameError, "undefined method `#{name}' for #{self.to_s}", error_at
- end
- end
-
- def call_font_configure(path, *args)
- if path.kind_of?(Array)
- # [path, optkey]
- win, tag = path[0].split(';')
- optkey = path[1].to_s
- else
- win, tag, optkey = path.split(';')
- end
-
- fontslot = _symbolkey2str(@fontslot)
- if optkey && optkey != ""
- ltn = fontslot.delete('font')
- knj = fontslot.delete('kanjifont')
- fontslot[optkey] = ltn if ltn
- fontslot["kanji#{optkey}"] = knj if knj
- end
-
- keys = _symbolkey2str(args.pop).update(fontslot)
- args.concat(hash_kv(keys))
- tk_call(*args)
- Tk_FontUseTBL[[win, tag, optkey].join(';')] = self
- self
- end
-
- def used
- ret = []
- Tk_FontUseTBL.each{|key,value|
- next unless self == value
- if key.include?(';')
- win, tag, optkey = key.split(';')
- winobj = tk_tcl2ruby(win)
- if winobj.kind_of? TkText
- if optkey
- ret.push([winobj, winobj.tagid2obj(tag), optkey])
- else
- ret.push([winobj, winobj.tagid2obj(tag)])
- end
- elsif winobj.kind_of? TkCanvas
- if (tagobj = TkcTag.id2obj(winobj, tag)).kind_of? TkcTag
- if optkey
- ret.push([winobj, tagobj, optkey])
- else
- ret.push([winobj, tagobj])
- end
- elsif (tagobj = TkcItem.id2obj(winobj, tag)).kind_of? TkcItem
- if optkey
- ret.push([winobj, tagobj, optkey])
- else
- ret.push([winobj, tagobj])
- end
- else
- if optkey
- ret.push([winobj, tag, optkey])
- else
- ret.push([winobj, tag])
- end
- end
- elsif winobj.kind_of? TkMenu
- if optkey
- ret.push([winobj, tag, optkey])
- else
- ret.push([winobj, tag])
- end
- else
- if optkey
- ret.push([win, tag, optkey])
- else
- ret.push([win, tag])
- end
- end
- else
- ret.push(tk_tcl2ruby(key))
- end
- }
- ret
- end
-
- def id
- @id
- end
-
- def to_eval
- font
- end
-
- def font
- @compoundfont
- end
- alias font_id font
-
- def latin_font_id
- @latinfont
- end
-
- def latin_font
- # @latinfont
- if @latin_descendant
- @latin_descendant
- else
- @latin_descendant = DescendantFont.new(self, 'latin')
- end
- end
- alias latinfont latin_font
-
- def kanji_font_id
- @kanjifont
- end
-
- def kanji_font
- # @kanjifont
- if @kanji_descendant
- @kanji_descendant
- else
- @kanji_descendant = DescendantFont.new(self, 'kanji')
- end
- end
- alias kanjifont kanji_font
-
- def actual(option=nil)
- actual_core(@compoundfont, nil, option)
- end
-
- def actual_displayof(win, option=nil)
- win = '.' unless win
- actual_core(@compoundfont, win, option)
- end
-
- def latin_actual(option=nil)
- actual_core(@latinfont, nil, option)
- end
-
- def latin_actual_displayof(win, option=nil)
- win = '.' unless win
- actual_core(@latinfont, win, option)
- end
-
- def kanji_actual(option=nil)
- #if JAPANIZED_TK
- if @kanjifont != ""
- actual_core(@kanjifont, nil, option)
- else
- actual_core_tk4x(nil, nil, option)
- end
- end
-
- def kanji_actual_displayof(win, option=nil)
- #if JAPANIZED_TK
- if @kanjifont != ""
- win = '.' unless win
- actual_core(@kanjifont, win, option)
- else
- actual_core_tk4x(nil, win, option)
- end
- end
-
- def [](slot)
- configinfo slot
- end
-
- def []=(slot, val)
- configure slot, val
- val
- end
-
- def configure(slot, value=None)
- configure_core(@compoundfont, slot, value)
- self
- end
-
- def configinfo(slot=nil)
- configinfo_core(@compoundfont, slot)
- end
-
- def current_configinfo(slot=nil)
- current_configinfo_core(@compoundfont, slot)
- end
-
- def delete
- delete_core
- end
-
- def latin_configure(slot, value=None)
- if JAPANIZED_TK
- configure_core(@latinfont, slot, value)
- else
- configure(slot, value)
- end
- self
- end
-
- def latin_configinfo(slot=nil)
- if JAPANIZED_TK
- configinfo_core(@latinfont, slot)
- else
- configinfo(slot)
- end
- end
-
- def kanji_configure(slot, value=None)
- #if JAPANIZED_TK
- if @kanjifont != ""
- configure_core(@kanjifont, slot, value)
- configure('size'=>configinfo('size')) # to reflect new configuration
- else
- #""
- configure(slot, value)
- end
- self
- end
-
- def kanji_configinfo(slot=nil)
- #if JAPANIZED_TK
- if @kanjifont != ""
- configinfo_core(@kanjifont, slot)
- else
- #[]
- configinfo(slot)
- end
- end
-
- def replace(ltn, knj=None)
- knj = ltn if knj == None
- latin_replace(ltn)
- kanji_replace(knj)
- self
- end
-
- def latin_replace(ltn)
- latin_replace_core(ltn)
- reset_pointadjust
- self
- end
-
- def kanji_replace(knj)
- kanji_replace_core(knj)
- reset_pointadjust
- self
- end
-
- def measure(text)
- measure_core(nil, text)
- end
-
- def measure_displayof(win, text)
- win = '.' unless win
- measure_core(win, text)
- end
-
- def metrics(option=nil)
- metrics_core(@compoundfont, nil, option)
- end
-
- def metrics_displayof(win, option=nil)
- win = '.' unless win
- metrics_core(@compoundfont, win, option)
- end
-
- def latin_metrics(option=nil)
- metrics_core(@latinfont, nil, option)
- end
-
- def latin_metrics_displayof(win, option=nil)
- win = '.' unless win
- metrics_core(@latinfont, win, option)
- end
-
- def kanji_metrics(option=nil)
- if JAPANIZED_TK
- metrics_core(@kanjifont, nil, option)
- else
- metrics_core_tk4x(nil, nil, option)
- end
- end
-
- def kanji_metrics_displayof(win, option=nil)
- if JAPANIZED_TK
- win = '.' unless win
- metrics_core(@kanjifont, win, option)
- else
- metrics_core_tk4x(nil, win, option)
- end
- end
-
- def reset_pointadjust
- begin
- if /^8\.*/ === Tk::TK_VERSION && JAPANIZED_TK
- configure('pointadjust' => latin_actual.assoc('size')[1].to_f /
- kanji_actual.assoc('size')[1].to_f )
- end
- rescue
- end
- self
- end
-
- ###################################
- # public alias
- ###################################
- alias ascii_font latin_font
- alias asciifont latinfont
- alias create_asciifont create_latinfont
- alias ascii_actual latin_actual
- alias ascii_actual_displayof latin_actual_displayof
- alias ascii_configure latin_configure
- alias ascii_configinfo latin_configinfo
- alias ascii_replace latin_replace
- alias ascii_metrics latin_metrics
-
- ###################################
- def dup
- src = self
- obj = super()
- obj.instance_eval{ initialize(src) }
- obj
- end
- def clone
- src = self
- obj = super()
- obj.instance_eval{ initialize(src) }
- obj
- end
+class TkFont
+ include TkFont::CoreMethods
+ extend TkFont::CoreMethods
end
diff --git a/ext/tk/lib/tk/menuspec.rb b/ext/tk/lib/tk/menuspec.rb
index c8819f8e41..118a4f42b1 100644
--- a/ext/tk/lib/tk/menuspec.rb
+++ b/ext/tk/lib/tk/menuspec.rb
@@ -12,12 +12,12 @@
# And the format of the menu_info is:
# [
# [text, underline, configs], # menu button/entry (*1)
-# [label, command, underline, accelerator, configs], # command entry
-# [label, TkVar_obj, underline, accelerator, configs], # checkbutton entry
+# [label, command, underline, accelerator, configs], # command entry
+# [label, TkVar_obj, underline, accelerator, configs], # checkbutton entry
# [label, [TkVar_obj, value],
-# underline, accelerator, configs], # radiobutton entry
+# underline, accelerator, configs], # radiobutton entry
# [label, [[...menu_info...], [...menu_info...], ...],
-# underline, accelerator, configs], # cascade entry
+# underline, accelerator, configs], # cascade entry (*2)
# '---', # separator
# ...
# ]
@@ -33,6 +33,10 @@
# and *.apple for Mac), append 'menu_name'=>name (name is 'help' for UNIX,
# 'system' for Win, and 'apple' for Mac) option to the configs hash of
# menu button/entry information.
+#
+# NOTE: (*2)
+# If you want to configure a cascade menu, add :menu_config=>{...configs..}
+# to the configs of the cascade entry.
module TkMenuSpec
def _create_menu(parent, menu_info, menu_name = nil,
diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb
index 98d66a7225..0e8fd86c0f 100644
--- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb
+++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb
@@ -99,7 +99,7 @@ class Tk::TreeCtrl::NotifyEvent
}
],
- [ ?o, proc{|val| tk_tcl2ruby(val)} ],
+ [ ?o, proc{|val| TkComm.tk_tcl2ruby(val)} ],
nil
]
@@ -131,12 +131,19 @@ module Tk::TreeCtrl::ConfigMethod
key = key.to_s
end
+ if (obj.kind_of?(Tk::TreeCtrl::Column) ||
+ obj.kind_of?(Tk::TreeCtrl::Element) ||
+ obj.kind_of?(Tk::TreeCtrl::Item) ||
+ obj.kind_of?(Tk::TreeCtrl::Style))
+ obj = obj.id
+ end
+
case key
when 'column'
obj
when 'debug'
- obj
+ None
when 'dragimage'
obj
@@ -162,12 +169,13 @@ module Tk::TreeCtrl::ConfigMethod
end
def tagid(mixed_id)
- if mixed_id.kind_of?(Array)
+ if mixed_id == 'debug'
+ ['debug', None]
+ elsif mixed_id.kind_of?(Array)
[mixed_id[0], treectrl_tagid(*mixed_id)]
else
tagid(mixed_id.split(':'))
end
- fail ArgumentError, "unknown id format"
end
def __item_cget_cmd(mixed_id)
@@ -346,17 +354,30 @@ module Tk::TreeCtrl::ConfigMethod
current_itemconfiginfo(['element', tagOrId], slot)
end
- def item_element_cget(tagOrId, option)
- itemcget([['item', 'element'], tagOrId], option)
+ def item_cget(tagOrId, option)
+ itemcget(['item', tagOrId], option)
end
- def item_element_configure(tagOrId, slot, value=None)
- itemconfigure([['item', 'element'], tagOrId], slot, value)
+ def item_configure(tagOrId, slot, value=None)
+ itemconfigure(['item', tagOrId], slot, value)
end
- def item_element_configinfo(tagOrId, slot=nil)
- itemconfiginfo([['item', 'element'], tagOrId], slot)
+ def item_configinfo(tagOrId, slot=nil)
+ itemconfiginfo(['item', tagOrId], slot)
end
- def current_item_element_configinfo(tagOrId, slot=nil)
- current_itemconfiginfo([['item', 'element'], tagOrId], slot)
+ def current_item_configinfo(tagOrId, slot=nil)
+ current_itemconfiginfo(['item', tagOrId], slot)
+ end
+
+ def item_element_cget(item, column, elem, option)
+ itemcget([['item', 'element'], [item, column, elem]], option)
+ end
+ def item_element_configure(item, column, elem, slot, value=None)
+ itemconfigure([['item', 'element'], [item, column, elem]], slot, value)
+ end
+ def item_element_configinfo(item, column, elem, slot=nil)
+ itemconfiginfo([['item', 'element'], [item, column, elem]], slot)
+ end
+ def current_item_element_configinfo(item, column, elem, slot=nil)
+ current_itemconfiginfo([['item', 'element'], [item, column, elem]], slot)
end
def marquee_cget(tagOrId, option)
@@ -407,11 +428,20 @@ class Tk::TreeCtrl
include Scrollable
TkCommandNames = ['treectrl'.freeze].freeze
- WidgetClassName = ''.freeze
+ WidgetClassName = 'TreeCtrl'.freeze
WidgetClassNames[WidgetClassName] = self
#########################
+ def __destroy_hook__
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.delete(@path)
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.delete(@path)
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.delete(@path)
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.delete(@path)
+ end
+
+ #########################
+
def __boolval_optkeys
[
'showbuttons', 'showheader', 'showlines', 'showroot',
@@ -480,6 +510,9 @@ class Tk::TreeCtrl
end
def column_delete(idx)
+ if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path]
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path].delete(idx)
+ end
tk_send('column', 'delete', idx)
self
end
@@ -488,8 +521,8 @@ class Tk::TreeCtrl
num_or_str(tk_send('column', 'index', idx))
end
- def column_move(idx, to)
- tk_send('column', 'move', idx, to)
+ def column_move(idx, before)
+ tk_send('column', 'move', idx, before)
self
end
@@ -503,7 +536,7 @@ class Tk::TreeCtrl
end
def compare(item1, op, item2)
- number(tk_send('compare', item1, op, item2))
+ bool(tk_send('compare', item1, op, item2))
end
def contentbox()
@@ -563,18 +596,29 @@ class Tk::TreeCtrl
end
def element_delete(*elems)
+ if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path]
+ elems.each{|elem|
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path].delete(elem)
+ }
+ end
tk_send('element', 'delete', *elems)
self
end
def element_names()
- list(tk_send('element', 'names'))
+ list(tk_send('element', 'names')).collect!{|elem|
+ Tk::TreeCtrl::Element.id2obj(self, elem)
+ }
end
def element_type(elem)
tk_send('element', 'type', elem)
end
+ def element_class(elem)
+ Tk::TreeCtrl::Element.type2class(element_type(elem))
+ end
+
def expand(*dsc)
tk_send('expand', *dsc)
self
@@ -586,7 +630,37 @@ class Tk::TreeCtrl
end
def identify(x, y)
- list(tk_send('identify', x, y))
+ lst = list(tk_send('identify', x, y))
+
+ if lst[0] == 'item'
+ lst[1] = Tk::TreeCtrl::Item.id2obj(self, lst[1])
+ size = lst.size
+ i = 2
+ while i < size
+ case lst[i]
+ when 'line'
+ i += 1
+ lst[i] = Tk::TreeCtrl::Item.id2obj(self, lst[i])
+ i += 1
+
+ when 'button'
+ i += 1
+
+ when 'column'
+ i += 2
+
+ when 'elem'
+ i += 1
+ lst[i] = Tk::TreeCtrl::Element.id2obj(self, lst[i])
+ i += 1
+
+ else
+ i += 1
+ end
+ end
+ end
+
+ lst
end
def index(idx)
@@ -594,7 +668,9 @@ class Tk::TreeCtrl
end
def item_ancestors(item)
- list(tk_send('item', 'ancestors', item))
+ list(tk_send('item', 'ancestors', item)).collect!{|id|
+ Tk::TreeCtrl::Item.id2obj(self, id)
+ }
end
def item_bbox(item, *args)
@@ -602,7 +678,9 @@ class Tk::TreeCtrl
end
def item_children(item)
- list(tk_send('item', 'children', item))
+ list(tk_send('item', 'children', item)).collect!{|id|
+ Tk::TreeCtrl::Item.id2obj(self, id)
+ }
end
def item_collapse(item)
@@ -624,7 +702,24 @@ class Tk::TreeCtrl
num_or_str(tk_send('item', 'create', keys))
end
+ def _erase_children(item)
+ item_children(item).each{|i| _erase_children(i)}
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].delete(item)
+ end
+ private :_erase_children
+
def item_delete(first, last=None)
+ if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path]
+ if first == 'all' || first == :all || last == 'all' || last == :all
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].clear
+ elsif last == None
+ _erase_children(first)
+ else
+ self.range(first, last).each{|id|
+ _erase_children(id)
+ }
+ end
+ end
tk_send('item', 'delete', first, last)
self
end
@@ -633,6 +728,10 @@ class Tk::TreeCtrl
list(tk_send('item', 'dump', item))
end
+ def item_dump_hash(item)
+ Hash[*list(tk_send('item', 'dump', item))]
+ end
+
def item_element_actual(item, column, elem, key)
tk_send('item', 'element', 'actual', item, column, elem, "-#{key}")
end
@@ -652,7 +751,8 @@ class Tk::TreeCtrl
tk_send('item', 'firstchild', parent, child)
self
else
- num_or_str(tk_send('item', 'firstchild', parent))
+ id = num_or_str(tk_send('item', 'firstchild', parent))
+ Tk::TreeCtrl::Item.id2obj(self, id)
end
end
alias item_first_child item_firstchild
@@ -694,7 +794,8 @@ class Tk::TreeCtrl
tk_send('item', 'lastchild', parent, child)
self
else
- num_or_str(tk_send('item', 'lastchild', parent))
+ id = num_or_str(tk_send('item', 'lastchild', parent))
+ Tk::TreeCtrl::Item.id2obj(self, id)
end
end
alias item_last_child item_lastchild
@@ -704,7 +805,8 @@ class Tk::TreeCtrl
tk_send('item', 'nextsibling', sibling, nxt)
self
else
- num_or_str(tk_send('item', 'nextsibling', sibling))
+ id = num_or_str(tk_send('item', 'nextsibling', sibling))
+ Tk::TreeCtrl::Item.id2obj(self, id)
end
end
alias item_next_sibling item_nextsibling
@@ -716,7 +818,8 @@ class Tk::TreeCtrl
alias item_children_size item_numchildren
def item_parent(item)
- num_or_str(tk_send('item', 'parent', item))
+ id = num_or_str(tk_send('item', 'parent', item))
+ Tk::TreeCtrl::Item.id2obj(self, id)
end
def item_prevsibling(sibling, prev=nil)
@@ -724,44 +827,84 @@ class Tk::TreeCtrl
tk_send('item', 'prevsibling', sibling, prev)
self
else
- num_or_str(tk_send('item', 'prevsibling', sibling))
+ id = num_or_str(tk_send('item', 'prevsibling', sibling))
+ Tk::TreeCtrl::Item.id2obj(self, id)
end
end
alias item_prev_sibling item_prevsibling
def item_remove(item)
- list(tk_send('item', 'remove', item))
+ tk_send('item', 'remove', item)
+ self
end
def item_rnc(item)
list(tk_send('item', 'rnc', item))
end
- def item_sort(item, *opts)
- flag = false
- if opts[-1].kind_of?(Hash)
- opts[-1,1] = __conv_item_keyonly_opts(item, opts[-1]).to_a
- end
+ def _item_sort_core(real_sort, item, *opts)
+ # opts ::= sort_param [, sort_param, ... ]
+ # sort_param ::= {key=>val, ...}
+ # [type, desc, {key=>val, ...}]
+ # param
+ opts = opts.collect{|param|
+ if param.kind_of?(Hash)
+ param = _symbolkey2str(param)
+ if param.key('column')
+ key = '-column'
+ desc = param.delete('column')
+ elsif param.key('element')
+ key = '-element'
+ desc = param.delete('element')
+ else
+ key = nil
+ end
+
+ if param.empty?
+ param = None
+ else
+ param = __conv_item_keyonly_opts(item, param).to_a
+ end
+
+ if key
+ [key, desc].concat(param)
+ else
+ param
+ end
+
+ elsif param.kind_of?(Array)
+ if param[2].kind_of?(Hash)
+ param[2] = __conv_item_keyonly_opts(item, param[2]).to_a
+ end
+ param
+
+ elsif param.kind_of?(String) && param =~ /\A[a-z]+\Z/
+ '-' << param
+
+ elsif param.kind_of?(Symbol)
+ '-' << param.to_s
- opts = opts.collect{|opt|
- if opt.kind_of?(Array)
- key = "-#{opt[0]}"
- flag = true if key == '-notreally'
- ["-#{opt[0]}", opt[1]]
else
- key = "-#{opt}"
- flag = true if key == '-notreally'
- key
+ param
end
}.flatten
- ret = tk_send('item', 'sort', item, *opts)
- if flag
- list(ret)
+ if real_sort
+ tk_send('item', 'sort', item, *opts)
+ self
else
- ret
+ list(tk_send('item', 'sort', item, '-notreally', *opts))
end
end
+ private :_item_sort_core
+
+ def item_sort_not_really(item, *opts)
+ _item_sort_core(false, item, *opts)
+ end
+
+ def item_sort(item, *opts)
+ _item_sort_core(true, item, *opts)
+ end
def item_state_forcolumn(item, column, *args)
tk_send('item', 'state', 'forcolumn', item, column, *args)
@@ -783,7 +926,9 @@ class Tk::TreeCtrl
end
def item_style_elements(item, column)
- list(tk_send('item', 'style', 'elements', item, column))
+ list(tk_send('item', 'style', 'elements', item, column)).collect!{|id|
+ Tk::TreeCtrl::Style.id2obj(self, id)
+ }
end
def item_style_map(item, column, style, map)
@@ -794,12 +939,15 @@ class Tk::TreeCtrl
def item_style_set(item, column=nil, *args)
if args.empty?
if column
- tk_send('item', 'style', 'set', item, column)
+ id = tk_send('item', 'style', 'set', item, column)
+ Tk::TreeCtrl::Style.id2obj(self, id)
else
- list(tk_send('item', 'style', 'set', item))
+ list(tk_send('item', 'style', 'set', item)).collect!{|id|
+ Tk::TreeCtrl::Style.id2obj(self, id)
+ }
end
else
- tk_send('item', 'style', 'set', item, *(args.flatten))
+ tk_send('item', 'style', 'set', item, column, *(args.flatten))
self
end
end
@@ -813,7 +961,7 @@ class Tk::TreeCtrl
tk_send('item', 'text', item, column)
end
else
- tk_send('item', 'text', item, txt, *args)
+ tk_send('item', 'text', item, column, txt, *args)
self
end
end
@@ -868,7 +1016,9 @@ class Tk::TreeCtrl
end
def marquee_identify()
- list(tk_send('marquee', 'identify'))
+ list(tk_send('marquee', 'identify')).collect!{|id|
+ Tk::TreeCtrl::Item.id2obj(self, id)
+ }
end
def marquee_visible(st=None)
@@ -913,7 +1063,7 @@ class Tk::TreeCtrl
self
end
- def notify_bindremove(obj, event)
+ def notify_bind_remove(obj, event)
_bind_remove([@path, 'notify', 'bind', obj], event)
self
end
@@ -970,17 +1120,25 @@ class Tk::TreeCtrl
def numcolumns()
num_or_str(tk_send('numcolumns'))
end
+ alias num_columns numcolumns
+ alias columns_size numcolumns
def numitems()
num_or_str(tk_send('numitems'))
end
+ alias num_items numitems
+ alias items_size numitems
def orphans()
- list(tk_send('orphans'))
+ list(tk_send('orphans')).collect!{|id|
+ Tk::TreeCtrl::Item.id2obj(self, id)
+ }
end
def range(first, last)
- list(tk_send('range', first, last))
+ list(tk_send('range', first, last)).collect!{|id|
+ Tk::TreeCtrl::Item.id2obj(self, id)
+ }
end
def state_define(name)
@@ -1012,7 +1170,8 @@ class Tk::TreeCtrl
end
def selection_anchor(item=None)
- num_or_str(tk_send('selection', 'anchor', item))
+ id = num_or_str(tk_send('selection', 'anchor', item))
+ Tk::TreeCtrl::Item.id2obj(self, id)
end
def selection_clear(*args) # first, last
@@ -1025,7 +1184,9 @@ class Tk::TreeCtrl
end
def selection_get()
- list(tk_send('selection', 'get'))
+ list(tk_send('selection', 'get')).collect!{|id|
+ Tk::TreeCtrl::Item.id2obj(self, id)
+ }
end
def selection_includes(item)
@@ -1046,34 +1207,65 @@ class Tk::TreeCtrl
end
def style_delete(*args)
+ if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path]
+ args.each{|sty|
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path].delete(sty)
+ }
+ end
tk_send('style', 'delete', *args)
self
end
def style_elements(style, *elems)
if elems.empty?
- list(tk_send('style', 'elements', style))
+ list(tk_send('style', 'elements', style)).collect!{|id|
+ Tk::TreeCtrl::Element.id2obj(self, id)
+ }
else
tk_send('style', 'elements', style, elems.flatten)
self
end
end
+ def _conv_style_layout_val(sty, val)
+ case sty.to_s
+ when 'padx', 'pady', 'ipadx', 'ipady'
+ number(val)
+ when 'detach'
+ bool(val)
+ when 'union'
+ simplelist(val).collect!{|elem|
+ Tk::TreeCtrl::Element.id2obj(self, elem)
+ }
+ else
+ val
+ end
+ end
+ private :_conv_style_layout_val
+
def style_layout(style, elem, keys=None)
if keys && keys != None
if keys.kind_of?(Hash)
tk_send('style', 'layout', style, elem, *hash_kv(keys))
self
else
- tk_send('style', 'layout', style, elem, "-#{keys}")
+ _conv_style_layout_val(keys,
+ tk_send('style', 'layout',
+ style, elem, "-#{keys}"))
end
else
- list(tk_send('style', 'layout', style, elem))
+ ret = Hash.new
+ Hash[*simplelist(tk_send('style', 'layout', style, elem))].each{|k, v|
+ ret[k] = _conv_style_layout_val(k, v)
+ }
+ ret
end
end
def style_names()
- list(tk_send('style', 'names'))
+ list(tk_send('style', 'names')).collect!{|id|
+ Tk::TreeCtrl::Style.id2obj(self, id)
+ }
end
def toggle(*items)
@@ -1086,3 +1278,554 @@ class Tk::TreeCtrl
self
end
end
+
+#####################
+
+class Tk::TreeCtrl::Column < TkObject
+ TreeCtrlColumnID_TBL = TkCore::INTERP.create_table
+ TreeCtrlColumnID = ['treectrl_column'.freeze, '00000'.taint].freeze
+
+ TkCore::INTERP.init_ip_env{Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.clear}
+
+ def self.id2obj(tree, id)
+ tpath = tree.path
+ return id unless Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath]
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id] : id
+ end
+
+ def initialize(parent, keys={})
+ @tree = parent
+ @tpath = parent.path
+
+ keys = _symbolkey2str(keys)
+
+ @path = @id =
+ keys.delete('tag') ||
+ Tk::TreeCtrl::Column::TreeCtrlColumnID.join(TkCore::INTERP._ip_id_)
+
+ keys['tag'] = @id
+
+ unless Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath]
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath][@id] = self
+ Tk::TreeCtrl::Column::TreeCtrlColumnID[1].succ!
+
+ @tree.column_create(keys)
+ end
+
+ def id
+ @id
+ end
+
+ def to_s
+ @id.to_s.dup
+ end
+
+ def cget(opt)
+ @tree.column_cget(@tree.column_index(@id), opt)
+ end
+
+ def configure(*args)
+ @tree.column_configure(@tree.column_index(@id), *args)
+ end
+
+ def configinfo(*args)
+ @tree.column_configinfo(@tree.column_index(@id), *args)
+ end
+
+ def current_configinfo(*args)
+ @tree.current_column_configinfo(@tree.column_index(@id), *args)
+ end
+
+ def delete
+ @tree.column_delete(@tree.column_index(@id))
+ self
+ end
+
+ def index
+ @tree.column_index(@id)
+ end
+
+ def move(before)
+ @tree.column_move(@tree.column_index(@id), before)
+ self
+ end
+
+ def needed_width
+ @tree.column_needed_width(@tree.column_index(@id))
+ end
+ alias neededwidth needed_width
+
+ def current_width
+ @tree.column_width(@tree.column_index(@id))
+ end
+end
+
+#####################
+
+class Tk::TreeCtrl::Element < TkObject
+ TreeCtrlElementID_TBL = TkCore::INTERP.create_table
+ TreeCtrlElementID = ['treectrl_element'.freeze, '00000'.taint].freeze
+ TreeCtrlElemTypeToClass = {}
+
+ TkCore::INTERP.init_ip_env{
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.clear
+ }
+
+ def self.type2class(type)
+ TreeCtrlElemTypeToClass[type] || type
+ end
+
+ def self.id2obj(tree, id)
+ tpath = tree.path
+ return id unless Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath]
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id] : id
+ end
+
+ def initialize(parent, type, keys=nil)
+ @tree = parent
+ @tpath = parent.path
+ @type = type.to_s
+ @path = @id =
+ Tk::TreeCtrl::Element::TreeCtrlElementID.join(TkCore::INTERP._ip_id_)
+ unless Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath]
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath][@id] = self
+ Tk::TreeCtrl::Element::TreeCtrlElementID[1].succ!
+
+ @tree.element_create(@id, @type, keys)
+ end
+
+ def id
+ @id
+ end
+
+ def to_s
+ @id.dup
+ end
+
+ def cget(opt)
+ @tree.element_cget(@id, opt)
+ end
+
+ def configure(*args)
+ @tree.element_configure(@id, *args)
+ end
+
+ def configinfo(*args)
+ @tree.element_configinfo(@id, *args)
+ end
+
+ def current_configinfo(*args)
+ @tree.current_element_configinfo(@id, *args)
+ end
+
+ def delete
+ @tree.element_delete(@id)
+ self
+ end
+
+ def element_type
+ @tree.element_type(@id)
+ end
+
+ def element_class
+ @tree.element_class(@id)
+ end
+end
+
+class Tk::TreeCtrl::BitmapElement < Tk::TreeCtrl::Element
+ TreeCtrlElemTypeToClass['bitmap'] = self
+
+ def initialize(parent, keys=nil)
+ super(parent, 'bitmap', keys)
+ end
+end
+
+class Tk::TreeCtrl::BorderElement < Tk::TreeCtrl::Element
+ TreeCtrlElemTypeToClass['border'] = self
+
+ def initialize(parent, keys=nil)
+ super(parent, 'border', keys)
+ end
+end
+
+class Tk::TreeCtrl::ImageElement < Tk::TreeCtrl::Element
+ TreeCtrlElemTypeToClass['image'] = self
+
+ def initialize(parent, keys=nil)
+ super(parent, 'image', keys)
+ end
+end
+
+class Tk::TreeCtrl::RectangleElement < Tk::TreeCtrl::Element
+ TreeCtrlElemTypeToClass['rect'] = self
+
+ def initialize(parent, keys=nil)
+ super(parent, 'rect', keys)
+ end
+end
+
+#####################
+
+class Tk::TreeCtrl::Item < TkObject
+ TreeCtrlItemID_TBL = TkCore::INTERP.create_table
+
+ TkCore::INTERP.init_ip_env{Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.clear}
+
+ def self.id2obj(tree, id)
+ tpath = tree.path
+ return id unless Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath]
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id] : id
+ end
+
+ def initialize(parent, keys={})
+ @tree = parent
+ @tpath = parent.path
+ @path = @id = @tree.item_create(keys)
+
+ unless Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath]
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath][@id] = self
+ end
+
+ def id
+ @id
+ end
+
+ def to_s
+ @id.to_s.dup
+ end
+
+ def ancestors
+ @tree.item_ancestors(@id)
+ end
+
+ def bbox(*args)
+ @tree.item_bbox(@id, *args)
+ end
+
+ def children
+ @tree.item_children(@id)
+ end
+
+ def collapse
+ @tree.item_collapse(@id)
+ self
+ end
+
+ def collapse_recurse
+ @tree.item_collapse_recurse(@id)
+ self
+ end
+
+ def complex(*args)
+ @tree.item_complex(@id, *args)
+ self
+ end
+
+ def cget(opt)
+ @tree.item_cget(@id, opt)
+ end
+
+ def configure(*args)
+ @tree.item_configure(@id, *args)
+ end
+
+ def configinfo(*args)
+ @tree.item_configinfo(@id, *args)
+ end
+
+ def current_configinfo(*args)
+ @tree.current_item_configinfo(@id, *args)
+ end
+
+ def delete
+ @tree.item_delete(@id)
+ self
+ end
+
+ def element_dump
+ @tree.item_dump(@id)
+ end
+
+ def element_dump_hash
+ @tree.item_dump_hash(@id)
+ end
+
+ def element_actual(column, elem, key)
+ @tree.item_element_actual(@id, column, elem, key)
+ end
+
+ def element_cget(opt)
+ @tree.item_element_cget(@id, opt)
+ end
+
+ def element_configure(*args)
+ @tree.item_element_configure(@id, *args)
+ end
+
+ def element_configinfo(*args)
+ @tree.item_element_configinfo(@id, *args)
+ end
+
+ def current_element_configinfo(*args)
+ @tree.current_item_element_configinfo(@id, *args)
+ end
+
+ def expand
+ @tree.item_expand(@id)
+ self
+ end
+
+ def expand_recurse
+ @tree.item_expand_recurse(@id)
+ self
+ end
+
+ def firstchild(child=nil)
+ if child
+ @tree.item_firstchild(@id, child)
+ self
+ else
+ @tree.item_firstchild(@id)
+ end
+ end
+ alias first_child firstchild
+
+ def hashbutton(st=None)
+ if st == None
+ @tree.item_hashbutton(@id)
+ else
+ @tree.item_hashbutton(@id, st)
+ self
+ end
+ end
+
+ def hashbutton?
+ @tree.item_hashbutton(@id)
+ end
+
+ def index
+ @tree.item_index(@id)
+ end
+
+ def isancestor(des)
+ @tree.item_isancestor(@id, des)
+ end
+ alias is_ancestor isancestor
+ alias isancestor? isancestor
+ alias is_ancestor? isancestor
+ alias ancestor? isancestor
+
+ def isopen
+ @tree.item_isopen(@id)
+ end
+ alias is_open isopen
+ alias isopen? isopen
+ alias is_open? isopen
+ alias isopened? isopen
+ alias is_opened? isopen
+ alias open? isopen
+
+ def lastchild(child=nil)
+ if child
+ @tree.item_lastchild(@id, child)
+ self
+ else
+ @tree.item_lastchild(@id)
+ end
+ end
+ alias last_child lastchild
+
+ def nextsibling(nxt=nil)
+ if nxt
+ @tree.item_nextsibling(@id, nxt)
+ self
+ else
+ @tree.item_nextsibling(@id)
+ end
+ end
+ alias next_sibling nextsibling
+
+ def numchildren
+ @tree.item_numchildren(@id)
+ end
+ alias num_children numchildren
+ alias children_size numchildren
+
+ def parent_index
+ @tree.item_parent(@id)
+ end
+
+ def prevsibling(nxt=nil)
+ if nxt
+ @tree.item_prevsibling(@id, nxt)
+ self
+ else
+ @tree.item_prevsibling(@id)
+ end
+ end
+ alias prev_sibling prevsibling
+
+ def remove
+ @tree.item_remove(@id)
+ end
+
+ def rnc
+ @tree.item_rnc(@id)
+ end
+
+ def sort(*opts)
+ @tree.item_sort(@id, *opts)
+ end
+
+ def state_forcolumn(column, *args)
+ @tree.item_state_forcolumn(@id, column, *args)
+ self
+ end
+ alias state_for_column state_forcolumn
+
+ def state_get(*args)
+ @tree.item_state_get(@id, *args)
+ end
+
+ def state_set(*args)
+ @tree.item_state_set(@id, *args)
+ self
+ end
+
+ def style_elements(column)
+ @tree.item_style_elements(@id, column)
+ end
+
+ def style_map(column, style, map)
+ @tree.item_style_map(@id, column, style, map)
+ self
+ end
+
+ def style_set(column=nil, *args)
+ if args.empty?
+ @tree.item_style_set(@id, column)
+ else
+ @tree.item_style_set(@id, column, *args)
+ self
+ end
+ end
+
+ def item_text(column, txt=nil, *args)
+ if args.empty?
+ if txt
+ @tree.item_text(@id, column, txt)
+ self
+ else
+ @tree.item_text(@id, column)
+ end
+ else
+ @tree.item_text(@id, column, txt, *args)
+ self
+ end
+ end
+
+ def toggle
+ @tree.item_toggle(@id)
+ self
+ end
+
+ def toggle_recurse
+ @tree.item_toggle_recurse(@id)
+ self
+ end
+
+ def visible(st=None)
+ if st == None
+ @tree.item_visible(@id)
+ else
+ @tree.item_visible(@id, st)
+ self
+ end
+ end
+end
+
+#####################
+
+class Tk::TreeCtrl::Style < TkObject
+ TreeCtrlStyleID_TBL = TkCore::INTERP.create_table
+ TreeCtrlStyleID = ['treectrl_style'.freeze, '00000'.taint].freeze
+
+ TkCore::INTERP.init_ip_env{ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.clear }
+
+ def self.id2obj(tree, id)
+ tpath = tree.path
+ return id unless Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath]
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id]? \
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id] : id
+ end
+
+ def initialize(parent, keys=nil)
+ @tree = parent
+ @tpath = parent.path
+ @path = @id =
+ Tk::TreeCtrl::Style::TreeCtrlStyleID.join(TkCore::INTERP._ip_id_)
+ unless Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath]
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath] = {}
+ end
+ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath][@id] = self
+ Tk::TreeCtrl::Style::TreeCtrlStyleID[1].succ!
+
+ @tree.style_create(@id, keys)
+ end
+
+ def id
+ @id
+ end
+
+ def to_s
+ @id.dup
+ end
+
+ def cget(opt)
+ @tree.style_cget(@id, opt)
+ end
+
+ def configure(*args)
+ @tree.style_configure(@id, *args)
+ end
+
+ def configinfo(*args)
+ @tree.style_configinfo(@id, *args)
+ end
+
+ def current_configinfo(*args)
+ @tree.current_style_configinfo(@id, *args)
+ end
+
+ def delete
+ @tree.style_delete(@id)
+ self
+ end
+
+ def elements(*elems)
+ if elems.empty?
+ @tree.style_elements(@id)
+ else
+ @tree.style_elements(@id, *elems)
+ self
+ end
+ end
+
+ def layout(elem, keys=None)
+ if keys && keys != None && keys.kind_of?(Hash)
+ @tree.style_layout(@id, elem, keys)
+ self
+ else
+ @tree.style_layout(@id, elem, keys)
+ end
+ end
+end