4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002, 2008 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
36 #include "winhelp_res.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
44 static BOOL WINHELP_RegisterWinClasses(void);
45 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
47 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
48 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
49 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
50 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
51 static void WINHELP_CheckPopup(UINT);
52 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
53 static void WINHELP_InitFonts(HWND hWnd);
54 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
55 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
56 static void WINHELP_DeleteButtons(WINHELP_WINDOW*);
57 static void WINHELP_SetupText(HWND hWnd, WINHELP_WINDOW *win, ULONG relative);
58 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
60 WINHELP_GLOBALS Globals = {3, NULL, TRUE, NULL, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}};
62 static BOOL use_richedit;
64 #define CTL_ID_BUTTON 0x700
65 #define CTL_ID_TEXT 0x701
67 /***********************************************************************
69 * WINHELP_GetOpenFileName
71 BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len)
73 OPENFILENAME openfilename;
75 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
80 LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
84 LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
90 GetCurrentDirectory(sizeof(szDir), szDir);
94 openfilename.lStructSize = sizeof(OPENFILENAME);
95 openfilename.hwndOwner = NULL;
96 openfilename.hInstance = Globals.hInstance;
97 openfilename.lpstrFilter = szzFilter;
98 openfilename.lpstrCustomFilter = 0;
99 openfilename.nMaxCustFilter = 0;
100 openfilename.nFilterIndex = 1;
101 openfilename.lpstrFile = lpszFile;
102 openfilename.nMaxFile = len;
103 openfilename.lpstrFileTitle = 0;
104 openfilename.nMaxFileTitle = 0;
105 openfilename.lpstrInitialDir = szDir;
106 openfilename.lpstrTitle = 0;
107 openfilename.Flags = 0;
108 openfilename.nFileOffset = 0;
109 openfilename.nFileExtension = 0;
110 openfilename.lpstrDefExt = 0;
111 openfilename.lCustData = 0;
112 openfilename.lpfnHook = 0;
113 openfilename.lpTemplateName = 0;
115 return GetOpenFileName(&openfilename);
118 static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage)
120 if (wpage->wininfo->caption[0]) return wpage->wininfo->caption;
121 return wpage->page->file->lpszTitle;
124 /***********************************************************************
126 * WINHELP_LookupHelpFile
128 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
131 char szFullName[MAX_PATH];
132 char szAddPath[MAX_PATH];
136 * NOTE: This is needed by popup windows only.
137 * In other cases it's not needed but does not hurt though.
139 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
141 strcpy(szAddPath, Globals.active_win->page->file->lpszPath);
142 p = strrchr(szAddPath, '\\');
147 * FIXME: Should we swap conditions?
149 if (!SearchPath(NULL, lpszFile, ".hlp", MAX_PATH, szFullName, NULL) &&
150 !SearchPath(szAddPath, lpszFile, ".hlp", MAX_PATH, szFullName, NULL))
152 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s, lpszFile, STID_WHERROR,
153 MB_YESNO|MB_ICONQUESTION) != IDYES)
155 if (!WINHELP_GetOpenFileName(szFullName, MAX_PATH))
158 hlpfile = HLPFILE_ReadHlpFile(szFullName);
160 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile,
161 STID_WHERROR, MB_OK|MB_ICONSTOP);
165 /******************************************************************
166 * WINHELP_GetWindowInfo
170 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
172 static HLPFILE_WINDOWINFO mwi;
175 if (!name || !name[0])
176 name = Globals.active_win->lpszName;
179 for (i = 0; i < hlpfile->numWindows; i++)
180 if (!strcmp(hlpfile->windows[i].name, name))
181 return &hlpfile->windows[i];
183 if (strcmp(name, "main") != 0)
185 WINE_FIXME("Couldn't find window info for %s\n", name);
191 strcpy(mwi.type, "primary");
192 strcpy(mwi.name, "main");
193 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
194 mwi.caption, sizeof(mwi.caption)))
195 strcpy(mwi.caption, hlpfile->lpszTitle);
196 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
198 mwi.win_style = WS_OVERLAPPEDWINDOW;
199 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
204 /******************************************************************
205 * HLPFILE_GetPopupWindowInfo
209 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile,
210 WINHELP_WINDOW* parent, POINT* mouse)
212 static HLPFILE_WINDOWINFO wi;
216 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
218 /* Calculate horizontal size and position of a popup window */
219 GetWindowRect(parent->hMainWnd, &parent_rect);
220 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
221 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
224 ClientToScreen(parent->hMainWnd, &wi.origin);
225 wi.origin.x -= wi.size.cx / 2;
226 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
227 wi.origin.x = max(wi.origin.x, 0);
230 wi.win_style = WS_POPUP | WS_BORDER;
231 wi.sr_color = parent->info->sr_color;
232 wi.nsr_color = 0xFFFFFF;
237 /***********************************************************************
241 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
246 static CHAR default_wndname[] = "main";
247 LPSTR wndname = default_wndname;
250 Globals.hInstance = hInstance;
252 use_richedit = getenv("WINHELP_RICHEDIT") != NULL;
253 if (use_richedit && LoadLibrary("riched20.dll") == NULL)
254 return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT),
255 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
258 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
262 if (*cmdline++ == ' ') continue;
265 if (option) cmdline++;
266 while (*cmdline && *cmdline == ' ') cmdline++;
272 while (*cmdline && *cmdline != ' ') cmdline++;
273 if (*cmdline) *cmdline++ = '\0';
274 lHash = HLPFILE_Hash(topic_id);
279 Globals.wVersion = option - '0';
284 Globals.isBook = FALSE;
288 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
293 /* Create primary window */
294 if (!WINHELP_RegisterWinClasses())
296 WINE_FIXME("Couldn't register classes\n");
303 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
308 if ((ptr = strchr(cmdline, '>')))
313 hlpfile = WINHELP_LookupHelpFile(cmdline);
314 if (!hlpfile) return 0;
317 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
318 WINHELP_GetWindowInfo(hlpfile, wndname), show);
321 while (GetMessage(&msg, 0, 0, 0))
323 TranslateMessage(&msg);
324 DispatchMessage(&msg);
326 for (dll = Globals.dlls; dll; dll = dll->next)
328 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
333 /***********************************************************************
337 static BOOL WINHELP_RegisterWinClasses(void)
339 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
341 class_main.style = CS_HREDRAW | CS_VREDRAW;
342 class_main.lpfnWndProc = WINHELP_MainWndProc;
343 class_main.cbClsExtra = 0;
344 class_main.cbWndExtra = sizeof(LONG);
345 class_main.hInstance = Globals.hInstance;
346 class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
347 class_main.hCursor = LoadCursor(0, IDC_ARROW);
348 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
349 class_main.lpszMenuName = 0;
350 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
352 class_button_box = class_main;
353 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
354 class_button_box.cbWndExtra = 0;
355 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
356 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
358 class_text = class_main;
359 class_text.lpfnWndProc = WINHELP_TextWndProc;
360 class_text.hbrBackground = 0;
361 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
363 class_shadow = class_main;
364 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
365 class_shadow.cbWndExtra = 0;
366 class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
367 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
369 class_history = class_main;
370 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
371 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
373 return (RegisterClass(&class_main) &&
374 RegisterClass(&class_button_box) &&
375 RegisterClass(&class_text) &&
376 RegisterClass(&class_shadow) &&
377 RegisterClass(&class_history));
388 } WINHELP,*LPWINHELP;
390 /******************************************************************
391 * WINHELP_HandleCommand
395 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
397 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
400 if (cds->dwData != 0xA1DE505)
402 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
406 wh = (WINHELP*)cds->lpData;
410 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
412 WINE_TRACE("Got[%u]: cmd=%u data=%08x fn=%s\n",
413 wh->size, wh->command, wh->data, ptr);
419 MACRO_JumpContext(ptr, "main", wh->data);
428 MACRO_JumpContents(ptr, "main");
431 case HELP_HELPONHELP:
434 /* case HELP_SETINDEX: */
435 case HELP_SETCONTENTS:
438 MACRO_SetContents(ptr, wh->data);
441 case HELP_CONTEXTPOPUP:
444 MACRO_PopupContext(ptr, wh->data);
447 /* case HELP_FORCEFILE:*/
448 /* case HELP_CONTEXTMENU: */
450 /* in fact, should be the topic dialog box */
451 WINE_FIXME("HELP_FINDER: stub\n");
454 MACRO_JumpHash(ptr, "main", 0);
457 /* case HELP_WM_HELP: */
458 /* case HELP_SETPOPUP_POS: */
460 /* case HELP_COMMAND: */
461 /* case HELP_PARTIALKEY: */
462 /* case HELP_MULTIKEY: */
463 /* case HELP_SETWINPOS: */
465 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
469 /* Always return success for now */
473 void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
475 RECT rect, button_box_rect;
477 HWND hButtonBoxWnd = GetDlgItem(win->hMainWnd, CTL_ID_BUTTON);
478 HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
480 GetClientRect(win->hMainWnd, &rect);
482 /* Update button box and text Window */
483 SetWindowPos(hButtonBoxWnd, HWND_TOP,
485 rect.right - rect.left,
486 rect.bottom - rect.top, 0);
488 if (GetWindowRect(hButtonBoxWnd, &button_box_rect))
489 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
491 SetWindowPos(hTextWnd, HWND_TOP,
493 rect.right - rect.left,
494 rect.bottom - text_top, 0);
498 static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage)
502 if (!Globals.history.index || Globals.history.set[0].page != wpage->page)
504 num = sizeof(Globals.history.set) / sizeof(Globals.history.set[0]);
505 /* we're full, remove latest entry */
506 if (Globals.history.index == num)
508 HLPFILE_FreeHlpFile(Globals.history.set[num - 1].page->file);
509 Globals.history.index--;
511 memmove(&Globals.history.set[1], &Globals.history.set[0],
512 Globals.history.index * sizeof(Globals.history.set[0]));
513 Globals.history.set[0] = *wpage;
514 Globals.history.index++;
515 wpage->page->file->wRefCount++;
517 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
519 num = sizeof(win->back.set) / sizeof(win->back.set[0]);
520 if (win->back.index == num)
522 /* we're full, remove latest entry */
523 HLPFILE_FreeHlpFile(win->back.set[0].page->file);
524 memmove(&win->back.set[0], &win->back.set[1],
525 (num - 1) * sizeof(win->back.set[0]));
528 win->back.set[win->back.index++] = *wpage;
529 wpage->page->file->wRefCount++;
532 /***********************************************************************
534 * WINHELP_CreateHelpWindow
536 BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remember)
538 WINHELP_WINDOW* win = NULL;
539 BOOL bPrimary, bPopup, bReUsed = FALSE;
542 HWND hTextWnd = NULL;
544 bPrimary = !lstrcmpi(wpage->wininfo->name, "main");
545 bPopup = !bPrimary && (wpage->wininfo->win_style & WS_POPUP);
547 if (wpage->page && !wpage->page->first_paragraph) HLPFILE_BrowsePage(wpage->page, NULL);
551 for (win = Globals.win_list; win; win = win->next)
553 if (!lstrcmpi(win->lpszName, wpage->wininfo->name))
557 DWORD flags = SWP_NOSIZE | SWP_NOMOVE;
559 WINHELP_DeleteButtons(win);
561 SetWindowText(win->hMainWnd, WINHELP_GetCaption(wpage));
562 if (wpage->wininfo->origin.x != CW_USEDEFAULT &&
563 wpage->wininfo->origin.y != CW_USEDEFAULT)
565 pt = wpage->wininfo->origin;
566 flags &= ~SWP_NOSIZE;
568 if (wpage->wininfo->size.cx != CW_USEDEFAULT &&
569 wpage->wininfo->size.cy != CW_USEDEFAULT)
571 sz = wpage->wininfo->size;
572 flags &= ~SWP_NOMOVE;
574 SetWindowPos(win->hMainWnd, HWND_TOP, pt.x, pt.y, sz.cx, sz.cy, flags);
576 if (wpage->page && wpage->page->file != win->page->file)
577 WINHELP_DeleteBackSet(win);
578 WINHELP_InitFonts(win->hMainWnd);
580 win->page = wpage->page;
581 win->info = wpage->wininfo;
582 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
583 WINHELP_SetupText(hTextWnd, win, wpage->relative);
585 InvalidateRect(win->hMainWnd, NULL, TRUE);
586 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
594 /* Initialize WINHELP_WINDOW struct */
595 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
596 sizeof(WINHELP_WINDOW) + strlen(wpage->wininfo->name) + 1);
597 if (!win) return FALSE;
598 win->next = Globals.win_list;
599 Globals.win_list = win;
601 name = (char*)win + sizeof(WINHELP_WINDOW);
602 lstrcpy(name, wpage->wininfo->name);
603 win->lpszName = name;
604 win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
607 win->page = wpage->page;
608 win->info = wpage->wininfo;
610 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
611 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
613 if (!bPopup && wpage->page && remember)
615 WINHELP_RememberPage(win, wpage);
619 Globals.active_popup = win;
621 Globals.active_win = win;
623 /* Initialize default pushbuttons */
624 if (bPrimary && wpage->page)
626 CHAR buffer[MAX_STRING_LEN];
628 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
629 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
630 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
631 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
632 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
633 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
634 if (win->back.index <= 1) MACRO_DisableButton("BTN_BACK");
635 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
636 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
637 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
638 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
643 win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
644 WINHELP_GetCaption(wpage),
645 bPrimary ? WS_OVERLAPPEDWINDOW : wpage->wininfo->win_style,
646 wpage->wininfo->origin.x, wpage->wininfo->origin.y,
647 wpage->wininfo->size.cx, wpage->wininfo->size.cy,
648 bPopup ? Globals.active_win->hMainWnd : NULL,
649 bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
650 Globals.hInstance, win);
652 /* Create button box and text Window */
653 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
654 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
657 hTextWnd = CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
658 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, win);
660 hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
661 ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
662 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
665 hIcon = (wpage->page) ? wpage->page->file->hIcon : NULL;
666 if (!hIcon) hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
667 SendMessage(win->hMainWnd, WM_SETICON, ICON_SMALL, (DWORD_PTR)hIcon);
669 /* Initialize file specific pushbuttons */
670 if (!(wpage->wininfo->win_style & WS_POPUP) && wpage->page)
672 HLPFILE_MACRO *macro;
673 for (macro = wpage->page->file->first_macro; macro; macro = macro->next)
674 MACRO_ExecuteMacro(macro->lpszMacro);
676 for (macro = wpage->page->first_macro; macro; macro = macro->next)
677 MACRO_ExecuteMacro(macro->lpszMacro);
680 WINHELP_LayoutMainWindow(win);
682 ShowWindow(win->hMainWnd, nCmdShow);
683 WINHELP_SetupText(hTextWnd, win, wpage->relative);
688 /******************************************************************
689 * WINHELP_OpenHelpWindow
690 * Main function to search for a page and display it in a window
692 BOOL WINHELP_OpenHelpWindow(HLPFILE_PAGE* (*lookup)(HLPFILE*, LONG, ULONG*),
693 HLPFILE* hlpfile, LONG val, HLPFILE_WINDOWINFO* wi,
696 WINHELP_WNDPAGE wpage;
698 wpage.page = lookup(hlpfile, val, &wpage.relative);
699 if (wpage.page) wpage.page->file->wRefCount++;
701 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
704 /***********************************************************************
706 * WINHELP_MainWndProc
708 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
711 WINHELP_BUTTON *button;
713 INT curPos, min, max, dy, keyDelta;
716 WINHELP_CheckPopup(msg);
721 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
722 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
723 if (!win->page && Globals.isBook)
724 PostMessage(hWnd, WM_COMMAND, MNID_FILE_OPEN, 0);
725 win->hMainWnd = hWnd;
728 case WM_WINDOWPOSCHANGED:
729 WINHELP_LayoutMainWindow((WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0));
733 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
737 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
738 case MNID_FILE_PRINT: MACRO_Print(); break;
739 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
740 case MNID_FILE_EXIT: MACRO_Exit(); break;
743 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
744 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
747 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
750 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
751 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
752 case MNID_HELP_ABOUT: MACRO_About(); break;
753 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
757 for (button = win->first_button; button; button = button->next)
758 if (wParam == button->wParam) break;
760 MACRO_ExecuteMacro(button->lpszMacro);
761 else if (!HIWORD(wParam))
762 MessageBox(0, MAKEINTRESOURCE(STID_NOT_IMPLEMENTED),
763 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
767 /* EPP case WM_DESTROY: */
768 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
771 return WINHELP_HandleCommand((HWND)wParam, lParam);
780 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
782 keyDelta = -keyDelta;
786 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
787 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
788 curPos = GetScrollPos(hTextWnd, SB_VERT);
789 GetScrollRange(hTextWnd, SB_VERT, &min, &max);
793 GetClientRect(hTextWnd, &rect);
794 keyDelta = (rect.bottom - rect.top) / 2;
795 if (wParam == VK_PRIOR)
796 keyDelta = -keyDelta;
802 else if (curPos < min)
805 dy = GetScrollPos(hTextWnd, SB_VERT) - curPos;
806 SetScrollPos(hTextWnd, SB_VERT, curPos, TRUE);
807 ScrollWindow(hTextWnd, 0, dy, NULL, NULL);
808 UpdateWindow(hTextWnd);
819 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
820 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
821 WINHELP_DeleteWindow(win);
823 if (bExit) MACRO_Exit();
824 if (!Globals.win_list)
829 return DefWindowProc(hWnd, msg, wParam, lParam);
832 static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff,
835 struct RtfData* rd = (struct RtfData*)cookie;
837 if (rd->where >= rd->ptr) return 1;
838 if (rd->where + cb > rd->ptr)
839 cb = rd->ptr - rd->where;
840 memcpy(buff, rd->where, cb);
846 static void WINHELP_FillRichEdit(HWND hTextWnd, WINHELP_WINDOW *win, ULONG relative)
848 SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0);
849 SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color);
850 /* set word-wrap to window size (undocumented) */
851 SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0);
857 if (HLPFILE_BrowsePage(win->page, &rd))
860 es.dwCookie = (DWORD_PTR)&rd;
862 es.pfnCallback = WINHELP_RtfStreamIn;
864 SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
866 /* FIXME: else leaking potentially the rd.first_link chain */
867 HeapFree(GetProcessHeap(), 0, rd.data);
871 SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)"");
873 SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0);
874 SendMessage(hTextWnd, EM_SETSEL, 0, 0);
875 SendMessage(hTextWnd, EM_SCROLLCARET, 0, 0);
876 InvalidateRect(hTextWnd, NULL, TRUE);
879 /***********************************************************************
881 * WINHELP_ButtonBoxWndProc
883 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
887 WINHELP_BUTTON *button;
891 WINHELP_CheckPopup(msg);
895 case WM_WINDOWPOSCHANGING:
896 winpos = (WINDOWPOS*) lParam;
897 win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0);
902 for (button = win->first_button; button; button = button->next)
908 button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName,
909 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
911 hWnd, (HMENU) button->wParam,
912 Globals.hInstance, 0);
914 if (Globals.button_proc == NULL)
915 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
916 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
919 hDc = GetDC(button->hWnd);
920 GetTextExtentPoint(hDc, button->lpszName,
921 lstrlen(button->lpszName), &textsize);
922 ReleaseDC(button->hWnd, hDc);
924 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
925 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
930 for (button = win->first_button; button; button = button->next)
932 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
934 if (x + 2 * button_size.cx <= winpos->cx)
937 x = 0, y += button_size.cy;
939 winpos->cy = y + (x ? button_size.cy : 0);
943 SendMessage(GetParent(hWnd), msg, wParam, lParam);
954 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
959 return DefWindowProc(hWnd, msg, wParam, lParam);
962 /***********************************************************************
964 * WINHELP_ButtonWndProc
966 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
968 if (msg == WM_KEYDOWN)
977 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
981 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
984 /***********************************************************************
986 * WINHELP_TextWndProc
988 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
992 WINHELP_LINE_PART *part;
1000 if (msg != WM_LBUTTONDOWN)
1001 WINHELP_CheckPopup(msg);
1006 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
1007 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
1008 win->hBrush = CreateSolidBrush(win->info->sr_color);
1009 WINHELP_InitFonts(hWnd);
1013 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1015 /* Calculate vertical size and position of a popup window */
1016 if (win->info->win_style & WS_POPUP)
1019 RECT old_window_rect;
1020 RECT old_client_rect;
1021 SIZE old_window_size;
1022 SIZE old_client_size;
1023 SIZE new_client_size;
1024 SIZE new_window_size;
1026 GetWindowRect(GetParent(hWnd), &old_window_rect);
1027 origin.x = old_window_rect.left;
1028 origin.y = old_window_rect.top;
1029 old_window_size.cx = old_window_rect.right - old_window_rect.left;
1030 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
1032 WINHELP_LayoutMainWindow(win);
1033 GetClientRect(hWnd, &old_client_rect);
1034 old_client_size.cx = old_client_rect.right - old_client_rect.left;
1035 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
1037 new_client_size = old_client_size;
1038 WINHELP_SplitLines(hWnd, &new_client_size);
1040 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
1041 origin.y += POPUP_YDISTANCE;
1043 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
1045 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
1046 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
1049 CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
1050 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
1051 new_window_size.cx, new_window_size.cy,
1052 0, 0, Globals.hInstance, 0);
1054 SetWindowPos(GetParent(hWnd), HWND_TOP, origin.x, origin.y,
1055 new_window_size.cx, new_window_size.cy,
1057 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
1058 ShowWindow(win->hShadowWnd, SW_NORMAL);
1059 SetActiveWindow(hWnd);
1063 case WM_WINDOWPOSCHANGED:
1064 winpos = (WINDOWPOS*) lParam;
1066 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd, NULL, 0);
1072 UINT scrollLines = 3;
1073 int curPos = GetScrollPos(hWnd, SB_VERT);
1076 GetScrollRange(hWnd, SB_VERT, &min, &max);
1078 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
1079 if (wParam & (MK_SHIFT | MK_CONTROL))
1080 return DefWindowProc(hWnd, msg, wParam, lParam);
1081 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
1082 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
1085 curPos += wheelDelta;
1088 else if (curPos < min)
1091 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
1092 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
1093 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1104 INT CurPos = GetScrollPos(hWnd, SB_VERT);
1107 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
1108 GetClientRect(hWnd, &rect);
1110 switch (wParam & 0xffff)
1113 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
1114 case SB_TOP: CurPos = Min; break;
1115 case SB_BOTTOM: CurPos = Max; break;
1116 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
1117 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
1118 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
1119 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
1120 default: update = FALSE;
1126 else if (CurPos < Min)
1128 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
1129 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
1130 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1137 hDc = BeginPaint(hWnd, &ps);
1138 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1139 scroll_pos = GetScrollPos(hWnd, SB_VERT);
1141 /* No DPtoLP needed - MM_TEXT map mode */
1142 if (ps.fErase) FillRect(hDc, &ps.rcPaint, win->hBrush);
1143 for (line = win->first_line; line; line = line->next)
1145 for (part = &line->first_part; part; part = part->next)
1147 switch (part->cookie)
1149 case hlp_line_part_text:
1150 SelectObject(hDc, part->u.text.hFont);
1151 SetTextColor(hDc, part->u.text.color);
1152 SetBkColor(hDc, win->info->sr_color);
1153 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
1154 part->u.text.lpsText, part->u.text.wTextLen);
1155 if (part->u.text.wUnderline)
1159 switch (part->u.text.wUnderline)
1161 case 1: /* simple */
1162 case 2: /* double */
1163 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
1165 case 3: /* dotted */
1166 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
1169 WINE_FIXME("Unknow underline type\n");
1173 SelectObject(hDc, hPen);
1174 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
1175 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
1176 if (part->u.text.wUnderline == 2)
1178 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
1179 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
1184 case hlp_line_part_bitmap:
1188 hMemDC = CreateCompatibleDC(hDc);
1189 SelectObject(hMemDC, part->u.bitmap.hBitmap);
1190 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1191 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
1192 hMemDC, 0, 0, SRCCOPY);
1196 case hlp_line_part_metafile:
1203 sz.cx = part->rect.right - part->rect.left;
1204 sz.cy = part->rect.bottom - part->rect.top;
1205 hMemDC = CreateCompatibleDC(hDc);
1206 hBitmap = CreateCompatibleBitmap(hDc, sz.cx, sz.cy);
1207 SelectObject(hMemDC, hBitmap);
1208 SelectObject(hMemDC, win->hBrush);
1213 FillRect(hMemDC, &rc, win->hBrush);
1214 SetMapMode(hMemDC, part->u.metafile.mm);
1215 SetWindowExtEx(hMemDC, sz.cx, sz.cy, 0);
1216 SetViewportExtEx(hMemDC, sz.cx, sz.cy, 0);
1217 SetWindowOrgEx(hMemDC, 0, 0, 0);
1218 SetViewportOrgEx(hMemDC, 0, 0, 0);
1219 PlayMetaFile(hMemDC, part->u.metafile.hMetaFile);
1220 SetMapMode(hMemDC, MM_TEXT);
1221 SetWindowOrgEx(hMemDC, 0, 0, 0);
1222 SetViewportOrgEx(hMemDC, 0, 0, 0);
1223 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1224 sz.cx, sz.cy, hMemDC, 0, 0, SRCCOPY);
1226 DeleteObject(hBitmap);
1233 EndPaint(hWnd, &ps);
1237 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1239 if (WINHELP_IsOverLink(win, wParam, lParam))
1240 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
1242 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
1246 case WM_LBUTTONDOWN:
1247 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1249 if (Globals.active_popup)
1251 hPopupWnd = Globals.active_popup->hMainWnd;
1252 Globals.active_popup = NULL;
1254 else hPopupWnd = NULL;
1256 part = WINHELP_IsOverLink(win, wParam, lParam);
1260 HLPFILE_WINDOWINFO* wi;
1262 mouse.x = (short)LOWORD(lParam);
1263 mouse.y = (short)HIWORD(lParam);
1265 if (part->link) switch (part->link->cookie)
1268 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1269 if (part->link->window == -1)
1271 else if (part->link->window < hlpfile->numWindows)
1272 wi = &hlpfile->windows[part->link->window];
1275 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
1278 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, part->link->lHash,
1281 case hlp_link_popup:
1282 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1283 if (hlpfile) WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, part->link->lHash,
1284 WINHELP_GetPopupWindowInfo(hlpfile, win, &mouse),
1287 case hlp_link_macro:
1288 MACRO_ExecuteMacro(part->link->lpszString);
1291 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1296 DestroyWindow(hPopupWnd);
1301 return DefWindowProc(hWnd, msg, wParam, lParam);
1304 /******************************************************************
1305 * WINHELP_HistoryWndProc
1309 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1311 WINHELP_WINDOW* win;
1321 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1322 SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win);
1323 win->hHistoryWnd = hWnd;
1326 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1328 GetTextMetrics(hDc, &tm);
1329 GetWindowRect(hWnd, &r);
1331 r.right = r.left + 30 * tm.tmAveCharWidth;
1332 r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight;
1333 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1334 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1335 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1337 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1338 ReleaseDC(hWnd, hDc);
1340 case WM_LBUTTONDOWN:
1341 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1343 GetTextMetrics(hDc, &tm);
1344 i = HIWORD(lParam) / tm.tmHeight;
1345 if (i < Globals.history.index)
1346 WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE);
1347 ReleaseDC(hWnd, hDc);
1350 hDc = BeginPaint(hWnd, &ps);
1351 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1352 GetTextMetrics(hDc, &tm);
1354 for (i = 0; i < Globals.history.index; i++)
1356 if (Globals.history.set[i].page->file == Globals.active_win->page->file)
1358 TextOut(hDc, 0, i * tm.tmHeight,
1359 Globals.history.set[i].page->lpszTitle,
1360 strlen(Globals.history.set[i].page->lpszTitle));
1369 ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\');
1370 if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath;
1372 ptr2 = strrchr(ptr1, '.');
1373 len = ptr2 ? ptr2 - ptr1 : strlen(ptr1);
1374 if (len > sizeof(buffer)) len = sizeof(buffer);
1375 memcpy(buffer, ptr1, len);
1376 if (len < sizeof(buffer)) buffer[len++] = ':';
1377 strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len);
1378 buffer[sizeof(buffer) - 1] = '\0';
1379 TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer));
1382 EndPaint(hWnd, &ps);
1385 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1386 if (hWnd == win->hHistoryWnd)
1387 win->hHistoryWnd = 0;
1390 return DefWindowProc(hWnd, msg, wParam, lParam);
1393 /***********************************************************************
1395 * WINHELP_ShadowWndProc
1397 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1399 WINHELP_CheckPopup(msg);
1400 return DefWindowProc(hWnd, msg, wParam, lParam);
1403 /***********************************************************************
1407 static void WINHELP_SetupText(HWND hWnd, WINHELP_WINDOW* win, ULONG relative)
1413 if (!win) win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1414 if (use_richedit) return WINHELP_FillRichEdit(hWnd, win, relative);
1416 ShowScrollBar(hWnd, SB_VERT, FALSE);
1417 if (!WINHELP_SplitLines(hWnd, NULL))
1419 ShowScrollBar(hWnd, SB_VERT, TRUE);
1420 GetClientRect(hWnd, &rect);
1422 WINHELP_SplitLines(hWnd, &newsize);
1423 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1427 SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1428 SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
1431 ReleaseDC(hWnd, hDc);
1434 /***********************************************************************
1436 * WINHELP_AppendText
1438 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1439 LPSIZE space, LPSIZE textsize,
1440 INT *line_ascent, INT ascent,
1441 LPCSTR text, UINT textlen,
1442 HFONT font, COLORREF color, HLPFILE_LINK *link,
1446 WINHELP_LINE_PART *part;
1449 if (!*partp) /* New line */
1451 *line_ascent = ascent;
1453 line = HeapAlloc(GetProcessHeap(), 0,
1454 sizeof(WINHELP_LINE) + textlen);
1455 if (!line) return FALSE;
1458 part = &line->first_part;
1459 ptr = (char*)line + sizeof(WINHELP_LINE);
1461 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1462 line->rect.bottom = line->rect.top;
1463 line->rect.left = space->cx;
1464 line->rect.right = space->cx;
1466 if (**linep) *linep = &(**linep)->next;
1470 else /* Same line */
1474 if (*line_ascent < ascent)
1476 WINHELP_LINE_PART *p;
1477 for (p = &line->first_part; p; p = p->next)
1479 p->rect.top += ascent - *line_ascent;
1480 p->rect.bottom += ascent - *line_ascent;
1482 line->rect.bottom += ascent - *line_ascent;
1483 *line_ascent = ascent;
1486 part = HeapAlloc(GetProcessHeap(), 0,
1487 sizeof(WINHELP_LINE_PART) + textlen);
1488 if (!part) return FALSE;
1490 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1493 memcpy(ptr, text, textlen);
1494 part->cookie = hlp_line_part_text;
1495 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1496 part->rect.right = part->rect.left + textsize->cx;
1497 line->rect.right = part->rect.right;
1499 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1500 part->rect.bottom = part->rect.top + textsize->cy;
1501 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1502 part->u.text.lpsText = ptr;
1503 part->u.text.wTextLen = textlen;
1504 part->u.text.hFont = font;
1505 part->u.text.color = color;
1506 part->u.text.wUnderline = underline;
1508 WINE_TRACE("Appended text '%*.*s'[%d] @ (%d,%d-%d,%d)\n",
1509 part->u.text.wTextLen,
1510 part->u.text.wTextLen,
1511 part->u.text.lpsText,
1512 part->u.text.wTextLen,
1513 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1516 if (link) link->wRefCount++;
1519 *partp = &part->next;
1526 /***********************************************************************
1528 * WINHELP_AppendGfxObject
1530 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1531 LPSIZE space, LPSIZE gfxSize,
1532 HLPFILE_LINK *link, unsigned pos)
1535 WINHELP_LINE_PART *part;
1538 if (!*partp || pos == 1) /* New line */
1540 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1541 if (!line) return NULL;
1544 part = &line->first_part;
1546 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1547 line->rect.bottom = line->rect.top;
1548 line->rect.left = space->cx;
1549 line->rect.right = space->cx;
1551 if (**linep) *linep = &(**linep)->next;
1554 ptr = (char*)line + sizeof(WINHELP_LINE);
1556 else /* Same line */
1558 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1561 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1562 if (!part) return NULL;
1564 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1567 /* part->cookie should be set by caller (image or metafile) */
1568 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1569 part->rect.right = part->rect.left + gfxSize->cx;
1570 line->rect.right = part->rect.right;
1571 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1572 part->rect.bottom = part->rect.top + gfxSize->cy;
1573 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1575 WINE_TRACE("Appended gfx @ (%d,%d-%d,%d)\n",
1576 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1579 if (link) link->wRefCount++;
1582 *partp = &part->next;
1590 /***********************************************************************
1592 * WINHELP_SplitLines
1594 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1596 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1597 HLPFILE_PARAGRAPH *p;
1598 WINHELP_LINE **line = &win->first_line;
1599 WINHELP_LINE_PART **part = 0;
1600 INT line_ascent = 0;
1605 if (newsize) newsize->cx = newsize->cy = 0;
1607 if (!win->page) return TRUE;
1609 WINHELP_DeleteLines(win);
1611 GetClientRect(hWnd, &rect);
1613 rect.top += INTERNAL_BORDER_WIDTH;
1614 rect.left += INTERNAL_BORDER_WIDTH;
1615 rect.right -= INTERNAL_BORDER_WIDTH;
1616 rect.bottom -= INTERNAL_BORDER_WIDTH;
1618 space.cy = rect.top;
1619 space.cx = rect.left;
1623 for (p = win->page->first_paragraph; p; p = p->next)
1627 case para_normal_text:
1628 case para_debug_text:
1631 SIZE textsize = {0, 0};
1632 LPCSTR text = p->u.text.lpszText;
1634 UINT len = strlen(text);
1635 unsigned underline = 0;
1638 COLORREF color = RGB(0, 0, 0);
1640 if (p->u.text.wFont < win->page->file->numFonts)
1642 HLPFILE* hlpfile = win->page->file;
1644 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1645 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1646 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1647 color = hlpfile->fonts[p->u.text.wFont].color;
1651 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1653 hFont = win->fonts[wFont];
1656 if (p->link && p->link->bClrChange)
1658 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1659 color = RGB(0, 0x80, 0);
1661 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1663 SelectObject(hDc, hFont);
1665 GetTextMetrics(hDc, &tm);
1667 if (p->u.text.wIndent)
1669 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1671 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1674 if (p->u.text.wVSpace)
1677 space.cx = rect.left + indent;
1678 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1681 if (p->u.text.wHSpace)
1683 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1686 WINE_TRACE("splitting text %s\n", text);
1690 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1691 UINT low = 0, curr = len, high = len, textlen = 0;
1697 GetTextExtentPoint(hDc, text, curr, &textsize);
1699 if (textsize.cx <= free_width) low = curr;
1702 if (high <= low + 1) break;
1704 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1705 if (curr <= low) curr = low + 1;
1706 else if (curr >= high) curr = high - 1;
1709 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1711 if (!part && !textlen) textlen = max(low, 1);
1713 if (free_width <= 0 || !textlen)
1716 space.cx = rect.left + indent;
1717 space.cx = min(space.cx, rect.right - rect.left - 1);
1721 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1723 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1724 &line_ascent, tm.tmAscent,
1725 text, textlen, hFont, color, p->link, underline) ||
1726 (!newsize && (*line)->rect.bottom > rect.bottom))
1728 ReleaseDC(hWnd, hDc);
1733 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1737 if (text[0] == ' ') text++, len--;
1746 WINHELP_LINE_PART* ref_part;
1748 if (p->u.gfx.pos & 0x8000)
1750 space.cx = rect.left;
1752 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1756 if (p->cookie == para_bitmap)
1760 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1761 gfxSize.cx = dibs.dsBm.bmWidth;
1762 gfxSize.cy = dibs.dsBm.bmHeight;
1766 LPMETAFILEPICT lpmfp = &p->u.gfx.u.mfp;
1767 if (lpmfp->mm == MM_ANISOTROPIC || lpmfp->mm == MM_ISOTROPIC)
1769 gfxSize.cx = MulDiv(lpmfp->xExt, GetDeviceCaps(hDc, HORZRES),
1770 100*GetDeviceCaps(hDc, HORZSIZE));
1771 gfxSize.cy = MulDiv(lpmfp->yExt, GetDeviceCaps(hDc, VERTRES),
1772 100*GetDeviceCaps(hDc, VERTSIZE));
1776 gfxSize.cx = lpmfp->xExt;
1777 gfxSize.cy = lpmfp->yExt;
1781 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1782 if (free_width <= 0)
1785 space.cx = rect.left;
1786 space.cx = min(space.cx, rect.right - rect.left - 1);
1788 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1789 p->link, p->u.gfx.pos);
1790 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1794 if (p->cookie == para_bitmap)
1796 ref_part->cookie = hlp_line_part_bitmap;
1797 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1801 ref_part->cookie = hlp_line_part_metafile;
1802 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mfp.hMF;
1803 ref_part->u.metafile.mm = p->u.gfx.u.mfp.mm;
1811 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1813 ReleaseDC(hWnd, hDc);
1817 /***********************************************************************
1819 * WINHELP_CheckPopup
1821 static void WINHELP_CheckPopup(UINT msg)
1825 if (!Globals.active_popup) return;
1830 case WM_LBUTTONDOWN:
1831 case WM_MBUTTONDOWN:
1832 case WM_RBUTTONDOWN:
1833 case WM_NCLBUTTONDOWN:
1834 case WM_NCMBUTTONDOWN:
1835 case WM_NCRBUTTONDOWN:
1836 hPopup = Globals.active_popup->hMainWnd;
1837 Globals.active_popup = NULL;
1838 DestroyWindow(hPopup);
1842 /***********************************************************************
1844 * WINHELP_DeleteLines
1846 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1848 WINHELP_LINE *line, *next_line;
1849 WINHELP_LINE_PART *part, *next_part;
1850 for (line = win->first_line; line; line = next_line)
1852 next_line = line->next;
1853 for (part = &line->first_part; part; part = next_part)
1855 next_part = part->next;
1856 HLPFILE_FreeLink(part->link);
1857 HeapFree(GetProcessHeap(), 0, part);
1860 win->first_line = 0;
1863 /******************************************************************
1864 * WINHELP_DeleteButtons
1867 static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
1872 for (b = win->first_button; b; b = bp)
1874 DestroyWindow(b->hWnd);
1876 HeapFree(GetProcessHeap(), 0, b);
1878 win->first_button = NULL;
1881 /******************************************************************
1882 * WINHELP_DeleteBackSet
1885 void WINHELP_DeleteBackSet(WINHELP_WINDOW* win)
1889 for (i = 0; i < win->back.index; i++)
1891 HLPFILE_FreeHlpFile(win->back.set[i].page->file);
1892 win->back.set[i].page = NULL;
1894 win->back.index = 0;
1897 /***********************************************************************
1899 * WINHELP_DeleteWindow
1901 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1905 for (w = &Globals.win_list; *w; w = &(*w)->next)
1914 if (Globals.active_win == win)
1916 Globals.active_win = Globals.win_list;
1917 if (Globals.win_list)
1918 SetActiveWindow(Globals.win_list->hMainWnd);
1921 if (win == Globals.active_popup)
1922 Globals.active_popup = NULL;
1924 WINHELP_DeleteButtons(win);
1926 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1927 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1929 DeleteObject(win->hBrush);
1931 WINHELP_DeleteBackSet(win);
1933 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1934 WINHELP_DeleteLines(win);
1935 HeapFree(GetProcessHeap(), 0, win);
1938 /***********************************************************************
1942 static void WINHELP_InitFonts(HWND hWnd)
1944 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1945 LOGFONT logfontlist[] = {
1946 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1947 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1948 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1949 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1950 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1951 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1952 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
1953 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1955 static HFONT fonts[FONTS_LEN];
1956 static BOOL init = 0;
1958 win->fonts_len = FONTS_LEN;
1965 for (i = 0; i < FONTS_LEN; i++)
1967 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1974 /***********************************************************************
1976 * WINHELP_MessageBoxIDS_s
1978 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1980 CHAR text[MAX_STRING_LEN];
1981 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
1983 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1984 wsprintf(newtext, text, str);
1986 return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type);
1989 /******************************************************************
1990 * WINHELP_IsOverLink
1994 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1998 WINHELP_LINE_PART *part;
1999 int scroll_pos = GetScrollPos(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), SB_VERT);
2001 mouse.x = LOWORD(lParam);
2002 mouse.y = HIWORD(lParam);
2003 for (line = win->first_line; line; line = line->next)
2005 for (part = &line->first_part; part; part = part->next)
2008 part->link->lpszString &&
2009 part->rect.left <= mouse.x &&
2010 part->rect.right >= mouse.x &&
2011 part->rect.top <= mouse.y + scroll_pos &&
2012 part->rect.bottom >= mouse.y + scroll_pos)
2022 /**************************************************************************
2025 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
2028 static void cb_KWBTree(void *p, void **next, void *cookie)
2030 HWND hListWnd = (HWND)cookie;
2033 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
2034 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
2035 count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0);
2036 SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p);
2037 *next = (char*)p + strlen((char*)p) + 7;
2040 /**************************************************************************
2041 * WINHELP_IndexDlgProc
2043 * Index dialog callback function.
2045 * nResult passed to EndDialog:
2047 * >1: valid offset value +2.
2048 * EndDialog itself can return 0 (error).
2050 INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2052 static HLPFILE *file;
2059 file = (HLPFILE *)lParam;
2060 HLPFILE_BPTreeEnum(file->kwbtree, cb_KWBTree,
2061 GetDlgItem(hWnd, IDC_INDEXLIST));
2064 switch (LOWORD(wParam))
2067 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
2073 p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST,
2074 LB_GETITEMDATA, sel, 0);
2075 count = *(short*)((char *)p + strlen((char *)p) + 1);
2078 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
2081 offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
2082 offset = *(long*)(file->kwdata + offset + 9);
2083 if (offset == 0xFFFFFFFF)
2085 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
2092 EndDialog(hWnd, offset);
2103 /**************************************************************************
2104 * WINHELP_CreateIndexWindow
2106 * Displays a dialog with keywords of current help file.
2109 BOOL WINHELP_CreateIndexWindow(void)
2114 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
2115 hlpfile = Globals.active_win->page->file;
2119 if (hlpfile->kwbtree == NULL)
2121 WINE_TRACE("No index provided\n");
2125 ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_INDEX),
2126 Globals.active_win->hMainWnd, WINHELP_SearchDlgProc,
2131 WINE_TRACE("got %d as an offset\n", ret);
2132 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset, hlpfile, ret,
2133 Globals.active_win->info, SW_NORMAL);