Functions
gtk_menu_set_screen ()
void
gtk_menu_set_screen (GtkMenu *menu,
GdkScreen *screen);
Sets the GdkScreen on which the menu will be displayed.
Since: 2.2
gtk_menu_reorder_child ()
void
gtk_menu_reorder_child (GtkMenu *menu,
GtkWidget *child,
gint position);
Moves child
to a new position
in the list of menu
children.
gtk_menu_attach ()
void
gtk_menu_attach (GtkMenu *menu,
GtkWidget *child,
guint left_attach,
guint right_attach,
guint top_attach,
guint bottom_attach);
Adds a new GtkMenuItem to a (table) menu. The number of “cells” that
an item will occupy is specified by left_attach
, right_attach
,
top_attach
and bottom_attach
. These each represent the leftmost,
rightmost, uppermost and lower column and row numbers of the table.
(Columns and rows are indexed from zero).
Note that this function is not related to gtk_menu_detach().
Since: 2.4
gtk_menu_popup_at_rect ()
void
gtk_menu_popup_at_rect (GtkMenu *menu,
GdkWindow *rect_window,
const GdkRectangle *rect,
GdkGravity rect_anchor,
GdkGravity menu_anchor,
const GdkEvent *trigger_event);
Displays menu
and makes it available for selection.
See gtk_menu_popup_at_widget() and gtk_menu_popup_at_pointer(), which
handle more common cases for popping up menus.
menu
will be positioned at rect
, aligning their anchor points. rect
is
relative to the top-left corner of rect_window
. rect_anchor
and
menu_anchor
determine anchor points on rect
and menu
to pin together.
menu
can optionally be offset by “rect-anchor-dx” and
“rect-anchor-dy”.
Anchors should be specified under the assumption that the text direction is
left-to-right; they will be flipped horizontally automatically if the text
direction is right-to-left.
Other properties that influence the behaviour of this function are
“anchor-hints” and “menu-type-hint”. Connect to the
“popped-up” signal to find out how it was actually positioned.
Since: 3.22
gtk_menu_popup_at_widget ()
void
gtk_menu_popup_at_widget (GtkMenu *menu,
GtkWidget *widget,
GdkGravity widget_anchor,
GdkGravity menu_anchor,
const GdkEvent *trigger_event);
Displays menu
and makes it available for selection.
See gtk_menu_popup_at_pointer() to pop up a menu at the master pointer.
gtk_menu_popup_at_rect() also allows you to position a menu at an arbitrary
rectangle.

