1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * GtkAccelLabel: GtkLabel with accelerator monitoring facilities.
5 * Copyright (C) 1998 Tim Janik
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.
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.
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.
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/.
33 #include "gtkaccellabel.h"
34 #include "gtkaccelmap.h"
36 #include "gtksizerequest.h"
37 #include "gtkprivate.h"
40 #include <gdk/gdkkeysyms.h>
43 * SECTION:gtkaccellabel
44 * @Short_description: A label which displays an accelerator key on the right of the text
45 * @Title: GtkAccelLabel
46 * @See_also: #GtkItemFactory, #GtkAccelGroup
48 * The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
49 * accelerator key on the right of the label text, e.g. 'Ctl+S'.
50 * It is commonly used in menus to show the keyboard short-cuts for commands.
52 * The accelerator key to display is not set explicitly.
53 * Instead, the #GtkAccelLabel displays the accelerators which have been added to
54 * a particular widget. This widget is set by calling
55 * gtk_accel_label_set_accel_widget().
57 * For example, a #GtkMenuItem widget may have an accelerator added to emit the
58 * "activate" signal when the 'Ctl+S' key combination is pressed.
59 * A #GtkAccelLabel is created and added to the #GtkMenuItem, and
60 * gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
61 * second argument. The #GtkAccelLabel will now display 'Ctl+S' after its label.
63 * Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
64 * one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
65 * automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
66 * gtk_accel_label_set_accel_widget() to set it up for you.
68 * A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
69 * set (see #GtkAccelFlags).
70 * A #GtkAccelLabel can display multiple accelerators and even signal names,
71 * though it is almost always used to display just one accelerator key.
73 * <title>Creating a simple menu item with an accelerator key.</title>
75 * GtkWidget *save_item;
76 * GtkAccelGroup *accel_group;
78 * /<!---->* Create a GtkAccelGroup and add it to the window. *<!---->/
79 * accel_group = gtk_accel_group_new (<!-- -->);
80 * gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
82 * /<!---->* Create the menu item using the convenience function. *<!---->/
83 * save_item = gtk_menu_item_new_with_label ("Save");
84 * gtk_widget_show (save_item);
85 * gtk_container_add (GTK_CONTAINER (menu), save_item);
87 * /<!---->* Now add the accelerator to the GtkMenuItem. Note that since we called
88 * gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the
89 * GtkAccelLabel is automatically set up to display the GtkMenuItem
90 * accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. *<!---->/
91 * gtk_widget_add_accelerator (save_item, "activate", accel_group,
92 * GDK_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
103 struct _GtkAccelLabelPrivate
105 guint accel_padding; /* should be style property? */
106 GtkWidget *accel_widget; /* done*/
107 GClosure *accel_closure; /* has set function */
108 GtkAccelGroup *accel_group; /* set by set_accel_closure() */
109 gchar *accel_string; /* has set function */
110 guint16 accel_string_width; /* seems to be private */
113 static void gtk_accel_label_set_property (GObject *object,
117 static void gtk_accel_label_get_property (GObject *object,
121 static void gtk_accel_label_destroy (GtkObject *object);
122 static void gtk_accel_label_finalize (GObject *object);
123 static gboolean gtk_accel_label_expose_event (GtkWidget *widget,
124 GdkEventExpose *event);
125 static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
128 static void gtk_accel_label_size_request_init (GtkSizeRequestIface *iface);
129 static void gtk_accel_label_get_width (GtkSizeRequest *widget,
133 #define GTK_ACCEL_LABEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ACCEL_LABEL, GtkAccelLabelPrivate))
136 static GtkSizeRequestIface *parent_size_request_iface;
138 G_DEFINE_TYPE_WITH_CODE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL,
139 G_IMPLEMENT_INTERFACE (GTK_TYPE_SIZE_REQUEST,
140 gtk_accel_label_size_request_init))
143 gtk_accel_label_class_init (GtkAccelLabelClass *class)
145 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
146 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
147 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
149 gobject_class->finalize = gtk_accel_label_finalize;
150 gobject_class->set_property = gtk_accel_label_set_property;
151 gobject_class->get_property = gtk_accel_label_get_property;
153 object_class->destroy = gtk_accel_label_destroy;
155 widget_class->expose_event = gtk_accel_label_expose_event;
157 class->signal_quote1 = g_strdup ("<:");
158 class->signal_quote2 = g_strdup (":>");
160 #ifndef GDK_WINDOWING_QUARTZ
161 /* This is the text that should appear next to menu accelerators
162 * that use the shift key. If the text on this key isn't typically
163 * translated on keyboards used for your language, don't translate
166 class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
167 /* This is the text that should appear next to menu accelerators
168 * that use the control key. If the text on this key isn't typically
169 * translated on keyboards used for your language, don't translate
172 class->mod_name_control = g_strdup (C_("keyboard label", "Ctrl"));
173 /* This is the text that should appear next to menu accelerators
174 * that use the alt key. If the text on this key isn't typically
175 * translated on keyboards used for your language, don't translate
178 class->mod_name_alt = g_strdup (C_("keyboard label", "Alt"));
179 class->mod_separator = g_strdup ("+");
180 #else /* GDK_WINDOWING_QUARTZ */
182 /* U+21E7 UPWARDS WHITE ARROW */
183 class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
184 /* U+2303 UP ARROWHEAD */
185 class->mod_name_control = g_strdup ("\xe2\x8c\x83");
186 /* U+2325 OPTION KEY */
187 class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
188 class->mod_separator = g_strdup ("");
190 #endif /* GDK_WINDOWING_QUARTZ */
192 g_object_class_install_property (gobject_class,
194 g_param_spec_boxed ("accel-closure",
195 P_("Accelerator Closure"),
196 P_("The closure to be monitored for accelerator changes"),
198 GTK_PARAM_READWRITE));
199 g_object_class_install_property (gobject_class,
201 g_param_spec_object ("accel-widget",
202 P_("Accelerator Widget"),
203 P_("The widget to be monitored for accelerator changes"),
205 GTK_PARAM_READWRITE));
207 g_type_class_add_private (gobject_class, sizeof (GtkAccelLabelPrivate));
211 gtk_accel_label_set_property (GObject *object,
216 GtkAccelLabel *accel_label;
218 accel_label = GTK_ACCEL_LABEL (object);
222 case PROP_ACCEL_CLOSURE:
223 gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
225 case PROP_ACCEL_WIDGET:
226 gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
229 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
235 gtk_accel_label_get_property (GObject *object,
240 GtkAccelLabel *accel_label;
242 accel_label = GTK_ACCEL_LABEL (object);
246 case PROP_ACCEL_CLOSURE:
247 g_value_set_boxed (value, accel_label->priv->accel_closure);
249 case PROP_ACCEL_WIDGET:
250 g_value_set_object (value, accel_label->priv->accel_widget);
253 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
259 gtk_accel_label_init (GtkAccelLabel *accel_label)
261 GtkAccelLabelPrivate *priv = GTK_ACCEL_LABEL_GET_PRIVATE (accel_label);
263 priv->accel_padding = 3;
264 priv->accel_widget = NULL;
265 priv->accel_closure = NULL;
266 priv->accel_group = NULL;
267 priv->accel_string = NULL;
269 accel_label->priv = priv;
273 * gtk_accel_label_new:
274 * @string: the label string. Must be non-%NULL.
276 * Creates a new #GtkAccelLabel.
278 * Returns: a new #GtkAccelLabel.
281 gtk_accel_label_new (const gchar *string)
283 GtkAccelLabel *accel_label;
285 g_return_val_if_fail (string != NULL, NULL);
287 accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
289 gtk_label_set_text (GTK_LABEL (accel_label), string);
291 return GTK_WIDGET (accel_label);
295 gtk_accel_label_destroy (GtkObject *object)
297 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
299 gtk_accel_label_set_accel_widget (accel_label, NULL);
300 gtk_accel_label_set_accel_closure (accel_label, NULL);
302 GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
306 gtk_accel_label_finalize (GObject *object)
308 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
310 g_free (accel_label->priv->accel_string);
312 G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
316 * gtk_accel_label_get_accel_widget:
317 * @accel_label: a #GtkAccelLabel
319 * Fetches the widget monitored by this accelerator label. See
320 * gtk_accel_label_set_accel_widget().
322 * Returns: the object monitored by the accelerator label, or %NULL.
325 gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
327 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
329 return accel_label->priv->accel_widget;
333 * gtk_accel_label_get_accel_width:
334 * @accel_label: a #GtkAccelLabel.
336 * Returns the width needed to display the accelerator key(s).
337 * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
338 * be needed by applications.
340 * Returns: the width needed to display the accelerator key(s).
343 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
345 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
347 return (accel_label->priv->accel_string_width +
348 (accel_label->priv->accel_string_width ? accel_label->priv->accel_padding : 0));
352 gtk_accel_label_size_request_init (GtkSizeRequestIface *iface)
354 parent_size_request_iface = g_type_interface_peek_parent (iface);
355 iface->get_width = gtk_accel_label_get_width;
359 gtk_accel_label_get_width (GtkSizeRequest *widget,
363 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
367 parent_size_request_iface->get_width (widget, min_width, nat_width);
369 layout = gtk_widget_create_pango_layout (GTK_WIDGET (widget),
370 gtk_accel_label_get_string (accel_label));
371 pango_layout_get_pixel_size (layout, &width, NULL);
372 accel_label->priv->accel_string_width = width;
374 g_object_unref (layout);
378 get_first_baseline (PangoLayout *layout)
380 PangoLayoutIter *iter;
383 iter = pango_layout_get_iter (layout);
384 result = pango_layout_iter_get_baseline (iter);
385 pango_layout_iter_free (iter);
387 return PANGO_PIXELS (result);
391 gtk_accel_label_expose_event (GtkWidget *widget,
392 GdkEventExpose *event)
394 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
395 GtkMisc *misc = GTK_MISC (accel_label);
396 GtkTextDirection direction;
398 direction = gtk_widget_get_direction (widget);
400 if (gtk_widget_is_drawable (widget))
403 GtkAllocation allocation;
404 GtkRequisition requisition;
406 ac_width = gtk_accel_label_get_accel_width (accel_label);
407 gtk_widget_get_allocation (widget, &allocation);
408 gtk_widget_size_request (widget, &requisition);
410 if (allocation.width >= requisition.width + ac_width)
412 PangoLayout *label_layout;
413 PangoLayout *accel_layout;
414 GtkLabel *label = GTK_LABEL (widget);
420 label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
422 if (direction == GTK_TEXT_DIR_RTL)
423 allocation.x += ac_width;
424 allocation.width -= ac_width;
425 if (gtk_label_get_ellipsize (label))
426 pango_layout_set_width (label_layout,
427 pango_layout_get_width (label_layout)
428 - ac_width * PANGO_SCALE);
430 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
431 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
432 if (direction == GTK_TEXT_DIR_RTL)
433 allocation.x -= ac_width;
434 allocation.width += ac_width;
435 if (gtk_label_get_ellipsize (label))
436 pango_layout_set_width (label_layout,
437 pango_layout_get_width (label_layout)
438 + ac_width * PANGO_SCALE);
440 gtk_misc_get_padding (misc, &xpad, NULL);
442 if (direction == GTK_TEXT_DIR_RTL)
443 x = allocation.x + xpad;
445 x = allocation.x + allocation.width - xpad - ac_width;
447 gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
449 accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
451 y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
453 gtk_paint_layout (gtk_widget_get_style (widget),
454 gtk_widget_get_window (widget),
455 gtk_widget_get_state (widget),
463 g_object_unref (accel_layout);
467 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
468 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
476 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
478 GClosure *closure = NULL;
481 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
482 g_return_if_fail (GTK_IS_WIDGET (accel_label->priv->accel_widget));
484 clist = gtk_widget_list_accel_closures (accel_label->priv->accel_widget);
485 for (list = clist; list; list = list->next)
487 /* we just take the first closure used */
488 closure = list->data;
492 gtk_accel_label_set_accel_closure (accel_label, closure);
496 * gtk_accel_label_set_accel_widget:
497 * @accel_label: a #GtkAccelLabel
498 * @accel_widget: the widget to be monitored.
500 * Sets the widget to be monitored by this accelerator label.
503 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
504 GtkWidget *accel_widget)
506 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
508 g_return_if_fail (GTK_IS_WIDGET (accel_widget));
510 if (accel_widget != accel_label->priv->accel_widget)
512 if (accel_label->priv->accel_widget)
514 gtk_accel_label_set_accel_closure (accel_label, NULL);
515 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_widget,
516 refetch_widget_accel_closure,
518 g_object_unref (accel_label->priv->accel_widget);
520 accel_label->priv->accel_widget = accel_widget;
521 if (accel_label->priv->accel_widget)
523 g_object_ref (accel_label->priv->accel_widget);
524 g_signal_connect_object (accel_label->priv->accel_widget, "accel-closures-changed",
525 G_CALLBACK (refetch_widget_accel_closure),
526 accel_label, G_CONNECT_SWAPPED);
527 refetch_widget_accel_closure (accel_label);
529 g_object_notify (G_OBJECT (accel_label), "accel-widget");
534 gtk_accel_label_reset (GtkAccelLabel *accel_label)
536 if (accel_label->priv->accel_string)
538 g_free (accel_label->priv->accel_string);
539 accel_label->priv->accel_string = NULL;
542 gtk_widget_queue_resize (GTK_WIDGET (accel_label));
546 check_accel_changed (GtkAccelGroup *accel_group,
548 GdkModifierType modifier,
549 GClosure *accel_closure,
550 GtkAccelLabel *accel_label)
552 if (accel_closure == accel_label->priv->accel_closure)
553 gtk_accel_label_reset (accel_label);
557 * gtk_accel_label_set_accel_closure:
558 * @accel_label: a #GtkAccelLabel
559 * @accel_closure: the closure to monitor for accelerator changes.
561 * Sets the closure to be monitored by this accelerator label. The closure
562 * must be connected to an accelerator group; see gtk_accel_group_connect().
565 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
566 GClosure *accel_closure)
568 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
570 g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
572 if (accel_closure != accel_label->priv->accel_closure)
574 if (accel_label->priv->accel_closure)
576 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_group,
579 accel_label->priv->accel_group = NULL;
580 g_closure_unref (accel_label->priv->accel_closure);
582 accel_label->priv->accel_closure = accel_closure;
583 if (accel_label->priv->accel_closure)
585 g_closure_ref (accel_label->priv->accel_closure);
586 accel_label->priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
587 g_signal_connect_object (accel_label->priv->accel_group, "accel-changed",
588 G_CALLBACK (check_accel_changed),
591 gtk_accel_label_reset (accel_label);
592 g_object_notify (G_OBJECT (accel_label), "accel-closure");
597 find_accel (GtkAccelKey *key,
601 return data == (gpointer) closure;
605 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
607 if (!accel_label->priv->accel_string)
608 gtk_accel_label_refetch (accel_label);
610 return accel_label->priv->accel_string;
613 /* Underscores in key names are better displayed as spaces
614 * E.g., Page_Up should be "Page Up"
617 substitute_underscores (char *str)
621 for (p = str; *p; p++)
626 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
627 * append it to gstring and return TRUE; otherwise return FALSE.
628 * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
629 * for the list of special keys. */
631 append_keyval_symbol (guint accelerator_key,
634 #ifdef GDK_WINDOWING_QUARTZ
635 switch (accelerator_key)
638 /* U+21A9 LEFTWARDS ARROW WITH HOOK */
639 g_string_append (gstring, "\xe2\x86\xa9");
642 case GDK_KEY_ISO_Enter:
643 /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
644 g_string_append (gstring, "\xe2\x8c\xa4");
648 /* U+2190 LEFTWARDS ARROW */
649 g_string_append (gstring, "\xe2\x86\x90");
653 /* U+2191 UPWARDS ARROW */
654 g_string_append (gstring, "\xe2\x86\x91");
658 /* U+2192 RIGHTWARDS ARROW */
659 g_string_append (gstring, "\xe2\x86\x92");
663 /* U+2193 DOWNWARDS ARROW */
664 g_string_append (gstring, "\xe2\x86\x93");
667 case GDK_KEY_Page_Up:
668 /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
669 g_string_append (gstring, "\xe2\x87\x9e");
672 case GDK_KEY_Page_Down:
673 /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
674 g_string_append (gstring, "\xe2\x87\x9f");
678 /* U+2196 NORTH WEST ARROW */
679 g_string_append (gstring, "\xe2\x86\x96");
683 /* U+2198 SOUTH EAST ARROW */
684 g_string_append (gstring, "\xe2\x86\x98");
688 /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
689 g_string_append (gstring, "\xe2\x8e\x8b");
692 case GDK_KEY_BackSpace:
693 /* U+232B ERASE TO THE LEFT */
694 g_string_append (gstring, "\xe2\x8c\xab");
698 /* U+2326 ERASE TO THE RIGHT */
699 g_string_append (gstring, "\xe2\x8c\xa6");
705 #else /* !GDK_WINDOWING_QUARTZ */
711 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
712 guint accelerator_key,
713 GdkModifierType accelerator_mods)
716 gboolean seen_mod = FALSE;
719 gstring = g_string_new ("");
721 if (accelerator_mods & GDK_SHIFT_MASK)
723 g_string_append (gstring, klass->mod_name_shift);
726 if (accelerator_mods & GDK_CONTROL_MASK)
729 g_string_append (gstring, klass->mod_separator);
730 g_string_append (gstring, klass->mod_name_control);
733 if (accelerator_mods & GDK_MOD1_MASK)
736 g_string_append (gstring, klass->mod_separator);
737 g_string_append (gstring, klass->mod_name_alt);
740 if (accelerator_mods & GDK_MOD2_MASK)
743 g_string_append (gstring, klass->mod_separator);
745 g_string_append (gstring, "Mod2");
748 if (accelerator_mods & GDK_MOD3_MASK)
751 g_string_append (gstring, klass->mod_separator);
753 g_string_append (gstring, "Mod3");
756 if (accelerator_mods & GDK_MOD4_MASK)
759 g_string_append (gstring, klass->mod_separator);
761 g_string_append (gstring, "Mod4");
764 if (accelerator_mods & GDK_MOD5_MASK)
767 g_string_append (gstring, klass->mod_separator);
769 g_string_append (gstring, "Mod5");
772 if (accelerator_mods & GDK_SUPER_MASK)
775 g_string_append (gstring, klass->mod_separator);
777 /* This is the text that should appear next to menu accelerators
778 * that use the super key. If the text on this key isn't typically
779 * translated on keyboards used for your language, don't translate
782 g_string_append (gstring, C_("keyboard label", "Super"));
785 if (accelerator_mods & GDK_HYPER_MASK)
788 g_string_append (gstring, klass->mod_separator);
790 /* This is the text that should appear next to menu accelerators
791 * that use the hyper key. If the text on this key isn't typically
792 * translated on keyboards used for your language, don't translate
795 g_string_append (gstring, C_("keyboard label", "Hyper"));
798 if (accelerator_mods & GDK_META_MASK)
801 g_string_append (gstring, klass->mod_separator);
803 #ifndef GDK_WINDOWING_QUARTZ
804 /* This is the text that should appear next to menu accelerators
805 * that use the meta key. If the text on this key isn't typically
806 * translated on keyboards used for your language, don't translate
809 g_string_append (gstring, C_("keyboard label", "Meta"));
811 /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
812 g_string_append (gstring, "\xe2\x8c\x98");
817 g_string_append (gstring, klass->mod_separator);
819 ch = gdk_keyval_to_unicode (accelerator_key);
820 if (ch && ch < 0x80 && (g_unichar_isgraph (ch) || ch == ' '))
825 g_string_append (gstring, C_("keyboard label", "Space"));
828 g_string_append (gstring, C_("keyboard label", "Backslash"));
831 g_string_append_unichar (gstring, g_unichar_toupper (ch));
835 else if (!append_keyval_symbol (accelerator_key, gstring))
839 tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
842 if (tmp[0] != 0 && tmp[1] == 0)
843 g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
847 str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
850 g_string_append (gstring, tmp);
851 substitute_underscores (gstring->str);
854 g_string_append (gstring, str);
859 return g_string_free (gstring, FALSE);
863 * gtk_accel_label_refetch:
864 * @accel_label: a #GtkAccelLabel.
866 * Recreates the string representing the accelerator keys.
867 * This should not be needed since the string is automatically updated whenever
868 * accelerators are added or removed from the associated widget.
870 * Returns: always returns %FALSE.
873 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
875 gboolean enable_accels;
877 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
879 if (accel_label->priv->accel_string)
881 g_free (accel_label->priv->accel_string);
882 accel_label->priv->accel_string = NULL;
885 g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
886 "gtk-enable-accels", &enable_accels,
889 if (enable_accels && accel_label->priv->accel_closure)
891 GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
893 if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
895 GtkAccelLabelClass *klass;
898 klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
899 tmp = _gtk_accel_label_class_get_accelerator_label (klass,
902 accel_label->priv->accel_string = g_strconcat (" ", tmp, NULL);
905 if (!accel_label->priv->accel_string)
906 accel_label->priv->accel_string = g_strdup ("-/-");
909 if (!accel_label->priv->accel_string)
910 accel_label->priv->accel_string = g_strdup ("");
912 gtk_widget_queue_resize (GTK_WIDGET (accel_label));