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

The 'GI.Pango.Structs.AttrColor.AttrColor' structure is used to represent attributes that
are colors.
-}

module GI.Pango.Structs.AttrColor
    ( 

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


 -- * Properties
-- ** attr #attr:attr#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    attrColor_attr                          ,
#endif
    getAttrColorAttr                        ,


-- ** color #attr:color#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    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.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

import {-# SOURCE #-} qualified GI.Pango.Structs.Attribute as Pango.Attribute
import {-# SOURCE #-} qualified GI.Pango.Structs.Color as Pango.Color

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


noAttrColor :: Maybe AttrColor
noAttrColor = Nothing

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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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


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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
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 defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList AttrColor
type instance O.AttributeList AttrColor = AttrColorAttributeList
type AttrColorAttributeList = ('[ '("attr", AttrColorAttrFieldInfo), '("color", AttrColorColorFieldInfo)] :: [(Symbol, *)])
#endif

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

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

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

#endif