ReactOS 0.4.17-dev-806-gffa4164
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#include "hhctrl.h"
21#include "stream.h"
22#include "resource.h"
23
24#include "wine/debug.h"
25
27
28typedef enum {
32
34{
36
37 while(item) {
38 next = item->next;
39
40 free_content_item(item->child);
41
42 free(item->name);
43 free(item->local);
44 free(item->merge.chm_file);
45 free(item->merge.chm_index);
46
47 item = next;
48 }
49}
50
51static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
52{
53 const char *ptr;
55 int len;
56
57 ptr = get_attr(text, "name", &len);
58 if(!ptr) {
59 WARN("name attr not found\n");
60 return;
61 }
62
63 if(!_strnicmp("name", ptr, len)) {
64 param = &item->name;
65 }else if(!_strnicmp("merge", ptr, len)) {
66 param = &merge;
67 }else if(!_strnicmp("local", ptr, len)) {
68 param = &item->local;
69 }else {
70 WARN("unhandled param %s\n", debugstr_an(ptr, len));
71 return;
72 }
73
74 ptr = get_attr(text, "value", &len);
75 if(!ptr) {
76 WARN("value attr not found\n");
77 return;
78 }
79
80 /*
81 * "merge" parameter data (referencing another CHM file) can be incorporated into the "local" parameter
82 * by specifying the filename in the format:
83 * MS-ITS:file.chm::/local_path.htm
84 */
85 if(param == &item->local && strstr(ptr, "::"))
86 {
87 const char *local = strstr(ptr, "::")+2;
88 int local_len = len-(local-ptr);
89
90 item->local = decode_html(local, local_len, code_page);
91 param = &merge;
92 }
93
95
96 if(param == &merge) {
97 SetChmPath(&item->merge, hhc_root->merge.chm_file, merge);
98 free(merge);
99 }
100}
101
103
105{
106 if(!item)
107 return new_item;
108
109 if(!new_item)
110 return item;
111
112 switch(insert_type) {
113 case INSERT_NEXT:
114 item->next = new_item;
115 return new_item;
116 case INSERT_CHILD:
117 if(item->child) {
118 ContentItem *iter = item->child;
119 while(iter->next)
120 iter = iter->next;
121 iter->next = new_item;
122 }else {
123 item->child = new_item;
124 }
125 return item;
126 }
127
128 return NULL;
129}
130
132 insert_type_t *insert_type)
133{
134 strbuf_t node, node_name;
136
137 *insert_type = INSERT_NEXT;
138
140 strbuf_init(&node_name);
141
142 item = calloc(1, sizeof(ContentItem));
143
144 while(next_node(stream, &node)) {
145 get_node_name(&node, &node_name);
146
147 TRACE("%s\n", node.buf);
148
149 if(!stricmp(node_name.buf, "/object"))
150 break;
151 if(!stricmp(node_name.buf, "param"))
152 parse_obj_node_param(item, hhc_root, node.buf, info->pCHMInfo->codePage);
153
155 }
156
158 strbuf_free(&node_name);
159
160 if(item->merge.chm_index) {
161 IStream *merge_stream;
162
163 merge_stream = GetChmStream(info->pCHMInfo, item->merge.chm_file, &item->merge);
164 if(merge_stream) {
165 item->child = parse_hhc(info, merge_stream, hhc_root, insert_type);
166 IStream_Release(merge_stream);
167 }else {
168 WARN("Could not get %s::%s stream\n", debugstr_w(item->merge.chm_file),
169 debugstr_w(item->merge.chm_file));
170
171 if(!item->name) {
173 item = NULL;
174 }
175 }
176
177 }
178
179 return item;
180}
181
183{
184 strbuf_t node, node_name;
185 ContentItem *ret = NULL, *prev = NULL, *new_item = NULL;
186 insert_type_t it;
187
189 strbuf_init(&node_name);
190
191 while(next_node(stream, &node)) {
192 get_node_name(&node, &node_name);
193
194 TRACE("%s\n", node.buf);
195
196 if(!stricmp(node_name.buf, "object")) {
197 const char *ptr;
198 int len;
199
200 static const char sz_text_sitemap[] = "text/sitemap";
201
202 ptr = get_attr(node.buf, "type", &len);
203
204 if(ptr && len == sizeof(sz_text_sitemap)-1
205 && !memcmp(ptr, sz_text_sitemap, len)) {
206 new_item = parse_sitemap_object(info, stream, hhc_root, &it);
207 prev = insert_item(prev, new_item, it);
208 if(!ret)
209 ret = prev;
210 }
211 }else if(!stricmp(node_name.buf, "ul")) {
212 new_item = parse_ul(info, stream, hhc_root);
213 insert_item(prev, new_item, INSERT_CHILD);
214 }else if(!stricmp(node_name.buf, "/ul")) {
215 break;
216 }
217
219 }
220
222 strbuf_free(&node_name);
223
224 return ret;
225}
226
228 insert_type_t *insert_type)
229{
231 strbuf_t node, node_name;
232 ContentItem *ret = NULL, *prev = NULL;
233
234 *insert_type = INSERT_NEXT;
235
237 strbuf_init(&node_name);
238
240
241 while(next_node(&stream, &node)) {
242 get_node_name(&node, &node_name);
243
244 TRACE("%s\n", node.buf);
245
246 if(!stricmp(node_name.buf, "ul")) {
247 ContentItem *item = parse_ul(info, &stream, hhc_root);
248 prev = insert_item(prev, item, INSERT_CHILD);
249 if(!ret)
250 ret = prev;
251 *insert_type = INSERT_CHILD;
252 }
253
255 }
256
258 strbuf_free(&node_name);
259
260 return ret;
261}
262
264{
265 TVINSERTSTRUCTW tvis;
266
267 memset(&tvis, 0, sizeof(tvis));
269 tvis.item.cchTextMax = lstrlenW(item->name)+1;
270 tvis.item.pszText = item->name;
271 tvis.item.lParam = (LPARAM)item;
272 tvis.item.iImage = item->child ? HHTV_FOLDER : HHTV_DOCUMENT;
273 tvis.item.iSelectedImage = item->child ? HHTV_FOLDER : HHTV_DOCUMENT;
274 tvis.hParent = parent ? parent->id : 0;
275 tvis.hInsertAfter = TVI_LAST;
276
278}
279
281{
282 while(item) {
283 if(item->name) {
286 }else {
288 }
289 item = item->next;
290 }
291}
292
294{
295 while(item) {
296 item->parent = parent;
297 set_item_parents(item, item->child);
298 item = item->next;
299 }
300}
301
303{
305 insert_type_t insert_type;
306
307 info->content = calloc(1, sizeof(ContentItem));
308 SetChmPath(&info->content->merge, info->pCHMInfo->szFile, info->WinType.pszToc);
309
310 stream = GetChmStream(info->pCHMInfo, info->pCHMInfo->szFile, &info->content->merge);
311 if(!stream) {
312 TRACE("Could not get content stream\n");
313 return;
314 }
315
316 info->content->child = parse_hhc(info, stream, info->content, &insert_type);
317 IStream_Release(stream);
318
319 set_item_parents(NULL, info->content);
320 fill_content_tree(info->tabs[TAB_CONTENTS].hwnd, NULL, info->content);
321}
322
324{
325 free_content_item(info->content);
326}
327
329{
330 if (lstrcmpiW(item->local, filename) == 0)
331 {
333 return;
334 }
335
336 if (item->next)
338
339 if (item->child)
341}
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _OutputIter __result)
Definition: _algo.c:1419
HWND hWnd
Definition: settings.c:17
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define WARN(fmt,...)
Definition: precomp.h:61
void SetChmPath(ChmPath *file, LPCWSTR base_file, LPCWSTR path)
Definition: chm.c:516
IStream * GetChmStream(CHMInfo *info, LPCWSTR parent_chm, ChmPath *chm_file)
Definition: chm.c:552
_Out_opt_ UINT * code_page
#define free
Definition: debug_ros.c:5
#define NULL
Definition: types.h:112
static void strbuf_init(strbuf *buf)
Definition: registrar.c:75
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 stricmp(_String1, _String2)
Definition: compat.h:24
#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
int WINAPI lstrcmpiW(LPCWSTR str1, LPCWSTR str2)
Definition: locale.c:4171
const WCHAR * text
Definition: package.c:1794
_ACRTIMP int __cdecl memcmp(const void *, const void *, size_t)
Definition: string.c:2807
_ACRTIMP char *__cdecl strstr(const char *, const char *)
Definition: string.c:3420
return ret
Definition: mutex.c:147
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
unsigned int UINT
Definition: sysinfo.c:13
#define TAB_CONTENTS
Definition: hhctrl.h:115
const char * filename
Definition: ioapi.h:137
#define debugstr_w
Definition: kernel32.h:32
LONG_PTR LPARAM
Definition: minwindef.h:175
static PVOID ptr
Definition: dispmode.c:27
#define TVI_LAST
Definition: commctrl.h:3375
#define TVIF_TEXT
Definition: commctrl.h:3271
#define TVIF_IMAGE
Definition: commctrl.h:3272
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3269
#define TVM_SELECTITEM
Definition: commctrl.h:3483
#define TVM_INSERTITEMW
Definition: commctrl.h:3413
#define TVGN_CARET
Definition: commctrl.h:3466
#define TVIF_PARAM
Definition: commctrl.h:3273
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3276
static unsigned __int64 next
Definition: rand_nt.c:6
#define calloc
Definition: rosglue.h:14
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:54
struct ContentItem * next
Definition: hhctrl.h:61
ChmPath merge
Definition: hhctrl.h:67
Definition: hhctrl.h:184
char * buf
Definition: stream.h:27
Definition: parse.h:23
HTREEITEM hParent
Definition: commctrl.h:3398
HTREEITEM hInsertAfter
Definition: commctrl.h:3399
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56
Definition: dlist.c:348
static ContentItem * parse_hhc(HHInfo *, IStream *, ContentItem *, insert_type_t *)
Definition: content.c:227
static void free_content_item(ContentItem *item)
Definition: content.c:33
insert_type_t
Definition: content.c:28
@ INSERT_NEXT
Definition: content.c:29
@ INSERT_CHILD
Definition: content.c:30
static ContentItem * insert_item(ContentItem *item, ContentItem *new_item, insert_type_t insert_type)
Definition: content.c:104
static void set_item_parents(ContentItem *parent, ContentItem *item)
Definition: content.c:293
void InitContent(HHInfo *info)
Definition: content.c:302
static void insert_content_item(HWND hwnd, ContentItem *parent, ContentItem *item)
Definition: content.c:263
void ActivateContentTopic(HWND hWnd, LPCWSTR filename, ContentItem *item)
Definition: content.c:328
static void fill_content_tree(HWND hwnd, ContentItem *parent, ContentItem *item)
Definition: content.c:280
void ReleaseContent(HHInfo *info)
Definition: content.c:323
static ContentItem * parse_sitemap_object(HHInfo *info, stream_t *stream, ContentItem *hhc_root, insert_type_t *insert_type)
Definition: content.c:131
static ContentItem * parse_ul(HHInfo *info, stream_t *stream, ContentItem *hhc_root)
Definition: content.c:182
static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
Definition: content.c:51
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)