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

A 'GI.Poppler.Structs.Rectangle.Rectangle' is used to describe
locations on a page and bounding boxes
-}

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

module GI.Poppler.Structs.Rectangle
    (

-- * Exported types
    Rectangle(..)                           ,
    newZeroRectangle                        ,
    noRectangle                             ,


 -- * Methods
-- ** copy #method:copy#

#if ENABLE_OVERLOADING
    RectangleCopyMethodInfo                 ,
#endif
    rectangleCopy                           ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    RectangleFreeMethodInfo                 ,
#endif
    rectangleFree                           ,


-- ** new #method:new#

    rectangleNew                            ,




 -- * Properties
-- ** x1 #attr:x1#
{- | x coordinate of lower left corner
-}
    getRectangleX1                          ,
#if ENABLE_OVERLOADING
    rectangle_x1                            ,
#endif
    setRectangleX1                          ,


-- ** x2 #attr:x2#
{- | x coordinate of upper right corner
-}
    getRectangleX2                          ,
#if ENABLE_OVERLOADING
    rectangle_x2                            ,
#endif
    setRectangleX2                          ,


-- ** y1 #attr:y1#
{- | y coordinate of lower left corner
-}
    getRectangleY1                          ,
#if ENABLE_OVERLOADING
    rectangle_y1                            ,
#endif
    setRectangleY1                          ,


-- ** y2 #attr:y2#
{- | y coordinate of upper right corner
-}
    getRectangleY2                          ,
#if ENABLE_OVERLOADING
    rectangle_y2                            ,
#endif
    setRectangleY2                          ,




    ) 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


-- | Memory-managed wrapper type.
newtype Rectangle = Rectangle (ManagedPtr Rectangle)
foreign import ccall "poppler_rectangle_get_type" c_poppler_rectangle_get_type ::
    IO GType

instance BoxedObject Rectangle where
    boxedType _ = c_poppler_rectangle_get_type

-- | Construct a `Rectangle` struct initialized to zero.
newZeroRectangle :: MonadIO m => m Rectangle
newZeroRectangle = liftIO $ callocBoxedBytes 32 >>= wrapBoxed Rectangle

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


-- | A convenience alias for `Nothing` :: `Maybe` `Rectangle`.
noRectangle :: Maybe Rectangle
noRectangle = Nothing

{- |
Get the value of the “@x1@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' rectangle #x1
@
-}
getRectangleX1 :: MonadIO m => Rectangle -> m Double
getRectangleX1 s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CDouble
    let val' = realToFrac val
    return val'

