| Module | TkEvent |
| In: |
tk/event.rb
|
Methods
Constants
| KEY_TBL | = | [ [ ?#, ?n, :serial ], [ ?a, ?s, :above ], [ ?b, ?n, :num ], [ ?c, ?n, :count ], [ ?d, ?s, :detail ], [ ?f, ?b, :focus ], [ ?h, ?n, :height ], [ ?i, ?s, :win_hex ], [ ?k, ?n, :keycode ], [ ?m, ?s, :mode ], [ ?o, ?b, :override ], [ ?p, ?s, :place ], [ ?s, ?x, :state ], [ ?t, ?n, :time ], [ ?w, ?n, :width ], [ ?x, ?n, :x ], [ ?y, ?n, :y ], [ ?A, ?s, :char ], [ ?B, ?n, :borderwidth ], [ ?D, ?n, :wheel_delta ], [ ?E, ?b, :send_event ], [ ?K, ?s, :keysym ], [ ?N, ?n, :keysym_num ], [ ?P, ?s, :property ], [ ?R, ?s, :rootwin_id ], [ ?S, ?s, :subwindow ], [ ?T, ?n, :type ], [ ?W, ?w, :widget ], [ ?X, ?n, :x_root ], [ ?Y, ?n, :y_root ], nil | [ <’%’ subst-key char>, <proc type char>, <instance var (accessor) name>] | |
| PROC_TBL | = | [ [ ?n, TkComm.method(:num_or_str) ], [ ?s, TkComm.method(:string) ], [ ?b, TkComm.method(:bool) ], [ ?w, TkComm.method(:window) ], [ ?x, proc{|val| begin TkComm::number(val) | [ <proc type char>, <proc/method to convert tcl-str to ruby-obj>] |
Public Instance methods
# File tk/event.rb, line 249
249: def generate(win, modkeys={})
250: klass = self.class
251:
252: if modkeys.has_key?(:type) || modkeys.has_key?('type')
253: modkeys = TkComm._symbolkey2str(modkeys)
254: type_id = modkeys.delete('type')
255: else
256: type_id = self.type
257: end
258:
259: type_name = klass.type_name(type_id)
260: unless type_name
261: fail RuntimeError, "type_id #{type_id} is invalid"
262: end
263:
264: group_flag = klass.group_flag(type_id)
265:
266: opts = valid_for_generate(group_flag)
267:
268: modkeys.each{|key, val|
269: if val
270: opts[key.to_s] = val
271: else
272: opts.delete(key.to_s)
273: end
274: }
275:
276: if group_flag != Grp::KEY
277: Tk.event_generate(win, type_name, opts)
278: else
279: # If type is KEY event, focus should be set to target widget.
280: # If not set, original widget will get the same event.
281: # That will make infinite loop.
282: w = Tk.tk_call_without_enc('focus')
283: begin
284: Tk.tk_call_without_enc('focus', win)
285: Tk.event_generate(win, type_name, opts)
286: ensure
287: Tk.tk_call_without_enc('focus', w)
288: end
289: end
290: end
# File tk/event.rb, line 215
215: def valid_fields(group_flag=nil)
216: group_flag = self.class.group_flag(self.type) unless group_flag
217:
218: fields = {}
219: FIELD_FLAG.each{|key, flag|
220: next if (flag & group_flag) == 0
221: begin
222: val = self.__send__(key)
223: rescue
224: next
225: end
226: next if !val || val == '??'
227: fields[key] = val
228: }
229:
230: fields
231: end
# File tk/event.rb, line 233
233: def valid_for_generate(group_flag=nil)
234: fields = valid_fields(group_flag)
235:
236: FIELD_OPERATION.each{|key, cmd|
237: next unless fields.has_key?(key)
238: val = FIELD_OPERATION[key].call(fields[key])
239: if val
240: fields[key] = val
241: else
242: fields.delete(key)
243: end
244: }
245:
246: fields
247: end