-- | Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
-- 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.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.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

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

-- 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" }
          , 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
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "properties"
          , argType = TBasicType TUTF8
          , 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
          , 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" }
--           , 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
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "properties"
--           , argType = TBasicType TUTF8
--           , 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
--           , 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 :: FunPtr C_MenuitemBuildvariantSlotT -> a -> Maybe Text -> m GVariant
dynamic_MenuitemBuildvariantSlotT FunPtr C_MenuitemBuildvariantSlotT
__funPtr a
mi Maybe Text
properties = IO GVariant -> m GVariant
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
    Ptr Menuitem
mi' <- a -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
mi
    Ptr CChar
maybeProperties <- case Maybe Text
properties of
        Maybe Text
Nothing -> Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
forall a. Ptr a
nullPtr
        Just Text
jProperties -> do
            Ptr CChar
jProperties' <- Text -> IO (Ptr CChar)
textToCString Text
jProperties
            Ptr CChar -> IO (Ptr CChar)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr CChar
jProperties'
    Ptr GVariant
result <- (FunPtr C_MenuitemBuildvariantSlotT -> C_MenuitemBuildvariantSlotT
__dynamic_C_MenuitemBuildvariantSlotT FunPtr C_MenuitemBuildvariantSlotT
__funPtr) Ptr Menuitem
mi' Ptr CChar
maybeProperties
    Text -> Ptr GVariant -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"menuitemBuildvariantSlotT" Ptr GVariant
result
    GVariant
result' <- Ptr GVariant -> IO GVariant
B.GVariant.wrapGVariantPtr Ptr GVariant
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
mi
    Ptr CChar -> IO ()
forall a. Ptr a -> IO ()
freeMem Ptr CChar
maybeProperties
    GVariant -> IO GVariant
forall (m :: * -> *) a. Monad m => a -> m a
return GVariant
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 :: MenuitemBuildvariantSlotT
-> m (GClosure C_MenuitemBuildvariantSlotT)
genClosure_MenuitemBuildvariantSlotT MenuitemBuildvariantSlotT
cb = IO (GClosure C_MenuitemBuildvariantSlotT)
-> m (GClosure C_MenuitemBuildvariantSlotT)
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 (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))
funptrptr MenuitemBuildvariantSlotT
_cb Ptr Menuitem
mi Ptr CChar
properties = do
    Menuitem
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
    Maybe Text
maybeProperties <-
        if Ptr CChar
properties Ptr CChar -> Ptr CChar -> Bool
forall a. Eq a => a -> a -> Bool
== Ptr CChar
forall a. Ptr a
nullPtr
        then Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Text
forall a. Maybe a
Nothing
        else do
            Text
properties' <- HasCallStack => Ptr CChar -> IO Text
Ptr CChar -> IO Text
cstringToText Ptr CChar
properties
            Maybe Text -> IO (Maybe Text)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Text -> IO (Maybe Text)) -> Maybe Text -> IO (Maybe Text)
forall a b. (a -> b) -> a -> b
$ Text -> Maybe Text
forall a. a -> Maybe a
Just Text
properties'
    GVariant
result <- MenuitemBuildvariantSlotT
_cb  Menuitem
mi' Maybe Text
maybeProperties
    Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_MenuitemBuildvariantSlotT))
funptrptr
    Ptr GVariant
result' <- GVariant -> IO (Ptr GVariant)
B.GVariant.disownGVariant GVariant
result
    Ptr GVariant -> IO (Ptr GVariant)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr GVariant
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" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "Menu item that should be shown"
                , 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 "Extra user data sent with the function"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = 1
          , argDestroy = -1
          , argCallerAllocates = False
          , 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" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "Menu item that should be shown"
--                 , 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 "Extra user data sent with the function"
--                 , 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_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 :: FunPtr C_MenuitemAboutToShowCb -> a -> Ptr () -> m ()
dynamic_MenuitemAboutToShowCb FunPtr C_MenuitemAboutToShowCb
__funPtr a
mi Ptr ()
userData = 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 Menuitem
mi' <- a -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
mi
    (FunPtr C_MenuitemAboutToShowCb -> C_MenuitemAboutToShowCb
__dynamic_C_MenuitemAboutToShowCb FunPtr C_MenuitemAboutToShowCb
__funPtr) Ptr Menuitem
mi' Ptr ()
userData
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
mi
    () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
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 :: MenuitemAboutToShowCb -> m (GClosure C_MenuitemAboutToShowCb)
genClosure_MenuitemAboutToShowCb MenuitemAboutToShowCb
cb = IO (GClosure C_MenuitemAboutToShowCb)
-> m (GClosure C_MenuitemAboutToShowCb)
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 (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))
funptrptr MenuitemAboutToShowCb_WithClosures
_cb Ptr Menuitem
mi Ptr ()
userData = do
    Menuitem
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
    MenuitemAboutToShowCb_WithClosures
_cb  Menuitem
mi' Ptr ()
userData
    Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_MenuitemAboutToShowCb))
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" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "The #DbusmenuMenuitem that was created"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "parent"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
          , 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
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "client"
          , argType =
              TInterface Name { namespace = "Dbusmenu" , name = "Client" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "A pointer to the #DbusmenuClient"
                , 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 data you gave us"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = 3
          , argDestroy = -1
          , argCallerAllocates = False
          , 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" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The #DbusmenuMenuitem that was created"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "parent"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Menuitem" }
--           , 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
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "client"
--           , argType =
--               TInterface Name { namespace = "Dbusmenu" , name = "Client" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "A pointer to the #DbusmenuClient"
--                 , 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 data you gave us"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = 3
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , 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 :: 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 (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
    Ptr Menuitem
newitem' <- a -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
newitem
    Ptr Menuitem
parent' <- b -> IO (Ptr Menuitem)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr b
parent
    Ptr Client
client' <- c -> IO (Ptr Client)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr c
client
    CInt
result <- (FunPtr C_ClientTypeHandler -> C_ClientTypeHandler
__dynamic_C_ClientTypeHandler FunPtr C_ClientTypeHandler
__funPtr) Ptr Menuitem
newitem' Ptr Menuitem
parent' Ptr Client
client' Ptr ()
userData
    let result' :: Bool
result' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
result
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
newitem
    b -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr b
parent
    c -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr c
client
    Bool -> IO Bool
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
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 :: ClientTypeHandler -> m (GClosure C_ClientTypeHandler)
genClosure_ClientTypeHandler ClientTypeHandler
cb = IO (GClosure C_ClientTypeHandler)
-> m (GClosure C_ClientTypeHandler)
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 (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))
funptrptr ClientTypeHandler_WithClosures
_cb Ptr Menuitem
newitem Ptr Menuitem
parent Ptr Client
client Ptr ()
userData = do
    Menuitem
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
    Menuitem
parent' <- ((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
parent
    Client
client' <- ((ManagedPtr Client -> Client) -> Ptr Client -> IO Client
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
newObject ManagedPtr Client -> Client
Dbusmenu.Client.Client) Ptr Client
client
    Bool
result <- ClientTypeHandler_WithClosures
_cb  Menuitem
newitem' Menuitem
parent' Client
client' Ptr ()
userData
    Maybe (Ptr (FunPtr C_ClientTypeHandler)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_ClientTypeHandler))
funptrptr
    let result' :: CInt
result' = (Int -> CInt
forall a b. (Integral a, Num b) => a -> b
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
fromEnum) Bool
result
    CInt -> IO CInt
forall (m :: * -> *) a. Monad m => a -> m a
return CInt
result'