3 # by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
6 require 'tkextlib/tile.rb'
10 class Treeview < TkWindow
15 Tk.__set_toplevel_aliases__(:Ttk, Tk::Tile::Treeview, :TkTreeview)
18 module Tk::Tile::TreeviewConfig
19 include TkItemConfigMethod
21 def __item_configinfo_struct(id)
22 # maybe need to override
23 {:key=>0, :alias=>nil, :db_name=>nil, :db_class=>nil,
24 :default_value=>nil, :current_value=>1}
26 private :__item_configinfo_struct
28 def __itemconfiginfo_core(tagOrId, slot = nil)
29 if TkComm::GET_CONFIGINFO_AS_ARRAY
30 if (slot && slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/)
32 return [slot.to_s, tagfontobj(tagid(tagOrId), fontkey)]
37 alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
43 when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/
45 # On tile-0.7.{2-8}, 'state' options has no '-' at its head.
46 val = tk_call(*(__item_confinfo_cmd(tagid(tagOrId)) << slot))
48 # Maybe, 'state' option has '-' in future.
49 val = tk_call(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
53 when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
54 method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
55 optval = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
57 val = method.call(tagOrId, optval)
59 warn("Warning:: #{e.message} (when #{method}lcall(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
64 when /^(#{__item_methodcall_optkeys(tagid(tagOrId)).keys.join('|')})$/
65 method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot]
66 return [slot, self.__send__(method, tagOrId)]
68 when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
70 val = number(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
76 when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
77 val = num_or_str(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
80 when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
82 val = bool(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
88 when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
89 val = simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
92 when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
93 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
95 return [slot, list(val)]
100 when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
101 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
104 when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
105 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
109 return [slot, TkVarAccess.new(val)]
113 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
115 return [slot, tk_split_list(val)]
117 return [slot, tk_tcl2ruby(val)]
122 ret = Hash[*(tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)))), false, false))].to_a.collect{|conf|
123 conf[0] = conf[0][1..-1] if conf[0][0] == ?-
125 when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
126 method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[conf[0]]
129 val = method.call(tagOrId, optval)
131 warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
136 when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
139 when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
141 conf[1] = number(conf[1])
146 when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
147 conf[1] = num_or_str(conf[1])
149 when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
151 conf[1] = bool(conf[1])
156 when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
157 conf[1] = simplelist(conf[1])
159 when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
160 if conf[1] =~ /^[0-9]/
161 conf[1] = list(conf[1])
164 when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
168 conf[1] = TkVarAccess.new(conf[1])
172 if conf[1].index('{')
173 conf[1] = tk_split_list(conf[1])
175 conf[1] = tk_tcl2ruby(conf[1])
182 __item_font_optkeys(tagid(tagOrId)).each{|optkey|
184 fontconf = ret.assoc(optkey)
186 ret.delete_if{|inf| inf[0] =~ /^(|latin|ascii|kanji)#{optkey}$/}
187 fontconf[1] = tagfontobj(tagid(tagOrId), optkey)
192 __item_methodcall_optkeys(tagid(tagOrId)).each{|optkey, method|
193 ret << [optkey.to_s, self.__send__(method, tagOrId)]
200 else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
201 if (slot && slot.to_s =~ /^(|latin|ascii|kanji)(#{__item_font_optkeys(tagid(tagOrId)).join('|')})$/)
203 return {slot.to_s => tagfontobj(tagid(tagOrId), fontkey)}
208 alias_name, real_name = __item_optkey_aliases(tagid(tagOrId)).find{|k, v| k.to_s == slot}
210 slot = real_name.to_s
214 when /^(#{__tile_specific_item_optkeys(tagid(tagOrId)).join('|')})$/
216 # On tile-0.7.{2-8}, 'state' option has no '-' at its head.
217 val = tk_call(*(__item_confinfo_cmd(tagid(tagOrId)) << slot))
219 # Maybe, 'state' option has '-' in future.
220 val = tk_call(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
224 when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
225 method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[slot]
226 optval = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
228 val = method.call(tagOrId, optval)
230 warn("Warning:: #{e.message} (when #{method}lcall(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
235 when /^(#{__item_methodcall_optkeys(tagid(tagOrId)).keys.join('|')})$/
236 method = _symbolkey2str(__item_methodcall_optkeys(tagid(tagOrId)))[slot]
237 return {slot => self.__send__(method, tagOrId)}
239 when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
241 val = number(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
247 when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
248 val = num_or_str(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
251 when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
253 val = bool(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
259 when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
260 val = simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}")))
263 when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
264 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
266 return {slot => list(val)}
271 when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
272 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
275 when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
276 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
280 return {slot => TkVarAccess.new(val)}
284 val = tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)) << "-#{slot}"))
286 return {slot => tk_split_list(val)}
288 return {slot => tk_tcl2ruby(val)}
294 ret = Hash[*(tk_split_simplelist(tk_call_without_enc(*(__item_confinfo_cmd(tagid(tagOrId)))), false, false))].to_a.collect{|conf|
295 conf[0] = conf[0][1..-1] if conf[0][0] == ?-
299 when /^(#{__item_val2ruby_optkeys(tagid(tagOrId)).keys.join('|')})$/
300 method = _symbolkey2str(__item_val2ruby_optkeys(tagid(tagOrId)))[optkey]
303 val = method.call(tagOrId, optval)
305 warn("Warning:: #{e.message} (when #{method}.call(#{tagOrId.inspect}, #{optval.inspect})") if $DEBUG
310 when /^(#{__item_strval_optkeys(tagid(tagOrId)).join('|')})$/
313 when /^(#{__item_numval_optkeys(tagid(tagOrId)).join('|')})$/
315 conf[1] = number(conf[1])
320 when /^(#{__item_numstrval_optkeys(tagid(tagOrId)).join('|')})$/
321 conf[1] = num_or_str(conf[1])
323 when /^(#{__item_boolval_optkeys(tagid(tagOrId)).join('|')})$/
325 conf[1] = bool(conf[1])
330 when /^(#{__item_listval_optkeys(tagid(tagOrId)).join('|')})$/
331 conf[1] = simplelist(conf[1])
333 when /^(#{__item_numlistval_optkeys(tagid(tagOrId)).join('|')})$/
334 if conf[1] =~ /^[0-9]/
335 conf[1] = list(conf[1])
338 when /^(#{__item_tkvariable_optkeys(tagid(tagOrId)).join('|')})$/
342 conf[1] = TkVarAccess.new(conf[1])
346 if conf[1].index('{')
347 return [slot, tk_split_list(conf[1])]
349 return [slot, tk_tcl2ruby(conf[1])]
353 ret[conf[0]] = conf[1]
356 __item_font_optkeys(tagid(tagOrId)).each{|optkey|
358 fontconf = ret[optkey]
359 if fontconf.kind_of?(Array)
361 ret.delete('latin' << optkey)
362 ret.delete('ascii' << optkey)
363 ret.delete('kanji' << optkey)
364 fontconf[1] = tagfontobj(tagid(tagOrId), optkey)
365 ret[optkey] = fontconf
369 __item_methodcall_optkeys(tagid(tagOrId)).each{|optkey, method|
370 ret[optkey.to_s] = self.__send__(method, tagOrId)
381 def __item_cget_cmd(id)
384 private :__item_cget_cmd
386 def __item_config_cmd(id)
389 private :__item_config_cmd
391 def __item_numstrval_optkeys(id)
395 when :column, 'column'
396 super(id[1]) + ['minwidth']
399 when :heading, 'heading'
405 private :__item_numstrval_optkeys
407 def __item_strval_optkeys(id)
411 when :column, 'column'
415 when :heading, 'heading'
421 private :__item_strval_optkeys
423 def __item_boolval_optkeys(id)
427 when :column, 'column'
428 super(id[1]) + ['stretch']
431 when :heading, 'heading'
435 private :__item_boolval_optkeys
437 def __item_listval_optkeys(id)
441 when :column, 'column'
443 when :heading, 'heading'
449 private :__item_listval_optkeys
451 def __item_val2ruby_optkeys(id)
455 'tags'=>proc{|arg_id, val|
456 simplelist(val).collect{|tag|
457 Tk::Tile::Treeview::Tag.id2obj(self, tag)
461 when :column, 'column'
463 when :heading, 'heading'
469 private :__item_val2ruby_optkeys
471 def __tile_specific_item_optkeys(id)
475 when :column, 'column'
477 when :heading, 'heading'
478 ['state'] # On tile-0.7.{2-8}, 'state' options has no '-' at its head.
483 private :__item_val2ruby_optkeys
485 def itemconfiginfo(tagOrId, slot = nil)
486 __itemconfiginfo_core(tagOrId, slot)
489 def current_itemconfiginfo(tagOrId, slot = nil)
490 if TkComm::GET_CONFIGINFO_AS_ARRAY
494 conf = __itemconfiginfo_core(tagOrId, slot)
495 if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
496 || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
497 return {conf[0] => conf[-1]}
499 slot = conf[__item_configinfo_struct(tagid(tagOrId))[:alias]]
500 end while(org_slot != slot)
502 "there is a configure alias loop about '#{org_slot}'"
505 __itemconfiginfo_core(tagOrId).each{|conf|
506 if ( ! __item_configinfo_struct(tagid(tagOrId))[:alias] \
507 || conf.size > __item_configinfo_struct(tagid(tagOrId))[:alias] + 1 )
508 ret[conf[0]] = conf[-1]
513 else # ! TkComm::GET_CONFIGINFO_AS_ARRAY
515 __itemconfiginfo_core(tagOrId, slot).each{|key, conf|
516 ret[key] = conf[-1] if conf.kind_of?(Array)
522 alias __itemcget itemcget
523 alias __itemcget_strict itemcget_strict
524 alias __itemconfigure itemconfigure
525 alias __itemconfiginfo itemconfiginfo
526 alias __current_itemconfiginfo current_itemconfiginfo
528 private :__itemcget, :__itemcget_strict
529 private :__itemconfigure, :__itemconfiginfo, :__current_itemconfiginfo
532 def itemcget(tagOrId, option)
533 __itemcget([:item, tagOrId], option)
535 def itemcget_strict(tagOrId, option)
536 __itemcget_strict([:item, tagOrId], option)
538 def itemconfigure(tagOrId, slot, value=None)
539 __itemconfigure([:item, tagOrId], slot, value)
541 def itemconfiginfo(tagOrId, slot=nil)
542 __itemconfiginfo([:item, tagOrId], slot)
544 def current_itemconfiginfo(tagOrId, slot=nil)
545 __current_itemconfiginfo([:item, tagOrId], slot)
549 def columncget(tagOrId, option)
550 __itemcget([:column, tagOrId], option)
552 def columncget_strict(tagOrId, option)
553 __itemcget_strict([:column, tagOrId], option)
555 def columnconfigure(tagOrId, slot, value=None)
556 __itemconfigure([:column, tagOrId], slot, value)
558 def columnconfiginfo(tagOrId, slot=nil)
559 __itemconfiginfo([:column, tagOrId], slot)
561 def current_columnconfiginfo(tagOrId, slot=nil)
562 __current_itemconfiginfo([:column, tagOrId], slot)
564 alias column_cget columncget
565 alias column_cget_strict columncget_strict
566 alias column_configure columnconfigure
567 alias column_configinfo columnconfiginfo
568 alias current_column_configinfo current_columnconfiginfo
571 def headingcget_strict(tagOrId, option)
572 if __tile_specific_item_optkeys([:heading, tagOrId]).index(option.to_s)
574 # On tile-0.7.{2-8}, 'state' options has no '-' at its head.
575 tk_call(*(__item_cget_cmd([:heading, tagOrId]) << option.to_s))
577 # Maybe, 'state' option has '-' in future.
578 tk_call(*(__item_cget_cmd([:heading, tagOrId]) << "-#{option}"))
581 __itemcget_strict([:heading, tagOrId], option)
584 def headingcget(tagOrId, option)
585 unless TkItemConfigMethod.__IGNORE_UNKNOWN_CONFIGURE_OPTION__
586 headingcget_strict(tagOrId, option)
589 headingcget_strict(tagOrId, option)
592 if current_headingconfiginfo(tagOrId).has_key?(option.to_s)
593 # not tag error & option is known -> error on known option
596 # not tag error & option is unknown
605 def headingconfigure(tagOrId, slot, value=None)
606 if slot.kind_of?(Hash)
607 slot = _symbolkey2str(slot)
609 __tile_specific_item_optkeys([:heading, tagOrId]).each{|k|
610 sp_kv << k << _get_eval_string(slot.delete(k)) if slot.has_key?(k)
612 tk_call(*(__item_config_cmd([:heading, tagOrId]).concat(sp_kv)))
613 tk_call(*(__item_config_cmd([:heading, tagOrId]).concat(hash_kv(slot))))
614 elsif __tile_specific_item_optkeys([:heading, tagOrId]).index(slot.to_s)
616 # On tile-0.7.{2-8}, 'state' options has no '-' at its head.
617 tk_call(*(__item_cget_cmd([:heading, tagOrId]) << slot.to_s << value))
619 # Maybe, 'state' option has '-' in future.
620 tk_call(*(__item_cget_cmd([:heading, tagOrId]) << "-#{slot}" << value))
623 __itemconfigure([:heading, tagOrId], slot, value)
627 def headingconfiginfo(tagOrId, slot=nil)
628 __itemconfiginfo([:heading, tagOrId], slot)
630 def current_headingconfiginfo(tagOrId, slot=nil)
631 __current_itemconfiginfo([:heading, tagOrId], slot)
633 alias heading_cget headingcget
634 alias heading_cget_strict headingcget_strict
635 alias heading_configure headingconfigure
636 alias heading_configinfo headingconfiginfo
637 alias current_heading_configinfo current_headingconfiginfo
640 def tagcget(tagOrId, option)
641 __itemcget([:tag, :configure, tagOrId], option)
643 def tagcget_strict(tagOrId, option)
644 __itemcget_strict([:tag, :configure, tagOrId], option)
646 def tagconfigure(tagOrId, slot, value=None)
647 __itemconfigure([:tag, :configure, tagOrId], slot, value)
649 def tagconfiginfo(tagOrId, slot=nil)
650 __itemconfiginfo([:tag, :configure, tagOrId], slot)
652 def current_tagconfiginfo(tagOrId, slot=nil)
653 __current_itemconfiginfo([:tag, :configure, tagOrId], slot)
655 alias tag_cget tagcget
656 alias tag_cget_strict tagcget_strict
657 alias tag_configure tagconfigure
658 alias tag_configinfo tagconfiginfo
659 alias current_tag_configinfo current_tagconfiginfo
662 ########################
664 class Tk::Tile::Treeview::Item < TkObject
665 ItemID_TBL = TkCore::INTERP.create_table
667 TkCore::INTERP.init_ip_env{
668 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
669 Tk::Tile::Treeview::Item::ItemID_TBL.clear
673 def self.id2obj(tree, id)
675 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
676 if Tk::Tile::Treeview::Item::ItemID_TBL[tpath]
677 (Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id])? \
678 Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]: id
685 def self.assign(tree, id)
688 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
689 if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] &&
690 Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]
691 return Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]
700 Tk::Tile::Treeview::Item::ItemID_TBL[tpath] ||= {}
701 Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] = obj
706 def _insert_item(tree, parent_item, idx, keys={})
707 keys = _symbolkey2str(keys)
708 id = keys.delete('id')
710 num_or_str(tk_call(tree, 'insert',
711 parent_item, idx, '-id', id, *hash_kv(keys)))
713 num_or_str(tk_call(tree, 'insert', parent_item, idx, *hash_kv(keys)))
716 private :_insert_item
718 def initialize(tree, parent_item = '', idx = 'end', keys = {})
719 if parent_item.kind_of?(Hash)
723 elsif idx.kind_of?(Hash)
730 @path = @id = _insert_item(@t, parent_item, idx, keys)
731 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
732 ItemID_TBL[@tpath] = {} unless ItemID_TBL[@tpath]
733 ItemID_TBL[@tpath][@id] = self
741 @t.itemcget(@id, option)
743 def cget_strict(option)
744 @t.itemcget_strict(@id, option)
747 def configure(key, value=None)
748 @t.itemconfigure(@id, key, value)
752 def configinfo(key=nil)
753 @t.itemconfiginfo(@id, key)
756 def current_configinfo(key=nil)
757 @t.current_itemconfiginfo(@id, key)
764 configure('open', true)
768 configure('open', false)
772 def bbox(column=None)
779 def set_children(*items)
780 @t.set_children(@id, *items)
806 def insert(idx='end', keys={})
807 @t.insert(@id, idx, keys)
810 def move(parent, idx)
811 @t.move(@id, parent, idx)
833 @t.selection_add(@id)
838 @t.selection_remove(@id)
843 @t.selection_set(@id)
848 @t.selection_toggle(@id)
853 @t.get_directory(@id)
855 alias get_dictionary get_directory
862 @t.set(@id, col, value)
866 ########################
868 class Tk::Tile::Treeview::Root < Tk::Tile::Treeview::Item
869 def self.new(tree, keys = {})
872 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
873 if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] &&
874 Tk::Tile::Treeview::Item::ItemID_TBL[tpath]['']
875 obj = Tk::Tile::Treeview::Item::ItemID_TBL[tpath]['']
878 (obj = self.allocate).instance_eval{
882 Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] ||= {}
883 Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self
887 obj.configure(keys) if keys && ! keys.empty?
891 def initialize(tree, keys = {})
892 # dummy:: not called by 'new' method
896 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
897 Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] ||= {}
898 Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self
903 ########################
905 class Tk::Tile::Treeview::Tag < TkObject
906 include TkTreatTagFont
908 TagID_TBL = TkCore::INTERP.create_table
910 (Tag_ID = ['tile_treeview_tag'.freeze, '00000'.taint]).instance_eval{
912 def mutex; @mutex; end
916 TkCore::INTERP.init_ip_env{
917 Tk::Tile::Treeview::Tag::TagID_TBL.mutex.synchronize{
918 Tk::Tile::Treeview::Tag::TagID_TBL.clear
922 def self.id2obj(tree, id)
924 Tk::Tile::Treeview::Tag::TagID_TBL.mutex.synchronize{
925 if Tk::Tile::Treeview::Tag::TagID_TBL[tpath]
926 (Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id])? \
927 Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id]: id
934 def initialize(tree, keys=nil)
937 Tag_ID.mutex.synchronize{
938 @path = @id = Tag_ID.join(TkCore::INTERP._ip_id_)
941 TagID_TBL.mutex.synchronize{
942 TagID_TBL[@tpath] = {} unless TagID_TBL[@tpath]
943 TagID_TBL[@tpath][@id] = self
945 if keys && keys != None
946 tk_call_without_enc(@tpath, 'tag', 'configure', @id, *hash_kv(keys,true))
954 if TkComm._callback_entry?(args[0]) || !block_given?
959 @t.tag_bind(@id, seq, cmd, *args)
963 def bind_append(seq, *args)
964 if TkComm._callback_entry?(args[0]) || !block_given?
969 @t.tag_bind_append(@id, seq, cmd, *args)
974 @t.tag_bind_remove(@id, seq)
978 def bindinfo(seq=nil)
979 @t.tag_bindinfo(@id, seq)
983 @t.tagcget(@id, option)
985 def cget_strict(option)
986 @t.tagcget_strict(@id, option)
989 def configure(key, value=None)
990 @t.tagconfigure(@id, key, value)
994 def configinfo(key=nil)
995 @t.tagconfiginfo(@id, key)
998 def current_configinfo(key=nil)
999 @t.current_tagconfiginfo(@id, key)
1003 ########################
1005 class Tk::Tile::Treeview < TkWindow
1006 include Tk::Tile::TileWidget
1009 include Tk::Tile::TreeviewConfig
1011 if Tk::Tile::USE_TTK_NAMESPACE
1012 TkCommandNames = ['::ttk::treeview'.freeze].freeze
1014 TkCommandNames = ['::treeview'.freeze].freeze
1016 WidgetClassName = 'Treeview'.freeze
1017 WidgetClassNames[WidgetClassName] = self
1019 def __destroy_hook__
1020 Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{
1021 Tk::Tile::Treeview::Item::ItemID_TBL.delete(@path)
1023 Tk::Tile::Treeview::Tag::ItemID_TBL.mutex.synchronize{
1024 Tk::Tile::Treeview::Tag::ItemID_TBL.delete(@path)
1028 def self.style(*args)
1029 [self::WidgetClassName, *(args.map!{|a| _get_eval_string(a)})].join('.')
1033 if id.kind_of?(Tk::Tile::Treeview::Item) ||
1034 id.kind_of?(Tk::Tile::Treeview::Tag)
1036 elsif id.kind_of?(Array)
1038 id[0..-2] << _get_eval_string(id[-1])
1040 _get_eval_string(id)
1045 Tk::Tile::Treeview::Root.new(self)
1048 def bbox(item, column=None)
1049 list(tk_send('item', 'bbox', item, column))
1053 simplelist(tk_send_without_enc('children', item)).collect{|id|
1054 Tk::Tile::Treeview::Item.id2obj(self, id)
1057 def set_children(item, *items)
1058 tk_send_without_enc('children', item,
1059 array2tk_list(items.flatten, true))
1064 tk_send_without_enc('delete', array2tk_list(items.flatten, true))
1069 tk_send_without_enc('detach', array2tk_list(items.flatten, true))
1074 bool(tk_send_without_enc('exists', _get_eval_enc_str(item)))
1077 def focus_item(item = nil)
1079 tk_send('focus', item)
1082 id = tk_send('focus')
1083 (id.empty?)? nil: Tk::Tile::Treeview::Item.id2obj(self, id)
1088 # tile-0.7.2 or previous
1089 ret = simplelist(tk_send('identify', x, y))
1091 when 'heading', 'separator'
1092 ret[-1] = num_or_str(ret[-1])
1094 ret[1] = Tk::Tile::Treeview::Item.id2obj(self, ret[1])
1095 ret[-1] = num_or_str(ret[-1])
1097 ret[1] = Tk::Tile::Treeview::Item.id2obj(self, ret[1])
1101 def row_identify(x, y)
1102 id = tk_send('identify', 'row', x, y)
1103 (id.empty?)? nil: Tk::Tile::Treeview::Item.id2obj(self, id)
1106 def column_identify(x, y)
1107 tk_send('identify', 'column', x, y)
1111 number(tk_send('index', item))
1114 # def insert(parent, idx='end', keys={})
1115 # keys = _symbolkey2str(keys)
1116 # id = keys.delete('id')
1118 # num_or_str(tk_send('insert', parent, idx, '-id', id, *hash_kv(keys)))
1120 # num_or_str(tk_send('insert', parent, idx, *hash_kv(keys)))
1123 def insert(parent, idx='end', keys={})
1124 Tk::Tile::Treeview::Item.new(self, parent, idx, keys)
1127 # def instate(spec, cmd=Proc.new)
1128 # tk_send('instate', spec, cmd)
1130 # def state(spec=None)
1131 # tk_send('state', spec)
1134 def move(item, parent, idx)
1135 tk_send('move', item, parent, idx)
1140 id = tk_send('next', item)
1141 (id.empty?)? nil: Tk::Tile::Treeview::Item.id2obj(self, id)
1144 def parent_item(item)
1145 if (id = tk_send('parent', item)).empty?
1146 Tk::Tile::Treeview::Root.new(self)
1148 Tk::Tile::Treeview::Item.id2obj(self, id)
1153 id = tk_send('prev', item)
1154 (id.empty?)? nil: Tk::Tile::Treeview::Item.id2obj(self, id)
1158 tk_send('see', item)
1163 simplelist(tk_send('selection')).collect{|id|
1164 Tk::Tile::Treeview::Item.id2obj(self, id)
1167 alias selection_get selection
1169 def selection_add(*items)
1170 tk_send('selection', 'add', array2tk_list(items.flatten, true))
1173 def selection_remove(*items)
1174 tk_send('selection', 'remove', array2tk_list(items.flatten, true))
1177 def selection_set(*items)
1178 tk_send('selection', 'set', array2tk_list(items.flatten, true))
1181 def selection_toggle(*items)
1182 tk_send('selection', 'toggle', array2tk_list(items.flatten, true))
1186 def get_directory(item)
1189 lst = simplelist(tk_send('set', item))
1197 alias get_dictionary get_directory
1200 tk_send('set', item, col)
1202 def set(item, col, value)
1203 tk_send('set', item, col, value)
1207 def tag_bind(tag, seq, *args)
1208 if TkComm._callback_entry?(args[0]) || !block_given?
1213 _bind([@path, 'tag', 'bind', tag], seq, cmd, *args)
1216 alias tagbind tag_bind
1218 def tag_bind_append(tag, seq, *args)
1219 if TkComm._callback_entry?(args[0]) || !block_given?
1224 _bind_append([@path, 'tag', 'bind', tag], seq, cmd, *args)
1227 alias tagbind_append tag_bind_append
1229 def tag_bind_remove(tag, seq)
1230 _bind_remove([@path, 'tag', 'bind', tag], seq)
1233 alias tagbind_remove tag_bind_remove
1235 def tag_bindinfo(tag, context=nil)
1236 _bindinfo([@path, 'tag', 'bind', tag], context)
1238 alias tagbindinfo tag_bindinfo