Commit cf5e6bce authored by Hin-Tak Leung's avatar Hin-Tak Leung Committed by Alexandre Julliard

hhctrl.ocx: Implement more navigation of chm to TOC, default topic and specific title.

parent 4194daf1
......@@ -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;
......
......@@ -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
{
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment