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

/No description available in the introspection data./
-}

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

module GI.Poppler.Structs.IndexIter
    (

-- * Exported types
    IndexIter(..)                           ,
    noIndexIter                             ,


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

#if ENABLE_OVERLOADING
    IndexIterCopyMethodInfo                 ,
#endif
    indexIterCopy                           ,


-- ** free #method:free#

#if ENABLE_OVERLOADING
    IndexIterFreeMethodInfo                 ,
#endif
    indexIterFree                           ,


-- ** getAction #method:getAction#

#if ENABLE_OVERLOADING
    IndexIterGetActionMethodInfo            ,
#endif
    indexIterGetAction                      ,


-- ** getChild #method:getChild#

#if ENABLE_OVERLOADING
    IndexIterGetChildMethodInfo             ,
#endif
    indexIterGetChild                       ,


-- ** isOpen #method:isOpen#

#if ENABLE_OVERLOADING
    IndexIterIsOpenMethodInfo               ,
#endif
    indexIterIsOpen                         ,


-- ** new #method:new#

    indexIterNew                            ,


-- ** next #method:next#

#if ENABLE_OVERLOADING
    IndexIterNextMethodInfo                 ,
#endif
    indexIterNext                           ,




    ) 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

import {-# SOURCE #-} qualified GI.Poppler.Objects.Document as Poppler.Document
import {-# SOURCE #-} qualified GI.Poppler.Unions.Action as Poppler.Action

-- | Memory-managed wrapper type.
newtype IndexIter = IndexIter (ManagedPtr IndexIter)
foreign import ccall "poppler_index_iter_get_type" c_poppler_index_iter_get_type ::
    IO GType

instance BoxedObject IndexIter where
    boxedType _ = c_poppler_index_iter_get_type

-- | A convenience alias for `Nothing` :: `Maybe` `IndexIter`.
noIndexIter :: Maybe IndexIter
noIndexIter = Nothing


#if ENABLE_OVERLOADING
instance O.HasAttributeList IndexIter
type instance O.AttributeList IndexIter = IndexIterAttributeList
type IndexIterAttributeList = ('[ ] :: [(Symbol, *)])
#endif

-- method IndexIter::new
-- method type : Constructor
-- Args : [Arg {argCName = "document", argType = TInterface (Name {namespace = "Poppler", name = "Document"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PopplerDocument", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Poppler", name = "IndexIter"}))
-- throws : False
-- Skip return : False

foreign import ccall "poppler_index_iter_new" poppler_index_iter_new ::
    Ptr Poppler.Document.Document ->        -- document : TInterface (Name {namespace = "Poppler", name = "Document"})
    IO (Ptr IndexIter)

{- |
Returns the root 'GI.Poppler.Structs.IndexIter.IndexIter' for /@document@/, or 'Nothing'.  This must be
freed with 'GI.Poppler.Structs.IndexIter.indexIterFree'.

Certain documents have an index associated with them.  This index can be used
to help the user navigate the document, and is similar to a table of
contents.  Each node in the index will contain a 'GI.Poppler.Unions.Action.Action' that can be
displayed to the user — typically a @/POPPLER_ACTION_GOTO_DEST/@ or a
@/POPPLER_ACTION_URI/@\<!-- -->.

Here is a simple example of some code that walks the full index:

\<informalexample>\<programlisting>
static void
walk_index (PopplerIndexIter *iter)
{
  do
    {
      \/\<!-- -->* Get the action and do something with it *\<!-- -->\/
      PopplerIndexIter *child = poppler_index_iter_get_child (iter);
      if (child)
        walk_index (child);
      poppler_index_iter_free (child);
    }
  while (poppler_index_iter_next (iter));
}
...
{
  iter = poppler_index_iter_new (document);
  walk_index (iter);
  poppler_index_iter_free (iter);
}
\<\/programlisting>\<\/informalexample>
-}
indexIterNew ::
    (B.CallStack.HasCallStack, MonadIO m, Poppler.Document.IsDocument a) =>
    a
    {- ^ /@document@/: a 'GI.Poppler.Objects.Document.Document' -}
    -> m IndexIter
    {- ^ __Returns:__ a new 'GI.Poppler.Structs.IndexIter.IndexIter' -}
indexIterNew document = liftIO $ do
    document' <- unsafeManagedPtrCastPtr document
    result <- poppler_index_iter_new document'
    checkUnexpectedReturnNULL "indexIterNew" result
    result' <- (wrapBoxed IndexIter) result
    touchManagedPtr document
    return result'

#if ENABLE_OVERLOADING
#endif

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

foreign import ccall "poppler_index_iter_copy" poppler_index_iter_copy ::
    Ptr IndexIter ->                        -- iter : TInterface (Name {namespace = "Poppler", name = "IndexIter"})
    IO (Ptr IndexIter)

{- |
Creates a new 'GI.Poppler.Structs.IndexIter.IndexIter' as a copy of /@iter@/.  This must be freed with
'GI.Poppler.Structs.IndexIter.indexIterFree'.
-}
indexIterCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexIter
    {- ^ /@iter@/: a 'GI.Poppler.Structs.IndexIter.IndexIter' -}
    -> m IndexIter
    {- ^ __Returns:__ a new 'GI.Poppler.Structs.IndexIter.IndexIter' -}
indexIterCopy iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    result <- poppler_index_iter_copy iter'
    checkUnexpectedReturnNULL "indexIterCopy" result
    result' <- (wrapBoxed IndexIter) result
    touchManagedPtr iter
    return result'

#if ENABLE_OVERLOADING
data IndexIterCopyMethodInfo
instance (signature ~ (m IndexIter), MonadIO m) => O.MethodInfo IndexIterCopyMethodInfo IndexIter signature where
    overloadedMethod _ = indexIterCopy

#endif

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

foreign import ccall "poppler_index_iter_free" poppler_index_iter_free ::
    Ptr IndexIter ->                        -- iter : TInterface (Name {namespace = "Poppler", name = "IndexIter"})
    IO ()

{- |
Frees /@iter@/.
-}
indexIterFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexIter
    {- ^ /@iter@/: a 'GI.Poppler.Structs.IndexIter.IndexIter' -}
    -> m ()
indexIterFree iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    poppler_index_iter_free iter'
    touchManagedPtr iter
    return ()

#if ENABLE_OVERLOADING
data IndexIterFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo IndexIterFreeMethodInfo IndexIter signature where
    overloadedMethod _ = indexIterFree

#endif

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

foreign import ccall "poppler_index_iter_get_action" poppler_index_iter_get_action ::
    Ptr IndexIter ->                        -- iter : TInterface (Name {namespace = "Poppler", name = "IndexIter"})
    IO (Ptr Poppler.Action.Action)

{- |
Returns the 'GI.Poppler.Unions.Action.Action' associated with /@iter@/.  It must be freed with
'GI.Poppler.Unions.Action.actionFree'.
-}
indexIterGetAction ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexIter
    {- ^ /@iter@/: a 'GI.Poppler.Structs.IndexIter.IndexIter' -}
    -> m Poppler.Action.Action
    {- ^ __Returns:__ a new 'GI.Poppler.Unions.Action.Action' -}
indexIterGetAction iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    result <- poppler_index_iter_get_action iter'
    checkUnexpectedReturnNULL "indexIterGetAction" result
    result' <- (wrapBoxed Poppler.Action.Action) result
    touchManagedPtr iter
    return result'

#if ENABLE_OVERLOADING
data IndexIterGetActionMethodInfo
instance (signature ~ (m Poppler.Action.Action), MonadIO m) => O.MethodInfo IndexIterGetActionMethodInfo IndexIter signature where
    overloadedMethod _ = indexIterGetAction

#endif

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

foreign import ccall "poppler_index_iter_get_child" poppler_index_iter_get_child ::
    Ptr IndexIter ->                        -- parent : TInterface (Name {namespace = "Poppler", name = "IndexIter"})
    IO (Ptr IndexIter)

{- |
Returns a newly created child of /@parent@/, or 'Nothing' if the iter has no child.
See 'GI.Poppler.Structs.IndexIter.indexIterNew' for more information on this function.
-}
indexIterGetChild ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexIter
    {- ^ /@parent@/: a 'GI.Poppler.Structs.IndexIter.IndexIter' -}
    -> m IndexIter
    {- ^ __Returns:__ a new 'GI.Poppler.Structs.IndexIter.IndexIter' -}
indexIterGetChild parent = liftIO $ do
    parent' <- unsafeManagedPtrGetPtr parent
    result <- poppler_index_iter_get_child parent'
    checkUnexpectedReturnNULL "indexIterGetChild" result
    result' <- (wrapBoxed IndexIter) result
    touchManagedPtr parent
    return result'

#if ENABLE_OVERLOADING
data IndexIterGetChildMethodInfo
instance (signature ~ (m IndexIter), MonadIO m) => O.MethodInfo IndexIterGetChildMethodInfo IndexIter signature where
    overloadedMethod _ = indexIterGetChild

#endif

-- method IndexIter::is_open
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Poppler", name = "IndexIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PopplerIndexIter", 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 "poppler_index_iter_is_open" poppler_index_iter_is_open ::
    Ptr IndexIter ->                        -- iter : TInterface (Name {namespace = "Poppler", name = "IndexIter"})
    IO CInt

{- |
Returns whether this node should be expanded by default to the user.  The
document can provide a hint as to how the document\'s index should be expanded
initially.
-}
indexIterIsOpen ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexIter
    {- ^ /@iter@/: a 'GI.Poppler.Structs.IndexIter.IndexIter' -}
    -> m Bool
    {- ^ __Returns:__ 'True', if the document wants /@iter@/ to be expanded -}
indexIterIsOpen iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    result <- poppler_index_iter_is_open iter'
    let result' = (/= 0) result
    touchManagedPtr iter
    return result'

#if ENABLE_OVERLOADING
data IndexIterIsOpenMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo IndexIterIsOpenMethodInfo IndexIter signature where
    overloadedMethod _ = indexIterIsOpen

#endif

-- method IndexIter::next
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "iter", argType = TInterface (Name {namespace = "Poppler", name = "IndexIter"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #PopplerIndexIter", 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 "poppler_index_iter_next" poppler_index_iter_next ::
    Ptr IndexIter ->                        -- iter : TInterface (Name {namespace = "Poppler", name = "IndexIter"})
    IO CInt

{- |
Sets /@iter@/ to point to the next action at the current level, if valid.  See
'GI.Poppler.Structs.IndexIter.indexIterNew' for more information.
-}
indexIterNext ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    IndexIter
    {- ^ /@iter@/: a 'GI.Poppler.Structs.IndexIter.IndexIter' -}
    -> m Bool
    {- ^ __Returns:__ 'True', if /@iter@/ was set to the next action -}
indexIterNext iter = liftIO $ do
    iter' <- unsafeManagedPtrGetPtr iter
    result <- poppler_index_iter_next iter'
    let result' = (/= 0) result
    touchManagedPtr iter
    return result'

#if ENABLE_OVERLOADING
data IndexIterNextMethodInfo
instance (signature ~ (m Bool), MonadIO m) => O.MethodInfo IndexIterNextMethodInfo IndexIter signature where
    overloadedMethod _ = indexIterNext

#endif

#if ENABLE_OVERLOADING
type family ResolveIndexIterMethod (t :: Symbol) (o :: *) :: * where
    ResolveIndexIterMethod "copy" o = IndexIterCopyMethodInfo
    ResolveIndexIterMethod "free" o = IndexIterFreeMethodInfo
    ResolveIndexIterMethod "isOpen" o = IndexIterIsOpenMethodInfo
    ResolveIndexIterMethod "next" o = IndexIterNextMethodInfo
    ResolveIndexIterMethod "getAction" o = IndexIterGetActionMethodInfo
    ResolveIndexIterMethod "getChild" o = IndexIterGetChildMethodInfo
    ResolveIndexIterMethod l o = O.MethodResolutionFailed l o

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