xtd 0.2.0
menu_item.h
Go to the documentation of this file.
1 #pragma once
5 #include "menu.h"
6 #include "menu_item_kind.h"
7 #include "shortcut.h"
8 #include <xtd/drawing/image>
9 #include <xtd/event>
10 
12 namespace xtd {
14  namespace forms {
16  class main_menu;
17  class context_menu;
19 
28  class forms_export_ menu_item : public xtd::forms::menu {
29  struct data;
30 
31  public:
33 
37  menu_item();
42  explicit menu_item(const xtd::ustring& text);
54  menu_item(const xtd::ustring& text, const xtd::drawing::image& image);
61  menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::shortcut shortcut);
104  menu_item(const xtd::ustring& text, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
112  menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked);
121  menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
127  menu_item(const xtd::ustring& text, xtd::event_handler on_click);
134  menu_item(const xtd::ustring& text, xtd::event_handler on_click, xtd::forms::shortcut shortcut);
141  menu_item(const xtd::ustring& text, xtd::event_handler on_click, const xtd::drawing::image& image);
149  menu_item(const xtd::ustring& text, xtd::event_handler on_click, const xtd::drawing::image& image, xtd::forms::shortcut shortcut);
189  menu_item(const xtd::ustring& text, xtd::event_handler on_click, xtd::forms::menu_item_kind kind, bool checked);
198  menu_item(const xtd::ustring& text, xtd::event_handler on_click, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
207  menu_item(const xtd::ustring& text, xtd::event_handler on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked);
217  menu_item(const xtd::ustring& text, xtd::event_handler on_click, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut);
218 
220  template<typename delegate_type>
221  menu_item(const xtd::ustring& text, delegate_type on_click) : menu_item(text, xtd::event_handler(on_click)) {}
222  template<typename delegate_type>
223  menu_item(const xtd::ustring& text, delegate_type on_click, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), shortcut) {}
224  template<typename delegate_type>
225  menu_item(const xtd::ustring& text, delegate_type on_click, const xtd::drawing::image& image) : menu_item(text, xtd::event_handler(on_click), image) {}
226  template<typename delegate_type>
227  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) {}
228  template<typename delegate_type>
229  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) {}
230  template<typename delegate_type>
231  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) {}
232  template<typename delegate_type>
233  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) {}
234  template<typename delegate_type>
235  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) {}
236  template<typename delegate_type>
237  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) {}
238  template<typename delegate_type>
239  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) {}
240  menu_item(const xtd::ustring& text, const std::initializer_list<const_menu_item_ref>& items);
242 
249  menu_item(const xtd::ustring& text, const std::vector<menu_item_ref>& items);
251 
253 
257  intptr menu_id() const noexcept;
258 
261  bool checked() const noexcept;
265  menu_item& checked(bool value);
266 
269  bool enabled() const noexcept;
273  menu_item& enabled(bool value);
274 
275  bool is_parent() const noexcept override;
276 
279  xtd::forms::menu_item_kind kind() const noexcept;
284 
287  xtd::forms::shortcut shortcut() const noexcept;
292 
297  const xtd::ustring& text() const noexcept;
303  menu_item& text(const xtd::ustring& value);
305 
307 
311  void perform_click();
312 
316  xtd::ustring to_string() const noexcept override;
318 
320 
327 
328  protected:
329  friend main_menu;
330  friend context_menu;
331 
333 
335  intptr create_menu_handle() override;
336  void destroy_menu_handle(intptr handle) override;
337 
341  virtual void on_click(const event_args& e);
342 
343  void on_item_added(size_t pos, menu_item_ref item) override;
344  void on_item_removed(size_t pos, menu_item_ref item) override;
346 
347  private:
348  std::shared_ptr<data> data_;
349  };
350  }
351 }
intmax_t intptr
Represent a pointer or a handle.
Definition: types.h:151
event< menu_item, event_handler > click
Occurs when the menu item is clicked or selected using a shortcut key or access key defined for the m...
Definition: menu_item.h:325
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
generic_event_handler<> event_handler
Represents the method that will handle an event that has no event data.
Definition: event_handler.h:32
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
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:46
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
Represents an event.
Definition: event.h:21
An abstract base class that provides functionality for the bitmap and metafile descended classes...
Definition: image.h:48
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:35
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
menu_item_kind
Represent menu item kind used by xtd::forms::menu_item component.
Definition: menu_item_kind.h:19
Represents the menu structure of a form.
Definition: main_menu.h:38
shortcut
Specifies shortcut keys that can be used by menu items.
Definition: shortcut.h:21
std::reference_wrapper< menu_item > menu_item_ref
Represents a menu item reference.
Definition: menu_item_ref.h:21
The xtd::forms::status_bar_panel displays text in the standard font.
Contains xtd::forms::shortcut enum class.