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