1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 A label which displays an accelerator key on the right of the text
7 <!-- ##### SECTION Long_Description ##### -->
9 The #GtkAccelLabel widget is a subclass of #GtkLabel that also displays an
10 accelerator key on the right of the label text, e.g. 'Ctl+S'.
11 It is commonly used in menus to show the keyboard short-cuts for commands.
14 The accelerator key to display is not set explicitly.
15 Instead, the #GtkAccelLabel displays the accelerators which have been added to
16 a particular widget. This widget is set by calling
17 gtk_accel_label_set_accel_widget().
20 For example, a #GtkMenuItem widget may have an accelerator added to emit the
21 "activate" signal when the 'Ctl+S' key combination is pressed.
22 A #GtkAccelLabel is created and added to the #GtkMenuItem, and
23 gtk_accel_label_set_accel_widget() is called with the #GtkMenuItem as the
24 second argument. The #GtkAccelLabel will now display 'Ctl+S' after its label.
27 Note that creating a #GtkMenuItem with gtk_menu_item_new_with_label() (or
28 one of the similar functions for #GtkCheckMenuItem and #GtkRadioMenuItem)
29 automatically adds a #GtkAccelLabel to the #GtkMenuItem and calls
30 gtk_accel_label_set_accel_widget() to set it up for you.
33 A #GtkAccelLabel will only display accelerators which have %GTK_ACCEL_VISIBLE
34 set (see #GtkAccelFlags).
35 A #GtkAccelLabel can display multiple accelerators and even signal names,
36 though it is almost always used to display just one accelerator key.
40 <title>Creating a simple menu item with an accelerator key.</title>
43 GtkAccelGroup *accel_group;
45 /* Create a GtkAccelGroup and add it to the window. */
46 accel_group = gtk_accel_group_new (<!-- -->);
47 gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
49 /* Create the menu item using the convenience function. */
50 save_item = gtk_menu_item_new_with_label ("Save");
51 gtk_widget_show (save_item);
52 gtk_container_add (GTK_CONTAINER (menu), save_item);
54 /* Now add the accelerator to the GtkMenuItem. Note that since we called
55 gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the
56 GtkAccelLabel is automatically set up to display the GtkMenuItem
57 accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. */
58 gtk_widget_add_accelerator (save_item, "activate", accel_group,
59 GDK_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
63 <!-- ##### SECTION See_Also ##### -->
68 <term><link linkend="gtk-keyboard-accelerators">Keyboard Accelerators</link>
70 <listitem><para>installing and using keyboard short-cuts.</para></listitem>
74 <term>#GtkItemFactory</term>
75 <listitem><para>an easier way to create menus.</para></listitem>
81 <!-- ##### STRUCT GtkAccelLabel ##### -->
83 The #GtkAccelLabel-struct struct contains private data only, and
84 should be accessed using the functions below.
88 <!-- ##### ARG GtkAccelLabel:accel-closure ##### -->
93 <!-- ##### ARG GtkAccelLabel:accel-widget ##### -->
98 <!-- ##### FUNCTION gtk_accel_label_new ##### -->
100 Creates a new #GtkAccelLabel.
103 @string: the label string. Must be non-%NULL.
104 @Returns: a new #GtkAccelLabel.
107 <!-- ##### FUNCTION gtk_accel_label_set_accel_closure ##### -->
114 <!-- # Unused Parameters # -->
118 <!-- ##### FUNCTION gtk_accel_label_get_accel_widget ##### -->
127 <!-- ##### FUNCTION gtk_accel_label_set_accel_widget ##### -->
136 <!-- ##### FUNCTION gtk_accel_label_get_accel_width ##### -->
138 Returns the width needed to display the accelerator key(s).
139 This is used by menus to align all of the #GtkMenuItem widgets, and shouldn't
140 be needed by applications.
143 @accel_label: a #GtkAccelLabel.
144 @Returns: the width needed to display the accelerator key(s).
147 <!-- ##### FUNCTION gtk_accel_label_refetch ##### -->
149 Recreates the string representing the accelerator keys.
150 This should not be needed since the string is automatically updated whenever
151 accelerators are added or removed from the associated widget.
154 @accel_label: a #GtkAccelLabel.
155 @Returns: always returns %FALSE.