push cc8bc80451cc24f4d7cf75168b569f0ebfe19547
[wine/hacks.git] / dlls / hhctrl.ocx / hhctrl.c
blob5e707b925609e27767f5c65d0e7aaf7b8c53e41d
1 /*
2 * hhctrl implementation
4 * Copyright 2004 Krzysztof Foltman
5 * Copyright 2007 Jacek Caban for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/debug.h"
24 #define INIT_GUID
25 #include "hhctrl.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
29 HINSTANCE hhctrl_hinstance;
30 BOOL hh_process = FALSE;
32 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
34 TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved);
36 switch (fdwReason)
38 case DLL_PROCESS_ATTACH:
39 hhctrl_hinstance = hInstance;
40 DisableThreadLibraryCalls(hInstance);
41 break;
42 case DLL_PROCESS_DETACH:
43 break;
45 return TRUE;
48 static const char *command_to_string(UINT command)
50 #define X(x) case x: return #x
51 switch (command)
53 X( HH_DISPLAY_TOPIC );
54 X( HH_DISPLAY_TOC );
55 X( HH_DISPLAY_INDEX );
56 X( HH_DISPLAY_SEARCH );
57 X( HH_SET_WIN_TYPE );
58 X( HH_GET_WIN_TYPE );
59 X( HH_GET_WIN_HANDLE );
60 X( HH_ENUM_INFO_TYPE );
61 X( HH_SET_INFO_TYPE );
62 X( HH_SYNC );
63 X( HH_RESERVED1 );
64 X( HH_RESERVED2 );
65 X( HH_RESERVED3 );
66 X( HH_KEYWORD_LOOKUP );
67 X( HH_DISPLAY_TEXT_POPUP );
68 X( HH_HELP_CONTEXT );
69 X( HH_TP_HELP_CONTEXTMENU );
70 X( HH_TP_HELP_WM_HELP );
71 X( HH_CLOSE_ALL );
72 X( HH_ALINK_LOOKUP );
73 X( HH_GET_LAST_ERROR );
74 X( HH_ENUM_CATEGORY );
75 X( HH_ENUM_CATEGORY_IT );
76 X( HH_RESET_IT_FILTER );
77 X( HH_SET_INCLUSIVE_FILTER );
78 X( HH_SET_EXCLUSIVE_FILTER );
79 X( HH_INITIALIZE );
80 X( HH_UNINITIALIZE );
81 X( HH_SAFE_DISPLAY_TOPIC );
82 X( HH_PRETRANSLATEMESSAGE );
83 X( HH_SET_GLOBAL_PROPERTY );
84 default: return "???";
86 #undef X
89 /******************************************************************
90 * HtmlHelpW (HHCTRL.OCX.15)
92 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
94 TRACE("(%p, %s, command=%s, data=%lx)\n",
95 caller, debugstr_w( filename ),
96 command_to_string( command ), data);
98 switch (command)
100 case HH_DISPLAY_TOPIC:
101 case HH_DISPLAY_TOC:
102 case HH_DISPLAY_SEARCH:{
103 static const WCHAR delimW[] = {':',':',0};
104 HHInfo *info;
105 BOOL res;
106 WCHAR chm_file[MAX_PATH];
107 const WCHAR *index;
109 FIXME("Not all HH cases handled correctly\n");
111 if (!filename)
112 return NULL;
114 index = strstrW(filename, delimW);
115 if (index)
117 memcpy(chm_file, filename, (index-filename)*sizeof(WCHAR));
118 chm_file[index-filename] = 0;
119 filename = chm_file;
120 index += 2; /* advance beyond "::" for calling NavigateToChm() later */
122 else
124 if (command!=HH_DISPLAY_SEARCH) /* FIXME - use HH_FTS_QUERYW structure in data */
125 index = (const WCHAR*)data;
128 info = CreateHelpViewer(filename);
129 if(!info)
130 return NULL;
132 if(!index)
133 index = info->WinType.pszFile;
135 res = NavigateToChm(info, info->pCHMInfo->szFile, index);
136 if(!res)
138 ReleaseHelpViewer(info);
139 return NULL;
141 return info->WinType.hwndHelp;
143 case HH_HELP_CONTEXT: {
144 HHInfo *info;
145 LPWSTR url;
147 if (!filename)
148 return NULL;
150 info = CreateHelpViewer(filename);
151 if(!info)
152 return NULL;
154 url = FindContextAlias(info->pCHMInfo, data);
155 if(!url)
157 ReleaseHelpViewer(info);
158 return NULL;
161 NavigateToUrl(info, url);
162 heap_free(url);
163 return info->WinType.hwndHelp;
165 case HH_PRETRANSLATEMESSAGE: {
166 static BOOL warned = FALSE;
168 if (!warned)
170 FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n");
171 warned = TRUE;
173 return 0;
175 default:
176 FIXME("HH case %s not handled.\n", command_to_string( command ));
179 return 0;
182 /******************************************************************
183 * HtmlHelpA (HHCTRL.OCX.14)
185 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data)
187 WCHAR *wfile = NULL, *wdata = NULL;
188 DWORD len;
189 HWND result;
191 if (filename)
193 len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
194 wfile = heap_alloc(len*sizeof(WCHAR));
195 MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
198 if (data)
200 switch(command)
202 case HH_ALINK_LOOKUP:
203 case HH_DISPLAY_SEARCH:
204 case HH_DISPLAY_TEXT_POPUP:
205 case HH_GET_LAST_ERROR:
206 case HH_GET_WIN_TYPE:
207 case HH_KEYWORD_LOOKUP:
208 case HH_SET_WIN_TYPE:
209 case HH_SYNC:
210 FIXME("structures not handled yet\n");
211 break;
213 case HH_DISPLAY_INDEX:
214 case HH_DISPLAY_TOPIC:
215 case HH_DISPLAY_TOC:
216 case HH_GET_WIN_HANDLE:
217 case HH_SAFE_DISPLAY_TOPIC:
218 len = MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, NULL, 0 );
219 wdata = heap_alloc(len*sizeof(WCHAR));
220 MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, wdata, len );
221 break;
223 case HH_CLOSE_ALL:
224 case HH_HELP_CONTEXT:
225 case HH_INITIALIZE:
226 case HH_PRETRANSLATEMESSAGE:
227 case HH_TP_HELP_CONTEXTMENU:
228 case HH_TP_HELP_WM_HELP:
229 case HH_UNINITIALIZE:
230 /* either scalar or pointer to scalar - do nothing */
231 break;
233 default:
234 FIXME("Unknown command: %s (%d)\n", command_to_string(command), command);
235 break;
239 result = HtmlHelpW( caller, wfile, command, wdata ? (DWORD_PTR)wdata : data );
241 heap_free(wfile);
242 heap_free(wdata);
243 return result;
246 /******************************************************************
247 * doWinMain (HHCTRL.OCX.13)
249 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
251 MSG msg;
252 int len, buflen;
253 WCHAR *filename;
254 char *endq = NULL;
256 hh_process = TRUE;
258 /* FIXME: Check szCmdLine for bad arguments */
259 if (*szCmdLine == '\"')
260 endq = strchr(++szCmdLine, '\"');
262 if (endq)
263 len = endq - szCmdLine;
264 else
265 len = strlen(szCmdLine);
266 buflen = MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, NULL, 0) + 1;
267 filename = heap_alloc(buflen * sizeof(WCHAR));
268 MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, filename, buflen);
269 filename[buflen-1] = 0;
271 HtmlHelpW(GetDesktopWindow(), filename, HH_DISPLAY_TOPIC, 0);
273 heap_free(filename);
275 while (GetMessageW(&msg, 0, 0, 0))
277 TranslateMessage(&msg);
278 DispatchMessageW(&msg);
281 return 0;
284 /******************************************************************
285 * DllGetClassObject (HHCTRL.OCX.@)
287 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
289 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
290 return CLASS_E_CLASSNOTAVAILABLE;