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

A GtkBindingSignal stores the necessary information to
activate a widget in response to a key press via a signal
emission.
-}

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

module GI.Gtk.Structs.BindingSignal
    (

-- * Exported types
    BindingSignal(..)                       ,
    newZeroBindingSignal                    ,
    noBindingSignal                         ,


 -- * Properties
-- ** nArgs #attr:nArgs#
{- | number of arguments specified for the signal
-}
#if ENABLE_OVERLOADING
    bindingSignal_nArgs                     ,
#endif
    getBindingSignalNArgs                   ,
    setBindingSignalNArgs                   ,


-- ** next #attr:next#
{- | implementation detail
-}
#if ENABLE_OVERLOADING
    bindingSignal_next                      ,
#endif
    clearBindingSignalNext                  ,
    getBindingSignalNext                    ,
    setBindingSignalNext                    ,


-- ** signalName #attr:signalName#
{- | the action signal to be emitted
-}
#if ENABLE_OVERLOADING
    bindingSignal_signalName                ,
#endif
    clearBindingSignalSignalName            ,
    getBindingSignalSignalName              ,
    setBindingSignalSignalName              ,




    ) 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


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

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

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


-- | A convenience alias for `Nothing` :: `Maybe` `BindingSignal`.
noBindingSignal :: Maybe BindingSignal
noBindingSignal = Nothing

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

@
'Data.GI.Base.Attributes.get' bindingSignal #next
@
-}
getBindingSignalNext :: MonadIO m => BindingSignal -> m (Maybe BindingSignal)
getBindingSignalNext s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO (Ptr BindingSignal)
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- (newPtr BindingSignal) val'
        return val''
    return result

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

@
'Data.GI.Base.Attributes.set' bindingSignal [ #next 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBindingSignalNext :: MonadIO m => BindingSignal -> Ptr BindingSignal -> m ()
setBindingSignalNext s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Ptr BindingSignal)

{- |
Set the value of the “@next@” 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' #next
@
-}
clearBindingSignalNext :: MonadIO m => BindingSignal -> m ()
clearBindingSignalNext s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (FP.nullPtr :: Ptr BindingSignal)

#if ENABLE_OVERLOADING
data BindingSignalNextFieldInfo
instance AttrInfo BindingSignalNextFieldInfo where
    type AttrAllowedOps BindingSignalNextFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint BindingSignalNextFieldInfo = (~) (Ptr BindingSignal)
    type AttrBaseTypeConstraint BindingSignalNextFieldInfo = (~) BindingSignal
    type AttrGetType BindingSignalNextFieldInfo = Maybe BindingSignal
    type AttrLabel BindingSignalNextFieldInfo = "next"
    type AttrOrigin BindingSignalNextFieldInfo = BindingSignal
    attrGet _ = getBindingSignalNext
    attrSet _ = setBindingSignalNext
    attrConstruct = undefined
    attrClear _ = clearBindingSignalNext

bindingSignal_next :: AttrLabelProxy "next"
bindingSignal_next = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' bindingSignal #signalName
@
-}
getBindingSignalSignalName :: MonadIO m => BindingSignal -> m (Maybe T.Text)
getBindingSignalSignalName 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 “@signal_name@” field.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

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

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

#if ENABLE_OVERLOADING
data BindingSignalSignalNameFieldInfo
instance AttrInfo BindingSignalSignalNameFieldInfo where
    type AttrAllowedOps BindingSignalSignalNameFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint BindingSignalSignalNameFieldInfo = (~) CString
    type AttrBaseTypeConstraint BindingSignalSignalNameFieldInfo = (~) BindingSignal
    type AttrGetType BindingSignalSignalNameFieldInfo = Maybe T.Text
    type AttrLabel BindingSignalSignalNameFieldInfo = "signal_name"
    type AttrOrigin BindingSignalSignalNameFieldInfo = BindingSignal
    attrGet _ = getBindingSignalSignalName
    attrSet _ = setBindingSignalSignalName
    attrConstruct = undefined
    attrClear _ = clearBindingSignalSignalName

bindingSignal_signalName :: AttrLabelProxy "signalName"
bindingSignal_signalName = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' bindingSignal #nArgs
@
-}
getBindingSignalNArgs :: MonadIO m => BindingSignal -> m Word32
getBindingSignalNArgs s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO Word32
    return val

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

@
'Data.GI.Base.Attributes.set' bindingSignal [ #nArgs 'Data.GI.Base.Attributes.:=' value ]
@
-}
setBindingSignalNArgs :: MonadIO m => BindingSignal -> Word32 -> m ()
setBindingSignalNArgs s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Word32)

#if ENABLE_OVERLOADING
data BindingSignalNArgsFieldInfo
instance AttrInfo BindingSignalNArgsFieldInfo where
    type AttrAllowedOps BindingSignalNArgsFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint BindingSignalNArgsFieldInfo = (~) Word32
    type AttrBaseTypeConstraint BindingSignalNArgsFieldInfo = (~) BindingSignal
    type AttrGetType BindingSignalNArgsFieldInfo = Word32
    type AttrLabel BindingSignalNArgsFieldInfo = "n_args"
    type AttrOrigin BindingSignalNArgsFieldInfo = BindingSignal
    attrGet _ = getBindingSignalNArgs
    attrSet _ = setBindingSignalNArgs
    attrConstruct = undefined
    attrClear _ = undefined

bindingSignal_nArgs :: AttrLabelProxy "nArgs"
bindingSignal_nArgs = AttrLabelProxy

#endif


-- XXX Skipped attribute for "BindingSignal:args" :: Not implemented: "Don't know how to unpack C array of type TCArray False (-1) 2 (TInterface (Name {namespace = \"Gtk\", name = \"BindingArg\"}))"

#if ENABLE_OVERLOADING
instance O.HasAttributeList BindingSignal
type instance O.AttributeList BindingSignal = BindingSignalAttributeList
type BindingSignalAttributeList = ('[ '("next", BindingSignalNextFieldInfo), '("signalName", BindingSignalSignalNameFieldInfo), '("nArgs", BindingSignalNArgsFieldInfo)] :: [(Symbol, *)])
#endif

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

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

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