]> Pileus Git - ~andy/gtk/blob - gtk/gtkaccellabel.c
Revert name change
[~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   if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request)
271     GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
272
273   layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
274   pango_layout_get_pixel_size (layout, &width, NULL);
275   accel_label->accel_string_width = width;
276   
277   g_object_unref (layout);
278 }
279
280 static gint
281 get_first_baseline (PangoLayout *layout)
282 {
283   PangoLayoutIter *iter;
284   gint result;
285
286   iter = pango_layout_get_iter (layout);
287   result = pango_layout_iter_get_baseline (iter);
288   pango_layout_iter_free (iter);
289
290   return PANGO_PIXELS (result);
291 }
292
293 static gboolean 
294 gtk_accel_label_expose_event (GtkWidget      *widget,
295                               GdkEventExpose *event)
296 {
297   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
298   GtkMisc *misc = GTK_MISC (accel_label);
299   GtkTextDirection direction;
300
301   direction = gtk_widget_get_direction (widget);
302
303   if (GTK_WIDGET_DRAWABLE (accel_label))
304     {
305       guint ac_width;
306       
307       ac_width = gtk_accel_label_get_accel_width (accel_label);
308       
309       if (widget->allocation.width >= widget->requisition.width + ac_width)
310         {
311           PangoLayout *label_layout;
312           PangoLayout *accel_layout;
313           GtkLabel *label = GTK_LABEL (widget);
314
315           gint x;
316           gint y;
317           
318           label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
319
320           if (direction == GTK_TEXT_DIR_RTL)
321             widget->allocation.x += ac_width;
322           widget->allocation.width -= ac_width;
323           if (gtk_label_get_ellipsize (label))
324             pango_layout_set_width (label_layout,
325                                     pango_layout_get_width (label_layout) 
326                                     - ac_width * PANGO_SCALE);
327           
328           if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
329             GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
330           if (direction == GTK_TEXT_DIR_RTL)
331             widget->allocation.x -= ac_width;
332           widget->allocation.width += ac_width;
333           if (gtk_label_get_ellipsize (label))
334             pango_layout_set_width (label_layout,
335                                     pango_layout_get_width (label_layout) 
336                                     + ac_width * PANGO_SCALE);
337           
338           if (direction == GTK_TEXT_DIR_RTL)
339             x = widget->allocation.x + misc->xpad;
340           else
341             x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
342
343           gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
344
345           accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
346
347           y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
348
349           gtk_paint_layout (widget->style,
350                             widget->window,
351                             GTK_WIDGET_STATE (widget),
352                             FALSE,
353                             &event->area,
354                             widget,
355                             "accellabel",
356                             x, y,
357                             accel_layout);                            
358
359           g_object_unref (accel_layout);
360         }
361       else
362         {
363           if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
364             GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
365         }
366     }
367   
368   return FALSE;
369 }
370
371 static void
372 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
373 {
374   GClosure *closure = NULL;
375   GList *clist, *list;
376   
377   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
378   g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
379   
380   clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
381   for (list = clist; list; list = list->next)
382     {
383       /* we just take the first closure used */
384       closure = list->data;
385       break;
386     }
387   g_list_free (clist);
388   gtk_accel_label_set_accel_closure (accel_label, closure);
389 }
390
391 /**
392  * gtk_accel_label_set_accel_widget:
393  * @accel_label: a #GtkAccelLabel
394  * @accel_widget: the widget to be monitored.
395  *
396  * Sets the widget to be monitored by this accelerator label. 
397  **/
398 void
399 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
400                                   GtkWidget     *accel_widget)
401 {
402   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
403   if (accel_widget)
404     g_return_if_fail (GTK_IS_WIDGET (accel_widget));
405     
406   if (accel_widget != accel_label->accel_widget)
407     {
408       if (accel_label->accel_widget)
409         {
410           gtk_accel_label_set_accel_closure (accel_label, NULL);
411           g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
412                                                 refetch_widget_accel_closure,
413                                                 accel_label);
414           g_object_unref (accel_label->accel_widget);
415         }
416       accel_label->accel_widget = accel_widget;
417       if (accel_label->accel_widget)
418         {
419           g_object_ref (accel_label->accel_widget);
420           g_signal_connect_object (accel_label->accel_widget, "accel_closures_changed",
421                                    G_CALLBACK (refetch_widget_accel_closure),
422                                    accel_label, G_CONNECT_SWAPPED);
423           refetch_widget_accel_closure (accel_label);
424         }
425       g_object_notify (G_OBJECT (accel_label), "accel-widget");
426     }
427 }
428
429 static void
430 gtk_accel_label_reset (GtkAccelLabel *accel_label)
431 {
432   if (accel_label->accel_string)
433     {
434       g_free (accel_label->accel_string);
435       accel_label->accel_string = NULL;
436     }
437   
438   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
439 }
440
441 static void
442 check_accel_changed (GtkAccelGroup  *accel_group,
443                      guint           keyval,
444                      GdkModifierType modifier,
445                      GClosure       *accel_closure,
446                      GtkAccelLabel  *accel_label)
447 {
448   if (accel_closure == accel_label->accel_closure)
449     gtk_accel_label_reset (accel_label);
450 }
451
452 /**
453  * gtk_accel_label_set_accel_closure:
454  * @accel_label: a #GtkAccelLabel
455  * @accel_closure: the closure to monitor for accelerator changes.
456  *
457  * Sets the closure to be monitored by this accelerator label. The closure
458  * must be connected to an accelerator group; see gtk_accel_group_connect().
459  **/
460 void
461 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
462                                    GClosure      *accel_closure)
463 {
464   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
465   if (accel_closure)
466     g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
467
468   if (accel_closure != accel_label->accel_closure)
469     {
470       if (accel_label->accel_closure)
471         {
472           g_signal_handlers_disconnect_by_func (accel_label->accel_group,
473                                                 check_accel_changed,
474                                                 accel_label);
475           accel_label->accel_group = NULL;
476           g_closure_unref (accel_label->accel_closure);
477         }
478       accel_label->accel_closure = accel_closure;
479       if (accel_label->accel_closure)
480         {
481           g_closure_ref (accel_label->accel_closure);
482           accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
483           g_signal_connect_object (accel_label->accel_group, "accel_changed",
484                                    G_CALLBACK (check_accel_changed),
485                                    accel_label, 0);
486         }
487       gtk_accel_label_reset (accel_label);
488       g_object_notify (G_OBJECT (accel_label), "accel-closure");
489     }
490 }
491
492 static gboolean
493 find_accel (GtkAccelKey *key,
494             GClosure    *closure,
495             gpointer     data)
496 {
497   return data == (gpointer) closure;
498 }
499
500 static const gchar *
501 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
502 {
503   if (!accel_label->accel_string)
504     gtk_accel_label_refetch (accel_label);
505   
506   return accel_label->accel_string;
507 }
508
509 /* Underscores in key names are better displayed as spaces
510  * E.g., Page_Up should be "Page Up"
511  */
512 static void
513 substitute_underscores (char *str)
514 {
515   char *p;
516
517   for (p = str; *p; p++)
518     if (*p == '_')
519       *p = ' ';
520 }
521
522 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
523  * append it to gstring and return TRUE; otherwise return FALSE.
524  * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html 
525  * for the list of special keys. */
526 static gboolean
527 append_keyval_symbol (guint    accelerator_key,
528                       GString *gstring)
529 {
530 #ifdef GDK_WINDOWING_QUARTZ
531   switch (accelerator_key)
532   {
533   case GDK_Return:
534     /* U+21A9 LEFTWARDS ARROW WITH HOOK */
535     g_string_append (gstring, "\xe2\x86\xa9");
536     return TRUE;
537
538   case GDK_ISO_Enter:
539     /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
540     g_string_append (gstring, "\xe2\x8c\xa4");
541     return TRUE;
542
543   case GDK_Left:
544     /* U+2190 LEFTWARDS ARROW */
545     g_string_append (gstring, "\xe2\x86\x90");
546     return TRUE;
547
548   case GDK_Up:
549     /* U+2191 UPWARDS ARROW */
550     g_string_append (gstring, "\xe2\x86\x91");
551     return TRUE;
552
553   case GDK_Right:
554     /* U+2192 RIGHTWARDS ARROW */
555     g_string_append (gstring, "\xe2\x86\x92");
556     return TRUE;
557
558   case GDK_Down:
559     /* U+2193 DOWNWARDS ARROW */
560     g_string_append (gstring, "\xe2\x86\x93");
561     return TRUE;
562
563   case GDK_Page_Up:
564     /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
565     g_string_append (gstring, "\xe2\x87\x9e");
566     return TRUE;
567
568   case GDK_Page_Down:
569     /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
570     g_string_append (gstring, "\xe2\x87\x9f");
571     return TRUE;
572
573   case GDK_Home:
574     /* U+2196 NORTH WEST ARROW */
575     g_string_append (gstring, "\xe2\x86\x96");
576     return TRUE;
577
578   case GDK_End:
579     /* U+2198 SOUTH EAST ARROW */
580     g_string_append (gstring, "\xe2\x86\x98");
581     return TRUE;
582
583   case GDK_Escape:
584     /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
585     g_string_append (gstring, "\xe2\x8e\x8b");
586     return TRUE;
587
588   case GDK_BackSpace:
589     /* U+232B ERASE TO THE LEFT */
590     g_string_append (gstring, "\xe2\x8c\xab");
591     return TRUE;
592
593   case GDK_Delete:
594     /* U+2326 ERASE TO THE RIGHT */
595     g_string_append (gstring, "\xe2\x8c\xa6");
596     return TRUE;
597
598   default:
599     return FALSE;
600   }
601 #else /* !GDK_WINDOWING_QUARTZ */
602   return FALSE;
603 #endif
604 }
605
606 gchar *
607 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
608                                               guint               accelerator_key,
609                                               GdkModifierType     accelerator_mods)
610 {
611   GString *gstring;
612   gboolean seen_mod = FALSE;
613   gunichar ch;
614   
615   gstring = g_string_new ("");
616   
617   if (accelerator_mods & GDK_SHIFT_MASK)
618     {
619       g_string_append (gstring, klass->mod_name_shift);
620       seen_mod = TRUE;
621     }
622   if (accelerator_mods & GDK_CONTROL_MASK)
623     {
624       if (seen_mod)
625         g_string_append (gstring, klass->mod_separator);
626       g_string_append (gstring, klass->mod_name_control);
627       seen_mod = TRUE;
628     }
629   if (accelerator_mods & GDK_MOD1_MASK)
630     {
631       if (seen_mod)
632         g_string_append (gstring, klass->mod_separator);
633       g_string_append (gstring, klass->mod_name_alt);
634       seen_mod = TRUE;
635     }
636   if (accelerator_mods & GDK_MOD2_MASK)
637     {
638       if (seen_mod)
639         g_string_append (gstring, klass->mod_separator);
640
641       g_string_append (gstring, "Mod2");
642       seen_mod = TRUE;
643     }
644   if (accelerator_mods & GDK_MOD3_MASK)
645     {
646       if (seen_mod)
647         g_string_append (gstring, klass->mod_separator);
648
649       g_string_append (gstring, "Mod3");
650       seen_mod = TRUE;
651     }
652   if (accelerator_mods & GDK_MOD4_MASK)
653     {
654       if (seen_mod)
655         g_string_append (gstring, klass->mod_separator);
656
657       g_string_append (gstring, "Mod4");
658       seen_mod = TRUE;
659     }
660   if (accelerator_mods & GDK_MOD5_MASK)
661     {
662       if (seen_mod)
663         g_string_append (gstring, klass->mod_separator);
664
665       g_string_append (gstring, "Mod5");
666       seen_mod = TRUE;
667     }
668   if (accelerator_mods & GDK_SUPER_MASK)
669     {
670       if (seen_mod)
671         g_string_append (gstring, klass->mod_separator);
672
673       /* This is the text that should appear next to menu accelerators
674        * that use the super key. If the text on this key isn't typically
675        * translated on keyboards used for your language, don't translate
676        * this.
677        * And do not translate the part before the |.
678        */
679       g_string_append (gstring, Q_("keyboard label|Super"));
680       seen_mod = TRUE;
681     }
682   if (accelerator_mods & GDK_HYPER_MASK)
683     {
684       if (seen_mod)
685         g_string_append (gstring, klass->mod_separator);
686
687       /* This is the text that should appear next to menu accelerators
688        * that use the hyper key. If the text on this key isn't typically
689        * translated on keyboards used for your language, don't translate
690        * this.
691        * And do not translate the part before the |.
692        */
693       g_string_append (gstring, Q_("keyboard label|Hyper"));
694       seen_mod = TRUE;
695     }
696   if (accelerator_mods & GDK_META_MASK)
697     {
698       if (seen_mod)
699         g_string_append (gstring, klass->mod_separator);
700
701 #ifndef GDK_WINDOWING_QUARTZ
702       /* This is the text that should appear next to menu accelerators
703        * that use the meta key. If the text on this key isn't typically
704        * translated on keyboards used for your language, don't translate
705        * this.
706        * And do not translate the part before the |.
707        */
708       g_string_append (gstring, Q_("keyboard label|Meta"));
709 #else
710       /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
711       g_string_append (gstring, "\xe2\x8c\x98");
712 #endif
713       seen_mod = TRUE;
714     }
715   if (seen_mod)
716     g_string_append (gstring, klass->mod_separator);
717   
718   ch = gdk_keyval_to_unicode (accelerator_key);
719   if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
720       (ch < 0x80 || klass->latin1_to_char))
721     {
722       switch (ch)
723         {
724         case ' ':
725           /* do not translate the part before the | */
726           g_string_append (gstring, Q_("keyboard label|Space"));
727           break;
728         case '\\':
729           /* do not translate the part before the | */
730           g_string_append (gstring, Q_("keyboard label|Backslash"));
731           break;
732         default:
733           g_string_append_unichar (gstring, g_unichar_toupper (ch));
734           break;
735         }
736     }
737   else if (!append_keyval_symbol (accelerator_key, gstring))
738     {
739       gchar *tmp;
740
741       tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
742       if (tmp != NULL)
743         {
744           if (tmp[0] != 0 && tmp[1] == 0)
745             g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
746           else
747             {
748               gchar msg[128];
749               gchar *str;
750               
751               strcpy (msg, "keyboard label|");
752               g_strlcat (msg, tmp, 128);
753               str = _(msg);
754               if (str == msg)
755                 {
756                   g_string_append (gstring, tmp);
757                   substitute_underscores (gstring->str);
758                 }
759               else
760                 g_string_append (gstring, str);
761             }
762         }
763     }
764
765   return g_string_free (gstring, FALSE);
766 }
767
768 gboolean
769 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
770 {
771   gboolean enable_accels;
772
773   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
774
775   if (accel_label->accel_string)
776     {
777       g_free (accel_label->accel_string);
778       accel_label->accel_string = NULL;
779     }
780
781   g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
782                 "gtk-enable-accels", &enable_accels,
783                 NULL);
784
785   if (enable_accels && accel_label->accel_closure)
786     {
787       GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
788
789       if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
790         {
791           GtkAccelLabelClass *klass;
792           gchar *tmp;
793
794           klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
795           tmp = _gtk_accel_label_class_get_accelerator_label (klass,
796                                                               key->accel_key,
797                                                               key->accel_mods);
798           accel_label->accel_string = g_strconcat ("   ", tmp, NULL);
799           g_free (tmp);
800         }
801       if (!accel_label->accel_string)
802         accel_label->accel_string = g_strdup ("-/-");
803     }
804   
805   if (!accel_label->accel_string)
806     accel_label->accel_string = g_strdup ("");
807
808   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
809
810   return FALSE;
811 }
812
813 #define __GTK_ACCEL_LABEL_C__
814 #include "gtkaliasdef.c"