]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkaccelgroup.c
Minor documentation improvements
[~andy/gtk] / gtk / gtkaccelgroup.c
index e244fdb9c7038d010168b7ff8c8c2e4bab99bf5e..7f09e67e4fd71328607e4fb061911a912079f340 100644 (file)
  * files for a list of changes.  These files are distributed with
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
-#include "gtkaccelgroup.h"
-#include "gtkaccelmap.h"
-#include "gdk/gdkkeysyms.h"
-#include "gtkmarshalers.h"
-#include "gtksignal.h"
 
+#include "config.h"
 #include <string.h>
 #include <stdlib.h>
 
-
-/* --- prototypes --- */
-static void gtk_accel_group_class_init (GtkAccelGroupClass     *class);
-static void gtk_accel_group_init       (GtkAccelGroup          *accel_group);
-static void gtk_accel_group_finalize   (GObject                *object);
-
-
-/* --- variables --- */
-static GObjectClass     *parent_class = NULL;
-static guint            signal_accel_activate = 0;
-static guint            signal_accel_changed = 0;
-static guint            quark_acceleratable_groups = 0;
-static guint            default_accel_mod_mask = (GDK_SHIFT_MASK |
-                                                  GDK_CONTROL_MASK |
-                                                  GDK_MOD1_MASK);
+#include "gtkaccelgroup.h"
+#include "gtkaccelgroupprivate.h"
+#include "gtkaccellabel.h"
+#include "gtkaccelmap.h"
+#include "gtkintl.h"
+#include "gtkmainprivate.h"
+#include "gtkmarshalers.h"
 
 
-/* --- functions --- */
 /**
- * gtk_accel_group_get_type:
- * @returns: the type ID for accelerator groups.
+ * SECTION:gtkaccelgroup
+ * @Short_description: Groups of global keyboard accelerators for an entire GtkWindow
+ * @Title: Accelerator Groups
+ * @See_also:gtk_window_add_accel_group(), gtk_accel_map_change_entry(),
+ * gtk_item_factory_new(), gtk_label_new_with_mnemonic()
+ *
+ * A #GtkAccelGroup represents a group of keyboard accelerators,
+ * typically attached to a toplevel #GtkWindow (with
+ * gtk_window_add_accel_group()). Usually you won't need to create a
+ * #GtkAccelGroup directly; instead, when using #GtkUIManager, GTK+
+ * automatically sets up the accelerators for your menus in the ui
+ * manager's #GtkAccelGroup.
+ * 
+ * Note that <firstterm>accelerators</firstterm> are different from
+ * <firstterm>mnemonics</firstterm>. Accelerators are shortcuts for
+ * activating a menu item; they appear alongside the menu item they're a
+ * shortcut for. For example "Ctrl+Q" might appear alongside the "Quit"
+ * menu item. Mnemonics are shortcuts for GUI elements such as text
+ * entries or buttons; they appear as underlined characters. See
+ * gtk_label_new_with_mnemonic(). Menu items can have both accelerators
+ * and mnemonics, of course.
  */
-GType
-gtk_accel_group_get_type (void)
-{
-  static GType object_type = 0;
 
-  if (!object_type)
-    {
-      static const GTypeInfo object_info = {
-       sizeof (GtkAccelGroupClass),
-       (GBaseInitFunc) NULL,
-       (GBaseFinalizeFunc) NULL,
-       (GClassInitFunc) gtk_accel_group_class_init,
-       NULL,   /* clas_finalize */
-       NULL,   /* class_data */
-       sizeof (GtkAccelGroup),
-       0,      /* n_preallocs */
-       (GInstanceInitFunc) gtk_accel_group_init,
-      };
-
-      object_type = g_type_register_static (G_TYPE_OBJECT,
-                                           "GtkAccelGroup",
-                                           &object_info, 0);
-    }
+#define GTK_ACCEL_GROUP_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ACCEL_GROUP, GtkAccelGroupPrivate))
 
-  return object_type;
-}
+/* --- prototypes --- */
+static void gtk_accel_group_finalize     (GObject    *object);
+static void gtk_accel_group_get_property (GObject    *object,
+                                          guint       param_id,
+                                          GValue     *value,
+                                          GParamSpec *pspec);
+static void accel_closure_invalidate     (gpointer    data,
+                                          GClosure   *closure);
 
-static gboolean
-accel_activate_accumulator (GSignalInvocationHint *ihint,
-                           GValue                *return_accu,
-                           const GValue          *handler_return,
-                           gpointer               data)
-{
-  gboolean continue_emission;
-  gboolean handler_val;
 
-  /* handler returns whether the accelerator was handled */
-  handler_val = g_value_get_boolean (handler_return);
+/* --- variables --- */
+static guint  signal_accel_activate      = 0;
+static guint  signal_accel_changed       = 0;
+static guint  quark_acceleratable_groups = 0;
+static guint  default_accel_mod_mask     = (GDK_SHIFT_MASK   |
+                                            GDK_CONTROL_MASK |
+                                            GDK_MOD1_MASK    |
+                                            GDK_SUPER_MASK   |
+                                            GDK_HYPER_MASK   |
+                                            GDK_META_MASK);
 
-  /* record that as result for this emission */
-  g_value_set_boolean (return_accu, handler_val);
 
-  /* don't continue if accelerator was handled */
-  continue_emission = !handler_val;
+enum {
+  PROP_0,
+  PROP_IS_LOCKED,
+  PROP_MODIFIER_MASK,
+};
 
-  return continue_emission;
-}
+G_DEFINE_TYPE (GtkAccelGroup, gtk_accel_group, G_TYPE_OBJECT)
 
