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

#if !defined(__HADDOCK_VERSION__)
#define ENABLE_OVERLOADING
#endif

module GI.Dbusmenu.Callbacks
    ( 

 -- * Signals


-- ** ClientTypeHandler #signal:ClientTypeHandler#

    C_ClientTypeHandler                     ,
    ClientTypeHandler                       ,
    ClientTypeHandler_WithClosures          ,
    drop_closures_ClientTypeHandler         ,
    dynamic_ClientTypeHandler               ,
    genClosure_ClientTypeHandler            ,
    mk_ClientTypeHandler                    ,
    noClientTypeHandler                     ,
    noClientTypeHandler_WithClosures        ,
    wrap_ClientTypeHandler                  ,


-- ** MenuitemAboutToShowCb #signal:MenuitemAboutToShowCb#

    C_MenuitemAboutToShowCb                 ,
    MenuitemAboutToShowCb                   ,
    MenuitemAboutToShowCb_WithClosures      ,
    drop_closures_MenuitemAboutToShowCb     ,
    dynamic_MenuitemAboutToShowCb           ,
    genClosure_MenuitemAboutToShowCb        ,
    mk_MenuitemAboutToShowCb                ,
    noMenuitemAboutToShowCb                 ,
    noMenuitemAboutToShowCb_WithClosures    ,
    wrap_MenuitemAboutToShowCb              ,


-- ** MenuitemBuildvariantSlotT #signal:MenuitemBuildvariantSlotT#

    C_MenuitemBuildvariantSlotT             ,
    MenuitemBuildvariantSlotT               ,
    dynamic_MenuitemBuildvariantSlotT       ,
    genClosure_MenuitemBuildvariantSlotT    ,
    mk_MenuitemBuildvariantSlotT            ,
    noMenuitemBuildvariantSlotT             ,
    wrap_MenuitemBuildvariantSlotT          ,




    ) 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
