goffice r2312 - in trunk: . goffice goffice/gtk goffice/utils



Author: tml
Date: Fri Feb  6 08:38:15 2009
New Revision: 2312
URL: http://svn.gnome.org/viewvc/goffice?rev=2312&view=rev

Log:
2009-02-06  Tor Lillqvist  <tml iki fi>

	Bug 570095 - [Win32] Make goffice build without urlmon and
	htmlhelp headers and libs

	Unfortunately, MinGW doesn't come with headers and libraries for
	urlmon and htmlhelp. So to make it easier to build goffice with
	MinGW, just include the very minimal declarations needed inline,
	and look up the two functions used at run-time.

	* goffice/utils/go-file.c (find_mime_from_data): Look up
	FindMimeFromData from urlmon.dll.

	* goffice/gtk/goffice-gtk.c (html_help): Look up HtmlHelp from
	hhctrl.ocx.

	* goffice/Makefile.am: Drop -lurlmon and -lhtmlhelp.



Modified:
   trunk/ChangeLog
   trunk/goffice/Makefile.am
   trunk/goffice/gtk/goffice-gtk.c
   trunk/goffice/utils/go-file.c

Modified: trunk/goffice/Makefile.am
==============================================================================
--- trunk/goffice/Makefile.am	(original)
+++ trunk/goffice/Makefile.am	Fri Feb  6 08:38:15 2009
@@ -24,11 +24,6 @@
 if WITH_WIN32
 libgoffice_ GOFFICE_API_VER@_la_DEPENDENCIES = goffice.def
 libgoffice_ GOFFICE_API_VER@_la_LDFLAGS += -no-undefined -export-symbols goffice.def
-if WITH_NATIVE_WIN32
-# libtool thinks there are undefined refs in libhtmlhelp, by pass libtool
-libgoffice_ GOFFICE_API_VER@_la_LDFLAGS += -Wl,-lhtmlhelp
-libgoffice_ GOFFICE_API_VER@_la_LIBADD += -lurlmon
-endif
 endif
 
 BUILT_SOURCES =	goffice-paths.h

Modified: trunk/goffice/gtk/goffice-gtk.c
==============================================================================
--- trunk/goffice/gtk/goffice-gtk.c	(original)
+++ trunk/goffice/gtk/goffice-gtk.c	Fri Feb  6 08:38:15 2009
@@ -781,7 +781,30 @@
 
 #ifdef G_OS_WIN32
 #include <windows.h>
-#include <htmlhelp.h>
+
+typedef HWND (* WINAPI HtmlHelpA_t) (HWND hwndCaller,
+				     LPCSTR pszFile,
+				     UINT uCommand,
+				     DWORD_PTR dwData);
+#define HH_HELP_CONTEXT 0x000F
+
+static HtmlHelpA_t
+html_help (void)
+{
+	HMODULE hhctrl;
+	static HtmlHelpA_t result = NULL;
+	static gboolean beenhere = FALSE;
+
+	if (!beenhere) {
+		hhctrl = LoadLibrary ("hhctrl.ocx");
+		if (hhctrl != NULL)
+			result = (HtmlHelpA_t) GetProcAddress (hhctrl, "HtmlHelpA");
+		beenhere = TRUE;
+	}
+
+	return result;
+}
+
 #endif
 static void
 go_help_display (CBHelpPaths const *paths)
@@ -835,8 +858,9 @@
 		gchar *path = g_build_filename (paths->data_dir, "doc", "C", chmfile, NULL);
 
 		g_free (chmfile);
-		if (!HtmlHelp (GetDesktopWindow (), path, HH_HELP_CONTEXT, id))
-			go_gtk_notice_dialog (NULL, GTK_MESSAGE_ERROR, "Failed to spawn HtmlHelp");
+		if (html_help () == NULL ||
+		    !(html_help ()) (GetDesktopWindow (), path, HH_HELP_CONTEXT, id))
+			go_gtk_notice_dialog (NULL, GTK_MESSAGE_ERROR, "Failed to load HtmlHelp");
 		g_free (path);
 	}
 #else

Modified: trunk/goffice/utils/go-file.c
==============================================================================
--- trunk/goffice/utils/go-file.c	(original)
+++ trunk/goffice/utils/go-file.c	Fri Feb  6 08:38:15 2009
@@ -32,7 +32,7 @@
 #include <gsf/gsf-input-gio.h>
 #include <gsf/gsf-output-gio.h>
 #ifdef G_OS_WIN32
-#include <urlmon.h>
+#include <windows.h>
 #include <io.h>
 #endif
 #ifdef HAVE_GTK_SHOW_URI
@@ -50,6 +50,36 @@
 #include <grp.h>
 #endif
 #include <time.h>
+
+#ifdef G_OS_WIN32
+typedef HRESULT (* STDCALL FindMimeFromData_t) (LPBC pBC,
+						LPCWSTR pwzUrl,
+						LPVOID pBuffer,
+						DWORD cbSize,
+						LPCWSTR pwzMimeProposed,
+						DWORD dwMimeFlags,
+						LPWSTR *ppwzMimeOut,
+						DWORD dwReserved);
+#define FMFD_ENABLEMIMESNIFFING 2
+
+static FindMimeFromData_t
+find_mime_from_data (void)
+{
+	HMODULE urlmon;
+	static FindMimeFromData_t result = NULL;
+	static gboolean beenhere = FALSE;
+
+	if (!beenhere) {
+		urlmon = LoadLibrary ("urlmon.dll");
+		if (urlmon != NULL)
+			result = (FindMimeFromData_t) GetProcAddress (urlmon, "FindMimeFromData");
+		beenhere = TRUE;
+	}
+
+	return result;
+}
+
+#endif
 /* ------------------------------------------------------------------------- */
 
 /*
@@ -997,10 +1027,10 @@
 
 	wuri = g_utf8_to_utf16 (uri, -1, NULL, NULL, NULL);
 	if (wuri &&
-	    FindMimeFromData (NULL, wuri,
-			      NULL, 0,
-			      NULL, FMFD_ENABLEMIMESNIFFING, &mime_type, 0) == NOERROR)
-	{
+	    find_mime_from_data () &&
+	    (find_mime_from_data ()) (NULL, wuri,
+				      NULL, 0,
+				      NULL, FMFD_ENABLEMIMESNIFFING, &mime_type, 0) == NOERROR)	{
 		g_free (wuri);
 		return g_utf16_to_utf8 (mime_type, -1, NULL, NULL, NULL);
 	}
@@ -1047,10 +1077,10 @@
 	/* Do we really need that? */
 	LPWSTR mime_type;
 
-	if (FindMimeFromData (NULL, NULL,
-			      (LPVOID)data, data_size,
-			      NULL, FMFD_ENABLEMIMESNIFFING, &mime_type, 0) == NOERROR)
-	{
+	if (find_mime_from_data () &&
+	    (find_mime_from_data ()) (NULL, NULL,
+				      (LPVOID)data, data_size,
+				      NULL, FMFD_ENABLEMIMESNIFFING, &mime_type, 0) == NOERROR)	{
 		return g_utf16_to_utf8 (mime_type, -1, NULL, NULL, NULL);
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]