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

The 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' class contains the actual text displayed in a
'GI.Gtk.Objects.Entry.Entry' widget.

A single 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' object can be shared by multiple 'GI.Gtk.Objects.Entry.Entry'
widgets which will then share the same text content, but not the cursor
position, visibility attributes, icon etc.

'GI.Gtk.Objects.EntryBuffer.EntryBuffer' may be derived from. Such a derived class might allow
text to be stored in an alternate location, such as non-pageable memory,
useful in the case of important passwords. Or a derived class could
integrate with an application’s concept of undo\/redo.
-}

module GI.Gtk.Objects.EntryBuffer
    ( 

-- * Exported types
    EntryBuffer(..)                         ,
    IsEntryBuffer                           ,
    toEntryBuffer                           ,
    noEntryBuffer                           ,


 -- * Methods
-- ** deleteText #method:deleteText#
    EntryBufferDeleteTextMethodInfo         ,
    entryBufferDeleteText                   ,


-- ** emitDeletedText #method:emitDeletedText#
    EntryBufferEmitDeletedTextMethodInfo    ,
    entryBufferEmitDeletedText              ,


-- ** emitInsertedText #method:emitInsertedText#
    EntryBufferEmitInsertedTextMethodInfo   ,
    entryBufferEmitInsertedText             ,


-- ** getBytes #method:getBytes#
    EntryBufferGetBytesMethodInfo           ,
    entryBufferGetBytes                     ,


-- ** getLength #method:getLength#
    EntryBufferGetLengthMethodInfo          ,
    entryBufferGetLength                    ,


-- ** getMaxLength #method:getMaxLength#
    EntryBufferGetMaxLengthMethodInfo       ,
    entryBufferGetMaxLength                 ,


-- ** getText #method:getText#
    EntryBufferGetTextMethodInfo            ,
    entryBufferGetText                      ,


-- ** insertText #method:insertText#
    EntryBufferInsertTextMethodInfo         ,
    entryBufferInsertText                   ,


-- ** new #method:new#
    entryBufferNew                          ,


-- ** setMaxLength #method:setMaxLength#
    EntryBufferSetMaxLengthMethodInfo       ,
    entryBufferSetMaxLength                 ,


-- ** setText #method:setText#
    EntryBufferSetTextMethodInfo            ,
    entryBufferSetText                      ,




 -- * Properties
-- ** length #attr:length#
    EntryBufferLengthPropertyInfo           ,
    entryBufferLength                       ,
    getEntryBufferLength                    ,


-- ** maxLength #attr:maxLength#
    EntryBufferMaxLengthPropertyInfo        ,
    constructEntryBufferMaxLength           ,
    entryBufferMaxLength                    ,
    getEntryBufferMaxLength                 ,
    setEntryBufferMaxLength                 ,


-- ** text #attr:text#
    EntryBufferTextPropertyInfo             ,
    clearEntryBufferText                    ,
    constructEntryBufferText                ,
    entryBufferText                         ,
    getEntryBufferText                      ,
    setEntryBufferText                      ,




 -- * Signals
-- ** deletedText #signal:deletedText#
    C_EntryBufferDeletedTextCallback        ,
    EntryBufferDeletedTextCallback          ,
    EntryBufferDeletedTextSignalInfo        ,
    afterEntryBufferDeletedText             ,
    genClosure_EntryBufferDeletedText       ,
    mk_EntryBufferDeletedTextCallback       ,
    noEntryBufferDeletedTextCallback        ,
    onEntryBufferDeletedText                ,
    wrap_EntryBufferDeletedTextCallback     ,


-- ** insertedText #signal:insertedText#
    C_EntryBufferInsertedTextCallback       ,
    EntryBufferInsertedTextCallback         ,
    EntryBufferInsertedTextSignalInfo       ,
    afterEntryBufferInsertedText            ,
    genClosure_EntryBufferInsertedText      ,
    mk_EntryBufferInsertedTextCallback      ,
    noEntryBufferInsertedTextCallback       ,
    onEntryBufferInsertedText               ,
    wrap_EntryBufferInsertedTextCallback    ,




    ) 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 qualified GI.GObject.Objects.Object as GObject.Object

