Description
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 1. Connecting the popup signal handler.
/* connect our handler which will popup the menu */
g_signal_connect_swapped (GTK_OBJECT (window), "button_press_event",
G_CALLBACK (my_popup_handler), GTK_OBJECT (menu));
|
Example 2. Signal handler which displays a popup menu.
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;
}
|
Details
struct GtkMenu
The GtkMenu struct contains private data only, and
should be accessed using the functions below.
gtk_menu_new ()
Creates a new GtkMenu.
gtk_menu_set_screen ()
Sets the GtkScreen on which the GtkMenu will be displayed.
This function can only be called before menu is realized.
gtk_menu_append()
#define gtk_menu_append(menu,child) gtk_menu_shell_append ((GtkMenuShell *)(menu),(child))
|
Warning |
gtk_menu_append is deprecated and should not be used in newly-written code.
|
Adds a new GtkMenuItem to the end of the menu's item list.
gtk_menu_prepend()
#define gtk_menu_prepend(menu,child) gtk_menu_shell_prepend ((GtkMenuShell *)(menu),(child))
|
Warning |
gtk_menu_prepend is deprecated and should not be used in newly-written code.
|
Adds a new GtkMenuItem to the beginning of the menu's item list.
gtk_menu_insert()
#define gtk_menu_insert(menu,child,pos) gtk_menu_shell_insert ((GtkMenuShell *)(menu),(child),(pos))
|
Warning |
gtk_menu_insert is deprecated and should not be used in newly-written code.
|
Adds a new GtkMenuItem to the menu's item list at the position
indicated by position.
gtk_menu_popup ()
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 pointer position.
gtk_menu_set_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().
gtk_menu_set_title ()
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.
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 ()
Returns the selected menu item from the menu. This is used by the
GtkOptionMenu.
gtk_menu_set_active ()
Selects the specified menu item within the menu. This is used by the
GtkOptionMenu and should not be used by anyone else.
gtk_menu_set_tearoff_state ()
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 ()
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.
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 ()
Returns the GtkWidget that the menu is attached to.
GtkMenuPositionFunc ()
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.
GtkMenuDetachFunc ()
A user function supplied when calling gtk_menu_attach_to_widget() which
will be called when the menu is later detached from the widget.