kernel32/tests: Fix memory leaks (found by Smatch).
[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 CHMInfo
69 {
70     IITStorage *pITStorage;
71     IStorage *pStorage;
72     LPCWSTR szFile;
73
74     IStream *strings_stream;
75     char **strings;
76     DWORD strings_size;
77 } CHMInfo;
78
79 #define TAB_CONTENTS   0
80 #define TAB_INDEX      1
81 #define TAB_SEARCH     2
82 #define TAB_FAVORITES  3
83
84 typedef struct {
85     HWND hwnd;
86     DWORD id;
87 } HHTab;
88
89 typedef struct {
90     IOleClientSite *client_site;
91     IWebBrowser2 *web_browser;
92     IOleObject *wb_object;
93
94     HH_WINTYPEW WinType;
95     CHMInfo *pCHMInfo;
96     ContentItem *content;
97     HWND hwndTabCtrl;
98     HWND hwndSizeBar;
99     HFONT hFont;
100
101     HHTab tabs[TAB_FAVORITES+1];
102     DWORD current_tab;
103 } HHInfo;
104
105 BOOL InitWebBrowser(HHInfo*,HWND);
106 void ReleaseWebBrowser(HHInfo*);
107 void ResizeWebBrowser(HHInfo*,DWORD,DWORD);
108 void DoPageAction(HHInfo*,DWORD);
109
110 void InitContent(HHInfo*);
111 void ReleaseContent(HHInfo*);
112
113 CHMInfo *OpenCHM(LPCWSTR szFile);
114 BOOL LoadWinTypeFromCHM(CHMInfo *pCHMInfo, HH_WINTYPEW *pHHWinType);
115 CHMInfo *CloseCHM(CHMInfo *pCHMInfo);
116 void SetChmPath(ChmPath*,LPCWSTR,LPCWSTR);
117 IStream *GetChmStream(CHMInfo*,LPCWSTR,ChmPath*);
118 LPWSTR FindContextAlias(CHMInfo*,DWORD);
119
120 HHInfo *CreateHelpViewer(LPCWSTR);
121 void ReleaseHelpViewer(HHInfo*);
122 BOOL NavigateToUrl(HHInfo*,LPCWSTR);
123 BOOL NavigateToChm(HHInfo*,LPCWSTR,LPCWSTR);
124
125 /* memory allocation functions */
126
127 static inline void *hhctrl_alloc(size_t len)
128 {
129     return HeapAlloc(GetProcessHeap(), 0, len);
130 }
131
132 static inline void *hhctrl_alloc_zero(size_t len)
133 {
134     return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, len);
135 }
136
137 static inline void *hhctrl_realloc(void *mem, size_t len)
138 {
139     return HeapReAlloc(GetProcessHeap(), 0, mem, len);
140 }
141
142 static inline void *hhctrl_realloc_zero(void *mem, size_t len)
143 {
144     return HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, mem, len);
145 }
146
147 static inline BOOL hhctrl_free(void *mem)
148 {
149     return HeapFree(GetProcessHeap(), 0, mem);
150 }
151
152 static inline LPWSTR strdupW(LPCWSTR str)
153 {
154     LPWSTR ret;
155     int size;
156
157     if(!str)
158         return NULL;
159
160     size = (strlenW(str)+1)*sizeof(WCHAR);
161     ret = hhctrl_alloc(size);
162     memcpy(ret, str, size);
163
164     return ret;
165 }
166
167 static inline LPWSTR strdupAtoW(LPCSTR str)
168 {
169     LPWSTR ret;
170     DWORD len;
171
172     if(!str)
173         return NULL;
174
175     len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
176     ret = hhctrl_alloc(len*sizeof(WCHAR));
177     MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
178
179     return ret;
180 }
181
182 extern HINSTANCE hhctrl_hinstance;
183 extern BOOL hh_process;
184
185 #endif