{- |
Set the value of the “@x1@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' rectangle [ #x1 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRectangleX1 :: MonadIO m => Rectangle -> Double -> m ()
setRectangleX1 s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = realToFrac val
    poke (ptr `plusPtr` 0) (val' :: CDouble)

#if ENABLE_OVERLOADING
data RectangleX1FieldInfo
instance AttrInfo RectangleX1FieldInfo where
    type AttrAllowedOps RectangleX1FieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleX1FieldInfo = (~) Double
    type AttrBaseTypeConstraint RectangleX1FieldInfo = (~) Rectangle
    type AttrGetType RectangleX1FieldInfo = Double
    type AttrLabel RectangleX1FieldInfo = "x1"
    type AttrOrigin RectangleX1FieldInfo = Rectangle
    attrGet _ = getRectangleX1
    attrSet _ = setRectangleX1
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_x1 :: AttrLabelProxy "x1"
rectangle_x1 = AttrLabelProxy

#endif


{- |
Get the value of the “@y1@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' rectangle #y1
@
-}
getRectangleY1 :: MonadIO m => Rectangle -> m Double
getRectangleY1 s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO CDouble
    let val' = realToFrac val
    return val'

{- |
Set the value of the “@y1@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' rectangle [ #y1 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRectangleY1 :: MonadIO m => Rectangle -> Double -> m ()
setRectangleY1 s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = realToFrac val
    poke (ptr `plusPtr` 8) (val' :: CDouble)

#if ENABLE_OVERLOADING
data RectangleY1FieldInfo
instance AttrInfo RectangleY1FieldInfo where
    type AttrAllowedOps RectangleY1FieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleY1FieldInfo = (~) Double
    type AttrBaseTypeConstraint RectangleY1FieldInfo = (~) Rectangle
    type AttrGetType RectangleY1FieldInfo = Double
    type AttrLabel RectangleY1FieldInfo = "y1"
    type AttrOrigin RectangleY1FieldInfo = Rectangle
    attrGet _ = getRectangleY1
    attrSet _ = setRectangleY1
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_y1 :: AttrLabelProxy "y1"
rectangle_y1 = AttrLabelProxy

#endif


{- |
Get the value of the “@x2@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' rectangle #x2
@
-}
getRectangleX2 :: MonadIO m => Rectangle -> m Double
getRectangleX2 s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO CDouble
    let val' = realToFrac val
    return val'

{- |
Set the value of the “@x2@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' rectangle [ #x2 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRectangleX2 :: MonadIO m => Rectangle -> Double -> m ()
setRectangleX2 s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = realToFrac val
    poke (ptr `plusPtr` 16) (val' :: CDouble)

#if ENABLE_OVERLOADING
data RectangleX2FieldInfo
instance AttrInfo RectangleX2FieldInfo where
    type AttrAllowedOps RectangleX2FieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleX2FieldInfo = (~) Double
    type AttrBaseTypeConstraint RectangleX2FieldInfo = (~) Rectangle
    type AttrGetType RectangleX2FieldInfo = Double
    type AttrLabel RectangleX2FieldInfo = "x2"
    type AttrOrigin RectangleX2FieldInfo = Rectangle
    attrGet _ = getRectangleX2
    attrSet _ = setRectangleX2
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_x2 :: AttrLabelProxy "x2"
rectangle_x2 = AttrLabelProxy

#endif


{- |
Get the value of the “@y2@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.get' rectangle #y2
@
-}
getRectangleY2 :: MonadIO m => Rectangle -> m Double
getRectangleY2 s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO CDouble
    let val' = realToFrac val
    return val'

{- |
Set the value of the “@y2@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.set' rectangle [ #y2 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRectangleY2 :: MonadIO m => Rectangle -> Double -> m ()
setRectangleY2 s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = realToFrac val
    poke (ptr `plusPtr` 24) (val' :: CDouble)

#if ENABLE_OVERLOADING
data RectangleY2FieldInfo
instance AttrInfo RectangleY2FieldInfo where
    type AttrAllowedOps RectangleY2FieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleY2FieldInfo = (~) Double
    type AttrBaseTypeConstraint RectangleY2FieldInfo = (~) Rectangle
    type AttrGetType RectangleY2FieldInfo = Double
    type AttrLabel RectangleY2FieldInfo = "y2"
    type AttrOrigin RectangleY2FieldInfo = Rectangle
    attrGet _ = getRectangleY2
    attrSet _ = setRectangleY2
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_y2 :: AttrLabelProxy "y2"
rectangle_y2 = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList Rectangle
type instance O.AttributeList Rectangle = RectangleAttributeList
type RectangleAttributeList = ('[ '("x1", RectangleX1FieldInfo), '("y1", RectangleY1FieldInfo), '("x2", RectangleX2FieldInfo), '("y2", RectangleY2FieldInfo)] :: [(Symbol, *)])
#endif

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

foreign import ccall "poppler_rectangle_new" poppler_rectangle_new ::
    IO (Ptr Rectangle)

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

#if ENABLE_OVERLOADING
#endif

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

foreign import ccall "poppler_rectangle_copy" poppler_rectangle_copy ::
    Ptr Rectangle ->                        -- rectangle : TInterface (Name {namespace = "Poppler", name = "Rectangle"})
    IO (Ptr Rectangle)

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

#if ENABLE_OVERLOADING
data RectangleCopyMethodInfo
instance (signature ~ (m Rectangle), MonadIO m) => O.MethodInfo RectangleCopyMethodInfo Rectangle signature where
    overloadedMethod _ = rectangleCopy

#endif

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

foreign import ccall "poppler_rectangle_free" poppler_rectangle_free ::
    Ptr Rectangle ->                        -- rectangle : TInterface (Name {namespace = "Poppler", name = "Rectangle"})
    IO ()

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

#if ENABLE_OVERLOADING
data RectangleFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo RectangleFreeMethodInfo Rectangle signature where
    overloadedMethod _ = rectangleFree

#endif

#if ENABLE_OVERLOADING
type family ResolveRectangleMethod (t :: Symbol) (o :: *) :: * where
    ResolveRectangleMethod "copy" o = RectangleCopyMethodInfo
    ResolveRectangleMethod "free" o = RectangleFreeMethodInfo
    ResolveRectangleMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveRectangleMethod t Rectangle, O.MethodInfo info Rectangle p) => OL.IsLabel t (Rectangle -> 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