The Gtk.Menu_Item.Gtk_Menu_Item widget and the derived widgets are the only valid children for menus. Their function is to correctly handle highlighting, alignment, events and submenus.
As a GtkMenuItem derives from Gtk.Bin.Gtk_Bin it can hold any valid child widget, although only a few are really useful.
By default, a GtkMenuItem sets a Gtk.Accel_Label.Gtk_Accel_Label as its child. GtkMenuItem has direct functions to set the label and its mnemonic. For more advanced label settings, you can fetch the child widget from the GtkBin.
An example for setting markup and accelerator on a MenuItem:
GtkWidget *menu_item = gtk_menu_item_new_with_label ("Example Menu Item");
GtkWidget *child = gtk_bin_get_child (GTK_BIN (menu_item));
gtk_label_set_markup (GTK_LABEL (child), "<i>new label</i> with <b>markup</b>");
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (child), GDK_KEY_1, 0);
# GtkMenuItem as GtkBuildable
The GtkMenuItem implementation of the Gtk.Buildable.Gtk_Buildable interface supports adding a submenu by specifying "submenu" as the "type" attribute of a <child> element.
An example of UI definition fragment with submenus:
<object class="GtkMenuItem">
<child type="submenu">
<object class="GtkMenu"/>
</child>
</object>
# CSS nodes
menuitem
âââ <child>
â°ââ [arrow.right]
GtkMenuItem has a single CSS node with name menuitem. If the menuitem has a submenu, it gets another CSS node with name arrow, which has the .left or .right style class.
function "+"
(Widget : access Gtk_Menu_Item_Record'Class)
return Gtk.Actionable.Gtk_Actionable
function "+"
(Widget : access Gtk_Menu_Item_Record'Class)
return Gtk.Activatable.Gtk_Activatable
function "+"
(Widget : access Gtk_Menu_Item_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "-"
(Interf : Gtk.Actionable.Gtk_Actionable)
return Gtk_Menu_Item
function "-"
(Interf : Gtk.Activatable.Gtk_Activatable)
return Gtk_Menu_Item
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Menu_Item
Accel_Path_Property : constant Glib.Properties.Property_String;
Sets the accelerator path of the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persistant storage.
procedure Activate (Menu_Item : not null access Gtk_Menu_Item_Record)
Emits the Gtk.Menu_Item.Gtk_Menu_Item::activate signal on the given item
type Cb_GObject_Address_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class;
Object : System.Address);
type Cb_GObject_Gint_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class;
Object : Glib.Gint);
type Cb_GObject_Void is not null access procedure
(Self : access Glib.Object.GObject_Record'Class);
type Cb_Gtk_Menu_Item_Address_Void is not null access procedure
(Self : access Gtk_Menu_Item_Record'Class;
Object : System.Address);
type Cb_Gtk_Menu_Item_Gint_Void is not null access procedure
(Self : access Gtk_Menu_Item_Record'Class;
Object : Glib.Gint);
type Cb_Gtk_Menu_Item_Void is not null access procedure (Self : access Gtk_Menu_Item_Record'Class);
procedure Deselect (Menu_Item : not null access Gtk_Menu_Item_Record)
Emits the Gtk.Menu_Item.Gtk_Menu_Item::deselect signal on the given item.
procedure Do_Set_Related_Action
(Self : not null access Gtk_Menu_Item_Record;
Action : not null access Gtk.Action.Gtk_Action_Record'Class)
function Get_Accel_Path
(Menu_Item : not null access Gtk_Menu_Item_Record) return UTF8_String
Retrieve the accelerator path that was previously set on Menu_Item. See Gtk.Menu_Item.Set_Accel_Path for details. Since: gtk+ 2.14
the accelerator path corresponding to this menu item's functionality, or null if not set
function Get_Action_Name
(Self : not null access Gtk_Menu_Item_Record) return UTF8_String
function Get_Action_Target_Value
(Self : not null access Gtk_Menu_Item_Record)
return Glib.Variant.Gvariant
function Get_Label
(Menu_Item : not null access Gtk_Menu_Item_Record) return UTF8_String
Sets Text on the Menu_Item label Since: gtk+ 2.16
The text in the Menu_Item label. This is the internal string used by the label, and must not be modified.
function Get_Related_Action
(Self : not null access Gtk_Menu_Item_Record)
return Gtk.Action.Gtk_Action
function Get_Reserve_Indicator
(Menu_Item : not null access Gtk_Menu_Item_Record) return Boolean
Returns whether the Menu_Item reserves space for the submenu indicator, regardless if it has a submenu or not. Since: gtk+ 3.0
True if Menu_Item always reserves space for the submenu indicator
function Get_Right_Justified
(Menu_Item : not null access Gtk_Menu_Item_Record) return Boolean
Gets whether the menu item appears justified at the right side of the menu bar. Deprecated since 3.2, 1
True if the menu item will appear at the far right if added to a menu bar.
function Get_Submenu
(Menu_Item : not null access Gtk_Menu_Item_Record)
return Gtk.Widget.Gtk_Widget
Gets the submenu underneath this menu item, if any. See Gtk.Menu_Item.Set_Submenu.
submenu for this menu item, or null if none
function Get_Type return Glib.GType
function Get_Use_Action_Appearance
(Self : not null access Gtk_Menu_Item_Record) return Boolean
function Get_Use_Underline
(Menu_Item : not null access Gtk_Menu_Item_Record) return Boolean
Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key. Since: gtk+ 2.16
True if an embedded underline in the label indicates the mnemonic accelerator key.
type Gtk_Menu_Item is access all Gtk_Menu_Item_Record'Class;
function Gtk_Menu_Item_New return Gtk_Menu_Item
Creates a new Gtk.Menu_Item.Gtk_Menu_Item.
function Gtk_Menu_Item_New_With_Label
(Label : UTF8_String) return Gtk_Menu_Item
Creates a new Gtk.Menu_Item.Gtk_Menu_Item whose child is a Gtk.Label.Gtk_Label.
the text for the label
function Gtk_Menu_Item_New_With_Mnemonic
(Label : UTF8_String) return Gtk_Menu_Item
Creates a new Gtk.Menu_Item.Gtk_Menu_Item containing a label. The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the menu item.
The text of the button, with an underscore in front of the mnemonic character
type Gtk_Menu_Item_Record is new Gtk_Bin_Record with null record;
procedure Gtk_New (Menu_Item : out Gtk_Menu_Item)
Creates a new Gtk.Menu_Item.Gtk_Menu_Item. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
procedure Gtk_New
(Menu_Item : out Gtk_Menu_Item;
Label : UTF8_String)
For backwards compatibility.
procedure Gtk_New_With_Label
(Menu_Item : out Gtk_Menu_Item;
Label : UTF8_String)
Creates a new Gtk.Menu_Item.Gtk_Menu_Item whose child is a Gtk.Label.Gtk_Label. Initialize_With_Label does nothing if the object was already created with another call to Initialize* or G_New.
the text for the label
procedure Gtk_New_With_Mnemonic
(Menu_Item : out Gtk_Menu_Item;
Label : UTF8_String)
Creates a new Gtk.Menu_Item.Gtk_Menu_Item containing a label. The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the menu item. Initialize_With_Mnemonic does nothing if the object was already created with another call to Initialize* or G_New.
The text of the button, with an underscore in front of the mnemonic character
procedure Gtk_Select (Menu_Item : not null access Gtk_Menu_Item_Record)
Emits the Gtk.Menu_Item.Gtk_Menu_Item::select signal on the given item.
package Implements_Gtk_Actionable is new Glib.Types.Implements
(Gtk.Actionable.Gtk_Actionable, Gtk_Menu_Item_Record, Gtk_Menu_Item);
package Implements_Gtk_Activatable is new Glib.Types.Implements
(Gtk.Activatable.Gtk_Activatable, Gtk_Menu_Item_Record, Gtk_Menu_Item);
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_Menu_Item_Record, Gtk_Menu_Item);
procedure Initialize
(Menu_Item : access Gtk_Menu_Item_Record'Class;
Label : UTF8_String)
For backwards compatibility.
procedure Initialize
(Menu_Item : not null access Gtk_Menu_Item_Record'Class)
Creates a new Gtk.Menu_Item.Gtk_Menu_Item. Initialize does nothing if the object was already created with another call to Initialize* or G_New.
procedure Initialize_With_Label
(Menu_Item : not null access Gtk_Menu_Item_Record'Class;
Label : UTF8_String)
Creates a new Gtk.Menu_Item.Gtk_Menu_Item whose child is a Gtk.Label.Gtk_Label. Initialize_With_Label does nothing if the object was already created with another call to Initialize* or G_New.
the text for the label
procedure Initialize_With_Mnemonic
(Menu_Item : not null access Gtk_Menu_Item_Record'Class;
Label : UTF8_String)
Creates a new Gtk.Menu_Item.Gtk_Menu_Item containing a label. The label will be created using Gtk.Label.Gtk_New_With_Mnemonic, so underscores in Label indicate the mnemonic for the menu item. Initialize_With_Mnemonic does nothing if the object was already created with another call to Initialize* or G_New.
The text of the button, with an underscore in front of the mnemonic character
Label_Property : constant Glib.Properties.Property_String;
The text for the child label.
procedure On_Activate
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_GObject_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
Emitted when the item is activated.
procedure On_Activate
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_Gtk_Menu_Item_Void;
After : Boolean := False)
Emitted when the item is activated.
procedure On_Activate_Item
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_GObject_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is Gtk.Menu_Item.Gtk_Menu_Item::activate.
procedure On_Activate_Item
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_Gtk_Menu_Item_Void;
After : Boolean := False)
Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is Gtk.Menu_Item.Gtk_Menu_Item::activate.
procedure On_Deselect
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_GObject_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
procedure On_Deselect
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_Gtk_Menu_Item_Void;
After : Boolean := False)
procedure On_Select
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_GObject_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
procedure On_Select
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_Gtk_Menu_Item_Void;
After : Boolean := False)
procedure On_Toggle_Size_Allocate
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_GObject_Gint_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
procedure On_Toggle_Size_Allocate
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_Gtk_Menu_Item_Gint_Void;
After : Boolean := False)
procedure On_Toggle_Size_Request
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_GObject_Address_Void;
Slot : not null access Glib.Object.GObject_Record'Class;
After : Boolean := False)
procedure On_Toggle_Size_Request
(Self : not null access Gtk_Menu_Item_Record;
Call : Cb_Gtk_Menu_Item_Address_Void;
After : Boolean := False)
Right_Justified_Property : constant Glib.Properties.Property_Boolean;
Sets whether the menu item appears justified at the right side of a menu bar.
procedure Set_Accel_Path
(Menu_Item : not null access Gtk_Menu_Item_Record;
Accel_Path : UTF8_String := "")
Set the accelerator path on Menu_Item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persistent storage (see Gtk.Accel_Map.Save on this). To set up a default accelerator for this menu item, call Gtk.Accel_Map.Add_Entry with the same Accel_Path. See also Gtk.Accel_Map.Add_Entry on the specifics of accelerator paths, and Gtk.Menu.Set_Accel_Path for a more convenient variant of this function. This function is basically a convenience wrapper that handles calling Gtk.Widget.Set_Accel_Path with the appropriate accelerator group for the menu item. Note that you do need to set an accelerator on the parent menu with Gtk.Menu.Set_Accel_Group for this to work. Note that Accel_Path string will be stored in a Glib.GQuark. Therefore, if you pass a static string, you can save some memory by interning it first with g_intern_static_string.
accelerator path, corresponding to this menu item's functionality, or null to unset the current path.
procedure Set_Action_Name
(Self : not null access Gtk_Menu_Item_Record;
Action_Name : UTF8_String := "")
procedure Set_Action_Target_Value
(Self : not null access Gtk_Menu_Item_Record;
Target_Value : Glib.Variant.Gvariant)
procedure Set_Detailed_Action_Name
(Self : not null access Gtk_Menu_Item_Record;
Detailed_Action_Name : UTF8_String)
procedure Set_Label
(Menu_Item : not null access Gtk_Menu_Item_Record;
Label : UTF8_String)
Sets Text on the Menu_Item label Since: gtk+ 2.16
the text you want to set
procedure Set_Related_Action
(Self : not null access Gtk_Menu_Item_Record;
Action : not null access Gtk.Action.Gtk_Action_Record'Class)
procedure Set_Reserve_Indicator
(Menu_Item : not null access Gtk_Menu_Item_Record;
Reserve : Boolean)
Sets whether the Menu_Item should reserve space for the submenu indicator, regardless if it actually has a submenu or not. There should be little need for applications to call this functions. Since: gtk+ 3.0
the new value
procedure Set_Right_Justified
(Menu_Item : not null access Gtk_Menu_Item_Record;
Right_Justified : Boolean := True)
Sets whether the menu item appears justified at the right side of a menu bar. This was traditionally done for "Help" menu items, but is now considered a bad idea. (If the widget layout is reversed for a right-to-left language like Hebrew or Arabic, right-justified-menu-items appear at the left.) Deprecated since 3.2, 1
if True the menu item will appear at the far right if added to a menu bar
procedure Set_Submenu
(Menu_Item : not null access Gtk_Menu_Item_Record;
Submenu : access Gtk.Widget.Gtk_Widget_Record'Class)
Sets or replaces the menu item's submenu, or removes it when a null submenu is passed.
the submenu, or null
procedure Set_Use_Action_Appearance
(Self : not null access Gtk_Menu_Item_Record;
Use_Appearance : Boolean)
procedure Set_Use_Underline
(Menu_Item : not null access Gtk_Menu_Item_Record;
Setting : Boolean)
If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key. Since: gtk+ 2.16
True if underlines in the text indicate mnemonics
Signal_Activate : constant Glib.Signal_Name := "activate";
Emitted when the item is activated.
Signal_Activate_Item : constant Glib.Signal_Name := "activate-item";
Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is Gtk.Menu_Item.Gtk_Menu_Item::activate.
Signal_Deselect : constant Glib.Signal_Name := "deselect";
Signal_Select : constant Glib.Signal_Name := "select";
Signal_Toggle_Size_Allocate : constant Glib.Signal_Name := "toggle-size-allocate";
Signal_Toggle_Size_Request : constant Glib.Signal_Name := "toggle-size-request";
Submenu_Property : constant Glib.Properties.Property_Object;
Type: Gtk.Menu.Gtk_Menu The submenu attached to the menu item, or null if it has none.
procedure Sync_Action_Properties
(Self : not null access Gtk_Menu_Item_Record;
Action : access Gtk.Action.Gtk_Action_Record'Class)
procedure Toggle_Size_Allocate
(Menu_Item : not null access Gtk_Menu_Item_Record;
Allocation : Glib.Gint)
Emits the Gtk.Menu_Item.Gtk_Menu_Item::toggle-size-allocate signal on the given item.
the allocation to use as signal data.
procedure Toggle_Size_Request
(Menu_Item : not null access Gtk_Menu_Item_Record;
Requisition : in out Glib.Gint)
Emits the Gtk.Menu_Item.Gtk_Menu_Item::toggle-size-request signal on the given item.
the requisition to use as signal data.
Use_Underline_Property : constant Glib.Properties.Property_Boolean;
True if underlines in the text indicate mnemonics.