winhelp.c 51.7 KB
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
1 2 3
/*
 * Help Viewer
 *
4 5 6
 * Copyright    1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
 *              2002 Sylvain Petreolle <spetreolle@yahoo.fr>
 *              2002 Eric Pouech <eric.pouech@wanadoo.fr>
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 *
 * 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
Alexandre Julliard's avatar
Alexandre Julliard committed
21 22
 */

23
#include <assert.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
24
#include <stdio.h>
25
#include <string.h>
26
#include "winbase.h"
27
#include "wingdi.h"
Eric Pouech's avatar
Eric Pouech committed
28
#include "winuser.h"
29
#include "winhelp.h"
30
#include "winhelp_res.h"
Eric Pouech's avatar
Eric Pouech committed
31
#include "shellapi.h"
32

33 34 35 36 37
#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(winhelp);

static BOOL    WINHELP_RegisterWinClasses(void);
38 39 40
static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
41
static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
42
static void    WINHELP_CheckPopup(UINT);
Alexandre Julliard's avatar
Alexandre Julliard committed
43
static BOOL    WINHELP_SplitLines(HWND hWnd, LPSIZE);
44 45 46 47
static void    WINHELP_InitFonts(HWND hWnd);
static void    WINHELP_DeleteLines(WINHELP_WINDOW*);
static void    WINHELP_DeleteWindow(WINHELP_WINDOW*);
static void    WINHELP_SetupText(HWND hWnd);
48
static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
Alexandre Julliard's avatar
Alexandre Julliard committed
49

50
WINHELP_GLOBALS Globals = {3, 0, 0, 0, 1, 0, 0};
Alexandre Julliard's avatar
Alexandre Julliard committed
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
/***********************************************************************
 *
 *           WINHELP_LookupHelpFile
 */
HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
{
    HLPFILE*        hlpfile;

    hlpfile = HLPFILE_ReadHlpFile(lpszFile);

    /* Add Suffix `.hlp' */
    if (!hlpfile && lstrcmpi(lpszFile + strlen(lpszFile) - 4, ".hlp") != 0)
    {
        char      szFile_hlp[MAX_PATHNAME_LEN];

        lstrcpyn(szFile_hlp, lpszFile, sizeof(szFile_hlp) - 4);
        szFile_hlp[sizeof(szFile_hlp) - 5] = '\0';
        lstrcat(szFile_hlp, ".hlp");

        hlpfile = HLPFILE_ReadHlpFile(szFile_hlp);
    }
    if (!hlpfile)
    {
        WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile, STID_WHERROR, MB_OK);
        if (Globals.win_list) return NULL;
    }
    return hlpfile;
}

/******************************************************************
 *		WINHELP_GetWindowInfo
 *
 *
 */
HLPFILE_WINDOWINFO*     WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
{
    static      HLPFILE_WINDOWINFO      mwi;
    int         i;

    if (!name || !name[0])
        name = Globals.active_win->lpszName;

94 95 96 97
    if (hlpfile)
        for (i = 0; i < hlpfile->numWindows; i++)
            if (!strcmp(hlpfile->windows[i].name, name))
                return &hlpfile->windows[i];
98 99 100 101 102 103 104 105 106 107 108

    if (strcmp(name, "main") != 0)
    {
        WINE_FIXME("Couldn't find window info for %s\n", name);
        assert(0);
        return NULL;
    }
    if (!mwi.name[0])
    {
        strcpy(mwi.type, "primary");
        strcpy(mwi.name, "main");
109 110 111
        if (!LoadString(Globals.hInstance, STID_WINE_HELP, 
                        mwi.caption, sizeof(mwi.caption)))
            strcpy(mwi.caption, hlpfile->lpszTitle);
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
        mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
        mwi.style = SW_SHOW;
        mwi.sr_color = mwi.sr_color = 0xFFFFFF;
    }
    return &mwi;
}

/******************************************************************
 *		HLPFILE_GetPopupWindowInfo
 *
 *
 */