import qualified Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)
import {-# SOURCE #-} qualified GI.Dbusmenu.Enums as Dbusmenu.Enums
import {-# SOURCE #-} qualified GI.Dbusmenu.Objects.Client as Dbusmenu.Client
import {-# SOURCE #-} qualified GI.Dbusmenu.Objects.Menuitem as Dbusmenu.Menuitem
import qualified GI.GLib.Callbacks as GLib.Callbacks
import qualified GI.GObject.Objects.Object as GObject.Object

#else
import {-# SOURCE #-} qualified GI.Dbusmenu.Objects.Client as Dbusmenu.Client
import {-# SOURCE #-} qualified GI.Dbusmenu.Objects.Menuitem as Dbusmenu.Menuitem

#endif

-- callback MenuitemBuildvariantSlotT
{- Callable
  { returnType = Just TVariant
  , returnMayBeNull = False
  , returnTransfer = TransferEverything
  , returnDocumentation =
      Documentation
        { rawDocText =
            Just "A variant representing this item and its children"
        , sinceVersion = Nothing
        }
  , args =
      [ Arg
          { argCName = "mi"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
          , argCType = Just "DbusmenuMenuitem*"
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "Menu item that should be built from"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "properties"
          , argType = TBasicType TUTF8
          , argCType = Just "gchar**"
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText =
                    Just
                      "A list of properties that should be the only ones in the resulting variant structure"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just
              "This is the function that is called to represent this menu item\nas a variant.  Should call its own children."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_MenuitemBuildvariantSlotT =
    Ptr Dbusmenu.Menuitem.Menuitem ->
    CString ->
    IO (Ptr GVariant)

-- Args: [ Arg
--           { argCName = "mi"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
--           , argCType = Just "DbusmenuMenuitem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "Menu item that should be built from"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "properties"
--           , argType = TBasicType TUTF8
--           , argCType = Just "gchar**"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "A list of properties that should be the only ones in the resulting variant structure"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just TVariant
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_MenuitemBuildvariantSlotT :: FunPtr C_MenuitemBuildvariantSlotT -> C_MenuitemBuildvariantSlotT

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_MenuitemBuildvariantSlotT ::
    (B.CallStack.HasCallStack, MonadIO m, Dbusmenu.Menuitem.IsMenuitem a) =>
    FunPtr C_MenuitemBuildvariantSlotT
    -> a
    -- ^ /@mi@/: Menu item that should be built from
    -> Maybe (T.Text)
    -- ^ /@properties@/: A list of properties that should be the only ones in the resulting variant structure
    -> m GVariant
    -- ^ __Returns:__ A variant representing this item and its children
dynamic_MenuitemBuildvariantSlotT :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsMenuitem a) =>
FunPtr C_MenuitemBuildvariantSlotT -> a -> Maybe Text -> m GVariant
dynamic_MenuitemBuildvariantSlotT FunPtr C_MenuitemBuildvariantSlotT
__funPtr a
mi Maybe Text
properties = IO GVariant -> m GVariant
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO GVariant -> m GVariant) -> IO GVariant -> m GVariant
forall a b. (a -> b) -> a -> b
$ do
    mi' <- a -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
mi
    maybeProperties <- case properties of
        Maybe Text
Nothing -> CString -> IO CString
forall a. a -> IO a
forall (m :: * -> *) a. Monad m => a -> m a
return CString
forall a. Ptr a
FP.nullPtr
        Just Text
jProperties -> do
            jProperties' <- Text -> IO CString
textToCString Text
jProperties
            return jProperties'
    result <- (__dynamic_C_MenuitemBuildvariantSlotT __funPtr) mi' maybeProperties
    checkUnexpectedReturnNULL "menuitemBuildvariantSlotT" result
    result' <- B.GVariant.wrapGVariantPtr result
    touchManagedPtr mi
    freeMem maybeProperties
    return result'

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

-- | This is the function that is called to represent this menu item
-- as a variant.  Should call its own children.
type MenuitemBuildvariantSlotT =
    Dbusmenu.Menuitem.Menuitem
    -- ^ /@mi@/: Menu item that should be built from
    -> Maybe T.Text
    -- ^ /@properties@/: A list of properties that should be the only ones in the resulting variant structure
    -> IO GVariant
    -- ^ __Returns:__ A variant representing this item and its children

-- | A convenience synonym for @`Nothing` :: `Maybe` `MenuitemBuildvariantSlotT`@.
noMenuitemBuildvariantSlotT :: Maybe MenuitemBuildvariantSlotT
noMenuitemBuildvariantSlotT :: Maybe MenuitemBuildvariantSlotT
noMenuitemBuildvariantSlotT = Maybe MenuitemBuildvariantSlotT
forall a. Maybe a
Nothing

-- | Wrap the callback into a `GClosure`.
genClosure_MenuitemBuildvariantSlotT :: MonadIO m => MenuitemBuildvariantSlotT -> m (GClosure C_MenuitemBuildvariantSlotT)
genClosure_MenuitemBuildvariantSlotT :: forall (m :: * -> *).
MonadIO m =>
MenuitemBuildvariantSlotT
-> m (GClosure C_MenuitemBuildvariantSlotT)
genClosure_MenuitemBuildvariantSlotT MenuitemBuildvariantSlotT
cb = IO (GClosure C_MenuitemBuildvariantSlotT)
-> m (GClosure C_MenuitemBuildvariantSlotT)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_MenuitemBuildvariantSlotT)
 -> m (GClosure C_MenuitemBuildvariantSlotT))
-> IO (GClosure C_MenuitemBuildvariantSlotT)
-> m (GClosure C_MenuitemBuildvariantSlotT)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: C_MenuitemBuildvariantSlotT
cb' = Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT))
-> MenuitemBuildvariantSlotT -> C_MenuitemBuildvariantSlotT
wrap_MenuitemBuildvariantSlotT Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT))
forall a. Maybe a
Nothing MenuitemBuildvariantSlotT
cb
    C_MenuitemBuildvariantSlotT
-> IO (FunPtr C_MenuitemBuildvariantSlotT)
mk_MenuitemBuildvariantSlotT C_MenuitemBuildvariantSlotT
cb' IO (FunPtr C_MenuitemBuildvariantSlotT)
-> (FunPtr C_MenuitemBuildvariantSlotT
    -> IO (GClosure C_MenuitemBuildvariantSlotT))
-> IO (GClosure C_MenuitemBuildvariantSlotT)
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_MenuitemBuildvariantSlotT
-> IO (GClosure C_MenuitemBuildvariantSlotT)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `MenuitemBuildvariantSlotT` into a `C_MenuitemBuildvariantSlotT`.
wrap_MenuitemBuildvariantSlotT :: 
    Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT)) ->
    MenuitemBuildvariantSlotT ->
    C_MenuitemBuildvariantSlotT
wrap_MenuitemBuildvariantSlotT :: Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT))
-> MenuitemBuildvariantSlotT -> C_MenuitemBuildvariantSlotT
wrap_MenuitemBuildvariantSlotT Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT))
gi'funptrptr MenuitemBuildvariantSlotT
gi'cb Ptr Menuitem
mi CString
properties = do
    mi' <- ((ManagedPtr Menuitem -> Menuitem) -> Ptr Menuitem -> IO Menuitem
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Menuitem -> Menuitem
Dbusmenu.Menuitem.Menuitem) Ptr Menuitem
mi
    maybeProperties <-
        if properties == FP.nullPtr
        then return Nothing
        else do
            properties' <- cstringToText properties
            return $ Just properties'
    result <- gi'cb  mi' maybeProperties
    maybeReleaseFunPtr gi'funptrptr
    result' <- B.GVariant.disownGVariant result
    return result'


