changeset 2000:77e43d71eaa7

Changes to allow mixing C and C++ when including dw.h. Win: Fixes to the last commit for embedding chromium based Edge.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 31 Oct 2019 08:26:58 +0000
parents 4e808c4cadfb
children f7acca46f795
files dw.h win/dw.c win/edge.cpp
diffstat 3 files changed, 108 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/dw.h	Thu Oct 31 07:01:35 2019 +0000
+++ b/dw.h	Thu Oct 31 08:26:58 2019 +0000
@@ -3,6 +3,10 @@
 #ifndef _H_DW
 #define _H_DW
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
 /* Dynamic Windows version numbers */
 #define DW_MAJOR_VERSION 3
 #define DW_MINOR_VERSION 0
@@ -1818,4 +1822,8 @@
 void API _dw_init_thread(void);
 void API _dw_deinit_thread(void);
 
+#ifdef __cplusplus
+}
 #endif
+
+#endif
--- a/win/dw.c	Thu Oct 31 07:01:35 2019 +0000
+++ b/win/dw.c	Thu Oct 31 08:26:58 2019 +0000
@@ -311,6 +311,7 @@
 #if (defined(BUILD_DLL) || defined(BUILD_HTML))
 LRESULT CALLBACK _browserWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 #ifdef BUILD_EDGE
+BOOL _dw_edge_detect(VOID);
 BOOL _DW_EDGE_DETECTED = FALSE;
 LRESULT CALLBACK _edgeWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
 #endif
@@ -5701,7 +5702,6 @@
 void _dw_edge_action(HWND hwnd, int action);
 int _dw_edge_raw(HWND hwnd, LPCWSTR string);
 int _dw_edge_url(HWND hwnd, LPCWSTR url);
-BOOL _dw_edge_detect(VOID);
 #endif
 #endif
 
--- a/win/edge.cpp	Thu Oct 31 07:01:35 2019 +0000
+++ b/win/edge.cpp	Thu Oct 31 08:26:58 2019 +0000
@@ -11,165 +11,152 @@
  */
 #include "dw.h"
 #include "webview2.h"
+#include <wrl.h>
+
+using namespace Microsoft::WRL;
 
 #define _DW_HTML_DATA_NAME (char *)"_dw_edge"
 
