{- |
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.EngineScriptInfo.EngineScriptInfo' structure contains
information about how the shaper covers a particular script.
-}

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

module GI.Pango.Structs.EngineScriptInfo
    (

-- * Exported types
    EngineScriptInfo(..)                    ,
    newZeroEngineScriptInfo                 ,
    noEngineScriptInfo                      ,


 -- * Properties
-- ** langs #attr:langs#
{- | a semicolon separated list of languages that this
engine handles for this script. This may be empty,
in which case the engine is saying that it is a
fallback choice for all languages for this range,
but should not be used if another engine
indicates that it is specific for the language for
a given code point. An entry in this list of \"*\"
indicates that this engine is specific to all
languages for this range.
-}
    clearEngineScriptInfoLangs              ,
#if ENABLE_OVERLOADING
    engineScriptInfo_langs                  ,
#endif
    getEngineScriptInfoLangs                ,
    setEngineScriptInfoLangs                ,


-- ** script #attr:script#
{- | a 'GI.Pango.Enums.Script'. The value 'GI.Pango.Enums.ScriptCommon' has
the special meaning here of \"all scripts\"
-}
#if ENABLE_OVERLOADING
    engineScriptInfo_script                 ,
#endif
    getEngineScriptInfoScript               ,
    setEngineScriptInfoScript               ,




    ) 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.Enums as Pango.Enums

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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `EngineScriptInfo`.
noEngineScriptInfo :: Maybe EngineScriptInfo
noEngineScriptInfo = Nothing

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

@
'Data.GI.Base.Attributes.get' engineScriptInfo #script
@
-}
getEngineScriptInfoScript :: MonadIO m => EngineScriptInfo -> m Pango.Enums.Script
getEngineScriptInfoScript s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CInt
    let val' = (toEnum . fromIntegral) val
    return val'

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

@
'Data.GI.Base.Attributes.set' engineScriptInfo [ #script 'Data.GI.Base.Attributes.:=' value ]
@
-}
setEngineScriptInfoScript :: MonadIO m => EngineScriptInfo -> Pango.Enums.Script -> m ()
setEngineScriptInfoScript s val = liftIO $ withManagedPtr s $ \ptr -> do
    let val' = (fromIntegral . fromEnum) val
    poke (ptr `plusPtr` 0) (val' :: CInt)

#if ENABLE_OVERLOADING
data EngineScriptInfoScriptFieldInfo
instance AttrInfo EngineScriptInfoScriptFieldInfo where
    type AttrAllowedOps EngineScriptInfoScriptFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint EngineScriptInfoScriptFieldInfo = (~) Pango.Enums.Script
    type AttrBaseTypeConstraint EngineScriptInfoScriptFieldInfo = (~) EngineScriptInfo
    type AttrGetType EngineScriptInfoScriptFieldInfo = Pango.Enums.Script
    type AttrLabel EngineScriptInfoScriptFieldInfo = "script"
    type AttrOrigin EngineScriptInfoScriptFieldInfo = EngineScriptInfo
    attrGet _ = getEngineScriptInfoScript
    attrSet _ = setEngineScriptInfoScript
    attrConstruct = undefined
    attrClear _ = undefined

engineScriptInfo_script :: AttrLabelProxy "script"
engineScriptInfo_script = AttrLabelProxy

#endif


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

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

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

@
'Data.GI.Base.Attributes.set' engineScriptInfo [ #langs 'Data.GI.Base.Attributes.:=' value ]
@
-}
setEngineScriptInfoLangs :: MonadIO m => EngineScriptInfo -> CString -> m ()
setEngineScriptInfoLangs s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: CString)

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

#if ENABLE_OVERLOADING
data EngineScriptInfoLangsFieldInfo
instance AttrInfo EngineScriptInfoLangsFieldInfo where
    type AttrAllowedOps EngineScriptInfoLangsFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint EngineScriptInfoLangsFieldInfo = (~) CString
    type AttrBaseTypeConstraint EngineScriptInfoLangsFieldInfo = (~) EngineScriptInfo
    type AttrGetType EngineScriptInfoLangsFieldInfo = Maybe T.Text
    type AttrLabel EngineScriptInfoLangsFieldInfo = "langs"
    type AttrOrigin EngineScriptInfoLangsFieldInfo = EngineScriptInfo
    attrGet _ = getEngineScriptInfoLangs
    attrSet _ = setEngineScriptInfoLangs
    attrConstruct = undefined
    attrClear _ = clearEngineScriptInfoLangs

engineScriptInfo_langs :: AttrLabelProxy "langs"
engineScriptInfo_langs = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList EngineScriptInfo
type instance O.AttributeList EngineScriptInfo = EngineScriptInfoAttributeList
type EngineScriptInfoAttributeList = ('[ '("script", EngineScriptInfoScriptFieldInfo), '("langs", EngineScriptInfoLangsFieldInfo)] :: [(Symbol, *)])
#endif

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

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