{-# 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 isolates its child from surrounding rendernodes.
-- 
-- /Since: 4.22/

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

module GI.Gsk.Objects.IsolationNode
    ( 

-- * Exported types
    IsolationNode(..)                       ,
    IsIsolationNode                         ,
    toIsolationNode                         ,


 -- * 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.IsolationNode#g:method:getChild"), [getChildren]("GI.Gsk.Objects.RenderNode#g:method:getChildren"), [getIsolations]("GI.Gsk.Objects.IsolationNode#g:method:getIsolations"), [getNodeType]("GI.Gsk.Objects.RenderNode#g:method:getNodeType"), [getOpaqueRect]("GI.Gsk.Objects.RenderNode#g:method:getOpaqueRect").
-- 
-- ==== Setters
-- /None/.

#if defined(ENABLE_OVERLOADING)
    ResolveIsolationNodeMethod              ,
#endif

-- ** getChild #method:getChild#

#if defined(ENABLE_OVERLOADING)
    IsolationNodeGetChildMethodInfo         ,
#endif
    isolationNodeGetChild                   ,


-- ** getIsolations #method:getIsolations#

#if defined(ENABLE_OVERLOADING)
    IsolationNodeGetIsolationsMethodInfo    ,
#endif
    isolationNodeGetIsolations              ,


-- ** new #method:new#

    isolationNodeNew                        ,




    ) 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.Flags as Gsk.Flags
import {-# SOURCE #-} qualified GI.Gsk.Objects.RenderNode as Gsk.RenderNode

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

#endif

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

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

foreign import ccall "gsk_isolation_node_get_type"
    c_gsk_isolation_node_get_type :: IO B.Types.GType

instance B.Types.TypedObject IsolationNode where
    glibType = c_gsk_isolation_node_get_type

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

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

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

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

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

#endif

instance (info ~ ResolveIsolationNodeMethod t IsolationNode, O.OverloadedMethodInfo info IsolationNode) => OL.IsLabel t (O.MethodProxy info IsolationNode) 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 IsolationNode where
    boxedPtrCopy = return
    boxedPtrFree = \_x -> return ()


-- method IsolationNode::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" , sinceVersion = Nothing }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "isolations"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "Isolation" }
--           , argCType = Just "GskIsolation"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "features to isolate"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , argCallbackUserData = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Gsk" , name = "IsolationNode" })
-- throws : False
-- Skip return : False

foreign import ccall "gsk_isolation_node_new" gsk_isolation_node_new :: 
    Ptr Gsk.RenderNode.RenderNode ->        -- child : TInterface (Name {namespace = "Gsk", name = "RenderNode"})
    CInt ->                                 -- isolations : TInterface (Name {namespace = "Gsk", name = "Isolation"})
    IO (Ptr IsolationNode)

-- | Creates a @GskRenderNode@ that isolates the drawing operations of
-- the child from surrounding ones.
-- 
-- You can express \"everything but these flags\" in a forward compatible
-- way by using bit math:
-- @GSK_ISOLATION_ALL & ~(GSK_ISOLATION_BACKGROUND | GSK_ISOLATION_COPY_PASTE)@
-- will isolate everything but background and copy\/paste.
-- 
-- For the available isolations, see [flags/@gsk@/.Isolation].
-- 
-- /Since: 4.22/
isolationNodeNew ::
    (B.CallStack.HasCallStack, MonadIO m, Gsk.RenderNode.IsRenderNode a) =>
    a
    -- ^ /@child@/: The child
    -> [Gsk.Flags.Isolation]
    -- ^ /@isolations@/: features to isolate
    -> m IsolationNode
    -- ^ __Returns:__ A new @GskRenderNode@
isolationNodeNew child isolations = liftIO $ do
    child' <- unsafeManagedPtrCastPtr child
    let isolations' = gflagsToWord isolations
    result <- gsk_isolation_node_new child' isolations'
    checkUnexpectedReturnNULL "isolationNodeNew" result
    result' <- (wrapPtr IsolationNode) result
    touchManagedPtr child
    return result'

#if defined(ENABLE_OVERLOADING)
#endif

-- method IsolationNode::get_child
-- method type : OrdinaryMethod
-- Args: [ Arg
--           { argCName = "node"
--           , argType =
--               TInterface Name { namespace = "Gsk" , name = "IsolationNode" }
--           , argCType = Just "const GskRenderNode*"
--           , direction = DirectionIn
--           , mayBeNull = False
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "an isolation `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_isolation_node_get_child" gsk_isolation_node_get_child :: 
    Ptr IsolationNode ->                    -- node : TInterface (Name {namespace = "Gsk", name = "IsolationNode"})
    IO (Ptr Gsk.RenderNode.RenderNode)

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

#if defined(ENABLE_OVERLOADING)
data IsolationNodeGetChildMethodInfo
instance (signature ~ (m Gsk.RenderNode.RenderNode), MonadIO m, IsIsolationNode a) => O.OverloadedMethod IsolationNodeGetChildMethodInfo a signature where
    overloadedMethod = isolationNodeGetChild

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


#endif

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

foreign import ccall "gsk_isolation_node_get_isolations" gsk_isolation_node_get_isolations :: 
    Ptr IsolationNode ->                    -- node : TInterface (Name {namespace = "Gsk", name = "IsolationNode"})
    IO CInt

-- | Gets the isolation features that are enforced by this node.
-- 
-- /Since: 4.22/
isolationNodeGetIsolations ::
    (B.CallStack.HasCallStack, MonadIO m, IsIsolationNode a) =>
    a
    -- ^ /@node@/: an isolation @GskRenderNode@
    -> m [Gsk.Flags.Isolation]
    -- ^ __Returns:__ the isolation features
isolationNodeGetIsolations node = liftIO $ do
    node' <- unsafeManagedPtrCastPtr node
    result <- gsk_isolation_node_get_isolations node'
    let result' = wordToGFlags result
    touchManagedPtr node
    return result'

#if defined(ENABLE_OVERLOADING)
data IsolationNodeGetIsolationsMethodInfo
instance (signature ~ (m [Gsk.Flags.Isolation]), MonadIO m, IsIsolationNode a) => O.OverloadedMethod IsolationNodeGetIsolationsMethodInfo a signature where
    overloadedMethod = isolationNodeGetIsolations

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


#endif


