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

A #GtkTargetList-struct is a reference counted list
of #GtkTargetPair and should be treated as
opaque.
-}

module GI.Gtk.Structs.TargetList
    ( 

-- * Exported types
    TargetList(..)                          ,
    noTargetList                            ,


 -- * Methods
-- ** targetListAdd
    targetListAdd                           ,


-- ** targetListAddImageTargets
    targetListAddImageTargets               ,


-- ** targetListAddRichTextTargets
    targetListAddRichTextTargets            ,


-- ** targetListAddTable
    targetListAddTable                      ,


-- ** targetListAddTextTargets
    targetListAddTextTargets                ,


-- ** targetListAddUriTargets
    targetListAddUriTargets                 ,


-- ** targetListFind
    targetListFind                          ,


-- ** targetListNew
    targetListNew                           ,


-- ** targetListRef
    targetListRef                           ,


-- ** targetListRemove
    targetListRemove                        ,


-- ** targetListUnref
    targetListUnref                         ,




    ) where

import Prelude ()
import Data.GI.Base.ShortPrelude

import qualified Data.Text as T
import qualified Data.ByteString.Char8 as B
import qualified Data.Map as Map

import GI.Gtk.Types
import GI.Gtk.Callbacks
import qualified GI.Gdk as Gdk

newtype TargetList = TargetList (ForeignPtr TargetList)
foreign import ccall "gtk_target_list_get_type" c_gtk_target_list_get_type :: 
    IO GType

instance BoxedObject TargetList where
    boxedType _ = c_gtk_target_list_get_type

noTargetList :: Maybe TargetList
noTargetList = Nothing

