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

'GI.Gtk.Objects.IMContext.IMContext' defines the interface for GTK+ input methods. An input method
is used by GTK+ text input widgets like 'GI.Gtk.Objects.Entry.Entry' to map from key events to
Unicode character strings.

The default input method can be set programmatically via the
'GI.Gtk.Objects.Settings.Settings':@/gtk-im-module/@ GtkSettings property. Alternatively, you may set
the GTK_IM_MODULE environment variable as documented in
[Running GTK+ Applications][gtk-running].

The 'GI.Gtk.Objects.Entry.Entry' 'GI.Gtk.Objects.Entry.Entry':@/im-module/@ and 'GI.Gtk.Objects.TextView.TextView' 'GI.Gtk.Objects.TextView.TextView':@/im-module/@
properties may also be used to set input methods for specific widget
instances. For instance, a certain entry widget might be expected to contain
certain characters which would be easier to input with a certain input
method.

An input method may consume multiple key events in sequence and finally
output the composed result. This is called preediting, and an input method
may provide feedback about this process by displaying the intermediate
composition states as preedit text. For instance, the default GTK+ input
method implements the input of arbitrary Unicode code points by holding down
the Control and Shift keys and then typing “U” followed by the hexadecimal
digits of the code point.  When releasing the Control and Shift keys,
preediting ends and the character is inserted as text. Ctrl+Shift+u20AC for
example results in the € sign.

Additional input methods can be made available for use by GTK+ widgets as
loadable modules. An input method module is a small shared library which
implements a subclass of 'GI.Gtk.Objects.IMContext.IMContext' or 'GI.Gtk.Objects.IMContextSimple.IMContextSimple' and exports
these four functions:


=== /C code/
>
>void im_module_init(GTypeModule *module);

This function should register the 'GType' of the 'GI.Gtk.Objects.IMContext.IMContext' subclass which
implements the input method by means of 'GI.GObject.Objects.TypeModule.typeModuleRegisterType'. Note
that 'GI.GObject.Functions.typeRegisterStatic' cannot be used as the type needs to be
registered dynamically.


=== /C code/
>
>void im_module_exit(void);

Here goes any cleanup code your input method might require on module unload.


=== /C code/
>
>void im_module_list(const GtkIMContextInfo ***contexts, int *n_contexts)
>{
>  *contexts = info_list;
>  *n_contexts = G_N_ELEMENTS (info_list);
>}

This function returns the list of input methods provided by the module. The
example implementation above shows a common solution and simply returns a
pointer to statically defined array of 'GI.Gtk.Structs.IMContextInfo.IMContextInfo' items for each
provided input method.


=== /C code/
>
>GtkIMContext * im_module_create(const gchar *context_id);

This function should return a pointer to a newly created instance of the
'GI.Gtk.Objects.IMContext.IMContext' subclass identified by /@contextId@/. The context ID is the same
as specified in the 'GI.Gtk.Structs.IMContextInfo.IMContextInfo' array returned by @/im_module_list()/@.

After a new loadable input method module has been installed on the system,
the configuration file @gtk.immodules@ needs to be
regenerated by [gtk-query-immodules-3.0][gtk-query-immodules-3.0],
in order for the new input method to become available to GTK+ applications.
-}

