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::slot< void, int&, int&, bool& > | SlotPositionCalc
| For instance, void on_popup_menu_position(int& x, int& y, bool& push_in);.
## Public Member Functions
void | attach (Gtk::Widget& child, guint left_attach, guint right_attach, guint top_attach, guint bottom_attach)
| Adds a new Gtk::MenuItem to a (table) menu.
void | detach ()
Glib::RefPtr<const AccelGroup> | get_accel_group () const
Glib::RefPtr<AccelGroup> | get_accel_group ()
const MenuItem* | get_active () const
MenuItem* | get_active ()
const Widget* | get_attach_widget () const
Widget* | get_attach_widget ()
bool | get_tearoff_state () const
| Return value: `true` if the menu is currently torn off.
Glib::ustring | get_title () const
| Return value: the title of the menu, or `0` if the menu has no.
const GtkMenu* | gobj () const
| Provides access to the underlying C GtkObject.
GtkMenu* | gobj ()
| Provides access to the underlying C GtkObject.
| Menu ()
void | popdown ()
void | popup (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 (MenuShell& parent_menu_shell, MenuItem& parent_menu_item, const SlotPositionCalc& slot, guint button, guint32 activate_time)
Glib::PropertyProxy_ReadOnly< Glib::ustring > | property_tearoff_title () const
| A title that may be displayed by the window manager when this menu is torn-off.
Glib::PropertyProxy<Glib::ustring> | property_tearoff_title ()
| A title that may be displayed by the window manager when this menu is torn-off.
void | reorder_child (const MenuItem& child, int position)
void | reposition ()
void | set_accel_group (const Glib::RefPtr<AccelGroup>& 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 | set_active (guint index)
void | set_monitor (int monitor_num)
| Informs GTK+ on which monitor a menu should be popped up.
void | set_screen (const Glib::RefPtr<Gdk::Screen>& screen)
| Sets the Gdk::Screen on which the menu will be displayed.
void | set_tearoff_state (bool torn_off=true)
void | set_title (const Glib::ustring& title)
| Sets the title string for the menu.
void | unset_accel_group ()
void | unset_title ()
virtual | ~Menu ()
## Protected Types
typedef void(*) | GtkMenuDetachFunc (GtkWidget* attach_widget, GtkMenu* menu)
## Protected Member Functions
void | attach_to_widget (Widget& attach_widget)
| Attaches the menu to the widget.
void | attach_to_widget (Widget& attach_widget, GtkMenuDetachFunc detacher)
## Related Functions
(Note that these are not member functions.)
Gtk::Menu* | wrap (GtkMenu* object, bool take_copy=false)
| A Glib::wrap() method for this object.

## Member Typedef Documentation

typedef void(*) Gtk::Menu::GtkMenuDetachFunc(GtkWidget* attach_widget, GtkMenu* menu)`[protected]`

typedef sigc::slot<void, int&, int&, bool&> Gtk::Menu::SlotPositionCalc

For instance, void on_popup_menu_position(int& x, int& y, bool& push_in);.

## Constructor & Destructor Documentation

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

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

## Member Function Documentation

void Gtk::Menu::attach | ( | Gtk::Widget& | child,
|  | guint | left_attach,
|  | guint | right_attach,
|  | guint | top_attach,
|  | guint | bottom_attach |
| ) |  |  |

Adds a new Gtk::MenuItem 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 detach().

Since gtkmm 2.4:

Parameters:

  | child | A Gtk::MenuItem.
  | 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.

void Gtk::Menu::attach_to_widget | ( | Widget& | attach_widget | ) | `[protected]`

Attaches the menu to the widget.

param : the Widget that the menu will be attached to.

Since gtkmm 2.10:

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

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

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

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

Return value: `true` if the menu is currently torn off.

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

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

Return value: the title of the menu, or `0` if the menu has no.

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.

Reimplemented in Gtk::RecentChooserMenu.

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

Provides access to the underlying C GtkObject.

Reimplemented from Gtk::MenuShell.

Reimplemented in Gtk::RecentChooserMenu.

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

Applications can use this function to display context-sensitive menus.

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:

  | func | A position_calc_slot supplied function used to position the menu, or `0`.
  | button | The mouse button which was pressed to initiate the event.
  | activate_time | The time at which the activation event occurred.

void Gtk::Menu::popup | ( | MenuShell& | parent_menu_shell,
|  | MenuItem& | parent_menu_item,
|  | const SlotPositionCalc& | slot,
|  | guint | button,
|  | guint32 | activate_time |
| ) |  |  |

Glib::PropertyProxy_ReadOnly<Glib::ustring> Gtk::Menu::property_tearoff_title | ( |  | ) | const

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

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.

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

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

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_monitor | ( | int | 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 Gtk::MenuPositionFunc 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 Gtk::MenuPositionFunc, since, for very long menus, these coordinates may extend beyond the monitor boundaries or even the screen boundaries.

Since gtkmm 2.4:

Parameters:

  | monitor_num | The number of the monitor on which the menu should be popped up.

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

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

Since gtkmm 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. If title is `0`, 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:

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

A Glib::wrap() method for this object.

Parameters:

  | object | The C instance.
  | take_copy | False if the result should take ownership of the C instance. True if it should take a new copy or ref.

Returns:
  A C++ instance that wraps this C instance.

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

- menu.h