1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
|
/*
* hhctrl implementation
*
* Copyright 2004 Krzysztof Foltman
* Copyright 2007 Jacek Caban for CodeWeavers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "wine/debug.h"
#include <stdarg.h>
#define COBJMACROS
#include "windef.h"
#include "winbase.h"
#include "winuser.h"
#include "winnls.h"
#include "htmlhelp.h"
#include "ole2.h"
#include "rpcproxy.h"
#define INIT_GUID
#include "hhctrl.h"
WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
HINSTANCE hhctrl_hinstance;
BOOL hh_process = FALSE;
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, LPVOID lpvReserved)
{
TRACE("(%p,%d,%p)\n", hInstance, fdwReason, lpvReserved);
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
hhctrl_hinstance = hInstance;
DisableThreadLibraryCalls(hInstance);
break;
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
static const char *command_to_string(UINT command)
{
#define X(x) case x: return #x
switch (command)
{
X( HH_DISPLAY_TOPIC );
X( HH_DISPLAY_TOC );
X( HH_DISPLAY_INDEX );
X( HH_DISPLAY_SEARCH );
X( HH_SET_WIN_TYPE );
X( HH_GET_WIN_TYPE );
X( HH_GET_WIN_HANDLE );
X( HH_ENUM_INFO_TYPE );
X( HH_SET_INFO_TYPE );
X( HH_SYNC );
X( HH_RESERVED1 );
X( HH_RESERVED2 );
X( HH_RESERVED3 );
X( HH_KEYWORD_LOOKUP );
X( HH_DISPLAY_TEXT_POPUP );
X( HH_HELP_CONTEXT );
X( HH_TP_HELP_CONTEXTMENU );
X( HH_TP_HELP_WM_HELP );
X( HH_CLOSE_ALL );
X( HH_ALINK_LOOKUP );
X( HH_GET_LAST_ERROR );
X( HH_ENUM_CATEGORY );
X( HH_ENUM_CATEGORY_IT );
X( HH_RESET_IT_FILTER );
X( HH_SET_INCLUSIVE_FILTER );
X( HH_SET_EXCLUSIVE_FILTER );
X( HH_INITIALIZE );
X( HH_UNINITIALIZE );
X( HH_SAFE_DISPLAY_TOPIC );
X( HH_PRETRANSLATEMESSAGE );
X( HH_SET_GLOBAL_PROPERTY );
default: return "???";
}
#undef X
}
static BOOL resolve_filename(const WCHAR *filename, WCHAR *fullname, DWORD buflen, const WCHAR **index, const WCHAR **window)
{
const WCHAR *extra;
WCHAR chm_file[MAX_PATH];
static const WCHAR helpW[] = {'\\','h','e','l','p','\\',0};
static const WCHAR delimW[] = {':',':',0};
static const WCHAR delim2W[] = {'>',0};
filename = skip_schema(filename);
/* the format is "helpFile[::/index][>window]" */
if (index) *index = NULL;
if (window) *window = NULL;
extra = strstrW(filename, delim2W);
if (extra)
{
memcpy(chm_file, filename, (extra-filename)*sizeof(WCHAR));
chm_file[extra-filename] = 0;
filename = chm_file;
if (window)
*window = strdupW(extra+1);
}
extra = strstrW(filename, delimW);
if (extra)
{
if (filename != chm_file)
memcpy(chm_file, filename, (extra-filename)*sizeof(WCHAR));
chm_file[extra-filename] = 0;
filename = chm_file;
if (index)
*index = strdupW(extra+2);
}
GetFullPathNameW(filename, buflen, fullname, NULL);
if (GetFileAttributesW(fullname) == INVALID_FILE_ATTRIBUTES)
{
GetWindowsDirectoryW(fullname, buflen);
strcatW(fullname, helpW);
strcatW(fullname, filename);
}
return (GetFileAttributesW(fullname) != INVALID_FILE_ATTRIBUTES);
}
/******************************************************************
* HtmlHelpW (HHCTRL.OCX.15)
*/
HWND WINAPI HtmlHelpW(HWND caller, LPCWSTR filename, UINT command, DWORD_PTR data)
{
WCHAR fullname[MAX_PATH];
TRACE("(%p, %s, command=%s, data=%lx)\n",
caller, debugstr_w( filename ),
command_to_string( command ), data);
switch (command)
{
case HH_DISPLAY_TOPIC:
case HH_DISPLAY_TOC:
case HH_DISPLAY_INDEX:
case HH_DISPLAY_SEARCH:{
HHInfo *info;
BOOL res;
NMHDR nmhdr;
const WCHAR *index = NULL;
int tab_index = TAB_CONTENTS;
const WCHAR *default_index = NULL;
if (!filename)
return NULL;
if (!resolve_filename(filename, fullname, MAX_PATH, &default_index, NULL))
{
WARN("can't find %s\n", debugstr_w(filename));
return 0;
}
index = default_index;
info = CreateHelpViewer(fullname);
if(!info)
return NULL;
if(!index)
index = info->WinType.pszFile;
/* called to load a specified topic */
switch(command)
{
case HH_DISPLAY_TOPIC:
case HH_DISPLAY_TOC:
if (data)
index = (const WCHAR *)data;
break;
}
res = NavigateToChm(info, info->pCHMInfo->szFile, index);
if (default_index)
heap_free((WCHAR*)default_index);
if(!res)
{
ReleaseHelpViewer(info);
return NULL;
}
switch(command)
{
case HH_DISPLAY_TOPIC:
case HH_DISPLAY_TOC:
tab_index = TAB_CONTENTS;
break;
case HH_DISPLAY_INDEX:
tab_index = TAB_INDEX;
if (data)
FIXME("Should select keyword '%s'.\n", debugstr_w((WCHAR *)data));
break;
case HH_DISPLAY_SEARCH:
tab_index = TAB_SEARCH;
if (data)
FIXME("Should display search specified by HH_FTS_QUERY structure.\n");
break;
}
/* open the requested tab */
memset(&nmhdr, 0, sizeof(nmhdr));
nmhdr.code = TCN_SELCHANGE;
SendMessageW(info->hwndTabCtrl, TCM_SETCURSEL, (WPARAM)info->tabs[tab_index].id, 0);
SendMessageW(info->WinType.hwndNavigation, WM_NOTIFY, 0, (LPARAM)&nmhdr);
return info->WinType.hwndHelp;
}
case HH_HELP_CONTEXT: {
HHInfo *info;
LPWSTR url;
if (!filename)
return NULL;
if (!resolve_filename(filename, fullname, MAX_PATH, NULL, NULL))
{
WARN("can't find %s\n", debugstr_w(filename));
return 0;
}
info = CreateHelpViewer(fullname);
if(!info)
return NULL;
url = FindContextAlias(info->pCHMInfo, data);
if(!url)
{
ReleaseHelpViewer(info);
return NULL;
}
NavigateToUrl(info, url);
heap_free(url);
return info->WinType.hwndHelp;
}
case HH_PRETRANSLATEMESSAGE: {
static BOOL warned = FALSE;
if (!warned)
{
FIXME("HH_PRETRANSLATEMESSAGE unimplemented\n");
warned = TRUE;
}
return 0;
}
default:
FIXME("HH case %s not handled.\n", command_to_string( command ));
}
return 0;
}
/******************************************************************
* HtmlHelpA (HHCTRL.OCX.14)
*/
HWND WINAPI HtmlHelpA(HWND caller, LPCSTR filename, UINT command, DWORD_PTR data)
{
WCHAR *wfile = NULL, *wdata = NULL;
DWORD len;
HWND result;
if (filename)
{
len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 );
wfile = heap_alloc(len*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, filename, -1, wfile, len );
}
if (data)
{
switch(command)
{
case HH_ALINK_LOOKUP:
case HH_DISPLAY_SEARCH:
case HH_DISPLAY_TEXT_POPUP:
case HH_GET_LAST_ERROR:
case HH_GET_WIN_TYPE:
case HH_KEYWORD_LOOKUP:
case HH_SET_WIN_TYPE:
case HH_SYNC:
FIXME("structures not handled yet\n");
break;
case HH_DISPLAY_INDEX:
case HH_DISPLAY_TOPIC:
case HH_DISPLAY_TOC:
case HH_GET_WIN_HANDLE:
case HH_SAFE_DISPLAY_TOPIC:
len = MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, NULL, 0 );
wdata = heap_alloc(len*sizeof(WCHAR));
MultiByteToWideChar( CP_ACP, 0, (const char*)data, -1, wdata, len );
break;
case HH_CLOSE_ALL:
case HH_HELP_CONTEXT:
case HH_INITIALIZE:
case HH_PRETRANSLATEMESSAGE:
case HH_TP_HELP_CONTEXTMENU:
case HH_TP_HELP_WM_HELP:
case HH_UNINITIALIZE:
/* either scalar or pointer to scalar - do nothing */
break;
default:
FIXME("Unknown command: %s (%d)\n", command_to_string(command), command);
break;
}
}
result = HtmlHelpW( caller, wfile, command, wdata ? (DWORD_PTR)wdata : data );
heap_free(wfile);
heap_free(wdata);
return result;
}
/******************************************************************
* doWinMain (HHCTRL.OCX.13)
*/
int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
{
MSG msg;
int len, buflen, mapid = -1;
WCHAR *filename;
char *endq = NULL;
HWND hwnd;
hh_process = TRUE;
/* Parse command line option of the HTML Help command.
*
* Note: The only currently handled action is "mapid",
* which corresponds to opening a specific page.
*/
while(*szCmdLine == '-')
{
LPSTR space, ptr;
ptr = szCmdLine + 1;
space = strchr(ptr, ' ');
if(!strncmp(ptr, "mapid", space-ptr))
{
char idtxt[10];
ptr += strlen("mapid")+1;
space = strchr(ptr, ' ');
/* command line ends without number */
if (!space)
return 0;
memcpy(idtxt, ptr, space-ptr);
idtxt[space-ptr] = '\0';
mapid = atoi(idtxt);
szCmdLine = space+1;
}
else
{
FIXME("Unhandled HTML Help command line parameter! (%.*s)\n", (int)(space-szCmdLine), szCmdLine);
return 0;
}
}
/* FIXME: Check szCmdLine for bad arguments */
if (*szCmdLine == '\"')
endq = strchr(++szCmdLine, '\"');
if (endq)
len = endq - szCmdLine;
else
len = strlen(szCmdLine);
/* no filename given */
if (!len)
return 0;
buflen = MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, NULL, 0) + 1;
filename = heap_alloc(buflen * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, szCmdLine, len, filename, buflen);
filename[buflen-1] = 0;
/* Open a specific help topic */
if(mapid != -1)
hwnd = HtmlHelpW(GetDesktopWindow(), filename, HH_HELP_CONTEXT, mapid);
else
hwnd = HtmlHelpW(GetDesktopWindow(), filename, HH_DISPLAY_TOPIC, 0);
heap_free(filename);
if (!hwnd)
{
ERR("Failed to open HTML Help file '%s'.\n", szCmdLine);
return 0;
}
while (GetMessageW(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
return 0;
}
/******************************************************************
* DllGetClassObject (HHCTRL.OCX.@)
*/
HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
{
FIXME("(%s %s %p)\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
return CLASS_E_CLASSNOTAVAILABLE;
}
/***********************************************************************
* DllRegisterServer (HHCTRL.OCX.@)
*/
HRESULT WINAPI DllRegisterServer(void)
{
return __wine_register_resources( hhctrl_hinstance );
}
/***********************************************************************
* DllUnregisterServer (HHCTRL.OCX.@)
*/
HRESULT WINAPI DllUnregisterServer(void)
{
return __wine_unregister_resources( hhctrl_hinstance );
}
|