xtd - Reference Guide  0.1.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
Loading...
Searching...
No Matches
menu.h
Go to the documentation of this file.
1
4#pragma once
5#include <any>
6#include <map>
7#include <optional>
8#include <string>
9#include "component.h"
11
13namespace xtd {
15 namespace forms {
17 class context_menu;
18 class main_menu;
19 class menu_item;
21
32 class forms_export_ menu : public component {
33 public:
36
38 ~menu();
40
44 intptr_t handle() const {return data_->handle_;}
45
48 bool is_parent() const;
49
53 const menu_item& mdi_list_item() const;
54
58 const menu_item_collection& menu_items() const {return data_->menu_items_;}
62 menu_item_collection& menu_items() {return data_->menu_items_;}
69 menu& menu_items(const std::initializer_list<menu_item>& value);
70 menu& menu_items(const std::vector<menu_item>& value);
72
76 const xtd::ustring& name() const {return data_->name_;}
77
82 menu& name(const xtd::ustring& value) {
83 data_->name_ = value;
84 return *this;
85 }
86
89 std::any tag() const {return data_->tag_;}
93 menu& tag(std::any value) {
94 data_->tag_ = value;
95 return *this;
96 }
97
101 std::optional<context_menu> get_context_menu() const;
102
106 std::optional<main_menu> get_main_menu() const;
107
111 virtual void merge_menu(const menu& menu_src);
112
116 xtd::ustring to_string() const noexcept override;
117
119 static constexpr const int find_handle = 0;
121 static constexpr const int find_shortcut = 1;
122
124 friend std::ostream& operator<<(std::ostream& os, const xtd::forms::menu& menu) noexcept {
125 return os << menu.to_string();
126 }
128
129 protected:
136 explicit menu(const menu_item_collection& items);
138 explicit menu(const std::initializer_list<menu_item>& items);
139 explicit menu(const std::vector<menu_item>& items);
141
145 void clone_menu(const menu& menu_src);
146
149 virtual intptr_t create_menu_handle() = 0;
150
153 virtual void destroy_menu_handle(intptr_t handle) = 0;
154
156 virtual void create_menu();
157 virtual void destroy_menu();
158 void recreate_menu();
159
160 void add_handles(const menu_item_collection& menu_items);
161 void remove_handles(const menu_item_collection& menu_items);
162
163 struct data {
164 intptr_t handle_ = 0;
165 menu* owner_ = nullptr;
166 std::optional<std::reference_wrapper<menu>> context_menu_;
167 menu_item_collection menu_items_;
168 std::unique_ptr<menu_item> mdi_list_item_;
169 std::optional<std::reference_wrapper<menu>> main_menu_;
170 xtd::ustring name_;
171 std::optional<std::reference_wrapper<menu>> parent_;
172 std::any tag_;
173 xtd::event_handler on_click_;
174 void callback(xtd::forms::menu& menu) {
175 on_click_(menu, event_args::empty);
176 };
177 };
178 std::shared_ptr<data> data_;
179 static std::map<intptr_t, menu*> handles_;
181 };
182 }
183}
Contains xtd::forms::arranged_element_collection collection.
Provides the base implementation and enables object sharing between applications.
Definition: component.h:21
Represents a collection of objects.
Definition: arranged_element_collection.h:28
Represents an individual item that is displayed within a main_menu or context_menu.
Definition: menu_item.h:26
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:32
menu(const menu_item_collection &items)
Initializes a new instance of the Menu class.
menu & menu_items(const menu_item_collection &value)
Sets a value indicating the collection of menu_item objects associated with the menu.
std::optional< context_menu > get_context_menu() const
Gets the context_menu that contains this menu.
std::optional< main_menu > get_main_menu() const
Gets the main_menu that contains this menu.
const xtd::ustring & name() const
Gets the name of the menu.
Definition: menu.h:76
xtd::ustring to_string() const noexcept override
Returns a string that represents the menu control.
void clone_menu(const menu &menu_src)
Copies the menu that is passed as a parameter to the current menu.
virtual void destroy_menu_handle(intptr_t handle)=0
Destroy the handle to the Menu.
menu()
Initializes a new instance of the Menu class.
std::any tag() const
Gets user-defined data associated with the control.
Definition: menu.h:89
const menu_item & mdi_list_item() const
Gets a value indicating the menu_item that is used to display a list of multiple document interface (...
virtual void merge_menu(const menu &menu_src)
Merges the MenuItem objects of one menu with the current menu.
virtual intptr_t create_menu_handle()=0
Creates a new handle to the Menu.
menu & name(const xtd::ustring &value)
Sets the name of the menu.
Definition: menu.h:82
intptr_t handle() const
Gets a value representing the window handle for the menu.
Definition: menu.h:44
bool is_parent() const
Gets a value indicating whether this menu contains any menu items.
const menu_item_collection & menu_items() const
Gets a value indicating the collection of menu_item objects associated with the menu.
Definition: menu.h:58
menu & tag(std::any value)
Sets user-defined data associated with the control.
Definition: menu.h:93
menu_item_collection & menu_items()
Gets a value indicating the collection of menu_item objects associated with the menu.
Definition: menu.h:62
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
Contains xtd::forms::component class.
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition: event_handler.h:33
#define forms_export_
Define shared library export.
Definition: forms_export.h:13
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition: system_report.h:17