require 'fox'

module Fox
  class FXApp

    # Accepted forms are:
    #   addTimeout(ms, target, selector)
    #   addTimeout(ms, method(:onTimeout))
    #   addTimeout(ms) { |sender, sel, ptr| block }

    alias addTimeoutOrig addTimeout

    def addTimeout(ms, *args, &block)
      tgt, sel = nil, 0
      if args.length > 0
        if args[0].respond_to? :call
          tgt = FXPseudoTarget.new
	  tgt.pconnect(SEL_TIMEOUT, args[0], nil)
        else # it's some other kind of object
          tgt = args[0]
          sel = args[1]
        end
      else
        tgt = FXPseudoTarget.new
	tgt.pconnect(SEL_TIMEOUT, nil, block)
      end
      addTimeoutOrig(ms, tgt, sel)
    end
  end
end
