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
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
xtd::forms::main_menu Class Reference

#include <main_menu.h>

Definition

Represents the menu structure of a form.

Namespace
xtd::forms
Library
xtd.forms
Examples
The following code example demonstrate the use of main_menu control.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::forms;
namespace examples {
class form1 : public form {
public:
form1() {
text("Main menu example");
menu({
{system_texts::file(), {
{system_texts::new_(), {*this, &form1::on_menu_click}, menu_images::file_new(), shortcut::cmd_n},
{"-"},
{system_texts::open(), {*this, &form1::on_menu_click}, menu_images::file_open(), shortcut::cmd_o},
{"Open recen", {
{"Path/File1", {*this, &form1::on_menu_click}},
{"Path/File2", {*this, &form1::on_menu_click}},
{"Path/File3", {*this, &form1::on_menu_click}},
{"Path/File4", {*this, &form1::on_menu_click}},
{"Path/File5", {*this, &form1::on_menu_click}},
}},
{system_texts::close(), {*this, &form1::on_menu_click}, shortcut::cmd_w},
{"-"},
{system_texts::save(), {*this, &form1::on_menu_click}, menu_images::file_save(), shortcut::cmd_s},
{system_texts::save_as(), {*this, &form1::on_menu_click}},
{"-"},
{"Page &Seup...", {*this, &form1::on_menu_click}},
{system_texts::print(), {*this, &form1::on_menu_click}, menu_images::file_print(), shortcut::cmd_p},
{system_texts::print_preview(), {*this, &form1::on_menu_click}, menu_images::file_print_preview()},
{"-"},
{system_texts::exit(), {overload_<>(&application::exit)}, menu_images::file_exit(), shortcut::alt_f4},
}},
{system_texts::edit(), {
{system_texts::undo(), {*this, &form1::on_menu_click}, menu_images::edit_undo(), shortcut::cmd_z},
{system_texts::redo(), {*this, &form1::on_menu_click}, menu_images::edit_redo(), shortcut::cmd_shift_z},
{"-"},
{system_texts::cut(), {*this, &form1::on_menu_click}, menu_images::edit_cut(), shortcut::cmd_x},
{system_texts::copy(), {*this, &form1::on_menu_click}, menu_images::edit_copy(), shortcut::cmd_c},
{system_texts::paste(), {*this, &form1::on_menu_click}, menu_images::edit_paste(), shortcut::cmd_v},
{"-"},
{system_texts::select_all(), {*this, &form1::on_menu_click}, shortcut::cmd_a},
{"-"},
{system_texts::options(), {*this, &form1::on_menu_click}},
}},
{system_texts::view(), {
{system_texts::back(), {*this, &form1::on_menu_click}, menu_images::view_back()},
{system_texts::forward(), {*this, &form1::on_menu_click}, menu_images::view_forward()},
{"-"},
{"Show", {*this, &form1::on_menu_click}},
{"Hide", {*this, &form1::on_menu_click}},
}},
{system_texts::options(), {
{"Value A", {*this, &form1::on_menu_click}, menu_item_kind::check, true, shortcut::alt_1},
{"Value B", {*this, &form1::on_menu_click}, menu_item_kind::check, shortcut::alt_2},
{"Value C", {*this, &form1::on_menu_click}, menu_item_kind::check, true, shortcut::alt_3},
{"-"},
{"Value D", {*this, &form1::on_menu_click}, menu_item_kind::radio, static_cast<shortcut>(keys::alt|keys::d)},
{"Value E", {*this, &form1::on_menu_click}, menu_item_kind::radio, true, static_cast<shortcut>(keys::alt|keys::e)},
{"Value F", {*this, &form1::on_menu_click}, menu_item_kind::radio, static_cast<shortcut>(keys::alt|keys::f)},
{"-"},
{"Value G", {*this, &form1::on_menu_click}, menu_item_kind::radio, static_cast<shortcut>(keys::alt|keys::shift|keys::left)},
{"Value H", {*this, &form1::on_menu_click}, menu_item_kind::radio},
{"Value I", {*this, &form1::on_menu_click}, menu_item_kind::radio, true},
}},
{system_texts::help(), {
{system_texts::about(), {*this, &form1::on_menu_click}},
}},
});
list_box1.parent(*this);
list_box1.dock(dock_style::fill);
}
void on_menu_click(object& sender, const event_args& e) {
list_box1.items().push_back(ustring::format("{} clicked", as<menu_item&>(sender).text()));
list_box1.selected_index(list_box1.items().size() - 1);
}
private:
list_box list_box1;
};
}
int main() {
application::run(examples::form1());
}
Represents the base class for classes that contain event data, and provides a value to use for events...
Definition: event_args.h:18
static void enable_menu_images()
Enables menu images for the application.
static void run()
Begins running a standard application message loop on the current thread, without a form.
Represents a window or dialog box that makes up an application's user interface.
Definition: form.h:40
Represents a standard Windows list box.
Definition: list_box.h:23
Represents the base functionality for all menus. Although tool_strip_drop_down and tool_strip_drop_do...
Definition: menu.h:32
shortcut
Specifies shortcut keys that can be used by menu items.
Definition: shortcut.h:19
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
Examples
The following code example demonstrate the use of main_menu::create_standard_items factory.
#include <xtd/xtd>
using namespace xtd;
using namespace xtd::forms;
namespace examples {
class form1 : public form {
public:
form1() {
text("Main menu create standard items example");
menu(main_menu::create_standard_items([&](object& sender, const event_args& e) {
list_box1.items().push_back(ustring::format("{} clicked", as<menu_item&>(sender).text()));
list_box1.selected_index(list_box1.items().size() - 1);
if (as<menu_item&>(sender).text() == system_texts::exit()) application::exit();
}));
list_box1.parent(*this);
list_box1.dock(dock_style::fill);
}
private:
list_box list_box1;
};
}
int main() {
application::run(examples::form1());
}

