_
LabelThe Gtk_Accel_Label widget is a child of Gtk_Label that also displays an accelerator key on the right of the label text, e.g. 'Ctl+S'. It is commonly used in menus to show the keyboard short-cuts for commands.
The accelerator key to display is not set explicitly. Instead, the Gtk_Accel_Label displays the accelerators which have been added to a particular widget. This widget is set by calling Set_Accel_Widget.
For example, a Gtk_Menu_Item widget may have an accelerator added to emit the "activate" signal when the 'Ctl+S' key combination is pressed. A Gtk_Accel_Label is created and added to the Gtk_Menu_Item, and Set_Accel_Widget is called with the Gtk_Menu_Item as the second argument. The Gtk_Accel_Label will now display 'Ctl+S' after its label.
Note that creating a Gtk_Menu_Item with Gtk_New and a non null "label" parameter (ditto for Gtk_Check_Menu_Item and Gtk_Radio_Menu_Item) automatically adds a Gtk_Accel_Label to the Gtk_Menu_Item and calls Set_Accel_Widget to set it up for you.
A Gtk_Accel_Label will only display accelerators which have the Accel_Visible (see Gtk.Accel_Group) flag set. A Gtk_Accel_Label can display multiple accelerators and even signal names, though it is almost always used to display just one accelerator key.
Widget Hierarchy |
---|
GObject (see section Package Glib.Object)
Gtk_Object (see section Package Gtk.Object)
\___ Gtk_Widget (see section Package Gtk.Widget)
\___ Gtk_Misc (see section Package Gtk.Misc)
\___ Gtk_Label (see section Package Gtk.Label)
\___ Gtk_Accel_Label (see section Package Gtk.Accel
|
Subprograms |
---|
procedure Gtk_New (Accel_Label : out Gtk_Accel_Label; Str : UTF8_String); | ||
Create a new Gtk_Accel_Label. | ||
function Get_Type return Gtk.Gtk_Type; | ||
Return the internal value associated with a Gtk_Accel_Label.
| ||
function Get_Accel_Widget (Accel_Label : access Gtk_Accel_Label_Record) return Gtk.Widget.Gtk_Widget; | ||
Return the widget monitored by Accel_Label.
| ||
function Get_Accel_Width (Accel_Label : access Gtk_Accel_Label_Record) return Guint; | ||
Return the width needed to display the accelerator key(s). | ||
procedure Set_Accel_Widget (Accel_Label : access Gtk_Accel_Label_Record; Accel_Widget : access Gtk.Widget.Gtk_Widget_Record'Class); | ||
Add an accelerator to a particular widget.
| ||
function Refetch (Accel_Label : access Gtk_Accel_Label_Record) return Boolean; | ||
Recreate the string representing the accelerator keys. |
Example |
---|
Creating a simple menu item with an accelerator key. Save_Item : Gtk_Menu_Item; Accel_Group : Gtk_Accel_Group; -- Create a Gtk_Accel_Group and add it to the window. Gtk_New (Accel_Group); Add_Accel_Group (Window, Accel_Group); -- Create the menu item using the convenience function. Gtk_New (Save_Item, "Save"); Show (Save_Item); Add (Menu, Save_Item); -- Now add the accelerator to the Gtk_Menu_Item. Note that since we called -- Gtk_New with a label to create the Gtk_Menu_Item the -- Gtk_Accel_Label is automatically set up to display the Gtk_Menu_Item -- accelerators. We just need to make sure we use Accel_Visible here. Add_Accelerator (Save_Item, "activate", Accel_Group, GDK_S, Control_Mask, Accel_Visible);