GtkMenu: GTK+ 2 Reference Manual

## GtkMenu GtkMenu |

## Functions

GtkWidget * | gtk_menu_new ()
void | gtk_menu_set_screen ()
#define | gtk_menu_append()
#define | gtk_menu_prepend()
#define | gtk_menu_insert()
void | gtk_menu_reorder_child ()
void | gtk_menu_attach ()
void | gtk_menu_popup ()
void | gtk_menu_set_accel_group ()
GtkAccelGroup * | gtk_menu_get_accel_group ()
void | gtk_menu_set_accel_path ()
const gchar * | gtk_menu_get_accel_path ()
void | gtk_menu_set_title ()
const gchar * | gtk_menu_get_title ()
void | gtk_menu_set_monitor ()
gint | gtk_menu_get_monitor ()
gboolean | gtk_menu_get_tearoff_state ()
void | gtk_menu_set_reserve_toggle_size ()
gboolean | gtk_menu_get_reserve_toggle_size ()
void | gtk_menu_popdown ()
void | gtk_menu_reposition ()
GtkWidget * | gtk_menu_get_active ()
void | gtk_menu_set_active ()
void | gtk_menu_set_tearoff_state ()
void | gtk_menu_attach_to_widget ()
void | gtk_menu_detach ()
GtkWidget * | gtk_menu_get_attach_widget ()
GList * | gtk_menu_get_for_attach_widget ()
void | (*GtkMenuPositionFunc) ()
void | (*GtkMenuDetachFunc) ()

## Properties

GtkAccelGroup * | accel-group | Read / Write
char * | accel-path | Read / Write
int | active | Read / Write
GtkWidget * | attach-widget | Read / Write
int | monitor | Read / Write
gboolean | reserve-toggle-size | Read / Write
gboolean | tearoff-state | Read / Write
char * | tearoff-title | Read / Write

## Child Properties

int | bottom-attach | Read / Write
int | left-attach | Read / Write
int | right-attach | Read / Write
int | top-attach | Read / Write

## Style Properties

GtkArrowPlacement | arrow-placement | Read
float | arrow-scaling | Read
gboolean | double-arrows | Read
int | horizontal-offset | Read
int | horizontal-padding | Read
int | vertical-offset | Read
int | vertical-padding | Read

## Signals

void | move-scroll | Action

## Types and Values

struct | GtkMenu

## Object Hierarchy

        GObject
        ╰── GInitiallyUnowned
            ╰── GtkObject
                ╰── GtkWidget
                    ╰── GtkContainer
                        ╰── GtkMenuShell
                            ╰── GtkMenu
                                ╰── GtkRecentChooserMenu

## Implemented Interfaces

GtkMenu implements AtkImplementorIface and GtkBuildable.

## Includes

    #include <gtk/gtk.h>

## Description

## Functions

### gtk_menu_new ()

    GtkWidget *
    gtk_menu_new (void);

### gtk_menu_set_screen ()

    void
    gtk_menu_set_screen (GtkMenu *menu,
                         GdkScreen *screen);

Sets the GdkScreen on which the menu will be displayed.

#### Parameters

menu | a GtkMenu. |
screen | a GdkScreen, or `NULL` if the screen should be determined by the widget the menu is attached to. | [allow-none]

Since: 2.2

### gtk_menu_append()

    #define gtk_menu_append(menu,child) gtk_menu_shell_append  ((GtkMenuShell *)(menu),(child))

`gtk_menu_append` is deprecated and should not be used in newly-written code.

### gtk_menu_prepend()

    #define gtk_menu_prepend(menu,child)    gtk_menu_shell_prepend ((GtkMenuShell *)(menu),(child))

`gtk_menu_prepend` is deprecated and should not be used in newly-written code.

### gtk_menu_insert()

    #define gtk_menu_insert(menu,child,pos) gtk_menu_shell_insert ((GtkMenuShell *)(menu),(child),(pos))

`gtk_menu_insert` is deprecated and should not be used in newly-written code.

### gtk_menu_reorder_child ()

    void
    gtk_menu_reorder_child (GtkMenu *menu,
                            GtkWidget *child,
                            gint position);

### 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()`.

#### Parameters

menu | a GtkMenu. |
child | a GtkMenuItem. |
left_attach | The column number to attach the left side of the item to. |
right_attach | The column number to attach the right side of the item to. |
top_attach | The row number to attach the top of the item to. |
bottom_attach | The row number to attach the bottom of the item 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 `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 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.

#### Parameters

menu | a GtkMenu. |
parent_menu_shell | the menu shell containing the triggering menu item, or `NULL`. | [allow-none]
parent_menu_item | the menu item whose activation triggered the popup, or `NULL`. | [allow-none]
func | a user supplied function used to position the menu, or `NULL`. | [allow-none]
data | user supplied data to be passed to `func` . | [allow-none]
button | the mouse button which was pressed to initiate the event. |
activate_time | the time at which the activation event occurred. |

### gtk_menu_set_accel_group ()

    void
    gtk_menu_set_accel_group (GtkMenu *menu,
                              GtkAccelGroup *accel_group);

#### Parameters

accel_group | . | [allow-none]

### 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_group()`.

#### Returns

the GtkAccelGroup associated with the menu.

[transfer none]

### 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()`.

#### Parameters

menu | a valid GtkMenu |
accel_path | a valid accelerator path. | [allow-none]

