]> Pileus Git - ~andy/gtk/blob - gtk/gtkaccelmap.c
2f4e6d1fb31855743b8983110e879368d1b04c68
[~andy/gtk] / gtk / gtkaccelmap.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1998, 2001 Tim Janik
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21
22 #include "gtkaccelmap.h"
23
24 #include "gtkwindow.h"  /* in lack of GtkAcceleratable */
25
26 #include <string.h>
27 #include <fcntl.h>
28 #ifdef HAVE_UNISTD_H
29 #include <unistd.h>
30 #endif
31 #ifdef G_OS_WIN32
32 #include <io.h>
33 #endif
34 #include <errno.h>
35
36
37 /* --- structures --- */
38 typedef struct {
39   const gchar *accel_path;
40   guint        accel_key;
41   guint        accel_mods;
42   guint        std_accel_key;
43   guint        std_accel_mods;
44   guint        changed : 1;
45   GSList      *groups;
46 } AccelEntry;
47
48
49 /* --- variables --- */
50 static GHashTable *accel_entry_ht = NULL;       /* accel_path -> AccelEntry */
51 static GSList     *accel_filters = NULL;
52
53
54 /* --- functions --- */
55 static guint
56 accel_entry_hash (gconstpointer key)
57 {
58   const AccelEntry *entry = key;
59
60   return g_str_hash (entry->accel_path);
61 }
62
63 static gboolean
64 accel_entry_equal (gconstpointer key1,
65                    gconstpointer key2)
66 {
67   const AccelEntry *entry1 = key1;
68   const AccelEntry *entry2 = key2;
69
70   return g_str_equal (entry1->accel_path, entry2->accel_path);
71 }
72
73 static inline AccelEntry*
74 accel_path_lookup (const gchar *accel_path)
75 {
76   AccelEntry ekey;
77
78   ekey.accel_path = accel_path;
79
80   /* safety NULL check for return_if_fail()s */
81   return accel_path ? g_hash_table_lookup (accel_entry_ht, &ekey) : NULL;
82 }
83
84 void
85 _gtk_accel_map_init (void)
86 {
87   g_assert (accel_entry_ht == NULL);
88
89   accel_entry_ht = g_hash_table_new (accel_entry_hash, accel_entry_equal);
90 }
91
92 gboolean
93 _gtk_accel_path_is_valid (const gchar *accel_path)
94 {
95   gchar *p;
96
97   if (!accel_path || accel_path[0] != '<' ||
98       accel_path[1] == '<' || accel_path[1] == '>' || !accel_path[1])
99     return FALSE;
100   p = strchr (accel_path, '>');
101   if (!p || p[1] != '/')
102     return FALSE;
103   return TRUE;
104 }
105
106 /**
107  * gtk_accel_map_add_entry:
108  * @accel_path: valid accelerator path
109  * @accel_key:  the accelerator key
110  * @accel_mods: the accelerator modifiers
111  *
112  * Registers a new accelerator with the global accelerator map.
113  * This function should only be called once per @accel_path
114  * with the canonical @accel_key and @accel_mods for this path.
115  * To change the accelerator during runtime programatically, use
116  * gtk_accel_map_change_entry().
117  * The accelerator path must consist of "&lt;WINDOWTYPE&gt;/Category1/Category2/.../Action",
118  * where &lt;WINDOWTYPE&gt; should be a unique application-specific identifier, that
119  * corresponds to the kind of window the accelerator is being used in, e.g. "Gimp-Image",
120  * "Abiword-Document" or "Gnumeric-Settings".
121  * The Category1/.../Action portion is most appropriately chosen by the action the
122  * accelerator triggers, i.e. for accelerators on menu items, choose the item's menu path,
123  * e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All".
124  * So a full valid accelerator path may look like:
125  * "&lt;Gimp-Toolbox&gt;/File/Dialogs/Tool Options...".
126  */
127 void
128 gtk_accel_map_add_entry (const gchar *accel_path,
129                          guint        accel_key,
130                          guint        accel_mods)
131 {
132   AccelEntry *entry;
133
134   g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
135
136   if (!accel_key)
137     accel_mods = 0;
138   else
139     accel_mods &= gtk_accelerator_get_default_mod_mask ();
140
141   entry = accel_path_lookup (accel_path);
142   if (entry)
143     {
144       if (!entry->std_accel_key && !entry->std_accel_mods &&
145           (accel_key || accel_mods))
146         {
147           entry->std_accel_key = accel_key;
148           entry->std_accel_mods = accel_mods;
149           if (!entry->changed)
150             gtk_accel_map_change_entry (entry->accel_path, accel_key, accel_mods, TRUE);
151         }
152     }
153   else
154     {
155       entry = g_new0 (AccelEntry, 1);
156       entry->accel_path = g_quark_to_string (g_quark_from_string (accel_path));
157       entry->std_accel_key = accel_key;
158       entry->std_accel_mods = accel_mods;
159       entry->accel_key = accel_key;
160       entry->accel_mods = accel_mods;
161       entry->changed = FALSE;
162       g_hash_table_insert (accel_entry_ht, entry, entry);
163     }
164 }
165
166 /**
167  * gtk_accel_map_lookup_entry:
168  * @accel_path:  a valid accelerator path
169  * @key:         the accelerator key to be filled in (optional)
170  * @returns:     %TRUE if @accel_path is known, %FALSE otherwise
171  *
172  * Looks up the accelerator entry for @accel_path and fills in @key.
173  */
174 gboolean
175 gtk_accel_map_lookup_entry (const gchar *accel_path,
176                             GtkAccelKey *key)
177 {
178   AccelEntry *entry;
179
180   g_return_val_if_fail (_gtk_accel_path_is_valid (accel_path), FALSE);
181
182   entry = accel_path_lookup (accel_path);
183   if (entry && key)
184     {
185       key->accel_key = entry->accel_key;
186       key->accel_mods = entry->accel_mods;
187       key->accel_flags = 0;
188     }
189
190   return entry ? TRUE : FALSE;
191 }
192
193 static void
194 hash2slist_foreach (gpointer  key,
195                     gpointer  value,
196                     gpointer  user_data)
197 {
198   GSList **slist_p = user_data;
199
200   *slist_p = g_slist_prepend (*slist_p, value);
201 }
202
203 static GSList*
204 g_hash_table_slist_values (GHashTable *hash_table)
205 {
206   GSList *slist = NULL;
207
208   g_return_val_if_fail (hash_table != NULL, NULL);
209
210   g_hash_table_foreach (hash_table, hash2slist_foreach, &slist);
211
212   return slist;
213 }
214
215 /* if simulate==TRUE, return whether accel_path can be changed to
216  * accel_key && accel_mods. otherwise, return whether accel_path
217  * was actually changed.
218  */
219 static gboolean
220 internal_change_entry (const gchar    *accel_path,
221                        guint           accel_key,
222                        GdkModifierType accel_mods,
223                        gboolean        replace,
224                        gboolean        simulate)
225 {
226   GSList *node, *slist, *win_list, *group_list, *replace_list = NULL;
227   GHashTable *group_hm, *window_hm;
228   gboolean change_accel, removable, can_change = TRUE, seen_accel = FALSE;
229   GQuark entry_quark;
230   AccelEntry *entry = accel_path_lookup (accel_path);
231
232   /* not much todo if there's no entry yet */
233   if (!entry)
234     {
235       if (!simulate)
236         {
237           gtk_accel_map_add_entry (accel_path, 0, 0);
238           entry = accel_path_lookup (accel_path);
239           entry->accel_key = accel_key;
240           entry->accel_mods = accel_mods;
241           entry->changed = TRUE;
242         }
243       return TRUE;
244     }
245
246   /* if there's nothing to change, not much todo either */
247   if (entry->accel_key == accel_key && entry->accel_mods == accel_mods)
248     {
249       if (!simulate)
250         entry->changed = TRUE;
251       return simulate ? TRUE : FALSE;
252     }
253
254   /* nobody's interested, easy going */
255   if (!entry->groups)
256     {
257       if (!simulate)
258         {
259           entry->accel_key = accel_key;
260           entry->accel_mods = accel_mods;
261           entry->changed = TRUE;
262         }
263       return TRUE;
264     }
265
266   /* 1) fetch all accel groups affected by this entry */
267   entry_quark = g_quark_try_string (entry->accel_path);
268   group_hm = g_hash_table_new (NULL, NULL);
269   window_hm = g_hash_table_new (NULL, NULL);
270   for (slist = entry->groups; slist; slist = slist->next)
271     g_hash_table_insert (group_hm, slist->data, slist->data);
272
273   /* 2) collect acceleratables affected */
274   group_list = g_hash_table_slist_values (group_hm);
275   for (slist = group_list; slist; slist = slist->next)
276     {
277       GtkAccelGroup *group = slist->data;
278
279       for (node = group->acceleratables; node; node = node->next)
280         g_hash_table_insert (window_hm, node->data, node->data);
281     }
282   g_slist_free (group_list);
283
284   /* 3) include all accel groups used by acceleratables */
285   win_list = g_hash_table_slist_values (window_hm);
286   g_hash_table_destroy (window_hm);
287   for (slist = win_list; slist; slist = slist->next)
288     for (node = gtk_accel_groups_from_object (slist->data); node; node = node->next)
289       g_hash_table_insert (group_hm, node->data, node->data);
290   group_list = g_hash_table_slist_values (group_hm);
291   g_hash_table_destroy (group_hm);
292   
293   /* 4) walk the acceleratables and figure whether they occupy accel_key&accel_mods */
294   if (accel_key)
295     for (slist = win_list; slist; slist = slist->next)
296       if (GTK_IS_WINDOW (slist->data))  /* bad kludge in lack of a GtkAcceleratable */
297         if (_gtk_window_query_nonaccels (slist->data, accel_key, accel_mods))
298           {
299             seen_accel = TRUE;
300             break;
301           }
302   removable = !seen_accel;
303   
304   /* 5) walk all accel groups and search for locks */
305   if (removable)
306     for (slist = group_list; slist; slist = slist->next)
307       {
308         GtkAccelGroup *group = slist->data;
309         GtkAccelGroupEntry *ag_entry;
310         guint i, n;
311         
312         n = 0;
313         ag_entry = entry->accel_key ? gtk_accel_group_query (group, entry->accel_key, entry->accel_mods, &n) : NULL;
314         for (i = 0; i < n; i++)
315           if (ag_entry[i].accel_path_quark == entry_quark)
316             {
317               can_change = !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
318               if (!can_change)
319                 goto break_loop_step5;
320             }
321         
322         n = 0;
323         ag_entry = accel_key ? gtk_accel_group_query (group, accel_key, accel_mods, &n) : NULL;
324         for (i = 0; i < n; i++)
325           {
326             seen_accel = TRUE;
327             removable = !group->lock_count && !(ag_entry[i].key.accel_flags & GTK_ACCEL_LOCKED);
328             if (!removable)
329               goto break_loop_step5;
330             if (ag_entry[i].accel_path_quark)
331               replace_list = g_slist_prepend (replace_list, GUINT_TO_POINTER (ag_entry->accel_path_quark));
332           }
333       }
334  break_loop_step5:
335   
336   /* 6) check whether we can remove existing accelerators */
337   if (removable && can_change)
338     for (slist = replace_list; slist; slist = slist->next)
339       if (!internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, TRUE))
340         {
341           removable = FALSE;
342           break;
343         }
344   
345   /* 7) check conditions and proceed if possible */
346   change_accel = can_change && (!seen_accel || (removable && replace));
347   
348   if (change_accel && !simulate)
349     {
350       guint old_accel_key, old_accel_mods;
351       
352       /* ref accel groups */
353       for (slist = group_list; slist; slist = slist->next)
354         g_object_ref (slist->data);
355
356       /* 8) remove existing accelerators */
357       for (slist = replace_list; slist; slist = slist->next)
358         internal_change_entry (g_quark_to_string (GPOINTER_TO_UINT (slist->data)), 0, 0, FALSE, FALSE);
359
360       /* 9) install new accelerator */
361       old_accel_key = entry->accel_key;
362       old_accel_mods = entry->accel_mods;
363       entry->accel_key = accel_key;
364       entry->accel_mods = accel_mods;
365       entry->changed = TRUE;
366       for (slist = group_list; slist; slist = slist->next)
367         _gtk_accel_group_reconnect (slist->data, g_quark_from_string (entry->accel_path));
368
369       /* unref accel groups */
370       for (slist = group_list; slist; slist = slist->next)
371         g_object_unref (slist->data);
372     }
373   g_slist_free (replace_list);
374   g_slist_free (group_list);
375   g_slist_free (win_list);
376
377   return change_accel;
378 }
379
380 /**
381  * gtk_accel_map_change_entry:
382  * @accel_path:  a valid accelerator path
383  * @accel_key:   the new accelerator key
384  * @accel_mods:  the new accelerator modifiers
385  * @replace:     %TRUE if other accelerators may be deleted upon conflicts
386  * @returns:     %TRUE if the accelerator could be changed, %FALSE otherwise
387  *
388  * Changes the @accel_key and @accel_mods currently associated with @accel_path.
389  * Due to conflicts with other accelerators, a change may not always be possible,
390  * @replace indicates whether other accelerators may be deleted to resolve such
391  * conflicts. A change will only occur if all conflicts could be resolved (which
392  * might not be the case if conflicting accelerators are locked). Successful
393  * changes are indicated by a %TRUE return value.
394  */
395 gboolean
396 gtk_accel_map_change_entry (const gchar    *accel_path,
397                             guint           accel_key,
398                             GdkModifierType accel_mods,
399                             gboolean        replace)
400 {
401   g_return_val_if_fail (_gtk_accel_path_is_valid (accel_path), FALSE);
402
403   return internal_change_entry (accel_path, accel_key, accel_key ? accel_mods : 0, replace, FALSE);
404 }
405
406 static guint
407 accel_map_parse_accel_path (GScanner *scanner)
408 {
409   guint accel_key = 0, accel_mods = 0;
410   gchar *path, *accel;
411   
412   /* parse accel path */
413   g_scanner_get_next_token (scanner);
414   if (scanner->token != G_TOKEN_STRING)
415     return G_TOKEN_STRING;
416
417   /* test if the next token is an accelerator */
418   g_scanner_peek_next_token (scanner);
419   if (scanner->next_token != G_TOKEN_STRING)
420     {
421       /* if not so, eat that token and error out */
422       g_scanner_get_next_token (scanner);
423       return G_TOKEN_STRING;
424     }
425
426   /* get the full accelerator specification */
427   path = g_strdup (scanner->value.v_string);
428   g_scanner_get_next_token (scanner);
429   accel = g_strdup (scanner->value.v_string);
430
431   /* ensure the entry is present */
432   gtk_accel_map_add_entry (path, 0, 0);
433
434   /* and propagate it */
435   gtk_accelerator_parse (accel, &accel_key, &accel_mods);
436   gtk_accel_map_change_entry (path, accel_key, accel_mods, TRUE);
437
438   g_free (accel);
439   g_free (path);
440
441   /* check correct statement end */
442   g_scanner_get_next_token (scanner);
443   if (scanner->token != ')')
444     return ')';
445   else
446     return G_TOKEN_NONE;
447 }
448
449 static void
450 accel_map_parse_statement (GScanner *scanner)
451 {
452   guint expected_token;
453
454   g_scanner_get_next_token (scanner);
455
456   if (scanner->token == G_TOKEN_SYMBOL)
457     {
458       guint (*parser_func) (GScanner*);
459
460       parser_func = scanner->value.v_symbol;
461
462       expected_token = parser_func (scanner);
463     }
464   else
465     expected_token = G_TOKEN_SYMBOL;
466
467   /* skip rest of statement on errrors
468    */
469   if (expected_token != G_TOKEN_NONE)
470     {
471       register guint level;
472
473       level = 1;
474       if (scanner->token == ')')
475         level--;
476       if (scanner->token == '(')
477         level++;
478
479       while (!g_scanner_eof (scanner) && level > 0)
480         {
481           g_scanner_get_next_token (scanner);
482
483           if (scanner->token == '(')
484             level++;
485           else if (scanner->token == ')')
486             level--;
487         }
488     }
489 }
490
491 /**
492  * gtk_accel_map_load_scanner:
493  * @scanner: a #GScanner which has already been provided with an input file
494  *
495  * #GScanner variant of gtk_accel_map_load().
496  */
497 void
498 gtk_accel_map_load_scanner (GScanner *scanner)
499 {
500   gboolean skip_comment_single;
501   gboolean symbol_2_token;
502   gchar *cpair_comment_single;
503   gpointer saved_symbol;
504   
505   g_return_if_fail (scanner != 0);
506
507   /* configure scanner */
508   skip_comment_single = scanner->config->skip_comment_single;
509   scanner->config->skip_comment_single = TRUE;
510   cpair_comment_single = scanner->config->cpair_comment_single;
511   scanner->config->cpair_comment_single = ";\n";
512   symbol_2_token = scanner->config->symbol_2_token;
513   scanner->config->symbol_2_token = FALSE;
514   saved_symbol = g_scanner_lookup_symbol (scanner, "gtk_accel_path");
515   g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path", accel_map_parse_accel_path);
516
517   /* outer parsing loop
518    */
519   g_scanner_peek_next_token (scanner);
520   while (scanner->next_token == '(')
521     {
522       g_scanner_get_next_token (scanner);
523
524       accel_map_parse_statement (scanner);
525
526       g_scanner_peek_next_token (scanner);
527     }
528
529   /* restore config */
530   scanner->config->skip_comment_single = skip_comment_single;
531   scanner->config->cpair_comment_single = cpair_comment_single;
532   scanner->config->symbol_2_token = symbol_2_token;
533   g_scanner_scope_remove_symbol (scanner, 0, "gtk_accel_path");
534   if (saved_symbol)
535     g_scanner_scope_add_symbol (scanner, 0, "gtk_accel_path", saved_symbol);
536 }
537
538 /**
539  * gtk_accel_map_load_fd:
540  * @fd: a valid readable file descriptor
541  *
542  * Filedescriptor variant of gtk_accel_map_load().
543  *
544  * Note that the file descriptor will not be closed by this function.
545  */
546 void
547 gtk_accel_map_load_fd (gint fd)
548 {
549   GScanner *scanner;
550
551   g_return_if_fail (fd >= 0);
552
553   /* create and setup scanner */
554   scanner = g_scanner_new (NULL);
555   g_scanner_input_file (scanner, fd);
556
557   gtk_accel_map_load_scanner (scanner);
558
559   g_scanner_destroy (scanner);
560 }
561
562 /**
563  * gtk_accel_map_load:
564  * @file_name: a file containing accelerator specifications
565  *
566  * Parses a file previously saved with gtk_accel_map_save() for
567  * accelerator specifications, and propagates them accordingly.
568  */
569 void
570 gtk_accel_map_load (const gchar *file_name)
571 {
572   gint fd;
573
574   g_return_if_fail (file_name != NULL);
575
576   if (!g_file_test (file_name, G_FILE_TEST_IS_REGULAR))
577     return;
578
579   fd = open (file_name, O_RDONLY);
580   if (fd < 0)
581     return;
582
583   gtk_accel_map_load_fd (fd);
584
585   close (fd);
586 }
587
588 static void
589 accel_map_print (gpointer        data,
590                  const gchar    *accel_path,
591                  guint           accel_key,
592                  guint           accel_mods,
593                  gboolean        changed)
594 {
595   GString *gstring = g_string_new (changed ? NULL : "; ");
596   gint err, fd = GPOINTER_TO_INT (data);
597   gchar *tmp, *name;
598
599   g_string_append (gstring, "(gtk_accel_path \"");
600
601   tmp = g_strescape (accel_path, NULL);
602   g_string_append (gstring, tmp);
603   g_free (tmp);
604
605   g_string_append (gstring, "\" \"");
606
607   name = gtk_accelerator_name (accel_key, accel_mods);
608   tmp = g_strescape (name, NULL);
609   g_free (name);
610   g_string_append (gstring, tmp);
611   g_free (tmp);
612
613   g_string_append (gstring, "\")\n");
614
615   do
616     err = write (fd, gstring->str, gstring->len);
617   while (err < 0 && errno == EINTR);
618
619   g_string_free (gstring, TRUE);
620 }
621
622 /**
623  * gtk_accel_map_save_fd:
624  * @fd: a valid writable file descriptor
625  *
626  * Filedescriptor variant of gtk_accel_map_save().
627  *
628  * Note that the file descriptor will not be closed by this function.
629  */
630 void
631 gtk_accel_map_save_fd (gint fd)
632 {
633   GString *gstring;
634   gint err;
635
636   g_return_if_fail (fd >= 0);
637
638   gstring = g_string_new ("; ");
639   if (g_get_prgname ())
640     g_string_append (gstring, g_get_prgname ());
641   g_string_append (gstring, " GtkAccelMap rc-file         -*- scheme -*-\n");
642   g_string_append (gstring, "; this file is an automated accelerator map dump\n");
643   g_string_append (gstring, ";\n");
644
645   do
646     err = write (fd, gstring->str, gstring->len);
647   while (err < 0 && errno == EINTR);
648
649   gtk_accel_map_foreach (GINT_TO_POINTER (fd), accel_map_print);
650 }
651
652 /**
653  * gtk_accel_map_save:
654  * @file_name: the file to contain accelerator specifications
655  *
656  * Saves current accelerator specifications (accelerator path, key
657  * and modifiers) to @file_name.
658  * The file is written in a format suitable to be read back in by
659  * gtk_accel_map_load().
660  */
661 void
662 gtk_accel_map_save (const gchar *file_name)
663 {
664   gint fd;
665
666   g_return_if_fail (file_name != NULL);
667
668   fd = open (file_name, O_CREAT | O_TRUNC | O_WRONLY, 0644);
669   if (fd < 0)
670     return;
671
672   gtk_accel_map_save_fd (fd);
673
674   close (fd);
675 }
676
677 /**
678  * gtk_accel_map_foreach:
679  * @data:         data to be passed into @foreach_func
680  * @foreach_func: function to be executed for each accel map entry which
681  *                is not filtered out
682  *
683  * Loops over the entries in the accelerator map whose accel path 
684  * doesn't match any of the filters added with gtk_accel_map_add_filter(), 
685  * and execute @foreach_func on each. The signature of @foreach_func is 
686  * that of #GtkAccelMapForeach, the @changed parameter indicates whether
687  * this accelerator was changed during runtime (thus, would need
688  * saving during an accelerator map dump).
689  */
690 void
691 gtk_accel_map_foreach (gpointer           data,
692                        GtkAccelMapForeach foreach_func)
693 {
694   GSList *entries, *slist, *node;
695
696   g_return_if_fail (foreach_func != NULL);
697
698   entries = g_hash_table_slist_values (accel_entry_ht);
699   for (slist = entries; slist; slist = slist->next)
700     {
701       AccelEntry *entry = slist->data;
702       gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
703
704       for (node = accel_filters; node; node = node->next)
705         if (g_pattern_match_string (node->data, entry->accel_path))
706           goto skip_accel;
707       foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
708     skip_accel:
709       /* noop */;
710     }
711   g_slist_free (entries);
712 }
713
714 /**
715  * gtk_accel_map_foreach_unfiltered:
716  * @data:         data to be passed into @foreach_func
717  * @foreach_func: function to be executed for each accel map entry
718  *
719  * Loops over all entries in the accelerator map, and execute
720  * @foreach_func on each. The signature of @foreach_func is that of
721  * #GtkAccelMapForeach, the @changed parameter indicates whether
722  * this accelerator was changed during runtime (thus, would need
723  * saving during an accelerator map dump).
724  */
725 void
726 gtk_accel_map_foreach_unfiltered (gpointer           data,
727                                   GtkAccelMapForeach foreach_func)
728 {
729   GSList *entries, *slist;
730
731   g_return_if_fail (foreach_func != NULL);
732
733   entries = g_hash_table_slist_values (accel_entry_ht);
734   for (slist = entries; slist; slist = slist->next)
735     {
736       AccelEntry *entry = slist->data;
737       gboolean changed = entry->accel_key != entry->std_accel_key || entry->accel_mods != entry->std_accel_mods;
738
739       foreach_func (data, entry->accel_path, entry->accel_key, entry->accel_mods, changed);
740     }
741   g_slist_free (entries);
742 }
743
744 /**
745  * gtk_accel_map_add_filter:
746  * @filter_pattern: a pattern (see #GPatternSpec)
747  *
748  * Adds a filter to the global list of accel path filters.
749  *
750  * Accel map entries whose accel path matches one of the filters
751  * are skipped by gtk_accel_map_foreach().
752  */
753 void
754 gtk_accel_map_add_filter (const gchar *filter_pattern)
755 {
756   GPatternSpec *pspec;
757   GSList *slist;
758
759   g_return_if_fail (filter_pattern != NULL);
760
761   pspec = g_pattern_spec_new (filter_pattern);
762   for (slist = accel_filters; slist; slist = slist->next)
763     if (g_pattern_spec_equal (pspec, slist->data))
764       {
765         g_pattern_spec_free (pspec);
766         return;
767       }
768   accel_filters = g_slist_prepend (accel_filters, pspec);
769 }
770
771 void
772 _gtk_accel_map_add_group (const gchar   *accel_path,
773                           GtkAccelGroup *accel_group)
774 {
775   AccelEntry *entry;
776
777   g_return_if_fail (_gtk_accel_path_is_valid (accel_path));
778   g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));
779
780   entry = accel_path_lookup (accel_path);
781   if (!entry)
782     {
783       gtk_accel_map_add_entry (accel_path, 0, 0);
784       entry = accel_path_lookup (accel_path);
785     }
786   entry->groups = g_slist_prepend (entry->groups, accel_group);
787 }
788
789 void
790 _gtk_accel_map_remove_group (const gchar   *accel_path,
791                              GtkAccelGroup *accel_group)
792 {
793   AccelEntry *entry;
794
795   entry = accel_path_lookup (accel_path);
796   g_return_if_fail (entry != NULL);
797   g_return_if_fail (g_slist_find (entry->groups, accel_group));
798
799   entry->groups = g_slist_remove (entry->groups, accel_group);
800 }