Sha256: 03b4de036bcea9485e1b3abd3c2bab9fd3e2e513d140dd0922cc5d8a3d415221

Contents?: true

Size: 896 Bytes

Versions: 1

Compression:

Stored size: 896 Bytes

Contents

class WIN32OLE_EVENT
  def initialize(ole, event_name=nil)
    @event_handlers = {}

    raise TypeError.new("1st parameter must be WIN32OLE object") if !ole.kind_of? WIN32OLE

    if event_name.nil? # Default event name
      # TODO: get default event
    end

    dispatch = ole.dispatch
    DispatchEvents.new dispatch, RubyInvocationProxy.new(self), dispatch.program_id
  end

  def on_event(name=nil, &block)
    if name
      @event_handlers[name.to_s] = block
    else
      @default_handler = block
    end
  end

  def method_missing(name, *args)
    name = name.to_s
    handler = @event_handlers[name]
    if handler
      handler.call *args
    elsif @default_handler
      @default_handler.call name, *args
    end
  end

  # Almost noop this.  We don't because it get CPU hot when people put this
  # in a hot loop!
  def self.message_loop
    DispatchEvents.message_loop
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jruby-win32ole-0.8.0 lib/win32ole/win32ole_event.rb