This repository has been archived by the owner on Jun 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathWebWindow.h
94 lines (87 loc) · 2.65 KB
/
WebWindow.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#ifndef WEBWINDOW_H
#define WEBWINDOW_H
#ifdef _WIN32
#include <Windows.h>
#include <wrl/event.h>
#include <map>
#include <string>
#include <wil/com.h>
#include <WebView2.h>
typedef const wchar_t* AutoString;
#else
#ifdef OS_LINUX
#include <gtk/gtk.h>
#endif
typedef char* AutoString;
#endif
struct Monitor
{
struct MonitorRect
{
int x, y;
int width, height;
} monitor, work;
};
typedef void (*ACTION)();
typedef void (*WebMessageReceivedCallback)(AutoString message);
typedef void* (*WebResourceRequestedCallback)(AutoString url, int* outNumBytes, AutoString* outContentType);
typedef int (*GetAllMonitorsCallback)(const Monitor* monitor);
typedef void (*ResizedCallback)(int width, int height);
typedef void (*MovedCallback)(int x, int y);
class WebWindow
{
private:
WebMessageReceivedCallback _webMessageReceivedCallback;
MovedCallback _movedCallback;
ResizedCallback _resizedCallback;
#ifdef _WIN32
static HINSTANCE _hInstance;
HWND _hWnd;
WebWindow* _parent;
wil::com_ptr<IWebView2Environment> _webviewEnvironment;
wil::com_ptr<IWebView2WebView> _webviewWindow;
std::map<std::wstring, WebResourceRequestedCallback> _schemeToRequestHandler;
void AttachWebView();
#elif OS_LINUX
GtkWidget* _window;
GtkWidget* _webview;
#elif OS_MAC
void* _window;
void* _webview;
void* _webviewConfiguration;
void AttachWebView();
#endif
public:
#ifdef _WIN32
static void Register(HINSTANCE hInstance);
HWND getHwnd();
void RefitContent();
#elif OS_MAC
static void Register();
#endif
WebWindow(AutoString title, WebWindow* parent, WebMessageReceivedCallback webMessageReceivedCallback);
~WebWindow();
void SetTitle(AutoString title);
void Show();
void WaitForExit();
void ShowMessage(AutoString title, AutoString body, unsigned int type);
void Invoke(ACTION callback);
void NavigateToUrl(AutoString url);
void NavigateToString(AutoString content);
void SendMessage(AutoString message);
void AddCustomScheme(AutoString scheme, WebResourceRequestedCallback requestHandler);
void SetResizable(bool resizable);
void GetSize(int* width, int* height);
void SetSize(int width, int height);
void SetResizedCallback(ResizedCallback callback) { _resizedCallback = callback; }
void InvokeResized(int width, int height) { if (_resizedCallback) _resizedCallback(width, height); }
void GetAllMonitors(GetAllMonitorsCallback callback);
unsigned int GetScreenDpi();
void GetPosition(int* x, int* y);
void SetPosition(int x, int y);
void SetMovedCallback(MovedCallback callback) { _movedCallback = callback; }
void InvokeMoved(int x, int y) { if (_movedCallback) _movedCallback(x, y); }
void SetTopmost(bool topmost);
void SetIconFile(AutoString filename);
};
#endif // !WEBWINDOW_H