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_item.h
Go to the documentation of this file.
1
4#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
12namespace xtd {
14 namespace forms {
16 class main_menu;
17 class context_menu;
19
27 public:
35 menu_item(const xtd::ustring& text);
47 menu_item(const xtd::ustring& text, const xtd::drawing::image& image);
89 menu_item(const xtd::ustring& text, xtd::forms::menu_item_kind kind, bool checked);
105 menu_item(const xtd::ustring& text, const xtd::drawing::image& image, xtd::forms::menu_item_kind kind, bool checked);
115
121 menu_item(const xtd::ustring& text, const xtd::event_handler& on_click);
135 menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, const xtd::drawing::image& image);
183 menu_item(const xtd::ustring& text, const xtd::event_handler& on_click, xtd::forms::menu_item_kind kind, bool checked);
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);
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>& items);
243
246 int32_t menu_id() const;
247
250 bool checked() const {return checked_;}
254 menu_item& checked(bool value) {
255 if (checked_ != value) {
256 checked_ = value;
257 on_menu_item_updated(event_args::empty);
258 }
259 return *this;
260 }
261
264 bool enabled() const {return enabled_;}
268 menu_item& enabled(bool value) {
269 if (enabled_ != value) {
270 enabled_ = value;
271 on_menu_item_updated(event_args::empty);
272 }
273 return *this;
274 }
275
278 xtd::forms::menu_item_kind kind() const {return kind_;}
283 if (kind_ != value) {
284 kind_ = value;
285 on_menu_item_updated(event_args::empty);
286 }
287 return *this;
288 }
289
292 xtd::forms::shortcut shortcut() const {return shortcut_;}
297 if (shortcut_ != value) {
298 shortcut_ = value;
299 on_menu_item_updated(event_args::empty);
300 }
301 return *this;
302 }
303
308 const xtd::ustring& text() const {return text_;}
314 menu_item& text(const xtd::ustring& value) {
315 if (text_ != value) {
316 text_ = value;
317 on_menu_item_updated(event_args::empty);
318 }
319 return *this;
320 }
321
325 xtd::ustring to_string() const noexcept override;
326
327 protected:
328 friend main_menu;
329 friend context_menu;
330
331 intptr_t create_menu_handle() override;
332 void destroy_menu_handle(intptr_t handle) override;
333
334 virtual void on_menu_item_updated(const event_args& e) {}
335
337 xtd::ustring text_;
338 xtd::drawing::image image_ = xtd::drawing::image::empty;
340 bool checked_ = false;
342 bool enabled_ = true;
344 };
345 }
346}
An abstract base class that provides functionality for the bitmap and metafile descended classes.
Definition: image.h:34
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
Represents a shortcut menu.
Definition: context_menu.h:17
Represents the menu structure of a form.
Definition: main_menu.h:30
Represents an individual item that is displayed within a main_menu or context_menu.
Definition: menu_item.h:26
xtd::forms::menu_item_kind kind() const
Gets a value that represents the kind of menu item.
Definition: menu_item.h:278
menu_item(const xtd::ustring &text, xtd::forms::menu_item_kind kind)
Initializes a new instance of the class with a specified caption, and kind the menu item.
menu_item & checked(bool value)
Sets a value indicating whether a check mark appears next to the text of the menu item.
Definition: menu_item.h:254
menu_item(const xtd::ustring &text, const xtd::drawing::image &image, xtd::forms::menu_item_kind kind, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, image menu item,...
menu_item(const xtd::ustring &text, const xtd::drawing::image &image, xtd::forms::menu_item_kind kind, bool checked)
Initializes a new instance of the class with a specified caption, image menu item,...
int32_t menu_id() const
Gets a value indicating the Windows identifier for this menu item.
xtd::ustring to_string() const noexcept override
Returns a string that represents the menu control.
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, const xtd::drawing::image &image, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, event handler, and image menu item,...
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)
Initializes a new instance of the class with a specified caption, event handler, image menu item,...
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, xtd::forms::menu_item_kind kind)
Initializes a new instance of the class with a specified caption, event handler, and kind the menu it...
menu_item & enabled(bool value)
Gets a value indicating whether the menu item is enabled.
Definition: menu_item.h:268
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click)
Initializes a new instance of the class with a specified caption and event handler for the Click even...
menu_item(const xtd::ustring &text)
Initializes a new instance of the menu_item class with a specified caption for the menu item.
const xtd::ustring & text() const
Gets a value indicating the caption of the menu item.
Definition: menu_item.h:308
menu_item()
Initializes a menu_item with a blank caption.
xtd::forms::shortcut shortcut() const
Gets a value indicating the shortcut key associated with the menu item.
Definition: menu_item.h:292
menu_item(const xtd::ustring &text, const std::vector< menu_item > &items)
Initializes a new instance of the class with a specified caption and an array of submenu items define...
menu_item(const xtd::ustring &text, xtd::forms::menu_item_kind kind, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, kind the menu item,...
menu_item & shortcut(xtd::forms::shortcut value)
Sets a value indicating the shortcut key associated with the menu item.
Definition: menu_item.h:296
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)
Initializes a new instance of the class with a specified caption, event handler, image menu item,...
menu_item & kind(xtd::forms::menu_item_kind value)
Gets a value that represents the kind of menu item.
Definition: menu_item.h:282
menu_item(const xtd::ustring &text, const xtd::drawing::image &image, xtd::forms::menu_item_kind kind)
Initializes a new instance of the class with a specified caption, image menu item,...
menu_item(const xtd::ustring &text, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, and associated shortcut key for the...
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, event handler, and associated short...
menu_item(const xtd::ustring &text, const xtd::drawing::image &image)
Initializes a new instance of the class with a specified caption, and image menu item.
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, const xtd::drawing::image &image)
Initializes a new instance of the class with a specified caption, event handler, and image menu item.
menu_item(const xtd::ustring &text, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, kind the menu item,...
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)
Initializes a new instance of the class with a specified caption, event handler, image menu item,...
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, event handler, kind the menu item,...
bool enabled() const
Gets a value indicating whether the menu item is enabled.
Definition: menu_item.h:264
menu_item & text(const xtd::ustring &value)
Sets a value indicating the caption of the menu item.
Definition: menu_item.h:314
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, xtd::forms::menu_item_kind kind, bool checked)
Initializes a new instance of the class with a specified caption, event handler, kind the menu item a...
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, const xtd::drawing::image &image, xtd::forms::menu_item_kind kind)
Initializes a new instance of the class with a specified caption, event handler, image menu item,...
menu_item(const xtd::ustring &text, const xtd::drawing::image &image, xtd::forms::menu_item_kind kind, bool checked, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, image menu item,...
menu_item(const xtd::ustring &text, const xtd::drawing::image &image, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, and image menu item,...
bool checked() const
Gets a value indicating whether a check mark appears next to the text of the menu item.
Definition: menu_item.h:250
menu_item(const xtd::ustring &text, xtd::forms::menu_item_kind kind, bool checked)
Initializes a new instance of the class with a specified caption, kind the menu item and checked.
menu_item(const xtd::ustring &text, const xtd::event_handler &on_click, xtd::forms::menu_item_kind kind, xtd::forms::shortcut shortcut)
Initializes a new instance of the class with a specified caption, event handler, kind the menu item,...
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:32
Represents text as a sequence of UTF-8 code units.
Definition: ustring.h:48
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
shortcut
Specifies shortcut keys that can be used by menu items.
Definition: shortcut.h:19
menu_item_kind
Represent menu item kind used by xtd::forms::menu_item component.
Definition: menu_item_kind.h:17
@ none
No shortcut key is associated with the menu item.
@ normal
Normal menu item.
Contains xtd::drawing::image class.
Contains xtd::forms::menu menu.
Contains xtd::forms::menu_item_kind enum class.
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
Contains xtd::forms::shortcut enum class.