HLPFILE_WINDOWINFO*     WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
{
    static      HLPFILE_WINDOWINFO      wi;

    RECT parent_rect;
    
    wi.type[0] = wi.name[0] = wi.caption[0] = '\0';

    /* Calculate horizontal size and position of a popup window */
    GetWindowRect(hParentWnd, &parent_rect);
    wi.size.cx = (parent_rect.right  - parent_rect.left) / 2;
    wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */

    wi.origin = *mouse;
    ClientToScreen(hParentWnd, &wi.origin);
    wi.origin.x -= wi.size.cx / 2;
    wi.origin.x  = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
    wi.origin.x  = max(wi.origin.x, 0);

    wi.style = SW_SHOW;
    wi.win_style = WS_POPUPWINDOW;
    wi.sr_color = wi.sr_color = 0xFFFFFF;

    return &wi;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
149 150 151 152 153

/***********************************************************************
 *
 *           WinMain
 */
154
int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
Alexandre Julliard's avatar
Alexandre Julliard committed
155
{
156 157
    MSG         msg;
    LONG        lHash = 0;
158
    HLPFILE*    hlpfile;
Alexandre Julliard's avatar
Alexandre Julliard committed
159

160
    Globals.hInstance = hInstance;
161
    
162 163
    /* Get options */
    while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
Alexandre Julliard's avatar
Alexandre Julliard committed
164
    {
165 166 167 168 169 170 171 172
        CHAR   option;
        LPCSTR topic_id;
        if (*cmdline++ == ' ') continue;

        option = *cmdline;
        if (option) cmdline++;
        while (*cmdline && *cmdline == ' ') cmdline++;
        switch (option)
Alexandre Julliard's avatar
Alexandre Julliard committed
173 174 175
	{
	case 'i':
	case 'I':
176 177 178 179 180
            topic_id = cmdline;
            while (*cmdline && *cmdline != ' ') cmdline++;
            if (*cmdline) *cmdline++ = '\0';
            lHash = HLPFILE_Hash(topic_id);
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed
181 182 183

	case '3':
	case '4':
184 185
            Globals.wVersion = option - '0';
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed
186

187 188
        case 'x':
            show = SW_HIDE; 
189
            Globals.isBook = FALSE;
190 191 192 193 194
            break;

        default:
            WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed
195 196 197
	}
    }

198 199
    /* Create primary window */
    WINHELP_RegisterWinClasses();
200 201 202 203 204 205
    if (*cmdline)
    {
        hlpfile = WINHELP_LookupHelpFile(cmdline);
        if (!hlpfile) return 0;
    }
    else hlpfile = NULL;
206 207
    WINHELP_CreateHelpWindowByHash(hlpfile, lHash, 
                                   WINHELP_GetWindowInfo(hlpfile, "main"), show);
Alexandre Julliard's avatar
Alexandre Julliard committed
208

209 210
    /* Message loop */
    while (GetMessage(&msg, 0, 0, 0))
Alexandre Julliard's avatar
Alexandre Julliard committed
211
    {
212 213
        TranslateMessage(&msg);
        DispatchMessage(&msg);
Alexandre Julliard's avatar
Alexandre Julliard committed
214
    }
215
    return 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
216 217 218 219 220 221
}

/***********************************************************************
 *
 *           RegisterWinClasses
 */
222
static BOOL WINHELP_RegisterWinClasses(void)
Alexandre Julliard's avatar
Alexandre Julliard committed
223
{
224
    WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
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

    class_main.style               = CS_HREDRAW | CS_VREDRAW;
    class_main.lpfnWndProc         = WINHELP_MainWndProc;
    class_main.cbClsExtra          = 0;
    class_main.cbWndExtra          = sizeof(LONG);
    class_main.hInstance           = Globals.hInstance;
    class_main.hIcon               = LoadIcon(0, IDI_APPLICATION);
    class_main.hCursor             = LoadCursor(0, IDC_ARROW);
    class_main.hbrBackground       = GetStockObject(WHITE_BRUSH);
    class_main.lpszMenuName        = 0;
    class_main.lpszClassName       = MAIN_WIN_CLASS_NAME;

    class_button_box               = class_main;
    class_button_box.lpfnWndProc   = WINHELP_ButtonBoxWndProc;
    class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
    class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;

    class_text = class_main;
    class_text.lpfnWndProc         = WINHELP_TextWndProc;
    class_text.lpszClassName       = TEXT_WIN_CLASS_NAME;

    class_shadow = class_main;
    class_shadow.lpfnWndProc       = DefWindowProc;
    class_shadow.hbrBackground     = GetStockObject(GRAY_BRUSH);
    class_shadow.lpszClassName     = SHADOW_WIN_CLASS_NAME;

251 252 253 254
    class_history = class_main;
    class_history.lpfnWndProc      = WINHELP_HistoryWndProc;
    class_history.lpszClassName    = HISTORY_WIN_CLASS_NAME;

255 256 257
    return (RegisterClass(&class_main) &&
            RegisterClass(&class_button_box) &&
            RegisterClass(&class_text) &&
258 259
            RegisterClass(&class_shadow) &&
            RegisterClass(&class_history));
Alexandre Julliard's avatar
Alexandre Julliard committed
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
typedef struct
{
    WORD size;
    WORD command;
    LONG data;
    LONG reserved;
    WORD ofsFilename;
    WORD ofsData;
} WINHELP,*LPWINHELP;

/******************************************************************
 *		WINHELP_HandleCommand
 *
 *
 */
static LRESULT  WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
{
    COPYDATASTRUCT*     cds = (COPYDATASTRUCT*)lParam;
    WINHELP*            wh;

    if (cds->dwData != 0xA1DE505)
    {
        WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
        return 0;
    }

    wh = (WINHELP*)cds->lpData;

    if (wh)
    {
292 293
        char*   ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;

294
        WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n", 
295
                   wh->size, wh->command, wh->data, ptr);
296 297
        switch (wh->command)
        {
298 299 300 301 302 303
        case HELP_CONTEXT:
            if (ptr)
            {
                MACRO_JumpContext(ptr, "main", wh->data);
            }
            break;
304 305 306
        case HELP_QUIT:
            MACRO_Exit();
            break;
307 308
        case HELP_CONTENTS:
            if (ptr)
309
            {
310
                MACRO_JumpContents(ptr, "main");
311 312
            }
            break;
313 314 315 316
        case HELP_HELPONHELP:
            MACRO_HelpOn();
            break;
        /* case HELP_SETINDEX: */
317
        case HELP_SETCONTENTS:
318 319 320 321 322
            if (ptr)
            {
                MACRO_SetContents(ptr, wh->data);
            }
            break;
323
        case HELP_CONTEXTPOPUP:
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
            if (ptr)
            {
                MACRO_PopupContext(ptr, wh->data);
            }
            break;
        /* case HELP_FORCEFILE:*/
        /* case HELP_CONTEXTMENU: */
        case HELP_FINDER:
            /* in fact, should be the topic dialog box */
            if (ptr)
            {
                MACRO_JumpHash(ptr, "main", 0);
            }
            break;
        /* case HELP_WM_HELP: */
        /* case HELP_SETPOPUP_POS: */
        /* case HELP_KEY: */
        /* case HELP_COMMAND: */
        /* case HELP_PARTIALKEY: */
        /* case HELP_MULTIKEY: */
        /* case HELP_SETWINPOS: */
            WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
346 347 348 349 350 351
            break;
        }
    }
    return 0L;
}

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
/******************************************************************
 *		WINHELP_ReuseWindow
 *
 *
 */
static BOOL     WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin, 
                                    HLPFILE_PAGE* page, int nCmdShow)
{
    int                 i;

    win->hMainWnd      = oldwin->hMainWnd;
    win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
    win->hTextWnd      = oldwin->hTextWnd;
    win->hHistoryWnd   = oldwin->hHistoryWnd;
    oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;

    SetWindowLong(win->hMainWnd,      0, (LONG)win);
    SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
    SetWindowLong(win->hTextWnd,      0, (LONG)win);
    SetWindowLong(win->hHistoryWnd,   0, (LONG)win);

    WINHELP_InitFonts(win->hMainWnd);

    if (page)
        SetWindowText(win->hMainWnd, page->file->lpszTitle);

    WINHELP_SetupText(win->hTextWnd);
    InvalidateRect(win->hTextWnd, NULL, TRUE);
    SendMessage(win->hMainWnd, WM_USER, 0, 0);
    ShowWindow(win->hMainWnd, nCmdShow);
    UpdateWindow(win->hTextWnd);

    if (!(win->info->win_style & WS_POPUP))
    {
        unsigned        num;

        memcpy(win->history, oldwin->history, sizeof(win->history));
        win->histIndex = oldwin->histIndex;

        /* FIXME: when using back, we shouldn't update the history... */

        if (page)
        {
            for (i = 0; i < win->histIndex; i++)
                if (win->history[i] == page) break;

            /* if the new page is already in the history, do nothing */
            if (i == win->histIndex)
            {
                num = sizeof(win->history) / sizeof(win->history[0]);
                if (win->histIndex == num)
                {
                    /* we're full, remove latest entry */
                    HLPFILE_FreeHlpFile(win->history[0]->file);
                    memmove(&win->history[0], &win->history[1], 
                            (num - 1) * sizeof(win->history[0]));
                    win->histIndex--;
                }
                win->history[win->histIndex++] = page;
                page->file->wRefCount++;
                if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
            }
        }

        memcpy(win->back, oldwin->back, sizeof(win->back));
        win->backIndex = oldwin->backIndex;

        if (page)
        {
            num = sizeof(win->back) / sizeof(win->back[0]);
            if (win->backIndex == num)
            {
                /* we're full, remove latest entry */
                HLPFILE_FreeHlpFile(win->back[0]->file);
                memmove(&win->back[0], &win->back[1], 
                        (num - 1) * sizeof(win->back[0]));
                win->backIndex--;
            }
            win->back[win->backIndex++] = page;
            page->file->wRefCount++;
        }
    }
    else
        win->backIndex = win->histIndex = 0;

    oldwin->histIndex = oldwin->backIndex = 0;
    WINHELP_DeleteWindow(oldwin);
    return TRUE;
}

