Molybden API
Loading...
Searching...
No Matches
menu.hpp
1// Copyright (c) 2000-2024 TeamDev. All rights reserved.
2// TeamDev PROPRIETARY and CONFIDENTIAL.
3// Use is subject to license terms.
4
5#ifndef MOLYBDEN_MENU_HPP
6#define MOLYBDEN_MENU_HPP
7
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
13#include "molybden/shortcuts/shortcut.hpp"
14
15namespace molybden {
16
17class App;
18class Browser;
19
20enum class MenuItemType {
21 kStandardMenu,
22 kStandardMenuItem,
23 kCustomMenu,
24 kCustomMenuItem,
25 kCustomCheckboxMenuItem,
26 kSeparator
27};
28
29class MenuItem {
30 public:
31 [[nodiscard]] MenuItemType type() const;
32
33 protected:
34 explicit MenuItem(MenuItemType type);
35
36 private:
37 MenuItemType type_;
38};
39
41 public:
42 static std::shared_ptr<SeparatorMenuItem> create();
43 static std::shared_ptr<SeparatorMenuItem> cast(
44 std::shared_ptr<MenuItem> item);
45
46 explicit SeparatorMenuItem();
47};
48
49using MenuItems = std::vector<std::shared_ptr<MenuItem>>;
50
51class Menu : public MenuItem {
52 public:
53 [[nodiscard]] MenuItems items() const;
54
55 protected:
56 Menu(MenuItemType type, MenuItems items);
57
58 private:
59 MenuItems items_;
60};
61
62class CustomMenu : public Menu {
63 public:
64 static std::shared_ptr<CustomMenu> create(MenuItems items);
65 static std::shared_ptr<CustomMenu> create(std::string title, MenuItems items);
66 static std::shared_ptr<CustomMenu> cast(std::shared_ptr<MenuItem> item);
67
68 CustomMenu(std::string title, MenuItems items);
69 [[nodiscard]] std::string title() const;
70
71 private:
72 std::string title_;
73};
74
75enum class StandardMenuRole {
76 kMacAppMenu,
77 kFileMenu,
78 kEditMenu,
79 kViewMenu,
80 kWindowMenu,
81 kHelpMenu
82};
83
84class StandardMenu : public Menu {
85 public:
86 static std::shared_ptr<StandardMenu> create(StandardMenuRole role);
87 static std::shared_ptr<StandardMenu> create(StandardMenuRole role,
88 MenuItems items);
89 static std::shared_ptr<StandardMenu> cast(std::shared_ptr<MenuItem> item);
90
91 StandardMenu(StandardMenuRole role, MenuItems items);
92
93 [[nodiscard]] StandardMenuRole role() const;
94
95 private:
96 StandardMenuRole role_;
97};
98
100 public:
101 [[nodiscard]] int32_t id() const;
102 [[nodiscard]] std::string title() const;
103 void setEnabled(bool enabled);
104 [[nodiscard]] bool isEnabled() const;
105
106 protected:
107 BaseCustomMenuItem(MenuItemType type, std::string title, bool enabled = true);
108
109 private:
110 int32_t id_ = 0;
111 std::string title_;
112 bool enabled_ = true;
113};
114
115class CustomMenuItem;
117
119 std::shared_ptr<App> app;
120 std::shared_ptr<Browser> browser;
121 std::shared_ptr<CustomMenuItem> menu_item;
122};
123
125 std::shared_ptr<App> app;
126 std::shared_ptr<Browser> browser;
127 std::shared_ptr<CustomCheckboxMenuItem> menu_item;
128};
129
130using CustomMenuItemAction =
131 std::function<void(const CustomMenuItemActionArgs& args)>;
132
133using CustomCheckboxMenuItemAction =
134 std::function<void(const CustomCheckboxMenuItemActionArgs& args)>;
135
137 public:
138 static std::shared_ptr<CustomMenuItem> create(std::string title,
139 CustomMenuItemAction action,
140 Shortcut shortcut,
141 bool enabled = true);
142 static std::shared_ptr<CustomMenuItem> cast(std::shared_ptr<MenuItem> item);
143 static std::shared_ptr<CustomMenuItem> fromId(int32_t id);
144
145 CustomMenuItem(std::string title,
146 CustomMenuItemAction action,
147 Shortcut shortcut,
148 bool enabled = true);
149
150 [[nodiscard]] CustomMenuItemAction action() const;
151 [[nodiscard]] Shortcut shortcut() const;
152 void setShortcut(Shortcut shortcut);
153
154 protected:
155 CustomMenuItem(MenuItemType type,
156 std::string title,
157 CustomMenuItemAction action,
158 Shortcut shortcut,
159 bool enabled = true);
160
161 private:
162 CustomMenuItemAction action_ = nullptr;
163 Shortcut shortcut_;
164};
165
167 public:
168 static std::shared_ptr<CustomCheckboxMenuItem> create(
169 std::string title,
170 CustomCheckboxMenuItemAction action,
171 bool enabled = true,
172 bool checked = false);
173 static std::shared_ptr<CustomCheckboxMenuItem> cast(
174 std::shared_ptr<MenuItem> item);
175 static std::shared_ptr<CustomCheckboxMenuItem> fromId(int32_t id);
176
177 CustomCheckboxMenuItem(std::string title,
178 CustomCheckboxMenuItemAction action,
179 bool enabled = true,
180 bool checked = false);
181
182 [[nodiscard]] bool isChecked() const;
183 void setChecked(bool checked);
184 [[nodiscard]] CustomCheckboxMenuItemAction action() const;
185
186 protected:
187 CustomCheckboxMenuItem(MenuItemType type,
188 std::string title,
189 CustomCheckboxMenuItemAction action,
190 bool enabled = true,
191 bool checked = false);
192
193 private:
194 bool checked_ = false;
195 CustomCheckboxMenuItemAction action_ = nullptr;
196};
197
198enum class StandardMenuItemCommandId {
199 // The standard app menu items.
200
201 // Mac App menu items.
202 kMacHideApp,
203 kMacHideOthers,
204 kMacShowAll,
205
206 // File menu items.
207 kSavePageAs,
208 kPrint,
209 kPrintUsingSystemDialog,
210 kCloseWindow,
211 kQuit,
212
213 // Edit menu items.
214 kUndo,
215 kRedo,
216 kCut,
217 kCopy,
218 kPaste,
219 kPasteAndMatchStyle,
220 kDelete,
221 kSelectAll,
222 kFind,
223 kFindNext,
224 kFindPrevious,
225
226 // View menu items.
227 kGoBack,
228 kGoForward,
229 kStop,
230 kReload,
231 kReloadBypassingCache,
232 kZoomNormal,
233 kZoomIn,
234 kZoomOut,
235 kFullScreen,
236 kDevTools,
237 kViewSource,
238
239 // Window menu items.
240 kMinimizeWindow,
241 kMaximizeWindow
242};
243
245 public:
246 static std::shared_ptr<StandardMenuItem> create(StandardMenuItemCommandId id);
247 static std::shared_ptr<StandardMenuItem> cast(std::shared_ptr<MenuItem> item);
248
249 explicit StandardMenuItem(StandardMenuItemCommandId command_id);
250
251 [[nodiscard]] StandardMenuItemCommandId commandId() const;
252
253 private:
254 StandardMenuItemCommandId command_id_;
255};
256
257namespace menu {
258std::shared_ptr<SeparatorMenuItem> Separator();
259std::shared_ptr<CustomMenu> Menu(MenuItems items);
260std::shared_ptr<CustomMenu> Menu(std::string title, MenuItems items);
261std::shared_ptr<CustomMenuItem> Item(std::string title,
262 CustomMenuItemAction action,
263 bool enabled = true);
264std::shared_ptr<CustomMenuItem> Item(std::string title,
265 CustomMenuItemAction action,
266 Shortcut shortcut,
267 bool enabled = true);
268std::shared_ptr<CustomCheckboxMenuItem> CheckboxItem(
269 std::string title,
270 CustomCheckboxMenuItemAction action,
271 bool enabled = true,
272 bool checked = false);
273
274std::shared_ptr<StandardMenu> MacApp(MenuItems items);
275std::shared_ptr<StandardMenu> File(MenuItems items);
276std::shared_ptr<StandardMenu> Edit(MenuItems items);
277std::shared_ptr<StandardMenu> View(MenuItems items);
278std::shared_ptr<StandardMenu> Window(MenuItems items);
279std::shared_ptr<StandardMenu> Help(MenuItems items);
280
281std::shared_ptr<CustomMenuItem> About(const std::shared_ptr<App>& app);
282
283std::shared_ptr<StandardMenuItem> MacHideApp();
284std::shared_ptr<StandardMenuItem> MacHideOthers();
285std::shared_ptr<StandardMenuItem> MacShowAll();
286std::shared_ptr<StandardMenuItem> Quit();
287
288std::shared_ptr<StandardMenuItem> SavePageAs();
289std::shared_ptr<StandardMenuItem> Print();
290std::shared_ptr<StandardMenuItem> PrintUsingSystemDialog();
291std::shared_ptr<StandardMenuItem> CloseWindow();
292
293std::shared_ptr<StandardMenuItem> Undo();
294std::shared_ptr<StandardMenuItem> Redo();
295std::shared_ptr<StandardMenuItem> Cut();
296std::shared_ptr<StandardMenuItem> Copy();
297std::shared_ptr<StandardMenuItem> Paste();
298std::shared_ptr<StandardMenuItem> PasteAndMatchStyle();
299std::shared_ptr<StandardMenuItem> Delete();
300std::shared_ptr<StandardMenuItem> SelectAll();
301std::shared_ptr<StandardMenuItem> Find();
302std::shared_ptr<StandardMenuItem> FindNext();
303std::shared_ptr<StandardMenuItem> FindPrevious();
304
305std::shared_ptr<StandardMenuItem> GoBack();
306std::shared_ptr<StandardMenuItem> GoForward();
307std::shared_ptr<StandardMenuItem> Stop();
308std::shared_ptr<StandardMenuItem> Reload();
309std::shared_ptr<StandardMenuItem> ReloadBypassingCache();
310std::shared_ptr<StandardMenuItem> ZoomNormal();
311std::shared_ptr<StandardMenuItem> ZoomIn();
312std::shared_ptr<StandardMenuItem> ZoomOut();
313std::shared_ptr<StandardMenuItem> FullScreen();
314std::shared_ptr<StandardMenuItem> DevTools();
315std::shared_ptr<StandardMenuItem> ViewSource();
316
317std::shared_ptr<StandardMenuItem> MinimizeWindow();
318std::shared_ptr<StandardMenuItem> MaximizeWindow();
319
320} // namespace menu
321} // namespace molybden
322
323#endif // MOLYBDEN_MENU_HPP
Definition menu.hpp:99
Definition menu.hpp:166
Definition menu.hpp:62
Definition menu.hpp:136
Allows working with the browser's DevTools.
Definition devtools.hpp:17
Definition menu.hpp:51
Definition menu.hpp:29
Definition menu.hpp:40
Definition menu.hpp:84
Definition menu.hpp:244
Definition menu.hpp:118
The file data.
Definition upload_data.hpp:255
A combination of a key code and modifier keys, such as Shift, Alt, etc.
Definition shortcut.hpp:25