{- |
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.Interfaces.Editable.Editable' interface is an interface which should be implemented by
text editing widgets, such as 'GI.Gtk.Objects.Entry.Entry' and 'GI.Gtk.Objects.SpinButton.SpinButton'. It contains functions
for generically manipulating an editable widget, a large number of action
signals used for key bindings, and several signals that an application can
connect to to modify the behavior of a widget.

As an example of the latter usage, by connecting
the following handler to 'GI.Gtk.Interfaces.Editable.Editable'::@/insert-text/@, an application
can convert all entry into a widget into uppercase.

== Forcing entry to uppercase.


=== /C code/
>
>#include <ctype.h>;
>
>void
>insert_text_handler (GtkEditable *editable,
>                     const gchar *text,
>                     gint         length,
>                     gint        *position,
>                     gpointer     data)
>{
>  gchar *result = g_utf8_strup (text, length);
>
>  g_signal_handlers_block_by_func (editable,
>                               (gpointer) insert_text_handler, data);
>  gtk_editable_insert_text (editable, result, length, position);
>  g_signal_handlers_unblock_by_func (editable,
>                                     (gpointer) insert_text_handler, data);
>
>  g_signal_stop_emission_by_name (editable, "insert_text");
>
>  g_free (result);
>}

-}

module GI.Gtk.Interfaces.Editable
    ( 

-- * Exported types
    Editable(..)                            ,
    noEditable                              ,
    IsEditable                              ,


 -- * Methods
-- ** copyClipboard #method:copyClipboard#
    EditableCopyClipboardMethodInfo         ,
    editableCopyClipboard                   ,


-- ** cutClipboard #method:cutClipboard#
    EditableCutClipboardMethodInfo          ,
    editableCutClipboard                    ,


-- ** deleteSelection #method:deleteSelection#
    EditableDeleteSelectionMethodInfo       ,
    editableDeleteSelection                 ,


-- ** deleteText #method:deleteText#
    EditableDeleteTextMethodInfo            ,
    editableDeleteText                      ,


-- ** getChars #method:getChars#
    EditableGetCharsMethodInfo              ,
    editableGetChars                        ,


-- ** getEditable #method:getEditable#
    EditableGetEditableMethodInfo           ,
    editableGetEditable                     ,


-- ** getPosition #method:getPosition#
    EditableGetPositionMethodInfo           ,
    editableGetPosition                     ,


-- ** getSelectionBounds #method:getSelectionBounds#
    EditableGetSelectionBoundsMethodInfo    ,
    editableGetSelectionBounds              ,


-- ** insertText #method:insertText#
    EditableInsertTextMethodInfo            ,
    editableInsertText                      ,


-- ** pasteClipboard #method:pasteClipboard#
    EditablePasteClipboardMethodInfo        ,
    editablePasteClipboard                  ,


-- ** selectRegion #method:selectRegion#
    EditableSelectRegionMethodInfo          ,
    editableSelectRegion                    ,


-- ** setEditable #method:setEditable#
    EditableSetEditableMethodInfo           ,
    editableSetEditable                     ,


-- ** setPosition #method:setPosition#
    EditableSetPositionMethodInfo           ,
    editableSetPosition                     ,




 -- * Signals
-- ** changed #signal:changed#
    C_EditableChangedCallback               ,
    EditableChangedCallback                 ,
    EditableChangedSignalInfo               ,
    afterEditableChanged                    ,
    genClosure_EditableChanged              ,
    mk_EditableChangedCallback              ,
    noEditableChangedCallback               ,
    onEditableChanged                       ,
    wrap_EditableChangedCallback            ,


-- ** deleteText #signal:deleteText#
    C_EditableDeleteTextCallback            ,
    EditableDeleteTextCallback              ,
    EditableDeleteTextSignalInfo            ,
    afterEditableDeleteText                 ,
    genClosure_EditableDeleteText           ,
    mk_EditableDeleteTextCallback           ,
    noEditableDeleteTextCallback            ,
    onEditableDeleteText                    ,
    wrap_EditableDeleteTextCallback         ,


-- ** insertText #signal:insertText#
    C_EditableInsertTextCallback            ,
    EditableInsertTextCallback              ,
    EditableInsertTextSignalInfo            ,
    afterEditableInsertText                 ,
    genClosure_EditableInsertText           ,
    mk_EditableInsertTextCallback           ,
    noEditableInsertTextCallback            ,
    onEditableInsertText                    ,
    wrap_EditableInsertTextCallback         ,




    ) 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


