Molybden
Loading...
Searching...
No Matches
menu.hpp
1// Copyright (c) 2000-2023 TeamDev Ltd. 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
13namespace molybden {
14
15class Browser;
16
17enum class MenuItemType {
18 kStandardMenu,
19 kStandardMenuItem,
20 kCustomMenu,
21 kCustomMenuItem,
22 kSeparator
23};
24
25class MenuItem {
26 public:
27 MenuItemType type() const;
28
29 protected:
30 explicit MenuItem(MenuItemType type);
31
32 private:
33 MenuItemType type_;
34};
35
37 public:
38 static std::shared_ptr<SeparatorMenuItem> create();
39 static std::shared_ptr<SeparatorMenuItem> cast(
40 std::shared_ptr<MenuItem> item);
41
42 explicit SeparatorMenuItem();
43};
44
45using MenuItems = std::vector<std::shared_ptr<MenuItem>>;
46
47class Menu : public MenuItem {
48 public:
49 MenuItems items() const;
50
51 protected:
52 Menu(MenuItemType type, MenuItems items);
53
54 private:
55 MenuItems items_;
56};
57
58class CustomMenu : public Menu {
59 public:
60 static std::shared_ptr<CustomMenu> create(MenuItems items);
61 static std::shared_ptr<CustomMenu> create(std::string title, MenuItems items);
62 static std::shared_ptr<CustomMenu> cast(std::shared_ptr<MenuItem> item);
63
64 CustomMenu(std::string title, MenuItems items);
65 std::string title() const;
66
67 private:
68 std::string title_;
69};
70
71enum class StandardMenuRole {
72 kMacAppMenu,
73 kFileMenu,
74 kEditMenu,
75 kViewMenu,
76 kWindowMenu,
77 kHelpMenu
78};
79
80class StandardMenu : public Menu {
81 public:
82 static std::shared_ptr<StandardMenu> create(StandardMenuRole role);
83 static std::shared_ptr<StandardMenu> create(StandardMenuRole role,
84 MenuItems items);
85 static std::shared_ptr<StandardMenu> cast(std::shared_ptr<MenuItem> item);
86
87 StandardMenu(StandardMenuRole role, MenuItems items);
88
89 StandardMenuRole role() const;
90
91 private:
92 StandardMenuRole role_;
93};
94
95class CustomMenuItem;
96
97using CustomMenuItemAction = std::function<
98 void(std::shared_ptr<Browser>, std::shared_ptr<CustomMenuItem>)>;
99
100class CustomMenuItem : public MenuItem {
101 public:
102 static std::shared_ptr<CustomMenuItem> create(
103 std::string title,
104 CustomMenuItemAction action,
105 bool enabled = true);
106 static std::shared_ptr<CustomMenuItem> cast(std::shared_ptr<MenuItem> item);
107 static std::shared_ptr<CustomMenuItem> fromId(int32_t id);
108
109 CustomMenuItem(std::string title,
110 CustomMenuItemAction action,
111 bool enabled = true);
112
113 int32_t id() const;
114 std::string title() const;
115 bool isEnabled() const;
116 CustomMenuItemAction action() const;
117
118 protected:
119 CustomMenuItem(MenuItemType type,
120 std::string title,
121 CustomMenuItemAction action,
122 bool enabled = true);
123
124 private:
125 int32_t id_ = 0;
126 std::string title_;
127 bool enabled_ = true;
128 CustomMenuItemAction action_ = nullptr;
129};
130
131enum class StandardMenuItemCommandId {
132 // The standard app menu items.
133
134 // Mac App menu items.
135 kMacHideApp,
136 kMacHideOthers,
137 kMacShowAll,
138 kMacQuitApp,
139
140 // File menu items.
141 kSavePageAs,
142 kPrint,
143 kPrintUsingSystemDialog,
144 kCloseWindow,
145 kExit,
146
147 // Edit menu items.
148 kUndo,
149 kRedo,
150 kCut,
151 kCopy,
152 kPaste,
153 kPasteAndMatchStyle,
154 kDelete,
155 kSelectAll,
156 kFind,
157 kFindNext,
158 kFindPrevious,
159
160 // View menu items.
161 kGoBack,
162 kGoForward,
163 kStop,
164 kReload,
165 kReloadBypassingCache,
166 kZoomNormal,
167 kZoomIn,
168 kZoomOut,
169 kFullScreen,
170 kDevTools,
171 kViewSource,
172
173 // Window menu items.
174 kMinimizeWindow,
175 kMaximizeWindow
176};
177
179 public:
180 static std::shared_ptr<StandardMenuItem> create(StandardMenuItemCommandId id);
181 static std::shared_ptr<StandardMenuItem> cast(std::shared_ptr<MenuItem> item);
182
183 explicit StandardMenuItem(StandardMenuItemCommandId command_id);
184
185 StandardMenuItemCommandId commandId() const;
186
187 private:
188 StandardMenuItemCommandId command_id_;
189};
190
191namespace menu {
192std::shared_ptr<SeparatorMenuItem> Separator();
193std::shared_ptr<CustomMenu> Menu(MenuItems items);
194std::shared_ptr<CustomMenu> Menu(std::string title, MenuItems items);
195std::shared_ptr<CustomMenuItem> Item(std::string title,
196 CustomMenuItemAction action,
197 bool enabled = true);
198
199std::shared_ptr<StandardMenu> MacApp(MenuItems items);
200std::shared_ptr<StandardMenu> File(MenuItems items);
201std::shared_ptr<StandardMenu> Edit(MenuItems items);
202std::shared_ptr<StandardMenu> View(MenuItems items);
203std::shared_ptr<StandardMenu> Window(MenuItems items);
204std::shared_ptr<StandardMenu> Help(MenuItems items);
205
206std::shared_ptr<StandardMenuItem> MacHideApp();
207std::shared_ptr<StandardMenuItem> MacHideOthers();
208std::shared_ptr<StandardMenuItem> MacShowAll();
209std::shared_ptr<StandardMenuItem> MacQuitApp();
210
211std::shared_ptr<StandardMenuItem> SavePageAs();
212std::shared_ptr<StandardMenuItem> Print();
213std::shared_ptr<StandardMenuItem> PrintUsingSystemDialog();
214std::shared_ptr<StandardMenuItem> CloseWindow();
215std::shared_ptr<StandardMenuItem> Exit();
216
217std::shared_ptr<StandardMenuItem> Undo();
218std::shared_ptr<StandardMenuItem> Redo();
219std::shared_ptr<StandardMenuItem> Cut();
220std::shared_ptr<StandardMenuItem> Copy();
221std::shared_ptr<StandardMenuItem> Paste();
222std::shared_ptr<StandardMenuItem> PasteAndMatchStyle();
223std::shared_ptr<StandardMenuItem> Delete();
224std::shared_ptr<StandardMenuItem> SelectAll();
225std::shared_ptr<StandardMenuItem> Find();
226std::shared_ptr<StandardMenuItem> FindNext();
227std::shared_ptr<StandardMenuItem> FindPrevious();
228
229std::shared_ptr<StandardMenuItem> GoBack();
230std::shared_ptr<StandardMenuItem> GoForward();
231std::shared_ptr<StandardMenuItem> Stop();
232std::shared_ptr<StandardMenuItem> Reload();
233std::shared_ptr<StandardMenuItem> ReloadBypassingCache();
234std::shared_ptr<StandardMenuItem> ZoomNormal();
235std::shared_ptr<StandardMenuItem> ZoomIn();
236std::shared_ptr<StandardMenuItem> ZoomOut();
237std::shared_ptr<StandardMenuItem> FullScreen();
238std::shared_ptr<StandardMenuItem> DevTools();
239std::shared_ptr<StandardMenuItem> ViewSource();
240
241std::shared_ptr<StandardMenuItem> MinimizeWindow();
242std::shared_ptr<StandardMenuItem> MaximizeWindow();
243
244} // namespace menu
245} // namespace molybden
246
247#endif // MOLYBDEN_MENU_HPP
Definition menu.hpp:58
Definition menu.hpp:100
Allows working with Chromium DevTools and access the remote debugging URL of the currently loaded web...
Definition devtools.hpp:20
The fullscreen controller of the fullscreen mode for HTML elements on the web page.
Definition full_screen.hpp:18
Definition menu.hpp:47
Definition menu.hpp:25
Definition menu.hpp:36
Definition menu.hpp:80
Definition menu.hpp:178
The file data.
Definition upload_data.hpp:255