module GI.Gtk.Objects.IMContext
    ( 

-- * Exported types
    IMContext(..)                           ,
    IsIMContext                             ,
    toIMContext                             ,
    noIMContext                             ,


 -- * Methods
-- ** deleteSurrounding #method:deleteSurrounding#
    IMContextDeleteSurroundingMethodInfo    ,
    iMContextDeleteSurrounding              ,


-- ** filterKeypress #method:filterKeypress#
    IMContextFilterKeypressMethodInfo       ,
    iMContextFilterKeypress                 ,


-- ** focusIn #method:focusIn#
    IMContextFocusInMethodInfo              ,
    iMContextFocusIn                        ,


-- ** focusOut #method:focusOut#
    IMContextFocusOutMethodInfo             ,
    iMContextFocusOut                       ,


-- ** getPreeditString #method:getPreeditString#
    IMContextGetPreeditStringMethodInfo     ,
    iMContextGetPreeditString               ,


-- ** getSurrounding #method:getSurrounding#
    IMContextGetSurroundingMethodInfo       ,
    iMContextGetSurrounding                 ,


-- ** reset #method:reset#
    IMContextResetMethodInfo                ,
    iMContextReset                          ,


-- ** setClientWindow #method:setClientWindow#
    IMContextSetClientWindowMethodInfo      ,
    iMContextSetClientWindow                ,


-- ** setCursorLocation #method:setCursorLocation#
    IMContextSetCursorLocationMethodInfo    ,
    iMContextSetCursorLocation              ,


-- ** setSurrounding #method:setSurrounding#
    IMContextSetSurroundingMethodInfo       ,
    iMContextSetSurrounding                 ,


-- ** setUsePreedit #method:setUsePreedit#
    IMContextSetUsePreeditMethodInfo        ,
    iMContextSetUsePreedit                  ,




 -- * Properties
-- ** inputHints #attr:inputHints#
    IMContextInputHintsPropertyInfo         ,
    constructIMContextInputHints            ,
    getIMContextInputHints                  ,
    iMContextInputHints                     ,
    setIMContextInputHints                  ,


-- ** inputPurpose #attr:inputPurpose#
    IMContextInputPurposePropertyInfo       ,
    constructIMContextInputPurpose          ,
    getIMContextInputPurpose                ,
    iMContextInputPurpose                   ,
    setIMContextInputPurpose                ,




 -- * Signals
-- ** commit #signal:commit#
    C_IMContextCommitCallback               ,
    IMContextCommitCallback                 ,
    IMContextCommitSignalInfo               ,
    afterIMContextCommit                    ,
    genClosure_IMContextCommit              ,
    mk_IMContextCommitCallback              ,
    noIMContextCommitCallback               ,
    onIMContextCommit                       ,
    wrap_IMContextCommitCallback            ,


-- ** deleteSurrounding #signal:deleteSurrounding#
    C_IMContextDeleteSurroundingCallback    ,
    IMContextDeleteSurroundingCallback      ,
    IMContextDeleteSurroundingSignalInfo    ,
    afterIMContextDeleteSurrounding         ,
    genClosure_IMContextDeleteSurrounding   ,
    mk_IMContextDeleteSurroundingCallback   ,
    noIMContextDeleteSurroundingCallback    ,
    onIMContextDeleteSurrounding            ,
    wrap_IMContextDeleteSurroundingCallback ,


-- ** preeditChanged #signal:preeditChanged#
    C_IMContextPreeditChangedCallback       ,
    IMContextPreeditChangedCallback         ,
    IMContextPreeditChangedSignalInfo       ,
    afterIMContextPreeditChanged            ,
    genClosure_IMContextPreeditChanged      ,
    mk_IMContextPreeditChangedCallback      ,
    noIMContextPreeditChangedCallback       ,
    onIMContextPreeditChanged               ,
    wrap_IMContextPreeditChangedCallback    ,


-- ** preeditEnd #signal:preeditEnd#
    C_IMContextPreeditEndCallback           ,
    IMContextPreeditEndCallback             ,
    IMContextPreeditEndSignalInfo           ,
    afterIMContextPreeditEnd                ,
    genClosure_IMContextPreeditEnd          ,
    mk_IMContextPreeditEndCallback          ,
    noIMContextPreeditEndCallback           ,
    onIMContextPreeditEnd                   ,
    wrap_IMContextPreeditEndCallback        ,


-- ** preeditStart #signal:preeditStart#
    C_IMContextPreeditStartCallback         ,
    IMContextPreeditStartCallback           ,
    IMContextPreeditStartSignalInfo         ,
    afterIMContextPreeditStart              ,
    genClosure_IMContextPreeditStart        ,
    mk_IMContextPreeditStartCallback        ,
    noIMContextPreeditStartCallback         ,
    onIMContextPreeditStart                 ,
    wrap_IMContextPreeditStartCallback      ,


-- ** retrieveSurrounding #signal:retrieveSurrounding#
    C_IMContextRetrieveSurroundingCallback  ,
    IMContextRetrieveSurroundingCallback    ,
    IMContextRetrieveSurroundingSignalInfo  ,
    afterIMContextRetrieveSurrounding       ,
    genClosure_IMContextRetrieveSurrounding ,
    mk_IMContextRetrieveSurroundingCallback ,
    noIMContextRetrieveSurroundingCallback  ,
    onIMContextRetrieveSurrounding          ,
    wrap_IMContextRetrieveSurroundingCallback,




    ) 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
