1 #
2 # tk/bind.rb : control event binding
3 #
4 require 'tk'
5
6 class TkBindTag
7 include TkBindCore
8
9 #BTagID_TBL = {}
10 BTagID_TBL = TkCore::INTERP.create_table
11
12 (Tk_BINDTAG_ID = ["btag".freeze, "00000".taint]).instance_eval{
13 @mutex = Mutex.new
14 def mutex; @mutex; end
15 freeze
16 }
17
18 TkCore::INTERP.init_ip_env{
19 BTagID_TBL.mutex.synchronize{ BTagID_TBL.clear }
20 }
21
22 def TkBindTag.id2obj(id)
23 BTagID_TBL.mutex.synchronize{
24 (BTagID_TBL[id])? BTagID_TBL[id]: id
25 }
26 end
27
28 =begin
29 def TkBindTag.new_by_name(name, *args, &b)
30 BTagID_TBL.mutex.synchronize{
31 return BTagID_TBL[name] if BTagID_TBL[name]
32 }
33
34 self.new.instance_eval{
35 BTagID_TBL.mutex.synchronize{
36 BTagID_TBL.delete @id
37 @id = name
38 BTagID_TBL[@id] = self
39 }
40 bind(*args, &b) if args != []
41 self
42 }
43 end
44 =end
45 def TkBindTag.new_by_name(name, *args, &b)
46 obj = nil
47 BTagID_TBL.mutex.synchronize{
48 if BTagID_TBL[name]
49 obj = BTagID_TBL[name]
50 else
51 (obj = BTagID_TBL[name] = self.allocate).instance_eval{
52 @id = name
53 }
54 end
55 }
56 bind(*args, &b) if obj && args != []
57 obj
58 end
59
60 def initialize(*args, &b)
61 Tk_BINDTAG_ID.mutex.synchronize{
62 # @id = Tk_BINDTAG_ID.join('')
63 @id = Tk_BINDTAG_ID.join(TkCore::INTERP._ip_id_)
64 Tk_BINDTAG_ID[1].succ!
65 }
66 BTagID_TBL.mutex.synchronize{
67 BTagID_TBL[@id] = self
68 }
69 bind(*args, &b) if args != []
70 end
71
72 ALL = self.new_by_name('all')
73
74 def name
75 @id
76 end
77
78 def to_eval
79 @id
80 end
81
82 def inspect
83 #Kernel.format "#<TkBindTag: %s>", @id
84 '#<TkBindTag: ' + @id + '>'
85 end
86 end
87
88
89 class TkBindTagAll<TkBindTag
90 def TkBindTagAll.new(*args, &b)
91 $stderr.puts "Warning: TkBindTagALL is obsolete. Use TkBindTag::ALL\n"
92
93 TkBindTag::ALL.bind(*args, &b) if args != []
94 TkBindTag::ALL
95 end
96 end
97
98
99 class TkDatabaseClass<TkBindTag
100 =begin
101 def self.new(name, *args, &b)
102 BTagID_TBL.mutex.synchronize{
103 return BTagID_TBL[name] if BTagID_TBL[name]
104 }
105 super(name, *args, &b)
106 end
107
108 def initialize(name, *args, &b)
109 @id = name
110 BTagID_TBL.mutex.synchronize{
111 BTagID_TBL[@id] = self
112 }
113 bind(*args, &b) if args != []
114 end
115 =end
116 def self.new(name, *args, &b)
117 BTagID_TBL.mutex.synchronize{
118 if BTagID_TBL[name]
119 BTagID_TBL[name]
120 else
121 BTagID_TBL[name] = self.allocate.instance_eval{
122 initialize(name, *args, &b)
123 self
124 }
125 end
126 }
127 end
128
129 def initialize(name, *args, &b)
130 @id = name
131 bind(*args, &b) if args != []
132 end
133
134 def inspect
135 #Kernel.format "#<TkDatabaseClass: %s>", @id
136 '#<TkDatabaseClass: ' + @id + '>'
137 end
138 end