{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- A render node that uses Porter\/Duff compositing operators to combine
-- its child with the background.
-- 
-- /Since: 4.22/

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

module GI.Gsk.Objects.CompositeNode
    ( 

-- * Exported types
    CompositeNode(..)                       ,
    IsCompositeNode                         ,
    toCompositeNode                         ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [draw]("GI.Gsk.Objects.RenderNode#g:method:draw"), [ref]("GI.Gsk.Objects.RenderNode#g:method:ref"), [serialize]("GI.Gsk.Objects.RenderNode#g:method:serialize"), [unref]("GI.Gsk.Objects.RenderNode#g:method:unref"), [writeToFile]("GI.Gsk.Objects.RenderNode#g:method:writeToFile").
-- 
-- ==== Getters
-- [getBounds]("GI.Gsk.Objects.RenderNode#g:method:getBounds"), [getChild]("GI.Gsk.Objects.CompositeNode#g:method:getChild"), [getChildren]("GI.Gsk.Objects.RenderNode#g:method:getChildren"), [getMask]("GI.Gsk.Objects.CompositeNode#g:method:getMask"), [getNodeType]("GI.Gsk.Objects.RenderNode#g:method:getNodeType"), [getOpaqueRect]("GI.Gsk.Objects.RenderNode#g:method:getOpaqueRect"), [getOperator]("GI.Gsk.Objects.CompositeNode#g:method:getOperator").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveCompositeNodeMethod              ,
#endif

-- ** getChild #method:getChild#

#if defined(ENABLE_OVERLOADING)
    CompositeNodeGetChildMethodInfo         ,
#endif
    compositeNodeGetChild                   ,


-- ** getMask #method:getMask#

#if defined(ENABLE_OVERLOADING)
    CompositeNodeGetMaskMethodInfo          ,
#endif
    compositeNodeGetMask                    ,


-- ** getOperator #method:getOperator#

#if defined(ENABLE_OVERLOADING)
    CompositeNodeGetOperatorMethodInfo      ,
#endif
    compositeNodeGetOperator                ,


-- ** new #method:new#

    compositeNodeNew                        ,




    ) 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.Kind as DK
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 Data.Word as DW
import qualified Data.Int as DI
import qualified System.Posix.Types as SPT
import qualified Foreign.C.Types as FCT

-- Workaround for https://gitlab.haskell.org/ghc/ghc/-/issues/23392
#if MIN_VERSION_base(4,18,0)
import qualified GI.Cairo.Structs.Context as Cairo.Context
import qualified GI.GLib.Structs.Bytes as GLib.Bytes
import qualified GI.Graphene.Structs.Rect as Graphene.Rect
import qualified GI.Gsk.Callbacks as Gsk.Callbacks
import {-# SOURCE #-} qualified GI.Gsk.Enums as Gsk.Enums
import {-# SOURCE #-} qualified GI.Gsk.Objects.RenderNode as Gsk.RenderNode

#else
import {-# SOURCE #-} qualified GI.Gsk.Enums as Gsk.Enums
import {-# SOURCE #-} qualified GI.Gsk.Objects.RenderNode as Gsk.RenderNode

#endif

-- | Memory-managed wrapper type.
newtype CompositeNode = CompositeNode (SP.ManagedPtr CompositeNode)
    deriving (Eq)

instance SP.ManagedPtrNewtype CompositeNode where
    toManagedPtr (CompositeNode p) = p

foreign import ccall "gsk_composite_node_get_type"
    c_gsk_composite_node_get_type :: IO B.Types.GType

instance B.Types.TypedObject CompositeNode where
    glibType = c_gsk_composite_node_get_type

-- | Type class for types which can be safely cast to t'CompositeNode', for instance with `toCompositeNode`.
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf CompositeNode o) => IsCompositeNode o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf CompositeNode o) => IsCompositeNode o

instance O.HasParentTypes CompositeNode
type instance O.ParentTypes CompositeNode = '[Gsk.RenderNode.RenderNode]

-- | Cast to t'CompositeNode', for types for which this is known to be safe. For general casts, use 'Data.GI.Base.ManagedPtr.castTo'.
toCompositeNode :: (MIO.MonadIO m, IsCompositeNode o) => o -> m CompositeNode
toCompositeNode = MIO.liftIO . B.ManagedPtr.unsafeCastTo CompositeNode

--- XXX Missing getter and/or setter, so no GValue instance could be generated.
#if defined(ENABLE_OVERLOADING)
type family ResolveCompositeNodeMethod (t :: Symbol) (o :: DK.Type) :: DK.Type where
    ResolveCompositeNodeMethod "draw" o = Gsk.RenderNode.RenderNodeDrawMethodInfo
    ResolveCompositeNodeMethod "ref" o = Gsk.RenderNode.RenderNodeRefMethodInfo
    ResolveCompositeNodeMethod "serialize" o = Gsk.RenderNode.RenderNodeSerializeMethodInfo
    ResolveCompositeNodeMethod "unref" o = Gsk.RenderNode.RenderNodeUnrefMethodInfo
    ResolveCompositeNodeMethod "writeToFile" o = Gsk.RenderNode.RenderNodeWriteToFileMethodInfo
    ResolveCompositeNodeMethod "getBounds" o = Gsk.RenderNode.RenderNodeGetBoundsMethodInfo
    ResolveCompositeNodeMethod "getChild" o = CompositeNodeGetChildMethodInfo
    ResolveCompositeNodeMethod "getChildren" o = Gsk.RenderNode.RenderNodeGetChildrenMethodInfo
    ResolveCompositeNodeMethod "getMask" o = CompositeNodeGetMaskMethodInfo
    ResolveCompositeNodeMethod "getNodeType" o = Gsk.RenderNode.RenderNodeGetNodeTypeMethodInfo
    ResolveCompositeNodeMethod "getOpaqueRect" o = Gsk.RenderNode.RenderNodeGetOpaqueRectMethodInfo
    ResolveCompositeNodeMethod "getOperator" o = CompositeNodeGetOperatorMethodInfo
    ResolveCompositeNodeMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveCompositeNodeMethod t CompositeNode, O.OverloadedMethod info CompositeNode p) => OL.IsLabel t (CompositeNode -> 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 ~ ResolveCompositeNodeMethod t CompositeNode, O.OverloadedMethod info CompositeNode p, R.HasField t CompositeNode p) => R.HasField t CompositeNode p where
    getField = O.overloadedMethod @info

#endif

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

#endif

-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance BoxedPtr CompositeNode where
    boxedPtrCopy = return
    boxedPtrFree = \_x -> return ()


-- method CompositeNode::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "child"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "RenderNode" }
--           , argCType = Just "GskRenderNode*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The child to composite"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "mask"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "RenderNode" }
--           , argCType = Just "GskRenderNode*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The mask where the compositing will apply"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "op"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "PorterDuff" }
--           , argCType = Just "GskPorterDuff"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "The compositing operator"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gsk" , name = "CompositeNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_composite_node_new" gsk_composite_node_new :: 
    Ptr Gsk.RenderNode.RenderNode ->        -- child : TInterface (Name {namespace = "Gsk", name = "RenderNode"})
    Ptr Gsk.RenderNode.RenderNode ->        -- mask : TInterface (Name {namespace = "Gsk", name = "RenderNode"})
    CUInt ->                                -- op : TInterface (Name {namespace = "Gsk", name = "PorterDuff"})
    IO (Ptr CompositeNode)

