hhctrl.ocx: Implement more navigation of chm to TOC, default topic and specific title.
authorHin-Tak Leung <Hin-Tak@localhost.localdomain>
Tue, 25 Mar 2008 20:55:07 +0000 (20:55 +0000)
committerAlexandre Julliard <julliard@winehq.org>
Thu, 27 Mar 2008 11:46:10 +0000 (12:46 +0100)
dlls/hhctrl.ocx/chm.c
dlls/hhctrl.ocx/hhctrl.c
dlls/hhctrl.ocx/hhctrl.h

index 710013e59135727747bb236dc3faaa3c6d2a6cbc..ece05f06202a0ad822f7c7bf70abfd41d32dd25f 100644 (file)
@@ -113,11 +113,20 @@ static BOOL ReadChmSystem(CHMInfo *chm)
             break;
 
         switch(entry.code) {
+        case 0x0:
+            TRACE("TOC is %s\n", debugstr_an(buf, entry.len));
+            heap_free(chm->defToc);
+            chm->defToc = strdupnAtoW(buf, entry.len);
+            break;
         case 0x2:
             TRACE("Default topic is %s\n", debugstr_an(buf, entry.len));
+            heap_free(chm->defTopic);
+            chm->defTopic = strdupnAtoW(buf, entry.len);
             break;
         case 0x3:
             TRACE("Title is %s\n", debugstr_an(buf, entry.len));
+            heap_free(chm->defTitle);
+            chm->defTitle = strdupnAtoW(buf, entry.len);
             break;
         case 0x5:
             TRACE("Default window is %s\n", debugstr_an(buf, entry.len));
@@ -212,7 +221,26 @@ BOOL LoadWinTypeFromCHM(HHInfo *info)
 
     hr = IStorage_OpenStream(pStorage, windowsW, NULL, STGM_READ, 0, &pStream);
     if (FAILED(hr))
-        return FALSE;
+    {
+        /* no defined window types so use (hopefully) sane defaults */
+        static const WCHAR defaultwinW[] = {'d','e','f','a','u','l','t','w','i','n','\0'};
+        static const WCHAR null[] = {0};
+        memset((void*)&(info->WinType), 0, sizeof(info->WinType));
+        info->WinType.cbStruct=sizeof(info->WinType);
+        info->WinType.fUniCodeStrings=TRUE;
+        info->WinType.pszType=strdupW(defaultwinW);
+        info->WinType.pszToc = strdupW(info->pCHMInfo->defToc);
+        info->WinType.pszIndex = strdupW(null);
+        info->WinType.fsValidMembers=0;
+        info->WinType.fsWinProperties=HHWIN_PROP_TRI_PANE;
+        info->WinType.pszCaption=strdupW(info->pCHMInfo->defTitle);
+        info->WinType.dwStyles=WS_POPUP;
+        info->WinType.dwExStyles=0;
+        info->WinType.nShowState=SW_SHOW;
+        info->WinType.pszFile=strdupW(info->pCHMInfo->defTopic);
+        info->WinType.curNavType=HHWIN_NAVTYPE_TOC;
+        return TRUE;
+    }
 
     /* jump past the #WINDOWS header */
     liOffset.QuadPart = sizeof(DWORD) * 2;
@@ -393,6 +421,9 @@ CHMInfo *CloseCHM(CHMInfo *chm)
     }
 
     heap_free(chm->strings);
+    heap_free(chm->defTitle);
+    heap_free(chm->defTopic);
+    heap_free(chm->defToc);
     heap_free(chm);
 
     return NULL;
index f8b5c99dc6ac10d9714ad207b5abd71afd3b4aef..472b7cfc3108f10c223651f094fb36696fc0c577 100644 (file)
@@ -114,6 +114,7 @@ HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR dat
             memcpy(chm_file, filename, (index-filename)*sizeof(WCHAR));
             chm_file[index-filename] = 0;
             filename = chm_file;
+            index += 2; /* advance beyond "::" for calling NavigateToChm() later */
         }
         else
         {
index 26c9d4da7ebe6c4d1edf5d6416a8a57351547ac9..6f7c96b63c4b7da2c9367e36e8c281d7f5cd188f 100644 (file)
@@ -74,6 +74,10 @@ typedef struct CHMInfo
     IStream *strings_stream;
     char **strings;
     DWORD strings_size;
+
+    WCHAR *defTopic;
+    WCHAR *defTitle;
+    WCHAR *defToc;
 } CHMInfo;
 
 #define TAB_CONTENTS   0
@@ -177,7 +181,7 @@ static inline LPWSTR strdupW(LPCWSTR str)
     return ret;
 }
 
-static inline LPWSTR strdupAtoW(LPCSTR str)
+static inline LPWSTR strdupnAtoW(LPCSTR str, LONG lenA)
 {
     LPWSTR ret;
     DWORD len;
@@ -185,13 +189,28 @@ static inline LPWSTR strdupAtoW(LPCSTR str)
     if(!str)
         return NULL;
 
-    len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
+    if (lenA > 0)
+    {
+        /* find length of string */
+        LPCSTR eos = memchr(str, 0, lenA);
+       if (eos) lenA = eos - str;
+    }
+
+    len = MultiByteToWideChar(CP_ACP, 0, str, lenA, NULL, 0)+1; /* +1 for null pad */
     ret = heap_alloc(len*sizeof(WCHAR));
-    MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
+    MultiByteToWideChar(CP_ACP, 0, str, lenA, ret, len);
+    ret[len-1] = 0;
 
     return ret;
 }
 
+static inline LPWSTR strdupAtoW(LPCSTR str)
+{
+    return strdupnAtoW(str, -1);
+}
+
+
+
 extern HINSTANCE hhctrl_hinstance;
 extern BOOL hh_process;