ReactOS  0.4.14-dev-98-gb0d4763
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 
30 typedef 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 
53 static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
54 {
55  const char *ptr;
56  LPWSTR *param, merge;
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(!strncasecmp("name", ptr, len)) {
66  param = &item->name;
67  }else if(!strncasecmp("merge", ptr, len)) {
68  param = &merge;
69  }else if(!strncasecmp("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);
100  heap_free(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;
137  ContentItem *item;
138 
139  *insert_type = INSERT_NEXT;
140 
141  strbuf_init(&node);
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(!strcasecmp(node_name.buf, "/object"))
152  break;
153  if(!strcasecmp(node_name.buf, "param"))
154  parse_obj_node_param(item, hhc_root, node.buf, info->pCHMInfo->codePage);
155 
156  strbuf_zero(&node);
157  }
158 
159  strbuf_free(&node);
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 
190  strbuf_init(&node);
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(!strcasecmp(node_name.buf, "object")) {
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(!strcasecmp(node_name.buf, "ul")) {
214  new_item = parse_ul(info, stream, hhc_root);
215  insert_item(prev, new_item, INSERT_CHILD);
216  }else if(!strcasecmp(node_name.buf, "/ul")) {
217  break;
218  }
219 
220  strbuf_zero(&node);
221  }
222 
223  strbuf_free(&node);
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 
238  strbuf_init(&node);
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(!strcasecmp(node_name.buf, "ul")) {
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 
256  strbuf_zero(&node);
257  }
258 
259  strbuf_free(&node);
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 = strlenW(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) {
287  fill_content_tree(hwnd, item, item->child);
288  }else {
289  fill_content_tree(hwnd, parent, item->child);
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 {
306  IStream *stream;
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 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
void get_node_name(strbuf_t *node, strbuf_t *name)
Definition: stream.c:88
HTREEITEM hParent
Definition: commctrl.h:3365
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
WINE_UNICODE_INLINE unsigned int strlenW(const WCHAR *str)
Definition: unicode.h:212
#define TVM_INSERTITEMW
Definition: commctrl.h:3380
void ReleaseContent(HHInfo *info)
Definition: content.c:325
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define strcasecmp
Definition: fake.h:9
#define TVM_SELECTITEM
Definition: commctrl.h:3450
#define TVGN_CARET
Definition: commctrl.h:3433
char * strstr(char *String1, char *String2)
Definition: utclib.c:653
const WCHAR * text
Definition: package.c:1827
const char * get_attr(const char *node, const char *name, int *len)
Definition: stream.c:162
#define WARN(fmt,...)
Definition: debug.h:111
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3236
static ContentItem * parse_sitemap_object(HHInfo *info, stream_t *stream, ContentItem *hhc_root, insert_type_t *insert_type)
Definition: content.c:133
HWND hWnd
Definition: settings.c:17
static void free_content_item(ContentItem *item)
Definition: content.c:35
#define TAB_CONTENTS
Definition: hhctrl.h:116
#define HHTV_FOLDER
Definition: resource.h:58
static void insert_content_item(HWND hwnd, ContentItem *parent, ContentItem *item)
Definition: content.c:265
#define TVIF_SELECTEDIMAGE
Definition: commctrl.h:3243
const char * filename
Definition: ioapi.h:135
BOOL next_node(stream_t *stream, strbuf_t *buf)
Definition: stream.c:140
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
ChmPath merge
Definition: hhctrl.h:68
struct node node
HTREEITEM hInsertAfter
Definition: commctrl.h:3366
_STLP_MOVE_TO_STD_NAMESPACE _OutputIter merge(_InputIter1 __first1, _InputIter1 __last1, _InputIter2 __first2, _InputIter2 __last2, _OutputIter __result)
Definition: _algo.c:1419
#define debugstr_w
Definition: kernel32.h:32
static PVOID ptr
Definition: dispmode.c:27
void strbuf_free(strbuf_t *buf)
Definition: stream.c:38
const WCHAR * str
#define strncasecmp
Definition: fake.h:10
smooth NULL
Definition: ftsmooth.c:416
static void set_item_parents(ContentItem *parent, ContentItem *item)
Definition: content.c:295
LONG_PTR LPARAM
Definition: windef.h:208
#define TVI_LAST
Definition: commctrl.h:3342
static ContentItem * parse_hhc(HHInfo *, IStream *, ContentItem *, insert_type_t *)
Definition: content.c:229
void ActivateContentTopic(HWND hWnd, LPCWSTR filename, ContentItem *item)
Definition: content.c:330
#define TRACE(s)
Definition: solgame.cpp:4
static void fill_content_tree(HWND hwnd, ContentItem *parent, ContentItem *item)
Definition: content.c:282
r parent
Definition: btrfs.c:2897
WCHAR * decode_html(const char *html_fragment, int html_fragment_len, UINT code_page)
Definition: help.c:1890
LPWSTR chm_file
Definition: hhctrl.h:55
Definition: hhctrl.h:185
GLfloat param
Definition: glext.h:5796
static void strbuf_init(strbuf *buf)
Definition: registrar.c:83
int ret
#define HHTV_DOCUMENT
Definition: resource.h:57
struct ContentItem * next
Definition: hhctrl.h:62
Definition: parse.h:22
static __inline const char * debugstr_an(const char *s, int n)
Definition: compat.h:47
GLuint GLuint stream
Definition: glext.h:7522
static ContentItem * insert_item(ContentItem *item, ContentItem *new_item, insert_type_t insert_type)
Definition: content.c:106
insert_type_t
Definition: content.c:30
GLenum GLsizei len
Definition: glext.h:6722
WINE_DEFAULT_DEBUG_CHANNEL(inetcpl)
void stream_init(stream_t *stream, IStream *str)
Definition: stream.c:54
#define local
Definition: zutil.h:30
void SetChmPath(ChmPath *file, LPCWSTR base_file, LPCWSTR path)
Definition: chm.c:496
static unsigned __int64 next
Definition: rand_nt.c:6
static ATOM item
Definition: dde.c:856
#define TVIF_TEXT
Definition: commctrl.h:3238
static void parse_obj_node_param(ContentItem *item, ContentItem *hhc_root, const char *text, UINT code_page)
Definition: content.c:53
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define TVIF_IMAGE
Definition: commctrl.h:3239
unsigned int UINT
Definition: ndis.h:50
IStream * GetChmStream(CHMInfo *info, LPCWSTR parent_chm, ChmPath *chm_file)
Definition: chm.c:532
#define TVIF_PARAM
Definition: commctrl.h:3240
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define memset(x, y, z)
Definition: compat.h:39
static ContentItem * parse_ul(HHInfo *info, stream_t *stream, ContentItem *hhc_root)
Definition: content.c:184
void strbuf_zero(strbuf_t *buf)
Definition: stream.c:33
static BOOL heap_free(void *mem)
Definition: appwiz.h:75
Definition: dlist.c:348
void InitContent(HHInfo *info)
Definition: content.c:304
char * buf
Definition: stream.h:27