Alexandre Julliard's avatar
Alexandre Julliard committed
442 443 444 445
/***********************************************************************
 *
 *           WINHELP_CreateHelpWindow
 */
446 447
BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
                              int nCmdShow)
Alexandre Julliard's avatar
Alexandre Julliard committed
448
{
449 450 451
    WINHELP_WINDOW *win, *oldwin;
    HWND hWnd;
    BOOL bPrimary;
452
    BOOL bPopup;
453

454
    bPrimary = !lstrcmpi(wi->name, "main");
455
    bPopup = wi->win_style & WS_POPUP;
Alexandre Julliard's avatar
Alexandre Julliard committed
456

457 458
    /* Initialize WINHELP_WINDOW struct */
    win = HeapAlloc(GetProcessHeap(), 0,
459
                    sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
460
    if (!win) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
461

462 463
    win->next  = Globals.win_list;
    Globals.win_list = win;
464 465 466

    win->lpszName = (char*)win + sizeof(WINHELP_WINDOW);
    lstrcpy((char*)win->lpszName, wi->name);
467

468 469 470 471 472 473 474
    win->page = page;
    win->first_button = 0;
    win->first_line = 0;
    win->hMainWnd = 0;
    win->hButtonBoxWnd = 0;
    win->hTextWnd = 0;
    win->hShadowWnd = 0;
475
    win->hHistoryWnd = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
476

477 478
    win->hArrowCur = LoadCursorA(0, IDC_ARROWA);
    win->hHandCur = LoadCursorA(0, IDC_HANDA);
479

480 481
    win->info = wi;

482
    Globals.active_win = win;
Alexandre Julliard's avatar
Alexandre Julliard committed
483

484 485
    /* Initialize default pushbuttons */
    if (bPrimary && page)
Alexandre Julliard's avatar
Alexandre Julliard committed
486
    {
487 488 489 490 491 492 493 494 495 496 497 498
        CHAR    buffer[MAX_STRING_LEN];

        LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
        MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
        LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
        MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
        LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
        MACRO_CreateButton("BTN_BACK", buffer, "Back()");
        LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
        MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
        LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
        MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
Alexandre Julliard's avatar
Alexandre Julliard committed
499 500
    }

501
    /* Initialize file specific pushbuttons */
502 503 504
    if (!(wi->win_style & WS_POPUP) && page)
    {
        HLPFILE_MACRO  *macro;
505 506
        for (macro = page->file->first_macro; macro; macro = macro->next)
            MACRO_ExecuteMacro(macro->lpszMacro);
507 508 509

        for (macro = page->first_macro; macro; macro = macro->next)
            MACRO_ExecuteMacro(macro->lpszMacro);
510
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
511

512
    win->histIndex = win->backIndex = 0;
513
    /* Reuse existing window */
514
    if (!bPopup)
515
    {
516
        for (oldwin = win->next; oldwin; oldwin = oldwin->next)
517 518
        {
            if (!lstrcmpi(oldwin->lpszName, wi->name))
519
            {
520
                return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
521
            }
522
        }
523 524 525 526 527 528
        if (page)
        {
            win->histIndex = win->backIndex = 1;
            win->history[0] = win->back[0] = page;
            page->file->wRefCount += 2;
        }
529
    }
530

531
    hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
532 533
                        wi->caption, wi->win_style,
                        wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
534 535 536 537 538
                        0, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
                        Globals.hInstance, win);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
539

540
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
541 542
}

543 544 545 546
/***********************************************************************
 *
 *           WINHELP_CreateHelpWindowByHash
 */
547 548
BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash, 
                                    HLPFILE_WINDOWINFO* wi, int nCmdShow)
Alexandre Julliard's avatar
Alexandre Julliard committed
549
{
Eric Pouech's avatar
Eric Pouech committed
550
    HLPFILE_PAGE*       page = NULL;
551

552 553 554 555 556
    if (hlpfile)
        page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) : 
            HLPFILE_Contents(hlpfile);
    if (page) page->file->wRefCount++;
    return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
}

/***********************************************************************
 *
 *           WINHELP_MainWndProc
 */
static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    WINHELP_WINDOW *win;
    WINHELP_BUTTON *button;
    RECT rect, button_box_rect;
    INT  text_top;

    WINHELP_CheckPopup(msg);

    switch (msg)
