1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/ext/tk/lib/tkextlib/tcllib/toolbar.rb
nagai ed6ce8b43b * ext/tk/extconf.rb: New strategy for searching Tcl/Tk libraries.
* ext/tk/*: Support new features of Tcl/Tk8.6b1 and minor bug fixes.
     ( [KNOWN BUG] Ruby/Tk on Ruby 1.9 will not work on Cygwin. )
* ext/tk/*: Unify sources between Ruby 1.8 & 1.9.
            Improve default_widget_set handling.
* ext/tk/*: Multi-TkInterpreter (multi-tk.rb) works on Ruby 1.8 & 1.9.
     ( [KNOWN BUG] On Ruby 1.8, join to a long term Thread on Tk
       callbacks may freeze. On Ruby 1.9, cannot create a second 
       master interpreter (creating slaves are OK); supported master
       interpreter is the default master interpreter only. )
* ext/tk/lib/tkextlib/*: Update supported versions of Tk extensions.
         Tcllib 1.8/Tklib 0.4.1  ==>  Tcllib 1.11.1/Tklib 0.5
         BWidgets 1.7            ==>  BWidgets 1.8
         TkTable 2.9             ==>  TkTable 2.10
         TkTreeCtrl 2005-12-02   ==>  TkTreeCtrl 2.2.9
         Tile 0.8.0/8.5.1        ==>  Tile 0.8.3/8.6b1
         IncrTcl 2005-02-14      ==>  IncrTcl 2008-12-15
         TclX 2005-02-07         ==>  TclX 2008-12-15
         Trofs 0.4.3             ==>  Trofs 0.4.4


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24063 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-12 23:08:32 +00:00

175 lines
3.3 KiB
Ruby

#
# tkextlib/tcllib/toolbar.rb
# by Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp)
#
# * Part of tcllib extension
# * toolbar widget
#
require 'tk'
require 'tkextlib/tcllib.rb'
# TkPackage.require('widget::toolbar', '1.2')
TkPackage.require('widget::toolbar')
module Tk::Tcllib
module Widget
class Toolbar < TkWindow
PACKAGE_NAME = 'widget::toolbar'.freeze
def self.package_name
PACKAGE_NAME
end
def self.package_version
begin
TkPackage.require('widget::toolbar')
rescue
''
end
end
end
module ToolbarItemConfig
include TkItemConfigMethod
end
end
end
class Tk::Tcllib::Widget::ToolbarItem < TkObject
include TkTreatTagFont
ToolbarItemID_TBL = TkCore::INTERP.create_table
TkCore::INTERP.init_ip_env{
TTagID_TBL.mutex.synchronize{ TTagID_TBL.clear }
}
def ToolbarItem.id2obj(tbar, id)
tpath = tbar.path
ToolbarItemID_TBL.mutex.synchronize{
if ToolbarItemID_TBL[tpath]
ToolbarItemID_TBL[tpath][id]? ToolbarItemID_TBL[tpath][id]: id
else
id
end
}
end
def initaialize(parent, *args)
@parent = @t = parent
@tpath = parent.path
@path = @id = @t.tk_send('add', *args)
# A same id is rejected by the Tcl function.
ToolbarItemID_TBL.mutex.synchronize{
ToolbarItemID_TBL[@id] = self
ToolbarItemID_TBL[@tpath] = {} unless ToolbarItemID_TBL[@tpath]
ToolbarItemID_TBL[@tpath][@id] = self
}
end
def [](key)
cget key
end
def []=(key,val)
configure key, val
val
end
def cget_tkstring(option)
@t.itemcget_tkstring(@id, option)
end
def cget(option)
@t.itemcget(@id, option)
end
def cget_strict(option)
@t.itemcget_strict(@id, option)
end
def configure(key, value=None)
@t.itemconfigure(@id, key, value)
self
end
def configinfo(key=nil)
@t.itemconfiginfo(@id, key)
end
def current_configinfo(key=nil)
@t.current_itemconfiginfo(@id, key)
end
def delete
@t.delete(@id)
end
def itemid
@t.itemid(@id)
end
def remove
@t.remove(@id)
end
def remove_with_destroy
@t.remove_with_destroy(@id)
end
end
class Tk::Tcllib::Widget::Toolbar
include Tk::Tcllib::Widget::ToolbarItemConfig
TkCommandNames = ['::widget::toolbar'.freeze].freeze
def __destroy_hook__
Tk::Tcllib::Widget::ToolbarItem::ToolbarItemID_TBL.mutex.synchronize{
Tk::Tcllib::Widget::ToolbarItem::ToolbarItemID_TBL.delete(@path)
}
end
def create_self(keys)
if keys and keys != None
tk_call_without_enc(self.class::TkCommandNames[0], @path,
*hash_kv(keys, true))
else
tk_call_without_enc(self.class::TkCommandNames[0], @path)
end
end
private :create_self
def getframe
window(tk_send('getframe'))
end
alias get_frame getframe
def add(*args)
Tk::Tcllib::Widget::Toolbar.new(self, *args)
end
def itemid(item)
window(tk_send('itemid'))
end
def items(pattern)
tk_split_simplelist(tk_send('items', pattern)).map{|id|
Tk::Tcllib::Widget::ToolbarItem.id2obj(self, id)
}
end
def remove(*items)
tk_send('remove', *items)
self
end
def remove_with_destroy(*items)
tk_send('remove', '-destroy', *items)
self
end
def delete(*items)
tk_send('delete', *items)
self
end
end