Inherits xtd::forms::menu.

Public Member Functions

 main_menu ()
 Initialize a new instance of main_menu class.
 
 main_menu (const std::vector< menu_item > &menu_items)
 Initialize a new instance of main_menu class.
 
- Public Member Functions inherited from xtd::forms::menu
std::optional< context_menuget_context_menu () const
 Gets the context_menu that contains this menu.
 
std::optional< main_menuget_main_menu () const
 Gets the main_menu that contains this menu.
 
intptr_t handle () const
 Gets a value representing the window handle for the menu.
 
bool is_parent () const
 Gets a value indicating whether this menu contains any menu items.
 
const menu_itemmdi_list_item () const
 Gets a value indicating the menu_item that is used to display a list of multiple document interface (MDI) child forms.
 
menu_item_collectionmenu_items ()
 Gets a value indicating the collection of menu_item objects associated with the menu.
 
const menu_item_collectionmenu_items () const
 Gets a value indicating the collection of menu_item objects associated with the menu.
 
menumenu_items (const menu_item_collection &value)
 Sets a value indicating the collection of menu_item objects associated with the menu.
 
virtual void merge_menu (const menu &menu_src)
 Merges the MenuItem objects of one menu with the current menu.
 
const xtd::ustringname () const
 Gets the name of the menu.
 
menuname (const xtd::ustring &value)
 Sets the name of the menu.
 
std::any tag () const
 Gets user-defined data associated with the control.
 
menutag (std::any value)
 Sets user-defined data associated with the control.
 
xtd::ustring to_string () const noexcept override
 Returns a string that represents the menu control.
 
- Public Member Functions inherited from xtd::object
 object ()=default
 Create a new instance of the ultimate base class object.
 
virtual bool equals (const object &obj) const noexcept
 Determines whether the specified object is equal to the current object.
 
virtual size_t get_hash_code () const noexcept
 Serves as a hash function for a particular type.
 
template<typename object_t >
std::unique_ptr< object_t > memberwise_clone () const
 Gets the type of the current instance.
 
virtual xtd::ustring to_string () const noexcept
 Returns a std::string that represents the current object.
 

Static Public Member Functions

static xtd::forms::main_menu create_standard_items (const xtd::drawing::size &image_size, const xtd::event_handler &on_click)
 A factory to create a main menu with specified image size and on click event handler.
 
static xtd::forms::main_menu create_standard_items (const xtd::event_handler &on_click)
 A factory to create a main menu with specified on click event handler.
 
static xtd::forms::main_menu create_standard_items (const xtd::forms::theme_images &theme, const xtd::drawing::size &size, const xtd::event_handler &on_click)
 A factory to create a main menu with specified theme, image size and on click event handler.
 
static xtd::forms::main_menu create_standard_items (const xtd::ustring &theme, const xtd::drawing::size &size, const xtd::event_handler &on_click)
 A factory to create a main menu with specified theme, image size and on click event handler.
 
static xtd::forms::main_menu create_standard_items (const xtd::ustring &theme, const xtd::event_handler &on_click)
 A factory to create a main menu with specified theme and on click event handler.
 
- Static Public Member Functions inherited from xtd::object
static bool equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are considered equal.
 
static bool reference_equals (const object &object_a, const object &object_b) noexcept
 Determines whether the specified object instances are the same instance.
 

