]> Pileus Git - ~andy/gtk/blob - gtk/gtkaccellabel.c
7e211f0bad42108c1282ecf8510c0a44fb9e0a05
[~andy/gtk] / gtk / gtkaccellabel.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * GtkAccelLabel: GtkLabel with accelerator monitoring facilities.
5  * Copyright (C) 1998 Tim Janik
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 /*
24  * Modified by the GTK+ Team and others 1997-2001.  See the AUTHORS
25  * file for a list of people on the GTK+ Team.  See the ChangeLog
26  * files for a list of changes.  These files are distributed with
27  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
28  */
29
30 #include "config.h"
31 #include <string.h>
32
33 #include "gtkaccellabel.h"
34 #include "gtkaccelmap.h"
35 #include "gtkmain.h"
36 #include "gtkprivate.h"
37 #include "gtkintl.h"
38 #include "gtkalias.h"
39 #include <gdk/gdkkeysyms.h>
40
41 enum {
42   PROP_0,
43   PROP_ACCEL_CLOSURE,
44   PROP_ACCEL_WIDGET
45 };
46
47 static void         gtk_accel_label_set_property (GObject            *object,
48                                                   guint               prop_id,
49                                                   const GValue       *value,
50                                                   GParamSpec         *pspec);
51 static void         gtk_accel_label_get_property (GObject            *object,
52                                                   guint               prop_id,
53                                                   GValue             *value,
54                                                   GParamSpec         *pspec);
55 static void         gtk_accel_label_destroy      (GtkObject          *object);
56 static void         gtk_accel_label_finalize     (GObject            *object);
57 static void         gtk_accel_label_size_request (GtkWidget          *widget,
58                                                   GtkRequisition     *requisition);
59 static gboolean     gtk_accel_label_expose_event (GtkWidget          *widget,
60                                                   GdkEventExpose     *event);
61 static const gchar *gtk_accel_label_get_string   (GtkAccelLabel      *accel_label);
62
63
64 G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
65
66 static void
67 gtk_accel_label_class_init (GtkAccelLabelClass *class)
68 {
69   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
70   GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
71   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
72   
73   gobject_class->finalize = gtk_accel_label_finalize;
74   gobject_class->set_property = gtk_accel_label_set_property;
75   gobject_class->get_property = gtk_accel_label_get_property;
76   
77   object_class->destroy = gtk_accel_label_destroy;
78    
79   widget_class->size_request = gtk_accel_label_size_request;
80   widget_class->expose_event = gtk_accel_label_expose_event;
81
82   class->signal_quote1 = g_strdup ("<:");
83   class->signal_quote2 = g_strdup (":>");
84
85 #ifndef GDK_WINDOWING_QUARTZ
86   /* This is the text that should appear next to menu accelerators
87    * that use the shift key. If the text on this key isn't typically
88    * translated on keyboards used for your language, don't translate
89    * this.
90    * 
91    * Don't include the prefix "keyboard label|" in the translation.
92    */
93   class->mod_name_shift = g_strdup (Q_("keyboard label|Shift"));
94   /* This is the text that should appear next to menu accelerators
95    * that use the control key. If the text on this key isn't typically
96    * translated on keyboards used for your language, don't translate
97    * this.
98    *
99    * Don't include the prefix "keyboard label|" in the translation.
100    */
101   class->mod_name_control = g_strdup (Q_("keyboard label|Ctrl"));
102   /* This is the text that should appear next to menu accelerators
103    * that use the alt key. If the text on this key isn't typically
104    * translated on keyboards used for your language, don't translate
105    * this.
106    *
107    * Don't include the prefix "keyboard label|" in the translation.
108    */
109   class->mod_name_alt = g_strdup (Q_("keyboard label|Alt"));
110   class->mod_separator = g_strdup ("+");
111 #else /* GDK_WINDOWING_QUARTZ */
112
113   /* U+21E7 UPWARDS WHITE ARROW */
114   class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
115   /* U+2303 UP ARROWHEAD */
116   class->mod_name_control = g_strdup ("\xe2\x8c\x83");
117   /* U+2325 OPTION KEY */
118   class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
119   class->mod_separator = g_strdup ("");
120
121 #endif /* GDK_WINDOWING_QUARTZ */
122
123   class->accel_seperator = g_strdup (" / ");
124   class->latin1_to_char = TRUE;
125   
126   g_object_class_install_property (gobject_class,
127                                    PROP_ACCEL_CLOSURE,
128                                    g_param_spec_boxed ("accel-closure",
129                                                        P_("Accelerator Closure"),
130                                                        P_("The closure to be monitored for accelerator changes"),
131                                                        G_TYPE_CLOSURE,
132                                                        GTK_PARAM_READWRITE));
133   g_object_class_install_property (gobject_class,
134                                    PROP_ACCEL_WIDGET,
135                                    g_param_spec_object ("accel-widget",
136                                                         P_("Accelerator Widget"),
137                                                         P_("The widget to be monitored for accelerator changes"),
138                                                         GTK_TYPE_WIDGET,
139                                                         GTK_PARAM_READWRITE));
140 }
141
142 static void
143 gtk_accel_label_set_property (GObject      *object,
144                               guint         prop_id,
145                               const GValue *value,
146                               GParamSpec   *pspec)
147 {
148   GtkAccelLabel  *accel_label;
149
150   accel_label = GTK_ACCEL_LABEL (object);
151
152   switch (prop_id)
153     {
154     case PROP_ACCEL_CLOSURE:
155       gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
156       break;
157     case PROP_ACCEL_WIDGET:
158       gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
159       break;
160     default:
161       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
162       break;
163     }
164 }
165
166 static void
167 gtk_accel_label_get_property (GObject    *object,
168                               guint       prop_id,
169                               GValue     *value,
170                               GParamSpec *pspec)
171 {
172   GtkAccelLabel  *accel_label;
173
174   accel_label = GTK_ACCEL_LABEL (object);
175
176   switch (prop_id)
177     {
178     case PROP_ACCEL_CLOSURE:
179       g_value_set_boxed (value, accel_label->accel_closure);
180       break;
181     case PROP_ACCEL_WIDGET:
182       g_value_set_object (value, accel_label->accel_widget);
183       break;
184     default:
185       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
186       break;
187     }
188 }
189
190 static void
191 gtk_accel_label_init (GtkAccelLabel *accel_label)
192 {
193   accel_label->accel_padding = 3;
194   accel_label->accel_widget = NULL;
195   accel_label->accel_closure = NULL;
196   accel_label->accel_group = NULL;
197   accel_label->accel_string = NULL;
198 }
199
200 GtkWidget*
201 gtk_accel_label_new (const gchar *string)
202 {
203   GtkAccelLabel *accel_label;
204   
205   g_return_val_if_fail (string != NULL, NULL);
206   
207   accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
208   
209   gtk_label_set_text (GTK_LABEL (accel_label), string);
210   
211   return GTK_WIDGET (accel_label);
212 }
213
214 static void
215 gtk_accel_label_destroy (GtkObject *object)
216 {
217   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
218
219   gtk_accel_label_set_accel_widget (accel_label, NULL);
220   gtk_accel_label_set_accel_closure (accel_label, NULL);
221   
222   GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
223 }
224
225 static void
226 gtk_accel_label_finalize (GObject *object)
227 {
228   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
229
230   g_free (accel_label->accel_string);
231   
232   G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
233 }
234
235 /**
236  * gtk_accel_label_get_accel_widget:
237  * @accel_label: a #GtkAccelLabel
238  *
239  * Fetches the widget monitored by this accelerator label. See
240  * gtk_accel_label_set_accel_widget().
241  *
242  * Return value: the object monitored by the accelerator label,
243  *               or %NULL.
244  **/
245 GtkWidget*
246 gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
247 {
248   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
249
250   return accel_label->accel_widget;
251 }
252
253 guint
254 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
255 {
256   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
257   
258   return (accel_label->accel_string_width +
259           (accel_label->accel_string_width ? accel_label->accel_padding : 0));
260 }
261
262 static void
263 gtk_accel_label_size_request (GtkWidget      *widget,
264                               GtkRequisition *requisition)
265 {
266   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
267   PangoLayout *layout;
268   gint width;
269
270   GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
271
272   layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
273   pango_layout_get_pixel_size (layout, &width, NULL);
274   accel_label->accel_string_width = width;
275   
276   g_object_unref (layout);
277 }
278
279 static gint
280 get_first_baseline (PangoLayout *layout)
281 {
282   PangoLayoutIter *iter;
283   gint result;
284
285   iter = pango_layout_get_iter (layout);
286   result = pango_layout_iter_get_baseline (iter);
287   pango_layout_iter_free (iter);
288
289   return PANGO_PIXELS (result);
290 }
291
292 static gboolean 
293 gtk_accel_label_expose_event (GtkWidget      *widget,
294                               GdkEventExpose *event)
295 {
296   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
297   GtkMisc *misc = GTK_MISC (accel_label);
298   GtkTextDirection direction;
299
300   direction = gtk_widget_get_direction (widget);
301
302   if (GTK_WIDGET_DRAWABLE (accel_label))
303     {
304       guint ac_width;
305       
306       ac_width = gtk_accel_label_get_accel_width (accel_label);
307       
308       if (widget->allocation.width >= widget->requisition.width + ac_width)
309         {
310           PangoLayout *label_layout;
311           PangoLayout *accel_layout;
312           GtkLabel *label = GTK_LABEL (widget);
313
314           gint x;
315           gint y;
316           
317           label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
318
319           if (direction == GTK_TEXT_DIR_RTL)
320             widget->allocation.x += ac_width;
321           widget->allocation.width -= ac_width;
322           if (gtk_label_get_ellipsize (label))
323             pango_layout_set_width (label_layout,
324                                     pango_layout_get_width (label_layout) 
325                                     - ac_width * PANGO_SCALE);
326           
327           if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
328             GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
329           if (direction == GTK_TEXT_DIR_RTL)
330             widget->allocation.x -= ac_width;
331           widget->allocation.width += ac_width;
332           if (gtk_label_get_ellipsize (label))
333             pango_layout_set_width (label_layout,
334                                     pango_layout_get_width (label_layout) 
335                                     + ac_width * PANGO_SCALE);
336           
337           if (direction == GTK_TEXT_DIR_RTL)
338             x = widget->allocation.x + misc->xpad;
339           else
340             x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
341
342           gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
343
344           accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
345
346           y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
347
348           gtk_paint_layout (widget->style,
349                             widget->window,
350                             GTK_WIDGET_STATE (widget),
351                             FALSE,
352                             &event->area,
353                             widget,
354                             "accellabel",
355                             x, y,
356                             accel_layout);                            
357
358           g_object_unref (accel_layout);
359         }
360       else
361         {
362           if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
363             GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
364         }
365     }
366   
367   return FALSE;
368 }
369
370 static void
371 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
372 {
373   GClosure *closure = NULL;
374   GList *clist, *list;
375   
376   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
377   g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
378   
379   clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
380   for (list = clist; list; list = list->next)
381     {
382       /* we just take the first closure used */
383       closure = list->data;
384       break;
385     }
386   g_list_free (clist);
387   gtk_accel_label_set_accel_closure (accel_label, closure);
388 }
389
390 /**
391  * gtk_accel_label_set_accel_widget:
392  * @accel_label: a #GtkAccelLabel
393  * @accel_widget: the widget to be monitored.
394  *
395  * Sets the widget to be monitored by this accelerator label. 
396  **/
397 void
398 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
399                                   GtkWidget     *accel_widget)
400 {
401   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
402   if (accel_widget)
403     g_return_if_fail (GTK_IS_WIDGET (accel_widget));
404     
405   if (accel_widget != accel_label->accel_widget)
406     {
407       if (accel_label->accel_widget)
408         {
409           gtk_accel_label_set_accel_closure (accel_label, NULL);
410           g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
411                                                 refetch_widget_accel_closure,
412                                                 accel_label);
413           g_object_unref (accel_label->accel_widget);
414         }
415       accel_label->accel_widget = accel_widget;
416       if (accel_label->accel_widget)
417         {
418           g_object_ref (accel_label->accel_widget);
419           g_signal_connect_object (accel_label->accel_widget, "accel_closures_changed",
420                                    G_CALLBACK (refetch_widget_accel_closure),
421                                    accel_label, G_CONNECT_SWAPPED);
422           refetch_widget_accel_closure (accel_label);
423         }
424       g_object_notify (G_OBJECT (accel_label), "accel-widget");
425     }
426 }
427
428 static void
429 gtk_accel_label_reset (GtkAccelLabel *accel_label)
430 {
431   if (accel_label->accel_string)
432     {
433       g_free (accel_label->accel_string);
434       accel_label->accel_string = NULL;
435     }
436   
437   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
438 }
439
440 static void
441 check_accel_changed (GtkAccelGroup  *accel_group,
442                      guint           keyval,
443                      GdkModifierType modifier,
444                      GClosure       *accel_closure,
445                      GtkAccelLabel  *accel_label)
446 {
447   if (accel_closure == accel_label->accel_closure)
448     gtk_accel_label_reset (accel_label);
449 }
450
451 /**
452  * gtk_accel_label_set_accel_closure:
453  * @accel_label: a #GtkAccelLabel
454  * @accel_closure: the closure to monitor for accelerator changes.
455  *
456  * Sets the closure to be monitored by this accelerator label. The closure
457  * must be connected to an accelerator group; see gtk_accel_group_connect().
458  **/
459 void
460 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
461                                    GClosure      *accel_closure)
462 {
463   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
464   if (accel_closure)
465     g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
466
467   if (accel_closure != accel_label->accel_closure)
468     {
469       if (accel_label->accel_closure)
470         {
471           g_signal_handlers_disconnect_by_func (accel_label->accel_group,
472                                                 check_accel_changed,
473                                                 accel_label);
474           accel_label->accel_group = NULL;
475           g_closure_unref (accel_label->accel_closure);
476         }
477       accel_label->accel_closure = accel_closure;
478       if (accel_label->accel_closure)
479         {
480           g_closure_ref (accel_label->accel_closure);
481           accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
482           g_signal_connect_object (accel_label->accel_group, "accel_changed",
483                                    G_CALLBACK (check_accel_changed),
484                                    accel_label, 0);
485         }
486       gtk_accel_label_reset (accel_label);
487       g_object_notify (G_OBJECT (accel_label), "accel-closure");
488     }
489 }
490
491 static gboolean
492 find_accel (GtkAccelKey *key,
493             GClosure    *closure,
494             gpointer     data)
495 {
496   return data == (gpointer) closure;
497 }
498
499 static const gchar *
500 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
501 {
502   if (!accel_label->accel_string)
503     gtk_accel_label_refetch (accel_label);
504   
505   return accel_label->accel_string;
506 }
507
508 /* Underscores in key names are better displayed as spaces
509  * E.g., Page_Up should be "Page Up"
510  */
511 static void
512 substitute_underscores (char *str)
513 {
514   char *p;
515
516   for (p = str; *p; p++)
517     if (*p == '_')
518       *p = ' ';
519 }
520
521 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
522  * append it to gstring and return TRUE; otherwise return FALSE.
523  * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html 
524  * for the list of special keys. */
525 static gboolean
526 append_keyval_symbol (guint    accelerator_key,
527                       GString *gstring)
528 {
529 #ifdef GDK_WINDOWING_QUARTZ
530   switch (accelerator_key)
531   {
532   case GDK_Return:
533     /* U+21A9 LEFTWARDS ARROW WITH HOOK */
534     g_string_append (gstring, "\xe2\x86\xa9");
535     return TRUE;
536
537   case GDK_ISO_Enter:
538     /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
539     g_string_append (gstring, "\xe2\x8c\xa4");
540     return TRUE;
541
542   case GDK_Left:
543     /* U+2190 LEFTWARDS ARROW */
544     g_string_append (gstring, "\xe2\x86\x90");
545     return TRUE;
546
547   case GDK_Up:
548     /* U+2191 UPWARDS ARROW */
549     g_string_append (gstring, "\xe2\x86\x91");
550     return TRUE;
551
552   case GDK_Right:
553     /* U+2192 RIGHTWARDS ARROW */
554     g_string_append (gstring, "\xe2\x86\x92");
555     return TRUE;
556
557   case GDK_Down:
558     /* U+2193 DOWNWARDS ARROW */
559     g_string_append (gstring, "\xe2\x86\x93");
560     return TRUE;
561
562   case GDK_Page_Up:
563     /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
564     g_string_append (gstring, "\xe2\x87\x9e");
565     return TRUE;
566
567   case GDK_Page_Down:
568     /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
569     g_string_append (gstring, "\xe2\x87\x9f");
570     return TRUE;
571
572   case GDK_Home:
573     /* U+2196 NORTH WEST ARROW */
574     g_string_append (gstring, "\xe2\x86\x96");
575     return TRUE;
576
577   case GDK_End:
578     /* U+2198 SOUTH EAST ARROW */
579     g_string_append (gstring, "\xe2\x86\x98");
580     return TRUE;
581
582   case GDK_Escape:
583     /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
584     g_string_append (gstring, "\xe2\x8e\x8b");
585     return TRUE;
586
587   case GDK_BackSpace:
588     /* U+232B ERASE TO THE LEFT */
589     g_string_append (gstring, "\xe2\x8c\xab");
590     return TRUE;
591
592   case GDK_Delete:
593     /* U+2326 ERASE TO THE RIGHT */
594     g_string_append (gstring, "\xe2\x8c\xa6");
595     return TRUE;
596
597   default:
598     return FALSE;
599   }
600 #else /* !GDK_WINDOWING_QUARTZ */
601   return FALSE;
602 #endif
603 }
604
605 gchar *
606 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
607                                               guint               accelerator_key,
608                                               GdkModifierType     accelerator_mods)
609 {
610   GString *gstring;
611   gboolean seen_mod = FALSE;
612   gunichar ch;
613   
614   gstring = g_string_new ("");
615   
616   if (accelerator_mods & GDK_SHIFT_MASK)
617     {
618       g_string_append (gstring, klass->mod_name_shift);
619       seen_mod = TRUE;
620     }
621   if (accelerator_mods & GDK_CONTROL_MASK)
622     {
623       if (seen_mod)
624         g_string_append (gstring, klass->mod_separator);
625       g_string_append (gstring, klass->mod_name_control);
626       seen_mod = TRUE;
627     }
628   if (accelerator_mods & GDK_MOD1_MASK)
629     {
630       if (seen_mod)
631         g_string_append (gstring, klass->mod_separator);
632       g_string_append (gstring, klass->mod_name_alt);
633       seen_mod = TRUE;
634     }
635   if (accelerator_mods & GDK_MOD2_MASK)
636     {
637       if (seen_mod)
638         g_string_append (gstring, klass->mod_separator);
639
640       g_string_append (gstring, "Mod2");
641       seen_mod = TRUE;
642     }
643   if (accelerator_mods & GDK_MOD3_MASK)
644     {
645       if (seen_mod)
646         g_string_append (gstring, klass->mod_separator);
647
648       g_string_append (gstring, "Mod3");
649       seen_mod = TRUE;
650     }
651   if (accelerator_mods & GDK_MOD4_MASK)
652     {
653       if (seen_mod)
654         g_string_append (gstring, klass->mod_separator);
655
656       g_string_append (gstring, "Mod4");
657       seen_mod = TRUE;
658     }
659   if (accelerator_mods & GDK_MOD5_MASK)
660     {
661       if (seen_mod)
662         g_string_append (gstring, klass->mod_separator);
663
664       g_string_append (gstring, "Mod5");
665       seen_mod = TRUE;
666     }
667   if (accelerator_mods & GDK_SUPER_MASK)
668     {
669       if (seen_mod)
670         g_string_append (gstring, klass->mod_separator);
671
672       /* This is the text that should appear next to menu accelerators
673        * that use the super key. If the text on this key isn't typically
674        * translated on keyboards used for your language, don't translate
675        * this.
676        * And do not translate the part before the |.
677        */
678       g_string_append (gstring, Q_("keyboard label|Super"));
679       seen_mod = TRUE;
680     }
681   if (accelerator_mods & GDK_HYPER_MASK)
682     {
683       if (seen_mod)
684         g_string_append (gstring, klass->mod_separator);
685
686       /* This is the text that should appear next to menu accelerators
687        * that use the hyper key. If the text on this key isn't typically
688        * translated on keyboards used for your language, don't translate
689        * this.
690        * And do not translate the part before the |.
691        */
692       g_string_append (gstring, Q_("keyboard label|Hyper"));
693       seen_mod = TRUE;
694     }
695   if (accelerator_mods & GDK_META_MASK)
696     {
697       if (seen_mod)
698         g_string_append (gstring, klass->mod_separator);
699
700 #ifndef GDK_WINDOWING_QUARTZ
701       /* This is the text that should appear next to menu accelerators
702        * that use the meta key. If the text on this key isn't typically
703        * translated on keyboards used for your language, don't translate
704        * this.
705        * And do not translate the part before the |.
706        */
707       g_string_append (gstring, Q_("keyboard label|Meta"));
708 #else
709       /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
710       g_string_append (gstring, "\xe2\x8c\x98");
711 #endif
712       seen_mod = TRUE;
713     }
714   if (seen_mod)
715     g_string_append (gstring, klass->mod_separator);
716   
717   ch = gdk_keyval_to_unicode (accelerator_key);
718   if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
719       (ch < 0x80 || klass->latin1_to_char))
720     {
721       switch (ch)
722         {
723         case ' ':
724           /* do not translate the part before the | */
725           g_string_append (gstring, Q_("keyboard label|Space"));
726           break;
727         case '\\':
728           /* do not translate the part before the | */
729           g_string_append (gstring, Q_("keyboard label|Backslash"));
730           break;
731         default:
732           g_string_append_unichar (gstring, g_unichar_toupper (ch));
733           break;
734         }
735     }
736   else if (!append_keyval_symbol (accelerator_key, gstring))
737     {
738       gchar *tmp;
739
740       tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
741       if (tmp != NULL)
742         {
743           if (tmp[0] != 0 && tmp[1] == 0)
744             g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
745           else
746             {
747               gchar msg[128];
748               gchar *str;
749               
750               strcpy (msg, "keyboard label|");
751               g_strlcat (msg, tmp, 128);
752               str = _(msg);
753               if (str == msg)
754                 {
755                   g_string_append (gstring, tmp);
756                   substitute_underscores (gstring->str);
757                 }
758               else
759                 g_string_append (gstring, str);
760             }
761         }
762     }
763
764   return g_string_free (gstring, FALSE);
765 }
766
767 gboolean
768 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
769 {
770   gboolean enable_accels;
771
772   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
773
774   if (accel_label->accel_string)
775     {
776       g_free (accel_label->accel_string);
777       accel_label->accel_string = NULL;
778     }
779
780   g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
781                 "gtk-enable-accels", &enable_accels,
782                 NULL);
783
784   if (enable_accels && accel_label->accel_closure)
785     {
786       GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
787
788       if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
789         {
790           GtkAccelLabelClass *klass;
791           gchar *tmp;
792
793           klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
794           tmp = _gtk_accel_label_class_get_accelerator_label (klass,
795                                                               key->accel_key,
796                                                               key->accel_mods);
797           accel_label->accel_string = g_strconcat ("   ", tmp, NULL);
798           g_free (tmp);
799         }
800       if (!accel_label->accel_string)
801         accel_label->accel_string = g_strdup ("-/-");
802     }
803   
804   if (!accel_label->accel_string)
805     accel_label->accel_string = g_strdup ("");
806
807   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
808
809   return FALSE;
810 }
811
812 #define __GTK_ACCEL_LABEL_C__
813 #include "gtkaliasdef.c"