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_size_request_get_size (GTK_SIZE_REQUEST (widget),
411 if (allocation.width >= requisition.width + ac_width)
413 PangoLayout *label_layout;
414 PangoLayout *accel_layout;
415 GtkLabel *label = GTK_LABEL (widget);
421 label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
423 if (direction == GTK_TEXT_DIR_RTL)
424 allocation.x += ac_width;
425 allocation.width -= ac_width;
426 if (gtk_label_get_ellipsize (label))
427 pango_layout_set_width (label_layout,
428 pango_layout_get_width (label_layout)
429 - ac_width * PANGO_SCALE);
431 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
432 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
433 if (direction == GTK_TEXT_DIR_RTL)
434 allocation.x -= ac_width;
435 allocation.width += ac_width;
436 if (gtk_label_get_ellipsize (label))
437 pango_layout_set_width (label_layout,
438 pango_layout_get_width (label_layout)
439 + ac_width * PANGO_SCALE);
441 gtk_misc_get_padding (misc, &xpad, NULL);
443 if (direction == GTK_TEXT_DIR_RTL)
444 x = allocation.x + xpad;
446 x = allocation.x + allocation.width - xpad - ac_width;
448 gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
450 accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
452 y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
454 gtk_paint_layout (gtk_widget_get_style (widget),
455 gtk_widget_get_window (widget),
456 gtk_widget_get_state (widget),
464 g_object_unref (accel_layout);
468 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
469 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
477 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
479 GClosure *closure = NULL;
482 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
483 g_return_if_fail (GTK_IS_WIDGET (accel_label->priv->accel_widget));
485 clist = gtk_widget_list_accel_closures (accel_label->priv->accel_widget);
486 for (list = clist; list; list = list->next)
488 /* we just take the first closure used */
489 closure = list->data;
493 gtk_accel_label_set_accel_closure (accel_label, closure);
497 * gtk_accel_label_set_accel_widget:
498 * @accel_label: a #GtkAccelLabel
499 * @accel_widget: the widget to be monitored.
501 * Sets the widget to be monitored by this accelerator label.
504 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
505 GtkWidget *accel_widget)
507 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
509 g_return_if_fail (GTK_IS_WIDGET (accel_widget));
511 if (accel_widget != accel_label->priv->accel_widget)
513 if (accel_label->priv->accel_widget)
515 gtk_accel_label_set_accel_closure (accel_label, NULL);
516 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_widget,
517 refetch_widget_accel_closure,
519 g_object_unref (accel_label->priv->accel_widget);
521 accel_label->priv->accel_widget = accel_widget;
522 if (accel_label->priv->accel_widget)
524 g_object_ref (accel_label->priv->accel_widget);
525 g_signal_connect_object (accel_label->priv->accel_widget, "accel-closures-changed",
526 G_CALLBACK (refetch_widget_accel_closure),
527 accel_label, G_CONNECT_SWAPPED);
528 refetch_widget_accel_closure (accel_label);
530 g_object_notify (G_OBJECT (accel_label), "accel-widget");
535 gtk_accel_label_reset (GtkAccelLabel *accel_label)
537 if (accel_label->priv->accel_string)
539 g_free (accel_label->priv->accel_string);
540 accel_label->priv->accel_string = NULL;
543 gtk_widget_queue_resize (GTK_WIDGET (accel_label));
547 check_accel_changed (GtkAccelGroup *accel_group,
549 GdkModifierType modifier,
550 GClosure *accel_closure,
551 GtkAccelLabel *accel_label)
553 if (accel_closure == accel_label->priv->accel_closure)
554 gtk_accel_label_reset (accel_label);
558 * gtk_accel_label_set_accel_closure:
559 * @accel_label: a #GtkAccelLabel
560 * @accel_closure: the closure to monitor for accelerator changes.
562 * Sets the closure to be monitored by this accelerator label. The closure
563 * must be connected to an accelerator group; see gtk_accel_group_connect().
566 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
567 GClosure *accel_closure)
569 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
571 g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
573 if (accel_closure != accel_label->priv->accel_closure)
575 if (accel_label->priv->accel_closure)
577 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_group,
580 accel_label->priv->accel_group = NULL;
581 g_closure_unref (accel_label->priv->accel_closure);
583 accel_label->priv->accel_closure = accel_closure;
584 if (accel_label->priv->accel_closure)
586 g_closure_ref (accel_label->priv->accel_closure);
587 accel_label->priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
588 g_signal_connect_object (accel_label->priv->accel_group, "accel-changed",
589 G_CALLBACK (check_accel_changed),
592 gtk_accel_label_reset (accel_label);
593 g_object_notify (G_OBJECT (accel_label), "accel-closure");
598 find_accel (GtkAccelKey *key,
602 return data == (gpointer) closure;
606 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
608 if (!accel_label->priv->accel_string)
609 gtk_accel_label_refetch (accel_label);
611 return accel_label->priv->accel_string;
614 /* Underscores in key names are better displayed as spaces
615 * E.g., Page_Up should be "Page Up"
618 substitute_underscores (char *str)
622 for (p = str; *p; p++)
627 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
628 * append it to gstring and return TRUE; otherwise return FALSE.
629 * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
630 * for the list of special keys. */
632 append_keyval_symbol (guint accelerator_key,
635 #ifdef GDK_WINDOWING_QUARTZ
636 switch (accelerator_key)
639 /* U+21A9 LEFTWARDS ARROW WITH HOOK */
640 g_string_append (gstring, "\xe2\x86\xa9");
643 case GDK_KEY_ISO_Enter:
644 /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
645 g_string_append (gstring, "\xe2\x8c\xa4");
649 /* U+2190 LEFTWARDS ARROW */
650 g_string_append (gstring, "\xe2\x86\x90");
654 /* U+2191 UPWARDS ARROW */
655 g_string_append (gstring, "\xe2\x86\x91");
659 /* U+2192 RIGHTWARDS ARROW */
660 g_string_append (gstring, "\xe2\x86\x92");
664 /* U+2193 DOWNWARDS ARROW */
665 g_string_append (gstring, "\xe2\x86\x93");
668 case GDK_KEY_Page_Up:
669 /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
670 g_string_append (gstring, "\xe2\x87\x9e");
673 case GDK_KEY_Page_Down:
674 /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
675 g_string_append (gstring, "\xe2\x87\x9f");
679 /* U+2196 NORTH WEST ARROW */
680 g_string_append (gstring, "\xe2\x86\x96");
684 /* U+2198 SOUTH EAST ARROW */
685 g_string_append (gstring, "\xe2\x86\x98");
689 /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
690 g_string_append (gstring, "\xe2\x8e\x8b");
693 case GDK_KEY_BackSpace:
694 /* U+232B ERASE TO THE LEFT */
695 g_string_append (gstring, "\xe2\x8c\xab");
699 /* U+2326 ERASE TO THE RIGHT */
700 g_string_append (gstring, "\xe2\x8c\xa6");
706 #else /* !GDK_WINDOWING_QUARTZ */
712 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
713 guint accelerator_key,
714 GdkModifierType accelerator_mods)
717 gboolean seen_mod = FALSE;
720 gstring = g_string_new ("");
722 if (accelerator_mods & GDK_SHIFT_MASK)
724 g_string_append (gstring, klass->mod_name_shift);
727 if (accelerator_mods & GDK_CONTROL_MASK)
730 g_string_append (gstring, klass->mod_separator);
731 g_string_append (gstring, klass->mod_name_control);
734 if (accelerator_mods & GDK_MOD1_MASK)
737 g_string_append (gstring, klass->mod_separator);
738 g_string_append (gstring, klass->mod_name_alt);
741 if (accelerator_mods & GDK_MOD2_MASK)
744 g_string_append (gstring, klass->mod_separator);
746 g_string_append (gstring, "Mod2");
749 if (accelerator_mods & GDK_MOD3_MASK)
752 g_string_append (gstring, klass->mod_separator);
754 g_string_append (gstring, "Mod3");
757 if (accelerator_mods & GDK_MOD4_MASK)
760 g_string_append (gstring, klass->mod_separator);
762 g_string_append (gstring, "Mod4");
765 if (accelerator_mods & GDK_MOD5_MASK)
768 g_string_append (gstring, klass->mod_separator);
770 g_string_append (gstring, "Mod5");
773 if (accelerator_mods & GDK_SUPER_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 super 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", "Super"));
786 if (accelerator_mods & GDK_HYPER_MASK)
789 g_string_append (gstring, klass->mod_separator);
791 /* This is the text that should appear next to menu accelerators
792 * that use the hyper key. If the text on this key isn't typically
793 * translated on keyboards used for your language, don't translate
796 g_string_append (gstring, C_("keyboard label", "Hyper"));
799 if (accelerator_mods & GDK_META_MASK)
802 g_string_append (gstring, klass->mod_separator);
804 #ifndef GDK_WINDOWING_QUARTZ
805 /* This is the text that should appear next to menu accelerators
806 * that use the meta key. If the text on this key isn't typically
807 * translated on keyboards used for your language, don't translate
810 g_string_append (gstring, C_("keyboard label", "Meta"));
812 /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
813 g_string_append (gstring, "\xe2\x8c\x98");
818 g_string_append (gstring, klass->mod_separator);
820 ch = gdk_keyval_to_unicode (accelerator_key);
821 if (ch && ch < 0x80 && (g_unichar_isgraph (ch) || ch == ' '))
826 g_string_append (gstring, C_("keyboard label", "Space"));
829 g_string_append (gstring, C_("keyboard label", "Backslash"));
832 g_string_append_unichar (gstring, g_unichar_toupper (ch));
836 else if (!append_keyval_symbol (accelerator_key, gstring))
840 tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
843 if (tmp[0] != 0 && tmp[1] == 0)
844 g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
848 str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
851 g_string_append (gstring, tmp);
852 substitute_underscores (gstring->str);
855 g_string_append (gstring, str);
860 return g_string_free (gstring, FALSE);
864 * gtk_accel_label_refetch:
865 * @accel_label: a #GtkAccelLabel.
867 * Recreates the string representing the accelerator keys.
868 * This should not be needed since the string is automatically updated whenever
869 * accelerators are added or removed from the associated widget.
871 * Returns: always returns %FALSE.
874 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
876 gboolean enable_accels;
878 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
880 if (accel_label->priv->accel_string)
882 g_free (accel_label->priv->accel_string);
883 accel_label->priv->accel_string = NULL;
886 g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
887 "gtk-enable-accels", &enable_accels,
890 if (enable_accels && accel_label->priv->accel_closure)
892 GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
894 if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
896 GtkAccelLabelClass *klass;
899 klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
900 tmp = _gtk_accel_label_class_get_accelerator_label (klass,
903 accel_label->priv->accel_string = g_strconcat (" ", tmp, NULL);
906 if (!accel_label->priv->accel_string)
907 accel_label->priv->accel_string = g_strdup ("-/-");
910 if (!accel_label->priv->accel_string)
911 accel_label->priv->accel_string = g_strdup ("");
913 gtk_widget_queue_resize (GTK_WIDGET (accel_label));