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"
39 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
41 HINSTANCE hhctrl_hinstance;
42 BOOL hh_process = FALSE;
44 extern struct list window_list;
46 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
48 TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved);
52 case DLL_PROCESS_ATTACH:
53 hhctrl_hinstance = hInstance;
54 DisableThreadLibraryCalls(hInstance);
56 case DLL_PROCESS_DETACH:
62 static const char *command_to_string(UINT command)
64 #define X(x) case x: return #x
67 X( HH_DISPLAY_TOPIC );
69 X( HH_DISPLAY_INDEX );
70 X( HH_DISPLAY_SEARCH );
73 X( HH_GET_WIN_HANDLE );
74 X( HH_ENUM_INFO_TYPE );
75 X( HH_SET_INFO_TYPE );
80 X( HH_KEYWORD_LOOKUP );
81 X( HH_DISPLAY_TEXT_POPUP );
83 X( HH_TP_HELP_CONTEXTMENU );
84 X( HH_TP_HELP_WM_HELP );
87 X( HH_GET_LAST_ERROR );
88 X( HH_ENUM_CATEGORY );
89 X( HH_ENUM_CATEGORY_IT );
90 X( HH_RESET_IT_FILTER );
91 X( HH_SET_INCLUSIVE_FILTER );
92 X( HH_SET_EXCLUSIVE_FILTER );
95 X( HH_SAFE_DISPLAY_TOPIC );
96 X( HH_PRETRANSLATEMESSAGE );
97 X( HH_SET_GLOBAL_PROPERTY );
98 default: return "???";
103 static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen, WCHAR **index, WCHAR **window)
106 WCHAR chm_file[MAX_PATH];
108 static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0};
109 static const WCHAR delimW[] = {':',':',0};
110 static const WCHAR delim2W[] = {'>',0};
112 filename = skip_schema(filename);
114 /* the format is "helpFile[::/index][>window]" */
115 if (index) *index = NULL;
116 if (window) *window = NULL;
118 extra = strstrW(filename, delim2W);
121 memcpy(chm_file, filename, (extra-filename)*sizeof(WCHAR));
122 chm_file[extra-filename] = 0;
125 *window = strdupW(extra+1);
128 extra = strstrW(filename, delimW);
131 if (filename != chm_file)
132 memcpy(chm_file, filename, (extra-filename)*sizeof(WCHAR));
133 chm_file[extra-filename] = 0;
136 *index = strdupW(extra+2);
139 GetFullPathNameW(filename, buflen, fullname, NULL);
140 if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES)
142 GetWindowsDirectoryW(fullname, buflen);
143 strcatW(fullname, helpW);
144 strcatW(fullname, filename);
146 return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES);
149 /******************************************************************
150 * HtmlHelpW (HHCTRL.OCX.15)
152 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
154 WCHAR fullname[MAX_PATH];
156 TRACE("(%p, %s, command=%s, data=%lx)\n",
157 caller, debugstr_w( filename ),
158 command_to_string( command ), data);
162 case HH_DISPLAY_TOPIC:
164 case HH_DISPLAY_INDEX:
165 case HH_DISPLAY_SEARCH:{
169 WCHAR *window = NULL;
170 const WCHAR *index = NULL;
171 WCHAR *default_index = NULL;
172 int tab_index = TAB_CONTENTS;
177 if (!resolve_filename(filename, fullname, MAX_PATH, &default_index, &window))
179 WARN("can't find %s\n", debugstr_w(filename));
182 index = default_index;
185 info = find_window(window);
187 info = CreateHelpViewer(info, fullname, caller);
190 heap_free(default_index);
196 index = info->WinType.pszFile;
197 if(!info->WinType.pszType)
198 info->WinType.pszType = info->stringsW.pszType = window;
202 /* called to load a specified topic */
205 case HH_DISPLAY_TOPIC:
208 index = (const WCHAR *)data;
212 res = NavigateToChm(info, info->pCHMInfo->szFile, index);
213 heap_free(default_index);
217 ReleaseHelpViewer(info);
223 case HH_DISPLAY_TOPIC:
225 tab_index = TAB_CONTENTS;
227 case HH_DISPLAY_INDEX:
228 tab_index = TAB_INDEX;
230 FIXME("Should select keyword '%s'.\n", debugstr_w((WCHAR *)data));
232 case HH_DISPLAY_SEARCH:
233 tab_index = TAB_SEARCH;
235 FIXME("Should display search specified by HH_FTS_QUERY structure.\n");
238 /* open the requested tab */
239 memset(&nmhdr, 0, sizeof(nmhdr));
240 nmhdr.code = TCN_SELCHANGE;
241 SendMessageW(info->hwndTabCtrl, TCM_SETCURSEL, (WPARAM)info->tabs[tab_index].id, 0);
242 SendMessageW(info->WinType.hwndNavigation, WM_NOTIFY, 0, (LPARAM)&nmhdr);
244 return info->WinType.hwndHelp;
246 case HH_HELP_CONTEXT: {
247 WCHAR *window = NULL;
254 if (!resolve_filename(filename, fullname, MAX_PATH, NULL, &window))
256 WARN("can't find %s\n", debugstr_w(filename));
261 info = find_window(window);
263 info = CreateHelpViewer(info, fullname, caller);
270 if(!info->WinType.pszType)
271 info->WinType.pszType = info->stringsW.pszType = window;
275 url = FindContextAlias(info->pCHMInfo, data);
278 ReleaseHelpViewer(info);
282 NavigateToUrl(info, url);
284 return info->WinType.hwndHelp;
286 case HH_PRETRANSLATEMESSAGE: {
287 static BOOL warned = FALSE;
291 FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n");
299 LIST_FOR_EACH_ENTRY_SAFE(info, next, &window_list, HHInfo, entry)
301 TRACE("Destroying window %s.\n", debugstr_w(info->WinType.pszType));
302 ReleaseHelpViewer(info);
306 case HH_SET_WIN_TYPE: {
307 HH_WINTYPEW *wintype = (HH_WINTYPEW *)data;
308 WCHAR *window = NULL;
311 if (!filename && wintype->pszType)
312 window = strdupW(wintype->pszType);
313 else if (!filename || !resolve_filename(filename, fullname, MAX_PATH, NULL, &window) || !window)
315 WARN("can't find window name: %s\n", debugstr_w(filename));
318 info = find_window(window);
321 info = heap_alloc_zero(sizeof(HHInfo));
322 info->WinType.pszType = info->stringsW.pszType = window;
323 list_add_tail(&window_list, &info->entry);
328 TRACE("Changing WINTYPE, fsValidMembers=0x%x\n", wintype->fsValidMembers);
330 MergeChmProperties(wintype, info, TRUE);
331 UpdateHelpWindow(info);
334 case HH_GET_WIN_TYPE: {
335 HH_WINTYPEW *wintype = (HH_WINTYPEW *)data;
336 WCHAR *window = NULL;
339 if (!filename || !resolve_filename(filename, fullname, MAX_PATH, NULL, &window) || !window)
341 WARN("can't find window name: %s\n", debugstr_w(filename));
344 info = find_window(window);
347 WARN("Could not find window named %s.\n", debugstr_w(window));
352 TRACE("Retrieving WINTYPE for %s.\n", debugstr_w(window));
353 *wintype = info->WinType;
358 FIXME("HH case %s not handled.\n", command_to_string( command ));
364 static void wintypeAtoW(const HH_WINTYPEA *data, HH_WINTYPEW *wdata, struct wintype_stringsW *stringsW)
366 memcpy(wdata, data, sizeof(*data));
367 /* convert all of the ANSI strings to Unicode */
368 wdata->pszType = stringsW->pszType = strdupAtoW(data->pszType);
369 wdata->pszCaption = stringsW->pszCaption = strdupAtoW(data->pszCaption);
370 wdata->pszToc = stringsW->pszToc = strdupAtoW(data->pszToc);
371 wdata->pszIndex = stringsW->pszIndex = strdupAtoW(data->pszIndex);
372 wdata->pszFile = stringsW->pszFile = strdupAtoW(data->pszFile);
373 wdata->pszHome = stringsW->pszHome = strdupAtoW(data->pszHome);
374 wdata->pszJump1 = stringsW->pszJump1 = strdupAtoW(data->pszJump1);
375 wdata->pszJump2 = stringsW->pszJump2 = strdupAtoW(data->pszJump2);
376 wdata->pszUrlJump1 = stringsW->pszUrlJump1 = strdupAtoW(data->pszUrlJump1);
377 wdata->pszUrlJump2 = stringsW->pszUrlJump2 = strdupAtoW(data->pszUrlJump2);
378 wdata->pszCustomTabs = stringsW->pszCustomTabs = strdupAtoW(data->pszCustomTabs);
381 static void wintypeWtoA(const HH_WINTYPEW *wdata, HH_WINTYPEA *data, struct wintype_stringsA *stringsA)
383 memcpy(data, wdata, sizeof(*wdata));
384 /* convert all of the Unicode strings to ANSI */
385 data->pszType = stringsA->pszType = strdupWtoA(wdata->pszType);
386 data->pszCaption = stringsA->pszCaption = strdupWtoA(wdata->pszCaption);
387 data->pszToc = stringsA->pszToc = strdupWtoA(wdata->pszToc);
388 data->pszIndex = stringsA->pszFile = strdupWtoA(wdata->pszIndex);
389 data->pszFile = stringsA->pszFile = strdupWtoA(wdata->pszFile);
390 data->pszHome = stringsA->pszHome = strdupWtoA(wdata->pszHome);
391 data->pszJump1 = stringsA->pszJump1 = strdupWtoA(wdata->pszJump1);
392 data->pszJump2 = stringsA->pszJump2 = strdupWtoA(wdata->pszJump2);
393 data->pszUrlJump1 = stringsA->pszUrlJump1 = strdupWtoA(wdata->pszUrlJump1);
394 data->pszUrlJump2 = stringsA->pszUrlJump2 = strdupWtoA(wdata->pszUrlJump2);
395 data->pszCustomTabs = stringsA->pszCustomTabs = strdupWtoA(wdata->pszCustomTabs);
398 /******************************************************************
399 * HtmlHelpA (HHCTRL.OCX.14)
401 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data)
403 WCHAR *wfile = strdupAtoW( filename );
410 case HH_ALINK_LOOKUP:
411 case HH_DISPLAY_SEARCH:
412 case HH_DISPLAY_TEXT_POPUP:
413 case HH_GET_LAST_ERROR:
414 case HH_KEYWORD_LOOKUP:
416 FIXME("structures not handled yet\n");
419 case HH_SET_WIN_TYPE:
421 struct wintype_stringsW stringsW;
424 wintypeAtoW((HH_WINTYPEA *)data, &wdata, &stringsW);
425 result = HtmlHelpW( caller, wfile, command, (DWORD_PTR)&wdata );
426 wintype_stringsW_free(&stringsW);
429 case HH_GET_WIN_TYPE:
434 result = HtmlHelpW( caller, wfile, command, (DWORD_PTR)&wdata );
435 if (!wdata.pszType) break;
436 info = find_window(wdata.pszType);
438 wintype_stringsA_free(&info->stringsA);
439 wintypeWtoA(&wdata, (HH_WINTYPEA *)data, &info->stringsA);
443 case HH_DISPLAY_INDEX:
444 case HH_DISPLAY_TOPIC:
446 case HH_GET_WIN_HANDLE:
447 case HH_SAFE_DISPLAY_TOPIC:
449 WCHAR *wdata = strdupAtoW( (const char *)data );
450 result = HtmlHelpW( caller, wfile, command, (DWORD_PTR)wdata );
456 case HH_HELP_CONTEXT:
458 case HH_PRETRANSLATEMESSAGE:
459 case HH_TP_HELP_CONTEXTMENU:
460 case HH_TP_HELP_WM_HELP:
461 case HH_UNINITIALIZE:
462 /* either scalar or pointer to scalar - do nothing */
466 FIXME("Unknown command: %s (%d)\n", command_to_string(command), command);
471 result = HtmlHelpW( caller, wfile, command, data );
477 /******************************************************************
478 * doWinMain (HHCTRL.OCX.13)
480 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
483 int len, buflen, mapid = -1;
490 /* Parse command line option of the HTML Help command.
492 * Note: The only currently handled action is "mapid",
493 * which corresponds to opening a specific page.
495 while(*szCmdLine == '-')
500 space = strchr(ptr, ' ');
501 if(!strncmp(ptr, "mapid", space-ptr))
505 ptr += strlen("mapid")+1;
506 space = strchr(ptr, ' ');
507 /* command line ends without number */
510 memcpy(idtxt, ptr, space-ptr);
511 idtxt[space-ptr] = '\0';
517 FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space-szCmdLine), szCmdLine);
522 /* FIXME: Check szCmdLine for bad arguments */
523 if (*szCmdLine == '\"')
524 endq = strchr(++szCmdLine, '\"');
527 len = endq - szCmdLine;
529 len = strlen(szCmdLine);
531 /* no filename given */
535 buflen = MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, NULL, 0) + 1;
536 filename = heap_alloc(buflen * sizeof(WCHAR));
537 MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, filename, buflen);
538 filename[buflen-1] = 0;
540 /* Open a specific help topic */
542 hwnd = HtmlHelpW(GetDesktopWindow(), filename, HH_HELP_CONTEXT, mapid);
544 hwnd = HtmlHelpW(GetDesktopWindow(), filename, HH_DISPLAY_TOPIC, 0);
550 ERR("Failed to open HTML Help file '%s'.\n", szCmdLine);
554 while (GetMessageW(&msg, 0, 0, 0))
556 TranslateMessage(&msg);
557 DispatchMessageW(&msg);
563 /******************************************************************
564 * DllGetClassObject (HHCTRL.OCX.@)
566 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
568 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
569 return CLASS_E_CLASSNOTAVAILABLE;
572 /***********************************************************************
573 * DllRegisterServer (HHCTRL.OCX.@)
575 HRESULT WINAPI DllRegisterServer(void)
577 return __wine_register_resources( hhctrl_hinstance );
580 /***********************************************************************
581 * DllUnregisterServer (HHCTRL.OCX.@)
583 HRESULT WINAPI DllUnregisterServer(void)
585 return __wine_unregister_resources( hhctrl_hinstance );