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
GtkMenuShell
instance.Declaration
Swift
var ptr: UnsafeMutableRawPointer! { get }
-
menu_shell_ptr
Default implementationTyped pointer to the underlying
GtkMenuShell
instance.Default Implementation
Return the stored, untyped pointer as a typed pointer to the
GtkMenuShell
instance.Declaration
Swift
var menu_shell_ptr: UnsafeMutablePointer<GtkMenuShell>! { get }
-
Required Initialiser for types conforming to
MenuShellProtocol
Declaration
Swift
init(raw: UnsafeMutableRawPointer)
-
bind(property:
Extension methodto: _: flags: transformFrom: transformTo: ) Bind a
MenuShellPropertyName
source 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 : ObjectProtocol
Parameters
source_property
the source property to bind
target
the target object to bind to
target_property
the target property to bind to
flags
the flags to pass to the
Binding
transform_from
ValueTransformer
to use for forward transformationtransform_to
ValueTransformer
to use for backwards transformationReturn Value
binding reference or
nil
in case of an error -
get(property:
Extension method) Get the value of a MenuShell property
Declaration
Swift
@inlinable func get(property: MenuShellPropertyName) -> GLibObject.Value
Parameters
property
the 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
property
the 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
MenuShellSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: MenuShellSignalName, flags f: ConnectFlags = ConnectFlags(0), handler h: @escaping SignalHandler) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
handler
The 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
MenuShellSignalName
signalDeclaration
Swift
@discardableResult @inlinable func connect(signal s: MenuShellSignalName, flags f: ConnectFlags = ConnectFlags(0), data userData: gpointer!, destroyData destructor: GClosureNotify? = nil, signalHandler h: @escaping GCallback) -> Int
Parameters
signal
The signal to connect
flags
The connection flags to use
data
A pointer to user data to provide to the callback
destroyData
A
GClosureNotify
C function to destroy the data pointed to byuserData
signalHandler
The 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-current
signalDeclaration
Swift
@discardableResult @inlinable func onActivateCurrent(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ forceHide: Bool) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
forceHide
if
true
, hide the menu after activating the menu itemhandler
The signal handler to call Run the given callback whenever the
activateCurrent
signal is emitted -
activateCurrentSignal
Extension methodTyped
activate-current
signal 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-done
signal to be emitted.Note
This represents the underlyingcancel
signalDeclaration
Swift
@discardableResult @inlinable func onCancel(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
cancel
signal is emitted -
cancelSignal
Extension methodTyped
cancel
signal 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-focus
signalDeclaration
Swift
@discardableResult @inlinable func onCycleFocus(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ direction: DirectionType) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
direction
the direction to cycle in
handler
The signal handler to call Run the given callback whenever the
cycleFocus
signal is emitted -
cycleFocusSignal
Extension methodTyped
cycle-focus
signal 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 underlyingdeactivate
signalDeclaration
Swift
@discardableResult @inlinable func onDeactivate(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
deactivate
signal is emitted -
deactivateSignal
Extension methodTyped
deactivate
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var deactivateSignal: MenuShellSignalName { get }
-
onInsert(flags:
Extension methodhandler: ) The
insert
signal is emitted when a newGtkMenuItem
is added to aGtkMenuShell
. A separate signal is used instead of GtkContaineradd
because of the need for an additional position parameter.The inverse of this signal is the GtkContainer
removed
signal.Note
This represents the underlyinginsert
signalDeclaration
Swift
@discardableResult @inlinable func onInsert(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ child: WidgetRef, _ position: Int) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
child
the
GtkMenuItem
that is being insertedposition
the position at which the insert occurs
handler
The signal handler to call Run the given callback whenever the
insert
signal is emitted -
insertSignal
Extension methodTyped
insert
signal 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-current
signalDeclaration
Swift
@discardableResult @inlinable func onMoveCurrent(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ direction: MenuDirectionType) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
direction
the direction to move
handler
The signal handler to call Run the given callback whenever the
moveCurrent
signal is emitted -
moveCurrentSignal
Extension methodTyped
move-current
signal for using theconnect(signal:)
methodsDeclaration
Swift
static var moveCurrentSignal: MenuShellSignalName { get }
-
onMoveSelected(flags:
Extension methodhandler: ) The
move-selected
signal is emitted to move the selection to another item.Note
This represents the underlyingmove-selected
signalDeclaration
Swift
@discardableResult @inlinable func onMoveSelected(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ distance: Int) -> Bool) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
distance
+1 to move to the next item, -1 to move to the previous
handler
true
to stop the signal emission,false
to continue Run the given callback whenever themoveSelected
signal is emitted -
moveSelectedSignal
Extension methodTyped
move-selected
signal 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-done
signalDeclaration
Swift
@discardableResult @inlinable func onSelectionDone(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
handler
The signal handler to call Run the given callback whenever the
selectionDone
signal is emitted -
selectionDoneSignal
Extension methodTyped
selection-done
signal 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 innotify
being 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-focus
signalDeclaration
Swift
@discardableResult @inlinable func onNotifyTakeFocus(flags: ConnectFlags = ConnectFlags(0), handler: @escaping (_ unownedSelf: MenuShellRef, _ pspec: ParamSpecRef) -> Void) -> Int
Parameters
flags
Flags
unownedSelf
Reference to instance of self
pspec
the
GParamSpec
of the property which changed.handler
The signal handler to call Run the given callback whenever the
notifyTakeFocus
signal is emitted -
notifyTakeFocusSignal
Extension methodTyped
notify::take-focus
signal 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
GtkMenuItem
to 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
GtkMenuShell
and aGMenuModel
.The contents of
shell
are removed and then refilled with menu items according tomodel
. Whenmodel
changes,shell
is updated. Calling this function twice onshell
with differentmodel
will cause the first binding to be replaced with a binding to the new model. Ifmodel
isnil
then any previous binding is undone and all children are removed.with_separators
determines 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_namespace
is non-nil
then the effect is as if all actions mentioned in themodel
have their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned andaction_namespace
is “app” then the effective action name is “app.quit”.This function uses
GtkActionable
to 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 aGtkMenuShell
outside 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 theGMenuModel
togtk_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
GtkMenuShell
and aGMenuModel
.The contents of
shell
are removed and then refilled with menu items according tomodel
. Whenmodel
changes,shell
is updated. Calling this function twice onshell
with differentmodel
will cause the first binding to be replaced with a binding to the new model. Ifmodel
isnil
then any previous binding is undone and all children are removed.with_separators
determines 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_namespace
is non-nil
then the effect is as if all actions mentioned in themodel
have their names prefixed with the namespace, plus a dot. For example, if the action “quit” is mentioned andaction_namespace
is “app” then the effective action name is “app.quit”.This function uses
GtkActionable
to 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 aGtkMenuShell
outside 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 theGMenuModel
togtk_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
GtkMenu
orGtkMenuBar
from 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
true
if the menu shell will take the keyboard focus on popup.Declaration
Swift
@inlinable func getTakeFocus() -> Bool
-
insert(child:
Extension methodposition: ) Adds a new
GtkMenuItem
to 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
GtkMenuItem
to 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_focus
istrue
(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_focus
tofalse
is useful only for special applications like virtual keyboard implementations which should not take keyboard focus.The
take_focus
state 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_focus
property of the submenu needs to be set explicitly.Note that setting it to
false
has 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_focus
set tofalse
should 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)
-
parentShell
Extension methodGets the parent menu shell.
The parent menu shell of a submenu is the
GtkMenu
orGtkMenuBar
from which it was opened up.Declaration
Swift
@inlinable var parentShell: WidgetRef! { get }
-
selectedItem
Extension methodGets the currently selected item.
Declaration
Swift
@inlinable var selectedItem: WidgetRef! { get }
-
takeFocus
Extension methodReturns
true
if the menu shell will take the keyboard focus on popup.Declaration
Swift
@inlinable var takeFocus: Bool { get nonmutating set }
-
container
Extension methodUndocumented
Declaration
Swift
@inlinable var container: GtkContainer { get }