{-# LANGUAGE TypeApplications #-}
#if (MIN_VERSION_haskell_gi_overloading(1,0,0) && !defined(__HADDOCK_VERSION__))
#define ENABLE_OVERLOADING
#endif
module GI.Atk.Structs.Attribute
(
Attribute(..) ,
newZeroAttribute ,
#if defined(ENABLE_OVERLOADING)
ResolveAttributeMethod ,
#endif
attributeSetFree ,
#if defined(ENABLE_OVERLOADING)
attribute_name ,
#endif
clearAttributeName ,
getAttributeName ,
setAttributeName ,
#if defined(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.BasicTypes as B.Types
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.GI.Base.Signals as B.Signals
import qualified Control.Monad.IO.Class as MIO
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 (SP.ManagedPtr Attribute)
deriving (Attribute -> Attribute -> Bool
(Attribute -> Attribute -> Bool)
-> (Attribute -> Attribute -> Bool) -> Eq Attribute
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Attribute -> Attribute -> Bool
$c/= :: Attribute -> Attribute -> Bool
== :: Attribute -> Attribute -> Bool
$c== :: Attribute -> Attribute -> Bool
Eq)
instance SP.ManagedPtrNewtype Attribute where
toManagedPtr :: Attribute -> ManagedPtr Attribute
toManagedPtr (Attribute ManagedPtr Attribute
p) = ManagedPtr Attribute
p
instance BoxedPtr Attribute where
boxedPtrCopy :: Attribute -> IO Attribute
boxedPtrCopy = \Attribute
p -> Attribute -> (Ptr Attribute -> IO Attribute) -> IO Attribute
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr Attribute
p (Int -> Ptr Attribute -> IO (Ptr Attribute)
forall a. (HasCallStack, CallocPtr a) => Int -> Ptr a -> IO (Ptr a)
copyBytes Int
16 (Ptr Attribute -> IO (Ptr Attribute))
-> (Ptr Attribute -> IO Attribute) -> Ptr Attribute -> IO Attribute
forall (m :: * -> *) a b c.
Monad m =>
(a -> m b) -> (b -> m c) -> a -> m c
>=> (ManagedPtr Attribute -> Attribute)
-> Ptr Attribute -> IO Attribute
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
B.ManagedPtr.wrapPtr ManagedPtr Attribute -> Attribute
Attribute)
boxedPtrFree :: Attribute -> IO ()
boxedPtrFree = \Attribute
x -> Attribute -> (Ptr Attribute -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
SP.withManagedPtr Attribute
x Ptr Attribute -> IO ()
forall a. Ptr a -> IO ()
SP.freeMem
instance CallocPtr Attribute where
boxedPtrCalloc :: IO (Ptr Attribute)
boxedPtrCalloc = Int -> IO (Ptr Attribute)
forall a. Int -> IO (Ptr a)
callocBytes Int
16
newZeroAttribute :: MonadIO m => m Attribute
newZeroAttribute :: m Attribute
newZeroAttribute = IO Attribute -> m Attribute
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Attribute -> m Attribute) -> IO Attribute -> m Attribute
forall a b. (a -> b) -> a -> b
$ IO (Ptr Attribute)
forall a. CallocPtr a => IO (Ptr a)
boxedPtrCalloc IO (Ptr Attribute)
-> (Ptr Attribute -> IO Attribute) -> IO Attribute
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (ManagedPtr Attribute -> Attribute)
-> Ptr Attribute -> IO Attribute
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr Attribute -> Attribute
Attribute
instance tag ~ 'AttrSet => Constructible Attribute tag where
new :: (ManagedPtr Attribute -> Attribute)
-> [AttrOp Attribute tag] -> m Attribute
new ManagedPtr Attribute -> Attribute
_ [AttrOp Attribute tag]
attrs = do
Attribute
o <- m Attribute
forall (m :: * -> *). MonadIO m => m Attribute
newZeroAttribute
Attribute -> [AttrOp Attribute 'AttrSet] -> m ()
forall o (m :: * -> *).
MonadIO m =>
o -> [AttrOp o 'AttrSet] -> m ()
GI.Attributes.set Attribute
o [AttrOp Attribute tag]
[AttrOp Attribute 'AttrSet]
attrs
Attribute -> m Attribute
forall (m :: * -> *) a. Monad m => a -> m a
return Attribute
o
getAttributeName :: MonadIO m => Attribute -> m (Maybe T.Text)
getAttributeName :: Attribute -> m (Maybe Text)
getAttributeName Attribute
s = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Attribute -> (Ptr Attribute -> IO (Maybe Text)) -> IO (Maybe Text)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Attribute
s ((Ptr Attribute -> IO (Maybe Text)) -> IO (Maybe Text))
-> (Ptr Attribute -> IO (Maybe Text)) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \Ptr Attribute
ptr -> do
CString
val <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek (Ptr Attribute
ptr Ptr Attribute -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) :: IO CString
Maybe Text
result <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
SP.convertIfNonNull CString
val ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
val' -> do
Text
val'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
val'
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val''
Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
result
setAttributeName :: MonadIO m => Attribute -> CString -> m ()
setAttributeName :: Attribute -> CString -> m ()
setAttributeName Attribute
s CString
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Attribute -> (Ptr Attribute -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Attribute
s ((Ptr Attribute -> IO ()) -> IO ())
-> (Ptr Attribute -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Attribute
ptr -> do
Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Attribute
ptr Ptr Attribute -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (CString
val :: CString)
clearAttributeName :: MonadIO m => Attribute -> m ()
clearAttributeName :: Attribute -> m ()
clearAttributeName Attribute
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Attribute -> (Ptr Attribute -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Attribute
s ((Ptr Attribute -> IO ()) -> IO ())
-> (Ptr Attribute -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Attribute
ptr -> do
Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Attribute
ptr Ptr Attribute -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
0) (CString
forall a. Ptr a
FP.nullPtr :: CString)
#if defined(ENABLE_OVERLOADING)
data AttributeNameFieldInfo
instance AttrInfo AttributeNameFieldInfo where
type AttrBaseTypeConstraint AttributeNameFieldInfo = (~) Attribute
type AttrAllowedOps AttributeNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint AttributeNameFieldInfo = (~) CString
type AttrTransferTypeConstraint AttributeNameFieldInfo = (~)CString
type AttrTransferType AttributeNameFieldInfo = CString
type AttrGetType AttributeNameFieldInfo = Maybe T.Text
type AttrLabel AttributeNameFieldInfo = "name"
type AttrOrigin AttributeNameFieldInfo = Attribute
attrGet = getAttributeName
attrSet = setAttributeName
attrConstruct = undefined
attrClear = clearAttributeName
attrTransfer _ v = do
return v
attribute_name :: AttrLabelProxy "name"
attribute_name = AttrLabelProxy
#endif
getAttributeValue :: MonadIO m => Attribute -> m (Maybe T.Text)
getAttributeValue :: Attribute -> m (Maybe Text)
getAttributeValue Attribute
s = IO (Maybe Text) -> m (Maybe Text)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Text) -> m (Maybe Text))
-> IO (Maybe Text) -> m (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Attribute -> (Ptr Attribute -> IO (Maybe Text)) -> IO (Maybe Text)
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Attribute
s ((Ptr Attribute -> IO (Maybe Text)) -> IO (Maybe Text))
-> (Ptr Attribute -> IO (Maybe Text)) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \Ptr Attribute
ptr -> do
CString
val <- Ptr CString -> IO CString
forall a. Storable a => Ptr a -> IO a
peek (Ptr Attribute
ptr Ptr Attribute -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) :: IO CString
Maybe Text
result <- CString -> (CString -> IO Text) -> IO (Maybe Text)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
SP.convertIfNonNull CString
val ((CString -> IO Text) -> IO (Maybe Text))
-> (CString -> IO Text) -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ \CString
val' -> do
Text
val'' <- HasCallStack => CString -> IO Text
CString -> IO Text
cstringToText CString
val'
Text -> IO Text
forall (m :: * -> *) a. Monad m => a -> m a
return Text
val''
Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
result
setAttributeValue :: MonadIO m => Attribute -> CString -> m ()
setAttributeValue :: Attribute -> CString -> m ()
setAttributeValue Attribute
s CString
val = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Attribute -> (Ptr Attribute -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Attribute
s ((Ptr Attribute -> IO ()) -> IO ())
-> (Ptr Attribute -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Attribute
ptr -> do
Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Attribute
ptr Ptr Attribute -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) (CString
val :: CString)
clearAttributeValue :: MonadIO m => Attribute -> m ()
clearAttributeValue :: Attribute -> m ()
clearAttributeValue Attribute
s = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Attribute -> (Ptr Attribute -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
withManagedPtr Attribute
s ((Ptr Attribute -> IO ()) -> IO ())
-> (Ptr Attribute -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Ptr Attribute
ptr -> do
Ptr CString -> CString -> IO ()
forall a. Storable a => Ptr a -> a -> IO ()
poke (Ptr Attribute
ptr Ptr Attribute -> Int -> Ptr CString
forall a b. Ptr a -> Int -> Ptr b
`plusPtr` Int
8) (CString
forall a. Ptr a
FP.nullPtr :: CString)
#if defined(ENABLE_OVERLOADING)
data AttributeValueFieldInfo
instance AttrInfo AttributeValueFieldInfo where
type AttrBaseTypeConstraint AttributeValueFieldInfo = (~) Attribute
type AttrAllowedOps AttributeValueFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
type AttrSetTypeConstraint AttributeValueFieldInfo = (~) CString
type AttrTransferTypeConstraint AttributeValueFieldInfo = (~)CString
type AttrTransferType AttributeValueFieldInfo = CString
type AttrGetType AttributeValueFieldInfo = Maybe T.Text
type AttrLabel AttributeValueFieldInfo = "value"
type AttrOrigin AttributeValueFieldInfo = Attribute
attrGet = getAttributeValue
attrSet = setAttributeValue
attrConstruct = undefined
attrClear = clearAttributeValue
attrTransfer _ v = do
return v
attribute_value :: AttrLabelProxy "value"
attribute_value = AttrLabelProxy
#endif
#if defined(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 :: [Ptr ()] -> m ()
attributeSetFree [Ptr ()]
attribSet = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
Ptr (GSList (Ptr ()))
attribSet' <- [Ptr ()] -> IO (Ptr (GSList (Ptr ())))
forall a. [Ptr a] -> IO (Ptr (GSList (Ptr a)))
packGSList [Ptr ()]
attribSet
Ptr (GSList (Ptr ())) -> IO ()
atk_attribute_set_free Ptr (GSList (Ptr ()))
attribSet'
Ptr (GSList (Ptr ())) -> IO ()
forall a. Ptr (GSList a) -> IO ()
g_slist_free Ptr (GSList (Ptr ()))
attribSet'
() -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
#if defined(ENABLE_OVERLOADING)
#endif
#if defined(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 @info
#else
fromLabel _ = O.overloadedMethod @info
#endif
#endif