xtd - Reference Guide  0.1.1
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Public Types | Static Public Attributes | Public Member Functions | Protected Member Functions | List of all members
xtd::forms::menu Class Referenceabstract

#include <menu.h>

Definition

Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_down_menu replace and add functionality to the menu control of previous versions, menu is retained for both backward compatibility and future use if you choose.

Namespace
xtd::forms
Library
xtd.forms
Remarks
This class is the base class for the main_menu, menu_item, and context_menu classes. You cannot create an instance of this class. The menus for an application consist of menu_item objects. These can contain other menu_item objects, representing submenu items. The menu_item objects can be stored in a main_menu for display as an entire menu structure for a form or a context_menu that is used to display shortcut menus. This class provides functionality that is common for all the menu classes.
Unlike many base classes, the menu class uses its derived classes to define many of its properties. If you are using your menu in a multiple-document interface (MDI) application, you can use the mdi_list_item property to specify a menu_item that displays a list of open MDI child forms in your application. The menu_items property contains a list of menu_item objects stored in the menu class. For a main_menu or context_menu, this property contains all the menu_item objects that are displayed. For a menu_item, the menu_items property represents the submenu items associated with it.
In addition to the properties that are provided for all the derived menu classes, the menu class also provides methods, such as clone_menu and merge_menu, that enable you to create new menus from existing menus, and also merge two menu structures together.
The menu class also defines the nested class menu::menu_item_collection. This class defines the collection of menu_item objects used by the menu_items property. You can use the methods of the menu::menu_item_collection class to add and remove menu items from a main_menu, context_menu, or menu_item.

Inherits xtd::forms::component.

Inherited by xtd::forms::context_menu, xtd::forms::main_menu, and xtd::forms::menu_item.

Public Types

using menu_item_collection = layout::arranged_element_collection< menu_item >
 Represents a collection of menu_item objects. More...
 

Static Public Attributes

static constexpr const int find_handle
 Specifies that the find_menu_item(int32_t, intptr_t) method should search for a handle. More...
 
static constexpr const int find_shortcut
 Specifies that the find_menu_item(int32_t, intptr_t) method should search for a shortcut. More...
 

Public Member Functions

std::optional< context_menuget_context_menu () const
 Gets the context_menu that contains this menu. More...
 
std::optional< main_menuget_main_menu () const
 Gets the main_menu that contains this menu. More...
 
intptr_t handle () const
 Gets a value representing the window handle for the menu. More...
 
bool is_parent () const
 Gets a value indicating whether this menu contains any menu items. More...
 
const menu_itemmdi_list_item () const
 Gets a value indicating the menu_item that is used to display a list of multiple document interface (MDI) child forms. More...
 
menu_item_collectionmenu_items ()
 Gets a value indicating the collection of menu_item objects associated with the menu. More...
 
const menu_item_collectionmenu_items () const
 Gets a value indicating the collection of menu_item objects associated with the menu. More...
 
menumenu_items (const menu_item_collection &value)
 Sets a value indicating the collection of menu_item objects associated with the menu. More...
 
virtual void merge_menu (const menu &menu_src)
 Merges the MenuItem objects of one menu with the current menu. More...
 
const xtd::ustringname () const
 Gets the name of the menu. More...
 
menuname (const xtd::ustring &value)
 Sets the name of the menu. More...
 
std::any tag () const
 Gets user-defined data associated with the control. More...
 
menutag (std::any value)
 Sets user-defined data associated with the control. More...
 
xtd::ustring to_string () const noexcept override
 Returns a string that represents the menu control. More...
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object. More...
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object. More...
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type. More...
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance. More...
 

Protected Member Functions

 menu ()
 Initializes a new instance of the Menu class. More...
 
 menu (const menu_item_collection &items)
 Initializes a new instance of the Menu class. More...
 
void clone_menu (const menu &menu_src)
 Copies the menu that is passed as a parameter to the current menu. More...
 
virtual intptr_t create_menu_handle ()=0
 Creates a new handle to the Menu. More...
 
virtual void destroy_menu_handle (intptr_t handle)=0
 Destroy the handle to the Menu. More...
 
- Protected Member Functions inherited from xtd::forms::component
 component ()=default
 Initialises a new instance of the component class. More...
 
