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
;
45 BOOL WINAPI
DllMain(HINSTANCE hInstance
, DWORD fdwReason
, LPVOID lpvReserved
)
47 TRACE("(%p,%ld,%p)\n", hInstance
, fdwReason
, lpvReserved
);
51 case DLL_PROCESS_ATTACH
:
52 hhctrl_hinstance
= hInstance
;
53 DisableThreadLibraryCalls(hInstance
);
59 static const char *command_to_string(UINT command
)
61 #define X(x) case x: return #x
64 X( HH_DISPLAY_TOPIC
);
66 X( HH_DISPLAY_INDEX
);
67 X( HH_DISPLAY_SEARCH
);
70 X( HH_GET_WIN_HANDLE
);
71 X( HH_ENUM_INFO_TYPE
);
72 X( HH_SET_INFO_TYPE
);
77 X( HH_KEYWORD_LOOKUP
);
78 X( HH_DISPLAY_TEXT_POPUP
);
80 X( HH_TP_HELP_CONTEXTMENU
);
81 X( HH_TP_HELP_WM_HELP
);
84 X( HH_GET_LAST_ERROR
);
85 X( HH_ENUM_CATEGORY
);
86 X( HH_ENUM_CATEGORY_IT
);
87 X( HH_RESET_IT_FILTER
);
88 X( HH_SET_INCLUSIVE_FILTER
);
89 X( HH_SET_EXCLUSIVE_FILTER
);
92 X( HH_SAFE_DISPLAY_TOPIC
);
93 X( HH_PRETRANSLATEMESSAGE
);
94 X( HH_SET_GLOBAL_PROPERTY
);
95 default: return "???";
100 static BOOL
resolve_filename(const WCHAR
*env_filename
, WCHAR
*fullname
, DWORD buflen
, WCHAR
**index
, WCHAR
**window
)
102 static const WCHAR helpW
[] = {'\\','h','e','l','p','\\',0};
103 static const WCHAR delimW
[] = {':',':',0};
104 static const WCHAR delim2W
[] = {'>',0};
107 WCHAR
*filename
, *extra
;
109 env_filename
= skip_schema(env_filename
);
111 /* the format is "helpFile[::/index][>window]" */
112 if (index
) *index
= NULL
;
113 if (window
) *window
= NULL
;
115 env_len
= ExpandEnvironmentStringsW(env_filename
, NULL
, 0);
119 filename
= malloc(env_len
* sizeof(WCHAR
));
120 if (filename
== NULL
)
123 ExpandEnvironmentStringsW(env_filename
, filename
, env_len
);
125 extra
= wcsstr(filename
, delim2W
);
130 *window
= wcsdup(extra
+ 1);
133 extra
= wcsstr(filename
, delimW
);
138 *index
= wcsdup(extra
+ 2);
141 GetFullPathNameW(filename
, buflen
, fullname
, NULL
);
142 if (GetFileAttributesW(fullname
) == INVALID_FILE_ATTRIBUTES
)
144 GetWindowsDirectoryW(fullname
, buflen
);
145 lstrcatW(fullname
, helpW
);
146 lstrcatW(fullname
, filename
);
151 if (GetFileAttributesW(fullname
) == INVALID_FILE_ATTRIBUTES
)
153 if (window
) free(*window
);
154 if (index
) free(*index
);
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=%Ix)\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
);
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
:
221 static const WCHAR delimW
[] = {':',':',0};
222 const WCHAR
*i
= (const WCHAR
*)data
;
224 index
= wcsstr(i
, delimW
);
227 if(memcmp(info
->pCHMInfo
->szFile
, i
, index
-i
))
228 FIXME("Opening a CHM file in the context of another is not supported.\n");
229 index
+= lstrlenW(delimW
);
237 res
= NavigateToChm(info
, info
->pCHMInfo
->szFile
, index
);
242 ReleaseHelpViewer(info
);
248 case HH_DISPLAY_TOPIC
:
250 tab_index
= TAB_CONTENTS
;
252 case HH_DISPLAY_INDEX
:
253 tab_index
= TAB_INDEX
;
255 FIXME("Should select keyword '%s'.\n", debugstr_w((WCHAR
*)data
));
257 case HH_DISPLAY_SEARCH
:
258 tab_index
= TAB_SEARCH
;
260 FIXME("Should display search specified by HH_FTS_QUERY structure.\n");
263 /* open the requested tab */
264 memset(&nmhdr
, 0, sizeof(nmhdr
));
265 nmhdr
.code
= TCN_SELCHANGE
;
266 SendMessageW(info
->hwndTabCtrl
, TCM_SETCURSEL
, (WPARAM
)info
->tabs
[tab_index
].id
, 0);
267 SendMessageW(info
->WinType
.hwndNavigation
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
269 return info
->WinType
.hwndHelp
;
271 case HH_HELP_CONTEXT
: {
272 WCHAR
*window
= NULL
;
279 if (!resolve_filename(filename
, fullname
, MAX_PATH
, NULL
, &window
))
281 WARN("can't find %s\n", debugstr_w(filename
));
286 info
= find_window(window
);
288 info
= CreateHelpViewer(info
, fullname
, caller
);
295 if(!info
->WinType
.pszType
)
296 info
->WinType
.pszType
= info
->stringsW
.pszType
= window
;
300 url
= FindContextAlias(info
->pCHMInfo
, data
);
303 if(!data
) /* there may legitimately be no context alias for id 0 */
304 return info
->WinType
.hwndHelp
;
305 ReleaseHelpViewer(info
);
309 NavigateToUrl(info
, url
);
311 return info
->WinType
.hwndHelp
;
313 case HH_PRETRANSLATEMESSAGE
: {
314 static BOOL warned
= FALSE
;
318 FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n");
326 LIST_FOR_EACH_ENTRY_SAFE(info
, next
, &window_list
, HHInfo
, entry
)
328 TRACE("Destroying window %s.\n", debugstr_w(info
->WinType
.pszType
));
329 ReleaseHelpViewer(info
);
333 case HH_SET_WIN_TYPE
: {
334 HH_WINTYPEW
*wintype
= (HH_WINTYPEW
*)data
;
335 WCHAR
*window
= NULL
;
338 if (!filename
&& wintype
->pszType
)
339 window
= wcsdup(wintype
->pszType
);
340 else if (!filename
|| !resolve_filename(filename
, fullname
, MAX_PATH
, NULL
, &window
) || !window
)
342 WARN("can't find window name: %s\n", debugstr_w(filename
));
345 info
= find_window(window
);
348 info
= calloc(1, sizeof(HHInfo
));
349 info
->WinType
.pszType
= info
->stringsW
.pszType
= window
;
350 list_add_tail(&window_list
, &info
->entry
);
355 TRACE("Changing WINTYPE, fsValidMembers=0x%lx\n", wintype
->fsValidMembers
);
357 MergeChmProperties(wintype
, info
, TRUE
);
358 UpdateHelpWindow(info
);
361 case HH_GET_WIN_TYPE
: {
362 HH_WINTYPEW
*wintype
= (HH_WINTYPEW
*)data
;
363 WCHAR
*window
= NULL
;
366 if (!filename
|| !resolve_filename(filename
, fullname
, MAX_PATH
, NULL
, &window
) || !window
)
368 WARN("can't find window name: %s\n", debugstr_w(filename
));
371 info
= find_window(window
);
374 WARN("Could not find window named %s.\n", debugstr_w(window
));
379 TRACE("Retrieving WINTYPE for %s.\n", debugstr_w(window
));
380 *wintype
= info
->WinType
;
385 FIXME("HH case %s not handled.\n", command_to_string( command
));
391 static void wintypeAtoW(const HH_WINTYPEA
*data
, HH_WINTYPEW
*wdata
, struct wintype_stringsW
*stringsW
)
393 memcpy(wdata
, data
, sizeof(*data
));
394 /* convert all of the ANSI strings to Unicode */
395 wdata
->pszType
= stringsW
->pszType
= strdupAtoW(data
->pszType
);
396 wdata
->pszCaption
= stringsW
->pszCaption
= strdupAtoW(data
->pszCaption
);
397 wdata
->pszToc
= stringsW
->pszToc
= strdupAtoW(data
->pszToc
);
398 wdata
->pszIndex
= stringsW
->pszIndex
= strdupAtoW(data
->pszIndex
);
399 wdata
->pszFile
= stringsW
->pszFile
= strdupAtoW(data
->pszFile
);
400 wdata
->pszHome
= stringsW
->pszHome
= strdupAtoW(data
->pszHome
);
401 wdata
->pszJump1
= stringsW
->pszJump1
= strdupAtoW(data
->pszJump1
);
402 wdata
->pszJump2
= stringsW
->pszJump2
= strdupAtoW(data
->pszJump2
);
403 wdata
->pszUrlJump1
= stringsW
->pszUrlJump1
= strdupAtoW(data
->pszUrlJump1
);
404 wdata
->pszUrlJump2
= stringsW
->pszUrlJump2
= strdupAtoW(data
->pszUrlJump2
);
405 wdata
->pszCustomTabs
= stringsW
->pszCustomTabs
= strdupAtoW(data
->pszCustomTabs
);
408 static void wintypeWtoA(const HH_WINTYPEW
*wdata
, HH_WINTYPEA
*data
, struct wintype_stringsA
*stringsA
)
410 memcpy(data
, wdata
, sizeof(*wdata
));
411 /* convert all of the Unicode strings to ANSI */
412 data
->pszType
= stringsA
->pszType
= strdupWtoA(wdata
->pszType
);
413 data
->pszCaption
= stringsA
->pszCaption
= strdupWtoA(wdata
->pszCaption
);
414 data
->pszToc
= stringsA
->pszToc
= strdupWtoA(wdata
->pszToc
);
415 data
->pszIndex
= stringsA
->pszFile
= strdupWtoA(wdata
->pszIndex
);
416 data
->pszFile
= stringsA
->pszFile
= strdupWtoA(wdata
->pszFile
);
417 data
->pszHome
= stringsA
->pszHome
= strdupWtoA(wdata
->pszHome
);
418 data
->pszJump1
= stringsA
->pszJump1
= strdupWtoA(wdata
->pszJump1
);
419 data
->pszJump2
= stringsA
->pszJump2
= strdupWtoA(wdata
->pszJump2
);
420 data
->pszUrlJump1
= stringsA
->pszUrlJump1
= strdupWtoA(wdata
->pszUrlJump1
);
421 data
->pszUrlJump2
= stringsA
->pszUrlJump2
= strdupWtoA(wdata
->pszUrlJump2
);
422 data
->pszCustomTabs
= stringsA
->pszCustomTabs
= strdupWtoA(wdata
->pszCustomTabs
);
425 /******************************************************************
426 * HtmlHelpA (HHCTRL.OCX.14)
428 HWND WINAPI
HtmlHelpA(HWND caller
, LPCSTR filename
, UINT command
, DWORD_PTR data
)
430 WCHAR
*wfile
= strdupAtoW( filename
);
437 case HH_ALINK_LOOKUP
:
438 case HH_DISPLAY_SEARCH
:
439 case HH_DISPLAY_TEXT_POPUP
:
440 case HH_GET_LAST_ERROR
:
441 case HH_KEYWORD_LOOKUP
:
443 FIXME("structures not handled yet\n");
446 case HH_SET_WIN_TYPE
:
448 struct wintype_stringsW stringsW
;
451 wintypeAtoW((HH_WINTYPEA
*)data
, &wdata
, &stringsW
);
452 result
= HtmlHelpW( caller
, wfile
, command
, (DWORD_PTR
)&wdata
);
453 wintype_stringsW_free(&stringsW
);
456 case HH_GET_WIN_TYPE
:
461 result
= HtmlHelpW( caller
, wfile
, command
, (DWORD_PTR
)&wdata
);
462 if (!wdata
.pszType
) break;
463 info
= find_window(wdata
.pszType
);
465 wintype_stringsA_free(&info
->stringsA
);
466 wintypeWtoA(&wdata
, (HH_WINTYPEA
*)data
, &info
->stringsA
);
470 case HH_DISPLAY_INDEX
:
471 case HH_DISPLAY_TOPIC
:
473 case HH_GET_WIN_HANDLE
:
474 case HH_SAFE_DISPLAY_TOPIC
:
476 WCHAR
*wdata
= strdupAtoW( (const char *)data
);
477 result
= HtmlHelpW( caller
, wfile
, command
, (DWORD_PTR
)wdata
);
483 case HH_HELP_CONTEXT
:
485 case HH_PRETRANSLATEMESSAGE
:
486 case HH_TP_HELP_CONTEXTMENU
:
487 case HH_TP_HELP_WM_HELP
:
488 case HH_UNINITIALIZE
:
489 /* either scalar or pointer to scalar - do nothing */
493 FIXME("Unknown command: %s (%d)\n", command_to_string(command
), command
);
498 result
= HtmlHelpW( caller
, wfile
, command
, data
);
504 /******************************************************************
505 * doWinMain (HHCTRL.OCX.13)
507 int WINAPI
doWinMain(HINSTANCE hInstance
, LPSTR szCmdLine
)
510 int len
, buflen
, mapid
= -1;
517 /* Parse command line option of the HTML Help command.
519 * Note: The only currently handled action is "mapid",
520 * which corresponds to opening a specific page.
522 while(*szCmdLine
== '-')
527 space
= strchr(ptr
, ' ');
528 if(!strncmp(ptr
, "mapid", space
-ptr
))
532 ptr
+= strlen("mapid")+1;
533 space
= strchr(ptr
, ' ');
534 /* command line ends without number */
537 memcpy(idtxt
, ptr
, space
-ptr
);
538 idtxt
[space
-ptr
] = '\0';
544 FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space
-szCmdLine
), szCmdLine
);
549 /* FIXME: Check szCmdLine for bad arguments */
550 if (*szCmdLine
== '\"')
551 endq
= strchr(++szCmdLine
, '\"');
554 len
= endq
- szCmdLine
;
556 len
= strlen(szCmdLine
);
558 /* no filename given */
562 buflen
= MultiByteToWideChar(CP_ACP
, 0, szCmdLine
, len
, NULL
, 0) + 1;
563 filename
= malloc(buflen
* sizeof(WCHAR
));
564 MultiByteToWideChar(CP_ACP
, 0, szCmdLine
, len
, filename
, buflen
);
565 filename
[buflen
-1] = 0;
567 /* Open a specific help topic */
569 hwnd
= HtmlHelpW(GetDesktopWindow(), filename
, HH_HELP_CONTEXT
, mapid
);
571 hwnd
= HtmlHelpW(GetDesktopWindow(), filename
, HH_DISPLAY_TOPIC
, 0);
577 ERR("Failed to open HTML Help file '%s'.\n", szCmdLine
);
581 while (GetMessageW(&msg
, 0, 0, 0))
583 TranslateMessage(&msg
);
584 DispatchMessageW(&msg
);
590 /******************************************************************
591 * DllGetClassObject (HHCTRL.OCX.@)
593 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
595 FIXME("(%s %s %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
596 return CLASS_E_CLASSNOTAVAILABLE
;