-- callback MenuitemAboutToShowCb
{- Callable
  { returnType = Nothing
  , returnMayBeNull = False
  , returnTransfer = TransferNothing
  , returnDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , args =
      [ Arg
          { argCName = "mi"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
          , argCType = Just "DbusmenuMenuitem*"
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "Menu item that should be shown"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "user_data"
          , argType = TBasicType TPtr
          , argCType = Just "gpointer"
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText = Just "Extra user data sent with the function"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = True
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just
              "Callback prototype for a callback that is called when the\nmenu should be shown."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_MenuitemAboutToShowCb =
    Ptr Dbusmenu.Menuitem.Menuitem ->
    Ptr () ->
    IO ()

-- Args: [ Arg
--           { argCName = "mi"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
--           , argCType = Just "DbusmenuMenuitem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "Menu item that should be shown"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , argCType = Just "gpointer"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "Extra user data sent with the function"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = True
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_MenuitemAboutToShowCb :: FunPtr C_MenuitemAboutToShowCb -> C_MenuitemAboutToShowCb

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_MenuitemAboutToShowCb ::
    (B.CallStack.HasCallStack, MonadIO m, Dbusmenu.Menuitem.IsMenuitem a) =>
    FunPtr C_MenuitemAboutToShowCb
    -> a
    -- ^ /@mi@/: Menu item that should be shown
    -> Ptr ()
    -- ^ /@userData@/: Extra user data sent with the function
    -> m ()
dynamic_MenuitemAboutToShowCb :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsMenuitem a) =>
FunPtr C_MenuitemAboutToShowCb -> a -> Ptr () -> m ()
dynamic_MenuitemAboutToShowCb FunPtr C_MenuitemAboutToShowCb
__funPtr a
mi 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
    mi' <- a -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
mi
    (__dynamic_C_MenuitemAboutToShowCb __funPtr) mi' userData
    touchManagedPtr mi
    return ()

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

-- | Callback prototype for a callback that is called when the
-- menu should be shown.
type MenuitemAboutToShowCb =
    Dbusmenu.Menuitem.Menuitem
    -- ^ /@mi@/: Menu item that should be shown
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `MenuitemAboutToShowCb`@.
noMenuitemAboutToShowCb :: Maybe MenuitemAboutToShowCb
noMenuitemAboutToShowCb :: Maybe MenuitemAboutToShowCb
noMenuitemAboutToShowCb = Maybe MenuitemAboutToShowCb
forall a. Maybe a
Nothing

-- | Callback prototype for a callback that is called when the
-- menu should be shown.
type MenuitemAboutToShowCb_WithClosures =
    Dbusmenu.Menuitem.Menuitem
    -- ^ /@mi@/: Menu item that should be shown
    -> Ptr ()
    -- ^ /@userData@/: Extra user data sent with the function
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `MenuitemAboutToShowCb_WithClosures`@.
noMenuitemAboutToShowCb_WithClosures :: Maybe MenuitemAboutToShowCb_WithClosures
noMenuitemAboutToShowCb_WithClosures :: Maybe MenuitemAboutToShowCb_WithClosures
noMenuitemAboutToShowCb_WithClosures = Maybe MenuitemAboutToShowCb_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_MenuitemAboutToShowCb :: MenuitemAboutToShowCb -> MenuitemAboutToShowCb_WithClosures
drop_closures_MenuitemAboutToShowCb :: MenuitemAboutToShowCb -> MenuitemAboutToShowCb_WithClosures
drop_closures_MenuitemAboutToShowCb MenuitemAboutToShowCb
_f Menuitem
mi Ptr ()
_ = MenuitemAboutToShowCb
_f Menuitem
mi

-- | Wrap the callback into a `GClosure`.
genClosure_MenuitemAboutToShowCb :: MonadIO m => MenuitemAboutToShowCb -> m (GClosure C_MenuitemAboutToShowCb)
genClosure_MenuitemAboutToShowCb :: forall (m :: * -> *).
MonadIO m =>
MenuitemAboutToShowCb -> m (GClosure C_MenuitemAboutToShowCb)
genClosure_MenuitemAboutToShowCb MenuitemAboutToShowCb
cb = IO (GClosure C_MenuitemAboutToShowCb)
-> m (GClosure C_MenuitemAboutToShowCb)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_MenuitemAboutToShowCb)
 -> m (GClosure C_MenuitemAboutToShowCb))
-> IO (GClosure C_MenuitemAboutToShowCb)
-> m (GClosure C_MenuitemAboutToShowCb)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: MenuitemAboutToShowCb_WithClosures
cb' = MenuitemAboutToShowCb -> MenuitemAboutToShowCb_WithClosures
drop_closures_MenuitemAboutToShowCb MenuitemAboutToShowCb
cb
    let cb'' :: C_MenuitemAboutToShowCb
cb'' = Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb))
-> MenuitemAboutToShowCb_WithClosures -> C_MenuitemAboutToShowCb
wrap_MenuitemAboutToShowCb Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb))
forall a. Maybe a
Nothing MenuitemAboutToShowCb_WithClosures
cb'
    C_MenuitemAboutToShowCb -> IO (FunPtr C_MenuitemAboutToShowCb)
