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>
43 /* --- structures --- */
46 GObject parent_instance;
49 struct _GtkAccelMapClass
51 GObjectClass parent_class;
55 const gchar *accel_path;
61 guint lock_count : 15;
71 /* --- variables --- */
73 static GHashTable *accel_entry_ht = NULL; /* accel_path -> AccelEntry */
74 static GSList *accel_filters = NULL;
75 static gulong accel_map_signals[LAST_SIGNAL] = { 0, };
76 static GtkAccelMap *accel_map;
78 /* --- prototypes --- */
79 static void do_accel_map_changed (AccelEntry *entry);
81 /* --- functions --- */
83 accel_entry_hash (gconstpointer key)
85 const AccelEntry *entry = key;
87 return g_str_hash (entry->accel_path);
91 accel_entry_equal (gconstpointer key1,
94 const AccelEntry *entry1 = key1;
95 const AccelEntry *entry2 = key2;
97 return g_str_equal (entry1->accel_path, entry2->accel_path);
100 static inline AccelEntry*
101 accel_path_lookup (const gchar *accel_path)
105 ekey.accel_path = accel_path;
107 /* safety NULL check for return_if_fail()s */
108 return accel_path ? g_hash_table_lookup (accel_entry_ht, &ekey) : NULL;
112 _gtk_accel_map_init (void)
114 g_assert (accel_entry_ht == NULL);
116 accel_entry_ht = g_hash_table_new (accel_entry_hash, accel_entry_equal);
120 _gtk_accel_path_is_valid (const gchar *accel_path)
124 if (!accel_path || accel_path[0] != '<' ||
125 accel_path[1] == '<' || accel_path[1] == '>' || !accel_path[1])
127 p = strchr (accel_path, '>');
128 if (!p || (p[1] != 0 && p[1] != '/'))
134 * gtk_accel_map_add_entry:
135 * @accel_path: valid accelerator path
136 * @accel_key: the accelerator key
137 * @accel_mods: the accelerator modifiers
139 * Registers a new accelerator with the global accelerator map.
140 * This function should only be called once per @accel_path
141 * with the canonical @accel_key and @accel_mods for this path.
142 * To change the accelerator during runtime programatically, use
143 * gtk_accel_map_change_entry().
144 * The accelerator path must consist of "<WINDOWTYPE>/Category1/Category2/.../Action",
145 * where <WINDOWTYPE> should be a unique application-specific identifier, that
146 * corresponds to the kind of window the accelerator is being used in, e.g. "Gimp-Image",
147 * "Abiword-Document" or "Gnumeric-Settings".
148 * The Category1/.../Action portion is most appropriately chosen by the action the
149 * accelerator triggers, i.e. for accelerators on menu items, choose the item's menu path,
150 * e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All".
151 * So a full valid accelerator path may look like:
152 * "<Gimp-Toolbox>/File/Dialogs/Tool Options...".
155 gtk_accel_map_add_entry (const gchar *accel_path,
157 GdkModifierType accel_mods)
161 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
166 accel_mods &= gtk_accelerator_get_default_mod_mask ();
168 entry = accel_path_lookup (accel_path);
171 if (!entry->std_accel_key && !entry->std_accel_mods &&
172 (accel_key || accel_mods))
174 entry->std_accel_key = accel_key;
175 entry->std_accel_mods = accel_mods;
177 gtk_accel_map_change_entry (entry->accel_path, accel_key, accel_mods, TRUE);
182 entry = g_slice_new0 (AccelEntry);
183 entry->accel_path = g_intern_string (accel_path);
184 entry->std_accel_key = accel_key;
185 entry->std_accel_mods = accel_mods;
186 entry->accel_key = accel_key;
187 entry->accel_mods = accel_mods;
188 entry->changed = FALSE;
189 entry->lock_count = 0;
190 g_hash_table_insert (accel_entry_ht, entry, entry);
192 do_accel_map_changed (entry);
197 * gtk_accel_map_lookup_entry:
198 * @accel_path: a valid accelerator path
199 * @key: the accelerator key to be filled in (optional)
200 * @returns: %TRUE if @accel_path is known, %FALSE otherwise
202 * Looks up the accelerator entry for @accel_path and fills in @key.
205 gtk_accel_map_lookup_entry (const gchar *accel_path,
210 g_return_val_if_fail (_gtk_accel_path_is_valid (accel_path), FALSE);
212 entry = accel_path_lookup (accel_path);
215 key->accel_key = entry->accel_key;
216 key->accel_mods = entry->accel_mods;
217 key->accel_flags = 0;
220 return entry ? TRUE : FALSE;
224 hash2slist_foreach (gpointer key,
228 GSList **slist_p = user_data;
230 *slist_p = g_slist_prepend (*slist_p, value);
234 g_hash_table_slist_values (GHashTable *hash_table)
236 GSList *slist = NULL;
238 g_return_val_if_fail (hash_table != NULL, NULL);
240 g_hash_table_foreach (hash_table, hash2slist_foreach, &slist);
245 /* if simulate==TRUE, return whether accel_path can be changed to
246 * accel_key && accel_mods. otherwise, return whether accel_path
247 * was actually changed.
250 internal_change_entry (const gchar *accel_path,
252 GdkModifierType accel_mods,
256 GSList *node, *slist, *win_list, *group_list, *replace_list = NULL;
257 GHashTable *group_hm, *window_hm;
258 gboolean change_accel, removable, can_change = TRUE, seen_accel = FALSE;
260 AccelEntry *entry = accel_path_lookup (accel_path);
262 /* not much todo if there's no entry yet */
267 gtk_accel_map_add_entry (accel_path, 0, 0);
268 entry = accel_path_lookup (accel_path);
269 entry->accel_key = accel_key;
270 entry->accel_mods = accel_mods;
271 entry->changed = TRUE;
273 do_accel_map_changed (entry);
278 /* if there's nothing to change, not much todo either */
279 if (entry->accel_key == accel_key && entry->accel_mods == accel_mods)
282 entry->changed = TRUE;
283 return simulate ? TRUE : FALSE;
286 /* The no-change case has already been handled, so
287 * simulate doesn't make a difference here.
289 if (entry->lock_count > 0)
292 /* nobody's interested, easy going */
297 entry->accel_key = accel_key;
298 entry->accel_mods = accel_mods;
299 entry->changed = TRUE;
301 do_accel_map_changed (entry);
306 /* 1) fetch all accel groups affected by this entry */
307 entry_quark = g_quark_try_string (entry->accel_path);
308 group_hm = g_hash_table_new (NULL, NULL);
309 window_hm = g_hash_table_new (NULL, NULL);
310 for (slist = entry->groups; slist; slist = slist->next)
311 g_hash_table_insert (group_hm, slist->data, slist->data);
313 /* 2) collect acceleratables affected */
314 group_list = g_hash_table_slist_values (group_hm);
315 for (slist = group_list; slist; slist = slist->next)
317 GtkAccelGroup *group = slist->data;
319 for (node = group->acceleratables; node; node = node->next)
320 g_hash_table_insert (window_hm, node->data, node->data);
322 g_slist_free (group_list);
324 /* 3) include all accel groups used by acceleratables */
325 win_list = g_hash_table_slist_values (window_hm);
326 g_hash_table_destroy (window_hm);
327 for (slist = win_list; slist; slist = slist->next)
328 for (node = gtk_accel_groups_from_object (slist->data); node; node = node->next)
329 g_hash_table_insert (group_hm, node->data, node->data);
330 group_list = g_hash_table_slist_values (group_hm);
331 g_hash_table_destroy (group_hm);
333 /* 4) walk the acceleratables and figure whether they occupy accel_key&accel_mods */
335 for (slist = win_list; slist; slist = slist->next)
336 if (GTK_IS_WINDOW (slist->data)) /* bad kludge in lack of a GtkAcceleratable */
337 if (_gtk_window_query_nonaccels (slist->data, accel_key, accel_mods))
342 removable = !seen_accel;
344 /* 5) walk all accel groups and search for locks */
346 for (slist = group_list; slist; slist = slist->next)
348 GtkAccelGroup *group = slist->data;
349 GtkAccelGroupEntry *ag_entry;
353 ag_entry = entry->accel_key ? gtk_accel_group_query (group, entry->accel_key, entry->accel_mods, &n) : NULL;
354 for (i = 0; i < n; i++)
355 if (ag_entry[i].accel_path_quark == entry_quark)
357 can_change = !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
359 goto break_loop_step5;
363 ag_entry = accel_key ? gtk_accel_group_query (group, accel_key, accel_mods, &n) : NULL;
364 for (i = 0; i < n; i++)
367 removable = !group->lock_count && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
369 goto break_loop_step5;
370 if (ag_entry[i].accel_path_quark)
371 replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry[i].accel_path_quark));
376 /* 6) check whether we can remove existing accelerators */
377 if (removable && can_change)
378 for (slist = replace_list; slist; slist = slist->next)
379 if (!internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, TRUE))
385 /* 7) check conditions and proceed if possible */
386 change_accel = can_change && (!seen_accel || (removable && replace));
388 if (change_accel && !simulate)
390 /* ref accel groups */
391 for (slist = group_list; slist; slist = slist->next)
392 g_object_ref (slist->data);
394 /* 8) remove existing accelerators */
395 for (slist = replace_list; slist; slist = slist->next)
396 internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, FALSE);
398 /* 9) install new accelerator */
399 entry->accel_key = accel_key;
400 entry->accel_mods = accel_mods;
401 entry->changed = TRUE;
403 for (slist = group_list; slist; slist = slist->next)
404 _gtk_accel_group_reconnect (slist->data, g_quark_from_string (entry->accel_path));
406 /* unref accel groups */
407 for (slist = group_list; slist; slist = slist->next)
408 g_object_unref (slist->data);
410 do_accel_map_changed (entry);
412 g_slist_free (replace_list);
413 g_slist_free (group_list);
414 g_slist_free (win_list);
420 * gtk_accel_map_change_entry:
421 * @accel_path: a valid accelerator path
422 * @accel_key: the new accelerator key
423 * @accel_mods: the new accelerator modifiers
424 * @replace: %TRUE if other accelerators may be deleted upon conflicts
425 * @returns: %TRUE if the accelerator could be changed, %FALSE otherwise
427 * Changes the @accel_key and @accel_mods currently associated with @accel_path.
428 * Due to conflicts with other accelerators, a change may not always be possible,
429 * @replace indicates whether other accelerators may be deleted to resolve such
430 * conflicts. A change will only occur if all conflicts could be resolved (which
431 * might not be the case if conflicting accelerators are locked). Successful
432 * changes are indicated by a %TRUE return value.
435 gtk_accel_map_change_entry (const gchar *accel_path,
437 GdkModifierType accel_mods,
440 g_return_val_if_fail (_gtk_accel_path_is_valid (accel_path), FALSE);
442 return internal_change_entry (accel_path, accel_key, accel_key ? accel_mods : 0, replace, FALSE);
446 accel_map_parse_accel_path (GScanner *scanner)
449 GdkModifierType accel_mods = 0;
452 /* parse accel path */
453 g_scanner_get_next_token (scanner);
454 if (scanner->token != G_TOKEN_STRING)
455 return G_TOKEN_STRING;
457 /* test if the next token is an accelerator */
458 g_scanner_peek_next_token (scanner);
459 if (scanner->next_token != G_TOKEN_STRING)
461 /* if not so, eat that token and error out */
462 g_scanner_get_next_token (scanner);
463 return G_TOKEN_STRING;
466 /* get the full accelerator specification */
467 path = g_strdup (scanner->value.v_string);
468 g_scanner_get_next_token (scanner);
469 accel = g_strdup (scanner->value.v_string);
471 /* ensure the entry is present */
472 gtk_accel_map_add_entry (path, 0, 0);
474 /* and propagate it */
475 gtk_accelerator_parse (accel, &accel_key, &accel_mods);
476 gtk_accel_map_change_entry (path, accel_key, accel_mods, TRUE);
481 /* check correct statement end */
482 g_scanner_get_next_token (scanner);
483 if (scanner->token != ')')
490 accel_map_parse_statement (GScanner *scanner)
492 guint expected_token;
494 g_scanner_get_next_token (scanner);
496 if (scanner->token == G_TOKEN_SYMBOL)
498 guint (*parser_func) (GScanner*);
500 parser_func = (guint (*) (GScanner *))scanner->value.v_symbol;
502 expected_token = parser_func (scanner);
505 expected_token = G_TOKEN_SYMBOL;
507 /* skip rest of statement on errrors
509 if (expected_token != G_TOKEN_NONE)
511 register guint level;
514 if (scanner->token == ')')
516 if (scanner->token == '(')
519 while (!g_scanner_eof (scanner) && level > 0)
521 g_scanner_get_next_token (scanner);
523 if (scanner->token == '(')
525 else if (scanner->token == ')')
532 * gtk_accel_map_load_scanner:
533 * @scanner: a #GScanner which has already been provided with an input file
535 * #GScanner variant of gtk_accel_map_load().
538 gtk_accel_map_load_scanner (GScanner *scanner)
540 gboolean skip_comment_single;
541 gboolean symbol_2_token;
542 gchar *cpair_comment_single;
543 gpointer saved_symbol;
545 g_return_if_fail (scanner != 0);
547 /* configure scanner */
548 skip_comment_single = scanner->config->skip_comment_single;
549 scanner->config->skip_comment_single = TRUE;
550 cpair_comment_single = scanner->config->cpair_comment_single;
551 scanner->config->cpair_comment_single = ";\n";
552 symbol_2_token = scanner->config->symbol_2_token;
553 scanner->config->symbol_2_token = FALSE;
554 saved_symbol = g_scanner_lookup_symbol (scanner, "gtk_accel_path");
555 g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path",
556 accel_map_parse_accel_path);
558 /* outer parsing loop
560 g_scanner_peek_next_token (scanner);
561 while (scanner->next_token == '(')
563 g_scanner_get_next_token (scanner);
565 accel_map_parse_statement (scanner);
567 g_scanner_peek_next_token (scanner);
571 scanner->config->skip_comment_single = skip_comment_single;
572 scanner->config->cpair_comment_single = cpair_comment_single;
573 scanner->config->symbol_2_token = symbol_2_token;
574 g_scanner_scope_remove_symbol (scanner, 0, "gtk_accel_path");
576 g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path", saved_symbol);
580 * gtk_accel_map_load_fd:
581 * @fd: a valid readable file descriptor
583 * Filedescriptor variant of gtk_accel_map_load().
585 * Note that the file descriptor will not be closed by this function.
588 gtk_accel_map_load_fd (gint fd)
592 g_return_if_fail (fd >= 0);
594 /* create and setup scanner */
595 scanner = g_scanner_new (NULL);
596 g_scanner_input_file (scanner, fd);
598 gtk_accel_map_load_scanner (scanner);
600 g_scanner_destroy (scanner);
604 * gtk_accel_map_load:
605 * @file_name: a file containing accelerator specifications,
606 * in the GLib file name encoding
608 * Parses a file previously saved with gtk_accel_map_save() for
609 * accelerator specifications, and propagates them accordingly.
612 gtk_accel_map_load (const gchar *file_name)
616 g_return_if_fail (file_name != NULL);
618 if (!g_file_test (file_name, G_FILE_TEST_IS_REGULAR))
621 fd = g_open (file_name, O_RDONLY, 0);
625 gtk_accel_map_load_fd (fd);
637 gssize count = write (fd, buf, to_write);
654 accel_map_print (gpointer data,
655 const gchar *accel_path,
657 GdkModifierType accel_mods,
660 GString *gstring = g_string_new (changed ? NULL : "; ");
661 gint fd = GPOINTER_TO_INT (data);
664 g_string_append (gstring, "(gtk_accel_path \"");
666 tmp = g_strescape (accel_path, NULL);
667 g_string_append (gstring, tmp);
670 g_string_append (gstring, "\" \"");
672 name = gtk_accelerator_name (accel_key, accel_mods);
673 tmp = g_strescape (name, NULL);
675 g_string_append (gstring, tmp);
678 g_string_append (gstring, "\")\n");
680 write_all (fd, gstring->str, gstring->len);
682 g_string_free (gstring, TRUE);
686 * gtk_accel_map_save_fd:
687 * @fd: a valid writable file descriptor
689 * Filedescriptor variant of gtk_accel_map_save().
691 * Note that the file descriptor will not be closed by this function.
694 gtk_accel_map_save_fd (gint fd)
698 g_return_if_fail (fd >= 0);
700 gstring = g_string_new ("; ");
701 if (g_get_prgname ())
702 g_string_append (gstring, g_get_prgname ());
703 g_string_append (gstring, " GtkAccelMap rc-file -*- scheme -*-\n");
704 g_string_append (gstring, "; this file is an automated accelerator map dump\n");
705 g_string_append (gstring, ";\n");
707 write_all (fd, gstring->str, gstring->len);
709 g_string_free (gstring, TRUE);
711 gtk_accel_map_foreach (GINT_TO_POINTER (fd), accel_map_print);
715 * gtk_accel_map_save:
716 * @file_name: the name of the file to contain accelerator specifications,
717 * in the GLib file name encoding
719 * Saves current accelerator specifications (accelerator path, key
720 * and modifiers) to @file_name.
721 * The file is written in a format suitable to be read back in by
722 * gtk_accel_map_load().
725 gtk_accel_map_save (const gchar *file_name)
729 g_return_if_fail (file_name != NULL);
731 fd = g_open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
735 gtk_accel_map_save_fd (fd);
741 * gtk_accel_map_foreach:
742 * @data: data to be passed into @foreach_func
743 * @foreach_func: function to be executed for each accel map entry which
744 * is not filtered out
746 * Loops over the entries in the accelerator map whose accel path
747 * doesn't match any of the filters added with gtk_accel_map_add_filter(),
748 * and execute @foreach_func on each. The signature of @foreach_func is
749 * that of #GtkAccelMapForeach, the @changed parameter indicates whether
750 * this accelerator was changed during runtime (thus, would need
751 * saving during an accelerator map dump).
754 gtk_accel_map_foreach (gpointer data,
755 GtkAccelMapForeach foreach_func)
757 GSList *entries, *slist, *node;
759 g_return_if_fail (foreach_func != NULL);
761 entries = g_hash_table_slist_values (accel_entry_ht);
762 for (slist = entries; slist; slist = slist->next)
764 AccelEntry *entry = slist->data;
765 gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
767 for (node = accel_filters; node; node = node->next)
768 if (g_pattern_match_string (node->data, entry->accel_path))
770 foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
774 g_slist_free (entries);
778 * gtk_accel_map_foreach_unfiltered:
779 * @data: data to be passed into @foreach_func
780 * @foreach_func: function to be executed for each accel map entry
782 * Loops over all entries in the accelerator map, and execute
783 * @foreach_func on each. The signature of @foreach_func is that of
784 * #GtkAccelMapForeach, the @changed parameter indicates whether
785 * this accelerator was changed during runtime (thus, would need
786 * saving during an accelerator map dump).
789 gtk_accel_map_foreach_unfiltered (gpointer data,
790 GtkAccelMapForeach foreach_func)
792 GSList *entries, *slist;
794 g_return_if_fail (foreach_func != NULL);
796 entries = g_hash_table_slist_values (accel_entry_ht);
797 for (slist = entries; slist; slist = slist->next)
799 AccelEntry *entry = slist->data;
800 gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
802 foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
804 g_slist_free (entries);
808 * gtk_accel_map_add_filter:
809 * @filter_pattern: a pattern (see #GPatternSpec)
811 * Adds a filter to the global list of accel path filters.
813 * Accel map entries whose accel path matches one of the filters
814 * are skipped by gtk_accel_map_foreach().
816 * This function is intended for GTK+ modules that create their own
817 * menus, but don't want them to be saved into the applications accelerator
821 gtk_accel_map_add_filter (const gchar *filter_pattern)
826 g_return_if_fail (filter_pattern != NULL);
828 pspec = g_pattern_spec_new (filter_pattern);
829 for (slist = accel_filters; slist; slist = slist->next)
830 if (g_pattern_spec_equal (pspec, slist->data))
832 g_pattern_spec_free (pspec);
835 accel_filters = g_slist_prepend (accel_filters, pspec);
839 _gtk_accel_map_add_group (const gchar *accel_path,
840 GtkAccelGroup *accel_group)
844 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
845 g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
847 entry = accel_path_lookup (accel_path);
850 gtk_accel_map_add_entry (accel_path, 0, 0);
851 entry = accel_path_lookup (accel_path);
853 entry->groups = g_slist_prepend (entry->groups, accel_group);
857 _gtk_accel_map_remove_group (const gchar *accel_path,
858 GtkAccelGroup *accel_group)
862 entry = accel_path_lookup (accel_path);
863 g_return_if_fail (entry != NULL);
864 g_return_if_fail (g_slist_find (entry->groups, accel_group));
866 entry->groups = g_slist_remove (entry->groups, accel_group);
871 * gtk_accel_map_lock_path:
872 * @accel_path: a valid accelerator path
874 * Locks the given accelerator path. If the accelerator map doesn't yet contain
875 * an entry for @accel_path, a new one is created.
877 * Locking an accelerator path prevents its accelerator from being changed
878 * during runtime. A locked accelerator path can be unlocked by
879 * gtk_accel_map_unlock_path(). Refer to gtk_accel_map_change_entry()
880 * for information about runtime accelerator changes.
882 * If called more than once, @accel_path remains locked until
883 * gtk_accel_map_unlock_path() has been called an equivalent number
886 * Note that locking of individual accelerator paths is independent from
887 * locking the #GtkAccelGroup containing them. For runtime accelerator
888 * changes to be possible both the accelerator path and its #GtkAccelGroup
889 * have to be unlocked.
894 gtk_accel_map_lock_path (const gchar *accel_path)
898 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
900 entry = accel_path_lookup (accel_path);
904 gtk_accel_map_add_entry (accel_path, 0, 0);
905 entry = accel_path_lookup (accel_path);
908 entry->lock_count += 1;
912 * gtk_accel_map_unlock_path:
913 * @accel_path: a valid accelerator path
915 * Undoes the last call to gtk_accel_map_lock_path() on this @accel_path.
916 * Refer to gtk_accel_map_lock_path() for information about accelerator path locking.
921 gtk_accel_map_unlock_path (const gchar *accel_path)
925 g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
927 entry = accel_path_lookup (accel_path);
929 g_return_if_fail (entry != NULL && entry->lock_count > 0);
931 entry->lock_count -= 1;
934 G_DEFINE_TYPE (GtkAccelMap, gtk_accel_map, G_TYPE_OBJECT)
937 gtk_accel_map_class_init (GtkAccelMapClass *accel_map_class)
940 * GtkAccelMap::changed:
941 * @object: the global accel map object
942 * @accel_path: the path of the accelerator that changed
943 * @accel_key: the key value for the new accelerator
944 * @accel_mods: the modifier mask for the new accelerator
946 * Notifies of a change in the global accelerator map.
947 * The path is also used as the detail for the signal,
948 * so it is possible to connect to
949 * changed::<replaceable>accel_path</replaceable>.
953 accel_map_signals[CHANGED] = g_signal_new (I_("changed"),
954 G_TYPE_FROM_CLASS (accel_map_class),
955 G_SIGNAL_DETAILED|G_SIGNAL_RUN_LAST,
958 _gtk_marshal_VOID__STRING_UINT_FLAGS,
960 G_TYPE_STRING, G_TYPE_UINT, GDK_TYPE_MODIFIER_TYPE);
964 gtk_accel_map_init (GtkAccelMap *accel_map)
971 * Gets the singleton global #GtkAccelMap object. This object
972 * is useful only for notification of changes to the accelerator
973 * map via the ::changed signal; it isn't a parameter to the
974 * other accelerator map functions.
976 * Return value: the global #GtkAccelMap object
981 gtk_accel_map_get (void)
984 accel_map = g_object_new (GTK_TYPE_ACCEL_MAP, NULL);
990 do_accel_map_changed (AccelEntry *entry)
993 g_signal_emit (accel_map,
994 accel_map_signals[CHANGED],
995 g_quark_from_string (entry->accel_path),
1003 #undef gtk_accel_map_load
1006 gtk_accel_map_load (const gchar *file_name)
1008 gchar *utf8_file_name = g_locale_to_utf8 (file_name, -1, NULL, NULL, NULL);
1010 gtk_accel_map_load_utf8 (utf8_file_name);
1012 g_free (utf8_file_name);
1015 #undef gtk_accel_map_save
1018 gtk_accel_map_save (const gchar *file_name)
1020 gchar *utf8_file_name = g_locale_to_utf8 (file_name, -1, NULL, NULL, NULL);
1022 gtk_accel_map_save_utf8 (utf8_file_name);
1024 g_free (utf8_file_name);
1029 #define __GTK_ACCEL_MAP_C__
1030 #include "gtkaliasdef.c"