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 "gtkprivate.h"
39 #include <gdk/gdkkeysyms.h>
42 * SECTION:gtkaccellabel
43 * @Short_description: A label which displays an accelerator key on the right of the text
44 * @Title: GtkAccelLabel
45 * @See_also: #GtkItemFactory, #GtkAccelGroup
47 * The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
48 * accelerator key on the right of the label text, e.g. 'Ctl+S'.
49 * It is commonly used in menus to show the keyboard short-cuts for commands.
51 * The accelerator key to display is not set explicitly.
52 * Instead, the #GtkAccelLabel displays the accelerators which have been added to
53 * a particular widget. This widget is set by calling
54 * gtk_accel_label_set_accel_widget().
56 * For example, a #GtkMenuItem widget may have an accelerator added to emit the
57 * "activate" signal when the 'Ctl+S' key combination is pressed.
58 * A #GtkAccelLabel is created and added to the #GtkMenuItem, and
59 * gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
60 * second argument. The #GtkAccelLabel will now display 'Ctl+S' after its label.
62 * Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
63 * one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
64 * automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
65 * gtk_accel_label_set_accel_widget() to set it up for you.
67 * A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
68 * set (see #GtkAccelFlags).
69 * A #GtkAccelLabel can display multiple accelerators and even signal names,
70 * though it is almost always used to display just one accelerator key.
72 * <title>Creating a simple menu item with an accelerator key.</title>
74 * GtkWidget *save_item;
75 * GtkAccelGroup *accel_group;
77 * /<!---->* Create a GtkAccelGroup and add it to the window. *<!---->/
78 * accel_group = gtk_accel_group_new (<!-- -->);
79 * gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
81 * /<!---->* Create the menu item using the convenience function. *<!---->/
82 * save_item = gtk_menu_item_new_with_label ("Save");
83 * gtk_widget_show (save_item);
84 * gtk_container_add (GTK_CONTAINER (menu), save_item);
86 * /<!---->* Now add the accelerator to the GtkMenuItem. Note that since we called
87 * gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the
88 * GtkAccelLabel is automatically set up to display the GtkMenuItem
89 * accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. *<!---->/
90 * gtk_widget_add_accelerator (save_item, "activate", accel_group,
91 * GDK_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
102 static void gtk_accel_label_set_property (GObject *object,
106 static void gtk_accel_label_get_property (GObject *object,
110 static void gtk_accel_label_destroy (GtkObject *object);
111 static void gtk_accel_label_finalize (GObject *object);
112 static void gtk_accel_label_size_request (GtkWidget *widget,
113 GtkRequisition *requisition);
114 static gboolean gtk_accel_label_expose_event (GtkWidget *widget,
115 GdkEventExpose *event);
116 static const gchar *gtk_accel_label_get_string (GtkAccelLabel *accel_label);
119 G_DEFINE_TYPE (GtkAccelLabel, gtk_accel_label, GTK_TYPE_LABEL)
122 gtk_accel_label_class_init (GtkAccelLabelClass *class)
124 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
125 GtkObjectClass *object_class = GTK_OBJECT_CLASS (class);
126 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
128 gobject_class->finalize = gtk_accel_label_finalize;
129 gobject_class->set_property = gtk_accel_label_set_property;
130 gobject_class->get_property = gtk_accel_label_get_property;
132 object_class->destroy = gtk_accel_label_destroy;
134 widget_class->size_request = gtk_accel_label_size_request;
135 widget_class->expose_event = gtk_accel_label_expose_event;
137 class->signal_quote1 = g_strdup ("<:");
138 class->signal_quote2 = g_strdup (":>");
140 #ifndef GDK_WINDOWING_QUARTZ
141 /* This is the text that should appear next to menu accelerators
142 * that use the shift key. If the text on this key isn't typically
143 * translated on keyboards used for your language, don't translate
146 class->mod_name_shift = g_strdup (C_("keyboard label", "Shift"));
147 /* This is the text that should appear next to menu accelerators
148 * that use the control key. If the text on this key isn't typically
149 * translated on keyboards used for your language, don't translate
152 class->mod_name_control = g_strdup (C_("keyboard label", "Ctrl"));
153 /* This is the text that should appear next to menu accelerators
154 * that use the alt key. If the text on this key isn't typically
155 * translated on keyboards used for your language, don't translate
158 class->mod_name_alt = g_strdup (C_("keyboard label", "Alt"));
159 class->mod_separator = g_strdup ("+");
160 #else /* GDK_WINDOWING_QUARTZ */
162 /* U+21E7 UPWARDS WHITE ARROW */
163 class->mod_name_shift = g_strdup ("\xe2\x87\xa7");
164 /* U+2303 UP ARROWHEAD */
165 class->mod_name_control = g_strdup ("\xe2\x8c\x83");
166 /* U+2325 OPTION KEY */
167 class->mod_name_alt = g_strdup ("\xe2\x8c\xa5");
168 class->mod_separator = g_strdup ("");
170 #endif /* GDK_WINDOWING_QUARTZ */
172 class->accel_seperator = g_strdup (" / ");
173 class->latin1_to_char = TRUE;
175 g_object_class_install_property (gobject_class,
177 g_param_spec_boxed ("accel-closure",
178 P_("Accelerator Closure"),
179 P_("The closure to be monitored for accelerator changes"),
181 GTK_PARAM_READWRITE));
182 g_object_class_install_property (gobject_class,
184 g_param_spec_object ("accel-widget",
185 P_("Accelerator Widget"),
186 P_("The widget to be monitored for accelerator changes"),
188 GTK_PARAM_READWRITE));
192 gtk_accel_label_set_property (GObject *object,
197 GtkAccelLabel *accel_label;
199 accel_label = GTK_ACCEL_LABEL (object);
203 case PROP_ACCEL_CLOSURE:
204 gtk_accel_label_set_accel_closure (accel_label, g_value_get_boxed (value));
206 case PROP_ACCEL_WIDGET:
207 gtk_accel_label_set_accel_widget (accel_label, g_value_get_object (value));
210 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
216 gtk_accel_label_get_property (GObject *object,
221 GtkAccelLabel *accel_label;
223 accel_label = GTK_ACCEL_LABEL (object);
227 case PROP_ACCEL_CLOSURE:
228 g_value_set_boxed (value, accel_label->accel_closure);
230 case PROP_ACCEL_WIDGET:
231 g_value_set_object (value, accel_label->accel_widget);
234 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
240 gtk_accel_label_init (GtkAccelLabel *accel_label)
242 accel_label->accel_padding = 3;
243 accel_label->accel_widget = NULL;
244 accel_label->accel_closure = NULL;
245 accel_label->accel_group = NULL;
246 accel_label->accel_string = NULL;
250 * gtk_accel_label_new:
251 * @string: the label string. Must be non-%NULL.
253 * Creates a new #GtkAccelLabel.
255 * Returns: a new #GtkAccelLabel.
258 gtk_accel_label_new (const gchar *string)
260 GtkAccelLabel *accel_label;
262 g_return_val_if_fail (string != NULL, NULL);
264 accel_label = g_object_new (GTK_TYPE_ACCEL_LABEL, NULL);
266 gtk_label_set_text (GTK_LABEL (accel_label), string);
268 return GTK_WIDGET (accel_label);
272 gtk_accel_label_destroy (GtkObject *object)
274 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
276 gtk_accel_label_set_accel_widget (accel_label, NULL);
277 gtk_accel_label_set_accel_closure (accel_label, NULL);
279 GTK_OBJECT_CLASS (gtk_accel_label_parent_class)->destroy (object);
283 gtk_accel_label_finalize (GObject *object)
285 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (object);
287 g_free (accel_label->accel_string);
289 G_OBJECT_CLASS (gtk_accel_label_parent_class)->finalize (object);
293 * gtk_accel_label_get_accel_widget:
294 * @accel_label: a #GtkAccelLabel
296 * Fetches the widget monitored by this accelerator label. See
297 * gtk_accel_label_set_accel_widget().
299 * Returns: the object monitored by the accelerator label, or %NULL.
302 gtk_accel_label_get_accel_widget (GtkAccelLabel *accel_label)
304 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), NULL);
306 return accel_label->accel_widget;
310 * gtk_accel_label_get_accel_width:
311 * @accel_label: a #GtkAccelLabel.
313 * Returns the width needed to display the accelerator key(s).
314 * This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
315 * be needed by applications.
317 * Returns: the width needed to display the accelerator key(s).
320 gtk_accel_label_get_accel_width (GtkAccelLabel *accel_label)
322 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), 0);
324 return (accel_label->accel_string_width +
325 (accel_label->accel_string_width ? accel_label->accel_padding : 0));
329 gtk_accel_label_size_request (GtkWidget *widget,
330 GtkRequisition *requisition)
332 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
336 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->size_request (widget, requisition);
338 layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
339 pango_layout_get_pixel_size (layout, &width, NULL);
340 accel_label->accel_string_width = width;
342 g_object_unref (layout);
346 get_first_baseline (PangoLayout *layout)
348 PangoLayoutIter *iter;
351 iter = pango_layout_get_iter (layout);
352 result = pango_layout_iter_get_baseline (iter);
353 pango_layout_iter_free (iter);
355 return PANGO_PIXELS (result);
359 gtk_accel_label_expose_event (GtkWidget *widget,
360 GdkEventExpose *event)
362 GtkAccelLabel *accel_label = GTK_ACCEL_LABEL (widget);
363 GtkMisc *misc = GTK_MISC (accel_label);
364 GtkTextDirection direction;
366 direction = gtk_widget_get_direction (widget);
368 if (gtk_widget_is_drawable (widget))
372 ac_width = gtk_accel_label_get_accel_width (accel_label);
374 if (widget->allocation.width >= widget->requisition.width + ac_width)
376 PangoLayout *label_layout;
377 PangoLayout *accel_layout;
378 GtkLabel *label = GTK_LABEL (widget);
383 label_layout = gtk_label_get_layout (GTK_LABEL (accel_label));
385 if (direction == GTK_TEXT_DIR_RTL)
386 widget->allocation.x += ac_width;
387 widget->allocation.width -= ac_width;
388 if (gtk_label_get_ellipsize (label))
389 pango_layout_set_width (label_layout,
390 pango_layout_get_width (label_layout)
391 - ac_width * PANGO_SCALE);
393 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
394 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
395 if (direction == GTK_TEXT_DIR_RTL)
396 widget->allocation.x -= ac_width;
397 widget->allocation.width += ac_width;
398 if (gtk_label_get_ellipsize (label))
399 pango_layout_set_width (label_layout,
400 pango_layout_get_width (label_layout)
401 + ac_width * PANGO_SCALE);
403 if (direction == GTK_TEXT_DIR_RTL)
404 x = widget->allocation.x + misc->xpad;
406 x = widget->allocation.x + widget->allocation.width - misc->xpad - ac_width;
408 gtk_label_get_layout_offsets (GTK_LABEL (accel_label), NULL, &y);
410 accel_layout = gtk_widget_create_pango_layout (widget, gtk_accel_label_get_string (accel_label));
412 y += get_first_baseline (label_layout) - get_first_baseline (accel_layout);
414 gtk_paint_layout (widget->style,
416 gtk_widget_get_state (widget),
424 g_object_unref (accel_layout);
428 if (GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event)
429 GTK_WIDGET_CLASS (gtk_accel_label_parent_class)->expose_event (widget, event);
437 refetch_widget_accel_closure (GtkAccelLabel *accel_label)
439 GClosure *closure = NULL;
442 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
443 g_return_if_fail (GTK_IS_WIDGET (accel_label->accel_widget));
445 clist = gtk_widget_list_accel_closures (accel_label->accel_widget);
446 for (list = clist; list; list = list->next)
448 /* we just take the first closure used */
449 closure = list->data;
453 gtk_accel_label_set_accel_closure (accel_label, closure);
457 * gtk_accel_label_set_accel_widget:
458 * @accel_label: a #GtkAccelLabel
459 * @accel_widget: the widget to be monitored.
461 * Sets the widget to be monitored by this accelerator label.
464 gtk_accel_label_set_accel_widget (GtkAccelLabel *accel_label,
465 GtkWidget *accel_widget)
467 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
469 g_return_if_fail (GTK_IS_WIDGET (accel_widget));
471 if (accel_widget != accel_label->accel_widget)
473 if (accel_label->accel_widget)
475 gtk_accel_label_set_accel_closure (accel_label, NULL);
476 g_signal_handlers_disconnect_by_func (accel_label->accel_widget,
477 refetch_widget_accel_closure,
479 g_object_unref (accel_label->accel_widget);
481 accel_label->accel_widget = accel_widget;
482 if (accel_label->accel_widget)
484 g_object_ref (accel_label->accel_widget);
485 g_signal_connect_object (accel_label->accel_widget, "accel-closures-changed",
486 G_CALLBACK (refetch_widget_accel_closure),
487 accel_label, G_CONNECT_SWAPPED);
488 refetch_widget_accel_closure (accel_label);
490 g_object_notify (G_OBJECT (accel_label), "accel-widget");
495 gtk_accel_label_reset (GtkAccelLabel *accel_label)
497 if (accel_label->accel_string)
499 g_free (accel_label->accel_string);
500 accel_label->accel_string = NULL;
503 gtk_widget_queue_resize (GTK_WIDGET (accel_label));
507 check_accel_changed (GtkAccelGroup *accel_group,
509 GdkModifierType modifier,
510 GClosure *accel_closure,
511 GtkAccelLabel *accel_label)
513 if (accel_closure == accel_label->accel_closure)
514 gtk_accel_label_reset (accel_label);
518 * gtk_accel_label_set_accel_closure:
519 * @accel_label: a #GtkAccelLabel
520 * @accel_closure: the closure to monitor for accelerator changes.
522 * Sets the closure to be monitored by this accelerator label. The closure
523 * must be connected to an accelerator group; see gtk_accel_group_connect().
526 gtk_accel_label_set_accel_closure (GtkAccelLabel *accel_label,
527 GClosure *accel_closure)
529 g_return_if_fail (GTK_IS_ACCEL_LABEL (accel_label));
531 g_return_if_fail (gtk_accel_group_from_accel_closure (accel_closure) != NULL);
533 if (accel_closure != accel_label->accel_closure)
535 if (accel_label->accel_closure)
537 g_signal_handlers_disconnect_by_func (accel_label->accel_group,
540 accel_label->accel_group = NULL;
541 g_closure_unref (accel_label->accel_closure);
543 accel_label->accel_closure = accel_closure;
544 if (accel_label->accel_closure)
546 g_closure_ref (accel_label->accel_closure);
547 accel_label->accel_group = gtk_accel_group_from_accel_closure (accel_closure);
548 g_signal_connect_object (accel_label->accel_group, "accel-changed",
549 G_CALLBACK (check_accel_changed),
552 gtk_accel_label_reset (accel_label);
553 g_object_notify (G_OBJECT (accel_label), "accel-closure");
558 find_accel (GtkAccelKey *key,
562 return data == (gpointer) closure;
566 gtk_accel_label_get_string (GtkAccelLabel *accel_label)
568 if (!accel_label->accel_string)
569 gtk_accel_label_refetch (accel_label);
571 return accel_label->accel_string;
574 /* Underscores in key names are better displayed as spaces
575 * E.g., Page_Up should be "Page Up"
578 substitute_underscores (char *str)
582 for (p = str; *p; p++)
587 /* On Mac, if the key has symbolic representation (e.g. arrow keys),
588 * append it to gstring and return TRUE; otherwise return FALSE.
589 * See http://docs.info.apple.com/article.html?path=Mac/10.5/en/cdb_symbs.html
590 * for the list of special keys. */
592 append_keyval_symbol (guint accelerator_key,
595 #ifdef GDK_WINDOWING_QUARTZ
596 switch (accelerator_key)
599 /* U+21A9 LEFTWARDS ARROW WITH HOOK */
600 g_string_append (gstring, "\xe2\x86\xa9");
604 /* U+2324 UP ARROWHEAD BETWEEN TWO HORIZONTAL BARS */
605 g_string_append (gstring, "\xe2\x8c\xa4");
609 /* U+2190 LEFTWARDS ARROW */
610 g_string_append (gstring, "\xe2\x86\x90");
614 /* U+2191 UPWARDS ARROW */
615 g_string_append (gstring, "\xe2\x86\x91");
619 /* U+2192 RIGHTWARDS ARROW */
620 g_string_append (gstring, "\xe2\x86\x92");
624 /* U+2193 DOWNWARDS ARROW */
625 g_string_append (gstring, "\xe2\x86\x93");
629 /* U+21DE UPWARDS ARROW WITH DOUBLE STROKE */
630 g_string_append (gstring, "\xe2\x87\x9e");
634 /* U+21DF DOWNWARDS ARROW WITH DOUBLE STROKE */
635 g_string_append (gstring, "\xe2\x87\x9f");
639 /* U+2196 NORTH WEST ARROW */
640 g_string_append (gstring, "\xe2\x86\x96");
644 /* U+2198 SOUTH EAST ARROW */
645 g_string_append (gstring, "\xe2\x86\x98");
649 /* U+238B BROKEN CIRCLE WITH NORTHWEST ARROW */
650 g_string_append (gstring, "\xe2\x8e\x8b");
654 /* U+232B ERASE TO THE LEFT */
655 g_string_append (gstring, "\xe2\x8c\xab");
659 /* U+2326 ERASE TO THE RIGHT */
660 g_string_append (gstring, "\xe2\x8c\xa6");
666 #else /* !GDK_WINDOWING_QUARTZ */
672 _gtk_accel_label_class_get_accelerator_label (GtkAccelLabelClass *klass,
673 guint accelerator_key,
674 GdkModifierType accelerator_mods)
677 gboolean seen_mod = FALSE;
680 gstring = g_string_new ("");
682 if (accelerator_mods & GDK_SHIFT_MASK)
684 g_string_append (gstring, klass->mod_name_shift);
687 if (accelerator_mods & GDK_CONTROL_MASK)
690 g_string_append (gstring, klass->mod_separator);
691 g_string_append (gstring, klass->mod_name_control);
694 if (accelerator_mods & GDK_MOD1_MASK)
697 g_string_append (gstring, klass->mod_separator);
698 g_string_append (gstring, klass->mod_name_alt);
701 if (accelerator_mods & GDK_MOD2_MASK)
704 g_string_append (gstring, klass->mod_separator);
706 g_string_append (gstring, "Mod2");
709 if (accelerator_mods & GDK_MOD3_MASK)
712 g_string_append (gstring, klass->mod_separator);
714 g_string_append (gstring, "Mod3");
717 if (accelerator_mods & GDK_MOD4_MASK)
720 g_string_append (gstring, klass->mod_separator);
722 g_string_append (gstring, "Mod4");
725 if (accelerator_mods & GDK_MOD5_MASK)
728 g_string_append (gstring, klass->mod_separator);
730 g_string_append (gstring, "Mod5");
733 if (accelerator_mods & GDK_SUPER_MASK)
736 g_string_append (gstring, klass->mod_separator);
738 /* This is the text that should appear next to menu accelerators
739 * that use the super key. If the text on this key isn't typically
740 * translated on keyboards used for your language, don't translate
743 g_string_append (gstring, C_("keyboard label", "Super"));
746 if (accelerator_mods & GDK_HYPER_MASK)
749 g_string_append (gstring, klass->mod_separator);
751 /* This is the text that should appear next to menu accelerators
752 * that use the hyper key. If the text on this key isn't typically
753 * translated on keyboards used for your language, don't translate
756 g_string_append (gstring, C_("keyboard label", "Hyper"));
759 if (accelerator_mods & GDK_META_MASK)
762 g_string_append (gstring, klass->mod_separator);
764 #ifndef GDK_WINDOWING_QUARTZ
765 /* This is the text that should appear next to menu accelerators
766 * that use the meta key. If the text on this key isn't typically
767 * translated on keyboards used for your language, don't translate
770 g_string_append (gstring, C_("keyboard label", "Meta"));
772 /* Command key symbol U+2318 PLACE OF INTEREST SIGN */
773 g_string_append (gstring, "\xe2\x8c\x98");
778 g_string_append (gstring, klass->mod_separator);
780 ch = gdk_keyval_to_unicode (accelerator_key);
781 if (ch && (g_unichar_isgraph (ch) || ch == ' ') &&
782 (ch < 0x80 || klass->latin1_to_char))
787 g_string_append (gstring, C_("keyboard label", "Space"));
790 g_string_append (gstring, C_("keyboard label", "Backslash"));
793 g_string_append_unichar (gstring, g_unichar_toupper (ch));
797 else if (!append_keyval_symbol (accelerator_key, gstring))
801 tmp = gdk_keyval_name (gdk_keyval_to_lower (accelerator_key));
804 if (tmp[0] != 0 && tmp[1] == 0)
805 g_string_append_c (gstring, g_ascii_toupper (tmp[0]));
809 str = g_dpgettext2 (GETTEXT_PACKAGE, "keyboard label", tmp);
812 g_string_append (gstring, tmp);
813 substitute_underscores (gstring->str);
816 g_string_append (gstring, str);
821 return g_string_free (gstring, FALSE);
825 * gtk_accel_label_refetch:
826 * @accel_label: a #GtkAccelLabel.
828 * Recreates the string representing the accelerator keys.
829 * This should not be needed since the string is automatically updated whenever
830 * accelerators are added or removed from the associated widget.
832 * Returns: always returns %FALSE.
835 gtk_accel_label_refetch (GtkAccelLabel *accel_label)
837 gboolean enable_accels;
839 g_return_val_if_fail (GTK_IS_ACCEL_LABEL (accel_label), FALSE);
841 if (accel_label->accel_string)
843 g_free (accel_label->accel_string);
844 accel_label->accel_string = NULL;
847 g_object_get (gtk_widget_get_settings (GTK_WIDGET (accel_label)),
848 "gtk-enable-accels", &enable_accels,
851 if (enable_accels && accel_label->accel_closure)
853 GtkAccelKey *key = gtk_accel_group_find (accel_label->accel_group, find_accel, accel_label->accel_closure);
855 if (key && key->accel_flags & GTK_ACCEL_VISIBLE)
857 GtkAccelLabelClass *klass;
860 klass = GTK_ACCEL_LABEL_GET_CLASS (accel_label);
861 tmp = _gtk_accel_label_class_get_accelerator_label (klass,
864 accel_label->accel_string = g_strconcat (" ", tmp, NULL);
867 if (!accel_label->accel_string)
868 accel_label->accel_string = g_strdup ("-/-");
871 if (!accel_label->accel_string)
872 accel_label->accel_string = g_strdup ("");
874 gtk_widget_queue_resize (GTK_WIDGET (accel_label));
879 #define __GTK_ACCEL_LABEL_C__
880 #include "gtkaliasdef.c"