require 'fox'

module Fox
  class FX_App
    def stopModal(*args)
      if args.length > 0
        if args[0].kind_of? Fixnum
          value = args[0]
          stopModalInnermost(value)
        else
          window = args[0]
          if args.length > 1
            value = args[1]
            stopModalMatching(window, value)
          else
            stopModalMatching(window)
          end
        end
      else
        stopModalInnermost
      end
    end
  end

  class FXFileStream
    def FXFileStream.open(filename, save_or_load, container=nil)
      fstream = FXFileStream.new(container)
      if block_given?
        if fstream.open(filename, save_or_load)
          yield fstream
          fstream.close
        else
          # open failed; raise an exception?
        end
        nil
      else
        if fstream.open(filename, save_or_load)
          fstream
        else
          # open failed; raise an exception?
        end
      end
    end
  end

  class FXHMat
    def rot(*args)
      if (args.length == 1)
        rot1(args[0])
      elsif (args.length == 2)
        rot2(args[0], args[1])
      else
        rot3(args[0], args[1], args[2])
      end
    end
    def xrot(*args)
      if (args.length == 1)
        xrot1(args[0])
      else
        xrot2(args[0], args[1])
      end
    end
    def yrot(*args)
      if (args.length == 1)
        yrot1(args[0])
      else
        yrot2(args[0], args[1])
      end
    end
    def zrot(*args)
      if (args.length == 1)
        zrot1(args[0])
      else
        zrot2(args[0], args[1])
      end
    end
    def trans(*args)
      if args.length == 1
        trans1(args[0])
      else
        trans3(args[0], args[1], args[2])
      end
    end
    def scale(*args)
      if args.length == 1
        if args[0].kind_of? Float
          scalef(args[0])
        else
          scalev(args[0])
        end
      else
        scale3(args[0], args[1], args[2])
      end
    end
  end

  class FX_Header
    def appendItem(*args)
      if (args.length > 0) && (args[0].kind_of? String)
        appendItem2(*args)
      else
        appendItem1(*args)
      end
    end
    def insertItem(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        insertItem2(*args)
      else
        insertItem1(*args)
      end
    end
    def prependItem(*args)
      if (args.length > 0) && (args[0].kind_of? String)
        prependItem2(*args)
      else
        prependItem1(*args)
      end
    end
    def replaceItem(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        replaceItem2(*args)
      else
        replaceItem1(*args)
      end
    end
  end

  class FX_IconList
    def appendItem(*args)
      if (args.length > 0) && (args[0].kind_of? String)
        appendItem2(*args)
      else
        appendItem1(*args)
      end
    end
    def insertItem(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        insertItem2(*args)
      else
        insertItem1(*args)
      end
    end
    def prependItem(*args)
      if (args.length > 0) && (args[0].kind_of? String)
        prependItem2(*args)
      else
        prependItem1(*args)
      end
    end
    def replaceItem(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        replaceItem2(*args)
      else
        replaceItem1(*args)
      end
    end
  end

  class FX_List
    def appendItem(*args)
      if (args.length > 0) && (args[0].kind_of? String)
        appendItem2(*args)
      else
        appendItem1(*args)
      end
    end
    def insertItem(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        insertItem2(*args)
      else
        insertItem1(*args)
      end
    end
    def prependItem(*args)
      if (args.length > 0) && (args[0].kind_of? String)
        prependItem2(*args)
      else
        prependItem1(*args)
      end
    end
    def replaceItem(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        replaceItem2(*args)
      else
        replaceItem1(*args)
      end
    end
  end

  class FXRange
    def include(*args)
      if args.length == 3
        includePoint(*args)
      else
        if args[0].kind_of? Fox::FXRange
          includeRange(*args)
        else
          includeVec(*args)
        end
      end
    end
  end

  class FX_TreeList
    def addItemAfter(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemAfter2(*args)
      else
        addItemAfter1(*args)
      end
    end
    def addItemBefore(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemBefore2(*args)
      else
        addItemBefore1(*args)
      end
    end
    def addItemFirst(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemFirst2(*args)
      else
        addItemFirst1(*args)
      end
    end
    def addItemLast(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemLast2(*args)
      else
        addItemLast1(*args)
      end
    end
  end

  class FX_TreeListBox
    def addItemAfter(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemAfter2(*args)
      else
        addItemAfter1(*args)
      end
    end
    def addItemBefore(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemBefore2(*args)
      else
        addItemBefore1(*args)
      end
    end
    def addItemFirst(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemFirst2(*args)
      else
        addItemFirst1(*args)
      end
    end
    def addItemLast(*args)
      if (args.length > 1) && (args[1].kind_of? String)
        addItemLast2(*args)
      else
        addItemLast1(*args)
      end
    end
  end

  class FX_Window
    def repaint(*args)
      if args.length == 4
        repaintArea(args[0], args[1], args[2], args[3])
      else
        repaintWindow
      end
    end
    def update(*args)
      if args.length == 4
        updateArea(args[0], args[1], args[2], args[3])
      else
        updateWindow
      end
    end
  end
end
