Popup Menus
| Chapter 10. Menus and Toolbars |

## Popup Menus

Menus are normally just added to a window, but they can also be displayed temporarily as the result of a mouse button click. For instance, a context menu might be diplayed when the user clicks their right mouse button.

The UI layout for a popup menu should use the `popup` node. For instance:

        Glib::ustring ui_info =
            "<ui>"
            "  <popup name='PopupMenu'>"
            "    <menuitem action='ContextEdit'/>"
            "    <menuitem action='ContextProcess'/>"
            "    <menuitem action='ContextRemove'/>"
            "  </popup>"
            "</ui";

        m_refUIManager->add_ui_from_string(ui_info);

To show the popup menu, use `Gtk::Menu`'s `popup()` method, providing the button identifier and the time of activation, as provided by the `button_press_event` signal, which you will need to handle anyway. For instance:

    bool ExampleWindow::on_button_press_event(GdkEventButton* event)
    {
      if( (event->type == GDK_BUTTON_PRESS) && (event->button == 3) )
      {
        m_Menu_Popup->popup(event->button, event->time);
        return true; //It has been handled.
      }
      else
        return false;
    }

UIManager |  | Examples