r15713 - gnucash/trunk - Add help support on Windows by using the HtmlHelp API.

Andreas Köhler andi5 at cvs.gnucash.org
Tue Mar 13 21:00:06 EDT 2007


Author: andi5
Date: 2007-03-13 21:00:06 -0400 (Tue, 13 Mar 2007)
New Revision: 15713
Trac: http://svn.gnucash.org/trac/changeset/15713

Added:
   gnucash/trunk/src/app-utils/gnc-help-utils.c
   gnucash/trunk/src/app-utils/gnc-help-utils.h
Modified:
   gnucash/trunk/configure.in
   gnucash/trunk/src/app-utils/Makefile.am
   gnucash/trunk/src/gnc-ui.h
   gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
Log:
Add help support on Windows by using the HtmlHelp API.

Find the correct CHM file according to the active locale and call
gnc_show_help in src/app-utils/gnc-help-utils.[ch].  These new files
were necessary because <windows.h> does not like things like GUID.  If
no htmlhelp.h was found, spawn hh to show the chm file.  Otherwise parse
the GKeyFile ending on .hhmap to determine a numeric ID for the given
anchor and use HtmlHelpW.


Modified: gnucash/trunk/configure.in
===================================================================
--- gnucash/trunk/configure.in	2007-03-14 00:41:59 UTC (rev 15712)
+++ gnucash/trunk/configure.in	2007-03-14 01:00:06 UTC (rev 15713)
@@ -136,6 +136,12 @@
 esac
 AC_MSG_RESULT($platform_win32)
 AM_CONDITIONAL(PLATFORM_WIN32, test "x$platform_win32" = "xyes")