-- interface Editable 
newtype Editable = Editable (ManagedPtr Editable)
noEditable :: Maybe Editable
noEditable = Nothing

type family ResolveEditableMethod (t :: Symbol) (o :: *) :: * where
    ResolveEditableMethod "copyClipboard" o = EditableCopyClipboardMethodInfo
    ResolveEditableMethod "cutClipboard" o = EditableCutClipboardMethodInfo
    ResolveEditableMethod "deleteSelection" o = EditableDeleteSelectionMethodInfo
    ResolveEditableMethod "deleteText" o = EditableDeleteTextMethodInfo
    ResolveEditableMethod "insertText" o = EditableInsertTextMethodInfo
    ResolveEditableMethod "pasteClipboard" o = EditablePasteClipboardMethodInfo
    ResolveEditableMethod "selectRegion" o = EditableSelectRegionMethodInfo
    ResolveEditableMethod "getChars" o = EditableGetCharsMethodInfo
    ResolveEditableMethod "getEditable" o = EditableGetEditableMethodInfo
    ResolveEditableMethod "getPosition" o = EditableGetPositionMethodInfo
    ResolveEditableMethod "getSelectionBounds" o = EditableGetSelectionBoundsMethodInfo
    ResolveEditableMethod "setEditable" o = EditableSetEditableMethodInfo
    ResolveEditableMethod "setPosition" o = EditableSetPositionMethodInfo
    ResolveEditableMethod l o = O.MethodResolutionFailed l o

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

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

-- signal Editable::changed
type EditableChangedCallback =
    IO ()

noEditableChangedCallback :: Maybe EditableChangedCallback
noEditableChangedCallback = Nothing

type C_EditableChangedCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_EditableChangedCallback :: C_EditableChangedCallback -> IO (FunPtr C_EditableChangedCallback)

genClosure_EditableChanged :: EditableChangedCallback -> IO Closure
genClosure_EditableChanged cb = do
    let cb' = wrap_EditableChangedCallback cb
    mk_EditableChangedCallback cb' >>= newCClosure


wrap_EditableChangedCallback ::
    EditableChangedCallback ->
    Ptr () ->
    Ptr () ->
    IO ()
wrap_EditableChangedCallback _cb _ _ = do
    _cb 


onEditableChanged :: (GObject a, MonadIO m) => a -> EditableChangedCallback -> m SignalHandlerId
onEditableChanged obj cb = liftIO $ connectEditableChanged obj cb SignalConnectBefore
afterEditableChanged :: (GObject a, MonadIO m) => a -> EditableChangedCallback -> m SignalHandlerId
afterEditableChanged obj cb = connectEditableChanged obj cb SignalConnectAfter

connectEditableChanged :: (GObject a, MonadIO m) =>
                          a -> EditableChangedCallback -> SignalConnectMode -> m SignalHandlerId
connectEditableChanged obj cb after = liftIO $ do
    let cb' = wrap_EditableChangedCallback cb
    cb'' <- mk_EditableChangedCallback cb'
    connectSignalFunPtr obj "changed" cb'' after

-- signal Editable::delete-text
type EditableDeleteTextCallback =
    Int32 ->
    Int32 ->
    IO ()

noEditableDeleteTextCallback :: Maybe EditableDeleteTextCallback
noEditableDeleteTextCallback = Nothing

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

foreign import ccall "wrapper"
    mk_EditableDeleteTextCallback :: C_EditableDeleteTextCallback -> IO (FunPtr C_EditableDeleteTextCallback)

genClosure_EditableDeleteText :: EditableDeleteTextCallback -> IO Closure
genClosure_EditableDeleteText cb = do
    let cb' = wrap_EditableDeleteTextCallback cb
    mk_EditableDeleteTextCallback cb' >>= newCClosure


wrap_EditableDeleteTextCallback ::
    EditableDeleteTextCallback ->
    Ptr () ->
    Int32 ->
    Int32 ->
    Ptr () ->
    IO ()