-- | Creates a @GskRenderNode@ that will composite the child onto the
-- background with the given operator wherever the mask is set.
-- 
-- Note that various operations can modify the background outside of
-- the child\'s bounds, so the mask may cause visual changes outside
-- of the child.
-- 
-- /Since: 4.22/
compositeNodeNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gsk.RenderNode.IsRenderNode a, Gsk.RenderNode.IsRenderNode b) =>
    a
    -- ^ /@child@/: The child to composite
    -> b
    -- ^ /@mask@/: The mask where the compositing will apply
    -> Gsk.Enums.PorterDuff
    -- ^ /@op@/: The compositing operator
    -> m CompositeNode
    -- ^ __Returns:__ A new @GskRenderNode@
compositeNodeNew child mask op = liftIO $ do
    child' <- unsafeManagedPtrCastPtr child
    mask' <- unsafeManagedPtrCastPtr mask
    let op' = (fromIntegral . fromEnum) op
    result <- gsk_composite_node_new child' mask' op'
    checkUnexpectedReturnNULL "compositeNodeNew" result
    result' <- (wrapPtr CompositeNode) result
    touchManagedPtr child
    touchManagedPtr mask
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method CompositeNode::get_child
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "CompositeNode" }
--           , argCType = Just "const GskRenderNode*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a composite `GskRenderNode`"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gsk" , name = "RenderNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_composite_node_get_child" gsk_composite_node_get_child :: 
    Ptr CompositeNode ->                    -- node : TInterface (Name {namespace = "Gsk", name = "CompositeNode"})
    IO (Ptr Gsk.RenderNode.RenderNode)

-- | Gets the child node that is getting composited by the given /@node@/.
-- 
-- /Since: 4.22/
compositeNodeGetChild ::
    (B.CallStack.HasCallStack, MonadIO m, IsCompositeNode a) =>
    a
    -- ^ /@node@/: a composite @GskRenderNode@
    -> m Gsk.RenderNode.RenderNode
    -- ^ __Returns:__ the child @GskRenderNode@
