ReactOS 0.4.15-dev-7931-gfd331f1
content.c
Go to the documentation of this file.
1/*
2 * Copyright 2007 Jacek Caban for CodeWeavers
3 * Copyright 2011 Owen Rudge for CodeWeavers
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20#define NONAMELESSUNION
21
22#include "hhctrl.h"
23#include "stream.h"
24#include "resource.h"
25
26#include "wine/debug.h"
27
29
30typedef enum {
34
36{
38
39 while(item) {
40 next = item->next;
41
42 free_content_item(item->child);
43
44 heap_free(item->name);
45 heap_free(item->local);
46 heap_free(item->merge.chm_file);
47 heap_free(item->merge.chm_index);
48
49 item = next;
50 }
51}
52
53static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
54{
55 const char *ptr;
57 int len;
58
59 ptr = get_attr(text, "name", &len);
60 if(!ptr) {
61 WARN("name attr not found\n");
62 return;
63 }
64
65 if(!_strnicmp("name", ptr, len)) {
66 param = &item->name;
67 }else if(!_strnicmp("merge", ptr, len)) {
68 param = &merge;
69 }else if(!_strnicmp("local", ptr, len)) {
70 param = &item->local;
71 }else {
72 WARN("unhandled param %s\n", debugstr_an(ptr, len));
73 return;
74 }
75
76 ptr = get_attr(text, "value", &len);
77 if(!ptr) {
78 WARN("value attr not found\n");
79 return;
80 }
81
82 /*
83 * "merge" parameter data (referencing another CHM file) can be incorporated into the "local" parameter
84 * by specifying the filename in the format:
85 * MS-ITS:file.chm::/local_path.htm
86 */
87 if(param == &item->local && strstr(ptr, "::"))
88 {
89 const char *local = strstr(ptr, "::")+2;
90 int local_len = len-(local-ptr);
91
92 item->local = decode_html(local, local_len, code_page);
93 param = &merge;
94 }
95
96 *param = decode_html(ptr, len, code_page);
97
98 if(param == &merge) {
99 SetChmPath(&item->merge, hhc_root->merge.chm_file, merge);
101 }
102}
103
105
107{
108 if(!item)
109 return new_item;
110
111 if(!new_item)
112 return item;
113
114 switch(insert_type) {
115 case INSERT_NEXT:
116 item->next = new_item;
117 return new_item;
118 case INSERT_CHILD:
119 if(item->child) {
120 ContentItem *iter = item->child;
121 while(iter->next)
122 iter = iter->next;
123 iter->next = new_item;
124 }else {
125 item->child = new_item;
126 }
127 return item;
128 }
129
130 return NULL;
131}
132
134 insert_type_t *insert_type)
135{
136 strbuf_t node, node_name;
138
139 *insert_type = INSERT_NEXT;
140
142 strbuf_init(&node_name);
143
144 item = heap_alloc_zero(sizeof(ContentItem));
145
146 while(next_node(stream, &node)) {
147 get_node_name(&node, &node_name);
148
149 TRACE("%s\n", node.buf);
150
151 if(!_strnicmp(node_name.buf, "/object", -1))
152 break;
153 if(!_strnicmp(node_name.buf, "param", -1))
154 parse_obj_node_param(item, hhc_root, node.buf, info->pCHMInfo->codePage);
155
157 }
158
160 strbuf_free(&node_name);
161
162 if(item->merge.chm_index) {
163 IStream *merge_stream;
164
165 merge_stream = GetChmStream(info->pCHMInfo, item->merge.chm_file, &item->merge);
166 if(merge_stream) {
167 item->child = parse_hhc(info, merge_stream, hhc_root, insert_type);
168 IStream_Release(merge_stream);
169 }else {
170 WARN("Could not get %s::%s stream\n", debugstr_w(item->merge.chm_file),
171 debugstr_w(item->merge.chm_file));
172
173 if(!item->name) {
175 item = NULL;
176 }
177 }
178
179 }
180
181 return item;
182}
183
185{
186 strbuf_t node, node_name;
187 ContentItem *ret = NULL, *prev = NULL, *new_item = NULL;
188 insert_type_t it;
189
191 strbuf_init(&node_name);
192
193 while(next_node(stream, &node)) {
194 get_node_name(&node, &node_name);
195
196 TRACE("%s\n", node.buf);
197
198 if(!_strnicmp(node_name.buf, "object", -1)) {
199 const char *ptr;
200 int len;
201
202 static const char sz_text_sitemap[] = "text/sitemap";
203
204 ptr = get_attr(node.buf, "type", &len);
205
206 if(ptr && len == sizeof(sz_text_sitemap)-1
207 && !memcmp(ptr, sz_text_sitemap, len)) {
208 new_item = parse_sitemap_object(info, stream, hhc_root, &it);
209 prev = insert_item(prev, new_item, it);
210 if(!ret)
211 ret = prev;
212 }
213 }else if(!_strnicmp(node_name.buf, "ul", -1)) {
214 new_item = parse_ul(info, stream, hhc_root);
215 insert_item(prev, new_item, INSERT_CHILD);
216 }else if(!_strnicmp(node_name.buf, "/ul", -1)) {
217 break;
218 }
219
221 }
222
224 strbuf_free(&node_name);
225
226 return ret;
227}
228
230 insert_type_t *insert_type)
231{
233 strbuf_t node, node_name;
234 ContentItem *ret = NULL, *prev = NULL;
235
236 *insert_type = INSERT_NEXT;
237
239 strbuf_init(&node_name);
240
242
243 while(next_node(&stream, &node)) {
244 get_node_name(&node, &node_name);
245
246 TRACE("%s\n", node.buf);
247
248 if(!_strnicmp(node_name.buf, "ul", -1)) {
249 ContentItem *item = parse_ul(info, &stream, hhc_root);
250 prev = insert_item(prev, item, INSERT_CHILD);
251 if(!ret)
252 ret = prev;
253 *insert_type = INSERT_CHILD;
254 }
255
257 }
258
260 strbuf_free(&node_name);
261
262 return ret;
263}
264
266{
267 TVINSERTSTRUCTW tvis;
268
269 memset(&tvis, 0, sizeof(tvis));
271 tvis.u.item.cchTextMax = lstrlenW(item->name)+1;
272 tvis.u.item.pszText = item->name;
273 tvis.u.item.lParam = (LPARAM)item;
274 tvis.u.item.iImage = item->child ? HHTV_FOLDER : HHTV_DOCUMENT;
275 tvis.u.item.iSelectedImage = item->child ? HHTV_FOLDER : HHTV_DOCUMENT;
276 tvis.hParent = parent ? parent->id : 0;
277 tvis.hInsertAfter = TVI_LAST;
278
280}
281
283{
284 while(item) {
285 if(item->name) {
288 }else {
290 }
291 item = item->next;
292 }
293}
294
296{
297 while(item) {
298 item->parent = parent;
299 set_item_parents(item, item->child);
300 item = item->next;
301 }
302}
303
305{
307 insert_type_t insert_type;
308
309 info->content = heap_alloc_zero(sizeof(ContentItem));
310 SetChmPath(&info->content->merge, info->pCHMInfo->szFile, info->WinType.pszToc);
311
312 stream = GetChmStream(info->pCHMInfo, info->pCHMInfo->szFile, &info->content->merge);
313 if(!stream) {
314 TRACE("Could not get content stream\n");
315 return;
316 }
317
318 info->content->child = parse_hhc(info, stream, info->content, &insert_type);
319 IStream_Release(stream);
320
321 set_item_parents(NULL, info->content);
322 fill_content_tree(info->tabs[TAB_CONTENTS].hwnd, NULL, info->content);
323}
324
326{
327 free_content_item(info->content);
328}
329
331{
332 if (lstrcmpiW(item->local, filename) == 0)
333 {
335 return;
336 }
337
338 if (item->next)
340
341 if (item->child)
343}
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _OutputIter __result)
Definition: _algo.c:1419
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
HWND hWnd
Definition: settings.c:17
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: debug.h:112
void SetChmPath(ChmPath *file, LPCWSTR base_file, LPCWSTR path)
Definition: chm.c:503
IStream * GetChmStream(CHMInfo *info, LPCWSTR parent_chm, ChmPath *chm_file)
Definition: chm.c:539
#define NULL
Definition: types.h:112
static void strbuf_init(strbuf *buf)
Definition: registrar.c:82
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:55
#define _strnicmp(_String1, _String2, _MaxCount)
Definition: compat.h:23
#define lstrlenW
Definition: compat.h:750
WCHAR * decode_html(const char *html_fragment, int html_fragment_len, UINT code_page)
Definition: help.c:1902
#define HHTV_FOLDER
Definition: resource.h:62
#define HHTV_DOCUMENT
Definition: resource.h:61
const char * get_attr(const char *node, const char *name, int *len)
Definition: stream.c:162
void strbuf_free(strbuf_t *buf)
Definition: stream.c:38
BOOL next_node(stream_t *stream, strbuf_t *buf)
Definition: stream.c:140
void strbuf_zero(strbuf_t *buf)
Definition: stream.c:33
void stream_init(stream_t *stream, IStream *str)
Definition: stream.c:54
void get_node_name(strbuf_t *node, strbuf_t *name)
Definition: stream.c:88
const WCHAR * text
Definition: package.c:1799
r parent
Definition: btrfs.c:3010
#define local
Definition: zutil.h:30
GLfloat param
Definition: glext.h:5796
GLenum GLsizei len
Definition: glext.h:6722
#define TAB_CONTENTS
Definition: hhctrl.h:116
const char * filename
Definition: ioapi.h:137
#define debugstr_w
Definition: kernel32.h:32
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
static PVOID ptr
Definition: dispmode.c:27
static ATOM item
Definition: dde.c:856
unsigned int UINT
Definition: ndis.h:50
#define TVI_LAST
Definition: commctrl.h:3370
#define TVIF_TEXT
Definition: commctrl.h:3266
#define TVIF_IMAGE
Definition: commctrl.h:3267
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3264
#define TVM_SELECTITEM
Definition: commctrl.h:3478
#define TVM_INSERTITEMW
Definition: commctrl.h:3408
#define TVGN_CARET
Definition: commctrl.h:3461
#define TVIF_PARAM
Definition: commctrl.h:3268
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3271
static unsigned __int64 next
Definition: rand_nt.c:6
const WCHAR * str
Console I/O streams.
#define memset(x, y, z)
Definition: compat.h:39
#define TRACE(s)
Definition: solgame.cpp:4
LPWSTR chm_file
Definition: hhctrl.h:55
struct ContentItem * next
Definition: hhctrl.h:62
ChmPath merge
Definition: hhctrl.h:68
Definition: hhctrl.h:185
char * buf
Definition: stream.h:27
Definition: parse.h:23
HTREEITEM hParent
Definition: commctrl.h:3393
HTREEITEM hInsertAfter
Definition: commctrl.h:3394
Definition: dlist.c:348
int ret
static ContentItem * parse_hhc(HHInfo *, IStream *, ContentItem *, insert_type_t *)
Definition: content.c:229
static void free_content_item(ContentItem *item)
Definition: content.c:35
insert_type_t
Definition: content.c:30
@ INSERT_NEXT
Definition: content.c:31
@ INSERT_CHILD
Definition: content.c:32
static ContentItem * insert_item(ContentItem *item, ContentItem *new_item, insert_type_t insert_type)
Definition: content.c:106
static void set_item_parents(ContentItem *parent, ContentItem *item)
Definition: content.c:295
void InitContent(HHInfo *info)
Definition: content.c:304
static void insert_content_item(HWND hwnd, ContentItem *parent, ContentItem *item)
Definition: content.c:265
void ActivateContentTopic(HWND hWnd, LPCWSTR filename, ContentItem *item)
Definition: content.c:330
static void fill_content_tree(HWND hwnd, ContentItem *parent, ContentItem *item)
Definition: content.c:282
void ReleaseContent(HHInfo *info)
Definition: content.c:325
static ContentItem * parse_sitemap_object(HHInfo *info, stream_t *stream, ContentItem *hhc_root, insert_type_t *insert_type)
Definition: content.c:133
static ContentItem * parse_ul(HHInfo *info, stream_t *stream, ContentItem *hhc_root)
Definition: content.c:184
static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
Definition: content.c:53
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185