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

The 'GI.Gtk.Structs.TreeIter.TreeIter' is the primary structure
for accessing a 'GI.Gtk.Interfaces.TreeModel.TreeModel'. Models are expected to put a unique
integer in the /@stamp@/ member, and put
model-specific data in the three /@userData@/
members.
-}

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

module GI.Gtk.Structs.TreeIter
    (

-- * Exported types
    TreeIter(..)                            ,
    newZeroTreeIter                         ,
    noTreeIter                              ,


 -- * Methods
-- ** copy #method:copy#

#if ENABLE_OVERLOADING
    TreeIterCopyMethodInfo                  ,
#endif
    treeIterCopy                            ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    TreeIterFreeMethodInfo                  ,
#endif
    treeIterFree                            ,




 -- * Properties
-- ** stamp #attr:stamp#
{- | a unique stamp to catch invalid iterators
-}
    getTreeIterStamp                        ,
    setTreeIterStamp                        ,
#if ENABLE_OVERLOADING
    treeIter_stamp                          ,
#endif


-- ** userData #attr:userData#
{- | model-specific data
-}
    clearTreeIterUserData                   ,
    getTreeIterUserData                     ,
    setTreeIterUserData                     ,
#if ENABLE_OVERLOADING
    treeIter_userData                       ,
#endif


-- ** userData2 #attr:userData2#
{- | model-specific data
-}
    clearTreeIterUserData2                  ,
    getTreeIterUserData2                    ,
    setTreeIterUserData2                    ,
#if ENABLE_OVERLOADING
    treeIter_userData2                      ,
#endif


-- ** userData3 #attr:userData3#
{- | model-specific data
-}
    clearTreeIterUserData3                  ,
    getTreeIterUserData3                    ,
    setTreeIterUserData3                    ,
#if ENABLE_OVERLOADING
    treeIter_userData3                      ,
#endif




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


-- | Memory-managed wrapper type.
newtype TreeIter = TreeIter (ManagedPtr TreeIter)
foreign import ccall "gtk_tree_iter_get_type" c_gtk_tree_iter_get_type ::
    IO GType

instance BoxedObject TreeIter where
    boxedType _ = c_gtk_tree_iter_get_type

-- | Construct a `TreeIter` struct initialized to zero.
newZeroTreeIter :: MonadIO m => m TreeIter
newZeroTreeIter = liftIO $ callocBoxedBytes 32 >>= wrapBoxed TreeIter

instance tag ~ 'AttrSet => Constructible TreeIter tag where
    new _ attrs = do
        o <- newZeroTreeIter
        GI.Attributes.set o attrs
        return o


-- | A convenience alias for `Nothing` :: `Maybe` `TreeIter`.
noTreeIter :: Maybe TreeIter
noTreeIter = Nothing

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

@
'Data.GI.Base.Attributes.get' treeIter #stamp
@
-}
getTreeIterStamp :: MonadIO m => TreeIter -> m Int32
getTreeIterStamp s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO Int32
    return val

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

@
'Data.GI.Base.Attributes.set' treeIter [ #stamp 'Data.GI.Base.Attributes.:=' value ]
@
-}
setTreeIterStamp :: MonadIO m => TreeIter -> Int32 -> m ()
setTreeIterStamp s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: Int32)

#if ENABLE_OVERLOADING
data TreeIterStampFieldInfo
instance AttrInfo TreeIterStampFieldInfo where
    type AttrAllowedOps TreeIterStampFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint TreeIterStampFieldInfo = (~) Int32
    type AttrBaseTypeConstraint TreeIterStampFieldInfo = (~) TreeIter
    type AttrGetType TreeIterStampFieldInfo = Int32
    type AttrLabel TreeIterStampFieldInfo = "stamp"
    type AttrOrigin TreeIterStampFieldInfo = TreeIter
    attrGet _ = getTreeIterStamp
    attrSet _ = setTreeIterStamp
    attrConstruct = undefined
    attrClear _ = undefined

