2007-02-28 03:59:07 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2007 Jacek Caban for CodeWeavers
|
2011-01-17 23:26:46 +01:00
|
|
|
* Copyright 2011 Owen Rudge for CodeWeavers
|
2007-02-28 03:59:07 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define NONAMELESSUNION
|
|
|
|
|
|
|
|
#include "hhctrl.h"
|
2010-01-28 03:12:21 +01:00
|
|
|
#include "stream.h"
|
2012-06-22 19:07:19 +02:00
|
|
|
#include "resource.h"
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
INSERT_NEXT,
|
|
|
|
INSERT_CHILD
|
|
|
|
} insert_type_t;
|
|
|
|
|
2007-04-25 15:37:36 +02:00
|
|
|
static void free_content_item(ContentItem *item)
|
|
|
|
{
|
|
|
|
ContentItem *next;
|
|
|
|
|
|
|
|
while(item) {
|
|
|
|
next = item->next;
|
|
|
|
|
|
|
|
free_content_item(item->child);
|
|
|
|
|
2007-12-09 16:29:44 +01:00
|
|
|
heap_free(item->name);
|
|
|
|
heap_free(item->local);
|
|
|
|
heap_free(item->merge.chm_file);
|
|
|
|
heap_free(item->merge.chm_index);
|
2007-04-25 15:37:36 +02:00
|
|
|
|
|
|
|
item = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-20 22:31:19 +02:00
|
|
|
static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
|
2007-02-28 03:59:07 +01:00
|
|
|
{
|
|
|
|
const char *ptr;
|
|
|
|
LPWSTR *param, merge;
|
2012-02-13 19:45:29 +01:00
|
|
|
int len;
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
ptr = get_attr(text, "name", &len);
|
|
|
|
if(!ptr) {
|
|
|
|
WARN("name attr not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-03 18:20:14 +02:00
|
|
|
if(!_strnicmp("name", ptr, len)) {
|
2007-02-28 03:59:07 +01:00
|
|
|
param = &item->name;
|
2019-04-03 18:20:14 +02:00
|
|
|
}else if(!_strnicmp("merge", ptr, len)) {
|
2007-02-28 03:59:07 +01:00
|
|
|
param = &merge;
|
2019-04-03 18:20:14 +02:00
|
|
|
}else if(!_strnicmp("local", ptr, len)) {
|
2007-02-28 03:59:07 +01:00
|
|
|
param = &item->local;
|
|
|
|
}else {
|
|
|
|
WARN("unhandled param %s\n", debugstr_an(ptr, len));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = get_attr(text, "value", &len);
|
|
|
|
if(!ptr) {
|
|
|
|
WARN("value attr not found\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-13 19:45:29 +01:00
|
|
|
/*
|
|
|
|
* "merge" parameter data (referencing another CHM file) can be incorporated into the "local" parameter
|
|
|
|
* by specifying the filename in the format:
|
|
|
|
* MS-ITS:file.chm::/local_path.htm
|
|
|
|
*/
|
|
|
|
if(param == &item->local && strstr(ptr, "::"))
|
|
|
|
{
|
|
|
|
const char *local = strstr(ptr, "::")+2;
|
|
|
|
int local_len = len-(local-ptr);
|
|
|
|
|
2012-06-20 22:31:19 +02:00
|
|
|
item->local = decode_html(local, local_len, code_page);
|
2012-02-13 19:45:29 +01:00
|
|
|
param = &merge;
|
|
|
|
}
|
|
|
|
|
2012-06-20 22:31:19 +02:00
|
|
|
*param = decode_html(ptr, len, code_page);
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
if(param == &merge) {
|
2007-03-01 18:28:09 +01:00
|
|
|
SetChmPath(&item->merge, hhc_root->merge.chm_file, merge);
|
2007-12-09 16:29:44 +01:00
|
|
|
heap_free(merge);
|
2007-02-28 03:59:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-01 18:28:09 +01:00
|
|
|
static ContentItem *parse_hhc(HHInfo*,IStream*,ContentItem*,insert_type_t*);
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
static ContentItem *insert_item(ContentItem *item, ContentItem *new_item, insert_type_t insert_type)
|
|
|
|
{
|
|
|
|
if(!item)
|
|
|
|
return new_item;
|
|
|
|
|
2007-04-25 15:37:36 +02:00
|
|
|
if(!new_item)
|
|
|
|
return item;
|
|
|
|
|
2007-02-28 03:59:07 +01:00
|
|
|
switch(insert_type) {
|
|
|
|
case INSERT_NEXT:
|
|
|
|
item->next = new_item;
|
|
|
|
return new_item;
|
|
|
|
case INSERT_CHILD:
|
|
|
|
if(item->child) {
|
|
|
|
ContentItem *iter = item->child;
|
|
|
|
while(iter->next)
|
|
|
|
iter = iter->next;
|
|
|
|
iter->next = new_item;
|
|
|
|
}else {
|
|
|
|
item->child = new_item;
|
|
|
|
}
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-03-01 18:28:09 +01:00
|
|
|
static ContentItem *parse_sitemap_object(HHInfo *info, stream_t *stream, ContentItem *hhc_root,
|
|
|
|
insert_type_t *insert_type)
|
2007-02-28 03:59:07 +01:00
|
|
|
{
|
|
|
|
strbuf_t node, node_name;
|
|
|
|
ContentItem *item;
|
|
|
|
|
|
|
|
*insert_type = INSERT_NEXT;
|
|
|
|
|
|
|
|
strbuf_init(&node);
|
|
|
|
strbuf_init(&node_name);
|
|
|
|
|
2007-12-09 16:29:44 +01:00
|
|
|
item = heap_alloc_zero(sizeof(ContentItem));
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
while(next_node(stream, &node)) {
|
|
|
|
get_node_name(&node, &node_name);
|
|
|
|
|
|
|
|
TRACE("%s\n", node.buf);
|
|
|
|
|
2019-04-03 18:20:14 +02:00
|
|
|
if(!_strnicmp(node_name.buf, "/object", -1))
|
2007-02-28 03:59:07 +01:00
|
|
|
break;
|
2019-04-03 18:20:14 +02:00
|
|
|
if(!_strnicmp(node_name.buf, "param", -1))
|
2012-06-20 22:31:19 +02:00
|
|
|
parse_obj_node_param(item, hhc_root, node.buf, info->pCHMInfo->codePage);
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
strbuf_zero(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_free(&node);
|
|
|
|
strbuf_free(&node_name);
|
|
|
|
|
|
|
|
if(item->merge.chm_index) {
|
|
|
|
IStream *merge_stream;
|
|
|
|
|
|
|
|
merge_stream = GetChmStream(info->pCHMInfo, item->merge.chm_file, &item->merge);
|
|
|
|
if(merge_stream) {
|
2007-03-01 18:28:09 +01:00
|
|
|
item->child = parse_hhc(info, merge_stream, hhc_root, insert_type);
|
2007-02-28 03:59:07 +01:00
|
|
|
IStream_Release(merge_stream);
|
|
|
|
}else {
|
|
|
|
WARN("Could not get %s::%s stream\n", debugstr_w(item->merge.chm_file),
|
|
|
|
debugstr_w(item->merge.chm_file));
|
2007-04-25 15:37:36 +02:00
|
|
|
|
|
|
|
if(!item->name) {
|
|
|
|
free_content_item(item);
|
|
|
|
item = NULL;
|
|
|
|
}
|
2007-02-28 03:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
2007-03-01 18:28:09 +01:00
|
|
|
static ContentItem *parse_ul(HHInfo *info, stream_t *stream, ContentItem *hhc_root)
|
2007-02-28 03:59:07 +01:00
|
|
|
{
|
|
|
|
strbuf_t node, node_name;
|
|
|
|
ContentItem *ret = NULL, *prev = NULL, *new_item = NULL;
|
|
|
|
insert_type_t it;
|
|
|
|
|
|
|
|
strbuf_init(&node);
|
|
|
|
strbuf_init(&node_name);
|
|
|
|
|
|
|
|
while(next_node(stream, &node)) {
|
|
|
|
get_node_name(&node, &node_name);
|
|
|
|
|
|
|
|
TRACE("%s\n", node.buf);
|
|
|
|
|
2019-04-03 18:20:14 +02:00
|
|
|
if(!_strnicmp(node_name.buf, "object", -1)) {
|
2007-02-28 03:59:07 +01:00
|
|
|
const char *ptr;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
static const char sz_text_sitemap[] = "text/sitemap";
|
|
|
|
|
|
|
|
ptr = get_attr(node.buf, "type", &len);
|
|
|
|
|
|
|
|
if(ptr && len == sizeof(sz_text_sitemap)-1
|
|
|
|
&& !memcmp(ptr, sz_text_sitemap, len)) {
|
2007-03-01 18:28:09 +01:00
|
|
|
new_item = parse_sitemap_object(info, stream, hhc_root, &it);
|
2007-02-28 03:59:07 +01:00
|
|
|
prev = insert_item(prev, new_item, it);
|
|
|
|
if(!ret)
|
|
|
|
ret = prev;
|
|
|
|
}
|
2019-04-03 18:20:14 +02:00
|
|
|
}else if(!_strnicmp(node_name.buf, "ul", -1)) {
|
2007-03-01 18:28:09 +01:00
|
|
|
new_item = parse_ul(info, stream, hhc_root);
|
2007-02-28 03:59:07 +01:00
|
|
|
insert_item(prev, new_item, INSERT_CHILD);
|
2019-04-03 18:20:14 +02:00
|
|
|
}else if(!_strnicmp(node_name.buf, "/ul", -1)) {
|
2007-02-28 03:59:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_zero(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_free(&node);
|
|
|
|
strbuf_free(&node_name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-03-01 18:28:09 +01:00
|
|
|
static ContentItem *parse_hhc(HHInfo *info, IStream *str, ContentItem *hhc_root,
|
|
|
|
insert_type_t *insert_type)
|
2007-02-28 03:59:07 +01:00
|
|
|
{
|
|
|
|
stream_t stream;
|
|
|
|
strbuf_t node, node_name;
|
|
|
|
ContentItem *ret = NULL, *prev = NULL;
|
|
|
|
|
|
|
|
*insert_type = INSERT_NEXT;
|
|
|
|
|
|
|
|
strbuf_init(&node);
|
|
|
|
strbuf_init(&node_name);
|
|
|
|
|
|
|
|
stream_init(&stream, str);
|
|
|
|
|
|
|
|
while(next_node(&stream, &node)) {
|
|
|
|
get_node_name(&node, &node_name);
|
|
|
|
|
|
|
|
TRACE("%s\n", node.buf);
|
|
|
|
|
2019-04-03 18:20:14 +02:00
|
|
|
if(!_strnicmp(node_name.buf, "ul", -1)) {
|
2007-03-01 18:28:09 +01:00
|
|
|
ContentItem *item = parse_ul(info, &stream, hhc_root);
|
2007-02-28 03:59:07 +01:00
|
|
|
prev = insert_item(prev, item, INSERT_CHILD);
|
|
|
|
if(!ret)
|
|
|
|
ret = prev;
|
|
|
|
*insert_type = INSERT_CHILD;
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_zero(&node);
|
|
|
|
}
|
|
|
|
|
|
|
|
strbuf_free(&node);
|
|
|
|
strbuf_free(&node_name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-28 04:00:00 +01:00
|
|
|
static void insert_content_item(HWND hwnd, ContentItem *parent, ContentItem *item)
|
|
|
|
{
|
|
|
|
TVINSERTSTRUCTW tvis;
|
|
|
|
|
|
|
|
memset(&tvis, 0, sizeof(tvis));
|
2012-06-22 19:07:19 +02:00
|
|
|
tvis.u.item.mask = TVIF_TEXT|TVIF_PARAM|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
|
2007-02-28 04:00:00 +01:00
|
|
|
tvis.u.item.cchTextMax = strlenW(item->name)+1;
|
|
|
|
tvis.u.item.pszText = item->name;
|
|
|
|
tvis.u.item.lParam = (LPARAM)item;
|
2012-06-22 19:07:19 +02:00
|
|
|
tvis.u.item.iImage = item->child ? HHTV_FOLDER : HHTV_DOCUMENT;
|
|
|
|
tvis.u.item.iSelectedImage = item->child ? HHTV_FOLDER : HHTV_DOCUMENT;
|
2007-02-28 04:00:00 +01:00
|
|
|
tvis.hParent = parent ? parent->id : 0;
|
|
|
|
tvis.hInsertAfter = TVI_LAST;
|
|
|
|
|
|
|
|
item->id = (HTREEITEM)SendMessageW(hwnd, TVM_INSERTITEMW, 0, (LPARAM)&tvis);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void fill_content_tree(HWND hwnd, ContentItem *parent, ContentItem *item)
|
|
|
|
{
|
|
|
|
while(item) {
|
|
|
|
if(item->name) {
|
|
|
|
insert_content_item(hwnd, parent, item);
|
|
|
|
fill_content_tree(hwnd, item, item->child);
|
|
|
|
}else {
|
|
|
|
fill_content_tree(hwnd, parent, item->child);
|
|
|
|
}
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-28 03:59:07 +01:00
|
|
|
static void set_item_parents(ContentItem *parent, ContentItem *item)
|
|
|
|
{
|
|
|
|
while(item) {
|
|
|
|
item->parent = parent;
|
|
|
|
set_item_parents(item, item->child);
|
|
|
|
item = item->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitContent(HHInfo *info)
|
|
|
|
{
|
|
|
|
IStream *stream;
|
|
|
|
insert_type_t insert_type;
|
|
|
|
|
2007-12-09 16:29:44 +01:00
|
|
|
info->content = heap_alloc_zero(sizeof(ContentItem));
|
2007-03-01 18:28:09 +01:00
|
|
|
SetChmPath(&info->content->merge, info->pCHMInfo->szFile, info->WinType.pszToc);
|
2007-02-28 03:59:07 +01:00
|
|
|
|
|
|
|
stream = GetChmStream(info->pCHMInfo, info->pCHMInfo->szFile, &info->content->merge);
|
|
|
|
if(!stream) {
|
|
|
|
TRACE("Could not get content stream\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-03-01 18:28:09 +01:00
|
|
|
info->content->child = parse_hhc(info, stream, info->content, &insert_type);
|
2007-02-28 03:59:07 +01:00
|
|
|
IStream_Release(stream);
|
|
|
|
|
|
|
|
set_item_parents(NULL, info->content);
|
2007-02-28 04:00:00 +01:00
|
|
|
fill_content_tree(info->tabs[TAB_CONTENTS].hwnd, NULL, info->content);
|
2007-02-28 03:59:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ReleaseContent(HHInfo *info)
|
|
|
|
{
|
|
|
|
free_content_item(info->content);
|
|
|
|
}
|
2011-01-17 23:26:46 +01:00
|
|
|
|
|
|
|
void ActivateContentTopic(HWND hWnd, LPCWSTR filename, ContentItem *item)
|
|
|
|
{
|
|
|
|
if (lstrcmpiW(item->local, filename) == 0)
|
|
|
|
{
|
|
|
|
SendMessageW(hWnd, TVM_SELECTITEM, TVGN_CARET, (LPARAM) item->id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item->next)
|
|
|
|
ActivateContentTopic(hWnd, filename, item->next);
|
|
|
|
|
|
|
|
if (item->child)
|
|
|
|
ActivateContentTopic(hWnd, filename, item->child);
|
|
|
|
}
|