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