xtd 0.2.0
menu.hpp
Go to the documentation of this file.
1
4#pragma once
6#include "component.hpp"
8#include "menu_item_ref.hpp"
9#include <xtd/optional>
10#include <xtd/any>
11#include <xtd/iequatable>
12#include <map>
13
15namespace xtd {
17 namespace forms {
19 class context_menu;
20 class main_menu;
22
37 class forms_export_ menu : public component, public xtd::iequatable<menu> {
38 struct data;
39 public:
41
46
48
51 static constexpr int32 find_handle = 0;
53 static constexpr int32 find_shortcut = 1;
55
57 ~menu();
59
61
66 intptr handle() const noexcept;
67
70 virtual bool is_parent() const noexcept;
71
75 const menu_item& mdi_list_item() const noexcept;
76
80 const menu_item_collection& menu_items() const noexcept;
91 menu& menu_items(const std::initializer_list<menu_item_ref>& value);
92 menu& menu_items(const std::vector<menu_item_ref>& value);
94
98 const xtd::string& name() const noexcept;
99
104 menu& name(const xtd::string& value);
105
108 const xtd::any_object& tag() const noexcept;
112 menu& tag(const xtd::any_object& value);
114
116
121 bool equals(const xtd::object& obj) const noexcept override;
125 bool equals(const menu& other) const noexcept override;
126
129 xtd::size get_hash_code() const noexcept override;
130
134 std::optional<xtd::ref<context_menu>> get_context_menu() const noexcept;
135
139 std::optional<xtd::ref<main_menu>> get_main_menu() const noexcept;
140
144 virtual void merge_menu(const menu& menu_src);
145
149 xtd::string to_string() const noexcept override;
151
152 protected:
153 friend menu_item;
154
156
164 explicit menu(const menu_item_collection& items);
166
168 explicit menu(const std::initializer_list<menu_item_ref>& items);
169 explicit menu(const std::vector<menu_item_ref>& items);
170 menu(menu&& rhs);
171 menu(const menu&) = default;
172 menu& operator =(const menu&) = default;
174
176
181 void clone_menu(const menu& menu_src);
182
186
190
191 virtual void on_item_added(size_t pos, menu_item_ref item);
192 virtual void on_item_removed(size_t pos, menu_item_ref item);
194
196 virtual void create_menu();
197 virtual void destroy_menu();
198 void recreate_menu();
199
200 xtd::sptr<data> data_;
201 static std::map<intptr, xtd::ref<menu>> handles_;
203 };
204 }
205}
Contains xtd::forms::layout::arranged_element_collection collection.
Represent a polymorphic wrapper capable of holding any type.
Definition any_object.hpp:29
component()
Initialises a new instance of the component class.
Represents a shortcut menu.
Definition context_menu.hpp:36
Represents a collection of objects.
Definition arranged_element_collection.hpp:35
Represents the menu structure of a form.
Definition main_menu.hpp:42
static constexpr int32 find_shortcut
Specifies that the find_menu_item(int32, intptr) method should search for a shortcut.
Definition menu.hpp:53
bool equals(const xtd::object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
const menu_item & mdi_list_item() const noexcept
Gets a value indicating the menu_item that is used to display a list of multiple document interface (...
void clone_menu(const menu &menu_src)
Copies the menu that is passed as a parameter to the current menu.
xtd::string to_string() const noexcept override
Returns a string that represents the menu control.
layout::arranged_element_collection< menu_item_ref > menu_item_collection
Represents a collection of menu_item objects.
Definition menu.hpp:44
static constexpr int32 find_handle
Specifies that the find_menu_item(int32, intptr) method should search for a handle.
Definition menu.hpp:51
menu()
Initializes a new instance of the Menu class.
xtd::size get_hash_code() const noexcept override
Serves as a hash function for a particular type.
virtual void merge_menu(const menu &menu_src)
Merges the MenuItem objects of one menu with the current menu.
virtual intptr create_menu_handle()=0
Creates a new handle to the Menu.
std::optional< xtd::ref< main_menu > > get_main_menu() const noexcept
Gets the main_menu that contains this menu.
const xtd::string & name() const noexcept
Gets the name of the menu.
virtual void destroy_menu_handle(intptr handle)
Destroys the handle to the Menu.
intptr handle() const noexcept
Gets a value representing the window handle for the menu.
std::optional< xtd::ref< context_menu > > get_context_menu() const noexcept
Gets the context_menu that contains this menu.
const menu_item_collection & menu_items() const noexcept
Gets a value indicating the collection of menu_item objects associated with the menu.
virtual bool is_parent() const noexcept
Gets a value indicating whether this menu contains any menu items.
const xtd::any_object & tag() const noexcept
Gets user-defined data associated with the control.
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
Contains xtd::forms::component class.
Contains xtd::forms::menu_item_ref alias.
#define forms_export_
Define shared library export.
Definition forms_export.hpp:13
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
xtd::reference_wrapper_object< type_t > ref
The xtd::ref object is a reference wrapper.
Definition ref.hpp:25
std::optional< type_t > optional
Represents the null_opt alias on std::nullopt_t.
Definition optional.hpp:175
@ other
The operating system is other.
Definition platform_id.hpp:58
xtd::ref< menu_item > menu_item_ref
Represents a menu item reference.
Definition menu_item_ref.hpp:23
@ size
Specifies that both the width and height property values of the control are defined.
Definition bounds_specified.hpp:36
Contains xtd::forms::menu_item_ref alias.
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition texts.hpp:217
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr const_pointer data() const noexcept
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:201