1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1998, 2001 Tim Janik
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gtkaccelgroup.h"
32 #include "gtkaccelgroupprivate.h"
33 #include "gtkaccellabel.h"
34 #include "gtkaccelmap.h"
36 #include "gtkmarshalers.h"
37 #include "gtkprivate.h"
40 * SECTION:gtkaccelgroup
41 * @Short_description: Groups of global keyboard accelerators for an
43 * @Title: Accelerator Groups
44 * @See_also:gtk_window_add_accel_group(), gtk_accel_map_change_entry(),
45 * gtk_item_factory_new(), gtk_label_new_with_mnemonic()
47 * A #GtkAccelGroup represents a group of keyboard accelerators,
48 * typically attached to a toplevel #GtkWindow (with
49 * gtk_window_add_accel_group()). Usually you won't need to create a
50 * #GtkAccelGroup directly; instead, when using #GtkUIManager, GTK+
51 * automatically sets up the accelerators for your menus in the ui
52 * manager's #GtkAccelGroup.
54 * Note that <firstterm>accelerators</firstterm> are different from
55 * <firstterm>mnemonics</firstterm>. Accelerators are shortcuts for
56 * activating a menu item; they appear alongside the menu item they're a
57 * shortcut for. For example "Ctrl+Q" might appear alongside the "Quit"
58 * menu item. Mnemonics are shortcuts for GUI elements such as text
59 * entries or buttons; they appear as underlined characters. See
60 * gtk_label_new_with_mnemonic(). Menu items can have both accelerators
61 * and mnemonics, of course.
64 /* --- prototypes --- */
65 static void gtk_accel_group_finalize (GObject *object);
66 static void gtk_accel_group_get_property (GObject *object,
70 static void accel_closure_invalidate (gpointer data,
74 /* --- variables --- */
75 static guint signal_accel_activate = 0;
76 static guint signal_accel_changed = 0;
77 static guint quark_acceleratable_groups = 0;
78 static guint default_accel_mod_mask = (GDK_SHIFT_MASK |
92 G_DEFINE_TYPE (GtkAccelGroup, gtk_accel_group, G_TYPE_OBJECT)
94 /* --- functions --- */
96 gtk_accel_group_class_init (GtkAccelGroupClass *class)
98 GObjectClass *object_class = G_OBJECT_CLASS (class);
100 quark_acceleratable_groups = g_quark_from_static_string ("gtk-acceleratable-accel-groups");
102 object_class->finalize = gtk_accel_group_finalize;
103 object_class->get_property = gtk_accel_group_get_property;
105 class->accel_changed = NULL;
107 g_object_class_install_property (object_class,
109 g_param_spec_boolean ("is-locked",
111 "Is the accel group locked",
115 g_object_class_install_property (object_class,
117 g_param_spec_flags ("modifier-mask",
120 GDK_TYPE_MODIFIER_TYPE,
121 default_accel_mod_mask,
125 * GtkAccelGroup::accel-activate:
126 * @accel_group: the #GtkAccelGroup which received the signal
127 * @acceleratable: the object on which the accelerator was activated
128 * @keyval: the accelerator keyval
129 * @modifier: the modifier combination of the accelerator
131 * The accel-activate signal is an implementation detail of
132 * #GtkAccelGroup and not meant to be used by applications.
134 * Returns: %TRUE if the accelerator was activated
136 signal_accel_activate =
137 g_signal_new (I_("accel-activate"),
138 G_OBJECT_CLASS_TYPE (class),
141 _gtk_boolean_handled_accumulator, NULL,
142 _gtk_marshal_BOOLEAN__OBJECT_UINT_FLAGS,
146 GDK_TYPE_MODIFIER_TYPE);
148 * GtkAccelGroup::accel-changed:
149 * @accel_group: the #GtkAccelGroup which received the signal
150 * @keyval: the accelerator keyval
151 * @modifier: the modifier combination of the accelerator
152 * @accel_closure: the #GClosure of the accelerator
154 * The accel-changed signal is emitted when a #GtkAccelGroupEntry
155 * is added to or removed from the accel group.
157 * Widgets like #GtkAccelLabel which display an associated
158 * accelerator should connect to this signal, and rebuild
159 * their visual representation if the @accel_closure is theirs.
161 signal_accel_changed =
162 g_signal_new (I_("accel-changed"),
163 G_OBJECT_CLASS_TYPE (class),
164 G_SIGNAL_RUN_FIRST | G_SIGNAL_DETAILED,
165 G_STRUCT_OFFSET (GtkAccelGroupClass, accel_changed),
167 _gtk_marshal_VOID__UINT_FLAGS_BOXED,
170 GDK_TYPE_MODIFIER_TYPE,
173 g_type_class_add_private (object_class, sizeof (GtkAccelGroupPrivate));
177 gtk_accel_group_finalize (GObject *object)
179 GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (object);
182 for (i = 0; i < accel_group->priv->n_accels; i++)
184 GtkAccelGroupEntry *entry = &accel_group->priv->priv_accels[i];
186 if (entry->accel_path_quark)
188 const gchar *accel_path = g_quark_to_string (entry->accel_path_quark);
190 _gtk_accel_map_remove_group (accel_path, accel_group);
192 g_closure_remove_invalidate_notifier (entry->closure, accel_group, accel_closure_invalidate);
194 /* remove quick_accel_add() refcount */
195 g_closure_unref (entry->closure);
198 g_free (accel_group->priv->priv_accels);
200 G_OBJECT_CLASS (gtk_accel_group_parent_class)->finalize (object);
204 gtk_accel_group_get_property (GObject *object,
209 GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (object);
214 g_value_set_boolean (value, accel_group->priv->lock_count > 0);
216 case PROP_MODIFIER_MASK:
217 g_value_set_flags (value, accel_group->priv->modifier_mask);
220 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
226 gtk_accel_group_init (GtkAccelGroup *accel_group)
228 GtkAccelGroupPrivate *priv;
230 accel_group->priv = G_TYPE_INSTANCE_GET_PRIVATE (accel_group,
231 GTK_TYPE_ACCEL_GROUP,
232 GtkAccelGroupPrivate);
233 priv = accel_group->priv;
235 priv->lock_count = 0;
236 priv->modifier_mask = gtk_accelerator_get_default_mod_mask ();
237 priv->acceleratables = NULL;
239 priv->priv_accels = NULL;
243 * gtk_accel_group_new:
245 * Creates a new #GtkAccelGroup.
247 * Returns: a new #GtkAccelGroup object
250 gtk_accel_group_new (void)
252 return g_object_new (GTK_TYPE_ACCEL_GROUP, NULL);
256 * gtk_accel_group_get_is_locked:
257 * @accel_group: a #GtkAccelGroup
259 * Locks are added and removed using gtk_accel_group_lock() and
260 * gtk_accel_group_unlock().
262 * Returns: %TRUE if there are 1 or more locks on the @accel_group,
268 gtk_accel_group_get_is_locked (GtkAccelGroup *accel_group)
270 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
272 return accel_group->priv->lock_count > 0;
276 * gtk_accel_group_get_modifier_mask:
277 * @accel_group: a #GtkAccelGroup
279 * Gets a #GdkModifierType representing the mask for this
280 * @accel_group. For example, #GDK_CONTROL_MASK, #GDK_SHIFT_MASK, etc.
282 * Returns: the modifier mask for this accel group.
287 gtk_accel_group_get_modifier_mask (GtkAccelGroup *accel_group)
289 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), 0);
291 return accel_group->priv->modifier_mask;
295 accel_group_weak_ref_detach (GSList *free_list,
296 GObject *stale_object)
300 for (slist = free_list; slist; slist = slist->next)
302 GtkAccelGroup *accel_group;
304 accel_group = slist->data;
305 accel_group->priv->acceleratables = g_slist_remove (accel_group->priv->acceleratables, stale_object);
306 g_object_unref (accel_group);
308 g_slist_free (free_list);
309 g_object_set_qdata (stale_object, quark_acceleratable_groups, NULL);
313 _gtk_accel_group_attach (GtkAccelGroup *accel_group,
318 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
319 g_return_if_fail (G_IS_OBJECT (object));
320 g_return_if_fail (g_slist_find (accel_group->priv->acceleratables, object) == NULL);
322 g_object_ref (accel_group);
323 accel_group->priv->acceleratables = g_slist_prepend (accel_group->priv->acceleratables, object);
324 slist = g_object_get_qdata (object, quark_acceleratable_groups);
326 g_object_weak_unref (object,
327 (GWeakNotify) accel_group_weak_ref_detach,
329 slist = g_slist_prepend (slist, accel_group);
330 g_object_set_qdata (object, quark_acceleratable_groups, slist);
331 g_object_weak_ref (object,
332 (GWeakNotify) accel_group_weak_ref_detach,
337 _gtk_accel_group_detach (GtkAccelGroup *accel_group,
342 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
343 g_return_if_fail (G_IS_OBJECT (object));
344 g_return_if_fail (g_slist_find (accel_group->priv->acceleratables, object) != NULL);
346 accel_group->priv->acceleratables = g_slist_remove (accel_group->priv->acceleratables, object);
347 slist = g_object_get_qdata (object, quark_acceleratable_groups);
348 g_object_weak_unref (object,
349 (GWeakNotify) accel_group_weak_ref_detach,
351 slist = g_slist_remove (slist, accel_group);
352 g_object_set_qdata (object, quark_acceleratable_groups, slist);
354 g_object_weak_ref (object,
355 (GWeakNotify) accel_group_weak_ref_detach,
357 g_object_unref (accel_group);
361 * gtk_accel_groups_from_object:
362 * @object: a #GObject, usually a #GtkWindow
364 * Gets a list of all accel groups which are attached to @object.
366 * Returns: (element-type GtkAccelGroup) (transfer none): a list of
367 * all accel groups which are attached to @object
370 gtk_accel_groups_from_object (GObject *object)
372 g_return_val_if_fail (G_IS_OBJECT (object), NULL);
374 return g_object_get_qdata (object, quark_acceleratable_groups);
378 * gtk_accel_group_find:
379 * @accel_group: a #GtkAccelGroup
380 * @find_func: (scope call): a function to filter the entries
381 * of @accel_group with
382 * @data: data to pass to @find_func
384 * Finds the first entry in an accelerator group for which
385 * @find_func returns %TRUE and returns its #GtkAccelKey.
387 * Returns: (transfer none): the key of the first entry passing
388 * @find_func. The key is owned by GTK+ and must not be freed.
391 gtk_accel_group_find (GtkAccelGroup *accel_group,
392 GtkAccelGroupFindFunc find_func,
395 GtkAccelKey *key = NULL;
398 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
399 g_return_val_if_fail (find_func != NULL, NULL);
401 g_object_ref (accel_group);
402 for (i = 0; i < accel_group->priv->n_accels; i++)
403 if (find_func (&accel_group->priv->priv_accels[i].key,
404 accel_group->priv->priv_accels[i].closure,
407 key = &accel_group->priv->priv_accels[i].key;
410 g_object_unref (accel_group);
416 * gtk_accel_group_lock:
417 * @accel_group: a #GtkAccelGroup
419 * Locks the given accelerator group.
421 * Locking an acelerator group prevents the accelerators contained
422 * within it to be changed during runtime. Refer to
423 * gtk_accel_map_change_entry() about runtime accelerator changes.
425 * If called more than once, @accel_group remains locked until
426 * gtk_accel_group_unlock() has been called an equivalent number
430 gtk_accel_group_lock (GtkAccelGroup *accel_group)
432 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
434 accel_group->priv->lock_count += 1;
436 if (accel_group->priv->lock_count == 1) {
437 /* State change from unlocked to locked */
438 g_object_notify (G_OBJECT (accel_group), "is-locked");
443 * gtk_accel_group_unlock:
444 * @accel_group: a #GtkAccelGroup
446 * Undoes the last call to gtk_accel_group_lock() on this @accel_group.
449 gtk_accel_group_unlock (GtkAccelGroup *accel_group)
451 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
452 g_return_if_fail (accel_group->priv->lock_count > 0);
454 accel_group->priv->lock_count -= 1;
456 if (accel_group->priv->lock_count < 1) {
457 /* State change from locked to unlocked */
458 g_object_notify (G_OBJECT (accel_group), "is-locked");
463 accel_closure_invalidate (gpointer data,
466 GtkAccelGroup *accel_group = GTK_ACCEL_GROUP (data);
468 gtk_accel_group_disconnect (accel_group, closure);
472 bsearch_compare_accels (const void *d1,
475 const GtkAccelGroupEntry *entry1 = d1;
476 const GtkAccelGroupEntry *entry2 = d2;
478 if (entry1->key.accel_key == entry2->key.accel_key)
479 return entry1->key.accel_mods < entry2->key.accel_mods ? -1 : entry1->key.accel_mods > entry2->key.accel_mods;
481 return entry1->key.accel_key < entry2->key.accel_key ? -1 : 1;
485 quick_accel_add (GtkAccelGroup *accel_group,
487 GdkModifierType accel_mods,
488 GtkAccelFlags accel_flags,
492 guint pos, i = accel_group->priv->n_accels++;
493 GtkAccelGroupEntry key;
496 key.key.accel_key = accel_key;
497 key.key.accel_mods = accel_mods;
498 for (pos = 0; pos < i; pos++)
499 if (bsearch_compare_accels (&key, accel_group->priv->priv_accels + pos) < 0)
502 /* insert at position, ref closure */
503 accel_group->priv->priv_accels = g_renew (GtkAccelGroupEntry, accel_group->priv->priv_accels, accel_group->priv->n_accels);
504 g_memmove (accel_group->priv->priv_accels + pos + 1, accel_group->priv->priv_accels + pos,
505 (i - pos) * sizeof (accel_group->priv->priv_accels[0]));
506 accel_group->priv->priv_accels[pos].key.accel_key = accel_key;
507 accel_group->priv->priv_accels[pos].key.accel_mods = accel_mods;
508 accel_group->priv->priv_accels[pos].key.accel_flags = accel_flags;
509 accel_group->priv->priv_accels[pos].closure = g_closure_ref (closure);
510 accel_group->priv->priv_accels[pos].accel_path_quark = path_quark;
511 g_closure_sink (closure);
513 /* handle closure invalidation and reverse lookups */
514 g_closure_add_invalidate_notifier (closure, accel_group, accel_closure_invalidate);
516 /* get accel path notification */
518 _gtk_accel_map_add_group (g_quark_to_string (path_quark), accel_group);
520 /* connect and notify changed */
523 gchar *accel_name = gtk_accelerator_name (accel_key, accel_mods);
524 GQuark accel_quark = g_quark_from_string (accel_name);
529 g_signal_connect_closure_by_id (accel_group, signal_accel_activate, accel_quark, closure, FALSE);
532 g_signal_emit (accel_group, signal_accel_changed, accel_quark, accel_key, accel_mods, closure);
537 quick_accel_remove (GtkAccelGroup *accel_group,
540 GQuark accel_quark = 0;
541 GtkAccelGroupEntry *entry = accel_group->priv->priv_accels + pos;
542 guint accel_key = entry->key.accel_key;
543 GdkModifierType accel_mods = entry->key.accel_mods;
544 GClosure *closure = entry->closure;
546 /* quark for notification */
549 gchar *accel_name = gtk_accelerator_name (accel_key, accel_mods);
551 accel_quark = g_quark_from_string (accel_name);
555 /* clean up closure invalidate notification and disconnect */
556 g_closure_remove_invalidate_notifier (entry->closure, accel_group, accel_closure_invalidate);
558 g_signal_handlers_disconnect_matched (accel_group,
559 G_SIGNAL_MATCH_ID | G_SIGNAL_MATCH_DETAIL | G_SIGNAL_MATCH_CLOSURE,
560 signal_accel_activate, accel_quark,
561 closure, NULL, NULL);
562 /* clean up accel path notification */
563 if (entry->accel_path_quark)
564 _gtk_accel_map_remove_group (g_quark_to_string (entry->accel_path_quark), accel_group);
566 /* physically remove */
567 accel_group->priv->n_accels -= 1;
568 g_memmove (entry, entry + 1,
569 (accel_group->priv->n_accels - pos) * sizeof (accel_group->priv->priv_accels[0]));
573 g_signal_emit (accel_group, signal_accel_changed, accel_quark, accel_key, accel_mods, closure);
575 /* remove quick_accel_add() refcount */
576 g_closure_unref (closure);
579 static GtkAccelGroupEntry*
580 quick_accel_find (GtkAccelGroup *accel_group,
582 GdkModifierType accel_mods,
585 GtkAccelGroupEntry *entry;
586 GtkAccelGroupEntry key;
590 if (!accel_group->priv->n_accels)
593 key.key.accel_key = accel_key;
594 key.key.accel_mods = accel_mods;
595 entry = bsearch (&key, accel_group->priv->priv_accels, accel_group->priv->n_accels,
596 sizeof (accel_group->priv->priv_accels[0]), bsearch_compare_accels);
601 /* step back to the first member */
602 for (; entry > accel_group->priv->priv_accels; entry--)
603 if (entry[-1].key.accel_key != accel_key ||
604 entry[-1].key.accel_mods != accel_mods)
606 /* count equal members */
607 for (; entry + *count_p < accel_group->priv->priv_accels + accel_group->priv->n_accels; (*count_p)++)
608 if (entry[*count_p].key.accel_key != accel_key ||
609 entry[*count_p].key.accel_mods != accel_mods)
615 * gtk_accel_group_connect:
616 * @accel_group: the accelerator group to install an accelerator in
617 * @accel_key: key value of the accelerator
618 * @accel_mods: modifier combination of the accelerator
619 * @accel_flags: a flag mask to configure this accelerator
620 * @closure: closure to be executed upon accelerator activation
622 * Installs an accelerator in this group. When @accel_group is being
623 * activated in response to a call to gtk_accel_groups_activate(),
624 * @closure will be invoked if the @accel_key and @accel_mods from
625 * gtk_accel_groups_activate() match those of this connection.
627 * The signature used for the @closure is that of #GtkAccelGroupActivate.
629 * Note that, due to implementation details, a single closure can
630 * only be connected to one accelerator group.
633 gtk_accel_group_connect (GtkAccelGroup *accel_group,
635 GdkModifierType accel_mods,
636 GtkAccelFlags accel_flags,
639 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
640 g_return_if_fail (closure != NULL);
641 g_return_if_fail (accel_key > 0);
642 g_return_if_fail (gtk_accel_group_from_accel_closure (closure) == NULL);
644 g_object_ref (accel_group);
645 if (!closure->is_invalid)
646 quick_accel_add (accel_group,
647 gdk_keyval_to_lower (accel_key),
648 accel_mods, accel_flags, closure, 0);
649 g_object_unref (accel_group);
653 * gtk_accel_group_connect_by_path:
654 * @accel_group: the accelerator group to install an accelerator in
655 * @accel_path: path used for determining key and modifiers
656 * @closure: closure to be executed upon accelerator activation
658 * Installs an accelerator in this group, using an accelerator path
659 * to look up the appropriate key and modifiers (see
660 * gtk_accel_map_add_entry()). When @accel_group is being activated
661 * in response to a call to gtk_accel_groups_activate(), @closure will
662 * be invoked if the @accel_key and @accel_mods from
663 * gtk_accel_groups_activate() match the key and modifiers for the path.
665 * The signature used for the @closure is that of #GtkAccelGroupActivate.
667 * Note that @accel_path string will be stored in a #GQuark. Therefore,
668 * if you pass a static string, you can save some memory by interning it
669 * first with g_intern_static_string().
672 gtk_accel_group_connect_by_path (GtkAccelGroup *accel_group,
673 const gchar *accel_path,
677 GdkModifierType accel_mods = 0;
680 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
681 g_return_if_fail (closure != NULL);
682 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
684 if (closure->is_invalid)
687 g_object_ref (accel_group);
689 if (gtk_accel_map_lookup_entry (accel_path, &key))
691 accel_key = gdk_keyval_to_lower (key.accel_key);
692 accel_mods = key.accel_mods;
695 quick_accel_add (accel_group, accel_key, accel_mods, GTK_ACCEL_VISIBLE, closure,
696 g_quark_from_string (accel_path));
698 g_object_unref (accel_group);
702 * gtk_accel_group_disconnect:
703 * @accel_group: the accelerator group to remove an accelerator from
704 * @closure: (allow-none): the closure to remove from this accelerator
705 * group, or %NULL to remove all closures
707 * Removes an accelerator previously installed through
708 * gtk_accel_group_connect().
710 * Since 2.20 @closure can be %NULL.
712 * Returns: %TRUE if the closure was found and got disconnected
715 gtk_accel_group_disconnect (GtkAccelGroup *accel_group,
720 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
722 for (i = 0; i < accel_group->priv->n_accels; i++)
723 if (accel_group->priv->priv_accels[i].closure == closure)
725 g_object_ref (accel_group);
726 quick_accel_remove (accel_group, i);
727 g_object_unref (accel_group);
734 * gtk_accel_group_disconnect_key:
735 * @accel_group: the accelerator group to install an accelerator in
736 * @accel_key: key value of the accelerator
737 * @accel_mods: modifier combination of the accelerator
739 * Removes an accelerator previously installed through
740 * gtk_accel_group_connect().
742 * Returns: %TRUE if there was an accelerator which could be
743 * removed, %FALSE otherwise
746 gtk_accel_group_disconnect_key (GtkAccelGroup *accel_group,
748 GdkModifierType accel_mods)
750 GtkAccelGroupEntry *entries;
751 GSList *slist, *clist = NULL;
752 gboolean removed_one = FALSE;
755 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
757 g_object_ref (accel_group);
759 accel_key = gdk_keyval_to_lower (accel_key);
760 entries = quick_accel_find (accel_group, accel_key, accel_mods, &n);
763 GClosure *closure = g_closure_ref (entries[n].closure);
765 clist = g_slist_prepend (clist, closure);
768 for (slist = clist; slist; slist = slist->next)
770 GClosure *closure = slist->data;
772 removed_one |= gtk_accel_group_disconnect (accel_group, closure);
773 g_closure_unref (closure);
775 g_slist_free (clist);
777 g_object_unref (accel_group);
783 _gtk_accel_group_reconnect (GtkAccelGroup *accel_group,
784 GQuark accel_path_quark)
786 GSList *slist, *clist = NULL;
789 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
791 g_object_ref (accel_group);
793 for (i = 0; i < accel_group->priv->n_accels; i++)
794 if (accel_group->priv->priv_accels[i].accel_path_quark == accel_path_quark)
796 GClosure *closure = g_closure_ref (accel_group->priv->priv_accels[i].closure);
798 clist = g_slist_prepend (clist, closure);
801 for (slist = clist; slist; slist = slist->next)
803 GClosure *closure = slist->data;
805 gtk_accel_group_disconnect (accel_group, closure);
806 gtk_accel_group_connect_by_path (accel_group, g_quark_to_string (accel_path_quark), closure);
807 g_closure_unref (closure);
809 g_slist_free (clist);
811 g_object_unref (accel_group);
815 _gtk_accel_group_get_accelerables (GtkAccelGroup *accel_group)
817 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
819 return accel_group->priv->acceleratables;
823 * gtk_accel_group_query:
824 * @accel_group: the accelerator group to query
825 * @accel_key: key value of the accelerator
826 * @accel_mods: modifier combination of the accelerator
827 * @n_entries: (allow-none): location to return the number
828 * of entries found, or %NULL
830 * Queries an accelerator group for all entries matching @accel_key
833 * Returns: (transfer none) (array length=n_entries): an array of
834 * @n_entries #GtkAccelGroupEntry elements, or %NULL. The array
835 * is owned by GTK+ and must not be freed.
838 gtk_accel_group_query (GtkAccelGroup *accel_group,
840 GdkModifierType accel_mods,
843 GtkAccelGroupEntry *entries;
846 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), NULL);
848 entries = quick_accel_find (accel_group, gdk_keyval_to_lower (accel_key), accel_mods, &n);
851 *n_entries = entries ? n : 0;
857 * gtk_accel_group_from_accel_closure:
858 * @closure: a #GClosure
860 * Finds the #GtkAccelGroup to which @closure is connected;
861 * see gtk_accel_group_connect().
863 * Returns: (transfer none): the #GtkAccelGroup to which @closure
864 * is connected, or %NULL
867 gtk_accel_group_from_accel_closure (GClosure *closure)
871 g_return_val_if_fail (closure != NULL, NULL);
873 /* A few remarks on what we do here. in general, we need a way to
874 * reverse lookup accel_groups from closures that are being used in
875 * accel groups. this could be done e.g via a hashtable. it is however
876 * cheaper (memory wise) to just use the invalidation notifier on the
877 * closure itself (which we need to install anyway), that contains the
878 * accel group as data which, besides needing to peek a bit at closure
879 * internals, works just as good.
881 for (i = 0; i < G_CLOSURE_N_NOTIFIERS (closure); i++)
882 if (closure->notifiers[i].notify == accel_closure_invalidate)
883 return closure->notifiers[i].data;
889 * gtk_accel_group_activate:
890 * @accel_group: a #GtkAccelGroup
891 * @accel_quark: the quark for the accelerator name
892 * @acceleratable: the #GObject, usually a #GtkWindow, on which
893 * to activate the accelerator
894 * @accel_key: accelerator keyval from a key event
895 * @accel_mods: keyboard state mask from a key event
897 * Finds the first accelerator in @accel_group that matches
898 * @accel_key and @accel_mods, and activates it.
900 * Returns: %TRUE if an accelerator was activated and handled
904 gtk_accel_group_activate (GtkAccelGroup *accel_group,
906 GObject *acceleratable,
908 GdkModifierType accel_mods)
910 gboolean was_handled;
912 g_return_val_if_fail (GTK_IS_ACCEL_GROUP (accel_group), FALSE);
913 g_return_val_if_fail (G_IS_OBJECT (acceleratable), FALSE);
916 g_signal_emit (accel_group, signal_accel_activate, accel_quark,
917 acceleratable, accel_key, accel_mods, &was_handled);
923 * gtk_accel_groups_activate:
924 * @object: the #GObject, usually a #GtkWindow, on which
925 * to activate the accelerator
926 * @accel_key: accelerator keyval from a key event
927 * @accel_mods: keyboard state mask from a key event
929 * Finds the first accelerator in any #GtkAccelGroup attached
930 * to @object that matches @accel_key and @accel_mods, and
931 * activates that accelerator.
933 * Returns: %TRUE if an accelerator was activated and handled
937 gtk_accel_groups_activate (GObject *object,
939 GdkModifierType accel_mods)
941 g_return_val_if_fail (G_IS_OBJECT (object), FALSE);
943 if (gtk_accelerator_valid (accel_key, accel_mods))
949 accel_name = gtk_accelerator_name (accel_key, (accel_mods & gtk_accelerator_get_default_mod_mask ()));
950 accel_quark = g_quark_from_string (accel_name);
953 for (slist = gtk_accel_groups_from_object (object); slist; slist = slist->next)
954 if (gtk_accel_group_activate (slist->data, accel_quark, object, accel_key, accel_mods))
962 * gtk_accelerator_valid:
963 * @keyval: a GDK keyval
964 * @modifiers: modifier mask
966 * Determines whether a given keyval and modifier mask constitute
967 * a valid keyboard accelerator. For example, the #GDK_KEY_a keyval
968 * plus #GDK_CONTROL_MASK is valid - this is a "Ctrl+a" accelerator.
969 * But, you can't, for instance, use the #GDK_KEY_Control_L keyval
972 * Returns: %TRUE if the accelerator is valid
975 gtk_accelerator_valid (guint keyval,
976 GdkModifierType modifiers)
978 static const guint invalid_accelerator_vals[] = {
979 GDK_KEY_Shift_L, GDK_KEY_Shift_R, GDK_KEY_Shift_Lock,
980 GDK_KEY_Caps_Lock, GDK_KEY_ISO_Lock, GDK_KEY_Control_L,
981 GDK_KEY_Control_R, GDK_KEY_Meta_L, GDK_KEY_Meta_R,
982 GDK_KEY_Alt_L, GDK_KEY_Alt_R, GDK_KEY_Super_L, GDK_KEY_Super_R,
983 GDK_KEY_Hyper_L, GDK_KEY_Hyper_R, GDK_KEY_ISO_Level3_Shift,
984 GDK_KEY_ISO_Next_Group, GDK_KEY_ISO_Prev_Group,
985 GDK_KEY_ISO_First_Group, GDK_KEY_ISO_Last_Group,
986 GDK_KEY_Mode_switch, GDK_KEY_Num_Lock, GDK_KEY_Multi_key,
987 GDK_KEY_Scroll_Lock, GDK_KEY_Sys_Req,
988 GDK_KEY_Tab, GDK_KEY_ISO_Left_Tab, GDK_KEY_KP_Tab,
989 GDK_KEY_First_Virtual_Screen, GDK_KEY_Prev_Virtual_Screen,
990 GDK_KEY_Next_Virtual_Screen, GDK_KEY_Last_Virtual_Screen,
991 GDK_KEY_Terminate_Server, GDK_KEY_AudibleBell_Enable,
994 static const guint invalid_unmodified_vals[] = {
995 GDK_KEY_Up, GDK_KEY_Down, GDK_KEY_Left, GDK_KEY_Right,
996 GDK_KEY_KP_Up, GDK_KEY_KP_Down, GDK_KEY_KP_Left, GDK_KEY_KP_Right,
1001 modifiers &= GDK_MODIFIER_MASK;
1004 return keyval >= 0x20;
1006 ac_val = invalid_accelerator_vals;
1009 if (keyval == *ac_val++)
1015 ac_val = invalid_unmodified_vals;
1018 if (keyval == *ac_val++)
1026 static inline gboolean
1027 is_alt (const gchar *string)
1029 return ((string[0] == '<') &&
1030 (string[1] == 'a' || string[1] == 'A') &&
1031 (string[2] == 'l' || string[2] == 'L') &&
1032 (string[3] == 't' || string[3] == 'T') &&
1033 (string[4] == '>'));
1036 static inline gboolean
1037 is_ctl (const gchar *string)
1039 return ((string[0] == '<') &&
1040 (string[1] == 'c' || string[1] == 'C') &&
1041 (string[2] == 't' || string[2] == 'T') &&
1042 (string[3] == 'l' || string[3] == 'L') &&
1043 (string[4] == '>'));
1046 static inline gboolean
1047 is_modx (const gchar *string)
1049 return ((string[0] == '<') &&
1050 (string[1] == 'm' || string[1] == 'M') &&
1051 (string[2] == 'o' || string[2] == 'O') &&
1052 (string[3] == 'd' || string[3] == 'D') &&
1053 (string[4] >= '1' && string[4] <= '5') &&
1054 (string[5] == '>'));
1057 static inline gboolean
1058 is_ctrl (const gchar *string)
1060 return ((string[0] == '<') &&
1061 (string[1] == 'c' || string[1] == 'C') &&
1062 (string[2] == 't' || string[2] == 'T') &&
1063 (string[3] == 'r' || string[3] == 'R') &&
1064 (string[4] == 'l' || string[4] == 'L') &&
1065 (string[5] == '>'));
1068 static inline gboolean
1069 is_shft (const gchar *string)
1071 return ((string[0] == '<') &&
1072 (string[1] == 's' || string[1] == 'S') &&
1073 (string[2] == 'h' || string[2] == 'H') &&
1074 (string[3] == 'f' || string[3] == 'F') &&
1075 (string[4] == 't' || string[4] == 'T') &&
1076 (string[5] == '>'));
1079 static inline gboolean
1080 is_shift (const gchar *string)
1082 return ((string[0] == '<') &&
1083 (string[1] == 's' || string[1] == 'S') &&
1084 (string[2] == 'h' || string[2] == 'H') &&
1085 (string[3] == 'i' || string[3] == 'I') &&
1086 (string[4] == 'f' || string[4] == 'F') &&
1087 (string[5] == 't' || string[5] == 'T') &&
1088 (string[6] == '>'));
1091 static inline gboolean
1092 is_control (const gchar *string)
1094 return ((string[0] == '<') &&
1095 (string[1] == 'c' || string[1] == 'C') &&
1096 (string[2] == 'o' || string[2] == 'O') &&
1097 (string[3] == 'n' || string[3] == 'N') &&
1098 (string[4] == 't' || string[4] == 'T') &&
1099 (string[5] == 'r' || string[5] == 'R') &&
1100 (string[6] == 'o' || string[6] == 'O') &&
1101 (string[7] == 'l' || string[7] == 'L') &&
1102 (string[8] == '>'));
1105 static inline gboolean
1106 is_release (const gchar *string)
1108 return ((string[0] == '<') &&
1109 (string[1] == 'r' || string[1] == 'R') &&
1110 (string[2] == 'e' || string[2] == 'E') &&
1111 (string[3] == 'l' || string[3] == 'L') &&
1112 (string[4] == 'e' || string[4] == 'E') &&
1113 (string[5] == 'a' || string[5] == 'A') &&
1114 (string[6] == 's' || string[6] == 'S') &&
1115 (string[7] == 'e' || string[7] == 'E') &&
1116 (string[8] == '>'));
1119 static inline gboolean
1120 is_meta (const gchar *string)
1122 return ((string[0] == '<') &&
1123 (string[1] == 'm' || string[1] == 'M') &&
1124 (string[2] == 'e' || string[2] == 'E') &&
1125 (string[3] == 't' || string[3] == 'T') &&
1126 (string[4] == 'a' || string[4] == 'A') &&
1127 (string[5] == '>'));
1130 static inline gboolean
1131 is_super (const gchar *string)
1133 return ((string[0] == '<') &&
1134 (string[1] == 's' || string[1] == 'S') &&
1135 (string[2] == 'u' || string[2] == 'U') &&
1136 (string[3] == 'p' || string[3] == 'P') &&
1137 (string[4] == 'e' || string[4] == 'E') &&
1138 (string[5] == 'r' || string[5] == 'R') &&
1139 (string[6] == '>'));
1142 static inline gboolean
1143 is_hyper (const gchar *string)
1145 return ((string[0] == '<') &&
1146 (string[1] == 'h' || string[1] == 'H') &&
1147 (string[2] == 'y' || string[2] == 'Y') &&
1148 (string[3] == 'p' || string[3] == 'P') &&
1149 (string[4] == 'e' || string[4] == 'E') &&
1150 (string[5] == 'r' || string[5] == 'R') &&
1151 (string[6] == '>'));
1154 static inline gboolean
1155 is_primary (const gchar *string)
1157 return ((string[0] == '<') &&
1158 (string[1] == 'p' || string[1] == 'P') &&
1159 (string[2] == 'r' || string[2] == 'R') &&
1160 (string[3] == 'i' || string[3] == 'I') &&
1161 (string[4] == 'm' || string[4] == 'M') &&
1162 (string[5] == 'a' || string[5] == 'A') &&
1163 (string[6] == 'r' || string[6] == 'R') &&
1164 (string[7] == 'y' || string[7] == 'Y') &&
1165 (string[8] == '>'));
1168 static inline gboolean
1169 is_keycode (const gchar *string)
1171 return (string[0] == '0' &&
1173 g_ascii_isxdigit (string[2]) &&
1174 g_ascii_isxdigit (string[3]));
1178 * gtk_accelerator_parse_with_keycode:
1179 * @accelerator: string representing an accelerator
1180 * @accelerator_key: (out) (allow-none): return location for accelerator
1182 * @accelerator_codes: (out) (allow-none): return location for accelerator
1183 * keycodes, or %NULL
1184 * @accelerator_mods: (out) (allow-none): return location for accelerator
1185 * modifier mask, %NULL
1187 * Parses a string representing an accelerator, similarly to
1188 * gtk_accelerator_parse() but handles keycodes as well. This is only
1189 * useful for system-level components, applications should use
1190 * gtk_accelerator_parse() instead.
1192 * If a keycode is present in the accelerator and no @accelerator_codes
1193 * is given, the parse will fail.
1195 * If the parse fails, @accelerator_key, @accelerator_mods and
1196 * @accelerator_codes will be set to 0 (zero).
1201 gtk_accelerator_parse_with_keycode (const gchar *accelerator,
1202 guint *accelerator_key,
1203 guint **accelerator_codes,
1204 GdkModifierType *accelerator_mods)
1207 GdkModifierType mods;
1211 if (accelerator_key)
1212 *accelerator_key = 0;
1213 if (accelerator_mods)
1214 *accelerator_mods = 0;
1215 if (accelerator_codes)
1216 *accelerator_codes = NULL;
1217 g_return_if_fail (accelerator != NULL);
1222 len = strlen (accelerator);
1225 if (*accelerator == '<')
1227 if (len >= 9 && is_release (accelerator))
1231 mods |= GDK_RELEASE_MASK;
1233 else if (len >= 9 && is_primary (accelerator))
1237 mods |= _gtk_get_primary_accel_mod ();
1239 else if (len >= 9 && is_control (accelerator))
1243 mods |= GDK_CONTROL_MASK;
1245 else if (len >= 7 && is_shift (accelerator))
1249 mods |= GDK_SHIFT_MASK;
1251 else if (len >= 6 && is_shft (accelerator))
1255 mods |= GDK_SHIFT_MASK;
1257 else if (len >= 6 && is_ctrl (accelerator))
1261 mods |= GDK_CONTROL_MASK;
1263 else if (len >= 6 && is_modx (accelerator))
1265 static const guint mod_vals[] = {
1266 GDK_MOD1_MASK, GDK_MOD2_MASK, GDK_MOD3_MASK,
1267 GDK_MOD4_MASK, GDK_MOD5_MASK
1272 mods |= mod_vals[*accelerator - '1'];
1275 else if (len >= 5 && is_ctl (accelerator))
1279 mods |= GDK_CONTROL_MASK;
1281 else if (len >= 5 && is_alt (accelerator))
1285 mods |= GDK_MOD1_MASK;
1287 else if (len >= 6 && is_meta (accelerator))
1291 mods |= GDK_META_MASK;
1293 else if (len >= 7 && is_hyper (accelerator))
1297 mods |= GDK_HYPER_MASK;
1299 else if (len >= 7 && is_super (accelerator))
1303 mods |= GDK_SUPER_MASK;
1309 last_ch = *accelerator;
1310 while (last_ch && last_ch != '>')
1312 last_ch = *accelerator;
1320 if (len >= 4 && is_keycode (accelerator))
1326 memcpy (keystring, accelerator, 4);
1327 keystring [4] = '\000';
1329 tmp_keycode = strtol (keystring, &endptr, 16);
1331 if (endptr == NULL || *endptr != '\000')
1336 else if (accelerator_codes != NULL)
1338 /* 0x00 is an invalid keycode too. */
1339 if (tmp_keycode == 0)
1346 *accelerator_codes = g_new0 (guint, 2);
1347 (*accelerator_codes)[0] = tmp_keycode;
1352 /* There was a keycode in the string, but
1353 * we cannot store it, so we have an error */
1360 keyval = gdk_keyval_from_name (accelerator);
1361 if (keyval == GDK_KEY_VoidSymbol)
1368 if (keyval && accelerator_codes != NULL)
1373 if (!gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (), keyval, &keys, &n_keys))
1381 *accelerator_codes = g_new0 (guint, n_keys + 1);
1383 for (i = 0, j = 0; i < n_keys; ++i)
1385 if (keys[i].level == 0)
1386 (*accelerator_codes)[j++] = keys[i].keycode;
1391 g_free (*accelerator_codes);
1392 *accelerator_codes = NULL;
1410 if (accelerator_key)
1411 *accelerator_key = gdk_keyval_to_lower (keyval);
1412 if (accelerator_mods)
1413 *accelerator_mods = mods;
1417 * gtk_accelerator_parse:
1418 * @accelerator: string representing an accelerator
1419 * @accelerator_key: (out) (allow-none): return location for accelerator
1421 * @accelerator_mods: (out) (allow-none): return location for accelerator
1422 * modifier mask, %NULL
1424 * Parses a string representing an accelerator. The
1425 * format looks like "<Control>a" or "<Shift><Alt>F1"
1426 * or "<Release>z" (the last one is for key release).
1428 * The parser is fairly liberal and allows lower or upper case,
1429 * and also abbreviations such as "<Ctl>" and "<Ctrl>".
1430 * Key names are parsed using gdk_keyval_from_name(). For character
1431 * keys the name is not the symbol, but the lowercase name, e.g. one
1432 * would use "<Ctrl>minus" instead of "<Ctrl>-".
1434 * If the parse fails, @accelerator_key and @accelerator_mods will
1435 * be set to 0 (zero).
1438 gtk_accelerator_parse (const gchar *accelerator,
1439 guint *accelerator_key,
1440 GdkModifierType *accelerator_mods)
1442 gtk_accelerator_parse_with_keycode (accelerator, accelerator_key, NULL, accelerator_mods);
1446 * gtk_accelerator_name_with_keycode:
1447 * @display: (allow-none): a #GdkDisplay or %NULL to use the default display
1448 * @accelerator_key: accelerator keyval
1449 * @accelerator_mods: accelerator modifier mask
1451 * Converts an accelerator keyval and modifier mask
1452 * into a string parseable by gtk_accelerator_parse_full(),
1453 * similarly to gtk_accelerator_name() but handling keycodes.
1454 * This is only useful for system-level components, applications
1455 * should use gtk_accelerator_parse() instead.
1457 * Returns: a newly allocated accelerator name.
1462 gtk_accelerator_name_with_keycode (GdkDisplay *display,
1463 guint accelerator_key,
1465 GdkModifierType accelerator_mods)
1469 if (display == NULL)
1470 display = gdk_display_manager_get_default_display (gdk_display_manager_get ());
1472 gdk_keymap_add_virtual_modifiers (gdk_keymap_get_for_display (display), &accelerator_mods);
1473 gtk_name = gtk_accelerator_name (accelerator_key, accelerator_mods);
1475 if (!accelerator_key)
1478 name = g_strdup_printf ("%s0x%02x", gtk_name, keycode);
1487 * gtk_accelerator_name:
1488 * @accelerator_key: accelerator keyval
1489 * @accelerator_mods: accelerator modifier mask
1491 * Converts an accelerator keyval and modifier mask
1492 * into a string parseable by gtk_accelerator_parse().
1493 * For example, if you pass in #GDK_KEY_q and #GDK_CONTROL_MASK,
1494 * this function returns "<Control>q".
1496 * If you need to display accelerators in the user interface,
1497 * see gtk_accelerator_get_label().
1499 * Returns: a newly-allocated accelerator name
1502 gtk_accelerator_name (guint accelerator_key,
1503 GdkModifierType accelerator_mods)
1505 static const gchar text_release[] = "<Release>";
1506 static const gchar text_primary[] = "<Primary>";
1507 static const gchar text_shift[] = "<Shift>";
1508 static const gchar text_control[] = "<Control>";
1509 static const gchar text_mod1[] = "<Alt>";
1510 static const gchar text_mod2[] = "<Mod2>";
1511 static const gchar text_mod3[] = "<Mod3>";
1512 static const gchar text_mod4[] = "<Mod4>";
1513 static const gchar text_mod5[] = "<Mod5>";
1514 static const gchar text_meta[] = "<Meta>";
1515 static const gchar text_super[] = "<Super>";
1516 static const gchar text_hyper[] = "<Hyper>";
1517 GdkModifierType saved_mods;
1522 accelerator_mods &= GDK_MODIFIER_MASK;
1524 keyval_name = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
1528 saved_mods = accelerator_mods;
1530 if (accelerator_mods & GDK_RELEASE_MASK)
1531 l += sizeof (text_release) - 1;
1532 if (accelerator_mods & _gtk_get_primary_accel_mod ())
1534 l += sizeof (text_primary) - 1;
1535 accelerator_mods &= ~_gtk_get_primary_accel_mod (); /* consume the default accel */
1537 if (accelerator_mods & GDK_SHIFT_MASK)
1538 l += sizeof (text_shift) - 1;
1539 if (accelerator_mods & GDK_CONTROL_MASK)
1540 l += sizeof (text_control) - 1;
1541 if (accelerator_mods & GDK_MOD1_MASK)
1542 l += sizeof (text_mod1) - 1;
1543 if (accelerator_mods & GDK_MOD2_MASK)
1544 l += sizeof (text_mod2) - 1;
1545 if (accelerator_mods & GDK_MOD3_MASK)
1546 l += sizeof (text_mod3) - 1;
1547 if (accelerator_mods & GDK_MOD4_MASK)
1548 l += sizeof (text_mod4) - 1;
1549 if (accelerator_mods & GDK_MOD5_MASK)
1550 l += sizeof (text_mod5) - 1;
1551 l += strlen (keyval_name);
1552 if (accelerator_mods & GDK_META_MASK)
1553 l += sizeof (text_meta) - 1;
1554 if (accelerator_mods & GDK_HYPER_MASK)
1555 l += sizeof (text_hyper) - 1;
1556 if (accelerator_mods & GDK_SUPER_MASK)
1557 l += sizeof (text_super) - 1;
1559 accelerator = g_new (gchar, l + 1);
1561 accelerator_mods = saved_mods;
1564 if (accelerator_mods & GDK_RELEASE_MASK)
1566 strcpy (accelerator + l, text_release);
1567 l += sizeof (text_release) - 1;
1569 if (accelerator_mods & _gtk_get_primary_accel_mod ())
1571 strcpy (accelerator + l, text_primary);
1572 l += sizeof (text_primary) - 1;
1573 accelerator_mods &= ~_gtk_get_primary_accel_mod (); /* consume the default accel */
1575 if (accelerator_mods & GDK_SHIFT_MASK)
1577 strcpy (accelerator + l, text_shift);
1578 l += sizeof (text_shift) - 1;
1580 if (accelerator_mods & GDK_CONTROL_MASK)
1582 strcpy (accelerator + l, text_control);
1583 l += sizeof (text_control) - 1;
1585 if (accelerator_mods & GDK_MOD1_MASK)
1587 strcpy (accelerator + l, text_mod1);
1588 l += sizeof (text_mod1) - 1;
1590 if (accelerator_mods & GDK_MOD2_MASK)
1592 strcpy (accelerator + l, text_mod2);
1593 l += sizeof (text_mod2) - 1;
1595 if (accelerator_mods & GDK_MOD3_MASK)
1597 strcpy (accelerator + l, text_mod3);
1598 l += sizeof (text_mod3) - 1;
1600 if (accelerator_mods & GDK_MOD4_MASK)
1602 strcpy (accelerator + l, text_mod4);
1603 l += sizeof (text_mod4) - 1;
1605 if (accelerator_mods & GDK_MOD5_MASK)
1607 strcpy (accelerator + l, text_mod5);
1608 l += sizeof (text_mod5) - 1;
1610 if (accelerator_mods & GDK_META_MASK)
1612 strcpy (accelerator + l, text_meta);
1613 l += sizeof (text_meta) - 1;
1615 if (accelerator_mods & GDK_HYPER_MASK)
1617 strcpy (accelerator + l, text_hyper);
1618 l += sizeof (text_hyper) - 1;
1620 if (accelerator_mods & GDK_SUPER_MASK)
1622 strcpy (accelerator + l, text_super);
1623 l += sizeof (text_super) - 1;
1625 strcpy (accelerator + l, keyval_name);
1631 * gtk_accelerator_get_label_with_keycode:
1632 * @display: (allow-none): a #GdkDisplay or %NULL to use the default display
1633 * @accelerator_key: accelerator keyval
1634 * @accelerator_mods: accelerator modifier mask
1636 * Converts an accelerator keyval and modifier mask
1637 * into a (possibly translated) string that can be displayed to
1638 * a user, similarly to gtk_accelerator_get_label(), but handling
1641 * This is only useful for system-level components, applications
1642 * should use gtk_accelerator_parse() instead.
1644 * Returns: a newly-allocated string representing the accelerator.
1649 gtk_accelerator_get_label_with_keycode (GdkDisplay *display,
1650 guint accelerator_key,
1652 GdkModifierType accelerator_mods)
1656 if (display == NULL)
1657 display = gdk_display_manager_get_default_display (gdk_display_manager_get ());
1659 gdk_keymap_add_virtual_modifiers (gdk_keymap_get_for_display (display), &accelerator_mods);
1660 gtk_label = gtk_accelerator_get_label (accelerator_key, accelerator_mods);
1662 if (!accelerator_key)
1665 label = g_strdup_printf ("%s0x%02x", gtk_label, keycode);
1674 * gtk_accelerator_get_label:
1675 * @accelerator_key: accelerator keyval
1676 * @accelerator_mods: accelerator modifier mask
1678 * Converts an accelerator keyval and modifier mask into a string
1679 * which can be used to represent the accelerator to the user.
1681 * Returns: a newly-allocated string representing the accelerator.
1686 gtk_accelerator_get_label (guint accelerator_key,
1687 GdkModifierType accelerator_mods)
1689 GtkAccelLabelClass *klass;
1692 klass = g_type_class_ref (GTK_TYPE_ACCEL_LABEL);
1693 label = _gtk_accel_label_class_get_accelerator_label (klass,
1696 g_type_class_unref (klass); /* klass is kept alive since gtk uses static types */
1702 * gtk_accelerator_set_default_mod_mask:
1703 * @default_mod_mask: accelerator modifier mask
1705 * Sets the modifiers that will be considered significant for keyboard
1706 * accelerators. The default mod mask is #GDK_CONTROL_MASK |
1707 * #GDK_SHIFT_MASK | #GDK_MOD1_MASK | #GDK_SUPER_MASK |
1708 * #GDK_HYPER_MASK | #GDK_META_MASK, that is, Control, Shift, Alt,
1709 * Super, Hyper and Meta. Other modifiers will by default be ignored
1710 * by #GtkAccelGroup.
1711 * You must include at least the three modifiers Control, Shift
1712 * and Alt in any value you pass to this function.
1714 * The default mod mask should be changed on application startup,
1715 * before using any accelerator groups.
1718 gtk_accelerator_set_default_mod_mask (GdkModifierType default_mod_mask)
1720 default_accel_mod_mask = (default_mod_mask & GDK_MODIFIER_MASK) |
1721 (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK);
1725 * gtk_accelerator_get_default_mod_mask:
1727 * Gets the value set by gtk_accelerator_set_default_mod_mask().
1729 * Returns: the default accelerator modifier mask
1732 gtk_accelerator_get_default_mod_mask (void)
1734 return default_accel_mod_mask;