Mercurial > dwindows
annotate win/edge.cpp @ 2034:89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
So adding const to any string parameters which are not written to.
Probably going to require changes to the other platforms due to header changes.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sun, 17 Nov 2019 03:13:37 +0000 |
parents | d81d2ea806c6 |
children | 638be5b17715 |
rev | line source |
---|---|
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
1 /* edge.cpp |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
2 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
3 * Allows dw_html_new() to embed a Microsoft Edge (Chromium) browser. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
4 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
5 * Requires Windows 10, 8 or 7 with Microsoft Edge (Chromium) installed. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
6 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
7 * Only included when BUILD_EDGE is defined, will fall back to embedded IE. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
8 * |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
9 * Currently only buildable with Visual Studio since it requires the EDGE |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
10 * SDK which is currently distributed as a nuget package. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
11 */ |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
12 #include "dw.h" |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
13 #include "webview2.h" |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
14 #include <wrl.h> |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
15 |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
16 using namespace Microsoft::WRL; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
17 |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
18 #define _DW_HTML_DATA_NAME "_dw_edge" |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
19 #define _DW_HTML_DATA_ENV "_dw_edge_env" |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
20 #define _DW_HTML_DATA_LOCATION "_dw_edge_location" |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
21 #define _DW_HTML_DATA_RAW "_dw_edge_raw" |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
22 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
23 extern "C" { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
24 |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
25 /* Import the character conversion functions from dw.c */ |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
26 LPWSTR _myUTF8toWide(const char *utf8string, void *outbuf); |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
27 char *_myWideToUTF8(LPCWSTR widestring, void *outbuf); |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
28 #define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL) |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
29 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) |
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
30 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); |
2022
28809bf17957
Win: Switch to using _wcsicmp() from CompareStringOrdinal() for increased compatibility.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2018
diff
changeset
|
31 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
32 extern HWND DW_HWND_OBJECT; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
33 BOOL DW_EDGE_DETECTED = FALSE; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
34 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
35 /******************************* dw_edge_detect() ************************** |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
36 * Attempts to create a temporary Edge (Chromium) browser context... |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
37 * If we succeed return TRUE and use Edge for HTML windows. |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
38 * If it fails return FALSE and fall back to using embedded IE. |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
39 */ |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
40 BOOL _dw_edge_detect(VOID) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
41 { |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
42 HWND hWnd = DW_HWND_OBJECT; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
43 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
44 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
45 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
46 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
47 // Successfully created Edge environment, return TRUE |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
48 DW_EDGE_DETECTED = TRUE; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
49 return S_OK; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
50 }).Get()); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
51 return DW_EDGE_DETECTED; |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
52 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
53 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
54 /******************************* dw_edge_action() ************************** |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
55 * Implements the functionality of a "Back". "Forward", "Home", "Search", |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
56 * "Refresh", or "Stop" button. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
57 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
58 * hwnd = Handle to the window hosting the browser object. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
59 * action = One of the following: |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
60 * 0 = Move back to the previously viewed web page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
61 * 1 = Move forward to the previously viewed web page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
62 * 2 = Move to the home page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
63 * 3 = Search. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
64 * 4 = Refresh the page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
65 * 5 = Stop the currently loading page. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
66 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
67 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
68 void _dw_edge_action(HWND hwnd, int action) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
69 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
70 IWebView2WebView* webview; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
71 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
72 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
73 // we initially attached the browser object to this window. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
74 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
75 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
76 // We want to get the base address (ie, a pointer) to the IWebView2WebView object embedded within the browser |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
77 // object, so we can call some of the functions in the former's table. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
78 if (webview) |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
79 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
80 // Call the desired function |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
81 switch (action) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
82 { |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
83 case DW_HTML_GOBACK: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
84 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
85 // Call the IWebView2WebView object's GoBack function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
86 webview->GoBack(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
87 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
88 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
89 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
90 case DW_HTML_GOFORWARD: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
91 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
92 // Call the IWebView2WebView object's GoForward function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
93 webview->GoForward(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
94 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
95 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
96 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
97 case DW_HTML_GOHOME: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
98 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
99 // Call the IWebView2WebView object's GoHome function. |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
100 dw_html_url(hwnd, (char *)DW_HOME_URL); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
101 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
102 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
103 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
104 case DW_HTML_SEARCH: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
105 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
106 // Call the IWebView2WebView object's GoSearch function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
107 //webview->GoSearch(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
108 break; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
109 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
110 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
111 case DW_HTML_RELOAD: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
112 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
113 // Call the IWebView2WebView object's Refresh function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
114 webview->Reload(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
115 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
116 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
117 case DW_HTML_STOP: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
118 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
119 // Call the IWebView2WebView object's Stop function. |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
120 //webview->Stop(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
121 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
122 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
123 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
124 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
125 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
126 /******************************* dw_edge_raw() **************************** |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
127 * Takes a string containing some HTML BODY, and displays it in the specified |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
128 * window. For example, perhaps you want to display the HTML text of... |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
129 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
130 * <P>This is a picture.<P><IMG src="mypic.jpg"> |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
131 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
132 * hwnd = Handle to the window hosting the browser object. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
133 * string = Pointer to nul-terminated string containing the HTML BODY. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
134 * (NOTE: No <BODY></BODY> tags are required in the string). |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
135 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
136 * RETURNS: 0 if success, or non-zero if an error. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
137 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
138 |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
139 int _dw_edge_raw(HWND hwnd, const char *string) |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
140 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
141 IWebView2WebView* webview; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
142 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
143 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
144 // we initially attached the browser object to this window. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
145 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
146 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
147 if (webview) |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
148 webview->NavigateToString(UTF8toWide(string)); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
149 else |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
150 dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(UTF8toWide(string))); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
151 return DW_ERROR_NONE; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
152 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
153 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
154 /******************************* dw_edge_url() **************************** |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
155 * Displays a URL, or HTML file on disk. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
156 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
157 * hwnd = Handle to the window hosting the browser object. |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
158 * url = Pointer to nul-terminated name of the URL/file. |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
159 * |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
160 * RETURNS: 0 if success, or non-zero if an error. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
161 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
162 |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
163 int _dw_edge_url(HWND hwnd, const char *url) |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
164 { |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
165 IWebView2WebView* webview; |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
166 |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
167 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
168 // we initially attached the browser object to this window. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
169 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
170 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
171 if (webview) |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
172 webview->Navigate(UTF8toWide(url)); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
173 else |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
174 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(UTF8toWide(url))); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
175 return DW_ERROR_NONE; |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
176 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
177 |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
178 /******************************* dw_edge_javascript_run() **************************** |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
179 * Runs a javascript in the specified browser context. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
180 * |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
181 * hwnd = Handle to the window hosting the browser object. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
182 * script = Pointer to nul-terminated javascript string. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
183 * scriptdata = Pointer to user data to be passed to the callback. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
184 * |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
185 * RETURNS: 0 if success, or non-zero if an error. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
186 */ |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
187 |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
188 int _dw_edge_javascript_run(HWND hwnd, const char *script, void *scriptdata) |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
189 { |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
190 IWebView2WebView* webview; |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
191 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
192 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
193 // we initially attached the browser object to this window. |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
194 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
195 |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
196 if (webview) |
2018
663d79f28e46
Win: Fix dw_html_javascript_run() when using embedded IE browser widget.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2015
diff
changeset
|
197 webview->ExecuteScript(UTF8toWide(script), |
2015
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
198 Callback<IWebView2ExecuteScriptCompletedHandler>( |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
199 [hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
200 { |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
201 _wndproc(hwnd, WM_USER + 100, (error == S_OK ? (WPARAM)WideToUTF8((LPWSTR)result) : NULL), (LPARAM)scriptdata); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
202 return S_OK; |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
203 }).Get()); |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
204 return DW_ERROR_NONE; |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
205 } |
c30f4354966e
Win: Added support for dw_html_javascript_run() using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2001
diff
changeset
|
206 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
207 /************************** edgeWindowProc() ************************* |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
208 * Our message handler for our window to host the browser. |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
209 */ |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
210 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
211 LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
212 { |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
213 switch (uMsg) |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
214 { |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
215 case WM_SIZE: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
216 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
217 // Resize the browser object to fit the window |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
218 IWebView2WebView* webview; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
219 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
220 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
221 // we initially attached the browser object to this window. |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
222 webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
223 // Resize WebView to fit the bounds of the parent window |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
224 if (webview) |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
225 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
226 RECT bounds; |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
227 |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
228 GetClientRect(hWnd, &bounds); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
229 webview->put_Bounds(bounds); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
230 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
231 return(0); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
232 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
233 |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
234 case WM_PAINT: |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
235 { |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
236 PAINTSTRUCT ps; |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
237 HDC hdc = BeginPaint(hWnd, &ps); |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
238 EndPaint(hWnd, &ps); |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
239 return(0); |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
240 } |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
241 |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
242 case WM_CREATE: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
243 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
244 // Step 3 - Create a single WebView within the parent window |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
245 // Locate the browser and set up the environment for WebView |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
246 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
247 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
248 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
249 |
2034
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
250 // Save the environment for later use |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
251 dw_window_set_data(hWnd, _DW_HTML_DATA_ENV, DW_POINTER(env)); |
89d62197124b
Visual C in C++ mode complains about missing const declarations in paramaters.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2033
diff
changeset
|
252 |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
253 // Create a WebView, whose parent is the main window hWnd |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
254 env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>( |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
255 [hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
256 if (webview != nullptr) { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
257 dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, DW_POINTER(webview)); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
258 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
259 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
260 // Add a few settings for the webview |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
261 // this is a redundant demo step as they are the default settings values |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
262 IWebView2Settings* Settings; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
263 webview->get_Settings(&Settings); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
264 Settings->put_IsScriptEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
265 Settings->put_AreDefaultScriptDialogsEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
266 Settings->put_IsWebMessageEnabled(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
267 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
268 // Resize WebView to fit the bounds of the parent window |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
269 RECT bounds; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
270 GetClientRect(hWnd, &bounds); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
271 webview->put_Bounds(bounds); |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
272 |
2033
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
273 // Save the token, we might need to dw_window_set_data() this value |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
274 // for later use to remove the handlers |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
275 EventRegistrationToken token; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
276 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
277 // Register a handler for the NavigationStarting event. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
278 webview->add_NavigationStarting( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
279 Callback<IWebView2NavigationStartingEventHandler>( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
280 [hWnd](IWebView2WebView* sender, |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
281 IWebView2NavigationStartingEventArgs* args) -> HRESULT |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
282 { |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
283 LPWSTR uri; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
284 sender->get_Source(&uri); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
285 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
286 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_STARTED), |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
287 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
288 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
289 return S_OK; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
290 }).Get(), &token); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
291 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
292 // Register a handler for the DocumentStateChanged event. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
293 webview->add_DocumentStateChanged( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
294 Callback<IWebView2DocumentStateChangedEventHandler>( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
295 [hWnd](IWebView2WebView* sender, |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
296 IWebView2DocumentStateChangedEventArgs* args) -> HRESULT |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
297 { |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
298 LPWSTR uri; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
299 sender->get_Source(&uri); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
300 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
301 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_LOADING), |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
302 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
303 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
304 return S_OK; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
305 }).Get(), &token); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
306 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
307 // Register a handler for the NavigationCompleted event. |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
308 webview->add_NavigationCompleted( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
309 Callback<IWebView2NavigationCompletedEventHandler>( |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
310 [hWnd](IWebView2WebView* sender, |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
311 IWebView2NavigationCompletedEventArgs* args) -> HRESULT |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
312 { |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
313 LPWSTR uri; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
314 sender->get_Source(&uri); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
315 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
316 _wndproc(hWnd, WM_USER + 101, (WPARAM)DW_INT_TO_POINTER(DW_HTML_CHANGE_COMPLETE), |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
317 !wcscmp(uri, L"about:blank") ? (LPARAM)"" : (LPARAM)WideToUTF8((LPWSTR)uri)); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
318 |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
319 return S_OK; |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
320 }).Get(), &token); |
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
321 |
2001
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
322 // Handle cached load requests due to delayed |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
323 // loading of the edge webview contexts |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
324 LPCWSTR url = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_LOCATION); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
325 if(url) |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
326 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
327 webview->Navigate(url); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
328 free((void *)url); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
329 } |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
330 LPCWSTR raw = (LPCWSTR)dw_window_get_data(hWnd, _DW_HTML_DATA_RAW); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
331 if (raw) |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
332 { |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
333 webview->NavigateToString(raw); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
334 free((void *)raw); |
f7acca46f795
Win: Fixes for Edge (Chromium) embedding, the loading can be delayed so...
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2000
diff
changeset
|
335 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
336 return S_OK; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
337 }).Get()); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
338 return S_OK; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
339 }).Get()); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
340 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
341 // Success |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
342 return(0); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
343 } |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
344 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
345 case WM_DESTROY: |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
346 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
347 // Detach the browser object from this window, and free resources. |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
348 IWebView2WebView* webview; |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
349 |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
350 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
351 // we initially attached the browser object to this window. |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
352 webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
353 if (webview) |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
354 { |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
355 dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, NULL); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
356 webview->Close(); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
357 } |
2033
d81d2ea806c6
Win: Added callback handlers to generate the HTML_CHANGED signals using Edge (Chromium).
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
2022
diff
changeset
|
358 _free_window_memory(hWnd, 0); |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
359 return(TRUE); |
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
360 } |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
361 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
362 |
2000
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
363 return(DefWindowProc(hWnd, uMsg, wParam, lParam)); |
77e43d71eaa7
Changes to allow mixing C and C++ when including dw.h.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
1999
diff
changeset
|
364 } |
1999
4e808c4cadfb
Win: Add initial support for Microsoft Edge (Chromium) embedding.
bsmith@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
365 } |