Alexandre Julliard's avatar
Alexandre Julliard committed
573 574
    {
    case WM_NCCREATE:
575 576 577 578
        win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
        SetWindowLong(hWnd, 0, (LONG) win);
        win->hMainWnd = hWnd;
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
579 580

    case WM_CREATE:
581
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
582

583 584 585
        /* Create button box and text Window */
        CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
                     0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
Alexandre Julliard's avatar
Alexandre Julliard committed
586

587 588
        CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
                     0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
Alexandre Julliard's avatar
Alexandre Julliard committed
589

590
        /* Fall through */
Alexandre Julliard's avatar
Alexandre Julliard committed
591 592
    case WM_USER:
    case WM_WINDOWPOSCHANGED:
593 594
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        GetClientRect(hWnd, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
595

596 597 598 599 600
        /* Update button box and text Window */
        SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
                     rect.left, rect.top,
                     rect.right - rect.left,
                     rect.bottom - rect.top, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
601

602 603
        GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
        text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
Alexandre Julliard's avatar
Alexandre Julliard committed
604

605 606 607 608
        SetWindowPos(win->hTextWnd, HWND_TOP,
                     rect.left, text_top,
                     rect.right - rect.left,
                     rect.bottom - text_top, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
609

610
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
611 612

    case WM_COMMAND:
613 614
        Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        switch (wParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
615
	{
616
            /* Menu FILE */
617 618 619 620
	case MNID_FILE_OPEN:    MACRO_FileOpen();       break;
	case MNID_FILE_PRINT:	MACRO_Print();          break;
	case MNID_FILE_SETUP:	MACRO_PrinterSetup();   break;
	case MNID_FILE_EXIT:	MACRO_Exit();           break;
Alexandre Julliard's avatar
Alexandre Julliard committed
621

622
            /* Menu EDIT */
623 624
	case MNID_EDIT_COPYDLG: MACRO_CopyDialog();     break;
	case MNID_EDIT_ANNOTATE:MACRO_Annotate();       break;
Alexandre Julliard's avatar
Alexandre Julliard committed
625

626
            /* Menu Bookmark */
627
	case MNID_BKMK_DEFINE:  MACRO_BookmarkDefine(); break;
Alexandre Julliard's avatar
Alexandre Julliard committed
628

629
            /* Menu Help */
630 631 632 633
	case MNID_HELP_HELPON:	MACRO_HelpOn();         break;
	case MNID_HELP_HELPTOP: MACRO_HelpOnTop();      break;
	case MNID_HELP_ABOUT:	MACRO_About();          break;
	case MNID_HELP_WINE:    ShellAbout(hWnd, "WINE", "Help", 0); break;
Alexandre Julliard's avatar
Alexandre Julliard committed
634 635

	default:
636 637 638 639 640 641
            /* Buttons */
            for (button = win->first_button; button; button = button->next)
                if (wParam == button->wParam) break;
            if (button)
                MACRO_ExecuteMacro(button->lpszMacro);
            else
642
                WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
643
            break;
Alexandre Julliard's avatar
Alexandre Julliard committed
644
	}
645 646 647 648
        break;
    case WM_DESTROY:
        if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
        break;
649 650
    case WM_COPYDATA:
        return WINHELP_HandleCommand((HWND)wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
651
    }
652
    return DefWindowProc(hWnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
653 654 655 656 657 658
}

/***********************************************************************
 *
 *           WINHELP_ButtonBoxWndProc
 */
659
static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
660
{
661 662 663 664 665
    WINDOWPOS      *winpos;
    WINHELP_WINDOW *win;
    WINHELP_BUTTON *button;
    SIZE button_size;
    INT  x, y;
Alexandre Julliard's avatar
Alexandre Julliard committed
666

667
    WINHELP_CheckPopup(msg);
Alexandre Julliard's avatar
Alexandre Julliard committed
668

669
    switch (msg)
Alexandre Julliard's avatar
Alexandre Julliard committed
670 671
    {
    case WM_NCCREATE:
672 673 674 675
        win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
        SetWindowLong(hWnd, 0, (LONG) win);
        win->hButtonBoxWnd = hWnd;
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
676 677

    case WM_WINDOWPOSCHANGING:
678 679
        winpos = (WINDOWPOS*) lParam;
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
680

681 682 683 684
        /* Update buttons */
        button_size.cx = 0;
        button_size.cy = 0;
        for (button = win->first_button; button; button = button->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
685
	{
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
            HDC  hDc;
            SIZE textsize;
            if (!button->hWnd)
                button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
                                            WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
                                            0, 0, 0, 0,
                                            hWnd, (HMENU) button->wParam,
                                            Globals.hInstance, 0);
            hDc = GetDC(button->hWnd);
            GetTextExtentPoint(hDc, button->lpszName,
                               lstrlen(button->lpszName), &textsize);
            ReleaseDC(button->hWnd, hDc);

            button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
            button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
Alexandre Julliard's avatar
Alexandre Julliard committed
701 702
	}

703 704 705
        x = 0;
        y = 0;
        for (button = win->first_button; button; button = button->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
706
	{
707
            SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
708

709 710 711 712
            if (x + 2 * button_size.cx <= winpos->cx)
                x += button_size.cx;
            else
                x = 0, y += button_size.cy;
Alexandre Julliard's avatar
Alexandre Julliard committed
713
	}
714 715
        winpos->cy = y + (x ? button_size.cy : 0);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
716 717

    case WM_COMMAND:
718 719
        SendMessage(GetParent(hWnd), msg, wParam, lParam);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
720 721
    }

722
    return DefWindowProc(hWnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
723 724 725 726 727 728
}

/***********************************************************************
 *
 *           WINHELP_TextWndProc
 */
729
static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
Alexandre Julliard's avatar
Alexandre Julliard committed
730
{
731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
    WINHELP_WINDOW    *win;
    WINHELP_LINE      *line;
    WINHELP_LINE_PART *part;
    WINDOWPOS         *winpos;
    PAINTSTRUCT        ps;
    HDC   hDc;
    POINT mouse;
    INT   scroll_pos;
    HWND  hPopupWnd;
    BOOL  bExit;

    if (msg != WM_LBUTTONDOWN)
        WINHELP_CheckPopup(msg);

    switch (msg)
Alexandre Julliard's avatar
Alexandre Julliard committed
746 747
    {
    case WM_NCCREATE:
748 749 750
        win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
        SetWindowLong(hWnd, 0, (LONG) win);
        win->hTextWnd = hWnd;
751
        if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
752 753
        WINHELP_InitFonts(hWnd);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
754 755

    case WM_CREATE:
756
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
757

758
        /* Calculate vertical size and position of a popup window */
759
        if (win->info->win_style & WS_POPUP)
Alexandre Julliard's avatar
Alexandre Julliard committed
760
	{
761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
            POINT origin;
            RECT old_window_rect;
            RECT old_client_rect;
            SIZE old_window_size;
            SIZE old_client_size;
            SIZE new_client_size;
            SIZE new_window_size;

            GetWindowRect(hWnd, &old_window_rect);
            origin.x = old_window_rect.left;
            origin.y = old_window_rect.top;
            old_window_size.cx = old_window_rect.right  - old_window_rect.left;
            old_window_size.cy = old_window_rect.bottom - old_window_rect.top;

            GetClientRect(hWnd, &old_client_rect);
            old_client_size.cx = old_client_rect.right  - old_client_rect.left;
            old_client_size.cy = old_client_rect.bottom - old_client_rect.top;

            new_client_size = old_client_size;
            WINHELP_SplitLines(hWnd, &new_client_size);

            if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
                origin.y += POPUP_YDISTANCE;
            else
                origin.y -= POPUP_YDISTANCE + new_client_size.cy;

            new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
            new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;

            win->hShadowWnd =
                CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
                             origin.x + SHADOW_DX, origin.y + SHADOW_DY,
                             new_window_size.cx, new_window_size.cy,
                             0, 0, Globals.hInstance, 0);

            SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
                         new_window_size.cx, new_window_size.cy,
                         0);
            SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
            ShowWindow(win->hShadowWnd, SW_NORMAL);
            SetActiveWindow(hWnd);
Alexandre Julliard's avatar
Alexandre Julliard committed
802
	}
803
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
804 805

    case WM_WINDOWPOSCHANGED:
806 807 808 809
        winpos = (WINDOWPOS*) lParam;

        if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
810 811

    case WM_VSCROLL:
812
    {
Alexandre Julliard's avatar
Alexandre Julliard committed
813 814
	BOOL  update = TRUE;
	RECT  rect;
Alexandre Julliard's avatar
Alexandre Julliard committed
815
	INT   Min, Max;
Alexandre Julliard's avatar
Alexandre Julliard committed
816
	INT   CurPos = GetScrollPos(hWnd, SB_VERT);
817 818
	INT   dy;
	
Alexandre Julliard's avatar
Alexandre Julliard committed
819 820 821 822
	GetScrollRange(hWnd, SB_VERT, &Min, &Max);
	GetClientRect(hWnd, &rect);

	switch (wParam & 0xffff)
823 824 825 826 827 828 829 830 831 832 833
        {
        case SB_THUMBTRACK:
        case SB_THUMBPOSITION: CurPos  = wParam >> 16;                   break;
        case SB_TOP:           CurPos  = Min;                            break;
        case SB_BOTTOM:        CurPos  = Max;                            break;
        case SB_PAGEUP:        CurPos -= (rect.bottom - rect.top) / 2;   break;
        case SB_PAGEDOWN:      CurPos += (rect.bottom - rect.top) / 2;   break;
        case SB_LINEUP:        CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
        case SB_LINEDOWN:      CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
        default: update = FALSE;
        }
Alexandre Julliard's avatar
Alexandre Julliard committed
834
	if (update)
835
        {
836 837 838 839 840
	    if (CurPos > Max)
                CurPos = Max;
	    else if (CurPos < Min)
                CurPos = Min;		    
	    dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
Alexandre Julliard's avatar
Alexandre Julliard committed
841 842 843
	    SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
	    ScrollWindow(hWnd, 0, dy, NULL, NULL);
	    UpdateWindow(hWnd);
844 845 846
        }
    }
    break;
Alexandre Julliard's avatar
Alexandre Julliard committed
847 848

    case WM_PAINT:
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892
        hDc = BeginPaint(hWnd, &ps);
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        scroll_pos = GetScrollPos(hWnd, SB_VERT);

        for (line = win->first_line; line; line = line->next)
        {
            for (part = &line->first_part; part; part = part->next)
            {
                switch (part->cookie)
                {
                case hlp_line_part_text:
                    SelectObject(hDc, part->u.text.hFont);
                    SetTextColor(hDc, part->u.text.color);
                    TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
                            part->u.text.lpsText, part->u.text.wTextLen);
                    if (part->u.text.wUnderline)
                    {
                        HPEN    hPen;

                        switch (part->u.text.wUnderline)
                        {
                        case 1: /* simple */
                        case 2: /* double */
                            hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
                            break;
                        case 3: /* dotted */
                            hPen = CreatePen(PS_DOT, 1, part->u.text.color);
                            break;
                        default:
                            WINE_FIXME("Unknow underline type\n");
                            continue;
                        }

                        SelectObject(hDc, hPen);
                        MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
                        LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
                        if (part->u.text.wUnderline == 2)
                        {
                            MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
                            LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
                        }
                        DeleteObject(hPen);
                    }
                    break;
893
                case hlp_line_part_bitmap:
894 895 896 897
                    {
                        HDC hMemDC;

                        hMemDC = CreateCompatibleDC(hDc);
898
                        SelectObject(hMemDC, part->u.bitmap.hBitmap);
899 900 901 902 903 904
                        BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
                               part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
                               hMemDC, 0, 0, SRCCOPY);
                        DeleteDC(hMemDC);
                    }
                    break;
905 906 907 908 909 910 911 912 913
                case hlp_line_part_metafile:
                    {
                        POINT   pt;

                        SetViewportOrgEx(hDc, part->rect.left, part->rect.top - scroll_pos, &pt);
                        PlayMetaFile(hDc, part->u.metafile.hMetaFile);
                        SetViewportOrgEx(hDc, pt.x, pt.y, NULL);
                    }
                    break;
914 915 916 917 918 919
                }
            }
        }

        EndPaint(hWnd, &ps);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
920

921
    case WM_MOUSEMOVE:
922
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
923

924
        if (WINHELP_IsOverLink(win, wParam, lParam))
925 926 927
            SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
        else
            SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
928

929
        break;
930

Alexandre Julliard's avatar
Alexandre Julliard committed
931
    case WM_LBUTTONDOWN:
932
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
933

934 935
        hPopupWnd = Globals.hPopupWnd;
        Globals.hPopupWnd = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
936

937
        part = WINHELP_IsOverLink(win, wParam, lParam);
938 939
        if (part)
        {
940 941 942
            HLPFILE*            hlpfile;
            HLPFILE_WINDOWINFO* wi;

943 944
            mouse.x = LOWORD(lParam);
            mouse.y = HIWORD(lParam);
945

946
            if (part->link) switch (part->link->cookie)
947 948
            {
            case hlp_link_link:
949 950
                hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
                if (part->link->window == -1)
951
                    wi = win->info;
952 953
                else if (part->link->window < hlpfile->numWindows)
                    wi = &hlpfile->windows[part->link->window];
954 955
                else
                {
956
                    WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
957 958
                    break;
                }
959
                WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
960
                                               SW_NORMAL);
961 962
                break;
            case hlp_link_popup:
963 964
                hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
                WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, 
965 966
                                               WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
                                               SW_NORMAL);
967 968
                break;
            case hlp_link_macro:
969
                MACRO_ExecuteMacro(part->link->lpszString);
970 971
                break;
            default:
972
                WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
973
            }
974
        }
975

976 977 978
        if (hPopupWnd)
            DestroyWindow(hPopupWnd);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
979 980

    case WM_NCDESTROY:
981
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
Alexandre Julliard's avatar
Alexandre Julliard committed
982

983
        if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
984

985
        bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
Alexandre Julliard's avatar
Alexandre Julliard committed
986

987
        WINHELP_DeleteWindow(win);
Alexandre Julliard's avatar
Alexandre Julliard committed
988

989
        if (bExit) MACRO_Exit();
Alexandre Julliard's avatar
Alexandre Julliard committed
990

991 992 993
        if (!Globals.win_list)
            PostQuitMessage(0);
        break;
Alexandre Julliard's avatar
Alexandre Julliard committed
994 995
    }

996
    return DefWindowProc(hWnd, msg, wParam, lParam);
Alexandre Julliard's avatar
Alexandre Julliard committed
997 998
}

