mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
e6697a6405
* ext/tk/tcltklib.c: avoid error on a shared object. * ext/tk/extconf.rb: support --with-tcltkversion * ext/tk/README.tcltklib: add document about --with-tcltkversion * ext/tk/lib/tk.rb, ext/tk/lib/multi-tk.rb, ext/tk/lib/remote-tk.rb: not work on $SAFE==4 * ext/tk/lib/multi-tk.rb: Object#methods returns Symbols on Ruby1.9. * ext/tk/lib/tk/timer.rb: add TkTimer#at_end(proc) to register the procedure which called at end of the timer. * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemfont.rb, ext/tk/lib/font.rb: support __IGNORE_UNKNOWN_CONFIGURE_OPTION__ about font options. * ext/tk/lib/*: treat __IGNORE_UNKNOWN_CONFIGURE_OPTION__ * ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb, ext/tk/lib/tkextlib/iwidgets/scrolledlistbox.rb, ext/tk/lib/tkextlib/iwidgets/scrolledtext.rb: bug fix. * ext/tk/lib/tk/text.rb: typo. call a wrong method. * ext/tk/lib/tk/itemconfig.rb: ditto. * ext/tk/lib/tk.rb, ext/tk/lib/tk/itemconfig.rb, ext/tk/lib/tk/canvas.rb: support alias names of option keys. * ext/tk/lib/tk/grid.rb: lack of module-method definitions. * ext/tk/lib/tk/pack.rb, ext/tk/lib/tk/grid.rb: increase supported parameter patterns of configure method. * ext/tk/lib/tk.rb: add TkWindow#grid_anchor, grid_column, grid_row. * ext/tk/lib/tk/wm.rb: methods of Tk::Wm_for_General module cannot pass the given block to methods of Tk::Wm module. * ext/tk/lib/tk/wm.rb: Wm#overrideredirect overwrites arguemnt to an invalid value. * ext/tk/lib/tk.rb: fix memory (object) leak bug. * ext/tk/tcltklib.c, ext/tk/tkutil/tkutil.c: fix memory leak. * ext/tk/sample/demos-jp/aniwave.rb, ext/tk/sample/demos-en/aniwave.rb: bug fix. * ext/tk/lib/tkextlib/blt/component.rb, ext/tk/lib/tkextlib/tile/tentry.rb, ext/tk/lib/tkextlib/tile/treeview.rb: ditto. * ext/tk/lib/tkextlib/tile/tpaned.rb: improve TPaned#add. * ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget, ext/tk/sample/demos-jp/style.rb, ext/tk/sample/demos-en/style.rb, ext/tk/sample/demos-jp/bind.rb, ext/tk/sample/demos-en/bind.rb: bug fix. * ext/tk/sample/ttk_wrapper.rb: ditto. * ext/tk/sample/ttk_wrapper.rb: support "if __FILE__ == $0" idiom. * ext/tk/sample/tktextio.rb: add binding for 'Ctrl-u' at console mode. * ext/tk/lib/tkextlib/tile.rb, ext/tk/lib/tkextlib/tile/style.rb, ext/tk/sample/ttk_wrapper.rb: improve treating and control themes. add Tk::Tile.themes and Tk::Tile.set_theme(theme). * ext/tk/lib/tkextlib/tile.rb: lack of autoload definitions. * ext/tk/lib/tkextlib/tile/tnotebook.rb: cannot use kanji (not UTF-8) characters for headings. * ext/tk/lib/tkextlib/tkDND/shape.rb: wrong package name. * ext/tk/tkutil/tkutil.c: improve handling callback-subst-keys. Now, support longnam-keys (e.g. '%CTT' on tkdnd-2.0; however, still not support tkdnd-2.0 on tkextlib), and symbols of parameters (e.g. :widget=>'%W', :keycode=>'%k', '%x'=>:x, '%X'=>:root_x, and so on; those are attributes of event object). It means that Ruby/Tk accepts not only "widget.bind(ev, '%W', '%k', ...){|w, k, ...| ... }", but also "widget.bind(ev, :widget, :keycode, ...){|w, k, ...| ... }". It is potentially incompatible, when user passes symbols to the arguments of the callback block (the block receives the symbols as strings). I think that is very rare case (probably, used by Ruby/Tk experts only). When causes such trouble, please give strings instead of such symbol parameters (e.g. call Symbol#to_s method). * ext/tk/lib/tk/event.rb, ext/tk/lib/tk/validation.rb, ext/tk/lib/tkextlib/blt/treeview.rb, ext/tk/lib/tkextlib/winico/winico.rb: ditto. * ext/tk/tkutil/tkutil.c: strings are available on subst_tables on TkUtil::CallbackSubst class (it is useful on Ruby 1.9). * ext/tk/lib/tk/spinbox.rb, ext/tk/lib/tkextlib/iwidgets/hierarchy.rb, ext/tk/lib/tkextlib/iwidgets/spinner.rb, ext/tk/lib/tkextlib/iwidgets/entryfield.rb, ext/tk/lib/tkextlib/iwidgets/calendar.rb, ext/tk/lib/tkextlib/blt/dragdrop.rb, ext/tk/lib/tkextlib/tkDND/tkdnd.rb, ext/tk/lib/tkextlib/treectrl/tktreectrl.rb, ext/tk/lib/tkextlib/tktable/tktable.rb: disable code piece became unnecessary by reason of the changes of ext/tk/tkutil/tkutil.c. * ext/tk/lib/tk.rb, ext/tk/lib/multi-tk.rb: change strategy to define the constant WITH_ENCODING. * ext/tk/lib/tk.rb: fix bug on Tk::Encoding.tk_encoding_names. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@17083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
430 lines
10 KiB
Ruby
430 lines
10 KiB
Ruby
#
|
|
# tkextlib/blt/tabset.rb
|
|
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
|
|
#
|
|
|
|
require 'tk'
|
|
require 'tkextlib/blt.rb'
|
|
|
|
module Tk::BLT
|
|
class Tabset < TkWindow
|
|
class Tab < TkObject
|
|
include TkTreatItemFont
|
|
|
|
TabID_TBL = TkCore::INTERP.create_table
|
|
|
|
(TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint]).instance_eval{
|
|
@mutex = Mutex.new
|
|
def mutex; @mutex; end
|
|
freeze
|
|
}
|
|
|
|
TkCore::INTERP.init_ip_env{
|
|
TabID_TBL.mutex.synchronize{ TabID_TBL.clear }
|
|
}
|
|
|
|
def self.id2obj(tabset, id)
|
|
tpath = tabset.path
|
|
TabID_TBL.mutex.synchronize{
|
|
if TabID_TBL[tpath]
|
|
TabID_TBL[tpath][id]? TabID_TBL[tpath]: id
|
|
else
|
|
id
|
|
end
|
|
}
|
|
end
|
|
|
|
def self.new(parent, pos=nil, name=nil, keys={})
|
|
if pos.kind_of?(Hash)
|
|
keys = pos
|
|
name = nil
|
|
pos = nil
|
|
end
|
|
if name.kind_of?(Hash)
|
|
keys = name
|
|
name = nil
|
|
end
|
|
obj = nil
|
|
TabID_TBL.mutex.synchronize{
|
|
if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name]
|
|
obj = TabID_TBL[parent.path][name]
|
|
obj.configure if keys && ! keys.empty?
|
|
else
|
|
(obj = self.allocate).instance_eval{
|
|
initialize(parent, pos, name, keys)
|
|
TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath]
|
|
TabID_TBL[@tpath][@id] = self
|
|
}
|
|
end
|
|
}
|
|
obj
|
|
end
|
|
|
|
def initialize(parent, pos, name, keys)
|
|
@t = parent
|
|
@tpath = parent.path
|
|
if name
|
|
@path = @id = name
|
|
unless (list(tk_call(@tpath, 'tab', 'names', @id)).empty?)
|
|
if pos
|
|
idx = tk_call(@tpath, 'index', '-name', @id)
|
|
if pos.to_s == 'end'
|
|
tk_call(@tpath, idx, 'moveto', 'after', 'end')
|
|
else
|
|
tk_call(@tpath, idx, 'moveto', 'before', pos)
|
|
end
|
|
end
|
|
tk_call(@tpath, 'tab', 'configure', @id, keys)
|
|
else
|
|
pos = 'end' unless pos
|
|
tk_call(@tpath, 'insert', pos, @id, keys)
|
|
end
|
|
else
|
|
TabsetTab_ID.mutex.synchronize{
|
|
@path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_)
|
|
TabsetTab_ID[1].succ!
|
|
}
|
|
pos = 'end' unless pos
|
|
tk_call(@tpath, 'insert', pos, @id, keys)
|
|
end
|
|
end
|
|
|
|
#def bind(context, cmd=Proc.new, *args)
|
|
# @t.tab_bind(@id, context, cmd, *args)
|
|
# self
|
|
#end
|
|
def bind(context, *args)
|
|
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
|
|
if TkComm._callback_entry?(args[0]) || !block_given?
|
|
cmd = args.shift
|
|
else
|
|
cmd = Proc.new
|
|
end
|
|
@t.tab_bind(@id, context, cmd, *args)
|
|
self
|
|
end
|
|
#def bind_append(context, cmd=Proc.new, *args)
|
|
# @t.tab_bind_append(@id, context, cmd, *args)
|
|
# self
|
|
#end
|
|
def bind_append(context, *args)
|
|
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
|
|
if TkComm._callback_entry?(args[0]) || !block_given?
|
|
cmd = args.shift
|
|
else
|
|
cmd = Proc.new
|
|
end
|
|
@t.tab_bind_append(@id, context, cmd, *args)
|
|
self
|
|
end
|
|
def bind_remove(context)
|
|
@t.tab_bind_remove(@id, context)
|
|
self
|
|
end
|
|
def bindinfo(context=nil)
|
|
@t.tab_bindinfo(@id, context)
|
|
end
|
|
|
|
def cget(*args)
|
|
@t.tab_cget(@id, *args)
|
|
end
|
|
def cget_strict(*args)
|
|
@t.tab_cget_strict(@id, *args)
|
|
end
|
|
def configure(*args)
|
|
@t.tab_configure(@id, *args)
|
|
end
|
|
def configinfo(*args)
|
|
@t.tab_configinfo(@id, *args)
|
|
end
|
|
def current_configinfo(*args)
|
|
@t.current_tab_configinfo(@id, *args)
|
|
end
|
|
|
|
def delete()
|
|
@t.delete(@id)
|
|
TabID_TBL.mutex.synchronize{
|
|
TabID_TBL[@tpath].delete(@id)
|
|
}
|
|
self
|
|
end
|
|
|
|
def get_name()
|
|
@id.dup
|
|
end
|
|
|
|
def focus()
|
|
@t.focus(self.index)
|
|
end
|
|
|
|
def index()
|
|
@t.index_name(@id)
|
|
end
|
|
|
|
def invoke()
|
|
@t.invoke(self.index)
|
|
end
|
|
|
|
def move_before(idx)
|
|
@t.move_before(self.index, idx)
|
|
end
|
|
def move_after(idx)
|
|
@t.move_after(self.index, idx)
|
|
end
|
|
|
|
def perforation_highlight(mode)
|
|
@t.perforation.highlight(self.index, mode)
|
|
end
|
|
def perforation_invoke()
|
|
@t.perforation.invoke(self.index)
|
|
end
|
|
|
|
def see()
|
|
@t.see(self.index)
|
|
end
|
|
|
|
def tearoff(name=None)
|
|
@t.tab_tearoff(self.index, *args)
|
|
end
|
|
end
|
|
|
|
########################################
|
|
|
|
class NamedTab < Tab
|
|
def self.new(parent, name)
|
|
super(parent, nil, name, {})
|
|
end
|
|
end
|
|
|
|
########################################
|
|
|
|
include X_Scrollable
|
|
include TkItemConfigMethod
|
|
|
|
TkCommandNames = ['::blt::tabset'.freeze].freeze
|
|
WidgetClassName = 'Tabset'.freeze
|
|
WidgetClassNames[WidgetClassName] = self
|
|
|
|
def __destroy_hook__
|
|
Tk::BLT::Tabset::Tab::TabID_TBL.mutex.synchronize{
|
|
Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path)
|
|
}
|
|
end
|
|
|
|
########################################
|
|
|
|
def __boolval_optkeys
|
|
super() << 'samewidth' << 'tearoff'
|
|
end
|
|
private :__strval_optkeys
|
|
|
|
def __strval_optkeys
|
|
super() << 'tabbackground' << 'tabforeground'
|
|
end
|
|
private :__strval_optkeys
|
|
|
|
def __item_cget_cmd(id)
|
|
[self.path, 'tab', 'cget', id]
|
|
end
|
|
private :__item_cget_cmd
|
|
|
|
def __item_config_cmd(id)
|
|
[self.path, 'tab', 'configure', id]
|
|
end
|
|
private :__item_config_cmd
|
|
|
|
def __item_pathname(tagOrId)
|
|
if tagOrId.kind_of?(Tk::BLT::Tabset::Tab)
|
|
self.path + ';' + tagOrId.id.to_s
|
|
else
|
|
self.path + ';' + tagOrId.to_s
|
|
end
|
|
end
|
|
private :__item_pathname
|
|
|
|
alias tab_cget itemcget
|
|
alias tab_cget_strict itemcget_strict
|
|
alias tab_configure itemconfigure
|
|
alias tab_configinfo itemconfiginfo
|
|
alias current_tab_configinfo current_itemconfiginfo
|
|
|
|
def __item_strval_optkeys(id)
|
|
super(id) << 'shadow'
|
|
end
|
|
private :__item_strval_optkeys
|
|
|
|
def tagid(tab)
|
|
if tab.kind_of?(Tk::BLT::Tabset::Tab)
|
|
tab.id
|
|
else
|
|
tab
|
|
end
|
|
end
|
|
|
|
def tagindex(tab)
|
|
if tab.kind_of?(Tk::BLT::Tabset::Tab)
|
|
tab.index
|
|
else
|
|
tab
|
|
end
|
|
end
|
|
|
|
########################################
|
|
|
|
def activate(index)
|
|
tk_send('activate', tagindex(index))
|
|
self
|
|
end
|
|
alias highlight activate
|
|
|
|
#def tabbind(tag, context, cmd=Proc.new, *args)
|
|
# _bind([path, "bind", tagid(tag)], context, cmd, *args)
|
|
# self
|
|
#end
|
|
def tabbind(tag, context, *args)
|
|
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
|
|
if TkComm._callback_entry?(args[0]) || !block_given?
|
|
cmd = args.shift
|
|
else
|
|
cmd = Proc.new
|
|
end
|
|
_bind([path, "bind", tagid(tag)], context, cmd, *args)
|
|
self
|
|
end
|
|
#def tabbind_append(tag, context, cmd=Proc.new, *args)
|
|
# _bind_append([path, "bind", tagid(tag)], context, cmd, *args)
|
|
# self
|
|
#end
|
|
def tabbind_append(tag, context, *args)
|
|
# if args[0].kind_of?(Proc) || args[0].kind_of?(Method)
|
|
if TkComm._callback_entry?(args[0]) || !block_given?
|
|
cmd = args.shift
|
|
else
|
|
cmd = Proc.new
|
|
end
|
|
_bind_append([path, "bind", tagid(tag)], context, cmd, *args)
|
|
self
|
|
end
|
|
def tabbind_remove(tag, context)
|
|
_bind_remove([path, "bind", tagid(tag)], context)
|
|
self
|
|
end
|
|
def tabbindinfo(tag, context=nil)
|
|
_bindinfo([path, "bind", tagid(tag)], context)
|
|
end
|
|
|
|
def delete(first, last=None)
|
|
tk_send('delete', tagindex(first), tagindex(last))
|
|
if first.kind_of?(Tk::BLT::Tabset::Tab)
|
|
TabID_TBL.mutex.synchronize{
|
|
TabID_TBL[@path].delete(first.id)
|
|
}
|
|
end
|
|
# middle tabs of the range are unknown
|
|
if last.kind_of?(Tk::BLT::Tabset::Tab)
|
|
TabID_TBL.mutex.synchronize{
|
|
TabID_TBL[@path].delete(last.id)
|
|
}
|
|
end
|
|
self
|
|
end
|
|
|
|
def focus(index)
|
|
tk_send('focus', tagindex(index))
|
|
self
|
|
end
|
|
|
|
def get_tab(index)
|
|
Tk::BLT::Tabset::Tab.id2obj(tk_send_without_enc('get', tagindex(index)))
|
|
end
|
|
|
|
def index(str)
|
|
num_or_str(tk_send('index', str))
|
|
end
|
|
def index_name(tab)
|
|
num_or_str(tk_send('index', '-mame', tagid(tab)))
|
|
end
|
|
|
|
def insert(pos, tab, keys={})
|
|
Tk::BLT::Tabset::Tab.new(self, tagindex(pos), tagid(tab), keys)
|
|
end
|
|
|
|
def invoke(index)
|
|
tk_send('invoke', tagindex(index))
|
|
end
|
|
|
|
def move_before(index, base_idx)
|
|
tk_send('move', tagindex(index), 'before', tagindex(base_idx))
|
|
self
|
|
end
|
|
def move_after(index, base_idx)
|
|
tk_send('move', tagindex(index), 'after', tagindex(base_idx))
|
|
self
|
|
end
|
|
|
|
def nearest(x, y)
|
|
Tk::BLT::Tabset::Tab.id2obj(num_or_str(tk_send_without_enc('nearest', x, y)))
|
|
end
|
|
|
|
def perforation_highlight(index, mode)
|
|
tk_send('perforation', 'highlight', tagindex(index), mode)
|
|
self
|
|
end
|
|
def perforation_invoke(index)
|
|
tk_send('perforation', 'invoke', tagindex(index))
|
|
end
|
|
|
|
def scan_mark(x, y)
|
|
tk_send_without_enc('scan', 'mark', x, y)
|
|
self
|
|
end
|
|
def scan_dragto(x, y)
|
|
tk_send_without_enc('scan', 'dragto', x, y)
|
|
self
|
|
end
|
|
|
|
def see(index)
|
|
tk_send('see', tagindex(index))
|
|
self
|
|
end
|
|
|
|
def size()
|
|
number(tk_send_without_enc('size'))
|
|
end
|
|
|
|
def select(index)
|
|
tk_send('select', tagindex(index))
|
|
self
|
|
end
|
|
|
|
def tab_names(pat=None)
|
|
simplelist(tk_send('tab', 'names', pat)).collect{|name|
|
|
Tk::BLT::Tabset::Tab.id2obj(name)
|
|
}
|
|
end
|
|
|
|
def tab_tearoff(index, name=None)
|
|
window(tk_send('tab', 'tearoff', tagindex(index), name))
|
|
end
|
|
|
|
def xscrollcommand(cmd=Proc.new)
|
|
configure_cmd 'scrollcommand', cmd
|
|
self
|
|
end
|
|
alias scrollcommand xscrollcommand
|
|
|
|
def xview(*index)
|
|
if index.empty?
|
|
list(tk_send_without_enc('view'))
|
|
else
|
|
tk_send_without_enc('view', *index)
|
|
self
|
|
end
|
|
end
|
|
alias view xview
|
|
alias view_moveto xview_moveto
|
|
alias view_scroll xview_scroll
|
|
|
|
alias scrollbar xscrollbar
|
|
end
|
|
end
|