{- |
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.AttrColor.AttrColor' structure is used to represent attributes that
are colors.
-}

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

module GI.Pango.Structs.AttrColor
    (

-- * Exported types
    AttrColor(..)                           ,
    newZeroAttrColor                        ,
    noAttrColor                             ,


 -- * Properties
-- ** attr #attr:attr#
{- | the common portion of the attribute
-}
#if ENABLE_OVERLOADING
    attrColor_attr                          ,
#endif
    getAttrColorAttr                        ,


-- ** color #attr:color#
{- | the 'GI.Pango.Structs.Color.Color' which is the value of the attribute
-}
#if ENABLE_OVERLOADING
    attrColor_color                         ,
#endif
    getAttrColorColor                       ,




    ) 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 {-# SOURCE #-} qualified GI.Pango.Structs.Attribute as Pango.Attribute
import {-# SOURCE #-} qualified GI.Pango.Structs.Color as Pango.Color

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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `AttrColor`.
noAttrColor :: Maybe AttrColor
noAttrColor = Nothing

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

@
'Data.GI.Base.Attributes.get' attrColor #attr
@
-}
getAttrColorAttr :: MonadIO m => AttrColor -> m Pango.Attribute.Attribute
getAttrColorAttr s = liftIO $ withManagedPtr s $ \ptr -> do
    let val = ptr `plusPtr` 0 :: (Ptr Pango.Attribute.Attribute)
    val' <- (newPtr Pango.Attribute.Attribute) val
    return val'

#if ENABLE_OVERLOADING
data AttrColorAttrFieldInfo
instance AttrInfo AttrColorAttrFieldInfo where
    type AttrAllowedOps AttrColorAttrFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint AttrColorAttrFieldInfo = (~) (Ptr Pango.Attribute.Attribute)
    type AttrBaseTypeConstraint AttrColorAttrFieldInfo = (~) AttrColor
    type AttrGetType AttrColorAttrFieldInfo = Pango.Attribute.Attribute
    type AttrLabel AttrColorAttrFieldInfo = "attr"
    type AttrOrigin AttrColorAttrFieldInfo = AttrColor
    attrGet _ = getAttrColorAttr
    attrSet _ = undefined
    attrConstruct = undefined
    attrClear _ = undefined

attrColor_attr :: AttrLabelProxy "attr"
attrColor_attr = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' attrColor #color
@
-}
getAttrColorColor :: MonadIO m => AttrColor -> m Pango.Color.Color
getAttrColorColor s = liftIO $ withManagedPtr s $ \ptr -> do
    let val = ptr `plusPtr` 16 :: (Ptr Pango.Color.Color)
    val' <- (newBoxed Pango.Color.Color) val
    return val'

#if ENABLE_OVERLOADING
data AttrColorColorFieldInfo
instance AttrInfo AttrColorColorFieldInfo where
    type AttrAllowedOps AttrColorColorFieldInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint AttrColorColorFieldInfo = (~) (Ptr Pango.Color.Color)
    type AttrBaseTypeConstraint AttrColorColorFieldInfo = (~) AttrColor
    type AttrGetType AttrColorColorFieldInfo = Pango.Color.Color
    type AttrLabel AttrColorColorFieldInfo = "color"
    type AttrOrigin AttrColorColorFieldInfo = AttrColor
    attrGet _ = getAttrColorColor
    attrSet _ = undefined
    attrConstruct = undefined
    attrClear _ = undefined

attrColor_color :: AttrLabelProxy "color"
attrColor_color = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList AttrColor
type instance O.AttributeList AttrColor = AttrColorAttributeList
type AttrColorAttributeList = ('[ '("attr", AttrColorAttrFieldInfo), '("color", AttrColorColorFieldInfo)] :: [(Symbol, *)])
#endif

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

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