treeIter_stamp :: AttrLabelProxy "stamp"
treeIter_stamp = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' treeIter #userData
@
-}
getTreeIterUserData :: MonadIO m => TreeIter -> m (Ptr ())
getTreeIterUserData s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO (Ptr ())
    return val

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

@
'Data.GI.Base.Attributes.set' treeIter [ #userData 'Data.GI.Base.Attributes.:=' value ]
@
-}
setTreeIterUserData :: MonadIO m => TreeIter -> Ptr () -> m ()
setTreeIterUserData s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Ptr ())

{- |
Set the value of the “@user_data@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #userData
@
-}
clearTreeIterUserData :: MonadIO m => TreeIter -> m ()
clearTreeIterUserData s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (FP.nullPtr :: Ptr ())

#if ENABLE_OVERLOADING
data TreeIterUserDataFieldInfo
instance AttrInfo TreeIterUserDataFieldInfo where
    type AttrAllowedOps TreeIterUserDataFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint TreeIterUserDataFieldInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint TreeIterUserDataFieldInfo = (~) TreeIter
    type AttrGetType TreeIterUserDataFieldInfo = Ptr ()
    type AttrLabel TreeIterUserDataFieldInfo = "user_data"
    type AttrOrigin TreeIterUserDataFieldInfo = TreeIter
    attrGet _ = getTreeIterUserData
    attrSet _ = setTreeIterUserData
    attrConstruct = undefined
    attrClear _ = clearTreeIterUserData

treeIter_userData :: AttrLabelProxy "userData"
treeIter_userData = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' treeIter #userData2
@
-}
getTreeIterUserData2 :: MonadIO m => TreeIter -> m (Ptr ())
getTreeIterUserData2 s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 16) :: IO (Ptr ())
    return val

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

@
'Data.GI.Base.Attributes.set' treeIter [ #userData2 'Data.GI.Base.Attributes.:=' value ]
@
-}
setTreeIterUserData2 :: MonadIO m => TreeIter -> Ptr () -> m ()
setTreeIterUserData2 s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (val :: Ptr ())

{- |
Set the value of the “@user_data2@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #userData2
@
-}
clearTreeIterUserData2 :: MonadIO m => TreeIter -> m ()
clearTreeIterUserData2 s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 16) (FP.nullPtr :: Ptr ())

#if ENABLE_OVERLOADING
data TreeIterUserData2FieldInfo
instance AttrInfo TreeIterUserData2FieldInfo where
    type AttrAllowedOps TreeIterUserData2FieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint TreeIterUserData2FieldInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint TreeIterUserData2FieldInfo = (~) TreeIter
    type AttrGetType TreeIterUserData2FieldInfo = Ptr ()
    type AttrLabel TreeIterUserData2FieldInfo = "user_data2"
    type AttrOrigin TreeIterUserData2FieldInfo = TreeIter
    attrGet _ = getTreeIterUserData2
    attrSet _ = setTreeIterUserData2
    attrConstruct = undefined
    attrClear _ = clearTreeIterUserData2

treeIter_userData2 :: AttrLabelProxy "userData2"
treeIter_userData2 = AttrLabelProxy

#endif


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

@
'Data.GI.Base.Attributes.get' treeIter #userData3
@
-}
getTreeIterUserData3 :: MonadIO m => TreeIter -> m (Ptr ())
getTreeIterUserData3 s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 24) :: IO (Ptr ())
    return val

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

@
'Data.GI.Base.Attributes.set' treeIter [ #userData3 'Data.GI.Base.Attributes.:=' value ]
@
-}
setTreeIterUserData3 :: MonadIO m => TreeIter -> Ptr () -> m ()
setTreeIterUserData3 s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (val :: Ptr ())

{- |
Set the value of the “@user_data3@” field to `Nothing`.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Attributes.clear' #userData3
@
-}
clearTreeIterUserData3 :: MonadIO m => TreeIter -> m ()
clearTreeIterUserData3 s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 24) (FP.nullPtr :: Ptr ())

