Xfce Foundation Classes
Main Page | Index | Namespace List | Alphabetical List | Class List | File List

# Xfc::Gtk::MenuItem Class Reference

A GtkMenuItem C++ wrapper class. More...

`#include <xfc/gtk/menuitem.hh>`

Inheritance diagram for Xfc::Gtk::MenuItem:

List of all members.

## Signal Prototypes

- const ActivateSignalType activate_signal
    Activate signal (see signal_activate()).
- const ActivateItemSignalType activate_item_signal
    Activate item signal (see signal_activate_item()).
- const ToggleSizeRequestSignalType toggle_size_request_signal
    Toggle size request signal (see signal_toggle_size_request()).
- const ToggleSizeAllocateSignalType toggle_size_allocate_signal
    Toggle size allocate signal (see signal_toggle_size_allocate()).

## Public Member Functions

Constructors

- MenuItem ()
    Construct a new MenuItem.
- MenuItem (const String &label, bool use_underline=false)
    Construct a new MenuItem whose child is a Label.
- MenuItem (const String &label, Menu &submenu, bool use_underline=false)
    Construct a new MenuItem that pops up a submenu.
- virtual ~MenuItem ()
    Destructor.

Accessors

- GtkMenuItem * gtk_menu_item () const
    Get a pointer to the GtkMenuItem structure.
- operator GtkMenuItem * () const
    Conversion operator; safely converts a MenuItem to a GtkMenuItem pointer.
- bool has_submenu () const
    Returns true if the menu item displays a submenu.
- bool get_right_justified () const
    Gets whether the menu item appears justified at the right side of the menu bar.
- Menu * get_submenu () const
    Gets the submenu underneath this menu item, if any (see set_submenu()).

Methods

- void set_label (const String &label, bool use_underline=false)
    Sets the label text to label.
- void set_submenu (Menu &submenu)
    Sets the widget submenu, or changes it.
- void remove_submenu ()
    Removes the widget's submenu.
- void activate ()
    Emits the "activate" signal on the given item.
- void toggle_size_request (int *requisition)
    Emits the "toggle_size_request" signal on the menu item.
- void toggle_size_allocate (int allocation)
    Emits the "toggle_size_allocate" signal on the menu item.
- void set_right_justified (bool right_justified)
    Sets whether the menu item appears justified at the right side of a menu bar.
- void set_accel_path (const String &accel_path)
    Set the accelerator path on the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persistant storage (see Gtk::AccelMap::save() on this).

Signal Proxies

- const ActivateSignalProxy signal_activate ()
    Connect to the activate_signal; emitted when the menu item is activated.
- const ActivateItemSignalProxy signal_activate_item ()
    Connect to the activate_item_signal; emitted when the item is activated, but also if the menu item has a submenu.
- const ToggleSizeRequestSignalProxy signal_toggle_size_request ()
    Connect to the toggle_size_request_signal; emitted when MenuBar or Menu requests the size of the toggle.
- const ToggleSizeAllocateSignalProxy signal_toggle_size_allocate ()
    Connect to the toggle_size_allocate_signal; emitted when MenuBar or Menu allocates a size for the toggle.

## Protected Member Functions

Contructors

- MenuItem (GtkMenuItem *menu_item, bool owns_reference=false)
    Construct a new MenuItem from an existing GtkMenuItem.

Methods

- void add_label (const String &label, bool use_underline)
    Adds a label widget to an empty menu item with the text label.

## Detailed Description

A GtkMenuItem C++ wrapper class.

The MenuItem widget and its derived widgets are the only valid child widgets for menus. Their function is to correctly handle highlighting, alignment, events and submenus. As MenuItem derives from Bin it can hold any valid child widget, although only a few are really useful.

See also: the MenuItem and Menu HOWTOs and example.

## Constructor & Destructor Documentation

Xfc::Gtk::MenuItem::MenuItem | ( | GtkMenuItem * | menu_item,
|  | bool | owns_reference = `false`
| ) | `[explicit, protected]`

Construct a new MenuItem from an existing GtkMenuItem.

Parameters:

  | menu_item | A pointer to a GtkMenuItem.
  | owns_reference | Set false if the initial reference count is floating, set true if it's not.

The menu_item can be a newly created GtkMenuItem or an existing GtkMenuItem (see G::Object::Object).

Xfc::Gtk::MenuItem::MenuItem | ( | const String & | label,
|  | bool | use_underline = `false`
| ) | `[explicit]`

Construct a new MenuItem whose child is a Label.

Parameters:

  | label | The text for the label.
  | use_underline | Set true if there is an underscore in front of the mnemonic character.

