msvcrt: Support 64-bit RTTI in __RTtypeid function.
[wine] / dlls / hhctrl.ocx / hhctrl.h
1 /*
2  * Copyright 2005 James Hawkins
3  * Copyright 2007 Jacek Caban 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 #ifndef HHCTRL_H
21 #define HHCTRL_H
22
23 #include <stdarg.h>
24
25 #define COBJMACROS
26
27 #include "windef.h"
28 #include "winbase.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "htmlhelp.h"
32 #include "ole2.h"
33 #include "exdisp.h"
34 #include "mshtmhst.h"
35 #include "commctrl.h"
36
37 #ifdef INIT_GUID
38 #include "initguid.h"
39 #endif
40
41 #include "wine/itss.h"
42 #include "wine/unicode.h"
43 #include "wine/list.h"
44
45 #define WB_GOBACK     0
46 #define WB_GOFORWARD  1
47 #define WB_GOHOME     2
48 #define WB_SEARCH     3
49 #define WB_REFRESH    4
50 #define WB_STOP       5
51 #define WB_PRINT      6
52
53 typedef struct {
54     LPWSTR chm_file;
55     LPWSTR chm_index;
56 } ChmPath;
57
58 typedef struct ContentItem {
59     struct ContentItem *parent;
60     struct ContentItem *child;
61     struct ContentItem *next;
62
63     HTREEITEM id;
64
65     LPWSTR name;
66     LPWSTR local;
67     ChmPath merge;
68 } ContentItem;
69
70 typedef struct IndexSubItem {
71     LPWSTR name;
72     LPWSTR local;
73 } IndexSubItem;
74
75 typedef struct IndexItem {
76     struct IndexItem *next;
77
78     HTREEITEM id;
79     LPWSTR keyword;
80     ChmPath merge;
81
82     int nItems;
83     int itemFlags;
84     int indentLevel;
85     IndexSubItem *items;
86 } IndexItem;
87
88 typedef struct SearchItem {
89     struct SearchItem *next;
90
91     HTREEITEM id;
92     LPWSTR title;
93     LPWSTR filename;
94 } SearchItem;
95
96 typedef struct CHMInfo
97 {
98     IITStorage *pITStorage;
99     IStorage *pStorage;
100     WCHAR *szFile;
101
102     IStream *strings_stream;
103     char **strings;
104     DWORD strings_size;
105
106     WCHAR *compiledFile;
107     WCHAR *defWindow;
108     WCHAR *defTopic;
109     WCHAR *defTitle;
110     WCHAR *defToc;
111
112     UINT codePage;
113 } CHMInfo;
114
115 #define TAB_CONTENTS   0
116 #define TAB_INDEX      1
117 #define TAB_SEARCH     2
118 #define TAB_FAVORITES  3
119 #define TAB_NUMTABS    TAB_FAVORITES
120
121 typedef struct {
122     HWND hwnd;
123     DWORD id;
124 } HHTab;
125
126 typedef struct {
127     HWND hwndList;
128     HWND hwndPopup;
129     HWND hwndCallback;
130 } IndexPopup;
131
132 typedef struct {
133     SearchItem *root;
134     HWND hwndEdit;
135     HWND hwndList;
136     HWND hwndContainer;
137 } SearchTab;
138
139 typedef struct {
140     HIMAGELIST hImageList;
141 } ContentsTab;
142
143 struct wintype_stringsW {
144     WCHAR *pszType;
145     WCHAR *pszCaption;
146     WCHAR *pszToc;
147     WCHAR *pszIndex;
148     WCHAR *pszFile;
149     WCHAR *pszHome;
150     WCHAR *pszJump1;
151     WCHAR *pszJump2;
152     WCHAR *pszUrlJump1;
153     WCHAR *pszUrlJump2;
154     WCHAR *pszCustomTabs;
155 };
156
157 struct wintype_stringsA {
158     char *pszType;
159     char *pszCaption;
160     char *pszToc;
161     char *pszIndex;
162     char *pszFile;
163     char *pszHome;
164     char *pszJump1;
165     char *pszJump2;
166     char *pszUrlJump1;
167     char *pszUrlJump2;
168     char *pszCustomTabs;
169 };
170
171 typedef struct {
172     IOleClientSite *client_site;
173     IWebBrowser2 *web_browser;
174     IOleObject *wb_object;
175
176     HH_WINTYPEW WinType;
177
178     struct wintype_stringsA stringsA;
179     struct wintype_stringsW stringsW;
180
181     struct list entry;
182     CHMInfo *pCHMInfo;
183     ContentItem *content;
184     IndexItem *index;
185     IndexPopup popup;
186     SearchTab search;
187     ContentsTab contents;
188     HWND hwndTabCtrl;
189     HWND hwndSizeBar;
190     HFONT hFont;
191
192     HHTab tabs[TAB_FAVORITES+1];
193     int viewer_initialized;
194     DWORD current_tab;
195 } HHInfo;
196
197 BOOL InitWebBrowser(HHInfo*,HWND) DECLSPEC_HIDDEN;
198 void ReleaseWebBrowser(HHInfo*) DECLSPEC_HIDDEN;
199 void ResizeWebBrowser(HHInfo*,DWORD,DWORD) DECLSPEC_HIDDEN;
200 void DoPageAction(HHInfo*,DWORD) DECLSPEC_HIDDEN;
201
202 void InitContent(HHInfo*) DECLSPEC_HIDDEN;
203 void ReleaseContent(HHInfo*) DECLSPEC_HIDDEN;
204 void ActivateContentTopic(HWND,LPCWSTR,ContentItem *) DECLSPEC_HIDDEN;
205
206 void InitIndex(HHInfo*) DECLSPEC_HIDDEN;
207 void ReleaseIndex(HHInfo*) DECLSPEC_HIDDEN;
208
209 CHMInfo *OpenCHM(LPCWSTR szFile) DECLSPEC_HIDDEN;
210 BOOL LoadWinTypeFromCHM(HHInfo *info) DECLSPEC_HIDDEN;
211 CHMInfo *CloseCHM(CHMInfo *pCHMInfo) DECLSPEC_HIDDEN;
212 void SetChmPath(ChmPath*,LPCWSTR,LPCWSTR) DECLSPEC_HIDDEN;
213 IStream *GetChmStream(CHMInfo*,LPCWSTR,ChmPath*) DECLSPEC_HIDDEN;
214 LPWSTR FindContextAlias(CHMInfo*,DWORD) DECLSPEC_HIDDEN;
215 WCHAR *GetDocumentTitle(CHMInfo*,LPCWSTR) DECLSPEC_HIDDEN;
216
217 HHInfo *CreateHelpViewer(HHInfo*,LPCWSTR,HWND) DECLSPEC_HIDDEN;
218 void ReleaseHelpViewer(HHInfo*) DECLSPEC_HIDDEN;
219 BOOL NavigateToUrl(HHInfo*,LPCWSTR) DECLSPEC_HIDDEN;
220 BOOL NavigateToChm(HHInfo*,LPCWSTR,LPCWSTR) DECLSPEC_HIDDEN;
221 void MergeChmProperties(HH_WINTYPEW*,HHInfo*) DECLSPEC_HIDDEN;
222
223 void InitSearch(HHInfo *info, const char *needle) DECLSPEC_HIDDEN;
224 void ReleaseSearch(HHInfo *info) DECLSPEC_HIDDEN;
225
226 LPCWSTR skip_schema(LPCWSTR url) DECLSPEC_HIDDEN;
227 void wintype_stringsA_free(struct wintype_stringsA *stringsA) DECLSPEC_HIDDEN;
228 void wintype_stringsW_free(struct wintype_stringsW *stringsW) DECLSPEC_HIDDEN;
229 WCHAR *decode_html(const char *html_fragment, int html_fragment_len, UINT code_page);
230
231 /* memory allocation functions */
232
233 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
234 {
235     return HeapAlloc(GetProcessHeap(), 0, len);
236 }
237
238 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
239 {
240     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
241 }
242
243 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
244 {
245     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
246 }
247
248 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
249 {
250     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
251 }
252
253 static inline BOOL heap_free(void *mem)
254 {
255     return HeapFree(GetProcessHeap(), 0, mem);
256 }
257
258 static inline LPWSTR strdupW(LPCWSTR str)
259 {
260     LPWSTR ret;
261     int size;
262
263     if(!str)
264         return NULL;
265
266     size = (strlenW(str)+1)*sizeof(WCHAR);
267     ret = heap_alloc(size);
268     memcpy(ret, str, size);
269
270     return ret;
271 }
272
273 static inline LPWSTR strdupnAtoW(LPCSTR str, LONG lenA)
274 {
275     LPWSTR ret;
276     DWORD len;
277
278     if(!str)
279         return NULL;
280
281     if (lenA > 0)
282     {
283         /* find length of string */
284         LPCSTR eos = memchr(str, 0, lenA);
285         if (eos) lenA = eos - str;
286     }
287
288     len = MultiByteToWideChar(CP_ACP, 0, str, lenA, NULL, 0)+1; /* +1 for null pad */
289     ret = heap_alloc(len*sizeof(WCHAR));
290     MultiByteToWideChar(CP_ACP, 0, str, lenA, ret, len);
291     ret[len-1] = 0;
292
293     return ret;
294 }
295
296 static inline LPWSTR strdupAtoW(LPCSTR str)
297 {
298     return strdupnAtoW(str, -1);
299 }
300
301 static inline LPSTR strdupWtoA(LPCWSTR str)
302 {
303     LPSTR ret;
304     DWORD len;
305
306     if(!str)
307         return NULL;
308
309     len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
310     ret = heap_alloc(len);
311     WideCharToMultiByte(CP_ACP, 0, str, -1, ret, len, NULL, NULL);
312     return ret;
313 }
314
315
316 extern HINSTANCE hhctrl_hinstance DECLSPEC_HIDDEN;
317 extern BOOL hh_process DECLSPEC_HIDDEN;
318
319 #endif