2
# tkextlib/blt/tabset.rb
3
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
7
require 'tkextlib/blt.rb'
10
class Tabset < TkWindow
12
include TkTreatItemFont
14
TabID_TBL = TkCore::INTERP.create_table
15
TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint].freeze
17
TkCore::INTERP.init_ip_env{ TabID_TBL.clear }
19
def self.id2obj(tabset, id)
21
return id unless TabID_TBL[tpath]
22
TabID_TBL[tpath][id]? TabID_TBL[tpath]: id
25
def self.new(parent, pos=nil, name=nil, keys={})
31
if name.kind_of?(Hash)
36
if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name]
37
TabID_TBL[parent.path][name]
39
super(parent, pos, name, keys)
43
def initialize(parent, pos, name, keys)
48
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
49
TabID_TBL[@tpath][@id] = self
51
unless (list(tk_call(@tpath, 'tab', 'names', @id)).empty?)
53
idx = tk_call(@tpath, 'index', '-name', @id)
55
tk_call(@tpath, idx, 'moveto', 'after', 'end')
57
tk_call(@tpath, idx, 'moveto', 'before', pos)
60
tk_call(@tpath, 'tab', 'configure', @id, keys)
65
@path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
66
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
67
TabID_TBL[@tpath][@id] = self
71
pos = 'end' unless pos
72
tk_call(@tpath, 'insert', pos, @id, keys)
75
#def bind(context, cmd=Proc.new, *args)
76
# @t.tab_bind(@id, context, cmd, *args)
79
def bind(context, *args)
80
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
81
if TkComm._callback_entry?(args[0]) || !block_given?
86
@t.tab_bind(@id, context, cmd, *args)
89
#def bind_append(context, cmd=Proc.new, *args)
90
# @t.tab_bind_append(@id, context, cmd, *args)
93
def bind_append(context, *args)
94
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
95
if TkComm._callback_entry?(args[0]) || !block_given?
100
@t.tab_bind_append(@id, context, cmd, *args)
103
def bind_remove(context)
104
@t.tab_bind_remove(@id, context)
107
def bindinfo(context=nil)
108
@t.tab_bindinfo(@id, context)
112
@t.tab_cget(@id, *args)
115
@t.tab_configure(@id, *args)
117
def configinfo(*args)
118
@t.tab_configinfo(@id, *args)
120
def current_configinfo(*args)
121
@t.current_tab_configinfo(@id, *args)
126
TabID_TBL[@tpath].delete(@id)
143
@t.invoke(self.index)
147
@t.move_before(self.index, idx)
150
@t.move_after(self.index, idx)
153
def perforation_highlight(mode)
154
@t.perforation.highlight(self.index, mode)
156
def perforation_invoke()
157
@t.perforation.invoke(self.index)
164
def tearoff(name=None)
165
@t.tab_tearoff(self.index, *args)
169
########################################
172
def self.new(parent, name)
173
super(parent, nil, name, {})
177
########################################
180
include TkItemConfigMethod
182
TkCommandNames = ['::blt::tabset'.freeze].freeze
183
WidgetClassName = 'Tabset'.freeze
184
WidgetClassNames[WidgetClassName] = self
187
Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path)
190
########################################
192
def __boolval_optkeys
193
super() << 'samewidth' << 'tearoff'
195
private :__strval_optkeys
198
super() << 'tabbackground' << 'tabforeground'
200
private :__strval_optkeys
202
def __item_cget_cmd(id)
203
[self.path, 'tab', 'cget', id]
205
private :__item_cget_cmd
207
def __item_config_cmd(id)
208
[self.path, 'tab', 'configure', id]
210
private :__item_config_cmd
212
def __item_pathname(tagOrId)
213
if tagOrId.kind_of?(Tk::BLT::Tabset::Tab)
214
self.path + ';' + tagOrId.id.to_s
216
self.path + ';' + tagOrId.to_s
219
private :__item_pathname
221
alias tab_cget itemcget
222
alias tab_configure itemconfigure
223
alias tab_configinfo itemconfiginfo
224
alias current_tab_configinfo current_itemconfiginfo
226
def __item_strval_optkeys(id)
227
super(id) << 'shadow'
229
private :__item_strval_optkeys
232
if tab.kind_of?(Tk::BLT::Tabset::Tab)
240
if tab.kind_of?(Tk::BLT::Tabset::Tab)
247
########################################
250
tk_send('activate', tagindex(index))
253
alias highlight activate
255
#def tabbind(tag, context, cmd=Proc.new, *args)
256
# _bind([path, "bind", tagid(tag)], context, cmd, *args)
259
def tabbind(tag, context, *args)
260
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
261
if TkComm._callback_entry?(args[0]) || !block_given?
266
_bind([path, "bind", tagid(tag)], context, cmd, *args)
269
#def tabbind_append(tag, context, cmd=Proc.new, *args)
270
# _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
273
def tabbind_append(tag, context, *args)
274
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
275
if TkComm._callback_entry?(args[0]) || !block_given?
280
_bind_append([path, "bind", tagid(tag)], context, cmd, *args)
283
def tabbind_remove(tag, context)
284
_bind_remove([path, "bind", tagid(tag)], context)
287
def tabbindinfo(tag, context=nil)
288
_bindinfo([path, "bind", tagid(tag)], context)
291
def delete(first, last=None)
292
tk_send('delete', tagindex(first), tagindex(last))
293
if first.kind_of?(Tk::BLT::Tabset::Tab)
294
TabID_TBL[@path].delete(first.id)
296
# middle tabs of the range are unknown
297
if last.kind_of?(Tk::BLT::Tabset::Tab)
298
TabID_TBL[@path].delete(last.id)
304
tk_send('focus', tagindex(index))
309
Tk::BLT::Tabset::Tab.id2obj(tk_send_without_enc('get', tagindex(index)))
313
num_or_str(tk_send('index', str))
316
num_or_str(tk_send('index', '-mame', tagid(tab)))
319
def insert(pos, tab, keys={})
320
Tk::BLT::Tabset::Tab.new(self, tagindex(pos), tagid(tab), keys)
324
tk_send('invoke', tagindex(index))
327
def move_before(index, base_idx)
328
tk_send('move', tagindex(index), 'before', tagindex(base_idx))
331
def move_after(index, base_idx)
332
tk_send('move', tagindex(index), 'after', tagindex(base_idx))
337
Tk::BLT::Tabset::Tab.id2obj(num_or_str(tk_send_without_enc('nearest', x, y)))
340
def perforation_highlight(index, mode)
341
tk_send('perforation', 'highlight', tagindex(index), mode)
344
def perforation_invoke(index)
345
tk_send('perforation', 'invoke', tagindex(index))
349
tk_send_without_enc('scan', 'mark', x, y)
352
def scan_dragto(x, y)
353
tk_send_without_enc('scan', 'dragto', x, y)
358
tk_send('see', tagindex(index))
363
number(tk_send_without_enc('size'))
367
tk_send('select', tagindex(index))
371
def tab_names(pat=None)
372
simplelist(tk_send('tab', 'names', pat)).collect{|name|
373
Tk::BLT::Tabset::Tab.id2obj(name)
377
def tab_tearoff(index, name=None)
378
window(tk_send('tab', 'tearoff', tagindex(index), name))
381
def xscrollcommand(cmd=Proc.new)
382
configure_cmd 'scrollcommand', cmd
385
alias scrollcommand xscrollcommand
389
list(tk_send_without_enc('view'))
391
tk_send_without_enc('view', *index)
396
alias view_moveto xview_moveto
397
alias view_scroll xview_scroll
399
alias scrollbar xscrollbar