+/* --- functions --- */
 static void
 gtk_accel_group_class_init (GtkAccelGroupClass *class)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (class);
 
-  parent_class = g_type_class_peek_parent (class);
-
   quark_acceleratable_groups = g_quark_from_static_string ("gtk-acceleratable-accel-groups");
 
   object_class->finalize = gtk_accel_group_finalize;
+  object_class->get_property = gtk_accel_group_get_property;
 
   class->accel_changed = NULL;
-  signal_accel_activate = g_signal_new ("accel_activate",
-                                       G_OBJECT_CLASS_TYPE (class),
-                                       G_SIGNAL_DETAILED,
-                                       0,
-                                       accel_activate_accumulator, NULL,
-                                       _gtk_marshal_BOOLEAN__OBJECT_UINT_UINT,
-                                       G_TYPE_BOOLEAN, 3, G_TYPE_OBJECT, G_TYPE_UINT, G_TYPE_UINT);
-  signal_accel_changed = g_signal_new ("accel_changed",
-                                      G_OBJECT_CLASS_TYPE (class),
-                                      G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
-                                      G_STRUCT_OFFSET (GtkAccelGroupClass, accel_changed),
-                                      NULL, NULL,
-                                      _gtk_marshal_VOID__UINT_UINT_BOXED,
-                                      G_TYPE_NONE, 3, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_CLOSURE);
+
+  g_object_class_install_property (object_class,
+                                   PROP_IS_LOCKED,
+                                   g_param_spec_boolean ("is-locked",
+                                                         "Is locked",
+                                                         "Is the accel group locked",
+                                                         FALSE,
+                                                         G_PARAM_READABLE));
+
+  g_object_class_install_property (object_class,
+                                   PROP_MODIFIER_MASK,
+                                   g_param_spec_flags ("modifier-mask",
+                                                       "Modifier Mask",
+                                                       "Modifier Mask",
+                                                       GDK_TYPE_MODIFIER_TYPE,
+                                                       default_accel_mod_mask,
+                                                       G_PARAM_READABLE));
+
+  /**
+   * GtkAccelGroup::accel-activate:
+   * @accel_group: the #GtkAccelGroup which received the signal
+   * @acceleratable: the object on which the accelerator was activated
+   * @keyval: the accelerator keyval
+   * @modifier: the modifier combination of the accelerator
+   *
+   * The accel-activate signal is an implementation detail of
+   * #GtkAccelGroup and not meant to be used by applications.
+   * 
+   * Returns: %TRUE if the accelerator was activated
+   */
+  signal_accel_activate =
+    g_signal_new (I_("accel-activate"),
+                 G_OBJECT_CLASS_TYPE (class),
+                 G_SIGNAL_DETAILED,
+                 0,
+                 _gtk_boolean_handled_accumulator, NULL,
+                 _gtk_marshal_BOOLEAN__OBJECT_UINT_FLAGS,
+                 G_TYPE_BOOLEAN, 3,
+                 G_TYPE_OBJECT,
+                 G_TYPE_UINT,
+                 GDK_TYPE_MODIFIER_TYPE);
+  /**
+   * GtkAccelGroup::accel-changed:
+   * @accel_group: the #GtkAccelGroup which received the signal
+   * @keyval: the accelerator keyval
+   * @modifier: the modifier combination of the accelerator
+   * @accel_closure: the #GClosure of the accelerator
+   *
+   * The accel-changed signal is emitted when a #GtkAccelGroupEntry
+   * is added to or removed from the accel group. 
+   *
+   * Widgets like #GtkAccelLabel which display an associated 
+   * accelerator should connect to this signal, and rebuild 
+   * their visual representation if the @accel_closure is theirs.
+   */
+  signal_accel_changed =
+    g_signal_new (I_("accel-changed"),
+                 G_OBJECT_CLASS_TYPE (class),
+                 G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
+                 G_STRUCT_OFFSET (GtkAccelGroupClass, accel_changed),
+                 NULL, NULL,
+                 _gtk_marshal_VOID__UINT_FLAGS_BOXED,
+                 G_TYPE_NONE, 3,
+                 G_TYPE_UINT,
+                 GDK_TYPE_MODIFIER_TYPE,
+                 G_TYPE_CLOSURE);
+
+  g_type_class_add_private (object_class, sizeof (GtkAccelGroupPrivate));
 }
 
 static void
@@ -136,31 +181,61 @@ gtk_accel_group_finalize (GObject *object)
   GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (object);
   guint i;
   
-  for (i = 0; i < accel_group->n_accels; i++)
+  for (i = 0; i < accel_group->priv->n_accels; i++)
     {
-      GtkAccelGroupEntry *entry = &accel_group->priv_accels[i];
+      GtkAccelGroupEntry *entry = &accel_group->priv->priv_accels[i];
 
       if (entry->accel_path_quark)
        {
-         const gchar *accel_path = g_quark_to_string (entry[i].accel_path_quark);
+         const gchar *accel_path = g_quark_to_string (entry->accel_path_quark);
 
          _gtk_accel_map_remove_group (accel_path, accel_group);
        }
+      g_closure_remove_invalidate_notifier (entry->closure, accel_group, accel_closure_invalidate);
+
+      /* remove quick_accel_add() refcount */
+      g_closure_unref (entry->closure);
     }
 
