Ocean
Loading...
Searching...
No Matches
PopupMenu.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_PLATFORM_WIN_POPUP_MENU_H
9#define META_OCEAN_PLATFORM_WIN_POPUP_MENU_H
10
12
13#include <memory>
14#include <vector>
15
16namespace Ocean
17{
18
19namespace Platform
20{
21
22namespace Win
23{
24
25// Forward declaration.
26class PopupMenu;
27
28/**
29 * Definition of a unique pointer holding a popup menu.
30 * @ingroup platformwin
31 */
32using UniquePopupMenu = std::unique_ptr<PopupMenu>;
33
34/**
35 * Definition of a vector holding popup menus.
36 * @ingroup platformwin
37 */
38using PopupMenus = std::vector<UniquePopupMenu>;
39
40/**
41 * This class implements a popup menu.
42 * @ingroup platformwin
43 */
44class OCEAN_PLATFORM_WIN_EXPORT PopupMenu
45{
46 public:
47
48 /**
49 * Creates a new popup menu object.
50 */
52
53 /**
54 * Disabled copy constructor.
55 * A sub-menu's handle stays attached to the handle of its parent menu, so the ownership of a menu must never leave the object holding it.
56 */
57 PopupMenu(const PopupMenu&) = delete;
58
59 /**
60 * Disabled move constructor.
61 */
62 PopupMenu(PopupMenu&&) = delete;
63
64 /**
65 * Destructs a popup menu object.
66 */
68
69 /**
70 * Returns the number of menu entries (not any sub-entries).
71 * @return Number of menu entries
72 */
73 size_t size() const;
74
75 /**
76 * Adds a new menu entry.
77 * @param text The text of the menu entry
78 * @param id the unique entry id that is returned if this entry is selected, must not be zero
79 * @param checked True, if the entry is checked
80 * @return True, if succeeded
81 */
82 bool addEntry(const std::wstring& text, const unsigned int id, const bool checked = false);
83
84 /**
85 * Adds a seperator menu entry.
86 * @return True, if succeeded
87 */
89
90 /**
91 * Adds a new sub-menu entry.
92 * @param text The text of the sub-menu entry
93 * @return The reference of the new sub-menu
94 */
95 PopupMenu& addMenu(const std::wstring& text);
96
97 /**
98 * Shows the menu at a specified screen position and returns the selected entry id.
99 * @param x The horizontal display position in screen coordinates
100 * @param y The vertical display position in screen coordinates
101 * @param parent The parent window handle, must not be zero
102 * @return The id of the selected menu entry, zero if no entry has been selected
103 */
104 unsigned int show(const int x, const int y, const HWND parent);
105
106 /**
107 * Shows the menu at the current cursor (mouse) position and returns the selected entry id.
108 * @param parent The parent window handle, must not be zero
109 * @return The id of the selected menu entry, zero if no entry has been selected
110 */
111 unsigned int show(const HWND parent);
112
113 protected:
114
115 /**
116 * Disabled copy operator.
117 * @return Reference to this object
118 */
119 PopupMenu& operator=(const PopupMenu&) = delete;
120
121 /**
122 * Disabled move operator.
123 * @return Reference to this object
124 */
126
127 protected:
128
129 /**
130 * Releases this menu and all of its sub-menus.
131 * Beware: This menu does not hold a valid handle afterwards and must not be used anymore!
132 */
133 void release();
134
135 /// The handle of this menu.
136 HMENU handle_ = nullptr;
137
138 /// The sub-menus of this menu.
140};
141
142}
143
144}
145
146}
147
148#endif // META_OCEAN_PLATFORM_WIN_POPUP_MENU_H
This class implements a popup menu.
Definition PopupMenu.h:45
PopupMenu()
Creates a new popup menu object.
PopupMenu & addMenu(const std::wstring &text)
Adds a new sub-menu entry.
unsigned int show(const HWND parent)
Shows the menu at the current cursor (mouse) position and returns the selected entry id.
~PopupMenu()
Destructs a popup menu object.
size_t size() const
Returns the number of menu entries (not any sub-entries).
bool addSeparator()
Adds a seperator menu entry.
PopupMenu & operator=(PopupMenu &&)=delete
Disabled move operator.
PopupMenu(const PopupMenu &)=delete
Disabled copy constructor.
bool addEntry(const std::wstring &text, const unsigned int id, const bool checked=false)
Adds a new menu entry.
unsigned int show(const int x, const int y, const HWND parent)
Shows the menu at a specified screen position and returns the selected entry id.
void release()
Releases this menu and all of its sub-menus.
PopupMenus subMenus_
The sub-menus of this menu.
Definition PopupMenu.h:139
PopupMenu & operator=(const PopupMenu &)=delete
Disabled copy operator.
PopupMenu(PopupMenu &&)=delete
Disabled move constructor.
std::vector< UniquePopupMenu > PopupMenus
Definition of a vector holding popup menus.
Definition PopupMenu.h:38
std::unique_ptr< PopupMenu > UniquePopupMenu
Definition of a unique pointer holding a popup menu.
Definition PopupMenu.h:32
The namespace covering the entire Ocean framework.
Definition Accessor.h:15