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