newtype EntryBuffer = EntryBuffer (ManagedPtr EntryBuffer)
foreign import ccall "gtk_entry_buffer_get_type"
    c_gtk_entry_buffer_get_type :: IO GType

instance GObject EntryBuffer where
    gobjectType _ = c_gtk_entry_buffer_get_type
    

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

toEntryBuffer :: IsEntryBuffer o => o -> IO EntryBuffer
toEntryBuffer = unsafeCastTo EntryBuffer

noEntryBuffer :: Maybe EntryBuffer
noEntryBuffer = Nothing

type family ResolveEntryBufferMethod (t :: Symbol) (o :: *) :: * where
    ResolveEntryBufferMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveEntryBufferMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveEntryBufferMethod "deleteText" o = EntryBufferDeleteTextMethodInfo
    ResolveEntryBufferMethod "emitDeletedText" o = EntryBufferEmitDeletedTextMethodInfo
    ResolveEntryBufferMethod "emitInsertedText" o = EntryBufferEmitInsertedTextMethodInfo
    ResolveEntryBufferMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveEntryBufferMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveEntryBufferMethod "insertText" o = EntryBufferInsertTextMethodInfo
    ResolveEntryBufferMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveEntryBufferMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveEntryBufferMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveEntryBufferMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveEntryBufferMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveEntryBufferMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveEntryBufferMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveEntryBufferMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveEntryBufferMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveEntryBufferMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveEntryBufferMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveEntryBufferMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveEntryBufferMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveEntryBufferMethod "getBytes" o = EntryBufferGetBytesMethodInfo
    ResolveEntryBufferMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveEntryBufferMethod "getLength" o = EntryBufferGetLengthMethodInfo
    ResolveEntryBufferMethod "getMaxLength" o = EntryBufferGetMaxLengthMethodInfo
    ResolveEntryBufferMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveEntryBufferMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveEntryBufferMethod "getText" o = EntryBufferGetTextMethodInfo
    ResolveEntryBufferMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveEntryBufferMethod "setMaxLength" o = EntryBufferSetMaxLengthMethodInfo
    ResolveEntryBufferMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveEntryBufferMethod "setText" o = EntryBufferSetTextMethodInfo
    ResolveEntryBufferMethod l o = O.MethodResolutionFailed l o

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

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

-- signal EntryBuffer::deleted-text
type EntryBufferDeletedTextCallback =
    Word32 ->
    Word32 ->
    IO ()

noEntryBufferDeletedTextCallback :: Maybe EntryBufferDeletedTextCallback
noEntryBufferDeletedTextCallback = Nothing

type C_EntryBufferDeletedTextCallback =
    Ptr () ->                               -- object
    Word32 ->
    Word32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_EntryBufferDeletedTextCallback :: C_EntryBufferDeletedTextCallback -> IO (FunPtr C_EntryBufferDeletedTextCallback)

genClosure_EntryBufferDeletedText :: EntryBufferDeletedTextCallback -> IO Closure
genClosure_EntryBufferDeletedText cb = do
    let cb' = wrap_EntryBufferDeletedTextCallback cb
    mk_EntryBufferDeletedTextCallback cb' >>= newCClosure


wrap_EntryBufferDeletedTextCallback ::
    EntryBufferDeletedTextCallback ->
    Ptr () ->
    Word32 ->
    Word32 ->
    Ptr () ->
    IO ()
wrap_EntryBufferDeletedTextCallback _cb _ position nChars _ = do
    _cb  position nChars


onEntryBufferDeletedText :: (GObject a, MonadIO m) => a -> EntryBufferDeletedTextCallback -> m SignalHandlerId
onEntryBufferDeletedText obj cb = liftIO $ connectEntryBufferDeletedText obj cb SignalConnectBefore
afterEntryBufferDeletedText :: (GObject a, MonadIO m) => a -> EntryBufferDeletedTextCallback -> m SignalHandlerId
afterEntryBufferDeletedText obj cb = connectEntryBufferDeletedText obj cb SignalConnectAfter

connectEntryBufferDeletedText :: (GObject a, MonadIO m) =>
                                 a -> EntryBufferDeletedTextCallback -> SignalConnectMode -> m SignalHandlerId
