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

A 'GI.Poppler.Structs.FormFieldMapping.FormFieldMapping' structure represents the location
of /@field@/ on the page
-}

module GI.Poppler.Structs.FormFieldMapping
    ( 

-- * Exported types
    FormFieldMapping(..)                    ,
    newZeroFormFieldMapping                 ,
    noFormFieldMapping                      ,


 -- * Methods
-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    FormFieldMappingCopyMethodInfo          ,
#endif
    formFieldMappingCopy                    ,


-- ** free #method:free#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    FormFieldMappingFreeMethodInfo          ,
#endif
    formFieldMappingFree                    ,


-- ** new #method:new#
    formFieldMappingNew                     ,




 -- * Properties
-- ** area #attr:area#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    formFieldMapping_area                   ,
#endif
    getFormFieldMappingArea                 ,


-- ** field #attr:field#
    clearFormFieldMappingField              ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    formFieldMapping_field                  ,
#endif
    getFormFieldMappingField                ,
    setFormFieldMappingField                ,




    ) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 {-# SOURCE #-} qualified GI.Poppler.Objects.FormField as Poppler.FormField
import {-# SOURCE #-} qualified GI.Poppler.Structs.Rectangle as Poppler.Rectangle

newtype FormFieldMapping = FormFieldMapping (ManagedPtr FormFieldMapping)
foreign import ccall "poppler_form_field_mapping_get_type" c_poppler_form_field_mapping_get_type :: 
    IO GType

instance BoxedObject FormFieldMapping where
    boxedType _ = c_poppler_form_field_mapping_get_type

-- | Construct a `FormFieldMapping` struct initialized to zero.
newZeroFormFieldMapping :: MonadIO m => m FormFieldMapping
newZeroFormFieldMapping = liftIO $ callocBoxedBytes 40 >>= wrapBoxed FormFieldMapping

instance tag ~ 'AttrSet => Constructible FormFieldMapping tag where
    new _ attrs = do
        o <- newZeroFormFieldMapping
        GI.Attributes.set o attrs
        return o


noFormFieldMapping :: Maybe FormFieldMapping
noFormFieldMapping = Nothing

getFormFieldMappingArea :: MonadIO m => FormFieldMapping -> m Poppler.Rectangle.Rectangle
getFormFieldMappingArea s = liftIO $ withManagedPtr s $ \ptr -> do
    let val = ptr `plusPtr` 0 :: (Ptr Poppler.Rectangle.Rectangle)
    val' <- (newBoxed Poppler.Rectangle.Rectangle) val
    return val'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data FormFieldMappingAreaFieldInfo
instance AttrInfo FormFieldMappingAreaFieldInfo where
    type AttrAllowedOps FormFieldMappingAreaFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint FormFieldMappingAreaFieldInfo = (~) (Ptr Poppler.Rectangle.Rectangle)
    type AttrBaseTypeConstraint FormFieldMappingAreaFieldInfo = (~) FormFieldMapping
    type AttrGetType FormFieldMappingAreaFieldInfo = Poppler.Rectangle.Rectangle
    type AttrLabel FormFieldMappingAreaFieldInfo = "area"
    type AttrOrigin FormFieldMappingAreaFieldInfo = FormFieldMapping
    attrGet _ = getFormFieldMappingArea
    attrSet _ = undefined
    attrConstruct = undefined
    attrClear _ = undefined

formFieldMapping_area :: AttrLabelProxy "area"
formFieldMapping_area = AttrLabelProxy

#endif


getFormFieldMappingField :: MonadIO m => FormFieldMapping -> m (Maybe Poppler.FormField.FormField)
getFormFieldMappingField s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 32) :: IO (Ptr Poppler.FormField.FormField)
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- (newObject Poppler.FormField.FormField) val'
        return val''
    return result

setFormFieldMappingField :: MonadIO m => FormFieldMapping -> Ptr Poppler.FormField.FormField -> m ()
setFormFieldMappingField s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (val :: Ptr Poppler.FormField.FormField)

clearFormFieldMappingField :: MonadIO m => FormFieldMapping -> m ()
clearFormFieldMappingField s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 32) (FP.nullPtr :: Ptr Poppler.FormField.FormField)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data FormFieldMappingFieldFieldInfo
instance AttrInfo FormFieldMappingFieldFieldInfo where
    type AttrAllowedOps FormFieldMappingFieldFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint FormFieldMappingFieldFieldInfo = (~) (Ptr Poppler.FormField.FormField)
    type AttrBaseTypeConstraint FormFieldMappingFieldFieldInfo = (~) FormFieldMapping
    type AttrGetType FormFieldMappingFieldFieldInfo = Maybe Poppler.FormField.FormField
    type AttrLabel FormFieldMappingFieldFieldInfo = "field"
    type AttrOrigin FormFieldMappingFieldFieldInfo = FormFieldMapping
    attrGet _ = getFormFieldMappingField
    attrSet _ = setFormFieldMappingField
    attrConstruct = undefined
    attrClear _ = clearFormFieldMappingField