compositeNodeGetChild node = liftIO $ do
    node' <- unsafeManagedPtrCastPtr node
    result <- gsk_composite_node_get_child node'
    checkUnexpectedReturnNULL "compositeNodeGetChild" result
    result' <- (newPtr Gsk.RenderNode.RenderNode) result
    touchManagedPtr node
    return result'

#if defined(ENABLE_OVERLOADING)
data CompositeNodeGetChildMethodInfo
instance (signature ~ (m Gsk.RenderNode.RenderNode), MonadIO m, IsCompositeNode a) => O.OverloadedMethod CompositeNodeGetChildMethodInfo a signature where
    overloadedMethod = compositeNodeGetChild

instance O.OverloadedMethodInfo CompositeNodeGetChildMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gsk.Objects.CompositeNode.compositeNodeGetChild",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gsk-4.0.8/docs/GI-Gsk-Objects-CompositeNode.html#v:compositeNodeGetChild"
        })


#endif

-- method CompositeNode::get_mask
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "CompositeNode" }
--           , argCType = Just "const GskRenderNode*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a composite `GskRenderNode`"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gsk" , name = "RenderNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_composite_node_get_mask" gsk_composite_node_get_mask :: 
    Ptr CompositeNode ->                    -- node : TInterface (Name {namespace = "Gsk", name = "CompositeNode"})
    IO (Ptr Gsk.RenderNode.RenderNode)

-- | Gets the mask node that describes the region where the compositing
-- applies.
-- 
-- /Since: 4.22/
compositeNodeGetMask ::
    (B.CallStack.HasCallStack, MonadIO m, IsCompositeNode a) =>
    a
    -- ^ /@node@/: a composite @GskRenderNode@
    -> m Gsk.RenderNode.RenderNode
    -- ^ __Returns:__ the mask @GskRenderNode@
compositeNodeGetMask node = liftIO $ do
    node' <- unsafeManagedPtrCastPtr node
    result <- gsk_composite_node_get_mask node'
    checkUnexpectedReturnNULL "compositeNodeGetMask" result
    result' <- (newPtr Gsk.RenderNode.RenderNode) result
    touchManagedPtr node
    return result'

#if defined(ENABLE_OVERLOADING)
data CompositeNodeGetMaskMethodInfo
instance (signature ~ (m Gsk.RenderNode.RenderNode), MonadIO m, IsCompositeNode a) => O.OverloadedMethod CompositeNodeGetMaskMethodInfo a signature where
    overloadedMethod = compositeNodeGetMask

instance O.OverloadedMethodInfo CompositeNodeGetMaskMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gsk.Objects.CompositeNode.compositeNodeGetMask",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gsk-4.0.8/docs/GI-Gsk-Objects-CompositeNode.html#v:compositeNodeGetMask"
        })


#endif

-- method CompositeNode::get_operator
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "CompositeNode" }
--           , argCType = Just "const GskRenderNode*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a composite `GskRenderNode`"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just (TInterface Name { namespace = "Gsk" , name = "PorterDuff" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_composite_node_get_operator" gsk_composite_node_get_operator :: 
    Ptr CompositeNode ->                    -- node : TInterface (Name {namespace = "Gsk", name = "CompositeNode"})
    IO CUInt

-- | Gets the compositing operator used by this node.
-- 
-- /Since: 4.22/
compositeNodeGetOperator ::
    (B.CallStack.HasCallStack, MonadIO m, IsCompositeNode a) =>
    a
    -- ^ /@node@/: a composite @GskRenderNode@
    -> m Gsk.Enums.PorterDuff
    -- ^ __Returns:__ The compositing operator
compositeNodeGetOperator node = liftIO $ do
    node' <- unsafeManagedPtrCastPtr node
    result <- gsk_composite_node_get_operator node'
    let result' = (toEnum . fromIntegral) result
    touchManagedPtr node
    return result'

#if defined(ENABLE_OVERLOADING)
data CompositeNodeGetOperatorMethodInfo
instance (signature ~ (m Gsk.Enums.PorterDuff), MonadIO m, IsCompositeNode a) => O.OverloadedMethod CompositeNodeGetOperatorMethodInfo a signature where
    overloadedMethod = compositeNodeGetOperator

instance O.OverloadedMethodInfo CompositeNodeGetOperatorMethodInfo a where
    overloadedMethodInfo = P.Just (O.ResolvedSymbolInfo {
        O.resolvedSymbolName = "GI.Gsk.Objects.CompositeNode.compositeNodeGetOperator",
        O.resolvedSymbolURL = "https://hackage.haskell.org/package/gi-gsk-4.0.8/docs/GI-Gsk-Objects-CompositeNode.html#v:compositeNodeGetOperator"
        })


#endif


