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
30 #define NONAMELESSUNION
31 #define NONAMELESSSTRUCT
39 #include "winhelp_res.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
48 static BOOL WINHELP_RegisterWinClasses(void);
49 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
50 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
51 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
52 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
53 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
54 static BOOL WINHELP_CheckPopup(HWND, UINT, WPARAM, LPARAM, LRESULT*);
55 static void WINHELP_InitFonts(HWND hWnd);
56 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
57 static void WINHELP_DeleteButtons(WINHELP_WINDOW*);
58 static void WINHELP_SetupText(HWND hWnd, WINHELP_WINDOW *win, ULONG relative);
59 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page);
61 WINHELP_GLOBALS Globals = {3, NULL, TRUE, NULL, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}};
63 #define CTL_ID_BUTTON 0x700
64 #define CTL_ID_TEXT 0x701
66 /***********************************************************************
68 * WINHELP_GetOpenFileName
70 BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len)
72 OPENFILENAME openfilename;
74 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
79 LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
83 LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
89 GetCurrentDirectory(sizeof(szDir), szDir);
93 openfilename.lStructSize = sizeof(OPENFILENAME);
94 openfilename.hwndOwner = NULL;
95 openfilename.hInstance = Globals.hInstance;
96 openfilename.lpstrFilter = szzFilter;
97 openfilename.lpstrCustomFilter = 0;
98 openfilename.nMaxCustFilter = 0;
99 openfilename.nFilterIndex = 1;
100 openfilename.lpstrFile = lpszFile;
101 openfilename.nMaxFile = len;
102 openfilename.lpstrFileTitle = 0;
103 openfilename.nMaxFileTitle = 0;
104 openfilename.lpstrInitialDir = szDir;
105 openfilename.lpstrTitle = 0;
106 openfilename.Flags = 0;
107 openfilename.nFileOffset = 0;
108 openfilename.nFileExtension = 0;
109 openfilename.lpstrDefExt = 0;
110 openfilename.lCustData = 0;
111 openfilename.lpfnHook = 0;
112 openfilename.lpTemplateName = 0;
114 return GetOpenFileName(&openfilename);
117 static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage)
119 if (wpage->wininfo->caption[0]) return wpage->wininfo->caption;
120 return wpage->page->file->lpszTitle;
123 /***********************************************************************
125 * WINHELP_LookupHelpFile
127 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
130 char szFullName[MAX_PATH];
131 char szAddPath[MAX_PATH];
135 * NOTE: This is needed by popup windows only.
136 * In other cases it's not needed but does not hurt though.
138 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
140 strcpy(szAddPath, Globals.active_win->page->file->lpszPath);
141 p = strrchr(szAddPath, '\\');
146 * FIXME: Should we swap conditions?
148 if (!SearchPath(NULL, lpszFile, ".hlp", MAX_PATH, szFullName, NULL) &&
149 !SearchPath(szAddPath, lpszFile, ".hlp", MAX_PATH, szFullName, NULL))
151 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s, lpszFile, STID_WHERROR,
152 MB_YESNO|MB_ICONQUESTION) != IDYES)
154 if (!WINHELP_GetOpenFileName(szFullName, MAX_PATH))
157 hlpfile = HLPFILE_ReadHlpFile(szFullName);
159 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile,
160 STID_WHERROR, MB_OK|MB_ICONSTOP);
164 /******************************************************************
165 * WINHELP_GetWindowInfo
169 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
171 static HLPFILE_WINDOWINFO mwi;
174 if (!name || !name[0])
175 name = Globals.active_win->lpszName;
178 for (i = 0; i < hlpfile->numWindows; i++)
179 if (!strcmp(hlpfile->windows[i].name, name))
180 return &hlpfile->windows[i];
182 if (strcmp(name, "main") != 0)
184 WINE_FIXME("Couldn't find window info for %s\n", name);
190 strcpy(mwi.type, "primary");
191 strcpy(mwi.name, "main");
192 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
193 mwi.caption, sizeof(mwi.caption)))
194 strcpy(mwi.caption, hlpfile->lpszTitle);
195 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
197 mwi.win_style = WS_OVERLAPPEDWINDOW;
198 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
203 /******************************************************************
204 * HLPFILE_GetPopupWindowInfo
208 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile,
209 WINHELP_WINDOW* parent, LPARAM mouse)
211 static HLPFILE_WINDOWINFO wi;
215 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
217 /* Calculate horizontal size and position of a popup window */
218 GetWindowRect(parent->hMainWnd, &parent_rect);
219 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
220 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
222 wi.origin.x = (short)LOWORD(mouse);
223 wi.origin.y = (short)HIWORD(mouse);
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 if (LoadLibrary("riched20.dll") == NULL)
253 return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT),
254 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
257 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
261 if (*cmdline++ == ' ') continue;
264 if (option) cmdline++;
265 while (*cmdline && *cmdline == ' ') cmdline++;
271 while (*cmdline && *cmdline != ' ') cmdline++;
272 if (*cmdline) *cmdline++ = '\0';
273 lHash = HLPFILE_Hash(topic_id);
278 Globals.wVersion = option - '0';
283 Globals.isBook = FALSE;
287 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
292 /* Create primary window */
293 if (!WINHELP_RegisterWinClasses())
295 WINE_FIXME("Couldn't register classes\n");
302 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
307 if ((ptr = strchr(cmdline, '>')))
312 hlpfile = WINHELP_LookupHelpFile(cmdline);
313 if (!hlpfile) return 0;
316 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
317 WINHELP_GetWindowInfo(hlpfile, wndname), show);
320 while (GetMessage(&msg, 0, 0, 0))
322 TranslateMessage(&msg);
323 DispatchMessage(&msg);
325 for (dll = Globals.dlls; dll; dll = dll->next)
327 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
332 /***********************************************************************
336 static BOOL WINHELP_RegisterWinClasses(void)
338 WNDCLASS class_main, class_button_box, class_shadow, class_history;
340 class_main.style = CS_HREDRAW | CS_VREDRAW;
341 class_main.lpfnWndProc = WINHELP_MainWndProc;
342 class_main.cbClsExtra = 0;
343 class_main.cbWndExtra = sizeof(LONG);
344 class_main.hInstance = Globals.hInstance;
345 class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
346 class_main.hCursor = LoadCursor(0, IDC_ARROW);
347 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
348 class_main.lpszMenuName = 0;
349 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
351 class_button_box = class_main;
352 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
353 class_button_box.cbWndExtra = 0;
354 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
355 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
357 class_shadow = class_main;
358 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
359 class_shadow.cbWndExtra = 0;
360 class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
361 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
363 class_history = class_main;
364 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
365 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
367 return (RegisterClass(&class_main) &&
368 RegisterClass(&class_button_box) &&
369 RegisterClass(&class_shadow) &&
370 RegisterClass(&class_history));
381 } WINHELP,*LPWINHELP;
383 static BOOL WINHELP_HasWorkingWindow(void)
385 if (!Globals.active_win) return FALSE;
386 if (Globals.active_win->next || Globals.win_list != Globals.active_win) return TRUE;
387 return Globals.active_win->page != NULL && Globals.active_win->page->file != NULL;
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);
421 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
429 MACRO_JumpContents(ptr, "main");
431 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
433 case HELP_HELPONHELP:
435 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
437 /* case HELP_SETINDEX: */
438 case HELP_SETCONTENTS:
441 MACRO_SetContents(ptr, wh->data);
444 case HELP_CONTEXTPOPUP:
447 MACRO_PopupContext(ptr, wh->data);
450 /* case HELP_FORCEFILE:*/
451 /* case HELP_CONTEXTMENU: */
453 /* in fact, should be the topic dialog box */
454 WINE_FIXME("HELP_FINDER: stub\n");
457 MACRO_JumpHash(ptr, "main", 0);
460 /* case HELP_WM_HELP: */
461 /* case HELP_SETPOPUP_POS: */
463 /* case HELP_COMMAND: */
464 /* case HELP_PARTIALKEY: */
465 /* case HELP_MULTIKEY: */
466 /* case HELP_SETWINPOS: */
468 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
472 /* Always return success for now */
476 void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
478 RECT rect, button_box_rect;
480 HWND hButtonBoxWnd = GetDlgItem(win->hMainWnd, CTL_ID_BUTTON);
481 HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
483 GetClientRect(win->hMainWnd, &rect);
485 /* Update button box and text Window */
486 SetWindowPos(hButtonBoxWnd, HWND_TOP,
488 rect.right - rect.left,
489 rect.bottom - rect.top, 0);
491 if (GetWindowRect(hButtonBoxWnd, &button_box_rect))
492 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
494 SetWindowPos(hTextWnd, HWND_TOP,
496 rect.right - rect.left,
497 rect.bottom - text_top, 0);
501 static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage)
505 if (!Globals.history.index || Globals.history.set[0].page != wpage->page)
507 num = sizeof(Globals.history.set) / sizeof(Globals.history.set[0]);
508 /* we're full, remove latest entry */
509 if (Globals.history.index == num)
511 HLPFILE_FreeHlpFile(Globals.history.set[num - 1].page->file);
512 Globals.history.index--;
514 memmove(&Globals.history.set[1], &Globals.history.set[0],
515 Globals.history.index * sizeof(Globals.history.set[0]));
516 Globals.history.set[0] = *wpage;
517 Globals.history.index++;
518 wpage->page->file->wRefCount++;
520 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
522 num = sizeof(win->back.set) / sizeof(win->back.set[0]);
523 if (win->back.index == num)
525 /* we're full, remove latest entry */
526 HLPFILE_FreeHlpFile(win->back.set[0].page->file);
527 memmove(&win->back.set[0], &win->back.set[1],
528 (num - 1) * sizeof(win->back.set[0]));
531 win->back.set[win->back.index++] = *wpage;
532 wpage->page->file->wRefCount++;
535 /***********************************************************************
537 * WINHELP_CreateHelpWindow
539 BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remember)
541 WINHELP_WINDOW* win = NULL;
542 BOOL bPrimary, bPopup, bReUsed = FALSE;
545 HWND hTextWnd = NULL;
547 bPrimary = !lstrcmpi(wpage->wininfo->name, "main");
548 bPopup = !bPrimary && (wpage->wininfo->win_style & WS_POPUP);
552 for (win = Globals.win_list; win; win = win->next)
554 if (!lstrcmpi(win->lpszName, wpage->wininfo->name))
558 DWORD flags = SWP_NOSIZE | SWP_NOMOVE;
560 WINHELP_DeleteButtons(win);
562 SetWindowText(win->hMainWnd, WINHELP_GetCaption(wpage));
563 if (wpage->wininfo->origin.x != CW_USEDEFAULT &&
564 wpage->wininfo->origin.y != CW_USEDEFAULT)
566 pt = wpage->wininfo->origin;
567 flags &= ~SWP_NOSIZE;
569 if (wpage->wininfo->size.cx != CW_USEDEFAULT &&
570 wpage->wininfo->size.cy != CW_USEDEFAULT)
572 sz = wpage->wininfo->size;
573 flags &= ~SWP_NOMOVE;
575 SetWindowPos(win->hMainWnd, HWND_TOP, pt.x, pt.y, sz.cx, sz.cy, flags);
577 if (wpage->page && win->page && wpage->page->file != win->page->file)
578 WINHELP_DeleteBackSet(win);
579 WINHELP_InitFonts(win->hMainWnd);
581 win->page = wpage->page;
582 win->info = wpage->wininfo;
583 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
584 WINHELP_SetupText(hTextWnd, win, wpage->relative);
586 InvalidateRect(win->hMainWnd, NULL, TRUE);
587 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
596 /* Initialize WINHELP_WINDOW struct */
597 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
598 sizeof(WINHELP_WINDOW) + strlen(wpage->wininfo->name) + 1);
599 if (!win) return FALSE;
600 win->next = Globals.win_list;
601 Globals.win_list = win;
603 name = (char*)win + sizeof(WINHELP_WINDOW);
604 lstrcpy(name, wpage->wininfo->name);
605 win->lpszName = name;
606 win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
610 win->page = wpage->page;
611 win->info = wpage->wininfo;
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_TOPICS, buffer, sizeof(buffer));
636 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
641 win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
642 WINHELP_GetCaption(wpage),
643 bPrimary ? WS_OVERLAPPEDWINDOW : wpage->wininfo->win_style,
644 wpage->wininfo->origin.x, wpage->wininfo->origin.y,
645 wpage->wininfo->size.cx, wpage->wininfo->size.cy,
646 bPopup ? Globals.active_win->hMainWnd : NULL,
647 bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
648 Globals.hInstance, win);
650 /* Create button box and text Window */
651 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
652 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
654 hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
655 ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
656 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
657 SendMessage(hTextWnd, EM_SETEVENTMASK, 0,
658 SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0) | ENM_MOUSEEVENTS);
661 hIcon = (wpage->page) ? wpage->page->file->hIcon : NULL;
662 if (!hIcon) hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
663 SendMessage(win->hMainWnd, WM_SETICON, ICON_SMALL, (DWORD_PTR)hIcon);
665 /* Initialize file specific pushbuttons */
666 if (!(wpage->wininfo->win_style & WS_POPUP) && wpage->page)
668 HLPFILE_MACRO *macro;
669 for (macro = wpage->page->file->first_macro; macro; macro = macro->next)
670 MACRO_ExecuteMacro(macro->lpszMacro);
672 for (macro = wpage->page->first_macro; macro; macro = macro->next)
673 MACRO_ExecuteMacro(macro->lpszMacro);
678 DWORD mask = SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0);
681 win->font_scale = Globals.active_win->font_scale;
682 WINHELP_SetupText(hTextWnd, win, wpage->relative);
684 /* we need the window to be shown for richedit to compute the size */
685 ShowWindow(win->hMainWnd, nCmdShow);
686 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask | ENM_REQUESTRESIZE);
687 SendMessage(hTextWnd, EM_REQUESTRESIZE, 0, 0);
688 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask);
690 GetWindowRect(win->hMainWnd, &rect);
691 win->hShadowWnd = CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME,
692 "", WS_POPUP | WS_VISIBLE,
693 rect.left + SHADOW_DX, rect.top + SHADOW_DY,
694 rect.right - rect.left,
695 rect.bottom - rect.top,
696 Globals.active_win->hMainWnd, 0,
697 Globals.hInstance, NULL);
698 SetWindowPos(win->hMainWnd, win->hShadowWnd, 0, 0, 0, 0,
699 SWP_NOSIZE | SWP_NOMOVE);
703 WINHELP_SetupText(hTextWnd, win, wpage->relative);
704 WINHELP_LayoutMainWindow(win);
705 ShowWindow(win->hMainWnd, nCmdShow);
711 /******************************************************************
712 * WINHELP_OpenHelpWindow
713 * Main function to search for a page and display it in a window
715 BOOL WINHELP_OpenHelpWindow(HLPFILE_PAGE* (*lookup)(HLPFILE*, LONG, ULONG*),
716 HLPFILE* hlpfile, LONG val, HLPFILE_WINDOWINFO* wi,
719 WINHELP_WNDPAGE wpage;
721 wpage.page = lookup(hlpfile, val, &wpage.relative);
722 if (wpage.page) wpage.page->file->wRefCount++;
724 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
727 /***********************************************************************
731 static HLPFILE_LINK* WINHELP_FindLink(WINHELP_WINDOW* win, LPARAM pos)
734 POINTL mouse_ptl, char_ptl, char_next_ptl;
737 if (!win->page) return NULL;
739 mouse_ptl.x = (short)LOWORD(pos);
740 mouse_ptl.y = (short)HIWORD(pos);
741 cp = SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_CHARFROMPOS,
742 0, (LPARAM)&mouse_ptl);
744 for (link = win->page->first_link; link; link = link->next)
746 if (link->cpMin <= cp && cp <= link->cpMax)
748 /* check whether we're at end of line */
749 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
750 (LPARAM)&char_ptl, cp);
751 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
752 (LPARAM)&char_next_ptl, cp + 1);
753 if (char_next_ptl.y != char_ptl.y || mouse_ptl.x >= char_next_ptl.x)
761 /******************************************************************
762 * WINHELP_HandleTextMouse
765 static BOOL WINHELP_HandleTextMouse(WINHELP_WINDOW* win, UINT msg, LPARAM lParam)
774 if (WINHELP_FindLink(win, lParam))
775 SetCursor(win->hHandCur);
777 SetCursor(LoadCursor(0, IDC_ARROW));
781 if ((win->current_link = WINHELP_FindLink(win, lParam)))
786 if ((link = WINHELP_FindLink(win, lParam)) && link == win->current_link)
788 HLPFILE_WINDOWINFO* wi;
790 switch (link->cookie)
793 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
795 if (link->window == -1)
797 else if (link->window < hlpfile->numWindows)
798 wi = &hlpfile->windows[link->window];
801 WINE_WARN("link to window %d/%d\n", link->window, hlpfile->numWindows);
804 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash, wi, SW_NORMAL);
808 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
809 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash,
810 WINHELP_GetPopupWindowInfo(hlpfile, win, lParam),
814 MACRO_ExecuteMacro(link->string);
817 WINE_FIXME("Unknown link cookie %d\n", link->cookie);
821 win->current_link = NULL;
827 /***********************************************************************
829 * WINHELP_MainWndProc
831 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
834 WINHELP_BUTTON *button;
836 INT curPos, min, max, dy, keyDelta;
840 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, &ret)) return ret;
845 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
846 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
847 if (!win->page && Globals.isBook)
848 PostMessage(hWnd, WM_COMMAND, MNID_FILE_OPEN, 0);
849 win->hMainWnd = hWnd;
852 case WM_WINDOWPOSCHANGED:
853 WINHELP_LayoutMainWindow((WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0));
857 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
861 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
862 case MNID_FILE_PRINT: MACRO_Print(); break;
863 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
864 case MNID_FILE_EXIT: MACRO_Exit(); break;
867 case MNID_EDIT_COPYDLG:
868 SendMessage(GetDlgItem(hWnd, CTL_ID_TEXT), WM_COPY, 0, 0);
870 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
873 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
876 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
877 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
878 case MNID_HELP_ABOUT: MACRO_About(); break;
879 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
882 case MNID_CTXT_ANNOTATE:MACRO_Annotate(); break;
883 case MNID_CTXT_COPY: MACRO_CopyDialog(); break;
884 case MNID_CTXT_PRINT: MACRO_Print(); break;
885 case MNID_OPTS_HISTORY: MACRO_History(); break;
886 case MNID_OPTS_FONTS_SMALL:
887 case MNID_CTXT_FONTS_SMALL:
888 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
889 if (win->font_scale != 0)
892 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
895 case MNID_OPTS_FONTS_NORMAL:
896 case MNID_CTXT_FONTS_NORMAL:
897 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
898 if (win->font_scale != 1)
901 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
904 case MNID_OPTS_FONTS_LARGE:
905 case MNID_CTXT_FONTS_LARGE:
906 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
907 if (win->font_scale != 2)
910 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
913 case MNID_OPTS_HELP_DEFAULT:
914 case MNID_OPTS_HELP_VISIBLE:
915 case MNID_OPTS_HELP_NONVISIBLE:
916 case MNID_OPTS_SYSTEM_COLORS:
917 case MNID_CTXT_HELP_DEFAULT:
918 case MNID_CTXT_HELP_VISIBLE:
919 case MNID_CTXT_HELP_NONVISIBLE:
920 case MNID_CTXT_SYSTEM_COLORS:
925 for (button = win->first_button; button; button = button->next)
926 if (wParam == button->wParam) break;
928 MACRO_ExecuteMacro(button->lpszMacro);
929 else if (!HIWORD(wParam))
930 MessageBox(0, MAKEINTRESOURCE(STID_NOT_IMPLEMENTED),
931 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
935 /* EPP case WM_DESTROY: */
936 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
939 return WINHELP_HandleCommand((HWND)wParam, lParam);
944 SendMessage(GetDlgItem(hWnd, CTL_ID_TEXT), WM_COPY, 0, 0);
956 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
958 keyDelta = -keyDelta;
962 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
963 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
964 curPos = GetScrollPos(hTextWnd, SB_VERT);
965 GetScrollRange(hTextWnd, SB_VERT, &min, &max);
969 GetClientRect(hTextWnd, &rect);
970 keyDelta = (rect.bottom - rect.top) / 2;
971 if (wParam == VK_PRIOR)
972 keyDelta = -keyDelta;
978 else if (curPos < min)
981 dy = GetScrollPos(hTextWnd, SB_VERT) - curPos;
982 SetScrollPos(hTextWnd, SB_VERT, curPos, TRUE);
983 ScrollWindow(hTextWnd, 0, dy, NULL, NULL);
984 UpdateWindow(hTextWnd);
994 if (wParam == CTL_ID_TEXT)
998 switch (((NMHDR*)lParam)->code)
1002 const MSGFILTER* msgf = (const MSGFILTER*)lParam;
1006 if (msgf->wParam == VK_ESCAPE) DestroyWindow(hWnd);
1008 case WM_RBUTTONDOWN:
1013 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1014 hMenu = LoadMenu(Globals.hInstance, (LPSTR)CONTEXT_MENU);
1015 switch (win->font_scale)
1018 CheckMenuItem(hMenu, MNID_CTXT_FONTS_SMALL,
1019 MF_BYCOMMAND|MF_CHECKED);
1022 WINE_FIXME("Unsupported %d\n", win->font_scale);
1024 CheckMenuItem(hMenu, MNID_CTXT_FONTS_NORMAL,
1025 MF_BYCOMMAND|MF_CHECKED);
1028 CheckMenuItem(hMenu, MNID_CTXT_FONTS_LARGE,
1029 MF_BYCOMMAND|MF_CHECKED);
1032 pt.x = (int)(short)LOWORD(msgf->lParam);
1033 pt.y = (int)(short)HIWORD(msgf->lParam);
1034 ClientToScreen(msgf->nmhdr.hwndFrom, &pt);
1035 TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_LEFTALIGN|TPM_TOPALIGN,
1036 pt.x, pt.y, 0, hWnd, NULL);
1041 return WINHELP_HandleTextMouse((WINHELP_WINDOW*)GetWindowLongPtr(hWnd, 0),
1042 msgf->msg, msgf->lParam);
1047 case EN_REQUESTRESIZE:
1048 rc = ((REQRESIZE*)lParam)->rc;
1049 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1050 AdjustWindowRect(&rc, GetWindowLong(win->hMainWnd, GWL_STYLE),
1052 SetWindowPos(win->hMainWnd, HWND_TOP, 0, 0,
1053 rc.right - rc.left, rc.bottom - rc.top,
1054 SWP_NOMOVE | SWP_NOZORDER);
1055 WINHELP_LayoutMainWindow(win);
1061 case WM_INITMENUPOPUP:
1062 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1063 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_SMALL,
1064 MF_BYCOMMAND | (win->font_scale == 0) ? MF_CHECKED : 0);
1065 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_NORMAL,
1066 MF_BYCOMMAND | (win->font_scale == 1) ? MF_CHECKED : 0);
1067 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_LARGE,
1068 MF_BYCOMMAND | (win->font_scale == 2) ? MF_CHECKED : 0);
1074 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1075 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1076 WINHELP_DeleteWindow(win);
1078 if (bExit) MACRO_Exit();
1079 if (!Globals.win_list)
1084 return DefWindowProc(hWnd, msg, wParam, lParam);
1087 static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff,
1090 struct RtfData* rd = (struct RtfData*)cookie;
1092 if (rd->where >= rd->ptr) return 1;
1093 if (rd->where + cb > rd->ptr)
1094 cb = rd->ptr - rd->where;
1095 memcpy(buff, rd->where, cb);
1101 static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative)
1103 SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0);
1104 SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color);
1105 /* set word-wrap to window size (undocumented) */
1106 SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0);
1116 if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative))
1119 es.dwCookie = (DWORD_PTR)&rd;
1121 es.pfnCallback = WINHELP_RtfStreamIn;
1123 SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
1124 cp = rd.char_pos_rel;
1126 /* FIXME: else leaking potentially the rd.first_link chain */
1127 HeapFree(GetProcessHeap(), 0, rd.data);
1128 SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0);
1129 pt.x = 0; pt.y = ptl.y;
1130 SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt);
1134 SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)"");
1136 SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0);
1137 InvalidateRect(hTextWnd, NULL, TRUE);
1140 /***********************************************************************
1142 * WINHELP_ButtonBoxWndProc
1144 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1147 WINHELP_WINDOW *win;
1148 WINHELP_BUTTON *button;
1152 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0L;
1156 case WM_WINDOWPOSCHANGING:
1157 winpos = (WINDOWPOS*) lParam;
1158 win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0);
1160 /* Update buttons */
1163 for (button = win->first_button; button; button = button->next)
1169 button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName,
1170 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
1172 hWnd, (HMENU) button->wParam,
1173 Globals.hInstance, 0);
1175 if (Globals.button_proc == NULL)
1176 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
1177 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
1180 hDc = GetDC(button->hWnd);
1181 GetTextExtentPoint(hDc, button->lpszName,
1182 lstrlen(button->lpszName), &textsize);
1183 ReleaseDC(button->hWnd, hDc);
1185 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
1186 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
1191 for (button = win->first_button; button; button = button->next)
1193 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
1195 if (x + 2 * button_size.cx <= winpos->cx)
1196 x += button_size.cx;
1198 x = 0, y += button_size.cy;
1200 winpos->cy = y + (x ? button_size.cy : 0);
1204 SendMessage(GetParent(hWnd), msg, wParam, lParam);
1215 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1220 return DefWindowProc(hWnd, msg, wParam, lParam);
1223 /***********************************************************************
1225 * WINHELP_ButtonWndProc
1227 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1229 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1231 if (msg == WM_KEYDOWN)
1240 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1244 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
1247 /******************************************************************
1248 * WINHELP_HistoryWndProc
1252 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1254 WINHELP_WINDOW* win;
1264 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1265 SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win);
1266 win->hHistoryWnd = hWnd;
1269 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1271 GetTextMetrics(hDc, &tm);
1272 GetWindowRect(hWnd, &r);
1274 r.right = r.left + 30 * tm.tmAveCharWidth;
1275 r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight;
1276 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1277 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1278 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1280 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1281 ReleaseDC(hWnd, hDc);
1283 case WM_LBUTTONDOWN:
1284 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1286 GetTextMetrics(hDc, &tm);
1287 i = HIWORD(lParam) / tm.tmHeight;
1288 if (i < Globals.history.index)
1289 WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE);
1290 ReleaseDC(hWnd, hDc);
1293 hDc = BeginPaint(hWnd, &ps);
1294 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1295 GetTextMetrics(hDc, &tm);
1297 for (i = 0; i < Globals.history.index; i++)
1299 if (Globals.history.set[i].page->file == Globals.active_win->page->file)
1301 TextOut(hDc, 0, i * tm.tmHeight,
1302 Globals.history.set[i].page->lpszTitle,
1303 strlen(Globals.history.set[i].page->lpszTitle));
1312 ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\');
1313 if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath;
1315 ptr2 = strrchr(ptr1, '.');
1316 len = ptr2 ? ptr2 - ptr1 : strlen(ptr1);
1317 if (len > sizeof(buffer)) len = sizeof(buffer);
1318 memcpy(buffer, ptr1, len);
1319 if (len < sizeof(buffer)) buffer[len++] = ':';
1320 strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len);
1321 buffer[sizeof(buffer) - 1] = '\0';
1322 TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer));
1325 EndPaint(hWnd, &ps);
1328 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1329 if (hWnd == win->hHistoryWnd)
1330 win->hHistoryWnd = 0;
1333 return DefWindowProc(hWnd, msg, wParam, lParam);
1336 /***********************************************************************
1338 * WINHELP_ShadowWndProc
1340 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1342 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1343 return WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL) ? 0L : DefWindowProc(hWnd, msg, wParam, lParam);
1346 /***********************************************************************
1348 * WINHELP_CheckPopup
1350 static BOOL WINHELP_CheckPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* lret)
1354 if (!Globals.active_popup) return FALSE;
1360 MSGFILTER* msgf = (MSGFILTER*)lParam;
1361 if (msgf->nmhdr.code == EN_MSGFILTER)
1363 if (!WINHELP_CheckPopup(hWnd, msgf->msg, msgf->wParam, msgf->lParam, NULL))
1365 if (lret) *lret = 1;
1371 if (wParam != WA_INACTIVE || (HWND)lParam == Globals.active_win->hMainWnd ||
1372 (HWND)lParam == Globals.active_popup->hMainWnd ||
1373 GetWindow((HWND)lParam, GW_OWNER) == Globals.active_win->hMainWnd)
1376 case WM_LBUTTONDOWN:
1377 if (WINHELP_HandleTextMouse(Globals.active_popup, msg, lParam) && msg == WM_LBUTTONDOWN)
1380 case WM_MBUTTONDOWN:
1381 case WM_RBUTTONDOWN:
1382 case WM_NCLBUTTONDOWN:
1383 case WM_NCMBUTTONDOWN:
1384 case WM_NCRBUTTONDOWN:
1385 hPopup = Globals.active_popup->hMainWnd;
1386 Globals.active_popup = NULL;
1387 DestroyWindow(hPopup);
1393 /******************************************************************
1394 * WINHELP_DeleteButtons
1397 static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
1402 for (b = win->first_button; b; b = bp)
1404 DestroyWindow(b->hWnd);
1406 HeapFree(GetProcessHeap(), 0, b);
1408 win->first_button = NULL;
1411 /******************************************************************
1412 * WINHELP_DeleteBackSet
1415 void WINHELP_DeleteBackSet(WINHELP_WINDOW* win)
1419 for (i = 0; i < win->back.index; i++)
1421 HLPFILE_FreeHlpFile(win->back.set[i].page->file);
1422 win->back.set[i].page = NULL;
1424 win->back.index = 0;
1427 /******************************************************************
1428 * WINHELP_DeletePageLinks
1431 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page)
1436 for (curr = page->first_link; curr; curr = next)
1439 HeapFree(GetProcessHeap(), 0, curr);
1443 /***********************************************************************
1445 * WINHELP_DeleteWindow
1447 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1451 for (w = &Globals.win_list; *w; w = &(*w)->next)
1460 if (Globals.active_win == win)
1462 Globals.active_win = Globals.win_list;
1463 if (Globals.win_list)
1464 SetActiveWindow(Globals.win_list->hMainWnd);
1467 if (win == Globals.active_popup)
1468 Globals.active_popup = NULL;
1470 WINHELP_DeleteButtons(win);
1472 if (win->page) WINHELP_DeletePageLinks(win->page);
1473 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1474 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1476 DeleteObject(win->hBrush);
1478 WINHELP_DeleteBackSet(win);
1480 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1481 HeapFree(GetProcessHeap(), 0, win);
1484 /***********************************************************************
1488 static void WINHELP_InitFonts(HWND hWnd)
1490 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1491 LOGFONT logfontlist[] = {
1492 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1493 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1494 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1495 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1496 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1497 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1498 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
1499 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1501 static HFONT fonts[FONTS_LEN];
1502 static BOOL init = 0;
1504 win->fonts_len = FONTS_LEN;
1511 for (i = 0; i < FONTS_LEN; i++)
1513 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1520 /***********************************************************************
1522 * WINHELP_MessageBoxIDS_s
1524 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1526 CHAR text[MAX_STRING_LEN];
1527 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
1529 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1530 wsprintf(newtext, text, str);
1532 return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type);
1535 /**************************************************************************
1538 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1541 static void cb_KWBTree(void *p, void **next, void *cookie)
1543 HWND hListWnd = (HWND)cookie;
1546 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
1547 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
1548 count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0);
1549 SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p);
1550 *next = (char*)p + strlen((char*)p) + 7;
1560 /**************************************************************************
1561 * WINHELP_IndexDlgProc
1563 * Index dialog callback function.
1565 * nResult passed to EndDialog:
1567 * >1: valid offset value +2.
1568 * EndDialog itself can return 0 (error).
1570 INT_PTR CALLBACK WINHELP_IndexDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1572 static struct index_data* id;
1578 id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam;
1579 HLPFILE_BPTreeEnum(id->hlpfile->kwbtree, cb_KWBTree,
1580 GetDlgItem(hWnd, IDC_INDEXLIST));
1585 switch (((NMHDR*)lParam)->code)
1588 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
1594 p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST,
1595 LB_GETITEMDATA, sel, 0);
1596 count = *(short*)((char *)p + strlen((char *)p) + 1);
1599 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
1600 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID);
1603 id->offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
1604 id->offset = *(long*)(id->hlpfile->kwdata + id->offset + 9);
1605 if (id->offset == 0xFFFFFFFF)
1607 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
1608 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID);
1612 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR);
1625 /**************************************************************************
1626 * WINHELP_CreateIndexWindow
1628 * Displays a dialog with keywords of current help file.
1631 BOOL WINHELP_CreateIndexWindow(void)
1633 HPROPSHEETPAGE psPage[3];
1635 PROPSHEETHEADER psHead;
1636 struct index_data id;
1639 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
1640 id.hlpfile = Globals.active_win->page->file;
1644 if (id.hlpfile->kwbtree == NULL)
1646 WINE_TRACE("No index provided\n");
1650 InitCommonControls();
1653 memset(&psp, 0, sizeof(psp));
1654 psp.dwSize = sizeof(psp);
1656 psp.hInstance = Globals.hInstance;
1658 psp.u.pszTemplate = MAKEINTRESOURCE(IDD_INDEX);
1659 psp.lParam = (LPARAM)&id;
1660 psp.pfnDlgProc = WINHELP_IndexDlgProc;
1661 psPage[0] = CreatePropertySheetPage(&psp);
1663 memset(&psHead, 0, sizeof(psHead));
1664 psHead.dwSize = sizeof(psHead);
1666 LoadString(Globals.hInstance, STID_PSH_INDEX, buf, sizeof(buf));
1667 strcat(buf, Globals.active_win->info->caption);
1669 psHead.pszCaption = buf;
1671 psHead.hwndParent = Globals.active_win->hMainWnd;
1672 psHead.u3.phpage = psPage;
1673 psHead.dwFlags = PSH_NOAPPLYNOW;
1675 PropertySheet(&psHead);
1678 WINE_TRACE("got %d as an offset\n", id.offset);
1679 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset, id.hlpfile, id.offset,
1680 Globals.active_win->info, SW_NORMAL);