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 (GtkWidget *widget);
122 static void gtk_accel_label_finalize (GObject *object);
123 static gboolean gtk_accel_label_draw (GtkWidget *widget,
125 static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
128 static void gtk_accel_label_get_preferred_width (GtkWidget *widget,
132 #define GTK_ACCEL_LABEL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_ACCEL_LABEL, GtkAccelLabelPrivate))
135 G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
138 gtk_accel_label_class_init (GtkAccelLabelClass *class)
140 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
141 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
143 gobject_class->finalize = gtk_accel_label_finalize;
144 gobject_class->set_property = gtk_accel_label_set_property;
145 gobject_class->get_property = gtk_accel_label_get_property;
147 widget_class->draw = gtk_accel_label_draw;
148 widget_class->get_preferred_width = gtk_accel_label_get_preferred_width;
149 widget_class->destroy = gtk_accel_label_destroy;
151 class->signal_quote1 = g_strdup ("<:");
152 class->signal_quote2 = g_strdup (":>");
154 #ifndef GDK_WINDOWING_QUARTZ
155 /* This is the text that should appear next to menu accelerators
156 * that use the shift key. If the text on this key isn't typically
157 * translated on keyboards used for your language, don't translate
160 class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
161 /* This is the text that should appear next to menu accelerators
162 * that use the control 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_control = g_strdup (C_("keyboard label", "Ctrl"));
167 /* This is the text that should appear next to menu accelerators
168 * that use the alt 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_alt = g_strdup (C_("keyboard label", "Alt"));
173 class->mod_separator = g_strdup ("+");
174 #else /* GDK_WINDOWING_QUARTZ */
176 /* U+21E7 UPWARDS WHITE ARROW */
177 class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
178 /* U+2303 UP ARROWHEAD */
179 class->mod_name_control = g_strdup ("\xe2\x8c\x83");
180 /* U+2325 OPTION KEY */
181 class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
182 class->mod_separator = g_strdup ("");
184 #endif /* GDK_WINDOWING_QUARTZ */
186 g_object_class_install_property (gobject_class,
188 g_param_spec_boxed ("accel-closure",
189 P_("Accelerator Closure"),
190 P_("The closure to be monitored for accelerator changes"),
192 GTK_PARAM_READWRITE));
193 g_object_class_install_property (gobject_class,
195 g_param_spec_object ("accel-widget",
196 P_("Accelerator Widget"),
197 P_("The widget to be monitored for accelerator changes"),
199 GTK_PARAM_READWRITE));
201 g_type_class_add_private (gobject_class, sizeof (GtkAccelLabelPrivate));
205 gtk_accel_label_set_property (GObject *object,
210 GtkAccelLabel *accel_label;
212 accel_label = GTK_ACCEL_LABEL (object);
216 case PROP_ACCEL_CLOSURE:
217 gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
219 case PROP_ACCEL_WIDGET:
220 gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
223 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
229 gtk_accel_label_get_property (GObject *object,
234 GtkAccelLabel *accel_label;
236 accel_label = GTK_ACCEL_LABEL (object);
240 case PROP_ACCEL_CLOSURE:
241 g_value_set_boxed (value, accel_label->priv->accel_closure);
243 case PROP_ACCEL_WIDGET:
244 g_value_set_object (value, accel_label->priv->accel_widget);
247 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
253 gtk_accel_label_init (GtkAccelLabel *accel_label)
255 GtkAccelLabelPrivate *priv = GTK_ACCEL_LABEL_GET_PRIVATE (accel_label);
257 priv->accel_padding = 3;
258 priv->accel_widget = NULL;
259 priv->accel_closure = NULL;
260 priv->accel_group = NULL;
261 priv->accel_string = NULL;
263 accel_label->priv = priv;
267 * gtk_accel_label_new:
268 * @string: the label string. Must be non-%NULL.
270 * Creates a new #GtkAccelLabel.
272 * Returns: a new #GtkAccelLabel.
275 gtk_accel_label_new (const gchar *string)
277 GtkAccelLabel *accel_label;
279 g_return_val_if_fail (string != NULL, NULL);
281 accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
283 gtk_label_set_text (GTK_LABEL (accel_label), string);
285 return GTK_WIDGET (accel_label);
289 gtk_accel_label_destroy (GtkWidget *widget)
291 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
293 gtk_accel_label_set_accel_widget (accel_label, NULL);
294 gtk_accel_label_set_accel_closure (accel_label, NULL);
296 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->destroy (widget);
300 gtk_accel_label_finalize (GObject *object)
302 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
304 g_free (accel_label->priv->accel_string);
306 G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
310 * gtk_accel_label_get_accel_widget:
311 * @accel_label: a #GtkAccelLabel
313 * Fetches the widget monitored by this accelerator label. See
314 * gtk_accel_label_set_accel_widget().
316 * Returns: (transfer none): the object monitored by the accelerator label, or %NULL.
319 gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
321 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
323 return accel_label->priv->accel_widget;
327 * gtk_accel_label_get_accel_width:
328 * @accel_label: a #GtkAccelLabel.
330 * Returns the width needed to display the accelerator key(s).
331 * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
332 * be needed by applications.
334 * Returns: the width needed to display the accelerator key(s).
337 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
339 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
341 return (accel_label->priv->accel_string_width +
342 (accel_label->priv->accel_string_width ? accel_label->priv->accel_padding : 0));
346 gtk_accel_label_get_preferred_width (GtkWidget *widget,
350 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
354 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->get_preferred_width (widget, min_width, nat_width);
356 layout = gtk_widget_create_pango_layout (GTK_WIDGET (widget),
357 gtk_accel_label_get_string (accel_label));
358 pango_layout_get_pixel_size (layout, &width, NULL);
359 accel_label->priv->accel_string_width = width;
361 g_object_unref (layout);
365 get_first_baseline (PangoLayout *layout)
367 PangoLayoutIter *iter;
370 iter = pango_layout_get_iter (layout);
371 result = pango_layout_iter_get_baseline (iter);
372 pango_layout_iter_free (iter);
374 return PANGO_PIXELS (result);
378 gtk_accel_label_draw (GtkWidget *widget,
381 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
382 GtkMisc *misc = GTK_MISC (accel_label);
383 GtkTextDirection direction;
385 GtkAllocation allocation;
386 GtkRequisition requisition;
388 direction = gtk_widget_get_direction (widget);
389 ac_width = gtk_accel_label_get_accel_width (accel_label);
390 gtk_widget_get_allocation (widget, &allocation);
391 gtk_widget_get_preferred_size (widget, &requisition, NULL);
393 if (allocation.width >= requisition.width + ac_width)
395 GtkStyleContext *context;
396 PangoLayout *label_layout;
397 PangoLayout *accel_layout;
398 GtkLabel *label = GTK_LABEL (widget);
404 context = gtk_widget_get_style_context (widget);
405 label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
409 /* XXX: Mad hack: We modify the label's width so it renders
410 * properly in its draw function that we chain to. */
411 if (direction == GTK_TEXT_DIR_RTL)
412 cairo_translate (cr, ac_width, 0);
413 if (gtk_label_get_ellipsize (label))
414 pango_layout_set_width (label_layout,
415 pango_layout_get_width (label_layout)
416 - ac_width * PANGO_SCALE);
418 allocation.width -= ac_width;
419 gtk_widget_set_allocation (widget, &allocation);
420 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
421 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget,
423 allocation.width += ac_width;
424 gtk_widget_set_allocation (widget, &allocation);
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);
432 gtk_misc_get_padding (misc, &xpad, NULL);
434 if (direction == GTK_TEXT_DIR_RTL)
437 x = gtk_widget_get_allocated_width (widget) - xpad - ac_width;
439 gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
441 accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
443 y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y;
445 gtk_style_context_save (context);
446 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ACCELERATOR);
447 gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
449 gtk_render_layout (context, cr, x, y, accel_layout);
450 gtk_style_context_restore (context);
452 g_object_unref (accel_layout);
456 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
457 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr);
464 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
466 GClosure *closure = NULL;
469 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
470 g_return_if_fail (GTK_IS_WIDGET (accel_label->priv->accel_widget));
472 clist = gtk_widget_list_accel_closures (accel_label->priv->accel_widget);
473 for (list = clist; list; list = list->next)
475 /* we just take the first closure used */
476 closure = list->data;
480 gtk_accel_label_set_accel_closure (accel_label, closure);
484 * gtk_accel_label_set_accel_widget:
485 * @accel_label: a #GtkAccelLabel
486 * @accel_widget: the widget to be monitored.
488 * Sets the widget to be monitored by this accelerator label.
491 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
492 GtkWidget *accel_widget)
494 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
496 g_return_if_fail (GTK_IS_WIDGET (accel_widget));
498 if (accel_widget != accel_label->priv->accel_widget)
500 if (accel_label->priv->accel_widget)
502 gtk_accel_label_set_accel_closure (accel_label, NULL);
503 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_widget,
504 refetch_widget_accel_closure,
506 g_object_unref (accel_label->priv->accel_widget);
508 accel_label->priv->accel_widget = accel_widget;
509 if (accel_label->priv->accel_widget)
511 g_object_ref (accel_label->priv->accel_widget);
512 g_signal_connect_object (accel_label->priv->accel_widget, "accel-closures-changed",
513 G_CALLBACK (refetch_widget_accel_closure),
514 accel_label, G_CONNECT_SWAPPED);
515 refetch_widget_accel_closure (accel_label);
517 g_object_notify (G_OBJECT (accel_label), "accel-widget");
522 gtk_accel_label_reset (GtkAccelLabel *accel_label)
524 if (accel_label->priv->accel_string)
526 g_free (accel_label->priv->accel_string);
527 accel_label->priv->accel_string = NULL;
530 gtk_widget_queue_resize (GTK_WIDGET (accel_label));
534 check_accel_changed (GtkAccelGroup *accel_group,
536 GdkModifierType modifier,
537 GClosure *accel_closure,
538 GtkAccelLabel *accel_label)
540 if (accel_closure == accel_label->priv->accel_closure)
541 gtk_accel_label_reset (accel_label);
545 * gtk_accel_label_set_accel_closure:
546 * @accel_label: a #GtkAccelLabel
547 * @accel_closure: the closure to monitor for accelerator changes.
549 * Sets the closure to be monitored by this accelerator label. The closure
550 * must be connected to an accelerator group; see gtk_accel_group_connect().
553 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
554 GClosure *accel_closure)
556 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
558 g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
560 if (accel_closure != accel_label->priv->accel_closure)
562 if (accel_label->priv->accel_closure)
564 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_group,
567 accel_label->priv->accel_group = NULL;
568 g_closure_unref (accel_label->priv->accel_closure);
570 accel_label->priv->accel_closure = accel_closure;
571 if (accel_label->priv->accel_closure)
573 g_closure_ref (accel_label->priv->accel_closure);
574 accel_label->priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
575 g_signal_connect_object (accel_label->priv->accel_group, "accel-changed",
576 G_CALLBACK (check_accel_changed),
579 gtk_accel_label_reset (accel_label);
580 g_object_notify (G_OBJECT (accel_label), "accel-closure");
585 find_accel (GtkAccelKey *key,
589 return data == (gpointer) closure;
593 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
595 if (!accel_label->priv->accel_string)
596 gtk_accel_label_refetch (accel_label);
598 return accel_label->priv->accel_string;
601 /* Underscores in key names are better displayed as spaces
602 * E.g., Page_Up should be "Page Up"
605 substitute_underscores (char *str)
609 for (p = str; *p; p++)
614 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
615 * append it to gstring and return TRUE; otherwise return FALSE.
616 * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
617 * for the list of special keys. */
619 append_keyval_symbol (guint accelerator_key,
622 #ifdef GDK_WINDOWING_QUARTZ
623 switch (accelerator_key)
626 /* U+21A9 LEFTWARDS ARROW WITH HOOK */
627 g_string_append (gstring, "\xe2\x86\xa9");
630 case GDK_KEY_ISO_Enter:
631 /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
632 g_string_append (gstring, "\xe2\x8c\xa4");
636 /* U+2190 LEFTWARDS ARROW */
637 g_string_append (gstring, "\xe2\x86\x90");
641 /* U+2191 UPWARDS ARROW */
642 g_string_append (gstring, "\xe2\x86\x91");
646 /* U+2192 RIGHTWARDS ARROW */
647 g_string_append (gstring, "\xe2\x86\x92");
651 /* U+2193 DOWNWARDS ARROW */
652 g_string_append (gstring, "\xe2\x86\x93");
655 case GDK_KEY_Page_Up:
656 /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
657 g_string_append (gstring, "\xe2\x87\x9e");
660 case GDK_KEY_Page_Down:
661 /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
662 g_string_append (gstring, "\xe2\x87\x9f");
666 /* U+2196 NORTH WEST ARROW */
667 g_string_append (gstring, "\xe2\x86\x96");
671 /* U+2198 SOUTH EAST ARROW */
672 g_string_append (gstring, "\xe2\x86\x98");
676 /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
677 g_string_append (gstring, "\xe2\x8e\x8b");
680 case GDK_KEY_BackSpace:
681 /* U+232B ERASE TO THE LEFT */
682 g_string_append (gstring, "\xe2\x8c\xab");
686 /* U+2326 ERASE TO THE RIGHT */
687 g_string_append (gstring, "\xe2\x8c\xa6");
693 #else /* !GDK_WINDOWING_QUARTZ */
699 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
700 guint accelerator_key,
701 GdkModifierType accelerator_mods)
704 gboolean seen_mod = FALSE;
707 gstring = g_string_new ("");
709 if (accelerator_mods & GDK_SHIFT_MASK)
711 g_string_append (gstring, klass->mod_name_shift);
714 if (accelerator_mods & GDK_CONTROL_MASK)
717 g_string_append (gstring, klass->mod_separator);
718 g_string_append (gstring, klass->mod_name_control);
721 if (accelerator_mods & GDK_MOD1_MASK)
724 g_string_append (gstring, klass->mod_separator);
725 g_string_append (gstring, klass->mod_name_alt);
728 if (accelerator_mods & GDK_MOD2_MASK)
731 g_string_append (gstring, klass->mod_separator);
733 g_string_append (gstring, "Mod2");
736 if (accelerator_mods & GDK_MOD3_MASK)
739 g_string_append (gstring, klass->mod_separator);
741 g_string_append (gstring, "Mod3");
744 if (accelerator_mods & GDK_MOD4_MASK)
747 g_string_append (gstring, klass->mod_separator);
749 g_string_append (gstring, "Mod4");
752 if (accelerator_mods & GDK_MOD5_MASK)
755 g_string_append (gstring, klass->mod_separator);
757 g_string_append (gstring, "Mod5");
760 if (accelerator_mods & GDK_SUPER_MASK)
763 g_string_append (gstring, klass->mod_separator);
765 /* This is the text that should appear next to menu accelerators
766 * that use the super key. If the text on this key isn't typically
767 * translated on keyboards used for your language, don't translate
770 g_string_append (gstring, C_("keyboard label", "Super"));
773 if (accelerator_mods & GDK_HYPER_MASK)
776 g_string_append (gstring, klass->mod_separator);
778 /* This is the text that should appear next to menu accelerators
779 * that use the hyper key. If the text on this key isn't typically
780 * translated on keyboards used for your language, don't translate
783 g_string_append (gstring, C_("keyboard label", "Hyper"));
786 if (accelerator_mods & GDK_META_MASK)
789 g_string_append (gstring, klass->mod_separator);
791 #ifndef GDK_WINDOWING_QUARTZ
792 /* This is the text that should appear next to menu accelerators
793 * that use the meta key. If the text on this key isn't typically
794 * translated on keyboards used for your language, don't translate
797 g_string_append (gstring, C_("keyboard label", "Meta"));
799 /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
800 g_string_append (gstring, "\xe2\x8c\x98");
805 g_string_append (gstring, klass->mod_separator);
807 ch = gdk_keyval_to_unicode (accelerator_key);
808 if (ch && ch < 0x80 && (g_unichar_isgraph (ch) || ch == ' '))
813 g_string_append (gstring, C_("keyboard label", "Space"));
816 g_string_append (gstring, C_("keyboard label", "Backslash"));
819 g_string_append_unichar (gstring, g_unichar_toupper (ch));
823 else if (!append_keyval_symbol (accelerator_key, gstring))
827 tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
830 if (tmp[0] != 0 && tmp[1] == 0)
831 g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
835 str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
838 g_string_append (gstring, tmp);
839 substitute_underscores (gstring->str);
842 g_string_append (gstring, str);
847 return g_string_free (gstring, FALSE);
851 * gtk_accel_label_refetch:
852 * @accel_label: a #GtkAccelLabel.
854 * Recreates the string representing the accelerator keys.
855 * This should not be needed since the string is automatically updated whenever
856 * accelerators are added or removed from the associated widget.
858 * Returns: always returns %FALSE.
861 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
863 gboolean enable_accels;
865 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
867 if (accel_label->priv->accel_string)
869 g_free (accel_label->priv->accel_string);
870 accel_label->priv->accel_string = NULL;
873 g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
874 "gtk-enable-accels", &enable_accels,
877 if (enable_accels && accel_label->priv->accel_closure)
879 GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
881 if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
883 GtkAccelLabelClass *klass;
886 klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
887 tmp = _gtk_accel_label_class_get_accelerator_label (klass,
890 accel_label->priv->accel_string = g_strconcat (" ", tmp, NULL);
893 if (!accel_label->priv->accel_string)
894 accel_label->priv->accel_string = g_strdup ("-/-");
897 if (!accel_label->priv->accel_string)
898 accel_label->priv->accel_string = g_strdup ("");
900 gtk_widget_queue_resize (GTK_WIDGET (accel_label));