virtual bool can_raise_events () const
 Gets a value indicating whether the component can raise an event. More...
 
bool design_mode () const
 Gets a value that indicates whether the component is currently in design mode. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal. More...
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance. More...
 

Member Typedef Documentation

◆ menu_item_collection

Represents a collection of menu_item objects.

Constructor & Destructor Documentation

◆ menu() [1/2]

xtd::forms::menu::menu ( )
protected

Initializes a new instance of the Menu class.

Remarks
Since menu is an abstract class, only inherited classes can call the menu constructor.

◆ menu() [2/2]

xtd::forms::menu::menu ( const menu_item_collection items)
explicitprotected

Initializes a new instance of the Menu class.

Parameters
itemsAn array of type MenuItem containing the objects to add to the menu.
Remarks
Since menu is an abstract class, only inherited classes can call the menu constructor.

Member Function Documentation

◆ clone_menu()

void xtd::forms::menu::clone_menu ( const menu menu_src)
protected

Copies the menu that is passed as a parameter to the current menu.

Parameters
menu_srcThe Menu to copy.
Remarks
This method copies the entire list of menuItem objects (stored in the menu passed in to menu_src) into the current menu. You can use this method in your derived class to clone menu_item objects. They can then be reused by other classes that derive from menu, such as main_menu, context_menu, and menu_item.

◆ create_menu_handle()

virtual intptr_t xtd::forms::menu::create_menu_handle ( )
protectedpure virtual

Creates a new handle to the Menu.

Returns
A handle to the menu if the method succeeds; otherwise, 0.

Implemented in xtd::forms::menu_item, xtd::forms::main_menu, and xtd::forms::context_menu.

◆ destroy_menu_handle()

virtual void xtd::forms::menu::destroy_menu_handle ( intptr_t  handle)
protectedpure virtual

Destroy the handle to the Menu.

Parameters
handleA handle to the menu.

Implemented in xtd::forms::menu_item, xtd::forms::main_menu, and xtd::forms::context_menu.

◆ get_context_menu()

std::optional<context_menu> xtd::forms::menu::get_context_menu ( ) const

Gets the context_menu that contains this menu.

Returns
The context_menu that contains this menu. The default is no value.
Remarks
This method allows you to obtain a reference to the context_menu that this menu is contained in. This property returns no value if the menu is not contained in a context_menu. This can occur if the menu is contained in a menu_item or main_menu, or if the menu is not contained in any menu. You can use this property to determine whether a menu is currently being used, and also to determine where.

◆ get_main_menu()

std::optional<main_menu> xtd::forms::menu::get_main_menu ( ) const

Gets the main_menu that contains this menu.

Returns
The main_menu that contains this menu. The default is has no value.
Remarks
This method allows you to obtain a reference to the main_menu that this menu is contained in. This property returns no value if the menu is not contained in a main_menu. This can occur if the menu is contained in a menu_item or context_menu, or if the menu is not contained in any menu. You can use this property to determine whether a menu is currently being used, and also to determine where.

◆ handle()

intptr_t xtd::forms::menu::handle ( ) const
inline

Gets a value representing the window handle for the menu.

Returns
The HMENU value of the menu.
Remarks
You can use this property to obtain the handle to the menu to perform special operations to the menu outside of the functionality provided by this class or its derived classes.

◆ is_parent()

bool xtd::forms::menu::is_parent ( ) const

Gets a value indicating whether this menu contains any menu items.

Returns
true if this menu contains menu_item objects; otherwise, false. The default is false.

◆ mdi_list_item()

const menu_item& xtd::forms::menu::mdi_list_item ( ) const

Gets a value indicating the menu_item that is used to display a list of multiple document interface (MDI) child forms.

Returns
A MenuItem that represents the menu item displaying a list of MDI child forms that are open in the application.
Remarks
You can use this property to determine whether a menu_item has been specified to display the list of open child windows in an MDI application. To use a specific menu_item as an MDI list, set the mdi_list property in the menu_item to be used.

◆ menu_items() [1/3]

menu_item_collection& xtd::forms::menu::menu_items ( )
inline

Gets a value indicating the collection of menu_item objects associated with the menu.

