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