formFieldMapping_field :: AttrLabelProxy "field"
formFieldMapping_field = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList FormFieldMapping
type instance O.AttributeList FormFieldMapping = FormFieldMappingAttributeList
type FormFieldMappingAttributeList = ('[ '("area", FormFieldMappingAreaFieldInfo), '("field", FormFieldMappingFieldFieldInfo)] :: [(Symbol, *)])
#endif

-- method FormFieldMapping::new
-- method type : Constructor
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Poppler", name = "FormFieldMapping"}))
-- throws : False
-- Skip return : False

foreign import ccall "poppler_form_field_mapping_new" poppler_form_field_mapping_new :: 
    IO (Ptr FormFieldMapping)

{- |
Creates a new 'GI.Poppler.Structs.FormFieldMapping.FormFieldMapping'
-}
formFieldMappingNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m FormFieldMapping
    {- ^ __Returns:__ a new 'GI.Poppler.Structs.FormFieldMapping.FormFieldMapping', use 'GI.Poppler.Structs.FormFieldMapping.formFieldMappingFree' to free it -}
formFieldMappingNew  = liftIO $ do
    result <- poppler_form_field_mapping_new
    checkUnexpectedReturnNULL "formFieldMappingNew" result
    result' <- (wrapBoxed FormFieldMapping) result
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

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

foreign import ccall "poppler_form_field_mapping_copy" poppler_form_field_mapping_copy :: 
    Ptr FormFieldMapping ->                 -- mapping : TInterface (Name {namespace = "Poppler", name = "FormFieldMapping"})
    IO (Ptr FormFieldMapping)

{- |
Creates a copy of /@mapping@/
-}
formFieldMappingCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FormFieldMapping
    {- ^ /@mapping@/: a 'GI.Poppler.Structs.FormFieldMapping.FormFieldMapping' to copy -}
    -> m FormFieldMapping
    {- ^ __Returns:__ a new allocated copy of /@mapping@/ -}
formFieldMappingCopy mapping = liftIO $ do
    mapping' <- unsafeManagedPtrGetPtr mapping
    result <- poppler_form_field_mapping_copy mapping'
    checkUnexpectedReturnNULL "formFieldMappingCopy" result
    result' <- (wrapBoxed FormFieldMapping) result
    touchManagedPtr mapping
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data FormFieldMappingCopyMethodInfo
instance (signature ~ (m FormFieldMapping), MonadIO m) => O.MethodInfo FormFieldMappingCopyMethodInfo FormFieldMapping signature where
    overloadedMethod _ = formFieldMappingCopy

#endif

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

foreign import ccall "poppler_form_field_mapping_free" poppler_form_field_mapping_free :: 
    Ptr FormFieldMapping ->                 -- mapping : TInterface (Name {namespace = "Poppler", name = "FormFieldMapping"})
    IO ()

{- |
Frees the given 'GI.Poppler.Structs.FormFieldMapping.FormFieldMapping'
-}
formFieldMappingFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FormFieldMapping
    {- ^ /@mapping@/: a 'GI.Poppler.Structs.FormFieldMapping.FormFieldMapping' -}
    -> m ()
formFieldMappingFree mapping = liftIO $ do
    mapping' <- unsafeManagedPtrGetPtr mapping
    poppler_form_field_mapping_free mapping'
    touchManagedPtr mapping
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data FormFieldMappingFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo FormFieldMappingFreeMethodInfo FormFieldMapping signature where
    overloadedMethod _ = formFieldMappingFree

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveFormFieldMappingMethod (t :: Symbol) (o :: *) :: * where
    ResolveFormFieldMappingMethod "copy" o = FormFieldMappingCopyMethodInfo
    ResolveFormFieldMappingMethod "free" o = FormFieldMappingFreeMethodInfo
    ResolveFormFieldMappingMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveFormFieldMappingMethod t FormFieldMapping, O.MethodInfo info FormFieldMapping p) => O.IsLabelProxy t (FormFieldMapping -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveFormFieldMappingMethod t FormFieldMapping, O.MethodInfo info FormFieldMapping p) => O.IsLabel t (FormFieldMapping -> 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

#endif