menu
will be positioned at widget
, aligning their anchor points.
widget_anchor
and menu_anchor
determine anchor points on widget
and menu
to pin together. menu
can optionally be offset by “rect-anchor-dx”
and “rect-anchor-dy”.
Anchors should be specified under the assumption that the text direction is
left-to-right; they will be flipped horizontally automatically if the text
direction is right-to-left.
Other properties that influence the behaviour of this function are
“anchor-hints” and “menu-type-hint”. Connect to the
“popped-up” signal to find out how it was actually positioned.
Since: 3.22
gtk_menu_popup_for_device ()
void
gtk_menu_popup_for_device (GtkMenu *menu,
GdkDevice *device,
GtkWidget *parent_menu_shell,
GtkWidget *parent_menu_item,
GtkMenuPositionFunc func,
gpointer data,
GDestroyNotify destroy,
guint button,
guint32 activate_time);
Displays a menu and makes it available for selection.
Applications can use this function to display context-sensitive menus,
and will typically supply NULL for the parent_menu_shell
,
parent_menu_item
, func
, data
and destroy
parameters. The default
menu positioning function will position the menu at the current position
of device
(or its corresponding pointer).
The button
parameter should be the mouse button pressed to initiate
the menu popup. If the menu popup was initiated by something other than
a mouse button press, such as a mouse button release or a keypress,
button
should be 0.
The activate_time
parameter is used to conflict-resolve initiation of
concurrent requests for mouse/keyboard grab requests. To function
properly, this needs to be the time stamp of the user event (such as
a mouse click or key press) that caused the initiation of the popup.
Only if no such event is available, gtk_get_current_event_time() can
be used instead.
Note that this function does not work very well on GDK backends that
do not have global coordinates, such as Wayland or Mir. You should
probably use one of the gtk_menu_popup_at_ variants, which do not
have this problem.
Since: 3.0
gtk_menu_popup ()
void
gtk_menu_popup (GtkMenu *menu,
GtkWidget *parent_menu_shell,
GtkWidget *parent_menu_item,
GtkMenuPositionFunc func,
gpointer data,
guint button,
guint32 activate_time);
Displays a menu and makes it available for selection.
Applications can use this function to display context-sensitive
menus, and will typically supply NULL for the parent_menu_shell
,
parent_menu_item
, func
and data
parameters. The default menu
positioning function will position the menu at the current mouse
cursor position.
The button
parameter should be the mouse button pressed to initiate
the menu popup. If the menu popup was initiated by something other
than a mouse button press, such as a mouse button release or a keypress,
button
should be 0.
The activate_time
parameter is used to conflict-resolve initiation
of concurrent requests for mouse/keyboard grab requests. To function
properly, this needs to be the timestamp of the user event (such as
a mouse click or key press) that caused the initiation of the popup.
Only if no such event is available, gtk_get_current_event_time() can
be used instead.
Note that this function does not work very well on GDK backends that
do not have global coordinates, such as Wayland or Mir. You should
probably use one of the gtk_menu_popup_at_ variants, which do not
have this problem.
gtk_menu_set_accel_group ()
void
gtk_menu_set_accel_group (GtkMenu *menu,
GtkAccelGroup *accel_group);
Set the GtkAccelGroup which holds global accelerators for the
menu. This accelerator group needs to also be added to all windows
that this menu is being used in with gtk_window_add_accel_group(),
in order for those windows to support all the accelerators
contained in this group.
gtk_menu_set_accel_path ()
void
gtk_menu_set_accel_path (GtkMenu *menu,
const gchar *accel_path);
Sets an accelerator path for this menu from which accelerator paths
for its immediate children, its menu items, can be constructed.
The main purpose of this function is to spare the programmer the
inconvenience of having to call gtk_menu_item_set_accel_path() on
each menu item that should support runtime user changable accelerators.
Instead, by just calling gtk_menu_set_accel_path() on their parent,
each menu item of this menu, that contains a label describing its
purpose, automatically gets an accel path assigned.
For example, a menu containing menu items “New” and “Exit”, will, after
gtk_menu_set_accel_path (menu, "<Gnumeric-Sheet>/File"); has been
called, assign its items the accel paths: "<Gnumeric-Sheet>/File/New"
and "<Gnumeric-Sheet>/File/Exit".
Assigning accel paths to menu items then enables the user to change
their accelerators at runtime. More details about accelerator paths
and their default setups can be found at gtk_accel_map_add_entry().
Note that accel_path
string will be stored in a GQuark. Therefore,
if you pass a static string, you can save some memory by interning
it first with g_intern_static_string().
gtk_menu_get_accel_path ()
const gchar *
gtk_menu_get_accel_path (GtkMenu *menu);
Retrieves the accelerator path set on the menu.
Returns
the accelerator path set on the menu.
Since: 2.14
gtk_menu_set_title ()
void
gtk_menu_set_title (GtkMenu *menu,
const gchar *title);
gtk_menu_set_title has been deprecated since version 3.10 and should not be used in newly-written code.
Sets the title string for the menu.
The title is displayed when the menu is shown as a tearoff
menu. If title
is NULL, the menu will see if it is attached
to a parent menu item, and if so it will try to use the same
text as that menu item’s label.
gtk_menu_get_title ()
const gchar *
gtk_menu_get_title (GtkMenu *menu);
gtk_menu_get_title has been deprecated since version 3.10 and should not be used in newly-written code.
Returns the title of the menu. See gtk_menu_set_title().
Returns
the title of the menu, or NULL if the menu
has no title set on it. This string is owned by GTK+
and should not be modified or freed.
gtk_menu_set_monitor ()
void
gtk_menu_set_monitor (GtkMenu *menu,
gint monitor_num);
Informs GTK+ on which monitor a menu should be popped up.
See gdk_monitor_get_geometry().
This function should be called from a GtkMenuPositionFunc
if the menu should not appear on the same monitor as the pointer.
This information can’t be reliably inferred from the coordinates
returned by a GtkMenuPositionFunc, since, for very long menus,
these coordinates may extend beyond the monitor boundaries or even
the screen boundaries.
Since: 2.4
gtk_menu_get_monitor ()
gint
gtk_menu_get_monitor (GtkMenu *menu);
Retrieves the number of the monitor on which to show the menu.
Returns
the number of the monitor on which the menu should
be popped up or -1, if no monitor has been set
Since: 2.14
gtk_menu_place_on_monitor ()
void
gtk_menu_place_on_monitor (GtkMenu *menu,
GdkMonitor *monitor);
Places menu
on the given monitor.
Since: 3.22
gtk_menu_get_tearoff_state ()
gboolean
gtk_menu_get_tearoff_state (GtkMenu *menu);
gtk_menu_get_tearoff_state has been deprecated since version 3.10 and should not be used in newly-written code.
Returns whether the menu is torn off.
See gtk_menu_set_tearoff_state().
Returns
TRUE if the menu is currently torn off.
gtk_menu_set_reserve_toggle_size ()
void
gtk_menu_set_reserve_toggle_size (GtkMenu *menu,
gboolean reserve_toggle_size);
Sets whether the menu should reserve space for drawing toggles
or icons, regardless of their actual presence.
Since: 2.18
gtk_menu_get_reserve_toggle_size ()
gboolean
gtk_menu_get_reserve_toggle_size (GtkMenu *menu);
Returns whether the menu reserves space for toggles and
icons, regardless of their actual presence.
Returns
Whether the menu reserves toggle space
Since: 2.18
gtk_menu_popdown ()
void
gtk_menu_popdown (GtkMenu *menu);
Removes the menu from the screen.
gtk_menu_reposition ()
void
gtk_menu_reposition (GtkMenu *menu);
Repositions the menu according to its position function.
gtk_menu_get_active ()
GtkWidget *
gtk_menu_get_active (GtkMenu *menu);
Returns the selected menu item from the menu. This is used by the
GtkComboBox.
Returns
the GtkMenuItem that was last selected
in the menu. If a selection has not yet been made, the
first menu item is selected.
[transfer none]
gtk_menu_set_active ()
void
gtk_menu_set_active (GtkMenu *menu,
guint index);
Selects the specified menu item within the menu. This is used by
the GtkComboBox and should not be used by anyone else.
gtk_menu_set_tearoff_state ()
void
gtk_menu_set_tearoff_state (GtkMenu *menu,
gboolean torn_off);
gtk_menu_set_tearoff_state has been deprecated since version 3.10 and should not be used in newly-written code.
Changes the tearoff state of the menu. A menu is normally
displayed as drop down menu which persists as long as the menu is
active. It can also be displayed as a tearoff menu which persists
until it is closed or reattached.
gtk_menu_attach_to_widget ()
void
gtk_menu_attach_to_widget (GtkMenu *menu,
GtkWidget *attach_widget,
GtkMenuDetachFunc detacher);
Attaches the menu to the widget and provides a callback function
that will be invoked when the menu calls gtk_menu_detach() during
its destruction.
If the menu is attached to the widget then it will be destroyed
when the widget is destroyed, as if it was a child widget.
An attached menu will also move between screens correctly if the
widgets moves between screens.
gtk_menu_detach ()
void
gtk_menu_detach (GtkMenu *menu);
Detaches the menu from the widget to which it had been attached.
This function will call the callback function, detacher
, provided
when the gtk_menu_attach_to_widget() function was called.
gtk_menu_get_attach_widget ()
GtkWidget *
gtk_menu_get_attach_widget (GtkMenu *menu);
Returns the GtkWidget that the menu is attached to.
Returns
the GtkWidget that the menu is attached to.
[transfer none]
gtk_menu_get_for_attach_widget ()
GList *
gtk_menu_get_for_attach_widget (GtkWidget *widget);
Returns a list of the menus which are attached to this widget.
This list is owned by GTK+ and must not be modified.
Returns
the list
of menus attached to his widget.
[element-type GtkWidget][transfer none]
Since: 2.6
GtkMenuPositionFunc ()
void
(*GtkMenuPositionFunc) (GtkMenu *menu,
gint *x,
gint *y,
gboolean *push_in,
gpointer user_data);
A user function supplied when calling gtk_menu_popup() which
controls the positioning of the menu when it is displayed. The
function sets the x
and y
parameters to the coordinates where the
menu is to be drawn. To make the menu appear on a different
monitor than the mouse pointer, gtk_menu_set_monitor() must be
called.
GtkMenuDetachFunc ()
void
(*GtkMenuDetachFunc) (GtkWidget *attach_widget,
GtkMenu *menu);
A user function supplied when calling gtk_menu_attach_to_widget() which
will be called when the menu is later detached from the widget.
Property Details
The “accel-group” property
“accel-group” GtkAccelGroup *
The accel group holding accelerators for the menu.
Owner: GtkMenu
Flags: Read / Write
Since: 2.14
The “accel-path” property
“accel-path” gchar *
An accel path used to conveniently construct accel paths of child items.
Owner: GtkMenu
Flags: Read / Write
Default value: NULL
Since: 2.14
The “active” property
“active” gint
The index of the currently selected menu item, or -1 if no
menu item is selected.
Owner: GtkMenu
Flags: Read / Write
Allowed values: >= -1
Default value: -1
Since: 2.14
The “attach-widget” property
“attach-widget” GtkWidget *
The widget the menu is attached to. Setting this property attaches
the menu without a GtkMenuDetachFunc. If you need to use a detacher,
use gtk_menu_attach_to_widget() directly.
Owner: GtkMenu
Flags: Read / Write
Since: 2.14
The “monitor” property
“monitor” gint
The monitor the menu will be popped up on.
Owner: GtkMenu
Flags: Read / Write
Allowed values: >= -1
Default value: -1
Since: 2.14
The “reserve-toggle-size” property
“reserve-toggle-size” gboolean
A boolean that indicates whether the menu reserves space for
toggles and icons, regardless of their actual presence.
This property should only be changed from its default value
for special-purposes such as tabular menus. Regular menus that
are connected to a menu bar or context menus should reserve
toggle space for consistency.
Owner: GtkMenu
Flags: Read / Write
Default value: TRUE
Since: 2.18
The “tearoff-state” property
“tearoff-state” gboolean
A boolean that indicates whether the menu is torn-off.
GtkMenu:tearoff-state has been deprecated since version 3.10 and should not be used in newly-written code.
Owner: GtkMenu
Flags: Read / Write
Default value: FALSE
Since: 2.6
The “tearoff-title” property
“tearoff-title” gchar *
A title that may be displayed by the window manager when this
menu is torn-off.
GtkMenu:tearoff-title has been deprecated since version 3.10 and should not be used in newly-written code.
Owner: GtkMenu
Flags: Read / Write
Default value: NULL