hhctrl: Don't use an extended menu.
[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
44 #define WB_GOBACK     0
45 #define WB_GOFORWARD  1
46 #define WB_GOHOME     2
47 #define WB_SEARCH     3
48 #define WB_REFRESH    4
49 #define WB_STOP       5
50 #define WB_PRINT      6
51
52 typedef struct {
53     LPWSTR chm_file;
54     LPWSTR chm_index;
55 } ChmPath;
56
57 typedef struct ContentItem {
58     struct ContentItem *parent;
59     struct ContentItem *child;
60     struct ContentItem *next;
61
62     HTREEITEM id;
63
64     LPWSTR name;
65     LPWSTR local;
66     ChmPath merge;
67 } ContentItem;
68
69 typedef struct IndexSubItem {
70     LPWSTR name;
71     LPWSTR local;
72 } IndexSubItem;
73
74 typedef struct IndexItem {
75     struct IndexItem *next;
76
77     HTREEITEM id;
78     LPWSTR keyword;
79     ChmPath merge;
80
81     int nItems;
82     int itemFlags;
83     int indentLevel;
84     IndexSubItem *items;
85 } IndexItem;
86
87 typedef struct SearchItem {
88     struct SearchItem *next;
89
90     HTREEITEM id;
91     LPWSTR title;
92     LPWSTR filename;
93 } SearchItem;
94
95 typedef struct CHMInfo
96 {
97     IITStorage *pITStorage;
98     IStorage *pStorage;
99     WCHAR *szFile;
100
101     IStream *strings_stream;
102     char **strings;
103     DWORD strings_size;
104
105     WCHAR *defTopic;
106     WCHAR *defTitle;
107     WCHAR *defToc;
108 } CHMInfo;
109
110 #define TAB_CONTENTS   0
111 #define TAB_INDEX      1
112 #define TAB_SEARCH     2
113 #define TAB_FAVORITES  3
114
115 typedef struct {
116     HWND hwnd;
117     DWORD id;
118 } HHTab;
119
120 typedef struct {
121     HWND hwndList;
122     HWND hwndPopup;
123     HWND hwndCallback;
124 } IndexPopup;
125
126 typedef struct {
127     SearchItem *root;
128     HWND hwndEdit;
129     HWND hwndList;
130     HWND hwndContainer;
131 } SearchTab;
132
133 typedef struct {
134     IOleClientSite *client_site;
135     IWebBrowser2 *web_browser;
136     IOleObject *wb_object;
137
138     HH_WINTYPEW WinType;
139
140     LPWSTR pszType;
141     LPWSTR pszCaption;
142     LPWSTR pszToc;
143     LPWSTR pszIndex;
144     LPWSTR pszFile;
145     LPWSTR pszHome;
146     LPWSTR pszJump1;
147     LPWSTR pszJump2;
148     LPWSTR pszUrlJump1;
149     LPWSTR pszUrlJump2;
150     LPWSTR pszCustomTabs;
151
152     CHMInfo *pCHMInfo;
153     ContentItem *content;
154     IndexItem *index;
155     IndexPopup popup;
156     SearchTab search;
157     HWND hwndTabCtrl;
158     HWND hwndSizeBar;
159     HFONT hFont;
160
161     HHTab tabs[TAB_FAVORITES+1];
162     DWORD current_tab;
163 } HHInfo;
164
165 BOOL InitWebBrowser(HHInfo*,HWND);
166 void ReleaseWebBrowser(HHInfo*);
167 void ResizeWebBrowser(HHInfo*,DWORD,DWORD);
168 void DoPageAction(HHInfo*,DWORD);
169
170 void InitContent(HHInfo*);
171 void ReleaseContent(HHInfo*);
172 void ActivateContentTopic(HWND,LPCWSTR,ContentItem *);
173
174 void InitIndex(HHInfo*);
175 void ReleaseIndex(HHInfo*);
176
177 CHMInfo *OpenCHM(LPCWSTR szFile);
178 BOOL LoadWinTypeFromCHM(HHInfo *info);
179 CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
180 void SetChmPath(ChmPath*,LPCWSTR,LPCWSTR);
181 IStream *GetChmStream(CHMInfo*,LPCWSTR,ChmPath*);
182 LPWSTR FindContextAlias(CHMInfo*,DWORD);
183
184 HHInfo *CreateHelpViewer(LPCWSTR);
185 void ReleaseHelpViewer(HHInfo*);
186 BOOL NavigateToUrl(HHInfo*,LPCWSTR);
187 BOOL NavigateToChm(HHInfo*,LPCWSTR,LPCWSTR);
188
189 void InitSearch(HHInfo *info, const char *needle);
190 void ReleaseSearch(HHInfo *info);
191
192 /* memory allocation functions */
193
194 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc(size_t len)
195 {
196     return HeapAlloc(GetProcessHeap(), 0, len);
197 }
198
199 static inline void * __WINE_ALLOC_SIZE(1) heap_alloc_zero(size_t len)
200 {
201     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
202 }
203
204 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc(void *mem, size_t len)
205 {
206     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
207 }
208
209 static inline void * __WINE_ALLOC_SIZE(2) heap_realloc_zero(void *mem, size_t len)
210 {
211     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
212 }
213
214 static inline BOOL heap_free(void *mem)
215 {
216     return HeapFree(GetProcessHeap(), 0, mem);
217 }
218
219 static inline LPWSTR strdupW(LPCWSTR str)
220 {
221     LPWSTR ret;
222     int size;
223
224     if(!str)
225         return NULL;
226
227     size = (strlenW(str)+1)*sizeof(WCHAR);
228     ret = heap_alloc(size);
229     memcpy(ret, str, size);
230
231     return ret;
232 }
233
234 static inline LPWSTR strdupnAtoW(LPCSTR str, LONG lenA)
235 {
236     LPWSTR ret;
237     DWORD len;
238
239     if(!str)
240         return NULL;
241
242     if (lenA > 0)
243     {
244         /* find length of string */
245         LPCSTR eos = memchr(str, 0, lenA);
246         if (eos) lenA = eos - str;
247     }
248
249     len = MultiByteToWideChar(CP_ACP, 0, str, lenA, NULL, 0)+1; /* +1 for null pad */
250     ret = heap_alloc(len*sizeof(WCHAR));
251     MultiByteToWideChar(CP_ACP, 0, str, lenA, ret, len);
252     ret[len-1] = 0;
253
254     return ret;
255 }
256
257 static inline LPWSTR strdupAtoW(LPCSTR str)
258 {
259     return strdupnAtoW(str, -1);
260 }
261
262
263
264 extern HINSTANCE hhctrl_hinstance;
265 extern BOOL hh_process;
266
267 #endif