{- |
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 'GI.Gtk.Structs.TargetEntry.TargetEntry' represents a single type of
data than can be supplied for by a widget for a selection
or for supplied or received during drag-and-drop.
-}

module GI.Gtk.Structs.TargetEntry
    ( 

-- * Exported types
    TargetEntry(..)                         ,
    newZeroTargetEntry                      ,
    noTargetEntry                           ,


 -- * Methods
-- ** copy #method:copy#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    TargetEntryCopyMethodInfo               ,
#endif
    targetEntryCopy                         ,


-- ** free #method:free#
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    TargetEntryFreeMethodInfo               ,
#endif
    targetEntryFree                         ,


-- ** new #method:new#
    targetEntryNew                          ,




 -- * Properties
-- ** flags #attr:flags#
    getTargetEntryFlags                     ,
    setTargetEntryFlags                     ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    targetEntry_flags                       ,
#endif


-- ** info #attr:info#
    getTargetEntryInfo                      ,
    setTargetEntryInfo                      ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    targetEntry_info                        ,
#endif


-- ** target #attr:target#
    clearTargetEntryTarget                  ,
    getTargetEntryTarget                    ,
    setTargetEntryTarget                    ,
#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
    targetEntry_target                      ,
#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.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


newtype TargetEntry = TargetEntry (ManagedPtr TargetEntry)
foreign import ccall "gtk_target_entry_get_type" c_gtk_target_entry_get_type :: 
    IO GType

instance BoxedObject TargetEntry where
    boxedType _ = c_gtk_target_entry_get_type

-- | Construct a `TargetEntry` struct initialized to zero.
newZeroTargetEntry :: MonadIO m => m TargetEntry
newZeroTargetEntry = liftIO $ callocBoxedBytes 16 >>= wrapBoxed TargetEntry

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


noTargetEntry :: Maybe TargetEntry
noTargetEntry = Nothing

getTargetEntryTarget :: MonadIO m => TargetEntry -> m (Maybe T.Text)
getTargetEntryTarget s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 0) :: IO CString
    result <- SP.convertIfNonNull val $ \val' -> do
        val'' <- cstringToText val'
        return val''
    return result

setTargetEntryTarget :: MonadIO m => TargetEntry -> CString -> m ()
setTargetEntryTarget s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (val :: CString)

clearTargetEntryTarget :: MonadIO m => TargetEntry -> m ()
clearTargetEntryTarget s = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 0) (FP.nullPtr :: CString)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TargetEntryTargetFieldInfo
instance AttrInfo TargetEntryTargetFieldInfo where
    type AttrAllowedOps TargetEntryTargetFieldInfo = '[ 'AttrSet, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint TargetEntryTargetFieldInfo = (~) CString
    type AttrBaseTypeConstraint TargetEntryTargetFieldInfo = (~) TargetEntry
    type AttrGetType TargetEntryTargetFieldInfo = Maybe T.Text
    type AttrLabel TargetEntryTargetFieldInfo = "target"
    type AttrOrigin TargetEntryTargetFieldInfo = TargetEntry
    attrGet _ = getTargetEntryTarget
    attrSet _ = setTargetEntryTarget
    attrConstruct = undefined
    attrClear _ = clearTargetEntryTarget

targetEntry_target :: AttrLabelProxy "target"
targetEntry_target = AttrLabelProxy

#endif


getTargetEntryFlags :: MonadIO m => TargetEntry -> m Word32
getTargetEntryFlags s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 8) :: IO Word32
    return val

setTargetEntryFlags :: MonadIO m => TargetEntry -> Word32 -> m ()
setTargetEntryFlags s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 8) (val :: Word32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TargetEntryFlagsFieldInfo
instance AttrInfo TargetEntryFlagsFieldInfo where
    type AttrAllowedOps TargetEntryFlagsFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint TargetEntryFlagsFieldInfo = (~) Word32
    type AttrBaseTypeConstraint TargetEntryFlagsFieldInfo = (~) TargetEntry
    type AttrGetType TargetEntryFlagsFieldInfo = Word32
    type AttrLabel TargetEntryFlagsFieldInfo = "flags"
    type AttrOrigin TargetEntryFlagsFieldInfo = TargetEntry
    attrGet _ = getTargetEntryFlags
    attrSet _ = setTargetEntryFlags
    attrConstruct = undefined
    attrClear _ = undefined

targetEntry_flags :: AttrLabelProxy "flags"
targetEntry_flags = AttrLabelProxy

#endif


getTargetEntryInfo :: MonadIO m => TargetEntry -> m Word32
getTargetEntryInfo s = liftIO $ withManagedPtr s $ \ptr -> do
    val <- peek (ptr `plusPtr` 12) :: IO Word32
    return val

setTargetEntryInfo :: MonadIO m => TargetEntry -> Word32 -> m ()
setTargetEntryInfo s val = liftIO $ withManagedPtr s $ \ptr -> do
    poke (ptr `plusPtr` 12) (val :: Word32)

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TargetEntryInfoFieldInfo
instance AttrInfo TargetEntryInfoFieldInfo where
    type AttrAllowedOps TargetEntryInfoFieldInfo = '[ 'AttrSet, 'AttrGet]
    type AttrSetTypeConstraint TargetEntryInfoFieldInfo = (~) Word32
    type AttrBaseTypeConstraint TargetEntryInfoFieldInfo = (~) TargetEntry
    type AttrGetType TargetEntryInfoFieldInfo = Word32
    type AttrLabel TargetEntryInfoFieldInfo = "info"
    type AttrOrigin TargetEntryInfoFieldInfo = TargetEntry
    attrGet _ = getTargetEntryInfo
    attrSet _ = setTargetEntryInfo
    attrConstruct = undefined
    attrClear _ = undefined

targetEntry_info :: AttrLabelProxy "info"
targetEntry_info = AttrLabelProxy

#endif



#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
instance O.HasAttributeList TargetEntry
type instance O.AttributeList TargetEntry = TargetEntryAttributeList
type TargetEntryAttributeList = ('[ '("target", TargetEntryTargetFieldInfo), '("flags", TargetEntryFlagsFieldInfo), '("info", TargetEntryInfoFieldInfo)] :: [(Symbol, *)])
#endif