Protected Member Functions

intptr_t create_menu_handle () override
 Creates a new handle to the Menu.
 
void destroy_menu_handle (intptr_t handle) override
 Destroy the handle to the Menu.
 
- Protected Member Functions inherited from xtd::forms::menu
 menu ()
 Initializes a new instance of the Menu class.
 
 menu (const menu_item_collection &items)
 Initializes a new instance of the Menu class.
 
void clone_menu (const menu &menu_src)
 Copies the menu that is passed as a parameter to the current menu.
 
virtual intptr_t create_menu_handle ()=0
 Creates a new handle to the Menu.
 
virtual void destroy_menu_handle (intptr_t handle)=0
 Destroy the handle to the Menu.
 
- Protected Member Functions inherited from xtd::forms::component
 component ()=default
 Initialises a new instance of the component class.
 
virtual bool can_raise_events () const
 Gets a value indicating whether the component can raise an event.
 
bool design_mode () const
 Gets a value that indicates whether the component is currently in design mode.
 

Additional Inherited Members

- Public Types inherited from xtd::forms::menu
using menu_item_collection = layout::arranged_element_collection< menu_item >
 Represents a collection of menu_item objects.
 
- Static Public Attributes inherited from xtd::forms::menu
static constexpr const int find_handle
 Specifies that the find_menu_item(int32_t, intptr_t) method should search for a handle.
 
static constexpr const int find_shortcut
 Specifies that the find_menu_item(int32_t, intptr_t) method should search for a shortcut.
 

Constructor & Destructor Documentation

◆ main_menu() [1/2]

xtd::forms::main_menu::main_menu ( )

Initialize a new instance of main_menu class.

◆ main_menu() [2/2]

xtd::forms::main_menu::main_menu ( const std::vector< menu_item > &  menu_items)

Initialize a new instance of main_menu class.

Parameters
menu_itemsAn array of menu_item objects that will be added to the main_menu.

Member Function Documentation

◆ create_menu_handle()

intptr_t xtd::forms::main_menu::create_menu_handle ( )
overrideprotectedvirtual

Creates a new handle to the Menu.

Returns
A handle to the menu if the method succeeds; otherwise, 0.

Implements xtd::forms::menu.

◆ create_standard_items() [1/5]

static xtd::forms::main_menu xtd::forms::main_menu::create_standard_items ( const xtd::drawing::size image_size,
const xtd::event_handler on_click 
)
static

A factory to create a main menu with specified image size and on click event handler.

Parameters
image_sizeA xtd::drawing::size that represent the menu item image size.
on_clickan event handler to respond on lick event.
Returns
new main menu instance.

◆ create_standard_items() [2/5]

static xtd::forms::main_menu xtd::forms::main_menu::create_standard_items ( const xtd::event_handler on_click)
static

A factory to create a main menu with specified on click event handler.

Parameters
on_clickan event handler to respond on lick event.
Returns
new main menu instance.

◆ create_standard_items() [3/5]

static xtd::forms::main_menu xtd::forms::main_menu::create_standard_items ( const xtd::forms::theme_images theme,
const xtd::drawing::size size,
const xtd::event_handler on_click 
)
static

A factory to create a main menu with specified theme, image size and on click event handler.

Parameters
themeThe theme of menu item image.
image_sizeA xtd::drawing::size that represent the menu item image size.
on_clickan event handler to respond on lick event.
Returns
new main menu instance.

◆ create_standard_items() [4/5]

static xtd::forms::main_menu xtd::forms::main_menu::create_standard_items ( const xtd::ustring theme,
const xtd::drawing::size size,
const xtd::event_handler on_click 
)
static

A factory to create a main menu with specified theme, image size and on click event handler.

Parameters
themeThe theme of menu item image.
image_sizeA xtd::drawing::size that represent the menu item image size.
on_clickan event handler to respond on lick event.
Returns
new main menu instance.

◆ create_standard_items() [5/5]

static xtd::forms::main_menu xtd::forms::main_menu::create_standard_items ( const xtd::ustring theme,
const xtd::event_handler on_click 
)
static

A factory to create a main menu with specified theme and on click event handler.

Parameters
themeThe theme of menu item image.
on_clickan event handler to respond on lick event.
Returns
new main menu instance.

◆ destroy_menu_handle()

void xtd::forms::main_menu::destroy_menu_handle ( intptr_t  handle)
overrideprotectedvirtual

Destroy the handle to the Menu.

Parameters
handleA handle to the menu.

Implements xtd::forms::menu.


The documentation for this class was generated from the following file: