{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (inaki@blueleaf.cc)

/No description available in the introspection data./
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Poppler.Objects.PSFile
    (

-- * Exported types
    PSFile(..)                              ,
    IsPSFile                                ,
    toPSFile                                ,
    noPSFile                                ,


 -- * Methods
-- ** free #method:free#

#if ENABLE_OVERLOADING
    PSFileFreeMethodInfo                    ,
#endif
    pSFileFree                              ,


-- ** new #method:new#

    pSFileNew                               ,


-- ** setDuplex #method:setDuplex#

#if ENABLE_OVERLOADING
    PSFileSetDuplexMethodInfo               ,
#endif
    pSFileSetDuplex                         ,


-- ** setPaperSize #method:setPaperSize#

#if ENABLE_OVERLOADING
    PSFileSetPaperSizeMethodInfo            ,
#endif
    pSFileSetPaperSize                      ,




    ) where

import Data.GI.Base.ShortPrelude
import qualified Data.GI.Base.ShortPrelude as SP
import qualified Data.GI.Base.Overloading as O
import qualified Prelude as P

import qualified Data.GI.Base.Attributes as GI.Attributes
import qualified Data.GI.Base.ManagedPtr as B.ManagedPtr
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GValue as B.GValue
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
import qualified Data.GI.Base.Properties as B.Properties
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP
import qualified GHC.OverloadedLabels as OL

import qualified GI.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Poppler.Objects.Document as Poppler.Document

-- | Memory-managed wrapper type.
newtype PSFile = PSFile (ManagedPtr PSFile)
foreign import ccall "poppler_ps_file_get_type"
    c_poppler_ps_file_get_type :: IO GType

instance GObject PSFile where
    gobjectType = c_poppler_ps_file_get_type


-- | Type class for types which can be safely cast to `PSFile`, for instance with `toPSFile`.
class (GObject o, O.IsDescendantOf PSFile o) => IsPSFile o
instance (GObject o, O.IsDescendantOf PSFile o) => IsPSFile o

instance O.HasParentTypes PSFile
type instance O.ParentTypes PSFile = '[GObject.Object.Object]

-- | Cast to `PSFile`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toPSFile :: (MonadIO m, IsPSFile o) => o -> m PSFile
toPSFile = liftIO . unsafeCastTo PSFile

-- | A convenience alias for `Nothing` :: `Maybe` `PSFile`.
noPSFile :: Maybe PSFile
noPSFile = Nothing

#if ENABLE_OVERLOADING
type family ResolvePSFileMethod (t :: Symbol) (o :: *) :: * where
    ResolvePSFileMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolvePSFileMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolvePSFileMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolvePSFileMethod "free" o = PSFileFreeMethodInfo
    ResolvePSFileMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolvePSFileMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolvePSFileMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolvePSFileMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolvePSFileMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolvePSFileMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolvePSFileMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolvePSFileMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolvePSFileMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolvePSFileMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolvePSFileMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolvePSFileMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolvePSFileMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolvePSFileMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolvePSFileMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolvePSFileMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolvePSFileMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolvePSFileMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolvePSFileMethod "setDuplex" o = PSFileSetDuplexMethodInfo
    ResolvePSFileMethod "setPaperSize" o = PSFileSetPaperSizeMethodInfo
    ResolvePSFileMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolvePSFileMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolvePSFileMethod t PSFile, O.MethodInfo info PSFile p) => OL.IsLabel t (PSFile -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#else
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

#endif

#if ENABLE_OVERLOADING
instance O.HasAttributeList PSFile
type instance O.AttributeList PSFile = PSFileAttributeList
type PSFileAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
type instance O.SignalList PSFile = PSFileSignalList
type PSFileSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method PSFile::new
-- method type : Constructor
-- Args : [Arg {argCName = "document", argType = TInterface (Name {namespace = "Poppler", name = "Document"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PopplerDocument", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the path of the output filename", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "first_page", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the first page to print", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_pages", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of pages to print", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Poppler", name = "PSFile"}))
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_new" poppler_ps_file_new ::
    Ptr Poppler.Document.Document ->        -- document : TInterface (Name {namespace = "Poppler", name = "Document"})
    CString ->                              -- filename : TBasicType TUTF8
    Int32 ->                                -- first_page : TBasicType TInt
    Int32 ->                                -- n_pages : TBasicType TInt
    IO (Ptr PSFile)

{- |
Create a new postscript file to render to
-}
pSFileNew ::
    (B.CallStack.HasCallStack, MonadIO m, Poppler.Document.IsDocument a) =>
    a
    {- ^ /@document@/: a 'GI.Poppler.Objects.Document.Document' -}
    -> T.Text
    {- ^ /@filename@/: the path of the output filename -}
    -> Int32
    {- ^ /@firstPage@/: the first page to print -}
    -> Int32
    {- ^ /@nPages@/: the number of pages to print -}
    -> m PSFile
    {- ^ __Returns:__ a PopplerPSFile -}
pSFileNew document filename firstPage nPages = liftIO $ do
    document' <- unsafeManagedPtrCastPtr document
    filename' <- textToCString filename
    result <- poppler_ps_file_new document' filename' firstPage nPages
    checkUnexpectedReturnNULL "pSFileNew" result
    result' <- (wrapObject PSFile) result
    touchManagedPtr document
    freeMem filename'
    return result'

#if ENABLE_OVERLOADING
#endif

-- method PSFile::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ps_file", argType = TInterface (Name {namespace = "Poppler", name = "PSFile"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a PopplerPSFile", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_free" poppler_ps_file_free ::
    Ptr PSFile ->                           -- ps_file : TInterface (Name {namespace = "Poppler", name = "PSFile"})
    IO ()

{- |
Frees /@psFile@/
-}
pSFileFree ::
    (B.CallStack.HasCallStack, MonadIO m, IsPSFile a) =>
    a
    {- ^ /@psFile@/: a PopplerPSFile -}
    -> m ()
pSFileFree psFile = liftIO $ do
    psFile' <- unsafeManagedPtrCastPtr psFile
    poppler_ps_file_free psFile'
    touchManagedPtr psFile
    return ()

#if ENABLE_OVERLOADING
data PSFileFreeMethodInfo
instance (signature ~ (m ()), MonadIO m, IsPSFile a) => O.MethodInfo PSFileFreeMethodInfo a signature where
    overloadedMethod _ = pSFileFree

#endif

-- method PSFile::set_duplex
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ps_file", argType = TInterface (Name {namespace = "Poppler", name = "PSFile"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a PopplerPSFile which was not yet printed to", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "duplex", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether to force duplex printing (on printers which support this)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_set_duplex" poppler_ps_file_set_duplex ::
    Ptr PSFile ->                           -- ps_file : TInterface (Name {namespace = "Poppler", name = "PSFile"})
    CInt ->                                 -- duplex : TBasicType TBoolean
    IO ()

{- |
Enable or disable Duplex printing.
-}
pSFileSetDuplex ::
    (B.CallStack.HasCallStack, MonadIO m, IsPSFile a) =>
    a
    {- ^ /@psFile@/: a PopplerPSFile which was not yet printed to -}
    -> Bool
    {- ^ /@duplex@/: whether to force duplex printing (on printers which support this) -}
    -> m ()
pSFileSetDuplex psFile duplex = liftIO $ do
    psFile' <- unsafeManagedPtrCastPtr psFile
    let duplex' = (fromIntegral . fromEnum) duplex
    poppler_ps_file_set_duplex psFile' duplex'
    touchManagedPtr psFile
    return ()

#if ENABLE_OVERLOADING
data PSFileSetDuplexMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsPSFile a) => O.MethodInfo PSFileSetDuplexMethodInfo a signature where
    overloadedMethod _ = pSFileSetDuplex

#endif

-- method PSFile::set_paper_size
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "ps_file", argType = TInterface (Name {namespace = "Poppler", name = "PSFile"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a PopplerPSFile which was not yet printed to.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "width", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the paper width in 1/72 inch", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "height", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the paper height in 1/72 inch", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_set_paper_size" poppler_ps_file_set_paper_size ::
    Ptr PSFile ->                           -- ps_file : TInterface (Name {namespace = "Poppler", name = "PSFile"})
    CDouble ->                              -- width : TBasicType TDouble
    CDouble ->                              -- height : TBasicType TDouble
    IO ()

{- |
Set the output paper size. These values will end up in the
DocumentMedia, the BoundingBox DSC comments and other places in the
generated PostScript.
-}
pSFileSetPaperSize ::
    (B.CallStack.HasCallStack, MonadIO m, IsPSFile a) =>
    a
    {- ^ /@psFile@/: a PopplerPSFile which was not yet printed to. -}
    -> Double
    {- ^ /@width@/: the paper width in 1\/72 inch -}
    -> Double
    {- ^ /@height@/: the paper height in 1\/72 inch -}
    -> m ()
pSFileSetPaperSize psFile width height = liftIO $ do
    psFile' <- unsafeManagedPtrCastPtr psFile
    let width' = realToFrac width
    let height' = realToFrac height
    poppler_ps_file_set_paper_size psFile' width' height'
    touchManagedPtr psFile
    return ()

#if ENABLE_OVERLOADING
data PSFileSetPaperSizeMethodInfo
instance (signature ~ (Double -> Double -> m ()), MonadIO m, IsPSFile a) => O.MethodInfo PSFileSetPaperSizeMethodInfo a signature where
    overloadedMethod _ = pSFileSetPaperSize

#endif