1#
2#  tkextlib/iwidgets/buttonbox.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 Buttonbox < Tk::Itk::Widget
12    end
13  end
14end
15
16class Tk::Iwidgets::Buttonbox
17  TkCommandNames = ['::iwidgets::buttonbox'.freeze].freeze
18  WidgetClassName = 'Buttonbox'.freeze
19  WidgetClassNames[WidgetClassName] ||= self
20
21  ####################################
22
23  include TkItemConfigMethod
24
25  def __item_cget_cmd(id)
26    [self.path, 'buttoncget', id]
27  end
28  private :__item_cget_cmd
29
30  def __item_config_cmd(id)
31    [self.path, 'buttonconfigure', id]
32  end
33  private :__item_config_cmd
34
35  def __item_boolval_optkeys(id)
36    super(id) << 'defaultring'
37  end
38  private :__item_boolval_optkeys
39
40  def tagid(tagOrId)
41    if tagOrId.kind_of?(Tk::Itk::Component)
42      tagOrId.name
43    else
44      #_get_eval_string(tagOrId)
45      tagOrId
46    end
47  end
48
49  alias buttoncget_tkstring itemcget_tkstring
50  alias buttoncget itemcget
51  alias buttoncget_strict itemcget_strict
52  alias buttonconfigure itemconfigure
53  alias buttonconfiginfo itemconfiginfo
54  alias current_buttonconfiginfo current_itemconfiginfo
55
56  private :itemcget_tkstring, :itemcget, :itemcget_strict
57  private :itemconfigure, :itemconfiginfo, :current_itemconfiginfo
58
59  ####################################
60
61  def add(tag=nil, keys={})
62    if tag.kind_of?(Hash)
63      keys = tag
64      tag = nil
65    end
66    if tag
67      tag = Tk::Itk::Component.new(self, tagid(tag))
68    else
69      tag = Tk::Itk::Component.new(self)
70    end
71    tk_call(@path, 'add', tagid(tag), *hash_kv(keys))
72    tag
73  end
74
75  def default(idx)
76    tk_call(@path, 'default', index(idx))
77    self
78  end
79
80  def delete(idx)
81    tk_call(@path, 'delete', index(idx))
82    self
83  end
84
85  def hide(idx)
86    tk_call(@path, 'hide', index(idx))
87    self
88  end
89
90  def index(idx)
91    number(tk_call(@path, 'index', tagid(idx)))
92  end
93
94  def insert(idx, tag=nil, keys={})
95    if tag.kind_of?(Hash)
96      keys = tag
97      tag = nil
98    end
99    if tag
100      tag = Tk::Itk::Component.new(self, tagid(tag))
101    else
102      tag = Tk::Itk::Component.new(self)
103    end
104    tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys))
105    tag
106  end
107
108  def invoke(idx=nil)
109    if idx
110      tk_call(@path, 'invoke', index(idx))
111    else
112      tk_call(@path, 'invoke')
113    end
114    self
115  end
116
117  def show(idx)
118    tk_call(@path, 'show', index(idx))
119    self
120  end
121end
122