mk_MenuitemAboutToShowCb C_MenuitemAboutToShowCb
cb'' IO (FunPtr C_MenuitemAboutToShowCb)
-> (FunPtr C_MenuitemAboutToShowCb
    -> IO (GClosure C_MenuitemAboutToShowCb))
-> IO (GClosure C_MenuitemAboutToShowCb)
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_MenuitemAboutToShowCb
-> IO (GClosure C_MenuitemAboutToShowCb)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `MenuitemAboutToShowCb` into a `C_MenuitemAboutToShowCb`.
wrap_MenuitemAboutToShowCb :: 
    Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb)) ->
    MenuitemAboutToShowCb_WithClosures ->
    C_MenuitemAboutToShowCb
wrap_MenuitemAboutToShowCb :: Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb))
-> MenuitemAboutToShowCb_WithClosures -> C_MenuitemAboutToShowCb
wrap_MenuitemAboutToShowCb Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb))
gi'funptrptr MenuitemAboutToShowCb_WithClosures
gi'cb Ptr Menuitem
mi Ptr ()
userData = do
    mi' <- ((ManagedPtr Menuitem -> Menuitem) -> Ptr Menuitem -> IO Menuitem
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Menuitem -> Menuitem
Dbusmenu.Menuitem.Menuitem) Ptr Menuitem
mi
    gi'cb  mi' userData
    maybeReleaseFunPtr gi'funptrptr


