MōBrowser 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 MOBROWSER_MENU_HPP
6#define MOBROWSER_MENU_HPP
7
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
13#include "mobrowser/shortcuts/shortcut.hpp"
14
15namespace mobrowser {
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 void setTitle(const std::string& title);
103 [[nodiscard]] std::string title() const;
104 void setEnabled(bool enabled);
105 [[nodiscard]] bool isEnabled() const;
106
107 protected:
108 BaseCustomMenuItem(MenuItemType type, std::string title, bool enabled = true);
109
110 private:
111 int32_t id_ = 0;
112 std::string title_;
113 bool enabled_ = true;
114};
115
116class CustomMenuItem;
118
120 std::shared_ptr<App> app;
121 std::shared_ptr<Browser> browser;
122 std::shared_ptr<CustomMenuItem> menu_item;
123};
124
126 std::shared_ptr<App> app;
127 std::shared_ptr<Browser> browser;
128 std::shared_ptr<CustomCheckboxMenuItem> menu_item;
129};
130
131using CustomMenuItemAction =
132 std::function<void(const CustomMenuItemActionArgs& args)>;
133
134using CustomCheckboxMenuItemAction =
135 std::function<void(const CustomCheckboxMenuItemActionArgs& args)>;
136
138 public:
139 static std::shared_ptr<CustomMenuItem> create(std::string title,
140 CustomMenuItemAction action,
141 Shortcut shortcut,
142 bool enabled = true);
143 static std::shared_ptr<CustomMenuItem> cast(std::shared_ptr<MenuItem> item);
144 static std::shared_ptr<CustomMenuItem> fromId(int32_t id);
145
146 CustomMenuItem(std::string title,
147 CustomMenuItemAction action,
148 Shortcut shortcut,
149 bool enabled = true);
150
151 [[nodiscard]] CustomMenuItemAction action() const;
152 [[nodiscard]] Shortcut shortcut() const;
153 void setShortcut(Shortcut shortcut);
154
155 protected:
156 CustomMenuItem(MenuItemType type,
157 std::string title,
158 CustomMenuItemAction action,
159 Shortcut shortcut,
160 bool enabled = true);
161
162 private:
163 CustomMenuItemAction action_ = nullptr;
164 Shortcut shortcut_;
165};
166
168 public:
169 static std::shared_ptr<CustomCheckboxMenuItem> create(
170 std::string title,
171 CustomCheckboxMenuItemAction action,
172 bool enabled = true,
173 bool checked = false);
174 static std::shared_ptr<CustomCheckboxMenuItem> cast(
175 std::shared_ptr<MenuItem> item);
176 static std::shared_ptr<CustomCheckboxMenuItem> fromId(int32_t id);
177
178 CustomCheckboxMenuItem(std::string title,
179 CustomCheckboxMenuItemAction action,
180 bool enabled = true,
181 bool checked = false);
182
183 [[nodiscard]] bool isChecked() const;
184 void setChecked(bool checked);
185 [[nodiscard]] CustomCheckboxMenuItemAction action() const;
186
187 protected:
188 CustomCheckboxMenuItem(MenuItemType type,
189 std::string title,
190 CustomCheckboxMenuItemAction action,
191 bool enabled = true,
192 bool checked = false);
193
194 private:
195 bool checked_ = false;
196 CustomCheckboxMenuItemAction action_ = nullptr;
197};
198
199enum class StandardMenuItemCommandId {
200 // The standard app menu items.
201
202 // Mac App menu items.
203 kMacHideApp,
204 kMacHideOthers,
205 kMacShowAll,
206
207 // File menu items.
208 kSavePageAs,
209 kPrint,
210 kPrintUsingSystemDialog,
211 kCloseWindow,
212 kQuit,
213
214 // Edit menu items.
215 kUndo,
216 kRedo,
217 kCut,
218 kCopy,
219 kPaste,
220 kPasteAndMatchStyle,
221 kDelete,
222 kSelectAll,
223 kFind,
224 kFindNext,
225 kFindPrevious,
226
227 // View menu items.
228 kGoBack,
229 kGoForward,
230 kStop,
231 kReload,
232 kReloadBypassingCache,
233 kZoomNormal,
234 kZoomIn,
235 kZoomOut,
236 kFullScreen,
237 kDevTools,
238 kViewSource,
239
240 // Window menu items.
241 kMinimizeWindow,
242 kMaximizeWindow
243};
244
246 public:
247 static std::shared_ptr<StandardMenuItem> create(StandardMenuItemCommandId id);
248 static std::shared_ptr<StandardMenuItem> cast(std::shared_ptr<MenuItem> item);
249
250 explicit StandardMenuItem(StandardMenuItemCommandId command_id);
251
252 [[nodiscard]] StandardMenuItemCommandId commandId() const;
253
254 private:
255 StandardMenuItemCommandId command_id_;
256};
257
258namespace menu {
259std::shared_ptr<SeparatorMenuItem> Separator();
260std::shared_ptr<CustomMenu> Menu(MenuItems items);
261std::shared_ptr<CustomMenu> Menu(std::string title, MenuItems items);
262std::shared_ptr<CustomMenuItem> Item(std::string title,
263 CustomMenuItemAction action,
264 bool enabled = true);
265std::shared_ptr<CustomMenuItem> Item(std::string title,
266 CustomMenuItemAction action,
267 Shortcut shortcut,
268 bool enabled = true);
269std::shared_ptr<CustomCheckboxMenuItem> CheckboxItem(
270 std::string title,
271 CustomCheckboxMenuItemAction action,
272 bool enabled = true,
273 bool checked = false);
274
275std::shared_ptr<StandardMenu> MacApp(MenuItems items);
276std::shared_ptr<StandardMenu> File(MenuItems items);
277std::shared_ptr<StandardMenu> Edit(MenuItems items);
278std::shared_ptr<StandardMenu> View(MenuItems items);
279std::shared_ptr<StandardMenu> Window(MenuItems items);
280std::shared_ptr<StandardMenu> Help(MenuItems items);
281
282std::shared_ptr<CustomMenuItem> About(const std::shared_ptr<App>& app);
283
284std::shared_ptr<StandardMenuItem> MacHideApp();
285std::shared_ptr<StandardMenuItem> MacHideOthers();
286std::shared_ptr<StandardMenuItem> MacShowAll();
287std::shared_ptr<StandardMenuItem> Quit();
288
289std::shared_ptr<StandardMenuItem> SavePageAs();
290std::shared_ptr<StandardMenuItem> Print();
291std::shared_ptr<StandardMenuItem> PrintUsingSystemDialog();
292std::shared_ptr<StandardMenuItem> CloseWindow();
293
294std::shared_ptr<StandardMenuItem> Undo();
295std::shared_ptr<StandardMenuItem> Redo();
296std::shared_ptr<StandardMenuItem> Cut();
297std::shared_ptr<StandardMenuItem> Copy();
298std::shared_ptr<StandardMenuItem> Paste();
299std::shared_ptr<StandardMenuItem> PasteAndMatchStyle();
300std::shared_ptr<StandardMenuItem> Delete();
301std::shared_ptr<StandardMenuItem> SelectAll();
302std::shared_ptr<StandardMenuItem> Find();
303std::shared_ptr<StandardMenuItem> FindNext();
304std::shared_ptr<StandardMenuItem> FindPrevious();
305
306std::shared_ptr<StandardMenuItem> GoBack();
307std::shared_ptr<StandardMenuItem> GoForward();
308std::shared_ptr<StandardMenuItem> Stop();
309std::shared_ptr<StandardMenuItem> Reload();
310std::shared_ptr<StandardMenuItem> ReloadBypassingCache();
311std::shared_ptr<StandardMenuItem> ZoomNormal();
312std::shared_ptr<StandardMenuItem> ZoomIn();
313std::shared_ptr<StandardMenuItem> ZoomOut();
314std::shared_ptr<StandardMenuItem> FullScreen();
315std::shared_ptr<StandardMenuItem> DevTools();
316std::shared_ptr<StandardMenuItem> ViewSource();
317
318std::shared_ptr<StandardMenuItem> MinimizeWindow();
319std::shared_ptr<StandardMenuItem> MaximizeWindow();
320
321} // namespace menu
322} // namespace mobrowser
323
324#endif // MOBROWSER_MENU_HPP
Definition menu.hpp:99
Definition menu.hpp:167
Definition menu.hpp:62
Definition menu.hpp:137
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:245
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