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.
22 #include "gtkaccelmap.h"
24 #include "gtkmarshalers.h"
25 #include "gtkwindow.h" /* in lack of GtkAcceleratable */
29 #include <glib/gstdio.h>
42 /* --- structures --- */
45 GObject parent_instance;
48 struct _GtkAccelMapClass
50 GObjectClass parent_class;
54 const gchar *accel_path;
60 guint lock_count : 15;
70 /* --- variables --- */
72 static GHashTable *accel_entry_ht = NULL; /* accel_path -> AccelEntry */
73 static GSList *accel_filters = NULL;
74 static gulong accel_map_signals[LAST_SIGNAL] = { 0, };
75 static GtkAccelMap *accel_map;
77 /* --- prototypes --- */
78 static void do_accel_map_changed (AccelEntry *entry);
80 /* --- functions --- */
82 accel_entry_hash (gconstpointer key)
84 const AccelEntry *entry = key;
86 return g_str_hash (entry->accel_path);
90 accel_entry_equal (gconstpointer key1,
93 const AccelEntry *entry1 = key1;
94 const AccelEntry *entry2 = key2;
96 return g_str_equal (entry1->accel_path, entry2->accel_path);
99 static inline AccelEntry*
100 accel_path_lookup (const gchar *accel_path)
104 ekey.accel_path = accel_path;
106 /* safety NULL check for return_if_fail()s */
107 return accel_path ? g_hash_table_lookup (accel_entry_ht, &ekey) : NULL;
111 _gtk_accel_map_init (void)
113 g_assert (accel_entry_ht == NULL);
115 accel_entry_ht = g_hash_table_new (accel_entry_hash, accel_entry_equal);
119 _gtk_accel_path_is_valid (const gchar *accel_path)
123 if (!accel_path || accel_path[0] != '<' ||
124 accel_path[1] == '<' || accel_path[1] == '>' || !accel_path[1])
126 p = strchr (accel_path, '>');
127 if (!p || (p[1] != 0 && p[1] != '/'))
133 * gtk_accel_map_add_entry:
134 * @accel_path: valid accelerator path
135 * @accel_key: the accelerator key
136 * @accel_mods: the accelerator modifiers
138 * Registers a new accelerator with the global accelerator map.
139 * This function should only be called once per @accel_path
140 * with the canonical @accel_key and @accel_mods for this path.
141 * To change the accelerator during runtime programatically, use
142 * gtk_accel_map_change_entry().
143 * The accelerator path must consist of "<WINDOWTYPE>/Category1/Category2/.../Action",
144 * where <WINDOWTYPE> should be a unique application-specific identifier, that
145 * corresponds to the kind of window the accelerator is being used in, e.g. "Gimp-Image",
146 * "Abiword-Document" or "Gnumeric-Settings".
147 * The Category1/.../Action portion is most appropriately chosen by the action the
148 * accelerator triggers, i.e. for accelerators on menu items, choose the item's menu path,
149 * e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All".
150 * So a full valid accelerator path may look like:
151 * "<Gimp-Toolbox>/File/Dialogs/Tool Options...".
153 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
154 * pass a static string, you can save some memory by interning it first with
155 * g_intern_static_string().
158 gtk_accel_map_add_entry (const gchar *accel_path,
160 GdkModifierType accel_mods)
164 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
169 accel_mods &= gtk_accelerator_get_default_mod_mask ();
171 entry = accel_path_lookup (accel_path);
174 if (!entry->std_accel_key && !entry->std_accel_mods &&
175 (accel_key || accel_mods))
177 entry->std_accel_key = accel_key;
178 entry->std_accel_mods = accel_mods;
180 gtk_accel_map_change_entry (entry->accel_path, accel_key, accel_mods, TRUE);
185 entry = g_slice_new0 (AccelEntry);
186 entry->accel_path = g_intern_string (accel_path);
187 entry->std_accel_key = accel_key;
188 entry->std_accel_mods = accel_mods;
189 entry->accel_key = accel_key;
190 entry->accel_mods = accel_mods;
191 entry->changed = FALSE;
192 entry->lock_count = 0;
193 g_hash_table_insert (accel_entry_ht, entry, entry);
195 do_accel_map_changed (entry);
200 * gtk_accel_map_lookup_entry:
201 * @accel_path: a valid accelerator path
202 * @key: the accelerator key to be filled in (optional)
203 * @returns: %TRUE if @accel_path is known, %FALSE otherwise
205 * Looks up the accelerator entry for @accel_path and fills in @key.
208 gtk_accel_map_lookup_entry (const gchar *accel_path,
213 g_return_val_if_fail (_gtk_accel_path_is_valid (accel_path), FALSE);
215 entry = accel_path_lookup (accel_path);
218 key->accel_key = entry->accel_key;
219 key->accel_mods = entry->accel_mods;
220 key->accel_flags = 0;
223 return entry ? TRUE : FALSE;
227 hash2slist_foreach (gpointer key,
231 GSList **slist_p = user_data;
233 *slist_p = g_slist_prepend (*slist_p, value);
237 g_hash_table_slist_values (GHashTable *hash_table)
239 GSList *slist = NULL;
241 g_return_val_if_fail (hash_table != NULL, NULL);
243 g_hash_table_foreach (hash_table, hash2slist_foreach, &slist);
248 /* if simulate==TRUE, return whether accel_path can be changed to
249 * accel_key && accel_mods. otherwise, return whether accel_path
250 * was actually changed.
253 internal_change_entry (const gchar *accel_path,
255 GdkModifierType accel_mods,
259 GSList *node, *slist, *win_list, *group_list, *replace_list = NULL;
260 GHashTable *group_hm, *window_hm;
261 gboolean change_accel, removable, can_change = TRUE, seen_accel = FALSE;
263 AccelEntry *entry = accel_path_lookup (accel_path);
265 /* not much todo if there's no entry yet */
270 gtk_accel_map_add_entry (accel_path, 0, 0);
271 entry = accel_path_lookup (accel_path);
272 entry->accel_key = accel_key;
273 entry->accel_mods = accel_mods;
274 entry->changed = TRUE;
276 do_accel_map_changed (entry);
281 /* if there's nothing to change, not much todo either */
282 if (entry->accel_key == accel_key && entry->accel_mods == accel_mods)
285 entry->changed = TRUE;
286 return simulate ? TRUE : FALSE;
289 /* The no-change case has already been handled, so
290 * simulate doesn't make a difference here.
292 if (entry->lock_count > 0)
295 /* nobody's interested, easy going */
300 entry->accel_key = accel_key;
301 entry->accel_mods = accel_mods;
302 entry->changed = TRUE;
304 do_accel_map_changed (entry);
309 /* 1) fetch all accel groups affected by this entry */
310 entry_quark = g_quark_try_string (entry->accel_path);
311 group_hm = g_hash_table_new (NULL, NULL);
312 window_hm = g_hash_table_new (NULL, NULL);
313 for (slist = entry->groups; slist; slist = slist->next)
314 g_hash_table_insert (group_hm, slist->data, slist->data);
316 /* 2) collect acceleratables affected */
317 group_list = g_hash_table_slist_values (group_hm);
318 for (slist = group_list; slist; slist = slist->next)
320 GtkAccelGroup *group = slist->data;
322 for (node = _gtk_accel_group_get_accelerables (group); node; node = node->next)
323 g_hash_table_insert (window_hm, node->data, node->data);
325 g_slist_free (group_list);
327 /* 3) include all accel groups used by acceleratables */
328 win_list = g_hash_table_slist_values (window_hm);
329 g_hash_table_destroy (window_hm);
330 for (slist = win_list; slist; slist = slist->next)
331 for (node = gtk_accel_groups_from_object (slist->data); node; node = node->next)
332 g_hash_table_insert (group_hm, node->data, node->data);
333 group_list = g_hash_table_slist_values (group_hm);
334 g_hash_table_destroy (group_hm);
336 /* 4) walk the acceleratables and figure whether they occupy accel_key&accel_mods */
338 for (slist = win_list; slist; slist = slist->next)
339 if (GTK_IS_WINDOW (slist->data)) /* bad kludge in lack of a GtkAcceleratable */
340 if (_gtk_window_query_nonaccels (slist->data, accel_key, accel_mods))
345 removable = !seen_accel;
347 /* 5) walk all accel groups and search for locks */
349 for (slist = group_list; slist; slist = slist->next)
351 GtkAccelGroup *group = slist->data;
352 GtkAccelGroupEntry *ag_entry;
356 ag_entry = entry->accel_key ? gtk_accel_group_query (group, entry->accel_key, entry->accel_mods, &n) : NULL;
357 for (i = 0; i < n; i++)
358 if (ag_entry[i].accel_path_quark == entry_quark)
360 can_change = !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
362 goto break_loop_step5;
366 ag_entry = accel_key ? gtk_accel_group_query (group, accel_key, accel_mods, &n) : NULL;
367 for (i = 0; i < n; i++)
370 removable = !gtk_accel_group_get_is_locked (group) && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
372 goto break_loop_step5;
373 if (ag_entry[i].accel_path_quark)
374 replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry[i].accel_path_quark));
379 /* 6) check whether we can remove existing accelerators */
380 if (removable && can_change)
381 for (slist = replace_list; slist; slist = slist->next)
382 if (!internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, TRUE))
388 /* 7) check conditions and proceed if possible */
389 change_accel = can_change && (!seen_accel || (removable && replace));
391 if (change_accel && !simulate)
393 /* ref accel groups */
394 for (slist = group_list; slist; slist = slist->next)
395 g_object_ref (slist->data);
397 /* 8) remove existing accelerators */
398 for (slist = replace_list; slist; slist = slist->next)
399 internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, FALSE);
401 /* 9) install new accelerator */
402 entry->accel_key = accel_key;
403 entry->accel_mods = accel_mods;
404 entry->changed = TRUE;
406 for (slist = group_list; slist; slist = slist->next)
407 _gtk_accel_group_reconnect (slist->data, g_quark_from_string (entry->accel_path));
409 /* unref accel groups */
410 for (slist = group_list; slist; slist = slist->next)
411 g_object_unref (slist->data);
413 do_accel_map_changed (entry);
415 g_slist_free (replace_list);
416 g_slist_free (group_list);
417 g_slist_free (win_list);
423 * gtk_accel_map_change_entry:
424 * @accel_path: a valid accelerator path
425 * @accel_key: the new accelerator key
426 * @accel_mods: the new accelerator modifiers
427 * @replace: %TRUE if other accelerators may be deleted upon conflicts
428 * @returns: %TRUE if the accelerator could be changed, %FALSE otherwise
430 * Changes the @accel_key and @accel_mods currently associated with @accel_path.
431 * Due to conflicts with other accelerators, a change may not always be possible,
432 * @replace indicates whether other accelerators may be deleted to resolve such
433 * conflicts. A change will only occur if all conflicts could be resolved (which
434 * might not be the case if conflicting accelerators are locked). Successful
435 * changes are indicated by a %TRUE return value.
437 * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
438 * pass a static string, you can save some memory by interning it first with
439 * g_intern_static_string().
442 gtk_accel_map_change_entry (const gchar *accel_path,
444 GdkModifierType accel_mods,
447 g_return_val_if_fail (_gtk_accel_path_is_valid (accel_path), FALSE);
449 return internal_change_entry (accel_path, accel_key, accel_key ? accel_mods : 0, replace, FALSE);
453 accel_map_parse_accel_path (GScanner *scanner)
456 GdkModifierType accel_mods = 0;
459 /* parse accel path */
460 g_scanner_get_next_token (scanner);
461 if (scanner->token != G_TOKEN_STRING)
462 return G_TOKEN_STRING;
464 /* test if the next token is an accelerator */
465 g_scanner_peek_next_token (scanner);
466 if (scanner->next_token != G_TOKEN_STRING)
468 /* if not so, eat that token and error out */
469 g_scanner_get_next_token (scanner);
470 return G_TOKEN_STRING;
473 /* get the full accelerator specification */
474 path = g_strdup (scanner->value.v_string);
475 g_scanner_get_next_token (scanner);
476 accel = g_strdup (scanner->value.v_string);
478 /* ensure the entry is present */
479 gtk_accel_map_add_entry (path, 0, 0);
481 /* and propagate it */
482 gtk_accelerator_parse (accel, &accel_key, &accel_mods);
483 gtk_accel_map_change_entry (path, accel_key, accel_mods, TRUE);
488 /* check correct statement end */
489 g_scanner_get_next_token (scanner);
490 if (scanner->token != ')')
497 accel_map_parse_statement (GScanner *scanner)
499 guint expected_token;
501 g_scanner_get_next_token (scanner);
503 if (scanner->token == G_TOKEN_SYMBOL)
505 guint (*parser_func) (GScanner*);
507 parser_func = (guint (*) (GScanner *))scanner->value.v_symbol;
509 expected_token = parser_func (scanner);
512 expected_token = G_TOKEN_SYMBOL;
514 /* skip rest of statement on errrors
516 if (expected_token != G_TOKEN_NONE)
518 register guint level;
521 if (scanner->token == ')')
523 if (scanner->token == '(')
526 while (!g_scanner_eof (scanner) && level > 0)
528 g_scanner_get_next_token (scanner);
530 if (scanner->token == '(')
532 else if (scanner->token == ')')
539 * gtk_accel_map_load_scanner:
540 * @scanner: a #GScanner which has already been provided with an input file
542 * #GScanner variant of gtk_accel_map_load().
545 gtk_accel_map_load_scanner (GScanner *scanner)
547 gboolean skip_comment_single;
548 gboolean symbol_2_token;
549 gchar *cpair_comment_single;
550 gpointer saved_symbol;
552 g_return_if_fail (scanner != NULL);
554 /* configure scanner */
555 skip_comment_single = scanner->config->skip_comment_single;
556 scanner->config->skip_comment_single = TRUE;
557 cpair_comment_single = scanner->config->cpair_comment_single;
558 scanner->config->cpair_comment_single = ";\n";
559 symbol_2_token = scanner->config->symbol_2_token;
560 scanner->config->symbol_2_token = FALSE;
561 saved_symbol = g_scanner_lookup_symbol (scanner, "gtk_accel_path");
562 g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path",
563 accel_map_parse_accel_path);
565 /* outer parsing loop
567 g_scanner_peek_next_token (scanner);
568 while (scanner->next_token == '(')
570 g_scanner_get_next_token (scanner);
572 accel_map_parse_statement (scanner);
574 g_scanner_peek_next_token (scanner);
578 scanner->config->skip_comment_single = skip_comment_single;
579 scanner->config->cpair_comment_single = cpair_comment_single;
580 scanner->config->symbol_2_token = symbol_2_token;
581 g_scanner_scope_remove_symbol (scanner, 0, "gtk_accel_path");
583 g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path", saved_symbol);
587 * gtk_accel_map_load_fd:
588 * @fd: a valid readable file descriptor
590 * Filedescriptor variant of gtk_accel_map_load().
592 * Note that the file descriptor will not be closed by this function.
595 gtk_accel_map_load_fd (gint fd)
599 g_return_if_fail (fd >= 0);
601 /* create and setup scanner */
602 scanner = g_scanner_new (NULL);
603 g_scanner_input_file (scanner, fd);
605 gtk_accel_map_load_scanner (scanner);
607 g_scanner_destroy (scanner);
611 * gtk_accel_map_load:
612 * @file_name: a file containing accelerator specifications,
613 * in the GLib file name encoding
615 * Parses a file previously saved with gtk_accel_map_save() for
616 * accelerator specifications, and propagates them accordingly.
619 gtk_accel_map_load (const gchar *file_name)
623 g_return_if_fail (file_name != NULL);
625 if (!g_file_test (file_name, G_FILE_TEST_IS_REGULAR))
628 fd = g_open (file_name, O_RDONLY, 0);
632 gtk_accel_map_load_fd (fd);
644 gssize count = write (fd, buf, to_write);
661 accel_map_print (gpointer data,
662 const gchar *accel_path,
664 GdkModifierType accel_mods,
667 GString *gstring = g_string_new (changed ? NULL : "; ");
668 gint fd = GPOINTER_TO_INT (data);
671 g_string_append (gstring, "(gtk_accel_path \"");
673 tmp = g_strescape (accel_path, NULL);
674 g_string_append (gstring, tmp);
677 g_string_append (gstring, "\" \"");
679 name = gtk_accelerator_name (accel_key, accel_mods);
680 tmp = g_strescape (name, NULL);
682 g_string_append (gstring, tmp);
685 g_string_append (gstring, "\")\n");
687 write_all (fd, gstring->str, gstring->len);
689 g_string_free (gstring, TRUE);
693 * gtk_accel_map_save_fd:
694 * @fd: a valid writable file descriptor
696 * Filedescriptor variant of gtk_accel_map_save().
698 * Note that the file descriptor will not be closed by this function.
701 gtk_accel_map_save_fd (gint fd)
705 g_return_if_fail (fd >= 0);
707 gstring = g_string_new ("; ");
708 if (g_get_prgname ())
709 g_string_append (gstring, g_get_prgname ());
710 g_string_append (gstring, " GtkAccelMap rc-file -*- scheme -*-\n");
711 g_string_append (gstring, "; this file is an automated accelerator map dump\n");
712 g_string_append (gstring, ";\n");
714 write_all (fd, gstring->str, gstring->len);
716 g_string_free (gstring, TRUE);
718 gtk_accel_map_foreach (GINT_TO_POINTER (fd), accel_map_print);
722 * gtk_accel_map_save:
723 * @file_name: the name of the file to contain accelerator specifications,
724 * in the GLib file name encoding
726 * Saves current accelerator specifications (accelerator path, key
727 * and modifiers) to @file_name.
728 * The file is written in a format suitable to be read back in by
729 * gtk_accel_map_load().
732 gtk_accel_map_save (const gchar *file_name)
736 g_return_if_fail (file_name != NULL);
738 fd = g_open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
742 gtk_accel_map_save_fd (fd);
748 * gtk_accel_map_foreach:
749 * @data: data to be passed into @foreach_func
750 * @foreach_func: function to be executed for each accel map entry which
751 * is not filtered out
753 * Loops over the entries in the accelerator map whose accel path
754 * doesn't match any of the filters added with gtk_accel_map_add_filter(),
755 * and execute @foreach_func on each. The signature of @foreach_func is
756 * that of #GtkAccelMapForeach, the @changed parameter indicates whether
757 * this accelerator was changed during runtime (thus, would need
758 * saving during an accelerator map dump).
761 gtk_accel_map_foreach (gpointer data,
762 GtkAccelMapForeach foreach_func)
764 GSList *entries, *slist, *node;
766 g_return_if_fail (foreach_func != NULL);
768 entries = g_hash_table_slist_values (accel_entry_ht);
769 for (slist = entries; slist; slist = slist->next)
771 AccelEntry *entry = slist->data;
772 gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
774 for (node = accel_filters; node; node = node->next)
775 if (g_pattern_match_string (node->data, entry->accel_path))
777 foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
781 g_slist_free (entries);
785 * gtk_accel_map_foreach_unfiltered:
786 * @data: data to be passed into @foreach_func
787 * @foreach_func: function to be executed for each accel map entry
789 * Loops over all entries in the accelerator map, and execute
790 * @foreach_func on each. The signature of @foreach_func is that of
791 * #GtkAccelMapForeach, the @changed parameter indicates whether
792 * this accelerator was changed during runtime (thus, would need
793 * saving during an accelerator map dump).
796 gtk_accel_map_foreach_unfiltered (gpointer data,
797 GtkAccelMapForeach foreach_func)
799 GSList *entries, *slist;
801 g_return_if_fail (foreach_func != NULL);
803 entries = g_hash_table_slist_values (accel_entry_ht);
804 for (slist = entries; slist; slist = slist->next)
806 AccelEntry *entry = slist->data;
807 gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
809 foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
811 g_slist_free (entries);
815 * gtk_accel_map_add_filter:
816 * @filter_pattern: a pattern (see #GPatternSpec)
818 * Adds a filter to the global list of accel path filters.
820 * Accel map entries whose accel path matches one of the filters
821 * are skipped by gtk_accel_map_foreach().
823 * This function is intended for GTK+ modules that create their own
824 * menus, but don't want them to be saved into the applications accelerator
828 gtk_accel_map_add_filter (const gchar *filter_pattern)
833 g_return_if_fail (filter_pattern != NULL);
835 pspec = g_pattern_spec_new (filter_pattern);
836 for (slist = accel_filters; slist; slist = slist->next)
837 if (g_pattern_spec_equal (pspec, slist->data))
839 g_pattern_spec_free (pspec);
842 accel_filters = g_slist_prepend (accel_filters, pspec);
846 _gtk_accel_map_add_group (const gchar *accel_path,
847 GtkAccelGroup *accel_group)
851 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
852 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
854 entry = accel_path_lookup (accel_path);
857 gtk_accel_map_add_entry (accel_path, 0, 0);
858 entry = accel_path_lookup (accel_path);
860 entry->groups = g_slist_prepend (entry->groups, accel_group);
864 _gtk_accel_map_remove_group (const gchar *accel_path,
865 GtkAccelGroup *accel_group)
869 entry = accel_path_lookup (accel_path);
870 g_return_if_fail (entry != NULL);
871 g_return_if_fail (g_slist_find (entry->groups, accel_group));
873 entry->groups = g_slist_remove (entry->groups, accel_group);
878 * gtk_accel_map_lock_path:
879 * @accel_path: a valid accelerator path
881 * Locks the given accelerator path. If the accelerator map doesn't yet contain
882 * an entry for @accel_path, a new one is created.
884 * Locking an accelerator path prevents its accelerator from being changed
885 * during runtime. A locked accelerator path can be unlocked by
886 * gtk_accel_map_unlock_path(). Refer to gtk_accel_map_change_entry()
887 * for information about runtime accelerator changes.
889 * If called more than once, @accel_path remains locked until
890 * gtk_accel_map_unlock_path() has been called an equivalent number
893 * Note that locking of individual accelerator paths is independent from
894 * locking the #GtkAccelGroup containing them. For runtime accelerator
895 * changes to be possible both the accelerator path and its #GtkAccelGroup
896 * have to be unlocked.
901 gtk_accel_map_lock_path (const gchar *accel_path)
905 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
907 entry = accel_path_lookup (accel_path);
911 gtk_accel_map_add_entry (accel_path, 0, 0);
912 entry = accel_path_lookup (accel_path);
915 entry->lock_count += 1;
919 * gtk_accel_map_unlock_path:
920 * @accel_path: a valid accelerator path
922 * Undoes the last call to gtk_accel_map_lock_path() on this @accel_path.
923 * Refer to gtk_accel_map_lock_path() for information about accelerator path locking.
928 gtk_accel_map_unlock_path (const gchar *accel_path)
932 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
934 entry = accel_path_lookup (accel_path);
936 g_return_if_fail (entry != NULL && entry->lock_count > 0);
938 entry->lock_count -= 1;
941 G_DEFINE_TYPE (GtkAccelMap, gtk_accel_map, G_TYPE_OBJECT)
944 gtk_accel_map_class_init (GtkAccelMapClass *accel_map_class)
947 * GtkAccelMap::changed:
948 * @object: the global accel map object
949 * @accel_path: the path of the accelerator that changed
950 * @accel_key: the key value for the new accelerator
951 * @accel_mods: the modifier mask for the new accelerator
953 * Notifies of a change in the global accelerator map.
954 * The path is also used as the detail for the signal,
955 * so it is possible to connect to
956 * changed::<replaceable>accel_path</replaceable>.
960 accel_map_signals[CHANGED] = g_signal_new (I_("changed"),
961 G_TYPE_FROM_CLASS (accel_map_class),
962 G_SIGNAL_DETAILED|G_SIGNAL_RUN_LAST,
965 _gtk_marshal_VOID__STRING_UINT_FLAGS,
967 G_TYPE_STRING, G_TYPE_UINT, GDK_TYPE_MODIFIER_TYPE);
971 gtk_accel_map_init (GtkAccelMap *accel_map)
978 * Gets the singleton global #GtkAccelMap object. This object
979 * is useful only for notification of changes to the accelerator
980 * map via the ::changed signal; it isn't a parameter to the
981 * other accelerator map functions.
983 * Return value: the global #GtkAccelMap object
988 gtk_accel_map_get (void)
991 accel_map = g_object_new (GTK_TYPE_ACCEL_MAP, NULL);
997 do_accel_map_changed (AccelEntry *entry)
1000 g_signal_emit (accel_map,
1001 accel_map_signals[CHANGED],
1002 g_quark_from_string (entry->accel_path),
1008 #if defined (G_OS_WIN32) && !defined (_WIN64)
1010 #undef gtk_accel_map_load
1013 gtk_accel_map_load (const gchar *file_name)
1015 gchar *utf8_file_name = g_locale_to_utf8 (file_name, -1, NULL, NULL, NULL);
1017 gtk_accel_map_load_utf8 (utf8_file_name);
1019 g_free (utf8_file_name);
1022 #undef gtk_accel_map_save
1025 gtk_accel_map_save (const gchar *file_name)
1027 gchar *utf8_file_name = g_locale_to_utf8 (file_name, -1, NULL, NULL, NULL);
1029 gtk_accel_map_save_utf8 (utf8_file_name);
1031 g_free (utf8_file_name);
1036 #define __GTK_ACCEL_MAP_C__
1037 #include "gtkaliasdef.c"