gtkmm 2.24.4

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Types | Protected Member Functions | Related Functions

# Gtk::Menu Class Reference
Widgets | Menu classes

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

Inheritance diagram for Gtk::Menu:
[legend]
Collaboration diagram for Gtk::Menu:
[legend]

List of all members.

## 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
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, const SlotPositionCalc& slot, guint button, guint32 activate_time)
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 ()
| Returns the selected menu item from the menu.
const MenuItem* | get_active () const
| Returns the selected menu item from the menu.
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 ()
| menu a Gtk::Menu
Glib::RefPtr< const AccelGroup > | get_accel_group () const
| menu a Gtk::Menu
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.
Glib::ustring | get_accel_path () const
| Retrieves the accelerator path set on the menu.
void | detach ()
Widget* | get_attach_widget ()
| Returns the Gtk::Widget that the menu is attached to.
const Widget* | get_attach_widget () const
| Returns the Gtk::Widget that the menu is attached to.
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 | 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 | set_monitor (int monitor_num)
| Informs GTK+ on which monitor a menu should be popped up.
int | get_monitor () const
| Retrieves the number of the monitor on which to show the menu.
void | reorder_child (const MenuItem& child, int position)
void | set_reserve_toggle_size (bool reserve_toggle_size=true)
| Sets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence.
bool | get_reserve_toggle_size () const
| Returns whether the menu reserves space for toggles and icons, regardless of their actual presence.
Glib::PropertyProxy< int > | property_active ()
| The currently selected menu item.
Glib::PropertyProxy_ReadOnly< int > | property_active () const
| The currently selected menu item.
Glib::PropertyProxy < Glib::RefPtr< AccelGroup > > | property_accel_group ()
| The accel group holding accelerators for the menu.
Glib::PropertyProxy_ReadOnly < Glib::RefPtr< AccelGroup > > | property_accel_group () const
| The accel group holding accelerators for the menu.
Glib::PropertyProxy < Glib::ustring > | property_accel_path ()
| An accel path used to conveniently construct accel paths of child items.
Glib::PropertyProxy_ReadOnly < Glib::ustring > | property_accel_path () const
| An accel path used to conveniently construct accel paths of child items.
Glib::PropertyProxy< Widget* > | property_attach_widget ()
| The widget the menu is attached to.
Glib::PropertyProxy_ReadOnly < Widget* > | property_attach_widget () const
| The widget the menu is attached to.
Glib::PropertyProxy < Glib::ustring > | property_tearoff_title ()
| A title that may be displayed by the window manager when this menu is torn-off.
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< bool > | property_tearoff_state ()
| A boolean that indicates whether the menu is torn-off.
Glib::PropertyProxy_ReadOnly < bool > | property_tearoff_state () const
| A boolean that indicates whether the menu is torn-off.
Glib::PropertyProxy< int > | property_monitor ()
| The monitor the menu will be popped up on.
Glib::PropertyProxy_ReadOnly< int > | property_monitor () const
| The monitor the menu will be popped up on.
Glib::PropertyProxy< bool > | property_reserve_toggle_size ()
| A boolean that indicates whether the menu reserves space for toggles and icons.
Glib::PropertyProxy_ReadOnly < bool > | property_reserve_toggle_size () const
| A boolean that indicates whether the menu reserves space for toggles and icons.
## Protected Types
typedef void(* | GtkMenuDetachFunc )(GtkWidget* attach_widget, GtkMenu* menu)
## Protected Member Functions
void | attach_to_widget (Widget& attach_widget, GtkMenuDetachFunc detacher)
void | attach_to_widget (Widget& attach_widget)
| Attaches the menu to the widget.
## 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.

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

## 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,
|  | GtkMenuDetachFunc | detacher
| ) |  | `[protected]`

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::detach | ( |  | ) |

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

menu a Gtk::Menu

Gets the Gtk::AccelGroup which holds global accelerators for the menu. See set_accel_group().

Returns:
  The Gtk::AccelGroup associated with the menu.

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

menu a Gtk::Menu

