-- | 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.PangoCairo.Callbacks
    ( 

 -- * Signals


-- ** ShapeRendererFunc #signal:ShapeRendererFunc#

    C_ShapeRendererFunc                     ,
    ShapeRendererFunc                       ,
    ShapeRendererFunc_WithClosures          ,
    drop_closures_ShapeRendererFunc         ,
    dynamic_ShapeRendererFunc               ,
    genClosure_ShapeRendererFunc            ,
    mk_ShapeRendererFunc                    ,
    noShapeRendererFunc                     ,
    noShapeRendererFunc_WithClosures        ,
    wrap_ShapeRendererFunc                  ,




    ) 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.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 GI.Cairo.Structs.Context as Cairo.Context
import qualified GI.Pango.Structs.AttrShape as Pango.AttrShape

-- callback ShapeRendererFunc
{- Callable
  { returnType = Nothing
  , returnMayBeNull = False
  , returnTransfer = TransferNothing
  , returnDocumentation =
      Documentation { rawDocText = Nothing , sinceVersion = Nothing }
  , args =
      [ Arg
          { argCName = "cr"
          , argType =
              TInterface Name { namespace = "cairo" , name = "Context" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText =
                    Just
                      "a Cairo context with current point set to where the shape should\nbe rendered"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "attr"
          , argType =
              TInterface Name { namespace = "Pango" , name = "AttrShape" }
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText = Just "the %PANGO_ATTR_SHAPE to render"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "do_path"
          , argType = TBasicType TBoolean
          , direction = DirectionIn
          , mayBeNull = False
          , argDoc =
              Documentation
                { rawDocText =
                    Just
                      "whether only the shape path should be appended to current\npath of @cr and no filling/stroking done.  This will be set\nto %TRUE when called from pango_cairo_layout_path() and\npango_cairo_layout_line_path() rendering functions."
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = -1
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      , Arg
          { argCName = "data"
          , argType = TBasicType TPtr
          , direction = DirectionIn
          , mayBeNull = True
          , argDoc =
              Documentation
                { rawDocText =
                    Just "user data passed to pango_cairo_context_set_shape_renderer()"
                , sinceVersion = Nothing
                }
          , argScope = ScopeTypeInvalid
          , argClosure = 3
          , argDestroy = -1
          , argCallerAllocates = False
          , transfer = TransferNothing
          }
      ]
  , skipReturn = False
  , callableThrows = False
  , callableDeprecated = Nothing
  , callableDocumentation =
      Documentation
        { rawDocText =
            Just
              "Function type for rendering attributes of type %PANGO_ATTR_SHAPE\nwith Pango's Cairo renderer."
        , sinceVersion = Nothing
        }
  , callableResolvable = Nothing
  }
-}
-- | Type for the callback on the (unwrapped) C side.
type C_ShapeRendererFunc =
    Ptr Cairo.Context.Context ->
    Ptr Pango.AttrShape.AttrShape ->
    CInt ->
    Ptr () ->
    IO ()

-- Args: [ Arg
--           { argCName = "cr"
--           , argType =
--               TInterface Name { namespace = "cairo" , name = "Context" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "a Cairo context with current point set to where the shape should\nbe rendered"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "attr"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "AttrShape" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "the %PANGO_ATTR_SHAPE to render"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "do_path"
--           , argType = TBasicType TBoolean
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just
--                       "whether only the shape path should be appended to current\npath of @cr and no filling/stroking done.  This will be set\nto %TRUE when called from pango_cairo_layout_path() and\npango_cairo_layout_line_path() rendering functions."
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "data"
--           , argType = TBasicType TPtr
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "user data passed to pango_cairo_context_set_shape_renderer()"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = 3
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Nothing
-- throws : False
-- Skip return : False

foreign import ccall "dynamic" __dynamic_C_ShapeRendererFunc :: FunPtr C_ShapeRendererFunc -> C_ShapeRendererFunc

-- | Given a pointer to a foreign C function, wrap it into a function callable from Haskell.
dynamic_ShapeRendererFunc ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    FunPtr C_ShapeRendererFunc
    -> Cairo.Context.Context
    -- ^ /@cr@/: a Cairo context with current point set to where the shape should
    -- be rendered
    -> Pango.AttrShape.AttrShape
    -- ^ /@attr@/: the 'GI.Pango.Enums.AttrTypeShape' to render
    -> Bool
    -- ^ /@doPath@/: whether only the shape path should be appended to current
    -- path of /@cr@/ and no filling\/stroking done.  This will be set
    -- to 'P.True' when called from 'GI.PangoCairo.Functions.layoutPath' and
    -- 'GI.PangoCairo.Functions.layoutLinePath' rendering functions.
    -> Ptr ()
    -- ^ /@data@/: user data passed to 'GI.PangoCairo.Functions.contextSetShapeRenderer'
    -> m ()
dynamic_ShapeRendererFunc :: forall (m :: * -> *).
(HasCallStack, MonadIO m) =>
FunPtr C_ShapeRendererFunc
-> Context -> AttrShape -> Bool -> Ptr () -> m ()
dynamic_ShapeRendererFunc FunPtr C_ShapeRendererFunc
__funPtr Context
cr AttrShape
attr Bool
doPath Ptr ()
data_ = 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
    Ptr Context
cr' <- Context -> IO (Ptr Context)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Context
cr
    Ptr AttrShape
attr' <- AttrShape -> IO (Ptr AttrShape)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr AttrShape
attr
    let doPath' :: CInt
doPath' = (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
doPath
    (FunPtr C_ShapeRendererFunc -> C_ShapeRendererFunc
__dynamic_C_ShapeRendererFunc FunPtr C_ShapeRendererFunc
__funPtr) Ptr Context
cr' Ptr AttrShape
attr' CInt
doPath' Ptr ()
data_
    Context -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr Context
cr
    AttrShape -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr AttrShape
attr
    () -> 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_ShapeRendererFunc`.
foreign import ccall "wrapper"
    mk_ShapeRendererFunc :: C_ShapeRendererFunc -> IO (FunPtr C_ShapeRendererFunc)

-- | Function type for rendering attributes of type 'GI.Pango.Enums.AttrTypeShape'
-- with Pango\'s Cairo renderer.
type ShapeRendererFunc =
    Cairo.Context.Context
    -- ^ /@cr@/: a Cairo context with current point set to where the shape should
    -- be rendered
    -> Pango.AttrShape.AttrShape
    -- ^ /@attr@/: the 'GI.Pango.Enums.AttrTypeShape' to render
    -> Bool
    -- ^ /@doPath@/: whether only the shape path should be appended to current
    -- path of /@cr@/ and no filling\/stroking done.  This will be set
    -- to 'P.True' when called from 'GI.PangoCairo.Functions.layoutPath' and
    -- 'GI.PangoCairo.Functions.layoutLinePath' rendering functions.
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ShapeRendererFunc`@.
noShapeRendererFunc :: Maybe ShapeRendererFunc
noShapeRendererFunc :: Maybe ShapeRendererFunc
noShapeRendererFunc = Maybe ShapeRendererFunc
forall a. Maybe a
Nothing

-- | Function type for rendering attributes of type 'GI.Pango.Enums.AttrTypeShape'
-- with Pango\'s Cairo renderer.
type ShapeRendererFunc_WithClosures =
    Cairo.Context.Context
    -- ^ /@cr@/: a Cairo context with current point set to where the shape should
    -- be rendered
    -> Pango.AttrShape.AttrShape
    -- ^ /@attr@/: the 'GI.Pango.Enums.AttrTypeShape' to render
    -> Bool
    -- ^ /@doPath@/: whether only the shape path should be appended to current
    -- path of /@cr@/ and no filling\/stroking done.  This will be set
    -- to 'P.True' when called from 'GI.PangoCairo.Functions.layoutPath' and
    -- 'GI.PangoCairo.Functions.layoutLinePath' rendering functions.
    -> Ptr ()
    -- ^ /@data@/: user data passed to 'GI.PangoCairo.Functions.contextSetShapeRenderer'
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `ShapeRendererFunc_WithClosures`@.
noShapeRendererFunc_WithClosures :: Maybe ShapeRendererFunc_WithClosures
noShapeRendererFunc_WithClosures :: Maybe ShapeRendererFunc_WithClosures
noShapeRendererFunc_WithClosures = Maybe ShapeRendererFunc_WithClosures
forall a. Maybe a
Nothing

-- | A simple wrapper that ignores the closure arguments.
drop_closures_ShapeRendererFunc :: ShapeRendererFunc -> ShapeRendererFunc_WithClosures
drop_closures_ShapeRendererFunc :: ShapeRendererFunc -> ShapeRendererFunc_WithClosures
drop_closures_ShapeRendererFunc ShapeRendererFunc
_f Context
cr AttrShape
attr Bool
doPath Ptr ()
_ = ShapeRendererFunc
_f Context
cr AttrShape
attr Bool
doPath

-- | Wrap the callback into a `GClosure`.
genClosure_ShapeRendererFunc :: MonadIO m => ShapeRendererFunc -> m (GClosure C_ShapeRendererFunc)
genClosure_ShapeRendererFunc :: forall (m :: * -> *).
MonadIO m =>
ShapeRendererFunc -> m (GClosure C_ShapeRendererFunc)
genClosure_ShapeRendererFunc ShapeRendererFunc
cb = IO (GClosure C_ShapeRendererFunc)
-> m (GClosure C_ShapeRendererFunc)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (GClosure C_ShapeRendererFunc)
 -> m (GClosure C_ShapeRendererFunc))
-> IO (GClosure C_ShapeRendererFunc)
-> m (GClosure C_ShapeRendererFunc)
forall a b. (a -> b) -> a -> b
$ do
    let cb' :: ShapeRendererFunc_WithClosures
cb' = ShapeRendererFunc -> ShapeRendererFunc_WithClosures
drop_closures_ShapeRendererFunc ShapeRendererFunc
cb
    let cb'' :: C_ShapeRendererFunc
cb'' = Maybe (Ptr (FunPtr C_ShapeRendererFunc))
-> ShapeRendererFunc_WithClosures -> C_ShapeRendererFunc
wrap_ShapeRendererFunc Maybe (Ptr (FunPtr C_ShapeRendererFunc))
forall a. Maybe a
Nothing ShapeRendererFunc_WithClosures
cb'
    C_ShapeRendererFunc -> IO (FunPtr C_ShapeRendererFunc)
mk_ShapeRendererFunc C_ShapeRendererFunc
cb'' IO (FunPtr C_ShapeRendererFunc)
-> (FunPtr C_ShapeRendererFunc
    -> IO (GClosure C_ShapeRendererFunc))
-> IO (GClosure C_ShapeRendererFunc)
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_ShapeRendererFunc -> IO (GClosure C_ShapeRendererFunc)
forall (m :: * -> *) a. MonadIO m => FunPtr a -> m (GClosure a)
B.GClosure.newGClosure


-- | Wrap a `ShapeRendererFunc` into a `C_ShapeRendererFunc`.
wrap_ShapeRendererFunc :: 
    Maybe (Ptr (FunPtr C_ShapeRendererFunc)) ->
    ShapeRendererFunc_WithClosures ->
    C_ShapeRendererFunc
wrap_ShapeRendererFunc :: Maybe (Ptr (FunPtr C_ShapeRendererFunc))
-> ShapeRendererFunc_WithClosures -> C_ShapeRendererFunc
wrap_ShapeRendererFunc Maybe (Ptr (FunPtr C_ShapeRendererFunc))
gi'funptrptr ShapeRendererFunc_WithClosures
gi'cb Ptr Context
cr Ptr AttrShape
attr CInt
doPath Ptr ()
data_ = do
    Ptr Context -> (Context -> IO ()) -> IO ()
forall a b.
(HasCallStack, ManagedPtrNewtype a) =>
Ptr a -> (a -> IO b) -> IO b
B.ManagedPtr.withTransient  Ptr Context
cr ((Context -> IO ()) -> IO ()) -> (Context -> IO ()) -> IO ()
forall a b. (a -> b) -> a -> b
$ \Context
cr' -> do
        AttrShape
attr' <- ((ManagedPtr AttrShape -> AttrShape)
-> Ptr AttrShape -> IO AttrShape
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
newPtr ManagedPtr AttrShape -> AttrShape
Pango.AttrShape.AttrShape) Ptr AttrShape
attr
        let doPath' :: Bool
doPath' = (CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/= CInt
0) CInt
doPath
        ShapeRendererFunc_WithClosures
gi'cb  Context
cr' AttrShape
attr' Bool
doPath' Ptr ()
data_
        Maybe (Ptr (FunPtr C_ShapeRendererFunc)) -> IO ()
forall a. Maybe (Ptr (FunPtr a)) -> IO ()
maybeReleaseFunPtr Maybe (Ptr (FunPtr C_ShapeRendererFunc))
gi'funptrptr