plusui-native-core 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Core/include/plusui/app.hpp +73 -73
- package/Core/include/plusui/browser.hpp +68 -68
- package/Core/include/plusui/clipboard.hpp +41 -41
- package/Core/include/plusui/custom_bindings.hpp +17 -17
- package/Core/include/plusui/display.hpp +90 -90
- package/Core/include/plusui/keyboard.hpp +112 -112
- package/Core/include/plusui/menu.hpp +153 -153
- package/Core/include/plusui/native_bindings.hpp +19 -19
- package/Core/include/plusui/tray.hpp +94 -94
- package/Core/include/plusui/webgpu.hpp +434 -434
- package/Core/include/plusui/webview.hpp +142 -142
- package/Core/include/plusui/window.hpp +111 -111
- package/Core/include/plusui/window_manager.hpp +59 -59
- package/package.json +1 -1
|
@@ -1,112 +1,112 @@
|
|
|
1
|
-
#ifndef PLUSUI_KEYBOARD_H
|
|
2
|
-
#define PLUSUI_KEYBOARD_H
|
|
3
|
-
|
|
4
|
-
#include <string>
|
|
5
|
-
#include <vector>
|
|
6
|
-
#include <functional>
|
|
7
|
-
#include <map>
|
|
8
|
-
#include <memory>
|
|
9
|
-
|
|
10
|
-
namespace plusui {
|
|
11
|
-
|
|
12
|
-
enum class KeyCode {
|
|
13
|
-
Unknown = 0,
|
|
14
|
-
Space = 32, Apostrophe = 39, Comma = 44, Minus = 45, Period = 46,
|
|
15
|
-
Slash = 47, Num0 = 48, Num1 = 49, Num2 = 50, Num3 = 51, Num4 = 52,
|
|
16
|
-
Num5 = 53, Num6 = 54, Num7 = 55, Num8 = 56, Num9 = 57,
|
|
17
|
-
Semicolon = 59, Equal = 61, A = 65, B = 66, C = 67, D = 68, E = 69,
|
|
18
|
-
F = 70, G = 71, H = 72, I = 73, J = 74, K = 75, L = 76, M = 77,
|
|
19
|
-
N = 78, O = 79, P = 80, Q = 81, R = 82, S = 83, T = 84, U = 85,
|
|
20
|
-
V = 86, W = 87, X = 88, Y = 89, Z = 90, LeftBracket = 91,
|
|
21
|
-
Backslash = 92, RightBracket = 93, GraveAccent = 96,
|
|
22
|
-
Escape = 256, Enter = 257, Tab = 258, Backspace = 259,
|
|
23
|
-
Insert = 260, Delete = 261, Right = 262, Left = 263, Down = 264,
|
|
24
|
-
Up = 265, PageUp = 266, PageDown = 267, Home = 268, End = 269,
|
|
25
|
-
CapsLock = 280, F1 = 290, F2 = 291, F3 = 292, F4 = 293, F5 = 294,
|
|
26
|
-
F6 = 295, F7 = 296, F8 = 297, F9 = 298, F10 = 299, F11 = 300,
|
|
27
|
-
F12 = 301, LeftShift = 340, LeftControl = 341, LeftAlt = 342,
|
|
28
|
-
LeftSuper = 343, RightShift = 344, RightControl = 345,
|
|
29
|
-
RightAlt = 346, RightSuper = 347
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
enum class KeyMod {
|
|
33
|
-
None = 0, Shift = 1, Control = 2, Alt = 4, Super = 8
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
inline KeyMod operator|(KeyMod a, KeyMod b) {
|
|
37
|
-
return static_cast<KeyMod>(static_cast<int>(a) | static_cast<int>(b));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
inline bool operator&(KeyMod a, KeyMod b) {
|
|
41
|
-
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
struct KeyEvent {
|
|
45
|
-
KeyCode key = KeyCode::Unknown;
|
|
46
|
-
int scancode = 0;
|
|
47
|
-
KeyMod mods = KeyMod::None;
|
|
48
|
-
bool pressed = false;
|
|
49
|
-
bool repeat = false;
|
|
50
|
-
std::string keyName;
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
struct Shortcut {
|
|
54
|
-
KeyCode key = KeyCode::Unknown;
|
|
55
|
-
KeyMod mods = KeyMod::None;
|
|
56
|
-
|
|
57
|
-
Shortcut() = default;
|
|
58
|
-
Shortcut(KeyCode k, KeyMod m = KeyMod::None) : key(k), mods(m) {}
|
|
59
|
-
|
|
60
|
-
std::string toString() const;
|
|
61
|
-
static Shortcut parse(const std::string& str);
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
class Keyboard {
|
|
65
|
-
public:
|
|
66
|
-
Keyboard();
|
|
67
|
-
~Keyboard();
|
|
68
|
-
|
|
69
|
-
static Keyboard& instance();
|
|
70
|
-
|
|
71
|
-
void onKeyDown(std::function<void(const KeyEvent&)> callback);
|
|
72
|
-
void onKeyUp(std::function<void(const KeyEvent&)> callback);
|
|
73
|
-
|
|
74
|
-
bool isKeyPressed(KeyCode key) const;
|
|
75
|
-
bool areModsActive(KeyMod mods) const;
|
|
76
|
-
|
|
77
|
-
std::string getKeyName(KeyCode key) const;
|
|
78
|
-
KeyCode getKeyFromName(const std::string& name) const;
|
|
79
|
-
|
|
80
|
-
void setAutoRepeat(bool enabled);
|
|
81
|
-
bool getAutoRepeat() const;
|
|
82
|
-
|
|
83
|
-
private:
|
|
84
|
-
struct Impl;
|
|
85
|
-
std::unique_ptr<Impl> pImpl;
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
class ShortcutManager {
|
|
89
|
-
public:
|
|
90
|
-
ShortcutManager();
|
|
91
|
-
~ShortcutManager();
|
|
92
|
-
|
|
93
|
-
static ShortcutManager& instance();
|
|
94
|
-
|
|
95
|
-
bool registerShortcut(const std::string& id, const Shortcut& shortcut,
|
|
96
|
-
std::function<void()> callback);
|
|
97
|
-
bool unregisterShortcut(const std::string& id);
|
|
98
|
-
void clearShortcuts();
|
|
99
|
-
|
|
100
|
-
bool isRegistered(const std::string& id) const;
|
|
101
|
-
Shortcut getShortcut(const std::string& id) const;
|
|
102
|
-
|
|
103
|
-
void onShortcutTriggered(std::function<void(const std::string& id)> callback);
|
|
104
|
-
|
|
105
|
-
private:
|
|
106
|
-
struct Impl;
|
|
107
|
-
std::unique_ptr<Impl> pImpl;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
#endif
|
|
1
|
+
#ifndef PLUSUI_KEYBOARD_H
|
|
2
|
+
#define PLUSUI_KEYBOARD_H
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
#include <vector>
|
|
6
|
+
#include <functional>
|
|
7
|
+
#include <map>
|
|
8
|
+
#include <memory>
|
|
9
|
+
|
|
10
|
+
namespace plusui {
|
|
11
|
+
|
|
12
|
+
enum class KeyCode {
|
|
13
|
+
Unknown = 0,
|
|
14
|
+
Space = 32, Apostrophe = 39, Comma = 44, Minus = 45, Period = 46,
|
|
15
|
+
Slash = 47, Num0 = 48, Num1 = 49, Num2 = 50, Num3 = 51, Num4 = 52,
|
|
16
|
+
Num5 = 53, Num6 = 54, Num7 = 55, Num8 = 56, Num9 = 57,
|
|
17
|
+
Semicolon = 59, Equal = 61, A = 65, B = 66, C = 67, D = 68, E = 69,
|
|
18
|
+
F = 70, G = 71, H = 72, I = 73, J = 74, K = 75, L = 76, M = 77,
|
|
19
|
+
N = 78, O = 79, P = 80, Q = 81, R = 82, S = 83, T = 84, U = 85,
|
|
20
|
+
V = 86, W = 87, X = 88, Y = 89, Z = 90, LeftBracket = 91,
|
|
21
|
+
Backslash = 92, RightBracket = 93, GraveAccent = 96,
|
|
22
|
+
Escape = 256, Enter = 257, Tab = 258, Backspace = 259,
|
|
23
|
+
Insert = 260, Delete = 261, Right = 262, Left = 263, Down = 264,
|
|
24
|
+
Up = 265, PageUp = 266, PageDown = 267, Home = 268, End = 269,
|
|
25
|
+
CapsLock = 280, F1 = 290, F2 = 291, F3 = 292, F4 = 293, F5 = 294,
|
|
26
|
+
F6 = 295, F7 = 296, F8 = 297, F9 = 298, F10 = 299, F11 = 300,
|
|
27
|
+
F12 = 301, LeftShift = 340, LeftControl = 341, LeftAlt = 342,
|
|
28
|
+
LeftSuper = 343, RightShift = 344, RightControl = 345,
|
|
29
|
+
RightAlt = 346, RightSuper = 347
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
enum class KeyMod {
|
|
33
|
+
None = 0, Shift = 1, Control = 2, Alt = 4, Super = 8
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
inline KeyMod operator|(KeyMod a, KeyMod b) {
|
|
37
|
+
return static_cast<KeyMod>(static_cast<int>(a) | static_cast<int>(b));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
inline bool operator&(KeyMod a, KeyMod b) {
|
|
41
|
+
return (static_cast<int>(a) & static_cast<int>(b)) != 0;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
struct KeyEvent {
|
|
45
|
+
KeyCode key = KeyCode::Unknown;
|
|
46
|
+
int scancode = 0;
|
|
47
|
+
KeyMod mods = KeyMod::None;
|
|
48
|
+
bool pressed = false;
|
|
49
|
+
bool repeat = false;
|
|
50
|
+
std::string keyName;
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
struct Shortcut {
|
|
54
|
+
KeyCode key = KeyCode::Unknown;
|
|
55
|
+
KeyMod mods = KeyMod::None;
|
|
56
|
+
|
|
57
|
+
Shortcut() = default;
|
|
58
|
+
Shortcut(KeyCode k, KeyMod m = KeyMod::None) : key(k), mods(m) {}
|
|
59
|
+
|
|
60
|
+
std::string toString() const;
|
|
61
|
+
static Shortcut parse(const std::string& str);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
class Keyboard {
|
|
65
|
+
public:
|
|
66
|
+
Keyboard();
|
|
67
|
+
~Keyboard();
|
|
68
|
+
|
|
69
|
+
static Keyboard& instance();
|
|
70
|
+
|
|
71
|
+
void onKeyDown(std::function<void(const KeyEvent&)> callback);
|
|
72
|
+
void onKeyUp(std::function<void(const KeyEvent&)> callback);
|
|
73
|
+
|
|
74
|
+
bool isKeyPressed(KeyCode key) const;
|
|
75
|
+
bool areModsActive(KeyMod mods) const;
|
|
76
|
+
|
|
77
|
+
std::string getKeyName(KeyCode key) const;
|
|
78
|
+
KeyCode getKeyFromName(const std::string& name) const;
|
|
79
|
+
|
|
80
|
+
void setAutoRepeat(bool enabled);
|
|
81
|
+
bool getAutoRepeat() const;
|
|
82
|
+
|
|
83
|
+
private:
|
|
84
|
+
struct Impl;
|
|
85
|
+
std::unique_ptr<Impl> pImpl;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
class ShortcutManager {
|
|
89
|
+
public:
|
|
90
|
+
ShortcutManager();
|
|
91
|
+
~ShortcutManager();
|
|
92
|
+
|
|
93
|
+
static ShortcutManager& instance();
|
|
94
|
+
|
|
95
|
+
bool registerShortcut(const std::string& id, const Shortcut& shortcut,
|
|
96
|
+
std::function<void()> callback);
|
|
97
|
+
bool unregisterShortcut(const std::string& id);
|
|
98
|
+
void clearShortcuts();
|
|
99
|
+
|
|
100
|
+
bool isRegistered(const std::string& id) const;
|
|
101
|
+
Shortcut getShortcut(const std::string& id) const;
|
|
102
|
+
|
|
103
|
+
void onShortcutTriggered(std::function<void(const std::string& id)> callback);
|
|
104
|
+
|
|
105
|
+
private:
|
|
106
|
+
struct Impl;
|
|
107
|
+
std::unique_ptr<Impl> pImpl;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#endif
|
|
@@ -1,153 +1,153 @@
|
|
|
1
|
-
#ifndef PLUSUI_MENU_H
|
|
2
|
-
#define PLUSUI_MENU_H
|
|
3
|
-
|
|
4
|
-
#include <functional>
|
|
5
|
-
#include <map>
|
|
6
|
-
#include <memory>
|
|
7
|
-
#include <string>
|
|
8
|
-
#include <vector>
|
|
9
|
-
|
|
10
|
-
namespace plusui {
|
|
11
|
-
class WebView;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
namespace plusui {
|
|
15
|
-
|
|
16
|
-
enum class MenuItemType { Normal, Separator, Submenu, Checkbox, Radio };
|
|
17
|
-
|
|
18
|
-
struct MenuItem {
|
|
19
|
-
std::string id;
|
|
20
|
-
std::string label;
|
|
21
|
-
std::string accelerator;
|
|
22
|
-
std::string icon;
|
|
23
|
-
MenuItemType type = MenuItemType::Normal;
|
|
24
|
-
bool enabled = true;
|
|
25
|
-
bool checked = false;
|
|
26
|
-
std::vector<MenuItem> submenu;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
struct MenuBarData {
|
|
30
|
-
std::vector<MenuItem> items;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
class Menu {
|
|
34
|
-
public:
|
|
35
|
-
Menu();
|
|
36
|
-
~Menu();
|
|
37
|
-
|
|
38
|
-
// Move semantics
|
|
39
|
-
Menu(Menu &&other) noexcept;
|
|
40
|
-
Menu &operator=(Menu &&other) noexcept;
|
|
41
|
-
|
|
42
|
-
// Disable copy
|
|
43
|
-
Menu(const Menu &) = delete;
|
|
44
|
-
Menu &operator=(const Menu &) = delete;
|
|
45
|
-
|
|
46
|
-
static Menu create(const std::vector<MenuItem> &items = {});
|
|
47
|
-
|
|
48
|
-
void setItems(const std::vector<MenuItem> &items);
|
|
49
|
-
std::vector<MenuItem> getItems() const;
|
|
50
|
-
|
|
51
|
-
void append(const MenuItem &item);
|
|
52
|
-
void insert(int index, const MenuItem &item);
|
|
53
|
-
void remove(const std::string &id);
|
|
54
|
-
void clear();
|
|
55
|
-
|
|
56
|
-
void popup(int x, int y);
|
|
57
|
-
void close();
|
|
58
|
-
|
|
59
|
-
private:
|
|
60
|
-
struct Impl;
|
|
61
|
-
std::unique_ptr<Impl> pImpl;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
class MenuBar {
|
|
65
|
-
public:
|
|
66
|
-
MenuBar();
|
|
67
|
-
~MenuBar();
|
|
68
|
-
|
|
69
|
-
static MenuBar &instance();
|
|
70
|
-
|
|
71
|
-
void setMenu(const MenuBarData &menu);
|
|
72
|
-
MenuBarData getMenu() const;
|
|
73
|
-
|
|
74
|
-
void append(const MenuItem &item);
|
|
75
|
-
void insert(int index, const MenuItem &item);
|
|
76
|
-
void remove(const std::string &id);
|
|
77
|
-
void clear();
|
|
78
|
-
|
|
79
|
-
void onMenuItemClick(std::function<void(const std::string &id)> callback);
|
|
80
|
-
|
|
81
|
-
private:
|
|
82
|
-
struct Impl;
|
|
83
|
-
std::unique_ptr<Impl> pImpl;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
class MenuManager {
|
|
87
|
-
public:
|
|
88
|
-
static MenuManager &instance();
|
|
89
|
-
|
|
90
|
-
// Manage ID to Menu mapping
|
|
91
|
-
std::string createMenu(const std::vector<MenuItem> &items);
|
|
92
|
-
Menu *getMenu(const std::string &id);
|
|
93
|
-
void destroyMenu(const std::string &id);
|
|
94
|
-
|
|
95
|
-
private:
|
|
96
|
-
MenuManager();
|
|
97
|
-
~MenuManager();
|
|
98
|
-
struct Impl;
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
namespace bindings {
|
|
102
|
-
|
|
103
|
-
class MenuBindings {
|
|
104
|
-
public:
|
|
105
|
-
MenuBindings() = default;
|
|
106
|
-
~MenuBindings() = default;
|
|
107
|
-
|
|
108
|
-
void registerBindings(WebView &webview);
|
|
109
|
-
void setItemClickCallback(
|
|
110
|
-
std::function<void(const std::string &menuId, const std::string &itemId)>
|
|
111
|
-
callback);
|
|
112
|
-
void setContextMenu(const std::vector<MenuItem> &items);
|
|
113
|
-
void enableContextMenu(bool enable);
|
|
114
|
-
void showContextMenuAtCursor();
|
|
115
|
-
|
|
116
|
-
private:
|
|
117
|
-
std::function<void(const std::string &, const std::string &)>
|
|
118
|
-
itemClickCallback_;
|
|
119
|
-
std::vector<MenuItem> contextMenuItems_;
|
|
120
|
-
bool contextMenuEnabled_ = false;
|
|
121
|
-
std::string currentContextMenuId_;
|
|
122
|
-
|
|
123
|
-
std::vector<MenuItem> parseMenuItems(const std::string &json);
|
|
124
|
-
std::string menuItemToJson(const MenuItem &item);
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
class ContextMenuManager {
|
|
128
|
-
public:
|
|
129
|
-
static ContextMenuManager &instance();
|
|
130
|
-
|
|
131
|
-
void setDefaultMenu(const std::vector<MenuItem> &items);
|
|
132
|
-
void setMenuForSelector(const std::string &selector,
|
|
133
|
-
const std::vector<MenuItem> &items);
|
|
134
|
-
void attachToWebView(WebView &webview);
|
|
135
|
-
void handleRightClick(int x, int y, const std::string &targetSelector);
|
|
136
|
-
void onItemClick(std::function<void(const std::string &itemId,
|
|
137
|
-
const std::string &targetSelector)>
|
|
138
|
-
callback);
|
|
139
|
-
|
|
140
|
-
private:
|
|
141
|
-
ContextMenuManager() = default;
|
|
142
|
-
~ContextMenuManager() = default;
|
|
143
|
-
|
|
144
|
-
std::vector<MenuItem> defaultMenu_;
|
|
145
|
-
std::map<std::string, std::vector<MenuItem>> selectorMenus_;
|
|
146
|
-
std::function<void(const std::string &, const std::string &)> clickCallback_;
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
} // namespace bindings
|
|
150
|
-
|
|
151
|
-
} // namespace plusui
|
|
152
|
-
|
|
153
|
-
#endif
|
|
1
|
+
#ifndef PLUSUI_MENU_H
|
|
2
|
+
#define PLUSUI_MENU_H
|
|
3
|
+
|
|
4
|
+
#include <functional>
|
|
5
|
+
#include <map>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
|
|
10
|
+
namespace plusui {
|
|
11
|
+
class WebView;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
namespace plusui {
|
|
15
|
+
|
|
16
|
+
enum class MenuItemType { Normal, Separator, Submenu, Checkbox, Radio };
|
|
17
|
+
|
|
18
|
+
struct MenuItem {
|
|
19
|
+
std::string id;
|
|
20
|
+
std::string label;
|
|
21
|
+
std::string accelerator;
|
|
22
|
+
std::string icon;
|
|
23
|
+
MenuItemType type = MenuItemType::Normal;
|
|
24
|
+
bool enabled = true;
|
|
25
|
+
bool checked = false;
|
|
26
|
+
std::vector<MenuItem> submenu;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
struct MenuBarData {
|
|
30
|
+
std::vector<MenuItem> items;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
class Menu {
|
|
34
|
+
public:
|
|
35
|
+
Menu();
|
|
36
|
+
~Menu();
|
|
37
|
+
|
|
38
|
+
// Move semantics
|
|
39
|
+
Menu(Menu &&other) noexcept;
|
|
40
|
+
Menu &operator=(Menu &&other) noexcept;
|
|
41
|
+
|
|
42
|
+
// Disable copy
|
|
43
|
+
Menu(const Menu &) = delete;
|
|
44
|
+
Menu &operator=(const Menu &) = delete;
|
|
45
|
+
|
|
46
|
+
static Menu create(const std::vector<MenuItem> &items = {});
|
|
47
|
+
|
|
48
|
+
void setItems(const std::vector<MenuItem> &items);
|
|
49
|
+
std::vector<MenuItem> getItems() const;
|
|
50
|
+
|
|
51
|
+
void append(const MenuItem &item);
|
|
52
|
+
void insert(int index, const MenuItem &item);
|
|
53
|
+
void remove(const std::string &id);
|
|
54
|
+
void clear();
|
|
55
|
+
|
|
56
|
+
void popup(int x, int y);
|
|
57
|
+
void close();
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
struct Impl;
|
|
61
|
+
std::unique_ptr<Impl> pImpl;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
class MenuBar {
|
|
65
|
+
public:
|
|
66
|
+
MenuBar();
|
|
67
|
+
~MenuBar();
|
|
68
|
+
|
|
69
|
+
static MenuBar &instance();
|
|
70
|
+
|
|
71
|
+
void setMenu(const MenuBarData &menu);
|
|
72
|
+
MenuBarData getMenu() const;
|
|
73
|
+
|
|
74
|
+
void append(const MenuItem &item);
|
|
75
|
+
void insert(int index, const MenuItem &item);
|
|
76
|
+
void remove(const std::string &id);
|
|
77
|
+
void clear();
|
|
78
|
+
|
|
79
|
+
void onMenuItemClick(std::function<void(const std::string &id)> callback);
|
|
80
|
+
|
|
81
|
+
private:
|
|
82
|
+
struct Impl;
|
|
83
|
+
std::unique_ptr<Impl> pImpl;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
class MenuManager {
|
|
87
|
+
public:
|
|
88
|
+
static MenuManager &instance();
|
|
89
|
+
|
|
90
|
+
// Manage ID to Menu mapping
|
|
91
|
+
std::string createMenu(const std::vector<MenuItem> &items);
|
|
92
|
+
Menu *getMenu(const std::string &id);
|
|
93
|
+
void destroyMenu(const std::string &id);
|
|
94
|
+
|
|
95
|
+
private:
|
|
96
|
+
MenuManager();
|
|
97
|
+
~MenuManager();
|
|
98
|
+
struct Impl;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
namespace bindings {
|
|
102
|
+
|
|
103
|
+
class MenuBindings {
|
|
104
|
+
public:
|
|
105
|
+
MenuBindings() = default;
|
|
106
|
+
~MenuBindings() = default;
|
|
107
|
+
|
|
108
|
+
void registerBindings(WebView &webview);
|
|
109
|
+
void setItemClickCallback(
|
|
110
|
+
std::function<void(const std::string &menuId, const std::string &itemId)>
|
|
111
|
+
callback);
|
|
112
|
+
void setContextMenu(const std::vector<MenuItem> &items);
|
|
113
|
+
void enableContextMenu(bool enable);
|
|
114
|
+
void showContextMenuAtCursor();
|
|
115
|
+
|
|
116
|
+
private:
|
|
117
|
+
std::function<void(const std::string &, const std::string &)>
|
|
118
|
+
itemClickCallback_;
|
|
119
|
+
std::vector<MenuItem> contextMenuItems_;
|
|
120
|
+
bool contextMenuEnabled_ = false;
|
|
121
|
+
std::string currentContextMenuId_;
|
|
122
|
+
|
|
123
|
+
std::vector<MenuItem> parseMenuItems(const std::string &json);
|
|
124
|
+
std::string menuItemToJson(const MenuItem &item);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
class ContextMenuManager {
|
|
128
|
+
public:
|
|
129
|
+
static ContextMenuManager &instance();
|
|
130
|
+
|
|
131
|
+
void setDefaultMenu(const std::vector<MenuItem> &items);
|
|
132
|
+
void setMenuForSelector(const std::string &selector,
|
|
133
|
+
const std::vector<MenuItem> &items);
|
|
134
|
+
void attachToWebView(WebView &webview);
|
|
135
|
+
void handleRightClick(int x, int y, const std::string &targetSelector);
|
|
136
|
+
void onItemClick(std::function<void(const std::string &itemId,
|
|
137
|
+
const std::string &targetSelector)>
|
|
138
|
+
callback);
|
|
139
|
+
|
|
140
|
+
private:
|
|
141
|
+
ContextMenuManager() = default;
|
|
142
|
+
~ContextMenuManager() = default;
|
|
143
|
+
|
|
144
|
+
std::vector<MenuItem> defaultMenu_;
|
|
145
|
+
std::map<std::string, std::vector<MenuItem>> selectorMenus_;
|
|
146
|
+
std::function<void(const std::string &, const std::string &)> clickCallback_;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
} // namespace bindings
|
|
150
|
+
|
|
151
|
+
} // namespace plusui
|
|
152
|
+
|
|
153
|
+
#endif
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
#pragma once
|
|
2
|
-
|
|
3
|
-
#include <string>
|
|
4
|
-
#include <vector>
|
|
5
|
-
|
|
6
|
-
namespace plusui {
|
|
7
|
-
|
|
8
|
-
struct BindingEntry {
|
|
9
|
-
const char *source;
|
|
10
|
-
const char *feature;
|
|
11
|
-
const char *method;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
class NativeBindings {
|
|
15
|
-
public:
|
|
16
|
-
static const std::vector<BindingEntry> &getEntries();
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
} // namespace plusui
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <string>
|
|
4
|
+
#include <vector>
|
|
5
|
+
|
|
6
|
+
namespace plusui {
|
|
7
|
+
|
|
8
|
+
struct BindingEntry {
|
|
9
|
+
const char *source;
|
|
10
|
+
const char *feature;
|
|
11
|
+
const char *method;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
class NativeBindings {
|
|
15
|
+
public:
|
|
16
|
+
static const std::vector<BindingEntry> &getEntries();
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
} // namespace plusui
|