999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
/******************************************************************
 *		WINHELP_HistoryWndProc
 *
 *
 */
static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    WINHELP_WINDOW*     win;
    PAINTSTRUCT         ps;
    HDC                 hDc;
    TEXTMETRIC          tm;
    int                 i;
    RECT                r;

    switch (msg)
    {
    case WM_NCCREATE:
        win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
        SetWindowLong(hWnd, 0, (LONG)win);
        win->hHistoryWnd = hWnd;
        break;
    case WM_CREATE:
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        hDc = GetDC(hWnd);
        GetTextMetrics(hDc, &tm);
        GetWindowRect(hWnd, &r);

        r.right = r.left + 30 * tm.tmAveCharWidth;
        r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
        AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
        if (r.left < 0) {r.right -= r.left; r.left = 0;}
        if (r.top < 0) {r.bottom -= r.top; r.top = 0;}

        MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
        ReleaseDC(hWnd, hDc);
        break;
    case WM_LBUTTONDOWN:
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        hDc = GetDC(hWnd);
        GetTextMetrics(hDc, &tm);
        i = HIWORD(lParam) / tm.tmHeight;
        if (i < win->histIndex)
            WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
        ReleaseDC(hWnd, hDc);
        break;
    case WM_PAINT:
        hDc = BeginPaint(hWnd, &ps);
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        GetTextMetrics(hDc, &tm);

        for (i = 0; i < win->histIndex; i++)
        {
            TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle, 
                    strlen(win->history[i]->lpszTitle));
        }
        EndPaint(hWnd, &ps);
        break;
    case WM_DESTROY:
        win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
        if (hWnd == win->hHistoryWnd)
            win->hHistoryWnd = 0;
        break;
    }
    return DefWindowProc(hWnd, msg, wParam, lParam);
}