connectEntryBufferDeletedText obj cb after = liftIO $ do
    let cb' = wrap_EntryBufferDeletedTextCallback cb
    cb'' <- mk_EntryBufferDeletedTextCallback cb'
    connectSignalFunPtr obj "deleted-text" cb'' after

-- signal EntryBuffer::inserted-text
type EntryBufferInsertedTextCallback =
    Word32 ->
    T.Text ->
    Word32 ->
    IO ()

noEntryBufferInsertedTextCallback :: Maybe EntryBufferInsertedTextCallback
noEntryBufferInsertedTextCallback = Nothing

type C_EntryBufferInsertedTextCallback =
    Ptr () ->                               -- object
    Word32 ->
    CString ->
    Word32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_EntryBufferInsertedTextCallback :: C_EntryBufferInsertedTextCallback -> IO (FunPtr C_EntryBufferInsertedTextCallback)

genClosure_EntryBufferInsertedText :: EntryBufferInsertedTextCallback -> IO Closure
genClosure_EntryBufferInsertedText cb = do
    let cb' = wrap_EntryBufferInsertedTextCallback cb
    mk_EntryBufferInsertedTextCallback cb' >>= newCClosure


wrap_EntryBufferInsertedTextCallback ::
    EntryBufferInsertedTextCallback ->
    Ptr () ->
    Word32 ->
    CString ->
    Word32 ->
    Ptr () ->
    IO ()
wrap_EntryBufferInsertedTextCallback _cb _ position chars nChars _ = do
    chars' <- cstringToText chars
    _cb  position chars' nChars


onEntryBufferInsertedText :: (GObject a, MonadIO m) => a -> EntryBufferInsertedTextCallback -> m SignalHandlerId
onEntryBufferInsertedText obj cb = liftIO $ connectEntryBufferInsertedText obj cb SignalConnectBefore
afterEntryBufferInsertedText :: (GObject a, MonadIO m) => a -> EntryBufferInsertedTextCallback -> m SignalHandlerId
afterEntryBufferInsertedText obj cb = connectEntryBufferInsertedText obj cb SignalConnectAfter

connectEntryBufferInsertedText :: (GObject a, MonadIO m) =>
                                  a -> EntryBufferInsertedTextCallback -> SignalConnectMode -> m SignalHandlerId
connectEntryBufferInsertedText obj cb after = liftIO $ do
    let cb' = wrap_EntryBufferInsertedTextCallback cb
    cb'' <- mk_EntryBufferInsertedTextCallback cb'
    connectSignalFunPtr obj "inserted-text" cb'' after

-- VVV Prop "length"
   -- Type: TBasicType TUInt
   -- Flags: [PropertyReadable]
   -- Nullable: (Just False,Nothing)

getEntryBufferLength :: (MonadIO m, IsEntryBuffer o) => o -> m Word32
getEntryBufferLength obj = liftIO $ getObjectPropertyUInt32 obj "length"

data EntryBufferLengthPropertyInfo
instance AttrInfo EntryBufferLengthPropertyInfo where
    type AttrAllowedOps EntryBufferLengthPropertyInfo = '[ 'AttrGet]
    type AttrSetTypeConstraint EntryBufferLengthPropertyInfo = (~) ()
    type AttrBaseTypeConstraint EntryBufferLengthPropertyInfo = IsEntryBuffer
    type AttrGetType EntryBufferLengthPropertyInfo = Word32
    type AttrLabel EntryBufferLengthPropertyInfo = "length"
    type AttrOrigin EntryBufferLengthPropertyInfo = EntryBuffer
    attrGet _ = getEntryBufferLength
    attrSet _ = undefined
    attrConstruct _ = undefined
    attrClear _ = undefined

-- VVV Prop "max-length"
   -- Type: TBasicType TInt
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Just False,Just False)

getEntryBufferMaxLength :: (MonadIO m, IsEntryBuffer o) => o -> m Int32
getEntryBufferMaxLength obj = liftIO $ getObjectPropertyInt32 obj "max-length"

setEntryBufferMaxLength :: (MonadIO m, IsEntryBuffer o) => o -> Int32 -> m ()
setEntryBufferMaxLength obj val = liftIO $ setObjectPropertyInt32 obj "max-length" val

constructEntryBufferMaxLength :: (IsEntryBuffer o) => Int32 -> IO (GValueConstruct o)
constructEntryBufferMaxLength val = constructObjectPropertyInt32 "max-length" val

