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 static inline HHInfo *find_window(const WCHAR *window)
153 LIST_FOR_EACH_ENTRY(info, &window_list, HHInfo, entry)
155 if (strcmpW(info->WinType.pszType, window) == 0)
161 /******************************************************************
162 * HtmlHelpW (HHCTRL.OCX.15)
164 HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
166 WCHAR fullname[MAX_PATH];
168 TRACE("(%p, %s, command=%s, data=%lx)\n",
169 caller, debugstr_w( filename ),
170 command_to_string( command ), data);
174 case HH_DISPLAY_TOPIC:
176 case HH_DISPLAY_INDEX:
177 case HH_DISPLAY_SEARCH:{
181 WCHAR *window = NULL;
182 const WCHAR *index = NULL;
183 WCHAR *default_index = NULL;
184 int tab_index = TAB_CONTENTS;
189 if (!resolve_filename(filename, fullname, MAX_PATH, &default_index, &window))
191 WARN("can't find %s\n", debugstr_w(filename));
194 index = default_index;
197 info = find_window(window);
199 info = CreateHelpViewer(info, fullname, caller);
202 heap_free(default_index);
208 index = info->WinType.pszFile;
209 if(!info->WinType.pszType)
210 info->WinType.pszType = info->stringsW.pszType = window;
214 /* called to load a specified topic */
217 case HH_DISPLAY_TOPIC:
220 index = (const WCHAR *)data;
224 res = NavigateToChm(info, info->pCHMInfo->szFile, index);
225 heap_free(default_index);
229 ReleaseHelpViewer(info);
235 case HH_DISPLAY_TOPIC:
237 tab_index = TAB_CONTENTS;
239 case HH_DISPLAY_INDEX:
240 tab_index = TAB_INDEX;
242 FIXME("Should select keyword '%s'.\n", debugstr_w((WCHAR *)data));
244 case HH_DISPLAY_SEARCH:
245 tab_index = TAB_SEARCH;
247 FIXME("Should display search specified by HH_FTS_QUERY structure.\n");
250 /* open the requested tab */
251 memset(&nmhdr, 0, sizeof(nmhdr));
252 nmhdr.code = TCN_SELCHANGE;
253 SendMessageW(info->hwndTabCtrl, TCM_SETCURSEL, (WPARAM)info->tabs[tab_index].id, 0);
254 SendMessageW(info->WinType.hwndNavigation, WM_NOTIFY, 0, (LPARAM)&nmhdr);
256 return info->WinType.hwndHelp;
258 case HH_HELP_CONTEXT: {
265 if (!resolve_filename(filename, fullname, MAX_PATH, NULL, NULL))
267 WARN("can't find %s\n", debugstr_w(filename));
271 info = CreateHelpViewer(NULL, fullname, caller);
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);
333 case HH_GET_WIN_TYPE: {
334 HH_WINTYPEW *wintype = (HH_WINTYPEW *)data;
335 WCHAR *window = NULL;
338 if (!filename || !resolve_filename(filename, fullname, MAX_PATH, NULL, &window) || !window)
340 WARN("can't find window name: %s\n", debugstr_w(filename));
343 info = find_window(window);
346 WARN("Could not find window named %s.\n", debugstr_w(window));
351 TRACE("Retrieving WINTYPE for %s.\n", debugstr_w(window));
352 *wintype = info->WinType;
357 FIXME("HH case %s not handled.\n", command_to_string( command ));
363 static void wintypeAtoW(const HH_WINTYPEA *data, HH_WINTYPEW *wdata, struct wintype_stringsW *stringsW)
365 memcpy(wdata, data, sizeof(*data));
366 /* convert all of the ANSI strings to Unicode */
367 wdata->pszType = stringsW->pszType = strdupAtoW(data->pszType);
368 wdata->pszCaption = stringsW->pszCaption = strdupAtoW(data->pszCaption);
369 wdata->pszToc = stringsW->pszToc = strdupAtoW(data->pszToc);
370 wdata->pszIndex = stringsW->pszIndex = strdupAtoW(data->pszIndex);
371 wdata->pszFile = stringsW->pszFile = strdupAtoW(data->pszFile);
372 wdata->pszHome = stringsW->pszHome = strdupAtoW(data->pszHome);
373 wdata->pszJump1 = stringsW->pszJump1 = strdupAtoW(data->pszJump1);
374 wdata->pszJump2 = stringsW->pszJump2 = strdupAtoW(data->pszJump2);
375 wdata->pszUrlJump1 = stringsW->pszUrlJump1 = strdupAtoW(data->pszUrlJump1);
376 wdata->pszUrlJump2 = stringsW->pszUrlJump2 = strdupAtoW(data->pszUrlJump2);
377 wdata->pszCustomTabs = stringsW->pszCustomTabs = strdupAtoW(data->pszCustomTabs);
380 static void wintypeWtoA(const HH_WINTYPEW *wdata, HH_WINTYPEA *data, struct wintype_stringsA *stringsA)
382 memcpy(data, wdata, sizeof(*wdata));
383 /* convert all of the Unicode strings to ANSI */
384 data->pszType = stringsA->pszType = strdupWtoA(wdata->pszType);
385 data->pszCaption = stringsA->pszCaption = strdupWtoA(wdata->pszCaption);
386 data->pszToc = stringsA->pszToc = strdupWtoA(wdata->pszToc);
387 data->pszIndex = stringsA->pszFile = strdupWtoA(wdata->pszIndex);
388 data->pszFile = stringsA->pszFile = strdupWtoA(wdata->pszFile);
389 data->pszHome = stringsA->pszHome = strdupWtoA(wdata->pszHome);
390 data->pszJump1 = stringsA->pszJump1 = strdupWtoA(wdata->pszJump1);
391 data->pszJump2 = stringsA->pszJump2 = strdupWtoA(wdata->pszJump2);
392 data->pszUrlJump1 = stringsA->pszUrlJump1 = strdupWtoA(wdata->pszUrlJump1);
393 data->pszUrlJump2 = stringsA->pszUrlJump2 = strdupWtoA(wdata->pszUrlJump2);
394 data->pszCustomTabs = stringsA->pszCustomTabs = strdupWtoA(wdata->pszCustomTabs);
397 /******************************************************************
398 * HtmlHelpA (HHCTRL.OCX.14)
400 HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data)
402 WCHAR *wfile = strdupAtoW( filename );
409 case HH_ALINK_LOOKUP:
410 case HH_DISPLAY_SEARCH:
411 case HH_DISPLAY_TEXT_POPUP:
412 case HH_GET_LAST_ERROR:
413 case HH_KEYWORD_LOOKUP:
415 FIXME("structures not handled yet\n");
418 case HH_SET_WIN_TYPE:
420 struct wintype_stringsW stringsW;
423 wintypeAtoW((HH_WINTYPEA *)data, &wdata, &stringsW);
424 result = HtmlHelpW( caller, wfile, command, (DWORD_PTR)&wdata );
425 wintype_stringsW_free(&stringsW);
428 case HH_GET_WIN_TYPE:
433 result = HtmlHelpW( caller, wfile, command, (DWORD_PTR)&wdata );
434 if (!wdata.pszType) break;
435 info = find_window(wdata.pszType);
437 wintype_stringsA_free(&info->stringsA);
438 wintypeWtoA(&wdata, (HH_WINTYPEA *)data, &info->stringsA);
442 case HH_DISPLAY_INDEX:
443 case HH_DISPLAY_TOPIC:
445 case HH_GET_WIN_HANDLE:
446 case HH_SAFE_DISPLAY_TOPIC:
448 WCHAR *wdata = strdupAtoW( (const char *)data );
449 result = HtmlHelpW( caller, wfile, command, (DWORD_PTR)wdata );
455 case HH_HELP_CONTEXT:
457 case HH_PRETRANSLATEMESSAGE:
458 case HH_TP_HELP_CONTEXTMENU:
459 case HH_TP_HELP_WM_HELP:
460 case HH_UNINITIALIZE:
461 /* either scalar or pointer to scalar - do nothing */
465 FIXME("Unknown command: %s (%d)\n", command_to_string(command), command);
470 result = HtmlHelpW( caller, wfile, command, data );
476 /******************************************************************
477 * doWinMain (HHCTRL.OCX.13)
479 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
482 int len, buflen, mapid = -1;
489 /* Parse command line option of the HTML Help command.
491 * Note: The only currently handled action is "mapid",
492 * which corresponds to opening a specific page.
494 while(*szCmdLine == '-')
499 space = strchr(ptr, ' ');
500 if(!strncmp(ptr, "mapid", space-ptr))
504 ptr += strlen("mapid")+1;
505 space = strchr(ptr, ' ');
506 /* command line ends without number */
509 memcpy(idtxt, ptr, space-ptr);
510 idtxt[space-ptr] = '\0';
516 FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space-szCmdLine), szCmdLine);
521 /* FIXME: Check szCmdLine for bad arguments */
522 if (*szCmdLine == '\"')
523 endq = strchr(++szCmdLine, '\"');
526 len = endq - szCmdLine;
528 len = strlen(szCmdLine);
530 /* no filename given */
534 buflen = MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, NULL, 0) + 1;
535 filename = heap_alloc(buflen * sizeof(WCHAR));
536 MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, filename, buflen);
537 filename[buflen-1] = 0;
539 /* Open a specific help topic */
541 hwnd = HtmlHelpW(GetDesktopWindow(), filename, HH_HELP_CONTEXT, mapid);
543 hwnd = HtmlHelpW(GetDesktopWindow(), filename, HH_DISPLAY_TOPIC, 0);
549 ERR("Failed to open HTML Help file '%s'.\n", szCmdLine);
553 while (GetMessageW(&msg, 0, 0, 0))
555 TranslateMessage(&msg);
556 DispatchMessageW(&msg);
562 /******************************************************************
563 * DllGetClassObject (HHCTRL.OCX.@)
565 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
567 FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
568 return CLASS_E_CLASSNOTAVAILABLE;
571 /***********************************************************************
572 * DllRegisterServer (HHCTRL.OCX.@)
574 HRESULT WINAPI DllRegisterServer(void)
576 return __wine_register_resources( hhctrl_hinstance );
579 /***********************************************************************
580 * DllUnregisterServer (HHCTRL.OCX.@)
582 HRESULT WINAPI DllUnregisterServer(void)
584 return __wine_unregister_resources( hhctrl_hinstance );