comparison win/edge.cpp @ 2018:663d79f28e46

Win: Fix dw_html_javascript_run() when using embedded IE browser widget. Switched both the Edge and IE modules to use the main UTF8 conversion utils.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Fri, 08 Nov 2019 09:49:16 +0000
parents c30f4354966e
children 28809bf17957
comparison
equal deleted inserted replaced
2017:686b2d049056 2018:663d79f28e46
19 #define _DW_HTML_DATA_LOCATION (char *)"_dw_edge_location" 19 #define _DW_HTML_DATA_LOCATION (char *)"_dw_edge_location"
20 #define _DW_HTML_DATA_RAW (char *)"_dw_edge_raw" 20 #define _DW_HTML_DATA_RAW (char *)"_dw_edge_raw"
21 21
22 extern "C" { 22 extern "C" {
23 23
24 /* Import the character conversion functions from dw.c */
25 LPWSTR _myUTF8toWide(char *utf8string, void *outbuf);
26 char *_myWideToUTF8(LPWSTR widestring, void *outbuf);
27 #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 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
24 extern HWND DW_HWND_OBJECT; 30 extern HWND DW_HWND_OBJECT;
25 BOOL DW_EDGE_DETECTED = FALSE; 31 BOOL DW_EDGE_DETECTED = FALSE;
26 32
27 /******************************* dw_edge_detect() ************************** 33 /******************************* dw_edge_detect() **************************
28 * Attempts to create a temporary Edge (Chromium) browser context... 34 * Attempts to create a temporary Edge (Chromium) browser context...
126 * (NOTE: No <BODY></BODY> tags are required in the string). 132 * (NOTE: No <BODY></BODY> tags are required in the string).
127 * 133 *
128 * RETURNS: 0 if success, or non-zero if an error. 134 * RETURNS: 0 if success, or non-zero if an error.
129 */ 135 */
130 136
131 int _dw_edge_raw(HWND hwnd, LPCWSTR string) 137 int _dw_edge_raw(HWND hwnd, char *string)
132 { 138 {
133 IWebView2WebView* webview; 139 IWebView2WebView* webview;
134 140
135 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when 141 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
136 // we initially attached the browser object to this window. 142 // we initially attached the browser object to this window.
137 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); 143 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
138 144
139 if (webview) 145 if (webview)
140 webview->NavigateToString(string); 146 webview->NavigateToString(UTF8toWide(string));
141 else 147 else
142 dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(string)); 148 dw_window_set_data(hwnd, _DW_HTML_DATA_RAW, _wcsdup(UTF8toWide(string)));
143 return DW_ERROR_NONE; 149 return DW_ERROR_NONE;
144 } 150 }
145 151
146 /******************************* dw_edge_url() **************************** 152 /******************************* dw_edge_url() ****************************
147 * Displays a URL, or HTML file on disk. 153 * Displays a URL, or HTML file on disk.
150 * url = Pointer to nul-terminated name of the URL/file. 156 * url = Pointer to nul-terminated name of the URL/file.
151 * 157 *
152 * RETURNS: 0 if success, or non-zero if an error. 158 * RETURNS: 0 if success, or non-zero if an error.
153 */ 159 */
154 160
155 int _dw_edge_url(HWND hwnd, LPCWSTR url) 161 int _dw_edge_url(HWND hwnd, char *url)
156 { 162 {
157 IWebView2WebView* webview; 163 IWebView2WebView* webview;
158 164
159 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when 165 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
160 // we initially attached the browser object to this window. 166 // we initially attached the browser object to this window.
161 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); 167 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
162 168
163 if (webview) 169 if (webview)
164 webview->Navigate(url); 170 webview->Navigate(UTF8toWide(url));
165 else 171 else
166 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(url)); 172 dw_window_set_data(hwnd, _DW_HTML_DATA_LOCATION, _wcsdup(UTF8toWide(url)));
167 return DW_ERROR_NONE; 173 return DW_ERROR_NONE;
168 } 174 }
169
170 /* These reference functions in dw.c */
171 #define WideToUTF8(a) _myWideToUTF8(a, a ? _alloca(WideCharToMultiByte(CP_UTF8, 0, a, -1, NULL, 0, NULL, NULL)) : NULL)
172 char* _myWideToUTF8(LPWSTR widestring, void* outbuf);
173 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
174 175
175 /******************************* dw_edge_javascript_run() **************************** 176 /******************************* dw_edge_javascript_run() ****************************
176 * Runs a javascript in the specified browser context. 177 * Runs a javascript in the specified browser context.
177 * 178 *
178 * hwnd = Handle to the window hosting the browser object. 179 * hwnd = Handle to the window hosting the browser object.
180 * scriptdata = Pointer to user data to be passed to the callback. 181 * scriptdata = Pointer to user data to be passed to the callback.
181 * 182 *
182 * RETURNS: 0 if success, or non-zero if an error. 183 * RETURNS: 0 if success, or non-zero if an error.
183 */ 184 */
184 185
185 int _dw_edge_javascript_run(HWND hwnd, LPCWSTR script, void *scriptdata) 186 int _dw_edge_javascript_run(HWND hwnd, char *script, void *scriptdata)
186 { 187 {
187 IWebView2WebView* webview; 188 IWebView2WebView* webview;
188 189
189 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when 190 // Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
190 // we initially attached the browser object to this window. 191 // we initially attached the browser object to this window.
191 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME); 192 webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
192 193
193 if (webview) 194 if (webview)
194 webview->ExecuteScript(script, 195 webview->ExecuteScript(UTF8toWide(script),
195 Callback<IWebView2ExecuteScriptCompletedHandler>( 196 Callback<IWebView2ExecuteScriptCompletedHandler>(
196 [hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT 197 [hwnd, scriptdata](HRESULT error, PCWSTR result) -> HRESULT
197 { 198 {
198 _wndproc(hwnd, WM_USER + 100, (error == S_OK ? (WPARAM)WideToUTF8((LPWSTR)result) : NULL), (LPARAM)scriptdata); 199 _wndproc(hwnd, WM_USER + 100, (error == S_OK ? (WPARAM)WideToUTF8((LPWSTR)result) : NULL), (LPARAM)scriptdata);
199 return S_OK; 200 return S_OK;