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

An interface used for objects which implement linking between
multiple resource or content locations, or multiple \'markers\'
within a single document.  A Hypertext instance is associated with
one or more Hyperlinks, which are associated with particular
offsets within the Hypertext\'s included content.  While this
interface is derived from Text, there is no requirement that
Hypertext instances have textual content; they may implement Image
as well, and Hyperlinks need not have non-zero text offsets.
-}

module GI.Atk.Interfaces.Hypertext
    ( 

-- * Exported types
    Hypertext(..)                           ,
    noHypertext                             ,
    IsHypertext                             ,
    toHypertext                             ,


 -- * Methods
-- ** getLink #method:getLink#
    HypertextGetLinkMethodInfo              ,
    hypertextGetLink                        ,


-- ** getLinkIndex #method:getLinkIndex#
    HypertextGetLinkIndexMethodInfo         ,
    hypertextGetLinkIndex                   ,


-- ** getNLinks #method:getNLinks#
    HypertextGetNLinksMethodInfo            ,
    hypertextGetNLinks                      ,




 -- * Signals
-- ** linkSelected #signal:linkSelected#
    C_HypertextLinkSelectedCallback         ,
    HypertextLinkSelectedCallback           ,
    HypertextLinkSelectedSignalInfo         ,
    afterHypertextLinkSelected              ,
    genClosure_HypertextLinkSelected        ,
    mk_HypertextLinkSelectedCallback        ,
    noHypertextLinkSelectedCallback         ,
    onHypertextLinkSelected                 ,
    wrap_HypertextLinkSelectedCallback      ,




    ) 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.GError as B.GError
