summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/canvas.rb
diff options
context:
space:
mode:
Diffstat (limited to 'ext/tk/lib/tk/canvas.rb')
-rw-r--r--ext/tk/lib/tk/canvas.rb45
1 files changed, 33 insertions, 12 deletions
diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb
index c30fd79bb9..fceadd5e9c 100644
--- a/ext/tk/lib/tk/canvas.rb
+++ b/ext/tk/lib/tk/canvas.rb
@@ -1,6 +1,5 @@
#
# tk/canvas.rb - Tk canvas classes
-# $Date$
# by Yukihiro Matsumoto <matz@caelum.co.jp>
#
require 'tk'
@@ -40,7 +39,7 @@ module TkCanvasItemConfig
private :__item_pathname
end
-class TkCanvas<TkWindow
+class Tk::Canvas<TkWindow
include TkCanvasItemConfig
include Tk::Scrollable
@@ -186,11 +185,17 @@ class TkCanvas<TkWindow
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
args.each{|tag|
find('withtag', tag).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
}
}
@@ -573,6 +578,10 @@ class TkCanvas<TkWindow
end
end
+#TkCanvas = Tk::Canvas unless Object.const_defined? :TkCanvas
+Tk.__set_toplevel_aliases__(:Tk, Tk::Canvas, :TkCanvas)
+
+
class TkcItem<TkObject
extend Tk
include TkcTagAccess
@@ -581,9 +590,12 @@ class TkcItem<TkObject
CItemTypeName = nil
CItemTypeToClass = {}
+
CItemID_TBL = TkCore::INTERP.create_table
- TkCore::INTERP.init_ip_env{ CItemID_TBL.clear }
+ TkCore::INTERP.init_ip_env{
+ CItemID_TBL.mutex.synchronize{ CItemID_TBL.clear }
+ }
def TkcItem.type2class(type)
CItemTypeToClass[type]
@@ -591,8 +603,13 @@ class TkcItem<TkObject
def TkcItem.id2obj(canvas, id)
cpath = canvas.path
- return id unless CItemID_TBL[cpath]
- CItemID_TBL[cpath][id]? CItemID_TBL[cpath][id]: id
+ CItemID_TBL.mutex.synchronize{
+ if CItemID_TBL[cpath]
+ CItemID_TBL[cpath][id]? CItemID_TBL[cpath][id]: id
+ else
+ id
+ end
+ }
end
########################################
@@ -658,15 +675,17 @@ class TkcItem<TkObject
########################################
def initialize(parent, *args)
- #unless parent.kind_of?(TkCanvas)
- # fail ArgumentError, "expect TkCanvas for 1st argument"
+ #unless parent.kind_of?(Tk::Canvas)
+ # fail ArgumentError, "expect Tk::Canvas for 1st argument"
#end
@parent = @c = parent
@path = parent.path
@id = create_self(*args) # an integer number as 'canvas item 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 create_self(*args)
self.class.create(@c, *args) # return an integer number as 'canvas item id'
@@ -687,7 +706,9 @@ class TkcItem<TkObject
def delete
@c.delete @id
- CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
+ CItemID_TBL.mutex.synchronize{
+ CItemID_TBL[@path].delete(@id) if CItemID_TBL[@path]
+ }
self
end
alias remove delete