-- callback ClientTypeHandler
{- Callable
  { returnType = Just (TBasicType TBoolean)
  , returnMayBeNull = False
  , returnTransfer = TransferNothing
  , returnDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , args =
      [ Arg
          { argCName = "newitem"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
          , argCType = Just "DbusmenuMenuitem*"
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The #DbusmenuMenuitem that was created"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "parent"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
          , argCType = Just "DbusmenuMenuitem*"
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The parent of @newitem or #NULL if none"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "client"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Client" }
          , argCType = Just "DbusmenuClient*"
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "A pointer to the #DbusmenuClient"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "user_data"
          , argType = TBasicType TPtr
          , argCType = Just "gpointer"
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText = Just "The data you gave us"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , argCallbackUserData = True
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just
              "The type handler is called when a dbusmenu item is created\n\twith a matching type as setup in #dbusmenu_client_add_type_handler\n\n\tReturn value: #TRUE if the type has been handled.  #FALSE if this\n\t\tfunction was somehow unable to handle it."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_ClientTypeHandler =
    Ptr Dbusmenu.Menuitem.Menuitem ->
    Ptr Dbusmenu.Menuitem.Menuitem ->
    Ptr Dbusmenu.Client.Client ->
    Ptr () ->
    IO CInt

-- Args: [ Arg
--           { argCName = "newitem"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
--           , argCType = Just "DbusmenuMenuitem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The #DbusmenuMenuitem that was created"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "parent"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
--           , argCType = Just "DbusmenuMenuitem*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The parent of @newitem or #NULL if none"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Client" }
--           , argCType = Just "DbusmenuClient*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A pointer to the #DbusmenuClient"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "user_data"
--           , argType = TBasicType TPtr
--           , argCType = Just "gpointer"
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The data you gave us"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = True
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_ClientTypeHandler :: FunPtr C_ClientTypeHandler -> C_ClientTypeHandler

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_ClientTypeHandler ::
    (B.CallStack.HasCallStack, MonadIO m, Dbusmenu.Menuitem.IsMenuitem a, Dbusmenu.Menuitem.IsMenuitem b, Dbusmenu.Client.IsClient c) =>
    FunPtr C_ClientTypeHandler
    -> a
    -- ^ /@newitem@/: The t'GI.Dbusmenu.Objects.Menuitem.Menuitem' that was created
    -> b
    -- ^ /@parent@/: The parent of /@newitem@/ or @/NULL/@ if none
    -> c
    -- ^ /@client@/: A pointer to the t'GI.Dbusmenu.Objects.Client.Client'
    -> Ptr ()
    -- ^ /@userData@/: The data you gave us
    -> m Bool
dynamic_ClientTypeHandler :: forall (m :: * -> *) a b c.
(HasCallStack, MonadIO m, IsMenuitem a, IsMenuitem b,
 IsClient c) =>
FunPtr C_ClientTypeHandler -> a -> b -> c -> Ptr () -> m Bool
dynamic_ClientTypeHandler FunPtr C_ClientTypeHandler
__funPtr a
newitem b
parent c
client Ptr ()
userData = IO Bool -> m Bool
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO Bool -> m Bool) -> IO Bool -> m Bool
forall a b. (a -> b) -> a -> b
$ do
    newitem' <- a -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
newitem
    parent' <- unsafeManagedPtrCastPtr parent
    client' <- unsafeManagedPtrCastPtr client
    result <- (__dynamic_C_ClientTypeHandler __funPtr) newitem' parent' client' userData
    let result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    touchManagedPtr newitem
    touchManagedPtr parent
    touchManagedPtr client
    return result'

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

-- | The type handler is called when a dbusmenu item is created
-- 	with a matching type as setup in @/dbusmenu_client_add_type_handler/@
-- 
-- 	Return value: @/TRUE/@ if the type has been handled.  @/FALSE/@ if this
-- 		function was somehow unable to handle it.
type ClientTypeHandler =
    Dbusmenu.Menuitem.Menuitem
    -- ^ /@newitem@/: The t'GI.Dbusmenu.Objects.Menuitem.Menuitem' that was created
    -> Dbusmenu.Menuitem.Menuitem
    -- ^ /@parent@/: The parent of /@newitem@/ or @/NULL/@ if none
    -> Dbusmenu.Client.Client
    -- ^ /@client@/: A pointer to the t'GI.Dbusmenu.Objects.Client.Client'
    -> IO Bool

-- | A convenience synonym for @`Nothing` :: `Maybe` `ClientTypeHandler`@.
noClientTypeHandler :: Maybe ClientTypeHandler
noClientTypeHandler :: Maybe ClientTypeHandler
noClientTypeHandler = Maybe ClientTypeHandler
forall a. Maybe a
Nothing

-- | The type handler is called when a dbusmenu item is created
-- 	with a matching type as setup in @/dbusmenu_client_add_type_handler/@
-- 
-- 	Return value: @/TRUE/@ if the type has been handled.  @/FALSE/@ if this
-- 		function was somehow unable to handle it.
type ClientTypeHandler_WithClosures =
    Dbusmenu.Menuitem.Menuitem
    -- ^ /@newitem@/: The t'GI.Dbusmenu.Objects.Menuitem.Menuitem' that was created
    -> Dbusmenu.Menuitem.Menuitem
    -- ^ /@parent@/: The parent of /@newitem@/ or @/NULL/@ if none
    -> Dbusmenu.Client.Client
    -- ^ /@client@/: A pointer to the t'GI.Dbusmenu.Objects.Client.Client'
    -> Ptr ()
    -- ^ /@userData@/: The data you gave us
    -> IO Bool

-- | A convenience synonym for @`Nothing` :: `Maybe` `ClientTypeHandler_WithClosures`@.
noClientTypeHandler_WithClosures :: Maybe ClientTypeHandler_WithClosures
noClientTypeHandler_WithClosures :: Maybe ClientTypeHandler_WithClosures
noClientTypeHandler_WithClosures = Maybe ClientTypeHandler_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_ClientTypeHandler :: ClientTypeHandler -> ClientTypeHandler_WithClosures
drop_closures_ClientTypeHandler :: ClientTypeHandler -> ClientTypeHandler_WithClosures
drop_closures_ClientTypeHandler ClientTypeHandler
_f Menuitem
newitem Menuitem
parent Client
client Ptr ()
_ = ClientTypeHandler
_f Menuitem
newitem Menuitem
parent Client
client

-- | Wrap the callback into a `GClosure`.
genClosure_ClientTypeHandler :: MonadIO m => ClientTypeHandler -> m (GClosure C_ClientTypeHandler)
genClosure_ClientTypeHandler :: forall (m :: * -> *).
MonadIO m =>
ClientTypeHandler -> m (GClosure C_ClientTypeHandler)
genClosure_ClientTypeHandler ClientTypeHandler
cb = IO (GClosure C_ClientTypeHandler)
-> m (GClosure C_ClientTypeHandler)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_ClientTypeHandler)
 -> m (GClosure C_ClientTypeHandler))
-> IO (GClosure C_ClientTypeHandler)
-> m (GClosure C_ClientTypeHandler)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: ClientTypeHandler_WithClosures
cb' = ClientTypeHandler -> ClientTypeHandler_WithClosures
drop_closures_ClientTypeHandler ClientTypeHandler
cb
    let cb'' :: C_ClientTypeHandler
cb'' = Maybe (Ptr (FunPtr C_ClientTypeHandler))
-> ClientTypeHandler_WithClosures -> C_ClientTypeHandler
wrap_ClientTypeHandler Maybe (Ptr (FunPtr C_ClientTypeHandler))
forall a. Maybe a
Nothing ClientTypeHandler_WithClosures
cb'
    C_ClientTypeHandler -> IO (FunPtr C_ClientTypeHandler)
mk_ClientTypeHandler C_ClientTypeHandler
cb'' IO (FunPtr C_ClientTypeHandler)
-> (FunPtr C_ClientTypeHandler
    -> IO (GClosure C_ClientTypeHandler))
-> IO (GClosure C_ClientTypeHandler)
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_ClientTypeHandler -> IO (GClosure C_ClientTypeHandler)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `ClientTypeHandler` into a `C_ClientTypeHandler`.
wrap_ClientTypeHandler :: 
    Maybe (Ptr (FunPtr C_ClientTypeHandler)) ->
    ClientTypeHandler_WithClosures ->
    C_ClientTypeHandler
wrap_ClientTypeHandler :: Maybe (Ptr (FunPtr C_ClientTypeHandler))
-> ClientTypeHandler_WithClosures -> C_ClientTypeHandler
wrap_ClientTypeHandler Maybe (Ptr (FunPtr C_ClientTypeHandler))
gi'funptrptr ClientTypeHandler_WithClosures
gi'cb Ptr Menuitem
newitem Ptr Menuitem
parent Ptr Client
client Ptr ()
userData = do
    newitem' <- ((ManagedPtr Menuitem -> Menuitem) -> Ptr Menuitem -> IO Menuitem
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Menuitem -> Menuitem
Dbusmenu.Menuitem.Menuitem) Ptr Menuitem
newitem
    parent' <- (newObject Dbusmenu.Menuitem.Menuitem) parent
    client' <- (newObject Dbusmenu.Client.Client) client
    result <- gi'cb  newitem' parent' client' userData
    maybeReleaseFunPtr gi'funptrptr
    let result' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
P.fromIntegral (Int -> CInt) -> (Bool -> Int) -> Bool -> CInt
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Int
forall a. Enum a => a -> Int
P.fromEnum) Bool
result
    return result'