-- method TargetList::new
-- method type : Constructor
-- Args : [Arg {argName = "targets", argType = TCArray False (-1) 1 (TInterface "Gtk" "TargetEntry"), direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "ntargets", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : [Arg {argName = "ntargets", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- hInArgs : [Arg {argName = "targets", argType = TCArray False (-1) 1 (TInterface "Gtk" "TargetEntry"), direction = DirectionIn, mayBeNull = True, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gtk" "TargetList"
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_new" gtk_target_list_new :: 
    Ptr TargetEntry ->                      -- targets : TCArray False (-1) 1 (TInterface "Gtk" "TargetEntry")
    Word32 ->                               -- ntargets : TBasicType TUInt32
    IO (Ptr TargetList)


targetListNew ::
    (MonadIO m) =>
    Maybe ([TargetEntry]) ->                -- targets
    m TargetList
targetListNew targets = liftIO $ do
    let ntargets = case targets of
            Nothing -> 0
            Just jTargets -> fromIntegral $ length jTargets
    maybeTargets <- case targets of
        Nothing -> return nullPtr
        Just jTargets -> do
            let jTargets' = map unsafeManagedPtrGetPtr jTargets
            jTargets'' <- packBlockArray 16 jTargets'
            return jTargets''
    result <- gtk_target_list_new maybeTargets ntargets
    checkUnexpectedReturnNULL "gtk_target_list_new" result
    result' <- (wrapBoxed TargetList) result
    whenJust targets (mapM_ touchManagedPtr)
    freeMem maybeTargets
    return result'

-- method TargetList::add
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "target", argType = TInterface "Gdk" "Atom", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "flags", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "target", argType = TInterface "Gdk" "Atom", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "flags", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_add" gtk_target_list_add :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Ptr Gdk.Atom ->                         -- target : TInterface "Gdk" "Atom"
    Word32 ->                               -- flags : TBasicType TUInt32
    Word32 ->                               -- info : TBasicType TUInt32
    IO ()


targetListAdd ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    Gdk.Atom ->                             -- target
    Word32 ->                               -- flags
    Word32 ->                               -- info
    m ()
targetListAdd _obj target flags info = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let target' = unsafeManagedPtrGetPtr target
    gtk_target_list_add _obj' target' flags info
    touchManagedPtr _obj
    touchManagedPtr target
    return ()

-- method TargetList::add_image_targets
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "writable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "writable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_add_image_targets" gtk_target_list_add_image_targets :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Word32 ->                               -- info : TBasicType TUInt32
    CInt ->                                 -- writable : TBasicType TBoolean
    IO ()


targetListAddImageTargets ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    Word32 ->                               -- info
    Bool ->                                 -- writable
    m ()
targetListAddImageTargets _obj info writable = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let writable' = (fromIntegral . fromEnum) writable
    gtk_target_list_add_image_targets _obj' info writable'
    touchManagedPtr _obj
    return ()

-- method TargetList::add_rich_text_targets
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "deserializable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "buffer", argType = TInterface "Gtk" "TextBuffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "deserializable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "buffer", argType = TInterface "Gtk" "TextBuffer", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_add_rich_text_targets" gtk_target_list_add_rich_text_targets :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Word32 ->                               -- info : TBasicType TUInt32
    CInt ->                                 -- deserializable : TBasicType TBoolean
    Ptr TextBuffer ->                       -- buffer : TInterface "Gtk" "TextBuffer"
    IO ()


targetListAddRichTextTargets ::
    (MonadIO m, TextBufferK a) =>
    TargetList ->                           -- _obj
    Word32 ->                               -- info
    Bool ->                                 -- deserializable
    a ->                                    -- buffer
    m ()
targetListAddRichTextTargets _obj info deserializable buffer = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let deserializable' = (fromIntegral . fromEnum) deserializable
    let buffer' = unsafeManagedPtrCastPtr buffer
    gtk_target_list_add_rich_text_targets _obj' info deserializable' buffer'
    touchManagedPtr _obj
    touchManagedPtr buffer
    return ()

-- method TargetList::add_table
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "targets", argType = TCArray False (-1) 2 (TInterface "Gtk" "TargetEntry"), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "ntargets", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : [Arg {argName = "ntargets", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "targets", argType = TCArray False (-1) 2 (TInterface "Gtk" "TargetEntry"), direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_add_table" gtk_target_list_add_table :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Ptr TargetEntry ->                      -- targets : TCArray False (-1) 2 (TInterface "Gtk" "TargetEntry")
    Word32 ->                               -- ntargets : TBasicType TUInt32
    IO ()


targetListAddTable ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    [TargetEntry] ->                        -- targets
    m ()
targetListAddTable _obj targets = liftIO $ do
    let ntargets = fromIntegral $ length targets
    let _obj' = unsafeManagedPtrGetPtr _obj
    let targets' = map unsafeManagedPtrGetPtr targets
    targets'' <- packBlockArray 16 targets'
    gtk_target_list_add_table _obj' targets'' ntargets
    touchManagedPtr _obj
    mapM_ touchManagedPtr targets
    freeMem targets''
    return ()

-- method TargetList::add_text_targets
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_add_text_targets" gtk_target_list_add_text_targets :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Word32 ->                               -- info : TBasicType TUInt32
    IO ()


targetListAddTextTargets ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    Word32 ->                               -- info
    m ()
targetListAddTextTargets _obj info = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    gtk_target_list_add_text_targets _obj' info
    touchManagedPtr _obj
    return ()

-- method TargetList::add_uri_targets
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_add_uri_targets" gtk_target_list_add_uri_targets :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Word32 ->                               -- info : TBasicType TUInt32
    IO ()


targetListAddUriTargets ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    Word32 ->                               -- info
    m ()
targetListAddUriTargets _obj info = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    gtk_target_list_add_uri_targets _obj' info
    touchManagedPtr _obj
    return ()

-- method TargetList::find
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "target", argType = TInterface "Gdk" "Atom", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "info", argType = TBasicType TUInt32, direction = DirectionOut, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferEverything}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "target", argType = TInterface "Gdk" "Atom", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TBoolean
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_find" gtk_target_list_find :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Ptr Gdk.Atom ->                         -- target : TInterface "Gdk" "Atom"
    Ptr Word32 ->                           -- info : TBasicType TUInt32
    IO CInt


targetListFind ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    Gdk.Atom ->                             -- target
    m (Bool,Word32)
targetListFind _obj target = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let target' = unsafeManagedPtrGetPtr target
    info <- allocMem :: IO (Ptr Word32)
    result <- gtk_target_list_find _obj' target' info
    let result' = (/= 0) result
    info' <- peek info
    touchManagedPtr _obj
    touchManagedPtr target
    freeMem info
    return (result', info')

-- method TargetList::ref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TInterface "Gtk" "TargetList"
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_ref" gtk_target_list_ref :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    IO (Ptr TargetList)


targetListRef ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    m TargetList
targetListRef _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    result <- gtk_target_list_ref _obj'
    checkUnexpectedReturnNULL "gtk_target_list_ref" result
    result' <- (wrapBoxed TargetList) result
    touchManagedPtr _obj
    return result'

-- method TargetList::remove
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "target", argType = TInterface "Gdk" "Atom", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing},Arg {argName = "target", argType = TInterface "Gdk" "Atom", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_remove" gtk_target_list_remove :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    Ptr Gdk.Atom ->                         -- target : TInterface "Gdk" "Atom"
    IO ()


targetListRemove ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    Gdk.Atom ->                             -- target
    m ()
targetListRemove _obj target = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    let target' = unsafeManagedPtrGetPtr target
    gtk_target_list_remove _obj' target'
    touchManagedPtr _obj
    touchManagedPtr target
    return ()

-- method TargetList::unref
-- method type : OrdinaryMethod
-- Args : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- Lengths : []
-- hInArgs : [Arg {argName = "_obj", argType = TInterface "Gtk" "TargetList", direction = DirectionIn, mayBeNull = False, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, transfer = TransferNothing}]
-- returnType : TBasicType TVoid
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_list_unref" gtk_target_list_unref :: 
    Ptr TargetList ->                       -- _obj : TInterface "Gtk" "TargetList"
    IO ()


targetListUnref ::
    (MonadIO m) =>
    TargetList ->                           -- _obj
    m ()
targetListUnref _obj = liftIO $ do
    let _obj' = unsafeManagedPtrGetPtr _obj
    gtk_target_list_unref _obj'
    touchManagedPtr _obj
    return ()