MenuItemProtocol
public protocol MenuItemProtocol : ActionableProtocol, ActivatableProtocol, BinProtocol
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: (C Language Example):
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
(plain Language Example):
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.
The MenuItemProtocol protocol exposes the methods and properties of an underlying GtkMenuItem instance.
The default implementation of these can be found in the protocol extension below.
For a concrete class that implements these methods and properties, see MenuItem.
Alternatively, use MenuItemRef as a lighweight, unowned reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkMenuIteminstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
menu_item_ptrDefault implementationTyped pointer to the underlying
GtkMenuIteminstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkMenuIteminstance.Declaration
Swift
var menu_item_ptr: UnsafeMutablePointer<GtkMenuItem>! { get } -
Required Initialiser for types conforming to
MenuItemProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
MenuItemPropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: MenuItemPropertyName, to target: T, _ target_property: Q, flags f: BindingFlags = .default, transformFrom transform_from: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }, transformTo transform_to: @escaping GLibObject.ValueTransformer = { $0.transform(destValue: $1) }) -> BindingRef! where Q : PropertyNameProtocol, T : ObjectProtocolParameters
source_propertythe source property to bind
targetthe target object to bind to
target_propertythe target property to bind to
flagsthe flags to pass to the
Bindingtransform_fromValueTransformerto use for forward transformationtransform_toValueTransformerto use for backwards transformationReturn Value
binding reference or
nilin case of an error -
get(property:Extension method) Get the value of a MenuItem property
Declaration
Swift
@inlinable func get(property: MenuItemPropertyName) -> GLibObject.ValueParameters
propertythe property to get the value for
Return Value
the value of the named property
-
set(property:Extension methodvalue: ) Set the value of a MenuItem property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: MenuItemPropertyName, value v: GLibObject.Value)Parameters
propertythe property to get the value for
Return Value
the value of the named property
-
connect(signal:Extension methodflags: handler: ) Connect a Swift signal handler to the given, typed
MenuItemSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: MenuItemSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatahandlerThe Swift signal handler (function or callback) to invoke on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
connect(signal:Extension methodflags: data: destroyData: signalHandler: ) Connect a C signal handler to the given, typed
MenuItemSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: MenuItemSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> IntParameters
signalThe signal to connect
flagsThe connection flags to use
dataA pointer to user data to provide to the callback
destroyDataA
GClosureNotifyC function to destroy the data pointed to byuserDatasignalHandlerThe C function to be called on the given signal
Return Value
The signal handler ID (always greater than 0 for successful connections)
-
toggleSizeRequestSignalExtension methodNote
This represents the underlyingtoggle-size-requestsignalWarning
aonToggleSizeRequestwrapper for this signal could not be generated because it contains unimplemented features: { (4) gpointer argument is not yet supported }Note
Instead, you can connecttoggleSizeRequestSignalusing theconnect(signal:)methodsDeclaration
Swift
static var toggleSizeRequestSignal: MenuItemSignalName { get }Parameters
flagsFlags
unownedSelfReference to instance of self
objectnone
handlerThe signal handler to call
-
onActivate(flags:Extension methodhandler: ) Emitted when the item is activated.
Note
This represents the underlyingactivatesignalDeclaration
Swift
@discardableResult @inlinable func onActivate(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
activatesignal is emitted -
activateSignalExtension methodTyped
activatesignal for using theconnect(signal:)methodsDeclaration
Swift
static var activateSignal: MenuItemSignalName { get } -
onActivateItem(flags:Extension methodhandler: ) Emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is
GtkMenuItem::activate.Note
This represents the underlyingactivate-itemsignalDeclaration
Swift
@discardableResult @inlinable func onActivateItem(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
activateItemsignal is emitted -
activateItemSignalExtension methodTyped
activate-itemsignal for using theconnect(signal:)methodsDeclaration
Swift
static var activateItemSignal: MenuItemSignalName { get } -
onDeselect(flags:Extension methodhandler: ) Note
This represents the underlyingdeselectsignalDeclaration
Swift
@discardableResult @inlinable func onDeselect(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
deselectsignal is emitted -
deselectSignalExtension methodTyped
deselectsignal for using theconnect(signal:)methodsDeclaration
Swift
static var deselectSignal: MenuItemSignalName { get } -
onSelect(flags:Extension methodhandler: ) Note
This represents the underlyingselectsignalDeclaration
Swift
@discardableResult @inlinable func onSelect(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
selectsignal is emitted -
selectSignalExtension methodTyped
selectsignal for using theconnect(signal:)methodsDeclaration
Swift
static var selectSignal: MenuItemSignalName { get } -
onToggleSizeAllocate(flags:Extension methodhandler: ) Note
This represents the underlyingtoggle-size-allocatesignalDeclaration
Swift
@discardableResult @inlinable func onToggleSizeAllocate(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef, _ object: Int) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
objectnone
handlerThe signal handler to call Run the given callback whenever the
toggleSizeAllocatesignal is emitted -
toggleSizeAllocateSignalExtension methodTyped
toggle-size-allocatesignal for using theconnect(signal:)methodsDeclaration
Swift
static var toggleSizeAllocateSignal: MenuItemSignalName { get } -
onNotifyAccelPath(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::accel-pathsignalDeclaration
Swift
@discardableResult @inlinable func onNotifyAccelPath(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyAccelPathsignal is emitted -
notifyAccelPathSignalExtension methodTyped
notify::accel-pathsignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyAccelPathSignal: MenuItemSignalName { get } -
onNotifyLabel(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::labelsignalDeclaration
Swift
@discardableResult @inlinable func onNotifyLabel(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyLabelsignal is emitted -
notifyLabelSignalExtension methodTyped
notify::labelsignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyLabelSignal: MenuItemSignalName { get } -
onNotifyRightJustified(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::right-justifiedsignalDeclaration
Swift
@discardableResult @inlinable func onNotifyRightJustified(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyRightJustifiedsignal is emitted -
notifyRightJustifiedSignalExtension methodTyped
notify::right-justifiedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyRightJustifiedSignal: MenuItemSignalName { get } -
onNotifySubmenu(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::submenusignalDeclaration
Swift
@discardableResult @inlinable func onNotifySubmenu(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifySubmenusignal is emitted -
notifySubmenuSignalExtension methodTyped
notify::submenusignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifySubmenuSignal: MenuItemSignalName { get } -
onNotifyUseUnderline(flags:Extension methodhandler: ) The notify signal is emitted on an object when one of its properties has its value set through
g_object_set_property(),g_object_set(), et al.Note that getting this signal doesn’t itself guarantee that the value of the property has actually changed. When it is emitted is determined by the derived GObject class. If the implementor did not create the property with
G_PARAM_EXPLICIT_NOTIFY, then any call tog_object_set_property()results innotifybeing emitted, even if the new value is the same as the old. If they did passG_PARAM_EXPLICIT_NOTIFY, then this signal is emitted only when they explicitly callg_object_notify()org_object_notify_by_pspec(), and common practice is to do that only when the value has actually changed.This signal is typically used to obtain change notification for a single property, by specifying the property name as a detail in the
g_signal_connect()call, like this:(C Language Example):
g_signal_connect (text_view->buffer, "notify::paste-target-list", G_CALLBACK (gtk_text_view_target_list_notify), text_view)It is important to note that you must use canonical parameter names as detail strings for the notify signal.
Note
This represents the underlyingnotify::use-underlinesignalDeclaration
Swift
@discardableResult @inlinable func onNotifyUseUnderline(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuItemRef, _ pspec: ParamSpecRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
pspecthe
GParamSpecof the property which changed.handlerThe signal handler to call Run the given callback whenever the
notifyUseUnderlinesignal is emitted -
notifyUseUnderlineSignalExtension methodTyped
notify::use-underlinesignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyUseUnderlineSignal: MenuItemSignalName { get }
-
activate()Extension methodEmits the
GtkMenuItem::activatesignal on the given itemDeclaration
Swift
@inlinable func activate() -
deselect()Extension methodEmits the
GtkMenuItem::deselectsignal on the given item.Declaration
Swift
@inlinable func deselect() -
getAccelPath()Extension methodRetrieve the accelerator path that was previously set on
menu_item.See
gtk_menu_item_set_accel_path()for details.Declaration
Swift
@inlinable func getAccelPath() -> String! -
getLabel()Extension methodSets
texton themenu_itemlabelDeclaration
Swift
@inlinable func getLabel() -> String! -
getReserveIndicator()Extension methodReturns whether the
menu_itemreserves space for the submenu indicator, regardless if it has a submenu or not.Declaration
Swift
@inlinable func getReserveIndicator() -> Bool -
getRightJustified()Extension methodGets whether the menu item appears justified at the right side of the menu bar.
get_right_justified is deprecated: See gtk_menu_item_set_right_justified()
Declaration
Swift
@available(*, deprecated) @inlinable func getRightJustified() -> Bool -
getSubmenu()Extension methodGets the submenu underneath this menu item, if any. See
gtk_menu_item_set_submenu().Declaration
Swift
@inlinable func getSubmenu() -> WidgetRef! -
getUseUnderline()Extension methodChecks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Declaration
Swift
@inlinable func getUseUnderline() -> Bool -
select()Extension methodEmits the
GtkMenuItem::selectsignal on the given item.Declaration
Swift
@inlinable func select() -
set(accelPath:Extension method) 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 (seegtk_accel_map_save()on this). To set up a default accelerator for this menu item, callgtk_accel_map_add_entry()with the sameaccel_path. See alsogtk_accel_map_add_entry()on the specifics of accelerator paths, andgtk_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_pathstring will be stored in aGQuark. Therefore, if you pass a static string, you can save some memory by interning it first withg_intern_static_string().Declaration
Swift
@inlinable func set(accelPath: UnsafePointer<gchar>? = nil) -
set(label:Extension method) Sets
texton themenu_itemlabelDeclaration
Swift
@inlinable func set(label: UnsafePointer<gchar>!) -
setReserveIndicator(reserve:Extension method) Sets whether the
menu_itemshould 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.
Declaration
Swift
@inlinable func setReserveIndicator(reserve: Bool) -
set(rightJustified:Extension method) 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.)
set_right_justified is deprecated: If you insist on using it, use gtk_widget_set_hexpand() and gtk_widget_set_halign().
Declaration
Swift
@available(*, deprecated) @inlinable func set(rightJustified: Bool) -
set(submenu:Extension method) Sets or replaces the menu item’s submenu, or removes it when a
nilsubmenu is passed.Declaration
Swift
@inlinable func set(submenu: MenuRef? = nil) -
set(submenu:Extension method) Sets or replaces the menu item’s submenu, or removes it when a
nilsubmenu is passed.Declaration
Swift
@inlinable func set<MenuT>(submenu: MenuT?) where MenuT : MenuProtocol -
set(useUnderline:Extension method) If true, an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Declaration
Swift
@inlinable func set(useUnderline setting: Bool) -
toggleSizeAllocate(allocation:Extension method) Emits the
GtkMenuItem::toggle-size-allocatesignal on the given item.Declaration
Swift
@inlinable func toggleSizeAllocate(allocation: Int) -
toggleSizeRequest(requisition:Extension method) Emits the
GtkMenuItem::toggle-size-requestsignal on the given item.Declaration
Swift
@inlinable func toggleSizeRequest(requisition: UnsafeMutablePointer<gint>!) -
accelPathExtension methodRetrieve the accelerator path that was previously set on
menu_item.See
gtk_menu_item_set_accel_path()for details.Declaration
Swift
@inlinable var accelPath: String! { get nonmutating set } -
labelExtension methodThe text for the child label.
Declaration
Swift
@inlinable var label: String! { get nonmutating set } -
reserveIndicatorExtension methodReturns whether the
menu_itemreserves space for the submenu indicator, regardless if it has a submenu or not.Declaration
Swift
@inlinable var reserveIndicator: Bool { get nonmutating set } -
rightJustifiedExtension methodGets whether the menu item appears justified at the right side of the menu bar.
get_right_justified is deprecated: See gtk_menu_item_set_right_justified()
Declaration
Swift
@inlinable var rightJustified: Bool { get nonmutating set } -
submenuExtension methodThe submenu attached to the menu item, or
nilif it has none.Declaration
Swift
@inlinable var submenu: WidgetRef! { get nonmutating set } -
useUnderlineExtension methodChecks if an underline in the text indicates the next character should be used for the mnemonic accelerator key.
Declaration
Swift
@inlinable var useUnderline: Bool { get nonmutating set } -
binExtension methodUndocumented
Declaration
Swift
@inlinable var bin: GtkBin { get }
View on GitHub
Install in Dash
MenuItemProtocol Protocol Reference