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

Accelerator maps are used to define runtime configurable accelerators.
Functions for manipulating them are are usually used by higher level
convenience mechanisms like 'GI.Gtk.Objects.UIManager.UIManager' and are thus considered
“low-level”. You’ll want to use them if you’re manually creating menus that
should have user-configurable accelerators.

An accelerator is uniquely defined by:

* accelerator path
* accelerator key
* accelerator modifiers


The accelerator path must consist of
“\<WINDOWTYPE>\/Category1\/Category2\/...\/Action”, where WINDOWTYPE
should be a unique application-specific identifier that corresponds
to the kind of window the accelerator is being used in, e.g.
“Gimp-Image”, “Abiword-Document” or “Gnumeric-Settings”.
The “Category1\/...\/Action” portion is most appropriately chosen by
the action the accelerator triggers, i.e. for accelerators on menu
items, choose the item’s menu path, e.g. “File\/Save As”,
“Image\/View\/Zoom” or “Edit\/Select All”. So a full valid accelerator
path may look like: “\<Gimp-Toolbox>\/File\/Dialogs\/Tool Options...”.

All accelerators are stored inside one global 'GI.Gtk.Objects.AccelMap.AccelMap' that can
be obtained using 'GI.Gtk.Objects.AccelMap.accelMapGet'. See
[Monitoring changes][monitoring-changes] for additional
details.

= Manipulating accelerators

New accelerators can be added using 'GI.Gtk.Objects.AccelMap.accelMapAddEntry'.
To search for specific accelerator, use 'GI.Gtk.Objects.AccelMap.accelMapLookupEntry'.
Modifications of existing accelerators should be done using
'GI.Gtk.Objects.AccelMap.accelMapChangeEntry'.

In order to avoid having some accelerators changed, they can be
locked using 'GI.Gtk.Objects.AccelMap.accelMapLockPath'. Unlocking is done using
'GI.Gtk.Objects.AccelMap.accelMapUnlockPath'.

= Saving and loading accelerator maps

Accelerator maps can be saved to and loaded from some external
resource. For simple saving and loading from file,
'GI.Gtk.Objects.AccelMap.accelMapSave' and 'GI.Gtk.Objects.AccelMap.accelMapLoad' are provided.
Saving and loading can also be done by providing file descriptor
to 'GI.Gtk.Objects.AccelMap.accelMapSaveFd' and 'GI.Gtk.Objects.AccelMap.accelMapLoadFd'.

= Monitoring changes

'GI.Gtk.Objects.AccelMap.AccelMap' object is only useful for monitoring changes of
accelerators. By connecting to 'GI.Gtk.Objects.AccelMap.AccelMap'::@/changed/@ signal, one
can monitor changes of all accelerators. It is also possible to
monitor only single accelerator path by using it as a detail of
the 'GI.Gtk.Objects.AccelMap.AccelMap'::@/changed/@ signal.
-}

#define ENABLE_OVERLOADING (MIN_VERSION_haskell_gi_overloading(1,0,0) \
       && !defined(__HADDOCK_VERSION__))