### gtk_menu_get_accel_path ()

    const gchar *
    gtk_menu_get_accel_path (GtkMenu *menu);

Retrieves the accelerator path set on the menu.

#### Parameters

menu | a valid GtkMenu |

#### 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);

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.

#### Parameters

menu | a GtkMenu |
title | a string containing the title for the menu. |

### gtk_menu_get_title ()

    const gchar *
    gtk_menu_get_title (GtkMenu *menu);

Returns the title of the menu. See `gtk_menu_set_title()`.

#### Parameters

menu | a GtkMenu |

#### Returns

the title of the menu, or `NULL` if the menu has no title set on it. This string is owned by the widget 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_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.

#### Parameters

menu | a GtkMenu |
monitor_num | the number of the monitor on which the menu should be popped up |

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.

#### Parameters

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

### gtk_menu_get_tearoff_state ()

    gboolean
    gtk_menu_get_tearoff_state (GtkMenu *menu);

Returns whether the menu is torn off. See `gtk_menu_set_tearoff_state()`.

#### Parameters

menu | a GtkMenu |

#### 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.

#### Parameters

menu | a GtkMenu |
reserve_toggle_size | whether to reserve size for toggles |

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.

#### Parameters

menu | a GtkMenu |

#### Returns

Whether the menu reserves toggle space

Since: 2.18

### gtk_menu_popdown ()

    void
    gtk_menu_popdown (GtkMenu *menu);

### gtk_menu_reposition ()

    void
    gtk_menu_reposition (GtkMenu *menu);

### 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.

#### Parameters

menu | 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]

### gtk_menu_set_active ()

    void
    gtk_menu_set_active (GtkMenu *menu,
                         guint index_);

### gtk_menu_set_tearoff_state ()

    void
    gtk_menu_set_tearoff_state (GtkMenu *menu,
                                gboolean torn_off);

### gtk_menu_attach_to_widget ()

    void
    gtk_menu_attach_to_widget (GtkMenu *menu,
                               GtkWidget *attach_widget,
                               GtkMenuDetachFunc detacher);

### gtk_menu_detach ()

    void
    gtk_menu_detach (GtkMenu *menu);

### gtk_menu_get_attach_widget ()

    GtkWidget *
    gtk_menu_get_attach_widget (GtkMenu *menu);

Returns the GtkWidget that the menu is attached to.

#### Parameters

menu | a GtkMenu |

#### 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.

#### Parameters

widget | a GtkWidget |

#### 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);

### GtkMenuDetachFunc ()

    void
    (*GtkMenuDetachFunc) (GtkWidget *attach_widget,
                          GtkMenu *menu);

## Types and Values

### struct GtkMenu

    struct GtkMenu;

## 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”               char *

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”                   int

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”                  int

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.

Owner: GtkMenu

Flags: Read / Write

Default value: FALSE

Since: 2.6

### The `“tearoff-title”` property

      “tearoff-title”            char *

A title that may be displayed by the window manager when this menu is torn-off.

Owner: GtkMenu

Flags: Read / Write

Default value: NULL

## Child Property Details

### The `“bottom-attach”` child property

      “bottom-attach”            int

The row number to attach the bottom of the child to.

Owner: GtkMenu

Flags: Read / Write

Allowed values: >= -1

Default value: -1

### The `“left-attach”` child property

      “left-attach”              int

The column number to attach the left side of the child to.

Owner: GtkMenu

Flags: Read / Write

Allowed values: >= -1

Default value: -1

### The `“right-attach”` child property

      “right-attach”             int

The column number to attach the right side of the child to.

Owner: GtkMenu

Flags: Read / Write

Allowed values: >= -1

Default value: -1

### The `“top-attach”` child property

      “top-attach”               int

The row number to attach the top of the child to.

Owner: GtkMenu

Flags: Read / Write

Allowed values: >= -1

Default value: -1

## Style Property Details

### The `“arrow-placement”` style property

      “arrow-placement”          GtkArrowPlacement

Indicates where scroll arrows should be placed.

Owner: GtkMenu

Flags: Read

Default value: GTK_ARROWS_BOTH

Since: 2.16

### The `“arrow-scaling”` style property

      “arrow-scaling”            float

Arbitrary constant to scale down the size of the scroll arrow.

Owner: GtkMenu

Flags: Read

Allowed values: [0,1]

Default value: 0.7

### The `“double-arrows”` style property

      “double-arrows”            gboolean

When scrolling, always show both arrows.

Owner: GtkMenu

Flags: Read

Default value: TRUE

### The `“horizontal-offset”` style property

      “horizontal-offset”        int

When the menu is a submenu, position it this number of pixels offset horizontally.

Owner: GtkMenu

Flags: Read

Default value: -2

### The `“horizontal-padding”` style property

      “horizontal-padding”       int

Extra space at the left and right edges of the menu.

Owner: GtkMenu

Flags: Read

Allowed values: >= 0

Default value: 0

### The `“vertical-offset”` style property

      “vertical-offset”          int

When the menu is a submenu, position it this number of pixels offset vertically.

Owner: GtkMenu

Flags: Read

Default value: 0

### The `“vertical-padding”` style property

      “vertical-padding”         int

Extra space at the top and bottom of the menu.

Owner: GtkMenu

Flags: Read

Allowed values: >= 0

Default value: 1

## Signal Details

### The `“move-scroll”` signal

    void
    user_function (GtkMenu      *menu,
                   GtkScrollType arg1,
                   gpointer      user_data)

Flags: Action