summaryrefslogtreecommitdiff
path: root/ext/tk/lib/tk/canvas.rb
diff options
context:
space:
mode:
authornagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-23 22:37:44 +0000
committernagai <nagai@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-05-23 22:37:44 +0000
commit3ca633b890706c4f5892a179389b8389b5022dc0 (patch)
tree6d334bc0ca75c0dd658d732d0bd017d4ffad1eeb /ext/tk/lib/tk/canvas.rb
parent08f2c46ce177bbe5891c0f90fea0bfa9ee153a66 (diff)
* ext/tk/lib/tk.rb: fail to start Tk.mainloop (exit immediately) on some environment (reported on [ruby-talk:381444]).
* ext/tk/lib/tk/canvas.rb: support creating a canvas item object from an item ID number. * ext/tk/lib/tk/image.rb: import documents which are pull-requested. [Ruby 1.9 - Feature #4595] * ext/tk/lib/tk/extconf.rb: search directories for 64bit library (e.g. /usr/lib64), add some new configure options (see README.tcltklib), and bug fix. * ext/tk/lib/tk/README.tcltklib: modify docs for some new configure options. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31717 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/tk/lib/tk/canvas.rb')
-rw-r--r--ext/tk/lib/tk/canvas.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/ext/tk/lib/tk/canvas.rb b/ext/tk/lib/tk/canvas.rb
index f0cb755bd7..7d3d71675c 100644
--- a/ext/tk/lib/tk/canvas.rb
+++ b/ext/tk/lib/tk/canvas.rb
@@ -85,6 +85,7 @@ class Tk::Canvas<TkWindow
# create a canvas item without creating a TkcItem object
def create(type, *args)
+ type = TkcItem.type2class(type.to_s) unless type.kind_of?(TkcItem)
type.create(self, *args)
end
@@ -603,6 +604,30 @@ class Tk::Canvas<TkWindow
def itemtype(tag)
TkcItem.type2class(tk_send('type', tagid(tag)))
end
+
+ def create_itemobj_from_id(idnum)
+ id = TkcItem.id2obj(self, idnum.to_i)
+ return id if id.kind_of?(TkcItem)
+
+ typename = tk_send('type', id)
+ unless type = TkcItem.type2class(typename)
+ (itemclass = typename.dup)[0,1] = typename[0,1].upcase
+ type = TkcItem.const_set(itemclass, Class.new(TkcItem))
+ type.const_set("CItemTypeName", typename.freeze)
+ TkcItem::CItemTypeToClass[typename] = type
+ end
+
+ canvas = self
+ (obj = type.allocate).instance_eval{
+ @parent = @c = canvas
+ @path = canvas.path
+ @id = id
+ TkcItem::CItemID_TBL.mutex.synchronize{
+ TkcItem::CItemID_TBL[@path] = {} unless TkcItem::CItemID_TBL[@path]
+ TkcItem::CItemID_TBL[@path][@id] = self
+ }
+ }
+ end
end
#TkCanvas = Tk::Canvas unless Object.const_defined? :TkCanvas