{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- @GdkCairoContext@ is an object representing the platform-specific
-- draw context.
-- 
-- @GdkCairoContext@s are created for a surface using
-- 'GI.Gdk.Objects.Surface.surfaceCreateCairoContext', and the context
-- can then be used to draw on that surface.

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

module GI.Gdk.Objects.CairoContext
    ( 

-- * Exported types
    CairoContext(..)                        ,
    IsCairoContext                          ,
    toCairoContext                          ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [beginFrame]("GI.Gdk.Objects.DrawContext#g:method:beginFrame"), [bindProperty]("GI.GObject.Objects.Object#g:method:bindProperty"), [bindPropertyFull]("GI.GObject.Objects.Object#g:method:bindPropertyFull"), [cairoCreate]("GI.Gdk.Objects.CairoContext#g:method:cairoCreate"), [endFrame]("GI.Gdk.Objects.DrawContext#g:method:endFrame"), [forceFloating]("GI.GObject.Objects.Object#g:method:forceFloating"), [freezeNotify]("GI.GObject.Objects.Object#g:method:freezeNotify"), [getv]("GI.GObject.Objects.Object#g:method:getv"), [isFloating]("GI.GObject.Objects.Object#g:method:isFloating"), [isInFrame]("GI.Gdk.Objects.DrawContext#g:method:isInFrame"), [notify]("GI.GObject.Objects.Object#g:method:notify"), [notifyByPspec]("GI.GObject.Objects.Object#g:method:notifyByPspec"), [ref]("GI.GObject.Objects.Object#g:method:ref"), [refSink]("GI.GObject.Objects.Object#g:method:refSink"), [runDispose]("GI.GObject.Objects.Object#g:method:runDispose"), [stealData]("GI.GObject.Objects.Object#g:method:stealData"), [stealQdata]("GI.GObject.Objects.Object#g:method:stealQdata"), [thawNotify]("GI.GObject.Objects.Object#g:method:thawNotify"), [unref]("GI.GObject.Objects.Object#g:method:unref"), [watchClosure]("GI.GObject.Objects.Object#g:method:watchClosure").
-- 
-- ==== Getters
-- [getData]("GI.GObject.Objects.Object#g:method:getData"), [getDisplay]("GI.Gdk.Objects.DrawContext#g:method:getDisplay"), [getFrameRegion]("GI.Gdk.Objects.DrawContext#g:method:getFrameRegion"), [getProperty]("GI.GObject.Objects.Object#g:method:getProperty"), [getQdata]("GI.GObject.Objects.Object#g:method:getQdata"), [getSurface]("GI.Gdk.Objects.DrawContext#g:method:getSurface").
-- 
-- ==== Setters
-- [setData]("GI.GObject.Objects.Object#g:method:setData"), [setDataFull]("GI.GObject.Objects.Object#g:method:setDataFull"), [setProperty]("GI.GObject.Objects.Object#g:method:setProperty").

#if defined(ENABLE_OVERLOADING)
    ResolveCairoContextMethod               ,
#endif

-- ** cairoCreate #method:cairoCreate#

#if defined(ENABLE_OVERLOADING)
    CairoContextCairoCreateMethodInfo       ,
#endif
    cairoContextCairoCreate                 ,




    ) 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.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.GObject.Objects.Object as GObject.Object
import {-# SOURCE #-} qualified GI.Gdk.Objects.DrawContext as Gdk.DrawContext

-- | Memory-managed wrapper type.
newtype CairoContext = CairoContext (SP.ManagedPtr CairoContext)
    deriving (CairoContext -> CairoContext -> Bool
(CairoContext -> CairoContext -> Bool)
-> (CairoContext -> CairoContext -> Bool) -> Eq CairoContext
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CairoContext -> CairoContext -> Bool
$c/= :: CairoContext -> CairoContext -> Bool
== :: CairoContext -> CairoContext -> Bool
$c== :: CairoContext -> CairoContext -> Bool
Eq)

instance SP.ManagedPtrNewtype CairoContext where
    toManagedPtr :: CairoContext -> ManagedPtr CairoContext
toManagedPtr (CairoContext ManagedPtr CairoContext
p) = ManagedPtr CairoContext
p

foreign import ccall "gdk_cairo_context_get_type"
    c_gdk_cairo_context_get_type :: IO B.Types.GType

instance B.Types.TypedObject CairoContext where
    glibType :: IO GType
glibType = IO GType
c_gdk_cairo_context_get_type

instance B.Types.GObject CairoContext

-- | Type class for types which can be safely cast to `CairoContext`, for instance with `toCairoContext`.
class (SP.GObject o, O.IsDescendantOf CairoContext o) => IsCairoContext o
instance (SP.GObject o, O.IsDescendantOf CairoContext o) => IsCairoContext o

instance O.HasParentTypes CairoContext
type instance O.ParentTypes CairoContext = '[Gdk.DrawContext.DrawContext, GObject.Object.Object]

-- | Cast to `CairoContext`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toCairoContext :: (MIO.MonadIO m, IsCairoContext o) => o -> m CairoContext
toCairoContext :: forall (m :: * -> *) o.
(MonadIO m, IsCairoContext o) =>
o -> m CairoContext
toCairoContext = IO CairoContext -> m CairoContext
forall (m :: * -> *) a. MonadIO m => IO a -> m a
MIO.liftIO (IO CairoContext -> m CairoContext)
-> (o -> IO CairoContext) -> o -> m CairoContext
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ManagedPtr CairoContext -> CairoContext) -> o -> IO CairoContext
forall o o'.
(HasCallStack, ManagedPtrNewtype o, TypedObject o,
 ManagedPtrNewtype o', TypedObject o') =>
(ManagedPtr o' -> o') -> o -> IO o'
B.ManagedPtr.unsafeCastTo ManagedPtr CairoContext -> CairoContext
CairoContext

-- | Convert 'CairoContext' to and from 'Data.GI.Base.GValue.GValue'. See 'Data.GI.Base.GValue.toGValue' and 'Data.GI.Base.GValue.fromGValue'.
instance B.GValue.IsGValue (Maybe CairoContext) where
    gvalueGType_ :: IO GType
gvalueGType_ = IO GType
c_gdk_cairo_context_get_type
    gvalueSet_ :: Ptr GValue -> Maybe CairoContext -> IO ()
gvalueSet_ Ptr GValue
gv Maybe CairoContext
P.Nothing = Ptr GValue -> Ptr CairoContext -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv (Ptr CairoContext
forall a. Ptr a
FP.nullPtr :: FP.Ptr CairoContext)
    gvalueSet_ Ptr GValue
gv (P.Just CairoContext
obj) = CairoContext -> (Ptr CairoContext -> IO ()) -> IO ()
forall a c.
(HasCallStack, ManagedPtrNewtype a) =>
a -> (Ptr a -> IO c) -> IO c
B.ManagedPtr.withManagedPtr CairoContext
obj (Ptr GValue -> Ptr CairoContext -> IO ()
forall a. GObject a => Ptr GValue -> Ptr a -> IO ()
B.GValue.set_object Ptr GValue
gv)
    gvalueGet_ :: Ptr GValue -> IO (Maybe CairoContext)
gvalueGet_ Ptr GValue
gv = do
        Ptr CairoContext
ptr <- Ptr GValue -> IO (Ptr CairoContext)
forall a. GObject a => Ptr GValue -> IO (Ptr a)
B.GValue.get_object Ptr GValue
gv :: IO (FP.Ptr CairoContext)
        if Ptr CairoContext
ptr Ptr CairoContext -> Ptr CairoContext -> Bool
forall a. Eq a => a -> a -> Bool
/= Ptr CairoContext
forall a. Ptr a
FP.nullPtr
        then CairoContext -> Maybe CairoContext
forall a. a -> Maybe a
P.Just (CairoContext -> Maybe CairoContext)
-> IO CairoContext -> IO (Maybe CairoContext)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (ManagedPtr CairoContext -> CairoContext)
-> Ptr CairoContext -> IO CairoContext
forall a b.
(HasCallStack, GObject a, GObject b) =>
(ManagedPtr a -> a) -> Ptr b -> IO a
B.ManagedPtr.newObject ManagedPtr CairoContext -> CairoContext
CairoContext Ptr CairoContext
ptr
        else Maybe CairoContext -> IO (Maybe CairoContext)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe CairoContext
forall a. Maybe a
P.Nothing
        
    

#if defined(ENABLE_OVERLOADING)
type family ResolveCairoContextMethod (t :: Symbol) (o :: *) :: * where
    ResolveCairoContextMethod "beginFrame" o = Gdk.DrawContext.DrawContextBeginFrameMethodInfo
    ResolveCairoContextMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveCairoContextMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveCairoContextMethod "cairoCreate" o = CairoContextCairoCreateMethodInfo
    ResolveCairoContextMethod "endFrame" o = Gdk.DrawContext.DrawContextEndFrameMethodInfo
    ResolveCairoContextMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveCairoContextMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveCairoContextMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveCairoContextMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveCairoContextMethod "isInFrame" o = Gdk.DrawContext.DrawContextIsInFrameMethodInfo
    ResolveCairoContextMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveCairoContextMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveCairoContextMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveCairoContextMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveCairoContextMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveCairoContextMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveCairoContextMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveCairoContextMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveCairoContextMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveCairoContextMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveCairoContextMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveCairoContextMethod "getDisplay" o = Gdk.DrawContext.DrawContextGetDisplayMethodInfo
    ResolveCairoContextMethod "getFrameRegion" o = Gdk.DrawContext.DrawContextGetFrameRegionMethodInfo
    ResolveCairoContextMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveCairoContextMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveCairoContextMethod "getSurface" o = Gdk.DrawContext.DrawContextGetSurfaceMethodInfo
    ResolveCairoContextMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveCairoContextMethod "setDataFull" o = GObject.Object.ObjectSetDataFullMethodInfo
    ResolveCairoContextMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveCairoContextMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCairoContextMethod t CairoContext, O.OverloadedMethod info CairoContext p) => OL.IsLabel t (CairoContext -> p) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.overloadedMethod @info
