Main Page Widgets Namespaces Book

# Gtk::Menu Class Reference
[Widgets, Menu classes]

Inheritance diagram for Gtk::Menu:

[legend]
List of all members.

## Detailed Description

A drop-down menu consisting of Gtk::MenuItem objects which can be navigated and activated by the user to perform application functions.

Menus are normally placed inside a Gtk::MenuBar or another MenuItem as a sub menu. A Menu can also be popped up, for instance as a right-click context menu, by calling the popup() method. See also Gtk::OptionMenu.

## Public Types

typedef SigC::Slot3< void, int&, int&, bool& > | SlotPositionCalc
| void on_menu_position(int&, int&, bool& push_in);

## Public Member Functions

virtual | ~Menu ()
GtkMenu* | gobj ()
| Provides access to the underlying C GtkObject.
const GtkMenu* | gobj () const
| Provides access to the underlying C GtkObject.
| Menu ()
void | popup (MenuShell& parent_menu_shell, MenuItem& parent_menu_item, GtkMenuPositionFunc func, gpointer data, guint button, guint32 activate_time)
| Displays a menu and makes it available for selection.
void | popup (const SlotPositionCalc& position_calc_slot, guint button, guint32 activate_time)
| Displays a menu and makes it available for selection.
void | popup (guint button, guint32 activate_time)
| Displays a menu and makes it available for selection.
void | reposition ()
void | popdown ()
MenuItem* | get_active ()
const MenuItem* | get_active () const
void | set_active (guint index)
void | set_accel_group (const Glib::RefPtr<AccelGroup>& accel_group)
void | unset_accel_group ()
Glib::RefPtr<AccelGroup> | get_accel_group ()
void | set_accel_path (const Glib::ustring& accel_path)
| Sets an accelerator path for this menu from which accelerator paths for its immediate children, its menu items, can be constructed.
void | detach ()
Widget* | get_attach_widget ()
const Widget* | get_attach_widget () const
void | set_tearoff_state (bool torn_off=true)
bool | get_tearoff_state () const
| Returns whether the menu is torn off.
void | set_title (const Glib::ustring& title)
| Sets the title string for the menu.
void | unset_title ()
Glib::ustring | get_title () const
| Returns the title of the menu.
void | set_screen (const Glib::RefPtr<Gdk::Screen>& screen)
| Sets the Gdk::Screen on which the menu will be displayed.
void | reorder_child (const MenuItem& child, int position)
Glib::PropertyProxy<Glib::ustring> | property_tearoff_title ()
| You rarely need to use properties because there are get_ and set_ methods for almost all of them.

## Protected Member Functions

void | attach_to_widget (Widget& widget, GtkMenuDetachFunc detacher)

## Related Functions

(Note that these are not member functions.)
Gtk::Menu* | wrap (GtkMenu* object, bool take_copy=false)

## Member Typedef Documentation

typedef SigC::Slot3<void, int&, int&, bool&> Gtk::Menu::SlotPositionCalc

| void on_menu_position(int&, int&, bool& push_in);

## Constructor & Destructor Documentation

virtual Gtk::Menu::~Menu | ( |  | ) | `[virtual]`

Gtk::Menu::Menu | ( |  | ) |

## Member Function Documentation

void Gtk::Menu::attach_to_widget | ( | Widget& | widget,
|  | GtkMenuDetachFunc | detacher
| ) | `[protected]`

void Gtk::Menu::detach | ( |  | ) |

Glib::RefPtr<AccelGroup> Gtk::Menu::get_accel_group | ( |  | ) |

const MenuItem* Gtk::Menu::get_active | ( |  | ) | const

MenuItem* Gtk::Menu::get_active | ( |  | ) |

const Widget* Gtk::Menu::get_attach_widget | ( |  | ) | const

Widget* Gtk::Menu::get_attach_widget | ( |  | ) |

bool Gtk::Menu::get_tearoff_state | ( |  | ) | const

Returns whether the menu is torn off.

See set_tearoff_state().

