Synopsis#include <gtk/gtk.h> GtkMenu; GtkWidget* gtk_menu_new (void); void gtk_menu_set_screen (GtkMenu *menu, GdkScreen *screen); #define gtk_menu_append (menu,child) #define gtk_menu_prepend (menu,child) #define gtk_menu_insert (menu,child,pos) 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 (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_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); Object HierarchyGObject +----GInitiallyUnowned +----GtkObject +----GtkWidget +----GtkContainer +----GtkMenuShell +----GtkMenu +----GtkRecentChooserMenu Properties"accel-group" GtkAccelGroup* : Read / Write "accel-path" gchar* : Read / Write "active" gint : Read / Write "attach-widget" GtkWidget* : Read / Write "monitor" gint : Read / Write "tearoff-state" gboolean : Read / Write "tearoff-title" gchar* : Read / Write Child Properties"bottom-attach" gint : Read / Write "left-attach" gint : Read / Write "right-attach" gint : Read / Write "top-attach" gint : Read / Write Style Properties"double-arrows" gboolean : Read "horizontal-offset" gint : Read "horizontal-padding" gint : Read "vertical-offset" gint : Read "vertical-padding" gint : Read DescriptionA 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
Example 26. Connecting the popup signal handler. /* connect our handler which will popup the menu */ g_signal_connect_swapped (window, "button_press_event", G_CALLBACK (my_popup_handler), menu); Example 27. 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; } DetailsGtkMenutypedef struct _GtkMenu GtkMenu; The GtkMenu struct contains private data only, and should be accessed using the functions below. 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_append()#define gtk_menu_append(menu,child) gtk_menu_shell_append ((GtkMenuShell *)(menu),(child)) Warning
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
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
Adds a new GtkMenuItem to the menu's item list at the position
indicated by
gtk_menu_reorder_child ()void gtk_menu_reorder_child (GtkMenu *menu, GtkWidget *child, gint position); Moves a GtkMenuItem to a new position within the GtkMenu.
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
Note that this function is not related to
Since 2.4 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
The
The
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_menu_get_accel_group ()GtkAccelGroup* gtk_menu_get_accel_group (GtkMenu *menu);
Gets the GtkAccelGroup which holds global accelerators for the menu.
See
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
Note that
gtk_menu_get_accel_path ()const gchar* gtk_menu_get_accel_path (GtkMenu *menu); Retrieves the accelerator path set on the menu.
Since 2.14 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. If
gtk_menu_get_title ()const gchar* gtk_menu_get_title (GtkMenu *menu);
Returns the title of the menu. See
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 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.
Since 2.14 gtk_menu_get_tearoff_state ()gboolean gtk_menu_get_tearoff_state (GtkMenu *menu);
Returns whether the menu is torn off. See
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 GtkOptionMenu.
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 GtkOptionMenu and should not be used by anyone else.
gtk_menu_set_tearoff_state ()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.
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 ()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,
gtk_menu_get_attach_widget ()GtkWidget* gtk_menu_get_attach_widget (GtkMenu *menu); Returns the GtkWidget that the menu is attached to. 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.
Since 2.6 GtkMenuPositionFunc ()void (*GtkMenuPositionFunc) (GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer user_data);
A user function supplied when calling
GtkMenuDetachFunc ()void (*GtkMenuDetachFunc) (GtkWidget *attach_widget, GtkMenu *menu);
A user function supplied when calling Property DetailsThe
|
|
the object which received the signal. |
|
|
|
user data set when the signal handler was connected. |