Alexandre Julliard's avatar
Alexandre Julliard committed
1065 1066 1067 1068
/***********************************************************************
 *
 *           SetupText
 */
1069
static void WINHELP_SetupText(HWND hWnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
1070
{
1071 1072 1073
    HDC  hDc = GetDC(hWnd);
    RECT rect;
    SIZE newsize;
Alexandre Julliard's avatar
Alexandre Julliard committed
1074

1075 1076
    ShowScrollBar(hWnd, SB_VERT, FALSE);
    if (!WINHELP_SplitLines(hWnd, NULL))
Alexandre Julliard's avatar
Alexandre Julliard committed
1077
    {
1078 1079
        ShowScrollBar(hWnd, SB_VERT, TRUE);
        GetClientRect(hWnd, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
1080

1081 1082
        WINHELP_SplitLines(hWnd, &newsize);
        SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1083
    }
1084
    else SetScrollPos(hWnd, SB_VERT, 0, FALSE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1085

1086
    ReleaseDC(hWnd, hDc);
Alexandre Julliard's avatar
Alexandre Julliard committed
1087 1088 1089 1090
}

/***********************************************************************
 *
1091
 *           WINHELP_AppendText
Alexandre Julliard's avatar
Alexandre Julliard committed
1092
 */
1093 1094 1095 1096 1097 1098
static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
			       LPSIZE space, LPSIZE textsize,
			       INT *line_ascent, INT ascent,
			       LPCSTR text, UINT textlen,
			       HFONT font, COLORREF color, HLPFILE_LINK *link,
                               unsigned underline)
Alexandre Julliard's avatar
Alexandre Julliard committed
1099
{
1100 1101 1102
    WINHELP_LINE      *line;
    WINHELP_LINE_PART *part;
    LPSTR ptr;
Alexandre Julliard's avatar
Alexandre Julliard committed
1103

1104
    if (!*partp) /* New line */
Alexandre Julliard's avatar
Alexandre Julliard committed
1105
    {
1106
        *line_ascent  = ascent;
Alexandre Julliard's avatar
Alexandre Julliard committed
1107

1108
        line = HeapAlloc(GetProcessHeap(), 0,
1109
                         sizeof(WINHELP_LINE) + textlen);
1110
        if (!line) return FALSE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1111

1112 1113 1114
        line->next    = 0;
        part          = &line->first_part;
        ptr           = (char*)line + sizeof(WINHELP_LINE);
Alexandre Julliard's avatar
Alexandre Julliard committed
1115

1116 1117 1118 1119
        line->rect.top    = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
        line->rect.bottom = line->rect.top;
        line->rect.left   = space->cx;
        line->rect.right  = space->cx;
Alexandre Julliard's avatar
Alexandre Julliard committed
1120

1121 1122 1123 1124 1125 1126 1127
        if (**linep) *linep = &(**linep)->next;
        **linep = line;
        space->cy = 0;
    }
    else /* Same line */
    {
        line = **linep;
Alexandre Julliard's avatar
Alexandre Julliard committed
1128

1129
        if (*line_ascent < ascent)
Alexandre Julliard's avatar
Alexandre Julliard committed
1130
	{
1131 1132 1133 1134 1135 1136 1137 1138
            WINHELP_LINE_PART *p;
            for (p = &line->first_part; p; p = p->next)
	    {
                p->rect.top    += ascent - *line_ascent;
                p->rect.bottom += ascent - *line_ascent;
	    }
            line->rect.bottom += ascent - *line_ascent;
            *line_ascent = ascent;
Alexandre Julliard's avatar
Alexandre Julliard committed
1139 1140
	}

1141
        part = HeapAlloc(GetProcessHeap(), 0,
1142
                         sizeof(WINHELP_LINE_PART) + textlen);
1143 1144 1145 1146
        if (!part) return FALSE;
        **partp = part;
        ptr     = (char*)part + sizeof(WINHELP_LINE_PART);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1147

1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
    memcpy(ptr, text, textlen);
    part->cookie            = hlp_line_part_text;
    part->rect.left         = line->rect.right + (*partp ? space->cx : 0);
    part->rect.right        = part->rect.left + textsize->cx;
    line->rect.right        = part->rect.right;
    part->rect.top          =
        ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
    part->rect.bottom       = part->rect.top + textsize->cy;
    line->rect.bottom       = max(line->rect.bottom, part->rect.bottom);
    part->u.text.lpsText    = ptr;
    part->u.text.wTextLen   = textlen;
    part->u.text.hFont      = font;
    part->u.text.color      = color;
    part->u.text.wUnderline = underline;

1163
    WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1164 1165 1166 1167 1168
               part->u.text.wTextLen,
               part->u.text.wTextLen,
               part->u.text.lpsText,
               part->u.text.wTextLen,
               part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1169 1170 1171

    part->link = link;
    if (link) link->wRefCount++;
Alexandre Julliard's avatar
Alexandre Julliard committed
1172

1173 1174
    part->next          = 0;
    *partp              = &part->next;
Alexandre Julliard's avatar
Alexandre Julliard committed
1175

1176
    space->cx = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1177

1178 1179
    return TRUE;
}
Alexandre Julliard's avatar
Alexandre Julliard committed
1180

1181 1182
/***********************************************************************
 *
1183
 *           WINHELP_AppendGfxObject
1184
 */
1185 1186 1187
static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
                                                  LPSIZE space, LPSIZE gfxSize,
                                                  HLPFILE_LINK *link, unsigned pos)
1188 1189 1190 1191
{
    WINHELP_LINE      *line;
    WINHELP_LINE_PART *part;
    LPSTR              ptr;
Alexandre Julliard's avatar
Alexandre Julliard committed
1192

1193 1194
    if (!*partp || pos == 1) /* New line */
    {
1195 1196
        line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
        if (!line) return NULL;
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215

        line->next    = NULL;
        part          = &line->first_part;

        line->rect.top    = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
        line->rect.bottom = line->rect.top;
        line->rect.left   = space->cx;
        line->rect.right  = space->cx;

        if (**linep) *linep = &(**linep)->next;
        **linep = line;
        space->cy = 0;
        ptr = (char*)line + sizeof(WINHELP_LINE);
    }
    else /* Same line */
    {
        if (pos == 2) WINE_FIXME("Left alignment not handled\n");
        line = **linep;

1216 1217
        part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
        if (!part) return NULL;
1218 1219 1220
        **partp = part;
        ptr = (char*)part + sizeof(WINHELP_LINE_PART);
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1221

1222
    /* part->cookie should be set by caller (image or metafile) */
1223
    part->rect.left       = line->rect.right + (*partp ? space->cx : 0);
1224
    part->rect.right      = part->rect.left + gfxSize->cx;
1225
    line->rect.right      = part->rect.right;
1226 1227
    part->rect.top        = (*partp) ? line->rect.top : line->rect.bottom;
    part->rect.bottom     = part->rect.top + gfxSize->cy;
1228 1229
    line->rect.bottom     = max(line->rect.bottom, part->rect.bottom);

1230
    WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1231 1232
               part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);

1233 1234
    part->link = link;
    if (link) link->wRefCount++;
Alexandre Julliard's avatar
Alexandre Julliard committed
1235

1236 1237
    part->next            = NULL;
    *partp                = &part->next;
Alexandre Julliard's avatar
Alexandre Julliard committed
1238

1239 1240
    space->cx = 0;

1241
    return part;
Alexandre Julliard's avatar
Alexandre Julliard committed
1242 1243
}

1244

Alexandre Julliard's avatar
Alexandre Julliard committed
1245 1246
/***********************************************************************
 *
1247
 *           WINHELP_SplitLines
Alexandre Julliard's avatar
Alexandre Julliard committed
1248
 */
1249
static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
Alexandre Julliard's avatar
Alexandre Julliard committed
1250
{
1251 1252 1253 1254 1255 1256 1257 1258
    WINHELP_WINDOW     *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
    HLPFILE_PARAGRAPH  *p;
    WINHELP_LINE      **line = &win->first_line;
    WINHELP_LINE_PART **part = 0;
    INT                 line_ascent = 0;
    SIZE                space;
    RECT                rect;
    HDC                 hDc;
Alexandre Julliard's avatar
Alexandre Julliard committed
1259

1260
    if (newsize) newsize->cx = newsize->cy = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1261

1262
    if (!win->page) return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1263

1264 1265 1266
    WINHELP_DeleteLines(win);

    GetClientRect(hWnd, &rect);
Alexandre Julliard's avatar
Alexandre Julliard committed
1267

1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
    rect.top    += INTERNAL_BORDER_WIDTH;
    rect.left   += INTERNAL_BORDER_WIDTH;
    rect.right  -= INTERNAL_BORDER_WIDTH;
    rect.bottom -= INTERNAL_BORDER_WIDTH;

    space.cy = rect.top;
    space.cx = rect.left;

    hDc = GetDC(hWnd);

    for (p = win->page->first_paragraph; p; p = p->next)
Alexandre Julliard's avatar
Alexandre Julliard committed
1279
    {
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
        switch (p->cookie)
        {
        case para_normal_text:
        case para_debug_text:
            {
                TEXTMETRIC tm;
                SIZE textsize    = {0, 0};
                LPCSTR text      = p->u.text.lpszText;
                UINT indent      = 0;
                UINT len         = strlen(text);
                unsigned underline = 0;

                HFONT hFont = 0;
                COLORREF color = RGB(0, 0, 0);

                if (p->u.text.wFont < win->page->file->numFonts)
                {
                    HLPFILE*    hlpfile = win->page->file;

                    if (!hlpfile->fonts[p->u.text.wFont].hFont)
                        hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
                    hFont = hlpfile->fonts[p->u.text.wFont].hFont;
                    color = hlpfile->fonts[p->u.text.wFont].color;
                }
                else
                {
                    UINT  wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;

                    hFont = win->fonts[wFont];
                }

1311
                if (p->link && p->link->bClrChange)
1312
                {
1313
                    underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395
                    color = RGB(0, 0x80, 0);
                }
                if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);

                SelectObject(hDc, hFont);

                GetTextMetrics(hDc, &tm);

                if (p->u.text.wIndent)
                {
                    indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
                    if (!part)
                        space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
                }

                if (p->u.text.wVSpace)
                {
                    part = 0;
                    space.cx = rect.left + indent;
                    space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
                }

                if (p->u.text.wHSpace)
                {
                    space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
                }

                WINE_TRACE("splitting text %s\n", text);

                while (len)
                {
                    INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
                    UINT low = 0, curr = len, high = len, textlen = 0;

                    if (free_width > 0)
                    {
                        while (1)
                        {
                            GetTextExtentPoint(hDc, text, curr, &textsize);

                            if (textsize.cx <= free_width) low = curr;
                            else high = curr;

                            if (high <= low + 1) break;

                            if (textsize.cx) curr = (curr * free_width) / textsize.cx;
                            if (curr <= low) curr = low + 1;
                            else if (curr >= high) curr = high - 1;
                        }
                        textlen = low;
                        while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
                    }
                    if (!part && !textlen) textlen = max(low, 1);

                    if (free_width <= 0 || !textlen)
                    {
                        part = 0;
                        space.cx = rect.left + indent;
                        space.cx = min(space.cx, rect.right - rect.left - 1);
                        continue;
                    }

                    WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);

                    if (!WINHELP_AppendText(&line, &part, &space, &textsize,
                                            &line_ascent, tm.tmAscent,
                                            text, textlen, hFont, color, p->link, underline) ||
                        (!newsize && (*line)->rect.bottom > rect.bottom))
                    {
                        ReleaseDC(hWnd, hDc);
                        return FALSE;
                    }

                    if (newsize)
                        newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);

                    len -= textlen;
                    text += textlen;
                    if (text[0] == ' ') text++, len--;
                }
            }
            break;
1396 1397
        case para_bitmap:
        case para_metafile:
1398
            {
1399 1400 1401
                SIZE                    gfxSize;
                INT                     free_width;
                WINHELP_LINE_PART*      ref_part;
1402

1403
                if (p->u.gfx.pos & 0x8000)
1404 1405
                {
                    space.cx = rect.left;
1406 1407
                    if (*line)
                        space.cy += (*line)->rect.bottom - (*line)->rect.top;
1408 1409 1410
                    part = 0;
                }

1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
                if (p->cookie == para_bitmap)
                {
                    DIBSECTION              dibs;
                    
                    GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
                    gfxSize.cx = dibs.dsBm.bmWidth;
                    gfxSize.cy = dibs.dsBm.bmHeight;
                }
                else gfxSize = p->u.gfx.u.mf.mfSize;
                    
1421
                free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1422 1423 1424 1425 1426 1427
                if (free_width <= 0)
                {
                    part = NULL;
                    space.cx = rect.left;
                    space.cx = min(space.cx, rect.right - rect.left - 1);
                }
1428 1429 1430
                ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
                                                   p->link, p->u.gfx.pos);
                if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1431 1432 1433
                {
                    return FALSE;
                }
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
                if (p->cookie == para_bitmap)
                {
                    ref_part->cookie = hlp_line_part_bitmap;
                    ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
                }
                else
                {
                    ref_part->cookie = hlp_line_part_metafile;
                    ref_part->u.metafile.hMetaFile = p->u.gfx.u.mf.hMetaFile;
                }
1444 1445 1446 1447
            }
            break;
        }
    }