Returns:
  `true` if the menu is currently torn off.

Glib::ustring Gtk::Menu::get_title | ( |  | ) | const

Returns the title of the menu.

See set_title().

Returns:
  The title of the menu, or `0` if the menu has no title set on it. This string is owned by the widget and should not be modified or freed.

const GtkMenu* Gtk::Menu::gobj | ( |  | ) | const`[inline]`

| Provides access to the underlying C GtkObject. Reimplemented from Gtk::MenuShell.

GtkMenu* Gtk::Menu::gobj | ( |  | ) | `[inline]`

| Provides access to the underlying C GtkObject. Reimplemented from Gtk::MenuShell.

void Gtk::Menu::popdown | ( |  | ) |

void Gtk::Menu::popup | ( | guint | button,
|  | guint32 | activate_time
| ) |

Displays a menu and makes it available for selection.

Applications can use this function to display context-sensitive menus. The default menu positioning function will position the menu at the current pointer position.

Parameters:

  button | The button which was pressed to initiate the event.
  activate_time | The time at which the activation event occurred.

void Gtk::Menu::popup | ( | const SlotPositionCalc& | position_calc_slot,
|  | guint | button,
|  | guint32 | activate_time
| ) |

| Displays a menu and makes it available for selection.

void Gtk::Menu::popup | ( | MenuShell& | parent_menu_shell,
|  | MenuItem& | 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 `0` 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 should be the time stamp of the event that initiated the popup. If such an event is not available, use gtk_get_current_event_time() instead.

Parameters:

  parent_menu_shell | The menu shell containing the triggering menu item, or `0`.
  parent_menu_item | The menu item whose activation triggered the popup, or `0`.
  func | A user supplied function used to position the menu, or `0`.
  data | User supplied data to be passed to func .
  button | The mouse button which was pressed to initiate the event.
  activate_time | The time at which the activation event occurred.

Glib::PropertyProxy<Glib::ustring> Gtk::Menu::property_tearoff_title | ( |  | ) |

You rarely need to use properties because there are get_ and set_ methods for almost all of them.

Returns:
  A PropertyProxy that allows you to get or set the property of the value, or receive notification when the value of the property changes.

void Gtk::Menu::reorder_child | ( | const MenuItem& | child,
|  | int | position
| ) |

void Gtk::Menu::reposition | ( |  | ) |

void Gtk::Menu::set_accel_group | ( | const Glib::RefPtr<AccelGroup>& | accel_group | ) |

void Gtk::Menu::set_accel_path | ( | const Glib::ustring& | 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::MenuItem::set_accel_path() on each menu item that should support runtime user changable accelerators. Instead, by just calling 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, "& lt;Gnumeric-Sheet& gt;/File");` has been called, assign its items the accel paths: `"& lt;Gnumeric-Sheet& gt;/File/New"` and `"& lt;Gnumeric-Sheet& gt;/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().

Parameters:

  accel_path | A valid accelerator path.

void Gtk::Menu::set_active | ( | guint | index | ) |

void Gtk::Menu::set_screen | ( | const Glib::RefPtr<Gdk::Screen>& | screen | ) |

Sets the Gdk::Screen on which the menu will be displayed.

Since: 2.2

Parameters:

  screen | A Gdk::Screen, or `0` if the screen should be determined by the widget the menu is attached to.

void Gtk::Menu::set_tearoff_state | ( | bool | torn_off = true | ) |

void Gtk::Menu::set_title | ( | const Glib::ustring& | title | ) |

Sets the title string for the menu.

The title is displayed when the menu is shown as a tearoff menu.

Parameters:

  title | A string containing the title for the menu.

void Gtk::Menu::unset_accel_group | ( |  | ) |

void Gtk::Menu::unset_title | ( |  | ) |

## Friends And Related Function Documentation

Gtk::Menu* wrap | ( | GtkMenu* | object,
|  | bool | take_copy = false
| ) | `[related]`

The documentation for this class was generated from the following file:

- menu.h