xtd 0.2.0
menu.h
Go to the documentation of this file.
1 #pragma once
6 #include "component.h"
7 #include "const_menu_item_ref.h"
8 #include "menu_item_ref.h"
9 #include <xtd/optional>
10 #include <xtd/any>
11 #include <xtd/iequatable>
12 #include <map>
13 
15 namespace xtd {
17  namespace forms {
19  class context_menu;
20  class main_menu;
22 
35  class forms_export_ menu : public component, public xtd::iequatable<menu> {
36  struct data;
37  public:
39 
44 
46 
49  static constexpr int32 find_handle = 0;
51  static constexpr int32 find_shortcut = 1;
53 
55  ~menu();
57 
59 
64  intptr handle() const noexcept;
65 
68  virtual bool is_parent() const noexcept;
69 
73  const menu_item& mdi_list_item() const noexcept;
74 
78  const menu_item_collection& menu_items() const noexcept;
82  menu_item_collection& menu_items() noexcept;
87  menu& menu_items(const menu_item_collection& value);
89  menu& menu_items(const std::initializer_list<menu_item_ref>& value);
90  menu& menu_items(const std::vector<menu_item_ref>& value);
92 
96  const xtd::ustring& name() const noexcept;
97 
102  menu& name(const xtd::ustring& value);
103 
106  std::any tag() const noexcept;
110  menu& tag(std::any value);
112 
114 
116  bool equals(const menu&) const noexcept override;
117 
121  std::optional<std::reference_wrapper<context_menu>> get_context_menu() const noexcept;
122 
126  std::optional<std::reference_wrapper<main_menu>> get_main_menu() const noexcept;
127 
131  virtual void merge_menu(const menu& menu_src);
132 
136  xtd::ustring to_string() const noexcept override;
138 
139  protected:
140  friend menu_item;
141 
143 
147  menu();
151  explicit menu(const menu_item_collection& items);
153 
155  explicit menu(const std::initializer_list<menu_item_ref>& items);
156  explicit menu(const std::vector<menu_item_ref>& items);
157  menu(menu&&) = default;
158  menu(const menu&) = delete;
160 
162 
167  void clone_menu(const menu& menu_src);
168 
171  virtual intptr create_menu_handle() = 0;
172 
175  virtual void destroy_menu_handle(intptr handle);
176 
177  virtual void on_item_added(size_t pos, menu_item_ref item);
178  virtual void on_item_removed(size_t pos, menu_item_ref item);
180 
182  virtual void create_menu();
183  virtual void destroy_menu();
184  void recreate_menu();
185 
186  std::shared_ptr<data> data_;
187  static std::map<intptr, std::reference_wrapper<menu>> handles_;
189  };
190  }
191 }
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:151
Contains xtd::forms::layout::arranged_element_collection collection.
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
Contains xtd::forms::menu_item_ref alias.
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
Represents a collection of objects.
Definition: arranged_element_collection.h:31
std::string to_string(const date_time &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: date_time.h:1063
Represents an individual item that is displayed within a main_menu or context_menu.
Definition: menu_item.h:28
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition: iequatable.h:18
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:35
int_least32_t int32
Represents a 32-bit signed integer.
Definition: types.h:129
Represents a shortcut menu.
Definition: context_menu.h:33
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
Contains xtd::forms::component class.
Represents the menu structure of a form.
Definition: main_menu.h:38
std::reference_wrapper< menu_item > menu_item_ref
Represents a menu item reference.
Definition: menu_item_ref.h:21
Provides the base implementation and enables object sharing between applications. ...
Definition: component.h:23