#else
    fromLabel _ = O.overloadedMethod @info
#endif

#if MIN_VERSION_base(4,13,0)
instance (info ~ ResolveCairoContextMethod t CairoContext, O.OverloadedMethod info CairoContext p, R.HasField t CairoContext p) => R.HasField t CairoContext p where
    getField = O.overloadedMethod @info

#endif

instance (info ~ ResolveCairoContextMethod t CairoContext, O.OverloadedMethodInfo info CairoContext) => OL.IsLabel t (O.MethodProxy info CairoContext) where
#if MIN_VERSION_base(4,10,0)
    fromLabel = O.MethodProxy
#else
    fromLabel _ = O.MethodProxy
#endif

#endif

#if defined(ENABLE_OVERLOADING)
instance O.HasAttributeList CairoContext
type instance O.AttributeList CairoContext = CairoContextAttributeList
type CairoContextAttributeList = ('[ '("display", Gdk.DrawContext.DrawContextDisplayPropertyInfo), '("surface", Gdk.DrawContext.DrawContextSurfacePropertyInfo)] :: [(Symbol, *)])
#endif

#if defined(ENABLE_OVERLOADING)
#endif

#if defined(ENABLE_OVERLOADING)
type instance O.SignalList CairoContext = CairoContextSignalList
type CairoContextSignalList = ('[ '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method CairoContext::cairo_create
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "self"
--           , argType =
--               TInterface Name { namespace = "Gdk" , name = "CairoContext" }
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a `GdkCairoContext` that is currently drawing"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "cairo" , name = "Context" })
-- throws : False
-- Skip return : False

foreign import ccall "gdk_cairo_context_cairo_create" gdk_cairo_context_cairo_create :: 
    Ptr CairoContext ->                     -- self : TInterface (Name {namespace = "Gdk", name = "CairoContext"})
    IO (Ptr Cairo.Context.Context)

-- | Retrieves a Cairo context to be used to draw on the @GdkSurface@
-- of /@context@/.
-- 
-- A call to 'GI.Gdk.Objects.DrawContext.drawContextBeginFrame' with this
-- /@context@/ must have been done or this function will return 'P.Nothing'.
-- 
-- The returned context is guaranteed to be valid until
-- 'GI.Gdk.Objects.DrawContext.drawContextEndFrame' is called.
cairoContextCairoCreate ::
    (B.CallStack.HasCallStack, MonadIO m, IsCairoContext a) =>
    a
    -- ^ /@self@/: a @GdkCairoContext@ that is currently drawing
    -> m (Maybe Cairo.Context.Context)
    -- ^ __Returns:__ a Cairo context
    --   to draw on \`GdkSurface
cairoContextCairoCreate :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsCairoContext a) =>
a -> m (Maybe Context)
cairoContextCairoCreate a
self = IO (Maybe Context) -> m (Maybe Context)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Context) -> m (Maybe Context))
-> IO (Maybe Context) -> m (Maybe Context)
forall a b. (a -> b) -> a -> b
$ do
    Ptr CairoContext
self' <- a -> IO (Ptr CairoContext)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
self
    Ptr Context
result <- Ptr CairoContext -> IO (Ptr Context)
gdk_cairo_context_cairo_create Ptr CairoContext
self'
    Maybe Context
maybeResult <- Ptr Context -> (Ptr Context -> IO Context) -> IO (Maybe Context)
forall a b. Ptr a -> (Ptr a -> IO b) -> IO (Maybe b)
convertIfNonNull Ptr Context
result ((Ptr Context -> IO Context) -> IO (Maybe Context))
-> (Ptr Context -> IO Context) -> IO (Maybe Context)
forall a b. (a -> b) -> a -> b
$ \Ptr Context
result' -> do
        Context
result'' <- ((ManagedPtr Context -> Context) -> Ptr Context -> IO Context
forall a.
(HasCallStack, GBoxed a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapBoxed ManagedPtr Context -> Context
Cairo.Context.Context) Ptr Context
result'
        Context -> IO Context
forall (m :: * -> *) a. Monad m => a -> m a
return Context
result''
    a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr a
self
    Maybe Context -> IO (Maybe Context)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Context
maybeResult

#if defined(ENABLE_OVERLOADING)
data CairoContextCairoCreateMethodInfo
instance (signature ~ (m (Maybe Cairo.Context.Context)), MonadIO m, IsCairoContext a) => O.OverloadedMethod CairoContextCairoCreateMethodInfo a signature where
    overloadedMethod = cairoContextCairoCreate

instance O.OverloadedMethodInfo CairoContextCairoCreateMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gdk.Objects.CairoContext.cairoContextCairoCreate",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gdk-4.0.4/docs/GI-Gdk-Objects-CairoContext.html#v:cairoContextCairoCreate"
        })


#endif