{- |
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 data structure for holding a rectangle. Those coordinates are
relative to the component top-level parent.
-}

module GI.Atk.Structs.Rectangle
    ( 

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


 -- * Properties
-- ** height #attr:height#
    getRectangleHeight                      ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    rectangle_height                        ,
#endif
    setRectangleHeight                      ,


-- ** width #attr:width#
    getRectangleWidth                       ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    rectangle_width                         ,
#endif
    setRectangleWidth                       ,


-- ** x #attr:x#
    getRectangleX                           ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    rectangle_x                             ,
#endif
    setRectangleX                           ,


-- ** y #attr:y#
    getRectangleY                           ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    rectangle_y                             ,
#endif
    setRectangleY                           ,




    ) 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


newtype Rectangle = Rectangle (ManagedPtr Rectangle)
foreign import ccall "atk_rectangle_get_type" c_atk_rectangle_get_type :: 
    IO GType

instance BoxedObject Rectangle where
    boxedType _ = c_atk_rectangle_get_type

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

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


noRectangle :: Maybe Rectangle
noRectangle = Nothing

getRectangleX :: MonadIO m => Rectangle -> m Int32
getRectangleX s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int32
    return val

setRectangleX :: MonadIO m => Rectangle -> Int32 -> m ()
setRectangleX s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RectangleXFieldInfo
instance AttrInfo RectangleXFieldInfo where
    type AttrAllowedOps RectangleXFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleXFieldInfo = (~) Int32
    type AttrBaseTypeConstraint RectangleXFieldInfo = (~) Rectangle
    type AttrGetType RectangleXFieldInfo = Int32
    type AttrLabel RectangleXFieldInfo = "x"
    type AttrOrigin RectangleXFieldInfo = Rectangle
    attrGet _ = getRectangleX
    attrSet _ = setRectangleX
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_x :: AttrLabelProxy "x"
rectangle_x = AttrLabelProxy

#endif


getRectangleY :: MonadIO m => Rectangle -> m Int32
getRectangleY s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 4) :: IO Int32
    return val

setRectangleY :: MonadIO m => Rectangle -> Int32 -> m ()
setRectangleY s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 4) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RectangleYFieldInfo
instance AttrInfo RectangleYFieldInfo where
    type AttrAllowedOps RectangleYFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleYFieldInfo = (~) Int32
    type AttrBaseTypeConstraint RectangleYFieldInfo = (~) Rectangle
    type AttrGetType RectangleYFieldInfo = Int32
    type AttrLabel RectangleYFieldInfo = "y"
    type AttrOrigin RectangleYFieldInfo = Rectangle
    attrGet _ = getRectangleY
    attrSet _ = setRectangleY
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_y :: AttrLabelProxy "y"
rectangle_y = AttrLabelProxy

#endif


getRectangleWidth :: MonadIO m => Rectangle -> m Int32
getRectangleWidth s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Int32
    return val

setRectangleWidth :: MonadIO m => Rectangle -> Int32 -> m ()
setRectangleWidth s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RectangleWidthFieldInfo
instance AttrInfo RectangleWidthFieldInfo where
    type AttrAllowedOps RectangleWidthFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleWidthFieldInfo = (~) Int32
    type AttrBaseTypeConstraint RectangleWidthFieldInfo = (~) Rectangle
    type AttrGetType RectangleWidthFieldInfo = Int32
    type AttrLabel RectangleWidthFieldInfo = "width"
    type AttrOrigin RectangleWidthFieldInfo = Rectangle
    attrGet _ = getRectangleWidth
    attrSet _ = setRectangleWidth
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_width :: AttrLabelProxy "width"
rectangle_width = AttrLabelProxy

#endif


getRectangleHeight :: MonadIO m => Rectangle -> m Int32
getRectangleHeight s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Int32
    return val

setRectangleHeight :: MonadIO m => Rectangle -> Int32 -> m ()
setRectangleHeight s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Int32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data RectangleHeightFieldInfo
instance AttrInfo RectangleHeightFieldInfo where
    type AttrAllowedOps RectangleHeightFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RectangleHeightFieldInfo = (~) Int32
    type AttrBaseTypeConstraint RectangleHeightFieldInfo = (~) Rectangle
    type AttrGetType RectangleHeightFieldInfo = Int32
    type AttrLabel RectangleHeightFieldInfo = "height"
    type AttrOrigin RectangleHeightFieldInfo = Rectangle
    attrGet _ = getRectangleHeight
    attrSet _ = setRectangleHeight
    attrConstruct = undefined
    attrClear _ = undefined

rectangle_height :: AttrLabelProxy "height"
rectangle_height = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList Rectangle
type instance O.AttributeList Rectangle = RectangleAttributeList
type RectangleAttributeList = ('[ '("x", RectangleXFieldInfo), '("y", RectangleYFieldInfo), '("width", RectangleWidthFieldInfo), '("height", RectangleHeightFieldInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveRectangleMethod (t :: Symbol) (o :: *) :: * where
    ResolveRectangleMethod l o = O.MethodResolutionFailed l o

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

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

#endif