useDynLib("grid", .registration = TRUE, .fixes = "C_")

import(grDevices)
importFrom(utils, str)

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

       "current.viewport", "current.vpPath", "current.vpTree",
       "current.transform", "current.rotation", "current.parent",
       "depth", "explode",
       "engine.display.list",
       "gpar", "get.gpar",
       "grid.collection",
       "grid.copy", "grid.display.list", "grid.draw",
       "grid.record", "recordGrob", "grid.delay", "grid.DLapply",
       "grid.grill",
       "grid.layout", "grid.locator",
       "grid.newpage",
       "grid.plot.and.legend",
       "grid.pretty",
       "grid.refresh",
       "grid.show.layout", "grid.show.viewport",

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

       "valid.just", "resolveHJust", "resolveVJust",
       "resolveRasterSize",

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

       "makeContext", "makeContent",
       "drawDetails", "preDrawDetails", "postDrawDetails",
       "editDetails",
       "validDetails",
       "heightDetails", "widthDetails",
       "xDetails", "yDetails",
       "ascentDetails", "descentDetails",

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

       # Creating and modifying grobs (and gTrees)
       "is.grob",
       "grid.grob",
       "grob", "gList", "gTree", "gPath", "grobTree",
       "grobName",
       "grid.get", "grid.set", "grid.add", "grid.remove", "grid.edit",
       "grid.gedit", "grid.gremove", "grid.gget",
       "getGrob", "setGrob", "addGrob", "removeGrob", "editGrob", "forceGrob",
       "gEdit", "gEditList", "applyEdit", "applyEdits",
       "grid.grab", "grid.grabExpr",
       "grid.force", "grid.revert",
       "grid.reorder", "reorderGrob",
       "grid.cap",
       "setChildren",
       "showGrob",

       # Listing grobs and viewports
       "grid.ls",
       "nestedListing", "pathListing", "grobPathListing",
       "grid.grep",
       # Deprecated
       "getNames", "childNames",

       # Creating and drawing predefined grobs and gTrees
       "grid.abline",
       "grid.arrows", "grid.circle", "grid.clip", "grid.curve",
       "grid.function",
       "grid.line.to", "grid.lines", "grid.move.to", "grid.null",
       "grid.points", "grid.path", "grid.polygon", "grid.polyline",
       "grid.raster", "grid.rect", "grid.roundrect",
       "grid.segments", "grid.text", "grid.xspline", "grid.bezier",
       "arrowsGrob", "circleGrob", "clipGrob", "curveGrob",
       "functionGrob",
       "linesGrob", "lineToGrob", "moveToGrob", "nullGrob",
       "pointsGrob", "pathGrob", "polygonGrob", "polylineGrob",
       "rasterGrob", "rectGrob", "roundrectGrob",
       "segmentsGrob", "textGrob", "xsplineGrob", "bezierGrob",
       "xsplinePoints", "bezierPoints",

       "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", "legendGrob",
       "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("[", "vpPath")
S3method("[<-", "unit")
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("format", "unit")
S3method("format", "unit.arithmetic")
S3method("format", "unit.list")
S3method("print", "grob")
S3method("print", "gList")
S3method("print", "unit")
S3method("print", "viewport")
S3method("print", "path")
S3method("print", "gpar")
S3method("print", "flatGridListing")

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

S3method("drawDetails", "arrows")
S3method("drawDetails", "circle")
S3method("drawDetails", "grob")
S3method("drawDetails", "line.to")
S3method("drawDetails", "lines")
S3method("drawDetails", "move.to")
S3method("drawDetails", "points")
S3method("drawDetails", "pathgrob")
S3method("drawDetails", "polygon")
S3method("drawDetails", "polyline")
S3method("drawDetails", "xspline")
S3method("drawDetails", "rect")
S3method("drawDetails", "segments")
S3method("drawDetails", "text")

S3method("editDetails", "default")
S3method("editDetails", "xaxis")
S3method("editDetails", "yaxis")

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("gridList", "default")
S3method("gridList", "grob")
S3method("gridList", "gList")
S3method("gridList", "gTree")
S3method("gridList", "viewport")
S3method("gridList", "vpList")
S3method("gridList", "vpStack")
S3method("gridList", "vpTree")
S3method("gridList", "vpPath")
S3method("gridList", "pop")
S3method("gridList", "up")

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("grobAscent", "grob")
S3method("grobAscent", "gList")
S3method("grobAscent", "gPath")
S3method("grobAscent", "default")
S3method("grobDescent", "grob")
S3method("grobDescent", "gList")
S3method("grobDescent", "gPath")
S3method("grobDescent", "default")

S3method("heightDetails", "arrows")
S3method("heightDetails", "circle")
S3method("heightDetails", "curve")
S3method("heightDetails", "functiongrob")
S3method("heightDetails", "default")
S3method("heightDetails", "frame")
S3method("heightDetails", "lines")
S3method("heightDetails", "points")
S3method("heightDetails", "polygon")
S3method("heightDetails", "polyline")
S3method("heightDetails", "rect")
S3method("heightDetails", "roundrect")
S3method("heightDetails", "segments")
S3method("heightDetails", "text")
S3method("heightDetails", "xspline")
S3method("heightDetails", "beziergrob")
S3method("heightDetails", "rastergrob")
#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", "functiongrob")
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", "roundrect")
S3method("validDetails", "segments")
S3method("validDetails", "text")
S3method("validDetails", "xspline")
S3method("validDetails", "beziergrob")
S3method("validDetails", "rastergrob")

S3method("widthDetails", "arrows")
S3method("widthDetails", "circle")
S3method("widthDetails", "curve")
S3method("widthDetails", "functiongrob")
S3method("widthDetails", "default")
S3method("widthDetails", "frame")
S3method("widthDetails", "lines")
S3method("widthDetails", "points")
S3method("widthDetails", "polygon")
S3method("widthDetails", "polyline")
S3method("widthDetails", "rect")
S3method("widthDetails", "roundrect")
S3method("widthDetails", "segments")
S3method("widthDetails", "text")
S3method("widthDetails", "xspline")
S3method("widthDetails", "beziergrob")
S3method("widthDetails", "rastergrob")
#S3method("width.details", "viewport")

S3method("xDetails", "circle")
S3method("xDetails", "curve")
S3method("xDetails", "functiongrob")
S3method("xDetails", "lines")
S3method("xDetails", "points")
S3method("xDetails", "polygon")
S3method("xDetails", "polyline")
S3method("xDetails", "rect")
S3method("xDetails", "roundrect")
S3method("xDetails", "segments")
S3method("xDetails", "text")
S3method("xDetails", "xspline")
S3method("xDetails", "beziergrob")
S3method("xDetails", "rastergrob")

S3method("yDetails", "circle")
S3method("yDetails", "curve")
S3method("yDetails", "functiongrob")
S3method("yDetails", "lines")
S3method("yDetails", "points")
S3method("yDetails", "polygon")
S3method("yDetails", "polyline")
S3method("yDetails", "rect")
S3method("yDetails", "roundrect")
S3method("yDetails", "segments")
S3method("yDetails", "text")
S3method("yDetails", "xspline")
S3method("yDetails", "beziergrob")
S3method("yDetails", "rastergrob")

S3method("ascentDetails", "default")
S3method("ascentDetails", "grob")
S3method("ascentDetails", "text")

S3method("descentDetails", "default")
S3method("descentDetails", "text")

S3method("forceGrob", "default")
S3method("forceGrob", "grob")
S3method("forceGrob", "gTree")

S3method("absolute.units", "unit")
S3method("absolute.units", "unit.list")
S3method("absolute.units", "unit.arithmetic")

# 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("explode", "character")
S3method("explode", "path")
S3method("drawVP", "viewport")
S3method("drawVP", "vpList")
S3method("drawVP", "vpStack")
S3method("drawVP", "vpTree")
S3method("drawVP", "vpPath")
S3method("labelGrob", "grob")
S3method("labelGrob", "gTree")
S3method("leafPaths", "viewport")
S3method("leafPaths", "vpList")
S3method("leafPaths", "vpStack")
S3method("leafPaths", "vpTree")
S3method("leafPaths", "vpPath")
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")
S3method("push.vp", "vpPath")

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

# S3 method for generic rep (in base)
S3method("rep", "unit")
S3method("rep", "arrow")

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

# S3 method for generic str (in utils)
S3method("str", "unit.arithmetic")
S3method("str", "arrow")

S3method("makeContent", "beziergrob")
S3method("makeContent", "roundrect")
S3method("makeContent", "curve")
S3method("makeContent", "functiongrob")
S3method("makeContent", "delayedgrob")
S3method("makeContent", "xaxis")
S3method("makeContent", "yaxis")
S3method("makeContent", "forcedgrob")

S3method("makeContext", "roundrect")
S3method("makeContext", "frame")
S3method("makeContext", "cellGrob")
S3method("makeContext", "forcedgrob")

S3method("grid.force", "default")
S3method("grid.force", "grob")
S3method("grid.force", "character")
S3method("grid.force", "gPath")
S3method("grid.revert", "default")
S3method("grid.revert", "grob")
S3method("grid.revert", "character")
S3method("grid.revert", "gPath")