data EntryBufferMaxLengthPropertyInfo
instance AttrInfo EntryBufferMaxLengthPropertyInfo where
    type AttrAllowedOps EntryBufferMaxLengthPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint EntryBufferMaxLengthPropertyInfo = (~) Int32
    type AttrBaseTypeConstraint EntryBufferMaxLengthPropertyInfo = IsEntryBuffer
    type AttrGetType EntryBufferMaxLengthPropertyInfo = Int32
    type AttrLabel EntryBufferMaxLengthPropertyInfo = "max-length"
    type AttrOrigin EntryBufferMaxLengthPropertyInfo = EntryBuffer
    attrGet _ = getEntryBufferMaxLength
    attrSet _ = setEntryBufferMaxLength
    attrConstruct _ = constructEntryBufferMaxLength
    attrClear _ = undefined

-- VVV Prop "text"
   -- Type: TBasicType TUTF8
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Just False,Nothing)

getEntryBufferText :: (MonadIO m, IsEntryBuffer o) => o -> m T.Text
getEntryBufferText obj = liftIO $ checkUnexpectedNothing "getEntryBufferText" $ getObjectPropertyString obj "text"

setEntryBufferText :: (MonadIO m, IsEntryBuffer o) => o -> T.Text -> m ()
setEntryBufferText obj val = liftIO $ setObjectPropertyString obj "text" (Just val)

constructEntryBufferText :: (IsEntryBuffer o) => T.Text -> IO (GValueConstruct o)
constructEntryBufferText val = constructObjectPropertyString "text" (Just val)

clearEntryBufferText :: (MonadIO m, IsEntryBuffer o) => o -> m ()
clearEntryBufferText obj = liftIO $ setObjectPropertyString obj "text" (Nothing :: Maybe T.Text)

data EntryBufferTextPropertyInfo
instance AttrInfo EntryBufferTextPropertyInfo where
    type AttrAllowedOps EntryBufferTextPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet, 'AttrClear]
    type AttrSetTypeConstraint EntryBufferTextPropertyInfo = (~) T.Text
    type AttrBaseTypeConstraint EntryBufferTextPropertyInfo = IsEntryBuffer
    type AttrGetType EntryBufferTextPropertyInfo = T.Text
    type AttrLabel EntryBufferTextPropertyInfo = "text"
    type AttrOrigin EntryBufferTextPropertyInfo = EntryBuffer
    attrGet _ = getEntryBufferText
    attrSet _ = setEntryBufferText
    attrConstruct _ = constructEntryBufferText
    attrClear _ = clearEntryBufferText

instance O.HasAttributeList EntryBuffer
type instance O.AttributeList EntryBuffer = EntryBufferAttributeList
type EntryBufferAttributeList = ('[ '("length", EntryBufferLengthPropertyInfo), '("maxLength", EntryBufferMaxLengthPropertyInfo), '("text", EntryBufferTextPropertyInfo)] :: [(Symbol, *)])

entryBufferLength :: AttrLabelProxy "length"
entryBufferLength = AttrLabelProxy

entryBufferMaxLength :: AttrLabelProxy "maxLength"
entryBufferMaxLength = AttrLabelProxy

entryBufferText :: AttrLabelProxy "text"
entryBufferText = AttrLabelProxy

data EntryBufferDeletedTextSignalInfo
instance SignalInfo EntryBufferDeletedTextSignalInfo where
    type HaskellCallbackType EntryBufferDeletedTextSignalInfo = EntryBufferDeletedTextCallback
    connectSignal _ = connectEntryBufferDeletedText

data EntryBufferInsertedTextSignalInfo
instance SignalInfo EntryBufferInsertedTextSignalInfo where
    type HaskellCallbackType EntryBufferInsertedTextSignalInfo = EntryBufferInsertedTextCallback
    connectSignal _ = connectEntryBufferInsertedText