import qualified GI.Gdk.Objects.Window as Gdk.Window
import qualified GI.Gdk.Structs.EventKey as Gdk.EventKey
import qualified GI.Gdk.Structs.Rectangle as Gdk.Rectangle
import {-# SOURCE #-} qualified GI.Gtk.Enums as Gtk.Enums
import {-# SOURCE #-} qualified GI.Gtk.Flags as Gtk.Flags
import qualified GI.Pango.Structs.AttrList as Pango.AttrList

newtype IMContext = IMContext (ManagedPtr IMContext)
foreign import ccall "gtk_im_context_get_type"
    c_gtk_im_context_get_type :: IO GType

instance GObject IMContext where
    gobjectType _ = c_gtk_im_context_get_type
    

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

toIMContext :: IsIMContext o => o -> IO IMContext
toIMContext = unsafeCastTo IMContext

noIMContext :: Maybe IMContext
noIMContext = Nothing

type family ResolveIMContextMethod (t :: Symbol) (o :: *) :: * where
    ResolveIMContextMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveIMContextMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveIMContextMethod "deleteSurrounding" o = IMContextDeleteSurroundingMethodInfo
    ResolveIMContextMethod "filterKeypress" o = IMContextFilterKeypressMethodInfo
    ResolveIMContextMethod "focusIn" o = IMContextFocusInMethodInfo
    ResolveIMContextMethod "focusOut" o = IMContextFocusOutMethodInfo
    ResolveIMContextMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveIMContextMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveIMContextMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveIMContextMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveIMContextMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveIMContextMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveIMContextMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveIMContextMethod "replaceData" o = GObject.Object.ObjectReplaceDataMethodInfo
    ResolveIMContextMethod "replaceQdata" o = GObject.Object.ObjectReplaceQdataMethodInfo
    ResolveIMContextMethod "reset" o = IMContextResetMethodInfo
    ResolveIMContextMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveIMContextMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveIMContextMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveIMContextMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveIMContextMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveIMContextMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveIMContextMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveIMContextMethod "getPreeditString" o = IMContextGetPreeditStringMethodInfo
    ResolveIMContextMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveIMContextMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveIMContextMethod "getSurrounding" o = IMContextGetSurroundingMethodInfo
    ResolveIMContextMethod "setClientWindow" o = IMContextSetClientWindowMethodInfo
    ResolveIMContextMethod "setCursorLocation" o = IMContextSetCursorLocationMethodInfo
    ResolveIMContextMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveIMContextMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveIMContextMethod "setSurrounding" o = IMContextSetSurroundingMethodInfo
    ResolveIMContextMethod "setUsePreedit" o = IMContextSetUsePreeditMethodInfo
    ResolveIMContextMethod l o = O.MethodResolutionFailed l o

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

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

-- signal IMContext::commit
type IMContextCommitCallback =
    T.Text ->
    IO ()

noIMContextCommitCallback :: Maybe IMContextCommitCallback
noIMContextCommitCallback = Nothing

type C_IMContextCommitCallback =
    Ptr () ->                               -- object
    CString ->
    Ptr () ->                               -- user_data
    IO ()

foreign import ccall "wrapper"
    mk_IMContextCommitCallback :: C_IMContextCommitCallback -> IO (FunPtr C_IMContextCommitCallback)

genClosure_IMContextCommit :: IMContextCommitCallback -> IO Closure
genClosure_IMContextCommit cb = do
    let cb' = wrap_IMContextCommitCallback cb
    mk_IMContextCommitCallback cb' >>= newCClosure


wrap_IMContextCommitCallback ::
    IMContextCommitCallback ->
    Ptr () ->
    CString ->
    Ptr () ->
    IO ()
wrap_IMContextCommitCallback _cb _ str _ = do
    str' <- cstringToText str
    _cb  str'


onIMContextCommit :: (GObject a, MonadIO m) => a -> IMContextCommitCallback -> m SignalHandlerId
onIMContextCommit obj cb = liftIO $ connectIMContextCommit obj cb SignalConnectBefore
afterIMContextCommit :: (GObject a, MonadIO m) => a -> IMContextCommitCallback -> m SignalHandlerId
afterIMContextCommit obj cb = connectIMContextCommit obj cb SignalConnectAfter

connectIMContextCommit :: (GObject a, MonadIO m) =>
                          a -> IMContextCommitCallback -> SignalConnectMode -> m SignalHandlerId
connectIMContextCommit obj cb after = liftIO $ do
    let cb' = wrap_IMContextCommitCallback cb
    cb'' <- mk_IMContextCommitCallback cb'
    connectSignalFunPtr obj "commit" cb'' after

-- signal IMContext::delete-surrounding
type IMContextDeleteSurroundingCallback =
    Int32 ->
    Int32 ->
    IO Bool

noIMContextDeleteSurroundingCallback :: Maybe IMContextDeleteSurroundingCallback
noIMContextDeleteSurroundingCallback = Nothing

type C_IMContextDeleteSurroundingCallback =
    Ptr () ->                               -- object
    Int32 ->
    Int32 ->
    Ptr () ->                               -- user_data
    IO CInt

foreign import ccall "wrapper"
    mk_IMContextDeleteSurroundingCallback :: C_IMContextDeleteSurroundingCallback -> IO (FunPtr C_IMContextDeleteSurroundingCallback)

genClosure_IMContextDeleteSurrounding :: IMContextDeleteSurroundingCallback -> IO Closure
genClosure_IMContextDeleteSurrounding cb = do
    let cb' = wrap_IMContextDeleteSurroundingCallback cb
    mk_IMContextDeleteSurroundingCallback cb' >>= newCClosure


wrap_IMContextDeleteSurroundingCallback ::
    IMContextDeleteSurroundingCallback ->
    Ptr () ->
    Int32 ->
    Int32 ->
    Ptr () ->
    IO CInt
wrap_IMContextDeleteSurroundingCallback _cb _ offset nChars _ = do
    result <- _cb  offset nChars
    let result' = (fromIntegral . fromEnum) result
    return result'


onIMContextDeleteSurrounding :: (GObject a, MonadIO m) => a -> IMContextDeleteSurroundingCallback -> m SignalHandlerId
onIMContextDeleteSurrounding obj cb = liftIO $ connectIMContextDeleteSurrounding obj cb SignalConnectBefore
afterIMContextDeleteSurrounding :: (GObject a, MonadIO m) => a -> IMContextDeleteSurroundingCallback -> m SignalHandlerId
afterIMContextDeleteSurrounding obj cb = connectIMContextDeleteSurrounding obj cb SignalConnectAfter

connectIMContextDeleteSurrounding :: (GObject a, MonadIO m) =>
                                     a -> IMContextDeleteSurroundingCallback -> SignalConnectMode -> m SignalHandlerId
connectIMContextDeleteSurrounding obj cb after = liftIO $ do
    let cb' = wrap_IMContextDeleteSurroundingCallback cb
    cb'' <- mk_IMContextDeleteSurroundingCallback cb'
    connectSignalFunPtr obj "delete-surrounding" cb'' after

-- signal IMContext::preedit-changed
type IMContextPreeditChangedCallback =
    IO ()

noIMContextPreeditChangedCallback :: Maybe IMContextPreeditChangedCallback
noIMContextPreeditChangedCallback = Nothing

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

foreign import ccall "wrapper"
    mk_IMContextPreeditChangedCallback :: C_IMContextPreeditChangedCallback -> IO (FunPtr C_IMContextPreeditChangedCallback)

genClosure_IMContextPreeditChanged :: IMContextPreeditChangedCallback -> IO Closure
genClosure_IMContextPreeditChanged cb = do
    let cb' = wrap_IMContextPreeditChangedCallback cb
    mk_IMContextPreeditChangedCallback cb' >>= newCClosure


wrap_IMContextPreeditChangedCallback ::
    IMContextPreeditChangedCallback ->
    Ptr () ->
    Ptr () ->
    IO ()
wrap_IMContextPreeditChangedCallback _cb _ _ = do
    _cb 


onIMContextPreeditChanged :: (GObject a, MonadIO m) => a -> IMContextPreeditChangedCallback -> m SignalHandlerId
onIMContextPreeditChanged obj cb = liftIO $ connectIMContextPreeditChanged obj cb SignalConnectBefore
afterIMContextPreeditChanged :: (GObject a, MonadIO m) => a -> IMContextPreeditChangedCallback -> m SignalHandlerId
afterIMContextPreeditChanged obj cb = connectIMContextPreeditChanged obj cb SignalConnectAfter

connectIMContextPreeditChanged :: (GObject a, MonadIO m) =>
                                  a -> IMContextPreeditChangedCallback -> SignalConnectMode -> m SignalHandlerId
connectIMContextPreeditChanged obj cb after = liftIO $ do
    let cb' = wrap_IMContextPreeditChangedCallback cb
    cb'' <- mk_IMContextPreeditChangedCallback cb'
    connectSignalFunPtr obj "preedit-changed" cb'' after

-- signal IMContext::preedit-end
type IMContextPreeditEndCallback =
    IO ()

noIMContextPreeditEndCallback :: Maybe IMContextPreeditEndCallback
noIMContextPreeditEndCallback = Nothing

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

foreign import ccall "wrapper"
    mk_IMContextPreeditEndCallback :: C_IMContextPreeditEndCallback -> IO (FunPtr C_IMContextPreeditEndCallback)

genClosure_IMContextPreeditEnd :: IMContextPreeditEndCallback -> IO Closure
genClosure_IMContextPreeditEnd cb = do
    let cb' = wrap_IMContextPreeditEndCallback cb
    mk_IMContextPreeditEndCallback cb' >>= newCClosure


wrap_IMContextPreeditEndCallback ::
    IMContextPreeditEndCallback ->
    Ptr () ->
    Ptr () ->
    IO ()
wrap_IMContextPreeditEndCallback _cb _ _ = do
    _cb 


onIMContextPreeditEnd :: (GObject a, MonadIO m) => a -> IMContextPreeditEndCallback -> m SignalHandlerId
onIMContextPreeditEnd obj cb = liftIO $ connectIMContextPreeditEnd obj cb SignalConnectBefore
afterIMContextPreeditEnd :: (GObject a, MonadIO m) => a -> IMContextPreeditEndCallback -> m SignalHandlerId
afterIMContextPreeditEnd obj cb = connectIMContextPreeditEnd obj cb SignalConnectAfter

connectIMContextPreeditEnd :: (GObject a, MonadIO m) =>
                              a -> IMContextPreeditEndCallback -> SignalConnectMode -> m SignalHandlerId
connectIMContextPreeditEnd obj cb after = liftIO $ do
    let cb' = wrap_IMContextPreeditEndCallback cb
    cb'' <- mk_IMContextPreeditEndCallback cb'
    connectSignalFunPtr obj "preedit-end" cb'' after

-- signal IMContext::preedit-start
type IMContextPreeditStartCallback =
    IO ()

noIMContextPreeditStartCallback :: Maybe IMContextPreeditStartCallback
noIMContextPreeditStartCallback = Nothing

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

foreign import ccall "wrapper"
    mk_IMContextPreeditStartCallback :: C_IMContextPreeditStartCallback -> IO (FunPtr C_IMContextPreeditStartCallback)

genClosure_IMContextPreeditStart :: IMContextPreeditStartCallback -> IO Closure
genClosure_IMContextPreeditStart cb = do
    let cb' = wrap_IMContextPreeditStartCallback cb
    mk_IMContextPreeditStartCallback cb' >>= newCClosure


wrap_IMContextPreeditStartCallback ::
    IMContextPreeditStartCallback ->
    Ptr () ->
    Ptr () ->
    IO ()
wrap_IMContextPreeditStartCallback _cb _ _ = do
    _cb 


onIMContextPreeditStart :: (GObject a, MonadIO m) => a -> IMContextPreeditStartCallback -> m SignalHandlerId
onIMContextPreeditStart obj cb = liftIO $ connectIMContextPreeditStart obj cb SignalConnectBefore
afterIMContextPreeditStart :: (GObject a, MonadIO m) => a -> IMContextPreeditStartCallback -> m SignalHandlerId
afterIMContextPreeditStart obj cb = connectIMContextPreeditStart obj cb SignalConnectAfter

connectIMContextPreeditStart :: (GObject a, MonadIO m) =>
                                a -> IMContextPreeditStartCallback -> SignalConnectMode -> m SignalHandlerId
connectIMContextPreeditStart obj cb after = liftIO $ do
    let cb' = wrap_IMContextPreeditStartCallback cb
    cb'' <- mk_IMContextPreeditStartCallback cb'
    connectSignalFunPtr obj "preedit-start" cb'' after

-- signal IMContext::retrieve-surrounding
type IMContextRetrieveSurroundingCallback =
    IO Bool

noIMContextRetrieveSurroundingCallback :: Maybe IMContextRetrieveSurroundingCallback
noIMContextRetrieveSurroundingCallback = Nothing

type C_IMContextRetrieveSurroundingCallback =
    Ptr () ->                               -- object
    Ptr () ->                               -- user_data
    IO CInt

foreign import ccall "wrapper"
    mk_IMContextRetrieveSurroundingCallback :: C_IMContextRetrieveSurroundingCallback -> IO (FunPtr C_IMContextRetrieveSurroundingCallback)

genClosure_IMContextRetrieveSurrounding :: IMContextRetrieveSurroundingCallback -> IO Closure
genClosure_IMContextRetrieveSurrounding cb = do
    let cb' = wrap_IMContextRetrieveSurroundingCallback cb
    mk_IMContextRetrieveSurroundingCallback cb' >>= newCClosure


wrap_IMContextRetrieveSurroundingCallback ::
    IMContextRetrieveSurroundingCallback ->
    Ptr () ->
    Ptr () ->
    IO CInt
wrap_IMContextRetrieveSurroundingCallback _cb _ _ = do
    result <- _cb 
    let result' = (fromIntegral . fromEnum) result
    return result'


onIMContextRetrieveSurrounding :: (GObject a, MonadIO m) => a -> IMContextRetrieveSurroundingCallback -> m SignalHandlerId
onIMContextRetrieveSurrounding obj cb = liftIO $ connectIMContextRetrieveSurrounding obj cb SignalConnectBefore
afterIMContextRetrieveSurrounding :: (GObject a, MonadIO m) => a -> IMContextRetrieveSurroundingCallback -> m SignalHandlerId
afterIMContextRetrieveSurrounding obj cb = connectIMContextRetrieveSurrounding obj cb SignalConnectAfter

connectIMContextRetrieveSurrounding :: (GObject a, MonadIO m) =>
                                       a -> IMContextRetrieveSurroundingCallback -> SignalConnectMode -> m SignalHandlerId
connectIMContextRetrieveSurrounding obj cb after = liftIO $ do
    let cb' = wrap_IMContextRetrieveSurroundingCallback cb
    cb'' <- mk_IMContextRetrieveSurroundingCallback cb'
    connectSignalFunPtr obj "retrieve-surrounding" cb'' after

-- VVV Prop "input-hints"
   -- Type: TInterface (Name {namespace = "Gtk", name = "InputHints"})
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Nothing,Nothing)

getIMContextInputHints :: (MonadIO m, IsIMContext o) => o -> m [Gtk.Flags.InputHints]
getIMContextInputHints obj = liftIO $ getObjectPropertyFlags obj "input-hints"

setIMContextInputHints :: (MonadIO m, IsIMContext o) => o -> [Gtk.Flags.InputHints] -> m ()
setIMContextInputHints obj val = liftIO $ setObjectPropertyFlags obj "input-hints" val

constructIMContextInputHints :: (IsIMContext o) => [Gtk.Flags.InputHints] -> IO (GValueConstruct o)
constructIMContextInputHints val = constructObjectPropertyFlags "input-hints" val

data IMContextInputHintsPropertyInfo
instance AttrInfo IMContextInputHintsPropertyInfo where
    type AttrAllowedOps IMContextInputHintsPropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint IMContextInputHintsPropertyInfo = (~) [Gtk.Flags.InputHints]
    type AttrBaseTypeConstraint IMContextInputHintsPropertyInfo = IsIMContext
    type AttrGetType IMContextInputHintsPropertyInfo = [Gtk.Flags.InputHints]
    type AttrLabel IMContextInputHintsPropertyInfo = "input-hints"
    type AttrOrigin IMContextInputHintsPropertyInfo = IMContext
    attrGet _ = getIMContextInputHints
    attrSet _ = setIMContextInputHints
    attrConstruct _ = constructIMContextInputHints
    attrClear _ = undefined

-- VVV Prop "input-purpose"
   -- Type: TInterface (Name {namespace = "Gtk", name = "InputPurpose"})
   -- Flags: [PropertyReadable,PropertyWritable]
   -- Nullable: (Nothing,Nothing)

getIMContextInputPurpose :: (MonadIO m, IsIMContext o) => o -> m Gtk.Enums.InputPurpose
getIMContextInputPurpose obj = liftIO $ getObjectPropertyEnum obj "input-purpose"

setIMContextInputPurpose :: (MonadIO m, IsIMContext o) => o -> Gtk.Enums.InputPurpose -> m ()
setIMContextInputPurpose obj val = liftIO $ setObjectPropertyEnum obj "input-purpose" val

constructIMContextInputPurpose :: (IsIMContext o) => Gtk.Enums.InputPurpose -> IO (GValueConstruct o)
constructIMContextInputPurpose val = constructObjectPropertyEnum "input-purpose" val

data IMContextInputPurposePropertyInfo
instance AttrInfo IMContextInputPurposePropertyInfo where
    type AttrAllowedOps IMContextInputPurposePropertyInfo = '[ 'AttrSet, 'AttrConstruct, 'AttrGet]
    type AttrSetTypeConstraint IMContextInputPurposePropertyInfo = (~) Gtk.Enums.InputPurpose
    type AttrBaseTypeConstraint IMContextInputPurposePropertyInfo = IsIMContext
    type AttrGetType IMContextInputPurposePropertyInfo = Gtk.Enums.InputPurpose
    type AttrLabel IMContextInputPurposePropertyInfo = "input-purpose"
    type AttrOrigin IMContextInputPurposePropertyInfo = IMContext
    attrGet _ = getIMContextInputPurpose
    attrSet _ = setIMContextInputPurpose
    attrConstruct _ = constructIMContextInputPurpose
    attrClear _ = undefined