-- method TargetEntry::new
-- method type : Constructor
-- Args : [Arg {argCName = "target", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "String identifier for target", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "flags", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "Set of flags, see #GtkTargetFlags", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "info", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "an ID that will be passed back to the application", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gtk", name = "TargetEntry"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_target_entry_new" gtk_target_entry_new :: 
    CString ->                              -- target : TBasicType TUTF8
    Word32 ->                               -- flags : TBasicType TUInt
    Word32 ->                               -- info : TBasicType TUInt
    IO (Ptr TargetEntry)

{- |
Makes a new 'GI.Gtk.Structs.TargetEntry.TargetEntry'.
-}
targetEntryNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@target@/: String identifier for target -}
    -> Word32
    {- ^ /@flags@/: Set of flags, see 'GI.Gtk.Flags.TargetFlags' -}
    -> Word32
    {- ^ /@info@/: an ID that will be passed back to the application -}
    -> m TargetEntry
    {- ^ __Returns:__ a pointer to a new 'GI.Gtk.Structs.TargetEntry.TargetEntry'.
    Free with 'GI.Gtk.Structs.TargetEntry.targetEntryFree' -}
targetEntryNew target flags info = liftIO $ do
    target' <- textToCString target
    result <- gtk_target_entry_new target' flags info
    checkUnexpectedReturnNULL "targetEntryNew" result
    result' <- (wrapBoxed TargetEntry) result
    freeMem target'
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
#endif

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

foreign import ccall "gtk_target_entry_copy" gtk_target_entry_copy :: 
    Ptr TargetEntry ->                      -- data : TInterface (Name {namespace = "Gtk", name = "TargetEntry"})
    IO (Ptr TargetEntry)

{- |
Makes a copy of a 'GI.Gtk.Structs.TargetEntry.TargetEntry' and its data.
-}
targetEntryCopy ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    TargetEntry
    {- ^ /@data@/: a pointer to a 'GI.Gtk.Structs.TargetEntry.TargetEntry' -}
    -> m TargetEntry
    {- ^ __Returns:__ a pointer to a copy of /@data@/.
    Free with 'GI.Gtk.Structs.TargetEntry.targetEntryFree' -}
targetEntryCopy data_ = liftIO $ do
    data_' <- unsafeManagedPtrGetPtr data_
    result <- gtk_target_entry_copy data_'
    checkUnexpectedReturnNULL "targetEntryCopy" result
    result' <- (wrapBoxed TargetEntry) result
    touchManagedPtr data_
    return result'

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TargetEntryCopyMethodInfo
instance (signature ~ (m TargetEntry), MonadIO m) => O.MethodInfo TargetEntryCopyMethodInfo TargetEntry signature where
    overloadedMethod _ = targetEntryCopy

#endif

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

foreign import ccall "gtk_target_entry_free" gtk_target_entry_free :: 
    Ptr TargetEntry ->                      -- data : TInterface (Name {namespace = "Gtk", name = "TargetEntry"})
    IO ()

{- |
Frees a 'GI.Gtk.Structs.TargetEntry.TargetEntry' returned from
'GI.Gtk.Structs.TargetEntry.targetEntryNew' or 'GI.Gtk.Structs.TargetEntry.targetEntryCopy'.
-}
targetEntryFree ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    TargetEntry
    {- ^ /@data@/: a pointer to a 'GI.Gtk.Structs.TargetEntry.TargetEntry'. -}
    -> m ()
targetEntryFree data_ = liftIO $ do
    data_' <- unsafeManagedPtrGetPtr data_
    gtk_target_entry_free data_'
    touchManagedPtr data_
    return ()

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
data TargetEntryFreeMethodInfo
instance (signature ~ (m ()), MonadIO m) => O.MethodInfo TargetEntryFreeMethodInfo TargetEntry signature where
    overloadedMethod _ = targetEntryFree

#endif

#if defined(ENABLE_OVERLOADING) && !defined(__HADDOCK_VERSION__)
type family ResolveTargetEntryMethod (t :: Symbol) (o :: *) :: * where
    ResolveTargetEntryMethod "copy" o = TargetEntryCopyMethodInfo
    ResolveTargetEntryMethod "free" o = TargetEntryFreeMethodInfo
    ResolveTargetEntryMethod l o = O.MethodResolutionFailed l o

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

#if MIN_VERSION_base(4,9,0)
instance (info ~ ResolveTargetEntryMethod t TargetEntry, O.MethodInfo info TargetEntry p) => O.IsLabel t (TargetEntry -> 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

#endif