#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
&& !defined(__HADDOCK_VERSION__))
module GI.Atk.Structs.Attribute
(
Attribute(..) ,
newZeroAttribute ,
noAttribute ,
attributeSetFree ,
#if ENABLE_OVERLOADING
attribute_name ,
#endif
clearAttributeName ,
getAttributeName ,
setAttributeName ,
#if ENABLE_OVERLOADING
attribute_value ,
#endif
clearAttributeValue ,
getAttributeValue ,
setAttributeValue ,
) 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
newtype Attribute = Attribute (ManagedPtr Attribute)
instance WrappedPtr Attribute where
wrappedPtrCalloc = callocBytes 16
wrappedPtrCopy = \p -> withManagedPtr p (copyBytes 16 >=> wrapPtr Attribute)
wrappedPtrFree = Just ptr_to_g_free
newZeroAttribute :: MonadIO m => m Attribute
newZeroAttribute = liftIO $ wrappedPtrCalloc >>= wrapPtr Attribute
instance tag ~ 'AttrSet => Constructible Attribute tag where
new _ attrs = do
o <- newZeroAttribute
GI.Attributes.set o attrs
return o
noAttribute :: Maybe Attribute
noAttribute = Nothing
getAttributeName :: MonadIO m => Attribute -> m (Maybe T.Text)
getAttributeName s = liftIO $ withManagedPtr s $ \ptr -> do
val <- peek (ptr `plusPtr` 0) :: IO CString
result <- SP.convertIfNonNull val $ \val' -> do
val'' <- cstringToText val'
return val''
return result
setAttributeName :: MonadIO m => Attribute -> CString -> m ()
setAttributeName s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (val :: CString)
clearAttributeName :: MonadIO m => Attribute -> m ()
clearAttributeName s = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 0) (FP.nullPtr :: CString)
#if ENABLE_OVERLOADING
data AttributeNameFieldInfo
instance AttrInfo AttributeNameFieldInfo where
type AttrAllowedOps AttributeNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint AttributeNameFieldInfo = (~) CString
type AttrBaseTypeConstraint AttributeNameFieldInfo = (~) Attribute
type AttrGetType AttributeNameFieldInfo = Maybe T.Text
type AttrLabel AttributeNameFieldInfo = "name"
type AttrOrigin AttributeNameFieldInfo = Attribute
attrGet _ = getAttributeName
attrSet _ = setAttributeName
attrConstruct = undefined
attrClear _ = clearAttributeName
attribute_name :: AttrLabelProxy "name"
attribute_name = AttrLabelProxy
#endif
getAttributeValue :: MonadIO m => Attribute -> m (Maybe T.Text)
getAttributeValue 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
setAttributeValue :: MonadIO m => Attribute -> CString -> m ()
setAttributeValue s val = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 8) (val :: CString)
clearAttributeValue :: MonadIO m => Attribute -> m ()
clearAttributeValue s = liftIO $ withManagedPtr s $ \ptr -> do
poke (ptr `plusPtr` 8) (FP.nullPtr :: CString)
#if ENABLE_OVERLOADING
data AttributeValueFieldInfo
instance AttrInfo AttributeValueFieldInfo where
type AttrAllowedOps AttributeValueFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint AttributeValueFieldInfo = (~) CString
type AttrBaseTypeConstraint AttributeValueFieldInfo = (~) Attribute
type AttrGetType AttributeValueFieldInfo = Maybe T.Text
type AttrLabel AttributeValueFieldInfo = "value"
type AttrOrigin AttributeValueFieldInfo = Attribute
attrGet _ = getAttributeValue
attrSet _ = setAttributeValue
attrConstruct = undefined
attrClear _ = clearAttributeValue
attribute_value :: AttrLabelProxy "value"
attribute_value = AttrLabelProxy
#endif
#if ENABLE_OVERLOADING
instance O.HasAttributeList Attribute
type instance O.AttributeList Attribute = AttributeAttributeList
type AttributeAttributeList = ('[ '("name", AttributeNameFieldInfo), '("value", AttributeValueFieldInfo)] :: [(Symbol, *)])
#endif
foreign import ccall "atk_attribute_set_free" atk_attribute_set_free ::
Ptr (GSList (Ptr ())) ->
IO ()
attributeSetFree ::
(B.CallStack.HasCallStack, MonadIO m) =>
[Ptr ()]
-> m ()
attributeSetFree attribSet = liftIO $ do
attribSet' <- packGSList attribSet
atk_attribute_set_free attribSet'
g_slist_free attribSet'
return ()
#if ENABLE_OVERLOADING
#endif
#if ENABLE_OVERLOADING
type family ResolveAttributeMethod (t :: Symbol) (o :: *) :: * where
ResolveAttributeMethod l o = O.MethodResolutionFailed l o
instance (info ~ ResolveAttributeMethod t Attribute, O.MethodInfo info Attribute p) => OL.IsLabel t (Attribute -> 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