Alexandre Julliard's avatar
Alexandre Julliard committed
1448

1449 1450
    if (newsize)
        newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
Alexandre Julliard's avatar
Alexandre Julliard committed
1451

1452 1453
    ReleaseDC(hWnd, hDc);
    return TRUE;
Alexandre Julliard's avatar
Alexandre Julliard committed
1454 1455 1456 1457 1458 1459
}

/***********************************************************************
 *
 *           WINHELP_CheckPopup
 */
1460
static void WINHELP_CheckPopup(UINT msg)
Alexandre Julliard's avatar
Alexandre Julliard committed
1461
{
1462
    if (!Globals.hPopupWnd) return;
Alexandre Julliard's avatar
Alexandre Julliard committed
1463

1464
    switch (msg)
Alexandre Julliard's avatar
Alexandre Julliard committed
1465 1466 1467 1468 1469 1470 1471 1472
    {
    case WM_COMMAND:
    case WM_LBUTTONDOWN:
    case WM_MBUTTONDOWN:
    case WM_RBUTTONDOWN:
    case WM_NCLBUTTONDOWN:
    case WM_NCMBUTTONDOWN:
    case WM_NCRBUTTONDOWN:
1473 1474
        DestroyWindow(Globals.hPopupWnd);
        Globals.hPopupWnd = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1475 1476 1477 1478 1479 1480 1481
    }
}