type instance O.SignalList EntryBuffer = EntryBufferSignalList
type EntryBufferSignalList = ('[ '("deletedText", EntryBufferDeletedTextSignalInfo), '("insertedText", EntryBufferInsertedTextSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

-- method EntryBuffer::new
-- method type : Constructor
-- Args : [Arg {argCName = "initial_chars", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "initial buffer text, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_initial_chars", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of characters in @initial_chars, or -1", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_new" gtk_entry_buffer_new :: 
    CString ->                              -- initial_chars : TBasicType TUTF8
    Int32 ->                                -- n_initial_chars : TBasicType TInt
    IO (Ptr EntryBuffer)

{- |
Create a new GtkEntryBuffer object.

Optionally, specify initial text to set in the buffer.

@since 2.18
-}
entryBufferNew ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Maybe (T.Text)
    {- ^ /@initialChars@/: initial buffer text, or 'Nothing' -}
    -> Int32
    {- ^ /@nInitialChars@/: number of characters in /@initialChars@/, or -1 -}
    -> m EntryBuffer
    {- ^ __Returns:__ A new GtkEntryBuffer object. -}
entryBufferNew initialChars nInitialChars = liftIO $ do
    maybeInitialChars <- case initialChars of
        Nothing -> return nullPtr
        Just jInitialChars -> do
            jInitialChars' <- textToCString jInitialChars
            return jInitialChars'
    result <- gtk_entry_buffer_new maybeInitialChars nInitialChars
    checkUnexpectedReturnNULL "entryBufferNew" result
    result' <- (wrapObject EntryBuffer) result
    freeMem maybeInitialChars
    return result'

-- method EntryBuffer::delete_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "position at which to delete text", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_chars", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of characters to delete", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_delete_text" gtk_entry_buffer_delete_text :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    Word32 ->                               -- position : TBasicType TUInt
    Int32 ->                                -- n_chars : TBasicType TInt
    IO Word32

{- |
Deletes a sequence of characters from the buffer. /@nChars@/ characters are
deleted starting at /@position@/. If /@nChars@/ is negative, then all characters
until the end of the text are deleted.

If /@position@/ or /@nChars@/ are out of bounds, then they are coerced to sane
values.

Note that the positions are specified in characters, not bytes.

@since 2.18
-}
entryBufferDeleteText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> Word32
    {- ^ /@position@/: position at which to delete text -}
    -> Int32
    {- ^ /@nChars@/: number of characters to delete -}
    -> m Word32
    {- ^ __Returns:__ The number of characters deleted. -}
entryBufferDeleteText buffer position nChars = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    result <- gtk_entry_buffer_delete_text buffer' position nChars
    touchManagedPtr buffer
    return result

data EntryBufferDeleteTextMethodInfo
instance (signature ~ (Word32 -> Int32 -> m Word32), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferDeleteTextMethodInfo a signature where
    overloadedMethod _ = entryBufferDeleteText

-- method EntryBuffer::emit_deleted_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "position at which text was deleted", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_chars", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of characters deleted", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_emit_deleted_text" gtk_entry_buffer_emit_deleted_text :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    Word32 ->                               -- position : TBasicType TUInt
    Word32 ->                               -- n_chars : TBasicType TUInt
    IO ()

{- |
Used when subclassing 'GI.Gtk.Objects.EntryBuffer.EntryBuffer'

@since 2.18
-}
entryBufferEmitDeletedText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> Word32
    {- ^ /@position@/: position at which text was deleted -}
    -> Word32
    {- ^ /@nChars@/: number of characters deleted -}
    -> m ()
entryBufferEmitDeletedText buffer position nChars = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    gtk_entry_buffer_emit_deleted_text buffer' position nChars
    touchManagedPtr buffer
    return ()

data EntryBufferEmitDeletedTextMethodInfo
instance (signature ~ (Word32 -> Word32 -> m ()), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferEmitDeletedTextMethodInfo a signature where
    overloadedMethod _ = entryBufferEmitDeletedText

-- method EntryBuffer::emit_inserted_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "position at which text was inserted", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "chars", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "text that was inserted", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_chars", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "number of characters inserted", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_emit_inserted_text" gtk_entry_buffer_emit_inserted_text :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    Word32 ->                               -- position : TBasicType TUInt
    CString ->                              -- chars : TBasicType TUTF8
    Word32 ->                               -- n_chars : TBasicType TUInt
    IO ()

{- |
Used when subclassing 'GI.Gtk.Objects.EntryBuffer.EntryBuffer'

@since 2.18
-}
entryBufferEmitInsertedText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> Word32
    {- ^ /@position@/: position at which text was inserted -}
    -> T.Text
    {- ^ /@chars@/: text that was inserted -}
    -> Word32
    {- ^ /@nChars@/: number of characters inserted -}
    -> m ()
entryBufferEmitInsertedText buffer position chars nChars = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    chars' <- textToCString chars
    gtk_entry_buffer_emit_inserted_text buffer' position chars' nChars
    touchManagedPtr buffer
    freeMem chars'
    return ()

data EntryBufferEmitInsertedTextMethodInfo
instance (signature ~ (Word32 -> T.Text -> Word32 -> m ()), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferEmitInsertedTextMethodInfo a signature where
    overloadedMethod _ = entryBufferEmitInsertedText

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

foreign import ccall "gtk_entry_buffer_get_bytes" gtk_entry_buffer_get_bytes :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    IO Word64

{- |
Retrieves the length in bytes of the buffer.
See 'GI.Gtk.Objects.EntryBuffer.entryBufferGetLength'.

@since 2.18
-}
entryBufferGetBytes ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> m Word64
    {- ^ __Returns:__ The byte length of the buffer. -}
entryBufferGetBytes buffer = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    result <- gtk_entry_buffer_get_bytes buffer'
    touchManagedPtr buffer
    return result

data EntryBufferGetBytesMethodInfo
instance (signature ~ (m Word64), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferGetBytesMethodInfo a signature where
    overloadedMethod _ = entryBufferGetBytes

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

foreign import ccall "gtk_entry_buffer_get_length" gtk_entry_buffer_get_length :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    IO Word32

{- |
Retrieves the length in characters of the buffer.

@since 2.18
-}
entryBufferGetLength ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> m Word32
    {- ^ __Returns:__ The number of characters in the buffer. -}
entryBufferGetLength buffer = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    result <- gtk_entry_buffer_get_length buffer'
    touchManagedPtr buffer
    return result

data EntryBufferGetLengthMethodInfo
instance (signature ~ (m Word32), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferGetLengthMethodInfo a signature where
    overloadedMethod _ = entryBufferGetLength

-- method EntryBuffer::get_max_length
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", 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 "gtk_entry_buffer_get_max_length" gtk_entry_buffer_get_max_length :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    IO Int32

{- |
Retrieves the maximum allowed length of the text in
/@buffer@/. See 'GI.Gtk.Objects.EntryBuffer.entryBufferSetMaxLength'.

@since 2.18
-}
entryBufferGetMaxLength ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> m Int32
    {- ^ __Returns:__ the maximum allowed number of characters
              in 'GI.Gtk.Objects.EntryBuffer.EntryBuffer', or 0 if there is no maximum. -}
entryBufferGetMaxLength buffer = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    result <- gtk_entry_buffer_get_max_length buffer'
    touchManagedPtr buffer
    return result

data EntryBufferGetMaxLengthMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferGetMaxLengthMethodInfo a signature where
    overloadedMethod _ = entryBufferGetMaxLength

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

foreign import ccall "gtk_entry_buffer_get_text" gtk_entry_buffer_get_text :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    IO CString

{- |
Retrieves the contents of the buffer.

The memory pointer returned by this call will not change
unless this object emits a signal, or is finalized.

@since 2.18
-}
entryBufferGetText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> m T.Text
    {- ^ __Returns:__ a pointer to the contents of the widget as a
     string. This string points to internally allocated
     storage in the buffer and must not be freed, modified or
     stored. -}
entryBufferGetText buffer = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    result <- gtk_entry_buffer_get_text buffer'
    checkUnexpectedReturnNULL "entryBufferGetText" result
    result' <- cstringToText result
    touchManagedPtr buffer
    return result'

data EntryBufferGetTextMethodInfo
instance (signature ~ (m T.Text), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferGetTextMethodInfo a signature where
    overloadedMethod _ = entryBufferGetText

-- method EntryBuffer::insert_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the position at which to insert text.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "chars", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the text to insert into the buffer.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_chars", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the length of the text in characters, or -1", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TUInt)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_insert_text" gtk_entry_buffer_insert_text :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    Word32 ->                               -- position : TBasicType TUInt
    CString ->                              -- chars : TBasicType TUTF8
    Int32 ->                                -- n_chars : TBasicType TInt
    IO Word32

{- |
Inserts /@nChars@/ characters of /@chars@/ into the contents of the
buffer, at position /@position@/.

If /@nChars@/ is negative, then characters from chars will be inserted
until a null-terminator is found. If /@position@/ or /@nChars@/ are out of
bounds, or the maximum buffer text length is exceeded, then they are
coerced to sane values.

Note that the position and length are in characters, not in bytes.

@since 2.18
-}
entryBufferInsertText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> Word32
    {- ^ /@position@/: the position at which to insert text. -}
    -> T.Text
    {- ^ /@chars@/: the text to insert into the buffer. -}
    -> Int32
    {- ^ /@nChars@/: the length of the text in characters, or -1 -}
    -> m Word32
    {- ^ __Returns:__ The number of characters actually inserted. -}
entryBufferInsertText buffer position chars nChars = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    chars' <- textToCString chars
    result <- gtk_entry_buffer_insert_text buffer' position chars' nChars
    touchManagedPtr buffer
    freeMem chars'
    return result

data EntryBufferInsertTextMethodInfo
instance (signature ~ (Word32 -> T.Text -> Int32 -> m Word32), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferInsertTextMethodInfo a signature where
    overloadedMethod _ = entryBufferInsertText

-- method EntryBuffer::set_max_length
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "max_length", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the maximum length of the entry buffer, or 0 for no maximum.\n  (other than the maximum length of entries.) The value passed in will\n  be clamped to the range 0-65536.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_set_max_length" gtk_entry_buffer_set_max_length :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    Int32 ->                                -- max_length : TBasicType TInt
    IO ()

{- |
Sets the maximum allowed length of the contents of the buffer. If
the current contents are longer than the given length, then they
will be truncated to fit.

@since 2.18
-}
entryBufferSetMaxLength ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> Int32
    {- ^ /@maxLength@/: the maximum length of the entry buffer, or 0 for no maximum.
  (other than the maximum length of entries.) The value passed in will
  be clamped to the range 0-65536. -}
    -> m ()
entryBufferSetMaxLength buffer maxLength = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    gtk_entry_buffer_set_max_length buffer' maxLength
    touchManagedPtr buffer
    return ()

data EntryBufferSetMaxLengthMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferSetMaxLengthMethodInfo a signature where
    overloadedMethod _ = entryBufferSetMaxLength

-- method EntryBuffer::set_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "buffer", argType = TInterface (Name {namespace = "Gtk", name = "EntryBuffer"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEntryBuffer", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "chars", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new text", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "n_chars", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the number of characters in @text, or -1", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_entry_buffer_set_text" gtk_entry_buffer_set_text :: 
    Ptr EntryBuffer ->                      -- buffer : TInterface (Name {namespace = "Gtk", name = "EntryBuffer"})
    CString ->                              -- chars : TBasicType TUTF8
    Int32 ->                                -- n_chars : TBasicType TInt
    IO ()

{- |
Sets the text in the buffer.

This is roughly equivalent to calling 'GI.Gtk.Objects.EntryBuffer.entryBufferDeleteText'
and 'GI.Gtk.Objects.EntryBuffer.entryBufferInsertText'.

Note that /@nChars@/ is in characters, not in bytes.

@since 2.18
-}
entryBufferSetText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEntryBuffer a) =>
    a
    {- ^ /@buffer@/: a 'GI.Gtk.Objects.EntryBuffer.EntryBuffer' -}
    -> T.Text
    {- ^ /@chars@/: the new text -}
    -> Int32
    {- ^ /@nChars@/: the number of characters in /@text@/, or -1 -}
    -> m ()
entryBufferSetText buffer chars nChars = liftIO $ do
    buffer' <- unsafeManagedPtrCastPtr buffer
    chars' <- textToCString chars
    gtk_entry_buffer_set_text buffer' chars' nChars
    touchManagedPtr buffer
    freeMem chars'
    return ()

data EntryBufferSetTextMethodInfo
instance (signature ~ (T.Text -> Int32 -> m ()), MonadIO m, IsEntryBuffer a) => O.MethodInfo EntryBufferSetTextMethodInfo a signature where
    overloadedMethod _ = entryBufferSetText