MenuItem

The #GtkMenuItem 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 #GtkBin it can hold any valid child widget, although only a few are really useful.

By default, a GtkMenuItem sets a #GtkAccelLabel 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: |[<!-- language="C" --> 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 #GtkBuildable 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

|[<!-- language="plain" --> 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.

class MenuItem : Bin , ActionableIF , ActivatableIF {}

Constructors

this
this(GtkMenuItem* gtkMenuItem, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this(string label, void delegate(MenuItem) dlg, string action)

Creates a new menu item with a label and a listener and a action. used for backward compatibily with DUI.

this
this(void delegate(MenuItem) dlg, string label, string action, bool mnemonic, AccelGroup accelGroup, char accelKey, GdkModifierType modifierType, GtkAccelFlags accelFlags)

Creates a new Item associated with a "activate" delegate and with a action code and optionally accelGroup

this
this(void delegate(MenuItem) dlg, string label, bool mnemonic)

Creates a new Item associated with a "activate" delegate

this
this(string label, bool mnemonic)

Creates a new GtkMenuItem whose child is a GtkLabel.

this
this()

Creates a new #GtkMenuItem.

Members

Functions

addOnActivate
gulong addOnActivate(void delegate(MenuItem) dlg, ConnectFlags connectFlags)

Emitted when the item is activated.

addOnActivateItem
gulong addOnActivateItem(void delegate(MenuItem) dlg, ConnectFlags connectFlags)

Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is #GtkMenuItem::activate.

addOnDeselect
gulong addOnDeselect(void delegate(MenuItem) dlg, ConnectFlags connectFlags)
addOnSelect
gulong addOnSelect(void delegate(MenuItem) dlg, ConnectFlags connectFlags)
addOnToggleSizeAllocate
gulong addOnToggleSizeAllocate(void delegate(int, MenuItem) dlg, ConnectFlags connectFlags)
addOnToggleSizeRequest
gulong addOnToggleSizeRequest(void delegate(void*, MenuItem) dlg, ConnectFlags connectFlags)
deselect
void deselect()

Emits the #GtkMenuItem::deselect signal on the given item.

getAccelPath
string getAccelPath()

Retrieve the accelerator path that was previously set on @menu_item.

getActionName
string getActionName()

Gets the application set action code

getLabel
string getLabel()

Sets @text on the @menu_item label

getMenuItemStruct
GtkMenuItem* getMenuItemStruct(bool transferOwnership)

Get the main Gtk struct

getReserveIndicator
bool getReserveIndicator()

Returns whether the @menu_item reserves space for the submenu indicator, regardless if it has a submenu or not.

getRightJustified
bool getRightJustified()

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

getStruct
void* getStruct()

the main Gtk struct as a void*

getSubmenu
Widget getSubmenu()

Gets the submenu underneath this menu item, if any. See gtk_menu_item_set_submenu().

getUseUnderline
bool getUseUnderline()

Checks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.

itemActivate
void itemActivate()

Emits the #GtkMenuItem::activate signal on the given item

select
void select()

Emits the #GtkMenuItem::select signal on the given item.

setAccelPath
void setAccelPath(string accelPath)

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.

setLabel
void setLabel(string label)

Sets @text on the @menu_item label

setReserveIndicator
void setReserveIndicator(bool reserve)

Sets whether the @menu_item should reserve space for the submenu indicator, regardless if it actually has a submenu or not.

setRightJustified
void setRightJustified(bool rightJustified)

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.)

setSubmenu
void setSubmenu(Menu submenu)

Sets or replaces the menu item’s submenu, or removes it when a %NULL submenu is passed.

setUseUnderline
void setUseUnderline(bool setting)

If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.

toggleSizeAllocate
void toggleSizeAllocate(int allocation)

Emits the #GtkMenuItem::toggle-size-allocate signal on the given item.

toggleSizeRequest
void toggleSizeRequest(int requisition)

Emits the #GtkMenuItem::toggle-size-request signal on the given item.

Mixins

__anonymous
mixin ActionableT!(GtkMenuItem)
Undocumented in source.
__anonymous
mixin ActivatableT!(GtkMenuItem)
Undocumented in source.

Static functions

getType
GType getType()

Variables

gtkMenuItem
GtkMenuItem* gtkMenuItem;

the main Gtk struct

Inherited Members

From Bin

gtkBin
GtkBin* gtkBin;

the main Gtk struct

getBinStruct
GtkBin* getBinStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
getChild
Widget getChild()

Gets the child of the #GtkBin, or %NULL if the bin contains no child widget. The returned widget does not have a reference added, so you do not need to unref it.

From ActionableIF

getActionableStruct
GtkActionable* getActionableStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
getActionName
string getActionName()

Gets the action name for @actionable.

getActionTargetValue
Variant getActionTargetValue()

Gets the current target value of @actionable.

setActionName
void setActionName(string actionName)

Specifies the name of the action with which this widget should be associated. If @action_name is %NULL then the widget will be unassociated from any previous action.

setActionTargetValue
void setActionTargetValue(Variant targetValue)

Sets the target value of an actionable widget.

setDetailedActionName
void setDetailedActionName(string detailedActionName)

Sets the action-name and associated string target value of an actionable widget.

From ActivatableIF

getActivatableStruct
GtkActivatable* getActivatableStruct(bool transferOwnership)

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

getType
GType getType()
doSetRelatedAction
void doSetRelatedAction(Action action)

This is a utility function for #GtkActivatable implementors.

getRelatedAction
Action getRelatedAction()

Gets the related #GtkAction for @activatable.

getUseActionAppearance
bool getUseActionAppearance()

Gets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance.

setRelatedAction
void setRelatedAction(Action action)

Sets the related action on the @activatable object.

setUseActionAppearance
void setUseActionAppearance(bool useAppearance)

Sets whether this activatable should reset its layout and appearance when setting the related action or when the action changes appearance

syncActionProperties
void syncActionProperties(Action action)

This is called to update the activatable completely, this is called internally when the #GtkActivatable:related-action property is set or unset and by the implementing class when #GtkActivatable:use-action-appearance changes.

Meta