module GI.Gtk.Objects.AccelMap
    (

-- * Exported types
    AccelMap(..)                            ,
    IsAccelMap                              ,
    toAccelMap                              ,
    noAccelMap                              ,


 -- * Methods
-- ** addEntry #method:addEntry#

    accelMapAddEntry                        ,


-- ** addFilter #method:addFilter#

    accelMapAddFilter                       ,


-- ** changeEntry #method:changeEntry#

    accelMapChangeEntry                     ,


-- ** foreach #method:foreach#

    accelMapForeach                         ,


-- ** foreachUnfiltered #method:foreachUnfiltered#

    accelMapForeachUnfiltered               ,


-- ** get #method:get#

    accelMapGet                             ,


-- ** load #method:load#

    accelMapLoad                            ,


-- ** loadFd #method:loadFd#

    accelMapLoadFd                          ,


-- ** loadScanner #method:loadScanner#

    accelMapLoadScanner                     ,


-- ** lockPath #method:lockPath#

    accelMapLockPath                        ,


-- ** lookupEntry #method:lookupEntry#

    accelMapLookupEntry                     ,


-- ** save #method:save#

    accelMapSave                            ,


-- ** saveFd #method:saveFd#

    accelMapSaveFd                          ,


-- ** unlockPath #method:unlockPath#

    accelMapUnlockPath                      ,




 -- * Signals
-- ** changed #signal:changed#

    AccelMapChangedCallback                 ,
#if ENABLE_OVERLOADING
    AccelMapChangedSignalInfo               ,
#endif
    C_AccelMapChangedCallback               ,
    afterAccelMapChanged                    ,
    genClosure_AccelMapChanged              ,
    mk_AccelMapChangedCallback              ,
    noAccelMapChangedCallback               ,
    onAccelMapChanged                       ,
    wrap_AccelMapChangedCallback            ,




    ) 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.GValue as B.GValue
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.GLib.Structs.Scanner as GLib.Scanner
import qualified GI.GObject.Objects.Object as GObject.Object
import qualified GI.Gdk.Flags as Gdk.Flags
import qualified GI.Gtk.Callbacks as Gtk.Callbacks
import {-# SOURCE #-} qualified GI.Gtk.Structs.AccelKey as Gtk.AccelKey

-- | Memory-managed wrapper type.
newtype AccelMap = AccelMap (ManagedPtr AccelMap)
foreign import ccall "gtk_accel_map_get_type"
    c_gtk_accel_map_get_type :: IO GType

instance GObject AccelMap where
    gobjectType _ = c_gtk_accel_map_get_type


-- | Type class for types which can be safely cast to `AccelMap`, for instance with `toAccelMap`.
class GObject o => IsAccelMap o
#if MIN_VERSION_base(4,9,0)
instance {-# OVERLAPPABLE #-} (GObject a, O.UnknownAncestorError AccelMap a) =>
    IsAccelMap a
#endif
instance IsAccelMap AccelMap
instance GObject.Object.IsObject AccelMap

-- | Cast to `AccelMap`, for types for which this is known to be safe. For general casts, use `Data.GI.Base.ManagedPtr.castTo`.
toAccelMap :: (MonadIO m, IsAccelMap o) => o -> m AccelMap
toAccelMap = liftIO . unsafeCastTo AccelMap

-- | A convenience alias for `Nothing` :: `Maybe` `AccelMap`.
noAccelMap :: Maybe AccelMap
noAccelMap = Nothing

#if ENABLE_OVERLOADING
type family ResolveAccelMapMethod (t :: Symbol) (o :: *) :: * where
    ResolveAccelMapMethod "bindProperty" o = GObject.Object.ObjectBindPropertyMethodInfo
    ResolveAccelMapMethod "bindPropertyFull" o = GObject.Object.ObjectBindPropertyFullMethodInfo
    ResolveAccelMapMethod "forceFloating" o = GObject.Object.ObjectForceFloatingMethodInfo
    ResolveAccelMapMethod "freezeNotify" o = GObject.Object.ObjectFreezeNotifyMethodInfo
    ResolveAccelMapMethod "getv" o = GObject.Object.ObjectGetvMethodInfo
    ResolveAccelMapMethod "isFloating" o = GObject.Object.ObjectIsFloatingMethodInfo
    ResolveAccelMapMethod "notify" o = GObject.Object.ObjectNotifyMethodInfo
    ResolveAccelMapMethod "notifyByPspec" o = GObject.Object.ObjectNotifyByPspecMethodInfo
    ResolveAccelMapMethod "ref" o = GObject.Object.ObjectRefMethodInfo
    ResolveAccelMapMethod "refSink" o = GObject.Object.ObjectRefSinkMethodInfo
    ResolveAccelMapMethod "runDispose" o = GObject.Object.ObjectRunDisposeMethodInfo
    ResolveAccelMapMethod "stealData" o = GObject.Object.ObjectStealDataMethodInfo
    ResolveAccelMapMethod "stealQdata" o = GObject.Object.ObjectStealQdataMethodInfo
    ResolveAccelMapMethod "thawNotify" o = GObject.Object.ObjectThawNotifyMethodInfo
    ResolveAccelMapMethod "unref" o = GObject.Object.ObjectUnrefMethodInfo
    ResolveAccelMapMethod "watchClosure" o = GObject.Object.ObjectWatchClosureMethodInfo
    ResolveAccelMapMethod "getData" o = GObject.Object.ObjectGetDataMethodInfo
    ResolveAccelMapMethod "getProperty" o = GObject.Object.ObjectGetPropertyMethodInfo
    ResolveAccelMapMethod "getQdata" o = GObject.Object.ObjectGetQdataMethodInfo
    ResolveAccelMapMethod "setData" o = GObject.Object.ObjectSetDataMethodInfo
    ResolveAccelMapMethod "setProperty" o = GObject.Object.ObjectSetPropertyMethodInfo
    ResolveAccelMapMethod l o = O.MethodResolutionFailed l o

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

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

#endif

-- signal AccelMap::changed
{- |
Notifies of a change in the global accelerator map.
The path is also used as the detail for the signal,
so it is possible to connect to
changed::@accel_path@.

/Since: 2.4/
-}
type AccelMapChangedCallback =
    T.Text
    {- ^ /@accelPath@/: the path of the accelerator that changed -}
    -> Word32
    {- ^ /@accelKey@/: the key value for the new accelerator -}
    -> [Gdk.Flags.ModifierType]
    {- ^ /@accelMods@/: the modifier mask for the new accelerator -}
    -> IO ()

-- | A convenience synonym for @`Nothing` :: `Maybe` `AccelMapChangedCallback`@.
noAccelMapChangedCallback :: Maybe AccelMapChangedCallback
noAccelMapChangedCallback = Nothing

-- | Type for the callback on the (unwrapped) C side.
type C_AccelMapChangedCallback =
    Ptr () ->                               -- object
    CString ->
    Word32 ->
    CUInt ->
    Ptr () ->                               -- user_data
    IO ()

-- | Generate a function pointer callable from C code, from a `C_AccelMapChangedCallback`.
foreign import ccall "wrapper"
    mk_AccelMapChangedCallback :: C_AccelMapChangedCallback -> IO (FunPtr C_AccelMapChangedCallback)

-- | Wrap the callback into a `Closure`.
genClosure_AccelMapChanged :: AccelMapChangedCallback -> IO Closure
genClosure_AccelMapChanged cb = do
    let cb' = wrap_AccelMapChangedCallback cb
    mk_AccelMapChangedCallback cb' >>= newCClosure


-- | Wrap a `AccelMapChangedCallback` into a `C_AccelMapChangedCallback`.
wrap_AccelMapChangedCallback ::
    AccelMapChangedCallback ->
    C_AccelMapChangedCallback
wrap_AccelMapChangedCallback _cb _ accelPath accelKey accelMods _ = do
    accelPath' <- cstringToText accelPath
    let accelMods' = wordToGFlags accelMods
    _cb  accelPath' accelKey accelMods'


{- |
Connect a signal handler for the “@changed@” signal, to be run before the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.on' accelMap #changed callback
@
-}
onAccelMapChanged :: (IsAccelMap a, MonadIO m) => a -> AccelMapChangedCallback -> m SignalHandlerId
onAccelMapChanged obj cb = liftIO $ do
    let cb' = wrap_AccelMapChangedCallback cb
    cb'' <- mk_AccelMapChangedCallback cb'
    connectSignalFunPtr obj "changed" cb'' SignalConnectBefore

{- |
Connect a signal handler for the “@changed@” signal, to be run after the default handler.
When <https://github.com/haskell-gi/haskell-gi/wiki/Overloading overloading> is enabled, this is equivalent to

@
'Data.GI.Base.Signals.after' accelMap #changed callback
@
-}
afterAccelMapChanged :: (IsAccelMap a, MonadIO m) => a -> AccelMapChangedCallback -> m SignalHandlerId
afterAccelMapChanged obj cb = liftIO $ do
    let cb' = wrap_AccelMapChangedCallback cb
    cb'' <- mk_AccelMapChangedCallback cb'
    connectSignalFunPtr obj "changed" cb'' SignalConnectAfter


#if ENABLE_OVERLOADING
instance O.HasAttributeList AccelMap
type instance O.AttributeList AccelMap = AccelMapAttributeList
type AccelMapAttributeList = ('[ ] :: [(Symbol, *)])
#endif

#if ENABLE_OVERLOADING
#endif

#if ENABLE_OVERLOADING
data AccelMapChangedSignalInfo
instance SignalInfo AccelMapChangedSignalInfo where
    type HaskellCallbackType AccelMapChangedSignalInfo = AccelMapChangedCallback
    connectSignal _ obj cb connectMode = do
        let cb' = wrap_AccelMapChangedCallback cb
        cb'' <- mk_AccelMapChangedCallback cb'
        connectSignalFunPtr obj "changed" cb'' connectMode

type instance O.SignalList AccelMap = AccelMapSignalList
type AccelMapSignalList = ('[ '("changed", AccelMapChangedSignalInfo), '("notify", GObject.Object.ObjectNotifySignalInfo)] :: [(Symbol, *)])

#endif

-- method AccelMap::add_entry
-- method type : MemberFunction
-- Args : [Arg {argCName = "accel_path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "valid accelerator path", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "accel_key", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the accelerator key", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "accel_mods", argType = TInterface (Name {namespace = "Gdk", name = "ModifierType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the accelerator modifiers", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_add_entry" gtk_accel_map_add_entry ::
    CString ->                              -- accel_path : TBasicType TUTF8
    Word32 ->                               -- accel_key : TBasicType TUInt
    CUInt ->                                -- accel_mods : TInterface (Name {namespace = "Gdk", name = "ModifierType"})
    IO ()

{- |
Registers a new accelerator with the global accelerator map.
This function should only be called once per /@accelPath@/
with the canonical /@accelKey@/ and /@accelMods@/ for this path.
To change the accelerator during runtime programatically, use
'GI.Gtk.Objects.AccelMap.accelMapChangeEntry'.

Set /@accelKey@/ and /@accelMods@/ to 0 to request a removal of
the accelerator.

Note that /@accelPath@/ string will be stored in a @/GQuark/@. Therefore, if you
pass a static string, you can save some memory by interning it first with
'GI.GLib.Functions.internStaticString'.
-}
accelMapAddEntry ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@accelPath@/: valid accelerator path -}
    -> Word32
    {- ^ /@accelKey@/: the accelerator key -}
    -> [Gdk.Flags.ModifierType]
    {- ^ /@accelMods@/: the accelerator modifiers -}
    -> m ()
accelMapAddEntry accelPath accelKey accelMods = liftIO $ do
    accelPath' <- textToCString accelPath
    let accelMods' = gflagsToWord accelMods
    gtk_accel_map_add_entry accelPath' accelKey accelMods'
    freeMem accelPath'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::add_filter
-- method type : MemberFunction
-- Args : [Arg {argCName = "filter_pattern", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a pattern (see #GPatternSpec)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_add_filter" gtk_accel_map_add_filter ::
    CString ->                              -- filter_pattern : TBasicType TUTF8
    IO ()

{- |
Adds a filter to the global list of accel path filters.

Accel map entries whose accel path matches one of the filters
are skipped by 'GI.Gtk.Objects.AccelMap.accelMapForeach'.

This function is intended for GTK+ modules that create their own
menus, but don’t want them to be saved into the applications accelerator
map dump.
-}
accelMapAddFilter ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@filterPattern@/: a pattern (see 'GI.GLib.Structs.PatternSpec.PatternSpec') -}
    -> m ()
accelMapAddFilter filterPattern = liftIO $ do
    filterPattern' <- textToCString filterPattern
    gtk_accel_map_add_filter filterPattern'
    freeMem filterPattern'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::change_entry
-- method type : MemberFunction
-- Args : [Arg {argCName = "accel_path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a valid accelerator path", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "accel_key", argType = TBasicType TUInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new accelerator key", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "accel_mods", argType = TInterface (Name {namespace = "Gdk", name = "ModifierType"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the new accelerator modifiers", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "replace", argType = TBasicType TBoolean, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "%TRUE if other accelerators may be deleted upon conflicts", 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_accel_map_change_entry" gtk_accel_map_change_entry ::
    CString ->                              -- accel_path : TBasicType TUTF8
    Word32 ->                               -- accel_key : TBasicType TUInt
    CUInt ->                                -- accel_mods : TInterface (Name {namespace = "Gdk", name = "ModifierType"})
    CInt ->                                 -- replace : TBasicType TBoolean
    IO CInt

{- |
Changes the /@accelKey@/ and /@accelMods@/ currently associated with /@accelPath@/.
Due to conflicts with other accelerators, a change may not always be possible,
/@replace@/ indicates whether other accelerators may be deleted to resolve such
conflicts. A change will only occur if all conflicts could be resolved (which
might not be the case if conflicting accelerators are locked). Successful
changes are indicated by a 'True' return value.

Note that /@accelPath@/ string will be stored in a @/GQuark/@. Therefore, if you
pass a static string, you can save some memory by interning it first with
'GI.GLib.Functions.internStaticString'.
-}
accelMapChangeEntry ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@accelPath@/: a valid accelerator path -}
    -> Word32
    {- ^ /@accelKey@/: the new accelerator key -}
    -> [Gdk.Flags.ModifierType]
    {- ^ /@accelMods@/: the new accelerator modifiers -}
    -> Bool
    {- ^ /@replace@/: 'True' if other accelerators may be deleted upon conflicts -}
    -> m Bool
    {- ^ __Returns:__ 'True' if the accelerator could be changed, 'False' otherwise -}
accelMapChangeEntry accelPath accelKey accelMods replace = liftIO $ do
    accelPath' <- textToCString accelPath
    let accelMods' = gflagsToWord accelMods
    let replace' = (fromIntegral . fromEnum) replace
    result <- gtk_accel_map_change_entry accelPath' accelKey accelMods' replace'
    let result' = (/= 0) result
    freeMem accelPath'
    return result'

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::foreach
-- method type : MemberFunction
-- Args : [Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data to be passed into @foreach_func", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "foreach_func", argType = TInterface (Name {namespace = "Gtk", name = "AccelMapForeach"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "function to be executed for each accel\n               map entry which is not filtered out", sinceVersion = Nothing}, argScope = ScopeTypeCall, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_foreach" gtk_accel_map_foreach ::
    Ptr () ->                               -- data : TBasicType TPtr
    FunPtr Gtk.Callbacks.C_AccelMapForeach -> -- foreach_func : TInterface (Name {namespace = "Gtk", name = "AccelMapForeach"})
    IO ()

{- |
Loops over the entries in the accelerator map whose accel path
doesn’t match any of the filters added with 'GI.Gtk.Objects.AccelMap.accelMapAddFilter',
and execute /@foreachFunc@/ on each. The signature of /@foreachFunc@/ is
that of 'GI.Gtk.Callbacks.AccelMapForeach', the /@changed@/ parameter indicates whether
this accelerator was changed during runtime (thus, would need
saving during an accelerator map dump).
-}
accelMapForeach ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Ptr ()
    {- ^ /@data@/: data to be passed into /@foreachFunc@/ -}
    -> Gtk.Callbacks.AccelMapForeach
    {- ^ /@foreachFunc@/: function to be executed for each accel
               map entry which is not filtered out -}
    -> m ()
accelMapForeach data_ foreachFunc = liftIO $ do
    foreachFunc' <- Gtk.Callbacks.mk_AccelMapForeach (Gtk.Callbacks.wrap_AccelMapForeach Nothing foreachFunc)
    gtk_accel_map_foreach data_ foreachFunc'
    safeFreeFunPtr $ castFunPtrToPtr foreachFunc'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::foreach_unfiltered
-- method type : MemberFunction
-- Args : [Arg {argCName = "data", argType = TBasicType TPtr, direction = DirectionIn, mayBeNull = True, argDoc = Documentation {rawDocText = Just "data to be passed into @foreach_func", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "foreach_func", argType = TInterface (Name {namespace = "Gtk", name = "AccelMapForeach"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "function to be executed for each accel\n               map entry", sinceVersion = Nothing}, argScope = ScopeTypeCall, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_foreach_unfiltered" gtk_accel_map_foreach_unfiltered ::
    Ptr () ->                               -- data : TBasicType TPtr
    FunPtr Gtk.Callbacks.C_AccelMapForeach -> -- foreach_func : TInterface (Name {namespace = "Gtk", name = "AccelMapForeach"})
    IO ()

{- |
Loops over all entries in the accelerator map, and execute
/@foreachFunc@/ on each. The signature of /@foreachFunc@/ is that of
'GI.Gtk.Callbacks.AccelMapForeach', the /@changed@/ parameter indicates whether
this accelerator was changed during runtime (thus, would need
saving during an accelerator map dump).
-}
accelMapForeachUnfiltered ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Ptr ()
    {- ^ /@data@/: data to be passed into /@foreachFunc@/ -}
    -> Gtk.Callbacks.AccelMapForeach
    {- ^ /@foreachFunc@/: function to be executed for each accel
               map entry -}
    -> m ()
accelMapForeachUnfiltered data_ foreachFunc = liftIO $ do
    foreachFunc' <- Gtk.Callbacks.mk_AccelMapForeach (Gtk.Callbacks.wrap_AccelMapForeach Nothing foreachFunc)
    gtk_accel_map_foreach_unfiltered data_ foreachFunc'
    safeFreeFunPtr $ castFunPtrToPtr foreachFunc'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::get
-- method type : MemberFunction
-- Args : []
-- Lengths : []
-- returnType : Just (TInterface (Name {namespace = "Gtk", name = "AccelMap"}))
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_get" gtk_accel_map_get ::
    IO (Ptr AccelMap)

{- |
Gets the singleton global 'GI.Gtk.Objects.AccelMap.AccelMap' object. This object
is useful only for notification of changes to the accelerator
map via the ::changed signal; it isn’t a parameter to the
other accelerator map functions.

/Since: 2.4/
-}
accelMapGet ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    m AccelMap
    {- ^ __Returns:__ the global 'GI.Gtk.Objects.AccelMap.AccelMap' object -}
accelMapGet  = liftIO $ do
    result <- gtk_accel_map_get
    checkUnexpectedReturnNULL "accelMapGet" result
    result' <- (newObject AccelMap) result
    return result'

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::load
-- method type : MemberFunction
-- Args : [Arg {argCName = "file_name", argType = TBasicType TFileName, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a file containing accelerator specifications,\n  in the GLib file name encoding", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_load" gtk_accel_map_load ::
    CString ->                              -- file_name : TBasicType TFileName
    IO ()

{- |
Parses a file previously saved with 'GI.Gtk.Objects.AccelMap.accelMapSave' for
accelerator specifications, and propagates them accordingly.
-}
accelMapLoad ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [Char]
    {- ^ /@fileName@/: a file containing accelerator specifications,
  in the GLib file name encoding -}
    -> m ()
accelMapLoad fileName = liftIO $ do
    fileName' <- stringToCString fileName
    gtk_accel_map_load fileName'
    freeMem fileName'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::load_fd
-- method type : MemberFunction
-- Args : [Arg {argCName = "fd", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a valid readable file descriptor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_load_fd" gtk_accel_map_load_fd ::
    Int32 ->                                -- fd : TBasicType TInt
    IO ()

{- |
Filedescriptor variant of 'GI.Gtk.Objects.AccelMap.accelMapLoad'.

Note that the file descriptor will not be closed by this function.
-}
accelMapLoadFd ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Int32
    {- ^ /@fd@/: a valid readable file descriptor -}
    -> m ()
accelMapLoadFd fd = liftIO $ do
    gtk_accel_map_load_fd fd
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::load_scanner
-- method type : MemberFunction
-- Args : [Arg {argCName = "scanner", argType = TInterface (Name {namespace = "GLib", name = "Scanner"}), direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a #GScanner which has already been provided with an input file", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_load_scanner" gtk_accel_map_load_scanner ::
    Ptr GLib.Scanner.Scanner ->             -- scanner : TInterface (Name {namespace = "GLib", name = "Scanner"})
    IO ()

{- |
'GI.GLib.Structs.Scanner.Scanner' variant of 'GI.Gtk.Objects.AccelMap.accelMapLoad'.
-}
accelMapLoadScanner ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    GLib.Scanner.Scanner
    {- ^ /@scanner@/: a 'GI.GLib.Structs.Scanner.Scanner' which has already been provided with an input file -}
    -> m ()
accelMapLoadScanner scanner = liftIO $ do
    scanner' <- unsafeManagedPtrGetPtr scanner
    gtk_accel_map_load_scanner scanner'
    touchManagedPtr scanner
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::lock_path
-- method type : MemberFunction
-- Args : [Arg {argCName = "accel_path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a valid accelerator path", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_lock_path" gtk_accel_map_lock_path ::
    CString ->                              -- accel_path : TBasicType TUTF8
    IO ()

{- |
Locks the given accelerator path. If the accelerator map doesn’t yet contain
an entry for /@accelPath@/, a new one is created.

Locking an accelerator path prevents its accelerator from being changed
during runtime. A locked accelerator path can be unlocked by
'GI.Gtk.Objects.AccelMap.accelMapUnlockPath'. Refer to 'GI.Gtk.Objects.AccelMap.accelMapChangeEntry'
for information about runtime accelerator changes.

If called more than once, /@accelPath@/ remains locked until
'GI.Gtk.Objects.AccelMap.accelMapUnlockPath' has been called an equivalent number
of times.

Note that locking of individual accelerator paths is independent from
locking the 'GI.Gtk.Objects.AccelGroup.AccelGroup' containing them. For runtime accelerator
changes to be possible, both the accelerator path and its 'GI.Gtk.Objects.AccelGroup.AccelGroup'
have to be unlocked.

/Since: 2.4/
-}
accelMapLockPath ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@accelPath@/: a valid accelerator path -}
    -> m ()
accelMapLockPath accelPath = liftIO $ do
    accelPath' <- textToCString accelPath
    gtk_accel_map_lock_path accelPath'
    freeMem accelPath'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::lookup_entry
-- method type : MemberFunction
-- Args : [Arg {argCName = "accel_path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a valid accelerator path", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing},Arg {argCName = "key", argType = TInterface (Name {namespace = "Gtk", name = "AccelKey"}), direction = DirectionOut, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the accelerator key to be filled in (optional)", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = True, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Just (TBasicType TBoolean)
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_lookup_entry" gtk_accel_map_lookup_entry ::
    CString ->                              -- accel_path : TBasicType TUTF8
    Ptr Gtk.AccelKey.AccelKey ->            -- key : TInterface (Name {namespace = "Gtk", name = "AccelKey"})
    IO CInt

{- |
Looks up the accelerator entry for /@accelPath@/ and fills in /@key@/.
-}
accelMapLookupEntry ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@accelPath@/: a valid accelerator path -}
    -> m ((Bool, Gtk.AccelKey.AccelKey))
    {- ^ __Returns:__ 'True' if /@accelPath@/ is known, 'False' otherwise -}
accelMapLookupEntry accelPath = liftIO $ do
    accelPath' <- textToCString accelPath
    key <- callocBytes 12 :: IO (Ptr Gtk.AccelKey.AccelKey)
    result <- gtk_accel_map_lookup_entry accelPath' key
    let result' = (/= 0) result
    key' <- (wrapPtr Gtk.AccelKey.AccelKey) key
    freeMem accelPath'
    return (result', key')

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::save
-- method type : MemberFunction
-- Args : [Arg {argCName = "file_name", argType = TBasicType TFileName, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "the name of the file to contain\n  accelerator specifications, in the GLib file name encoding", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_save" gtk_accel_map_save ::
    CString ->                              -- file_name : TBasicType TFileName
    IO ()

{- |
Saves current accelerator specifications (accelerator path, key
and modifiers) to /@fileName@/.
The file is written in a format suitable to be read back in by
'GI.Gtk.Objects.AccelMap.accelMapLoad'.
-}
accelMapSave ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    [Char]
    {- ^ /@fileName@/: the name of the file to contain
  accelerator specifications, in the GLib file name encoding -}
    -> m ()
accelMapSave fileName = liftIO $ do
    fileName' <- stringToCString fileName
    gtk_accel_map_save fileName'
    freeMem fileName'
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::save_fd
-- method type : MemberFunction
-- Args : [Arg {argCName = "fd", argType = TBasicType TInt, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a valid writable file descriptor", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_save_fd" gtk_accel_map_save_fd ::
    Int32 ->                                -- fd : TBasicType TInt
    IO ()

{- |
Filedescriptor variant of 'GI.Gtk.Objects.AccelMap.accelMapSave'.

Note that the file descriptor will not be closed by this function.
-}
accelMapSaveFd ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    Int32
    {- ^ /@fd@/: a valid writable file descriptor -}
    -> m ()
accelMapSaveFd fd = liftIO $ do
    gtk_accel_map_save_fd fd
    return ()

#if ENABLE_OVERLOADING
#endif

-- method AccelMap::unlock_path
-- method type : MemberFunction
-- Args : [Arg {argCName = "accel_path", argType = TBasicType TUTF8, direction = DirectionIn, mayBeNull = False, argDoc = Documentation {rawDocText = Just "a valid accelerator path", sinceVersion = Nothing}, argScope = ScopeTypeInvalid, argClosure = -1, argDestroy = -1, argCallerAllocates = False, transfer = TransferNothing}]
-- Lengths : []
-- returnType : Nothing
-- throws : False
-- Skip return : False

foreign import ccall "gtk_accel_map_unlock_path" gtk_accel_map_unlock_path ::
    CString ->                              -- accel_path : TBasicType TUTF8
    IO ()

{- |
Undoes the last call to 'GI.Gtk.Objects.AccelMap.accelMapLockPath' on this /@accelPath@/.
Refer to 'GI.Gtk.Objects.AccelMap.accelMapLockPath' for information about accelerator path locking.

/Since: 2.4/
-}
accelMapUnlockPath ::
    (B.CallStack.HasCallStack, MonadIO m) =>
    T.Text
    {- ^ /@accelPath@/: a valid accelerator path -}
    -> m ()
accelMapUnlockPath accelPath = liftIO $ do
    accelPath' <- textToCString accelPath
    gtk_accel_map_unlock_path accelPath'
    freeMem accelPath'
    return ()

#if ENABLE_OVERLOADING
#endif