instance O.HasAttributeList IMContext
type instance O.AttributeList IMContext = IMContextAttributeList
type IMContextAttributeList = ('[ '("inputHints", IMContextInputHintsPropertyInfo), '("inputPurpose", IMContextInputPurposePropertyInfo)] :: [(Symbol, *)])

iMContextInputHints :: AttrLabelProxy "inputHints"
iMContextInputHints = AttrLabelProxy

iMContextInputPurpose :: AttrLabelProxy "inputPurpose"
iMContextInputPurpose = AttrLabelProxy

data IMContextCommitSignalInfo
instance SignalInfo IMContextCommitSignalInfo where
    type HaskellCallbackType IMContextCommitSignalInfo = IMContextCommitCallback
    connectSignal _ = connectIMContextCommit

data IMContextDeleteSurroundingSignalInfo
instance SignalInfo IMContextDeleteSurroundingSignalInfo where
    type HaskellCallbackType IMContextDeleteSurroundingSignalInfo = IMContextDeleteSurroundingCallback
    connectSignal _ = connectIMContextDeleteSurrounding

data IMContextPreeditChangedSignalInfo
instance SignalInfo IMContextPreeditChangedSignalInfo where
    type HaskellCallbackType IMContextPreeditChangedSignalInfo = IMContextPreeditChangedCallback
    connectSignal _ = connectIMContextPreeditChanged

data IMContextPreeditEndSignalInfo
instance SignalInfo IMContextPreeditEndSignalInfo where
    type HaskellCallbackType IMContextPreeditEndSignalInfo = IMContextPreeditEndCallback
    connectSignal _ = connectIMContextPreeditEnd

data IMContextPreeditStartSignalInfo
instance SignalInfo IMContextPreeditStartSignalInfo where
    type HaskellCallbackType IMContextPreeditStartSignalInfo = IMContextPreeditStartCallback
    connectSignal _ = connectIMContextPreeditStart

data IMContextRetrieveSurroundingSignalInfo
instance SignalInfo IMContextRetrieveSurroundingSignalInfo where
    type HaskellCallbackType IMContextRetrieveSurroundingSignalInfo = IMContextRetrieveSurroundingCallback
    connectSignal _ = connectIMContextRetrieveSurrounding

type instance O.SignalList IMContext = IMContextSignalList
type IMContextSignalList = ('[ '("commit", IMContextCommitSignalInfo), '("deleteSurrounding", IMContextDeleteSurroundingSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo), '("preeditChanged", IMContextPreeditChangedSignalInfo), '("preeditEnd", IMContextPreeditEndSignalInfo), '("preeditStart", IMContextPreeditStartSignalInfo), '("retrieveSurrounding", IMContextRetrieveSurroundingSignalInfo)] :: [(Symbol, *)])

-- method IMContext::delete_surrounding
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "offset", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "offset from cursor position in chars;\n   a negative value means start before the cursor.", 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 TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_im_context_delete_surrounding" gtk_im_context_delete_surrounding :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    Int32 ->                                -- offset : TBasicType TInt
    Int32 ->                                -- n_chars : TBasicType TInt
    IO CInt

{- |
Asks the widget that the input context is attached to to delete
characters around the cursor position by emitting the
GtkIMContext::delete_surrounding signal. Note that /@offset@/ and /@nChars@/
are in characters not in bytes which differs from the usage other
places in 'GI.Gtk.Objects.IMContext.IMContext'.

In order to use this function, you should first call
'GI.Gtk.Objects.IMContext.iMContextGetSurrounding' to get the current context, and
call this function immediately afterwards to make sure that you
know what you are deleting. You should also account for the fact
that even if the signal was handled, the input context might not
have deleted all the characters that were requested to be deleted.

This function is used by an input method that wants to make
subsitutions in the existing text in response to new input. It is
not useful for applications.
-}
iMContextDeleteSurrounding ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> Int32
    {- ^ /@offset@/: offset from cursor position in chars;
   a negative value means start before the cursor. -}
    -> Int32
    {- ^ /@nChars@/: number of characters to delete. -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the signal was handled. -}
iMContextDeleteSurrounding context offset nChars = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    result <- gtk_im_context_delete_surrounding context' offset nChars
    let result' = (/= 0) result
    touchManagedPtr context
    return result'

data IMContextDeleteSurroundingMethodInfo
instance (signature ~ (Int32 -> Int32 -> m Bool), MonadIO m, IsIMContext a) => O.MethodInfo IMContextDeleteSurroundingMethodInfo a signature where
    overloadedMethod _ = iMContextDeleteSurrounding

-- method IMContext::filter_keypress
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "event", argType = TInterface (Name {namespace = "Gdk", name = "EventKey"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the key event", 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_im_context_filter_keypress" gtk_im_context_filter_keypress :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    Ptr Gdk.EventKey.EventKey ->            -- event : TInterface (Name {namespace = "Gdk", name = "EventKey"})
    IO CInt

{- |
Allow an input method to internally handle key press and release
events. If this function returns 'True', then no further processing
should be done for this key event.
-}
iMContextFilterKeypress ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> Gdk.EventKey.EventKey
    {- ^ /@event@/: the key event -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the input method handled the key event. -}
iMContextFilterKeypress context event = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    event' <- unsafeManagedPtrGetPtr event
    result <- gtk_im_context_filter_keypress context' event'
    let result' = (/= 0) result
    touchManagedPtr context
    touchManagedPtr event
    return result'

data IMContextFilterKeypressMethodInfo
instance (signature ~ (Gdk.EventKey.EventKey -> m Bool), MonadIO m, IsIMContext a) => O.MethodInfo IMContextFilterKeypressMethodInfo a signature where
    overloadedMethod _ = iMContextFilterKeypress

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

foreign import ccall "gtk_im_context_focus_in" gtk_im_context_focus_in :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    IO ()

{- |
Notify the input method that the widget to which this
input context corresponds has gained focus. The input method
may, for example, change the displayed feedback to reflect
this change.
-}
iMContextFocusIn ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> m ()
iMContextFocusIn context = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    gtk_im_context_focus_in context'
    touchManagedPtr context
    return ()

data IMContextFocusInMethodInfo
instance (signature ~ (m ()), MonadIO m, IsIMContext a) => O.MethodInfo IMContextFocusInMethodInfo a signature where
    overloadedMethod _ = iMContextFocusIn

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

foreign import ccall "gtk_im_context_focus_out" gtk_im_context_focus_out :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    IO ()

{- |
Notify the input method that the widget to which this
input context corresponds has lost focus. The input method
may, for example, change the displayed feedback or reset the contexts
state to reflect this change.
-}
iMContextFocusOut ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> m ()
iMContextFocusOut context = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    gtk_im_context_focus_out context'
    touchManagedPtr context
    return ()

data IMContextFocusOutMethodInfo
instance (signature ~ (m ()), MonadIO m, IsIMContext a) => O.MethodInfo IMContextFocusOutMethodInfo a signature where
    overloadedMethod _ = iMContextFocusOut

-- method IMContext::get_preedit_string
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "str", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store the retrieved\n             string. The string retrieved must be freed with g_free().", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "attrs", argType = TInterface (Name {namespace = "Pango", name = "AttrList"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store the retrieved\n             attribute list.  When you are done with this list, you\n             must unreference it with pango_attr_list_unref().", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "cursor_pos", argType = TBasicType TInt, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store position of cursor (in characters)\n             within the preedit string.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_im_context_get_preedit_string" gtk_im_context_get_preedit_string :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    Ptr CString ->                          -- str : TBasicType TUTF8
    Ptr (Ptr Pango.AttrList.AttrList) ->    -- attrs : TInterface (Name {namespace = "Pango", name = "AttrList"})
    Ptr Int32 ->                            -- cursor_pos : TBasicType TInt
    IO ()

{- |
Retrieve the current preedit string for the input context,
and a list of attributes to apply to the string.
This string should be displayed inserted at the insertion
point.
-}
iMContextGetPreeditString ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> m (T.Text,Pango.AttrList.AttrList,Int32)
iMContextGetPreeditString context = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    str <- allocMem :: IO (Ptr CString)
    attrs <- allocMem :: IO (Ptr (Ptr Pango.AttrList.AttrList))
    cursorPos <- allocMem :: IO (Ptr Int32)
    gtk_im_context_get_preedit_string context' str attrs cursorPos
    str' <- peek str
    str'' <- cstringToText str'
    freeMem str'
    attrs' <- peek attrs
    attrs'' <- (wrapBoxed Pango.AttrList.AttrList) attrs'
    cursorPos' <- peek cursorPos
    touchManagedPtr context
    freeMem str
    freeMem attrs
    freeMem cursorPos
    return (str'', attrs'', cursorPos')

data IMContextGetPreeditStringMethodInfo
instance (signature ~ (m (T.Text,Pango.AttrList.AttrList,Int32)), MonadIO m, IsIMContext a) => O.MethodInfo IMContextGetPreeditStringMethodInfo a signature where
    overloadedMethod _ = iMContextGetPreeditString

-- method IMContext::get_surrounding
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "text", argType = TBasicType TUTF8, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store a UTF-8 encoded\n       string of text holding context around the insertion point.\n       If the function returns %TRUE, then you must free the result\n       stored in this location with g_free().", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferEverything},Arg {argCName = "cursor_index", argType = TBasicType TInt, direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "location to store byte index of the insertion\n       cursor within @text.", 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_im_context_get_surrounding" gtk_im_context_get_surrounding :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    Ptr CString ->                          -- text : TBasicType TUTF8
    Ptr Int32 ->                            -- cursor_index : TBasicType TInt
    IO CInt

{- |
Retrieves context around the insertion point. Input methods
typically want context in order to constrain input text based on
existing text; this is important for languages such as Thai where
only some sequences of characters are allowed.

This function is implemented by emitting the
GtkIMContext::retrieve_surrounding signal on the input method; in
response to this signal, a widget should provide as much context as
is available, up to an entire paragraph, by calling
'GI.Gtk.Objects.IMContext.iMContextSetSurrounding'. Note that there is no obligation
for a widget to respond to the ::retrieve_surrounding signal, so input
methods must be prepared to function without context.
-}
iMContextGetSurrounding ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> m (Bool,T.Text,Int32)
    {- ^ __Returns:__ 'True' if surrounding text was provided; in this case
   you must free the result stored in *text. -}
iMContextGetSurrounding context = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    text <- allocMem :: IO (Ptr CString)
    cursorIndex <- allocMem :: IO (Ptr Int32)
    result <- gtk_im_context_get_surrounding context' text cursorIndex
    let result' = (/= 0) result
    text' <- peek text
    text'' <- cstringToText text'
    freeMem text'
    cursorIndex' <- peek cursorIndex
    touchManagedPtr context
    freeMem text
    freeMem cursorIndex
    return (result', text'', cursorIndex')

data IMContextGetSurroundingMethodInfo
instance (signature ~ (m (Bool,T.Text,Int32)), MonadIO m, IsIMContext a) => O.MethodInfo IMContextGetSurroundingMethodInfo a signature where
    overloadedMethod _ = iMContextGetSurrounding

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

foreign import ccall "gtk_im_context_reset" gtk_im_context_reset :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    IO ()

{- |
Notify the input method that a change such as a change in cursor
position has been made. This will typically cause the input
method to clear the preedit state.
-}
iMContextReset ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> m ()
iMContextReset context = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    gtk_im_context_reset context'
    touchManagedPtr context
    return ()

data IMContextResetMethodInfo
instance (signature ~ (m ()), MonadIO m, IsIMContext a) => O.MethodInfo IMContextResetMethodInfo a signature where
    overloadedMethod _ = iMContextReset

-- method IMContext::set_client_window
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "window", argType = TInterface (Name {namespace = "Gdk", name = "Window"}), direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "the client window. This may be %NULL to indicate\n          that the previous client window no longer exists.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_im_context_set_client_window" gtk_im_context_set_client_window :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    Ptr Gdk.Window.Window ->                -- window : TInterface (Name {namespace = "Gdk", name = "Window"})
    IO ()

{- |
Set the client window for the input context; this is the
'GI.Gdk.Objects.Window.Window' in which the input appears. This window is
used in order to correctly position status windows, and may
also be used for purposes internal to the input method.
-}
iMContextSetClientWindow ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a, Gdk.Window.IsWindow b) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> Maybe (b)
    {- ^ /@window@/: the client window. This may be 'Nothing' to indicate
          that the previous client window no longer exists. -}
    -> m ()
iMContextSetClientWindow context window = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    maybeWindow <- case window of
        Nothing -> return nullPtr
        Just jWindow -> do
            jWindow' <- unsafeManagedPtrCastPtr jWindow
            return jWindow'
    gtk_im_context_set_client_window context' maybeWindow
    touchManagedPtr context
    whenJust window touchManagedPtr
    return ()

data IMContextSetClientWindowMethodInfo
instance (signature ~ (Maybe (b) -> m ()), MonadIO m, IsIMContext a, Gdk.Window.IsWindow b) => O.MethodInfo IMContextSetClientWindowMethodInfo a signature where
    overloadedMethod _ = iMContextSetClientWindow

-- method IMContext::set_cursor_location
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "area", argType = TInterface (Name {namespace = "Gdk", name = "Rectangle"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "new location", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_im_context_set_cursor_location" gtk_im_context_set_cursor_location :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    Ptr Gdk.Rectangle.Rectangle ->          -- area : TInterface (Name {namespace = "Gdk", name = "Rectangle"})
    IO ()

{- |
Notify the input method that a change in cursor
position has been made. The location is relative to the client
window.
-}
iMContextSetCursorLocation ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> Gdk.Rectangle.Rectangle
    {- ^ /@area@/: new location -}
    -> m ()
iMContextSetCursorLocation context area = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    area' <- unsafeManagedPtrGetPtr area
    gtk_im_context_set_cursor_location context' area'
    touchManagedPtr context
    touchManagedPtr area
    return ()

data IMContextSetCursorLocationMethodInfo
instance (signature ~ (Gdk.Rectangle.Rectangle -> m ()), MonadIO m, IsIMContext a) => O.MethodInfo IMContextSetCursorLocationMethodInfo a signature where
    overloadedMethod _ = iMContextSetCursorLocation

-- method IMContext::set_surrounding
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "text", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "text surrounding the insertion point, as UTF-8.\n       the preedit string should not be included within\n       @text.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "len", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the length of @text, or -1 if @text is nul-terminated", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "cursor_index", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the byte index of the insertion cursor within @text.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_im_context_set_surrounding" gtk_im_context_set_surrounding :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    CString ->                              -- text : TBasicType TUTF8
    Int32 ->                                -- len : TBasicType TInt
    Int32 ->                                -- cursor_index : TBasicType TInt
    IO ()

{- |
Sets surrounding context around the insertion point and preedit
string. This function is expected to be called in response to the
GtkIMContext::retrieve_surrounding signal, and will likely have no
effect if called at other times.
-}
iMContextSetSurrounding ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> T.Text
    {- ^ /@text@/: text surrounding the insertion point, as UTF-8.
       the preedit string should not be included within
       /@text@/. -}
    -> Int32
    {- ^ /@len@/: the length of /@text@/, or -1 if /@text@/ is nul-terminated -}
    -> Int32
    {- ^ /@cursorIndex@/: the byte index of the insertion cursor within /@text@/. -}
    -> m ()
iMContextSetSurrounding context text len cursorIndex = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    text' <- textToCString text
    gtk_im_context_set_surrounding context' text' len cursorIndex
    touchManagedPtr context
    freeMem text'
    return ()

data IMContextSetSurroundingMethodInfo
instance (signature ~ (T.Text -> Int32 -> Int32 -> m ()), MonadIO m, IsIMContext a) => O.MethodInfo IMContextSetSurroundingMethodInfo a signature where
    overloadedMethod _ = iMContextSetSurrounding

-- method IMContext::set_use_preedit
-- method type : OrdinaryMethod
-- Args : [Arg {argCName = "context", argType = TInterface (Name {namespace = "Gtk", name = "IMContext"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GtkIMContext", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "use_preedit", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "whether the IM context should use the preedit string.", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_im_context_set_use_preedit" gtk_im_context_set_use_preedit :: 
    Ptr IMContext ->                        -- context : TInterface (Name {namespace = "Gtk", name = "IMContext"})
    CInt ->                                 -- use_preedit : TBasicType TBoolean
    IO ()

{- |
Sets whether the IM context should use the preedit string
to display feedback. If /@usePreedit@/ is FALSE (default
is TRUE), then the IM context may use some other method to display
feedback, such as displaying it in a child of the root window.
-}
iMContextSetUsePreedit ::
    (B.CallStack.HasCallStack, MonadIO m, IsIMContext a) =>
    a
    {- ^ /@context@/: a 'GI.Gtk.Objects.IMContext.IMContext' -}
    -> Bool
    {- ^ /@usePreedit@/: whether the IM context should use the preedit string. -}
    -> m ()
iMContextSetUsePreedit context usePreedit = liftIO $ do
    context' <- unsafeManagedPtrCastPtr context
    let usePreedit' = (fromIntegral . fromEnum) usePreedit
    gtk_im_context_set_use_preedit context' usePreedit'
    touchManagedPtr context
    return ()

data IMContextSetUsePreeditMethodInfo
instance (signature ~ (Bool -> m ()), MonadIO m, IsIMContext a) => O.MethodInfo IMContextSetUsePreeditMethodInfo a signature where
    overloadedMethod _ = iMContextSetUsePreedit