-  g_free (accel_group->priv_accels);
+  g_free (accel_group->priv->priv_accels);
+
+  G_OBJECT_CLASS (gtk_accel_group_parent_class)->finalize (object);
+}
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+static void
+gtk_accel_group_get_property (GObject    *object,
+                              guint       param_id,
+                              GValue     *value,
+                              GParamSpec *pspec)
+{
+  GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (object);
+
+  switch (param_id)
+    {
+    case PROP_IS_LOCKED:
+      g_value_set_boolean (value, accel_group->priv->lock_count > 0);
+      break;
+    case PROP_MODIFIER_MASK:
+      g_value_set_flags (value, accel_group->priv->modifier_mask);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+    }
 }
 
 static void
 gtk_accel_group_init (GtkAccelGroup *accel_group)
 {
-  accel_group->lock_count = 0;
-  accel_group->modifier_mask = gtk_accelerator_get_default_mod_mask ();
-  accel_group->acceleratables = NULL;
-  accel_group->n_accels = 0;
-  accel_group->priv_accels = NULL;
+  GtkAccelGroupPrivate *priv = GTK_ACCEL_GROUP_GET_PRIVATE (accel_group);
+
+  priv->lock_count = 0;
+  priv->modifier_mask = gtk_accelerator_get_default_mod_mask ();
+  priv->acceleratables = NULL;
+  priv->n_accels = 0;
+  priv->priv_accels = NULL;
+
+  accel_group->priv = priv;
 }
 
 /**
@@ -175,6 +250,45 @@ gtk_accel_group_new (void)
   return g_object_new (GTK_TYPE_ACCEL_GROUP, NULL);
 }
 
+/**
+ * gtk_accel_group_get_is_locked:
+ * @accel_group: a #GtkAccelGroup
+ *
+ * Locks are added and removed using gtk_accel_group_lock() and
+ * gtk_accel_group_unlock().
+ *
+ * Returns: %TRUE if there are 1 or more locks on the @accel_group,
+ * %FALSE otherwise.
+ *
+ * Since: 2.14
+ */
+gboolean
+gtk_accel_group_get_is_locked (GtkAccelGroup *accel_group)
+{
+  g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
+
+  return accel_group->priv->lock_count > 0;
+}
+
+/**
+ * gtk_accel_group_get_modifier_mask:
+ * @accel_group: a #GtkAccelGroup
+ *
+ * Gets a #GdkModifierType representing the mask for this
+ * @accel_group. For example, #GDK_CONTROL_MASK, #GDK_SHIFT_MASK, etc.
+ *
+ * Returns: the modifier mask for this accel group.
+ *
+ * Since: 2.14
+ */
+GdkModifierType
+gtk_accel_group_get_modifier_mask (GtkAccelGroup *accel_group)
+{
+  g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), 0);
+
+  return accel_group->priv->modifier_mask;
+}
+
 static void
 accel_group_weak_ref_detach (GSList  *free_list,
                             GObject *stale_object)
@@ -186,10 +300,11 @@ accel_group_weak_ref_detach (GSList  *free_list,
       GtkAccelGroup *accel_group;
       
       accel_group = slist->data;
-      accel_group->acceleratables = g_slist_remove (accel_group->acceleratables, stale_object);
+      accel_group->priv->acceleratables = g_slist_remove (accel_group->priv->acceleratables, stale_object);
       g_object_unref (accel_group);
     }
   g_slist_free (free_list);
+  g_object_set_qdata (stale_object, quark_acceleratable_groups, NULL);
 }
 
 void
