MenuRef
public struct MenuRef : MenuProtocol, GWeakCapturing
A GtkMenu
is a GtkMenuShell
that implements a drop down menu
consisting of a list of GtkMenuItem
objects which can be navigated
and activated by the user to perform application functions.
A GtkMenu
is most commonly dropped down by activating a
GtkMenuItem
in a GtkMenuBar
or popped up by activating a
GtkMenuItem
in another GtkMenu
.
A GtkMenu
can also be popped up by activating a GtkComboBox
.
Other composite widgets such as the GtkNotebook
can pop up a
GtkMenu
as well.
Applications can display a GtkMenu
as a popup menu by calling the
gtk_menu_popup()
function. The example below shows how an application
can pop up a menu when the 3rd mouse button is pressed.
Connecting the popup signal handler.
(C Language Example):
// connect our handler which will popup the menu
g_signal_connect_swapped (window, "button_press_event",
G_CALLBACK (my_popup_handler), menu);
Signal handler which displays a popup menu.
(C Language Example):
static gint
my_popup_handler (GtkWidget *widget, GdkEvent *event)
{
GtkMenu *menu;
GdkEventButton *event_button;
g_return_val_if_fail (widget != NULL, FALSE);
g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
// The "widget" is the menu that was supplied when
// g_signal_connect_swapped() was called.
menu = GTK_MENU (widget);
if (event->type == GDK_BUTTON_PRESS)
{
event_button = (GdkEventButton *) event;
if (event_button->button == GDK_BUTTON_SECONDARY)
{
gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
event_button->button, event_button->time);
return TRUE;
}
}
return FALSE;
}
CSS nodes
(plain Language Example):
menu
├── arrow.top
├── <child>
┊
├── <child>
╰── arrow.bottom
The main CSS node of GtkMenu has name menu, and there are two subnodes with name arrow, for scrolling menu arrows. These subnodes get the .top and .bottom style classes.
The MenuRef
type acts as a lightweight Swift reference to an underlying GtkMenu
instance.
It exposes methods that can operate on this data type through MenuProtocol
conformance.
Use MenuRef
only as an unowned
reference to an existing GtkMenu
instance.
-
Untyped pointer to the underlying `GtkMenu` instance.
For type-safe access, use the generated, typed pointer
menu_ptr
property instead.Declaration
Swift
public let ptr: UnsafeMutableRawPointer!
-
Designated initialiser from the underlying
C
data typeDeclaration
Swift
@inlinable init(_ p: UnsafeMutablePointer<GtkMenu>)
-
Designated initialiser from a constant pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init(_ p: UnsafePointer<GtkMenu>)
-
Conditional initialiser from an optional pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafeMutablePointer<GtkMenu>?)
-
Conditional initialiser from an optional, non-mutable pointer to the underlying
C
data typeDeclaration
Swift
@inlinable init!(_ maybePointer: UnsafePointer<GtkMenu>?)
-
Conditional initialiser from an optional
gpointer
Declaration
Swift
@inlinable init!(gpointer g: gpointer?)
-
Conditional initialiser from an optional, non-mutable
gconstpointer
Declaration
Swift
@inlinable init!(gconstpointer g: gconstpointer?)
-
Reference intialiser for a related type that implements
MenuProtocol
Declaration
Swift
@inlinable init<T>(_ other: T) where T : MenuProtocol
-
This factory is syntactic sugar for setting weak pointers wrapped in
GWeak<T>
Declaration
Swift
@inlinable static func unowned<T>(_ other: T) -> MenuRef where T : MenuProtocol
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuProtocol
.Declaration
Swift
@inlinable init<T>(cPointer: UnsafeMutablePointer<T>)
-
Unsafe typed initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuProtocol
.Declaration
Swift
@inlinable init<T>(constPointer: UnsafePointer<T>)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuProtocol
.Declaration
Swift
@inlinable init(mutating raw: UnsafeRawPointer)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuProtocol
.Declaration
Swift
@inlinable init(raw: UnsafeMutableRawPointer)
-
Unsafe untyped initialiser. Do not use unless you know the underlying data type the pointer points to conforms to
MenuProtocol
.Declaration
Swift
@inlinable init(opaquePointer: OpaquePointer)
-
Creates a new
GtkMenu
Declaration
Swift
@inlinable init()
-
Creates a
GtkMenu
and populates it with menu items and submenus according tomodel
.The created menu items are connected to actions found in the
GtkApplicationWindow
to which the menu belongs - typically by means of being attached to a widget (seegtk_menu_attach_to_widget()
) that is contained within theGtkApplicationWindows
widget hierarchy.Actions can also be added using
gtk_widget_insert_action_group()
on the menu’s attach widget or on any of its parent widgets.Declaration
Swift
@inlinable init<MenuModelT>(model: MenuModelT) where MenuModelT : MenuModelProtocol
-
Creates a
GtkMenu
and populates it with menu items and submenus according tomodel
.The created menu items are connected to actions found in the
GtkApplicationWindow
to which the menu belongs - typically by means of being attached to a widget (seegtk_menu_attach_to_widget()
) that is contained within theGtkApplicationWindows
widget hierarchy.Actions can also be added using
gtk_widget_insert_action_group()
on the menu’s attach widget or on any of its parent widgets.Declaration
Swift
@inlinable static func newFrom<MenuModelT>(model: MenuModelT) -> WidgetRef! where MenuModelT : MenuModelProtocol