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
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
146 // File menu items.
147 kSavePageAs,
148 kPrint,
149 kPrintUsingSystemDialog,
150 kCloseWindow,
151 kQuit,
152
153 // Edit menu items.
154 kUndo,
155 kRedo,
156 kCut,
157 kCopy,
158 kPaste,
159 kPasteAndMatchStyle,
160 kDelete,
161 kSelectAll,
162 kFind,
163 kFindNext,
164 kFindPrevious,
165
166 // View menu items.
167 kGoBack,
168 kGoForward,
169 kStop,
170 kReload,
171 kReloadBypassingCache,
172 kZoomNormal,
173 kZoomIn,
174 kZoomOut,
175 kFullScreen,
176 kDevTools,
177 kViewSource,
178
179 // Window menu items.
180 kMinimizeWindow,
181 kMaximizeWindow
182};
183
185 public:
186 static std::shared_ptr<StandardMenuItem> create(StandardMenuItemCommandId id);
187 static std::shared_ptr<StandardMenuItem> cast(std::shared_ptr<MenuItem> item);
188
189 explicit StandardMenuItem(StandardMenuItemCommandId command_id);
190
191 StandardMenuItemCommandId commandId() const;
192
193 private:
194 StandardMenuItemCommandId command_id_;
195};
196
197namespace menu {
198std::shared_ptr<SeparatorMenuItem> Separator();
199std::shared_ptr<CustomMenu> Menu(MenuItems items);
200std::shared_ptr<CustomMenu> Menu(std::string title, MenuItems items);
201std::shared_ptr<CustomMenuItem> Item(std::string title,
202 CustomMenuItemAction action,
203 bool enabled = true);
204
205std::shared_ptr<StandardMenu> MacApp(MenuItems items);
206std::shared_ptr<StandardMenu> File(MenuItems items);
207std::shared_ptr<StandardMenu> Edit(MenuItems items);
208std::shared_ptr<StandardMenu> View(MenuItems items);
209std::shared_ptr<StandardMenu> Window(MenuItems items);
210std::shared_ptr<StandardMenu> Help(MenuItems items);
211
212std::shared_ptr<CustomMenuItem> About(const std::shared_ptr<App>& app);
213
214std::shared_ptr<StandardMenuItem> MacHideApp();
215std::shared_ptr<StandardMenuItem> MacHideOthers();
216std::shared_ptr<StandardMenuItem> MacShowAll();
217std::shared_ptr<StandardMenuItem> Quit();
218
219std::shared_ptr<StandardMenuItem> SavePageAs();
220std::shared_ptr<StandardMenuItem> Print();
221std::shared_ptr<StandardMenuItem> PrintUsingSystemDialog();
222std::shared_ptr<StandardMenuItem> CloseWindow();
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 the browser's DevTools.
Definition devtools.hpp:17
Definition menu.hpp:48
Definition menu.hpp:26
Definition menu.hpp:37
Definition menu.hpp:81
Definition menu.hpp:184
The file data.
Definition upload_data.hpp:255