1# 2# tkextlib/iwidgets/toolbar.rb 3# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) 4# 5 6require 'tk' 7require 'tkextlib/iwidgets.rb' 8 9module Tk 10 module Iwidgets 11 class Toolbar < Tk::Itk::Widget 12 end 13 end 14end 15 16class Tk::Iwidgets::Toolbar 17 TkCommandNames = ['::iwidgets::toolbar'.freeze].freeze 18 WidgetClassName = 'Toolbar'.freeze 19 WidgetClassNames[WidgetClassName] ||= self 20 21 def __tkvariable_optkeys 22 super() << 'helpvariable' 23 end 24 private :__tkvariable_optkeys 25 26 #################################### 27 28 include TkItemConfigMethod 29 30 def __item_cget_cmd(id) 31 [self.path, 'itemcget', self.index(id)] 32 end 33 private :__item_cget_cmd 34 35 def __item_config_cmd(id) 36 [self.path, 'itemconfigure', self.index(id)] 37 end 38 private :__item_config_cmd 39 40 def __item_strval_optkeys(id) 41 super(id) << 'helpstr' << 'balloonstr' 42 end 43 private :__item_strval_optkeys 44 45 def tagid(tagOrId) 46 if tagOrId.kind_of?(Tk::Itk::Component) 47 tagOrId.name 48 else 49 #_get_eval_string(tagOrId) 50 tagOrId 51 end 52 end 53 54 #################################### 55 56 def __strval_optkeys 57 super() << 'balloonbackground' << 'balloonforeground' 58 end 59 private :__strval_optkeys 60 61 def __tkvariable_optkeys 62 super() << 'helpvariable' 63 end 64 private :__tkvariable_optkeys 65 66 def __font_optkeys 67 super() << 'balloonfont' 68 end 69 private :__font_optkeys 70 71 def add(type, tag=nil, keys={}) 72 if tag.kind_of?(Hash) 73 keys = tag 74 tag = nil 75 end 76 if tag 77 tag = Tk::Itk::Component.new(self, tagid(tag)) 78 else 79 tag = Tk::Itk::Component.new(self) 80 end 81 window(tk_call(@path, 'add', type, tagid(tag), *hash_kv(keys))) 82 tag 83 end 84 85 def delete(idx1, idx2=nil) 86 if idx2 87 tk_call(@path, 'delete', index(idx1), index(idx2)) 88 else 89 tk_call(@path, 'delete', index(idx1)) 90 end 91 self 92 end 93 94 def index(idx) 95 number(tk_call(@path, 'index', tagid(idx))) 96 end 97 98 def insert(idx, type, tag=nil, keys={}) 99 if tag.kind_of?(Hash) 100 keys = tag 101 tag = nil 102 end 103 if tag 104 tag = Tk::Itk::Component.new(self, tagid(tag)) 105 else 106 tag = Tk::Itk::Component.new(self) 107 end 108 window(tk_call(@path, 'insert', index(idx), type, 109 tagid(tag), *hash_kv(keys))) 110 tag 111 end 112end 113