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

The 'GI.Pango.Structs.AttrClass.AttrClass' structure stores the type and operations for
a particular type of attribute. The functions in this structure should
not be called directly. Instead, one should use the wrapper functions
provided for 'GI.Pango.Structs.Attribute.Attribute'.
-}

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

module GI.Pango.Structs.AttrClass
    (

-- * Exported types
    AttrClass(..)                           ,
    newZeroAttrClass                        ,
    noAttrClass                             ,


 -- * Properties
-- ** destroy #attr:destroy#
{- | /No description available in the introspection data./
-}
#if ENABLE_OVERLOADING
    attrClass_destroy                       ,
#endif
    clearAttrClassDestroy                   ,
    getAttrClassDestroy                     ,
    setAttrClassDestroy                     ,


-- ** equal #attr:equal#
{- | /No description available in the introspection data./
-}
#if ENABLE_OVERLOADING
    attrClass_equal                         ,
#endif
    clearAttrClassEqual                     ,
    getAttrClassEqual                       ,
    setAttrClassEqual                       ,


-- ** type #attr:type#
{- | the type ID for this attribute
-}
#if ENABLE_OVERLOADING
    attrClass_type                          ,
#endif
    getAttrClassType                        ,
    setAttrClassType                        ,




    ) 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

import qualified GI.Pango.Callbacks as Pango.Callbacks
import {-# SOURCE #-} qualified GI.Pango.Enums as Pango.Enums

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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `AttrClass`.
noAttrClass :: Maybe AttrClass
noAttrClass = Nothing

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

@
'Data.GI.Base.Attributes.get' attrClass #type
@
-}
getAttrClassType :: MonadIO m => AttrClass -> m Pango.Enums.AttrType
getAttrClassType s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CUInt
    let val' = (toEnum . fromIntegral) val
    return val'

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

@
'Data.GI.Base.Attributes.set' attrClass [ #type 'Data.GI.Base.Attributes.:=' value ]
@
-}
setAttrClassType :: MonadIO m => AttrClass -> Pango.Enums.AttrType -> m ()
setAttrClassType s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = (fromIntegral . fromEnum) val
    poke (ptr `plusPtr` 0) (val' :: CUInt)

#if ENABLE_OVERLOADING
data AttrClassTypeFieldInfo
instance AttrInfo AttrClassTypeFieldInfo where
    type AttrAllowedOps AttrClassTypeFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint AttrClassTypeFieldInfo = (~) Pango.Enums.AttrType
    type AttrBaseTypeConstraint AttrClassTypeFieldInfo = (~) AttrClass
    type AttrGetType AttrClassTypeFieldInfo = Pango.Enums.AttrType
    type AttrLabel AttrClassTypeFieldInfo = "type"
    type AttrOrigin AttrClassTypeFieldInfo = AttrClass
    attrGet _ = getAttrClassType
    attrSet _ = setAttrClassType
    attrConstruct = undefined
    attrClear _ = undefined

attrClass_type :: AttrLabelProxy "type"
attrClass_type = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' attrClass #destroy
@
-}
getAttrClassDestroy :: MonadIO m => AttrClass -> m (Maybe Pango.Callbacks.AttrClassDestroyFieldCallback)
getAttrClassDestroy s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO (FunPtr Pango.Callbacks.C_AttrClassDestroyFieldCallback)
    result <- SP.convertFunPtrIfNonNull val $ \val' -> do
        let val'' = Pango.Callbacks.dynamic_AttrClassDestroyFieldCallback val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' attrClass [ #destroy 'Data.GI.Base.Attributes.:=' value ]
@
-}
setAttrClassDestroy :: MonadIO m => AttrClass -> FunPtr Pango.Callbacks.C_AttrClassDestroyFieldCallback -> m ()
setAttrClassDestroy s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: FunPtr Pango.Callbacks.C_AttrClassDestroyFieldCallback)

{- |
Set the value of the “@destroy@” 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' #destroy
@
-}
clearAttrClassDestroy :: MonadIO m => AttrClass -> m ()
clearAttrClassDestroy s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullFunPtr :: FunPtr Pango.Callbacks.C_AttrClassDestroyFieldCallback)

#if ENABLE_OVERLOADING
data AttrClassDestroyFieldInfo
instance AttrInfo AttrClassDestroyFieldInfo where
    type AttrAllowedOps AttrClassDestroyFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint AttrClassDestroyFieldInfo = (~) (FunPtr Pango.Callbacks.C_AttrClassDestroyFieldCallback)
    type AttrBaseTypeConstraint AttrClassDestroyFieldInfo = (~) AttrClass
    type AttrGetType AttrClassDestroyFieldInfo = Maybe Pango.Callbacks.AttrClassDestroyFieldCallback
    type AttrLabel AttrClassDestroyFieldInfo = "destroy"
    type AttrOrigin AttrClassDestroyFieldInfo = AttrClass
    attrGet _ = getAttrClassDestroy
    attrSet _ = setAttrClassDestroy
    attrConstruct = undefined
    attrClear _ = clearAttrClassDestroy

attrClass_destroy :: AttrLabelProxy "destroy"
attrClass_destroy = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' attrClass #equal
@
-}
getAttrClassEqual :: MonadIO m => AttrClass -> m (Maybe Pango.Callbacks.AttrClassEqualFieldCallback)
getAttrClassEqual s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO (FunPtr Pango.Callbacks.C_AttrClassEqualFieldCallback)
    result <- SP.convertFunPtrIfNonNull val $ \val' -> do
        let val'' = Pango.Callbacks.dynamic_AttrClassEqualFieldCallback val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' attrClass [ #equal 'Data.GI.Base.Attributes.:=' value ]
@
-}
setAttrClassEqual :: MonadIO m => AttrClass -> FunPtr Pango.Callbacks.C_AttrClassEqualFieldCallback -> m ()
setAttrClassEqual s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (val :: FunPtr Pango.Callbacks.C_AttrClassEqualFieldCallback)

{- |
Set the value of the “@equal@” 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' #equal
@
-}
clearAttrClassEqual :: MonadIO m => AttrClass -> m ()
clearAttrClassEqual s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (FP.nullFunPtr :: FunPtr Pango.Callbacks.C_AttrClassEqualFieldCallback)

#if ENABLE_OVERLOADING
data AttrClassEqualFieldInfo
instance AttrInfo AttrClassEqualFieldInfo where
    type AttrAllowedOps AttrClassEqualFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint AttrClassEqualFieldInfo = (~) (FunPtr Pango.Callbacks.C_AttrClassEqualFieldCallback)
    type AttrBaseTypeConstraint AttrClassEqualFieldInfo = (~) AttrClass
    type AttrGetType AttrClassEqualFieldInfo = Maybe Pango.Callbacks.AttrClassEqualFieldCallback
    type AttrLabel AttrClassEqualFieldInfo = "equal"
    type AttrOrigin AttrClassEqualFieldInfo = AttrClass
    attrGet _ = getAttrClassEqual
    attrSet _ = setAttrClassEqual
    attrConstruct = undefined
    attrClear _ = clearAttrClassEqual

attrClass_equal :: AttrLabelProxy "equal"
attrClass_equal = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList AttrClass
type instance O.AttributeList AttrClass = AttrClassAttributeList
type AttrClassAttributeList = ('[ '("type", AttrClassTypeFieldInfo), '("destroy", AttrClassDestroyFieldInfo), '("equal", AttrClassEqualFieldInfo)] :: [(Symbol, *)])
#endif

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

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