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