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"
41 * SECTION:gtkaccellabel
42 * @Short_description: A label which displays an accelerator key on the right of the text
43 * @Title: GtkAccelLabel
44 * @See_also: #GtkAccelGroup
46 * The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
47 * accelerator key on the right of the label text, e.g. 'Ctl+S'.
48 * It is commonly used in menus to show the keyboard short-cuts for commands.
50 * The accelerator key to display is not set explicitly.
51 * Instead, the #GtkAccelLabel displays the accelerators which have been added to
52 * a particular widget. This widget is set by calling
53 * gtk_accel_label_set_accel_widget().
55 * For example, a #GtkMenuItem widget may have an accelerator added to emit the
56 * "activate" signal when the 'Ctl+S' key combination is pressed.
57 * A #GtkAccelLabel is created and added to the #GtkMenuItem, and
58 * gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
59 * second argument. The #GtkAccelLabel will now display 'Ctl+S' after its label.
61 * Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
62 * one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
63 * automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
64 * gtk_accel_label_set_accel_widget() to set it up for you.
66 * A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
67 * set (see #GtkAccelFlags).
68 * A #GtkAccelLabel can display multiple accelerators and even signal names,
69 * though it is almost always used to display just one accelerator key.
71 * <title>Creating a simple menu item with an accelerator key.</title>
73 * GtkWidget *save_item;
74 * GtkAccelGroup *accel_group;
76 * /<!---->* Create a GtkAccelGroup and add it to the window. *<!---->/
77 * accel_group = gtk_accel_group_new (<!-- -->);
78 * gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
80 * /<!---->* Create the menu item using the convenience function. *<!---->/
81 * save_item = gtk_menu_item_new_with_label ("Save");
82 * gtk_widget_show (save_item);
83 * gtk_container_add (GTK_CONTAINER (menu), save_item);
85 * /<!---->* Now add the accelerator to the GtkMenuItem. Note that since we called
86 * gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the
87 * GtkAccelLabel is automatically set up to display the GtkMenuItem
88 * accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. *<!---->/
89 * gtk_widget_add_accelerator (save_item, "activate", accel_group,
90 * GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
101 struct _GtkAccelLabelPrivate
103 GtkWidget *accel_widget; /* done */
104 GClosure *accel_closure; /* has set function */
105 GtkAccelGroup *accel_group; /* set by set_accel_closure() */
106 gchar *accel_string; /* has set function */
107 guint accel_padding; /* should be style property? */
108 guint16 accel_string_width; /* seems to be private */
111 static void gtk_accel_label_set_property (GObject *object,
115 static void gtk_accel_label_get_property (GObject *object,
119 static void gtk_accel_label_destroy (GtkWidget *widget);
120 static void gtk_accel_label_finalize (GObject *object);
121 static gboolean gtk_accel_label_draw (GtkWidget *widget,
123 static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
126 static void gtk_accel_label_get_preferred_width (GtkWidget *widget,
131 G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
134 gtk_accel_label_class_init (GtkAccelLabelClass *class)
136 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
137 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
139 gobject_class->finalize = gtk_accel_label_finalize;
140 gobject_class->set_property = gtk_accel_label_set_property;
141 gobject_class->get_property = gtk_accel_label_get_property;
143 widget_class->draw = gtk_accel_label_draw;
144 widget_class->get_preferred_width = gtk_accel_label_get_preferred_width;
145 widget_class->destroy = gtk_accel_label_destroy;
147 class->signal_quote1 = g_strdup ("<:");
148 class->signal_quote2 = g_strdup (":>");
150 #ifndef GDK_WINDOWING_QUARTZ
151 /* This is the text that should appear next to menu accelerators
152 * that use the shift key. If the text on this key isn't typically
153 * translated on keyboards used for your language, don't translate
156 class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
157 /* This is the text that should appear next to menu accelerators
158 * that use the control key. If the text on this key isn't typically
159 * translated on keyboards used for your language, don't translate
162 class->mod_name_control = g_strdup (C_("keyboard label", "Ctrl"));
163 /* This is the text that should appear next to menu accelerators
164 * that use the alt key. If the text on this key isn't typically
165 * translated on keyboards used for your language, don't translate
168 class->mod_name_alt = g_strdup (C_("keyboard label", "Alt"));
169 class->mod_separator = g_strdup ("+");
170 #else /* GDK_WINDOWING_QUARTZ */
172 /* U+21E7 UPWARDS WHITE ARROW */
173 class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
174 /* U+2303 UP ARROWHEAD */
175 class->mod_name_control = g_strdup ("\xe2\x8c\x83");
176 /* U+2325 OPTION KEY */
177 class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
178 class->mod_separator = g_strdup ("");
180 #endif /* GDK_WINDOWING_QUARTZ */
182 g_object_class_install_property (gobject_class,
184 g_param_spec_boxed ("accel-closure",
185 P_("Accelerator Closure"),
186 P_("The closure to be monitored for accelerator changes"),
188 GTK_PARAM_READWRITE));
189 g_object_class_install_property (gobject_class,
191 g_param_spec_object ("accel-widget",
192 P_("Accelerator Widget"),
193 P_("The widget to be monitored for accelerator changes"),
195 GTK_PARAM_READWRITE));
197 g_type_class_add_private (gobject_class, sizeof (GtkAccelLabelPrivate));
201 gtk_accel_label_set_property (GObject *object,
206 GtkAccelLabel *accel_label;
208 accel_label = GTK_ACCEL_LABEL (object);
212 case PROP_ACCEL_CLOSURE:
213 gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
215 case PROP_ACCEL_WIDGET:
216 gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
219 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
225 gtk_accel_label_get_property (GObject *object,
230 GtkAccelLabel *accel_label;
232 accel_label = GTK_ACCEL_LABEL (object);
236 case PROP_ACCEL_CLOSURE:
237 g_value_set_boxed (value, accel_label->priv->accel_closure);
239 case PROP_ACCEL_WIDGET:
240 g_value_set_object (value, accel_label->priv->accel_widget);
243 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
249 gtk_accel_label_init (GtkAccelLabel *accel_label)
251 GtkAccelLabelPrivate *priv;
253 accel_label->priv = G_TYPE_INSTANCE_GET_PRIVATE (accel_label,
254 GTK_TYPE_ACCEL_LABEL,
255 GtkAccelLabelPrivate);
256 priv = accel_label->priv;
258 priv->accel_padding = 3;
259 priv->accel_widget = NULL;
260 priv->accel_closure = NULL;
261 priv->accel_group = NULL;
262 priv->accel_string = NULL;
266 * gtk_accel_label_new:
267 * @string: the label string. Must be non-%NULL.
269 * Creates a new #GtkAccelLabel.
271 * Returns: a new #GtkAccelLabel.
274 gtk_accel_label_new (const gchar *string)
276 GtkAccelLabel *accel_label;
278 g_return_val_if_fail (string != NULL, NULL);
280 accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
282 gtk_label_set_text (GTK_LABEL (accel_label), string);
284 return GTK_WIDGET (accel_label);
288 gtk_accel_label_destroy (GtkWidget *widget)
290 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
292 gtk_accel_label_set_accel_widget (accel_label, NULL);
293 gtk_accel_label_set_accel_closure (accel_label, NULL);
295 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->destroy (widget);
299 gtk_accel_label_finalize (GObject *object)
301 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
303 g_free (accel_label->priv->accel_string);
305 G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
309 * gtk_accel_label_get_accel_widget:
310 * @accel_label: a #GtkAccelLabel
312 * Fetches the widget monitored by this accelerator label. See
313 * gtk_accel_label_set_accel_widget().
315 * Returns: (transfer none): the object monitored by the accelerator label, or %NULL.
318 gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
320 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
322 return accel_label->priv->accel_widget;
326 * gtk_accel_label_get_accel_width:
327 * @accel_label: a #GtkAccelLabel.
329 * Returns the width needed to display the accelerator key(s).
330 * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
331 * be needed by applications.
333 * Returns: the width needed to display the accelerator key(s).
336 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
338 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
340 return (accel_label->priv->accel_string_width +
341 (accel_label->priv->accel_string_width ? accel_label->priv->accel_padding : 0));
345 gtk_accel_label_get_preferred_width (GtkWidget *widget,
349 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
353 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->get_preferred_width (widget, min_width, nat_width);
355 layout = gtk_widget_create_pango_layout (GTK_WIDGET (widget),
356 gtk_accel_label_get_string (accel_label));
357 pango_layout_get_pixel_size (layout, &width, NULL);
358 accel_label->priv->accel_string_width = width;
360 g_object_unref (layout);
364 get_first_baseline (PangoLayout *layout)
366 PangoLayoutIter *iter;
369 iter = pango_layout_get_iter (layout);
370 result = pango_layout_iter_get_baseline (iter);
371 pango_layout_iter_free (iter);
373 return PANGO_PIXELS (result);
377 gtk_accel_label_draw (GtkWidget *widget,
380 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
381 GtkMisc *misc = GTK_MISC (accel_label);
382 GtkTextDirection direction;
384 GtkAllocation allocation;
385 GtkRequisition requisition;
387 direction = gtk_widget_get_direction (widget);
388 ac_width = gtk_accel_label_get_accel_width (accel_label);
389 gtk_widget_get_allocation (widget, &allocation);
390 gtk_widget_get_preferred_size (widget, NULL, &requisition);
392 if (allocation.width >= requisition.width + ac_width)
394 GtkStyleContext *context;
395 PangoLayout *label_layout;
396 PangoLayout *accel_layout;
397 GtkLabel *label = GTK_LABEL (widget);
403 context = gtk_widget_get_style_context (widget);
404 label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
408 /* XXX: Mad hack: We modify the label's width so it renders
409 * properly in its draw function that we chain to. */
410 if (direction == GTK_TEXT_DIR_RTL)
411 cairo_translate (cr, ac_width, 0);
412 if (gtk_label_get_ellipsize (label))
413 pango_layout_set_width (label_layout,
414 pango_layout_get_width (label_layout)
415 - ac_width * PANGO_SCALE);
417 allocation.width -= ac_width;
418 gtk_widget_set_allocation (widget, &allocation);
419 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
420 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget,
422 allocation.width += ac_width;
423 gtk_widget_set_allocation (widget, &allocation);
424 if (gtk_label_get_ellipsize (label))
425 pango_layout_set_width (label_layout,
426 pango_layout_get_width (label_layout)
427 + ac_width * PANGO_SCALE);
431 gtk_misc_get_padding (misc, &xpad, NULL);
433 if (direction == GTK_TEXT_DIR_RTL)
436 x = gtk_widget_get_allocated_width (widget) - xpad - ac_width;
438 gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
440 accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
442 y += get_first_baseline (label_layout) - get_first_baseline (accel_layout) - allocation.y;
444 gtk_style_context_save (context);
445 gtk_style_context_add_class (context, GTK_STYLE_CLASS_ACCELERATOR);
446 gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
448 gtk_render_layout (context, cr, x, y, accel_layout);
449 gtk_style_context_restore (context);
451 g_object_unref (accel_layout);
455 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw)
456 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->draw (widget, cr);
463 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
465 GClosure *closure = NULL;
468 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
469 g_return_if_fail (GTK_IS_WIDGET (accel_label->priv->accel_widget));
471 clist = gtk_widget_list_accel_closures (accel_label->priv->accel_widget);
472 for (list = clist; list; list = list->next)
474 /* we just take the first closure used */
475 closure = list->data;
479 gtk_accel_label_set_accel_closure (accel_label, closure);
483 * gtk_accel_label_set_accel_widget:
484 * @accel_label: a #GtkAccelLabel
485 * @accel_widget: the widget to be monitored.
487 * Sets the widget to be monitored by this accelerator label.
490 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
491 GtkWidget *accel_widget)
493 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
495 g_return_if_fail (GTK_IS_WIDGET (accel_widget));
497 if (accel_widget != accel_label->priv->accel_widget)
499 if (accel_label->priv->accel_widget)
501 gtk_accel_label_set_accel_closure (accel_label, NULL);
502 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_widget,
503 refetch_widget_accel_closure,
505 g_object_unref (accel_label->priv->accel_widget);
507 accel_label->priv->accel_widget = accel_widget;
508 if (accel_label->priv->accel_widget)
510 g_object_ref (accel_label->priv->accel_widget);
511 g_signal_connect_object (accel_label->priv->accel_widget, "accel-closures-changed",
512 G_CALLBACK (refetch_widget_accel_closure),
513 accel_label, G_CONNECT_SWAPPED);
514 refetch_widget_accel_closure (accel_label);
516 g_object_notify (G_OBJECT (accel_label), "accel-widget");
521 gtk_accel_label_reset (GtkAccelLabel *accel_label)
523 if (accel_label->priv->accel_string)
525 g_free (accel_label->priv->accel_string);
526 accel_label->priv->accel_string = NULL;
529 gtk_widget_queue_resize (GTK_WIDGET (accel_label));
533 check_accel_changed (GtkAccelGroup *accel_group,
535 GdkModifierType modifier,
536 GClosure *accel_closure,
537 GtkAccelLabel *accel_label)
539 if (accel_closure == accel_label->priv->accel_closure)
540 gtk_accel_label_reset (accel_label);
544 * gtk_accel_label_set_accel_closure:
545 * @accel_label: a #GtkAccelLabel
546 * @accel_closure: the closure to monitor for accelerator changes.
548 * Sets the closure to be monitored by this accelerator label. The closure
549 * must be connected to an accelerator group; see gtk_accel_group_connect().
552 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
553 GClosure *accel_closure)
555 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
557 g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
559 if (accel_closure != accel_label->priv->accel_closure)
561 if (accel_label->priv->accel_closure)
563 g_signal_handlers_disconnect_by_func (accel_label->priv->accel_group,
566 accel_label->priv->accel_group = NULL;
567 g_closure_unref (accel_label->priv->accel_closure);
569 accel_label->priv->accel_closure = accel_closure;
570 if (accel_label->priv->accel_closure)
572 g_closure_ref (accel_label->priv->accel_closure);
573 accel_label->priv->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
574 g_signal_connect_object (accel_label->priv->accel_group, "accel-changed",
575 G_CALLBACK (check_accel_changed),
578 gtk_accel_label_reset (accel_label);
579 g_object_notify (G_OBJECT (accel_label), "accel-closure");
584 find_accel (GtkAccelKey *key,
588 return data == (gpointer) closure;
592 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
594 if (!accel_label->priv->accel_string)
595 gtk_accel_label_refetch (accel_label);
597 return accel_label->priv->accel_string;
600 /* Underscores in key names are better displayed as spaces
601 * E.g., Page_Up should be "Page Up".
603 * Some keynames also have prefixes that are not suitable
604 * for display, e.g XF86AudioMute, so strip those out, too.
606 * This function is only called on untranslated keynames,
607 * so no need to be UTF-8 safe.
610 append_without_underscores (GString *s,
615 if (g_str_has_prefix (str, "XF86"))
617 else if (g_str_has_prefix (str, "ISO_"))
625 g_string_append_c (s, ' ');
627 g_string_append_c (s, *p);
631 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
632 * append it to gstring and return TRUE; otherwise return FALSE.
633 * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
634 * for the list of special keys. */
636 append_keyval_symbol (guint accelerator_key,
639 #ifdef GDK_WINDOWING_QUARTZ
640 switch (accelerator_key)
643 /* U+21A9 LEFTWARDS ARROW WITH HOOK */
644 g_string_append (gstring, "\xe2\x86\xa9");
647 case GDK_KEY_ISO_Enter:
648 /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
649 g_string_append (gstring, "\xe2\x8c\xa4");
653 /* U+2190 LEFTWARDS ARROW */
654 g_string_append (gstring, "\xe2\x86\x90");
658 /* U+2191 UPWARDS ARROW */
659 g_string_append (gstring, "\xe2\x86\x91");
663 /* U+2192 RIGHTWARDS ARROW */
664 g_string_append (gstring, "\xe2\x86\x92");
668 /* U+2193 DOWNWARDS ARROW */
669 g_string_append (gstring, "\xe2\x86\x93");
672 case GDK_KEY_Page_Up:
673 /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
674 g_string_append (gstring, "\xe2\x87\x9e");
677 case GDK_KEY_Page_Down:
678 /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
679 g_string_append (gstring, "\xe2\x87\x9f");
683 /* U+2196 NORTH WEST ARROW */
684 g_string_append (gstring, "\xe2\x86\x96");
688 /* U+2198 SOUTH EAST ARROW */
689 g_string_append (gstring, "\xe2\x86\x98");
693 /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
694 g_string_append (gstring, "\xe2\x8e\x8b");
697 case GDK_KEY_BackSpace:
698 /* U+232B ERASE TO THE LEFT */
699 g_string_append (gstring, "\xe2\x8c\xab");
703 /* U+2326 ERASE TO THE RIGHT */
704 g_string_append (gstring, "\xe2\x8c\xa6");
710 #else /* !GDK_WINDOWING_QUARTZ */
716 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
717 guint accelerator_key,
718 GdkModifierType accelerator_mods)
721 gboolean seen_mod = FALSE;
724 gstring = g_string_new ("");
726 if (accelerator_mods & GDK_SHIFT_MASK)
728 g_string_append (gstring, klass->mod_name_shift);
731 if (accelerator_mods & GDK_CONTROL_MASK)
734 g_string_append (gstring, klass->mod_separator);
735 g_string_append (gstring, klass->mod_name_control);
738 if (accelerator_mods & GDK_MOD1_MASK)
741 g_string_append (gstring, klass->mod_separator);
742 g_string_append (gstring, klass->mod_name_alt);
745 if (accelerator_mods & GDK_MOD2_MASK)
748 g_string_append (gstring, klass->mod_separator);
750 g_string_append (gstring, "Mod2");
753 if (accelerator_mods & GDK_MOD3_MASK)
756 g_string_append (gstring, klass->mod_separator);
758 g_string_append (gstring, "Mod3");
761 if (accelerator_mods & GDK_MOD4_MASK)
764 g_string_append (gstring, klass->mod_separator);
766 g_string_append (gstring, "Mod4");
769 if (accelerator_mods & GDK_MOD5_MASK)
772 g_string_append (gstring, klass->mod_separator);
774 g_string_append (gstring, "Mod5");
777 if (accelerator_mods & GDK_SUPER_MASK)
780 g_string_append (gstring, klass->mod_separator);
782 /* This is the text that should appear next to menu accelerators
783 * that use the super key. If the text on this key isn't typically
784 * translated on keyboards used for your language, don't translate
787 g_string_append (gstring, C_("keyboard label", "Super"));
790 if (accelerator_mods & GDK_HYPER_MASK)
793 g_string_append (gstring, klass->mod_separator);
795 /* This is the text that should appear next to menu accelerators
796 * that use the hyper key. If the text on this key isn't typically
797 * translated on keyboards used for your language, don't translate
800 g_string_append (gstring, C_("keyboard label", "Hyper"));
803 if (accelerator_mods & GDK_META_MASK)
806 g_string_append (gstring, klass->mod_separator);
808 #ifndef GDK_WINDOWING_QUARTZ
809 /* This is the text that should appear next to menu accelerators
810 * that use the meta key. If the text on this key isn't typically
811 * translated on keyboards used for your language, don't translate
814 g_string_append (gstring, C_("keyboard label", "Meta"));
816 /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
817 g_string_append (gstring, "\xe2\x8c\x98");
822 g_string_append (gstring, klass->mod_separator);
824 ch = gdk_keyval_to_unicode (accelerator_key);
825 if (ch && ch < 0x80 && (g_unichar_isgraph (ch) || ch == ' '))
830 g_string_append (gstring, C_("keyboard label", "Space"));
833 g_string_append (gstring, C_("keyboard label", "Backslash"));
836 g_string_append_unichar (gstring, g_unichar_toupper (ch));
840 else if (!append_keyval_symbol (accelerator_key, gstring))
844 tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
847 if (tmp[0] != 0 && tmp[1] == 0)
848 g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
852 str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
854 append_without_underscores (gstring, tmp);
856 g_string_append (gstring, str);
861 return g_string_free (gstring, FALSE);
865 * gtk_accel_label_refetch:
866 * @accel_label: a #GtkAccelLabel.
868 * Recreates the string representing the accelerator keys.
869 * This should not be needed since the string is automatically updated whenever
870 * accelerators are added or removed from the associated widget.
872 * Returns: always returns %FALSE.
875 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
877 gboolean enable_accels;
879 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
881 if (accel_label->priv->accel_string)
883 g_free (accel_label->priv->accel_string);
884 accel_label->priv->accel_string = NULL;
887 g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
888 "gtk-enable-accels", &enable_accels,
891 if (enable_accels && accel_label->priv->accel_closure)
893 GtkAccelKey *key = gtk_accel_group_find (accel_label->priv->accel_group, find_accel, accel_label->priv->accel_closure);
895 if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
897 GtkAccelLabelClass *klass;
900 klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
901 tmp = _gtk_accel_label_class_get_accelerator_label (klass,
904 accel_label->priv->accel_string = g_strconcat (" ", tmp, NULL);
907 if (!accel_label->priv->accel_string)
908 accel_label->priv->accel_string = g_strdup ("-/-");
911 if (!accel_label->priv->accel_string)
912 accel_label->priv->accel_string = g_strdup ("");
914 gtk_widget_queue_resize (GTK_WIDGET (accel_label));