xtd 1.0.0
Loading...
Searching...
No Matches
menu_item.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "menu.hpp"
6#include "menu_item_kind.hpp"
7#include "shortcut.hpp"
8#include <xtd/drawing/image>
9#include <xtd/event>
10
12namespace xtd {
14 namespace forms {
16 class main_menu;
17 class context_menu;
19
31 struct data;
32
33 public:
35
44 explicit menu_item(const xtd::string& text);
220
222 template<typename delegate_type>
224 template<typename delegate_type>
225 menu_item(const xtd::string& text, delegate_type on_click, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), shortcut) {}
226 template<typename delegate_type>
227 menu_item(const xtd::string& text, delegate_type on_click, const xtd::drawing::image& image) : menu_item(text, xtd::event_handler(on_click), image) {}
228 template<typename delegate_type>
229 menu_item(const xtd::string& text, delegate_type on_click, const xtd::drawing::image& image, xtd::forms::shortcut shortcut) : menu_item(text, xtd::event_handler(on_click), image, shortcut) {}
230 template<typename delegate_type>
231 menu_item(const xtd::string& text, delegate_type on_click, xtd::forms::menu_item_kind kind) : menu_item(text, xtd::event_handler(on_click), kind) {}
232 template<typename delegate_type>
233 menu_item(const xtd::string& 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) {}
234 template<typename delegate_type>
235 menu_item(const xtd::string& text, delegate_type on_click, xtd::forms::menu_item_kind kind, bool checked) : menu_item(text, xtd::event_handler(on_click), kind, checked) {}
236 template<typename delegate_type>
237 menu_item(const xtd::string& 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) {}
238 template<typename delegate_type>
239 menu_item(const xtd::string& 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) {}
240 template<typename delegate_type>
241 menu_item(const xtd::string& 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) {}
242 menu_item(const xtd::string& text, const std::initializer_list<const_menu_item_ref>& items);
244
251 menu_item(const xtd::string& text, const std::vector<menu_item_ref>& items);
252 menu_item(menu_item&&) = default;
253 menu_item(const menu_item&) = default;
254 menu_item& operator =(const menu_item&) = default;
256
258
262 [[nodiscard]] auto menu_id() const noexcept -> xtd::intptr;
263
266 [[nodiscard]] auto checked() const noexcept -> bool;
270 auto checked(bool value) -> menu_item&;
271
274 [[nodiscard]] auto enabled() const noexcept -> bool;
278 auto enabled(bool value) -> menu_item&;
279
280 [[nodiscard]] auto is_parent() const noexcept -> bool override;
281
284 [[nodiscard]] auto kind() const noexcept -> xtd::forms::menu_item_kind;
289
292 [[nodiscard]] auto shortcut() const noexcept -> xtd::forms::shortcut;
297
302 [[nodiscard]] auto text() const noexcept -> const xtd::string&;
308 auto text(const xtd::string& value) -> menu_item&;
310
312
317
321 [[nodiscard]] auto to_string() const noexcept -> xtd::string override;
323
325
332
333 protected:
334 friend main_menu;
335 friend context_menu;
336
338
340 auto create_menu_handle() -> xtd::intptr override;
341 auto destroy_menu_handle(xtd::intptr handle) -> void override;
342
346 virtual auto on_click(const event_args& e) -> void;
347
348 auto on_item_added(xtd::usize pos, menu_item_ref item) -> void override;
349 auto on_item_removed(xtd::usize pos, menu_item_ref item) -> void override;
351
352 private:
353 xtd::sptr<data> data_;
354 };
355 }
356}
An abstract base class that provides functionality for the bitmap and metafile descended classes.
Definition image.hpp:49
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition event_args.hpp:18
Represents an event.
Definition event.hpp:23
Represents a shortcut menu.
Definition context_menu.hpp:35
Represents the menu structure of a form.
Definition main_menu.hpp:41
Represents an individual item that is displayed within a main_menu or context_menu.
Definition menu_item.hpp:30
menu_item(const xtd::string &text, 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::string &text, const std::vector< menu_item_ref > &items)
Initializes a new instance of the class with a specified caption and an array of submenu items define...
menu_item(const xtd::string &text, xtd::forms::menu_item_kind kind)
Initializes a new instance of the class with a specified caption, and kind the menu item.
auto is_parent() const noexcept -> bool override
Gets a value indicating whether this menu contains any menu items.
menu_item(const xtd::string &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::string &text, 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,...
menu_item(const xtd::string &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,...
virtual auto on_click(const event_args &e) -> void
Raises the Click event.
menu_item(const xtd::string &text, 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::string &text, 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::string &text, 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,...
menu_item(const xtd::string &text, xtd::event_handler on_click)
Initializes a new instance of the class with a specified caption and event handler for the Click even...
xtd::event< menu_item, xtd::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.hpp:330
auto kind() const noexcept -> xtd::forms::menu_item_kind
Gets a value that represents the kind of menu item.
auto text() const noexcept -> const xtd::string &
Gets a value indicating the caption of the menu item.
menu_item(const xtd::string &text, 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(const xtd::string &text, 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::string &text, 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...
void perform_click()
Generates a xtd::forms::menu_item::click event for the xtd::forms::menu_item, simulating a click by a...
auto enabled() const noexcept -> bool
Gets a value indicating whether the menu item is enabled.
menu_item()
Initializes a menu_item with a blank caption.
menu_item(const xtd::string &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::string &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(const xtd::string &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,...
auto to_string() const noexcept -> xtd::string override
Returns a string that represents the menu control.
menu_item(const xtd::string &text, const xtd::drawing::image &image)
Initializes a new instance of the class with a specified caption, and image menu item.
auto destroy_menu_handle(xtd::intptr handle) -> void override
Destroys the handle to the Menu.
menu_item(const xtd::string &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,...
menu_item(const xtd::string &text)
Initializes a new instance of the menu_item class with a specified caption for the menu item.
auto create_menu_handle() -> xtd::intptr override
Creates a new handle to the Menu.
menu_item(const xtd::string &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::string &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,...
auto menu_id() const noexcept -> xtd::intptr
Gets a value indicating the Windows identifier for this menu item.
auto shortcut() const noexcept -> xtd::forms::shortcut
Gets a value indicating the shortcut key associated with the menu item.
menu_item(const xtd::string &text, 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::string &text, 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(const xtd::string &text, 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.
auto checked() const noexcept -> bool
Gets a value indicating whether a check mark appears next to the text of the menu item.
menu_item(const xtd::string &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.
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition menu.hpp:37
auto handle() const noexcept -> xtd::intptr
Gets a value representing the window handle for the menu.
generic_event_handler< const xtd::event_args & > event_handler
Represents the method that will handle an event that has no event data.
Definition event_handler.hpp:24
#define forms_export_
Define shared library export.
Definition forms_export.hpp:13
xtd::basic_string< char > string
Represents text as a sequence of UTF-8 code units.
Definition __string_definitions.hpp:43
xtd::shared_ptr_object< type_t > sptr
The xtd::sptr object is a shared pointer.
Definition sptr.hpp:25
std::intmax_t intptr
Represent a pointer or a handle.
Definition intptr.hpp:23
std::size_t usize
Represents an unsigned size of any object in bytes.
Definition usize.hpp:22
shortcut
Specifies shortcut keys that can be used by menu items.
Definition shortcut.hpp:24
menu_item_kind
Represent menu item kind used by xtd::forms::menu_item component.
Definition menu_item_kind.hpp:21
xtd::ref< xtd::forms::menu_item > menu_item_ref
Represents a menu item reference.
Definition menu_item_ref.hpp:23
@ checked
The button has a checked or latched appearance. Use this appearance to show that a toggle button has ...
Definition button_state.hpp:31
@ text
The xtd::forms::status_bar_panel displays text in the standard font.
Definition status_bar_panel_style.hpp:25
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 texts.hpp:219
Contains classes that represent ASCII and Unicode character encodings; abstract base classes for conv...
Definition basic_string_builder.hpp:13
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
constexpr auto data() const noexcept -> const_pointer
Gets direct access to the underlying contiguous storage.
Definition read_only_span.hpp:197
Contains xtd::forms::shortcut enum class.