{- |
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
-}

module GI.Gdk.Objects.DrawingContext
    ( 

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


 -- * Methods
-- ** getCairoContext #method:getCairoContext#
    DrawingContextGetCairoContextMethodInfo ,
    drawingContextGetCairoContext           ,


-- ** getClip #method:getClip#
    DrawingContextGetClipMethodInfo         ,
    drawingContextGetClip                   ,


-- ** getWindow #method:getWindow#
    DrawingContextGetWindowMethodInfo       ,
    drawingContextGetWindow                 ,


-- ** isValid #method:isValid#
    DrawingContextIsValidMethodInfo         ,
    drawingContextIsValid                   ,




 -- * Properties
-- ** clip #attr:clip#
    DrawingContextClipPropertyInfo          ,
    constructDrawingContextClip             ,
    drawingContextClip                      ,
    getDrawingContextClip                   ,


-- ** window #attr:window#
    DrawingContextWindowPropertyInfo        ,
    constructDrawingContextWindow           ,
    drawingContextWindow                    ,
    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.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

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
    

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

toDrawingContext :: IsDrawingContext o => o -> IO DrawingContext
toDrawingContext = unsafeCastTo DrawingContext

noDrawingContext :: Maybe DrawingContext
noDrawingContext = Nothing

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 "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 "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveDrawingContextMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    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
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

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

getDrawingContextClip :: (MonadIO m, IsDrawingContext o) => o -> m (Maybe Cairo.Region.Region)
getDrawingContextClip obj = liftIO $ getObjectPropertyBoxed obj "clip" Cairo.Region.Region

constructDrawingContextClip :: (IsDrawingContext o) => Cairo.Region.Region -> IO (GValueConstruct o)
constructDrawingContextClip val = constructObjectPropertyBoxed "clip" (Just val)

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

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

getDrawingContextWindow :: (MonadIO m, IsDrawingContext o) => o -> m Gdk.Window.Window
getDrawingContextWindow obj = liftIO $ checkUnexpectedNothing "getDrawingContextWindow" $ getObjectPropertyObject obj "window" Gdk.Window.Window

constructDrawingContextWindow :: (IsDrawingContext o, Gdk.Window.IsWindow a) => a -> IO (GValueConstruct o)
constructDrawingContextWindow val = constructObjectPropertyObject "window" (Just val)

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

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

drawingContextClip :: AttrLabelProxy "clip"
drawingContextClip = AttrLabelProxy

drawingContextWindow :: AttrLabelProxy "window"
drawingContextWindow = AttrLabelProxy

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

-- 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'

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

-- 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

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

-- 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'

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

-- 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'

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