/***********************************************************************
 *
 *           WINHELP_DeleteLines
 */
1482
static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
Alexandre Julliard's avatar
Alexandre Julliard committed
1483
{
1484 1485
    WINHELP_LINE      *line, *next_line;
    WINHELP_LINE_PART *part, *next_part;
1486
    for (line = win->first_line; line; line = next_line)
Alexandre Julliard's avatar
Alexandre Julliard committed
1487
    {
1488 1489
        next_line = line->next;
        for (part = &line->first_part; part; part = next_part)
Alexandre Julliard's avatar
Alexandre Julliard committed
1490
	{
1491
            next_part = part->next;
1492
            HLPFILE_FreeLink(part->link);
1493
            HeapFree(GetProcessHeap(), 0, part);
Alexandre Julliard's avatar
Alexandre Julliard committed
1494 1495
	}
    }
1496
    win->first_line = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1497 1498 1499 1500 1501 1502
}

/***********************************************************************
 *
 *           WINHELP_DeleteWindow
 */
1503
static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
Alexandre Julliard's avatar
Alexandre Julliard committed
1504
{
1505 1506 1507 1508
    WINHELP_WINDOW**    w;
    int                 i;
    WINHELP_BUTTON*     b;
    WINHELP_BUTTON*     bp;
1509 1510

    for (w = &Globals.win_list; *w; w = &(*w)->next)
1511
    {
1512 1513 1514 1515 1516
        if (*w == win)
        {
            *w = win->next;
            break;
        }
1517 1518 1519 1520 1521 1522 1523 1524
    }

    for (b = win->first_button; b; b = bp)
    {
        DestroyWindow(b->hWnd);
        bp = b->next;
        HeapFree(GetProcessHeap(), 0, b);
    }
1525 1526

    if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
    if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);

    for (i = 0; i < win->histIndex; i++)
    {
        HLPFILE_FreeHlpFile(win->history[i]->file);
    }

    for (i = 0; i < win->backIndex; i++)
        HLPFILE_FreeHlpFile(win->back[i]->file);

    if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1538 1539
    WINHELP_DeleteLines(win);
    HeapFree(GetProcessHeap(), 0, win);
Alexandre Julliard's avatar
Alexandre Julliard committed
1540 1541 1542 1543 1544 1545
}

/***********************************************************************
 *
 *           WINHELP_InitFonts
 */
1546
static void WINHELP_InitFonts(HWND hWnd)
Alexandre Julliard's avatar
Alexandre Julliard committed
1547
{
1548 1549 1550 1551 1552 1553 1554 1555 1556
    WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
    LOGFONT logfontlist[] = {
        {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
        {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
        {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
        {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
        {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
        {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
        { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
Alexandre Julliard's avatar
Alexandre Julliard committed
1557 1558
#define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))

1559 1560
    static HFONT fonts[FONTS_LEN];
    static BOOL init = 0;
Alexandre Julliard's avatar
Alexandre Julliard committed
1561

1562 1563
    win->fonts_len = FONTS_LEN;
    win->fonts = fonts;
Alexandre Julliard's avatar
Alexandre Julliard committed
1564

1565
    if (!init)
Alexandre Julliard's avatar
Alexandre Julliard committed
1566
    {
1567
        INT i;
Alexandre Julliard's avatar
Alexandre Julliard committed
1568

1569
        for (i = 0; i < FONTS_LEN; i++)
Alexandre Julliard's avatar
Alexandre Julliard committed
1570
	{
1571
            fonts[i] = CreateFontIndirect(&logfontlist[i]);
Alexandre Julliard's avatar
Alexandre Julliard committed
1572 1573
	}

1574
        init = 1;
Alexandre Julliard's avatar
Alexandre Julliard committed
1575 1576 1577 1578 1579 1580 1581 1582 1583
    }
}

/***********************************************************************
 *
 *           WINHELP_MessageBoxIDS
 */
INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
{
1584 1585
    CHAR text[MAX_STRING_LEN];
    CHAR title[MAX_STRING_LEN];
Alexandre Julliard's avatar
Alexandre Julliard committed
1586

1587 1588
    LoadString(Globals.hInstance, ids_text, text, sizeof(text));
    LoadString(Globals.hInstance, ids_title, title, sizeof(title));
Alexandre Julliard's avatar
Alexandre Julliard committed
1589

1590
    return MessageBox(0, text, title, type);
Alexandre Julliard's avatar
Alexandre Julliard committed
1591 1592 1593 1594 1595 1596 1597 1598
}

/***********************************************************************
 *
 *           MAIN_MessageBoxIDS_s
 */
INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
{
1599 1600 1601
    CHAR text[MAX_STRING_LEN];
    CHAR title[MAX_STRING_LEN];
    CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
Alexandre Julliard's avatar
Alexandre Julliard committed
1602

1603 1604 1605
    LoadString(Globals.hInstance, ids_text, text, sizeof(text));
    LoadString(Globals.hInstance, ids_title, title, sizeof(title));
    wsprintf(newtext, text, str);
Alexandre Julliard's avatar
Alexandre Julliard committed
1606

1607
    return MessageBox(0, newtext, title, type);
Alexandre Julliard's avatar
Alexandre Julliard committed
1608 1609
}

1610 1611 1612 1613 1614
/******************************************************************
 *		WINHELP_IsOverLink
 *
 *
 */
1615
WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1616
{
1617 1618 1619
    POINT mouse;
    WINHELP_LINE      *line;
    WINHELP_LINE_PART *part;
1620
    int scroll_pos = GetScrollPos(win->hMainWnd, SB_VERT);
1621 1622 1623 1624

    mouse.x = LOWORD(lParam);
    mouse.y = HIWORD(lParam);
    for (line = win->first_line; line; line = line->next)
1625
    {
1626 1627
        for (part = &line->first_part; part; part = part->next)
        {
1628 1629
            if (part->link && 
                part->link->lpszString &&
1630 1631 1632 1633 1634 1635 1636 1637
                part->rect.left   <= mouse.x &&
                part->rect.right  >= mouse.x &&
                part->rect.top    <= mouse.y + scroll_pos &&
                part->rect.bottom >= mouse.y + scroll_pos)
            {
                return part;
            }
        }
1638 1639
    }

1640
    return NULL;
1641
}