useDynLib("grid", .registration = TRUE)

import(grDevices)

export(
       "arcCurvature", "arrow",
       # Conversion of units
       "convertUnit", "convertX", "convertY",
       "convertWidth", "convertHeight",
       # Deprecated conversion functions
       "convertNative",
       "grid.convertWidth", "grid.convertX", "grid.convertY",
       "grid.convert", "grid.convertHeight",

       "current.viewport", "current.vpPath", "current.vpTree",
       "current.transform",
       "engine.display.list",
       "gpar", "get.gpar",
       "grid.collection",
       "grid.copy", "grid.display.list", "grid.draw",
       "grid.record",
       "grid.grill",
       "grid.layout", "grid.locator",
       "grid.newpage",
       "grid.plot.and.legend",
       "grid.pretty",
       "grid.prompt",
       "grid.refresh",
       "grid.show.layout", "grid.show.viewport",

       "unit",
       "is.unit",
       "unit.c", "unit.length", "unit.pmax", "unit.pmin", "unit.rep",
       "stringWidth", "stringHeight",
       "grobX", "grobY", "grobWidth", "grobHeight",
       "absolute.size",

       "viewport", "vpList", "vpStack", "vpTree", "vpPath",
       "pop.viewport", "push.viewport",
       "popViewport", "pushViewport",
       "dataViewport", "plotViewport",
       "downViewport", "upViewport", "seekViewport",

       "drawDetails", "preDrawDetails", "postDrawDetails",
       "editDetails",
       "validDetails",
       "heightDetails", "widthDetails",
       "xDetails", "yDetails",

#       "height", "heightDetails",
#       "width", "widthDetails",

       # Creating and modifying grobs (and gTrees)
       "grid.grob",
       "grob", "gList", "gTree", "gPath",
       "grobName",
       "grid.get", "grid.set", "grid.add", "grid.remove", "grid.edit",
       "getGrob", "setGrob", "addGrob", "removeGrob", "editGrob",
       "gEdit", "gEditList", "applyEdit", "applyEdits",
       "getNames", "childNames",
       "grid.grab", "grid.grabExpr",
       "setChildren",

       # Creating and drawing predefined grobs and gTrees
       "grid.arrows", "grid.circle", "grid.clip", "grid.curve",
       "grid.line.to", "grid.lines", "grid.move.to",
       "grid.points", "grid.polygon", "grid.polyline", 
       "grid.rect", "grid.segments", "grid.text", "grid.xspline",
       "arrowsGrob", "circleGrob", "clipGrob", "curveGrob",
       "linesGrob", "lineToGrob", "moveToGrob",
       "pointsGrob", "polygonGrob", "polylineGrob",
       "rectGrob", "segmentsGrob", "textGrob", "xsplineGrob",
       
       "grid.xaxis", "grid.yaxis",
       "xaxisGrob", "yaxisGrob", 

       # Frames and packing
       "grid.frame", "grid.pack", "grid.place",
       "frameGrob", "packGrob", "placeGrob"
       )

## Documented as internal but in Paul's first attempt at a sensible
## export list:
export("draw.details",
       "grid.legend", "grid.multipanel",
       "grid.panel", "grid.strip",
       "layoutRegion",
       "layout.widths", "layout.heights",
       "viewport.layout", "viewport.transform")

## Manipulated via C code ...
## export("get.gpar", "grid.top.level.vp")

## <FIXME>
## In the grid.layout.Rd \example ...
export("layout.torture")
## </FIXME>

## S3 methods for generics in base
S3method("[", "arrow")
S3method("[", "gList")
S3method("[", "gpar")
S3method("[", "unit")
S3method("[", "unit.arithmetic")
S3method("[", "unit.list")
S3method("Ops", "unit")
S3method("Summary", "unit")
S3method("as.character", "grob")
S3method("as.character", "gList")
S3method("as.character", "path")
S3method("as.character", "unit")
S3method("as.character", "unit.arithmetic")
S3method("as.character", "unit.list")
S3method("as.character", "viewport")
S3method("as.character", "vpList")
S3method("as.character", "vpStack")
S3method("as.character", "vpTree")
S3method("print", "grob")
S3method("print", "gList")
S3method("print", "unit")
S3method("print", "viewport")
S3method("print", "path")
S3method("print", "gpar")

## S3 methods for exported generics in grid
S3method("downViewport", "default")
S3method("downViewport", "vpPath")

