xtd - Reference Guide  0.2.0
Modern c++17/20 framework to create console, GUI and unit test applications on Windows, macOS, Linux, iOS and android.
menu_item.h
Go to the documentation of this file.
1 #pragma once
5 #include <string>
6 #include <xtd/drawing/image.h>
7 #include "menu.h"
8 #include "menu_item_kind.h"
9 #include "shortcut.h"
10 
12 namespace xtd {
14  namespace forms {
16  class main_menu;
17  class context_menu;
19 
26  class forms_export_ menu_item : public xtd::forms::menu {
27  public:
30  menu_item();
35  menu_item(const xtd::ustring& text);
47  menu_item(const xtd::ustring& text, const xtd::drawing::image& image);
54  menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::shortcut shortcut);
97  menu_item(const xtd::ustring& text, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
105  menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked);
114  menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
115 
121  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click);
128  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, xtd::forms::shortcut shortcut);
135  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image);
143  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image, xtd::forms::shortcut shortcut);
150  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, xtd::forms::menu_item_kind kind);
158  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, xtd::forms::menu_item_kind kind, xtd::forms::shortcut shortcut);
166  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind);
175  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, xtd::forms::shortcut shortcut);
183  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, xtd::forms::menu_item_kind kind, bool checked);
192  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
201  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked);
211  menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
212 
214  template<typename delegate_type>
215  menu_item(const xtd::ustring& text, delegate_type on_click) : menu_item(text, xtd::event_handler(on_click)) {}
216  template<typename delegate_type>
217  menu_item(const xtd::ustring& text, delegate_type on_click, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), shortcut) {}
218  template<typename delegate_type>
219  menu_item(const xtd::ustring& text, delegate_type on_click, const xtd::drawing::image& image) : menu_item(text, xtd::event_handler(on_click), image) {}
220  template<typename delegate_type>
221  menu_item(const xtd::ustring& text, delegate_type on_click, const xtd::drawing::image& image, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), image, shortcut) {}
222  template<typename delegate_type>
223  menu_item(const xtd::ustring& text, delegate_type on_click, xtd::forms::menu_item_kind kind) : menu_item(text, xtd::event_handler(on_click), kind) {}
224  template<typename delegate_type>
225  menu_item(const xtd::ustring& text, delegate_type on_click, xtd::forms::menu_item_kind kind, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), kind, shortcut) {}
226  template<typename delegate_type>
227  menu_item(const xtd::ustring& text, delegate_type on_click, xtd::forms::menu_item_kind kind, bool checked) : menu_item(text, xtd::event_handler(on_click), kind, checked) {}
228  template<typename delegate_type>
229  menu_item(const xtd::ustring& text, delegate_type on_click, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), kind, checked, shortcut) {}
230  template<typename delegate_type>
231  menu_item(const xtd::ustring& text, delegate_type on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked) : menu_item(text, xtd::event_handler(on_click), image, kind, checked) {}
232  template<typename delegate_type>
233  menu_item(const xtd::ustring& text, delegate_type on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), image, kind, checked, shortcut) {}
235 
242  menu_item(const xtd::ustring& text, const std::vector<menu_item_ref>& items);
243 
245  menu_item(const xtd::ustring& text, const std::initializer_list<const_menu_item_ref>& items);
247 
250  int32_t menu_id() const;
251 
254  bool checked() const {return checked_;}
258  menu_item& checked(bool value);
259 
262  bool enabled() const {return enabled_;}
266  menu_item& enabled(bool value);
267 
268  bool is_parent() const override;
269 
272  xtd::forms::menu_item_kind kind() const {return kind_;}
277 
280  xtd::forms::shortcut shortcut() const {return shortcut_;}
285 
290  const xtd::ustring& text() const {return text_;}
296  menu_item& text(const xtd::ustring& value);
297 
301  xtd::ustring to_string() const noexcept override;
302 
303  protected:
304  friend main_menu;
305  friend context_menu;
306 
307  intptr_t create_menu_handle() override;
308  void destroy_menu_handle(intptr_t handle) override;
309 
310  void on_item_added(size_t pos, menu_item_ref item) override;
311  void on_item_removed(size_t pos, menu_item_ref item) override;
312 
314  xtd::ustring text_;
315  xtd::drawing::image image_ = xtd::drawing::image::empty;
317  bool checked_ = false;
319  bool enabled_ = true;
320  bool is_parent_ = false;
322  };
323  }
324 }
The default appearance defined by the control class.
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition: event_handler.h:33
The button has a checked or latched appearance. Use this appearance to show that a toggle button has ...
The xtd namespace contains all fundamental classes to access Hardware, Os, System, and more.
Definition: system_report.h:17
bool checked() const
Gets a value indicating whether a check mark appears next to the text of the menu item...
Definition: menu_item.h:254
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
No shortcut key is associated with the menu item.
const xtd::ustring & text() const
Gets a value indicating the caption of the menu item.
Definition: menu_item.h:290
Contains xtd::drawing::image class.
Represents an individual item that is displayed within a main_menu or context_menu.
Definition: menu_item.h:26
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:34
xtd::forms::menu_item_kind kind() const
Gets a value that represents the kind of menu item.
Definition: menu_item.h:272
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:49
xtd::forms::shortcut shortcut() const
Gets a value indicating the shortcut key associated with the menu item.
Definition: menu_item.h:280
bool enabled() const
Gets a value indicating whether the menu item is enabled.
Definition: menu_item.h:262
Represents a shortcut menu.
Definition: context_menu.h:22
The xtd::forms namespace contains classes for creating Windows-based applications that take full adva...
Definition: about_box.h:13
menu_item_kind
Represent menu item kind used by xtd::forms::menu_item component.
Definition: menu_item_kind.h:17
Represents the menu structure of a form.
Definition: main_menu.h:32
shortcut
Specifies shortcut keys that can be used by menu items.
Definition: shortcut.h:19
std::reference_wrapper< menu_item > menu_item_ref
Represents a menu item reference.
Definition: menu.h:29
Contains xtd::forms::shortcut enum class.
std::string to_string(const value_t &value, const std::string &fmt, const std::locale &loc)
Convert a specified value into a string with specified format and locale.
Definition: to_string.h:37