From 3024ffdc3a5fdb115de651edae9e3d7a335a6614 Mon Sep 17 00:00:00 2001 From: nagai Date: Sat, 29 Mar 2008 05:25:12 +0000 Subject: * ext/tk/*: full update Ruby/Tk to support Ruby(1.9|1.8) and Tc/Tk8.5. * ext/tk/lib/tkextlib/tile.rb: [incompatible] remove TileWidgets' instate/state/identify method to avoid the conflict with standard widget options. Those methods are renamed to ttk_instate/ttk_state/ ttk_identify (tile_instate/tile_state/tile_identify are available too). Although I don't recommend, if you realy need old methods, please define "Tk::USE_OBSOLETE_TILE_STATE_METHOD = true" before "require 'tkextlib/tile'". * ext/tk/lib/tkextlib/tile.rb: "Tk::Tile::__Import_Tile_Widgets__!" is obsolete. It outputs warning. To control default widget set, use "Tk.default_widget_set = :Ttk". * ext/tk/lib/tk.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind as module methods of TkConfigMethod. It may help users to wrap old Ruby/Tk scripts (use standard widgets) to force to use Ttk widgets. Ttk widgets don't have some options of standard widgets which are control the view of widgets. When set ignore-mode true, configure method tries to ignoure such unknown options with no exception. Of course, it may raise other troubles on the GUI design. So, those are a little danger methods. * ext/tk/lib/tk/itemconfig.rb: __IGNORE_UNKNOWN_CONFIGURE_OPTION__ method and __set_IGNORE_UNKNOWN_CONFIGURE_OPTION__!(mode) method are defind as module methods of TkItemConfigMethod as the same purpose as TkConfigMethod's ones. * ext/tk/sample/ttk_wrapper.rb: A new example. This is a tool for wrapping old Ruby/Tk scripts (which use standard widgets) to use Ttk (Tile) widgets as default. * ext/tk/sample/tkextlib/tile/demo.rb: use ttk_instate/ttk_state method instead of instate/state method. * ext/tk/lib/tk/root, ext/tk/lib/tk/namespace.rb, ext/tk/lib/tk/text.rb, ext/tk/lib/tkextlib/*: some 'instance_eval's are replaced to "instance_exec(self)". * ext/tk/lib/tk/event.rb: bug fix on KEY_TBL and PROC_TBL (?x is not a character code on Ruby1.9). * ext/tk/lib/tk/variable.rb: support new style of operation argument on Tcl/Tk's 'trace' command for variables. * ext/tk/sample/demos-jp/widget, ext/tk/sample/demos-en/widget: bug fix * ext/tk/sammple/demos-jp/textpeer.rb, ext/tk/sammple/demos-en/textpeer.rb: new widget demo. * ext/tk/tcltklib.c: decrase SEGV troubles (probably) * ext/tk/lib/tk.rb: remove Thread.critical access if Ruby1.9 * ext/tk/lib/tk/multi-tk.rb: support Ruby1.9 (probably) * ext/tk/lib/tkextlib/tile.rb: add method to define Tcl/Tk command to make Tcl/Tk theme sources (based on different version of Tile extension) available. (Tk::Tile::__define_LoadImages_proc_for_comaptibility__) * ext/tk/lib/tk.rb, ext/tk/lib/tk/wm.rb: support dockable frames (Tcl/Tk8.5 feature). 'wm' command can treat many kinds of widgets as toplevel widgets. * ext/tk/lib/tkextlib/tile/style.rb: ditto. (Tk::Tile::Style.__define_wrapper_proc_for_compatibility__) * ext/tk/lib/tk/font.rb: add actual_hash and metrics_hash to get properties as a hash. metrics_hash method returns a boolean value for 'fixed' option. But metrics method returns numeric value (0 or 1) for 'fixed' option, because of backward compatibility. * ext/tk/lib/tk/timer.rb: somtimes fail to set callback procedure. * ext/tk/lib/tk.rb: add Tk.sleep and Tk.wakeup method. Tk.sleep doesn't block the eventloop. It will be better to use the method in event callbacks. * ext/tk/sample/tksleep_sample.rb: sample script about Tk.sleep. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/tk/lib/tkextlib/SUPPORT_STATUS | 2 +- ext/tk/lib/tkextlib/blt/bitmap.rb | 21 +- ext/tk/lib/tkextlib/blt/component.rb | 351 ++++++++++++++++++++----- ext/tk/lib/tkextlib/blt/dragdrop.rb | 48 ++++ ext/tk/lib/tkextlib/blt/tabset.rb | 77 ++++-- ext/tk/lib/tkextlib/blt/tree.rb | 341 ++++++++++++++++-------- ext/tk/lib/tkextlib/blt/treeview.rb | 197 ++++++++++---- ext/tk/lib/tkextlib/blt/vector.rb | 37 ++- ext/tk/lib/tkextlib/blt/watch.rb | 28 +- ext/tk/lib/tkextlib/bwidget/buttonbox.rb | 16 +- ext/tk/lib/tkextlib/bwidget/combobox.rb | 8 +- ext/tk/lib/tkextlib/bwidget/dialog.rb | 24 +- ext/tk/lib/tkextlib/bwidget/labelframe.rb | 8 +- ext/tk/lib/tkextlib/bwidget/listbox.rb | 34 ++- ext/tk/lib/tkextlib/bwidget/mainframe.rb | 48 +++- ext/tk/lib/tkextlib/bwidget/messagedlg.rb | 5 +- ext/tk/lib/tkextlib/bwidget/notebook.rb | 24 +- ext/tk/lib/tkextlib/bwidget/pagesmanager.rb | 16 +- ext/tk/lib/tkextlib/bwidget/panedwindow.rb | 8 +- ext/tk/lib/tkextlib/bwidget/panelframe.rb | 8 +- ext/tk/lib/tkextlib/bwidget/progressdlg.rb | 4 + ext/tk/lib/tkextlib/bwidget/scrollableframe.rb | 8 +- ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb | 8 +- ext/tk/lib/tkextlib/bwidget/selectcolor.rb | 28 ++ ext/tk/lib/tkextlib/bwidget/selectfont.rb | 7 +- ext/tk/lib/tkextlib/bwidget/statusbar.rb | 8 +- ext/tk/lib/tkextlib/bwidget/titleframe.rb | 8 +- ext/tk/lib/tkextlib/bwidget/tree.rb | 34 ++- ext/tk/lib/tkextlib/bwidget/widget.rb | 8 +- ext/tk/lib/tkextlib/itcl/incr_tcl.rb | 12 +- ext/tk/lib/tkextlib/itk/incr_tk.rb | 44 +++- ext/tk/lib/tkextlib/iwidgets/calendar.rb | 17 ++ ext/tk/lib/tkextlib/iwidgets/entryfield.rb | 17 ++ ext/tk/lib/tkextlib/iwidgets/hierarchy.rb | 50 ++++ ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb | 10 +- ext/tk/lib/tkextlib/iwidgets/spinner.rb | 17 ++ ext/tk/lib/tkextlib/tcllib/ico.rb | 6 +- ext/tk/lib/tkextlib/tcllib/plotchart.rb | 45 +++- ext/tk/lib/tkextlib/tcllib/tkpiechart.rb | 14 +- ext/tk/lib/tkextlib/tile.rb | 142 ++++++++-- ext/tk/lib/tkextlib/tile/style.rb | 134 +++++++++- ext/tk/lib/tkextlib/tile/treeview.rb | 130 ++++++--- ext/tk/lib/tkextlib/tkDND/tkdnd.rb | 16 ++ ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb | 17 +- ext/tk/lib/tkextlib/tktable/tktable.rb | 167 +++++++++--- ext/tk/lib/tkextlib/treectrl/tktreectrl.rb | 233 +++++++++++----- ext/tk/lib/tkextlib/version.rb | 2 +- ext/tk/lib/tkextlib/vu/pie.rb | 73 +++-- ext/tk/lib/tkextlib/winico/winico.rb | 49 +++- 49 files changed, 2064 insertions(+), 545 deletions(-) (limited to 'ext/tk/lib/tkextlib') diff --git a/ext/tk/lib/tkextlib/SUPPORT_STATUS b/ext/tk/lib/tkextlib/SUPPORT_STATUS index 15925cba72..cfbe274c86 100644 --- a/ext/tk/lib/tkextlib/SUPPORT_STATUS +++ b/ext/tk/lib/tkextlib/SUPPORT_STATUS @@ -83,7 +83,7 @@ BLT 2.4z http://sourceforge.net/projects/blt TkTreeCtrl CVS/Hd(2005-12-02) http://sourceforge.net/projects/tktreectrl ==> treectrl -Tile 0.7.8 +Tile 0.8.0/8.5.1 http://sourceforge.net/projects/tktable ==> tile diff --git a/ext/tk/lib/tkextlib/blt/bitmap.rb b/ext/tk/lib/tkextlib/blt/bitmap.rb index 31cf8d4229..23c6d2d064 100644 --- a/ext/tk/lib/tkextlib/blt/bitmap.rb +++ b/ext/tk/lib/tkextlib/blt/bitmap.rb @@ -13,7 +13,16 @@ module Tk::BLT TkCommandNames = ['::blt::bitmap'.freeze].freeze BITMAP_ID_TBL = TkCore::INTERP.create_table - BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint].freeze + + (BITMAP_ID = ['blt_bitmap_id'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + BITMAP_ID_TBL.mutex.synchronize{ BITMAP_ID_TBL.clear } + } def self.data(name) dat = tk_simple_list(tk_call('::blt::bitmap', 'data', name)) @@ -64,9 +73,13 @@ module Tk::BLT if name @id = name else - @id = BITMAP_ID.join(TkCore::INTERP._ip_id_) - BITMAP_ID[1].succ! - BITMAP_ID_TBL[@id] = self + BITMAP_ID.mutex.synchronize{ + @id = BITMAP_ID.join(TkCore::INTERP._ip_id_) + BITMAP_ID[1].succ! + } + BITMAP_ID_TBL.mutex.synchronize{ + BITMAP_ID_TBL[@id] = self + } end @path = @id diff --git a/ext/tk/lib/tkextlib/blt/component.rb b/ext/tk/lib/tkextlib/blt/component.rb index ad78a5430b..dd387634ee 100644 --- a/ext/tk/lib/tkextlib/blt/component.rb +++ b/ext/tk/lib/tkextlib/blt/component.rb @@ -327,13 +327,24 @@ module Tk::BLT ################# class Axis < TkObject - OBJ_ID = ['blt_chart_axis'.freeze, '00000'.taint].freeze - OBJ_TBL={} + (OBJ_ID = ['blt_chart_axis'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + AxisID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ + AxisID_TBL.mutex.synchronize{ AxisID_TBL.clear } + } def self.id2obj(chart, id) cpath = chart.path - return id unless OBJ_TBL[cpath] - OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id + AxisID_TBL.mutex.synchronize{ + return id unless AxisID_TBL[cpath] + AxisID_TBL[cpath][id]? AxisID_TBL[cpath][id]: id + } end def self.new(chart, axis=nil, keys={}) @@ -341,12 +352,48 @@ module Tk::BLT keys = axis axis = nil end - OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path] - return OBJ_TBL[chart.path][axis] if axis && OBJ_TBL[chart.path][axis] - super(chart, axis, keys) + if keys + keys = _symbolkey2str(keys) + not_create = keys.delete('without_creating') + else + not_create = false + end + + obj = nil + AxisID_TBL.mutex.synchronize{ + chart_path = chart.path + AxisID_TBL[chart_path] ||= {} + if axis && AxisID_TBL[chart_path][axis] + obj = AxisID_TBL[chart_path][axis] + else + (obj = self.allocate).instance_eval{ + if axis + @axis = @id = axis.to_s + else + OBJ_ID.mutex.synchronize{ + @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze + OBJ_ID[1].succ! + } + end + @path = @id + @parent = @chart = chart + @cpath = @chart.path + Axis::AxisID_TBL[@cpath][@axis] = self + unless not_create + tk_call(@chart, 'axis', 'create', @axis, keys) + return obj + end + } + end + } + + obj.configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, axis=nil, keys={}) + # dummy:: not called by 'new' method + if axis.kind_of?(Hash) keys = axis axis = nil @@ -354,13 +401,15 @@ module Tk::BLT if axis @axis = @id = axis.to_s else - @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze - OBJ_ID[1].succ! + OBJ_ID.mutex.synchronize{ + @axis = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze + OBJ_ID[1].succ! + } end @path = @id @parent = @chart = chart @cpath = @chart.path - Axis::OBJ_TBL[@cpath][@axis] = self + # Axis::AxisID_TBL[@cpath][@axis] = self keys = _symbolkey2str(keys) unless keys.delete('without_creating') # @chart.axis_create(@axis, keys) @@ -438,17 +487,34 @@ module Tk::BLT ################# class Crosshairs < TkObject - OBJ_TBL={} + CrosshairsID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ + CrosshairsID_TBL.mutex.synchronize{ CrosshairsID_TBL.clear } + } def self.new(chart, keys={}) - return OBJ_TBL[chart.path] if OBJ_TBL[chart.path] - super(chart, keys) + obj = nil + CrosshairsID_TBL.mutex.synchronize{ + unless (obj = CrosshairsID_TBL[chart.path]) + (obj = self.allocate).instance_eval{ + @parent = @chart = chart + @cpath = @chart.path + @path = @id = 'crosshairs' + Crosshairs::CrosshairsID_TBL[@cpath] = self + } + end + } + chart.crosshair_configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, keys={}) + # dummy:: not called by 'new' method + @parent = @chart = chart @cpath = @chart.path - Crosshairs::OBJ_TBL[@cpath] = self + # Crosshairs::CrosshairsID_TBL[@cpath] = self @chart.crosshair_configure(keys) unless keys.empty? @path = @id = 'crosshairs' end @@ -500,12 +566,18 @@ module Tk::BLT ElementTypeName = 'element' ElementTypeToClass = { ElementTypeName=>self } + ElementID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ ElementID_TBL.clear } + TkCore::INTERP.init_ip_env{ + ElementID_TBL.mutex.synchronize{ ElementID_TBL.clear } + } - OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint].freeze - OBJ_TBL={} + (OBJ_ID = ['blt_chart_element'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } def Element.type2class(type) ElementTypeToClass[type] @@ -513,8 +585,10 @@ module Tk::BLT def Element.id2obj(chart, id) cpath = chart.path - return id unless OBJ_TBL[cpath] - OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id + ElementID_TBL.mutex.synchronize{ + return id unless ElementID_TBL[cpath] + ElementID_TBL[cpath][id]? ElementID_TBL[cpath][id]: id + } end def self.new(chart, element=nil, keys={}) @@ -522,14 +596,49 @@ module Tk::BLT keys = element element = nil end - OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path] - if element && OBJ_TBL[chart.path][element] - return OBJ_TBL[chart.path][element] + if keys + keys = _symbolkey2str(keys) + not_create = keys.delete('without_creating') + else + not_create = false end - super(chart, element, keys) + + obj = nil + ElementID_TBL.mutex.synchronize{ + chart_path = chart.path + ElementID_TBL[chart_path] ||= {} + if element && ElementID_TBL[chart_path][element] + obj = ElementID_TBL[chart_path][element] + else + (obj = self.allocate).instance_eval{ + if element + @element = @id = element.to_s + else + OBJ_ID.mutex.synchronize{ + @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze + OBJ_ID[1].succ! + } + end + @path = @id + @parent = @chart = chart + @cpath = @chart.path + @typename = self.class::ElementTypeName + Element::ElementID_TBL[@cpath][@element] = self + unless not_create + tk_call(@chart, @typename, 'create', @element, keys) + return obj + end + } + end + } + + obj.configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, element=nil, keys={}) + # dummy:: not called by 'new' method + if element.kind_of?(Hash) keys = element element = nil @@ -537,14 +646,16 @@ module Tk::BLT if element @element = @id = element.to_s else - @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze - OBJ_ID[1].succ! + OBJ_ID.mutex.synchronize{ + @element = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze + OBJ_ID[1].succ! + } end @path = @id @parent = @chart = chart @cpath = @chart.path @typename = self.class::ElementTypeName - Element::OBJ_TBL[@cpath][@element] = self + # Element::ElementID_TBL[@cpath][@element] = self keys = _symbolkey2str(keys) unless keys.delete('without_creating') # @chart.element_create(@element, keys) @@ -622,17 +733,33 @@ module Tk::BLT ################# class GridLine < TkObject - OBJ_TBL={} + GridLineID_TBL = TkCore::INTERP.create_table + TkCore::INTERP.init_ip_env{ + GridLineID_TBL.mutex.synchronize{ GridLineID_TBL.clear } + } def self.new(chart, keys={}) - return OBJ_TBL[chart.path] if OBJ_TBL[chart.path] - super(chart, keys) + obj = nil + GridLineID_TBL.mutex.synchronize{ + unless (obj = GridLineID_TBL[chart.path]) + (obj = self.allocate).instance_eval{ + @parent = @chart = chart + @cpath = @chart.path + @path = @id = 'grid' + GridLine::GridLineID_TBL[@cpath] = self + } + end + } + chart.gridline_configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, keys={}) + # dummy:: not called by 'new' method + @parent = @chart = chart @cpath = @chart.path - GridLine::OBJ_TBL[@cpath] = self + # GridLine::GridLineID_TBL[@cpath] = self @chart.gridline_configure(keys) unless keys.empty? @path = @id = 'grid' end @@ -676,18 +803,35 @@ module Tk::BLT ################# class Legend < TkObject - OBJ_TBL={} + LegendID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ + LegendID_TBL.mutex.synchronize{ LegendID_TBL.clear } + } def self.new(chart, keys={}) - return OBJ_TBL[chart.path] if OBJ_TBL[chart.path] - super(chart, keys) + obj = nil + LegenedID_TBL.mutex.synchronize{ + unless (obj = LegenedID_TBL[chart.path]) + (obj = self.allocate).instance_eval{ + @parent = @chart = chart + @cpath = @chart.path + @path = @id = 'crosshairs' + Legend::LegenedID_TBL[@cpath] = self + } + end + } + chart.legend_configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, keys={}) + # dummy:: not called by 'new' method + @parent = @chart = chart @cpath = @chart.path - Crosshairs::OBJ_TBL[@cpath] = self - @chart.crosshair_configure(keys) unless keys.empty? + # Legend::LegendID_TBL[@cpath] = self + @chart.legend_configure(keys) unless keys.empty? @path = @id = 'legend' end @@ -729,13 +873,24 @@ module Tk::BLT ################# class Pen < TkObject - OBJ_ID = ['blt_chart_pen'.freeze, '00000'.taint].freeze - OBJ_TBL={} + (OBJ_ID = ['blt_chart_pen'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + PenID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ + PenID_TBL.mutex.synchronize{ PenID_TBL.clear } + } def self.id2obj(chart, id) cpath = chart.path - return id unless OBJ_TBL[cpath] - OBJ_TBL[cpath][id]? OBJ_TBL[cpath][id]: id + PenID_TBL.mutex.synchronize{ + return id unless PenID_TBL[cpath] + PenID_TBL[cpath][id]? PenID_TBL[cpath][id]: id + } end def self.new(chart, pen=nil, keys={}) @@ -743,9 +898,43 @@ module Tk::BLT keys = pen pen = nil end - OBJ_TBL[chart.path] = {} unless OBJ_TBL[chart.path] - return OBJ_TBL[chart.path][pen] if pen && OBJ_TBL[chart.path][pen] - super(chart, pen, keys) + if keys + keys = _symbolkey2str(keys) + not_create = keys.delete('without_creating') + else + not_create = false + end + + obj = nil + PenID_TBL.mutex.synchronize{ + chart_path = chart.path + PenID_TBL[chart_path] ||= {} + if pen && PenID_TBL[chart_path][pen] + obj = PenID_TBL[chart_path][pen] + else + (obj = self.allocate).instance_eval{ + if pen + @pen = @id = pen.to_s + else + OBJ_ID.mutex.synchronize{ + @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze + OBJ_ID[1].succ! + } + end + @path = @id + @parent = @chart = chart + @cpath = @chart.path + Pen::PenID_TBL[@cpath][@pen] = self + unless not_create + tk_call(@chart, 'pen', 'create', @pen, keys) + return obj + end + } + end + } + + obj.configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, pen=nil, keys={}) @@ -756,13 +945,15 @@ module Tk::BLT if pen @pen = @id = pen.to_s else - @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze - OBJ_ID[1].succ! + OBJ_ID.mutex.synchronize{ + @pen = @id = OBJ_ID.join(TkCore::INTERP._ip_id_).freeze + OBJ_ID[1].succ! + } end @path = @id @parent = @chart = chart @cpath = @chart.path - Pen::OBJ_TBL[@cpath][@pen] = self + Pen::PenID_TBL[@cpath][@pen] = self keys = _symbolkey2str(keys) unless keys.delete('without_creating') # @chart.pen_create(@pen, keys) @@ -805,17 +996,34 @@ module Tk::BLT ################# class Postscript < TkObject - OBJ_TBL={} + PostscriptID_TBL = TkCore::INTERP.create_table + + TkCore::INTERP.init_ip_env{ + PostscriptID_TBL.mutex.synchronize{ PostscriptID_TBL.clear } + } def self.new(chart, keys={}) - return OBJ_TBL[chart.path] if OBJ_TBL[chart.path] - super(chart, keys) + obj = nil + PostscriptID_TBL.mutex.synchronize{ + unless (obj = PostscriptID_TBL[chart.path]) + (obj = self.allocate).instance_eval{ + @parent = @chart = chart + @cpath = @chart.path + @path = @id = 'postscript' + Postscript::PostscriptID_TBL[@cpath] = self + } + end + } + chart.postscript_configure(keys) if obj && ! keys.empty? + obj end def initialize(chart, keys={}) + # dummy:: not called by 'new' method + @parent = @chart = chart @cpath = @chart.path - Postscript::OBJ_TBL[@cpath] = self + # Postscript::PostscriptID_TBL[@cpath] = self @chart.postscript_configure(keys) unless keys.empty? @path = @id = 'postscript' end @@ -870,7 +1078,9 @@ module Tk::BLT MarkerTypeToClass = {} MarkerID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ MarkerID_TBL.clear } + TkCore::INTERP.init_ip_env{ + MarkerID_TBL.mutex.synchronize{ MarkerID_TBL.clear } + } def Marker.type2class(type) MarkerTypeToClass[type] @@ -878,8 +1088,13 @@ module Tk::BLT def Marker.id2obj(chart, id) cpath = chart.path - return id unless MarkerID_TBL[cpath] - MarkerID_TBL[cpath][id]? MarkerID_TBL[cpath][id]: id + MarkerID_TBL.mutex.synchronize{ + if MarkerID_TBL[cpath] + MarkerID_TBL[cpath][id]? MarkerID_TBL[cpath][id]: id + else + id + end + } end def self._parse_create_args(keys) @@ -943,10 +1158,10 @@ module Tk::BLT @parent = @chart = chart @cpath = chart.path @id = id - unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] - Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {} - end - Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self + Tk::BLT::PlotComponent::Marker::MarkerID_TBL.mutex.synchronize{ + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] ||= {} + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self + } } obj end @@ -956,10 +1171,10 @@ module Tk::BLT @cpath = parent.path @path = @id = create_self(*args) # an integer number as 'item id' - unless Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] - Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] = {} - end - Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self + Tk::BLT::PlotComponent::Marker::MarkerID_TBL.mutex.synchronize{ + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath] ||= {} + Tk::BLT::PlotComponent::Marker::MarkerID_TBL[@cpath][@id] = self + } end def create_self(*args) self.class.create(@chart, *args) # return an integer as 'item id' @@ -1037,14 +1252,14 @@ module Tk::BLT ################# def __destroy_hook__ - Axis::OBJ_TBL.delete(@path) - Crosshairs::OBJ_TBL.delete(@path) - Element::OBJ_TBL.delete(@path) - GridLine::OBJ_TBL.delete(@path) - Legend::OBJ_TBL.delete(@path) - Pen::OBJ_TBL.delete(@path) - Postscript::OBJ_TBL.delete(@path) - Marker::OBJ_TBL.delete(@path) + Axis::AxisID_TBL.delete(@path) + Crosshairs::CrosshairsID_TBL.delete(@path) + Element::ElementID_TBL.delete(@path) + GridLine::GridLineID_TBL.delete(@path) + Legend::LegendID_TBL.delete(@path) + Pen::PenID_TBL.delete(@path) + Postscript::PostscriptID_TBL.delete(@path) + Marker::MarkerID_TBL.delete(@path) super() end diff --git a/ext/tk/lib/tkextlib/blt/dragdrop.rb b/ext/tk/lib/tkextlib/blt/dragdrop.rb index 68fb9e591a..98b1a4832f 100644 --- a/ext/tk/lib/tkextlib/blt/dragdrop.rb +++ b/ext/tk/lib/tkextlib/blt/dragdrop.rb @@ -81,6 +81,22 @@ module Tk::BLT nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL) def self.ret_val(val) @@ -107,6 +123,22 @@ module Tk::BLT nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL) def self.ret_val(val) @@ -145,6 +177,22 @@ module Tk::BLT nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL) end diff --git a/ext/tk/lib/tkextlib/blt/tabset.rb b/ext/tk/lib/tkextlib/blt/tabset.rb index c26b6ee001..1a0f312c4c 100644 --- a/ext/tk/lib/tkextlib/blt/tabset.rb +++ b/ext/tk/lib/tkextlib/blt/tabset.rb @@ -12,14 +12,26 @@ module Tk::BLT include TkTreatItemFont TabID_TBL = TkCore::INTERP.create_table - TabsetTab_ID = ['blt_tabset_tab'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ TabID_TBL.clear } + (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 - return id unless TabID_TBL[tpath] - TabID_TBL[tpath][id]? TabID_TBL[tpath]: id + 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={}) @@ -32,12 +44,20 @@ module Tk::BLT keys = name name = nil end - - if name && TabID_TBL[parent.path] && TabID_TBL[parent.path][name] - TabID_TBL[parent.path][name] - else - super(parent, pos, name, keys) - 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) @@ -45,9 +65,6 @@ module Tk::BLT @tpath = parent.path if name @path = @id = name - TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath] - TabID_TBL[@tpath][@id] = self - unless (list(tk_call(@tpath, 'tab', 'names', @id)).empty?) if pos idx = tk_call(@tpath, 'index', '-name', @id) @@ -58,18 +75,18 @@ module Tk::BLT end end tk_call(@tpath, 'tab', 'configure', @id, keys) - return + else + pos = 'end' unless pos + tk_call(@tpath, 'insert', pos, @id, keys) end - else - @path = @id = TabsetTab_ID.join(TkCore::INTERP._ip_id_) - TabID_TBL[@tpath] = {} unless TabID_TBL[@tpath] - TabID_TBL[@tpath][@id] = self - TabsetTab_ID[1].succ! + 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 - - pos = 'end' unless pos - tk_call(@tpath, 'insert', pos, @id, keys) end #def bind(context, cmd=Proc.new, *args) @@ -123,7 +140,9 @@ module Tk::BLT def delete() @t.delete(@id) - TabID_TBL[@tpath].delete(@id) + TabID_TBL.mutex.synchronize{ + TabID_TBL[@tpath].delete(@id) + } self end @@ -184,7 +203,9 @@ module Tk::BLT WidgetClassNames[WidgetClassName] = self def __destroy_hook__ - Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path) + Tk::BLT::Tabset::Tab::TabID_TBL.mutex.synchronize{ + Tk::BLT::Tabset::Tab::TabID_TBL.delete(@path) + } end ######################################## @@ -291,11 +312,15 @@ module Tk::BLT def delete(first, last=None) tk_send('delete', tagindex(first), tagindex(last)) if first.kind_of?(Tk::BLT::Tabset::Tab) - TabID_TBL[@path].delete(first.id) + 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[@path].delete(last.id) + TabID_TBL.mutex.synchronize{ + TabID_TBL[@path].delete(last.id) + } end self end diff --git a/ext/tk/lib/tkextlib/blt/tree.rb b/ext/tk/lib/tkextlib/blt/tree.rb index 07dc7ef7e8..77b85f1717 100644 --- a/ext/tk/lib/tkextlib/blt/tree.rb +++ b/ext/tk/lib/tkextlib/blt/tree.rb @@ -12,53 +12,77 @@ module Tk::BLT ################################### - class Node < TkObject + class Node < TkObject TreeNodeID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear } + + TkCore::INTERP.init_ip_env{ + TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear } + } def self.id2obj(tree, id) tpath = tree.path - return id unless TreeNodeID_TBL[tpath] - if TreeNodeID_TBL[tpath][id] - TreeNodeID_TBL[tpath][id] - else - begin - self.new(tree, nil, 'node'=>Integer(id)) - rescue + TreeNodeID_TBL.mutex.synchronize{ + if TreeNodeID_TBL[tpath] + if TreeNodeID_TBL[tpath][id] + TreeNodeID_TBL[tpath][id] + else + begin + # self.new(tree, nil, 'node'=>Integer(id)) + id = Integer(id) + if bool(tk_call(@tpath, 'exists', id)) + (obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = tpath + @path = @id = id + TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath] + TreeNodeID_TBL[@tpath][@id] = self + } + obj + else + id + end + rescue + id + end + end + else id end - end + } end def self.new(tree, parent, keys={}) keys = _symbolkey2str(keys) tpath = tree.path - if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id]) - keys.delete('node') - tk_call(tree.path, 'move', id, parent, keys) if parent - return obj - end + TreeNodeID_TBL.mutex.synchronize{ + TreeNodeID_TBL[tpath] ||= {} + if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id]) + keys.delete('node') + tk_call(tree.path, 'move', id, parent, keys) if parent + return obj + end - super(tree, parent, keys) + (obj = self.allocate).instance_eval{ + initialize(tree, parent, keys) + TreeNodeID_TBL[tpath][@id] = self + } + obj + } end def initialize(tree, parent, keys={}) @parent = @tree = tree @tpath = @parent.path - parent = tk_call(@tpath, 'root') unless parent - if (id = keys['node']) && bool(tk_call(@tpath, 'exists', id)) @path = @id = id keys.delete('node') tk_call(@tpath, 'move', @id, parent, keys) if parent else + parent = tk_call(@tpath, 'root') unless parent @path = @id = tk_call(@tpath, 'insert', parent, keys) end - - TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath] - TreeNodeID_TBL[@tpath][@id] = self end def id @@ -243,17 +267,42 @@ module Tk::BLT class Tag < TkObject TreeTagID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear } - TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint].freeze + + TkCore::INTERP.init_ip_env{ + TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear } + } + + (TreeTag_ID = ['blt_tree_tag'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } def self.id2obj(tree, id) tpath = tree.path - return id unless TreeTagID_TBL[tpath] - if TreeTagID_TBL[tpath][id] - TreeTagID_TBL[tpath][id] - else - self.new(tree, id) - end + TreeTagID_TBL.mutex.synchronize{ + if TreeTagID_TBL[tpath] + if TreeTagID_TBL[tpath][id] + TreeTagID_TBL[tpath][id] + else + begin + # self.new(tree, id) + (obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = @parent.path + @path = @id = id.dup.freeze if id + TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] + TreeTagID_TBL[@tpath][@id] = self + } + obj + rescue + id + end + end + else + id + end + } end def initialize(tree, tag_str = nil) @@ -263,12 +312,15 @@ module Tk::BLT if tag_str @path = @id = tag_str.dup.freeze else - @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_) - TreeTagID_TBL[@id] = self - TreeTag_ID[1].succ! + TreeTag_ID.mutex.synchronize{ + @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_) + TreeTag_ID[1].succ! + } end - TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] - TreeTagID_TBL[@tpath][@id] = self + TreeTagID_TBL.mutex.synchronize{ + TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] + TreeTagID_TBL[@tpath][@id] = self + } end def id @@ -287,7 +339,9 @@ module Tk::BLT def forget() tk_call(@tpath, 'tag', 'forget', @id) - TreeTagID_TBL[@tpath].delete(@id) + TreeTagID_TBL.mutex.synchronize{ + TreeTagID_TBL[@tpath].delete(@id) + } self end @@ -312,44 +366,63 @@ module Tk::BLT class Notify < TkObject NotifyID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ NotifyID_TBL.clear } + + TkCore::INTERP.init_ip_env{ + NotifyID_TBL.mutex.synchronize{ NotifyID_TBL.clear } + } def self.id2obj(tree, id) tpath = tree.path - return id unless NotifyID_TBL[tpath] - if NotifyID_TBL[tpath][id] - NotifyID_TBL[tpath][id] - else - begin - self.new([tree, id]) - rescue - id + NotifyID_TBL.mutex.synchronize{ + if NotifyID_TBL[tpath] + if NotifyID_TBL[tpath][id] + NotifyID_TBL[tpath][id] + else + (obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = @parent.path + @path = @id = id + NotifyID_TBL[@tpath] ||= {} + NotifyID_TBL[@tpath][@id] = self + } + obj + end + else + return id end - end + } end def self.new(tree, *args, &b) - if tree.kind_of?(Array) - # not create - if obj = NotifyID_TBL[tree[0].path][tree[1]] + NotifyID_TBL.mutex.synchronize{ + if tree.kind_of?(Array) + # not create + tpath = tree[0].path + NotifyID_TBL[tpath] ||= {} + unless (obj = NotifyID_TBL[tpath][tree[1]]) + (NotifyID_TBL[tpath][tree[1]] = + obj = self.allocate).instance_eval{ + @parent = @tree = tree[0] + @tpath = @parent.path + @path = @id = tree[1] + } + end return obj - else - return super(false, tree[0], tree[1]) end - end - super(true, tree, *args, &b) + (obj = self.allocate).instance_eval{ + initialize(tree, *args, &b) + NotifyID_TBL[@tpath] ||= {} + NotifyID_TBL[@tpath][@id] = self + } + return obj + } end - def initialize(create, tree, *args, &b) + def initialize(tree, *args, &b) @parent = @tree = tree @tpath = @parent.path - unless create - @path = @id = args[0] - return - end - # if args[0].kind_of?(Proc) || args[0].kind_of?(Method) if TkComm._callback_entry?(args[0]) cmd = args.shift @@ -378,7 +451,9 @@ module Tk::BLT def delete() tk_call(@tpath, 'notify', 'delete', @id) - NotifyID_TBL[tpath].delete(@id) + NotifyID_TBL.mutex.synchronize{ + NotifyID_TBL[@tpath].delete(@id) + } self end @@ -395,44 +470,69 @@ module Tk::BLT class Trace < TkObject TraceID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ TraceID_TBL.clear } + + TkCore::INTERP.init_ip_env{ + TraceID_TBL.mutex.synchronize{ TraceID_TBL.clear } + } def self.id2obj(tree, id) tpath = tree.path - return id unless TraceID_TBL[tpath] - if TraceID_TBL[tpath][id] - TraceID_TBL[tpath][id] - else - begin - self.new([tree, id]) - rescue + TraceID_TBL.mutex.synchronize{ + if TraceID_TBL[tpath] + if TraceID_TBL[tpath][id] + TraceID_TBL[tpath][id] + else + begin + # self.new([tree, id]) + (obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = @parent.path + @path = @id = node # == traceID + TraceID_TBL[@tpath] ||= {} + TraceID_TBL[@tpath][@id] = self + } + obj + rescue + id + end + end + else id end - end + } end def self.new(tree, *args, &b) - if tree.kind_of?(Array) - # not create - if obj = TraceID_TBL[tree[0].path][tree[1]] + TraceID_TBL.mutex.synchronize{ + if tree.kind_of?(Array) + # not create + tpath = tree[0].path + TraceID_TBL[tpath] ||= {} + unless (obj = TraceID_TBL[tpath][tree[1]]) + (TraceID_TBL[tpath][tree[1]] = + obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = @parent.path + @path = @id = tree[1] # == traceID + } + end return obj - else - return super(false, tree[0], tree[1]) end - end - super(true, tree, *args, &b) + # super(true, tree, *args, &b) + (obj = self.allocate).instance_eval{ + initialize(tree, *args, &b) + TraceID_TBL[@tpath] ||= {} + TraceID_TBL[@tpath][@id] = self + } + return obj + } end - def initialize(create, tree, node, key, opts, cmd=nil, &b) + def initialize(tree, node, key, opts, cmd=nil, &b) @parent = @tree = tree @tpath = @parent.path - unless create - @path = @id = node # == traceID - return - end - if !cmd if b cmd = Proc.new(&b) @@ -459,7 +559,9 @@ module Tk::BLT def delete() tk_call(@tpath, 'trace', 'delete', @id) - TraceID_TBL[tpath].delete(@id) + TraceID_TBL.mutex.synchronize{ + TraceID_TBL[tpath].delete(@id) + } self end @@ -475,7 +577,12 @@ module Tk::BLT ################################### TreeID_TBL = TkCore::INTERP.create_table - Tree_ID = ['blt_tree'.freeze, '00000'.taint].freeze + + (Tree_ID = ['blt_tree'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } def __keyonly_optkeys { @@ -498,7 +605,9 @@ module Tk::BLT end def self.id2obj(id) - TreeID_TBL[id]? TreeID_TBL[id]: id + TreeID_TBL.mutex.synchronize{ + TreeID_TBL[id]? TreeID_TBL[id]: id + } end def self.names(pat = None) @@ -513,27 +622,45 @@ module Tk::BLT end def self.new(name = nil) - return TreeID_TBL[name] if name && TreeID_TBL[name] - super(name) + TreeID_TBL.mutex.synchronize{ + if name && TreeID_TBL[name] + TreeID_TBL[name] + else + (obj = self.allocate).instance_eval{ + initialize(name) + TreeID_TBL[@id] = self + } + obj + end + } end def initialzie(name = nil) if name @path = @id = name else - @path = @id = Tree_ID.join(TkCore::INTERP._ip_id_) - TreeID_TBL[@id] = self - Tree_ID[1].succ! + Tree_ID.mutex.synchronize{ + @path = @id = Tree_ID.join(TkCore::INTERP._ip_id_) + Tree_ID[1].succ! + } end - TreeID_TBL[@id] = self + tk_call('::blt::tree', 'create', @id) end def __destroy_hook__ - Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path) - Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path) - Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path) - Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path) + Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{ + Tk::BLT::Tree::Node::TreeNodeID_TBL.delete(@path) + } + Tk::BLT::Tree::Tag::TreeTagID_TBL.mutex.synchronize{ + Tk::BLT::Tree::Tag::TreeTagID_TBL.delete(@path) + } + Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{ + Tk::BLT::Tree::Notify::NotifyID_TBL.delete(@path) + } + Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{ + Tk::BLT::Tree::Trace::TraceID_TBL.delete(@path) + } end def tagid(tag) @@ -592,12 +719,14 @@ module Tk::BLT def delete(*nodes) tk_call('::blt::tree', 'delete', *(nodes.collect{|node| tagid(node)})) - nodes.each{|node| - if node.kind_of?(Tk::BLT::Tree::Node) - Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id) - else - Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s) - end + Tk::BLT::Tree::Node::TreeNodeID_TBL.mutex.synchronize{ + nodes.each{|node| + if node.kind_of?(Tk::BLT::Tree::Node) + Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.id) + else + Tk::BLT::Tree::Node::TreeNodeID_TBL[@path].delete(node.to_s) + end + } } self end @@ -728,7 +857,9 @@ module Tk::BLT id.delete else tk_call(@path, 'notify', 'delete', id) - Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s) + Tk::BLT::Tree::Notify::NotifyID_TBL.mutex.synchronize{ + Tk::BLT::Tree::Notify::NotifyID_TBL[@path].delete(id.to_s) + } end self end @@ -835,7 +966,9 @@ module Tk::BLT def tag_forget(tag) tag = tag.id if tag.kind_of?(Tk::BLT::Tree::Tag) tk_call(@path, 'tag', 'forget', tag) - TreeTagID_TBL[@path].delete(tag) + TreeTagID_TBL.mutex.synchronize{ + TreeTagID_TBL[@path].delete(tag) + } self end @@ -889,7 +1022,9 @@ module Tk::BLT def trace_delete(*args) args = args.collect{|id| tagid(id)} tk_call(@path, 'trace', 'delete', *args) - args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)} + Tk::BLT::Tree::Trace::TraceID_TBL.mutex.synchronize{ + args.each{|id| Tk::BLT::Tree::Trace::TraceID_TBL[@path].delete(id.to_s)} + } self end diff --git a/ext/tk/lib/tkextlib/blt/treeview.rb b/ext/tk/lib/tkextlib/blt/treeview.rb index 0343d28b9c..fc890614be 100644 --- a/ext/tk/lib/tkextlib/blt/treeview.rb +++ b/ext/tk/lib/tkextlib/blt/treeview.rb @@ -239,6 +239,22 @@ class Tk::BLT::Treeview nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -273,8 +289,12 @@ class Tk::BLT::Treeview ######################## def __destroy_hook__ - Tk::BLT::Treeview::Node::TreeNodeID_TBL.delete(@path) - Tk::BLT::Treeview::Tag::TreeTagID_TBL.delete(@path) + Tk::BLT::Treeview::Node::TreeNodeID_TBL.mutex.synchronize{ + Tk::BLT::Treeview::Node::TreeNodeID_TBL.delete(@path) + } + Tk::BLT::Treeview::Tag::TreeTagID_TBL.mutex.synchronize{ + Tk::BLT::Treeview::Tag::TreeTagID_TBL.delete(@path) + } end def tagid(tag) @@ -472,6 +492,22 @@ class Tk::BLT::Treeview nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -967,22 +1003,47 @@ class Tk::BLT::Treeview::Node < TkObject include Tk::BLT::Treeview::TagOrID_Methods TreeNodeID_TBL = TkCore::INTERP.create_table - TreeNode_ID = ['blt_treeview_node'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ TreeNodeID_TBL.clear } + (TreeNode_ID = ['blt_treeview_node'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + TreeNodeID_TBL.mutex.synchronize{ TreeNodeID_TBL.clear } + } def self.id2obj(tree, id) tpath = tree.path - return id unless TreeNodeID_TBL[tpath] - if TreeNodeID_TBL[tpath][id] - TreeNodeID_TBL[tpath][id] - else - begin - self.new(tree, nil, nil, 'node'=>Integer(id)) - rescue + TreeNodeID_TBL.mutex.synchronize{ + if TreeNodeID_TBL[tpath] + if TreeNodeID_TBL[tpath][id] + TreeNodeID_TBL[tpath][id] + else + begin + # self.new(tree, nil, nil, 'node'=>Integer(id)) + unless (tk_call(@tpath, 'get', id)).empty? + id = Integer(id) + (obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = @parent.path + @path = @id = id + TreeNodeID_TBL[@tpath] ||= {} + TreeNodeID_TBL[@tpath][@id] = self + } + obj + else + id + end + rescue + id + end + end + else id end - end + } end def self.new(tree, pos, parent=nil, keys={}) @@ -994,13 +1055,21 @@ class Tk::BLT::Treeview::Node < TkObject keys = _symbolkey2str(keys) tpath = tree.path - if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id]) - keys.delete('node') - tk_call(tree.path, 'move', id, pos, parent) if parent - return obj - end + TreeNodeID_TBL.mutex.synchronize{ + TreeNodeID_TBL[tpath] ||= {} + if (id = keys['node']) && (obj = TreeNodeID_TBL[tpath][id]) + keys.delete('node') + tk_call(tree.path, 'move', id, pos, parent) if parent + return obj + end - super(tree, pos, parent, keys) + #super(tree, pos, parent, keys) + (obj = self.allocate).instance_eval{ + initialize(tree, pos, parent, keys) + TreeNodeID_TBL[tpath][@id] = self + } + obj + } end def initialize(tree, pos, parent, keys) @@ -1008,11 +1077,18 @@ class Tk::BLT::Treeview::Node < TkObject @tpath = @parent.path if (id = keys['node']) + # if tk_call(@tpath, 'get', id).empty? + # fail RuntimeError, "not exist the node '#{id}'" + # end @path = @id = id tk_call(@tpath, 'move', @id, pos, tagid(parent)) if parent + configure(keys) if keys && ! keys.empty? else - name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze - TreeNode_ID[1].succ! + name = nil + TreeNode_ID.mutex.synchronize{ + name = TreeNode_ID.join(TkCore::INTERP._ip_id_).freeze + TreeNode_ID[1].succ! + } at = keys.delete['at'] @@ -1035,9 +1111,6 @@ class Tk::BLT::Treeview::Node < TkObject end @path = @id end - - TreeNodeID_TBL[@tpath] = {} unless TreeNodeID_TBL[@tpath] - TreeNodeID_TBL[@tpath][@id] = self end def id @@ -1051,37 +1124,66 @@ class Tk::BLT::Treeview::Tag < TkObject include Tk::BLT::Treeview::TagOrID_Methods TreeTagID_TBL = TkCore::INTERP.create_table - TreeTag_ID = ['blt_treeview_tag'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ TreeTagID_TBL.clear } + (TreeTag_ID = ['blt_treeview_tag'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } - def self.id2obj(tree, id) + TkCore::INTERP.init_ip_env{ + TreeTagID_TBL.mutex.synchronize{ TreeTagID_TBL.clear } + } + + def self.id2obj(tree, name) tpath = tree.path - return id unless TreeTagID_TBL[tpath] - if TreeTagID_TBL[tpath][id] - TreeTagID_TBL[tpath][id] - else - begin - self.new(tree, nil, nil, 'name'=>Integer(id)) - rescue + TreeTagID_TBL.mutex.synchronize{ + if TreeTagID_TBL[tpath] + if TreeTagID_TBL[tpath][name] + TreeTagID_TBL[tpath][name] + else + #self.new(tree, name) + (obj = self.allocate).instance_eval{ + @parent = @tree = tree + @tpath = @parent.path + @path = @id = name + TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] + TreeTagID_TBL[@tpath][@id] = self + } + obj + end + else id end - end + } end def self.new_by_name(tree, name, *ids) - if (obj = TreeTagID_TBL[tree.path][name]) - return obj - end - new([tree, name], ids) + TreeTagID_TBL.mutex.synchronize{ + unless (obj = TreeTagID_TBL[tree.path][name]) + (obj = self.allocate).instance_eval{ + initialize(tree, name, ids) + TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] + TreeTagID_TBL[@tpath][@id] = self + } + end + obj + } end def self.new(tree, *ids) - if tree.kind_of?(Array) - super(tree[0], tree[1], ids) - else - super(tree, nil, ids) - end + TreeTagID_TBL.mutex.synchronize{ + (obj = self.allocate).instance_eval{ + if tree.kind_of?(Array) + initialize(tree[0], tree[1], ids) + else + initialize(tree, nil, ids) + end + TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] + TreeTagID_TBL[@tpath][@id] = self + } + obj + } end def initialize(tree, name, ids) @@ -1091,13 +1193,12 @@ class Tk::BLT::Treeview::Tag < TkObject if name @path = @id = name else - @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_).freeze - TreeTag_ID[1].succ! + TreeTag_ID.mutex.synchronize{ + @path = @id = TreeTag_ID.join(TkCore::INTERP._ip_id_).freeze + TreeTag_ID[1].succ! + } end - TreeTagID_TBL[@tpath] = {} unless TreeTagID_TBL[@tpath] - TreeTagID_TBL[@tpath][@id] = self - unless ids.empty? tk_call(@tpath, 'tag', 'add', @id, *(ids.collect{|id| tagid(id)})) end diff --git a/ext/tk/lib/tkextlib/blt/vector.rb b/ext/tk/lib/tkextlib/blt/vector.rb index 540b6b9102..76c12a24e8 100644 --- a/ext/tk/lib/tkextlib/blt/vector.rb +++ b/ext/tk/lib/tkextlib/blt/vector.rb @@ -23,14 +23,17 @@ module Tk::BLT end def self.names(pat=None) - simplelist(tk_call('::blt::vector', 'names', pat)).collect{|name| - if TkVar_ID_TBL[name] - TkVar_ID_TBL[name] - elsif name[0..1] == '::' && TkVar_ID_TBL[name[2..-1]] - TkVar_ID_TBL[name[2..-1]] - else - name - end + list = simplelist(tk_call('::blt::vector', 'names', pat)) + TkVar_ID_TBL.mutex.synchronize{ + list.collect{|name| + if TkVar_ID_TBL[name] + TkVar_ID_TBL[name] + elsif name[0..1] == '::' && TkVar_ID_TBL[name[2..-1]] + TkVar_ID_TBL[name[2..-1]] + else + name + end + } } end @@ -53,7 +56,9 @@ module Tk::BLT "#auto", *hash_kv(keys)) end - TkVar_ID_TBL[@id] = self + TkVar_ID_TBL.mutex.synchronize{ + TkVar_ID_TBL[@id] = self + } @def_default = false @default_val = nil @@ -221,13 +226,21 @@ module Tk::BLT class VectorAccess < Vector def self.new(name) - return TkVar_ID_TBL[name] if TkVar_ID_TBL[name] - super(name, size=nil, keys={}) + TkVar_ID_TBL.mutex.synchronize{ + if TkVar_ID_TBL[name] + TkVar_ID_TBL[name] + else + (obj = self.allocate).instance_eval{ + initialize(name) + TkVar_ID_TBL[@id] = self + } + obj + end + } end def initialize(vec_name) @id = vec_name - TkVar_ID_TBL[@id] = self @def_default = false @default_val = nil diff --git a/ext/tk/lib/tkextlib/blt/watch.rb b/ext/tk/lib/tkextlib/blt/watch.rb index ae5e50f126..2daf417e0b 100644 --- a/ext/tk/lib/tkextlib/blt/watch.rb +++ b/ext/tk/lib/tkextlib/blt/watch.rb @@ -13,11 +13,23 @@ module Tk::BLT TkCommandNames = ['::blt::watch'.freeze].freeze WATCH_ID_TBL = TkCore::INTERP.create_table - BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint].freeze + + (BLT_WATCH_ID = ['blt_watch_id'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + WATCH_ID_TBL.mutex.synchronize{ WATCH_ID_TBL.clear } + } def self.names(state = None) - tk_split_list(tk_call('::blt::watch', 'names', state)).collect{|name| - WATCH_ID_TBL[name] || name + lst = tk_split_list(tk_call('::blt::watch', 'names', state)) + WATCH_ID_TBL.mutex.synchronize{ + lst.collect{|name| + WATCH_ID_TBL[name] || name + } } end @@ -45,13 +57,17 @@ module Tk::BLT if name @id = name.to_s else - @id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_) - BLT_WATCH_ID[1].succ! + BLT_WATCH_ID.mutex.synchronize{ + @id = BLT_WATCH_ID.join(TkCore::INTERP._ip_id_) + BLT_WATCH_ID[1].succ! + } end @path = @id - WATCH_ID_TBL[@id] = self + WATCH_ID_TBL.mutex.synchronize{ + WATCH_ID_TBL[@id] = self + } tk_call('::blt::watch', 'create', @id, *hash_kv(keys)) end diff --git a/ext/tk/lib/tkextlib/bwidget/buttonbox.rb b/ext/tk/lib/tkextlib/bwidget/buttonbox.rb index a8f23e8749..8d6d212189 100644 --- a/ext/tk/lib/tkextlib/bwidget/buttonbox.rb +++ b/ext/tk/lib/tkextlib/bwidget/buttonbox.rb @@ -40,7 +40,13 @@ class Tk::BWidget::ButtonBox def add(keys={}, &b) win = window(tk_send('add', *hash_kv(keys))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end @@ -62,7 +68,13 @@ class Tk::BWidget::ButtonBox def insert(idx, keys={}, &b) win = window(tk_send('insert', tagid(idx), *hash_kv(keys))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/combobox.rb b/ext/tk/lib/tkextlib/bwidget/combobox.rb index 31f71c3aaf..1c58a4ccb0 100644 --- a/ext/tk/lib/tkextlib/bwidget/combobox.rb +++ b/ext/tk/lib/tkextlib/bwidget/combobox.rb @@ -25,7 +25,13 @@ class Tk::BWidget::ComboBox def get_listbox(&b) win = window(tk_send_without_enc('getlistbox')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/dialog.rb b/ext/tk/lib/tkextlib/bwidget/dialog.rb index ae5f0238a3..0ddee21d05 100644 --- a/ext/tk/lib/tkextlib/bwidget/dialog.rb +++ b/ext/tk/lib/tkextlib/bwidget/dialog.rb @@ -112,19 +112,37 @@ class Tk::BWidget::Dialog def add(keys={}, &b) win = window(tk_send('add', *hash_kv(keys))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def get_frame(&b) win = window(tk_send('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def get_buttonbox(&b) win = window(@path + '.bbox') - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/labelframe.rb b/ext/tk/lib/tkextlib/bwidget/labelframe.rb index f7b267eebb..dc221806e4 100644 --- a/ext/tk/lib/tkextlib/bwidget/labelframe.rb +++ b/ext/tk/lib/tkextlib/bwidget/labelframe.rb @@ -40,7 +40,13 @@ class Tk::BWidget::LabelFrame end def get_frame(&b) win = window(tk_send_without_enc('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end end diff --git a/ext/tk/lib/tkextlib/bwidget/listbox.rb b/ext/tk/lib/tkextlib/bwidget/listbox.rb index 1267500661..d8cd72fec2 100644 --- a/ext/tk/lib/tkextlib/bwidget/listbox.rb +++ b/ext/tk/lib/tkextlib/bwidget/listbox.rb @@ -211,14 +211,26 @@ class Tk::BWidget::ListBox::Item include TkTreatTagFont ListItem_TBL = TkCore::INTERP.create_table - ListItem_ID = ['bw:item'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ ListItem_TBL.clear } + (ListItem_ID = ['bw:item'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + ListItem_TBL.mutex.synchronize{ ListItem_TBL.clear } + } def self.id2obj(lbox, id) lpath = lbox.path - return id unless ListItem_TBL[lpath] - ListItem_TBL[lpath][id]? ListItem_TBL[lpath][id]: id + ListItem_TBL.mutex.synchronize{ + if ListItem_TBL[lpath] + ListItem_TBL[lpath][id]? ListItem_TBL[lpath][id]: id + else + id + end + } end def initialize(lbox, *args) @@ -250,13 +262,17 @@ class Tk::BWidget::ListBox::Item if keys.key?('itemname') @path = @id = keys.delete('itemname') else - @path = @id = ListItem_ID.join(TkCore::INTERP._ip_id_) - ListItem_ID[1].succ! + ListItem_ID.mutex.synchronize{ + @path = @id = ListItem_ID.join(TkCore::INTERP._ip_id_) + ListItem_ID[1].succ! + } end - ListItem_TBL[@id] = self - ListItem_TBL[@lpath] = {} unless ListItem_TBL[@lpath] - ListItem_TBL[@lpath][@id] = self + ListItem_TBL.mutex.synchronize{ + ListItem_TBL[@id] = self + ListItem_TBL[@lpath] = {} unless ListItem_TBL[@lpath] + ListItem_TBL[@lpath][@id] = self + } @listbox.insert(index, @id, keys) end diff --git a/ext/tk/lib/tkextlib/bwidget/mainframe.rb b/ext/tk/lib/tkextlib/bwidget/mainframe.rb index c54e878557..de66eaf81e 100644 --- a/ext/tk/lib/tkextlib/bwidget/mainframe.rb +++ b/ext/tk/lib/tkextlib/bwidget/mainframe.rb @@ -41,37 +41,73 @@ class Tk::BWidget::MainFrame def add_indicator(keys={}, &b) win = window(tk_send('addindicator', *hash_kv(keys))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def add_toolbar(&b) win = window(tk_send('addtoolbar')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def get_frame(&b) win = window(tk_send('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def get_indicator(idx, &b) win = window(tk_send('getindicator', idx)) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def get_menu(menu_id, &b) win = window(tk_send('getmenu', menu_id)) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end def get_toolbar(idx, &b) win = window(tk_send('gettoolbar', idx)) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb index 9c946d0630..cc8a996f46 100644 --- a/ext/tk/lib/tkextlib/bwidget/messagedlg.rb +++ b/ext/tk/lib/tkextlib/bwidget/messagedlg.rb @@ -173,6 +173,9 @@ class Tk::BWidget::MessageDlg end def create - num_or_str(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys))) + # return the index of the pressed button, or nil if it is destroyed + ret = num_or_str(tk_call(self.class::TkCommandNames[0], + @path, *hash_kv(@keys))) + (ret < 0)? nil: ret end end diff --git a/ext/tk/lib/tkextlib/bwidget/notebook.rb b/ext/tk/lib/tkextlib/bwidget/notebook.rb index 5146d4915d..423943619c 100644 --- a/ext/tk/lib/tkextlib/bwidget/notebook.rb +++ b/ext/tk/lib/tkextlib/bwidget/notebook.rb @@ -89,7 +89,13 @@ class Tk::BWidget::NoteBook def add(page, &b) win = window(tk_send('add', tagid(page))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end @@ -105,7 +111,13 @@ class Tk::BWidget::NoteBook def get_frame(page, &b) win = window(tk_send('getframe', tagid(page))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end @@ -115,7 +127,13 @@ class Tk::BWidget::NoteBook def insert(index, page, keys={}, &b) win = window(tk_send('insert', index, tagid(page), *hash_kv(keys))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb b/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb index fc01284be6..fbc2c11255 100644 --- a/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb +++ b/ext/tk/lib/tkextlib/bwidget/pagesmanager.rb @@ -26,7 +26,13 @@ class Tk::BWidget::PagesManager def add(page, &b) win = window(tk_send('add', tagid(page))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end @@ -42,7 +48,13 @@ class Tk::BWidget::PagesManager def get_frame(page, &b) win = window(tk_send('getframe', tagid(page))) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/panedwindow.rb b/ext/tk/lib/tkextlib/bwidget/panedwindow.rb index 19982c6095..4d979fd523 100644 --- a/ext/tk/lib/tkextlib/bwidget/panedwindow.rb +++ b/ext/tk/lib/tkextlib/bwidget/panedwindow.rb @@ -25,7 +25,13 @@ class Tk::BWidget::PanedWindow def get_frame(idx, &b) win = window(tk_send_without_enc('getframe', idx)) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end end diff --git a/ext/tk/lib/tkextlib/bwidget/panelframe.rb b/ext/tk/lib/tkextlib/bwidget/panelframe.rb index 13f8817d74..84bae0768b 100644 --- a/ext/tk/lib/tkextlib/bwidget/panelframe.rb +++ b/ext/tk/lib/tkextlib/bwidget/panelframe.rb @@ -36,7 +36,13 @@ class Tk::BWidget::PanelFrame def get_frame(&b) win = window(tk_send_without_enc('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/progressdlg.rb b/ext/tk/lib/tkextlib/bwidget/progressdlg.rb index fbf00f3b00..32600255d5 100644 --- a/ext/tk/lib/tkextlib/bwidget/progressdlg.rb +++ b/ext/tk/lib/tkextlib/bwidget/progressdlg.rb @@ -51,4 +51,8 @@ class Tk::BWidget::ProgressDlg def value= (val) @keys['variable'].value = val end + + def create + window(tk_call(self.class::TkCommandNames[0], @path, *hash_kv(@keys))) + end end diff --git a/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb b/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb index a3986681a5..010c960ec5 100644 --- a/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb +++ b/ext/tk/lib/tkextlib/bwidget/scrollableframe.rb @@ -23,7 +23,13 @@ class Tk::BWidget::ScrollableFrame def get_frame(&b) win = window(tk_send_without_enc('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb b/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb index e9e53235b7..3599fd8459 100644 --- a/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb +++ b/ext/tk/lib/tkextlib/bwidget/scrolledwindow.rb @@ -21,7 +21,13 @@ class Tk::BWidget::ScrolledWindow def get_frame(&b) win = window(tk_send_without_enc('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/selectcolor.rb b/ext/tk/lib/tkextlib/bwidget/selectcolor.rb index 742a84cd84..0f9014f8de 100644 --- a/ext/tk/lib/tkextlib/bwidget/selectcolor.rb +++ b/ext/tk/lib/tkextlib/bwidget/selectcolor.rb @@ -10,6 +10,11 @@ require 'tkextlib/bwidget/messagedlg' module Tk module BWidget class SelectColor < Tk::BWidget::MessageDlg + class Dialog < Tk::BWidget::SelectColor + end + class Menubutton < Tk::Menubutton + end + MenuButton = Menubutton end end end @@ -43,3 +48,26 @@ class Tk::BWidget::SelectColor tk_call('SelectColor::setcolor', idx, color) end end + +class Tk::BWidget::SelectColor::Dialog + def create_self(keys) + super(keys) + @keys['type'] = 'dialog' + end + + def create + @keys['type'] = 'dialog' # 'dialog' type returns color + tk_call(Tk::BWidget::SelectColor::TkCommandNames[0], + @path, *hash_kv(@keys)) + end +end + +class Tk::BWidget::SelectColor::Menubutton + def create_self(keys) + keys = {} unless keys + keys = _symbolkey2str(keys) + keys['type'] = 'menubutton' # 'toolbar' type returns widget path + window(tk_call(Tk::BWidget::SelectColor::TkCommandNames[0], + @path, *hash_kv(keys))) + end +end diff --git a/ext/tk/lib/tkextlib/bwidget/selectfont.rb b/ext/tk/lib/tkextlib/bwidget/selectfont.rb index 478787602a..e53eb3b5bc 100644 --- a/ext/tk/lib/tkextlib/bwidget/selectfont.rb +++ b/ext/tk/lib/tkextlib/bwidget/selectfont.rb @@ -66,7 +66,7 @@ class Tk::BWidget::SelectFont::Dialog end def create - @keys['type'] = 'dialog' + @keys['type'] = 'dialog' # 'dialog' type returns font name tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(@keys)) end end @@ -79,7 +79,8 @@ class Tk::BWidget::SelectFont::Toolbar def create_self(keys) keys = {} unless keys keys = _symbolkey2str(keys) - keys['type'] = 'toolbar' - tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], @path, *hash_kv(keys)) + keys['type'] = 'toolbar' # 'toolbar' type returns widget path + window(tk_call(Tk::BWidget::SelectFont::TkCommandNames[0], + @path, *hash_kv(keys))) end end diff --git a/ext/tk/lib/tkextlib/bwidget/statusbar.rb b/ext/tk/lib/tkextlib/bwidget/statusbar.rb index df16e4c0b7..39c678d37e 100644 --- a/ext/tk/lib/tkextlib/bwidget/statusbar.rb +++ b/ext/tk/lib/tkextlib/bwidget/statusbar.rb @@ -36,7 +36,13 @@ class Tk::BWidget::StatusBar def get_frame(&b) win = window(tk_send_without_enc('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/bwidget/titleframe.rb b/ext/tk/lib/tkextlib/bwidget/titleframe.rb index f519490430..68534e66e9 100644 --- a/ext/tk/lib/tkextlib/bwidget/titleframe.rb +++ b/ext/tk/lib/tkextlib/bwidget/titleframe.rb @@ -21,7 +21,13 @@ class Tk::BWidget::TitleFrame def get_frame(&b) win = window(tk_send_without_enc('getframe')) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end end diff --git a/ext/tk/lib/tkextlib/bwidget/tree.rb b/ext/tk/lib/tkextlib/bwidget/tree.rb index e7178debe2..7a46db575e 100644 --- a/ext/tk/lib/tkextlib/bwidget/tree.rb +++ b/ext/tk/lib/tkextlib/bwidget/tree.rb @@ -263,14 +263,26 @@ class Tk::BWidget::Tree::Node include TkTreatTagFont TreeNode_TBL = TkCore::INTERP.create_table - TreeNode_ID = ['bw:node'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ TreeNode_TBL.clear } + (TreeNode_ID = ['bw:node'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + TreeNode_TBL.mutex.synchronize{ TreeNode_TBL.clear } + } def self.id2obj(tree, id) tpath = tree.path - return id unless TreeNode_TBL[tpath] - TreeNode_TBL[tpath][id]? TreeNode_TBL[tpath][id]: id + TreeNode_TBL.mutex.synchronize{ + if TreeNode_TBL[tpath] + TreeNode_TBL[tpath][id]? TreeNode_TBL[tpath][id]: id + else + id + end + } end def initialize(tree, *args) @@ -311,13 +323,17 @@ class Tk::BWidget::Tree::Node if keys.key?('nodename') @path = @id = keys.delete('nodename') else - @path = @id = TreeNode_ID.join(TkCore::INTERP._ip_id_) - TreeNode_ID[1].succ! + TreeNode_ID.mutex.synchronize{ + @path = @id = TreeNode_ID.join(TkCore::INTERP._ip_id_) + TreeNode_ID[1].succ! + } end - TreeNode_TBL[@id] = self - TreeNode_TBL[@tpath] = {} unless TreeNode_TBL[@tpath] - TreeNode_TBL[@tpath][@id] = self + TreeNode_TBL.mutex.synchronize{ + TreeNode_TBL[@id] = self + TreeNode_TBL[@tpath] = {} unless TreeNode_TBL[@tpath] + TreeNode_TBL[@tpath][@id] = self + } @tree.insert(index, parent, @id, keys) end diff --git a/ext/tk/lib/tkextlib/bwidget/widget.rb b/ext/tk/lib/tkextlib/bwidget/widget.rb index 568e503a8b..34e51308a5 100644 --- a/ext/tk/lib/tkextlib/bwidget/widget.rb +++ b/ext/tk/lib/tkextlib/bwidget/widget.rb @@ -43,7 +43,13 @@ module Tk::BWidget::Widget def self.create(klass, path, rename=None, &b) win = window(tk_call('Widget::create', klass, path, rename)) - win.instance_eval(&b) if b + if b + if TkCore::WITH_RUBY_VM ### Ruby 1.9 !!!! + win.instance_exec(self, &b) + else + win.instance_eval(&b) + end + end win end diff --git a/ext/tk/lib/tkextlib/itcl/incr_tcl.rb b/ext/tk/lib/tkextlib/itcl/incr_tcl.rb index 07abf3a7bf..2b75d62eb9 100644 --- a/ext/tk/lib/tkextlib/itcl/incr_tcl.rb +++ b/ext/tk/lib/tkextlib/itcl/incr_tcl.rb @@ -40,16 +40,22 @@ module Tk class ItclObject < TkObject ITCL_CLASSNAME = ''.freeze - ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint].freeze + (ITCL_OBJ_ID = ['itclobj'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } ITCL_OBJ_TBL = {}.taint def initialize(*args) if (@klass = self.class::ITCL_CLASSNAME).empty? fail RuntimeError, 'unknown itcl class (abstract class?)' end - @id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_) + Tk::Itcl::ItclObject::ITCL_OBJ_ID.mutex.synchronize{ + @id = Tk::Itcl::ItclObject::TCL_OBJ_ID.join(TkCore::INTERP._ip_id_) + Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ! + } @path = @id - Tk::Itcl::ItclObject::ITCL_OBJ_ID[1].succ! end def self.call_proc(name, *args) diff --git a/ext/tk/lib/tkextlib/itk/incr_tk.rb b/ext/tk/lib/tkextlib/itk/incr_tk.rb index c7b4e40af8..e06deb552c 100644 --- a/ext/tk/lib/tkextlib/itk/incr_tk.rb +++ b/ext/tk/lib/tkextlib/itk/incr_tk.rb @@ -145,9 +145,16 @@ module Tk private :__config_cmd ComponentID_TBL = TkCore::INTERP.create_table - Itk_Component_ID = ['itk:component'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ ComponentID_TBL.clear } + (Itk_Component_ID = ['itk:component'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + ComponentID_TBL.mutex.synchronize{ ComponentID_TBL.clear } + } def self.id2obj(master, id) if master.kind_of?(TkObject) @@ -155,8 +162,13 @@ module Tk else master = master.to_s end - return id unless ComponentID_TBL.key?(master) - (ComponentID_TBL[master].key?(id))? ComponentID_TBL[master][id]: id + ComponentID_TBL.mutex.synchronize{ + if ComponentID_TBL.key?(master) + (ComponentID_TBL[master].key?(id))? ComponentID_TBL[master][id]: id + else + id + end + } end def self.new(master, component=nil) @@ -171,17 +183,21 @@ module Tk elsif component component = component.to_s else - component = Itk_Component_ID.join(TkCore::INTERP._ip_id_) - Itk_Component_ID[1].succ! + Itk_Component_ID.mutex.synchronize{ + component = Itk_Component_ID.join(TkCore::INTERP._ip_id_) + Itk_Component_ID[1].succ! + } end - if ComponentID_TBL.key?(master) - if ComponentID_TBL[master].key?(component) - return ComponentID_TBL[master][component] + ComponentID_TBL.mutex.synchronize{ + if ComponentID_TBL.key?(master) + if ComponentID_TBL[master].key?(component) + return ComponentID_TBL[master][component] + end + else + ComponentID_TBL[master] = {} end - else - ComponentID_TBL[master] = {} - end + } super(master, component) end @@ -190,7 +206,9 @@ module Tk @master = master @component = component - ComponentID_TBL[@master][@component] = self + ComponentID_TBL.mutex.synchronize{ + ComponentID_TBL[@master][@component] = self + } begin @widget = window(tk_call(@master, 'component', @component)) diff --git a/ext/tk/lib/tkextlib/iwidgets/calendar.rb b/ext/tk/lib/tkextlib/iwidgets/calendar.rb index 0152f8593a..236ca96f00 100644 --- a/ext/tk/lib/tkextlib/iwidgets/calendar.rb +++ b/ext/tk/lib/tkextlib/iwidgets/calendar.rb @@ -45,6 +45,23 @@ class Tk::Iwidgets::Calendar class ValidateArgs < TkUtil::CallbackSubst KEY_TBL = [ [?d, ?s, :date], nil ] PROC_TBL = [ [?s, TkComm.method(:string) ], nil ] + + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) diff --git a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb index 6aa933ce06..1f9effb46e 100644 --- a/ext/tk/lib/tkextlib/iwidgets/entryfield.rb +++ b/ext/tk/lib/tkextlib/iwidgets/entryfield.rb @@ -42,6 +42,23 @@ class Tk::Iwidgets::Entryfield [ ?w, TkComm.method(:window) ], nil ] + + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); end diff --git a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb index 028f6ac0e7..4e7d8f8579 100644 --- a/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb +++ b/ext/tk/lib/tkextlib/iwidgets/hierarchy.rb @@ -30,6 +30,23 @@ class Tk::Iwidgets::Hierarchy class ValidateArgs < TkUtil::CallbackSubst KEY_TBL = [ [?n, ?s, :node], nil ] PROC_TBL = [ [?s, TkComm.method(:string) ], nil ] + + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -57,6 +74,22 @@ class Tk::Iwidgets::Hierarchy nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -78,6 +111,23 @@ class Tk::Iwidgets::Hierarchy nil ] PROC_TBL = [ [ ?s, TkComm.method(:string) ], nil ] + + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) diff --git a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb index 407c8f2aad..b07602e340 100644 --- a/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb +++ b/ext/tk/lib/tkextlib/iwidgets/scrolledcanvas.rb @@ -171,10 +171,16 @@ class Tk::Iwidgets::Scrolledcanvas end def delete(*args) - if TkcItem::CItemID_TBL[self.path] + tbl = nil + TkcItem::CItemID_TBL.mutex.synchronize{ + tbl = TkcItem::CItemID_TBL[self.path] + } + if tbl find('withtag', *args).each{|item| if item.kind_of?(TkcItem) - TkcItem::CItemID_TBL[self.path].delete(item.id) + TkcItem::CItemID_TBL.mutex.synchronize{ + tbl.delete(item.id) + } end } end diff --git a/ext/tk/lib/tkextlib/iwidgets/spinner.rb b/ext/tk/lib/tkextlib/iwidgets/spinner.rb index 174b9bd506..126cfe7c95 100644 --- a/ext/tk/lib/tkextlib/iwidgets/spinner.rb +++ b/ext/tk/lib/tkextlib/iwidgets/spinner.rb @@ -37,6 +37,23 @@ class Tk::Iwidgets::Spinner [ ?w, TkComm.method(:window) ], nil ] + + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); end diff --git a/ext/tk/lib/tkextlib/tcllib/ico.rb b/ext/tk/lib/tkextlib/tcllib/ico.rb index 3beeb11a4d..8c92926a4c 100644 --- a/ext/tk/lib/tkextlib/tcllib/ico.rb +++ b/ext/tk/lib/tkextlib/tcllib/ico.rb @@ -94,8 +94,10 @@ class Tk::Tcllib::ICO if keys.key?('name') @path = keys['name'].to_s else - @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_) - Tk_Image_ID[1].succ! + Tk_Image_ID.mutex.synchronize{ + @path = Tk_Image_ID.join(TkCore::INTERP._ip_id_) + Tk_Image_ID[1].succ! + } end tk_call_without_enc('::ico::getIcon', file, index, '-name', @path, '-format', 'image', *hash_kv(keys, true)) diff --git a/ext/tk/lib/tkextlib/tcllib/plotchart.rb b/ext/tk/lib/tkextlib/tcllib/plotchart.rb index cde42c8a0a..06ab20f3e6 100644 --- a/ext/tk/lib/tkextlib/tcllib/plotchart.rb +++ b/ext/tk/lib/tkextlib/tcllib/plotchart.rb @@ -265,7 +265,9 @@ module Tk::Tcllib::Plotchart private :_create_chart def __destroy_hook__ - Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + } end def plot(series, x, y) @@ -374,7 +376,9 @@ module Tk::Tcllib::Plotchart private :_create_chart def __destroy_hook__ - Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + } end def plot(series, radius, angle) @@ -645,7 +649,9 @@ module Tk::Tcllib::Plotchart private :_create_chart def __destroy_hook__ - Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.mutex.synchronize{ + Tk::Tcllib::Plotchart::PlotSeries::SeriesID_TBL.delete(@path) + } end def plot(series, dat, col=None) @@ -834,23 +840,38 @@ module Tk::Tcllib::Plotchart ############################ class PlotSeries < TkObject SeriesID_TBL = TkCore::INTERP.create_table - Series_ID = ['series'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ SeriesID_TBL.clear } + + (Series_ID = ['series'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + TkCore::INTERP.init_ip_env{ + SeriesID_TBL.mutex.synchronize{ SeriesID_TBL.clear } + } def self.id2obj(chart, id) path = chart.path - return id unless SeriesID_TBL[path] - SeriesID_TBL[path][id]? SeriesID_TBL[path][id]: id + SeriesID_TBL.mutex.synchronize{ + if SeriesID_TBL[path] + SeriesID_TBL[path][id]? SeriesID_TBL[path][id]: id + else + id + end + } end def initialize(chart, keys=nil) @parent = @chart_obj = chart @ppath = @chart_obj.path - @path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_) - # SeriesID_TBL[@id] = self - SeriesID_TBL[@ppath] = {} unless SeriesID_TBL[@ppath] - SeriesID_TBL[@ppath][@id] = self - Series_ID[1].succ! + Series_ID.mutex.synchronize{ + @path = @series = @id = Series_ID.join(TkCore::INTERP._ip_id_) + Series_ID[1].succ! + } + SeriesID_TBL.mutex.synchronize{ + SeriesID_TBL[@ppath] ||= {} + SeriesID_TBL[@ppath][@id] = self + } dataconfig(keys) if keys.kind_of?(Hash) end diff --git a/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb b/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb index 92dde65ce7..b366e0198b 100644 --- a/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb +++ b/ext/tk/lib/tkextlib/tcllib/tkpiechart.rb @@ -125,7 +125,9 @@ module Tk::Tcllib::Tkpiechart def delete tk_call_without_enc('::stooop::delete', @tag_key) - CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path] + CItemID_TBL.mutex.synchronize{ + CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path] + } self end @@ -184,8 +186,10 @@ module Tk::Tcllib::Tkpiechart @id = "slices(#{@tag_key})" @tag = TkcNamedTag.new(@pie.canvas, @id) - CItemID_TBL[@path] = {} unless CItemID_TBL[@path] - CItemID_TBL[@path][@id] = self + CItemID_TBL.mutex.synchronize{ + CItemID_TBL[@path] = {} unless CItemID_TBL[@path] + CItemID_TBL[@path][@id] = self + } end def tag_key @@ -200,7 +204,9 @@ module Tk::Tcllib::Tkpiechart def delete tk_call_without_enc('pie::deleteSlice', @pie.tag_key, @tag_key) - CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path] + CItemID_TBL.mutex.synchronize{ + CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path] + } @pie._delete_slice(self) self end diff --git a/ext/tk/lib/tkextlib/tile.rb b/ext/tk/lib/tkextlib/tile.rb index b527935a60..02473d57a1 100644 --- a/ext/tk/lib/tkextlib/tile.rb +++ b/ext/tk/lib/tkextlib/tile.rb @@ -18,11 +18,8 @@ require 'tkextlib/tile/setup.rb' # TkPackage.require('tile', '0.7') if Tk::TK_MAJOR_VERSION > 8 || (Tk::TK_MAJOR_VERSION == 8 && Tk::TK_MINOR_VERSION >= 5) - begin - verstr = TkPackage.require('Ttk') - rescue RuntimeError - verstr = TkPackage.require('tile') - end + TkPackage.require('tile') # for compatibility (version check of 'tile') + verstr = TkPackage.require('Ttk') else verstr = TkPackage.require('tile') end @@ -101,16 +98,97 @@ module Tk end def self.__Import_Tile_Widgets__! + warn 'Warning: "Tk::Tile::__Import_Tile_Widgets__!" is obsolete.' << + ' To control default widget set, use "Tk.default_widget_set = :Ttk"' Tk.tk_call('namespace', 'import', '-force', 'ttk::*') end - def self.load_images(imgdir, pat=TkComm::None) - images = Hash[*TkComm.simplelist(Tk.tk_call('::tile::LoadImages', - imgdir, pat))] - images.keys.each{|k| - images[k] = TkPhotoImage.new(:imagename=>images[k], - :without_creating=>true) + def self.__define_LoadImages_proc_for_compatibility__! + # Ttk 8.5 (Tile 0.8) lost 'LoadImages' utility procedure. + # So, some old scripts doen't work, because those scripts use the + # procedure to define local styles. + # Of course, rewriting such Tcl/Tk scripts isn't difficult for + # Tcl/Tk users. However, it may be troublesome for Ruby/Tk users + # who use such Tcl/Tk scripts as it is. + # This method may help Ruby/Tk users who don't want to modify old + # Tcl/Tk scripts for the latest version of Ttk (Tile) extension. + # This method defines a comaptible 'LoadImages' procedure on the + # Tcl/Tk interpreter working under Ruby/Tk. + # Please give attention to use this method. It may conflict with + # some definitions on Tcl/Tk scripts. + klass_name = self.name + proc_name = 'LoadImages' + if Tk::Tile::USE_TTK_NAMESPACE + ns_list = ['::tile'] + if Tk.info(:commands, "::ttk::#{proc_name}").empty? + ns_list << '::ttk' + end + else # Tk::Tile::USE_TILE_NAMESPACE + ns_list = ['::ttk'] + if Tk.info(:commands, "::tile::#{proc_name}").empty? + ns_list << '::tile' + end + end + + ns_list.each{|ns| + cmd = "#{ns}::#{proc_name}" + unless Tk.info(:commands, cmd).empty? + fail RuntimeError, "can't define '#{cmd}' command (already exist)" + end + TkNamespace.eval(ns){ + TkCore::INTERP.add_tk_procs(proc_name, 'imgdir {patterns {*.gif}}', + <<-'EOS') + foreach pattern $patterns { + foreach file [glob -directory $imgdir $pattern] { + set img [file tail [file rootname $file]] + if {![info exists images($img)]} { + set images($img) [image create photo -file $file] + } + } + } + return [array get images] + EOS + } } + end + + def self.load_images(imgdir, pat=nil) + if Tk::Tile::TILE_SPEC_VERSION_ID < 8 + if Tk::Tile::USE_TTK_NAMESPACE + cmd = '::ttk::LoadImages' + else # Tk::Tile::USE_TILE_NAMESPACE + cmd = '::tile::LoadImages' + end + pat ||= TkComm::None + images = Hash[*TkComm.simplelist(Tk.tk_call(cmd, imgdir, pat))] + images.keys.each{|k| + images[k] = TkPhotoImage.new(:imagename=>images[k], + :without_creating=>true) + } + else ## TILE_SPEC_VERSION_ID >= 8 + pat ||= '*.gif' + if pat.kind_of?(Array) + pat_list = pat + else + pat_list = [ pat ] + end + Dir.chdir(imgdir){ + pat_list.each{|pat| + Dir.glob(pat).each{|f| + img = File.basename(f, '.*') + unless TkComm.bool(Tk.info('exists', "images(#{img})")) + Tk.tk_call('set', "images(#{img})", + Tk.tk_call('image', 'create', 'photo', '-file', f)) + end + } + } + } + images = Hash[*TkComm.simplelist(Tk.tk_call('array', 'get', 'images'))] + images.keys.each{|k| + images[k] = TkPhotoImage.new(:imagename=>images[k], + :without_creating=>true) + } + end images end @@ -120,11 +198,20 @@ module Tk end module KeyNav - def self.enableMnemonics(w) - Tk.tk_call('::keynav::enableMnemonics', w) - end - def self.defaultButton(w) - Tk.tk_call('::keynav::defaultButton', w) + if Tk::Tile::TILE_SPEC_VERSION_ID < 8 + def self.enableMnemonics(w) + Tk.tk_call('::keynav::enableMnemonics', w) + end + def self.defaultButton(w) + Tk.tk_call('::keynav::defaultButton', w) + end + else # dummy + def self.enableMnemonics(w) + "" + end + def self.defaultButton(w) + "" + end end end @@ -139,6 +226,12 @@ module Tk Menu = 'TkMenuFont' SmallCaption = 'TkSmallCaptionFont' Icon = 'TkIconFont' + + TkFont::SYSTEM_FONT_NAMES.add [ + 'TkDefaultFont', 'TkTextFont', 'TkHeadingFont', + 'TkCaptionFont', 'TkTooltipFont', 'TkFixedFont', + 'TkMenuFont', 'TkSmallCaptionFont', 'TkIconFont' + ] end module ParseStyleLayout @@ -177,7 +270,7 @@ module Tk end private :__val2ruby_optkeys - def instate(state, script=nil, &b) + def ttk_instate(state, script=nil, &b) if script tk_send('instate', state, script) elsif b @@ -186,19 +279,30 @@ module Tk bool(tk_send('instate', state)) end end + alias tile_instate ttk_instate - def state(state=nil) + def ttk_state(state=nil) if state tk_send('state', state) else list(tk_send('state')) end end + alias tile_state ttk_state - def identify(x, y) + def ttk_identify(x, y) ret = tk_send_without_enc('identify', x, y) (ret.empty?)? nil: ret end + alias tile_identify ttk_identify + + # remove instate/state/identify method + # to avoid the conflict with widget options + if Tk.const_defined?(:USE_OBSOLETE_TILE_STATE_METHOD) && Tk::USE_OBSOLETE_TILE_STATE_METHOD + alias instate ttk_instate + alias state ttk_state + alias identify ttk_identify + end end ###################################### diff --git a/ext/tk/lib/tkextlib/tile/style.rb b/ext/tk/lib/tkextlib/tile/style.rb index e01011cb21..bf8acb34b0 100644 --- a/ext/tk/lib/tkextlib/tile/style.rb +++ b/ext/tk/lib/tkextlib/tile/style.rb @@ -19,8 +19,93 @@ end class << Tk::Tile::Style if Tk::Tile::TILE_SPEC_VERSION_ID < 8 TkCommandNames = ['style'.freeze].freeze - else + + # --- Tk::Tile::Style.__define_wrapper_proc_for_compatibility__! --- + # On Ttk (Tile) extension, 'style' command has imcompatible changes + # depend on the version of the extention. It requires modifying the + # Tcl/Tk scripts to define local styles. The rule for modification + # is a simple one. But, if users want to keep compatibility between + # versions of the extension, they will have to contrive to do that. + # It may be troublesome, especially for Ruby/Tk users. + # This method may help such work. This method make some definitions + # on the Tcl/Tk interpreter to work with different version of style + # command format. Please give attention to use this method. It may + # conflict with some definitions on Tcl/Tk scripts. + if Tk::Tile::TILE_SPEC_VERSION_ID < 7 + def __define_wrapper_proc_for_compatibility__! + unless Tk.info(:commands, '::ttk::style').empty? + fail RuntimeError, + "can't define ':ttk::style' command (already exist)" + end + TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS') + if [string equal [lrange $args 0 1] {element create}] { + if [string equal [lindex $args 3] image] { + set spec [lindex $args 4] + set map [lrange $spec 1 end] + if [llength $map] { + # return [eval [concat [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]] + return [uplevel 1 [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]] + } + } + } + # return [eval "::style $args"] + return [uplevel 1 ::style $args] + EOS + ######################### + end + else ### TILE_SPEC_VERSION_ID == 7 + def __define_wrapper_proc_for_compatibility__! + unless Tk.info(:commands, '::ttk::style').empty? + fail RuntimeError, + "can't define ':ttk::style' command (already exist)" + end + TkCore::INTERP.add_tk_procs('::ttk::style', 'args', <<-'EOS') + if [string equal [lrange $args 0 1] {element create}] { + if [string equal [lindex $args 3] image] { + set spec [lindex $args 4] + set map [lrange $spec 1 end] + if [llength $map] { + # return [eval [concat [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]] + return [uplevel 1 [list ::style element create [lindex $args 2] image [lindex $spec 0] -map $map] [lrange $args 5 end]]] + } + } + } elseif [string equal [lindex $args 0] default] { + # return [eval "::style [lreplace $args 0 0 configure]"] + return [uplevel 1 ::style [lreplace $args 0 0 configure]] + } + # return [eval "::style $args"] + return [uplevel 1 ::style $args] + EOS + ######################### + end + end + else ### TILE_SPEC_VERSION_ID >= 8 TkCommandNames = ['::ttk::style'.freeze].freeze + + def __define_wrapper_proc_for_compatibility__! + unless Tk.info(:commands, '::style').empty? + fail RuntimeError, "can't define '::style' command (already exist)" + end + TkCore::INTERP.add_tk_procs('::style', 'args', <<-'EOS') + if [string equal [lrange $args 0 1] {element create}] { + if [string equal [lindex $args 3] image] { + set name [lindex $args 4] + set opts [lrange $args 5 end] + set idx [lsearch $opts -map] + if {$idx >= 0 && [expr $idx % 2 == 0]} { + # return [eval [concat [list ::ttk::style element create [lindex $args 2] image [concat $name [lindex $opts [expr $idx + 1]]]] [lreplace $opts $idx [expr $idx + 1]]]] + return [uplevel 1 [list ::ttk::style element create [lindex $args 2] image [concat $name [lindex $opts [expr $idx + 1]]]] [lreplace $opts $idx [expr $idx + 1]]] + } + } + } elseif [string equal [lindex $args 0] default] { + # return [eval "::ttk::style [lreplace $args 0 0 configure]"] + return [uplevel 1 ::ttk::style [lreplace $args 0 0 configure]] + } + # return [eval "::ttk::style $args"] + return [uplevel 1 ::ttk::style $args] + EOS + ######################### + end end def configure(style=nil, keys=nil) @@ -98,7 +183,52 @@ class << Tk::Tile::Style end def element_create(name, type, *args) - tk_call(TkCommandNames[0], 'element', 'create', name, type, *args) + if type == 'image' || type == :image + element_create_image(name, *args) + else + tk_call(TkCommandNames[0], 'element', 'create', name, type, *args) + end + end + + def element_create_image(name, *args) + fail ArgumentError, 'Must supply a base image' unless (spec = args.shift) + if (opts = args.shift) + if opts.kind_of?(Hash) + opts = _symbolkey2str(opts) + else + fail ArgumentError, 'bad option' + end + end + fail ArgumentError, 'too many arguments' unless args.empty? + + if spec.kind_of?(Array) + # probably, command format is tile 0.8+ (Tcl/Tk8.5+) style + if Tk::Tile::TILE_SPEC_VERSION_ID >= 8 + if opts + tk_call(TkCommandNames[0], + 'element', 'create', name, 'image', spec, opts) + else + tk_call(TkCommandNames[0], 'element', 'create', name, 'image', spec) + end + else + fail ArgumentError, 'illegal arguments' if opts.key?('map') + base = spec.shift + opts['map'] = spec + tk_call(TkCommandNames[0], + 'element', 'create', name, 'image', base, opts) + end + else + # probably, command format is tile 0.7.8 or older style + if Tk::Tile::TILE_SPEC_VERSION_ID >= 8 + spec = [spec, *(opts.delete('map'))] if opts.key?('map') + end + if opts + tk_call(TkCommandNames[0], + 'element', 'create', name, 'image', spec, opts) + else + tk_call(TkCommandNames[0], 'element', 'create', name, 'image', spec) + end + end end def element_names() diff --git a/ext/tk/lib/tkextlib/tile/treeview.rb b/ext/tk/lib/tkextlib/tile/treeview.rb index 36496ee0b9..7f31b9c233 100644 --- a/ext/tk/lib/tkextlib/tile/treeview.rb +++ b/ext/tk/lib/tkextlib/tile/treeview.rb @@ -381,7 +381,7 @@ module Tk::Tile::TreeviewConfig when :item, 'item' ['width'] when :column, 'column' - super(id[1]) + super(id[1]) + ['minwidth'] when :tag, 'tag' super(id[1]) when :heading, 'heading' @@ -413,7 +413,7 @@ module Tk::Tile::TreeviewConfig when :item, 'item' ['open'] when :column, 'column' - super(id[1]) + super(id[1]) + ['stretch'] when :tag, 'tag' super(id[1]) when :heading, 'heading' @@ -617,30 +617,43 @@ end class Tk::Tile::Treeview::Item < TkObject ItemID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ Tk::Tile::Treeview::Item::ItemID_TBL.clear } + + TkCore::INTERP.init_ip_env{ + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + Tk::Tile::Treeview::Item::ItemID_TBL.clear + } + } def self.id2obj(tree, id) tpath = tree.path - return id unless Tk::Tile::Treeview::Item::ItemID_TBL[tpath] - (Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id])? \ - Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]: id + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] + (Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id])? \ + Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id]: id + else + id + end + } end def self.assign(tree, id) tpath = tree.path - if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] && - Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] - return Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] - end + obj = nil + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] && + Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] + return Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] + end - obj = self.allocate - obj.instance_eval{ - @parent = @t = tree - @tpath = tpath - @path = @id = id + obj = self.allocate + obj.instance_eval{ + @parent = @t = tree + @tpath = tpath + @path = @id = id + } + Tk::Tile::Treeview::Item::ItemID_TBL[tpath] ||= {} + Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] = obj } - ItemID_TBL[tpath] = {} unless ItemID_TBL[tpath] - Tk::Tile::Treeview::Item::ItemID_TBL[tpath][id] = obj obj end @@ -669,8 +682,10 @@ class Tk::Tile::Treeview::Item < TkObject @parent = @t = tree @tpath = tree.path @path = @id = _insert_item(@t, parent_item, idx, keys) - ItemID_TBL[@tpath] = {} unless ItemID_TBL[@tpath] - ItemID_TBL[@tpath][@id] = self + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + ItemID_TBL[@tpath] = {} unless ItemID_TBL[@tpath] + ItemID_TBL[@tpath][@id] = self + } end def id @id @@ -804,22 +819,35 @@ end class Tk::Tile::Treeview::Root < Tk::Tile::Treeview::Item def self.new(tree, keys = {}) tpath = tree.path - if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] && - Tk::Tile::Treeview::Item::ItemID_TBL[tpath][''] - Tk::Tile::Treeview::Item::ItemID_TBL[tpath][''] - else - super(tree, keys) - end + obj = nil + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + if Tk::Tile::Treeview::Item::ItemID_TBL[tpath] && + Tk::Tile::Treeview::Item::ItemID_TBL[tpath][''] + obj = Tk::Tile::Treeview::Item::ItemID_TBL[tpath][''] + else + #super(tree, keys) + (obj = self.allocate).instance_eval{ + @parent = @t = tree + @tpath = tree.path + @path = @id = '' + Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] ||= {} + Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self + } + end + } + obj.configure(keys) if keys && ! keys.empty? + obj end def initialize(tree, keys = {}) + # dummy:: not called by 'new' method @parent = @t = tree @tpath = tree.path @path = @id = '' - unless Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] - Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] = {} - end - Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + Tk::Tile::Treeview::Item::ItemID_TBL[@tpath] ||= {} + Tk::Tile::Treeview::Item::ItemID_TBL[@tpath][@id] = self + } end end @@ -829,24 +857,42 @@ class Tk::Tile::Treeview::Tag < TkObject include TkTreatTagFont TagID_TBL = TkCore::INTERP.create_table - Tag_ID = ['tile_treeview_tag'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ Tk::Tile::Treeview::Tag::TagID_TBL.clear } + (Tag_ID = ['tile_treeview_tag'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + Tk::Tile::Treeview::Tag::TagID_TBL.mutex.synchronize{ + Tk::Tile::Treeview::Tag::TagID_TBL.clear + } + } def self.id2obj(tree, id) tpath = tree.path - return id unless Tk::Tile::Treeview::Tag::TagID_TBL[tpath] - (Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id])? \ - Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id]: id + Tk::Tile::Treeview::Tag::TagID_TBL.mutex.synchronize{ + if Tk::Tile::Treeview::Tag::TagID_TBL[tpath] + (Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id])? \ + Tk::Tile::Treeview::Tag::TagID_TBL[tpath][id]: id + else + id + end + } end def initialize(tree, keys=nil) @parent = @t = tree @tpath = tree.path - @path = @id = Tag_ID.join(TkCore::INTERP._ip_id_) - TagID_TBL[@tpath] = {} unless TagID_TBL[@tpath] - TagID_TBL[@tpath][@id] = self - Tag_ID[1].succ! + Tag_ID.mutex.synchronize{ + @path = @id = Tag_ID.join(TkCore::INTERP._ip_id_) + Tag_ID[1].succ! + } + TagID_TBL.mutex.synchronize{ + TagID_TBL[@tpath] = {} unless TagID_TBL[@tpath] + TagID_TBL[@tpath][@id] = self + } if keys && keys != None tk_call_without_enc(@tpath, 'tag', 'configure', *hash_kv(keys, true)) end @@ -919,8 +965,12 @@ class Tk::Tile::Treeview < TkWindow WidgetClassNames[WidgetClassName] = self def __destroy_hook__ - Tk::Tile::Treeview::Item::ItemID_TBL.delete(@path) - Tk::Tile::Treeview::Tag::ItemID_TBL.delete(@path) + Tk::Tile::Treeview::Item::ItemID_TBL.mutex.synchronize{ + Tk::Tile::Treeview::Item::ItemID_TBL.delete(@path) + } + Tk::Tile::Treeview::Tag::ItemID_TBL.mutex.synchronize{ + Tk::Tile::Treeview::Tag::ItemID_TBL.delete(@path) + } end def self.style(*args) diff --git a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb index a040532eb6..ea91d3d1f4 100644 --- a/ext/tk/lib/tkextlib/tkDND/tkdnd.rb +++ b/ext/tk/lib/tkextlib/tkDND/tkdnd.rb @@ -57,6 +57,22 @@ module Tk nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + # setup tables _setup_subst_table(KEY_TBL, PROC_TBL); end diff --git a/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb b/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb index 8527f61df1..d893a83cf2 100644 --- a/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb +++ b/ext/tk/lib/tkextlib/tkHTML/htmlwidget.rb @@ -39,7 +39,10 @@ class Tk::HTML_Widget::ClippingWindow WidgetClassNames[WidgetClassName] = self HtmlClip_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ HtmlClip_TBL.clear } + + TkCore::INTERP.init_ip_env{ + HtmlClip_TBL.mutex.synchronize{ HtmlClip_TBL.clear } + } def self.new(parent, keys={}) if parent.kind_of?(Hash) @@ -54,7 +57,9 @@ class Tk::HTML_Widget::ClippingWindow else ppath = '' end - return HtmlClip_TBL[ppath] if HtmlClip_TBL[ppath] + HtmlClip_TBL.mutex.synchronize{ + return HtmlClip_TBL[ppath] if HtmlClip_TBL[ppath] + } widgetname = keys.delete('widgetname') if widgetname =~ /^(.*)\.[^.]+$/ @@ -62,7 +67,9 @@ class Tk::HTML_Widget::ClippingWindow if ppath2[0] != ?. ppath2 = ppath + '.' + ppath2 end - return HtmlClip_TBL[ppath2] if HtmlClip_TBL[ppath2] + HtmlClip_TBL.mutex.synchronize{ + return HtmlClip_TBL[ppath2] if HtmlClip_TBL[ppath2] + } ppath = ppath2 end @@ -79,7 +86,9 @@ class Tk::HTML_Widget::ClippingWindow @parent = parent @ppath = parent.path @path = @id = @ppath + '.x' - HtmlClip_TBL[@ppath] = self + HtmlClip_TBL.mutex.synchronize{ + HtmlClip_TBL[@ppath] = self + } end def method_missing(m, *args, &b) diff --git a/ext/tk/lib/tkextlib/tktable/tktable.rb b/ext/tk/lib/tkextlib/tktable/tktable.rb index 4edaabc847..fb8a8b0f72 100644 --- a/ext/tk/lib/tkextlib/tktable/tktable.rb +++ b/ext/tk/lib/tkextlib/tktable/tktable.rb @@ -118,23 +118,39 @@ class Tk::TkTable::CellTag include TkTreatTagFont CellTagID_TBL = TkCore::INTERP.create_table - CellTag_ID = ['tktbl:celltag'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ CellTagID_TBL.clear } + (CellTag_ID = ['tktbl:celltag'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + CellTagID_TBL.mutex.synchronize{ CellTagID_TBL.clear } + } def self.id2obj(table, id) tpath = table.path - return id unless CellTagID_TBL[tpath] - CellTagID_TBL[tpath][id]? CellTagID_TBL[tpath][id] : id + CellTagID_TBL.mutex.synchronize{ + if CellTagID_TBL[tpath] + CellTagID_TBL[tpath][id]? CellTagID_TBL[tpath][id] : id + else + id + end + } end def initialize(parent, keys=nil) @parent = @t = parent @tpath - parent.path - @path = @id = CellTag_ID.join(TkCore::INTERP._ip_id_) - CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] - CellTagID_TBL[@tpath][@id] = self - CellTag_ID[1].succ! + CellTag_ID.mutex.synchronize{ + @path = @id = CellTag_ID.join(TkCore::INTERP._ip_id_) + CellTag_ID[1].succ! + } + CellTagID_TBL.mutex.synchronize{ + CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] + CellTagID_TBL[@tpath][@id] = self + } configure(keys) if keys end @@ -144,7 +160,9 @@ class Tk::TkTable::CellTag def destroy tk_call(@tpath, 'tag', 'delete', @id) - CellTagID_TBL[@tpath].delete(@id) if CellTagID_TBL[@tpath] + CellTagID_TBL.mutex.synchronize{ + CellTagID_TBL[@tpath].delete(@id) if CellTagID_TBL[@tpath] + } self end alias delete destroy @@ -189,22 +207,35 @@ end class Tk::TkTable::NamedCellTag < Tk::TkTable::CellTag def self.new(parent, name, keys=nil) - if CellTagID_TBL[parent.path] && CellTagID_TBL[parent.path][name] - cell = CellTagID_TBL[parent.path][name] - cell.configure(keys) if keys - return cell - else - super(parent, name, keys) - end + obj = nil + CellTagID_TBL.mutex.synchronize{ + if CellTagID_TBL[parent.path] && CellTagID_TBL[parent.path][name] + obj = CellTagID_TBL[parent.path][name] + else + #super(parent, name, keys) + (obj = self.allocate).instance_eval{ + @parent = @t = parent + @tpath = parent.path + @path = @id = name + CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] + CellTagID_TBL[@tpath][@id] = self + } + end + } + obj.configure(keys) if keys && ! keys.empty? + obj end def initialize(parent, name, keys=nil) + # dummy:: not called by 'new' method @parent = @t = parent - @tpath - parent.path + @tpath = parent.path @path = @id = name - CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] - CellTagID_TBL[@tpath][@id] = self - configure(keys) if keys + CellTagID_TBL.mutex.synchronize{ + CellTagID_TBL[@tpath] = {} unless CellTagID_TBL[@tpath] + CellTagID_TBL[@tpath][@id] = self + } + configure(keys) if keys && ! keys.empty? end end @@ -220,7 +251,9 @@ class Tk::TkTable include Tk::ValidateConfigure def __destroy_hook__ - Tk::TkTable::CelTag::CellTagID_TBL.delete(@path) + Tk::TkTable::CelTag::CellTagID_TBL.mutex.synchronize{ + Tk::TkTable::CelTag::CellTagID_TBL.delete(@path) + } end def __boolval_optkeys @@ -258,6 +291,22 @@ class Tk::TkTable nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -291,6 +340,22 @@ class Tk::TkTable nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -322,6 +387,22 @@ class Tk::TkTable nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) @@ -356,6 +437,22 @@ class Tk::TkTable nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); end @@ -746,15 +843,17 @@ class Tk::TkTable end def tagid2obj(tagid) - if Tk::TkTable::CellTag::CellTagID_TBL.key?(@path) - if Tk::TkTable::CellTag::CellTagID_TBL[@path].key?(tagid) - Tk::TkTable::CellTag::CellTagID_TBL[@path][tagid] + Tk::TkTable::CellTag::CellTagID_TBL.mutex.synchronize{ + if Tk::TkTable::CellTag::CellTagID_TBL.key?(@path) + if Tk::TkTable::CellTag::CellTagID_TBL[@path].key?(tagid) + Tk::TkTable::CellTag::CellTagID_TBL[@path][tagid] + else + tagid + end else tagid end - else - tagid - end + } end def tag_cell(tag, *cells) @@ -775,13 +874,15 @@ class Tk::TkTable end def tag_delete(tag) tk_send('tag', 'delete', tagid(tag)) - if Tk::TkTable::CellTag::CellTagID_TBL[@path] - if tag.kind_of? Tk::TkTable::CellTag - Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag.id) - else - Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag) + Tk::TkTable::CellTag::CellTagID_TBL.mutex.synchronize{ + if Tk::TkTable::CellTag::CellTagID_TBL[@path] + if tag.kind_of? Tk::TkTable::CellTag + Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag.id) + else + Tk::TkTable::CellTag::CellTagID_TBL[@path].delete(tag) + end end - end + } self end def tag_exist?(tag) diff --git a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb index 12f7cffabf..b72b157dcd 100644 --- a/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb +++ b/ext/tk/lib/tkextlib/treectrl/tktreectrl.rb @@ -137,6 +137,22 @@ class Tk::TreeCtrl::NotifyEvent nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + # setup tables to be used by scan_args, _get_subst_key, _get_all_subst_keys # # _get_subst_key() and _get_all_subst_keys() generates key-string @@ -544,10 +560,18 @@ class Tk::TreeCtrl ######################### def __destroy_hook__ - Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.delete(@path) - Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.delete(@path) - Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.delete(@path) - Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.delete(@path) + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.delete(@path) + } + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.delete(@path) + } + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.delete(@path) + } + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.delete(@path) + } end ######################### @@ -638,9 +662,11 @@ class Tk::TreeCtrl end def column_delete(idx) - if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path] - Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path].delete(idx) - end + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path] + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[self.path].delete(idx) + end + } tk_send('column', 'delete', idx) self end @@ -750,11 +776,13 @@ class Tk::TreeCtrl end def element_delete(*elems) - if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path] - elems.each{|elem| - Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path].delete(elem) - } - end + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path] + elems.each{|elem| + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[self.path].delete(elem) + } + end + } tk_send('element', 'delete', *elems) self end @@ -885,22 +913,25 @@ class Tk::TreeCtrl def _erase_children(item) item_children(item).each{|i| _erase_children(i)} + # table is already locked Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].delete(item) end private :_erase_children def item_delete(first, last=None) - if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path] - if first == 'all' || first == :all || last == 'all' || last == :all - Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].clear - elsif last == None - _erase_children(first) - else - self.range(first, last).each{|id| - _erase_children(id) - } + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path] + if first == 'all' || first == :all || last == 'all' || last == :all + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[self.path].clear + elsif last == None + _erase_children(first) + else + self.range(first, last).each{|id| + _erase_children(id) + } + end end - end + } tk_send('item', 'delete', first, last) self end @@ -1520,11 +1551,13 @@ class Tk::TreeCtrl end def style_delete(*args) - if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path] - args.each{|sty| - Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path].delete(sty) - } - end + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path] + args.each{|sty| + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[self.path].delete(sty) + } + end + } tk_send('style', 'delete', *args) self end @@ -1608,15 +1641,29 @@ end class Tk::TreeCtrl::Column < TkObject TreeCtrlColumnID_TBL = TkCore::INTERP.create_table - TreeCtrlColumnID = ['treectrl_column'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.clear} + (TreeCtrlColumnID = ['treectrl_column'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.clear + } + } def self.id2obj(tree, id) tpath = tree.path - return id unless Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath] - Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id]? \ - Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id] : id + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath] + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id]? \ + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[tpath][id] : id + else + id + end + } end def initialize(parent, keys={}) @@ -1625,17 +1672,19 @@ class Tk::TreeCtrl::Column < TkObject keys = _symbolkey2str(keys) - @path = @id = - keys.delete('tag') || - Tk::TreeCtrl::Column::TreeCtrlColumnID.join(TkCore::INTERP._ip_id_) + Tk::TreeCtrl::Column::TreeCtrlColumnID.mutex.synchronize{ + @path = @id = + keys.delete('tag') || + Tk::TreeCtrl::Column::TreeCtrlColumnID.join(TkCore::INTERP._ip_id_) + Tk::TreeCtrl::Column::TreeCtrlColumnID[1].succ! + } keys['tag'] = @id - unless Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath] - Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath] = {} - end - Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath][@id] = self - Tk::TreeCtrl::Column::TreeCtrlColumnID[1].succ! + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath] ||= {} + Tk::TreeCtrl::Column::TreeCtrlColumnID_TBL[@tpath][@id] = self + } @tree.column_create(keys) end @@ -1692,11 +1741,18 @@ end class Tk::TreeCtrl::Element < TkObject TreeCtrlElementID_TBL = TkCore::INTERP.create_table - TreeCtrlElementID = ['treectrl_element'.freeze, '00000'.taint].freeze + + (TreeCtrlElementID = ['treectrl_element'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } TreeCtrlElemTypeToClass = {} TkCore::INTERP.init_ip_env{ - Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.clear + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.clear + } } def self.type2class(type) @@ -1705,22 +1761,30 @@ class Tk::TreeCtrl::Element < TkObject def self.id2obj(tree, id) tpath = tree.path - return id unless Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath] - Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id]? \ + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath] + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id]? \ Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[tpath][id] : id + else + id + end + } end def initialize(parent, type, keys=nil) @tree = parent @tpath = parent.path @type = type.to_s - @path = @id = - Tk::TreeCtrl::Element::TreeCtrlElementID.join(TkCore::INTERP._ip_id_) - unless Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath] - Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath] = {} - end - Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath][@id] = self - Tk::TreeCtrl::Element::TreeCtrlElementID[1].succ! + Tk::TreeCtrl::Element::TreeCtrlElementID.mutex.synchronize{ + @path = @id = + Tk::TreeCtrl::Element::TreeCtrlElementID.join(TkCore::INTERP._ip_id_) + Tk::TreeCtrl::Element::TreeCtrlElementID[1].succ! + } + + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath] ||= {} + Tk::TreeCtrl::Element::TreeCtrlElementID_TBL[@tpath][@id] = self + } @tree.element_create(@id, @type, keys) end @@ -1800,13 +1864,22 @@ end class Tk::TreeCtrl::Item < TkObject TreeCtrlItemID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.clear} + TkCore::INTERP.init_ip_env{ + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.clear + } + } def self.id2obj(tree, id) tpath = tree.path - return id unless Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath] - Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id]? \ - Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id] : id + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath] + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id]? \ + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[tpath][id] : id + else + id + end + } end def initialize(parent, keys={}) @@ -1814,10 +1887,10 @@ class Tk::TreeCtrl::Item < TkObject @tpath = parent.path @path = @id = @tree.item_create(keys) - unless Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath] - Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath] = {} - end - Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath][@id] = self + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath] ||= {} + Tk::TreeCtrl::Item::TreeCtrlItemID_TBL[@tpath][@id] = self + } end def id @@ -2088,27 +2161,45 @@ end class Tk::TreeCtrl::Style < TkObject TreeCtrlStyleID_TBL = TkCore::INTERP.create_table - TreeCtrlStyleID = ['treectrl_style'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.clear } + (TreeCtrlStyleID = ['treectrl_style'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.clear + } + } def self.id2obj(tree, id) tpath = tree.path - return id unless Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath] - Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id]? \ - Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id] : id + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{ + if Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath] + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id]? \ + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[tpath][id] : id + else + id + end + } end def initialize(parent, keys=nil) @tree = parent @tpath = parent.path - @path = @id = - Tk::TreeCtrl::Style::TreeCtrlStyleID.join(TkCore::INTERP._ip_id_) - unless Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath] - Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath] = {} - end - Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath][@id] = self - Tk::TreeCtrl::Style::TreeCtrlStyleID[1].succ! + + Tk::TreeCtrl::Style::TreeCtrlStyleID.mutex.synchronize{ + @path = @id = + Tk::TreeCtrl::Style::TreeCtrlStyleID.join(TkCore::INTERP._ip_id_) + Tk::TreeCtrl::Style::TreeCtrlStyleID[1].succ! + } + + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL.mutex.synchronize{ + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath] ||= {} + Tk::TreeCtrl::Style::TreeCtrlStyleID_TBL[@tpath][@id] = self + } @tree.style_create(@id, keys) end diff --git a/ext/tk/lib/tkextlib/version.rb b/ext/tk/lib/tkextlib/version.rb index c7816fd4a5..3542c79dbe 100644 --- a/ext/tk/lib/tkextlib/version.rb +++ b/ext/tk/lib/tkextlib/version.rb @@ -2,5 +2,5 @@ # release date of tkextlib # module Tk - Tkextlib_RELEASE_DATE = '2007-05-26'.freeze + Tkextlib_RELEASE_DATE = '2008-03-29'.freeze end diff --git a/ext/tk/lib/tkextlib/vu/pie.rb b/ext/tk/lib/tkextlib/vu/pie.rb index 78f3fa54da..1975803db1 100644 --- a/ext/tk/lib/tkextlib/vu/pie.rb +++ b/ext/tk/lib/tkextlib/vu/pie.rb @@ -116,13 +116,26 @@ end class Tk::Vu::PieSlice SliceID_TBL = TkCore::INTERP.create_table - Pie_Slice_ID = ['vu:pie'.freeze, '00000'.taint].freeze - TkCore::INTERP.init_ip_env{ SliceID_TBL.clear } + + (Pie_Slice_ID = ['vu:pie'.freeze, '00000'.taint]).instance_eval{ + @mutex = Mutex.new + def mutex; @mutex; end + freeze + } + + TkCore::INTERP.init_ip_env{ + SliceID_TBL.mutex.synchronize{ SliceID_TBL.clear } + } def self.id2obj(pie, id) pie_path = pie.path - return id unless SliceID_TBL[pie_path] - SliceID_TBL[pie_path][id]? SliceID_TBL[pie_path][id]: id + SliceID_TBL.mutex.synchronize{ + if SliceID_TBL[pie_path] + SliceID_TBL[pie_path][id]? SliceID_TBL[pie_path][id]: id + else + id + end + } end def initialize(parent, *args) @@ -131,10 +144,14 @@ class Tk::Vu::PieSlice end @parent = @pie = parent @ppath = parent.path - @path = @id = Pie_Slice_ID.join(TkCore::INTERP._ip_id_) - SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath] - SliceID_TBL[@ppath][@id] = self - Pie_Slice_ID[1].succ! + Pie_Slice_ID.mutex.synchronize{ + @path = @id = Pie_Slice_ID.join(TkCore::INTERP._ip_id_) + Pie_Slice_ID[1].succ! + } + SliceID_TBL.mutex.synchronize{ + SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath] + SliceID_TBL[@ppath][@id] = self + } if args[-1].kind_of?(Hash) keys = args.unshift @@ -209,22 +226,48 @@ end class Tk::Vu::NamedPieSlice def self.new(parent, name, *args) - if SliceID_TBL[parent.path] && SliceID_TBL[parent.path][name] - return SliceID_TBL[parent.path][name] - else - super(parent, name, *args) - end + obj = nil + SliceID_TBL.mutex.synchronize{ + if SliceID_TBL[parent.path] && SliceID_TBL[parent.path][name] + obj = SliceID_TBL[parent.path][name] + else + #super(parent, name, *args) + unless parent.kind_of?(Tk::Vu::Pie) + fail ArgumentError, "expect a Tk::Vu::Pie instance for 1st argument" + end + obj = self.allocate + obj.instance_eval{ + @parent = @pie = parent + @ppath = parent.path + @path = @id = name.to_s + SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath] + SliceID_TBL[@ppath][@id] = self + } + end + } + obj.instance_eval{ + if args[-1].kind_of?(Hash) + keys = args.unshift + end + @pie.set(@id, *args) + configure(keys) + } + + obj end def initialize(parent, name, *args) + # dummy:: not called by 'new' method unless parent.kind_of?(Tk::Vu::Pie) fail ArgumentError, "expect a Tk::Vu::Pie instance for 1st argument" end @parent = @pie = parent @ppath = parent.path @path = @id = name.to_s - SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath] - SliceID_TBL[@ppath][@id] = self + SliceID_TBL.mutex.synchronize{ + SliceID_TBL[@ppath] = {} unless SliceID_TBL[@ppath] + SliceID_TBL[@ppath][@id] = self + } if args[-1].kind_of?(Hash) keys = args.unshift diff --git a/ext/tk/lib/tkextlib/winico/winico.rb b/ext/tk/lib/tkextlib/winico/winico.rb index c53a3ff48c..30fb9682d5 100644 --- a/ext/tk/lib/tkextlib/winico/winico.rb +++ b/ext/tk/lib/tkextlib/winico/winico.rb @@ -34,10 +34,15 @@ end class Tk::Winico WinicoID_TBL = TkCore::INTERP.create_table - TkCore::INTERP.init_ip_env{ WinicoID_TBL.clear } + + TkCore::INTERP.init_ip_env{ + WinicoID_TBL.mutex.synchronize{ WinicoID_TBL.clear } + } def self.id2obj(id) - (WinicoID_TBL.key?(id))? WinicoID_TBL[id] : id + WinicoID_TBL.mutex.synchronize{ + (WinicoID_TBL.key?(id))? WinicoID_TBL[id] : id + } end def self.info @@ -81,7 +86,9 @@ class Tk::Winico "must be given proper information from where loading icons" end @path = @id - WinicoID_TBL[@id] = self + WinicoID_TBL.mutex.synchronize{ + WinicoID_TBL[@id] = self + } end def id @@ -96,7 +103,9 @@ class Tk::Winico def delete tk_call('winico', 'delete', @id) - WinicoID_TBL.delete(@id) + WinicoID_TBL.mutex.synchronize{ + WinicoID_TBL.delete(@id) + } self end alias destroy delete @@ -126,15 +135,37 @@ class Tk::Winico [ ?n, TkComm.method(:number) ], [ ?s, TkComm.method(:string) ], [ ?x, proc{|id| - if Tk::Winico::WinicoID_TBL.key?(id) - Tk::Winico::WinicoID_TBL[id] - else - Tk::Winico.new(nil, nil, id) - end + Tk::Winico::WinicoID_TBL.mutex.synchronize{ + if Tk::Winico::WinicoID_TBL.key?(id) + obj = Tk::Winico::WinicoID_TBL[id] + else + # Tk::Winico.new(nil, nil, id) + obj = Tk::Winico.allocate + obj.instance_eval{ @path = @id = id } + Tk::Winico::WinicoID_TBL[id] = obj + end + obj + } } ], nil ] + # for Ruby m17n :: ?x --> String --> char-code ( getbyte(0) ) + KEY_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + inf[1] = inf[1].getbyte(0) if inf[1].kind_of?(String) + end + inf + } + + PROC_TBL.map!{|inf| + if inf.kind_of?(Array) + inf[0] = inf[0].getbyte(0) if inf[0].kind_of?(String) + end + inf + } + _setup_subst_table(KEY_TBL, PROC_TBL); def self.ret_val(val) -- cgit v1.2.3