Sha256: bb42a2650b5bd7f7c3694256ca66b34a875dd44ea88a6af09445dc71e1733f3c

Contents?: true

Size: 942 Bytes

Versions: 3

Compression:

Stored size: 942 Bytes

Contents

class WIN32OLE_EVENT
  java_import org.racob.com.DispatchEvents
  
  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

3 entries across 3 versions & 1 rubygems

Version Path
jruby-win32ole-0.8.3 lib/win32ole/win32ole_event.rb
jruby-win32ole-0.8.2 lib/win32ole/win32ole_event.rb
jruby-win32ole-0.8.1 lib/win32ole/win32ole_event.rb