1#
2#  tkextlib/iwidgets/radiobox.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 Radiobox < Tk::Iwidgets::Labeledframe
12    end
13  end
14end
15
16class Tk::Iwidgets::Radiobox
17  TkCommandNames = ['::iwidgets::radiobox'.freeze].freeze
18  WidgetClassName = 'Radiobox'.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 delete(idx)
76    tk_call(@path, 'delete', index(idx))
77    self
78  end
79
80  def deselect(idx)
81    tk_call(@path, 'deselect', index(idx))
82    self
83  end
84
85  def flash(idx)
86    tk_call(@path, 'flash', index(idx))
87    self
88  end
89
90  def get_tag
91    ((tag = tk_call_without_enc(@path, 'get')).empty?)? nil: tag
92  end
93  alias get get_tag
94
95  def get_obj
96    (tag = get_tag)? Tk::Itk::Component.id2obj(self, tag): nil
97  end
98
99  def index(idx)
100    number(tk_call(@path, 'index', tagid(idx)))
101  end
102
103  def insert(idx, tag=nil, keys={})
104    if tag.kind_of?(Hash)
105      keys = tag
106      tag = nil
107    end
108    if tag
109      tag = Tk::Itk::Component.new(self, tagid(tag))
110    else
111      tag = Tk::Itk::Component.new(self)
112    end
113    tk_call(@path, 'insert', index(idx), tagid(tag), *hash_kv(keys))
114    tag
115  end
116
117  def select(idx)
118    tk_call(@path, 'select', index(idx))
119    self
120  end
121end
122