MenuShellProtocol
public protocol MenuShellProtocol : ContainerProtocol
A GtkMenuShell is the abstract base class used to derive the
GtkMenu and GtkMenuBar subclasses.
A GtkMenuShell is a container of GtkMenuItem objects arranged
in a list which can be navigated, selected, and activated by the
user to perform application functions. A GtkMenuItem can have a
submenu associated with it, allowing for nested hierarchical menus.
Terminology
A menu item can be “selected”, this means that it is displayed in the prelight state, and if it has a submenu, that submenu will be popped up.
A menu is “active” when it is visible onscreen and the user is selecting from it. A menubar is not active until the user clicks on one of its menuitems. When a menu is active, passing the mouse over a submenu will pop it up.
There is also is a concept of the current menu and a current menu item. The current menu item is the selected menu item that is furthest down in the hierarchy. (Every active menu shell does not necessarily contain a selected menu item, but if it does, then the parent menu shell must also contain a selected menu item.) The current menu is the menu that contains the current menu item. It will always have a GTK grab and receive all key presses.
The MenuShellProtocol protocol exposes the methods and properties of an underlying GtkMenuShell 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 MenuShell.
Alternatively, use MenuShellRef as a lighweight, unowned reference if you already have an instance you just want to use.
-
Untyped pointer to the underlying
GtkMenuShellinstance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get } -
menu_shell_ptrDefault implementationTyped pointer to the underlying
GtkMenuShellinstance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkMenuShellinstance.Declaration
Swift
var menu_shell_ptr: UnsafeMutablePointer<GtkMenuShell>! { get } -
Required Initialiser for types conforming to
MenuShellProtocolDeclaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
MenuShellPropertyNamesource property to a given target object.Declaration
Swift
@discardableResult @inlinable func bind<Q, T>(property source_property: MenuShellPropertyName, 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 MenuShell property
Declaration
Swift
@inlinable func get(property: MenuShellPropertyName) -> 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 MenuShell property. Note that this will only have an effect on properties that are writable and not construct-only!
Declaration
Swift
@inlinable func set(property: MenuShellPropertyName, 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
MenuShellSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: MenuShellSignalName, 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
MenuShellSignalNamesignalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: MenuShellSignalName, 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)
-
onActivateCurrent(flags:Extension methodhandler: ) An action signal that activates the current menu item within the menu shell.
Note
This represents the underlyingactivate-currentsignalDeclaration
Swift
@discardableResult @inlinable func onActivateCurrent(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ forceHide: Bool) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
forceHideif
true, hide the menu after activating the menu itemhandlerThe signal handler to call Run the given callback whenever the
activateCurrentsignal is emitted -
activateCurrentSignalExtension methodTyped
activate-currentsignal for using theconnect(signal:)methodsDeclaration
Swift
static var activateCurrentSignal: MenuShellSignalName { get } -
onCancel(flags:Extension methodhandler: ) An action signal which cancels the selection within the menu shell. Causes the
GtkMenuShell::selection-donesignal to be emitted.Note
This represents the underlyingcancelsignalDeclaration
Swift
@discardableResult @inlinable func onCancel(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
cancelsignal is emitted -
cancelSignalExtension methodTyped
cancelsignal for using theconnect(signal:)methodsDeclaration
Swift
static var cancelSignal: MenuShellSignalName { get } -
onCycleFocus(flags:Extension methodhandler: ) A keybinding signal which moves the focus in the given
direction.Note
This represents the underlyingcycle-focussignalDeclaration
Swift
@discardableResult @inlinable func onCycleFocus(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ direction: DirectionType) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
directionthe direction to cycle in
handlerThe signal handler to call Run the given callback whenever the
cycleFocussignal is emitted -
cycleFocusSignalExtension methodTyped
cycle-focussignal for using theconnect(signal:)methodsDeclaration
Swift
static var cycleFocusSignal: MenuShellSignalName { get } -
onDeactivate(flags:Extension methodhandler: ) This signal is emitted when a menu shell is deactivated.
Note
This represents the underlyingdeactivatesignalDeclaration
Swift
@discardableResult @inlinable func onDeactivate(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
deactivatesignal is emitted -
deactivateSignalExtension methodTyped
deactivatesignal for using theconnect(signal:)methodsDeclaration
Swift
static var deactivateSignal: MenuShellSignalName { get } -
onInsert(flags:Extension methodhandler: ) The
insertsignal is emitted when a newGtkMenuItemis added to aGtkMenuShell. A separate signal is used instead of GtkContaineraddbecause of the need for an additional position parameter.The inverse of this signal is the GtkContainer
removedsignal.Note
This represents the underlyinginsertsignalDeclaration
Swift
@discardableResult @inlinable func onInsert(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ child: WidgetRef, _ position: Int) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
childthe
GtkMenuItemthat is being insertedpositionthe position at which the insert occurs
handlerThe signal handler to call Run the given callback whenever the
insertsignal is emitted -
insertSignalExtension methodTyped
insertsignal for using theconnect(signal:)methodsDeclaration
Swift
static var insertSignal: MenuShellSignalName { get } -
onMoveCurrent(flags:Extension methodhandler: ) An keybinding signal which moves the current menu item in the direction specified by
direction.Note
This represents the underlyingmove-currentsignalDeclaration
Swift
@discardableResult @inlinable func onMoveCurrent(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ direction: MenuDirectionType) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
directionthe direction to move
handlerThe signal handler to call Run the given callback whenever the
moveCurrentsignal is emitted -
moveCurrentSignalExtension methodTyped
move-currentsignal for using theconnect(signal:)methodsDeclaration
Swift
static var moveCurrentSignal: MenuShellSignalName { get } -
onMoveSelected(flags:Extension methodhandler: ) The
move-selectedsignal is emitted to move the selection to another item.Note
This represents the underlyingmove-selectedsignalDeclaration
Swift
@discardableResult @inlinable func onMoveSelected(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ distance: Int) -> Bool) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
distance+1 to move to the next item, -1 to move to the previous
handlertrueto stop the signal emission,falseto continue Run the given callback whenever themoveSelectedsignal is emitted -
moveSelectedSignalExtension methodTyped
move-selectedsignal for using theconnect(signal:)methodsDeclaration
Swift
static var moveSelectedSignal: MenuShellSignalName { get } -
onSelectionDone(flags:Extension methodhandler: ) This signal is emitted when a selection has been completed within a menu shell.
Note
This represents the underlyingselection-donesignalDeclaration
Swift
@discardableResult @inlinable func onSelectionDone(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef) -> Void) -> IntParameters
flagsFlags
unownedSelfReference to instance of self
handlerThe signal handler to call Run the given callback whenever the
selectionDonesignal is emitted -
selectionDoneSignalExtension methodTyped
selection-donesignal for using theconnect(signal:)methodsDeclaration
Swift
static var selectionDoneSignal: MenuShellSignalName { get } -
onNotifyTakeFocus(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::take-focussignalDeclaration
Swift
@discardableResult @inlinable func onNotifyTakeFocus(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ 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
notifyTakeFocussignal is emitted -
notifyTakeFocusSignalExtension methodTyped
notify::take-focussignal for using theconnect(signal:)methodsDeclaration
Swift
static var notifyTakeFocusSignal: MenuShellSignalName { get }
-
activateItem(menuItem:Extension methodforceDeactivate: ) Activates the menu item within the menu shell.
Declaration
Swift
@inlinable func activateItem<WidgetT>(menuItem: WidgetT, forceDeactivate: Bool) where WidgetT : WidgetProtocol -
append(child:Extension method) Adds a new
GtkMenuItemto the end of the menu shell’s item list.Declaration
Swift
@inlinable func append<MenuItemT>(child: MenuItemT) where MenuItemT : MenuItemProtocol -
bind(model:Extension methodactionNamespace: with: ) Establishes a binding between a
GtkMenuShelland aGMenuModel.The contents of
shellare removed and then refilled with menu items according tomodel. Whenmodelchanges,shellis updated. Calling this function twice onshellwith differentmodelwill cause the first binding to be replaced with a binding to the new model. Ifmodelisnilthen any previous binding is undone and all children are removed.with_separatorsdetermines if toplevel items (eg: sections) have separators inserted between them. This is typically desired for menus but doesn’t make sense for menubars.If
action_namespaceis non-nilthen the effect is as if all actions mentioned in themodelhave their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned andaction_namespaceis “app” then the effective action name is “app.quit”.This function uses
GtkActionableto define the action name and target values on the created menu items. If you want to use an action group other than “app” and “win”, or if you want to use aGtkMenuShelloutside of aGtkApplicationWindow, then you will need to attach your own action group to the widget hierarchy usinggtk_widget_insert_action_group(). As an example, if you created a group with a “quit” action and inserted it with the name “mygroup” then you would use the action name “mygroup.quit” in yourGMenuModel.For most cases you are probably better off using
gtk_menu_new_from_model()orgtk_menu_bar_new_from_model()or just directly passing theGMenuModeltogtk_application_set_app_menu()orgtk_application_set_menubar().Declaration
Swift
@inlinable func bind(model: GIO.MenuModelRef? = nil, actionNamespace: UnsafePointer<gchar>? = nil, with separators: Bool) -
bind(model:Extension methodactionNamespace: with: ) Establishes a binding between a
GtkMenuShelland aGMenuModel.The contents of
shellare removed and then refilled with menu items according tomodel. Whenmodelchanges,shellis updated. Calling this function twice onshellwith differentmodelwill cause the first binding to be replaced with a binding to the new model. Ifmodelisnilthen any previous binding is undone and all children are removed.with_separatorsdetermines if toplevel items (eg: sections) have separators inserted between them. This is typically desired for menus but doesn’t make sense for menubars.If
action_namespaceis non-nilthen the effect is as if all actions mentioned in themodelhave their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned andaction_namespaceis “app” then the effective action name is “app.quit”.This function uses
GtkActionableto define the action name and target values on the created menu items. If you want to use an action group other than “app” and “win”, or if you want to use aGtkMenuShelloutside of aGtkApplicationWindow, then you will need to attach your own action group to the widget hierarchy usinggtk_widget_insert_action_group(). As an example, if you created a group with a “quit” action and inserted it with the name “mygroup” then you would use the action name “mygroup.quit” in yourGMenuModel.For most cases you are probably better off using
gtk_menu_new_from_model()orgtk_menu_bar_new_from_model()or just directly passing theGMenuModeltogtk_application_set_app_menu()orgtk_application_set_menubar().Declaration
Swift
@inlinable func bind<MenuModelT>(model: MenuModelT?, actionNamespace: UnsafePointer<gchar>? = nil, with separators: Bool) where MenuModelT : MenuModelProtocol -
cancel()Extension methodCancels the selection within the menu shell.
Declaration
Swift
@inlinable func cancel() -
deactivate()Extension methodDeactivates the menu shell.
Typically this results in the menu shell being erased from the screen.
Declaration
Swift
@inlinable func deactivate() -
deselect()Extension methodDeselects the currently selected item from the menu shell, if any.
Declaration
Swift
@inlinable func deselect() -
getParentShell()Extension methodGets the parent menu shell.
The parent menu shell of a submenu is the
GtkMenuorGtkMenuBarfrom which it was opened up.Declaration
Swift
@inlinable func getParentShell() -> WidgetRef! -
getSelectedItem()Extension methodGets the currently selected item.
Declaration
Swift
@inlinable func getSelectedItem() -> WidgetRef! -
getTakeFocus()Extension methodReturns
trueif the menu shell will take the keyboard focus on popup.Declaration
Swift
@inlinable func getTakeFocus() -> Bool -
insert(child:Extension methodposition: ) Adds a new
GtkMenuItemto the menu shell’s item list at the position indicated byposition.Declaration
Swift
@inlinable func insert<WidgetT>(child: WidgetT, position: Int) where WidgetT : WidgetProtocol -
prepend(child:Extension method) Adds a new
GtkMenuItemto the beginning of the menu shell’s item list.Declaration
Swift
@inlinable func prepend<WidgetT>(child: WidgetT) where WidgetT : WidgetProtocol -
selectFirst(searchSensitive:Extension method) Select the first visible or selectable child of the menu shell; don’t select tearoff items unless the only item is a tearoff item.
Declaration
Swift
@inlinable func selectFirst(searchSensitive: Bool) -
selectItem(menuItem:Extension method) Selects the menu item from the menu shell.
Declaration
Swift
@inlinable func selectItem<WidgetT>(menuItem: WidgetT) where WidgetT : WidgetProtocol -
set(takeFocus:Extension method) If
take_focusistrue(the default) the menu shell will take the keyboard focus so that it will receive all keyboard events which is needed to enable keyboard navigation in menus.Setting
take_focustofalseis useful only for special applications like virtual keyboard implementations which should not take keyboard focus.The
take_focusstate of a menu or menu bar is automatically propagated to submenus whenever a submenu is popped up, so you don’t have to worry about recursively setting it for your entire menu hierarchy. Only when programmatically picking a submenu and popping it up manually, thetake_focusproperty of the submenu needs to be set explicitly.Note that setting it to
falsehas side-effects:If the focus is in some other app, it keeps the focus and keynav in the menu doesn’t work. Consequently, keynav on the menu will only work if the focus is on some toplevel owned by the onscreen keyboard.
To avoid confusing the user, menus with
take_focusset tofalseshould not display mnemonics or accelerators, since it cannot be guaranteed that they will work.See also
gdk_keyboard_grab()Declaration
Swift
@inlinable func set(takeFocus: Bool) -
parentShellExtension methodGets the parent menu shell.
The parent menu shell of a submenu is the
GtkMenuorGtkMenuBarfrom which it was opened up.Declaration
Swift
@inlinable var parentShell: WidgetRef! { get } -
selectedItemExtension methodGets the currently selected item.
Declaration
Swift
@inlinable var selectedItem: WidgetRef! { get } -
takeFocusExtension methodReturns
trueif the menu shell will take the keyboard focus on popup.Declaration
Swift
@inlinable var takeFocus: Bool { get nonmutating set } -
containerExtension methodUndocumented
Declaration
Swift
@inlinable var container: GtkContainer { get }
View on GitHub
Install in Dash
MenuShellProtocol Protocol Reference