GTK+ 3 Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties | Child Properties | Style Properties | Signals |
#include <gtk/gtk.h> struct GtkMenu; GtkWidget * gtk_menu_new (void
); void gtk_menu_set_screen (GtkMenu *menu
,GdkScreen *screen
); void gtk_menu_reorder_child (GtkMenu *menu
,GtkWidget *child
,gint position
); void gtk_menu_attach (GtkMenu *menu
,GtkWidget *child
,guint left_attach
,guint right_attach
,guint top_attach
,guint bottom_attach
); 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
); void gtk_menu_popup (GtkMenu *menu
,GtkWidget *parent_menu_shell
,GtkWidget *parent_menu_item
,GtkMenuPositionFunc func
,gpointer data
,guint button
,guint32 activate_time
); void gtk_menu_set_accel_group (GtkMenu *menu
,GtkAccelGroup *accel_group
); GtkAccelGroup * gtk_menu_get_accel_group (GtkMenu *menu
); void gtk_menu_set_accel_path (GtkMenu *menu
,const gchar *accel_path
); const gchar * gtk_menu_get_accel_path (GtkMenu *menu
); void gtk_menu_set_title (GtkMenu *menu
,const gchar *title
); const gchar * gtk_menu_get_title (GtkMenu *menu
); void gtk_menu_set_monitor (GtkMenu *menu
,gint monitor_num
); gint gtk_menu_get_monitor (GtkMenu *menu
); gboolean gtk_menu_get_tearoff_state (GtkMenu *menu
); void gtk_menu_set_reserve_toggle_size (GtkMenu *menu
,gboolean reserve_toggle_size
); gboolean gtk_menu_get_reserve_toggle_size (GtkMenu *menu
); void gtk_menu_popdown (GtkMenu *menu
); void gtk_menu_reposition (GtkMenu *menu
); GtkWidget * gtk_menu_get_active (GtkMenu *menu
); void gtk_menu_set_active (GtkMenu *menu
,guint index
); void gtk_menu_set_tearoff_state (GtkMenu *menu
,gboolean torn_off
); void gtk_menu_attach_to_widget (GtkMenu *menu
,GtkWidget *attach_widget
,GtkMenuDetachFunc detacher
); void gtk_menu_detach (GtkMenu *menu
); GtkWidget * gtk_menu_get_attach_widget (GtkMenu *menu
); GList * gtk_menu_get_for_attach_widget (GtkWidget *widget
); void (*GtkMenuPositionFunc) (GtkMenu *menu
,gint *x
,gint *y
,gboolean *push_in
,gpointer user_data
); void (*GtkMenuDetachFunc) (GtkWidget *attach_widget
,GtkMenu *menu
);
GObject +----GInitiallyUnowned +----GtkWidget +----GtkContainer +----GtkMenuShell +----GtkMenu +----GtkRecentChooserMenu
"accel-group" GtkAccelGroup* : Read / Write "accel-path" gchar* : Read / Write "active" gint : Read / Write "attach-widget" GtkWidget* : Read / Write "monitor" gint : Read / Write "reserve-toggle-size" gboolean : Read / Write "tearoff-state" gboolean : Read / Write "tearoff-title" gchar* : Read / Write
"bottom-attach" gint : Read / Write "left-attach" gint : Read / Write "right-attach" gint : Read / Write "top-attach" gint : Read / Write
"arrow-placement" GtkArrowPlacement : Read "arrow-scaling" gfloat : Read "double-arrows" gboolean : Read "horizontal-offset" gint : Read "horizontal-padding" gint : Read "vertical-offset" gint : Read "vertical-padding" gint : Read
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 GtkOptionMenu. 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.
Example 75. Connecting the popup signal handler.
1 2 3 |
/* connect our handler which will popup the menu */ g_signal_connect_swapped (window, "button_press_event", G_CALLBACK (my_popup_handler), menu); |
Example 76. Signal handler which displays a popup menu.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
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 == 3) { gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event_button->button, event_button->time); return TRUE; } } return FALSE; } |
void gtk_menu_set_screen (GtkMenu *menu
,GdkScreen *screen
);
Sets the GdkScreen on which the menu will be displayed.
|
a GtkMenu |
|
a GdkScreen, or NULL if the screen should be
determined by the widget the menu is attached to. [allow-none]
|
Since 2.2
void gtk_menu_reorder_child (GtkMenu *menu
,GtkWidget *child
,gint position
);
Moves child
to a new position
in the list of menu
children.
|
a GtkMenu |
|
the GtkMenuItem to move |
|
the new position to place child .
Positions are numbered from 0 to n - 1 |
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()
.
|
a GtkMenu |
|
a GtkMenuItem |
|
The column number to attach the left side of the item to |
|
The column number to attach the right side of the item to |
|
The row number to attach the top of the item to |
|
The row number to attach the bottom of the item to |
Since 2.4
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.
|
a GtkMenu |
|
a GdkDevice. [allow-none] |
|
the menu shell containing the triggering
menu item, or NULL . [allow-none]
|
|
the menu item whose activation triggered
the popup, or NULL . [allow-none]
|
|
a user supplied function used to position the menu,
or NULL . [allow-none]
|
|
user supplied data to be passed to func . [allow-none]
|
|
destroy notify for data . [allow-none]
|
|
the mouse button which was pressed to initiate the event |
|
the time at which the activation event occurred |
Since 3.0
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.
|
a GtkMenu |
|
the menu shell containing the
triggering menu item, or NULL . [allow-none]
|
|
the menu item whose activation
triggered the popup, or NULL . [allow-none]
|
|
a user supplied function used to position
the menu, or NULL . [allow-none]
|
|
user supplied data to be passed to func . |
|
the mouse button which was pressed to initiate the event. |
|
the time at which the activation event occurred. |
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.
|
a GtkMenu |
|
the GtkAccelGroup to be associated with the menu. [allow-none] |
GtkAccelGroup * gtk_menu_get_accel_group (GtkMenu *menu
);
Gets the GtkAccelGroup which holds global accelerators for the
menu. See gtk_menu_set_accel_group()
.
|
a GtkMenu |
Returns : |
the GtkAccelGroup associated with the menu. [transfer none] |
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()
.
|
a valid GtkMenu |
|
a valid accelerator path. [allow-none] |
const gchar * gtk_menu_get_accel_path (GtkMenu *menu
);
Retrieves the accelerator path set on the menu.
|
a valid GtkMenu |
Returns : |
the accelerator path set on the menu. |
Since 2.14
void gtk_menu_set_title (GtkMenu *menu
,const gchar *title
);
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.
|
a GtkMenu |
|
a string containing the title for the menu |
const gchar * gtk_menu_get_title (GtkMenu *menu
);
Returns the title of the menu. See gtk_menu_set_title()
.
void gtk_menu_set_monitor (GtkMenu *menu
,gint monitor_num
);
Informs GTK+ on which monitor a menu should be popped up.
See gdk_screen_get_monitor_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.
|
a GtkMenu |
|
the number of the monitor on which the menu should be popped up |
Since 2.4
gint gtk_menu_get_monitor (GtkMenu *menu
);
Retrieves the number of the monitor on which to show the menu.
|
a GtkMenu |
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
gboolean gtk_menu_get_tearoff_state (GtkMenu *menu
);
Returns whether the menu is torn off.
See gtk_menu_set_tearoff_state()
.
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.
|
a GtkMenu |
|
whether to reserve size for toggles |
Since 2.18
gboolean gtk_menu_get_reserve_toggle_size (GtkMenu *menu
);
Returns whether the menu reserves space for toggles and icons, regardless of their actual presence.
|
a GtkMenu |
Returns : |
Whether the menu reserves toggle space |
Since 2.18
void gtk_menu_popdown (GtkMenu *menu
);
Removes the menu from the screen.
|
a GtkMenu |
void gtk_menu_reposition (GtkMenu *menu
);
Repositions the menu according to its position function.
|
a GtkMenu |
GtkWidget * gtk_menu_get_active (GtkMenu *menu
);
Returns the selected menu item from the menu. This is used by the GtkOptionMenu.
|
a GtkMenu |
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] |
void gtk_menu_set_active (GtkMenu *menu
,guint index
);
Selects the specified menu item within the menu. This is used by the GtkOptionMenu and should not be used by anyone else.
|
a GtkMenu |
|
the index of the menu item to select. Iindex values are from 0 to n-1 |
void gtk_menu_set_tearoff_state (GtkMenu *menu
,gboolean torn_off
);
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.
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.
|
a GtkMenu |
|
the GtkWidget that the menu will be attached to |
|
the user supplied callback function
that will be called when the menu calls gtk_menu_detach() . [scope async][allow-none]
|
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.
|
a GtkMenu |
GtkWidget * gtk_menu_get_attach_widget (GtkMenu *menu
);
Returns the GtkWidget that the menu is attached to.
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.
|
a GtkWidget |
Returns : |
the list of menus attached to his widget. [element-type GtkWidget][transfer none] |
Since 2.6
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.
|
a GtkMenu. |
|
address of the gint representing the horizontal position where the menu shall be drawn. [out] |
|
address of the gint representing the vertical position where the menu shall be drawn. This is an output parameter. [out] |
|
This parameter controls how menus placed outside
the monitor are handled. If this is set to TRUE and part of
the menu is outside the monitor then GTK+ pushes the window
into the visible area, effectively modifying the popup
position. Note that moving and possibly resizing the menu
around will alter the scroll position to keep the menu items
"in place", i.e. at the same monitor position they would have
been without resizing. In practice, this behavior is only
useful for combobox popups or option menus and cannot be used
to simply confine a menu to monitor boundaries. In that case,
changing the scroll offset is not desirable. [inout]
|
|
the data supplied by the user in the gtk_menu_popup()
data parameter. |
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.
"accel-group"
property"accel-group" GtkAccelGroup* : Read / Write
The accel group holding accelerators for the menu.
Since 2.14
"accel-path"
property"accel-path" gchar* : Read / Write
An accel path used to conveniently construct accel paths of child items.
Default value: NULL
Since 2.14
"active"
property"active" gint : Read / Write
The index of the currently selected menu item, or -1 if no menu item is selected.
Allowed values: >= G_MAXULONG
Default value: -1
Since 2.14
"attach-widget"
property"attach-widget" GtkWidget* : Read / Write
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.
Since 2.14
"monitor"
property"monitor" gint : Read / Write
The monitor the menu will be popped up on.
Allowed values: >= G_MAXULONG
Default value: -1
Since 2.14
"reserve-toggle-size"
property"reserve-toggle-size" gboolean : Read / Write
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.
Default value: TRUE
Since 2.18
"tearoff-state"
property"tearoff-state" gboolean : Read / Write
A boolean that indicates whether the menu is torn-off.
Default value: FALSE
Since 2.6
"tearoff-title"
property"tearoff-title" gchar* : Read / Write
A title that may be displayed by the window manager when this menu is torn-off.
Default value: NULL
"bottom-attach"
child property"bottom-attach" gint : Read / Write
The row number to attach the bottom of the child to.
Allowed values: >= G_MAXULONG
Default value: -1
"left-attach"
child property"left-attach" gint : Read / Write
The column number to attach the left side of the child to.
Allowed values: >= G_MAXULONG
Default value: -1
"right-attach"
child property"right-attach" gint : Read / Write
The column number to attach the right side of the child to.
Allowed values: >= G_MAXULONG
Default value: -1
"top-attach"
child property"top-attach" gint : Read / Write
The row number to attach the top of the child to.
Allowed values: >= G_MAXULONG
Default value: -1
"arrow-placement"
style property"arrow-placement" GtkArrowPlacement : Read
Indicates where scroll arrows should be placed.
Default value: GTK_ARROWS_BOTH
Since 2.16
"arrow-scaling"
style property"arrow-scaling" gfloat : Read
Arbitrary constant to scale down the size of the scroll arrow.
Allowed values: [0,1]
Default value: 0.7
Since 2.16
"double-arrows"
style property"double-arrows" gboolean : Read
When scrolling, always show both arrows.
Default value: TRUE
"horizontal-offset"
style property"horizontal-offset" gint : Read
When the menu is a submenu, position it this number of pixels offset horizontally.
Default value: -2
"horizontal-padding"
style property"horizontal-padding" gint : Read
Extra space at the left and right edges of the menu.
Allowed values: >= 0
Default value: 0
"vertical-offset"
style property"vertical-offset" gint : Read
When the menu is a submenu, position it this number of pixels offset vertically.
Default value: 0
"vertical-padding"
style property"vertical-padding" gint : Read
Extra space at the top and bottom of the menu.
Allowed values: >= 0
Default value: 1
"move-scroll"
signalvoid user_function (GtkMenu *menu,
GtkScrollType scroll_type,
gpointer user_data) : Action
|
a GtkMenu |
|
a GtkScrollType |
|
user data set when the signal handler was connected. |