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