X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;ds=sidebyside;f=gtk%2Fgtkaccelmap.c;h=7154b404f86e6e60ebdda2322a5eb8feb05e4afc;hb=3b2182e711ace4a2d6843848208224cd7525d530;hp=3f7c8f5e171d9e1ee2f6bcd24a185b70cf500c86;hpb=a381648faac7e9930d6fbb0535e955beb1458cf5;p=~andy%2Fgtk
diff --git a/gtk/gtkaccelmap.c b/gtk/gtkaccelmap.c
index 3f7c8f5e1..7154b404f 100644
--- a/gtk/gtkaccelmap.c
+++ b/gtk/gtkaccelmap.c
@@ -12,18 +12,21 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see .
*/
#include "config.h"
-#include "gtkaccelmap.h"
+#include "gtkaccelmapprivate.h"
-#include "gtkwindow.h" /* in lack of GtkAcceleratable */
+#include "gtkmarshalers.h"
+#include "gtkwindowprivate.h"
+#include "gtkintl.h"
+
+#include
#include
+#include
#include
#ifdef HAVE_UNISTD_H
#include
@@ -31,25 +34,115 @@
#ifdef G_OS_WIN32
#include
#endif
-#include
+
+
+/**
+ * SECTION:gtkaccelmap
+ * @Short_description: Loadable keyboard accelerator specifications
+ * @Title: Accelerator Maps
+ * @See_also: #GtkAccelGroup, #GtkAccelKey, #GtkUIManager, gtk_widget_set_accel_path(), gtk_menu_item_set_accel_path(), #GtkSettings:gtk-can-change-accels
+ *
+ * Accelerator maps are used to define runtime configurable accelerators.
+ * Functions for manipulating them are are usually used by higher level
+ * convenience mechanisms like #GtkUIManager and are thus considered
+ * "low-level". You'll want to use them if you're manually creating menus that
+ * should have user-configurable accelerators.
+ *
+ * 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 #GtkAccelMap that can be
+ * obtained using gtk_accel_map_get(). See Monitoring changes for additional
+ * details.
+ *
+ *
+ * Manipulating accelerators
+ *
+ * New accelerators can be added using gtk_accel_map_add_entry(). To search for
+ * specific accelerator, use gtk_accel_map_lookup_entry(). Modifications of
+ * existing accelerators should be done using gtk_accel_map_change_entry().
+ *
+ * In order to avoid having some accelerators changed, they can be locked using
+ * gtk_accel_map_lock_path(). Unlocking is done using
+ * gtk_accel_map_unlock_path().
+ *
+ *
+ *
+ * Saving and loading accelerator maps
+ *
+ * Accelerator maps can be saved to and loaded from some external resource. For
+ * simple saving and loading from file, gtk_accel_map_save() and
+ * gtk_accel_map_load() are provided. Saving and loading can also be done by
+ * providing file descriptor to gtk_accel_map_save_fd() and
+ * gtk_accel_map_load_fd().
+ *
+ *
+ *
+ * Monitoring changes
+ *
+ * #GtkAccelMap object is only useful for monitoring changes of accelerators. By
+ * connecting to #GtkAccelMap::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 #GtkAccelMap::changed signal.
+ *
+ *
+ */
/* --- structures --- */
+struct _GtkAccelMap
+{
+ GObject parent_instance;
+};
+
+struct _GtkAccelMapClass
+{
+ GObjectClass parent_class;
+};
+
typedef struct {
const gchar *accel_path;
guint accel_key;
guint accel_mods;
guint std_accel_key;
guint std_accel_mods;
- guint changed : 1;
+ guint changed : 1;
+ guint lock_count : 15;
GSList *groups;
} AccelEntry;
+/* --- signals --- */
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
/* --- variables --- */
-static GHashTable *accel_entry_ht = NULL; /* accel_path -> AccelEntry */
-static GSList *accel_filters = NULL;
+static GHashTable *accel_entry_ht = NULL; /* accel_path -> AccelEntry */
+static GSList *accel_filters = NULL;
+static gulong accel_map_signals[LAST_SIGNAL] = { 0, };
+static GtkAccelMap *accel_map;
+
+/* --- prototypes --- */
+static void do_accel_map_changed (AccelEntry *entry);
/* --- functions --- */
static guint
@@ -84,9 +177,8 @@ accel_path_lookup (const gchar *accel_path)
void
_gtk_accel_map_init (void)
{
- g_assert (accel_entry_ht == NULL);
-
- accel_entry_ht = g_hash_table_new (accel_entry_hash, accel_entry_equal);
+ if (accel_entry_ht == NULL)
+ accel_entry_ht = g_hash_table_new (accel_entry_hash, accel_entry_equal);
}
gboolean
@@ -98,36 +190,34 @@ _gtk_accel_path_is_valid (const gchar *accel_path)
accel_path[1] == '<' || accel_path[1] == '>' || !accel_path[1])
return FALSE;
p = strchr (accel_path, '>');
- if (!p || p[1] != '/')
+ if (!p || (p[1] != 0 && p[1] != '/'))
return FALSE;
return TRUE;
}
/**
- * gtk_accel_map_add_entry
+ * gtk_accel_map_add_entry:
* @accel_path: valid accelerator path
* @accel_key: the accelerator key
* @accel_mods: the accelerator modifiers
*
- * Register a new accelerator with the global accelerator map.
+ * Registers a new accelerator with the global accelerator map.
* This function should only be called once per @accel_path
* with the canonical @accel_key and @accel_mods for this path.
* To change the accelerator during runtime programatically, use
* gtk_accel_map_change_entry().
- * 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...".
+ *
+ * Set @accel_key and @accel_mods to 0 to request a removal of
+ * the accelerator.
+ *
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with
+ * g_intern_static_string().
*/
void
-gtk_accel_map_add_entry (const gchar *accel_path,
- guint accel_key,
- guint accel_mods)
+gtk_accel_map_add_entry (const gchar *accel_path,
+ guint accel_key,
+ GdkModifierType accel_mods)
{
AccelEntry *entry;
@@ -152,24 +242,28 @@ gtk_accel_map_add_entry (const gchar *accel_path,
}
else
{
- entry = g_new0 (AccelEntry, 1);
- entry->accel_path = g_quark_to_string (g_quark_from_string (accel_path));
+ entry = g_slice_new0 (AccelEntry);
+ entry->accel_path = g_intern_string (accel_path);
entry->std_accel_key = accel_key;
entry->std_accel_mods = accel_mods;
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = FALSE;
+ entry->lock_count = 0;
g_hash_table_insert (accel_entry_ht, entry, entry);
+
+ do_accel_map_changed (entry);
}
}
/**
- * gtk_accel_map_lookup_entry
- * @accel_path: valid accelerator path
- * @key: accelerator key to be filled in (optional)
- * @returns: %TRUE if @accel_path is known, %FALSE otherwise
+ * gtk_accel_map_lookup_entry:
+ * @accel_path: a valid accelerator path
+ * @key: (allow-none) (out): the accelerator key to be filled in (optional)
*
* Looks up the accelerator entry for @accel_path and fills in @key.
+ *
+ * Returns: %TRUE if @accel_path is known, %FALSE otherwise
*/
gboolean
gtk_accel_map_lookup_entry (const gchar *accel_path,
@@ -212,6 +306,10 @@ g_hash_table_slist_values (GHashTable *hash_table)
return slist;
}
+/* if simulate==TRUE, return whether accel_path can be changed to
+ * accel_key && accel_mods. otherwise, return whether accel_path
+ * was actually changed.
+ */
static gboolean
internal_change_entry (const gchar *accel_path,
guint accel_key,
@@ -220,7 +318,7 @@ internal_change_entry (const gchar *accel_path,
gboolean simulate)
{
GSList *node, *slist, *win_list, *group_list, *replace_list = NULL;
- GHashTable *group_hm, *win_hm;
+ GHashTable *group_hm, *window_hm;
gboolean change_accel, removable, can_change = TRUE, seen_accel = FALSE;
GQuark entry_quark;
AccelEntry *entry = accel_path_lookup (accel_path);
@@ -235,12 +333,24 @@ internal_change_entry (const gchar *accel_path,
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
+
+ do_accel_map_changed (entry);
}
return TRUE;
}
/* if there's nothing to change, not much todo either */
if (entry->accel_key == accel_key && entry->accel_mods == accel_mods)
+ {
+ if (!simulate)
+ entry->changed = TRUE;
+ return simulate ? TRUE : FALSE;
+ }
+
+ /* The no-change case has already been handled, so
+ * simulate doesn't make a difference here.
+ */
+ if (entry->lock_count > 0)
return FALSE;
/* nobody's interested, easy going */
@@ -251,6 +361,8 @@ internal_change_entry (const gchar *accel_path,
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
+
+ do_accel_map_changed (entry);
}
return TRUE;
}
@@ -258,7 +370,7 @@ internal_change_entry (const gchar *accel_path,
/* 1) fetch all accel groups affected by this entry */
entry_quark = g_quark_try_string (entry->accel_path);
group_hm = g_hash_table_new (NULL, NULL);
- win_hm = g_hash_table_new (NULL, NULL);
+ window_hm = g_hash_table_new (NULL, NULL);
for (slist = entry->groups; slist; slist = slist->next)
g_hash_table_insert (group_hm, slist->data, slist->data);
@@ -268,14 +380,14 @@ internal_change_entry (const gchar *accel_path,
{
GtkAccelGroup *group = slist->data;
- for (node = group->acceleratables; node; node = node->next)
- g_hash_table_insert (win_hm, node->data, node->data);
+ for (node = _gtk_accel_group_get_accelerables (group); node; node = node->next)
+ g_hash_table_insert (window_hm, node->data, node->data);
}
g_slist_free (group_list);
/* 3) include all accel groups used by acceleratables */
- win_list = g_hash_table_slist_values (win_hm);
- g_hash_table_destroy (win_hm);
+ win_list = g_hash_table_slist_values (window_hm);
+ g_hash_table_destroy (window_hm);
for (slist = win_list; slist; slist = slist->next)
for (node = gtk_accel_groups_from_object (slist->data); node; node = node->next)
g_hash_table_insert (group_hm, node->data, node->data);
@@ -316,11 +428,11 @@ internal_change_entry (const gchar *accel_path,
for (i = 0; i < n; i++)
{
seen_accel = TRUE;
- removable = !group->lock_count && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
+ removable = !gtk_accel_group_get_is_locked (group) && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
if (!removable)
goto break_loop_step5;
if (ag_entry[i].accel_path_quark)
- replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry->accel_path_quark));
+ replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry[i].accel_path_quark));
}
}
break_loop_step5:
@@ -339,8 +451,6 @@ internal_change_entry (const gchar *accel_path,
if (change_accel && !simulate)
{
- guint old_accel_key, old_accel_mods;
-
/* ref accel groups */
for (slist = group_list; slist; slist = slist->next)
g_object_ref (slist->data);
@@ -350,17 +460,18 @@ internal_change_entry (const gchar *accel_path,
internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, FALSE);
/* 9) install new accelerator */
- old_accel_key = entry->accel_key;
- old_accel_mods = entry->accel_mods;
entry->accel_key = accel_key;
entry->accel_mods = accel_mods;
entry->changed = TRUE;
+
for (slist = group_list; slist; slist = slist->next)
_gtk_accel_group_reconnect (slist->data, g_quark_from_string (entry->accel_path));
/* unref accel groups */
for (slist = group_list; slist; slist = slist->next)
g_object_unref (slist->data);
+
+ do_accel_map_changed (entry);
}
g_slist_free (replace_list);
g_slist_free (group_list);
@@ -370,19 +481,24 @@ internal_change_entry (const gchar *accel_path,
}
/**
- * gtk_accel_map_change_entry
- * @accel_path: valid accelerator path
- * @accel_key: new accelerator key
- * @accel_mods: new accelerator modifiers
+ * gtk_accel_map_change_entry:
+ * @accel_path: a valid accelerator path
+ * @accel_key: the new accelerator key
+ * @accel_mods: the new accelerator modifiers
* @replace: %TRUE if other accelerators may be deleted upon conflicts
- * @returns: %TRUE if the accelerator could be changed, %FALSE otherwise
*
- * Change the @accel_key and @accel_mods currently associated with @accel_path.
+ * Changes the @accel_key and @accel_mods currently associated with @accel_path.
* 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 @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with
+ * g_intern_static_string().
+ *
+ * Returns: %TRUE if the accelerator could be changed, %FALSE otherwise
*/
gboolean
gtk_accel_map_change_entry (const gchar *accel_path,
@@ -398,7 +514,8 @@ gtk_accel_map_change_entry (const gchar *accel_path,
static guint
accel_map_parse_accel_path (GScanner *scanner)
{
- guint accel_key = 0, accel_mods = 0;
+ guint accel_key = 0;
+ GdkModifierType accel_mods = 0;
gchar *path, *accel;
/* parse accel path */
@@ -449,7 +566,7 @@ accel_map_parse_statement (GScanner *scanner)
{
guint (*parser_func) (GScanner*);
- parser_func = scanner->value.v_symbol;
+ parser_func = (guint (*) (GScanner *))scanner->value.v_symbol;
expected_token = parser_func (scanner);
}
@@ -480,6 +597,12 @@ accel_map_parse_statement (GScanner *scanner)
}
}
+/**
+ * gtk_accel_map_load_scanner:
+ * @scanner: a #GScanner which has already been provided with an input file
+ *
+ * #GScanner variant of gtk_accel_map_load().
+ */
void
gtk_accel_map_load_scanner (GScanner *scanner)
{
@@ -488,7 +611,7 @@ gtk_accel_map_load_scanner (GScanner *scanner)
gchar *cpair_comment_single;
gpointer saved_symbol;
- g_return_if_fail (scanner != 0);
+ g_return_if_fail (scanner != NULL);
/* configure scanner */
skip_comment_single = scanner->config->skip_comment_single;
@@ -498,7 +621,8 @@ gtk_accel_map_load_scanner (GScanner *scanner)
symbol_2_token = scanner->config->symbol_2_token;
scanner->config->symbol_2_token = FALSE;
saved_symbol = g_scanner_lookup_symbol (scanner, "gtk_accel_path");
- g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path", accel_map_parse_accel_path);
+ g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path",
+ accel_map_parse_accel_path);
/* outer parsing loop
*/
@@ -522,10 +646,11 @@ gtk_accel_map_load_scanner (GScanner *scanner)
}
/**
- * gtk_accel_map_load_fd
- * @fd: valid readable file descriptor
+ * gtk_accel_map_load_fd:
+ * @fd: a valid readable file descriptor
*
* Filedescriptor variant of gtk_accel_map_load().
+ *
* Note that the file descriptor will not be closed by this function.
*/
void
@@ -545,8 +670,9 @@ gtk_accel_map_load_fd (gint fd)
}
/**
- * gtk_accel_map_load
- * @file_name: a file containing accelerator specifications
+ * gtk_accel_map_load:
+ * @file_name: (type filename): a file containing accelerator specifications,
+ * in the GLib file name encoding
*
* Parses a file previously saved with gtk_accel_map_save() for
* accelerator specifications, and propagates them accordingly.
@@ -561,7 +687,7 @@ gtk_accel_map_load (const gchar *file_name)
if (!g_file_test (file_name, G_FILE_TEST_IS_REGULAR))
return;
- fd = open (file_name, O_RDONLY);
+ fd = g_open (file_name, O_RDONLY, 0);
if (fd < 0)
return;
@@ -570,15 +696,38 @@ gtk_accel_map_load (const gchar *file_name)
close (fd);
}
+static gboolean
+write_all (gint fd,
+ gchar *buf,
+ gsize to_write)
+{
+ while (to_write > 0)
+ {
+ gssize count = write (fd, buf, to_write);
+ if (count < 0)
+ {
+ if (errno != EINTR)
+ return FALSE;
+ }
+ else
+ {
+ to_write -= count;
+ buf += count;
+ }
+ }
+
+ return TRUE;
+}
+
static void
accel_map_print (gpointer data,
const gchar *accel_path,
guint accel_key,
- guint accel_mods,
+ GdkModifierType accel_mods,
gboolean changed)
{
GString *gstring = g_string_new (changed ? NULL : "; ");
- gint err, fd = GPOINTER_TO_INT (data);
+ gint fd = GPOINTER_TO_INT (data);
gchar *tmp, *name;
g_string_append (gstring, "(gtk_accel_path \"");
@@ -597,25 +746,23 @@ accel_map_print (gpointer data,
g_string_append (gstring, "\")\n");
- do
- err = write (fd, gstring->str, gstring->len);
- while (err < 0 && errno == EINTR);
+ write_all (fd, gstring->str, gstring->len);
g_string_free (gstring, TRUE);
}
/**
- * gtk_accel_map_save_fd
- * @fd: valid writable file descriptor
+ * gtk_accel_map_save_fd:
+ * @fd: a valid writable file descriptor
*
* Filedescriptor variant of gtk_accel_map_save().
+ *
* Note that the file descriptor will not be closed by this function.
*/
void
gtk_accel_map_save_fd (gint fd)
{
GString *gstring;
- gint err;
g_return_if_fail (fd >= 0);
@@ -626,16 +773,17 @@ gtk_accel_map_save_fd (gint fd)
g_string_append (gstring, "; this file is an automated accelerator map dump\n");
g_string_append (gstring, ";\n");
- do
- err = write (fd, gstring->str, gstring->len);
- while (err < 0 && errno == EINTR);
+ write_all (fd, gstring->str, gstring->len);
+
+ g_string_free (gstring, TRUE);
gtk_accel_map_foreach (GINT_TO_POINTER (fd), accel_map_print);
}
/**
- * gtk_accel_map_save
- * @file_name: the file to contain accelerator specifications
+ * gtk_accel_map_save:
+ * @file_name: (type filename): the name of the file to contain
+ * accelerator specifications, in the GLib file name encoding
*
* Saves current accelerator specifications (accelerator path, key
* and modifiers) to @file_name.
@@ -649,7 +797,7 @@ gtk_accel_map_save (const gchar *file_name)
g_return_if_fail (file_name != NULL);
- fd = open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
+ fd = g_open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
if (fd < 0)
return;
@@ -659,13 +807,15 @@ gtk_accel_map_save (const gchar *file_name)
}
/**
- * gtk_accel_map_foreach
- * @data: data to be passed into @foreach_func
- * @foreach_func: function to be executed for each accel map entry
+ * gtk_accel_map_foreach:
+ * @data: (allow-none): data to be passed into @foreach_func
+ * @foreach_func: (scope call): function to be executed for each accel
+ * map entry which is not filtered out
*
- * Loop over the entries in the accelerator map, and execute
- * @foreach_func on each. The signature of @foreach_func is that of
- * #GtkAccelMapForeach, the @changed parameter indicates whether
+ * Loops over the entries in the accelerator map whose accel path
+ * doesn't match any of the filters added with gtk_accel_map_add_filter(),
+ * and execute @foreach_func on each. The signature of @foreach_func is
+ * that of #GtkAccelMapForeach, the @changed parameter indicates whether
* this accelerator was changed during runtime (thus, would need
* saving during an accelerator map dump).
*/
@@ -693,6 +843,18 @@ gtk_accel_map_foreach (gpointer data,
g_slist_free (entries);
}
+/**
+ * gtk_accel_map_foreach_unfiltered:
+ * @data: data to be passed into @foreach_func
+ * @foreach_func: (scope call): function to be executed for each accel
+ * map entry
+ *
+ * Loops over all entries in the accelerator map, and execute
+ * @foreach_func on each. The signature of @foreach_func is that of
+ * #GtkAccelMapForeach, the @changed parameter indicates whether
+ * this accelerator was changed during runtime (thus, would need
+ * saving during an accelerator map dump).
+ */
void
gtk_accel_map_foreach_unfiltered (gpointer data,
GtkAccelMapForeach foreach_func)
@@ -712,6 +874,19 @@ gtk_accel_map_foreach_unfiltered (gpointer data,
g_slist_free (entries);
}
+/**
+ * gtk_accel_map_add_filter:
+ * @filter_pattern: a pattern (see #GPatternSpec)
+ *
+ * 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 gtk_accel_map_foreach().
+ *
+ * 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.
+ */
void
gtk_accel_map_add_filter (const gchar *filter_pattern)
{
@@ -760,3 +935,152 @@ _gtk_accel_map_remove_group (const gchar *accel_path,
entry->groups = g_slist_remove (entry->groups, accel_group);
}
+
+
+/**
+ * gtk_accel_map_lock_path:
+ * @accel_path: a valid accelerator path
+ *
+ * Locks the given accelerator path. If the accelerator map doesn't yet contain
+ * an entry for @accel_path, 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
+ * gtk_accel_map_unlock_path(). Refer to gtk_accel_map_change_entry()
+ * for information about runtime accelerator changes.
+ *
+ * If called more than once, @accel_path remains locked until
+ * gtk_accel_map_unlock_path() has been called an equivalent number
+ * of times.
+ *
+ * Note that locking of individual accelerator paths is independent from
+ * locking the #GtkAccelGroup containing them. For runtime accelerator
+ * changes to be possible, both the accelerator path and its #GtkAccelGroup
+ * have to be unlocked.
+ *
+ * Since: 2.4
+ **/
+void
+gtk_accel_map_lock_path (const gchar *accel_path)
+{
+ AccelEntry *entry;
+
+ g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
+
+ entry = accel_path_lookup (accel_path);
+
+ if (!entry)
+ {
+ gtk_accel_map_add_entry (accel_path, 0, 0);
+ entry = accel_path_lookup (accel_path);
+ }
+
+ entry->lock_count += 1;
+}
+
+/**
+ * gtk_accel_map_unlock_path:
+ * @accel_path: a valid accelerator path
+ *
+ * Undoes the last call to gtk_accel_map_lock_path() on this @accel_path.
+ * Refer to gtk_accel_map_lock_path() for information about accelerator path locking.
+ *
+ * Since: 2.4
+ **/
+void
+gtk_accel_map_unlock_path (const gchar *accel_path)
+{
+ AccelEntry *entry;
+
+ g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
+
+ entry = accel_path_lookup (accel_path);
+
+ g_return_if_fail (entry != NULL && entry->lock_count > 0);
+
+ entry->lock_count -= 1;
+}
+
+G_DEFINE_TYPE (GtkAccelMap, gtk_accel_map, G_TYPE_OBJECT)
+
+static void
+gtk_accel_map_class_init (GtkAccelMapClass *accel_map_class)
+{
+ /**
+ * GtkAccelMap::changed:
+ * @object: the global accel map object
+ * @accel_path: the path of the accelerator that changed
+ * @accel_key: the key value for the new accelerator
+ * @accel_mods: the modifier mask for the new accelerator
+ *
+ * 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
+ */
+ accel_map_signals[CHANGED] = g_signal_new (I_("changed"),
+ G_TYPE_FROM_CLASS (accel_map_class),
+ G_SIGNAL_DETAILED|G_SIGNAL_RUN_LAST,
+ 0,
+ NULL, NULL,
+ _gtk_marshal_VOID__STRING_UINT_FLAGS,
+ G_TYPE_NONE, 3,
+ G_TYPE_STRING, G_TYPE_UINT, GDK_TYPE_MODIFIER_TYPE);
+}
+
+static void
+gtk_accel_map_init (GtkAccelMap *accel_map)
+{
+}
+
+/**
+ * gtk_accel_map_get:
+ *
+ * Gets the singleton global #GtkAccelMap 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.
+ *
+ * Return value: (transfer none): the global #GtkAccelMap object
+ *
+ * Since: 2.4
+ **/
+GtkAccelMap *
+gtk_accel_map_get (void)
+{
+ if (!accel_map)
+ accel_map = g_object_new (GTK_TYPE_ACCEL_MAP, NULL);
+
+ return accel_map;
+}
+
+static void
+do_accel_map_changed (AccelEntry *entry)
+{
+ if (accel_map)
+ g_signal_emit (accel_map,
+ accel_map_signals[CHANGED],
+ g_quark_from_string (entry->accel_path),
+ entry->accel_path,
+ entry->accel_key,
+ entry->accel_mods);
+}
+
+gchar *
+_gtk_accel_path_for_action (const gchar *action_name,
+ GVariant *parameter)
+{
+ GString *s;
+
+ s = g_string_new ("/");
+ g_string_append (s, action_name);
+ if (parameter)
+ {
+ g_string_append_c (s, '/');
+ g_variant_print_string (parameter, s, FALSE);
+ }
+ return g_string_free (s, FALSE);
+}
+