glibmm 2.56.0

Public Member Functions | Static Public Member Functions | Protected Member Functions | Related Functions | List of all members
Gio::MenuItem Class Reference

A menu item for use with Gio::Menu. More...

`#include <giomm/menuitem.h>`

Inheritance diagram for Gio::MenuItem:
[legend]

## Public Member Functions
| MenuItem (MenuItem&& src) noexcept
MenuItem& | operator= (MenuItem&& src) noexcept
| ~MenuItem () noexcept override
GMenuItem* | gobj ()
| Provides access to the underlying C GObject. More...
const GMenuItem* | gobj () const
| Provides access to the underlying C GObject. More...
GMenuItem* | gobj_copy ()
| Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. More...
void | set_attribute_value (const Glib::ustring& attribute, const Glib::VariantBase& value)
| Sets or unsets an attribute on menu_item. More...
void | set_attribute (const Glib::ustring& attribute, const Glib::VariantBase& value)
| Sets or unsets an attribute on menu_item. More...
Glib::RefPtr< MenuModel > | get_link (const Glib::ustring& link)
| Queries the named link on menu_item. More...
Glib::RefPtr< const MenuModel > | get_link (const Glib::ustring& link) const
| Queries the named link on menu_item. More...
void | set_link (const Glib::ustring& link, const Glib::RefPtr< MenuModel >& model)
| Creates a link from menu_item to model if non-`nullptr`, or unsets it. More...
void | set_label (const Glib::ustring& label)
| Sets or unsets the "label" attribute of menu_item. More...
void | set_submenu (const Glib::RefPtr< MenuModel >& submenu)
| Sets or unsets the "submenu" link of menu_item to submenu. More...
void | set_section (const Glib::RefPtr< MenuModel >& section)
| Sets or unsets the "section" link of menu_item to section. More...
Glib::VariantBase | get_attribute (const Glib::ustring& attribute, const Glib::VariantType& expected_type) const
| Queries the named attribute on menu_item. More...
Glib::VariantBase | get_attribute (const Glib::ustring& attribute) const
| A get_attribute() convenience overload. More...
Glib::VariantBase | get_attribute_value (const Glib::ustring& attribute, const Glib::VariantType& expected_type) const
| Queries the named attribute on menu_item. More...
Glib::VariantBase | get_attribute_value (const Glib::ustring& attribute) const
| A get_attribute_value() convenience overload. More...
void | set_action_and_target (const Glib::ustring& action)
| Unsets the target for the specified action. More...
void | set_action (const Glib::ustring& action)
| Sets the action for the menu item. More...
void | unset_target ()
| Unsets the target for the menu item. More...
void | unset_action_and_target ()
| Unsets the action and target for the menu item. More...
void | set_action_and_target (const Glib::ustring& action, const Glib::VariantBase& target_value)
| Sets or unsets the "action" and "target" attributes of menu_item. More...
void | set_detailed_action (const Glib::ustring& detailed_action)
| Sets the "action" and possibly the "target" attribute of menu_item. More...
void | set_icon (const Glib::RefPtr< Icon >& icon)
| Sets (or unsets) the icon on menu_item. More...
void | unset_icon ()
| Unset the icon on the menu item. More...
Public Member Functions inherited from Glib::Object
| Object (const Object&)=delete
Object& | operator= (const Object&)=delete
| Object (Object&& src) noexcept
Object& | operator= (Object&& src) noexcept
void* | get_data (const QueryQuark& key)
void | set_data (const Quark& key, void* data)
void | set_data (const Quark& key, void* data, DestroyNotify notify)
void | remove_data (const QueryQuark& quark)
void* | steal_data (const QueryQuark& quark)
Public Member Functions inherited from Glib::ObjectBase
| ObjectBase (const ObjectBase&)=delete
ObjectBase& | operator= (const ObjectBase&)=delete
void | set_property_value (const Glib::ustring& property_name, const Glib::ValueBase& value)
| You probably want to use a specific property_*() accessor method instead. More...
void | get_property_value (const Glib::ustring& property_name, Glib::ValueBase& value) const
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | set_property (const Glib::ustring& property_name, const PropertyType& value)
| You probably want to use a specific property_*() accessor method instead. More...
template<class PropertyType >
void | get_property (const Glib::ustring& property_name, PropertyType& value) const
| You probably want to use a specific property_*() accessor method instead. More...
void | connect_property_changed (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | connect_property_changed (const Glib::ustring& property_name, sigc::slot< void >&& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, const sigc::slot< void >& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
sigc::connection | connect_property_changed_with_return (const Glib::ustring& property_name, sigc::slot< void >&& slot)
| You can use the signal_changed() signal of the property proxy instead. More...
void | freeze_notify ()
| Increases the freeze count on object. More...
void | thaw_notify ()
| Reverts the effect of a previous call to freeze_notify(). More...
virtual void | reference () const
| Increment the reference count for this object. More...
virtual void | unreference () const
| Decrement the reference count for this object. More...
GObject* | gobj ()
| Provides access to the underlying C GObject. More...
const GObject* | gobj () const
| Provides access to the underlying C GObject. More...
GObject* | gobj_copy () const
| Give a ref-ed copy to someone. Use for direct struct access. More...
Public Member Functions inherited from sigc::trackable
| trackable () noexcept
| trackable (const trackable &src) noexcept
| trackable (trackable &&src)
| ~trackable ()
void | add_destroy_notify_callback (void *data, func_destroy_notify func) const
void | notify_callbacks ()
trackable & | operator= (const trackable &src)
trackable & | operator= (trackable &&src)
void | remove_destroy_notify_callback (void *data) const

## Static Public Member Functions
static GType | get_type ()
| Get the GType for this class, for use with the underlying GObject type system. More...
static Glib::RefPtr< MenuItem > | create (const Glib::ustring& label, const Glib::ustring& detailed_action)
static Glib::RefPtr< MenuItem > | create (const Glib::ustring& label, const Glib::RefPtr< MenuModel >& submenu)
static Glib::RefPtr< MenuItem > | create (const Glib::RefPtr< MenuModel >& submenu)
| A create() convenience overload. More...

## Protected Member Functions
| MenuItem (const Glib::ustring& label=Glib::ustring(), const Glib::ustring& detailed_action=Glib::ustring())
| Creates a new MenuItem. More...
| MenuItem (const Glib::ustring& label, const Glib::RefPtr< MenuModel >& submenu)
| Creates a new MenuItem representing a submenu. More...
| MenuItem (const Glib::RefPtr< MenuModel >& submenu)
| Creates a new MenuItem representing a submenu. More...
Protected Member Functions inherited from Glib::Object
| Object ()
| Object (const Glib::ConstructParams& construct_params)
| Object (GObject* castitem)
| ~Object () noexcept override
Protected Member Functions inherited from Glib::ObjectBase
| ObjectBase ()
| This default constructor is called implicitly from the constructor of user-derived classes, even if, for instance, Gtk::Button calls a different ObjectBase constructor. More...
| ObjectBase (const char* custom_type_name)
| A derived constructor always overrides this choice. More...
| ObjectBase (const std::type_info& custom_type_info)
| This constructor is a special feature to allow creation of derived types on the fly, without having to use g_object_new() manually. More...
| ObjectBase (ObjectBase&& src) noexcept
ObjectBase& | operator= (ObjectBase&& src) noexcept
virtual | ~ObjectBase () noexcept=0
void | initialize (GObject* castitem)
void | initialize_move (GObject* castitem, Glib::ObjectBase* previous_wrapper)

## Related Functions
(Note that these are not member functions.)
Glib::RefPtr< Gio::MenuItem > | wrap (GMenuItem* object, bool take_copy=false)
| A Glib::wrap() method for this object. More...
Related Functions inherited from Glib::Object
Glib::RefPtr< Glib::Object > | wrap (GObject* object, bool take_copy=false)

## Additional Inherited Members
Public Types inherited from Glib::Object
using | DestroyNotify = void(*)(gpointer data)
Public Types inherited from sigc::trackable
typedef internal::func_destroy_notify | func_destroy_notify

## Detailed Description

A menu item for use with Gio::Menu.

Since glibmm 2.32:

## Constructor & Destructor Documentation

## ◆ MenuItem() [1/4]

Gio::MenuItem::MenuItem | ( | MenuItem&& | src | ) |
| noexcept

## ◆ ~MenuItem()

Gio::MenuItem::~MenuItem | ( |  | ) |
| override noexcept

## ◆ MenuItem() [2/4]

Gio::MenuItem::MenuItem | ( | const Glib::ustring& | label = `Glib::ustring()`,
|  | const Glib::ustring& | detailed_action = `Glib::ustring()`
| ) |  |
| explicit protected

Creates a new MenuItem.

If label is not empty it is used to set the "label" attribute of the new item.

If detailed_action is not empty it is used to set the "action" and possibly the "target" attribute of the new item. See set_detailed_action() for more information.

Parameters

  label | The section label.
  detailed_action | The detailed action string.

## ◆ MenuItem() [3/4]

Gio::MenuItem::MenuItem | ( | const Glib::ustring& | label,
|  | const Glib::RefPtr< MenuModel >& | submenu
| ) |  |
| explicit protected

Creates a new MenuItem representing a submenu.

This is a convenience API around the MenuItem(label, detailed_action) constructor and set_submenu().

Parameters

  label | The section label.
  submenu | A MenuModel with the items of the submenu.

## ◆ MenuItem() [4/4]

Gio::MenuItem::MenuItem | ( | const Glib::RefPtr< MenuModel >& | submenu | ) |
| explicit protected

Creates a new MenuItem representing a submenu.

This is a convenience API around the MenuItem(label, detailed_action) constructor and set_submenu().

Parameters

  submenu | A MenuModel with the items of the submenu.

## Member Function Documentation

## ◆ create() [1/3]

static Glib::RefPtr<MenuItem> Gio::MenuItem::create | ( | const Glib::ustring& | label,
|  | const Glib::ustring& | detailed_action
| ) |  |
| static

## ◆ create() [2/3]

static Glib::RefPtr<MenuItem> Gio::MenuItem::create | ( | const Glib::ustring& | label,
|  | const Glib::RefPtr< MenuModel >& | submenu
| ) |  |
| static

## ◆ create() [3/3]

static Glib::RefPtr<MenuItem> Gio::MenuItem::create | ( | const Glib::RefPtr< MenuModel >& | submenu | ) |
| static

A create() convenience overload.

## ◆ get_attribute() [1/2]

Glib::VariantBase Gio::MenuItem::get_attribute | ( | const Glib::ustring& | attribute,
|  | const Glib::VariantType& | expected_type
| ) |  | const

Queries the named attribute on menu_item.

If expected_type is specified and the attribute does not have this type, `nullptr` is returned. `nullptr` is also returned if the attribute simply does not exist.

Since glibmm 2.34:

Deprecated:
  Use get_attribute_value() instead.

Parameters

  attribute | The attribute name to query.
  expected_type | The expected type of the attribute.

Returns
  The attribute value, or `nullptr`.

## ◆ get_attribute() [2/2]

Glib::VariantBase Gio::MenuItem::get_attribute | ( | const Glib::ustring& | attribute | ) | const

A get_attribute() convenience overload.

## ◆ get_attribute_value() [1/2]

Glib::VariantBase Gio::MenuItem::get_attribute_value | ( | const Glib::ustring& | attribute,
|  | const Glib::VariantType& | expected_type
| ) |  | const

Queries the named attribute on menu_item.

If expected_type is specified and the attribute does not have this type, `nullptr` is returned. `nullptr` is also returned if the attribute simply does not exist.

Since glibmm 2.34:

Parameters

  attribute | The attribute name to query.
  expected_type | The expected type of the attribute.

Returns
  The attribute value, or `nullptr`.

## ◆ get_attribute_value() [2/2]

Glib::VariantBase Gio::MenuItem::get_attribute_value | ( | const Glib::ustring& | attribute | ) | const

A get_attribute_value() convenience overload.

## ◆ get_link() [1/2]

Glib::RefPtr<MenuModel> Gio::MenuItem::get_link | ( | const Glib::ustring& | link | ) |

Queries the named link on menu_item.

Since glibmm 2.34:

Parameters

  link | The link name to query.

Returns
  The link, or `nullptr`.

## ◆ get_link() [2/2]

Glib::RefPtr<const MenuModel> Gio::MenuItem::get_link | ( | const Glib::ustring& | link | ) | const

Queries the named link on menu_item.

Since glibmm 2.34:

Parameters

  link | The link name to query.

Returns
  The link, or `nullptr`.

## ◆ get_type()

static GType Gio::MenuItem::get_type | ( |  | ) |
| static

Get the GType for this class, for use with the underlying GObject type system.

## ◆ gobj() [1/2]

GMenuItem* Gio::MenuItem::gobj | ( |  | ) |
| inline

Provides access to the underlying C GObject.

## ◆ gobj() [2/2]

const GMenuItem* Gio::MenuItem::gobj | ( |  | ) | const
| inline

Provides access to the underlying C GObject.

## ◆ gobj_copy()

GMenuItem* Gio::MenuItem::gobj_copy | ( |  | ) |

Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs.

## ◆ operator=()

MenuItem& Gio::MenuItem::operator= | ( | MenuItem&& | src | ) |
| noexcept

## ◆ set_action()

void Gio::MenuItem::set_action | ( | const Glib::ustring& | action | ) |

Sets the action for the menu item.

See set_action_and_target().

Since glibmm 2.38:

## ◆ set_action_and_target() [1/2]

void Gio::MenuItem::set_action_and_target | ( | const Glib::ustring& | action | ) |

Unsets the target for the specified action.

Deprecated:
  Use set_action() or unset_target() instead.

## ◆ set_action_and_target() [2/2]

void Gio::MenuItem::set_action_and_target | ( | const Glib::ustring& | action,
|  | const Glib::VariantBase& | target_value
| ) |  |

Sets or unsets the "action" and "target" attributes of menu_item.

If action is `nullptr` then both the "action" and "target" attributes are unset (and target_value is ignored).

If action is non-`nullptr` then the "action" attribute is set. The "target" attribute is then set to the value of target_value if it is non-`nullptr` or unset otherwise.

Normal menu items (ie: not submenu, section or other custom item types) are expected to have the "action" attribute set to identify the action that they are associated with. The state type of the action help to determine the disposition of the menu item. See Action and ActionGroup for an overview of actions.

In general, clicking on the menu item will result in activation of the named action with the "target" attribute given as the parameter to the action invocation. If the "target" attribute is not set then the action is invoked with no parameter.

If the action has no state then the menu item is usually drawn as a plain menu item (ie: with no additional decoration).

If the action has a boolean state then the menu item is usually drawn as a toggle menu item (ie: with a checkmark or equivalent indication). The item should be marked as 'toggled' or 'checked' when the boolean state is `true`.

If the action has a string state then the menu item is usually drawn as a radio menu item (ie: with a radio bullet or equivalent indication). The item should be marked as 'selected' when the string state is equal to the value of the target property.

See g_menu_item_set_action_and_target() or g_menu_item_set_detailed_action() for two equivalent calls that are probably more convenient for most uses.

Since glibmm 2.32:

Parameters

  action | The name of the action for this item.
  target_value | A Variant to use as the action target.

## ◆ set_attribute()

void Gio::MenuItem::set_attribute | ( | const Glib::ustring& | attribute,
|  | const Glib::VariantBase& | value
| ) |  |

Sets or unsets an attribute on menu_item.

The attribute to set or unset is specified by attribute. This can be one of the standard attribute names G_MENU_ATTRIBUTE_LABEL, G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, or a custom attribute name. Attribute names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.

must consist only of lowercase ASCII characters, digits and '-'.

If value is non-`nullptr` then it is used as the new value for the attribute. If value is `nullptr` then the attribute is unset. If the value Variant is floating, it is consumed.

See also g_menu_item_set_attribute() for a more convenient way to do the same.

Since glibmm 2.32:

Deprecated:
  Use set_attribute() instead.

Parameters

  attribute | The attribute to set.
  value | A Variant to use as the value, or `nullptr`.

## ◆ set_attribute_value()

void Gio::MenuItem::set_attribute_value | ( | const Glib::ustring& | attribute,
|  | const Glib::VariantBase& | value
| ) |  |

Sets or unsets an attribute on menu_item.

The attribute to set or unset is specified by attribute. This can be one of the standard attribute names G_MENU_ATTRIBUTE_LABEL, G_MENU_ATTRIBUTE_ACTION, G_MENU_ATTRIBUTE_TARGET, or a custom attribute name. Attribute names are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.

must consist only of lowercase ASCII characters, digits and '-'.

If value is non-`nullptr` then it is used as the new value for the attribute. If value is `nullptr` then the attribute is unset. If the value Variant is floating, it is consumed.

See also g_menu_item_set_attribute() for a more convenient way to do the same.

Since glibmm 2.32:

Parameters

  attribute | The attribute to set.
  value | A Variant to use as the value, or `nullptr`.

## ◆ set_detailed_action()

void Gio::MenuItem::set_detailed_action | ( | const Glib::ustring& | detailed_action | ) |

Sets the "action" and possibly the "target" attribute of menu_item.

The format of detailed_action is the same format parsed by g_action_parse_detailed_name().

See g_menu_item_set_action_and_target() or g_menu_item_set_action_and_target_value() for more flexible (but slightly less convenient) alternatives.

See also g_menu_item_set_action_and_target_value() for a description of the semantics of the action and target attributes.

Since glibmm 2.32:

Parameters

  detailed_action | The "detailed" action string.

## ◆ set_icon()

void Gio::MenuItem::set_icon | ( | const Glib::RefPtr< Icon >& | icon | ) |

Sets (or unsets) the icon on menu_item.

This call is the same as calling g_icon_serialize() and using the result as the value to g_menu_item_set_attribute_value() for G_MENU_ATTRIBUTE_ICON.

This API is only intended for use with "noun" menu items; things like bookmarks or applications in an "Open With" menu. Don't use it on menu items corresponding to verbs (eg: stock icons for 'Save' or 'Quit').

If icon is `nullptr` then the icon is unset.

Since glibmm 2.38:

Parameters

  icon | A Icon, or `nullptr`.

## ◆ set_label()

void Gio::MenuItem::set_label | ( | const Glib::ustring& | label | ) |

Sets or unsets the "label" attribute of menu_item.

If label is non-`nullptr` it is used as the label for the menu item. If it is `nullptr` then the label attribute is unset.

Since glibmm 2.32:

Parameters

  label | The label to set, or `nullptr` to unset.

## ◆ set_link()

void Gio::MenuItem::set_link | ( | const Glib::ustring& | link,
|  | const Glib::RefPtr< MenuModel >& | model
| ) |  |

Creates a link from menu_item to model if non-`nullptr`, or unsets it.

Links are used to establish a relationship between a particular menu item and another menu. For example, G_MENU_LINK_SUBMENU is used to associate a submenu with a particular menu item, and G_MENU_LINK_SECTION is used to create a section. Other types of link can be used, but there is no guarantee that clients will be able to make sense of them. Link types are restricted to lowercase characters, numbers and '-'. Furthermore, the names must begin with a lowercase character, must not end with a '-', and must not contain consecutive dashes.

Since glibmm 2.32:

Parameters

  link | Type of link to establish or unset.
  model | The MenuModel to link to (or `nullptr` to unset).

## ◆ set_section()

void Gio::MenuItem::set_section | ( | const Glib::RefPtr< MenuModel >& | section | ) |

Sets or unsets the "section" link of menu_item to section.

The effect of having one menu appear as a section of another is exactly as it sounds: the items from section become a direct part of the menu that menu_item is added to. See g_menu_item_new_section() for more information about what it means for a menu item to be a section.

Since glibmm 2.32:

Parameters

  section | A MenuModel, or `nullptr`.

## ◆ set_submenu()

void Gio::MenuItem::set_submenu | ( | const Glib::RefPtr< MenuModel >& | submenu | ) |

Sets or unsets the "submenu" link of menu_item to submenu.

If submenu is non-`nullptr`, it is linked to. If it is `nullptr` then the link is unset.

The effect of having one menu appear as a submenu of another is exactly as it sounds.

Since glibmm 2.32:

Parameters

  submenu | A MenuModel, or `nullptr`.

## ◆ unset_action_and_target()

void Gio::MenuItem::unset_action_and_target | ( |  | ) |

Unsets the action and target for the menu item.

See set_action_and_target().

Since glibmm 2.38:

## ◆ unset_icon()

void Gio::MenuItem::unset_icon | ( |  | ) |

Unset the icon on the menu item.

See set_icon().

Since glibmm 2.38:

## ◆ unset_target()

void Gio::MenuItem::unset_target | ( |  | ) |

Unsets the target for the menu item.

See set_action_and_target().

Since glibmm 2.38:

## Friends And Related Function Documentation

## ◆ wrap()

Glib::RefPtr< Gio::MenuItem > wrap | ( | GMenuItem * | 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.