wrap_EditableDeleteTextCallback _cb _ startPos endPos _ = do
    _cb  startPos endPos


onEditableDeleteText :: (GObject a, MonadIO m) => a -> EditableDeleteTextCallback -> m SignalHandlerId
onEditableDeleteText obj cb = liftIO $ connectEditableDeleteText obj cb SignalConnectBefore
afterEditableDeleteText :: (GObject a, MonadIO m) => a -> EditableDeleteTextCallback -> m SignalHandlerId
afterEditableDeleteText obj cb = connectEditableDeleteText obj cb SignalConnectAfter

connectEditableDeleteText :: (GObject a, MonadIO m) =>
                             a -> EditableDeleteTextCallback -> SignalConnectMode -> m SignalHandlerId
connectEditableDeleteText obj cb after = liftIO $ do
    let cb' = wrap_EditableDeleteTextCallback cb
    cb'' <- mk_EditableDeleteTextCallback cb'
    connectSignalFunPtr obj "delete-text" cb'' after

-- signal Editable::insert-text
type EditableInsertTextCallback =
    T.Text ->
    Int32 ->
    Int32 ->
    IO (Int32)

noEditableInsertTextCallback :: Maybe EditableInsertTextCallback
noEditableInsertTextCallback = Nothing

type C_EditableInsertTextCallback =
    Ptr () ->                               -- object
    CString ->
    Int32 ->
    Ptr Int32 ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_EditableInsertTextCallback :: C_EditableInsertTextCallback -> IO (FunPtr C_EditableInsertTextCallback)

genClosure_EditableInsertText :: EditableInsertTextCallback -> IO Closure
genClosure_EditableInsertText cb = do
    let cb' = wrap_EditableInsertTextCallback cb
    mk_EditableInsertTextCallback cb' >>= newCClosure


wrap_EditableInsertTextCallback ::
    EditableInsertTextCallback ->
    Ptr () ->
    CString ->
    Int32 ->
    Ptr Int32 ->
    Ptr () ->
    IO ()
wrap_EditableInsertTextCallback _cb _ newText newTextLength position _ = do
    newText' <- cstringToText newText
    position' <- peek position
    outposition <- _cb  newText' newTextLength position'
    poke position outposition


onEditableInsertText :: (GObject a, MonadIO m) => a -> EditableInsertTextCallback -> m SignalHandlerId
onEditableInsertText obj cb = liftIO $ connectEditableInsertText obj cb SignalConnectBefore
afterEditableInsertText :: (GObject a, MonadIO m) => a -> EditableInsertTextCallback -> m SignalHandlerId
afterEditableInsertText obj cb = connectEditableInsertText obj cb SignalConnectAfter

connectEditableInsertText :: (GObject a, MonadIO m) =>
                             a -> EditableInsertTextCallback -> SignalConnectMode -> m SignalHandlerId
connectEditableInsertText obj cb after = liftIO $ do
    let cb' = wrap_EditableInsertTextCallback cb
    cb'' <- mk_EditableInsertTextCallback cb'
    connectSignalFunPtr obj "insert-text" cb'' after

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

data EditableChangedSignalInfo
instance SignalInfo EditableChangedSignalInfo where
    type HaskellCallbackType EditableChangedSignalInfo = EditableChangedCallback
    connectSignal _ = connectEditableChanged

data EditableDeleteTextSignalInfo
instance SignalInfo EditableDeleteTextSignalInfo where
    type HaskellCallbackType EditableDeleteTextSignalInfo = EditableDeleteTextCallback
    connectSignal _ = connectEditableDeleteText

data EditableInsertTextSignalInfo
instance SignalInfo EditableInsertTextSignalInfo where
    type HaskellCallbackType EditableInsertTextSignalInfo = EditableInsertTextCallback
    connectSignal _ = connectEditableInsertText

type instance O.SignalList Editable = EditableSignalList
type EditableSignalList = ('[ '("changed", EditableChangedSignalInfo), '("deleteText", EditableDeleteTextSignalInfo), '("insertText", EditableInsertTextSignalInfo)] :: [(Symbol, *)])

class ManagedPtrNewtype a => IsEditable a
instance IsEditable Editable
-- XXX Wrapping a foreign struct/union with no known destructor or size, leak?
instance WrappedPtr Editable where
    wrappedPtrCalloc = return nullPtr
    wrappedPtrCopy = return
    wrappedPtrFree = Nothing


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

