-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria

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

module GI.Adw.Callbacks
    ( 

 -- * Signals


-- ** AnimationTargetFunc #signal:AnimationTargetFunc#

    AnimationTargetFunc                     ,
    AnimationTargetFunc_WithClosures        ,
    C_AnimationTargetFunc                   ,
    drop_closures_AnimationTargetFunc       ,
    dynamic_AnimationTargetFunc             ,
    genClosure_AnimationTargetFunc          ,
    mk_AnimationTargetFunc                  ,
    noAnimationTargetFunc                   ,
    noAnimationTargetFunc_WithClosures      ,
    wrap_AnimationTargetFunc                ,




    ) 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.GArray as B.GArray
import qualified Data.GI.Base.GClosure as B.GClosure
import qualified Data.GI.Base.GError as B.GError
import qualified Data.GI.Base.GHashTable as B.GHT
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.Coerce as Coerce
import qualified Data.Text as T
import qualified Data.Kind as DK
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 qualified GHC.Records as R


-- callback AnimationTargetFunc
{- Callable
  { returnType = Nothing
  , returnMayBeNull = False
  , returnTransfer = TransferNothing
  , returnDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , args =
      [ Arg
          { argCName = "value"
          , argType = TBasicType TDouble
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The animation value"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "user_data"
          , argType = TBasicType TPtr
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText =
                    Just "The user data provided when creating the target"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = 1
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just "Prototype for animation targets based on user callbacks."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_AnimationTargetFunc =
    CDouble ->
    Ptr () ->
    IO ()

-- Args: [ Arg
--           { argCName = "value"
--           , argType = TBasicType TDouble
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The animation value"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "The user data provided when creating the target"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = 1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_AnimationTargetFunc :: FunPtr C_AnimationTargetFunc -> C_AnimationTargetFunc

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_AnimationTargetFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_AnimationTargetFunc
    -> Double
    -- ^ /@value@/: The animation value
    -> Ptr ()
    -- ^ /@userData@/: The user data provided when creating the target
    -> m ()
dynamic_AnimationTargetFunc :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_AnimationTargetFunc -> Double -> Ptr () -> m ()
dynamic_AnimationTargetFunc FunPtr C_AnimationTargetFunc
__funPtr Double
value Ptr ()
userData = IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ do
    let value' :: CDouble
value' = Double -> CDouble
forall a b. (Real a, Fractional b) => a -> b
realToFrac Double
value
    (FunPtr C_AnimationTargetFunc -> C_AnimationTargetFunc
__dynamic_C_AnimationTargetFunc FunPtr C_AnimationTargetFunc
__funPtr) CDouble
value' Ptr ()
userData
    () -> IO ()
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Generate a function pointer callable from C code, from a `C_AnimationTargetFunc`.
foreign import ccall "wrapper"
    mk_AnimationTargetFunc :: C_AnimationTargetFunc -> IO (FunPtr C_AnimationTargetFunc)

-- | Prototype for animation targets based on user callbacks.
type AnimationTargetFunc =
    Double
    -- ^ /@value@/: The animation value
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `AnimationTargetFunc`@.
noAnimationTargetFunc :: Maybe AnimationTargetFunc
noAnimationTargetFunc :: Maybe AnimationTargetFunc
noAnimationTargetFunc = Maybe AnimationTargetFunc
forall a. Maybe a
Nothing

-- | Prototype for animation targets based on user callbacks.
type AnimationTargetFunc_WithClosures =
    Double
    -- ^ /@value@/: The animation value
    -> Ptr ()
    -- ^ /@userData@/: The user data provided when creating the target
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `AnimationTargetFunc_WithClosures`@.
noAnimationTargetFunc_WithClosures :: Maybe AnimationTargetFunc_WithClosures
noAnimationTargetFunc_WithClosures :: Maybe AnimationTargetFunc_WithClosures
noAnimationTargetFunc_WithClosures = Maybe AnimationTargetFunc_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_AnimationTargetFunc :: AnimationTargetFunc -> AnimationTargetFunc_WithClosures
drop_closures_AnimationTargetFunc :: AnimationTargetFunc -> AnimationTargetFunc_WithClosures
drop_closures_AnimationTargetFunc AnimationTargetFunc
_f Double
value Ptr ()
_ = AnimationTargetFunc
_f Double
value

-- | Wrap the callback into a `GClosure`.
genClosure_AnimationTargetFunc :: MonadIO m => AnimationTargetFunc -> m (GClosure C_AnimationTargetFunc)
genClosure_AnimationTargetFunc :: forall (m :: * -> *).
MonadIO m =>
AnimationTargetFunc -> m (GClosure C_AnimationTargetFunc)
genClosure_AnimationTargetFunc AnimationTargetFunc
cb = IO (GClosure C_AnimationTargetFunc)
-> m (GClosure C_AnimationTargetFunc)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_AnimationTargetFunc)
 -> m (GClosure C_AnimationTargetFunc))
-> IO (GClosure C_AnimationTargetFunc)
-> m (GClosure C_AnimationTargetFunc)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: AnimationTargetFunc_WithClosures
cb' = AnimationTargetFunc -> AnimationTargetFunc_WithClosures
drop_closures_AnimationTargetFunc AnimationTargetFunc
cb
    let cb'' :: C_AnimationTargetFunc
cb'' = Maybe (Ptr (FunPtr C_AnimationTargetFunc))
-> AnimationTargetFunc_WithClosures -> C_AnimationTargetFunc
wrap_AnimationTargetFunc Maybe (Ptr (FunPtr C_AnimationTargetFunc))
forall a. Maybe a
Nothing AnimationTargetFunc_WithClosures
cb'
    C_AnimationTargetFunc -> IO (FunPtr C_AnimationTargetFunc)
mk_AnimationTargetFunc C_AnimationTargetFunc
cb'' IO (FunPtr C_AnimationTargetFunc)
-> (FunPtr C_AnimationTargetFunc
    -> IO (GClosure C_AnimationTargetFunc))
-> IO (GClosure C_AnimationTargetFunc)
forall a b. IO a -> (a -> IO b) -> IO b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= FunPtr C_AnimationTargetFunc -> IO (GClosure C_AnimationTargetFunc)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `AnimationTargetFunc` into a `C_AnimationTargetFunc`.
wrap_AnimationTargetFunc :: 
    Maybe (Ptr (FunPtr C_AnimationTargetFunc)) ->
    AnimationTargetFunc_WithClosures ->
    C_AnimationTargetFunc
wrap_AnimationTargetFunc :: Maybe (Ptr (FunPtr C_AnimationTargetFunc))
-> AnimationTargetFunc_WithClosures -> C_AnimationTargetFunc
wrap_AnimationTargetFunc Maybe (Ptr (FunPtr C_AnimationTargetFunc))
gi'funptrptr AnimationTargetFunc_WithClosures
gi'cb CDouble
value Ptr ()
userData = do
    let value' :: Double
value' = CDouble -> Double
forall a b. (Real a, Fractional b) => a -> b
realToFrac CDouble
value
    AnimationTargetFunc_WithClosures
gi'cb  Double
value' Ptr ()
userData
    Maybe (Ptr (FunPtr C_AnimationTargetFunc)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_AnimationTargetFunc))
gi'funptrptr