+
+if test "x$native_win32" = "xyes" ; then
+  HTMLHELP_LIBS=
+  AC_CHECK_HEADERS(htmlhelp.h,[HTMLHELP_LIBS=-lhtmlhelp],,[#include <windows.h>])
+  AC_SUBST(HTMLHELP_LIBS)
+fi
 ##################################################
   
 STRUCT_TM_GMTOFF_CHECK

Modified: gnucash/trunk/src/app-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/app-utils/Makefile.am	2007-03-14 00:41:59 UTC (rev 15712)
+++ gnucash/trunk/src/app-utils/Makefile.am	2007-03-14 01:00:06 UTC (rev 15713)
@@ -60,6 +60,7 @@
   gnc-euro.h \
   gnc-exp-parser.h \
   gnc-gettext-util.h \
+  gnc-help-utils.h \
   gnc-helpers.h \
   gnc-sx-instance-model.h \
   gnc-ui-common.h \
@@ -106,6 +107,13 @@
   ${gncmod_DATA} \
   ${gncscm_DATA}
 
+if OS_WIN32
+libgncmod_app_utils_la_SOURCES += gnc-help-utils.c
+libgncmod_app_utils_la_LIBADD += $(HTMLHELP_LIBS)
+else
+EXTRA_DIST += gnc-help-utils.c
+endif
+
 if GNUCASH_SEPARATE_BUILDDIR
 #For executing test cases
 SCM_FILE_LINKS = \

Added: gnucash/trunk/src/app-utils/gnc-help-utils.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-help-utils.c	2007-03-14 00:41:59 UTC (rev 15712)
+++ gnucash/trunk/src/app-utils/gnc-help-utils.c	2007-03-14 01:00:06 UTC (rev 15713)
@@ -0,0 +1,151 @@
+/* 
+ * gnc-help-utils.c
+ *
+ * Copyright (C) 2007 Andreas Koehler <andi5.py at gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#include "config.h"
+#include <glib.h>
+
+#ifdef HAVE_HTMLHELP_H
+#    include <windows.h>
+#    include <htmlhelp.h>
+#endif
+
+#include "gnc-help-utils.h"
+
+#ifdef HAVE_HTMLHELP_H
+
+static GHashTable *
+parse_hhmap_file(const gchar *chmfile)
+{
+	gchar *mapfile = NULL, *dot;
+    GKeyFile *keyfile = NULL;
+    GError *error = NULL;
+    gchar **keys = NULL, **key;
+    gint value;
+    GHashTable *ctxtmap = NULL;
+
+    g_return_val_if_fail(chmfile, NULL);
+
+    mapfile = g_new(gchar, strlen(chmfile) + 7);
+    strcpy(mapfile, chmfile);
+    dot = strrchr(mapfile, '.');
+    if (dot)
+        strcpy(dot, ".hhmap");
+    else
+        strcat(mapfile, ".hhmap");
+
+    keyfile = g_key_file_new();
+    if (!g_key_file_load_from_file(keyfile, mapfile, G_KEY_FILE_NONE, &error))
+        goto cleanup_parse;
+        
+    if (NULL == (keys = g_key_file_get_keys(keyfile, "Map", NULL, &error)))
+        goto cleanup_parse;
+
+    ctxtmap = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+    for (key=keys; *key; key++) {
+        value = g_key_file_get_integer(keyfile, "Map", *key, &error);
+        if (error)
+            goto cleanup_parse;
+        else
+            g_hash_table_insert(ctxtmap, g_strdup(*key), GINT_TO_POINTER(value));
+    }
+
+ cleanup_parse:
+    if (error) {
+        g_warning("Could not load help map file: %s", error->message);
+        g_error_free(error);
+        if (ctxtmap)
+            g_hash_table_destroy(ctxtmap);
+        ctxtmap = NULL;
+    }
+    if (keys)
+        g_strfreev(keys);
+    if (keyfile)
+        g_key_file_free (keyfile);
+    if (mapfile)
+        g_free(mapfile);
+
+    return ctxtmap;
+}
+
+void
+gnc_show_htmlhelp(const gchar *chmfile, const gchar *anchor)
+{
+    static GHashTable *chmfile_ctxtmap_map;
+    G_LOCK_DEFINE_STATIC(chmfile_ctxtmap_map);
+    GHashTable *ctxtmap;
+    gboolean create_map = FALSE;
+    wchar_t *wpath;
+    gint id = 0;
+
+    g_return_if_fail(chmfile);
+
+    if (anchor) {
+        G_LOCK(chmfile_ctxtmap_map);
+        if (!chmfile_ctxtmap_map) {
+            chmfile_ctxtmap_map = g_hash_table_new(g_str_hash, g_str_equal);
+            create_map = TRUE;
+        } else {
+            create_map = !g_hash_table_lookup_extended(
+                chmfile_ctxtmap_map, chmfile, NULL, (gpointer) &ctxtmap);
+        }
+
+        if (create_map) {
+            ctxtmap = parse_hhmap_file(chmfile);
+            g_hash_table_insert(chmfile_ctxtmap_map, g_strdup(chmfile), ctxtmap);
+        }
+
+        if (ctxtmap) {
+            gpointer ptr = g_hash_table_lookup(ctxtmap, anchor);
+            if (ptr)
+                id = GPOINTER_TO_INT(ptr);
+        }
+        G_UNLOCK(chmfile_ctxtmap_map);
+
+        if (!id)
+            g_warning("Could not find anchor '%s'", anchor);
+    }
+
+    wpath = g_utf8_to_utf16(chmfile, -1, NULL, NULL, NULL);
+    HtmlHelpW(GetDesktopWindow(), wpath, HH_HELP_CONTEXT, id);
+    g_free(wpath);
+}
+
+#else /* !HAVE_HTMLHELP_H */
+void
+gnc_show_htmlhelp(const gchar *chmfile, const gchar *anchor)
+{
+    gchar *argv[3];
+
+    g_return_if_fail(chmfile);
+
+    argv[0] = "hh";
+    argv[1] = g_strdup(chmfile);
+    argv[2] = NULL;
+
+    if (!g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH,
+                       NULL, NULL, NULL, NULL))
+        if (g_file_test(chmfile, G_FILE_TEST_IS_REGULAR))
+            g_warning("Found CHM help file, but could not spawn hh to open it");
+
+    g_free(argv[1]);
+}
+#endif /* HAVE_HTMLHELP_H */

Added: gnucash/trunk/src/app-utils/gnc-help-utils.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-help-utils.h	2007-03-14 00:41:59 UTC (rev 15712)
+++ gnucash/trunk/src/app-utils/gnc-help-utils.h	2007-03-14 01:00:06 UTC (rev 15713)
@@ -0,0 +1,36 @@
+/* 
+ * gnc-help-utils.h
+ *
+ * Copyright (C) 2007 Andreas Koehler <andi5.py at gmx.net>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#ifndef __GNC_HELP_UTILS_H__
+#define __GNC_HELP_UTILS_H__
+
+#include "config.h"
+#include <glibconfig.h>
+
+#ifdef G_OS_WIN32
+
+void
+gnc_show_htmlhelp(const gchar *chmfile, const gchar *anchor);
+
+#endif /* G_OS_WIN32 */
+
+#endif /* __GNC_HELP_UTILS_H__ */

Modified: gnucash/trunk/src/gnc-ui.h
===================================================================
--- gnucash/trunk/src/gnc-ui.h	2007-03-14 00:41:59 UTC (rev 15712)
+++ gnucash/trunk/src/gnc-ui.h	2007-03-14 01:00:06 UTC (rev 15713)
@@ -39,8 +39,13 @@
 
 
 /** Help Files ******************************************************/
-#define HF_GUIDE             "gnucash-guide.xml"
-#define HF_HELP              "gnucash-help.xml"
+#ifdef G_OS_WIN32
+#    define HF_GUIDE         "gnucash-guide.chm"
+#    define HF_HELP          "gnucash-help.chm"
+#else
+#    define HF_GUIDE         "gnucash-guide.xml"
+#    define HF_HELP          "gnucash-help.xml"
+#endif
 
 /** Links in the Help Files *****************************************/
 #define HL_USAGE             "usage"

Modified: gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2007-03-14 00:41:59 UTC (rev 15712)
+++ gnucash/trunk/src/gnome-utils/gnc-gnome-utils.c	2007-03-14 01:00:06 UTC (rev 15713)
@@ -53,6 +53,9 @@
 #include "dialog-totd.h"
 #include "gnc-ui-util.h"
 #include "gnc-session.h"
+#ifdef G_OS_WIN32
+#    include "gnc-help-utils.h"
+#endif
 
 static QofLogModule log_module = GNC_MOD_GUI;
 static GnomeProgram *gnucash_program = NULL;
@@ -232,6 +235,7 @@
   return;
 }
 