-BOOL _dw_edge_detect(VOID)
-{
-	return TRUE;
-}
+extern "C" {
+
+	BOOL _dw_edge_detect(VOID)
+	{
+		return TRUE;
+	}
 
-/******************************* dw_html_action() **************************
- * Implements the functionality of a "Back". "Forward", "Home", "Search",
- * "Refresh", or "Stop" button.
- *
- * hwnd =		Handle to the window hosting the browser object.
- * action =		One of the following:
- *				0 = Move back to the previously viewed web page.
- *				1 = Move forward to the previously viewed web page.
- *				2 = Move to the home page.
- *				3 = Search.
- *				4 = Refresh the page.
- *				5 = Stop the currently loading page.
- *
- * NOTE: EmbedBrowserObject() must have been successfully called once with the
- * specified window, prior to calling this function. You need call
- * EmbedBrowserObject() once only, and then you can make multiple calls to
- * this function to display numerous pages in the specified window.
- */
+	/******************************* dw_html_action() **************************
+	 * Implements the functionality of a "Back". "Forward", "Home", "Search",
+	 * "Refresh", or "Stop" button.
+	 *
+	 * hwnd =		Handle to the window hosting the browser object.
+	 * action =		One of the following:
+	 *				0 = Move back to the previously viewed web page.
+	 *				1 = Move forward to the previously viewed web page.
+	 *				2 = Move to the home page.
+	 *				3 = Search.
+	 *				4 = Refresh the page.
+	 *				5 = Stop the currently loading page.
+	 */
 
-void _dw_edge_action(HWND hwnd, int action)
-{
-	IWebView2WebView* webview;
+	void _dw_edge_action(HWND hwnd, int action)
+	{
+		IWebView2WebView* webview;
 
-	// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
-	// we initially attached the browser object to this window.
+		// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
+		// we initially attached the browser object to this window.
+		webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
 
-	webview = *((IWebView2WebView**)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME));
-	// We want to get the base address (ie, a pointer) to the IWebBrowser2 object embedded within the browser
-	// object, so we can call some of the functions in the former's table.
-	if (webview)
-	{
-		// Ok, now the pointer to our IWebBrowser2 object is in 'webBrowser2', and so its VTable is
-		// webBrowser2->lpVtbl.
-
-		// Call the desired function
-		switch (action)
+		// We want to get the base address (ie, a pointer) to the IWebView2WebView object embedded within the browser
+		// object, so we can call some of the functions in the former's table.
+		if (webview)
 		{
+			// Call the desired function
+			switch (action)
+			{
 			case DW_HTML_GOBACK:
 			{
-				// Call the IWebBrowser2 object's GoBack function.
+				// Call the IWebView2WebView object's GoBack function.
 				webview->GoBack();
 				break;
 			}
 
 			case DW_HTML_GOFORWARD:
 			{
-				// Call the IWebBrowser2 object's GoForward function.
+				// Call the IWebView2WebView object's GoForward function.
 				webview->GoForward();
 				break;
 			}
 
 			case DW_HTML_GOHOME:
 			{
-				// Call the IWebBrowser2 object's GoHome function.
+				// Call the IWebView2WebView object's GoHome function.
 				//webview->GoHome();
 				break;
 			}
 
 			case DW_HTML_SEARCH:
 			{
-				// Call the IWebBrowser2 object's GoSearch function.
+				// Call the IWebView2WebView object's GoSearch function.
 				//webview->GoSearch();
 				break;
 			}
 
 			case DW_HTML_RELOAD:
 			{
-				// Call the IWebBrowser2 object's Refresh function.
+				// Call the IWebView2WebView object's Refresh function.
 				webview->Reload();
 			}
 
 			case DW_HTML_STOP:
 			{
-				// Call the IWebBrowser2 object's Stop function.
+				// Call the IWebView2WebView object's Stop function.
 				//webview->Stop();
 			}
+			}
 		}
 	}
-}
+
+	/******************************* dw_html_raw() ****************************
+	 * Takes a string containing some HTML BODY, and displays it in the specified
+	 * window. For example, perhaps you want to display the HTML text of...
+	 *
+	 * <P>This is a picture.<P><IMG src="mypic.jpg">
+	 *
+	 * hwnd =		Handle to the window hosting the browser object.
+	 * string =		Pointer to nul-terminated string containing the HTML BODY.
+	 *				(NOTE: No <BODY></BODY> tags are required in the string).
+	 *
+	 * RETURNS: 0 if success, or non-zero if an error.
+	 */
 
-/******************************* dw_html_raw() ****************************
- * Takes a string containing some HTML BODY, and displays it in the specified
- * window. For example, perhaps you want to display the HTML text of...
- *
- * <P>This is a picture.<P><IMG src="mypic.jpg">
- *
- * hwnd =		Handle to the window hosting the browser object.
- * string =		Pointer to nul-terminated string containing the HTML BODY.
- *				(NOTE: No <BODY></BODY> tags are required in the string).
- *
- * RETURNS: 0 if success, or non-zero if an error.
- *
- * NOTE: EmbedBrowserObject() must have been successfully called once with the
- * specified window, prior to calling this function. You need call
- * EmbedBrowserObject() once only, and then you can make multiple calls to
- * this function to display numerous pages in the specified window.
- */
+	int _dw_edge_raw(HWND hwnd, LPCWSTR string)
+	{
+		IWebView2WebView* webview;
 
-int _dw_edge_raw(HWND hwnd, LPCWSTR string)
-{
-	IWebView2WebView* webview;
+		// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
+		// we initially attached the browser object to this window.
+		webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
 
-	// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
-	// we initially attached the browser object to this window.
-	webview = *((IWebView2WebView**)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME));
-
-	if (webview)
-	{
-		return DW_ERROR_NONE;
+		if (webview)
+		{
+			return DW_ERROR_NONE;
+		}
+		return DW_ERROR_UNKNOWN;
 	}
-	return DW_ERROR_UNKNOWN;
-}
 
-/******************************* dw_html_url() ****************************
- * Displays a URL, or HTML file on disk.
- *
- * hwnd =		Handle to the window hosting the browser object.
- * webPageName =	Pointer to nul-terminated name of the URL/file.
- *
- * RETURNS: 0 if success, or non-zero if an error.
- *
- * NOTE: EmbedBrowserObject() must have been successfully called once with the
- * specified window, prior to calling this function. You need call
- * EmbedBrowserObject() once only, and then you can make multiple calls to
- * this function to display numerous pages in the specified window.
- */
+	/******************************* dw_html_url() ****************************
+	 * Displays a URL, or HTML file on disk.
+	 *
+	 * hwnd =		Handle to the window hosting the browser object.
+	 * webPageName =	Pointer to nul-terminated name of the URL/file.
+	 *
+	 * RETURNS: 0 if success, or non-zero if an error.
+	 */
 
-int _dw_edge_url(HWND hwnd, LPCWSTR url)
-{
-	IWebView2WebView * webview;
+	int _dw_edge_url(HWND hwnd, LPCWSTR url)
+	{
+		IWebView2WebView* webview;
+
+		// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
+		// we initially attached the browser object to this window.
+		webview = (IWebView2WebView*)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME);
 
-	// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
-	// we initially attached the browser object to this window.
-	webview = *((IWebView2WebView**)dw_window_get_data(hwnd, _DW_HTML_DATA_NAME));
-
-	if (webview)
-	{
-		webview->Navigate(url);
-		return DW_ERROR_NONE;
+		if (webview)
+		{
+			webview->Navigate(url);
+			return DW_ERROR_NONE;
+		}
+		return DW_ERROR_UNKNOWN;
 	}
-	return DW_ERROR_UNKNOWN;
-}
+
+	/************************** browserWindowProc() *************************
+	 * Our message handler for our window to host the browser.
+	 */
 
-/************************** browserWindowProc() *************************
- * Our message handler for our window to host the browser.
- */
-
-LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
-	switch (uMsg)
+	LRESULT CALLBACK _edgeWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 	{
+		switch (uMsg)
+		{
 		case WM_SIZE:
 		{
 			// Resize the browser object to fit the window
@@ -178,10 +165,10 @@
 
 			// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
 			// we initially attached the browser object to this window.
-			webview = *((IWebView2WebView**)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME));
+			webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME);
 			GetClientRect(hWnd, &bounds);
 			// Resize WebView to fit the bounds of the parent window
-			if(webview)
+			if (webview)
 				webview->put_Bounds(bounds);
 			return(0);
 		}
@@ -229,7 +216,7 @@
 
 			// Retrieve the browser object's pointer we stored in our window's GWL_USERDATA when
 			// we initially attached the browser object to this window.
-			webview = *((IWebView2WebView**)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME));
+			webview = (IWebView2WebView*)dw_window_get_data(hWnd, _DW_HTML_DATA_NAME);
 			if (webview)
 			{
 				dw_window_set_data(hWnd, _DW_HTML_DATA_NAME, NULL);
@@ -238,8 +225,8 @@
 			}
 			return(TRUE);
 		}
-	}
+		}
 
-	return(DefWindowProc(hWnd, uMsg, wParam, lParam));
+		return(DefWindowProc(hWnd, uMsg, wParam, lParam));
+	}
 }
-