#if ENABLE_OVERLOADING
data TreeIterUserData3FieldInfo
instance AttrInfo TreeIterUserData3FieldInfo where
    type AttrAllowedOps TreeIterUserData3FieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint TreeIterUserData3FieldInfo = (~) (Ptr ())
    type AttrBaseTypeConstraint TreeIterUserData3FieldInfo = (~) TreeIter
    type AttrGetType TreeIterUserData3FieldInfo = Ptr ()
    type AttrLabel TreeIterUserData3FieldInfo = "user_data3"
    type AttrOrigin TreeIterUserData3FieldInfo = TreeIter
    attrGet _ = getTreeIterUserData3
    attrSet _ = setTreeIterUserData3
    attrConstruct = undefined
    attrClear _ = clearTreeIterUserData3

treeIter_userData3 :: AttrLabelProxy "userData3"
treeIter_userData3 = AttrLabelProxy

#endif



#if ENABLE_OVERLOADING
instance O.HasAttributeList TreeIter
type instance O.AttributeList TreeIter = TreeIterAttributeList
type TreeIterAttributeList = ('[ '("stamp", TreeIterStampFieldInfo), '("userData", TreeIterUserDataFieldInfo), '("userData2", TreeIterUserData2FieldInfo), '("userData3", TreeIterUserData3FieldInfo)] :: [(Symbol, *)])
#endif

-- method TreeIter::copy
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Gtk", name = "TreeIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkTreeIter-struct", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gtk", name = "TreeIter"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_tree_iter_copy" gtk_tree_iter_copy ::
    Ptr TreeIter ->                         -- iter : TInterface (Name {namespace = "Gtk", name = "TreeIter"})
    IO (Ptr TreeIter)

{- |
Creates a dynamically allocated tree iterator as a copy of /@iter@/.

This function is not intended for use in applications,
because you can just copy the structs by value
(@GtkTreeIter new_iter = iter;@).
You must free this iter with 'GI.Gtk.Structs.TreeIter.treeIterFree'.
-}
treeIterCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    TreeIter
    {- ^ /@iter@/: a 'GI.Gtk.Structs.TreeIter.TreeIter'-struct -}
    -> m TreeIter
    {- ^ __Returns:__ a newly-allocated copy of /@iter@/ -}
treeIterCopy iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    result <- gtk_tree_iter_copy iter'
    checkUnexpectedReturnNULL "treeIterCopy" result
    result' <- (wrapBoxed TreeIter) result
    touchManagedPtr iter
    return result'

#if ENABLE_OVERLOADING
data TreeIterCopyMethodInfo
instance (signature ~ (m TreeIter), MonadIO m) => O.MethodInfo TreeIterCopyMethodInfo TreeIter signature where
    overloadedMethod _ = treeIterCopy

#endif

-- method TreeIter::free
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Gtk", name = "TreeIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a dynamically allocated tree iterator", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_tree_iter_free" gtk_tree_iter_free ::
    Ptr TreeIter ->                         -- iter : TInterface (Name {namespace = "Gtk", name = "TreeIter"})
    IO ()

{- |
Frees an iterator that has been allocated by 'GI.Gtk.Structs.TreeIter.treeIterCopy'.

This function is mainly used for language bindings.
-}
treeIterFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    TreeIter
    {- ^ /@iter@/: a dynamically allocated tree iterator -}
    -> m ()
treeIterFree iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    gtk_tree_iter_free iter'
    touchManagedPtr iter
    return ()

#if ENABLE_OVERLOADING
data TreeIterFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo TreeIterFreeMethodInfo TreeIter signature where
    overloadedMethod _ = treeIterFree

#endif

#if ENABLE_OVERLOADING
type family ResolveTreeIterMethod (t :: Symbol) (o :: *) :: * where
    ResolveTreeIterMethod "copy" o = TreeIterCopyMethodInfo
    ResolveTreeIterMethod "free" o = TreeIterFreeMethodInfo
    ResolveTreeIterMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveTreeIterMethod t TreeIter, O.MethodInfo info TreeIter p) => OL.IsLabel t (TreeIter -> 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