Gtk.Menu_Item

Entities

Tagged Types

Access Types

Constants

Subprograms

Generic Instantiations

Description

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
Parameters
Widget
Return Value

"+"

function "+"
  (Widget : access Gtk_Menu_Item_Record'Class)
return Gtk.Activatable.Gtk_Activatable
Parameters
Widget
Return Value

"+"

function "+"
  (Widget : access Gtk_Menu_Item_Record'Class)
return Gtk.Buildable.Gtk_Buildable
Parameters
Widget
Return Value

"-"

function "-"
  (Interf : Gtk.Actionable.Gtk_Actionable)
return Gtk_Menu_Item
Parameters
Interf
Return Value

"-"

function "-"
  (Interf : Gtk.Activatable.Gtk_Activatable)
return Gtk_Menu_Item
Parameters
Interf
Return Value

"-"

function "-"
  (Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Menu_Item
Parameters
Interf
Return Value

Accel_Path_Property

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.

Activate

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

Parameters
Menu_Item

Cb_GObject_Address_Void

type Cb_GObject_Address_Void is not null access procedure
  (Self   : access Glib.Object.GObject_Record'Class;
   Object : System.Address);
Parameters
Self
Object

Cb_GObject_Gint_Void

type Cb_GObject_Gint_Void is not null access procedure
  (Self   : access Glib.Object.GObject_Record'Class;
   Object : Glib.Gint);
Parameters
Self
Object

Cb_GObject_Void

type Cb_GObject_Void is not null access procedure
  (Self : access Glib.Object.GObject_Record'Class);
Parameters
Self

Cb_Gtk_Menu_Item_Address_Void

type Cb_Gtk_Menu_Item_Address_Void is not null access procedure
  (Self   : access Gtk_Menu_Item_Record'Class;
   Object : System.Address);
Parameters
Self
Object

Cb_Gtk_Menu_Item_Gint_Void

type Cb_Gtk_Menu_Item_Gint_Void is not null access procedure
  (Self   : access Gtk_Menu_Item_Record'Class;
   Object : Glib.Gint);
Parameters
Self
Object

Cb_Gtk_Menu_Item_Void

type Cb_Gtk_Menu_Item_Void is not null access procedure (Self : access Gtk_Menu_Item_Record'Class);
Parameters
Self

Deselect

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.

Parameters
Menu_Item

Do_Set_Related_Action

procedure Do_Set_Related_Action
   (Self   : not null access Gtk_Menu_Item_Record;
    Action : not null access Gtk.Action.Gtk_Action_Record'Class)
Parameters
Self
Action

Get_Accel_Path

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

Parameters
Menu_Item
Return Value

the accelerator path corresponding to this menu item's functionality, or null if not set

Get_Action_Name

function Get_Action_Name
   (Self : not null access Gtk_Menu_Item_Record) return UTF8_String
Parameters
Self
Return Value

Get_Action_Target_Value

function Get_Action_Target_Value
   (Self : not null access Gtk_Menu_Item_Record)
    return Glib.Variant.Gvariant
Parameters
Self
Return Value

Get_Label

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

Parameters
Menu_Item
Return Value

The text in the Menu_Item label. This is the internal string used by the label, and must not be modified.

Get_Related_Action

function Get_Related_Action
   (Self : not null access Gtk_Menu_Item_Record)
    return Gtk.Action.Gtk_Action
Parameters
Self
Return Value

Get_Reserve_Indicator

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

Parameters
Menu_Item
Return Value

True if Menu_Item always reserves space for the submenu indicator

Get_Right_Justified

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

Parameters
Menu_Item
Return Value

True if the menu item will appear at the far right if added to a menu bar.

Get_Submenu

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.

Parameters
Menu_Item
Return Value

submenu for this menu item, or null if none

Get_Type

function Get_Type return Glib.GType
Return Value

Get_Use_Action_Appearance

function Get_Use_Action_Appearance
   (Self : not null access Gtk_Menu_Item_Record) return Boolean
Parameters
Self
Return Value

Get_Use_Underline

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

Parameters
Menu_Item
Return Value

True if an embedded underline in the label indicates the mnemonic accelerator key.

Gtk_Menu_Item

type Gtk_Menu_Item is access all Gtk_Menu_Item_Record'Class;

Gtk_Menu_Item_New

function Gtk_Menu_Item_New return Gtk_Menu_Item

Creates a new Gtk.Menu_Item.Gtk_Menu_Item.

Return Value

Gtk_Menu_Item_New_With_Label

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.

Parameters
Label

the text for the label

Return Value

Gtk_Menu_Item_New_With_Mnemonic

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.

Parameters
Label

The text of the button, with an underscore in front of the mnemonic character

Return Value

Gtk_Menu_Item_Record

type Gtk_Menu_Item_Record is new Gtk_Bin_Record with null record;

Gtk_New

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.

Parameters
Menu_Item

Gtk_New

procedure Gtk_New
  (Menu_Item : out Gtk_Menu_Item;
   Label     : UTF8_String)

For backwards compatibility.

Parameters
Menu_Item
Label

Gtk_New_With_Label

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.

Parameters
Menu_Item
Label

the text for the label

Gtk_New_With_Mnemonic

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.

Parameters
Menu_Item
Label

The text of the button, with an underscore in front of the mnemonic character

Gtk_Select

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.

Parameters
Menu_Item

Implements_Gtk_Actionable

package Implements_Gtk_Actionable is new Glib.Types.Implements
  (Gtk.Actionable.Gtk_Actionable, Gtk_Menu_Item_Record, Gtk_Menu_Item);

Implements_Gtk_Activatable

package Implements_Gtk_Activatable is new Glib.Types.Implements
  (Gtk.Activatable.Gtk_Activatable, Gtk_Menu_Item_Record, Gtk_Menu_Item);

Implements_Gtk_Buildable

package Implements_Gtk_Buildable is new Glib.Types.Implements
  (Gtk.Buildable.Gtk_Buildable, Gtk_Menu_Item_Record, Gtk_Menu_Item);

Initialize

procedure Initialize
  (Menu_Item : access Gtk_Menu_Item_Record'Class;
   Label     : UTF8_String)

For backwards compatibility.

Parameters
Menu_Item
Label

Initialize

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.

Parameters
Menu_Item

Initialize_With_Label

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.

Parameters
Menu_Item
Label

the text for the label

Initialize_With_Mnemonic

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.

Parameters
Menu_Item
Label

The text of the button, with an underscore in front of the mnemonic character

Label_Property

Label_Property : constant Glib.Properties.Property_String;

The text for the child label.

On_Activate

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.

Parameters
Self
Call
Slot
After

On_Activate

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.

Parameters
Self
Call
After

On_Activate_Item

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.

Parameters
Self
Call
Slot
After

On_Activate_Item

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.

Parameters
Self
Call
After

On_Deselect

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)
Parameters
Self
Call
Slot
After

On_Deselect

procedure On_Deselect
   (Self  : not null access Gtk_Menu_Item_Record;
    Call  : Cb_Gtk_Menu_Item_Void;
    After : Boolean := False)
Parameters
Self
Call
After

On_Select

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)
Parameters
Self
Call
Slot
After

On_Select

procedure On_Select
   (Self  : not null access Gtk_Menu_Item_Record;
    Call  : Cb_Gtk_Menu_Item_Void;
    After : Boolean := False)
Parameters
Self
Call
After

On_Toggle_Size_Allocate

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)
Parameters
Self
Call
Slot
After

On_Toggle_Size_Allocate

procedure On_Toggle_Size_Allocate
   (Self  : not null access Gtk_Menu_Item_Record;
    Call  : Cb_Gtk_Menu_Item_Gint_Void;
    After : Boolean := False)
Parameters
Self
Call
After

On_Toggle_Size_Request

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)
Parameters
Self
Call
Slot
After

On_Toggle_Size_Request

procedure On_Toggle_Size_Request
   (Self  : not null access Gtk_Menu_Item_Record;
    Call  : Cb_Gtk_Menu_Item_Address_Void;
    After : Boolean := False)
Parameters
Self
Call
After

Right_Justified_Property

Right_Justified_Property : constant Glib.Properties.Property_Boolean;

Sets whether the menu item appears justified at the right side of a menu bar.

Set_Accel_Path

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.

Parameters
Menu_Item
Accel_Path

accelerator path, corresponding to this menu item's functionality, or null to unset the current path.

Set_Action_Name

procedure Set_Action_Name
   (Self        : not null access Gtk_Menu_Item_Record;
    Action_Name : UTF8_String := "")
Parameters
Self
Action_Name

Set_Action_Target_Value

procedure Set_Action_Target_Value
   (Self         : not null access Gtk_Menu_Item_Record;
    Target_Value : Glib.Variant.Gvariant)
Parameters
Self
Target_Value

Set_Detailed_Action_Name

procedure Set_Detailed_Action_Name
   (Self                 : not null access Gtk_Menu_Item_Record;
    Detailed_Action_Name : UTF8_String)
Parameters
Self
Detailed_Action_Name

Set_Label

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

Parameters
Menu_Item
Label

the text you want to set

Set_Related_Action

procedure Set_Related_Action
   (Self   : not null access Gtk_Menu_Item_Record;
    Action : not null access Gtk.Action.Gtk_Action_Record'Class)
Parameters
Self
Action

Set_Reserve_Indicator

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

Parameters
Menu_Item
Reserve

the new value

Set_Right_Justified

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

Parameters
Menu_Item
Right_Justified

if True the menu item will appear at the far right if added to a menu bar

Set_Submenu

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.

Parameters
Menu_Item
Submenu

the submenu, or null

Set_Use_Action_Appearance

procedure Set_Use_Action_Appearance
   (Self           : not null access Gtk_Menu_Item_Record;
    Use_Appearance : Boolean)
Parameters
Self
Use_Appearance

Set_Use_Underline

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

Parameters
Menu_Item
Setting

True if underlines in the text indicate mnemonics

Signal_Activate

Signal_Activate : constant Glib.Signal_Name := "activate";

Emitted when the item is activated.

Signal_Activate_Item

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

Signal_Deselect : constant Glib.Signal_Name := "deselect";

Signal_Select

Signal_Select : constant Glib.Signal_Name := "select";

Signal_Toggle_Size_Allocate

Signal_Toggle_Size_Allocate : constant Glib.Signal_Name := "toggle-size-allocate";

Signal_Toggle_Size_Request

Signal_Toggle_Size_Request : constant Glib.Signal_Name := "toggle-size-request";

Submenu_Property

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.

Sync_Action_Properties

procedure Sync_Action_Properties
   (Self   : not null access Gtk_Menu_Item_Record;
    Action : access Gtk.Action.Gtk_Action_Record'Class)
Parameters
Self
Action

Toggle_Size_Allocate

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.

Parameters
Menu_Item
Allocation

the allocation to use as signal data.

Toggle_Size_Request

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.

Parameters
Menu_Item
Requisition

the requisition to use as signal data.

Use_Underline_Property

Use_Underline_Property : constant Glib.Properties.Property_Boolean;

True if underlines in the text indicate mnemonics.