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"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
43 static BOOL WINHELP_RegisterWinClasses(void);
44 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
45 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
47 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
48 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
49 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
50 static void WINHELP_CheckPopup(UINT);
51 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
52 static void WINHELP_InitFonts(HWND hWnd);
53 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
54 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
55 static void WINHELP_DeleteButtons(WINHELP_WINDOW*);
56 static void WINHELP_SetupText(HWND hWnd);
57 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
59 WINHELP_GLOBALS Globals = {3, NULL, NULL, TRUE, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}};
61 #define CTL_ID_BUTTON 0x700
62 #define CTL_ID_TEXT 0x701
64 /***********************************************************************
66 * WINHELP_GetOpenFileName
68 BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len)
70 OPENFILENAME openfilename;
72 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
77 LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
81 LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
87 GetCurrentDirectory(sizeof(szDir), szDir);
91 openfilename.lStructSize = sizeof(OPENFILENAME);
92 openfilename.hwndOwner = NULL;
93 openfilename.hInstance = Globals.hInstance;
94 openfilename.lpstrFilter = szzFilter;
95 openfilename.lpstrCustomFilter = 0;
96 openfilename.nMaxCustFilter = 0;
97 openfilename.nFilterIndex = 1;
98 openfilename.lpstrFile = lpszFile;
99 openfilename.nMaxFile = len;
100 openfilename.lpstrFileTitle = 0;
101 openfilename.nMaxFileTitle = 0;
102 openfilename.lpstrInitialDir = szDir;
103 openfilename.lpstrTitle = 0;
104 openfilename.Flags = 0;
105 openfilename.nFileOffset = 0;
106 openfilename.nFileExtension = 0;
107 openfilename.lpstrDefExt = 0;
108 openfilename.lCustData = 0;
109 openfilename.lpfnHook = 0;
110 openfilename.lpTemplateName = 0;
112 return GetOpenFileName(&openfilename);
115 static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage)
117 if (wpage->wininfo->caption[0]) return wpage->wininfo->caption;
118 return wpage->page->file->lpszTitle;
121 /***********************************************************************
123 * WINHELP_LookupHelpFile
125 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
128 char szFullName[MAX_PATH];
129 char szAddPath[MAX_PATH];
133 * NOTE: This is needed by popup windows only.
134 * In other cases it's not needed but does not hurt though.
136 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
138 strcpy(szAddPath, Globals.active_win->page->file->lpszPath);
139 p = strrchr(szAddPath, '\\');
144 * FIXME: Should we swap conditions?
146 if (!SearchPath(NULL, lpszFile, ".hlp", MAX_PATH, szFullName, NULL) &&
147 !SearchPath(szAddPath, lpszFile, ".hlp", MAX_PATH, szFullName, NULL))
149 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s, lpszFile, STID_WHERROR,
150 MB_YESNO|MB_ICONQUESTION) != IDYES)
152 if (!WINHELP_GetOpenFileName(szFullName, MAX_PATH))
155 hlpfile = HLPFILE_ReadHlpFile(szFullName);
157 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile,
158 STID_WHERROR, MB_OK|MB_ICONSTOP);
162 /******************************************************************
163 * WINHELP_GetWindowInfo
167 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
169 static HLPFILE_WINDOWINFO mwi;
172 if (!name || !name[0])
173 name = Globals.active_win->lpszName;
176 for (i = 0; i < hlpfile->numWindows; i++)
177 if (!strcmp(hlpfile->windows[i].name, name))
178 return &hlpfile->windows[i];
180 if (strcmp(name, "main") != 0)
182 WINE_FIXME("Couldn't find window info for %s\n", name);
188 strcpy(mwi.type, "primary");
189 strcpy(mwi.name, "main");
190 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
191 mwi.caption, sizeof(mwi.caption)))
192 strcpy(mwi.caption, hlpfile->lpszTitle);
193 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
195 mwi.win_style = WS_OVERLAPPEDWINDOW;
196 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
201 /******************************************************************
202 * HLPFILE_GetPopupWindowInfo
206 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
208 static HLPFILE_WINDOWINFO wi;
212 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
214 /* Calculate horizontal size and position of a popup window */
215 GetWindowRect(hParentWnd, &parent_rect);
216 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
217 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
220 ClientToScreen(hParentWnd, &wi.origin);
221 wi.origin.x -= wi.size.cx / 2;
222 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
223 wi.origin.x = max(wi.origin.x, 0);
226 wi.win_style = WS_POPUP | WS_BORDER;
227 wi.sr_color = wi.sr_color = 0xFFFFFF;
232 /***********************************************************************
236 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
241 static CHAR default_wndname[] = "main";
242 LPSTR wndname = default_wndname;
245 Globals.hInstance = hInstance;
248 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
252 if (*cmdline++ == ' ') continue;
255 if (option) cmdline++;
256 while (*cmdline && *cmdline == ' ') cmdline++;
262 while (*cmdline && *cmdline != ' ') cmdline++;
263 if (*cmdline) *cmdline++ = '\0';
264 lHash = HLPFILE_Hash(topic_id);
269 Globals.wVersion = option - '0';
274 Globals.isBook = FALSE;
278 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
283 /* Create primary window */
284 if (!WINHELP_RegisterWinClasses())
286 WINE_FIXME("Couldn't register classes\n");
293 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
298 if ((ptr = strchr(cmdline, '>')))
303 hlpfile = WINHELP_LookupHelpFile(cmdline);
304 if (!hlpfile) return 0;
307 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
308 WINHELP_GetWindowInfo(hlpfile, wndname), show);
311 while (GetMessage(&msg, 0, 0, 0))
313 TranslateMessage(&msg);
314 DispatchMessage(&msg);
316 for (dll = Globals.dlls; dll; dll = dll->next)
318 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
323 /***********************************************************************
327 static BOOL WINHELP_RegisterWinClasses(void)
329 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
331 class_main.style = CS_HREDRAW | CS_VREDRAW;
332 class_main.lpfnWndProc = WINHELP_MainWndProc;
333 class_main.cbClsExtra = 0;
334 class_main.cbWndExtra = sizeof(LONG);
335 class_main.hInstance = Globals.hInstance;
336 class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
337 class_main.hCursor = LoadCursor(0, IDC_ARROW);
338 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
339 class_main.lpszMenuName = 0;
340 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
342 class_button_box = class_main;
343 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
344 class_button_box.cbWndExtra = 0;
345 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
346 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
348 class_text = class_main;
349 class_text.lpfnWndProc = WINHELP_TextWndProc;
350 class_text.hbrBackground = 0;
351 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
353 class_shadow = class_main;
354 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
355 class_shadow.cbWndExtra = 0;
356 class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
357 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
359 class_history = class_main;
360 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
361 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
363 return (RegisterClass(&class_main) &&
364 RegisterClass(&class_button_box) &&
365 RegisterClass(&class_text) &&
366 RegisterClass(&class_shadow) &&
367 RegisterClass(&class_history));
378 } WINHELP,*LPWINHELP;
380 /******************************************************************
381 * WINHELP_HandleCommand
385 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
387 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
390 if (cds->dwData != 0xA1DE505)
392 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
396 wh = (WINHELP*)cds->lpData;
400 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
402 WINE_TRACE("Got[%u]: cmd=%u data=%08x fn=%s\n",
403 wh->size, wh->command, wh->data, ptr);
409 MACRO_JumpContext(ptr, "main", wh->data);
418 MACRO_JumpContents(ptr, "main");
421 case HELP_HELPONHELP:
424 /* case HELP_SETINDEX: */
425 case HELP_SETCONTENTS:
428 MACRO_SetContents(ptr, wh->data);
431 case HELP_CONTEXTPOPUP:
434 MACRO_PopupContext(ptr, wh->data);
437 /* case HELP_FORCEFILE:*/
438 /* case HELP_CONTEXTMENU: */
440 /* in fact, should be the topic dialog box */
441 WINE_FIXME("HELP_FINDER: stub\n");
444 MACRO_JumpHash(ptr, "main", 0);
447 /* case HELP_WM_HELP: */
448 /* case HELP_SETPOPUP_POS: */
450 /* case HELP_COMMAND: */
451 /* case HELP_PARTIALKEY: */
452 /* case HELP_MULTIKEY: */
453 /* case HELP_SETWINPOS: */
455 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
459 /* Always return success for now */
463 void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
465 RECT rect, button_box_rect;
467 HWND hButtonBoxWnd = GetDlgItem(win->hMainWnd, CTL_ID_BUTTON);
468 HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
470 GetClientRect(win->hMainWnd, &rect);
472 /* Update button box and text Window */
473 SetWindowPos(hButtonBoxWnd, HWND_TOP,
475 rect.right - rect.left,
476 rect.bottom - rect.top, 0);
478 if (GetWindowRect(hButtonBoxWnd, &button_box_rect))
479 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
481 SetWindowPos(hTextWnd, HWND_TOP,
483 rect.right - rect.left,
484 rect.bottom - text_top, 0);
488 static void WINHELP_RememberPage(WINHELP_WINDOW* win, HLPFILE_PAGE* page)
492 if (!Globals.history.index || Globals.history.set[0].page != page)
494 num = sizeof(Globals.history.set) / sizeof(Globals.history.set[0]);
495 /* we're full, remove latest entry */
496 if (Globals.history.index == num)
498 HLPFILE_FreeHlpFile(Globals.history.set[num - 1].page->file);
499 Globals.history.index--;
501 memmove(&Globals.history.set[1], &Globals.history.set[0],
502 Globals.history.index * sizeof(Globals.history.set[0]));
503 Globals.history.set[0].page = page;
504 Globals.history.set[0].wininfo = win->info;
505 Globals.history.index++;
506 page->file->wRefCount++;
508 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
510 num = sizeof(win->back.set) / sizeof(win->back.set[0]);
511 if (win->back.index == num)
513 /* we're full, remove latest entry */
514 HLPFILE_FreeHlpFile(win->back.set[0].page->file);
515 memmove(&win->back.set[0], &win->back.set[1],
516 (num - 1) * sizeof(win->back.set[0]));
519 win->back.set[win->back.index].page = page;
520 win->back.set[win->back.index++].wininfo = win->info;
521 page->file->wRefCount++;
524 /***********************************************************************
526 * WINHELP_CreateHelpWindow
528 BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remember)
530 WINHELP_WINDOW* win = NULL;
531 BOOL bPrimary, bPopup, bReUsed = FALSE;
534 bPrimary = !lstrcmpi(wpage->wininfo->name, "main");
535 bPopup = !bPrimary && (wpage->wininfo->win_style & WS_POPUP);
537 if (wpage->page && !wpage->page->first_paragraph) HLPFILE_BrowsePage(wpage->page);
541 for (win = Globals.win_list; win; win = win->next)
543 if (!lstrcmpi(win->lpszName, wpage->wininfo->name))
545 WINHELP_DeleteButtons(win);
547 SetWindowText(win->hMainWnd, WINHELP_GetCaption(wpage));
548 if (wpage->wininfo->origin.x != CW_USEDEFAULT &&
549 wpage->wininfo->origin.y != CW_USEDEFAULT)
550 SetWindowPos(win->hMainWnd, HWND_TOP,
551 wpage->wininfo->origin.x, wpage->wininfo->origin.y, 0, 0, SWP_NOSIZE);
552 if (wpage->wininfo->size.cx != CW_USEDEFAULT &&
553 wpage->wininfo->size.cy != CW_USEDEFAULT)
554 SetWindowPos(win->hMainWnd, HWND_TOP,
555 0, 0, wpage->wininfo->size.cx, wpage->wininfo->size.cy, SWP_NOMOVE);
556 if (wpage->page && wpage->page->file != win->page->file)
557 WINHELP_DeleteBackSet(win);
558 WINHELP_InitFonts(win->hMainWnd);
560 win->page = wpage->page;
561 win->info = wpage->wininfo;
562 WINHELP_SetupText(GetDlgItem(win->hMainWnd, CTL_ID_TEXT));
563 InvalidateRect(win->hMainWnd, NULL, TRUE);
564 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
572 /* Initialize WINHELP_WINDOW struct */
573 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
574 sizeof(WINHELP_WINDOW) + strlen(wpage->wininfo->name) + 1);
575 if (!win) return FALSE;
576 win->next = Globals.win_list;
577 Globals.win_list = win;
579 name = (char*)win + sizeof(WINHELP_WINDOW);
580 lstrcpy(name, wpage->wininfo->name);
581 win->lpszName = name;
582 win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
585 win->page = wpage->page;
586 win->info = wpage->wininfo;
588 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
589 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
591 if (!bPopup && wpage->page && remember)
593 WINHELP_RememberPage(win, wpage->page);
597 Globals.active_win = win;
599 /* Initialize default pushbuttons */
600 if (bPrimary && wpage->page)
602 CHAR buffer[MAX_STRING_LEN];
604 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
605 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
606 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
607 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
608 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
609 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
610 if (win->back.index <= 1) MACRO_DisableButton("BTN_BACK");
611 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
612 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
613 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
614 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
617 /* Initialize file specific pushbuttons */
618 if (!(wpage->wininfo->win_style & WS_POPUP) && wpage->page)
620 HLPFILE_MACRO *macro;
621 for (macro = wpage->page->file->first_macro; macro; macro = macro->next)
622 MACRO_ExecuteMacro(macro->lpszMacro);
624 for (macro = wpage->page->first_macro; macro; macro = macro->next)
625 MACRO_ExecuteMacro(macro->lpszMacro);
630 win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
631 WINHELP_GetCaption(wpage),
632 bPrimary ? WS_OVERLAPPEDWINDOW : wpage->wininfo->win_style,
633 wpage->wininfo->origin.x, wpage->wininfo->origin.y,
634 wpage->wininfo->size.cx, wpage->wininfo->size.cy,
635 bPopup ? Globals.active_win->hMainWnd : NULL,
636 bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
637 Globals.hInstance, win);
639 /* Create button box and text Window */
640 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
641 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
643 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
644 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, win);
647 WINHELP_LayoutMainWindow(win);
648 if (bPopup) Globals.hPopupWnd = win->hMainWnd;
650 ShowWindow(win->hMainWnd, nCmdShow);
651 UpdateWindow(win->hMainWnd);
656 /***********************************************************************
658 * WINHELP_CreateHelpWindowByHash
660 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
661 HLPFILE_WINDOWINFO* wi, int nCmdShow)
663 WINHELP_WNDPAGE wpage;
667 wpage.page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
668 HLPFILE_Contents(hlpfile);
669 if (wpage.page) wpage.page->file->wRefCount++;
671 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
674 /***********************************************************************
676 * WINHELP_CreateHelpWindowByMap
678 BOOL WINHELP_CreateHelpWindowByMap(HLPFILE* hlpfile, LONG lMap,
679 HLPFILE_WINDOWINFO* wi, int nCmdShow)
681 WINHELP_WNDPAGE wpage;
683 wpage.page = HLPFILE_PageByMap(hlpfile, lMap);
684 if (wpage.page) wpage.page->file->wRefCount++;
686 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
689 /***********************************************************************
691 * WINHELP_CreateHelpWindowByOffset
693 BOOL WINHELP_CreateHelpWindowByOffset(HLPFILE* hlpfile, LONG lOffset,
694 HLPFILE_WINDOWINFO* wi, int nCmdShow)
696 WINHELP_WNDPAGE wpage;
698 wpage.page = HLPFILE_PageByOffset(hlpfile, lOffset);
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 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
767 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
770 return WINHELP_HandleCommand((HWND)wParam, lParam);
779 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
781 keyDelta = -keyDelta;
785 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
786 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
787 curPos = GetScrollPos(hTextWnd, SB_VERT);
788 GetScrollRange(hTextWnd, SB_VERT, &min, &max);
792 GetClientRect(hTextWnd, &rect);
793 keyDelta = (rect.bottom - rect.top) / 2;
794 if (wParam == VK_PRIOR)
795 keyDelta = -keyDelta;
801 else if (curPos < min)
804 dy = GetScrollPos(hTextWnd, SB_VERT) - curPos;
805 SetScrollPos(hTextWnd, SB_VERT, curPos, TRUE);
806 ScrollWindow(hTextWnd, 0, dy, NULL, NULL);
807 UpdateWindow(hTextWnd);
818 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
819 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 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 /***********************************************************************
834 * WINHELP_ButtonBoxWndProc
836 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
840 WINHELP_BUTTON *button;
844 WINHELP_CheckPopup(msg);
848 case WM_WINDOWPOSCHANGING:
849 winpos = (WINDOWPOS*) lParam;
850 win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0);
855 for (button = win->first_button; button; button = button->next)
861 button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName,
862 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
864 hWnd, (HMENU) button->wParam,
865 Globals.hInstance, 0);
867 if (Globals.button_proc == NULL)
868 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
869 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
872 hDc = GetDC(button->hWnd);
873 GetTextExtentPoint(hDc, button->lpszName,
874 lstrlen(button->lpszName), &textsize);
875 ReleaseDC(button->hWnd, hDc);
877 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
878 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
883 for (button = win->first_button; button; button = button->next)
885 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
887 if (x + 2 * button_size.cx <= winpos->cx)
890 x = 0, y += button_size.cy;
892 winpos->cy = y + (x ? button_size.cy : 0);
896 SendMessage(GetParent(hWnd), msg, wParam, lParam);
907 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
912 return DefWindowProc(hWnd, msg, wParam, lParam);
915 /***********************************************************************
917 * WINHELP_ButtonWndProc
919 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
921 if (msg == WM_KEYDOWN)
930 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
934 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
937 /***********************************************************************
939 * WINHELP_TextWndProc
941 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
945 WINHELP_LINE_PART *part;
953 if (msg != WM_LBUTTONDOWN)
954 WINHELP_CheckPopup(msg);
959 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
960 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
961 win->hBrush = CreateSolidBrush(win->info->sr_color);
962 WINHELP_InitFonts(hWnd);
966 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
968 /* Calculate vertical size and position of a popup window */
969 if (win->info->win_style & WS_POPUP)
972 RECT old_window_rect;
973 RECT old_client_rect;
974 SIZE old_window_size;
975 SIZE old_client_size;
976 SIZE new_client_size;
977 SIZE new_window_size;
979 GetWindowRect(GetParent(hWnd), &old_window_rect);
980 origin.x = old_window_rect.left;
981 origin.y = old_window_rect.top;
982 old_window_size.cx = old_window_rect.right - old_window_rect.left;
983 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
985 WINHELP_LayoutMainWindow(win);
986 GetClientRect(hWnd, &old_client_rect);
987 old_client_size.cx = old_client_rect.right - old_client_rect.left;
988 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
990 new_client_size = old_client_size;
991 WINHELP_SplitLines(hWnd, &new_client_size);
993 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
994 origin.y += POPUP_YDISTANCE;
996 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
998 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
999 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
1002 CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
1003 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
1004 new_window_size.cx, new_window_size.cy,
1005 0, 0, Globals.hInstance, 0);
1007 SetWindowPos(GetParent(hWnd), HWND_TOP, origin.x, origin.y,
1008 new_window_size.cx, new_window_size.cy,
1010 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
1011 ShowWindow(win->hShadowWnd, SW_NORMAL);
1012 SetActiveWindow(hWnd);
1016 case WM_WINDOWPOSCHANGED:
1017 winpos = (WINDOWPOS*) lParam;
1019 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
1025 UINT scrollLines = 3;
1026 int curPos = GetScrollPos(hWnd, SB_VERT);
1029 GetScrollRange(hWnd, SB_VERT, &min, &max);
1031 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
1032 if (wParam & (MK_SHIFT | MK_CONTROL))
1033 return DefWindowProc(hWnd, msg, wParam, lParam);
1034 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
1035 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
1038 curPos += wheelDelta;
1041 else if (curPos < min)
1044 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
1045 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
1046 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1057 INT CurPos = GetScrollPos(hWnd, SB_VERT);
1060 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
1061 GetClientRect(hWnd, &rect);
1063 switch (wParam & 0xffff)
1066 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
1067 case SB_TOP: CurPos = Min; break;
1068 case SB_BOTTOM: CurPos = Max; break;
1069 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
1070 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
1071 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
1072 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
1073 default: update = FALSE;
1079 else if (CurPos < Min)
1081 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
1082 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
1083 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1090 hDc = BeginPaint(hWnd, &ps);
1091 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1092 scroll_pos = GetScrollPos(hWnd, SB_VERT);
1094 /* No DPtoLP needed - MM_TEXT map mode */
1095 if (ps.fErase) FillRect(hDc, &ps.rcPaint, win->hBrush);
1096 for (line = win->first_line; line; line = line->next)
1098 for (part = &line->first_part; part; part = part->next)
1100 switch (part->cookie)
1102 case hlp_line_part_text:
1103 SelectObject(hDc, part->u.text.hFont);
1104 SetTextColor(hDc, part->u.text.color);
1105 SetBkColor(hDc, win->info->sr_color);
1106 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
1107 part->u.text.lpsText, part->u.text.wTextLen);
1108 if (part->u.text.wUnderline)
1112 switch (part->u.text.wUnderline)
1114 case 1: /* simple */
1115 case 2: /* double */
1116 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
1118 case 3: /* dotted */
1119 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
1122 WINE_FIXME("Unknow underline type\n");
1126 SelectObject(hDc, hPen);
1127 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
1128 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
1129 if (part->u.text.wUnderline == 2)
1131 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
1132 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
1137 case hlp_line_part_bitmap:
1141 hMemDC = CreateCompatibleDC(hDc);
1142 SelectObject(hMemDC, part->u.bitmap.hBitmap);
1143 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1144 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
1145 hMemDC, 0, 0, SRCCOPY);
1149 case hlp_line_part_metafile:
1156 sz.cx = part->rect.right - part->rect.left;
1157 sz.cy = part->rect.bottom - part->rect.top;
1158 hMemDC = CreateCompatibleDC(hDc);
1159 hBitmap = CreateCompatibleBitmap(hDc, sz.cx, sz.cy);
1160 SelectObject(hMemDC, hBitmap);
1161 SelectObject(hMemDC, win->hBrush);
1166 FillRect(hMemDC, &rc, win->hBrush);
1167 SetMapMode(hMemDC, part->u.metafile.mm);
1168 SetWindowExtEx(hMemDC, sz.cx, sz.cy, 0);
1169 SetViewportExtEx(hMemDC, sz.cx, sz.cy, 0);
1170 SetWindowOrgEx(hMemDC, 0, 0, 0);
1171 SetViewportOrgEx(hMemDC, 0, 0, 0);
1172 PlayMetaFile(hMemDC, part->u.metafile.hMetaFile);
1173 SetMapMode(hMemDC, MM_TEXT);
1174 SetWindowOrgEx(hMemDC, 0, 0, 0);
1175 SetViewportOrgEx(hMemDC, 0, 0, 0);
1176 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1177 sz.cx, sz.cy, hMemDC, 0, 0, SRCCOPY);
1179 DeleteObject(hBitmap);
1186 EndPaint(hWnd, &ps);
1190 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1192 if (WINHELP_IsOverLink(win, wParam, lParam))
1193 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
1195 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
1199 case WM_LBUTTONDOWN:
1200 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1202 hPopupWnd = Globals.hPopupWnd;
1203 Globals.hPopupWnd = 0;
1205 part = WINHELP_IsOverLink(win, wParam, lParam);
1209 HLPFILE_WINDOWINFO* wi;
1211 mouse.x = (short)LOWORD(lParam);
1212 mouse.y = (short)HIWORD(lParam);
1214 if (part->link) switch (part->link->cookie)
1217 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1218 if (part->link->window == -1)
1220 else if (part->link->window < hlpfile->numWindows)
1221 wi = &hlpfile->windows[part->link->window];
1224 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
1227 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
1230 case hlp_link_popup:
1231 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1232 if (hlpfile) WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
1233 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
1236 case hlp_link_macro:
1237 MACRO_ExecuteMacro(part->link->lpszString);
1240 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1245 DestroyWindow(hPopupWnd);
1250 return DefWindowProc(hWnd, msg, wParam, lParam);
1253 /******************************************************************
1254 * WINHELP_HistoryWndProc
1258 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1260 WINHELP_WINDOW* win;
1270 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1271 SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win);
1272 win->hHistoryWnd = hWnd;
1275 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1277 GetTextMetrics(hDc, &tm);
1278 GetWindowRect(hWnd, &r);
1280 r.right = r.left + 30 * tm.tmAveCharWidth;
1281 r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight;
1282 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1283 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1284 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1286 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1287 ReleaseDC(hWnd, hDc);
1289 case WM_LBUTTONDOWN:
1290 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1292 GetTextMetrics(hDc, &tm);
1293 i = HIWORD(lParam) / tm.tmHeight;
1294 if (i < Globals.history.index)
1295 WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE);
1296 ReleaseDC(hWnd, hDc);
1299 hDc = BeginPaint(hWnd, &ps);
1300 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1301 GetTextMetrics(hDc, &tm);
1303 for (i = 0; i < Globals.history.index; i++)
1305 if (Globals.history.set[i].page->file == Globals.active_win->page->file)
1307 TextOut(hDc, 0, i * tm.tmHeight,
1308 Globals.history.set[i].page->lpszTitle,
1309 strlen(Globals.history.set[i].page->lpszTitle));
1318 ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\');
1319 if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath;
1321 ptr2 = strrchr(ptr1, '.');
1322 len = ptr2 ? ptr2 - ptr1 : strlen(ptr1);
1323 if (len > sizeof(buffer)) len = sizeof(buffer);
1324 memcpy(buffer, ptr1, len);
1325 if (len < sizeof(buffer)) buffer[len++] = ':';
1326 strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len);
1327 buffer[sizeof(buffer) - 1] = '\0';
1328 TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer));
1331 EndPaint(hWnd, &ps);
1334 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1335 if (hWnd == win->hHistoryWnd)
1336 win->hHistoryWnd = 0;
1339 return DefWindowProc(hWnd, msg, wParam, lParam);
1342 /***********************************************************************
1344 * WINHELP_ShadowWndProc
1346 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1348 WINHELP_CheckPopup(msg);
1349 return DefWindowProc(hWnd, msg, wParam, lParam);
1352 /***********************************************************************
1356 static void WINHELP_SetupText(HWND hWnd)
1358 HDC hDc = GetDC(hWnd);
1362 ShowScrollBar(hWnd, SB_VERT, FALSE);
1363 if (!WINHELP_SplitLines(hWnd, NULL))
1365 ShowScrollBar(hWnd, SB_VERT, TRUE);
1366 GetClientRect(hWnd, &rect);
1368 WINHELP_SplitLines(hWnd, &newsize);
1369 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1373 SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1374 SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
1377 ReleaseDC(hWnd, hDc);
1380 /***********************************************************************
1382 * WINHELP_AppendText
1384 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1385 LPSIZE space, LPSIZE textsize,
1386 INT *line_ascent, INT ascent,
1387 LPCSTR text, UINT textlen,
1388 HFONT font, COLORREF color, HLPFILE_LINK *link,
1392 WINHELP_LINE_PART *part;
1395 if (!*partp) /* New line */
1397 *line_ascent = ascent;
1399 line = HeapAlloc(GetProcessHeap(), 0,
1400 sizeof(WINHELP_LINE) + textlen);
1401 if (!line) return FALSE;
1404 part = &line->first_part;
1405 ptr = (char*)line + sizeof(WINHELP_LINE);
1407 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1408 line->rect.bottom = line->rect.top;
1409 line->rect.left = space->cx;
1410 line->rect.right = space->cx;
1412 if (**linep) *linep = &(**linep)->next;
1416 else /* Same line */
1420 if (*line_ascent < ascent)
1422 WINHELP_LINE_PART *p;
1423 for (p = &line->first_part; p; p = p->next)
1425 p->rect.top += ascent - *line_ascent;
1426 p->rect.bottom += ascent - *line_ascent;
1428 line->rect.bottom += ascent - *line_ascent;
1429 *line_ascent = ascent;
1432 part = HeapAlloc(GetProcessHeap(), 0,
1433 sizeof(WINHELP_LINE_PART) + textlen);
1434 if (!part) return FALSE;
1436 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1439 memcpy(ptr, text, textlen);
1440 part->cookie = hlp_line_part_text;
1441 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1442 part->rect.right = part->rect.left + textsize->cx;
1443 line->rect.right = part->rect.right;
1445 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1446 part->rect.bottom = part->rect.top + textsize->cy;
1447 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1448 part->u.text.lpsText = ptr;
1449 part->u.text.wTextLen = textlen;
1450 part->u.text.hFont = font;
1451 part->u.text.color = color;
1452 part->u.text.wUnderline = underline;
1454 WINE_TRACE("Appended text '%*.*s'[%d] @ (%d,%d-%d,%d)\n",
1455 part->u.text.wTextLen,
1456 part->u.text.wTextLen,
1457 part->u.text.lpsText,
1458 part->u.text.wTextLen,
1459 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1462 if (link) link->wRefCount++;
1465 *partp = &part->next;
1472 /***********************************************************************
1474 * WINHELP_AppendGfxObject
1476 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1477 LPSIZE space, LPSIZE gfxSize,
1478 HLPFILE_LINK *link, unsigned pos)
1481 WINHELP_LINE_PART *part;
1484 if (!*partp || pos == 1) /* New line */
1486 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1487 if (!line) return NULL;
1490 part = &line->first_part;
1492 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1493 line->rect.bottom = line->rect.top;
1494 line->rect.left = space->cx;
1495 line->rect.right = space->cx;
1497 if (**linep) *linep = &(**linep)->next;
1500 ptr = (char*)line + sizeof(WINHELP_LINE);
1502 else /* Same line */
1504 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1507 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1508 if (!part) return NULL;
1510 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1513 /* part->cookie should be set by caller (image or metafile) */
1514 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1515 part->rect.right = part->rect.left + gfxSize->cx;
1516 line->rect.right = part->rect.right;
1517 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1518 part->rect.bottom = part->rect.top + gfxSize->cy;
1519 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1521 WINE_TRACE("Appended gfx @ (%d,%d-%d,%d)\n",
1522 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1525 if (link) link->wRefCount++;
1528 *partp = &part->next;
1536 /***********************************************************************
1538 * WINHELP_SplitLines
1540 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1542 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1543 HLPFILE_PARAGRAPH *p;
1544 WINHELP_LINE **line = &win->first_line;
1545 WINHELP_LINE_PART **part = 0;
1546 INT line_ascent = 0;
1551 if (newsize) newsize->cx = newsize->cy = 0;
1553 if (!win->page) return TRUE;
1555 WINHELP_DeleteLines(win);
1557 GetClientRect(hWnd, &rect);
1559 rect.top += INTERNAL_BORDER_WIDTH;
1560 rect.left += INTERNAL_BORDER_WIDTH;
1561 rect.right -= INTERNAL_BORDER_WIDTH;
1562 rect.bottom -= INTERNAL_BORDER_WIDTH;
1564 space.cy = rect.top;
1565 space.cx = rect.left;
1569 for (p = win->page->first_paragraph; p; p = p->next)
1573 case para_normal_text:
1574 case para_debug_text:
1577 SIZE textsize = {0, 0};
1578 LPCSTR text = p->u.text.lpszText;
1580 UINT len = strlen(text);
1581 unsigned underline = 0;
1584 COLORREF color = RGB(0, 0, 0);
1586 if (p->u.text.wFont < win->page->file->numFonts)
1588 HLPFILE* hlpfile = win->page->file;
1590 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1591 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1592 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1593 color = hlpfile->fonts[p->u.text.wFont].color;
1597 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1599 hFont = win->fonts[wFont];
1602 if (p->link && p->link->bClrChange)
1604 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1605 color = RGB(0, 0x80, 0);
1607 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1609 SelectObject(hDc, hFont);
1611 GetTextMetrics(hDc, &tm);
1613 if (p->u.text.wIndent)
1615 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1617 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1620 if (p->u.text.wVSpace)
1623 space.cx = rect.left + indent;
1624 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1627 if (p->u.text.wHSpace)
1629 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1632 WINE_TRACE("splitting text %s\n", text);
1636 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1637 UINT low = 0, curr = len, high = len, textlen = 0;
1643 GetTextExtentPoint(hDc, text, curr, &textsize);
1645 if (textsize.cx <= free_width) low = curr;
1648 if (high <= low + 1) break;
1650 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1651 if (curr <= low) curr = low + 1;
1652 else if (curr >= high) curr = high - 1;
1655 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1657 if (!part && !textlen) textlen = max(low, 1);
1659 if (free_width <= 0 || !textlen)
1662 space.cx = rect.left + indent;
1663 space.cx = min(space.cx, rect.right - rect.left - 1);
1667 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1669 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1670 &line_ascent, tm.tmAscent,
1671 text, textlen, hFont, color, p->link, underline) ||
1672 (!newsize && (*line)->rect.bottom > rect.bottom))
1674 ReleaseDC(hWnd, hDc);
1679 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1683 if (text[0] == ' ') text++, len--;
1692 WINHELP_LINE_PART* ref_part;
1694 if (p->u.gfx.pos & 0x8000)
1696 space.cx = rect.left;
1698 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1702 if (p->cookie == para_bitmap)
1706 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1707 gfxSize.cx = dibs.dsBm.bmWidth;
1708 gfxSize.cy = dibs.dsBm.bmHeight;
1712 LPMETAFILEPICT lpmfp = &p->u.gfx.u.mfp;
1713 if (lpmfp->mm == MM_ANISOTROPIC || lpmfp->mm == MM_ISOTROPIC)
1715 gfxSize.cx = MulDiv(lpmfp->xExt, GetDeviceCaps(hDc, HORZRES),
1716 100*GetDeviceCaps(hDc, HORZSIZE));
1717 gfxSize.cy = MulDiv(lpmfp->yExt, GetDeviceCaps(hDc, VERTRES),
1718 100*GetDeviceCaps(hDc, VERTSIZE));
1722 gfxSize.cx = lpmfp->xExt;
1723 gfxSize.cy = lpmfp->yExt;
1727 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1728 if (free_width <= 0)
1731 space.cx = rect.left;
1732 space.cx = min(space.cx, rect.right - rect.left - 1);
1734 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1735 p->link, p->u.gfx.pos);
1736 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1740 if (p->cookie == para_bitmap)
1742 ref_part->cookie = hlp_line_part_bitmap;
1743 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1747 ref_part->cookie = hlp_line_part_metafile;
1748 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mfp.hMF;
1749 ref_part->u.metafile.mm = p->u.gfx.u.mfp.mm;
1757 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1759 ReleaseDC(hWnd, hDc);
1763 /***********************************************************************
1765 * WINHELP_CheckPopup
1767 static void WINHELP_CheckPopup(UINT msg)
1769 if (!Globals.hPopupWnd) return;
1774 case WM_LBUTTONDOWN:
1775 case WM_MBUTTONDOWN:
1776 case WM_RBUTTONDOWN:
1777 case WM_NCLBUTTONDOWN:
1778 case WM_NCMBUTTONDOWN:
1779 case WM_NCRBUTTONDOWN:
1780 DestroyWindow(Globals.hPopupWnd);
1781 Globals.hPopupWnd = 0;
1785 /***********************************************************************
1787 * WINHELP_DeleteLines
1789 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1791 WINHELP_LINE *line, *next_line;
1792 WINHELP_LINE_PART *part, *next_part;
1793 for (line = win->first_line; line; line = next_line)
1795 next_line = line->next;
1796 for (part = &line->first_part; part; part = next_part)
1798 next_part = part->next;
1799 HLPFILE_FreeLink(part->link);
1800 HeapFree(GetProcessHeap(), 0, part);
1803 win->first_line = 0;
1806 /******************************************************************
1807 * WINHELP_DeleteButtons
1810 static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
1815 for (b = win->first_button; b; b = bp)
1817 DestroyWindow(b->hWnd);
1819 HeapFree(GetProcessHeap(), 0, b);
1821 win->first_button = NULL;
1824 /******************************************************************
1825 * WINHELP_DeleteBackSet
1828 void WINHELP_DeleteBackSet(WINHELP_WINDOW* win)
1832 for (i = 0; i < win->back.index; i++)
1834 HLPFILE_FreeHlpFile(win->back.set[i].page->file);
1835 win->back.set[i].page = NULL;
1837 win->back.index = 0;
1840 /***********************************************************************
1842 * WINHELP_DeleteWindow
1844 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1848 for (w = &Globals.win_list; *w; w = &(*w)->next)
1857 if (Globals.active_win == win)
1859 Globals.active_win = Globals.win_list;
1860 if (Globals.win_list)
1861 SetActiveWindow(Globals.win_list->hMainWnd);
1864 WINHELP_DeleteButtons(win);
1866 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1867 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1869 DeleteObject(win->hBrush);
1871 WINHELP_DeleteBackSet(win);
1873 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1874 WINHELP_DeleteLines(win);
1875 HeapFree(GetProcessHeap(), 0, win);
1878 /***********************************************************************
1882 static void WINHELP_InitFonts(HWND hWnd)
1884 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1885 LOGFONT logfontlist[] = {
1886 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1887 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1888 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1889 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1890 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1891 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1892 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
1893 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1895 static HFONT fonts[FONTS_LEN];
1896 static BOOL init = 0;
1898 win->fonts_len = FONTS_LEN;
1905 for (i = 0; i < FONTS_LEN; i++)
1907 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1914 /***********************************************************************
1916 * WINHELP_MessageBoxIDS
1918 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1920 CHAR text[MAX_STRING_LEN];
1921 CHAR title[MAX_STRING_LEN];
1923 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1924 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1926 return MessageBox(0, text, title, type);
1929 /***********************************************************************
1931 * MAIN_MessageBoxIDS_s
1933 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1935 CHAR text[MAX_STRING_LEN];
1936 CHAR title[MAX_STRING_LEN];
1937 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
1939 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1940 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1941 wsprintf(newtext, text, str);
1943 return MessageBox(0, newtext, title, type);
1946 /******************************************************************
1947 * WINHELP_IsOverLink
1951 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1955 WINHELP_LINE_PART *part;
1956 int scroll_pos = GetScrollPos(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), SB_VERT);
1958 mouse.x = LOWORD(lParam);
1959 mouse.y = HIWORD(lParam);
1960 for (line = win->first_line; line; line = line->next)
1962 for (part = &line->first_part; part; part = part->next)
1965 part->link->lpszString &&
1966 part->rect.left <= mouse.x &&
1967 part->rect.right >= mouse.x &&
1968 part->rect.top <= mouse.y + scroll_pos &&
1969 part->rect.bottom >= mouse.y + scroll_pos)
1979 /**************************************************************************
1982 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1985 static void cb_KWBTree(void *p, void **next, void *cookie)
1987 HWND hListWnd = (HWND)cookie;
1990 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
1991 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
1992 count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0);
1993 SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p);
1994 *next = (char*)p + strlen((char*)p) + 7;
1997 /**************************************************************************
1998 * WINHELP_IndexDlgProc
2000 * Index dialog callback function.
2002 * nResult passed to EndDialog:
2004 * >1: valid offset value +2.
2005 * EndDialog itself can return 0 (error).
2007 INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
2009 static HLPFILE *file;
2016 file = (HLPFILE *)lParam;
2017 HLPFILE_BPTreeEnum(file->kwbtree, cb_KWBTree,
2018 GetDlgItem(hWnd, IDC_INDEXLIST));
2021 switch (LOWORD(wParam))
2024 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
2030 p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST,
2031 LB_GETITEMDATA, sel, 0);
2032 count = *(short*)((char *)p + strlen((char *)p) + 1);
2035 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
2038 offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
2039 offset = *(long*)(file->kwdata + offset + 9);
2040 if (offset == 0xFFFFFFFF)
2042 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
2049 EndDialog(hWnd, offset);
2060 /**************************************************************************
2061 * WINHELP_CreateIndexWindow
2063 * Displays a dialog with keywords of current help file.
2066 BOOL WINHELP_CreateIndexWindow(void)
2071 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
2072 hlpfile = Globals.active_win->page->file;
2076 if (hlpfile->kwbtree == NULL)
2078 WINE_TRACE("No index provided\n");
2082 ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_INDEX),
2083 Globals.active_win->hMainWnd, WINHELP_SearchDlgProc,
2088 WINE_TRACE("got %d as an offset\n", ret);
2089 WINHELP_CreateHelpWindowByOffset(hlpfile, ret, Globals.active_win->info, SW_NORMAL);