foreign import ccall "gtk_editable_copy_clipboard" gtk_editable_copy_clipboard :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    IO ()

{- |
Copies the contents of the currently selected content in the editable and
puts it on the clipboard.
-}
editableCopyClipboard ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m ()
editableCopyClipboard editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_copy_clipboard editable'
    touchManagedPtr editable
    return ()

data EditableCopyClipboardMethodInfo
instance (signature ~ (m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableCopyClipboardMethodInfo a signature where
    overloadedMethod _ = editableCopyClipboard

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

foreign import ccall "gtk_editable_cut_clipboard" gtk_editable_cut_clipboard :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    IO ()

{- |
Removes the contents of the currently selected content in the editable and
puts it on the clipboard.
-}
editableCutClipboard ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m ()
editableCutClipboard editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_cut_clipboard editable'
    touchManagedPtr editable
    return ()

data EditableCutClipboardMethodInfo
instance (signature ~ (m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableCutClipboardMethodInfo a signature where
    overloadedMethod _ = editableCutClipboard

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

foreign import ccall "gtk_editable_delete_selection" gtk_editable_delete_selection :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    IO ()

{- |
Deletes the currently selected text of the editable.
This call doesn’t do anything if there is no selected text.
-}
editableDeleteSelection ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m ()
editableDeleteSelection editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_delete_selection editable'
    touchManagedPtr editable
    return ()

data EditableDeleteSelectionMethodInfo
instance (signature ~ (m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableDeleteSelectionMethodInfo a signature where
    overloadedMethod _ = editableDeleteSelection

-- method Editable::delete_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "start_pos", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "start position", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "end_pos", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "end position", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_editable_delete_text" gtk_editable_delete_text :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    Int32 ->                                -- start_pos : TBasicType TInt
    Int32 ->                                -- end_pos : TBasicType TInt
    IO ()

{- |
Deletes a sequence of characters. The characters that are deleted are
those characters at positions from /@startPos@/ up to, but not including
/@endPos@/. If /@endPos@/ is negative, then the characters deleted
are those from /@startPos@/ to the end of the text.

Note that the positions are specified in characters, not bytes.
-}
editableDeleteText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> Int32
    {- ^ /@startPos@/: start position -}
    -> Int32
    {- ^ /@endPos@/: end position -}
    -> m ()
editableDeleteText editable startPos endPos = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_delete_text editable' startPos endPos
    touchManagedPtr editable
    return ()

data EditableDeleteTextMethodInfo
instance (signature ~ (Int32 -> Int32 -> m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableDeleteTextMethodInfo a signature where
    overloadedMethod _ = editableDeleteText

-- method Editable::get_chars
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "start_pos", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "start of text", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "end_pos", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "end of text", 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_editable_get_chars" gtk_editable_get_chars :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    Int32 ->                                -- start_pos : TBasicType TInt
    Int32 ->                                -- end_pos : TBasicType TInt
    IO CString

{- |
Retrieves a sequence of characters. The characters that are retrieved
are those characters at positions from /@startPos@/ up to, but not
including /@endPos@/. If /@endPos@/ is negative, then the characters
retrieved are those characters from /@startPos@/ to the end of the text.

Note that positions are specified in characters, not bytes.
-}
editableGetChars ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> Int32
    {- ^ /@startPos@/: start of text -}
    -> Int32
    {- ^ /@endPos@/: end of text -}
    -> m T.Text
    {- ^ __Returns:__ a pointer to the contents of the widget as a
     string. This string is allocated by the 'GI.Gtk.Interfaces.Editable.Editable'
     implementation and should be freed by the caller. -}
editableGetChars editable startPos endPos = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    result <- gtk_editable_get_chars editable' startPos endPos
    checkUnexpectedReturnNULL "editableGetChars" result
    result' <- cstringToText result
    freeMem result
    touchManagedPtr editable
    return result'

data EditableGetCharsMethodInfo
instance (signature ~ (Int32 -> Int32 -> m T.Text), MonadIO m, IsEditable a) => O.MethodInfo EditableGetCharsMethodInfo a signature where
    overloadedMethod _ = editableGetChars

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

foreign import ccall "gtk_editable_get_editable" gtk_editable_get_editable :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    IO CInt

{- |
Retrieves whether /@editable@/ is editable. See
'GI.Gtk.Interfaces.Editable.editableSetEditable'.
-}
editableGetEditable ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m Bool
    {- ^ __Returns:__ 'True' if /@editable@/ is editable. -}
editableGetEditable editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    result <- gtk_editable_get_editable editable'
    let result' = (/= 0) result
    touchManagedPtr editable
    return result'

data EditableGetEditableMethodInfo
instance (signature ~ (m Bool), MonadIO m, IsEditable a) => O.MethodInfo EditableGetEditableMethodInfo a signature where
    overloadedMethod _ = editableGetEditable

-- method Editable::get_position
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", 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_editable_get_position" gtk_editable_get_position :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    IO Int32

{- |
Retrieves the current position of the cursor relative to the start
of the content of the editable.

Note that this position is in characters, not in bytes.
-}
editableGetPosition ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m Int32
    {- ^ __Returns:__ the cursor position -}
editableGetPosition editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    result <- gtk_editable_get_position editable'
    touchManagedPtr editable
    return result

data EditableGetPositionMethodInfo
instance (signature ~ (m Int32), MonadIO m, IsEditable a) => O.MethodInfo EditableGetPositionMethodInfo a signature where
    overloadedMethod _ = editableGetPosition

-- method Editable::get_selection_bounds
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "start_pos", argType = TBasicType TInt, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store the starting position, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "end_pos", argType = TBasicType TInt, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store the end position, or %NULL", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_editable_get_selection_bounds" gtk_editable_get_selection_bounds :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    Ptr Int32 ->                            -- start_pos : TBasicType TInt
    Ptr Int32 ->                            -- end_pos : TBasicType TInt
    IO CInt

{- |
Retrieves the selection bound of the editable. start_pos will be filled
with the start of the selection and /@endPos@/ with end. If no text was
selected both will be identical and 'False' will be returned.

Note that positions are specified in characters, not bytes.
-}
editableGetSelectionBounds ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m (Bool,Int32,Int32)
    {- ^ __Returns:__ 'True' if an area is selected, 'False' otherwise -}
editableGetSelectionBounds editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    startPos <- allocMem :: IO (Ptr Int32)
    endPos <- allocMem :: IO (Ptr Int32)
    result <- gtk_editable_get_selection_bounds editable' startPos endPos
    let result' = (/= 0) result
    startPos' <- peek startPos
    endPos' <- peek endPos
    touchManagedPtr editable
    freeMem startPos
    freeMem endPos
    return (result', startPos', endPos')

data EditableGetSelectionBoundsMethodInfo
instance (signature ~ (m (Bool,Int32,Int32)), MonadIO m, IsEditable a) => O.MethodInfo EditableGetSelectionBoundsMethodInfo a signature where
    overloadedMethod _ = editableGetSelectionBounds

-- method Editable::insert_text
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "new_text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the text to append", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "new_text_length", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the length of the text in bytes, or -1", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TBasicType TInt, direction = DirectionInout, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location of the position text will be inserted at", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_editable_insert_text" gtk_editable_insert_text :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    CString ->                              -- new_text : TBasicType TUTF8
    Int32 ->                                -- new_text_length : TBasicType TInt
    Ptr Int32 ->                            -- position : TBasicType TInt
    IO ()

{- |
Inserts /@newTextLength@/ bytes of /@newText@/ into the contents of the
widget, at position /@position@/.

Note that the position is in characters, not in bytes.
The function updates /@position@/ to point after the newly inserted text.
-}
editableInsertText ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> T.Text
    {- ^ /@newText@/: the text to append -}
    -> Int32
    {- ^ /@newTextLength@/: the length of the text in bytes, or -1 -}
    -> Int32
    {- ^ /@position@/: location of the position text will be inserted at -}
    -> m (Int32)
editableInsertText editable newText newTextLength position = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    newText' <- textToCString newText
    position' <- allocMem :: IO (Ptr Int32)
    poke position' position
    gtk_editable_insert_text editable' newText' newTextLength position'
    position'' <- peek position'
    touchManagedPtr editable
    freeMem newText'
    freeMem position'
    return position''

data EditableInsertTextMethodInfo
instance (signature ~ (T.Text -> Int32 -> Int32 -> m (Int32)), MonadIO m, IsEditable a) => O.MethodInfo EditableInsertTextMethodInfo a signature where
    overloadedMethod _ = editableInsertText

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

foreign import ccall "gtk_editable_paste_clipboard" gtk_editable_paste_clipboard :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    IO ()

{- |
Pastes the content of the clipboard to the current position of the
cursor in the editable.
-}
editablePasteClipboard ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> m ()
editablePasteClipboard editable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_paste_clipboard editable'
    touchManagedPtr editable
    return ()

data EditablePasteClipboardMethodInfo
instance (signature ~ (m ()), MonadIO m, IsEditable a) => O.MethodInfo EditablePasteClipboardMethodInfo a signature where
    overloadedMethod _ = editablePasteClipboard

-- method Editable::select_region
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "start_pos", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "start of region", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "end_pos", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "end of region", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_editable_select_region" gtk_editable_select_region :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    Int32 ->                                -- start_pos : TBasicType TInt
    Int32 ->                                -- end_pos : TBasicType TInt
    IO ()

{- |
Selects a region of text. The characters that are selected are
those characters at positions from /@startPos@/ up to, but not
including /@endPos@/. If /@endPos@/ is negative, then the
characters selected are those characters from /@startPos@/ to
the end of the text.

Note that positions are specified in characters, not bytes.
-}
editableSelectRegion ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> Int32
    {- ^ /@startPos@/: start of region -}
    -> Int32
    {- ^ /@endPos@/: end of region -}
    -> m ()
editableSelectRegion editable startPos endPos = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_select_region editable' startPos endPos
    touchManagedPtr editable
    return ()

data EditableSelectRegionMethodInfo
instance (signature ~ (Int32 -> Int32 -> m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableSelectRegionMethodInfo a signature where
    overloadedMethod _ = editableSelectRegion

-- method Editable::set_editable
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "is_editable", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "%TRUE if the user is allowed to edit the text\n  in the widget", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_editable_set_editable" gtk_editable_set_editable :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    CInt ->                                 -- is_editable : TBasicType TBoolean
    IO ()

{- |
Determines if the user can edit the text in the editable
widget or not.
-}
editableSetEditable ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> Bool
    {- ^ /@isEditable@/: 'True' if the user is allowed to edit the text
  in the widget -}
    -> m ()
editableSetEditable editable isEditable = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    let isEditable' = (fromIntegral . fromEnum) isEditable
    gtk_editable_set_editable editable' isEditable'
    touchManagedPtr editable
    return ()

data EditableSetEditableMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableSetEditableMethodInfo a signature where
    overloadedMethod _ = editableSetEditable

-- method Editable::set_position
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "editable", argType = TInterface (Name {namespace = "Gtk", name = "Editable"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkEditable", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "position", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the position of the cursor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_editable_set_position" gtk_editable_set_position :: 
    Ptr Editable ->                         -- editable : TInterface (Name {namespace = "Gtk", name = "Editable"})
    Int32 ->                                -- position : TBasicType TInt
    IO ()

{- |
Sets the cursor position in the editable to the given value.

The cursor is displayed before the character with the given (base 0)
index in the contents of the editable. The value must be less than or
equal to the number of characters in the editable. A value of -1
indicates that the position should be set after the last character
of the editable. Note that /@position@/ is in characters, not in bytes.
-}
editableSetPosition ::
    (B.CallStack.HasCallStack, MonadIO m, IsEditable a) =>
    a
    {- ^ /@editable@/: a 'GI.Gtk.Interfaces.Editable.Editable' -}
    -> Int32
    {- ^ /@position@/: the position of the cursor -}
    -> m ()
editableSetPosition editable position = liftIO $ do
    editable' <- unsafeManagedPtrCastPtr editable
    gtk_editable_set_position editable' position
    touchManagedPtr editable
    return ()

data EditableSetPositionMethodInfo
instance (signature ~ (Int32 -> m ()), MonadIO m, IsEditable a) => O.MethodInfo EditableSetPositionMethodInfo a signature where
    overloadedMethod _ = editableSetPosition