Mercurial > dwindows
comparison 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 |
comparison
equal
deleted
inserted
replaced
2033:d81d2ea806c6 | 2034:89d62197124b |
---|---|
13 #include "webview2.h" | 13 #include "webview2.h" |
14 #include <wrl.h> | 14 #include <wrl.h> |
15 | 15 |
16 using namespace Microsoft::WRL; | 16 using namespace Microsoft::WRL; |
17 | 17 |
18 #define _DW_HTML_DATA_NAME (char *)"_dw_edge" | 18 #define _DW_HTML_DATA_NAME "_dw_edge" |
19 #define _DW_HTML_DATA_LOCATION (char *)"_dw_edge_location" | 19 #define _DW_HTML_DATA_ENV "_dw_edge_env" |
20 #define _DW_HTML_DATA_RAW (char *)"_dw_edge_raw" | 20 #define _DW_HTML_DATA_LOCATION "_dw_edge_location" |
21 #define _DW_HTML_DATA_RAW "_dw_edge_raw" | |
21 | 22 |
22 extern "C" { | 23 extern "C" { |
23 | 24 |
24 /* Import the character conversion functions from dw.c */ | 25 /* Import the character conversion functions from dw.c */ |
25 LPWSTR _myUTF8toWide(char *utf8string, void *outbuf); | 26 LPWSTR _myUTF8toWide(const char *utf8string, void *outbuf); |
26 char *_myWideToUTF8(LPWSTR widestring, void *outbuf); | 27 char *_myWideToUTF8(LPCWSTR widestring, void *outbuf); |
27 #define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL) | 28 #define UTF8toWide(a) _myUTF8toWide(a, a ? _alloca(MultiByteToWideChar(CP_UTF8, 0, a, -1, NULL, 0) * sizeof(WCHAR)) : NULL) |
28 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) | 29 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL) |
29 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); | 30 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); |
30 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam); | 31 BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam); |
31 extern HWND DW_HWND_OBJECT; | 32 extern HWND DW_HWND_OBJECT; |
133 * (NOTE: No <BODY></BODY> tags are required in the string). | 134 * (NOTE: No <BODY></BODY> tags are required in the string). |
134 * | 135 * |
135 * RETURNS: 0 if success, or non-zero if an error. | 136 * RETURNS: 0 if success, or non-zero if an error. |
136 */ | 137 */ |
137 | 138 |
138 int _dw_edge_raw(HWND hwnd, char *string) | 139 int _dw_edge_raw(HWND hwnd, const char *string) |
139 { | 140 { |
140 IWebView2WebView* webview; | 141 IWebView2WebView* webview; |
141 | 142 |
142 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when | 143 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
143 // we initially attached the browser object to this window. | 144 // we initially attached the browser object to this window. |
157 * url = Pointer to nul-terminated name of the URL/file. | 158 * url = Pointer to nul-terminated name of the URL/file. |
158 * | 159 * |
159 * RETURNS: 0 if success, or non-zero if an error. | 160 * RETURNS: 0 if success, or non-zero if an error. |
160 */ | 161 */ |
161 | 162 |
162 int _dw_edge_url(HWND hwnd, char *url) | 163 int _dw_edge_url(HWND hwnd, const char *url) |
163 { | 164 { |
164 IWebView2WebView* webview; | 165 IWebView2WebView* webview; |
165 | 166 |
166 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when | 167 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
167 // we initially attached the browser object to this window. | 168 // we initially attached the browser object to this window. |
182 * scriptdata = Pointer to user data to be passed to the callback. | 183 * scriptdata = Pointer to user data to be passed to the callback. |
183 * | 184 * |
184 * RETURNS: 0 if success, or non-zero if an error. | 185 * RETURNS: 0 if success, or non-zero if an error. |
185 */ | 186 */ |
186 | 187 |
187 int _dw_edge_javascript_run(HWND hwnd, char *script, void *scriptdata) | 188 int _dw_edge_javascript_run(HWND hwnd, const char *script, void *scriptdata) |
188 { | 189 { |
189 IWebView2WebView* webview; | 190 IWebView2WebView* webview; |
190 | 191 |
191 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when | 192 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when |
192 // we initially attached the browser object to this window. | 193 // we initially attached the browser object to this window. |
228 webview->put_Bounds(bounds); | 229 webview->put_Bounds(bounds); |
229 } | 230 } |
230 return(0); | 231 return(0); |
231 } | 232 } |
232 | 233 |
234 case WM_PAINT: | |
235 { | |
236 PAINTSTRUCT ps; | |
237 HDC hdc = BeginPaint(hWnd, &ps); | |
238 EndPaint(hWnd, &ps); | |
239 return(0); | |
240 } | |
241 | |
233 case WM_CREATE: | 242 case WM_CREATE: |
234 { | 243 { |
235 // Step 3 - Create a single WebView within the parent window | 244 // Step 3 - Create a single WebView within the parent window |
236 // Locate the browser and set up the environment for WebView | 245 // Locate the browser and set up the environment for WebView |
237 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, | 246 CreateWebView2EnvironmentWithDetails(nullptr, nullptr, nullptr, |
238 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( | 247 Callback<IWebView2CreateWebView2EnvironmentCompletedHandler>( |
239 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { | 248 [hWnd](HRESULT result, IWebView2Environment* env) -> HRESULT { |
249 | |
250 // Save the environment for later use | |
251 dw_window_set_data(hWnd, _DW_HTML_DATA_ENV, DW_POINTER(env)); | |
240 | 252 |
241 // Create a WebView, whose parent is the main window hWnd | 253 // Create a WebView, whose parent is the main window hWnd |
242 env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>( | 254 env->CreateWebView(hWnd, Callback<IWebView2CreateWebViewCompletedHandler>( |
243 [hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT { | 255 [hWnd](HRESULT result, IWebView2WebView* webview) -> HRESULT { |
244 if (webview != nullptr) { | 256 if (webview != nullptr) { |
261 // Save the token, we might need to dw_window_set_data() this value | 273 // Save the token, we might need to dw_window_set_data() this value |
262 // for later use to remove the handlers | 274 // for later use to remove the handlers |
263 EventRegistrationToken token; | 275 EventRegistrationToken token; |
264 | 276 |
265 // Register a handler for the NavigationStarting event. | 277 // Register a handler for the NavigationStarting event. |
266 // This handler will check the domain being navigated to, and if the domain | |
267 // matches a list of blocked sites, it will cancel the navigation and | |
268 // possibly display a warning page. It will also disable JavaScript on | |
269 // selected websites. | |
270 webview->add_NavigationStarting( | 278 webview->add_NavigationStarting( |
271 Callback<IWebView2NavigationStartingEventHandler>( | 279 Callback<IWebView2NavigationStartingEventHandler>( |
272 [hWnd](IWebView2WebView* sender, | 280 [hWnd](IWebView2WebView* sender, |
273 IWebView2NavigationStartingEventArgs* args) -> HRESULT | 281 IWebView2NavigationStartingEventArgs* args) -> HRESULT |
274 { | 282 { |
280 | 288 |
281 return S_OK; | 289 return S_OK; |
282 }).Get(), &token); | 290 }).Get(), &token); |
283 | 291 |
284 // Register a handler for the DocumentStateChanged event. | 292 // Register a handler for the DocumentStateChanged event. |
285 // This handler will read the webview's source URI and update | |
286 // the app's address bar. | |
287 webview->add_DocumentStateChanged( | 293 webview->add_DocumentStateChanged( |
288 Callback<IWebView2DocumentStateChangedEventHandler>( | 294 Callback<IWebView2DocumentStateChangedEventHandler>( |
289 [hWnd](IWebView2WebView* sender, | 295 [hWnd](IWebView2WebView* sender, |
290 IWebView2DocumentStateChangedEventArgs* args) -> HRESULT | 296 IWebView2DocumentStateChangedEventArgs* args) -> HRESULT |
291 { | 297 { |
297 | 303 |
298 return S_OK; | 304 return S_OK; |
299 }).Get(), &token); | 305 }).Get(), &token); |
300 | 306 |
301 // Register a handler for the NavigationCompleted event. | 307 // Register a handler for the NavigationCompleted event. |
302 // If the navigation was successful, update the back and forward buttons. | |
303 webview->add_NavigationCompleted( | 308 webview->add_NavigationCompleted( |
304 Callback<IWebView2NavigationCompletedEventHandler>( | 309 Callback<IWebView2NavigationCompletedEventHandler>( |
305 [hWnd](IWebView2WebView* sender, | 310 [hWnd](IWebView2WebView* sender, |
306 IWebView2NavigationCompletedEventArgs* args) -> HRESULT | 311 IWebView2NavigationCompletedEventArgs* args) -> HRESULT |
307 { | 312 { |