@@ -200,10 +315,10 @@ _gtk_accel_group_attach (GtkAccelGroup *accel_group,
   
   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
   g_return_if_fail (G_IS_OBJECT (object));
-  g_return_if_fail (g_slist_find (accel_group->acceleratables, object) == NULL);
+  g_return_if_fail (g_slist_find (accel_group->priv->acceleratables, object) == NULL);
   
   g_object_ref (accel_group);
-  accel_group->acceleratables = g_slist_prepend (accel_group->acceleratables, object);
+  accel_group->priv->acceleratables = g_slist_prepend (accel_group->priv->acceleratables, object);
   slist = g_object_get_qdata (object, quark_acceleratable_groups);
   if (slist)
     g_object_weak_unref (object,
@@ -224,9 +339,9 @@ _gtk_accel_group_detach (GtkAccelGroup *accel_group,
   
   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
   g_return_if_fail (G_IS_OBJECT (object));
-  g_return_if_fail (g_slist_find (accel_group->acceleratables, object) != NULL);
+  g_return_if_fail (g_slist_find (accel_group->priv->acceleratables, object) != NULL);
   
-  accel_group->acceleratables = g_slist_remove (accel_group->acceleratables, object);
+  accel_group->priv->acceleratables = g_slist_remove (accel_group->priv->acceleratables, object);
   slist = g_object_get_qdata (object, quark_acceleratable_groups);
   g_object_weak_unref (object,
                       (GWeakNotify) accel_group_weak_ref_detach,
@@ -242,10 +357,11 @@ _gtk_accel_group_detach (GtkAccelGroup *accel_group,
 
 /**
  * gtk_accel_groups_from_object:
- * @object:        a #GObject, usually a #GtkWindow 
- * @returns: a list of all accel groups which are attached to @object
+ * @object:        a #GObject, usually a #GtkWindow
  *
  * Gets a list of all accel groups which are attached to @object.
+ *
+ * Returns: (element-type GtkAccelGroup) (transfer none): a list of all accel groups which are attached to @object
  */
 GSList*
 gtk_accel_groups_from_object (GObject *object)
@@ -258,21 +374,20 @@ gtk_accel_groups_from_object (GObject *object)
 /**
  * gtk_accel_group_find:
  * @accel_group: a #GtkAccelGroup
- * @find_func: a function to filter the entries of @accel_group with
+ * @find_func: (scope call): a function to filter the entries
+ *    of @accel_group with
  * @data: data to pass to @find_func
- * @returns: the key of the first entry passing @find_func. The key is 
- * owned by GTK+ and must not be freed.
+ * @returns: (transfer none): the key of the first entry passing
+ *    @find_func. The key is owned by GTK+ and must not be freed.
  *
  * Finds the first entry in an accelerator group for which 
  * @find_func returns %TRUE and returns its #GtkAccelKey.
  *
  */
 GtkAccelKey*
-gtk_accel_group_find (GtkAccelGroup  *accel_group,
-                     gboolean (*find_func) (GtkAccelKey *key,
-                                            GClosure    *closure,
-                                            gpointer     data),
-                     gpointer        data)
+gtk_accel_group_find (GtkAccelGroup        *accel_group,
+                     GtkAccelGroupFindFunc find_func,
+                     gpointer              data)
 {
   GtkAccelKey *key = NULL;
   guint i;
@@ -281,12 +396,12 @@ gtk_accel_group_find (GtkAccelGroup  *accel_group,
   g_return_val_if_fail (find_func != NULL, NULL);
 
   g_object_ref (accel_group);
-  for (i = 0; i < accel_group->n_accels; i++)
-    if (find_func (&accel_group->priv_accels[i].key,
-                  accel_group->priv_accels[i].closure,
+  for (i = 0; i < accel_group->priv->n_accels; i++)
+    if (find_func (&accel_group->priv->priv_accels[i].key,
+                  accel_group->priv->priv_accels[i].closure,
                   data))
       {
-       key = &accel_group->priv_accels[i].key;
+       key = &accel_group->priv->priv_accels[i].key;
        break;
       }
   g_object_unref (accel_group);
@@ -313,7 +428,12 @@ gtk_accel_group_lock (GtkAccelGroup *accel_group)
 {
   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
   
-  accel_group->lock_count += 1;
+  accel_group->priv->lock_count += 1;
+
+  if (accel_group->priv->lock_count == 1) {
+    /* State change from unlocked to locked */
+    g_object_notify (G_OBJECT (accel_group), "is-locked");
+  }
 }
 
 /**
@@ -326,9 +446,14 @@ void
 gtk_accel_group_unlock (GtkAccelGroup *accel_group)
 {
   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
-  g_return_if_fail (accel_group->lock_count > 0);
+  g_return_if_fail (accel_group->priv->lock_count > 0);
+
+  accel_group->priv->lock_count -= 1;
 
-  accel_group->lock_count -= 1;
+  if (accel_group->priv->lock_count < 1) {
+    /* State change from locked to unlocked */
+    g_object_notify (G_OBJECT (accel_group), "is-locked");
+  }
 }
 
 static void
@@ -361,25 +486,25 @@ quick_accel_add (GtkAccelGroup  *accel_group,
                 GClosure       *closure,
                 GQuark          path_quark)
 {
-  guint pos, i = accel_group->n_accels++;
+  guint pos, i = accel_group->priv->n_accels++;
   GtkAccelGroupEntry key;
 
   /* find position */
   key.key.accel_key = accel_key;
   key.key.accel_mods = accel_mods;
   for (pos = 0; pos < i; pos++)
-    if (bsearch_compare_accels (&key, accel_group->priv_accels + pos) < 0)
+    if (bsearch_compare_accels (&key, accel_group->priv->priv_accels + pos) < 0)
       break;
 
   /* insert at position, ref closure */
-  accel_group->priv_accels = g_renew (GtkAccelGroupEntry, accel_group->priv_accels, accel_group->n_accels);
-  g_memmove (accel_group->priv_accels + pos + 1, accel_group->priv_accels + pos,
-            (i - pos) * sizeof (accel_group->priv_accels[0]));
-  accel_group->priv_accels[pos].key.accel_key = accel_key;
-  accel_group->priv_accels[pos].key.accel_mods = accel_mods;
-  accel_group->priv_accels[pos].key.accel_flags = accel_flags;
-  accel_group->priv_accels[pos].closure = g_closure_ref (closure);
-  accel_group->priv_accels[pos].accel_path_quark = path_quark;
+  accel_group->priv->priv_accels = g_renew (GtkAccelGroupEntry, accel_group->priv->priv_accels, accel_group->priv->n_accels);
+  g_memmove (accel_group->priv->priv_accels + pos + 1, accel_group->priv->priv_accels + pos,
+            (i - pos) * sizeof (accel_group->priv->priv_accels[0]));
+  accel_group->priv->priv_accels[pos].key.accel_key = accel_key;
+  accel_group->priv->priv_accels[pos].key.accel_mods = accel_mods;
+  accel_group->priv->priv_accels[pos].key.accel_flags = accel_flags;
+  accel_group->priv->priv_accels[pos].closure = g_closure_ref (closure);
+  accel_group->priv->priv_accels[pos].accel_path_quark = path_quark;
   g_closure_sink (closure);
   
   /* handle closure invalidation and reverse lookups */
@@ -407,10 +532,10 @@ quick_accel_add (GtkAccelGroup  *accel_group,
 
 static void
 quick_accel_remove (GtkAccelGroup      *accel_group,
-                   GtkAccelGroupEntry *entry)
+                    guint               pos)
 {
-  guint pos = entry - accel_group->priv_accels;
   GQuark accel_quark = 0;
+  GtkAccelGroupEntry *entry = accel_group->priv->priv_accels + pos;
   guint accel_key = entry->key.accel_key;
   GdkModifierType accel_mods = entry->key.accel_mods;
   GClosure *closure = entry->closure;
@@ -436,9 +561,9 @@ quick_accel_remove (GtkAccelGroup      *accel_group,
     _gtk_accel_map_remove_group (g_quark_to_string (entry->accel_path_quark), accel_group);
 
   /* physically remove */
-  accel_group->n_accels -= 1;
+  accel_group->priv->n_accels -= 1;
   g_memmove (entry, entry + 1,
-            (accel_group->n_accels - pos) * sizeof (accel_group->priv_accels[0]));
+            (accel_group->priv->n_accels - pos) * sizeof (accel_group->priv->priv_accels[0]));
 
   /* and notify */
   if (accel_quark)
@@ -457,24 +582,26 @@ quick_accel_find (GtkAccelGroup  *accel_group,
   GtkAccelGroupEntry *entry;
   GtkAccelGroupEntry key;
 
-  if (!accel_group->n_accels)
+  *count_p = 0;
+
+  if (!accel_group->priv->n_accels)
     return NULL;
 
   key.key.accel_key = accel_key;
   key.key.accel_mods = accel_mods;
-  entry = bsearch (&key, accel_group->priv_accels, accel_group->n_accels,
-                  sizeof (accel_group->priv_accels[0]), bsearch_compare_accels);
+  entry = bsearch (&key, accel_group->priv->priv_accels, accel_group->priv->n_accels,
+                  sizeof (accel_group->priv->priv_accels[0]), bsearch_compare_accels);
   
   if (!entry)
     return NULL;
 
   /* step back to the first member */
-  for (; entry > accel_group->priv_accels; entry--)
+  for (; entry > accel_group->priv->priv_accels; entry--)
     if (entry[-1].key.accel_key != accel_key ||
        entry[-1].key.accel_mods != accel_mods)
       break;
   /* count equal members */
-  for (*count_p = 0; entry + *count_p < accel_group->priv_accels + accel_group->n_accels; (*count_p)++)
+  for (; entry + *count_p < accel_group->priv->priv_accels + accel_group->priv->n_accels; (*count_p)++)
     if (entry[*count_p].key.accel_key != accel_key ||
        entry[*count_p].key.accel_mods != accel_mods)
       break;
@@ -533,6 +660,10 @@ gtk_accel_group_connect (GtkAccelGroup     *accel_group,
  * for the path.
  *
  * The signature used for the @closure is that of #GtkAccelGroupActivate.
+ * 
+ * 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_group_connect_by_path (GtkAccelGroup *accel_group,
@@ -567,11 +698,14 @@ gtk_accel_group_connect_by_path (GtkAccelGroup    *accel_group,
 /**
  * gtk_accel_group_disconnect:
  * @accel_group: the accelerator group to remove an accelerator from
- * @closure:     the closure to remove from this accelerator group
+ * @closure: (allow-none):     the closure to remove from this accelerator group, or %NULL
+ *               to remove all closures
  * @returns:     %TRUE if the closure was found and got disconnected
  *
  * Removes an accelerator previously installed through
  * gtk_accel_group_connect().
+ *
+ * Since 2.20 @closure can be %NULL.
  */
 gboolean
 gtk_accel_group_disconnect (GtkAccelGroup *accel_group,
@@ -581,11 +715,11 @@ gtk_accel_group_disconnect (GtkAccelGroup *accel_group,
 
   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
 
-  for (i = 0; i < accel_group->n_accels; i++)
-    if (accel_group->priv_accels[i].closure == closure)
+  for (i = 0; i < accel_group->priv->n_accels; i++)
+    if (accel_group->priv->priv_accels[i].closure == closure)
       {
        g_object_ref (accel_group);
-       quick_accel_remove (accel_group, accel_group->priv_accels + i);
+       quick_accel_remove (accel_group, i);
        g_object_unref (accel_group);
        return TRUE;
       }
@@ -651,10 +785,10 @@ _gtk_accel_group_reconnect (GtkAccelGroup *accel_group,
 
   g_object_ref (accel_group);
 
-  for (i = 0; i < accel_group->n_accels; i++)
-    if (accel_group->priv_accels[i].accel_path_quark == accel_path_quark)
+  for (i = 0; i < accel_group->priv->n_accels; i++)
+    if (accel_group->priv->priv_accels[i].accel_path_quark == accel_path_quark)
       {
-       GClosure *closure = g_closure_ref (accel_group->priv_accels[i].closure);
+       GClosure *closure = g_closure_ref (accel_group->priv->priv_accels[i].closure);
 
        clist = g_slist_prepend (clist, closure);
       }
@@ -672,13 +806,24 @@ _gtk_accel_group_reconnect (GtkAccelGroup *accel_group,
   g_object_unref (accel_group);
 }
 
+GSList*
+_gtk_accel_group_get_accelerables (GtkAccelGroup *accel_group)
+{
+    g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
+
+    return accel_group->priv->acceleratables;
+}
+
 /**
  * gtk_accel_group_query:
  * @accel_group:      the accelerator group to query
  * @accel_key:        key value of the accelerator
  * @accel_mods:       modifier combination of the accelerator
- * @n_entries:        location to return the number of entries found, or %NULL
- * @returns:          an array of @n_entries #GtkAccelGroupEntry elements, or %NULL. The array is owned by GTK+ and must not be freed. 
+ * @n_entries: (allow-none): location to return the number of entries found,
+ *     or %NULL
+ * @returns: (transfer none) (array length=n_entries): an array of
+ *     @n_entries #GtkAccelGroupEntry elements, or %NULL. The array is
+ *     owned by GTK+ and must not be freed.
  *
  * Queries an accelerator group for all entries matching @accel_key and 
  * @accel_mods.
@@ -694,7 +839,7 @@ gtk_accel_group_query (GtkAccelGroup  *accel_group,
 
   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
 
-  entries = quick_accel_find (accel_group, accel_key, accel_mods, &n);
+  entries = quick_accel_find (accel_group, gdk_keyval_to_lower (accel_key), accel_mods, &n);
 
   if (n_entries)
     *n_entries = entries ? n : 0;
@@ -705,7 +850,8 @@ gtk_accel_group_query (GtkAccelGroup  *accel_group,
 /**
  * gtk_accel_group_from_accel_closure:
  * @closure: a #GClosure
- * @returns: the #GtkAccelGroup to which @closure is connected, or %NULL.
+ * @returns: (transfer none): the #GtkAccelGroup to which @closure
+ *     is connected, or %NULL.
  *
  * Finds the #GtkAccelGroup to which @closure is connected; 
  * see gtk_accel_group_connect().
@@ -731,17 +877,33 @@ gtk_accel_group_from_accel_closure (GClosure *closure)
   return NULL;
 }
 
+/**
+ * gtk_accel_group_activate:
+ * @accel_group:   a #GtkAccelGroup
+ * @accel_quark:   the quark for the accelerator name
+ * @acceleratable: the #GObject, usually a #GtkWindow, on which
+ *                 to activate the accelerator.
+ * @accel_key:     accelerator keyval from a key event
+ * @accel_mods:    keyboard state mask from a key event
+ * 
+ * Finds the first accelerator in @accel_group 
+ * that matches @accel_key and @accel_mods, and
+ * activates it.
+ *
+ * Returns: %TRUE if an accelerator was activated and handled this keypress
+ */
 gboolean
-_gtk_accel_group_activate (GtkAccelGroup  *accel_group,
-                          GQuark          accel_quark,
-                          GObject        *acceleratable,
-                          guint           accel_key,
-                          GdkModifierType accel_mods)
+gtk_accel_group_activate (GtkAccelGroup   *accel_group,
+                          GQuark          accel_quark,
+                          GObject        *acceleratable,
+                          guint                   accel_key,
+                          GdkModifierType  accel_mods)
 {
   gboolean was_handled;
 
   g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
-
+  g_return_val_if_fail (G_IS_OBJECT (acceleratable), FALSE);
+  
   was_handled = FALSE;
   g_signal_emit (accel_group, signal_accel_activate, accel_quark,
                 acceleratable, accel_key, accel_mods, &was_handled);
@@ -755,13 +917,12 @@ _gtk_accel_group_activate (GtkAccelGroup  *accel_group,
  *                 to activate the accelerator.
  * @accel_key:     accelerator keyval from a key event
  * @accel_mods:    keyboard state mask from a key event
- * @returns:       %TRUE if the accelerator was handled, %FALSE otherwise
  * 
  * Finds the first accelerator in any #GtkAccelGroup attached
  * to @object that matches @accel_key and @accel_mods, and
  * activates that accelerator.
- * If an accelerator was activated and handled this keypress, %TRUE
- * is returned.
+ *
+ * Returns: %TRUE if an accelerator was activated and handled this keypress
  */
 gboolean
 gtk_accel_groups_activate (GObject       *object,
@@ -781,7 +942,7 @@ gtk_accel_groups_activate (GObject    *object,
       g_free (accel_name);
       
       for (slist = gtk_accel_groups_from_object (object); slist; slist = slist->next)
-       if (_gtk_accel_group_activate (slist->data, accel_quark, object, accel_key, accel_mods))
+       if (gtk_accel_group_activate (slist->data, accel_quark, object, accel_key, accel_mods))
          return TRUE;
     }
   
@@ -793,30 +954,34 @@ gtk_accel_groups_activate (GObject          *object,
  * @keyval:    a GDK keyval
  * @modifiers: modifier mask
  * @returns:   %TRUE if the accelerator is valid
- * 
+ *
  * Determines whether a given keyval and modifier mask constitute
- * a valid keyboard accelerator. For example, the #GDK_a keyval
+ * a valid keyboard accelerator. For example, the #GDK_KEY_a keyval
  * plus #GDK_CONTROL_MASK is valid - this is a "Ctrl+a" accelerator.
- * But by default (see gtk_accelerator_set_default_mod_mask()) you
- * cannot use the NumLock key as an accelerator modifier.
+ * But, you can't, for instance, use the #GDK_KEY_Control_L keyval
+ * as an accelerator.
  */
 gboolean
 gtk_accelerator_valid (guint             keyval,
                       GdkModifierType    modifiers)
 {
   static const guint invalid_accelerator_vals[] = {
-    GDK_Shift_L, GDK_Shift_R, GDK_Shift_Lock, GDK_Caps_Lock, GDK_ISO_Lock,
-    GDK_Control_L, GDK_Control_R, GDK_Meta_L, GDK_Meta_R,
-    GDK_Alt_L, GDK_Alt_R, GDK_Super_L, GDK_Super_R, GDK_Hyper_L, GDK_Hyper_R,
-    GDK_ISO_Level3_Shift, GDK_ISO_Next_Group, GDK_ISO_Prev_Group,
-    GDK_ISO_First_Group, GDK_ISO_Last_Group,
-    GDK_Mode_switch, GDK_Num_Lock, GDK_Multi_key,
-    GDK_Scroll_Lock, GDK_Sys_Req, 
-    GDK_Up, GDK_Down, GDK_Left, GDK_Right, GDK_Tab, GDK_ISO_Left_Tab,
-    GDK_KP_Up, GDK_KP_Down, GDK_KP_Left, GDK_KP_Right, GDK_KP_Tab,
-    GDK_First_Virtual_Screen, GDK_Prev_Virtual_Screen,
-    GDK_Next_Virtual_Screen, GDK_Last_Virtual_Screen,
-    GDK_Terminate_Server, GDK_AudibleBell_Enable,
+    GDK_KEY_Shift_L, GDK_KEY_Shift_R, GDK_KEY_Shift_Lock, GDK_KEY_Caps_Lock, GDK_KEY_ISO_Lock,
+    GDK_KEY_Control_L, GDK_KEY_Control_R, GDK_KEY_Meta_L, GDK_KEY_Meta_R,
+    GDK_KEY_Alt_L, GDK_KEY_Alt_R, GDK_KEY_Super_L, GDK_KEY_Super_R, GDK_KEY_Hyper_L, GDK_KEY_Hyper_R,
+    GDK_KEY_ISO_Level3_Shift, GDK_KEY_ISO_Next_Group, GDK_KEY_ISO_Prev_Group,
+    GDK_KEY_ISO_First_Group, GDK_KEY_ISO_Last_Group,
+    GDK_KEY_Mode_switch, GDK_KEY_Num_Lock, GDK_KEY_Multi_key,
+    GDK_KEY_Scroll_Lock, GDK_KEY_Sys_Req, 
+    GDK_KEY_Tab, GDK_KEY_ISO_Left_Tab, GDK_KEY_KP_Tab,
+    GDK_KEY_First_Virtual_Screen, GDK_KEY_Prev_Virtual_Screen,
+    GDK_KEY_Next_Virtual_Screen, GDK_KEY_Last_Virtual_Screen,
+    GDK_KEY_Terminate_Server, GDK_KEY_AudibleBell_Enable,
+    0
+  };
+  static const guint invalid_unmodified_vals[] = {
+    GDK_KEY_Up, GDK_KEY_Down, GDK_KEY_Left, GDK_KEY_Right,
+    GDK_KEY_KP_Up, GDK_KEY_KP_Down, GDK_KEY_KP_Left, GDK_KEY_KP_Right,
     0
   };
   const guint *ac_val;
@@ -833,6 +998,16 @@ gtk_accelerator_valid (guint                 keyval,
        return FALSE;
     }
 
+  if (!modifiers)
+    {
+      ac_val = invalid_unmodified_vals;
+      while (*ac_val)
+       {
+         if (keyval == *ac_val++)
+           return FALSE;
+       }
+    }
+  
   return TRUE;
 }
 
@@ -929,17 +1104,55 @@ is_release (const gchar *string)
          (string[8] == '>'));
 }
 
+static inline gboolean
+is_meta (const gchar *string)
+{
+  return ((string[0] == '<') &&
+         (string[1] == 'm' || string[1] == 'M') &&
+         (string[2] == 'e' || string[2] == 'E') &&
+         (string[3] == 't' || string[3] == 'T') &&
+         (string[4] == 'a' || string[4] == 'A') &&
+         (string[5] == '>'));
+}
+
+static inline gboolean
+is_super (const gchar *string)
+{
+  return ((string[0] == '<') &&
+         (string[1] == 's' || string[1] == 'S') &&
+         (string[2] == 'u' || string[2] == 'U') &&
+         (string[3] == 'p' || string[3] == 'P') &&
+         (string[4] == 'e' || string[4] == 'E') &&
+         (string[5] == 'r' || string[5] == 'R') &&
+         (string[6] == '>'));
+}
+
+static inline gboolean
+is_hyper (const gchar *string)
+{
+  return ((string[0] == '<') &&
+         (string[1] == 'h' || string[1] == 'H') &&
+         (string[2] == 'y' || string[2] == 'Y') &&
+         (string[3] == 'p' || string[3] == 'P') &&
+         (string[4] == 'e' || string[4] == 'E') &&
+         (string[5] == 'r' || string[5] == 'R') &&
+         (string[6] == '>'));
+}
+
 /**
  * gtk_accelerator_parse:
  * @accelerator:      string representing an accelerator
- * @accelerator_key:  return location for accelerator keyval
- * @accelerator_mods: return location for accelerator modifier mask
+ * @accelerator_key: (out):  return location for accelerator keyval
+ * @accelerator_mods: (out): return location for accelerator modifier mask
  *
  * Parses a string representing an accelerator. The
  * format looks like "&lt;Control&gt;a" or "&lt;Shift&gt;&lt;Alt&gt;F1" or
  * "&lt;Release&gt;z" (the last one is for key release).
  * The parser is fairly liberal and allows lower or upper case,
  * and also abbreviations such as "&lt;Ctl&gt;" and "&lt;Ctrl&gt;".
+ * Key names are parsed using gdk_keyval_from_name(). For character keys the
+ * name is not the symbol, but the lowercase name, e.g. one would use
+ * "&lt;Ctrl&gt;minus" instead of "&lt;Ctrl&gt;-".
  *
  * If the parse fails, @accelerator_key and @accelerator_mods will
  * be set to 0 (zero).
@@ -1020,6 +1233,24 @@ gtk_accelerator_parse (const gchar     *accelerator,
              len -= 5;
              mods |= GDK_MOD1_MASK;
            }
+          else if (len >= 6 && is_meta (accelerator))
+           {
+             accelerator += 6;
+             len -= 6;
+             mods |= GDK_META_MASK;
+           }
+          else if (len >= 7 && is_hyper (accelerator))
+           {
+             accelerator += 7;
+             len -= 7;
+             mods |= GDK_HYPER_MASK;
+           }
+          else if (len >= 7 && is_super (accelerator))
+           {
+             accelerator += 7;
+             len -= 7;
+             mods |= GDK_SUPER_MASK;
+           }
          else
            {
              gchar last_ch;
@@ -1051,14 +1282,16 @@ gtk_accelerator_parse (const gchar     *accelerator,
  * gtk_accelerator_name:
  * @accelerator_key:  accelerator keyval
  * @accelerator_mods: accelerator modifier mask
- * @returns:          a newly-allocated accelerator name
- * 
+ *
  * Converts an accelerator keyval and modifier mask
  * into a string parseable by gtk_accelerator_parse().
- * For example, if you pass in #GDK_q and #GDK_CONTROL_MASK,
- * this function returns "&lt;Control&gt;q". 
+ * For example, if you pass in #GDK_KEY_q and #GDK_CONTROL_MASK,
+ * this function returns "&lt;Control&gt;q".
  *
- * The caller of this function must free the returned string.
+ * If you need to display accelerators in the user interface,
+ * see gtk_accelerator_get_label().
+ *
+ * Returns: a newly-allocated accelerator name
  */
 gchar*
 gtk_accelerator_name (guint           accelerator_key,
@@ -1072,6 +1305,9 @@ gtk_accelerator_name (guint           accelerator_key,
   static const gchar text_mod3[] = "<Mod3>";
   static const gchar text_mod4[] = "<Mod4>";
   static const gchar text_mod5[] = "<Mod5>";
+  static const gchar text_meta[] = "<Meta>";
+  static const gchar text_super[] = "<Super>";
+  static const gchar text_hyper[] = "<Hyper>";
   guint l;
   gchar *keyval_name;
   gchar *accelerator;
@@ -1100,6 +1336,12 @@ gtk_accelerator_name (guint           accelerator_key,
   if (accelerator_mods & GDK_MOD5_MASK)
     l += sizeof (text_mod5) - 1;
   l += strlen (keyval_name);
+  if (accelerator_mods & GDK_META_MASK)
+    l += sizeof (text_meta) - 1;
+  if (accelerator_mods & GDK_HYPER_MASK)
+    l += sizeof (text_hyper) - 1;
+  if (accelerator_mods & GDK_SUPER_MASK)
+    l += sizeof (text_super) - 1;
 
   accelerator = g_new (gchar, l + 1);
 
@@ -1145,21 +1387,66 @@ gtk_accelerator_name (guint           accelerator_key,
       strcpy (accelerator + l, text_mod5);
       l += sizeof (text_mod5) - 1;
     }
+  if (accelerator_mods & GDK_META_MASK)
+    {
+      strcpy (accelerator + l, text_meta);
+      l += sizeof (text_meta) - 1;
+    }
+  if (accelerator_mods & GDK_HYPER_MASK)
+    {
+      strcpy (accelerator + l, text_hyper);
+      l += sizeof (text_hyper) - 1;
+    }
+  if (accelerator_mods & GDK_SUPER_MASK)
+    {
+      strcpy (accelerator + l, text_super);
+      l += sizeof (text_super) - 1;
+    }
   strcpy (accelerator + l, keyval_name);
 
   return accelerator;
 }
 
+/**
+ * gtk_accelerator_get_label:
+ * @accelerator_key:  accelerator keyval
+ * @accelerator_mods: accelerator modifier mask
+ * 
+ * Converts an accelerator keyval and modifier mask into a string 
+ * which can be used to represent the accelerator to the user. 
+ *
+ * Returns: a newly-allocated string representing the accelerator.
+ *
+ * Since: 2.6
+ */
+gchar*
+gtk_accelerator_get_label (guint           accelerator_key,
+                          GdkModifierType accelerator_mods)
+{
+  GtkAccelLabelClass *klass;
+  gchar *label;
+
+  klass = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
+  label = _gtk_accel_label_class_get_accelerator_label (klass, 
+                                                       accelerator_key, 
+                                                       accelerator_mods);
+  g_type_class_unref (klass); /* klass is kept alive since gtk uses static types */
+
+  return label;
+}  
+
 /**
  * gtk_accelerator_set_default_mod_mask:
  * @default_mod_mask: accelerator modifier mask
  *
  * Sets the modifiers that will be considered significant for keyboard
  * accelerators. The default mod mask is #GDK_CONTROL_MASK |
- * #GDK_SHIFT_MASK | #GDK_MOD1_MASK, that is, Control, Shift, and Alt.
- * Other modifiers will by default be ignored by #GtkAccelGroup.
- * You must include at least the three default modifiers in any
- * value you pass to this function.
+ * #GDK_SHIFT_MASK | #GDK_MOD1_MASK | #GDK_SUPER_MASK | 
+ * #GDK_HYPER_MASK | #GDK_META_MASK, that is, Control, Shift, Alt, 
+ * Super, Hyper and Meta. Other modifiers will by default be ignored 
+ * by #GtkAccelGroup.
+ * You must include at least the three modifiers Control, Shift
+ * and Alt in any value you pass to this function.
  *
  * The default mod mask should be changed on application startup,
  * before using any accelerator groups.
@@ -1177,7 +1464,7 @@ gtk_accelerator_set_default_mod_mask (GdkModifierType default_mod_mask)
  *
  * Gets the value set by gtk_accelerator_set_default_mod_mask().
  */
-guint
+GdkModifierType
 gtk_accelerator_get_default_mod_mask (void)
 {
   return default_accel_mod_mask;