4 * Copyright 1996 Ulrich Schmid
5 * 2002, 2008 Eric Pouech
6 * 2007 Kirill K. Smirnov
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
37 static inline unsigned short GET_USHORT(const BYTE
* buffer
, unsigned i
)
39 return (BYTE
)buffer
[i
] + 0x100 * (BYTE
)buffer
[i
+ 1];
42 static inline short GET_SHORT(const BYTE
* buffer
, unsigned i
)
44 return (BYTE
)buffer
[i
] + 0x100 * (signed char)buffer
[i
+1];
47 static inline unsigned GET_UINT(const BYTE
* buffer
, unsigned i
)
49 return GET_USHORT(buffer
, i
) + 0x10000 * GET_USHORT(buffer
, i
+ 2);
52 static HLPFILE
*first_hlpfile
= 0;
63 static BOOL
HLPFILE_DoReadHlpFile(HLPFILE
*, LPCSTR
);
64 static BOOL
HLPFILE_ReadFileToBuffer(HLPFILE
*, HFILE
);
65 static BOOL
HLPFILE_FindSubFile(HLPFILE
*, LPCSTR
, BYTE
**, BYTE
**);
66 static BOOL
HLPFILE_SystemCommands(HLPFILE
*);
67 static INT
HLPFILE_UncompressedLZ77_Size(BYTE
*ptr
, BYTE
*end
);
68 static BYTE
* HLPFILE_UncompressLZ77(BYTE
*ptr
, BYTE
*end
, BYTE
*newptr
);
69 static BOOL
HLPFILE_UncompressLZ77_Phrases(HLPFILE
*);
70 static BOOL
HLPFILE_Uncompress_Phrases40(HLPFILE
*);
71 static BOOL
HLPFILE_Uncompress_Topic(HLPFILE
*);
72 static BOOL
HLPFILE_GetContext(HLPFILE
*);
73 static BOOL
HLPFILE_GetKeywords(HLPFILE
*);
74 static BOOL
HLPFILE_GetMap(HLPFILE
*);
75 static BOOL
HLPFILE_AddPage(HLPFILE
*, BYTE
*, BYTE
*, unsigned, unsigned);
76 static BOOL
HLPFILE_SkipParagraph(HLPFILE
*, BYTE
*, BYTE
*, unsigned*);
77 static void HLPFILE_Uncompress2(HLPFILE
*, const BYTE
*, const BYTE
*, BYTE
*, const BYTE
*);
78 static BOOL
HLPFILE_Uncompress3(HLPFILE
*, char*, const char*, const BYTE
*, const BYTE
*);
79 static void HLPFILE_UncompressRLE(const BYTE
* src
, const BYTE
* end
, BYTE
** dst
, unsigned dstsz
);
80 static BOOL
HLPFILE_ReadFont(HLPFILE
* hlpfile
);
82 /***********************************************************************
84 * HLPFILE_PageByNumber
86 static HLPFILE_PAGE
*HLPFILE_PageByNumber(HLPFILE
* hlpfile
, UINT wNum
)
91 WINE_TRACE("<%s>[%u]\n", hlpfile
->lpszPath
, wNum
);
93 for (page
= hlpfile
->first_page
; page
&& temp
; page
= page
->next
) temp
--;
95 WINE_ERR("Page of number %u not found in file %s\n", wNum
, hlpfile
->lpszPath
);
99 /******************************************************************
100 * HLPFILE_PageByOffset
104 HLPFILE_PAGE
*HLPFILE_PageByOffset(HLPFILE
* hlpfile
, LONG offset
, ULONG
* relative
)
109 if (!hlpfile
) return 0;
111 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, offset
);
113 if (offset
== 0xFFFFFFFF) return NULL
;
116 for (found
= NULL
, page
= hlpfile
->first_page
; page
; page
= page
->next
)
118 if (page
->offset
<= offset
&& (!found
|| found
->offset
< page
->offset
))
120 *relative
= offset
- page
->offset
;
125 WINE_ERR("Page of offset %u not found in file %s\n",
126 offset
, hlpfile
->lpszPath
);
130 /**************************************************************************
133 * HLPFILE_BPTreeCompare function for '|CONTEXT' B+ tree file
136 static int comp_PageByHash(void *p
, const void *key
,
137 int leaf
, void** next
)
139 LONG lKey
= (LONG_PTR
)key
;
140 LONG lTest
= (INT
)GET_UINT(p
, 0);
142 *next
= (char *)p
+(leaf
?8:6);
143 WINE_TRACE("Comparing '%d' with '%d'\n", lKey
, lTest
);
144 if (lTest
< lKey
) return -1;
145 if (lTest
> lKey
) return 1;
149 /***********************************************************************
153 HLPFILE_PAGE
*HLPFILE_PageByHash(HLPFILE
* hlpfile
, LONG lHash
, ULONG
* relative
)
157 if (!hlpfile
) return NULL
;
158 if (!lHash
) return HLPFILE_Contents(hlpfile
, relative
);
160 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, lHash
);
162 /* For win 3.0 files hash values are really page numbers */
163 if (hlpfile
->version
<= 16)
166 return HLPFILE_PageByNumber(hlpfile
, lHash
);
169 ptr
= HLPFILE_BPTreeSearch(hlpfile
->Context
, LongToPtr(lHash
), comp_PageByHash
);
172 WINE_ERR("Page of hash %x not found in file %s\n", lHash
, hlpfile
->lpszPath
);
176 return HLPFILE_PageByOffset(hlpfile
, GET_UINT(ptr
, 4), relative
);
179 /***********************************************************************
183 HLPFILE_PAGE
*HLPFILE_PageByMap(HLPFILE
* hlpfile
, LONG lMap
, ULONG
* relative
)
187 if (!hlpfile
) return 0;
189 WINE_TRACE("<%s>[%x]\n", hlpfile
->lpszPath
, lMap
);
191 for (i
= 0; i
< hlpfile
->wMapLen
; i
++)
193 if (hlpfile
->Map
[i
].lMap
== lMap
)
194 return HLPFILE_PageByOffset(hlpfile
, hlpfile
->Map
[i
].offset
, relative
);
197 WINE_ERR("Page of Map %x not found in file %s\n", lMap
, hlpfile
->lpszPath
);
201 /***********************************************************************
205 HLPFILE_PAGE
* HLPFILE_Contents(HLPFILE
*hlpfile
, ULONG
* relative
)
207 HLPFILE_PAGE
* page
= NULL
;
209 if (!hlpfile
) return NULL
;
211 page
= HLPFILE_PageByOffset(hlpfile
, hlpfile
->contents_start
, relative
);
214 page
= hlpfile
->first_page
;
220 /***********************************************************************
224 LONG
HLPFILE_Hash(LPCSTR lpszContext
)
229 while ((c
= *lpszContext
++))
232 if (c
>= 'A' && c
<= 'Z') x
= c
- 'A' + 17;
233 if (c
>= 'a' && c
<= 'z') x
= c
- 'a' + 17;
234 if (c
>= '1' && c
<= '9') x
= c
- '0';
235 if (c
== '0') x
= 10;
236 if (c
== '.') x
= 12;
237 if (c
== '_') x
= 13;
238 if (x
) lHash
= lHash
* 43 + x
;
243 /***********************************************************************
245 * HLPFILE_ReadHlpFile
247 HLPFILE
*HLPFILE_ReadHlpFile(LPCSTR lpszPath
)
251 for (hlpfile
= first_hlpfile
; hlpfile
; hlpfile
= hlpfile
->next
)
253 if (!strcmp(lpszPath
, hlpfile
->lpszPath
))
255 hlpfile
->wRefCount
++;
260 hlpfile
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
261 sizeof(HLPFILE
) + lstrlen(lpszPath
) + 1);
262 if (!hlpfile
) return 0;
264 hlpfile
->lpszPath
= (char*)hlpfile
+ sizeof(HLPFILE
);
265 hlpfile
->contents_start
= 0xFFFFFFFF;
266 hlpfile
->next
= first_hlpfile
;
267 hlpfile
->wRefCount
= 1;
269 strcpy(hlpfile
->lpszPath
, lpszPath
);
271 first_hlpfile
= hlpfile
;
272 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
;
274 if (!HLPFILE_DoReadHlpFile(hlpfile
, lpszPath
))
276 HLPFILE_FreeHlpFile(hlpfile
);
283 /***********************************************************************
285 * HLPFILE_DoReadHlpFile
287 static BOOL
HLPFILE_DoReadHlpFile(HLPFILE
*hlpfile
, LPCSTR lpszPath
)
294 unsigned index
, old_index
, offset
, len
, offs
;
296 hFile
= OpenFile(lpszPath
, &ofs
, OF_READ
);
297 if (hFile
== HFILE_ERROR
) return FALSE
;
299 ret
= HLPFILE_ReadFileToBuffer(hlpfile
, hFile
);
301 if (!ret
) return FALSE
;
303 if (!HLPFILE_SystemCommands(hlpfile
)) return FALSE
;
305 /* load phrases support */
306 if (!HLPFILE_UncompressLZ77_Phrases(hlpfile
))
307 HLPFILE_Uncompress_Phrases40(hlpfile
);
309 if (!HLPFILE_Uncompress_Topic(hlpfile
)) return FALSE
;
310 if (!HLPFILE_ReadFont(hlpfile
)) return FALSE
;
312 buf
= hlpfile
->topic_map
[0];
319 if (hlpfile
->version
<= 16)
321 index
= (ref
- 0x0C) / hlpfile
->dsize
;
322 offset
= (ref
- 0x0C) % hlpfile
->dsize
;
326 index
= (ref
- 0x0C) >> 14;
327 offset
= (ref
- 0x0C) & 0x3FFF;
330 if (hlpfile
->version
<= 16 && index
!= old_index
&& index
!= 0)
332 /* we jumped to the next block, adjust pointers */
337 WINE_TRACE("ref=%08x => [%u/%u]\n", ref
, index
, offset
);
339 if (index
>= hlpfile
->topic_maplen
) {WINE_WARN("maplen\n"); break;}
340 buf
= hlpfile
->topic_map
[index
] + offset
;
341 if (buf
+ 0x15 >= hlpfile
->topic_end
) {WINE_WARN("extra\n"); break;}
342 end
= min(buf
+ GET_UINT(buf
, 0), hlpfile
->topic_end
);
343 if (index
!= old_index
) {offs
= 0; old_index
= index
;}
348 if (!HLPFILE_AddPage(hlpfile
, buf
, end
, ref
, index
* 0x8000L
+ offs
)) return FALSE
;
354 if (!HLPFILE_SkipParagraph(hlpfile
, buf
, end
, &len
)) return FALSE
;
359 WINE_ERR("buf[0x14] = %x\n", buf
[0x14]);
362 if (hlpfile
->version
<= 16)
364 ref
+= GET_UINT(buf
, 0xc);
365 if (GET_UINT(buf
, 0xc) == 0)
369 ref
= GET_UINT(buf
, 0xc);
370 } while (ref
!= 0xffffffff);
372 HLPFILE_GetKeywords(hlpfile
);
373 HLPFILE_GetMap(hlpfile
);
374 if (hlpfile
->version
<= 16) return TRUE
;
375 return HLPFILE_GetContext(hlpfile
);
378 /***********************************************************************
382 static BOOL
HLPFILE_AddPage(HLPFILE
*hlpfile
, BYTE
*buf
, BYTE
*end
, unsigned ref
, unsigned offset
)
386 UINT titlesize
, blocksize
, datalen
;
390 blocksize
= GET_UINT(buf
, 0);
391 datalen
= GET_UINT(buf
, 0x10);
392 title
= buf
+ datalen
;
393 if (title
> end
) {WINE_WARN("page2\n"); return FALSE
;};
395 titlesize
= GET_UINT(buf
, 4);
396 page
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_PAGE
) + titlesize
+ 1);
397 if (!page
) return FALSE
;
398 page
->lpszTitle
= (char*)page
+ sizeof(HLPFILE_PAGE
);
400 if (titlesize
> blocksize
- datalen
)
402 /* need to decompress */
403 if (hlpfile
->hasPhrases
)
404 HLPFILE_Uncompress2(hlpfile
, title
, end
, (BYTE
*)page
->lpszTitle
, (BYTE
*)page
->lpszTitle
+ titlesize
);
405 else if (hlpfile
->hasPhrases40
)
406 HLPFILE_Uncompress3(hlpfile
, page
->lpszTitle
, page
->lpszTitle
+ titlesize
, title
, end
);
409 WINE_FIXME("Text size is too long, splitting\n");
410 titlesize
= blocksize
- datalen
;
411 memcpy(page
->lpszTitle
, title
, titlesize
);
415 memcpy(page
->lpszTitle
, title
, titlesize
);
417 page
->lpszTitle
[titlesize
] = '\0';
419 if (hlpfile
->first_page
)
421 hlpfile
->last_page
->next
= page
;
422 page
->prev
= hlpfile
->last_page
;
423 hlpfile
->last_page
= page
;
427 hlpfile
->first_page
= page
;
428 hlpfile
->last_page
= page
;
432 page
->file
= hlpfile
;
434 page
->first_paragraph
= NULL
;
435 page
->first_macro
= NULL
;
436 page
->first_link
= NULL
;
437 page
->wNumber
= GET_UINT(buf
, 0x21);
438 page
->offset
= offset
;
439 page
->reference
= ref
;
441 page
->browse_bwd
= GET_UINT(buf
, 0x19);
442 page
->browse_fwd
= GET_UINT(buf
, 0x1D);
444 WINE_TRACE("Added page[%d]: title='%s' %08x << %08x >> %08x\n",
445 page
->wNumber
, page
->lpszTitle
,
446 page
->browse_bwd
, page
->offset
, page
->browse_fwd
);
448 memset(&attributes
, 0, sizeof(attributes
));
450 /* now load macros */
451 ptr
= page
->lpszTitle
+ strlen(page
->lpszTitle
) + 1;
452 while (ptr
< page
->lpszTitle
+ titlesize
)
454 unsigned len
= strlen(ptr
);
457 WINE_TRACE("macro: %s\n", ptr
);
458 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + len
+ 1);
459 macro
->lpszMacro
= macro_str
= (char*)(macro
+ 1);
460 memcpy(macro_str
, ptr
, len
+ 1);
461 /* FIXME: shall we really link macro in reverse order ??
462 * may produce strange results when played at page opening
464 macro
->next
= page
->first_macro
;
465 page
->first_macro
= macro
;
472 static long fetch_long(BYTE
** ptr
)
478 ret
= (*(unsigned long*)(*ptr
) - 0x80000000L
) / 2;
483 ret
= (*(unsigned short*)(*ptr
) - 0x8000) / 2;
490 static unsigned long fetch_ulong(BYTE
** ptr
)
496 ret
= *(unsigned long*)(*ptr
) / 2;
501 ret
= *(unsigned short*)(*ptr
) / 2;
507 static short fetch_short(BYTE
** ptr
)
513 ret
= (*(unsigned short*)(*ptr
) - 0x8000) / 2;
518 ret
= (*(unsigned char*)(*ptr
) - 0x80) / 2;
524 static unsigned short fetch_ushort(BYTE
** ptr
)
530 ret
= *(unsigned short*)(*ptr
) / 2;
535 ret
= *(unsigned char*)(*ptr
) / 2;
541 /***********************************************************************
543 * HLPFILE_SkipParagraph
545 static BOOL
HLPFILE_SkipParagraph(HLPFILE
*hlpfile
, BYTE
*buf
, BYTE
*end
, unsigned* len
)
549 if (!hlpfile
->first_page
) {WINE_WARN("no page\n"); return FALSE
;};
550 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
553 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
556 *len
= fetch_ushort(&tmp
);
558 else *len
= end
-buf
-15;
563 /******************************************************************
564 * HLPFILE_DecompressGfx
566 * Decompress the data part of a bitmap or a metafile
568 static BYTE
* HLPFILE_DecompressGfx(BYTE
* src
, unsigned csz
, unsigned sz
, BYTE packing
)
575 WINE_TRACE("Unpacking (%d) from %u bytes to %u bytes\n", packing
, csz
, sz
);
579 case 0: /* uncompressed */
581 WINE_WARN("Bogus gfx sizes (uncompressed): %u / %u\n", sz
, csz
);
585 tmp
= dst
= HeapAlloc(GetProcessHeap(), 0, sz
);
586 if (!dst
) return NULL
;
587 HLPFILE_UncompressRLE(src
, src
+ csz
, &tmp
, sz
);
589 WINE_WARN("Bogus gfx sizes (RunLen): %lu/%u\n", (SIZE_T
)(tmp
- dst
), sz
);
592 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
593 dst
= HeapAlloc(GetProcessHeap(), 0, sz77
);
594 if (!dst
) return NULL
;
595 HLPFILE_UncompressLZ77(src
, src
+ csz
, dst
);
597 WINE_WARN("Bogus gfx sizes (LZ77): %u / %u\n", sz77
, sz
);
599 case 3: /* LZ77 then RLE */
600 sz77
= HLPFILE_UncompressedLZ77_Size(src
, src
+ csz
);
601 tmp
= HeapAlloc(GetProcessHeap(), 0, sz77
);
602 if (!tmp
) return FALSE
;
603 HLPFILE_UncompressLZ77(src
, src
+ csz
, tmp
);
604 dst
= tmp2
= HeapAlloc(GetProcessHeap(), 0, sz
);
607 HeapFree(GetProcessHeap(), 0, tmp
);
610 HLPFILE_UncompressRLE(tmp
, tmp
+ sz77
, &tmp2
, sz
);
611 if (tmp2
- dst
!= sz
)
612 WINE_WARN("Bogus gfx sizes (LZ77+RunLen): %lu / %u\n", (SIZE_T
)(tmp2
- dst
), sz
);
613 HeapFree(GetProcessHeap(), 0, tmp
);
616 WINE_FIXME("Unsupported packing %u\n", packing
);
622 static BOOL
HLPFILE_RtfAddRawString(struct RtfData
* rd
, const char* str
, size_t sz
)
624 if (!rd
) return TRUE
; /* FIXME: TEMP */
625 if (rd
->ptr
+ sz
>= rd
->data
+ rd
->allocated
)
627 char* new = HeapReAlloc(GetProcessHeap(), 0, rd
->data
, rd
->allocated
*= 2);
628 if (!new) return FALSE
;
629 rd
->ptr
= new + (rd
->ptr
- rd
->data
);
632 memcpy(rd
->ptr
, str
, sz
);
638 static BOOL
HLPFILE_RtfAddControl(struct RtfData
* rd
, const char* str
)
640 if (!rd
) return TRUE
; /* FIXME: TEMP */
641 if (*str
== '\\' || *str
== '{') rd
->in_text
= FALSE
;
642 else if (*str
== '}') rd
->in_text
= TRUE
;
643 return HLPFILE_RtfAddRawString(rd
, str
, strlen(str
));
646 static BOOL
HLPFILE_RtfAddText(struct RtfData
* rd
, const char* str
)
653 if (!rd
) return TRUE
; /* FIXME: TEMP */
656 if (!HLPFILE_RtfAddRawString(rd
, " ", 1)) return FALSE
;
659 for (last
= p
= str
; *p
; p
++)
661 if (*p
< 0) /* escape non ASCII chars */
664 rlen
= sprintf(xx
, "\\'%x", *(const BYTE
*)p
);
669 case '{': rlen
= 2; replace
= "\\{"; break;
670 case '}': rlen
= 2; replace
= "\\}"; break;
671 case '\\': rlen
= 2; replace
= "\\\\"; break;
674 if ((p
!= last
&& !HLPFILE_RtfAddRawString(rd
, last
, p
- last
)) ||
675 !HLPFILE_RtfAddRawString(rd
, replace
, rlen
)) return FALSE
;
678 return HLPFILE_RtfAddRawString(rd
, last
, p
- last
);
681 /******************************************************************
685 static BOOL
HLPFILE_RtfAddHexBytes(struct RtfData
* rd
, const void* _ptr
, unsigned sz
)
689 const BYTE
* ptr
= _ptr
;
690 static const char* _2hex
= "0123456789abcdef";
692 if (!rd
) return TRUE
; /* FIXME: TEMP */
695 if (!HLPFILE_RtfAddRawString(rd
, " ", 1)) return FALSE
;
698 for (; sz
; sz
-= step
)
701 for (i
= 0; i
< step
; i
++)
703 tmp
[2 * i
+ 0] = _2hex
[*ptr
>> 4];
704 tmp
[2 * i
+ 1] = _2hex
[*ptr
++ & 0xF];
706 if (!HLPFILE_RtfAddRawString(rd
, tmp
, 2 * step
)) return FALSE
;
711 /******************************************************************
712 * HLPFILE_RtfAddBitmap
715 static BOOL
HLPFILE_RtfAddBitmap(struct RtfData
* rd
, BYTE
* beg
, BYTE type
, BYTE pack
)
720 unsigned long off
, csz
;
725 bi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*bi
));
726 if (!bi
) return FALSE
;
728 ptr
= beg
+ 2; /* for type and pack */
730 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
731 bi
->bmiHeader
.biXPelsPerMeter
= fetch_ulong(&ptr
);
732 bi
->bmiHeader
.biYPelsPerMeter
= fetch_ulong(&ptr
);
733 bi
->bmiHeader
.biPlanes
= fetch_ushort(&ptr
);
734 bi
->bmiHeader
.biBitCount
= fetch_ushort(&ptr
);
735 bi
->bmiHeader
.biWidth
= fetch_ulong(&ptr
);
736 bi
->bmiHeader
.biHeight
= fetch_ulong(&ptr
);
737 bi
->bmiHeader
.biClrUsed
= fetch_ulong(&ptr
);
738 bi
->bmiHeader
.biClrImportant
= fetch_ulong(&ptr
);
739 bi
->bmiHeader
.biCompression
= BI_RGB
;
740 if (bi
->bmiHeader
.biBitCount
> 32) WINE_FIXME("Unknown bit count %u\n", bi
->bmiHeader
.biBitCount
);
741 if (bi
->bmiHeader
.biPlanes
!= 1) WINE_FIXME("Unsupported planes %u\n", bi
->bmiHeader
.biPlanes
);
742 bi
->bmiHeader
.biSizeImage
= (((bi
->bmiHeader
.biWidth
* bi
->bmiHeader
.biBitCount
+ 31) & ~31) / 8) * bi
->bmiHeader
.biHeight
;
743 WINE_TRACE("planes=%d bc=%d size=(%d,%d)\n",
744 bi
->bmiHeader
.biPlanes
, bi
->bmiHeader
.biBitCount
,
745 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
747 csz
= fetch_ulong(&ptr
);
748 fetch_ulong(&ptr
); /* hotspot size */
750 off
= GET_UINT(ptr
, 0); ptr
+= 4;
751 /* GET_UINT(ptr, 0); hotspot offset */ ptr
+= 4;
753 /* now read palette info */
758 nc
= bi
->bmiHeader
.biClrUsed
;
759 /* not quite right, especially for bitfields type of compression */
760 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
761 nc
= 1 << bi
->bmiHeader
.biBitCount
;
763 bi
= HeapReAlloc(GetProcessHeap(), 0, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
));
764 if (!bi
) return FALSE
;
765 for (i
= 0; i
< nc
; i
++)
767 bi
->bmiColors
[i
].rgbBlue
= ptr
[0];
768 bi
->bmiColors
[i
].rgbGreen
= ptr
[1];
769 bi
->bmiColors
[i
].rgbRed
= ptr
[2];
770 bi
->bmiColors
[i
].rgbReserved
= 0;
774 pict_beg
= HLPFILE_DecompressGfx(beg
+ off
, csz
, bi
->bmiHeader
.biSizeImage
, pack
);
777 if (!HLPFILE_RtfAddControl(rd
, "{\\pict")) goto done
;
780 sprintf(tmp
, "\\dibitmap0\\picw%d\\pich%d",
781 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
782 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
783 if (!HLPFILE_RtfAddHexBytes(rd
, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
))) goto done
;
787 sprintf(tmp
, "\\wbitmap0\\wbmbitspixel%d\\wbmplanes%d\\picw%d\\pich%d",
788 bi
->bmiHeader
.biBitCount
, bi
->bmiHeader
.biPlanes
,
789 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
790 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
792 if (!HLPFILE_RtfAddHexBytes(rd
, pict_beg
, bi
->bmiHeader
.biSizeImage
)) goto done
;
793 if (!HLPFILE_RtfAddControl(rd
, "}")) goto done
;
797 HeapFree(GetProcessHeap(), 0, bi
);
798 if (pict_beg
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, pict_beg
);
803 /******************************************************************
804 * HLPFILE_RtfAddMetaFile
807 static BOOL
HLPFILE_RtfAddMetaFile(struct RtfData
* rd
, BYTE
* beg
, BYTE pack
)
810 unsigned long size
, csize
;
811 unsigned long off
, hsoff
;
817 WINE_TRACE("Loading metafile\n");
819 ptr
= beg
+ 2; /* for type and pack */
821 mm
= fetch_ushort(&ptr
); /* mapping mode */
822 sprintf(tmp
, "{\\pict\\wmetafile%d\\picw%d\\pich%d",
823 mm
, GET_USHORT(ptr
, 0), GET_USHORT(ptr
, 2));
824 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
827 size
= fetch_ulong(&ptr
); /* decompressed size */
828 csize
= fetch_ulong(&ptr
); /* compressed size */
829 fetch_ulong(&ptr
); /* hotspot size */
830 off
= GET_UINT(ptr
, 0);
831 hsoff
= GET_UINT(ptr
, 4);
834 WINE_TRACE("sz=%lu csz=%lu offs=%lu/%u,%lu\n",
835 size
, csize
, off
, ptr
- beg
, hsoff
);
837 bits
= HLPFILE_DecompressGfx(beg
+ off
, csize
, size
, pack
);
838 if (!bits
) return FALSE
;
840 ret
= HLPFILE_RtfAddHexBytes(rd
, bits
, size
) &&
841 HLPFILE_RtfAddControl(rd
, "}");
843 if (bits
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, bits
);
848 /******************************************************************
849 * HLPFILE_RtfAddGfxByAddr
852 static BOOL
HLPFILE_RtfAddGfxByAddr(struct RtfData
* rd
, HLPFILE
*hlpfile
,
853 BYTE
* ref
, unsigned long size
)
857 numpict
= GET_USHORT(ref
, 2);
858 WINE_TRACE("Got picture magic=%04x #=%d\n", GET_USHORT(ref
, 0), numpict
);
860 for (i
= 0; i
< numpict
; i
++)
866 WINE_TRACE("Offset[%d] = %x\n", i
, GET_UINT(ref
, (1 + i
) * 4));
867 beg
= ptr
= ref
+ GET_UINT(ref
, (1 + i
) * 4);
874 case 5: /* device dependent bmp */
875 case 6: /* device independent bmp */
876 HLPFILE_RtfAddBitmap(rd
, beg
, type
, pack
);
879 HLPFILE_RtfAddMetaFile(rd
, beg
, pack
);
881 default: WINE_FIXME("Unknown type %u\n", type
); return FALSE
;
884 /* FIXME: hotspots */
886 /* FIXME: implement support for multiple picture format */
887 if (numpict
!= 1) WINE_FIXME("Supporting only one bitmap format per logical bitmap (for now). Using first format\n");
893 /******************************************************************
894 * HLPFILE_RtfAddGfxByIndex
898 static BOOL
HLPFILE_RtfAddGfxByIndex(struct RtfData
* rd
, HLPFILE
*hlpfile
,
904 WINE_TRACE("Loading picture #%d\n", index
);
906 sprintf(tmp
, "|bm%u", index
);
908 if (!HLPFILE_FindSubFile(hlpfile
, tmp
, &ref
, &end
)) {WINE_WARN("no sub file\n"); return FALSE
;}
911 return HLPFILE_RtfAddGfxByAddr(rd
, hlpfile
, ref
, end
- ref
);
914 /******************************************************************
919 static BOOL
HLPFILE_LoadBitmap(BYTE
* beg
, BYTE type
, BYTE pack
,
920 HLPFILE_PARAGRAPH
* paragraph
)
925 unsigned long off
, csz
;
928 bi
= HeapAlloc(GetProcessHeap(), 0, sizeof(*bi
));
929 if (!bi
) return FALSE
;
931 ptr
= beg
+ 2; /* for type and pack */
933 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
934 bi
->bmiHeader
.biXPelsPerMeter
= fetch_ulong(&ptr
);
935 bi
->bmiHeader
.biYPelsPerMeter
= fetch_ulong(&ptr
);
936 bi
->bmiHeader
.biPlanes
= fetch_ushort(&ptr
);
937 bi
->bmiHeader
.biBitCount
= fetch_ushort(&ptr
);
938 bi
->bmiHeader
.biWidth
= fetch_ulong(&ptr
);
939 bi
->bmiHeader
.biHeight
= fetch_ulong(&ptr
);
940 bi
->bmiHeader
.biClrUsed
= fetch_ulong(&ptr
);
941 bi
->bmiHeader
.biClrImportant
= fetch_ulong(&ptr
);
942 bi
->bmiHeader
.biCompression
= BI_RGB
;
943 if (bi
->bmiHeader
.biBitCount
> 32) WINE_FIXME("Unknown bit count %u\n", bi
->bmiHeader
.biBitCount
);
944 if (bi
->bmiHeader
.biPlanes
!= 1) WINE_FIXME("Unsupported planes %u\n", bi
->bmiHeader
.biPlanes
);
945 bi
->bmiHeader
.biSizeImage
= (((bi
->bmiHeader
.biWidth
* bi
->bmiHeader
.biBitCount
+ 31) & ~31) / 8) * bi
->bmiHeader
.biHeight
;
946 WINE_TRACE("planes=%d bc=%d size=(%d,%d)\n",
947 bi
->bmiHeader
.biPlanes
, bi
->bmiHeader
.biBitCount
,
948 bi
->bmiHeader
.biWidth
, bi
->bmiHeader
.biHeight
);
950 csz
= fetch_ulong(&ptr
);
951 fetch_ulong(&ptr
); /* hotspot size */
953 off
= GET_UINT(ptr
, 0); ptr
+= 4;
954 /* GET_UINT(ptr, 0); hotspot offset */ ptr
+= 4;
956 /* now read palette info */
959 unsigned nc
= bi
->bmiHeader
.biClrUsed
;
962 /* not quite right, especially for bitfields type of compression */
963 if (!nc
&& bi
->bmiHeader
.biBitCount
<= 8)
964 nc
= 1 << bi
->bmiHeader
.biBitCount
;
966 bi
= HeapReAlloc(GetProcessHeap(), 0, bi
, sizeof(*bi
) + nc
* sizeof(RGBQUAD
));
967 if (!bi
) return FALSE
;
968 for (i
= 0; i
< nc
; i
++)
970 bi
->bmiColors
[i
].rgbBlue
= ptr
[0];
971 bi
->bmiColors
[i
].rgbGreen
= ptr
[1];
972 bi
->bmiColors
[i
].rgbRed
= ptr
[2];
973 bi
->bmiColors
[i
].rgbReserved
= 0;
977 pict_beg
= HLPFILE_DecompressGfx(beg
+ off
, csz
, bi
->bmiHeader
.biSizeImage
, pack
);
979 paragraph
->u
.gfx
.u
.bmp
.hBitmap
= CreateDIBitmap(hdc
= GetDC(0), &bi
->bmiHeader
,
983 if (!paragraph
->u
.gfx
.u
.bmp
.hBitmap
)
984 WINE_ERR("Couldn't create bitmap\n");
986 HeapFree(GetProcessHeap(), 0, bi
);
987 if (pict_beg
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, pict_beg
);
992 /******************************************************************
993 * HLPFILE_LoadMetaFile
997 static BOOL
HLPFILE_LoadMetaFile(BYTE
* beg
, BYTE pack
, HLPFILE_PARAGRAPH
* paragraph
)
1000 unsigned long size
, csize
;
1001 unsigned long off
, hsoff
;
1003 LPMETAFILEPICT lpmfp
;
1005 WINE_TRACE("Loading metafile\n");
1007 ptr
= beg
+ 2; /* for type and pack */
1009 lpmfp
= ¶graph
->u
.gfx
.u
.mfp
;
1010 lpmfp
->mm
= fetch_ushort(&ptr
); /* mapping mode */
1012 lpmfp
->xExt
= GET_USHORT(ptr
, 0);
1013 lpmfp
->yExt
= GET_USHORT(ptr
, 2);
1016 size
= fetch_ulong(&ptr
); /* decompressed size */
1017 csize
= fetch_ulong(&ptr
); /* compressed size */
1018 fetch_ulong(&ptr
); /* hotspot size */
1019 off
= GET_UINT(ptr
, 0);
1020 hsoff
= GET_UINT(ptr
, 4);
1023 WINE_TRACE("sz=%lu csz=%lu (%d,%d) offs=%lu/%lu,%lu\n",
1024 size
, csize
, lpmfp
->xExt
, lpmfp
->yExt
, off
, (SIZE_T
)(ptr
- beg
), hsoff
);
1026 bits
= HLPFILE_DecompressGfx(beg
+ off
, csize
, size
, pack
);
1027 if (!bits
) return FALSE
;
1029 paragraph
->cookie
= para_metafile
;
1031 lpmfp
->hMF
= SetMetaFileBitsEx(size
, bits
);
1034 WINE_FIXME("Couldn't load metafile\n");
1036 if (bits
!= beg
+ off
) HeapFree(GetProcessHeap(), 0, bits
);
1041 /******************************************************************
1042 * HLPFILE_LoadGfxByAddr
1046 static BOOL
HLPFILE_LoadGfxByAddr(HLPFILE
*hlpfile
, BYTE
* ref
,
1048 HLPFILE_PARAGRAPH
* paragraph
)
1050 unsigned i
, numpict
;
1052 numpict
= GET_USHORT(ref
, 2);
1053 WINE_TRACE("Got picture magic=%04x #=%d\n",
1054 GET_USHORT(ref
, 0), numpict
);
1056 for (i
= 0; i
< numpict
; i
++)
1062 WINE_TRACE("Offset[%d] = %x\n", i
, GET_UINT(ref
, (1 + i
) * 4));
1063 beg
= ptr
= ref
+ GET_UINT(ref
, (1 + i
) * 4);
1070 case 5: /* device dependent bmp */
1071 case 6: /* device independent bmp */
1072 HLPFILE_LoadBitmap(beg
, type
, pack
, paragraph
);
1075 HLPFILE_LoadMetaFile(beg
, pack
, paragraph
);
1077 default: WINE_FIXME("Unknown type %u\n", type
); return FALSE
;
1080 /* FIXME: hotspots */
1082 /* FIXME: implement support for multiple picture format */
1083 if (numpict
!= 1) WINE_FIXME("Supporting only one bitmap format per logical bitmap (for now). Using first format\n");
1089 /******************************************************************
1090 * HLPFILE_LoadGfxByIndex
1094 static BOOL
HLPFILE_LoadGfxByIndex(HLPFILE
*hlpfile
, unsigned index
,
1095 HLPFILE_PARAGRAPH
* paragraph
)
1101 WINE_TRACE("Loading picture #%d\n", index
);
1103 if (index
< hlpfile
->numBmps
&& hlpfile
->bmps
[index
] != NULL
)
1105 paragraph
->u
.gfx
.u
.bmp
.hBitmap
= hlpfile
->bmps
[index
];
1109 sprintf(tmp
, "|bm%u", index
);
1111 if (!HLPFILE_FindSubFile(hlpfile
, tmp
, &ref
, &end
)) {WINE_WARN("no sub file\n"); return FALSE
;}
1115 ret
= HLPFILE_LoadGfxByAddr(hlpfile
, ref
, end
- ref
, paragraph
);
1118 if (ret
&& paragraph
->cookie
== para_bitmap
)
1120 if (index
>= hlpfile
->numBmps
)
1122 hlpfile
->numBmps
= index
+ 1;
1124 hlpfile
->bmps
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->bmps
,
1125 hlpfile
->numBmps
* sizeof(hlpfile
->bmps
[0]));
1127 hlpfile
->bmps
= HeapAlloc(GetProcessHeap(), 0,
1128 hlpfile
->numBmps
* sizeof(hlpfile
->bmps
[0]));
1131 hlpfile
->bmps
[index
] = paragraph
->u
.gfx
.u
.bmp
.hBitmap
;
1136 /******************************************************************
1141 static HLPFILE_LINK
* HLPFILE_AllocLink(struct RtfData
* rd
, int cookie
,
1142 const char* str
, unsigned len
, LONG hash
,
1143 unsigned clrChange
, unsigned wnd
)
1148 /* FIXME: should build a string table for the attributes.link.lpszPath
1149 * they are reallocated for each link
1151 if (len
== -1) len
= strlen(str
);
1152 link
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_LINK
) + len
+ 1);
1153 if (!link
) return NULL
;
1155 link
->cookie
= cookie
;
1156 link
->string
= link_str
= (char*)(link
+ 1);
1157 memcpy(link_str
, str
, len
);
1158 link_str
[len
] = '\0';
1160 link
->bClrChange
= clrChange
? 1 : 0;
1162 link
->wRefCount
= 1;
1164 link
->next
= rd
->first_link
;
1165 rd
->first_link
= link
;
1166 link
->cpMin
= rd
->char_pos
;
1168 rd
->force_color
= clrChange
;
1170 if (rd
->current_link
) WINE_FIXME("Pending link\n");
1171 rd
->current_link
= link
;
1174 WINE_TRACE("Link[%d] to %s@%08x:%d\n",
1175 link
->cookie
, link
->string
, link
->hash
, link
->window
);
1179 unsigned HLPFILE_HalfPointsToTwips(unsigned pts
)
1181 static unsigned logPxY
;
1184 HDC hdc
= GetDC(NULL
);
1185 logPxY
= GetDeviceCaps(hdc
, LOGPIXELSY
);
1186 ReleaseDC(NULL
, hdc
);
1188 return MulDiv(pts
, 72 * 10, logPxY
);
1191 /***********************************************************************
1193 * HLPFILE_BrowseParagraph
1195 static BOOL
HLPFILE_BrowseParagraph(HLPFILE_PAGE
* page
, struct RtfData
* rd
, BYTE
*buf
, BYTE
* end
)
1197 HLPFILE_PARAGRAPH
*paragraph
, **paragraphptr
;
1199 BYTE
*format
, *format_end
;
1200 char *text
, *text_base
, *text_end
;
1201 long size
, blocksize
, datalen
;
1202 unsigned short bits
;
1203 unsigned nc
, ncol
= 1;
1204 BOOL in_table
= FALSE
;
1208 for (paragraphptr
= &page
->first_paragraph
; *paragraphptr
;
1209 paragraphptr
= &(*paragraphptr
)->next
) /* Nothing */;
1211 if (buf
+ 0x19 > end
) {WINE_WARN("header too small\n"); return FALSE
;};
1213 blocksize
= GET_UINT(buf
, 0);
1214 size
= GET_UINT(buf
, 0x4);
1215 datalen
= GET_UINT(buf
, 0x10);
1216 text
= text_base
= HeapAlloc(GetProcessHeap(), 0, size
);
1217 if (!text
) return FALSE
;
1218 if (size
> blocksize
- datalen
)
1220 /* need to decompress */
1221 if (page
->file
->hasPhrases
)
1222 HLPFILE_Uncompress2(page
->file
, buf
+ datalen
, end
, (BYTE
*)text
, (BYTE
*)text
+ size
);
1223 else if (page
->file
->hasPhrases40
)
1224 HLPFILE_Uncompress3(page
->file
, text
, text
+ size
, buf
+ datalen
, end
);
1227 WINE_FIXME("Text size is too long, splitting\n");
1228 size
= blocksize
- datalen
;
1229 memcpy(text
, buf
+ datalen
, size
);
1233 memcpy(text
, buf
+ datalen
, size
);
1235 text_end
= text
+ size
;
1237 format
= buf
+ 0x15;
1238 format_end
= buf
+ GET_UINT(buf
, 0x10);
1240 if (buf
[0x14] == 0x20 || buf
[0x14] == 0x23)
1242 fetch_long(&format
);
1243 fetch_ushort(&format
);
1246 if (buf
[0x14] == 0x23)
1253 WINE_TRACE("#cols %u\n", ncol
);
1255 if (type
== 0 || type
== 2)
1260 for (nc
= 0; nc
< ncol
; /**/)
1262 WINE_TRACE("looking for format at offset %lu in column %d\n", (SIZE_T
)(format
- (buf
+ 0x15)), nc
);
1265 nc
= GET_SHORT(format
, 0);
1266 if (nc
== -1) break;
1271 bits
= GET_USHORT(format
, 0); format
+= 2;
1272 if (bits
& 0x0001) fetch_long(&format
);
1275 sprintf(tmp
, "\\sb%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1276 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1280 sprintf(tmp
, "\\sa%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1281 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1285 sprintf(tmp
, "\\sl%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1286 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1290 sprintf(tmp
, "\\li%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1291 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1295 sprintf(tmp
, "\\ri%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1296 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1300 sprintf(tmp
, "\\fi%d", HLPFILE_HalfPointsToTwips(fetch_short(&format
)));
1301 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1305 BYTE brdr
= *format
++;
1308 if (brdr
& 0x01 && !HLPFILE_RtfAddControl(rd
, "\\box")) goto done
;
1309 if (brdr
& 0x02 && !HLPFILE_RtfAddControl(rd
, "\\brdrt")) goto done
;
1310 if (brdr
& 0x04 && !HLPFILE_RtfAddControl(rd
, "\\brdrl")) goto done
;
1311 if (brdr
& 0x08 && !HLPFILE_RtfAddControl(rd
, "\\brdrb")) goto done
;
1312 if (brdr
& 0x10 && !HLPFILE_RtfAddControl(rd
, "\\brdrr")) goto done
;
1313 if (brdr
& 0x20 && !HLPFILE_RtfAddControl(rd
, "\\brdrth")) goto done
;
1314 if (!(brdr
& 0x20) && !HLPFILE_RtfAddControl(rd
, "\\brdrs")) goto done
;
1315 if (brdr
& 0x40 && !HLPFILE_RtfAddControl(rd
, "\\brdrdb")) goto done
;
1318 w
= GET_SHORT(format
, 0); format
+= 2;
1321 sprintf(tmp
, "\\brdrw%d", HLPFILE_HalfPointsToTwips(w
));
1322 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1327 int i
, ntab
= fetch_short(&format
);
1331 for (i
= 0; i
< ntab
; i
++)
1333 tab
= fetch_ushort(&format
);
1334 ts
= (tab
& 0x4000) ? fetch_ushort(&format
) : 0 /* left */;
1337 default: WINE_FIXME("Unknown tab style %x\n", ts
);
1339 case 0: kind
= ""; break;
1340 case 1: kind
= "\\tqr"; break;
1341 case 2: kind
= "\\tqc"; break;
1343 /* FIXME: do kind */
1344 sprintf(tmp
, "%s\\tx%d",
1345 kind
, HLPFILE_HalfPointsToTwips(tab
& 0x3FFF));
1346 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1349 switch (bits
& 0xc00)
1351 default: WINE_FIXME("Unsupported alignment 0xC00\n"); break;
1352 case 0: if (!HLPFILE_RtfAddControl(rd
, "\\ql")) goto done
; break;
1353 case 0x400: if (!HLPFILE_RtfAddControl(rd
, "\\qr")) goto done
; break;
1354 case 0x800: if (!HLPFILE_RtfAddControl(rd
, "\\qc")) goto done
; break;
1357 /* 0x1000 doesn't need space */
1358 if ((bits
& 0x1000) && !HLPFILE_RtfAddControl(rd
, "\\keep")) goto done
;
1359 if ((bits
& 0xE080) != 0)
1360 WINE_FIXME("Unsupported bits %04x, potential trouble ahead\n", bits
);
1362 while (text
< text_end
&& format
< format_end
)
1364 WINE_TRACE("Got text: %s (%p/%p - %p/%p)\n", wine_dbgstr_a(text
), text
, text_end
, format
, format_end
);
1365 textsize
= strlen(text
);
1368 paragraph
= HeapAlloc(GetProcessHeap(), 0,
1369 sizeof(HLPFILE_PARAGRAPH
) + textsize
+ 1);
1370 if (!paragraph
) return FALSE
;
1371 *paragraphptr
= paragraph
;
1372 paragraphptr
= ¶graph
->next
;
1374 paragraph
->next
= NULL
;
1377 paragraph
->link
= attributes
.link
;
1378 if (paragraph
->link
) paragraph
->link
->wRefCount
++;
1380 else paragraph
->link
= NULL
;
1381 paragraph
->cookie
= para_normal_text
;
1382 paragraph
->u
.text
.wFont
= attributes
.wFont
;
1383 paragraph
->u
.text
.wVSpace
= attributes
.wVSpace
;
1384 paragraph
->u
.text
.wHSpace
= attributes
.wHSpace
;
1385 paragraph
->u
.text
.wIndent
= attributes
.wIndent
;
1386 paragraph
->u
.text
.lpszText
= (char*)paragraph
+ sizeof(HLPFILE_PARAGRAPH
);
1387 strcpy(paragraph
->u
.text
.lpszText
, text
);
1389 attributes
.wVSpace
= 0;
1390 attributes
.wHSpace
= 0;
1391 if (rd
) /* FIXME: TEMP */ {
1392 if (rd
->force_color
)
1394 if ((rd
->current_link
->cookie
== hlp_link_popup
) ?
1395 !HLPFILE_RtfAddControl(rd
, "{\\uld\\cf1") :
1396 !HLPFILE_RtfAddControl(rd
, "{\\ul\\cf1")) goto done
;
1398 if (!HLPFILE_RtfAddText(rd
, text
)) goto done
;
1399 if (rd
->force_color
&& !HLPFILE_RtfAddControl(rd
, "}")) goto done
;
1400 rd
->char_pos
+= textsize
;
1403 /* else: null text, keep on storing attributes */
1404 text
+= textsize
+ 1;
1406 if (*format
== 0xff)
1412 WINE_TRACE("format=%02x\n", *format
);
1416 WINE_FIXME("NIY20\n");
1421 WINE_FIXME("NIY21\n");
1427 unsigned font
= GET_USHORT(format
, 1);
1429 attributes
.wFont
= font
;
1430 WINE_TRACE("Changing font to %d\n", attributes
.wFont
);
1432 fs
= (4 * page
->file
->fonts
[font
].LogFont
.lfHeight
- 3) / 5;
1433 /* FIXME: missing at least colors, also bold attribute looses information */
1435 sprintf(tmp
, "\\f%d\\cf%d\\fs%d%s%s%s%s",
1437 page
->file
->fonts
[font
].LogFont
.lfWeight
> 400 ? "\\b" : "\\b0",
1438 page
->file
->fonts
[font
].LogFont
.lfItalic
? "\\i" : "\\i0",
1439 page
->file
->fonts
[font
].LogFont
.lfUnderline
? "\\ul" : "\\ul0",
1440 page
->file
->fonts
[font
].LogFont
.lfStrikeOut
? "\\strike" : "\\strike0");
1441 if (!HLPFILE_RtfAddControl(rd
, tmp
)) goto done
;
1446 if (!HLPFILE_RtfAddControl(rd
, "\\line")) goto done
;
1447 attributes
.wVSpace
++;
1449 if (rd
) /* FIXME: TEMP */ rd
->char_pos
++;
1453 if (!HLPFILE_RtfAddControl(rd
, "\\par\\pard")) goto done
;
1454 attributes
.wVSpace
++;
1455 attributes
.wIndent
= 0;
1457 if (rd
) /* FIXME: TEMP */ rd
->char_pos
++;
1461 if (!HLPFILE_RtfAddControl(rd
, "\\tab")) goto done
;
1462 attributes
.wIndent
++;
1464 if (rd
) /* FIXME: TEMP */ rd
->char_pos
++;
1477 BYTE pos
= (*format
- 0x86);
1478 BYTE type
= format
[1];
1482 size
= fetch_long(&format
);
1484 paragraph
= HeapAlloc(GetProcessHeap(), 0,
1485 sizeof(HLPFILE_PARAGRAPH
) + textsize
);
1486 if (!paragraph
) return FALSE
;
1487 *paragraphptr
= paragraph
;
1488 paragraphptr
= ¶graph
->next
;
1490 paragraph
->next
= NULL
;
1492 paragraph
->link
= attributes
.link
;
1493 if (paragraph
->link
) paragraph
->link
->wRefCount
++;
1495 else paragraph
->link
= NULL
;
1496 paragraph
->cookie
= para_bitmap
;
1497 paragraph
->u
.gfx
.pos
= pos
;
1501 fetch_ushort(&format
); /* hot spot */
1504 switch (GET_SHORT(format
, 0))
1507 HLPFILE_LoadGfxByIndex(page
->file
, GET_SHORT(format
, 2),
1509 if (rd
) { /* FIXME: TEMP */
1510 HLPFILE_RtfAddGfxByIndex(rd
, page
->file
, GET_SHORT(format
, 2));
1515 WINE_FIXME("does it work ??? %x<%lu>#%u\n",
1516 GET_SHORT(format
, 0),
1517 size
, GET_SHORT(format
, 2));
1518 HLPFILE_LoadGfxByAddr(page
->file
, format
+ 2, size
- 4,
1520 if (rd
) { /* FIXME: TEMP */
1521 HLPFILE_RtfAddGfxByAddr(rd
, page
->file
, format
+ 2, size
- 4);
1526 WINE_FIXME("??? %u\n", GET_SHORT(format
, 0));
1531 WINE_FIXME("Got an embedded element %s\n", format
+ 6);
1534 WINE_FIXME("Got a type %d picture\n", type
);
1537 if (attributes
.wVSpace
) paragraph
->u
.gfx
.pos
|= 0x8000;
1544 HLPFILE_FreeLink(attributes
.link
);
1545 attributes
.link
= NULL
;
1548 if (!rd
->current_link
)
1549 WINE_FIXME("No existing link\n");
1551 rd
->current_link
->cpMax
= rd
->char_pos
;
1552 rd
->current_link
= NULL
;
1553 rd
->force_color
= FALSE
;
1558 if (!HLPFILE_RtfAddControl(rd
, "\\~")) goto done
;
1560 if (rd
) /* FIXME: TEMP */ rd
->char_pos
++;
1564 if (!HLPFILE_RtfAddControl(rd
, "\\_")) goto done
;
1565 /* FIXME: it could be that hypen is also in input stream !! */
1567 if (rd
) /* FIXME: TEMP */ rd
->char_pos
++;
1578 WINE_TRACE("macro => %s\n", format
+ 3);
1579 HLPFILE_FreeLink(attributes
.link
);
1580 attributes
.link
= HLPFILE_AllocLink(rd
, hlp_link_macro
, (const char*)format
+ 3,
1581 GET_USHORT(format
, 1), 0, !(*format
& 4), -1);
1582 format
+= 3 + GET_USHORT(format
, 1);
1587 WINE_WARN("jump topic 1 => %u\n", GET_UINT(format
, 1));
1588 HLPFILE_FreeLink(attributes
.link
);
1589 attributes
.link
= HLPFILE_AllocLink(rd
, (*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1590 page
->file
->lpszPath
, -1,
1591 GET_UINT(format
, 1)-16,
1602 attributes
.link
= HLPFILE_AllocLink(rd
, (*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1603 page
->file
->lpszPath
, -1,
1604 GET_UINT(format
, 1),
1605 !(*format
& 4), -1);
1614 char* ptr
= (char*) format
+ 8;
1615 BYTE type
= format
[3];
1624 ptr
= page
->file
->lpszPath
;
1627 for (wnd
= page
->file
->numWindows
- 1; wnd
>= 0; wnd
--)
1629 if (!strcmp(ptr
, page
->file
->windows
[wnd
].name
)) break;
1632 WINE_WARN("Couldn't find window info for %s\n", ptr
);
1633 ptr
+= strlen(ptr
) + 1;
1638 WINE_WARN("Unknown link type %d\n", type
);
1641 HLPFILE_FreeLink(attributes
.link
);
1642 attributes
.link
= HLPFILE_AllocLink(rd
, (*format
& 1) ? hlp_link_link
: hlp_link_popup
,
1643 ptr
, -1, GET_UINT(format
, 4),
1644 !(*format
& 4), wnd
);
1646 format
+= 3 + GET_USHORT(format
, 1);
1650 WINE_WARN("format %02x\n", *format
);
1657 HeapFree(GetProcessHeap(), 0, text_base
);
1661 /******************************************************************
1662 * HLPFILE_BrowsePage
1665 BOOL
HLPFILE_BrowsePage(HLPFILE_PAGE
* page
, struct RtfData
* rd
)
1667 HLPFILE
*hlpfile
= page
->file
;
1669 DWORD ref
= page
->reference
;
1670 unsigned index
, old_index
= -1, offset
, count
= 0, cpg
;
1672 const char* ck
= NULL
;
1674 if (rd
) { /* FIXME: TEMP */
1676 rd
->data
= rd
->ptr
= HeapAlloc(GetProcessHeap(), 0, rd
->allocated
= 32768);
1678 rd
->first_link
= rd
->current_link
= NULL
;
1679 rd
->force_color
= FALSE
;
1682 switch (hlpfile
->charset
)
1684 case DEFAULT_CHARSET
:
1685 case ANSI_CHARSET
: cpg
= 1252; break;
1686 case SHIFTJIS_CHARSET
: cpg
= 932; break;
1687 case HANGEUL_CHARSET
: cpg
= 949; break;
1688 case GB2312_CHARSET
: cpg
= 936; break;
1689 case CHINESEBIG5_CHARSET
: cpg
= 950; break;
1690 case GREEK_CHARSET
: cpg
= 1253; break;
1691 case TURKISH_CHARSET
: cpg
= 1254; break;
1692 case HEBREW_CHARSET
: cpg
= 1255; break;
1693 case ARABIC_CHARSET
: cpg
= 1256; break;
1694 case BALTIC_CHARSET
: cpg
= 1257; break;
1695 case VIETNAMESE_CHARSET
: cpg
= 1258; break;
1696 case RUSSIAN_CHARSET
: cpg
= 1251; break;
1697 case EE_CHARSET
: cpg
= 1250; break;
1698 case THAI_CHARSET
: cpg
= 874; break;
1699 case JOHAB_CHARSET
: cpg
= 1361; break;
1700 case MAC_CHARSET
: ck
= "mac"; break;
1702 WINE_FIXME("Unsupported charset %u\n", hlpfile
->charset
);
1707 sprintf(tmp
, "{\\rtf1\\%s\\deff0", ck
);
1708 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1712 sprintf(tmp
, "{\\rtf1\\ansi\\ansicpg%d\\deff0", cpg
);
1713 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1716 /* generate font table */
1717 if (!HLPFILE_RtfAddControl(rd
, "{\\fonttbl")) return FALSE
;
1718 for (index
= 0; index
< hlpfile
->numFonts
; index
++)
1721 switch (hlpfile
->fonts
[index
].LogFont
.lfPitchAndFamily
& 0xF0)
1723 case FF_MODERN
: family
= "modern"; break;
1724 case FF_ROMAN
: family
= "roman"; break;
1725 case FF_SWISS
: family
= "swiss"; break;
1726 case FF_SCRIPT
: family
= "script"; break;
1727 case FF_DECORATIVE
: family
= "decor"; break;
1728 default: family
= "nil"; break;
1730 sprintf(tmp
, "{\\f%d\\f%s\\fprq%d\\fcharset%d %s;}",
1732 hlpfile
->fonts
[index
].LogFont
.lfPitchAndFamily
& 0x0F,
1733 hlpfile
->fonts
[index
].LogFont
.lfCharSet
,
1734 hlpfile
->fonts
[index
].LogFont
.lfFaceName
);
1735 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1737 if (!HLPFILE_RtfAddControl(rd
, "}")) return FALSE
;
1738 /* generate color table */
1739 if (!HLPFILE_RtfAddControl(rd
, "{\\colortbl ;\\red0\\green128\\blue0;")) return FALSE
;
1740 for (index
= 0; index
< hlpfile
->numFonts
; index
++)
1743 switch (hlpfile
->fonts
[index
].LogFont
.lfPitchAndFamily
& 0xF0)
1745 case FF_MODERN
: family
= "modern"; break;
1746 case FF_ROMAN
: family
= "roman"; break;
1747 case FF_SWISS
: family
= "swiss"; break;
1748 case FF_SCRIPT
: family
= "script"; break;
1749 case FF_DECORATIVE
: family
= "decor"; break;
1750 default: family
= "nil"; break;
1752 sprintf(tmp
, "\\red%d\\green%d\\blue%d;",
1753 GetRValue(hlpfile
->fonts
[index
].color
),
1754 GetGValue(hlpfile
->fonts
[index
].color
),
1755 GetBValue(hlpfile
->fonts
[index
].color
));
1756 if (!HLPFILE_RtfAddControl(rd
, tmp
)) return FALSE
;
1758 if (!HLPFILE_RtfAddControl(rd
, "}")) return FALSE
;
1762 if (hlpfile
->version
<= 16)
1764 index
= (ref
- 0x0C) / hlpfile
->dsize
;
1765 offset
= (ref
- 0x0C) % hlpfile
->dsize
;
1769 index
= (ref
- 0x0C) >> 14;
1770 offset
= (ref
- 0x0C) & 0x3FFF;
1773 if (hlpfile
->version
<= 16 && index
!= old_index
&& index
!= 0)
1775 /* we jumped to the next block, adjust pointers */
1780 if (index
>= hlpfile
->topic_maplen
) {WINE_WARN("maplen\n"); break;}
1781 buf
= hlpfile
->topic_map
[index
] + offset
;
1782 if (buf
+ 0x15 >= hlpfile
->topic_end
) {WINE_WARN("extra\n"); break;}
1783 end
= min(buf
+ GET_UINT(buf
, 0), hlpfile
->topic_end
);
1784 if (index
!= old_index
) {old_index
= index
;}
1789 if (count
++) goto done
;
1794 if (!HLPFILE_BrowseParagraph(page
, rd
, buf
, end
)) return FALSE
;
1797 WINE_ERR("buf[0x14] = %x\n", buf
[0x14]);
1799 if (hlpfile
->version
<= 16)
1801 ref
+= GET_UINT(buf
, 0xc);
1802 if (GET_UINT(buf
, 0xc) == 0)
1806 ref
= GET_UINT(buf
, 0xc);
1807 } while (ref
!= 0xffffffff);
1810 page
->first_link
= rd
->first_link
;
1811 return HLPFILE_RtfAddControl(rd
, "}");
1814 /******************************************************************
1819 static BOOL
HLPFILE_ReadFont(HLPFILE
* hlpfile
)
1822 unsigned i
, len
, idx
;
1823 unsigned face_num
, dscr_num
, face_offset
, dscr_offset
;
1826 if (!HLPFILE_FindSubFile(hlpfile
, "|FONT", &ref
, &end
))
1828 WINE_WARN("no subfile FONT\n");
1829 hlpfile
->numFonts
= 0;
1830 hlpfile
->fonts
= NULL
;
1836 face_num
= GET_USHORT(ref
, 0);
1837 dscr_num
= GET_USHORT(ref
, 2);
1838 face_offset
= GET_USHORT(ref
, 4);
1839 dscr_offset
= GET_USHORT(ref
, 6);
1841 WINE_TRACE("Got NumFacenames=%u@%u NumDesc=%u@%u\n",
1842 face_num
, face_offset
, dscr_num
, dscr_offset
);
1844 hlpfile
->numFonts
= dscr_num
;
1845 hlpfile
->fonts
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_FONT
) * dscr_num
);
1847 len
= (dscr_offset
- face_offset
) / face_num
;
1848 /* EPP for (i = face_offset; i < dscr_offset; i += len) */
1849 /* EPP WINE_FIXME("[%d]: %*s\n", i / len, len, ref + i); */
1850 for (i
= 0; i
< dscr_num
; i
++)
1852 flag
= ref
[dscr_offset
+ i
* 11 + 0];
1853 family
= ref
[dscr_offset
+ i
* 11 + 2];
1855 hlpfile
->fonts
[i
].LogFont
.lfHeight
= ref
[dscr_offset
+ i
* 11 + 1];
1856 hlpfile
->fonts
[i
].LogFont
.lfWidth
= 0;
1857 hlpfile
->fonts
[i
].LogFont
.lfEscapement
= 0;
1858 hlpfile
->fonts
[i
].LogFont
.lfOrientation
= 0;
1859 hlpfile
->fonts
[i
].LogFont
.lfWeight
= (flag
& 1) ? 700 : 400;
1860 hlpfile
->fonts
[i
].LogFont
.lfItalic
= (flag
& 2) ? TRUE
: FALSE
;
1861 hlpfile
->fonts
[i
].LogFont
.lfUnderline
= (flag
& 4) ? TRUE
: FALSE
;
1862 hlpfile
->fonts
[i
].LogFont
.lfStrikeOut
= (flag
& 8) ? TRUE
: FALSE
;
1863 hlpfile
->fonts
[i
].LogFont
.lfCharSet
= hlpfile
->charset
;
1864 hlpfile
->fonts
[i
].LogFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
1865 hlpfile
->fonts
[i
].LogFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
1866 hlpfile
->fonts
[i
].LogFont
.lfQuality
= DEFAULT_QUALITY
;
1867 hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
1871 case 0x01: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_MODERN
; break;
1872 case 0x02: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_ROMAN
; break;
1873 case 0x03: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SWISS
; break;
1874 case 0x04: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_SCRIPT
; break;
1875 case 0x05: hlpfile
->fonts
[i
].LogFont
.lfPitchAndFamily
|= FF_DECORATIVE
; break;
1876 default: WINE_FIXME("Unknown family %u\n", family
);
1878 idx
= GET_USHORT(ref
, dscr_offset
+ i
* 11 + 3);
1882 memcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, ref
+ face_offset
+ idx
* len
, min(len
, LF_FACESIZE
- 1));
1883 hlpfile
->fonts
[i
].LogFont
.lfFaceName
[min(len
, LF_FACESIZE
- 1)] = '\0';
1887 WINE_FIXME("Too high face ref (%u/%u)\n", idx
, face_num
);
1888 strcpy(hlpfile
->fonts
[i
].LogFont
.lfFaceName
, "Helv");
1890 hlpfile
->fonts
[i
].hFont
= 0;
1891 hlpfile
->fonts
[i
].color
= RGB(ref
[dscr_offset
+ i
* 11 + 5],
1892 ref
[dscr_offset
+ i
* 11 + 6],
1893 ref
[dscr_offset
+ i
* 11 + 7]);
1894 #define X(b,s) ((flag & (1 << b)) ? "-"s: "")
1895 WINE_TRACE("Font[%d]: flags=%02x%s%s%s%s%s%s pSize=%u family=%u face=%s[%u] color=%08x\n",
1901 X(4, "dblUnderline"),
1903 ref
[dscr_offset
+ i
* 11 + 1],
1905 hlpfile
->fonts
[i
].LogFont
.lfFaceName
, idx
,
1906 GET_UINT(ref
, dscr_offset
+ i
* 11 + 5) & 0x00FFFFFF);
1911 /***********************************************************************
1913 * HLPFILE_ReadFileToBuffer
1915 static BOOL
HLPFILE_ReadFileToBuffer(HLPFILE
* hlpfile
, HFILE hFile
)
1917 BYTE header
[16], dummy
[1];
1919 if (_hread(hFile
, header
, 16) != 16) {WINE_WARN("header\n"); return FALSE
;};
1922 if (GET_UINT(header
, 0) != 0x00035F3F)
1923 {WINE_WARN("wrong header\n"); return FALSE
;};
1925 hlpfile
->file_buffer_size
= GET_UINT(header
, 12);
1926 hlpfile
->file_buffer
= HeapAlloc(GetProcessHeap(), 0, hlpfile
->file_buffer_size
+ 1);
1927 if (!hlpfile
->file_buffer
) return FALSE
;
1929 memcpy(hlpfile
->file_buffer
, header
, 16);
1930 if (_hread(hFile
, hlpfile
->file_buffer
+ 16, hlpfile
->file_buffer_size
- 16) !=hlpfile
->file_buffer_size
- 16)
1931 {WINE_WARN("filesize1\n"); return FALSE
;};
1933 if (_hread(hFile
, dummy
, 1) != 0) WINE_WARN("filesize2\n");
1935 hlpfile
->file_buffer
[hlpfile
->file_buffer_size
] = '\0'; /* FIXME: was '0', sounds backwards to me */
1940 /**************************************************************************
1943 * HLPFILE_BPTreeCompare function for HLPFILE directory.
1946 static int comp_FindSubFile(void *p
, const void *key
,
1947 int leaf
, void** next
)
1949 *next
= (char *)p
+strlen(p
)+(leaf
?5:3);
1950 WINE_TRACE("Comparing '%s' with '%s'\n", (char *)p
, (char *)key
);
1951 return strcmp(p
, key
);
1954 /***********************************************************************
1956 * HLPFILE_FindSubFile
1958 static BOOL
HLPFILE_FindSubFile(HLPFILE
* hlpfile
, LPCSTR name
, BYTE
**subbuf
, BYTE
**subend
)
1962 WINE_TRACE("looking for file '%s'\n", name
);
1963 ptr
= HLPFILE_BPTreeSearch(hlpfile
->file_buffer
+ GET_UINT(hlpfile
->file_buffer
, 4),
1964 name
, comp_FindSubFile
);
1965 if (!ptr
) return FALSE
;
1966 *subbuf
= hlpfile
->file_buffer
+ GET_UINT(ptr
, strlen(name
)+1);
1967 if (*subbuf
>= hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
1969 WINE_ERR("internal file %s does not fit\n", name
);
1972 *subend
= *subbuf
+ GET_UINT(*subbuf
, 0);
1973 if (*subend
> hlpfile
->file_buffer
+ hlpfile
->file_buffer_size
)
1975 WINE_ERR("internal file %s does not fit\n", name
);
1978 if (GET_UINT(*subbuf
, 0) < GET_UINT(*subbuf
, 4) + 9)
1980 WINE_ERR("invalid size provided for internal file %s\n", name
);
1986 /***********************************************************************
1988 * HLPFILE_SystemCommands
1990 static BOOL
HLPFILE_SystemCommands(HLPFILE
* hlpfile
)
1992 BYTE
*buf
, *ptr
, *end
;
1993 HLPFILE_MACRO
*macro
, **m
;
1995 unsigned short magic
, minor
, major
, flags
;
1997 hlpfile
->lpszTitle
= NULL
;
1999 if (!HLPFILE_FindSubFile(hlpfile
, "|SYSTEM", &buf
, &end
)) return FALSE
;
2001 magic
= GET_USHORT(buf
+ 9, 0);
2002 minor
= GET_USHORT(buf
+ 9, 2);
2003 major
= GET_USHORT(buf
+ 9, 4);
2004 /* gen date on 4 bytes */
2005 flags
= GET_USHORT(buf
+ 9, 10);
2006 WINE_TRACE("Got system header: magic=%04x version=%d.%d flags=%04x\n",
2007 magic
, major
, minor
, flags
);
2008 if (magic
!= 0x036C || major
!= 1)
2009 {WINE_WARN("Wrong system header\n"); return FALSE
;}
2012 hlpfile
->tbsize
= 0x800;
2013 hlpfile
->compressed
= 0;
2015 else if (flags
== 0)
2017 hlpfile
->tbsize
= 0x1000;
2018 hlpfile
->compressed
= 0;
2020 else if (flags
== 4)
2022 hlpfile
->tbsize
= 0x1000;
2023 hlpfile
->compressed
= 1;
2027 hlpfile
->tbsize
= 0x800;
2028 hlpfile
->compressed
= 1;
2031 if (hlpfile
->compressed
)
2032 hlpfile
->dsize
= 0x4000;
2034 hlpfile
->dsize
= hlpfile
->tbsize
- 0x0C;
2036 hlpfile
->version
= minor
;
2037 hlpfile
->flags
= flags
;
2038 hlpfile
->charset
= DEFAULT_CHARSET
;
2040 for (ptr
= buf
+ 0x15; ptr
+ 4 <= end
; ptr
+= GET_USHORT(ptr
, 2) + 4)
2042 char *str
= (char*) ptr
+ 4;
2043 switch (GET_USHORT(ptr
, 0))
2046 if (hlpfile
->lpszTitle
) {WINE_WARN("title\n"); break;}
2047 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
2048 if (!hlpfile
->lpszTitle
) return FALSE
;
2049 lstrcpy(hlpfile
->lpszTitle
, str
);
2050 WINE_TRACE("Title: %s\n", hlpfile
->lpszTitle
);
2054 if (hlpfile
->lpszCopyright
) {WINE_WARN("copyright\n"); break;}
2055 hlpfile
->lpszCopyright
= HeapAlloc(GetProcessHeap(), 0, strlen(str
) + 1);
2056 if (!hlpfile
->lpszCopyright
) return FALSE
;
2057 lstrcpy(hlpfile
->lpszCopyright
, str
);
2058 WINE_TRACE("Copyright: %s\n", hlpfile
->lpszCopyright
);
2062 if (GET_USHORT(ptr
, 2) != 4) {WINE_WARN("system3\n");break;}
2063 hlpfile
->contents_start
= GET_UINT(ptr
, 4);
2064 WINE_TRACE("Setting contents start at %08lx\n", hlpfile
->contents_start
);
2068 macro
= HeapAlloc(GetProcessHeap(), 0, sizeof(HLPFILE_MACRO
) + lstrlen(str
) + 1);
2070 p
= (char*)macro
+ sizeof(HLPFILE_MACRO
);
2072 macro
->lpszMacro
= p
;
2074 for (m
= &hlpfile
->first_macro
; *m
; m
= &(*m
)->next
);
2079 if (GET_USHORT(ptr
, 4 + 4) != 1)
2080 WINE_FIXME("More than one icon, picking up first\n");
2081 /* 0x16 is sizeof(CURSORICONDIR), see user32/user_private.h */
2082 hlpfile
->hIcon
= CreateIconFromResourceEx(ptr
+ 4 + 0x16,
2083 GET_USHORT(ptr
, 2) - 0x16, TRUE
,
2088 if (GET_USHORT(ptr
, 2) != 90) {WINE_WARN("system6\n");break;}
2090 if (hlpfile
->windows
)
2091 hlpfile
->windows
= HeapReAlloc(GetProcessHeap(), 0, hlpfile
->windows
,
2092 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
2094 hlpfile
->windows
= HeapAlloc(GetProcessHeap(), 0,
2095 sizeof(HLPFILE_WINDOWINFO
) * ++hlpfile
->numWindows
);
2097 if (hlpfile
->windows
)
2099 unsigned flags
= GET_USHORT(ptr
, 4);
2100 HLPFILE_WINDOWINFO
* wi
= &hlpfile
->windows
[hlpfile
->numWindows
- 1];
2102 if (flags
& 0x0001) strcpy(wi
->type
, &str
[2]);
2103 else wi
->type
[0] = '\0';
2104 if (flags
& 0x0002) strcpy(wi
->name
, &str
[12]);
2105 else wi
->name
[0] = '\0';
2106 if (flags
& 0x0004) strcpy(wi
->caption
, &str
[21]);
2107 else lstrcpynA(wi
->caption
, hlpfile
->lpszTitle
, sizeof(wi
->caption
));
2108 wi
->origin
.x
= (flags
& 0x0008) ? GET_USHORT(ptr
, 76) : CW_USEDEFAULT
;
2109 wi
->origin
.y
= (flags
& 0x0010) ? GET_USHORT(ptr
, 78) : CW_USEDEFAULT
;
2110 wi
->size
.cx
= (flags
& 0x0020) ? GET_USHORT(ptr
, 80) : CW_USEDEFAULT
;
2111 wi
->size
.cy
= (flags
& 0x0040) ? GET_USHORT(ptr
, 82) : CW_USEDEFAULT
;
2112 wi
->style
= (flags
& 0x0080) ? GET_USHORT(ptr
, 84) : SW_SHOW
;
2113 wi
->win_style
= WS_OVERLAPPEDWINDOW
;
2114 wi
->sr_color
= (flags
& 0x0100) ? GET_UINT(ptr
, 86) : 0xFFFFFF;
2115 wi
->nsr_color
= (flags
& 0x0200) ? GET_UINT(ptr
, 90) : 0xFFFFFF;
2116 WINE_TRACE("System-Window: flags=%c%c%c%c%c%c%c%c type=%s name=%s caption=%s (%d,%d)x(%d,%d)\n",
2117 flags
& 0x0001 ? 'T' : 't',
2118 flags
& 0x0002 ? 'N' : 'n',
2119 flags
& 0x0004 ? 'C' : 'c',
2120 flags
& 0x0008 ? 'X' : 'x',
2121 flags
& 0x0010 ? 'Y' : 'y',
2122 flags
& 0x0020 ? 'W' : 'w',
2123 flags
& 0x0040 ? 'H' : 'h',
2124 flags
& 0x0080 ? 'S' : 's',
2125 wi
->type
, wi
->name
, wi
->caption
, wi
->origin
.x
, wi
->origin
.y
,
2126 wi
->size
.cx
, wi
->size
.cy
);
2130 WINE_WARN("Citation: '%s'\n", ptr
+ 4);
2133 hlpfile
->charset
= ptr
[4];
2134 WINE_TRACE("Charset: %d\n", hlpfile
->charset
);
2137 WINE_WARN("Unsupported SystemRecord[%d]\n", GET_USHORT(ptr
, 0));
2140 if (!hlpfile
->lpszTitle
)
2141 hlpfile
->lpszTitle
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, 1);
2145 /***********************************************************************
2147 * HLPFILE_UncompressedLZ77_Size
2149 static INT
HLPFILE_UncompressedLZ77_Size(BYTE
*ptr
, BYTE
*end
)
2156 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
2160 int code
= GET_USHORT(ptr
, 0);
2161 int len
= 3 + (code
>> 12);
2165 else newsize
++, ptr
++;
2172 /***********************************************************************
2174 * HLPFILE_UncompressLZ77
2176 static BYTE
*HLPFILE_UncompressLZ77(BYTE
*ptr
, BYTE
*end
, BYTE
*newptr
)
2183 for (i
= 0; i
< 8 && ptr
< end
; i
++, mask
>>= 1)
2187 int code
= GET_USHORT(ptr
, 0);
2188 int len
= 3 + (code
>> 12);
2189 int offset
= code
& 0xfff;
2191 * We must copy byte-by-byte here. We cannot use memcpy nor
2192 * memmove here. Just example:
2193 * a[]={1,2,3,4,5,6,7,8,9,10}
2197 * {1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 11, 12}
2199 for (; len
>0; len
--, newptr
++) *newptr
= *(newptr
-offset
-1);
2202 else *newptr
++ = *ptr
++;
2209 /***********************************************************************
2211 * HLPFILE_UncompressLZ77_Phrases
2213 static BOOL
HLPFILE_UncompressLZ77_Phrases(HLPFILE
* hlpfile
)
2215 UINT i
, num
, dec_size
, head_size
;
2218 if (!HLPFILE_FindSubFile(hlpfile
, "|Phrases", &buf
, &end
)) return FALSE
;
2220 if (hlpfile
->version
<= 16)
2225 num
= hlpfile
->num_phrases
= GET_USHORT(buf
, 9);
2226 if (buf
+ 2 * num
+ 0x13 >= end
) {WINE_WARN("1a\n"); return FALSE
;};
2228 if (hlpfile
->version
<= 16)
2229 dec_size
= end
- buf
- 15 - 2 * num
;
2231 dec_size
= HLPFILE_UncompressedLZ77_Size(buf
+ 0x13 + 2 * num
, end
);
2233 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
2234 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
2235 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
2237 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2238 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2242 for (i
= 0; i
<= num
; i
++)
2243 hlpfile
->phrases_offsets
[i
] = GET_USHORT(buf
, 0x11 + 2 * i
) - 2 * num
- 2;
2245 if (hlpfile
->version
<= 16)
2246 memcpy(hlpfile
->phrases_buffer
, buf
+ 15 + 2*num
, dec_size
);
2248 HLPFILE_UncompressLZ77(buf
+ 0x13 + 2 * num
, end
, (BYTE
*)hlpfile
->phrases_buffer
);
2250 hlpfile
->hasPhrases
= TRUE
;
2254 /***********************************************************************
2256 * HLPFILE_Uncompress_Phrases40
2258 static BOOL
HLPFILE_Uncompress_Phrases40(HLPFILE
* hlpfile
)
2261 INT dec_size
, cpr_size
;
2262 BYTE
*buf_idx
, *end_idx
;
2263 BYTE
*buf_phs
, *end_phs
;
2264 long* ptr
, mask
= 0;
2266 unsigned short bc
, n
;
2268 if (!HLPFILE_FindSubFile(hlpfile
, "|PhrIndex", &buf_idx
, &end_idx
) ||
2269 !HLPFILE_FindSubFile(hlpfile
, "|PhrImage", &buf_phs
, &end_phs
)) return FALSE
;
2271 ptr
= (long*)(buf_idx
+ 9 + 28);
2272 bc
= GET_USHORT(buf_idx
, 9 + 24) & 0x0F;
2273 num
= hlpfile
->num_phrases
= GET_USHORT(buf_idx
, 9 + 4);
2275 WINE_TRACE("Index: Magic=%08x #entries=%u CpsdSize=%u PhrImgSize=%u\n"
2276 "\tPhrImgCprsdSize=%u 0=%u bc=%x ukn=%x\n",
2277 GET_UINT(buf_idx
, 9 + 0),
2278 GET_UINT(buf_idx
, 9 + 4),
2279 GET_UINT(buf_idx
, 9 + 8),
2280 GET_UINT(buf_idx
, 9 + 12),
2281 GET_UINT(buf_idx
, 9 + 16),
2282 GET_UINT(buf_idx
, 9 + 20),
2283 GET_USHORT(buf_idx
, 9 + 24),
2284 GET_USHORT(buf_idx
, 9 + 26));
2286 dec_size
= GET_UINT(buf_idx
, 9 + 12);
2287 cpr_size
= GET_UINT(buf_idx
, 9 + 16);
2289 if (dec_size
!= cpr_size
&&
2290 dec_size
!= HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
))
2292 WINE_WARN("size mismatch %u %u\n",
2293 dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
2294 dec_size
= max(dec_size
, HLPFILE_UncompressedLZ77_Size(buf_phs
+ 9, end_phs
));
2297 hlpfile
->phrases_offsets
= HeapAlloc(GetProcessHeap(), 0, sizeof(unsigned) * (num
+ 1));
2298 hlpfile
->phrases_buffer
= HeapAlloc(GetProcessHeap(), 0, dec_size
);
2299 if (!hlpfile
->phrases_offsets
|| !hlpfile
->phrases_buffer
)
2301 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2302 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2306 #define getbit() (ptr += (mask < 0), mask = mask*2 + (mask<=0), (*ptr & mask) != 0)
2308 hlpfile
->phrases_offsets
[0] = 0;
2309 for (i
= 0; i
< num
; i
++)
2311 for (n
= 1; getbit(); n
+= 1 << bc
);
2313 if (bc
> 1 && getbit()) n
+= 2;
2314 if (bc
> 2 && getbit()) n
+= 4;
2315 if (bc
> 3 && getbit()) n
+= 8;
2316 if (bc
> 4 && getbit()) n
+= 16;
2317 hlpfile
->phrases_offsets
[i
+ 1] = hlpfile
->phrases_offsets
[i
] + n
;
2321 if (dec_size
== cpr_size
)
2322 memcpy(hlpfile
->phrases_buffer
, buf_phs
+ 9, dec_size
);
2324 HLPFILE_UncompressLZ77(buf_phs
+ 9, end_phs
, (BYTE
*)hlpfile
->phrases_buffer
);
2326 hlpfile
->hasPhrases40
= TRUE
;
2330 /***********************************************************************
2332 * HLPFILE_Uncompress_Topic
2334 static BOOL
HLPFILE_Uncompress_Topic(HLPFILE
* hlpfile
)
2336 BYTE
*buf
, *ptr
, *end
, *newptr
;
2337 unsigned int i
, newsize
= 0;
2338 unsigned int topic_size
;
2340 if (!HLPFILE_FindSubFile(hlpfile
, "|TOPIC", &buf
, &end
))
2341 {WINE_WARN("topic0\n"); return FALSE
;}
2343 buf
+= 9; /* Skip file header */
2344 topic_size
= end
- buf
;
2345 if (hlpfile
->compressed
)
2347 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
2349 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
2351 ptr
= buf
+ i
* hlpfile
->tbsize
;
2353 /* I don't know why, it's necessary for printman.hlp */
2354 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
2356 newsize
+= HLPFILE_UncompressedLZ77_Size(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
));
2359 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
2360 hlpfile
->topic_maplen
* sizeof(hlpfile
->topic_map
[0]) + newsize
);
2361 if (!hlpfile
->topic_map
) return FALSE
;
2362 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
2363 hlpfile
->topic_end
= newptr
+ newsize
;
2365 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
2367 ptr
= buf
+ i
* hlpfile
->tbsize
;
2368 if (ptr
+ 0x44 > end
) ptr
= end
- 0x44;
2370 hlpfile
->topic_map
[i
] = newptr
;
2371 newptr
= HLPFILE_UncompressLZ77(ptr
+ 0xc, min(end
, ptr
+ hlpfile
->tbsize
), newptr
);
2376 /* basically, we need to copy the TopicBlockSize byte pages
2377 * (removing the first 0x0C) in one single area in memory
2379 hlpfile
->topic_maplen
= (topic_size
- 1) / hlpfile
->tbsize
+ 1;
2380 hlpfile
->topic_map
= HeapAlloc(GetProcessHeap(), 0,
2381 hlpfile
->topic_maplen
* (sizeof(hlpfile
->topic_map
[0]) + hlpfile
->dsize
));
2382 if (!hlpfile
->topic_map
) return FALSE
;
2383 newptr
= (BYTE
*)(hlpfile
->topic_map
+ hlpfile
->topic_maplen
);
2384 hlpfile
->topic_end
= newptr
+ topic_size
;
2386 for (i
= 0; i
< hlpfile
->topic_maplen
; i
++)
2388 hlpfile
->topic_map
[i
] = newptr
+ i
* hlpfile
->dsize
;
2389 memcpy(hlpfile
->topic_map
[i
], buf
+ i
* hlpfile
->tbsize
+ 0x0C, hlpfile
->dsize
);
2395 /***********************************************************************
2397 * HLPFILE_Uncompress2
2400 static void HLPFILE_Uncompress2(HLPFILE
* hlpfile
, const BYTE
*ptr
, const BYTE
*end
, BYTE
*newptr
, const BYTE
*newend
)
2402 BYTE
*phptr
, *phend
;
2406 while (ptr
< end
&& newptr
< newend
)
2408 if (!*ptr
|| *ptr
>= 0x10)
2412 code
= 0x100 * ptr
[0] + ptr
[1];
2413 index
= (code
- 0x100) / 2;
2415 phptr
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
];
2416 phend
= (BYTE
*)hlpfile
->phrases_buffer
+ hlpfile
->phrases_offsets
[index
+ 1];
2418 if (newptr
+ (phend
- phptr
) > newend
)
2420 WINE_FIXME("buffer overflow %p > %p for %lu bytes\n",
2421 newptr
, newend
, (SIZE_T
)(phend
- phptr
));
2424 memcpy(newptr
, phptr
, phend
- phptr
);
2425 newptr
+= phend
- phptr
;
2426 if (code
& 1) *newptr
++ = ' ';
2431 if (newptr
> newend
) WINE_FIXME("buffer overflow %p > %p\n", newptr
, newend
);
2434 /******************************************************************
2435 * HLPFILE_Uncompress3
2439 static BOOL
HLPFILE_Uncompress3(HLPFILE
* hlpfile
, char* dst
, const char* dst_end
,
2440 const BYTE
* src
, const BYTE
* src_end
)
2442 unsigned int idx
, len
;
2444 for (; src
< src_end
; src
++)
2446 if ((*src
& 1) == 0)
2449 if (idx
> hlpfile
->num_phrases
)
2451 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
2456 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
2457 if (dst
+ len
<= dst_end
)
2458 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
2461 else if ((*src
& 0x03) == 0x01)
2463 idx
= (*src
+ 1) * 64;
2465 if (idx
> hlpfile
->num_phrases
)
2467 WINE_ERR("index in phrases %d/%d\n", idx
, hlpfile
->num_phrases
);
2472 len
= hlpfile
->phrases_offsets
[idx
+ 1] - hlpfile
->phrases_offsets
[idx
];
2473 if (dst
+ len
<= dst_end
)
2474 memcpy(dst
, &hlpfile
->phrases_buffer
[hlpfile
->phrases_offsets
[idx
]], len
);
2477 else if ((*src
& 0x07) == 0x03)
2479 len
= (*src
/ 8) + 1;
2480 if (dst
+ len
<= dst_end
)
2481 memcpy(dst
, src
+ 1, len
);
2486 len
= (*src
/ 16) + 1;
2487 if (dst
+ len
<= dst_end
)
2488 memset(dst
, ((*src
& 0x0F) == 0x07) ? ' ' : 0, len
);
2493 if (dst
> dst_end
) WINE_ERR("buffer overflow (%p > %p)\n", dst
, dst_end
);
2497 /******************************************************************
2498 * HLPFILE_UncompressRLE
2502 static void HLPFILE_UncompressRLE(const BYTE
* src
, const BYTE
* end
, BYTE
** dst
, unsigned dstsz
)
2505 BYTE
* sdst
= *dst
+ dstsz
;
2513 if ((*dst
) + ch
<= sdst
)
2514 memcpy(*dst
, src
, ch
);
2519 if ((*dst
) + ch
<= sdst
)
2520 memset(*dst
, (char)*src
, ch
);
2526 WINE_WARN("Buffer X-flow: d(%lu) instead of d(%u)\n",
2527 (SIZE_T
)(*dst
- (sdst
- dstsz
)), dstsz
);
2530 /**************************************************************************
2531 * HLPFILE_BPTreeSearch
2533 * Searches for an element in B+ tree
2536 * buf [I] pointer to the embedded file structured as a B+ tree
2537 * key [I] pointer to data to find
2538 * comp [I] compare function
2541 * Pointer to block identified by key, or NULL if failure.
2544 void* HLPFILE_BPTreeSearch(BYTE
* buf
, const void* key
,
2545 HLPFILE_BPTreeCompare comp
)
2551 BYTE
*pages
, *ptr
, *newptr
;
2555 magic
= GET_USHORT(buf
, 9);
2556 if (magic
!= 0x293B)
2558 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
2561 page_size
= GET_USHORT(buf
, 9+4);
2562 cur_page
= GET_USHORT(buf
, 9+26);
2563 level
= GET_USHORT(buf
, 9+32);
2564 pages
= buf
+ 9 + 38;
2567 ptr
= pages
+ cur_page
*page_size
;
2568 entries
= GET_SHORT(ptr
, 2);
2570 for (i
= 0; i
< entries
; i
++)
2572 if (comp(ptr
, key
, 0, (void **)&newptr
) > 0) break;
2575 cur_page
= GET_USHORT(ptr
-2, 0);
2577 ptr
= pages
+ cur_page
*page_size
;
2578 entries
= GET_SHORT(ptr
, 2);
2580 for (i
= 0; i
< entries
; i
++)
2582 ret
= comp(ptr
, key
, 1, (void **)&newptr
);
2583 if (ret
== 0) return ptr
;
2584 if (ret
> 0) return NULL
;
2590 /**************************************************************************
2591 * HLPFILE_BPTreeEnum
2593 * Enumerates elements in B+ tree.
2596 * buf [I] pointer to the embedded file structured as a B+ tree
2597 * cb [I] compare function
2598 * cookie [IO] cookie for cb function
2600 void HLPFILE_BPTreeEnum(BYTE
* buf
, HLPFILE_BPTreeCallback cb
, void* cookie
)
2606 BYTE
*pages
, *ptr
, *newptr
;
2609 magic
= GET_USHORT(buf
, 9);
2610 if (magic
!= 0x293B)
2612 WINE_ERR("Invalid magic in B+ tree: 0x%x\n", magic
);
2615 page_size
= GET_USHORT(buf
, 9+4);
2616 cur_page
= GET_USHORT(buf
, 9+26);
2617 level
= GET_USHORT(buf
, 9+32);
2618 pages
= buf
+ 9 + 38;
2621 ptr
= pages
+ cur_page
*page_size
;
2622 cur_page
= GET_USHORT(ptr
, 4);
2624 while (cur_page
!= 0xFFFF)
2626 ptr
= pages
+ cur_page
*page_size
;
2627 entries
= GET_SHORT(ptr
, 2);
2629 for (i
= 0; i
< entries
; i
++)
2631 cb(ptr
, (void **)&newptr
, cookie
);
2634 cur_page
= GET_USHORT(pages
+cur_page
*page_size
, 6);
2639 /***********************************************************************
2641 * HLPFILE_GetContext
2643 static BOOL
HLPFILE_GetContext(HLPFILE
*hlpfile
)
2648 if (!HLPFILE_FindSubFile(hlpfile
, "|CONTEXT", &cbuf
, &cend
))
2649 {WINE_WARN("context0\n"); return FALSE
;}
2652 hlpfile
->Context
= HeapAlloc(GetProcessHeap(), 0, clen
);
2653 if (!hlpfile
->Context
) return FALSE
;
2654 memcpy(hlpfile
->Context
, cbuf
, clen
);
2659 /***********************************************************************
2661 * HLPFILE_GetKeywords
2663 static BOOL
HLPFILE_GetKeywords(HLPFILE
*hlpfile
)
2668 if (!HLPFILE_FindSubFile(hlpfile
, "|KWBTREE", &cbuf
, &cend
)) return FALSE
;
2670 hlpfile
->kwbtree
= HeapAlloc(GetProcessHeap(), 0, clen
);
2671 if (!hlpfile
->kwbtree
) return FALSE
;
2672 memcpy(hlpfile
->kwbtree
, cbuf
, clen
);
2674 if (!HLPFILE_FindSubFile(hlpfile
, "|KWDATA", &cbuf
, &cend
))
2676 WINE_ERR("corrupted help file: kwbtree present but kwdata absent\n");
2677 HeapFree(GetProcessHeap(), 0, hlpfile
->kwbtree
);
2681 hlpfile
->kwdata
= HeapAlloc(GetProcessHeap(), 0, clen
);
2682 if (!hlpfile
->kwdata
)
2684 HeapFree(GetProcessHeap(), 0, hlpfile
->kwdata
);
2687 memcpy(hlpfile
->kwdata
, cbuf
, clen
);
2692 /***********************************************************************
2696 static BOOL
HLPFILE_GetMap(HLPFILE
*hlpfile
)
2699 unsigned entries
, i
;
2701 if (!HLPFILE_FindSubFile(hlpfile
, "|CTXOMAP", &cbuf
, &cend
))
2702 {WINE_WARN("no map section\n"); return FALSE
;}
2704 entries
= GET_USHORT(cbuf
, 9);
2705 hlpfile
->Map
= HeapAlloc(GetProcessHeap(), 0, entries
* sizeof(HLPFILE_MAP
));
2706 if (!hlpfile
->Map
) return FALSE
;
2707 hlpfile
->wMapLen
= entries
;
2708 for (i
= 0; i
< entries
; i
++)
2710 hlpfile
->Map
[i
].lMap
= GET_UINT(cbuf
+11,i
*8);
2711 hlpfile
->Map
[i
].offset
= GET_UINT(cbuf
+11,i
*8+4);
2716 /******************************************************************
2717 * HLPFILE_DeleteLink
2721 void HLPFILE_FreeLink(HLPFILE_LINK
* link
)
2723 if (link
&& !--link
->wRefCount
)
2725 HeapFree(GetProcessHeap(), 0, link
);
2729 /***********************************************************************
2731 * HLPFILE_DeleteParagraph
2733 static void HLPFILE_DeleteParagraph(HLPFILE_PARAGRAPH
* paragraph
)
2735 HLPFILE_PARAGRAPH
* next
;
2739 next
= paragraph
->next
;
2741 if (paragraph
->cookie
== para_metafile
)
2742 DeleteMetaFile(paragraph
->u
.gfx
.u
.mfp
.hMF
);
2744 HLPFILE_FreeLink(paragraph
->link
);
2746 HeapFree(GetProcessHeap(), 0, paragraph
);
2751 /***********************************************************************
2755 static void HLPFILE_DeleteMacro(HLPFILE_MACRO
* macro
)
2757 HLPFILE_MACRO
* next
;
2762 HeapFree(GetProcessHeap(), 0, macro
);
2767 /***********************************************************************
2771 static void HLPFILE_DeletePage(HLPFILE_PAGE
* page
)
2778 HLPFILE_DeleteParagraph(page
->first_paragraph
);
2779 HLPFILE_DeleteMacro(page
->first_macro
);
2780 HeapFree(GetProcessHeap(), 0, page
);
2785 /***********************************************************************
2787 * HLPFILE_FreeHlpFile
2789 void HLPFILE_FreeHlpFile(HLPFILE
* hlpfile
)
2793 if (!hlpfile
|| --hlpfile
->wRefCount
> 0) return;
2795 if (hlpfile
->next
) hlpfile
->next
->prev
= hlpfile
->prev
;
2796 if (hlpfile
->prev
) hlpfile
->prev
->next
= hlpfile
->next
;
2797 else first_hlpfile
= hlpfile
->next
;
2799 if (hlpfile
->numFonts
)
2801 for (i
= 0; i
< hlpfile
->numFonts
; i
++)
2803 DeleteObject(hlpfile
->fonts
[i
].hFont
);
2805 HeapFree(GetProcessHeap(), 0, hlpfile
->fonts
);
2808 if (hlpfile
->numBmps
)
2810 for (i
= 0; i
< hlpfile
->numBmps
; i
++)
2812 DeleteObject(hlpfile
->bmps
[i
]);
2814 HeapFree(GetProcessHeap(), 0, hlpfile
->bmps
);
2817 HLPFILE_DeletePage(hlpfile
->first_page
);
2818 HLPFILE_DeleteMacro(hlpfile
->first_macro
);
2820 DestroyIcon(hlpfile
->hIcon
);
2821 if (hlpfile
->numWindows
) HeapFree(GetProcessHeap(), 0, hlpfile
->windows
);
2822 HeapFree(GetProcessHeap(), 0, hlpfile
->Context
);
2823 HeapFree(GetProcessHeap(), 0, hlpfile
->Map
);
2824 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszTitle
);
2825 HeapFree(GetProcessHeap(), 0, hlpfile
->lpszCopyright
);
2826 HeapFree(GetProcessHeap(), 0, hlpfile
->file_buffer
);
2827 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_offsets
);
2828 HeapFree(GetProcessHeap(), 0, hlpfile
->phrases_buffer
);
2829 HeapFree(GetProcessHeap(), 0, hlpfile
->topic_map
);
2830 HeapFree(GetProcessHeap(), 0, hlpfile
);