]> Pileus Git - ~andy/gtk/blob - gtk/gtkaccellabel.c
Don't use GTK_WIDGET_STATE in internal code anymore
[~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 /**
42  * SECTION:gtkaccellabel
43  * @Short_description: A label which displays an accelerator key on the right of the text
44  * @Title: GtkAccelLabel
45  * @See_also: #GtkItemFactory, #GtkAccelGroup
46  *
47  * The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
48  * accelerator key on the right of the label text, e.g. 'Ctl+S'.
49  * It is commonly used in menus to show the keyboard short-cuts for commands.
50  *
51  * The accelerator key to display is not set explicitly.
52  * Instead, the #GtkAccelLabel displays the accelerators which have been added to
53  * a particular widget. This widget is set by calling
54  * gtk_accel_label_set_accel_widget().
55  *
56  * For example, a #GtkMenuItem widget may have an accelerator added to emit the
57  * "activate" signal when the 'Ctl+S' key combination is pressed.
58  * A #GtkAccelLabel is created and added to the #GtkMenuItem, and
59  * gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
60  * second argument. The #GtkAccelLabel will now display 'Ctl+S' after its label.
61  *
62  * Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
63  * one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
64  * automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
65  * gtk_accel_label_set_accel_widget() to set it up for you.
66  *
67  * A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
68  * set (see #GtkAccelFlags).
69  * A #GtkAccelLabel can display multiple accelerators and even signal names,
70  * though it is almost always used to display just one accelerator key.
71  * <example>
72  * <title>Creating a simple menu item with an accelerator key.</title>
73  * <programlisting>
74  *   GtkWidget *save_item;
75  *   GtkAccelGroup *accel_group;
76  *
77  *   /<!---->* Create a GtkAccelGroup and add it to the window. *<!---->/
78  *   accel_group = gtk_accel_group_new (<!-- -->);
79  *   gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
80  *
81  *   /<!---->* Create the menu item using the convenience function. *<!---->/
82  *   save_item = gtk_menu_item_new_with_label ("Save");
83  *   gtk_widget_show (save_item);
84  *   gtk_container_add (GTK_CONTAINER (menu), save_item);
85  *
86  *   /<!---->* Now add the accelerator to the GtkMenuItem. Note that since we called
87  *      gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the
88  *      GtkAccelLabel is automatically set up to display the GtkMenuItem
89  *      accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. *<!---->/
90  *   gtk_widget_add_accelerator (save_item, "activate", accel_group,
91  *                               GDK_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
92  * </programlisting>
93  * </example>
94  */
95
96 enum {
97   PROP_0,
98   PROP_ACCEL_CLOSURE,
99   PROP_ACCEL_WIDGET
100 };
101
102 static void         gtk_accel_label_set_property (GObject            *object,
103                                                   guint               prop_id,
104                                                   const GValue       *value,
105                                                   GParamSpec         *pspec);
106 static void         gtk_accel_label_get_property (GObject            *object,
107                                                   guint               prop_id,
108                                                   GValue             *value,
109                                                   GParamSpec         *pspec);
110 static void         gtk_accel_label_destroy      (GtkObject          *object);
111 static void         gtk_accel_label_finalize     (GObject            *object);
112 static void         gtk_accel_label_size_request (GtkWidget          *widget,
113                                                   GtkRequisition     *requisition);
114 static gboolean     gtk_accel_label_expose_event (GtkWidget          *widget,
115                                                   GdkEventExpose     *event);
116 static const gchar *gtk_accel_label_get_string   (GtkAccelLabel      *accel_label);
117
118
119 G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
120
121 static void
122 gtk_accel_label_class_init (GtkAccelLabelClass *class)
123 {
124   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
125   GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
126   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
127   
128   gobject_class->finalize = gtk_accel_label_finalize;
129   gobject_class->set_property = gtk_accel_label_set_property;
130   gobject_class->get_property = gtk_accel_label_get_property;
131   
132   object_class->destroy = gtk_accel_label_destroy;
133    
134   widget_class->size_request = gtk_accel_label_size_request;
135   widget_class->expose_event = gtk_accel_label_expose_event;
136
137   class->signal_quote1 = g_strdup ("<:");
138   class->signal_quote2 = g_strdup (":>");
139
140 #ifndef GDK_WINDOWING_QUARTZ
141   /* This is the text that should appear next to menu accelerators
142    * that use the shift key. If the text on this key isn't typically
143    * translated on keyboards used for your language, don't translate
144    * this.
145    */
146   class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
147   /* This is the text that should appear next to menu accelerators
148    * that use the control key. If the text on this key isn't typically
149    * translated on keyboards used for your language, don't translate
150    * this.
151    */
152   class->mod_name_control = g_strdup (C_("keyboard label", "Ctrl"));
153   /* This is the text that should appear next to menu accelerators
154    * that use the alt key. If the text on this key isn't typically
155    * translated on keyboards used for your language, don't translate
156    * this.
157    */
158   class->mod_name_alt = g_strdup (C_("keyboard label", "Alt"));
159   class->mod_separator = g_strdup ("+");
160 #else /* GDK_WINDOWING_QUARTZ */
161
162   /* U+21E7 UPWARDS WHITE ARROW */
163   class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
164   /* U+2303 UP ARROWHEAD */
165   class->mod_name_control = g_strdup ("\xe2\x8c\x83");
166   /* U+2325 OPTION KEY */
167   class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
168   class->mod_separator = g_strdup ("");
169
170 #endif /* GDK_WINDOWING_QUARTZ */
171
172   class->accel_seperator = g_strdup (" / ");
173   class->latin1_to_char = TRUE;
174   
175   g_object_class_install_property (gobject_class,
176                                    PROP_ACCEL_CLOSURE,
177                                    g_param_spec_boxed ("accel-closure",
178                                                        P_("Accelerator Closure"),
179                                                        P_("The closure to be monitored for accelerator changes"),
180                                                        G_TYPE_CLOSURE,
181                                                        GTK_PARAM_READWRITE));
182   g_object_class_install_property (gobject_class,
183                                    PROP_ACCEL_WIDGET,
184                                    g_param_spec_object ("accel-widget",
185                                                         P_("Accelerator Widget"),
186                                                         P_("The widget to be monitored for accelerator changes"),
187                                                         GTK_TYPE_WIDGET,
188                                                         GTK_PARAM_READWRITE));
189 }
190
191 static void
192 gtk_accel_label_set_property (GObject      *object,
193                               guint         prop_id,
194                               const GValue *value,
195                               GParamSpec   *pspec)
196 {
197   GtkAccelLabel  *accel_label;
198
199   accel_label = GTK_ACCEL_LABEL (object);
200
201   switch (prop_id)
202     {
203     case PROP_ACCEL_CLOSURE:
204       gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
205       break;
206     case PROP_ACCEL_WIDGET:
207       gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
208       break;
209     default:
210       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
211       break;
212     }
213 }
214
215 static void
216 gtk_accel_label_get_property (GObject    *object,
217                               guint       prop_id,
218                               GValue     *value,
219                               GParamSpec *pspec)
220 {
221   GtkAccelLabel  *accel_label;
222
223   accel_label = GTK_ACCEL_LABEL (object);
224
225   switch (prop_id)
226     {
227     case PROP_ACCEL_CLOSURE:
228       g_value_set_boxed (value, accel_label->accel_closure);
229       break;
230     case PROP_ACCEL_WIDGET:
231       g_value_set_object (value, accel_label->accel_widget);
232       break;
233     default:
234       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
235       break;
236     }
237 }
238
239 static void
240 gtk_accel_label_init (GtkAccelLabel *accel_label)
241 {
242   accel_label->accel_padding = 3;
243   accel_label->accel_widget = NULL;
244   accel_label->accel_closure = NULL;
245   accel_label->accel_group = NULL;
246   accel_label->accel_string = NULL;
247 }
248
249 /**
250  * gtk_accel_label_new:
251  * @string: the label string. Must be non-%NULL.
252  *
253  * Creates a new #GtkAccelLabel.
254  *
255  * Returns: a new #GtkAccelLabel.
256  */
257 GtkWidget*
258 gtk_accel_label_new (const gchar *string)
259 {
260   GtkAccelLabel *accel_label;
261   
262   g_return_val_if_fail (string != NULL, NULL);
263   
264   accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
265   
266   gtk_label_set_text (GTK_LABEL (accel_label), string);
267   
268   return GTK_WIDGET (accel_label);
269 }
270
271 static void
272 gtk_accel_label_destroy (GtkObject *object)
273 {
274   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
275
276   gtk_accel_label_set_accel_widget (accel_label, NULL);
277   gtk_accel_label_set_accel_closure (accel_label, NULL);
278   
279   GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
280 }
281
282 static void
283 gtk_accel_label_finalize (GObject *object)
284 {
285   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
286
287   g_free (accel_label->accel_string);
288   
289   G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
290 }
291
292 /**
293  * gtk_accel_label_get_accel_widget:
294  * @accel_label: a #GtkAccelLabel
295  *
296  * Fetches the widget monitored by this accelerator label. See
297  * gtk_accel_label_set_accel_widget().
298  *
299  * Returns: the object monitored by the accelerator label, or %NULL.
300  **/
301 GtkWidget*
302 gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
303 {
304   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
305
306   return accel_label->accel_widget;
307 }
308
309 /**
310  * gtk_accel_label_get_accel_width:
311  * @accel_label: a #GtkAccelLabel.
312  *
313  * Returns the width needed to display the accelerator key(s).
314  * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
315  * be needed by applications.
316  *
317  * Returns: the width needed to display the accelerator key(s).
318  */
319 guint
320 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
321 {
322   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
323   
324   return (accel_label->accel_string_width +
325           (accel_label->accel_string_width ? accel_label->accel_padding : 0));
326 }
327
328 static void
329 gtk_accel_label_size_request (GtkWidget      *widget,
330                               GtkRequisition *requisition)
331 {
332   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
333   PangoLayout *layout;
334   gint width;
335
336   GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
337
338   layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
339   pango_layout_get_pixel_size (layout, &width, NULL);
340   accel_label->accel_string_width = width;
341   
342   g_object_unref (layout);
343 }
344
345 static gint
346 get_first_baseline (PangoLayout *layout)
347 {
348   PangoLayoutIter *iter;
349   gint result;
350
351   iter = pango_layout_get_iter (layout);
352   result = pango_layout_iter_get_baseline (iter);
353   pango_layout_iter_free (iter);
354
355   return PANGO_PIXELS (result);
356 }
357
358 static gboolean 
359 gtk_accel_label_expose_event (GtkWidget      *widget,
360                               GdkEventExpose *event)
361 {
362   GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
363   GtkMisc *misc = GTK_MISC (accel_label);
364   GtkTextDirection direction;
365
366   direction = gtk_widget_get_direction (widget);
367
368   if (gtk_widget_is_drawable (widget))
369     {
370       guint ac_width;
371       
372       ac_width = gtk_accel_label_get_accel_width (accel_label);
373       
374       if (widget->allocation.width >= widget->requisition.width + ac_width)
375         {
376           PangoLayout *label_layout;
377           PangoLayout *accel_layout;
378           GtkLabel *label = GTK_LABEL (widget);
379
380           gint x;
381           gint y;
382           
383           label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
384
385           if (direction == GTK_TEXT_DIR_RTL)
386             widget->allocation.x += ac_width;
387           widget->allocation.width -= ac_width;
388           if (gtk_label_get_ellipsize (label))
389             pango_layout_set_width (label_layout,
390                                     pango_layout_get_width (label_layout) 
391                                     - ac_width * PANGO_SCALE);
392           
393           if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
394             GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
395           if (direction == GTK_TEXT_DIR_RTL)
396             widget->allocation.x -= ac_width;
397           widget->allocation.width += ac_width;
398           if (gtk_label_get_ellipsize (label))
399             pango_layout_set_width (label_layout,
400                                     pango_layout_get_width (label_layout) 
401                                     + ac_width * PANGO_SCALE);
402           
403           if (direction == GTK_TEXT_DIR_RTL)
404             x = widget->allocation.x + misc->xpad;
405           else
406             x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
407
408           gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
409
410           accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
411
412           y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
413
414           gtk_paint_layout (widget->style,
415                             widget->window,
416                             gtk_widget_get_state (widget),
417                             FALSE,
418                             &event->area,
419                             widget,
420                             "accellabel",
421                             x, y,
422                             accel_layout);                            
423
424           g_object_unref (accel_layout);
425         }
426       else
427         {
428           if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
429             GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
430         }
431     }
432   
433   return FALSE;
434 }
435
436 static void
437 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
438 {
439   GClosure *closure = NULL;
440   GList *clist, *list;
441   
442   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
443   g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
444   
445   clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
446   for (list = clist; list; list = list->next)
447     {
448       /* we just take the first closure used */
449       closure = list->data;
450       break;
451     }
452   g_list_free (clist);
453   gtk_accel_label_set_accel_closure (accel_label, closure);
454 }
455
456 /**
457  * gtk_accel_label_set_accel_widget:
458  * @accel_label: a #GtkAccelLabel
459  * @accel_widget: the widget to be monitored.
460  *
461  * Sets the widget to be monitored by this accelerator label. 
462  **/
463 void
464 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
465                                   GtkWidget     *accel_widget)
466 {
467   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
468   if (accel_widget)
469     g_return_if_fail (GTK_IS_WIDGET (accel_widget));
470     
471   if (accel_widget != accel_label->accel_widget)
472     {
473       if (accel_label->accel_widget)
474         {
475           gtk_accel_label_set_accel_closure (accel_label, NULL);
476           g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
477                                                 refetch_widget_accel_closure,
478                                                 accel_label);
479           g_object_unref (accel_label->accel_widget);
480         }
481       accel_label->accel_widget = accel_widget;
482       if (accel_label->accel_widget)
483         {
484           g_object_ref (accel_label->accel_widget);
485           g_signal_connect_object (accel_label->accel_widget, "accel-closures-changed",
486                                    G_CALLBACK (refetch_widget_accel_closure),
487                                    accel_label, G_CONNECT_SWAPPED);
488           refetch_widget_accel_closure (accel_label);
489         }
490       g_object_notify (G_OBJECT (accel_label), "accel-widget");
491     }
492 }
493
494 static void
495 gtk_accel_label_reset (GtkAccelLabel *accel_label)
496 {
497   if (accel_label->accel_string)
498     {
499       g_free (accel_label->accel_string);
500       accel_label->accel_string = NULL;
501     }
502   
503   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
504 }
505
506 static void
507 check_accel_changed (GtkAccelGroup  *accel_group,
508                      guint           keyval,
509                      GdkModifierType modifier,
510                      GClosure       *accel_closure,
511                      GtkAccelLabel  *accel_label)
512 {
513   if (accel_closure == accel_label->accel_closure)
514     gtk_accel_label_reset (accel_label);
515 }
516
517 /**
518  * gtk_accel_label_set_accel_closure:
519  * @accel_label: a #GtkAccelLabel
520  * @accel_closure: the closure to monitor for accelerator changes.
521  *
522  * Sets the closure to be monitored by this accelerator label. The closure
523  * must be connected to an accelerator group; see gtk_accel_group_connect().
524  **/
525 void
526 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
527                                    GClosure      *accel_closure)
528 {
529   g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
530   if (accel_closure)
531     g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
532
533   if (accel_closure != accel_label->accel_closure)
534     {
535       if (accel_label->accel_closure)
536         {
537           g_signal_handlers_disconnect_by_func (accel_label->accel_group,
538                                                 check_accel_changed,
539                                                 accel_label);
540           accel_label->accel_group = NULL;
541           g_closure_unref (accel_label->accel_closure);
542         }
543       accel_label->accel_closure = accel_closure;
544       if (accel_label->accel_closure)
545         {
546           g_closure_ref (accel_label->accel_closure);
547           accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
548           g_signal_connect_object (accel_label->accel_group, "accel-changed",
549                                    G_CALLBACK (check_accel_changed),
550                                    accel_label, 0);
551         }
552       gtk_accel_label_reset (accel_label);
553       g_object_notify (G_OBJECT (accel_label), "accel-closure");
554     }
555 }
556
557 static gboolean
558 find_accel (GtkAccelKey *key,
559             GClosure    *closure,
560             gpointer     data)
561 {
562   return data == (gpointer) closure;
563 }
564
565 static const gchar *
566 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
567 {
568   if (!accel_label->accel_string)
569     gtk_accel_label_refetch (accel_label);
570   
571   return accel_label->accel_string;
572 }
573
574 /* Underscores in key names are better displayed as spaces
575  * E.g., Page_Up should be "Page Up"
576  */
577 static void
578 substitute_underscores (char *str)
579 {
580   char *p;
581
582   for (p = str; *p; p++)
583     if (*p == '_')
584       *p = ' ';
585 }
586
587 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
588  * append it to gstring and return TRUE; otherwise return FALSE.
589  * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html 
590  * for the list of special keys. */
591 static gboolean
592 append_keyval_symbol (guint    accelerator_key,
593                       GString *gstring)
594 {
595 #ifdef GDK_WINDOWING_QUARTZ
596   switch (accelerator_key)
597   {
598   case GDK_Return:
599     /* U+21A9 LEFTWARDS ARROW WITH HOOK */
600     g_string_append (gstring, "\xe2\x86\xa9");
601     return TRUE;
602
603   case GDK_ISO_Enter:
604     /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
605     g_string_append (gstring, "\xe2\x8c\xa4");
606     return TRUE;
607
608   case GDK_Left:
609     /* U+2190 LEFTWARDS ARROW */
610     g_string_append (gstring, "\xe2\x86\x90");
611     return TRUE;
612
613   case GDK_Up:
614     /* U+2191 UPWARDS ARROW */
615     g_string_append (gstring, "\xe2\x86\x91");
616     return TRUE;
617
618   case GDK_Right:
619     /* U+2192 RIGHTWARDS ARROW */
620     g_string_append (gstring, "\xe2\x86\x92");
621     return TRUE;
622
623   case GDK_Down:
624     /* U+2193 DOWNWARDS ARROW */
625     g_string_append (gstring, "\xe2\x86\x93");
626     return TRUE;
627
628   case GDK_Page_Up:
629     /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
630     g_string_append (gstring, "\xe2\x87\x9e");
631     return TRUE;
632
633   case GDK_Page_Down:
634     /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
635     g_string_append (gstring, "\xe2\x87\x9f");
636     return TRUE;
637
638   case GDK_Home:
639     /* U+2196 NORTH WEST ARROW */
640     g_string_append (gstring, "\xe2\x86\x96");
641     return TRUE;
642
643   case GDK_End:
644     /* U+2198 SOUTH EAST ARROW */
645     g_string_append (gstring, "\xe2\x86\x98");
646     return TRUE;
647
648   case GDK_Escape:
649     /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
650     g_string_append (gstring, "\xe2\x8e\x8b");
651     return TRUE;
652
653   case GDK_BackSpace:
654     /* U+232B ERASE TO THE LEFT */
655     g_string_append (gstring, "\xe2\x8c\xab");
656     return TRUE;
657
658   case GDK_Delete:
659     /* U+2326 ERASE TO THE RIGHT */
660     g_string_append (gstring, "\xe2\x8c\xa6");
661     return TRUE;
662
663   default:
664     return FALSE;
665   }
666 #else /* !GDK_WINDOWING_QUARTZ */
667   return FALSE;
668 #endif
669 }
670
671 gchar *
672 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
673                                               guint               accelerator_key,
674                                               GdkModifierType     accelerator_mods)
675 {
676   GString *gstring;
677   gboolean seen_mod = FALSE;
678   gunichar ch;
679   
680   gstring = g_string_new ("");
681   
682   if (accelerator_mods & GDK_SHIFT_MASK)
683     {
684       g_string_append (gstring, klass->mod_name_shift);
685       seen_mod = TRUE;
686     }
687   if (accelerator_mods & GDK_CONTROL_MASK)
688     {
689       if (seen_mod)
690         g_string_append (gstring, klass->mod_separator);
691       g_string_append (gstring, klass->mod_name_control);
692       seen_mod = TRUE;
693     }
694   if (accelerator_mods & GDK_MOD1_MASK)
695     {
696       if (seen_mod)
697         g_string_append (gstring, klass->mod_separator);
698       g_string_append (gstring, klass->mod_name_alt);
699       seen_mod = TRUE;
700     }
701   if (accelerator_mods & GDK_MOD2_MASK)
702     {
703       if (seen_mod)
704         g_string_append (gstring, klass->mod_separator);
705
706       g_string_append (gstring, "Mod2");
707       seen_mod = TRUE;
708     }
709   if (accelerator_mods & GDK_MOD3_MASK)
710     {
711       if (seen_mod)
712         g_string_append (gstring, klass->mod_separator);
713
714       g_string_append (gstring, "Mod3");
715       seen_mod = TRUE;
716     }
717   if (accelerator_mods & GDK_MOD4_MASK)
718     {
719       if (seen_mod)
720         g_string_append (gstring, klass->mod_separator);
721
722       g_string_append (gstring, "Mod4");
723       seen_mod = TRUE;
724     }
725   if (accelerator_mods & GDK_MOD5_MASK)
726     {
727       if (seen_mod)
728         g_string_append (gstring, klass->mod_separator);
729
730       g_string_append (gstring, "Mod5");
731       seen_mod = TRUE;
732     }
733   if (accelerator_mods & GDK_SUPER_MASK)
734     {
735       if (seen_mod)
736         g_string_append (gstring, klass->mod_separator);
737
738       /* This is the text that should appear next to menu accelerators
739        * that use the super key. If the text on this key isn't typically
740        * translated on keyboards used for your language, don't translate
741        * this.
742        */
743       g_string_append (gstring, C_("keyboard label", "Super"));
744       seen_mod = TRUE;
745     }
746   if (accelerator_mods & GDK_HYPER_MASK)
747     {
748       if (seen_mod)
749         g_string_append (gstring, klass->mod_separator);
750
751       /* This is the text that should appear next to menu accelerators
752        * that use the hyper key. If the text on this key isn't typically
753        * translated on keyboards used for your language, don't translate
754        * this.
755        */
756       g_string_append (gstring, C_("keyboard label", "Hyper"));
757       seen_mod = TRUE;
758     }
759   if (accelerator_mods & GDK_META_MASK)
760     {
761       if (seen_mod)
762         g_string_append (gstring, klass->mod_separator);
763
764 #ifndef GDK_WINDOWING_QUARTZ
765       /* This is the text that should appear next to menu accelerators
766        * that use the meta key. If the text on this key isn't typically
767        * translated on keyboards used for your language, don't translate
768        * this.
769        */
770       g_string_append (gstring, C_("keyboard label", "Meta"));
771 #else
772       /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
773       g_string_append (gstring, "\xe2\x8c\x98");
774 #endif
775       seen_mod = TRUE;
776     }
777   if (seen_mod)
778     g_string_append (gstring, klass->mod_separator);
779   
780   ch = gdk_keyval_to_unicode (accelerator_key);
781   if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
782       (ch < 0x80 || klass->latin1_to_char))
783     {
784       switch (ch)
785         {
786         case ' ':
787           g_string_append (gstring, C_("keyboard label", "Space"));
788           break;
789         case '\\':
790           g_string_append (gstring, C_("keyboard label", "Backslash"));
791           break;
792         default:
793           g_string_append_unichar (gstring, g_unichar_toupper (ch));
794           break;
795         }
796     }
797   else if (!append_keyval_symbol (accelerator_key, gstring))
798     {
799       gchar *tmp;
800
801       tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
802       if (tmp != NULL)
803         {
804           if (tmp[0] != 0 && tmp[1] == 0)
805             g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
806           else
807             {
808               const gchar *str;
809               str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
810               if (str == tmp)
811                 {
812                   g_string_append (gstring, tmp);
813                   substitute_underscores (gstring->str);
814                 }
815               else
816                 g_string_append (gstring, str);
817             }
818         }
819     }
820
821   return g_string_free (gstring, FALSE);
822 }
823
824 /**
825  * gtk_accel_label_refetch:
826  * @accel_label: a #GtkAccelLabel.
827  *
828  * Recreates the string representing the accelerator keys.
829  * This should not be needed since the string is automatically updated whenever
830  * accelerators are added or removed from the associated widget.
831  *
832  * Returns: always returns %FALSE.
833  */
834 gboolean
835 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
836 {
837   gboolean enable_accels;
838
839   g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
840
841   if (accel_label->accel_string)
842     {
843       g_free (accel_label->accel_string);
844       accel_label->accel_string = NULL;
845     }
846
847   g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
848                 "gtk-enable-accels", &enable_accels,
849                 NULL);
850
851   if (enable_accels && accel_label->accel_closure)
852     {
853       GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
854
855       if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
856         {
857           GtkAccelLabelClass *klass;
858           gchar *tmp;
859
860           klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
861           tmp = _gtk_accel_label_class_get_accelerator_label (klass,
862                                                               key->accel_key,
863                                                               key->accel_mods);
864           accel_label->accel_string = g_strconcat ("   ", tmp, NULL);
865           g_free (tmp);
866         }
867       if (!accel_label->accel_string)
868         accel_label->accel_string = g_strdup ("-/-");
869     }
870   
871   if (!accel_label->accel_string)
872     accel_label->accel_string = g_strdup ("");
873
874   gtk_widget_queue_resize (GTK_WIDGET (accel_label));
875
876   return FALSE;
877 }
878
879 #define __GTK_ACCEL_LABEL_C__
880 #include "gtkaliasdef.c"