{-# LANGUAGE TypeApplications #-}


-- | Copyright  : Will Thompson and Iñaki García Etxebarria
-- License    : LGPL-2.1
-- Maintainer : Iñaki García Etxebarria
-- 
-- The t'GI.Clutter.Objects.TextNode.TextNode' structure is an opaque
-- type whose members cannot be directly accessed.
-- 
-- /Since: 1.10/

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

module GI.Clutter.Objects.TextNode
    ( 

-- * Exported types
    TextNode(..)                            ,
    IsTextNode                              ,
    toTextNode                              ,


 -- * Methods
-- | 
-- 
--  === __Click to display all available methods, including inherited ones__
-- ==== Methods
-- [addChild]("GI.Clutter.Objects.PaintNode#g:method:addChild"), [addRectangle]("GI.Clutter.Objects.PaintNode#g:method:addRectangle"), [addTextureRectangle]("GI.Clutter.Objects.PaintNode#g:method:addTextureRectangle"), [ref]("GI.Clutter.Objects.PaintNode#g:method:ref"), [unref]("GI.Clutter.Objects.PaintNode#g:method:unref").
-- 
-- ==== Getters
-- /None/.
-- 
-- ==== Setters
-- [setName]("GI.Clutter.Objects.PaintNode#g:method:setName").

#if defined(ENABLE_OVERLOADING)
    ResolveTextNodeMethod                   ,
#endif

-- ** new #method:new#

    textNodeNew                             ,




    ) 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 {-# SOURCE #-} qualified GI.Clutter.Objects.PaintNode as Clutter.PaintNode
import {-# SOURCE #-} qualified GI.Clutter.Structs.Color as Clutter.Color
import qualified GI.Pango.Objects.Layout as Pango.Layout

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

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

foreign import ccall "clutter_text_node_get_type"
    c_clutter_text_node_get_type :: IO B.Types.GType

instance B.Types.TypedObject TextNode where
    glibType :: IO GType
glibType = IO GType
c_clutter_text_node_get_type

-- | Type class for types which can be safely cast to `TextNode`, for instance with `toTextNode`.
class (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf TextNode o) => IsTextNode o
instance (SP.BoxedPtr o, SP.TypedObject o, O.IsDescendantOf TextNode o) => IsTextNode o

instance O.HasParentTypes TextNode
type instance O.ParentTypes TextNode = '[Clutter.PaintNode.PaintNode]

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

--- XXX Missing getter and/or setter, so no GValue instance could be generated.
#if defined(ENABLE_OVERLOADING)
type family ResolveTextNodeMethod (t :: Symbol) (o :: *) :: * where
    ResolveTextNodeMethod "addChild" o = Clutter.PaintNode.PaintNodeAddChildMethodInfo
    ResolveTextNodeMethod "addRectangle" o = Clutter.PaintNode.PaintNodeAddRectangleMethodInfo
    ResolveTextNodeMethod "addTextureRectangle" o = Clutter.PaintNode.PaintNodeAddTextureRectangleMethodInfo
    ResolveTextNodeMethod "ref" o = Clutter.PaintNode.PaintNodeRefMethodInfo
    ResolveTextNodeMethod "unref" o = Clutter.PaintNode.PaintNodeUnrefMethodInfo
    ResolveTextNodeMethod "setName" o = Clutter.PaintNode.PaintNodeSetNameMethodInfo
    ResolveTextNodeMethod l o = O.MethodResolutionFailed l o

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

#endif

instance (info ~ ResolveTextNodeMethod t TextNode, O.OverloadedMethodInfo info TextNode) => OL.IsLabel t (O.MethodProxy info TextNode) 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 TextNode where
    boxedPtrCopy :: TextNode -> IO TextNode
boxedPtrCopy = TextNode -> IO TextNode
forall (m :: * -> *) a. Monad m => a -> m a
return
    boxedPtrFree :: TextNode -> IO ()
boxedPtrFree = \TextNode
_x -> () -> IO ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()


-- method TextNode::new
-- method type : Constructor
-- Args: [ Arg
--           { argCName = "layout"
--           , argType =
--               TInterface Name { namespace = "Pango" , name = "Layout" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText = Just "a #PangoLayout, or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       , Arg
--           { argCName = "color"
--           , argType =
--               TInterface Name { namespace = "Clutter" , name = "Color" }
--           , direction = DirectionIn
--           , mayBeNull = True
--           , argDoc =
--               Documentation
--                 { rawDocText =
--                     Just "the color used to paint the layout,\n  or %NULL"
--                 , sinceVersion = Nothing
--                 }
--           , argScope = ScopeTypeInvalid
--           , argClosure = -1
--           , argDestroy = -1
--           , argCallerAllocates = False
--           , transfer = TransferNothing
--           }
--       ]
-- Lengths: []
-- returnType: Just
--               (TInterface Name { namespace = "Clutter" , name = "PaintNode" })
-- throws : False
-- Skip return : False

foreign import ccall "clutter_text_node_new" clutter_text_node_new :: 
    Ptr Pango.Layout.Layout ->              -- layout : TInterface (Name {namespace = "Pango", name = "Layout"})
    Ptr Clutter.Color.Color ->              -- color : TInterface (Name {namespace = "Clutter", name = "Color"})
    IO (Ptr Clutter.PaintNode.PaintNode)

-- | Creates a new t'GI.Clutter.Objects.PaintNode.PaintNode' that will paint a t'GI.Pango.Objects.Layout.Layout'
-- with the given color.
-- 
-- This function takes a reference on the passed /@layout@/, so it
-- is safe to call 'GI.GObject.Objects.Object.objectUnref' after it returns.
-- 
-- /Since: 1.10/
textNodeNew ::
    (B.CallStack.HasCallStack, MonadIO m, Pango.Layout.IsLayout a) =>
    Maybe (a)
    -- ^ /@layout@/: a t'GI.Pango.Objects.Layout.Layout', or 'P.Nothing'
    -> Maybe (Clutter.Color.Color)
    -- ^ /@color@/: the color used to paint the layout,
    --   or 'P.Nothing'
    -> m Clutter.PaintNode.PaintNode
    -- ^ __Returns:__ the newly created t'GI.Clutter.Objects.PaintNode.PaintNode'.
    --   Use 'GI.Clutter.Objects.PaintNode.paintNodeUnref' when done
textNodeNew :: forall (m :: * -> *) a.
(HasCallStack, MonadIO m, IsLayout a) =>
Maybe a -> Maybe Color -> m PaintNode
textNodeNew Maybe a
layout Maybe Color
color = IO PaintNode -> m PaintNode
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO PaintNode -> m PaintNode) -> IO PaintNode -> m PaintNode
forall a b. (a -> b) -> a -> b
$ do
    Ptr Layout
maybeLayout <- case Maybe a
layout of
        Maybe a
Nothing -> Ptr Layout -> IO (Ptr Layout)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Layout
forall a. Ptr a
nullPtr
        Just a
jLayout -> do
            Ptr Layout
jLayout' <- a -> IO (Ptr Layout)
forall a b. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr b)
unsafeManagedPtrCastPtr a
jLayout
            Ptr Layout -> IO (Ptr Layout)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Layout
jLayout'
    Ptr Color
maybeColor <- case Maybe Color
color of
        Maybe Color
Nothing -> Ptr Color -> IO (Ptr Color)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Color
forall a. Ptr a
nullPtr
        Just Color
jColor -> do
            Ptr Color
jColor' <- Color -> IO (Ptr Color)
forall a. (HasCallStack, ManagedPtrNewtype a) => a -> IO (Ptr a)
unsafeManagedPtrGetPtr Color
jColor
            Ptr Color -> IO (Ptr Color)
forall (m :: * -> *) a. Monad m => a -> m a
return Ptr Color
jColor'
    Ptr PaintNode
result <- Ptr Layout -> Ptr Color -> IO (Ptr PaintNode)
clutter_text_node_new Ptr Layout
maybeLayout Ptr Color
maybeColor
    Text -> Ptr PaintNode -> IO ()
forall a. HasCallStack => Text -> Ptr a -> IO ()
checkUnexpectedReturnNULL Text
"textNodeNew" Ptr PaintNode
result
    PaintNode
result' <- ((ManagedPtr PaintNode -> PaintNode)
-> Ptr PaintNode -> IO PaintNode
forall a.
(HasCallStack, BoxedPtr a) =>
(ManagedPtr a -> a) -> Ptr a -> IO a
wrapPtr ManagedPtr PaintNode -> PaintNode
Clutter.PaintNode.PaintNode) Ptr PaintNode
result
    Maybe a -> (a -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe a
layout a -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    Maybe Color -> (Color -> IO ()) -> IO ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Color
color Color -> IO ()
forall a. ManagedPtrNewtype a => a -> IO ()
touchManagedPtr
    PaintNode -> IO PaintNode
forall (m :: * -> *) a. Monad m => a -> m a
return PaintNode
result'

#if defined(ENABLE_OVERLOADING)
#endif