    {- |
    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.AttrFontFeatures.AttrFontFeatures' structure is used to represent OpenType
    font features as an attribute.

    /Since: 1.38/
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Pango.Structs.AttrFontFeatures
        (

    -- * Exported types
        AttrFontFeatures(..)                    ,
        newZeroAttrFontFeatures                 ,
        noAttrFontFeatures                      ,

     -- * Methods
    -- ** new #method:new#

        attrFontFeaturesNew                     ,

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

    -- ** features #attr:features#
    {- | the featues, as a string in CSS syntax
    -}
    #if ENABLE_OVERLOADING
        attrFontFeatures_features               ,
    #endif
        clearAttrFontFeaturesFeatures           ,
        getAttrFontFeaturesFeatures             ,
        setAttrFontFeaturesFeatures             ,

        ) 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

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

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

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

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

    -- | A convenience alias for `Nothing` :: `Maybe` `AttrFontFeatures`.
    noAttrFontFeatures :: Maybe AttrFontFeatures
    noAttrFontFeatures = 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' attrFontFeatures #attr
    @
    -}
    getAttrFontFeaturesAttr :: MonadIO m => AttrFontFeatures -> m Pango.Attribute.Attribute
    getAttrFontFeaturesAttr 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 AttrFontFeaturesAttrFieldInfo
    instance AttrInfo AttrFontFeaturesAttrFieldInfo where
        type AttrAllowedOps AttrFontFeaturesAttrFieldInfo = '[ 'AttrGet]
        type AttrSetTypeConstraint AttrFontFeaturesAttrFieldInfo = (~) (Ptr Pango.Attribute.Attribute)
        type AttrBaseTypeConstraint AttrFontFeaturesAttrFieldInfo = (~) AttrFontFeatures
        type AttrGetType AttrFontFeaturesAttrFieldInfo = Pango.Attribute.Attribute
        type AttrLabel AttrFontFeaturesAttrFieldInfo = "attr"
        type AttrOrigin AttrFontFeaturesAttrFieldInfo = AttrFontFeatures
        attrGet _ = getAttrFontFeaturesAttr
        attrSet _ = undefined
        attrConstruct = undefined
        attrClear _ = undefined

    attrFontFeatures_attr :: AttrLabelProxy "attr"
    attrFontFeatures_attr = AttrLabelProxy

    #endif

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

    @
    'Data.GI.Base.Attributes.get' attrFontFeatures #features
    @
    -}
    getAttrFontFeaturesFeatures :: MonadIO m => AttrFontFeatures -> m (Maybe T.Text)
    getAttrFontFeaturesFeatures s = liftIO $ withManagedPtr s $ \ptr -> do
        val <- peek (ptr `plusPtr` 16) :: IO CString
        result <- SP.convertIfNonNull val $ \val' -> do
            val'' <- cstringToText val'
            return val''
        return result

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

    @
    'Data.GI.Base.Attributes.set' attrFontFeatures [ #features 'Data.GI.Base.Attributes.:=' value ]
    @
    -}
    setAttrFontFeaturesFeatures :: MonadIO m => AttrFontFeatures -> CString -> m ()
    setAttrFontFeaturesFeatures s val = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 16) (val :: CString)

    {- |
    Set the value of the “@features@” 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' #features
    @
    -}
    clearAttrFontFeaturesFeatures :: MonadIO m => AttrFontFeatures -> m ()
    clearAttrFontFeaturesFeatures s = liftIO $ withManagedPtr s $ \ptr -> do
        poke (ptr `plusPtr` 16) (FP.nullPtr :: CString)

    #if ENABLE_OVERLOADING
    data AttrFontFeaturesFeaturesFieldInfo
    instance AttrInfo AttrFontFeaturesFeaturesFieldInfo where
        type AttrAllowedOps AttrFontFeaturesFeaturesFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint AttrFontFeaturesFeaturesFieldInfo = (~) CString
        type AttrBaseTypeConstraint AttrFontFeaturesFeaturesFieldInfo = (~) AttrFontFeatures
        type AttrGetType AttrFontFeaturesFeaturesFieldInfo = Maybe T.Text
        type AttrLabel AttrFontFeaturesFeaturesFieldInfo = "features"
        type AttrOrigin AttrFontFeaturesFeaturesFieldInfo = AttrFontFeatures
        attrGet _ = getAttrFontFeaturesFeatures
        attrSet _ = setAttrFontFeaturesFeatures
        attrConstruct = undefined
        attrClear _ = clearAttrFontFeaturesFeatures

    attrFontFeatures_features :: AttrLabelProxy "features"
    attrFontFeatures_features = AttrLabelProxy

    #endif

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList AttrFontFeatures
    type instance O.AttributeList AttrFontFeatures = AttrFontFeaturesAttributeList
    type AttrFontFeaturesAttributeList = ('[ '("attr", AttrFontFeaturesAttrFieldInfo), '("features", AttrFontFeaturesFeaturesFieldInfo)] :: [(Symbol, *)])
    #endif

    -- method AttrFontFeatures::new
    -- method type : MemberFunction
    -- Args : [Arg {argCName = "features", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a string with OpenType font features, in CSS syntax", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "Pango", name = "Attribute"}))
    -- throws : False
    -- Skip return : False

    foreign import ccall "pango_attr_font_features_new" pango_attr_font_features_new ::
        CString ->                              -- features : TBasicType TUTF8
        IO (Ptr Pango.Attribute.Attribute)

    {- |
    Create a new font features tag attribute.

    /Since: 1.38/
    -}
    attrFontFeaturesNew ::
        (B.CallStack.HasCallStack, MonadIO m) =>
        T.Text
        {- ^ /@features@/: a string with OpenType font features, in CSS syntax -}
        -> m Pango.Attribute.Attribute
        {- ^ __Returns:__ the newly allocated 'GI.Pango.Structs.Attribute.Attribute',
                  which should be freed with 'GI.Pango.Structs.Attribute.attributeDestroy'. -}
    attrFontFeaturesNew features = liftIO $ do
        features' <- textToCString features
        result <- pango_attr_font_features_new features'
        checkUnexpectedReturnNULL "attrFontFeaturesNew" result
        result' <- (wrapPtr Pango.Attribute.Attribute) result
        freeMem features'
        return result'

    #if ENABLE_OVERLOADING
    #endif

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

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

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