Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • tk/lib/tk/event.rb

Class/Module Index [+]

Quicksearch

TkEvent::Event

Constants

ALIAS_TBL

alias button num alias delta wheel_delta alias root rootwin_id alias rootx x_root alias root_x x_root alias rooty y_root alias root_y y_root alias sendevent send_event

FIELD_FLAG
FIELD_OPERATION
KEY_TBL
<‘%’ subst-key char>, <proc type char>, <instance var (accessor) name>
LONGKEY_TBL
<‘%’ subst-key str>, <proc type char>, <instance var (accessor) name>

the subst-key string will be converted to a bytecode (128+idx).

PROC_TBL
<proc type char>, <proc/method to convert tcl-str to ruby-obj>
TYPE_GROUP_TBL
TYPE_ID_TBL
TYPE_NAME_TBL

Public Class Methods

group_flag(id) click to toggle source
 
               # File tk/lib/tk/event.rb, line 121
def self.group_flag(id)
  TYPE_GROUP_TBL[id] || 0
end
            
type_id(name) click to toggle source
 
               # File tk/lib/tk/event.rb, line 113
def self.type_id(name)
  TYPE_NAME_TBL[name.to_s]
end
            
type_name(id) click to toggle source
 
               # File tk/lib/tk/event.rb, line 117
def self.type_name(id)
  TYPE_ID_TBL[id] && TYPE_ID_TBL[id][0]
end
            

Public Instance Methods

generate(win, modkeys={}) click to toggle source
 
               # File tk/lib/tk/event.rb, line 252
def generate(win, modkeys={})
  klass = self.class

  if modkeys.has_key?(:type) || modkeys.has_key?('type')
    modkeys = TkComm._symbolkey2str(modkeys)
    type_id = modkeys.delete('type')
  else
    type_id = self.type
  end

  type_name  = klass.type_name(type_id)
  unless type_name
    fail RuntimeError, "type_id #{type_id} is invalid"
  end

  group_flag = klass.group_flag(type_id)

  opts = valid_for_generate(group_flag)

  modkeys.each{|key, val|
    if val
      opts[key.to_s] = val
    else
      opts.delete(key.to_s)
    end
  }

  if group_flag != Grp::KEY
    Tk.event_generate(win, type_name, opts)
  else
    # If type is KEY event, focus should be set to target widget.
    # If not set, original widget will get the same event.
    # That will make infinite loop.
    w = Tk.tk_call_without_enc('focus')
    begin
      Tk.tk_call_without_enc('focus', win)
      Tk.event_generate(win, type_name, opts)
    ensure
      Tk.tk_call_without_enc('focus', w)
    end
  end
end
            
valid_fields(group_flag=nil) click to toggle source
 
               # File tk/lib/tk/event.rb, line 217
def valid_fields(group_flag=nil)
  group_flag = self.class.group_flag(self.type) unless group_flag

  fields = {}
  FIELD_FLAG.each{|key, flag|
    next if (flag & group_flag) == 0
    begin
      val = self.__send__(key)
    rescue
      next
    end
    # next if !val || val == '??'
    next if !val || (val == '??' && (flag & Grp::STRING_DATA))
    fields[key] = val
  }

  fields
end
            
valid_for_generate(group_flag=nil) click to toggle source
 
               # File tk/lib/tk/event.rb, line 236
def valid_for_generate(group_flag=nil)
  fields = valid_fields(group_flag)

  FIELD_OPERATION.each{|key, cmd|
    next unless fields.has_key?(key)
    val = FIELD_OPERATION[key].call(fields[key])
    if val
      fields[key] = val
    else
      fields.delete(key)
    end
  }

  fields
end