    {- |
    Copyright  : Will Thompson, Iñaki García Etxebarria and Jonas Platte
    License    : LGPL-2.1
    Maintainer : Iñaki García Etxebarria (garetxe@gmail.com)

    'GI.Gdk.Objects.DrawingContext.DrawingContext' is an object that represents the current drawing
    state of a 'GI.Gdk.Objects.Window.Window'.

    It\'s possible to use a 'GI.Gdk.Objects.DrawingContext.DrawingContext' to draw on a 'GI.Gdk.Objects.Window.Window'
    via rendering API like Cairo or OpenGL.

    A 'GI.Gdk.Objects.DrawingContext.DrawingContext' can only be created by calling 'GI.Gdk.Objects.Window.windowBeginDrawFrame'
    and will be valid until a call to 'GI.Gdk.Objects.Window.windowEndDrawFrame'.

    'GI.Gdk.Objects.DrawingContext.DrawingContext' is available since GDK 3.22
    -}

    #define ENABLE_OVERLOADING \
           (!defined(__HADDOCK_VERSION__))

    module GI.Gdk.Objects.DrawingContext
        (

    -- * Exported types
        DrawingContext(..)                      ,
        IsDrawingContext                        ,
        toDrawingContext                        ,
        noDrawingContext                        ,

     -- * Methods
    -- ** getCairoContext #method:getCairoContext#

    #if ENABLE_OVERLOADING
        DrawingContextGetCairoContextMethodInfo ,
    #endif
        drawingContextGetCairoContext           ,

    -- ** getClip #method:getClip#

    #if ENABLE_OVERLOADING
        DrawingContextGetClipMethodInfo         ,
    #endif
        drawingContextGetClip                   ,

    -- ** getWindow #method:getWindow#

    #if ENABLE_OVERLOADING
        DrawingContextGetWindowMethodInfo       ,
    #endif
        drawingContextGetWindow                 ,

    -- ** isValid #method:isValid#

    #if ENABLE_OVERLOADING
        DrawingContextIsValidMethodInfo         ,
    #endif
        drawingContextIsValid                   ,

     -- * Properties
    -- ** clip #attr:clip#
    {- | The clip region applied to the drawing context.

    /Since: 3.22/
    -}
    #if ENABLE_OVERLOADING
        DrawingContextClipPropertyInfo          ,
    #endif
        constructDrawingContextClip             ,
    #if ENABLE_OVERLOADING
        drawingContextClip                      ,
    #endif
        getDrawingContextClip                   ,

    -- ** window #attr:window#
    {- | The 'GI.Gdk.Objects.Window.Window' that created the drawing context.

    /Since: 3.22/
    -}
    #if ENABLE_OVERLOADING
        DrawingContextWindowPropertyInfo        ,
    #endif
        constructDrawingContextWindow           ,
    #if ENABLE_OVERLOADING
        drawingContextWindow                    ,
    #endif
        getDrawingContextWindow                 ,

        ) 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.ManagedPtr as B.ManagedPtr
    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.Text as T
    import qualified Data.ByteString.Char8 as B
    import qualified Data.Map as Map
    import qualified Foreign.Ptr as FP

    import qualified GI.Cairo.Structs.Context as Cairo.Context
    import qualified GI.Cairo.Structs.Region as Cairo.Region
    import qualified GI.GObject.Objects.Object as GObject.Object
    import {-# SOURCE #-} qualified GI.Gdk.Objects.Window as Gdk.Window

    -- | Memory-managed wrapper type.
    newtype DrawingContext = DrawingContext (ManagedPtr DrawingContext)
    foreign import ccall "gdk_drawing_context_get_type"
        c_gdk_drawing_context_get_type :: IO GType

    instance GObject DrawingContext where
        gobjectType _ = c_gdk_drawing_context_get_type

    -- | Type class for types which can be safely cast to `DrawingContext`, for instance with `toDrawingContext`.
    class GObject o => IsDrawingContext o
    #if MIN_VERSION_base(4,9,0)
    instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError DrawingContext a) =>
        IsDrawingContext a
    #endif
    instance IsDrawingContext DrawingContext
    instance GObject.Object.IsObject DrawingContext

    -- | Cast to `DrawingContext`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
    toDrawingContext :: (MonadIO m, IsDrawingContext o) => o -> m DrawingContext
    toDrawingContext = liftIO . unsafeCastTo DrawingContext

    -- | A convenience alias for `Nothing` :: `Maybe` `DrawingContext`.
    noDrawingContext :: Maybe DrawingContext
    noDrawingContext = Nothing

    #if ENABLE_OVERLOADING
    type family ResolveDrawingContextMethod (t :: Symbol) (o :: *) :: * where
        ResolveDrawingContextMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
        ResolveDrawingContextMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
        ResolveDrawingContextMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
        ResolveDrawingContextMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
        ResolveDrawingContextMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
        ResolveDrawingContextMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
        ResolveDrawingContextMethod "isValid" o = DrawingContextIsValidMethodInfo
        ResolveDrawingContextMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
        ResolveDrawingContextMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
        ResolveDrawingContextMethod "ref" o = GObject.Object.ObjectRefMethodInfo
        ResolveDrawingContextMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
        ResolveDrawingContextMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
        ResolveDrawingContextMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
        ResolveDrawingContextMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
        ResolveDrawingContextMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
        ResolveDrawingContextMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
        ResolveDrawingContextMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
        ResolveDrawingContextMethod "getCairoContext" o = DrawingContextGetCairoContextMethodInfo
        ResolveDrawingContextMethod "getClip" o = DrawingContextGetClipMethodInfo
        ResolveDrawingContextMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
        ResolveDrawingContextMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
        ResolveDrawingContextMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
        ResolveDrawingContextMethod "getWindow" o = DrawingContextGetWindowMethodInfo
        ResolveDrawingContextMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
        ResolveDrawingContextMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
        ResolveDrawingContextMethod l o = O.MethodResolutionFailed l o

    instance (info ~ ResolveDrawingContextMethod t DrawingContext, O.MethodInfo info DrawingContext p) => O.IsLabelProxy t (DrawingContext -> p) where
        fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

    #if MIN_VERSION_base(4,9,0)
    instance (info ~ ResolveDrawingContextMethod t DrawingContext, O.MethodInfo info DrawingContext p) => O.IsLabel t (DrawingContext -> p) where
    #if MIN_VERSION_base(4,10,0)
        fromLabel = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
    #else
        fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
    #endif
    #endif

    #endif

    -- VVV Prop "clip"
       -- Type: TInterface (Name {namespace = "cairo", name = "Region"})
       -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
       -- Nullable: (Nothing,Nothing)

    {- |
    Get the value of the “@clip@” property.
    When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

    @
    'Data.GI.Base.Attributes.get' drawingContext #clip
    @
    -}
    getDrawingContextClip :: (MonadIO m, IsDrawingContext o) => o -> m (Maybe Cairo.Region.Region)
    getDrawingContextClip obj = liftIO $ getObjectPropertyBoxed obj "clip" Cairo.Region.Region

    {- |
    Construct a `GValueConstruct` with valid value for the “@clip@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
    -}
    constructDrawingContextClip :: (IsDrawingContext o) => Cairo.Region.Region -> IO (GValueConstruct o)
    constructDrawingContextClip val = constructObjectPropertyBoxed "clip" (Just val)

    #if ENABLE_OVERLOADING
    data DrawingContextClipPropertyInfo
    instance AttrInfo DrawingContextClipPropertyInfo where
        type AttrAllowedOps DrawingContextClipPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint DrawingContextClipPropertyInfo = (~) Cairo.Region.Region
        type AttrBaseTypeConstraint DrawingContextClipPropertyInfo = IsDrawingContext
        type AttrGetType DrawingContextClipPropertyInfo = (Maybe Cairo.Region.Region)
        type AttrLabel DrawingContextClipPropertyInfo = "clip"
        type AttrOrigin DrawingContextClipPropertyInfo = DrawingContext
        attrGet _ = getDrawingContextClip
        attrSet _ = undefined
        attrConstruct _ = constructDrawingContextClip
        attrClear _ = undefined
    #endif

    -- VVV Prop "window"
       -- Type: TInterface (Name {namespace = "Gdk", name = "Window"})
       -- Flags: [PropertyReadable,PropertyWritable,PropertyConstructOnly]
       -- Nullable: (Just False,Nothing)

    {- |
    Get the value of the “@window@” property.
    When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

    @
    'Data.GI.Base.Attributes.get' drawingContext #window
    @
    -}
    getDrawingContextWindow :: (MonadIO m, IsDrawingContext o) => o -> m Gdk.Window.Window
    getDrawingContextWindow obj = liftIO $ checkUnexpectedNothing "getDrawingContextWindow" $ getObjectPropertyObject obj "window" Gdk.Window.Window

    {- |
    Construct a `GValueConstruct` with valid value for the “@window@” property. This is rarely needed directly, but it is used by `Data.GI.Base.Constructible.new`.
    -}
    constructDrawingContextWindow :: (IsDrawingContext o, Gdk.Window.IsWindow a) => a -> IO (GValueConstruct o)
    constructDrawingContextWindow val = constructObjectPropertyObject "window" (Just val)

    #if ENABLE_OVERLOADING
    data DrawingContextWindowPropertyInfo
    instance AttrInfo DrawingContextWindowPropertyInfo where
        type AttrAllowedOps DrawingContextWindowPropertyInfo = '[ 'AttrConstruct, 'AttrGet, 'AttrClear]
        type AttrSetTypeConstraint DrawingContextWindowPropertyInfo = Gdk.Window.IsWindow
        type AttrBaseTypeConstraint DrawingContextWindowPropertyInfo = IsDrawingContext
        type AttrGetType DrawingContextWindowPropertyInfo = Gdk.Window.Window
        type AttrLabel DrawingContextWindowPropertyInfo = "window"
        type AttrOrigin DrawingContextWindowPropertyInfo = DrawingContext
        attrGet _ = getDrawingContextWindow
        attrSet _ = undefined
        attrConstruct _ = constructDrawingContextWindow
        attrClear _ = undefined
    #endif

    #if ENABLE_OVERLOADING
    instance O.HasAttributeList DrawingContext
    type instance O.AttributeList DrawingContext = DrawingContextAttributeList
    type DrawingContextAttributeList = ('[ '("clip", DrawingContextClipPropertyInfo), '("window", DrawingContextWindowPropertyInfo)] :: [(Symbol, *)])
    #endif

    #if ENABLE_OVERLOADING
    drawingContextClip :: AttrLabelProxy "clip"
    drawingContextClip = AttrLabelProxy

    drawingContextWindow :: AttrLabelProxy "window"
    drawingContextWindow = AttrLabelProxy

    #endif

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

    #endif

    -- method DrawingContext::get_cairo_context
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gdk", name = "DrawingContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Nothing, 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_drawing_context_get_cairo_context" gdk_drawing_context_get_cairo_context ::
        Ptr DrawingContext ->                   -- context : TInterface (Name {namespace = "Gdk", name = "DrawingContext"})
        IO (Ptr Cairo.Context.Context)

    {- |
    Retrieves a Cairo context to be used to draw on the 'GI.Gdk.Objects.Window.Window'
    that created the 'GI.Gdk.Objects.DrawingContext.DrawingContext'.

    The returned context is guaranteed to be valid as long as the
    'GI.Gdk.Objects.DrawingContext.DrawingContext' is valid, that is between a call to
    'GI.Gdk.Objects.Window.windowBeginDrawFrame' and 'GI.Gdk.Objects.Window.windowEndDrawFrame'.

    /Since: 3.22/
    -}
    drawingContextGetCairoContext ::
        (B.CallStack.HasCallStack, MonadIO m, IsDrawingContext a) =>
        a
        -> m Cairo.Context.Context
        {- ^ __Returns:__ a Cairo context to be used to draw
      the contents of the 'GI.Gdk.Objects.Window.Window'. The context is owned by the
      'GI.Gdk.Objects.DrawingContext.DrawingContext' and should not be destroyed -}
    drawingContextGetCairoContext context = liftIO $ do
        context' <- unsafeManagedPtrCastPtr context
        result <- gdk_drawing_context_get_cairo_context context'
        checkUnexpectedReturnNULL "drawingContextGetCairoContext" result
        result' <- (newBoxed Cairo.Context.Context) result
        touchManagedPtr context
        return result'

    #if ENABLE_OVERLOADING
    data DrawingContextGetCairoContextMethodInfo
    instance (signature ~ (m Cairo.Context.Context), MonadIO m, IsDrawingContext a) => O.MethodInfo DrawingContextGetCairoContextMethodInfo a signature where
        overloadedMethod _ = drawingContextGetCairoContext

    #endif

    -- method DrawingContext::get_clip
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gdk", name = "DrawingContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkDrawingContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "cairo", name = "Region"}))
    -- throws : False
    -- Skip return : False

    foreign import ccall "gdk_drawing_context_get_clip" gdk_drawing_context_get_clip ::
        Ptr DrawingContext ->                   -- context : TInterface (Name {namespace = "Gdk", name = "DrawingContext"})
        IO (Ptr Cairo.Region.Region)

    {- |
    Retrieves a copy of the clip region used when creating the /@context@/.

    /Since: 3.22/
    -}
    drawingContextGetClip ::
        (B.CallStack.HasCallStack, MonadIO m, IsDrawingContext a) =>
        a
        {- ^ /@context@/: a 'GI.Gdk.Objects.DrawingContext.DrawingContext' -}
        -> m (Maybe Cairo.Region.Region)
        {- ^ __Returns:__ a Cairo region -}
    drawingContextGetClip context = liftIO $ do
        context' <- unsafeManagedPtrCastPtr context
        result <- gdk_drawing_context_get_clip context'
        maybeResult <- convertIfNonNull result $ \result' -> do
            result'' <- (wrapBoxed Cairo.Region.Region) result'
            return result''
        touchManagedPtr context
        return maybeResult

    #if ENABLE_OVERLOADING
    data DrawingContextGetClipMethodInfo
    instance (signature ~ (m (Maybe Cairo.Region.Region)), MonadIO m, IsDrawingContext a) => O.MethodInfo DrawingContextGetClipMethodInfo a signature where
        overloadedMethod _ = drawingContextGetClip

    #endif

    -- method DrawingContext::get_window
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gdk", name = "DrawingContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkDrawingContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TInterface (Name {namespace = "Gdk", name = "Window"}))
    -- throws : False
    -- Skip return : False

    foreign import ccall "gdk_drawing_context_get_window" gdk_drawing_context_get_window ::
        Ptr DrawingContext ->                   -- context : TInterface (Name {namespace = "Gdk", name = "DrawingContext"})
        IO (Ptr Gdk.Window.Window)

    {- |
    Retrieves the window that created the drawing /@context@/.

    /Since: 3.22/
    -}
    drawingContextGetWindow ::
        (B.CallStack.HasCallStack, MonadIO m, IsDrawingContext a) =>
        a
        {- ^ /@context@/: a 'GI.Gdk.Objects.DrawingContext.DrawingContext' -}
        -> m Gdk.Window.Window
        {- ^ __Returns:__ a 'GI.Gdk.Objects.Window.Window' -}
    drawingContextGetWindow context = liftIO $ do
        context' <- unsafeManagedPtrCastPtr context
        result <- gdk_drawing_context_get_window context'
        checkUnexpectedReturnNULL "drawingContextGetWindow" result
        result' <- (newObject Gdk.Window.Window) result
        touchManagedPtr context
        return result'

    #if ENABLE_OVERLOADING
    data DrawingContextGetWindowMethodInfo
    instance (signature ~ (m Gdk.Window.Window), MonadIO m, IsDrawingContext a) => O.MethodInfo DrawingContextGetWindowMethodInfo a signature where
        overloadedMethod _ = drawingContextGetWindow

    #endif

    -- method DrawingContext::is_valid
    -- method type : OrdinaryMethod
    -- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gdk", name = "DrawingContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GdkDrawingContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
    -- Lengths : []
    -- returnType : Just (TBasicType TBoolean)
    -- throws : False
    -- Skip return : False

    foreign import ccall "gdk_drawing_context_is_valid" gdk_drawing_context_is_valid ::
        Ptr DrawingContext ->                   -- context : TInterface (Name {namespace = "Gdk", name = "DrawingContext"})
        IO CInt

    {- |
    Checks whether the given 'GI.Gdk.Objects.DrawingContext.DrawingContext' is valid.

    /Since: 3.22/
    -}
    drawingContextIsValid ::
        (B.CallStack.HasCallStack, MonadIO m, IsDrawingContext a) =>
        a
        {- ^ /@context@/: a 'GI.Gdk.Objects.DrawingContext.DrawingContext' -}
        -> m Bool
        {- ^ __Returns:__ 'True' if the context is valid -}
    drawingContextIsValid context = liftIO $ do
        context' <- unsafeManagedPtrCastPtr context
        result <- gdk_drawing_context_is_valid context'
        let result' = (/= 0) result
        touchManagedPtr context
        return result'

    #if ENABLE_OVERLOADING
    data DrawingContextIsValidMethodInfo
    instance (signature ~ (m Bool), MonadIO m, IsDrawingContext a) => O.MethodInfo DrawingContextIsValidMethodInfo a signature where
        overloadedMethod _ = drawingContextIsValid

    #endif