S3method("grid.draw", "grob")
S3method("grid.draw", "gList")
S3method("grid.draw", "gTree")
S3method("grid.draw", "viewport")
S3method("grid.draw", "vpPath")
S3method("grid.draw", "pop")
S3method("grid.draw", "up")
S3method("drawDetails", "arrows")
S3method("drawDetails", "circle")
S3method("drawDetails", "curve")
S3method("drawDetails", "grob")
S3method("drawDetails", "line.to")
S3method("drawDetails", "lines")
S3method("drawDetails", "move.to")
S3method("drawDetails", "points")
S3method("drawDetails", "polygon")
S3method("drawDetails", "polyline")
S3method("drawDetails", "xspline")
S3method("drawDetails", "rect")
S3method("drawDetails", "segments")
S3method("drawDetails", "text")
S3method("drawDetails", "xaxis")
S3method("drawDetails", "yaxis")
S3method("editDetails", "default")
S3method("editDetails", "xaxis")
S3method("editDetails", "yaxis")
S3method("grobHeight", "grob")
S3method("grobHeight", "gList")
S3method("grobHeight", "gPath")
S3method("grobHeight", "default")
S3method("grobWidth", "grob")
S3method("grobWidth", "gList")
S3method("grobWidth", "gPath")
S3method("grobWidth", "default")
S3method("grobX", "grob")
S3method("grobX", "gList")
S3method("grobX", "gPath")
S3method("grobX", "default")
S3method("grobY", "grob")
S3method("grobY", "gList")
S3method("grobY", "gPath")
S3method("grobY", "default")
S3method("heightDetails", "arrows")
S3method("heightDetails", "circle")
S3method("heightDetails", "curve")
S3method("heightDetails", "default")
S3method("heightDetails", "frame")
S3method("heightDetails", "lines")
S3method("heightDetails", "points")
S3method("heightDetails", "polygon")
S3method("heightDetails", "polyline")
S3method("heightDetails", "rect")
S3method("heightDetails", "segments")
S3method("heightDetails", "text")
S3method("heightDetails", "xspline")
#S3method("height.details", "viewport")
S3method("postDraw", "grob")
S3method("preDraw", "grob")
S3method("preDraw", "gTree")
S3method("preDrawDetails", "grob")
S3method("postDrawDetails", "grob")
S3method("record", "default")
S3method("record", "grob")
S3method("record", "viewport")
S3method("record", "vpPath")
S3method("validDetails", "arrows")
S3method("validDetails", "circle")
S3method("validDetails", "clip")
S3method("validDetails", "curve")
S3method("validDetails", "grob")
S3method("validDetails", "lines")
S3method("validDetails", "line.to")
S3method("validDetails", "move.to")
S3method("validDetails", "polygon")
S3method("validDetails", "polyline")
S3method("validDetails", "points")
S3method("validDetails", "rect")
S3method("validDetails", "segments")
S3method("validDetails", "text")
S3method("widthDetails", "arrows")
S3method("widthDetails", "circle")
S3method("widthDetails", "curve")
S3method("widthDetails", "default")
S3method("widthDetails", "frame")
S3method("widthDetails", "lines")
S3method("widthDetails", "points")
S3method("widthDetails", "polygon")
S3method("widthDetails", "polyline")
S3method("widthDetails", "rect")
S3method("widthDetails", "segments")
S3method("widthDetails", "text")
S3method("widthDetails", "xspline")
#S3method("width.details", "viewport")
S3method("xDetails", "circle")
S3method("xDetails", "curve")
S3method("xDetails", "lines")
S3method("xDetails", "points")
S3method("xDetails", "polygon")
S3method("xDetails", "polyline")
S3method("xDetails", "rect")
S3method("xDetails", "segments")
S3method("xDetails", "text")
S3method("xDetails", "xspline")
S3method("yDetails", "circle")
S3method("yDetails", "curve")
S3method("yDetails", "lines")
S3method("yDetails", "points")
S3method("yDetails", "polygon")
S3method("yDetails", "polyline")
S3method("yDetails", "rect")
S3method("yDetails", "segments")
S3method("yDetails", "text")
S3method("yDetails", "xspline")

# S3 methods for internal generics that are used in calls to external fns
S3method("depth", "viewport")
S3method("depth", "vpList")
S3method("depth", "vpStack")
S3method("depth", "vpTree")
S3method("depth", "path")
S3method("pushgrobvp", "viewport")
S3method("pushgrobvp", "vpPath")
S3method("popgrobvp", "viewport")
S3method("popgrobvp", "vpPath")
S3method("setvpgpar", "viewport")
S3method("setvpgpar", "vpStack")
S3method("setvpgpar", "vpList")
S3method("setvpgpar", "vpTree")
S3method("push.vp", "default")
S3method("push.vp", "viewport")
S3method("push.vp", "vpList")
S3method("push.vp", "vpStack")
S3method("push.vp", "vpTree")

# S3 method for generic dim (in base)
S3method("dim", "layout")

# S3 method for generic rep (in base)
S3method("rep", "unit")
S3method("rep", "unit.arithmetic")
S3method("rep", "unit.list")

# S3 method for generic length (in base)
S3method("length", "unit")
S3method("length", "unit.arithmetic")
S3method("length", "unit.list")