Xfc::Gtk::MenuItem::MenuItem | ( | const String & | label,
|  | Menu & | submenu,
|  | bool | use_underline = `false`
| ) |

Construct a new MenuItem that pops up a submenu.

Parameters:

  | label | The text for the label.
  | submenu | The submenu.
  | use_underline | Set true if there is an underscore in front of the mnemonic character.

## Member Function Documentation

void Xfc::Gtk::MenuItem::add_label | ( | const String & | label,
|  | bool | use_underline
| ) | `[protected]`

Adds a label widget to an empty menu item with the text label.

Parameters:

  | label | The text for the label.
  | use_underline | Set true if there is an underscore in front of the mnemonic character.

This method is used by the derived menu item widgets such as CheckMenuItem and ImageMenuItem. You probably wont find much use for it.

bool Xfc::Gtk::MenuItem::get_right_justified | ( |  | ) | const

Gets whether the menu item appears justified at the right side of the menu bar.

Returns:
  true if the menu item will appear at the far right if added to a menu bar.

Menu* Xfc::Gtk::MenuItem::get_submenu | ( |  | ) | const

Gets the submenu underneath this menu item, if any (see set_submenu()).

Returns:
  The submenu for this menu item, or null if there is none.

void Xfc::Gtk::MenuItem::set_accel_path | ( | const String & | accel_path | ) |

Set the accelerator path on the menu item, through which runtime changes of the menu item's accelerator caused by the user can be identified and saved to persistant storage (see Gtk::AccelMap::save() on this).

Parameters:

  | accel_path | The accelerator path, corresponding to this menu item's functionality, or null to unset the current path.

To setup a default accelerator for this menu item, call Gtk::AccelMap::add_entry() with the same accel_path. See also Gtk::AccelMap::add_entry() on the specifics of accelerator paths, and Gtk::Menu::set_accel_path() for a more convenient variant of this function.

This Method is basically a convenience wrapper that handles calling Gtk::Widget::set_accel_path() with the appropriate accelerator group for the menu item. Note that you do need to set an accelerator group on the parent menu at construction or later with Gtk::Menu::set_accel_group() for this to work.

void Xfc::Gtk::MenuItem::set_label | ( | const String & | label,
|  | bool | use_underline = `false`
| ) |

Sets the label text to label.

Parameters:

  | label | The text for the label.
  | use_underline | Set true if there is an underscore in front of the mnemonic character.

This method can be used to dynamically change the menu item text. If the menu item is empty, a label widget is added with the text label.

void Xfc::Gtk::MenuItem::set_right_justified | ( | bool | right_justified | ) |

Sets whether the menu item appears justified at the right side of a menu bar.

Parameters:

  | right_justified | If true the menu item will appear at the far right if added to a menu bar. This was traditionally done for "Help" menu items, but is now considered a bad idea. If the widget layout is reversed for a right-to-left language like Hebrew or Arabic, right-justified-menu-items appear at the left.

void Xfc::Gtk::MenuItem::set_submenu | ( | Menu & | submenu | ) |

Sets the widget submenu, or changes it.

Parameters:

  | submenu | The submenu.

const ActivateItemSignalProxy Xfc::Gtk::MenuItem::signal_activate_item | ( |  | ) |

| Connect to the activate_item_signal; emitted when the item is activated, but also if the menu item has a submenu. For normal applications, the relevant signal is "activate".

## Member Data Documentation

const ActivateItemSignalType Xfc::Gtk::MenuItem::activate_item_signal `[static, protected]`

Activate item signal (see signal_activate_item()).

Calls a slot with the signature:

                 void function();

const ActivateSignalType Xfc::Gtk::MenuItem::activate_signal `[static, protected]`

Activate signal (see signal_activate()).

Calls a slot with the signature:

                 void function();

const ToggleSizeAllocateSignalType Xfc::Gtk::MenuItem::toggle_size_allocate_signal `[static, protected]`

Toggle size allocate signal (see signal_toggle_size_allocate()).

Calls a slot with the signature:

                 void function(int allocate);
                 // allocate: The size allocated to the toggle.

const ToggleSizeRequestSignalType Xfc::Gtk::MenuItem::toggle_size_request_signal `[static, protected]`

Toggle size request signal (see signal_toggle_size_request()).

Calls a slot with the signature:

                 void function(int *requisition);
                 // requisition: The return location for the size of the toggle.

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

- menuitem.hh

Xfce Foundation Classes

Copyright © 2004-2005 The XFC Development Team | XFC 4.3