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

Represents a request of a screen object in a given orientation. These
are primarily used in container implementations when allocating a natural
size for children calling. See 'GI.Gtk.Functions.distributeNaturalAllocation'.
-}

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

module GI.Gtk.Structs.RequestedSize
    (

-- * Exported types
    RequestedSize(..)                       ,
    newZeroRequestedSize                    ,
    noRequestedSize                         ,


 -- * Properties
-- ** data #attr:data#
{- | A client pointer
-}
    clearRequestedSizeData                  ,
    getRequestedSizeData                    ,
#if ENABLE_OVERLOADING
    requestedSize_data                      ,
#endif
    setRequestedSizeData                    ,


-- ** minimumSize #attr:minimumSize#
{- | The minimum size needed for allocation in a given orientation
-}
    getRequestedSizeMinimumSize             ,
#if ENABLE_OVERLOADING
    requestedSize_minimumSize               ,
#endif
    setRequestedSizeMinimumSize             ,


-- ** naturalSize #attr:naturalSize#
{- | The natural size for allocation in a given orientation
-}
    getRequestedSizeNaturalSize             ,
#if ENABLE_OVERLOADING
    requestedSize_naturalSize               ,
#endif
    setRequestedSizeNaturalSize             ,




    ) 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.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.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map
import qualified Foreign.Ptr as FP


-- | Memory-managed wrapper type.
newtype RequestedSize = RequestedSize (ManagedPtr RequestedSize)
instance WrappedPtr RequestedSize where
    wrappedPtrCalloc = callocBytes 16
    wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 16 >=> wrapPtr RequestedSize)
    wrappedPtrFree = Just ptr_to_g_free

-- | Construct a `RequestedSize` struct initialized to zero.
newZeroRequestedSize :: MonadIO m => m RequestedSize
newZeroRequestedSize = liftIO $ wrappedPtrCalloc >>= wrapPtr RequestedSize

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


-- | A convenience alias for `Nothing` :: `Maybe` `RequestedSize`.
noRequestedSize :: Maybe RequestedSize
noRequestedSize = Nothing

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

@
'Data.GI.Base.Attributes.get' requestedSize #data
@
-}
getRequestedSizeData :: MonadIO m => RequestedSize -> m (Ptr ())
getRequestedSizeData s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO (Ptr ())
    return val

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

@
'Data.GI.Base.Attributes.set' requestedSize [ #data 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRequestedSizeData :: MonadIO m => RequestedSize -> Ptr () -> m ()
setRequestedSizeData s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Ptr ())

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

@
'Data.GI.Base.Attributes.clear' #data
@
-}
clearRequestedSizeData :: MonadIO m => RequestedSize -> m ()
clearRequestedSizeData s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (FP.nullPtr :: Ptr ())

#if ENABLE_OVERLOADING
data RequestedSizeDataFieldInfo
instance AttrInfo RequestedSizeDataFieldInfo where
    type AttrAllowedOps RequestedSizeDataFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint RequestedSizeDataFieldInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint RequestedSizeDataFieldInfo = (~) RequestedSize
    type AttrGetType RequestedSizeDataFieldInfo = Ptr ()
    type AttrLabel RequestedSizeDataFieldInfo = "data"
    type AttrOrigin RequestedSizeDataFieldInfo = RequestedSize
    attrGet _ = getRequestedSizeData
    attrSet _ = setRequestedSizeData
    attrConstruct = undefined
    attrClear _ = clearRequestedSizeData

requestedSize_data :: AttrLabelProxy "data"
requestedSize_data = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' requestedSize #minimumSize
@
-}
getRequestedSizeMinimumSize :: MonadIO m => RequestedSize -> m Int32
getRequestedSizeMinimumSize s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' requestedSize [ #minimumSize 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRequestedSizeMinimumSize :: MonadIO m => RequestedSize -> Int32 -> m ()
setRequestedSizeMinimumSize s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Int32)

#if ENABLE_OVERLOADING
data RequestedSizeMinimumSizeFieldInfo
instance AttrInfo RequestedSizeMinimumSizeFieldInfo where
    type AttrAllowedOps RequestedSizeMinimumSizeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RequestedSizeMinimumSizeFieldInfo = (~) Int32
    type AttrBaseTypeConstraint RequestedSizeMinimumSizeFieldInfo = (~) RequestedSize
    type AttrGetType RequestedSizeMinimumSizeFieldInfo = Int32
    type AttrLabel RequestedSizeMinimumSizeFieldInfo = "minimum_size"
    type AttrOrigin RequestedSizeMinimumSizeFieldInfo = RequestedSize
    attrGet _ = getRequestedSizeMinimumSize
    attrSet _ = setRequestedSizeMinimumSize
    attrConstruct = undefined
    attrClear _ = undefined

requestedSize_minimumSize :: AttrLabelProxy "minimumSize"
requestedSize_minimumSize = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' requestedSize #naturalSize
@
-}
getRequestedSizeNaturalSize :: MonadIO m => RequestedSize -> m Int32
getRequestedSizeNaturalSize s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' requestedSize [ #naturalSize 'Data.GI.Base.Attributes.:=' value ]
@
-}
setRequestedSizeNaturalSize :: MonadIO m => RequestedSize -> Int32 -> m ()
setRequestedSizeNaturalSize s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Int32)

#if ENABLE_OVERLOADING
data RequestedSizeNaturalSizeFieldInfo
instance AttrInfo RequestedSizeNaturalSizeFieldInfo where
    type AttrAllowedOps RequestedSizeNaturalSizeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint RequestedSizeNaturalSizeFieldInfo = (~) Int32
    type AttrBaseTypeConstraint RequestedSizeNaturalSizeFieldInfo = (~) RequestedSize
    type AttrGetType RequestedSizeNaturalSizeFieldInfo = Int32
    type AttrLabel RequestedSizeNaturalSizeFieldInfo = "natural_size"
    type AttrOrigin RequestedSizeNaturalSizeFieldInfo = RequestedSize
    attrGet _ = getRequestedSizeNaturalSize
    attrSet _ = setRequestedSizeNaturalSize
    attrConstruct = undefined
    attrClear _ = undefined

requestedSize_naturalSize :: AttrLabelProxy "naturalSize"
requestedSize_naturalSize = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList RequestedSize
type instance O.AttributeList RequestedSize = RequestedSizeAttributeList
type RequestedSizeAttributeList = ('[ '("data", RequestedSizeDataFieldInfo), '("minimumSize", RequestedSizeMinimumSizeFieldInfo), '("naturalSize", RequestedSizeNaturalSizeFieldInfo)] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
type family ResolveRequestedSizeMethod (t :: Symbol) (o :: *) :: * where
    ResolveRequestedSizeMethod l o = O.MethodResolutionFailed l o

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

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