Returns
A menu::menu_item_collection that represents the list of menu_item objects stored in the menu.
Remarks
You can use this property to obtain a reference to the list of menu items that are currently stored in the menu. For main_menu and context_menu objects, the menu_items property contains the entire menu structure in the control. For the menu_item class, the menu_items property contains the list of submenu items associated with the menu_item. With the reference to the collection of menu items for the menu (provided by this property), you can add and remove menu items, determine the total number of menu items, and clear the list of menu items from the collection. For more information on maintaining the menu item collection for a menu, see the xtd::forms::menu::menu_item_collection documentation.

◆ menu_items() [2/3]

const menu_item_collection& xtd::forms::menu::menu_items ( ) const
inline

Gets a value indicating the collection of menu_item objects associated with the menu.

Returns
A menu::menu_item_collection that represents the list of menu_item objects stored in the menu.
Remarks
You can use this property to obtain a reference to the list of menu items that are currently stored in the menu. For main_menu and context_menu objects, the menu_items property contains the entire menu structure in the control. For the menu_item class, the menu_items property contains the list of submenu items associated with the menu_item. With the reference to the collection of menu items for the menu (provided by this property), you can add and remove menu items, determine the total number of menu items, and clear the list of menu items from the collection. For more information on maintaining the menu item collection for a menu, see the xtd::forms::menu::menu_item_collection documentation.

◆ menu_items() [3/3]

menu& xtd::forms::menu::menu_items ( const menu_item_collection value)

Sets a value indicating the collection of menu_item objects associated with the menu.

Parameters
valueA menu::menu_item_collection that represents the list of menu_item objects stored in the menu.
Returns
Current menu class.
Remarks
You can use this property to obtain a reference to the list of menu items that are currently stored in the menu. For main_menu and context_menu objects, the menu_items property contains the entire menu structure in the control. For the menu_item class, the menu_items property contains the list of submenu items associated with the menu_item. With the reference to the collection of menu items for the menu (provided by this property), you can add and remove menu items, determine the total number of menu items, and clear the list of menu items from the collection. For more information on maintaining the menu item collection for a menu, see the xtd::forms::menu::menu_item_collection documentation.

◆ merge_menu()

virtual void xtd::forms::menu::merge_menu ( const menu menu_src)
virtual

Merges the MenuItem objects of one menu with the current menu.

Parameters
menu_srcThe menu whose menu items are merged with the menu items of the current menu.
Exceptions
std::invalid_argumentIt was attempted to merge the menu with itself.

◆ name() [1/2]

const xtd::ustring& xtd::forms::menu::name ( ) const
inline

Gets the name of the menu.

Returns
A string representing the name.
Remarks
At design time, this property is set to the programmatic identifier of the control. However, this property has no bearing on the control at run time.

◆ name() [2/2]

menu& xtd::forms::menu::name ( const xtd::ustring value)
inline

Sets the name of the menu.

Parameters
valueA string representing the name.
Returns
Current menu class.
Remarks
At design time, this property is set to the programmatic identifier of the control. However, this property has no bearing on the control at run time.

◆ tag() [1/2]

std::any xtd::forms::menu::tag ( ) const
inline

Gets user-defined data associated with the control.

Returns
An object representing the data.

◆ tag() [2/2]

menu& xtd::forms::menu::tag ( std::any  value)
inline

Sets user-defined data associated with the control.

Parameters
valueAn object representing the data.
Returns
Current menu class.

◆ to_string()

xtd::ustring xtd::forms::menu::to_string ( ) const
overridevirtualnoexcept

Returns a string that represents the menu control.

Returns
A string that represents the current menu.
Remarks
The to_string method returns a string that includes the type and the number of items in the menu_items property of the control.

Reimplemented from xtd::object.

Reimplemented in xtd::forms::menu_item.

Member Data Documentation

◆ find_handle

constexpr const int xtd::forms::menu::find_handle
staticconstexpr

Specifies that the find_menu_item(int32_t, intptr_t) method should search for a handle.

◆ find_shortcut

constexpr const int xtd::forms::menu::find_shortcut
staticconstexpr

Specifies that the find_menu_item(int32_t, intptr_t) method should search for a shortcut.


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