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