import qualified Data.GI.Base.GVariant as B.GVariant
import qualified Data.GI.Base.GParamSpec as B.GParamSpec
import qualified Data.GI.Base.CallStack as B.CallStack
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 {-# SOURCE #-} qualified GI.Atk.Objects.Hyperlink as Atk.Hyperlink
import qualified GI.GObject.Objects.Object as GObject.Object

-- interface Hypertext 
newtype Hypertext = Hypertext (ManagedPtr Hypertext)
noHypertext :: Maybe Hypertext
noHypertext = Nothing

-- signal Hypertext::link-selected
type HypertextLinkSelectedCallback =
    Int32 ->
    IO ()

noHypertextLinkSelectedCallback :: Maybe HypertextLinkSelectedCallback
noHypertextLinkSelectedCallback = Nothing

type C_HypertextLinkSelectedCallback =
    Ptr () ->                               -- object
    Int32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_HypertextLinkSelectedCallback :: C_HypertextLinkSelectedCallback -> IO (FunPtr C_HypertextLinkSelectedCallback)

genClosure_HypertextLinkSelected :: HypertextLinkSelectedCallback -> IO Closure
genClosure_HypertextLinkSelected cb = do
    let cb' = wrap_HypertextLinkSelectedCallback cb
    mk_HypertextLinkSelectedCallback cb' >>= newCClosure


wrap_HypertextLinkSelectedCallback ::
    HypertextLinkSelectedCallback ->
    Ptr () ->
    Int32 ->
    Ptr () ->
    IO ()
wrap_HypertextLinkSelectedCallback _cb _ arg1 _ = do
    _cb  arg1


onHypertextLinkSelected :: (IsHypertext a, MonadIO m) => a -> HypertextLinkSelectedCallback -> m SignalHandlerId
onHypertextLinkSelected obj cb = liftIO $ do
    let cb' = wrap_HypertextLinkSelectedCallback cb
    cb'' <- mk_HypertextLinkSelectedCallback cb'
    connectSignalFunPtr obj "link-selected" cb'' SignalConnectBefore

afterHypertextLinkSelected :: (IsHypertext a, MonadIO m) => a -> HypertextLinkSelectedCallback -> m SignalHandlerId
afterHypertextLinkSelected obj cb = liftIO $ do
    let cb' = wrap_HypertextLinkSelectedCallback cb
    cb'' <- mk_HypertextLinkSelectedCallback cb'
    connectSignalFunPtr obj "link-selected" cb'' SignalConnectAfter


data HypertextLinkSelectedSignalInfo
instance SignalInfo HypertextLinkSelectedSignalInfo where
    type HaskellCallbackType HypertextLinkSelectedSignalInfo = HypertextLinkSelectedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_HypertextLinkSelectedCallback cb
        cb'' <- mk_HypertextLinkSelectedCallback cb'
        connectSignalFunPtr obj "link-selected" cb'' connectMode

type instance O.SignalList Hypertext = HypertextSignalList
type HypertextSignalList = ('[ '("linkSelected", HypertextLinkSelectedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

foreign import ccall "atk_hypertext_get_type"
    c_atk_hypertext_get_type :: IO GType

instance GObject Hypertext where
    gobjectType _ = c_atk_hypertext_get_type
    

class GObject o => IsHypertext o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError Hypertext a) =>
    IsHypertext a
#endif
instance IsHypertext Hypertext
instance GObject.Object.IsObject Hypertext

toHypertext :: IsHypertext o => o -> IO Hypertext
toHypertext = unsafeCastTo Hypertext

instance O.HasAttributeList Hypertext
type instance O.AttributeList Hypertext = HypertextAttributeList
type HypertextAttributeList = ('[ ] :: [(Symbol, *)])

type family ResolveHypertextMethod (t :: Symbol) (o :: *) :: * where
    ResolveHypertextMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveHypertextMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveHypertextMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveHypertextMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveHypertextMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveHypertextMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveHypertextMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveHypertextMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveHypertextMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveHypertextMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveHypertextMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveHypertextMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveHypertextMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveHypertextMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveHypertextMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveHypertextMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveHypertextMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveHypertextMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveHypertextMethod "getLink" o = HypertextGetLinkMethodInfo
    ResolveHypertextMethod "getLinkIndex" o = HypertextGetLinkIndexMethodInfo
    ResolveHypertextMethod "getNLinks" o = HypertextGetNLinksMethodInfo
    ResolveHypertextMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveHypertextMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveHypertextMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveHypertextMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveHypertextMethod l o = O.MethodResolutionFailed l o

instance (info ~ ResolveHypertextMethod t Hypertext, O.MethodInfo info Hypertext p) => O.IsLabelProxy t (Hypertext -> p) where
    fromLabelProxy _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveHypertextMethod t Hypertext, O.MethodInfo info Hypertext p) => O.IsLabel t (Hypertext -> p) where
    fromLabel _ = O.overloadedMethod (O.MethodProxy :: O.MethodProxy info)
#endif

-- method Hypertext::get_link
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "hypertext", argType = TInterface (Name {namespace = "Atk", name = "Hypertext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an #AtkHypertext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "link_index", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an integer specifying the desired link", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Atk", name = "Hyperlink"}))
-- throws : False
-- Skip return : False

foreign import ccall "atk_hypertext_get_link" atk_hypertext_get_link :: 
    Ptr Hypertext ->                        -- hypertext : TInterface (Name {namespace = "Atk", name = "Hypertext"})
    Int32 ->                                -- link_index : TBasicType TInt
    IO (Ptr Atk.Hyperlink.Hyperlink)

{- |
Gets the link in this hypertext document at index
/@linkIndex@/
-}
hypertextGetLink ::
    (B.CallStack.HasCallStack, MonadIO m, IsHypertext a) =>
    a
    {- ^ /@hypertext@/: an 'GI.Atk.Interfaces.Hypertext.Hypertext' -}
    -> Int32
    {- ^ /@linkIndex@/: an integer specifying the desired link -}
    -> m Atk.Hyperlink.Hyperlink
    {- ^ __Returns:__ the link in this hypertext document at
index /@linkIndex@/ -}
hypertextGetLink hypertext linkIndex = liftIO $ do
    hypertext' <- unsafeManagedPtrCastPtr hypertext
    result <- atk_hypertext_get_link hypertext' linkIndex
    checkUnexpectedReturnNULL "hypertextGetLink" result
    result' <- (newObject Atk.Hyperlink.Hyperlink) result
    touchManagedPtr hypertext
    return result'

data HypertextGetLinkMethodInfo
instance (signature ~ (Int32 -> m Atk.Hyperlink.Hyperlink), MonadIO m, IsHypertext a) => O.MethodInfo HypertextGetLinkMethodInfo a signature where
    overloadedMethod _ = hypertextGetLink

-- method Hypertext::get_link_index
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "hypertext", argType = TInterface (Name {namespace = "Atk", name = "Hypertext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an #AtkHypertext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "char_index", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a character index", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "atk_hypertext_get_link_index" atk_hypertext_get_link_index :: 
    Ptr Hypertext ->                        -- hypertext : TInterface (Name {namespace = "Atk", name = "Hypertext"})
    Int32 ->                                -- char_index : TBasicType TInt
    IO Int32

{- |
Gets the index into the array of hyperlinks that is associated with
the character specified by /@charIndex@/.
-}
hypertextGetLinkIndex ::
    (B.CallStack.HasCallStack, MonadIO m, IsHypertext a) =>
    a
    {- ^ /@hypertext@/: an 'GI.Atk.Interfaces.Hypertext.Hypertext' -}
    -> Int32
    {- ^ /@charIndex@/: a character index -}
    -> m Int32
    {- ^ __Returns:__ an index into the array of hyperlinks in /@hypertext@/,
or -1 if there is no hyperlink associated with this character. -}
hypertextGetLinkIndex hypertext charIndex = liftIO $ do
    hypertext' <- unsafeManagedPtrCastPtr hypertext
    result <- atk_hypertext_get_link_index hypertext' charIndex
    touchManagedPtr hypertext
    return result

data HypertextGetLinkIndexMethodInfo
instance (signature ~ (Int32 -> m Int32), MonadIO m, IsHypertext a) => O.MethodInfo HypertextGetLinkIndexMethodInfo a signature where
    overloadedMethod _ = hypertextGetLinkIndex

-- method Hypertext::get_n_links
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "hypertext", argType = TInterface (Name {namespace = "Atk", name = "Hypertext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an #AtkHypertext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TInt)
-- throws : False
-- Skip return : False

foreign import ccall "atk_hypertext_get_n_links" atk_hypertext_get_n_links :: 
    Ptr Hypertext ->                        -- hypertext : TInterface (Name {namespace = "Atk", name = "Hypertext"})
    IO Int32

{- |
Gets the number of links within this hypertext document.
-}
hypertextGetNLinks ::
    (B.CallStack.HasCallStack, MonadIO m, IsHypertext a) =>
    a
    {- ^ /@hypertext@/: an 'GI.Atk.Interfaces.Hypertext.Hypertext' -}
    -> m Int32
    {- ^ __Returns:__ the number of links within this hypertext document -}
hypertextGetNLinks hypertext = liftIO $ do
    hypertext' <- unsafeManagedPtrCastPtr hypertext
    result <- atk_hypertext_get_n_links hypertext'
    touchManagedPtr hypertext
    return result

data HypertextGetNLinksMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsHypertext a) => O.MethodInfo HypertextGetNLinksMethodInfo a signature where
    overloadedMethod _ = hypertextGetNLinks