4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002 Eric Pouech <eric.pouech@wanadoo.fr>
7 * 2004 Ken Belleau <jamez@ivic.qc.ca>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "winhelp_res.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
42 static BOOL WINHELP_RegisterWinClasses(void);
43 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
44 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
45 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
47 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
48 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
49 static void WINHELP_CheckPopup(UINT);
50 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
51 static void WINHELP_InitFonts(HWND hWnd);
52 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
53 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
54 static void WINHELP_SetupText(HWND hWnd);
55 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
57 WINHELP_GLOBALS Globals = {3, NULL, NULL, 0, TRUE, NULL, NULL, NULL, NULL};
59 /***********************************************************************
61 * WINHELP_LookupHelpFile
63 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
67 hlpfile = HLPFILE_ReadHlpFile(lpszFile);
69 /* Add Suffix `.hlp' */
70 if (!hlpfile && lstrcmpi(lpszFile + strlen(lpszFile) - 4, ".hlp") != 0)
72 char szFile_hlp[MAX_PATHNAME_LEN];
74 lstrcpyn(szFile_hlp, lpszFile, sizeof(szFile_hlp) - 4);
75 szFile_hlp[sizeof(szFile_hlp) - 5] = '\0';
76 lstrcat(szFile_hlp, ".hlp");
78 hlpfile = HLPFILE_ReadHlpFile(szFile_hlp);
82 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile, STID_WHERROR, MB_OK);
83 if (Globals.win_list) return NULL;
88 /******************************************************************
89 * WINHELP_GetWindowInfo
93 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
95 static HLPFILE_WINDOWINFO mwi;
98 if (!name || !name[0])
99 name = Globals.active_win->lpszName;
102 for (i = 0; i < hlpfile->numWindows; i++)
103 if (!strcmp(hlpfile->windows[i].name, name))
104 return &hlpfile->windows[i];
106 if (strcmp(name, "main") != 0)
108 WINE_FIXME("Couldn't find window info for %s\n", name);
114 strcpy(mwi.type, "primary");
115 strcpy(mwi.name, "main");
116 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
117 mwi.caption, sizeof(mwi.caption)))
118 strcpy(mwi.caption, hlpfile->lpszTitle);
119 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
121 mwi.win_style = WS_OVERLAPPEDWINDOW;
122 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
127 /******************************************************************
128 * HLPFILE_GetPopupWindowInfo
132 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
134 static HLPFILE_WINDOWINFO wi;
138 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
140 /* Calculate horizontal size and position of a popup window */
141 GetWindowRect(hParentWnd, &parent_rect);
142 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
143 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
146 ClientToScreen(hParentWnd, &wi.origin);
147 wi.origin.x -= wi.size.cx / 2;
148 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
149 wi.origin.x = max(wi.origin.x, 0);
152 wi.win_style = WS_POPUPWINDOW;
153 wi.sr_color = wi.sr_color = 0xFFFFFF;
158 /***********************************************************************
162 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
167 static CHAR default_wndname[] = "main";
168 LPSTR wndname = default_wndname;
171 Globals.hInstance = hInstance;
174 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
178 if (*cmdline++ == ' ') continue;
181 if (option) cmdline++;
182 while (*cmdline && *cmdline == ' ') cmdline++;
188 while (*cmdline && *cmdline != ' ') cmdline++;
189 if (*cmdline) *cmdline++ = '\0';
190 lHash = HLPFILE_Hash(topic_id);
195 Globals.wVersion = option - '0';
200 Globals.isBook = FALSE;
204 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
209 /* Create primary window */
210 if (!WINHELP_RegisterWinClasses())
212 WINE_FIXME("Couldn't register classes\n");
219 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
224 if ((ptr = strchr(cmdline, '>')))
229 hlpfile = WINHELP_LookupHelpFile(cmdline);
230 if (!hlpfile) return 0;
233 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
234 WINHELP_GetWindowInfo(hlpfile, wndname), show);
237 while (GetMessage(&msg, 0, 0, 0))
239 TranslateMessage(&msg);
240 DispatchMessage(&msg);
242 for (dll = Globals.dlls; dll; dll = dll->next)
244 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
249 /***********************************************************************
253 static BOOL WINHELP_RegisterWinClasses(void)
255 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
257 class_main.style = CS_HREDRAW | CS_VREDRAW;
258 class_main.lpfnWndProc = WINHELP_MainWndProc;
259 class_main.cbClsExtra = 0;
260 class_main.cbWndExtra = sizeof(LONG);
261 class_main.hInstance = Globals.hInstance;
262 class_main.hIcon = LoadIcon(0, IDI_APPLICATION);
263 class_main.hCursor = LoadCursor(0, IDC_ARROW);
264 class_main.hbrBackground = GetStockObject(WHITE_BRUSH);
265 class_main.lpszMenuName = 0;
266 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
268 class_button_box = class_main;
269 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
270 class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
271 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
273 class_text = class_main;
274 class_text.lpfnWndProc = WINHELP_TextWndProc;
275 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
277 class_shadow = class_main;
278 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
279 class_shadow.hbrBackground = GetStockObject(GRAY_BRUSH);
280 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
282 class_history = class_main;
283 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
284 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
286 return (RegisterClass(&class_main) &&
287 RegisterClass(&class_button_box) &&
288 RegisterClass(&class_text) &&
289 RegisterClass(&class_shadow) &&
290 RegisterClass(&class_history));
301 } WINHELP,*LPWINHELP;
303 /******************************************************************
304 * WINHELP_HandleCommand
308 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
310 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
313 if (cds->dwData != 0xA1DE505)
315 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
319 wh = (WINHELP*)cds->lpData;
323 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
325 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
326 wh->size, wh->command, wh->data, ptr);
332 MACRO_JumpContext(ptr, "main", wh->data);
341 MACRO_JumpContents(ptr, "main");
344 case HELP_HELPONHELP:
347 /* case HELP_SETINDEX: */
348 case HELP_SETCONTENTS:
351 MACRO_SetContents(ptr, wh->data);
354 case HELP_CONTEXTPOPUP:
357 MACRO_PopupContext(ptr, wh->data);
360 /* case HELP_FORCEFILE:*/
361 /* case HELP_CONTEXTMENU: */
363 /* in fact, should be the topic dialog box */
366 MACRO_JumpHash(ptr, "main", 0);
369 /* case HELP_WM_HELP: */
370 /* case HELP_SETPOPUP_POS: */
372 /* case HELP_COMMAND: */
373 /* case HELP_PARTIALKEY: */
374 /* case HELP_MULTIKEY: */
375 /* case HELP_SETWINPOS: */
376 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
383 /******************************************************************
384 * WINHELP_ReuseWindow
388 static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
389 HLPFILE_PAGE* page, int nCmdShow)
393 win->hMainWnd = oldwin->hMainWnd;
394 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
395 win->hTextWnd = oldwin->hTextWnd;
396 win->hHistoryWnd = oldwin->hHistoryWnd;
397 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
399 SetWindowLong(win->hMainWnd, 0, (LONG)win);
400 SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
401 SetWindowLong(win->hTextWnd, 0, (LONG)win);
402 SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
404 WINHELP_InitFonts(win->hMainWnd);
407 SetWindowText(win->hMainWnd, page->file->lpszTitle);
409 WINHELP_SetupText(win->hTextWnd);
410 InvalidateRect(win->hTextWnd, NULL, TRUE);
411 SendMessage(win->hMainWnd, WM_USER, 0, 0);
412 ShowWindow(win->hMainWnd, nCmdShow);
413 UpdateWindow(win->hTextWnd);
415 if (!(win->info->win_style & WS_POPUP))
419 memcpy(win->history, oldwin->history, sizeof(win->history));
420 win->histIndex = oldwin->histIndex;
422 /* FIXME: when using back, we shouldn't update the history... */
426 for (i = 0; i < win->histIndex; i++)
427 if (win->history[i] == page) break;
429 /* if the new page is already in the history, do nothing */
430 if (i == win->histIndex)
432 num = sizeof(win->history) / sizeof(win->history[0]);
433 if (win->histIndex == num)
435 /* we're full, remove latest entry */
436 HLPFILE_FreeHlpFile(win->history[0]->file);
437 memmove(&win->history[0], &win->history[1],
438 (num - 1) * sizeof(win->history[0]));
441 win->history[win->histIndex++] = page;
442 page->file->wRefCount++;
443 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
447 memcpy(win->back, oldwin->back, sizeof(win->back));
448 win->backIndex = oldwin->backIndex;
452 num = sizeof(win->back) / sizeof(win->back[0]);
453 if (win->backIndex == num)
455 /* we're full, remove latest entry */
456 HLPFILE_FreeHlpFile(win->back[0]->file);
457 memmove(&win->back[0], &win->back[1],
458 (num - 1) * sizeof(win->back[0]));
461 win->back[win->backIndex++] = page;
462 page->file->wRefCount++;
466 win->backIndex = win->histIndex = 0;
468 oldwin->histIndex = oldwin->backIndex = 0;
469 WINHELP_DeleteWindow(oldwin);
473 /***********************************************************************
475 * WINHELP_CreateHelpWindow
477 BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
480 WINHELP_WINDOW *win, *oldwin;
485 bPrimary = !lstrcmpi(wi->name, "main");
486 bPopup = wi->win_style & WS_POPUP;
488 /* Initialize WINHELP_WINDOW struct */
489 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
490 sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
491 if (!win) return FALSE;
493 win->next = Globals.win_list;
494 Globals.win_list = win;
496 win->lpszName = (char*)win + sizeof(WINHELP_WINDOW);
497 lstrcpy((char*)win->lpszName, wi->name);
501 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
502 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
506 Globals.active_win = win;
508 /* Initialize default pushbuttons */
509 if (bPrimary && page)
511 CHAR buffer[MAX_STRING_LEN];
513 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
514 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
515 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
516 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
517 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
518 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
519 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
520 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
521 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
522 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
525 /* Initialize file specific pushbuttons */
526 if (!(wi->win_style & WS_POPUP) && page)
528 HLPFILE_MACRO *macro;
529 for (macro = page->file->first_macro; macro; macro = macro->next)
530 MACRO_ExecuteMacro(macro->lpszMacro);
532 for (macro = page->first_macro; macro; macro = macro->next)
533 MACRO_ExecuteMacro(macro->lpszMacro);
536 /* Reuse existing window */
539 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
541 if (!lstrcmpi(oldwin->lpszName, wi->name))
543 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
548 win->histIndex = win->backIndex = 1;
549 win->history[0] = win->back[0] = page;
550 page->file->wRefCount += 2;
551 strcpy(wi->caption, page->file->lpszTitle);
555 hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
557 bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
558 wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
559 NULL, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
560 Globals.hInstance, win);
562 ShowWindow(hWnd, nCmdShow);
568 /***********************************************************************
570 * WINHELP_CreateHelpWindowByHash
572 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
573 HLPFILE_WINDOWINFO* wi, int nCmdShow)
575 HLPFILE_PAGE* page = NULL;
578 page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
579 HLPFILE_Contents(hlpfile);
580 if (page) page->file->wRefCount++;
581 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
584 /***********************************************************************
586 * WINHELP_MainWndProc
588 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
591 WINHELP_BUTTON *button;
592 RECT rect, button_box_rect;
593 INT text_top, curPos, min, max, dy, keyDelta;
595 WINHELP_CheckPopup(msg);
600 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
601 SetWindowLong(hWnd, 0, (LONG) win);
602 win->hMainWnd = hWnd;
606 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
608 /* Create button box and text Window */
609 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
610 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
612 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
613 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
617 case WM_WINDOWPOSCHANGED:
618 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
619 GetClientRect(hWnd, &rect);
621 /* Update button box and text Window */
622 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
624 rect.right - rect.left,
625 rect.bottom - rect.top, 0);
627 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
628 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
630 SetWindowPos(win->hTextWnd, HWND_TOP,
632 rect.right - rect.left,
633 rect.bottom - text_top, 0);
638 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
642 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
643 case MNID_FILE_PRINT: MACRO_Print(); break;
644 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
645 case MNID_FILE_EXIT: MACRO_Exit(); break;
648 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
649 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
652 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
655 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
656 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
657 case MNID_HELP_ABOUT: MACRO_About(); break;
658 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
662 for (button = win->first_button; button; button = button->next)
663 if (wParam == button->wParam) break;
665 MACRO_ExecuteMacro(button->lpszMacro);
667 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
672 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
675 return WINHELP_HandleCommand((HWND)wParam, lParam);
684 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
686 keyDelta = -keyDelta;
690 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
691 curPos = GetScrollPos(win->hTextWnd, SB_VERT);
692 GetScrollRange(win->hTextWnd, SB_VERT, &min, &max);
696 GetClientRect(win->hTextWnd, &rect);
697 keyDelta = (rect.bottom - rect.top) / 2;
698 if (wParam == VK_PRIOR)
699 keyDelta = -keyDelta;
705 else if (curPos < min)
708 dy = GetScrollPos(win->hTextWnd, SB_VERT) - curPos;
709 SetScrollPos(win->hTextWnd, SB_VERT, curPos, TRUE);
710 ScrollWindow(win->hTextWnd, 0, dy, NULL, NULL);
711 UpdateWindow(win->hTextWnd);
720 return DefWindowProc(hWnd, msg, wParam, lParam);
723 /***********************************************************************
725 * WINHELP_ButtonBoxWndProc
727 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
731 WINHELP_BUTTON *button;
735 WINHELP_CheckPopup(msg);
740 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
741 SetWindowLong(hWnd, 0, (LONG) win);
742 win->hButtonBoxWnd = hWnd;
745 case WM_WINDOWPOSCHANGING:
746 winpos = (WINDOWPOS*) lParam;
747 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
752 for (button = win->first_button; button; button = button->next)
758 button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
759 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
761 hWnd, (HMENU) button->wParam,
762 Globals.hInstance, 0);
764 if (Globals.button_proc == NULL)
765 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
766 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
769 hDc = GetDC(button->hWnd);
770 GetTextExtentPoint(hDc, button->lpszName,
771 lstrlen(button->lpszName), &textsize);
772 ReleaseDC(button->hWnd, hDc);
774 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
775 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
780 for (button = win->first_button; button; button = button->next)
782 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
784 if (x + 2 * button_size.cx <= winpos->cx)
787 x = 0, y += button_size.cy;
789 winpos->cy = y + (x ? button_size.cy : 0);
793 SendMessage(GetParent(hWnd), msg, wParam, lParam);
804 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
809 return DefWindowProc(hWnd, msg, wParam, lParam);
812 /***********************************************************************
814 * WINHELP_ButtonWndProc
816 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
818 if (msg == WM_KEYDOWN)
827 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
831 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
834 /***********************************************************************
836 * WINHELP_TextWndProc
838 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
842 WINHELP_LINE_PART *part;
851 if (msg != WM_LBUTTONDOWN)
852 WINHELP_CheckPopup(msg);
857 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
858 SetWindowLong(hWnd, 0, (LONG) win);
859 win->hTextWnd = hWnd;
860 if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
861 WINHELP_InitFonts(hWnd);
865 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
867 /* Calculate vertical size and position of a popup window */
868 if (win->info->win_style & WS_POPUP)
871 RECT old_window_rect;
872 RECT old_client_rect;
873 SIZE old_window_size;
874 SIZE old_client_size;
875 SIZE new_client_size;
876 SIZE new_window_size;
878 GetWindowRect(hWnd, &old_window_rect);
879 origin.x = old_window_rect.left;
880 origin.y = old_window_rect.top;
881 old_window_size.cx = old_window_rect.right - old_window_rect.left;
882 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
884 GetClientRect(hWnd, &old_client_rect);
885 old_client_size.cx = old_client_rect.right - old_client_rect.left;
886 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
888 new_client_size = old_client_size;
889 WINHELP_SplitLines(hWnd, &new_client_size);
891 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
892 origin.y += POPUP_YDISTANCE;
894 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
896 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
897 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
900 CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
901 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
902 new_window_size.cx, new_window_size.cy,
903 0, 0, Globals.hInstance, 0);
905 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
906 new_window_size.cx, new_window_size.cy,
908 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
909 ShowWindow(win->hShadowWnd, SW_NORMAL);
910 SetActiveWindow(hWnd);
914 case WM_WINDOWPOSCHANGED:
915 winpos = (WINDOWPOS*) lParam;
917 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
923 UINT scrollLines = 3;
924 int curPos = GetScrollPos(hWnd, SB_VERT);
927 GetScrollRange(hWnd, SB_VERT, &min, &max);
929 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
930 if (wParam & (MK_SHIFT | MK_CONTROL))
931 return DefWindowProc(hWnd, msg, wParam, lParam);
932 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
933 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
936 curPos += wheelDelta;
939 else if (curPos < min)
942 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
943 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
944 ScrollWindow(hWnd, 0, dy, NULL, NULL);
955 INT CurPos = GetScrollPos(hWnd, SB_VERT);
958 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
959 GetClientRect(hWnd, &rect);
961 switch (wParam & 0xffff)
964 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
965 case SB_TOP: CurPos = Min; break;
966 case SB_BOTTOM: CurPos = Max; break;
967 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
968 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
969 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
970 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
971 default: update = FALSE;
977 else if (CurPos < Min)
979 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
980 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
981 ScrollWindow(hWnd, 0, dy, NULL, NULL);
988 hDc = BeginPaint(hWnd, &ps);
989 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
990 scroll_pos = GetScrollPos(hWnd, SB_VERT);
992 for (line = win->first_line; line; line = line->next)
994 for (part = &line->first_part; part; part = part->next)
996 switch (part->cookie)
998 case hlp_line_part_text:
999 SelectObject(hDc, part->u.text.hFont);
1000 SetTextColor(hDc, part->u.text.color);
1001 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
1002 part->u.text.lpsText, part->u.text.wTextLen);
1003 if (part->u.text.wUnderline)
1007 switch (part->u.text.wUnderline)
1009 case 1: /* simple */
1010 case 2: /* double */
1011 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
1013 case 3: /* dotted */
1014 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
1017 WINE_FIXME("Unknow underline type\n");
1021 SelectObject(hDc, hPen);
1022 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
1023 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
1024 if (part->u.text.wUnderline == 2)
1026 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
1027 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
1032 case hlp_line_part_bitmap:
1036 hMemDC = CreateCompatibleDC(hDc);
1037 SelectObject(hMemDC, part->u.bitmap.hBitmap);
1038 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1039 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
1040 hMemDC, 0, 0, SRCCOPY);
1044 case hlp_line_part_metafile:
1048 SetViewportOrgEx(hDc, part->rect.left, part->rect.top - scroll_pos, &pt);
1049 PlayMetaFile(hDc, part->u.metafile.hMetaFile);
1050 SetViewportOrgEx(hDc, pt.x, pt.y, NULL);
1057 EndPaint(hWnd, &ps);
1061 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1063 if (WINHELP_IsOverLink(win, wParam, lParam))
1064 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
1066 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
1070 case WM_LBUTTONDOWN:
1071 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1073 hPopupWnd = Globals.hPopupWnd;
1074 Globals.hPopupWnd = 0;
1076 part = WINHELP_IsOverLink(win, wParam, lParam);
1080 HLPFILE_WINDOWINFO* wi;
1082 mouse.x = LOWORD(lParam);
1083 mouse.y = HIWORD(lParam);
1085 if (part->link) switch (part->link->cookie)
1088 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1089 if (part->link->window == -1)
1091 else if ((part->link->window >= 0) && (part->link->window < hlpfile->numWindows))
1092 wi = &hlpfile->windows[part->link->window];
1095 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
1098 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
1101 case hlp_link_popup:
1102 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1103 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
1104 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
1107 case hlp_link_macro:
1108 MACRO_ExecuteMacro(part->link->lpszString);
1111 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1116 DestroyWindow(hPopupWnd);
1120 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1122 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
1124 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1126 WINHELP_DeleteWindow(win);
1128 if (bExit) MACRO_Exit();
1130 if (!Globals.win_list)
1135 return DefWindowProc(hWnd, msg, wParam, lParam);
1138 /******************************************************************
1139 * WINHELP_HistoryWndProc
1143 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1145 WINHELP_WINDOW* win;
1155 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1156 SetWindowLong(hWnd, 0, (LONG)win);
1157 win->hHistoryWnd = hWnd;
1160 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1162 GetTextMetrics(hDc, &tm);
1163 GetWindowRect(hWnd, &r);
1165 r.right = r.left + 30 * tm.tmAveCharWidth;
1166 r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
1167 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1168 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1169 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1171 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1172 ReleaseDC(hWnd, hDc);
1174 case WM_LBUTTONDOWN:
1175 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1177 GetTextMetrics(hDc, &tm);
1178 i = HIWORD(lParam) / tm.tmHeight;
1179 if (i < win->histIndex)
1180 WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
1181 ReleaseDC(hWnd, hDc);
1184 hDc = BeginPaint(hWnd, &ps);
1185 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1186 GetTextMetrics(hDc, &tm);
1188 for (i = 0; i < win->histIndex; i++)
1190 TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle,
1191 strlen(win->history[i]->lpszTitle));
1193 EndPaint(hWnd, &ps);
1196 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1197 if (hWnd == win->hHistoryWnd)
1198 win->hHistoryWnd = 0;
1201 return DefWindowProc(hWnd, msg, wParam, lParam);
1204 /***********************************************************************
1206 * WINHELP_ShadowWndProc
1208 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1210 WINHELP_CheckPopup(msg);
1211 return DefWindowProc(hWnd, msg, wParam, lParam);
1214 /***********************************************************************
1218 static void WINHELP_SetupText(HWND hWnd)
1220 HDC hDc = GetDC(hWnd);
1224 ShowScrollBar(hWnd, SB_VERT, FALSE);
1225 if (!WINHELP_SplitLines(hWnd, NULL))
1227 ShowScrollBar(hWnd, SB_VERT, TRUE);
1228 GetClientRect(hWnd, &rect);
1230 WINHELP_SplitLines(hWnd, &newsize);
1231 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1235 SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1236 SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
1239 ReleaseDC(hWnd, hDc);
1242 /***********************************************************************
1244 * WINHELP_AppendText
1246 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1247 LPSIZE space, LPSIZE textsize,
1248 INT *line_ascent, INT ascent,
1249 LPCSTR text, UINT textlen,
1250 HFONT font, COLORREF color, HLPFILE_LINK *link,
1254 WINHELP_LINE_PART *part;
1257 if (!*partp) /* New line */
1259 *line_ascent = ascent;
1261 line = HeapAlloc(GetProcessHeap(), 0,
1262 sizeof(WINHELP_LINE) + textlen);
1263 if (!line) return FALSE;
1266 part = &line->first_part;
1267 ptr = (char*)line + sizeof(WINHELP_LINE);
1269 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1270 line->rect.bottom = line->rect.top;
1271 line->rect.left = space->cx;
1272 line->rect.right = space->cx;
1274 if (**linep) *linep = &(**linep)->next;
1278 else /* Same line */
1282 if (*line_ascent < ascent)
1284 WINHELP_LINE_PART *p;
1285 for (p = &line->first_part; p; p = p->next)
1287 p->rect.top += ascent - *line_ascent;
1288 p->rect.bottom += ascent - *line_ascent;
1290 line->rect.bottom += ascent - *line_ascent;
1291 *line_ascent = ascent;
1294 part = HeapAlloc(GetProcessHeap(), 0,
1295 sizeof(WINHELP_LINE_PART) + textlen);
1296 if (!part) return FALSE;
1298 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1301 memcpy(ptr, text, textlen);
1302 part->cookie = hlp_line_part_text;
1303 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1304 part->rect.right = part->rect.left + textsize->cx;
1305 line->rect.right = part->rect.right;
1307 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1308 part->rect.bottom = part->rect.top + textsize->cy;
1309 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1310 part->u.text.lpsText = ptr;
1311 part->u.text.wTextLen = textlen;
1312 part->u.text.hFont = font;
1313 part->u.text.color = color;
1314 part->u.text.wUnderline = underline;
1316 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1317 part->u.text.wTextLen,
1318 part->u.text.wTextLen,
1319 part->u.text.lpsText,
1320 part->u.text.wTextLen,
1321 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1324 if (link) link->wRefCount++;
1327 *partp = &part->next;
1334 /***********************************************************************
1336 * WINHELP_AppendGfxObject
1338 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1339 LPSIZE space, LPSIZE gfxSize,
1340 HLPFILE_LINK *link, unsigned pos)
1343 WINHELP_LINE_PART *part;
1346 if (!*partp || pos == 1) /* New line */
1348 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1349 if (!line) return NULL;
1352 part = &line->first_part;
1354 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1355 line->rect.bottom = line->rect.top;
1356 line->rect.left = space->cx;
1357 line->rect.right = space->cx;
1359 if (**linep) *linep = &(**linep)->next;
1362 ptr = (char*)line + sizeof(WINHELP_LINE);
1364 else /* Same line */
1366 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1369 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1370 if (!part) return NULL;
1372 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1375 /* part->cookie should be set by caller (image or metafile) */
1376 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1377 part->rect.right = part->rect.left + gfxSize->cx;
1378 line->rect.right = part->rect.right;
1379 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1380 part->rect.bottom = part->rect.top + gfxSize->cy;
1381 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1383 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1384 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1387 if (link) link->wRefCount++;
1390 *partp = &part->next;
1398 /***********************************************************************
1400 * WINHELP_SplitLines
1402 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1404 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1405 HLPFILE_PARAGRAPH *p;
1406 WINHELP_LINE **line = &win->first_line;
1407 WINHELP_LINE_PART **part = 0;
1408 INT line_ascent = 0;
1413 if (newsize) newsize->cx = newsize->cy = 0;
1415 if (!win->page) return TRUE;
1417 WINHELP_DeleteLines(win);
1419 GetClientRect(hWnd, &rect);
1421 rect.top += INTERNAL_BORDER_WIDTH;
1422 rect.left += INTERNAL_BORDER_WIDTH;
1423 rect.right -= INTERNAL_BORDER_WIDTH;
1424 rect.bottom -= INTERNAL_BORDER_WIDTH;
1426 space.cy = rect.top;
1427 space.cx = rect.left;
1431 for (p = win->page->first_paragraph; p; p = p->next)
1435 case para_normal_text:
1436 case para_debug_text:
1439 SIZE textsize = {0, 0};
1440 LPCSTR text = p->u.text.lpszText;
1442 UINT len = strlen(text);
1443 unsigned underline = 0;
1446 COLORREF color = RGB(0, 0, 0);
1448 if (p->u.text.wFont < win->page->file->numFonts)
1450 HLPFILE* hlpfile = win->page->file;
1452 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1453 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1454 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1455 color = hlpfile->fonts[p->u.text.wFont].color;
1459 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1461 hFont = win->fonts[wFont];
1464 if (p->link && p->link->bClrChange)
1466 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1467 color = RGB(0, 0x80, 0);
1469 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1471 SelectObject(hDc, hFont);
1473 GetTextMetrics(hDc, &tm);
1475 if (p->u.text.wIndent)
1477 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1479 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1482 if (p->u.text.wVSpace)
1485 space.cx = rect.left + indent;
1486 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1489 if (p->u.text.wHSpace)
1491 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1494 WINE_TRACE("splitting text %s\n", text);
1498 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1499 UINT low = 0, curr = len, high = len, textlen = 0;
1505 GetTextExtentPoint(hDc, text, curr, &textsize);
1507 if (textsize.cx <= free_width) low = curr;
1510 if (high <= low + 1) break;
1512 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1513 if (curr <= low) curr = low + 1;
1514 else if (curr >= high) curr = high - 1;
1517 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1519 if (!part && !textlen) textlen = max(low, 1);
1521 if (free_width <= 0 || !textlen)
1524 space.cx = rect.left + indent;
1525 space.cx = min(space.cx, rect.right - rect.left - 1);
1529 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1531 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1532 &line_ascent, tm.tmAscent,
1533 text, textlen, hFont, color, p->link, underline) ||
1534 (!newsize && (*line)->rect.bottom > rect.bottom))
1536 ReleaseDC(hWnd, hDc);
1541 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1545 if (text[0] == ' ') text++, len--;
1554 WINHELP_LINE_PART* ref_part;
1556 if (p->u.gfx.pos & 0x8000)
1558 space.cx = rect.left;
1560 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1564 if (p->cookie == para_bitmap)
1568 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1569 gfxSize.cx = dibs.dsBm.bmWidth;
1570 gfxSize.cy = dibs.dsBm.bmHeight;
1572 else gfxSize = p->u.gfx.u.mf.mfSize;
1574 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1575 if (free_width <= 0)
1578 space.cx = rect.left;
1579 space.cx = min(space.cx, rect.right - rect.left - 1);
1581 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1582 p->link, p->u.gfx.pos);
1583 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1587 if (p->cookie == para_bitmap)
1589 ref_part->cookie = hlp_line_part_bitmap;
1590 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1594 ref_part->cookie = hlp_line_part_metafile;
1595 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mf.hMetaFile;
1603 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1605 ReleaseDC(hWnd, hDc);
1609 /***********************************************************************
1611 * WINHELP_CheckPopup
1613 static void WINHELP_CheckPopup(UINT msg)
1615 if (!Globals.hPopupWnd) return;
1620 case WM_LBUTTONDOWN:
1621 case WM_MBUTTONDOWN:
1622 case WM_RBUTTONDOWN:
1623 case WM_NCLBUTTONDOWN:
1624 case WM_NCMBUTTONDOWN:
1625 case WM_NCRBUTTONDOWN:
1626 DestroyWindow(Globals.hPopupWnd);
1627 Globals.hPopupWnd = 0;
1631 /***********************************************************************
1633 * WINHELP_DeleteLines
1635 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1637 WINHELP_LINE *line, *next_line;
1638 WINHELP_LINE_PART *part, *next_part;
1639 for (line = win->first_line; line; line = next_line)
1641 next_line = line->next;
1642 for (part = &line->first_part; part; part = next_part)
1644 next_part = part->next;
1645 HLPFILE_FreeLink(part->link);
1646 HeapFree(GetProcessHeap(), 0, part);
1649 win->first_line = 0;
1652 /***********************************************************************
1654 * WINHELP_DeleteWindow
1656 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1663 for (w = &Globals.win_list; *w; w = &(*w)->next)
1672 for (b = win->first_button; b; b = bp)
1674 DestroyWindow(b->hWnd);
1676 HeapFree(GetProcessHeap(), 0, b);
1679 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1680 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1682 for (i = 0; i < win->histIndex; i++)
1684 HLPFILE_FreeHlpFile(win->history[i]->file);
1687 for (i = 0; i < win->backIndex; i++)
1688 HLPFILE_FreeHlpFile(win->back[i]->file);
1690 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1691 WINHELP_DeleteLines(win);
1692 HeapFree(GetProcessHeap(), 0, win);
1695 /***********************************************************************
1699 static void WINHELP_InitFonts(HWND hWnd)
1701 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1702 LOGFONT logfontlist[] = {
1703 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1704 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1705 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1706 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1707 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1708 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1709 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1710 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1712 static HFONT fonts[FONTS_LEN];
1713 static BOOL init = 0;
1715 win->fonts_len = FONTS_LEN;
1722 for (i = 0; i < FONTS_LEN; i++)
1724 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1731 /***********************************************************************
1733 * WINHELP_MessageBoxIDS
1735 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1737 CHAR text[MAX_STRING_LEN];
1738 CHAR title[MAX_STRING_LEN];
1740 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1741 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1743 return MessageBox(0, text, title, type);
1746 /***********************************************************************
1748 * MAIN_MessageBoxIDS_s
1750 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1752 CHAR text[MAX_STRING_LEN];
1753 CHAR title[MAX_STRING_LEN];
1754 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
1756 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1757 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1758 wsprintf(newtext, text, str);
1760 return MessageBox(0, newtext, title, type);
1763 /******************************************************************
1764 * WINHELP_IsOverLink
1768 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1772 WINHELP_LINE_PART *part;
1773 int scroll_pos = GetScrollPos(win->hTextWnd, SB_VERT);
1775 mouse.x = LOWORD(lParam);
1776 mouse.y = HIWORD(lParam);
1777 for (line = win->first_line; line; line = line->next)
1779 for (part = &line->first_part; part; part = part->next)
1782 part->link->lpszString &&
1783 part->rect.left <= mouse.x &&
1784 part->rect.right >= mouse.x &&
1785 part->rect.top <= mouse.y + scroll_pos &&
1786 part->rect.bottom >= mouse.y + scroll_pos)