Gtk.Menu

const Gtk = imports.gi.Gtk;

let menu = new Gtk.Menu({
    accel_group: value,
    accel_path: value,
    active: value,
    attach_widget: value,
    monitor: value,
    reserve_toggle_size: value,
    tearoff_state: value,
    tearoff_title: value,
});
  

A Gtk.Menu is a Gtk.MenuShell that implements a drop down menu consisting of a list of Gtk.MenuItem objects which can be navigated and activated by the user to perform application functions.

A Gtk.Menu is most commonly dropped down by activating a Gtk.MenuItem in a Gtk.MenuBar or popped up by activating a Gtk.MenuItem in another Gtk.Menu.

A Gtk.Menu can also be popped up by activating a Gtk.ComboBox. Other composite widgets such as the Gtk.Notebook can pop up a Gtk.Menu as well.

Applications can display a Gtk.Menu as a popup menu by calling the Gtk.popup function. The example below shows how an application can pop up a menu when the 3rd mouse button is pressed.

<example> <title>Connecting the popup signal handler.</title> <programlisting> /<!---->* connect our handler which will popup the menu *<!---->/ g_signal_connect_swapped (window, "button_press_event", G_CALLBACK (my_popup_handler), menu); </programlisting> </example>

<example> <title>Signal handler which displays a popup menu.</title> <programlisting> 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 == GDK_BUTTON_SECONDARY) { gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event_button->button, event_button->time); return TRUE; } }

return FALSE; } </programlisting> </example>

Hierarchy

  • GObject.Object
    • GObject.InitiallyUnowned
      • Gtk.Widget
        • Gtk.Container
          • Gtk.MenuShell
            • Gtk.Menu