Gets the Gtk::AccelGroup which holds global accelerators for the menu. See set_accel_group().

Returns:
  The Gtk::AccelGroup associated with the menu.

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

Retrieves the accelerator path set on the menu.

Since gtkmm 2.14:

Returns:
  The accelerator path set on the menu.

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

Returns the selected menu item from the menu.

This is used by the Gtk::OptionMenu.

Returns:
  The Gtk::MenuItem that was last selected in the menu. If a selection has not yet been made, the first menu item is selected.

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

Returns the selected menu item from the menu.

This is used by the Gtk::OptionMenu.

Returns:
  The Gtk::MenuItem that was last selected in the menu. If a selection has not yet been made, the first menu item is selected.

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

Returns the Gtk::Widget that the menu is attached to.

Returns:
  The Gtk::Widget that the menu is attached to.

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

Returns the Gtk::Widget that the menu is attached to.

Returns:
  The Gtk::Widget that the menu is attached to.

int Gtk::Menu::get_monitor | ( |  | ) | const

Retrieves the number of the monitor on which to show the menu.

Since gtkmm 2.14:

Returns:
  The number of the monitor on which the menu should be popped up or -1, if no monitor has been set.

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

Returns whether the menu reserves space for toggles and icons, regardless of their actual presence.

Since gtkmm 2.18:

Returns:
  Whether the menu reserves toggle space.

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.

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

Provides access to the underlying C GtkObject.

Reimplemented from Gtk::MenuShell.

Reimplemented in Gtk::RecentChooserMenu.

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

Provides access to the underlying C GtkObject.

Reimplemented from Gtk::MenuShell.

Reimplemented in Gtk::RecentChooserMenu.

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

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 | ( | 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 | ( | MenuShell& | parent_menu_shell,
|  | MenuItem& | parent_menu_item,
|  | const SlotPositionCalc & | slot,
|  | guint | button,
|  | guint32 | activate_time
| ) |  |

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

The accel group holding accelerators for the menu.

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::RefPtr<AccelGroup> > Gtk::Menu::property_accel_group | ( |  | ) |

The accel group holding accelerators for the menu.

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_ReadOnly<Glib::ustring> Gtk::Menu::property_accel_path | ( |  | ) | const

An accel path used to conveniently construct accel paths of child items.

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_accel_path | ( |  | ) |

An accel path used to conveniently construct accel paths of child items.

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<int> Gtk::Menu::property_active | ( |  | ) |

The currently selected menu item.

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_ReadOnly<int> Gtk::Menu::property_active | ( |  | ) | const

The currently selected menu item.

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<Widget*> Gtk::Menu::property_attach_widget | ( |  | ) |

The widget the menu is attached to.

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_ReadOnly<Widget*> Gtk::Menu::property_attach_widget | ( |  | ) | const

The widget the menu is attached to.

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<int> Gtk::Menu::property_monitor | ( |  | ) |

The monitor the menu will be popped up on.

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_ReadOnly<int> Gtk::Menu::property_monitor | ( |  | ) | const

The monitor the menu will be popped up on.

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<bool> Gtk::Menu::property_reserve_toggle_size | ( |  | ) |

A boolean that indicates whether the menu reserves space for toggles and icons.

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_ReadOnly<bool> Gtk::Menu::property_reserve_toggle_size | ( |  | ) | const

A boolean that indicates whether the menu reserves space for toggles and icons.

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<bool> Gtk::Menu::property_tearoff_state | ( |  | ) |

A boolean that indicates whether the 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_ReadOnly<bool> Gtk::Menu::property_tearoff_state | ( |  | ) | const

A boolean that indicates whether the 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.

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.

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, "<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::AccelMap::add_entry().

Note that accel_path string will be stored in a Quark. Therefore, if you pass a static string, you can save some memory by interning it first with Glib::intern_static_string().

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_reserve_toggle_size | ( | bool | reserve_toggle_size = `true` | ) |

Sets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence.

Since gtkmm 2.18:

Parameters:

  reserve_toggle_size | Whether to reserve size for toggles.

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:

- gtkmm/menu.h