1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/treectrl/tktreectrl.rb: performance tuning. (call tk_send_without_enc

if possible)

* sample/tkextlib/treectrl/*.rb: some speed up... cache the result of
  version checking.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@8265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ocean 2005-04-07 14:55:55 +00:00
parent 9961c29c25
commit 138b4c427c
11 changed files with 110 additions and 76 deletions

View file

@ -1,3 +1,13 @@
2005-04-07 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* lib/treectrl/tktreectrl.rb: performance tuning. (call tk_send_without_enc
if possible)
2005-04-07 ocean <ocean@ruby-lang.org>
* sample/tkextlib/treectrl/*.rb: some speed up... cache the result of
version checking.
2005-04-04 ocean <ocean@ruby-lang.org>
* lib/tkextlib/tktable/tktable.rb: added Tk::TkTable#selection_present.

View file

@ -554,12 +554,13 @@ class Tk::TreeCtrl
end
def collapse(*dsc)
tk_send('collapse', *dsc)
tk_send_without_enc('collapse', *(dsc.map!{|d| _get_eval_string(d, true)}))
self
end
def collapse_recurse(*dsc)
tk_send('collapse', '-recurse', *dsc)
tk_send_without_enc('collapse', '-recurse',
*(dsc.map!{|d| _get_eval_string(d, true)}))
self
end
@ -610,7 +611,7 @@ class Tk::TreeCtrl
end
def depth(item=None)
num_or_str(tk_send('depth', item))
num_or_str(tk_send_without_enc('depth', _get_eval_string(item, true)))
end
def dragimage_add(item, *args)
@ -750,22 +751,25 @@ class Tk::TreeCtrl
end
def item_collapse(item)
tk_send('item', 'collapse', item)
tk_send_without_enc('item', 'collapse', _get_eval_string(item, true))
self
end
def item_collapse_recurse(item)
tk_send('item', 'collapse', item, '-recurse')
tk_send_without_enc('item', 'collapse',
_get_eval_string(item, true), '-recurse')
self
end
def item_complex(item, *args)
tk_send('item', 'complex', item, *args)
tk_send_without_enc('item', 'complex',
_get_eval_string(item, true),
*(args.map!{|arg| _get_eval_string(arg, true)}))
self
end
def item_create(keys={})
num_or_str(tk_send('item', 'create', keys))
num_or_str(tk_send_without_enc('item', 'create', *hash_kv(keys, true)))
end
def _erase_children(item)
@ -814,10 +818,13 @@ class Tk::TreeCtrl
def item_firstchild(parent, child=nil)
if child
tk_send('item', 'firstchild', parent, child)
tk_send_without_enc('item', 'firstchild',
_get_eval_string(parent, true),
_get_eval_string(child, true))
self
else
id = num_or_str(tk_send('item', 'firstchild', parent))
id = num_or_str(tk_send_without_enc('item', 'firstchild',
_get_eval_string(parent, true)))
Tk::TreeCtrl::Item.id2obj(self, id)
end
end
@ -825,9 +832,12 @@ class Tk::TreeCtrl
def item_hasbutton(item, st=None)
if st == None
bool(tk_send('item', 'hasbutton'))
bool(tk_send_without_enc('item', 'hasbutton',
_get_eval_string(item, true)))
else
tk_send('item', 'hasbutton', st)
tk_send_without_enc('item', 'hasbutton',
_get_eval_string(item, true),
_get_eval_string(st))
self
end
end
@ -860,10 +870,13 @@ class Tk::TreeCtrl
def item_lastchild(parent, child=nil)
if child
tk_send('item', 'lastchild', parent, child)
tk_send_without_enc('item', 'lastchild',
_get_eval_string(parent, true),
_get_eval_string(child, true))
self
else
id = num_or_str(tk_send('item', 'lastchild', parent))
id = num_or_str(tk_send_without_enc('item', 'lastchild',
_get_eval_string(parent, true)))
Tk::TreeCtrl::Item.id2obj(self, id)
end
end
@ -881,7 +894,8 @@ class Tk::TreeCtrl
alias item_next_sibling item_nextsibling
def item_numchildren(item)
number(tk_send('item', 'numchildren', item))
number(tk_send_without_enc('item', 'numchildren',
_get_eval_string(item, true)))
end
alias item_num_children item_numchildren
alias item_children_size item_numchildren
@ -1005,15 +1019,23 @@ class Tk::TreeCtrl
def item_style_set(item, column=nil, *args)
if args.empty?
if column
id = tk_send('item', 'style', 'set', item, column)
id = tk_send_without_enc('item', 'style', 'set',
_get_eval_string(item, true),
_get_eval_string(column, true))
Tk::TreeCtrl::Style.id2obj(self, id)
else
list(tk_send('item', 'style', 'set', item)).collect!{|id|
list(tk_send_without_enc('item', 'style', 'set',
_get_eval_string(item, true))).collect!{|id|
Tk::TreeCtrl::Style.id2obj(self, id)
}
end
else
tk_send('item', 'style', 'set', item, column, *(args.flatten))
tk_send_without_enc('item', 'style', 'set',
_get_eval_string(item, true),
_get_eval_string(column, true),
*(args.flatten.map!{|arg|
_get_eval_string(arg, true)
}))
self
end
end

View file

@ -2,7 +2,7 @@
# Demo: Bitmaps
#
def demoBitmaps(t)
#if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
#if $Version_1_1_OrLater
if @has_bgimg
t.configure(:showroot=>false, :showbuttons=>false, :showlines=>false,
:selectmode=>:browse, :orient=>:horizontal, :wrap=>'5 items',
@ -38,7 +38,7 @@ def demoBitmaps(t)
t.style_layout(s, 'elemTxt', :expand=>:we)
# Set default item style
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.defaultstyle = [s]
end
@ -47,7 +47,7 @@ def demoBitmaps(t)
bitmap_names.each{|name|
i = t.item_create
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_style_set(i, 0, s)
end
t.item_text(i, 0, name)

View file

@ -7,6 +7,8 @@ $ScriptDir = File.dirname(File.expand_path(__FILE__))
$HasColumnCreate = Tk::TreeCtrl::HasColumnCreateCommand
$Version_1_1_OrLater = (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if Hash.instance_methods.include?('key')
# probably ruby 1.9.x --> use Hash#key
# Because Hash#index show warning "Hash#index is deprecated; use Hash#key".
@ -53,7 +55,7 @@ class TkTreeCtrl_demo
make_menubar()
make_main_window()
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
begin
@tree2[:backgroundimage]
@has_bgimg = true
@ -351,7 +353,7 @@ class TkTreeCtrl_demo
[ 'Expand', [], nil, '', {:menu_config=>{:tearoff=>false}} ]
]
# if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
# if $Version_1_1_OrLater
if @has_bgimg
menuspec << \
[ 'Background Image',
@ -503,7 +505,7 @@ class TkTreeCtrl_demo
m = @mTree[w].entrycget('Collapse', :menu)
m.delete(0, :end)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
m.add_command(:label=>'All', :command=>proc{w.item_collapse(:all)})
else
m.add_command(:label=>'All', :command=>proc{w.collapse(:all)})
@ -511,7 +513,7 @@ class TkTreeCtrl_demo
unless id.empty?
if id[0] == 'item'
item = id[1]
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
m.add_command(:label=>"Item #{item}",
:command=>proc{w.item_collapse(item)})
m.add_command(:label=>"Item #{item} (recurse)",
@ -527,7 +529,7 @@ class TkTreeCtrl_demo
m = @mTree[w].entrycget('Expand', :menu)
m.delete(0, :end)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
m.add_command(:label=>'All', :command=>proc{w.item_expand(:all)})
else
m.add_command(:label=>'All', :command=>proc{w.expand(:all)})
@ -535,7 +537,7 @@ class TkTreeCtrl_demo
unless id.empty?
if id[0] == 'item'
item = id[1]
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
m.add_command(:label=>"Item #{item}",
:command=>proc{w.item_expand(item)})
m.add_command(:label=>"Item #{item} (recurse)",
@ -552,7 +554,7 @@ class TkTreeCtrl_demo
[:data, :display, :enable].each{|k|
@popup[:debug][k].value = w.debug_cget(k)
}
# if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
# if $Version_1_1_OrLater
if @has_bgimg
@popup[:bgimg].value = @images.key(w[:backgroundimage])
end
@ -803,7 +805,7 @@ class TkTreeCtrl_demo
@tree1.style_layout('s1', 'e2', :union=>['e1'],
:ipadx=>2, :ipady=>[0, 1], :iexpand=>:e)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
@tree1.defaultstyle = 's1'
end
@ -826,7 +828,7 @@ class TkTreeCtrl_demo
].each{|label, cmd, file|
item = @tree1.item_create
@tree1.item_lastchild(:root, item)
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
@tree1.item_style_set(item, 0, 's1')
end
@tree1.item_text(item, 0, label)
@ -883,7 +885,7 @@ class TkTreeCtrl_demo
# One item for each element in the demo list
@tree2.element_names.sort.each{|elem|
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
item = @tree4.item_create(:button=>true)
@tree4.item_collapse(item)
else
@ -920,7 +922,7 @@ class TkTreeCtrl_demo
# One item for each style in the demo list
@tree2.style_names.sort.each{|sty|
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
item = @tree4.item_create(:button=>true)
@tree4.item_collapse(item)
else
@ -933,7 +935,7 @@ class TkTreeCtrl_demo
# One item for each element in the style
@tree2.style_elements(sty).each{|elem|
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
item2 = @tree4.item_create(:button=>true)
@tree4.item_collapse(item2)
else
@ -948,7 +950,7 @@ class TkTreeCtrl_demo
# One item for each layout option for this element in this style
@tree2.style_layout(sty, elem).each{|k, v|
item3 = @tree4.item_create
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
@tree4.item_hasbutton(item3, false)
end
@tree4.item_style_set(item3, 0, 's1')
@ -1002,7 +1004,7 @@ class TkTreeCtrl_demo
column = 0
@tree2.item_style_set(item).each{|sty|
item2 = @tree3.item_create
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
@tree3.item_collapse(item2)
else
@tree3.collapse(item2)
@ -1017,13 +1019,13 @@ class TkTreeCtrl_demo
unless sty.to_s.empty?
@tree2.item_style_elements(item, column).each{|elem|
button = true
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
item3 = @tree3.item_create(:button=>true)
else
item3 = @tree3.item_create
@tree3.item_hasbutton(item3, true)
end
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
@tree3.item_collapse(item3)
else
@tree3.collapse(item3)
@ -1060,7 +1062,7 @@ class TkTreeCtrl_demo
}
@tree3.item_lastchild(item2, item3)
}
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
@tree3.item_configure(item2, :button=>true) if button
else
@tree3.item_hasbutton(item2, true) if button
@ -1101,7 +1103,7 @@ class TkTreeCtrl_demo
# Delete all elements in demo list
@tree2.element_delete(*(@tree2.element_names))
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
@tree2.item_configure(:root, :button=>false)
@tree2.item_expand(:root)
else
@ -1110,7 +1112,7 @@ class TkTreeCtrl_demo
end
# Restore some happy defaults to the demo list
# if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
# if $Version_1_1_OrLater
if @has_bgimg
@tree2.configure(:orient=>:vertical, :wrap=>'',
:xscrollincrement=>0, :yscrollincrement=>0,

View file

@ -9,7 +9,7 @@ def demoHelpContents(t)
init_pics('help-*')
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.column_create(:text=>'Help Contents')
else # TreeCtrl 1.0
t.column_configure(0, :text=>'Help Contents')
@ -69,7 +69,7 @@ def demoHelpContents(t)
item = t.item_create
t.item_style_set(item, 0, style)
t.item_element_configure(item, 0, 'e3', :text=>text)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_collapse(item)
else # TreeCtrl 1.0
t.collapse(item)
@ -147,7 +147,7 @@ def demoHelpContents2(t)
init_pics('help-*')
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.column_create(:text=>'Help Contents')
else # TreeCtrl 1.0
t.column_configure(0, :text=>'Help Contents')
@ -222,7 +222,7 @@ def demoHelpContents2(t)
item = t.item_create
t.item_style_set(item, 0, style)
t.item_element_configure(item, 0, 'e3', :text=>text)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_collapse(item)
else # TreeCtrl 1.0
t.collapse(item)
@ -301,13 +301,13 @@ def helpButton1(w, x, y)
end
if w.selection_get.length > 0
item2 = w.selection_get[0]
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
w.item_collapse(item2)
else # TreeCtrl 1.0
w.collapse(item2)
end
w.item_ancestors(item2).each{|i|
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
w.item_collapse(i) if w.compare(item, '!=', i)
else # TreeCtrl 1.0
w.collapse(i) if w.compare(item, '!=', i)
@ -315,7 +315,7 @@ def helpButton1(w, x, y)
}
end
w.activate(item)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
w.item_ancestors(item).each{|i|
w.item_expand(i)
}

View file

@ -47,7 +47,7 @@ def demoIMovie(t)
:ipadx=>6, :padx=>[0,3], :pady=>[0,3])
# Set default item style
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.defaultstyle([s])
end
@ -62,7 +62,7 @@ def demoIMovie(t)
['07:20', 'Clip 7', @images['imovie-07']]
].each{|time, name, image|
item = t.item_create
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_style_set(item, 0, s)
end
t.item_element_configure(item, 0, 'elemTime', :text=>time)

View file

@ -36,7 +36,7 @@ def demoLayout(t)
t.style_layout(s, 'e7', :detach=>true, :expand=>:wn,
:padx=>[0,2], :pady=>[0,2])
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
i = t.item_create(:button=>true)
else
i = t.item_create
@ -47,7 +47,7 @@ def demoLayout(t)
parent = i
i = t.item_create()
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_hasbutton(i, false)
end
t.item_style_set(i, 0, s)
@ -61,7 +61,7 @@ def demoLayout(t)
t.style_layout(s, 'e3', :union=>['e1'], :ipadx=>[20,4], :ipady=>[4,12])
t.style_layout(s, 'e4', :detach=>true, :iexpand=>:es)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
i = t.item_create(:button=>true)
else
i = t.item_create
@ -71,7 +71,7 @@ def demoLayout(t)
t.item_lastchild(:root, i)
i2 = t.item_create()
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_hasbutton(i2, false)
end
t.item_style_set(i2, 0, s)
@ -85,7 +85,7 @@ def demoLayout(t)
t.style_layout(s, 'e3', :union=>['e1', 'e5'], :ipadx=>4, :ipady=>4)
t.style_layout(s, 'e5', :ipady=>[0,20])
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
i = t.item_create(:button=>true)
else
i = t.item_create
@ -95,7 +95,7 @@ def demoLayout(t)
t.item_lastchild(:root, i)
i2 = t.item_create()
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_hasbutton(i2, false)
end
t.item_style_set(i2, 0, s)
@ -115,7 +115,7 @@ def demoLayout(t)
t.style_layout(s, 'eb', :union=>['et'], :ipadx=>2, :ipady=>2)
t.style_layout(s, 'et', :squeeze=>:x)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
i = t.item_create(:button=>true)
else
i = t.item_create
@ -127,7 +127,7 @@ def demoLayout(t)
parent = i
i = t.item_create()
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_hasbutton(i, false)
end
t.item_style_set(i, 0, s)

View file

@ -13,7 +13,7 @@ def demoMailWasher(t)
pad = 4
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.column_create(:text=>'Delete', :textpadx=>pad, :tag=>'delete')
t.column_create(:text=>'Bounce', :textpadx=>pad, :tag=>'bounce')
t.column_create(:text=>'Status', :width=>80, :textpadx=>pad,
@ -70,7 +70,7 @@ def demoMailWasher(t)
t.element_create('txtBlacklist', :text, :text=>'Blacklisted', :lines=>1,
:fill=>[@SystemHighlightText, ['selected'], '#FF5800', []])
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
s = t.style_create('styCheck')
t.style_elements(s, ['border', 'imgCheck'])
t.style_layout(s, 'border', :detach=>true, :iexpand=>:es)
@ -112,7 +112,7 @@ def demoMailWasher(t)
status = ['styNormal','styPossSpam','styProbSpam','styBlacklist'][rand(4)]
attachments = ['styNone','styYes'][rand(2)]
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
delete = [false, true][rand(2)]
bounce = [false, true][rand(2)]
t.item_style_set(item,
@ -197,7 +197,7 @@ def demoMailWasher(t)
mailWasher = TkBindTag.new
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
mailWasher.bind('ButtonPress-1',
proc{|w, x, y|
id = w.identify(x, y)
@ -241,7 +241,7 @@ def demoMailWasher(t)
t.bindtags = [t, mailWasher, Tk::TreeCtrl, t.winfo_toplevel, TkBindTag::ALL]
end
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
def compareOnOff(w, c, item1, item2)
s1 = w.item_state_forcolumn(item1, c)
s2 = w.item_state_forcolumn(item2, c)

View file

@ -84,7 +84,7 @@ def demoOutlookFolders(t)
[0, :server, "news.gmane.org", true, 0],
[1, :group, "gmane.comp.lang.lua.general", false, 498]
].each{|depth, img, text, button, unread|
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
item = t.item_create(:button=>button)
else
item = t.item_create

View file

@ -9,7 +9,7 @@ def demoOutlookNewsgroup(t)
t.configure(:itemheight=>height, :selectmode=>:browse, :showlines=>false,
:showroot=>false, :showrootbutton=>false, :showbuttons=>true)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.column_create(:image=>@images['outlook-clip'], :tag=>'clip')
t.column_create(:image=>@images['outlook-arrow'], :tag=>'arrow')
t.column_create(:image=>@images['outlook-watch'], :tag=>'watch')
@ -90,7 +90,7 @@ def demoOutlookNewsgroup(t)
t.style_layout(s, 'sel.w', :detach=>true, :iexpand=>:es)
# Set default item style
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.defaultstyle = ['', '', '', 's1', 's2.we', 's2.we', 's2.w']
end
@ -147,21 +147,21 @@ def demoOutlookNewsgroup(t)
t.item_state_set(item_i, 'unread') if anyUnreadDescendants(t, item_i)
if t.item_numchildren(item_i) > 0
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_configure(item_i, :button=>true)
else # TreeCtrl 1.0
t.item_hasbutton(item_i, true)
end
# Collapse some messages
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_collapse(item_i) if rand(2) == 0
else # TreeCtrl 1.0
t.collapse(item_i) if rand(2) == 0
end
end
unless (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
unless $Version_1_1_OrLater
t.item_style_set(item_i, 3, 's1', 4, 's2.we', 5, 's2.we', 6, 's2.w')
end
t.item_text(item_i, 3, subject, 4, from, 5, sent, 6, size)
@ -211,7 +211,7 @@ def demoOutlookNewsgroup2(t)
t.configure(:itemheight=>height, :selectmode=>:browse, :showlines=>false,
:showroot=>false, :showrootbutton=>false, :showbuttons=>true)
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.column_create(:image=>@images['outlook-clip'], :tag=>'clip')
t.column_create(:image=>@images['outlook-arrow'], :tag=>'arrow')
t.column_create(:image=>@images['outlook-watch'], :tag=>'watch')
@ -421,7 +421,7 @@ def demoOutlookNewsgroup2(t)
(1...(msgCnt)).each{|i|
if rand(2) == 0
if t.item_numchildren(i) > 0
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_collapse(i)
else # TreeCtrl 1.0
t.collapse(i)

View file

@ -16,7 +16,7 @@ def demoRandom(t)
:showlines=>true, :scrollmargin=>16,
:xscrolldelay=>[500, 50], :yscrolldelay=>[500, 50])
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.column_create(:expand=>true, :text=>'Item',
:itembackground=>['#e0e8f0', []], :tag=>'item')
t.column_create(:text=>'Parent', :justify=>:center,
@ -83,7 +83,7 @@ def demoRandom(t)
item_j = items[j]
break if t.depth(item_j) < 5
}
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_collapse(item_i) if rand(2) == 0
else # TreeCtrl 1.0
t.collapse(item_i) if rand(2) == 0
@ -103,7 +103,7 @@ def demoRandom(t)
item_j = nil
numChildren = t.item_numchildren(item_i)
if numChildren > 0
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_configure(item_i, :button=>true)
else # TreeCtrl 1.0
t.item_hasbutton(item_i, true)
@ -191,14 +191,14 @@ def randomButton1(t, x, y)
where, item, arg1, arg2, arg3, arg4 = id
case arg1
when 'button'
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_toggle(item)
else # TreeCtrl 1.0
t.toggle(item)
end
when 'line'
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_toggle(arg2)
else # TreeCtrl 1.0
t.toggle(arg2)
@ -423,7 +423,7 @@ def randomDrop(t, target, src, pos)
parentList.each{|item|
numChildren = t.item_numchildren(item)
if numChildren == 0
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_configure(item, :button=>false)
else # TreeCtrl 1.0
t.item_hasbutton(item, false)
@ -436,7 +436,7 @@ def randomDrop(t, target, src, pos)
# Update the target that gained some children
if t.item_style_set(parent, 0) != 's1'
if (TkPackage.vcompare(Tk::TreeCtrl.package_version, '1.1') >= 0)
if $Version_1_1_OrLater
t.item_configure(parent, :button=>true)
else # TreeCtrl 1.0
t.item_hasbutton(parent, true)