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
;
184 info
= CreateHelpViewer(fullname
, caller
);
187 heap_free(default_index
);
193 index
= info
->WinType
.pszFile
;
195 info
->WinType
.pszType
= info
->pszType
= window
;
199 /* called to load a specified topic */
202 case HH_DISPLAY_TOPIC
:
205 index
= (const WCHAR
*)data
;
209 res
= NavigateToChm(info
, info
->pCHMInfo
->szFile
, index
);
210 heap_free(default_index
);
214 ReleaseHelpViewer(info
);
220 case HH_DISPLAY_TOPIC
:
222 tab_index
= TAB_CONTENTS
;
224 case HH_DISPLAY_INDEX
:
225 tab_index
= TAB_INDEX
;
227 FIXME("Should select keyword '%s'.\n", debugstr_w((WCHAR
*)data
));
229 case HH_DISPLAY_SEARCH
:
230 tab_index
= TAB_SEARCH
;
232 FIXME("Should display search specified by HH_FTS_QUERY structure.\n");
235 /* open the requested tab */
236 memset(&nmhdr
, 0, sizeof(nmhdr
));
237 nmhdr
.code
= TCN_SELCHANGE
;
238 SendMessageW(info
->hwndTabCtrl
, TCM_SETCURSEL
, (WPARAM
)info
->tabs
[tab_index
].id
, 0);
239 SendMessageW(info
->WinType
.hwndNavigation
, WM_NOTIFY
, 0, (LPARAM
)&nmhdr
);
241 return info
->WinType
.hwndHelp
;
243 case HH_HELP_CONTEXT
: {
250 if (!resolve_filename(filename
, fullname
, MAX_PATH
, NULL
, NULL
))
252 WARN("can't find %s\n", debugstr_w(filename
));
256 info
= CreateHelpViewer(fullname
, caller
);
260 url
= FindContextAlias(info
->pCHMInfo
, data
);
263 ReleaseHelpViewer(info
);
267 NavigateToUrl(info
, url
);
269 return info
->WinType
.hwndHelp
;
271 case HH_PRETRANSLATEMESSAGE
: {
272 static BOOL warned
= FALSE
;
276 FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n");
284 LIST_FOR_EACH_ENTRY_SAFE(info
, next
, &window_list
, HHInfo
, entry
)
286 TRACE("Destroying window %s.\n", debugstr_w(info
->WinType
.pszType
));
287 ReleaseHelpViewer(info
);
292 FIXME("HH case %s not handled.\n", command_to_string( command
));
298 /******************************************************************
299 * HtmlHelpA (HHCTRL.OCX.14)
301 HWND WINAPI
HtmlHelpA(HWND caller
, LPCSTR filename
, UINT command
, DWORD_PTR data
)
303 WCHAR
*wfile
= NULL
, *wdata
= NULL
;
309 len
= MultiByteToWideChar( CP_ACP
, 0, filename
, -1, NULL
, 0 );
310 wfile
= heap_alloc(len
*sizeof(WCHAR
));
311 MultiByteToWideChar( CP_ACP
, 0, filename
, -1, wfile
, len
);
318 case HH_ALINK_LOOKUP
:
319 case HH_DISPLAY_SEARCH
:
320 case HH_DISPLAY_TEXT_POPUP
:
321 case HH_GET_LAST_ERROR
:
322 case HH_GET_WIN_TYPE
:
323 case HH_KEYWORD_LOOKUP
:
324 case HH_SET_WIN_TYPE
:
326 FIXME("structures not handled yet\n");
329 case HH_DISPLAY_INDEX
:
330 case HH_DISPLAY_TOPIC
:
332 case HH_GET_WIN_HANDLE
:
333 case HH_SAFE_DISPLAY_TOPIC
:
334 len
= MultiByteToWideChar( CP_ACP
, 0, (const char*)data
, -1, NULL
, 0 );
335 wdata
= heap_alloc(len
*sizeof(WCHAR
));
336 MultiByteToWideChar( CP_ACP
, 0, (const char*)data
, -1, wdata
, len
);
340 case HH_HELP_CONTEXT
:
342 case HH_PRETRANSLATEMESSAGE
:
343 case HH_TP_HELP_CONTEXTMENU
:
344 case HH_TP_HELP_WM_HELP
:
345 case HH_UNINITIALIZE
:
346 /* either scalar or pointer to scalar - do nothing */
350 FIXME("Unknown command: %s (%d)\n", command_to_string(command
), command
);
355 result
= HtmlHelpW( caller
, wfile
, command
, wdata
? (DWORD_PTR
)wdata
: data
);
362 /******************************************************************
363 * doWinMain (HHCTRL.OCX.13)
365 int WINAPI
doWinMain(HINSTANCE hInstance
, LPSTR szCmdLine
)
368 int len
, buflen
, mapid
= -1;
375 /* Parse command line option of the HTML Help command.
377 * Note: The only currently handled action is "mapid",
378 * which corresponds to opening a specific page.
380 while(*szCmdLine
== '-')
385 space
= strchr(ptr
, ' ');
386 if(!strncmp(ptr
, "mapid", space
-ptr
))
390 ptr
+= strlen("mapid")+1;
391 space
= strchr(ptr
, ' ');
392 /* command line ends without number */
395 memcpy(idtxt
, ptr
, space
-ptr
);
396 idtxt
[space
-ptr
] = '\0';
402 FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space
-szCmdLine
), szCmdLine
);
407 /* FIXME: Check szCmdLine for bad arguments */
408 if (*szCmdLine
== '\"')
409 endq
= strchr(++szCmdLine
, '\"');
412 len
= endq
- szCmdLine
;
414 len
= strlen(szCmdLine
);
416 /* no filename given */
420 buflen
= MultiByteToWideChar(CP_ACP
, 0, szCmdLine
, len
, NULL
, 0) + 1;
421 filename
= heap_alloc(buflen
* sizeof(WCHAR
));
422 MultiByteToWideChar(CP_ACP
, 0, szCmdLine
, len
, filename
, buflen
);
423 filename
[buflen
-1] = 0;
425 /* Open a specific help topic */
427 hwnd
= HtmlHelpW(GetDesktopWindow(), filename
, HH_HELP_CONTEXT
, mapid
);
429 hwnd
= HtmlHelpW(GetDesktopWindow(), filename
, HH_DISPLAY_TOPIC
, 0);
435 ERR("Failed to open HTML Help file '%s'.\n", szCmdLine
);
439 while (GetMessageW(&msg
, 0, 0, 0))
441 TranslateMessage(&msg
);
442 DispatchMessageW(&msg
);
448 /******************************************************************
449 * DllGetClassObject (HHCTRL.OCX.@)
451 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
453 FIXME("(%s %s %p)\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
454 return CLASS_E_CLASSNOTAVAILABLE
;
457 /***********************************************************************
458 * DllRegisterServer (HHCTRL.OCX.@)
460 HRESULT WINAPI
DllRegisterServer(void)
462 return __wine_register_resources( hhctrl_hinstance
);
465 /***********************************************************************
466 * DllUnregisterServer (HHCTRL.OCX.@)
468 HRESULT WINAPI
DllUnregisterServer(void)
470 return __wine_unregister_resources( hhctrl_hinstance
);