{- |
Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
License    : LGPL-2.1
Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)
-}

module GI.Poppler.Objects.PSFile
    ( 

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


 -- * Methods
-- ** pSFileFree
    pSFileFree                              ,


-- ** pSFileNew
    pSFileNew                               ,


-- ** pSFileSetDuplex
    pSFileSetDuplex                         ,


-- ** pSFileSetPaperSize
    pSFileSetPaperSize                      ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Poppler.Types
import GI.Poppler.Callbacks
import qualified GI.GObject as GObject

newtype PSFile = PSFile (ForeignPtr PSFile)
foreign import ccall "poppler_ps_file_get_type"
    c_poppler_ps_file_get_type :: IO GType

type instance ParentTypes PSFile = PSFileParentTypes
type PSFileParentTypes = '[GObject.Object]

instance GObject PSFile where
    gobjectIsInitiallyUnowned _ = False
    gobjectType _ = c_poppler_ps_file_get_type
    

class GObject o => PSFileK o
instance (GObject o, IsDescendantOf PSFile o) => PSFileK o

toPSFile :: PSFileK o => o -> IO PSFile
toPSFile = unsafeCastTo PSFile

noPSFile :: Maybe PSFile
noPSFile = Nothing

type instance AttributeList PSFile = PSFileAttributeList
type PSFileAttributeList = ('[ ] :: [(Symbol, *)])

type instance SignalList PSFile = PSFileSignalList
type PSFileSignalList = ('[ '("notify", GObject.ObjectNotifySignalInfo), '("notify::[property]", GObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method PSFile::new
-- method type : Constructor
-- Args : [Arg {argName = "document", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "first_page", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "n_pages", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "document", argType = TInterface "Poppler" "Document", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "filename", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "first_page", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "n_pages", argType = TBasicType TInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Poppler" "PSFile"
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_new" poppler_ps_file_new :: 
    Ptr Document ->                         -- document : TInterface "Poppler" "Document"
    CString ->                              -- filename : TBasicType TUTF8
    Int32 ->                                -- first_page : TBasicType TInt32
    Int32 ->                                -- n_pages : TBasicType TInt32
    IO (Ptr PSFile)


pSFileNew ::
    (MonadIO m, DocumentK a) =>
    a ->                                    -- document
    T.Text ->                               -- filename
    Int32 ->                                -- first_page
    Int32 ->                                -- n_pages
    m PSFile
pSFileNew document filename first_page n_pages = liftIO $ do
    let document' = unsafeManagedPtrCastPtr document
    filename' <- textToCString filename
    result <- poppler_ps_file_new document' filename' first_page n_pages
    checkUnexpectedReturnNULL "poppler_ps_file_new" result
    result' <- (wrapObject PSFile) result
    touchManagedPtr document
    freeMem filename'
    return result'

-- method PSFile::free
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "PSFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "PSFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_free" poppler_ps_file_free :: 
    Ptr PSFile ->                           -- _obj : TInterface "Poppler" "PSFile"
    IO ()


pSFileFree ::
    (MonadIO m, PSFileK a) =>
    a ->                                    -- _obj
    m ()
pSFileFree _obj = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    poppler_ps_file_free _obj'
    touchManagedPtr _obj
    return ()

-- method PSFile::set_duplex
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "PSFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "duplex", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "PSFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "duplex", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_set_duplex" poppler_ps_file_set_duplex :: 
    Ptr PSFile ->                           -- _obj : TInterface "Poppler" "PSFile"
    CInt ->                                 -- duplex : TBasicType TBoolean
    IO ()


pSFileSetDuplex ::
    (MonadIO m, PSFileK a) =>
    a ->                                    -- _obj
    Bool ->                                 -- duplex
    m ()
pSFileSetDuplex _obj duplex = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let duplex' = (fromIntegral . fromEnum) duplex
    poppler_ps_file_set_duplex _obj' duplex'
    touchManagedPtr _obj
    return ()

-- method PSFile::set_paper_size
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Poppler" "PSFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "width", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "height", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Poppler" "PSFile", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "width", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "height", argType = TBasicType TDouble, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "poppler_ps_file_set_paper_size" poppler_ps_file_set_paper_size :: 
    Ptr PSFile ->                           -- _obj : TInterface "Poppler" "PSFile"
    CDouble ->                              -- width : TBasicType TDouble
    CDouble ->                              -- height : TBasicType TDouble
    IO ()


pSFileSetPaperSize ::
    (MonadIO m, PSFileK a) =>
    a ->                                    -- _obj
    Double ->                               -- width
    Double ->                               -- height
    m ()
pSFileSetPaperSize _obj width height = liftIO $ do
    let _obj' = unsafeManagedPtrCastPtr _obj
    let width' = realToFrac width
    let height' = realToFrac height
    poppler_ps_file_set_paper_size _obj' width' height'
    touchManagedPtr _obj
    return ()