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