+#ifndef G_OS_WIN32
 void
 gnc_gnome_help (const char *file_name, const char *anchor)
 {
@@ -252,6 +256,37 @@
   g_error_free(error);
 }
 
+#else /* G_OS_WIN32 */
+void
+gnc_gnome_help (const char *file_name, const char *anchor)
+{
+  const gchar * const *lang;
+  gchar *pkgdatadir, *fullpath, *found = NULL;
+  
+  pkgdatadir = gnc_path_get_pkgdatadir ();
+  for (lang=g_get_language_names (); *lang; lang++) {
+    fullpath = g_build_filename (pkgdatadir, "help", *lang, file_name,
+                                 (gchar*) NULL);
+    if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR)) {
+      found = g_strdup (fullpath);
+      g_free (fullpath);
+      break;
+    }
+    g_free (fullpath);
+  }
+  g_free (pkgdatadir);
+
+  if (!found) {
+    const gchar *message =
+      _("GnuCash could not find the files for the help documentation.");
+    gnc_error_dialog (NULL, message);
+  } else {
+    gnc_show_htmlhelp (found, anchor);
+  }
+  g_free (found);
+}
+#endif
+
 /********************************************************************\
  * gnc_gnome_get_pixmap                                             *
  *   returns a GtkWidget given a pixmap filename                    *



More information about the gnucash-changes mailing list