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>
8 * 2008 Kirill K. Smirnov <lich@math.spbu.ru>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
40 #include "winhelp_res.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
49 static BOOL WINHELP_RegisterWinClasses(void);
50 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
51 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
52 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
53 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
54 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
55 static BOOL WINHELP_CheckPopup(HWND, UINT, WPARAM, LPARAM, LRESULT*);
56 static void WINHELP_InitFonts(HWND hWnd);
57 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
58 static void WINHELP_DeleteButtons(WINHELP_WINDOW*);
59 static void WINHELP_SetupText(HWND hWnd, WINHELP_WINDOW *win, ULONG relative);
60 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page);
62 WINHELP_GLOBALS Globals = {3, NULL, TRUE, NULL, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}, NULL};
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, LPARAM 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 */
223 wi.origin.x = (short)LOWORD(mouse);
224 wi.origin.y = (short)HIWORD(mouse);
225 ClientToScreen(parent->hMainWnd, &wi.origin);
226 wi.origin.x -= wi.size.cx / 2;
227 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
228 wi.origin.x = max(wi.origin.x, 0);
231 wi.win_style = WS_POPUP | WS_BORDER;
232 if (parent->page->file->has_popup_color)
233 wi.sr_color = parent->page->file->popup_color;
235 wi.sr_color = parent->info->sr_color;
236 wi.nsr_color = 0xFFFFFF;
241 /***********************************************************************
245 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
250 static CHAR default_wndname[] = "main";
251 LPSTR wndname = default_wndname;
254 Globals.hInstance = hInstance;
256 if (LoadLibrary("riched20.dll") == NULL)
257 return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT),
258 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
261 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
265 if (*cmdline++ == ' ') continue;
268 if (option) cmdline++;
269 while (*cmdline && *cmdline == ' ') cmdline++;
275 while (*cmdline && *cmdline != ' ') cmdline++;
276 if (*cmdline) *cmdline++ = '\0';
277 lHash = HLPFILE_Hash(topic_id);
282 Globals.wVersion = option - '0';
287 Globals.isBook = FALSE;
291 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
296 /* Create primary window */
297 if (!WINHELP_RegisterWinClasses())
299 WINE_FIXME("Couldn't register classes\n");
306 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
311 if ((ptr = strchr(cmdline, '>')))
316 hlpfile = WINHELP_LookupHelpFile(cmdline);
317 if (!hlpfile) return 0;
320 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
321 WINHELP_GetWindowInfo(hlpfile, wndname), show);
324 while (GetMessage(&msg, 0, 0, 0))
326 TranslateMessage(&msg);
327 DispatchMessage(&msg);
329 for (dll = Globals.dlls; dll; dll = dll->next)
331 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
336 /***********************************************************************
340 static BOOL WINHELP_RegisterWinClasses(void)
342 WNDCLASS class_main, class_button_box, class_shadow, class_history;
344 class_main.style = CS_HREDRAW | CS_VREDRAW;
345 class_main.lpfnWndProc = WINHELP_MainWndProc;
346 class_main.cbClsExtra = 0;
347 class_main.cbWndExtra = sizeof(LONG);
348 class_main.hInstance = Globals.hInstance;
349 class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
350 class_main.hCursor = LoadCursor(0, IDC_ARROW);
351 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
352 class_main.lpszMenuName = 0;
353 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
355 class_button_box = class_main;
356 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
357 class_button_box.cbWndExtra = 0;
358 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
359 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
361 class_shadow = class_main;
362 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
363 class_shadow.cbWndExtra = 0;
364 class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
365 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
367 class_history = class_main;
368 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
369 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
371 return (RegisterClass(&class_main) &&
372 RegisterClass(&class_button_box) &&
373 RegisterClass(&class_shadow) &&
374 RegisterClass(&class_history));
385 } WINHELP,*LPWINHELP;
387 static BOOL WINHELP_HasWorkingWindow(void)
389 if (!Globals.active_win) return FALSE;
390 if (Globals.active_win->next || Globals.win_list != Globals.active_win) return TRUE;
391 return Globals.active_win->page != NULL && Globals.active_win->page->file != NULL;
394 /******************************************************************
395 * WINHELP_HandleCommand
399 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
401 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
404 if (cds->dwData != 0xA1DE505)
406 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
410 wh = (WINHELP*)cds->lpData;
414 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
416 WINE_TRACE("Got[%u]: cmd=%u data=%08x fn=%s\n",
417 wh->size, wh->command, wh->data, ptr);
423 MACRO_JumpContext(ptr, "main", wh->data);
425 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
433 MACRO_JumpContents(ptr, "main");
435 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
437 case HELP_HELPONHELP:
439 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
441 /* case HELP_SETINDEX: */
442 case HELP_SETCONTENTS:
445 MACRO_SetContents(ptr, wh->data);
448 case HELP_CONTEXTPOPUP:
451 MACRO_PopupContext(ptr, wh->data);
454 /* case HELP_FORCEFILE:*/
455 /* case HELP_CONTEXTMENU: */
457 /* in fact, should be the topic dialog box */
458 WINE_FIXME("HELP_FINDER: stub\n");
461 MACRO_JumpHash(ptr, "main", 0);
464 /* case HELP_WM_HELP: */
465 /* case HELP_SETPOPUP_POS: */
467 /* case HELP_COMMAND: */
468 /* case HELP_PARTIALKEY: */
469 /* case HELP_MULTIKEY: */
470 /* case HELP_SETWINPOS: */
472 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
476 /* Always return success for now */
480 void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
482 RECT rect, button_box_rect;
484 HWND hButtonBoxWnd = GetDlgItem(win->hMainWnd, CTL_ID_BUTTON);
485 HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
487 GetClientRect(win->hMainWnd, &rect);
489 /* Update button box and text Window */
490 SetWindowPos(hButtonBoxWnd, HWND_TOP,
492 rect.right - rect.left,
493 rect.bottom - rect.top, 0);
495 if (GetWindowRect(hButtonBoxWnd, &button_box_rect))
496 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
498 SetWindowPos(hTextWnd, HWND_TOP,
500 rect.right - rect.left,
501 rect.bottom - text_top, 0);
505 static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage)
509 if (!Globals.history.index || Globals.history.set[0].page != wpage->page)
511 num = sizeof(Globals.history.set) / sizeof(Globals.history.set[0]);
512 /* we're full, remove latest entry */
513 if (Globals.history.index == num)
515 HLPFILE_FreeHlpFile(Globals.history.set[num - 1].page->file);
516 Globals.history.index--;
518 memmove(&Globals.history.set[1], &Globals.history.set[0],
519 Globals.history.index * sizeof(Globals.history.set[0]));
520 Globals.history.set[0] = *wpage;
521 Globals.history.index++;
522 wpage->page->file->wRefCount++;
524 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
526 num = sizeof(win->back.set) / sizeof(win->back.set[0]);
527 if (win->back.index == num)
529 /* we're full, remove latest entry */
530 HLPFILE_FreeHlpFile(win->back.set[0].page->file);
531 memmove(&win->back.set[0], &win->back.set[1],
532 (num - 1) * sizeof(win->back.set[0]));
535 win->back.set[win->back.index++] = *wpage;
536 wpage->page->file->wRefCount++;
539 /***********************************************************************
541 * WINHELP_CreateHelpWindow
543 BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remember)
545 WINHELP_WINDOW* win = NULL;
546 BOOL bPrimary, bPopup, bReUsed = FALSE;
549 HWND hTextWnd = NULL;
551 bPrimary = !lstrcmpi(wpage->wininfo->name, "main");
552 bPopup = !bPrimary && (wpage->wininfo->win_style & WS_POPUP);
556 for (win = Globals.win_list; win; win = win->next)
558 if (!lstrcmpi(win->lpszName, wpage->wininfo->name))
562 DWORD flags = SWP_NOSIZE | SWP_NOMOVE;
564 WINHELP_DeleteButtons(win);
566 SetWindowText(win->hMainWnd, WINHELP_GetCaption(wpage));
567 if (wpage->wininfo->origin.x != CW_USEDEFAULT &&
568 wpage->wininfo->origin.y != CW_USEDEFAULT)
570 pt = wpage->wininfo->origin;
571 flags &= ~SWP_NOSIZE;
573 if (wpage->wininfo->size.cx != CW_USEDEFAULT &&
574 wpage->wininfo->size.cy != CW_USEDEFAULT)
576 sz = wpage->wininfo->size;
577 flags &= ~SWP_NOMOVE;
579 SetWindowPos(win->hMainWnd, HWND_TOP, pt.x, pt.y, sz.cx, sz.cy, flags);
581 if (wpage->page && win->page && wpage->page->file != win->page->file)
582 WINHELP_DeleteBackSet(win);
583 WINHELP_InitFonts(win->hMainWnd);
585 win->page = wpage->page;
586 win->info = wpage->wininfo;
587 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
588 WINHELP_SetupText(hTextWnd, win, wpage->relative);
590 InvalidateRect(win->hMainWnd, NULL, TRUE);
591 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
600 /* Initialize WINHELP_WINDOW struct */
601 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
602 sizeof(WINHELP_WINDOW) + strlen(wpage->wininfo->name) + 1);
603 if (!win) return FALSE;
604 win->next = Globals.win_list;
605 Globals.win_list = win;
607 name = (char*)win + sizeof(WINHELP_WINDOW);
608 lstrcpy(name, wpage->wininfo->name);
609 win->lpszName = name;
610 win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
614 win->page = wpage->page;
615 win->info = wpage->wininfo;
617 if (!bPopup && wpage->page && remember)
619 WINHELP_RememberPage(win, wpage);
623 Globals.active_popup = win;
625 Globals.active_win = win;
627 /* Initialize default pushbuttons */
628 if (bPrimary && wpage->page)
630 CHAR buffer[MAX_STRING_LEN];
632 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
633 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
634 LoadString(Globals.hInstance, STID_INDEX, buffer, sizeof(buffer));
635 MACRO_CreateButton("BTN_INDEX", buffer, "Finder()");
636 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
637 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
638 if (win->back.index <= 1) MACRO_DisableButton("BTN_BACK");
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);
656 hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
657 ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
658 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
659 SendMessage(hTextWnd, EM_SETEVENTMASK, 0,
660 SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0) | ENM_MOUSEEVENTS);
663 hIcon = (wpage->page) ? wpage->page->file->hIcon : NULL;
664 if (!hIcon) hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
665 SendMessage(win->hMainWnd, WM_SETICON, ICON_SMALL, (DWORD_PTR)hIcon);
667 /* Initialize file specific pushbuttons */
668 if (!(wpage->wininfo->win_style & WS_POPUP) && wpage->page)
670 HLPFILE_MACRO *macro;
671 for (macro = wpage->page->file->first_macro; macro; macro = macro->next)
672 MACRO_ExecuteMacro(macro->lpszMacro);
674 for (macro = wpage->page->first_macro; macro; macro = macro->next)
675 MACRO_ExecuteMacro(macro->lpszMacro);
680 DWORD mask = SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0);
683 win->font_scale = Globals.active_win->font_scale;
684 WINHELP_SetupText(hTextWnd, win, wpage->relative);
686 /* we need the window to be shown for richedit to compute the size */
687 ShowWindow(win->hMainWnd, nCmdShow);
688 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask | ENM_REQUESTRESIZE);
689 SendMessage(hTextWnd, EM_REQUESTRESIZE, 0, 0);
690 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask);
692 GetWindowRect(win->hMainWnd, &rect);
693 win->hShadowWnd = CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME,
694 "", WS_POPUP | WS_VISIBLE,
695 rect.left + SHADOW_DX, rect.top + SHADOW_DY,
696 rect.right - rect.left,
697 rect.bottom - rect.top,
698 Globals.active_win->hMainWnd, 0,
699 Globals.hInstance, NULL);
700 SetWindowPos(win->hMainWnd, win->hShadowWnd, 0, 0, 0, 0,
701 SWP_NOSIZE | SWP_NOMOVE);
705 WINHELP_SetupText(hTextWnd, win, wpage->relative);
706 WINHELP_LayoutMainWindow(win);
707 ShowWindow(win->hMainWnd, nCmdShow);
713 /******************************************************************
714 * WINHELP_OpenHelpWindow
715 * Main function to search for a page and display it in a window
717 BOOL WINHELP_OpenHelpWindow(HLPFILE_PAGE* (*lookup)(HLPFILE*, LONG, ULONG*),
718 HLPFILE* hlpfile, LONG val, HLPFILE_WINDOWINFO* wi,
721 WINHELP_WNDPAGE wpage;
723 wpage.page = lookup(hlpfile, val, &wpage.relative);
724 if (wpage.page) wpage.page->file->wRefCount++;
726 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
729 /***********************************************************************
733 static HLPFILE_LINK* WINHELP_FindLink(WINHELP_WINDOW* win, LPARAM pos)
736 POINTL mouse_ptl, char_ptl, char_next_ptl;
739 if (!win->page) return NULL;
741 mouse_ptl.x = (short)LOWORD(pos);
742 mouse_ptl.y = (short)HIWORD(pos);
743 cp = SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_CHARFROMPOS,
744 0, (LPARAM)&mouse_ptl);
746 for (link = win->page->first_link; link; link = link->next)
748 if (link->cpMin <= cp && cp <= link->cpMax)
750 /* check whether we're at end of line */
751 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
752 (LPARAM)&char_ptl, cp);
753 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
754 (LPARAM)&char_next_ptl, cp + 1);
755 if (char_next_ptl.y != char_ptl.y || mouse_ptl.x >= char_next_ptl.x)
763 /******************************************************************
764 * WINHELP_HandleTextMouse
767 static BOOL WINHELP_HandleTextMouse(WINHELP_WINDOW* win, UINT msg, LPARAM lParam)
776 if (WINHELP_FindLink(win, lParam))
777 SetCursor(win->hHandCur);
779 SetCursor(LoadCursor(0, IDC_ARROW));
783 if ((win->current_link = WINHELP_FindLink(win, lParam)))
788 if ((link = WINHELP_FindLink(win, lParam)) && link == win->current_link)
790 HLPFILE_WINDOWINFO* wi;
792 switch (link->cookie)
795 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
797 if (link->window == -1)
799 else if (link->window < hlpfile->numWindows)
800 wi = &hlpfile->windows[link->window];
803 WINE_WARN("link to window %d/%d\n", link->window, hlpfile->numWindows);
806 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash, wi, SW_NORMAL);
810 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
811 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash,
812 WINHELP_GetPopupWindowInfo(hlpfile, win, lParam),
816 MACRO_ExecuteMacro(link->string);
819 WINE_FIXME("Unknown link cookie %d\n", link->cookie);
823 win->current_link = NULL;
829 /***********************************************************************
831 * WINHELP_MainWndProc
833 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
836 WINHELP_BUTTON *button;
838 INT curPos, min, max, dy, keyDelta;
842 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, &ret)) return ret;
847 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
848 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
849 if (!win->page && Globals.isBook)
850 PostMessage(hWnd, WM_COMMAND, MNID_FILE_OPEN, 0);
851 win->hMainWnd = hWnd;
854 case WM_WINDOWPOSCHANGED:
855 WINHELP_LayoutMainWindow((WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0));
859 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
863 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
864 case MNID_FILE_PRINT: MACRO_Print(); break;
865 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
866 case MNID_FILE_EXIT: MACRO_Exit(); break;
869 case MNID_EDIT_COPYDLG:
870 SendMessage(GetDlgItem(hWnd, CTL_ID_TEXT), WM_COPY, 0, 0);
872 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
875 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
878 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
879 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
880 case MNID_HELP_ABOUT: MACRO_About(); break;
881 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
884 case MNID_CTXT_ANNOTATE:MACRO_Annotate(); break;
885 case MNID_CTXT_COPY: MACRO_CopyDialog(); break;
886 case MNID_CTXT_PRINT: MACRO_Print(); break;
887 case MNID_OPTS_HISTORY: MACRO_History(); break;
888 case MNID_OPTS_FONTS_SMALL:
889 case MNID_CTXT_FONTS_SMALL:
890 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
891 if (win->font_scale != 0)
894 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
897 case MNID_OPTS_FONTS_NORMAL:
898 case MNID_CTXT_FONTS_NORMAL:
899 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
900 if (win->font_scale != 1)
903 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
906 case MNID_OPTS_FONTS_LARGE:
907 case MNID_CTXT_FONTS_LARGE:
908 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
909 if (win->font_scale != 2)
912 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
915 case MNID_OPTS_HELP_DEFAULT:
916 case MNID_OPTS_HELP_VISIBLE:
917 case MNID_OPTS_HELP_NONVISIBLE:
918 case MNID_OPTS_SYSTEM_COLORS:
919 case MNID_CTXT_HELP_DEFAULT:
920 case MNID_CTXT_HELP_VISIBLE:
921 case MNID_CTXT_HELP_NONVISIBLE:
922 case MNID_CTXT_SYSTEM_COLORS:
927 for (button = win->first_button; button; button = button->next)
928 if (wParam == button->wParam) break;
930 MACRO_ExecuteMacro(button->lpszMacro);
931 else if (!HIWORD(wParam))
932 MessageBox(0, MAKEINTRESOURCE(STID_NOT_IMPLEMENTED),
933 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
937 /* EPP case WM_DESTROY: */
938 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
941 return WINHELP_HandleCommand((HWND)wParam, lParam);
946 SendMessage(GetDlgItem(hWnd, CTL_ID_TEXT), WM_COPY, 0, 0);
958 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
960 keyDelta = -keyDelta;
964 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
965 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
966 curPos = GetScrollPos(hTextWnd, SB_VERT);
967 GetScrollRange(hTextWnd, SB_VERT, &min, &max);
971 GetClientRect(hTextWnd, &rect);
972 keyDelta = (rect.bottom - rect.top) / 2;
973 if (wParam == VK_PRIOR)
974 keyDelta = -keyDelta;
980 else if (curPos < min)
983 dy = GetScrollPos(hTextWnd, SB_VERT) - curPos;
984 SetScrollPos(hTextWnd, SB_VERT, curPos, TRUE);
985 ScrollWindow(hTextWnd, 0, dy, NULL, NULL);
986 UpdateWindow(hTextWnd);
996 if (wParam == CTL_ID_TEXT)
1000 switch (((NMHDR*)lParam)->code)
1004 const MSGFILTER* msgf = (const MSGFILTER*)lParam;
1008 if (msgf->wParam == VK_ESCAPE) DestroyWindow(hWnd);
1010 case WM_RBUTTONDOWN:
1015 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1016 hMenu = LoadMenu(Globals.hInstance, (LPSTR)CONTEXT_MENU);
1017 switch (win->font_scale)
1020 CheckMenuItem(hMenu, MNID_CTXT_FONTS_SMALL,
1021 MF_BYCOMMAND|MF_CHECKED);
1024 WINE_FIXME("Unsupported %d\n", win->font_scale);
1026 CheckMenuItem(hMenu, MNID_CTXT_FONTS_NORMAL,
1027 MF_BYCOMMAND|MF_CHECKED);
1030 CheckMenuItem(hMenu, MNID_CTXT_FONTS_LARGE,
1031 MF_BYCOMMAND|MF_CHECKED);
1034 pt.x = (int)(short)LOWORD(msgf->lParam);
1035 pt.y = (int)(short)HIWORD(msgf->lParam);
1036 ClientToScreen(msgf->nmhdr.hwndFrom, &pt);
1037 TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_LEFTALIGN|TPM_TOPALIGN,
1038 pt.x, pt.y, 0, hWnd, NULL);
1043 return WINHELP_HandleTextMouse((WINHELP_WINDOW*)GetWindowLongPtr(hWnd, 0),
1044 msgf->msg, msgf->lParam);
1049 case EN_REQUESTRESIZE:
1050 rc = ((REQRESIZE*)lParam)->rc;
1051 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1052 AdjustWindowRect(&rc, GetWindowLong(win->hMainWnd, GWL_STYLE),
1054 SetWindowPos(win->hMainWnd, HWND_TOP, 0, 0,
1055 rc.right - rc.left, rc.bottom - rc.top,
1056 SWP_NOMOVE | SWP_NOZORDER);
1057 WINHELP_LayoutMainWindow(win);
1063 case WM_INITMENUPOPUP:
1064 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1065 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_SMALL,
1066 MF_BYCOMMAND | (win->font_scale == 0) ? MF_CHECKED : 0);
1067 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_NORMAL,
1068 MF_BYCOMMAND | (win->font_scale == 1) ? MF_CHECKED : 0);
1069 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_LARGE,
1070 MF_BYCOMMAND | (win->font_scale == 2) ? MF_CHECKED : 0);
1076 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1077 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1078 WINHELP_DeleteWindow(win);
1080 if (bExit) MACRO_Exit();
1081 if (!Globals.win_list)
1086 return DefWindowProc(hWnd, msg, wParam, lParam);
1089 static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff,
1092 struct RtfData* rd = (struct RtfData*)cookie;
1094 if (rd->where >= rd->ptr) return 1;
1095 if (rd->where + cb > rd->ptr)
1096 cb = rd->ptr - rd->where;
1097 memcpy(buff, rd->where, cb);
1103 static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative)
1105 /* At first clear area - needed by EM_POSFROMCHAR/EM_SETSCROLLPOS */
1106 SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)"");
1107 SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0);
1108 SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color);
1109 /* set word-wrap to window size (undocumented) */
1110 SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0);
1120 if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative))
1123 es.dwCookie = (DWORD_PTR)&rd;
1125 es.pfnCallback = WINHELP_RtfStreamIn;
1127 SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
1128 cp = rd.char_pos_rel;
1130 /* FIXME: else leaking potentially the rd.first_link chain */
1131 HeapFree(GetProcessHeap(), 0, rd.data);
1132 SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0);
1133 pt.x = 0; pt.y = ptl.y;
1134 SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt);
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);
1176 if (Globals.button_proc == NULL)
1178 NONCLIENTMETRICSW ncm;
1179 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
1181 ncm.cbSize = sizeof(NONCLIENTMETRICSW);
1182 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
1183 sizeof(NONCLIENTMETRICSW), &ncm, 0);
1184 Globals.hButtonFont = CreateFontIndirectW(&ncm.lfMenuFont);
1186 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
1187 if (Globals.hButtonFont)
1188 SendMessage(button->hWnd, WM_SETFONT, (WPARAM)Globals.hButtonFont, TRUE);
1191 hDc = GetDC(button->hWnd);
1192 GetTextExtentPoint(hDc, button->lpszName,
1193 lstrlen(button->lpszName), &textsize);
1194 ReleaseDC(button->hWnd, hDc);
1196 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
1197 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
1202 for (button = win->first_button; button; button = button->next)
1204 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
1206 if (x + 2 * button_size.cx <= winpos->cx)
1207 x += button_size.cx;
1209 x = 0, y += button_size.cy;
1211 winpos->cy = y + (x ? button_size.cy : 0);
1215 SendMessage(GetParent(hWnd), msg, wParam, lParam);
1226 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1231 return DefWindowProc(hWnd, msg, wParam, lParam);
1234 /***********************************************************************
1236 * WINHELP_ButtonWndProc
1238 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1240 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1242 if (msg == WM_KEYDOWN)
1251 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1255 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
1258 /******************************************************************
1259 * WINHELP_HistoryWndProc
1263 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1265 WINHELP_WINDOW* win;
1275 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1276 SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win);
1277 win->hHistoryWnd = hWnd;
1280 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1282 GetTextMetrics(hDc, &tm);
1283 GetWindowRect(hWnd, &r);
1285 r.right = r.left + 30 * tm.tmAveCharWidth;
1286 r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight;
1287 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1288 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1289 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1291 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1292 ReleaseDC(hWnd, hDc);
1294 case WM_LBUTTONDOWN:
1295 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1297 GetTextMetrics(hDc, &tm);
1298 i = HIWORD(lParam) / tm.tmHeight;
1299 if (i < Globals.history.index)
1300 WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE);
1301 ReleaseDC(hWnd, hDc);
1304 hDc = BeginPaint(hWnd, &ps);
1305 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1306 GetTextMetrics(hDc, &tm);
1308 for (i = 0; i < Globals.history.index; i++)
1310 if (Globals.history.set[i].page->file == Globals.active_win->page->file)
1312 TextOut(hDc, 0, i * tm.tmHeight,
1313 Globals.history.set[i].page->lpszTitle,
1314 strlen(Globals.history.set[i].page->lpszTitle));
1323 ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\');
1324 if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath;
1326 ptr2 = strrchr(ptr1, '.');
1327 len = ptr2 ? ptr2 - ptr1 : strlen(ptr1);
1328 if (len > sizeof(buffer)) len = sizeof(buffer);
1329 memcpy(buffer, ptr1, len);
1330 if (len < sizeof(buffer)) buffer[len++] = ':';
1331 strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len);
1332 buffer[sizeof(buffer) - 1] = '\0';
1333 TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer));
1336 EndPaint(hWnd, &ps);
1339 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1340 if (hWnd == win->hHistoryWnd)
1341 win->hHistoryWnd = 0;
1344 return DefWindowProc(hWnd, msg, wParam, lParam);
1347 /***********************************************************************
1349 * WINHELP_ShadowWndProc
1351 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1353 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1354 return WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL) ? 0L : DefWindowProc(hWnd, msg, wParam, lParam);
1357 /***********************************************************************
1359 * WINHELP_CheckPopup
1361 static BOOL WINHELP_CheckPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* lret)
1365 if (!Globals.active_popup) return FALSE;
1371 MSGFILTER* msgf = (MSGFILTER*)lParam;
1372 if (msgf->nmhdr.code == EN_MSGFILTER)
1374 if (!WINHELP_CheckPopup(hWnd, msgf->msg, msgf->wParam, msgf->lParam, NULL))
1376 if (lret) *lret = 1;
1382 if (wParam != WA_INACTIVE || (HWND)lParam == Globals.active_win->hMainWnd ||
1383 (HWND)lParam == Globals.active_popup->hMainWnd ||
1384 GetWindow((HWND)lParam, GW_OWNER) == Globals.active_win->hMainWnd)
1387 case WM_LBUTTONDOWN:
1388 if (WINHELP_HandleTextMouse(Globals.active_popup, msg, lParam) && msg == WM_LBUTTONDOWN)
1391 case WM_MBUTTONDOWN:
1392 case WM_RBUTTONDOWN:
1393 case WM_NCLBUTTONDOWN:
1394 case WM_NCMBUTTONDOWN:
1395 case WM_NCRBUTTONDOWN:
1396 hPopup = Globals.active_popup->hMainWnd;
1397 Globals.active_popup = NULL;
1398 DestroyWindow(hPopup);
1404 /******************************************************************
1405 * WINHELP_DeleteButtons
1408 static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
1413 for (b = win->first_button; b; b = bp)
1415 DestroyWindow(b->hWnd);
1417 HeapFree(GetProcessHeap(), 0, b);
1419 win->first_button = NULL;
1422 /******************************************************************
1423 * WINHELP_DeleteBackSet
1426 void WINHELP_DeleteBackSet(WINHELP_WINDOW* win)
1430 for (i = 0; i < win->back.index; i++)
1432 HLPFILE_FreeHlpFile(win->back.set[i].page->file);
1433 win->back.set[i].page = NULL;
1435 win->back.index = 0;
1438 /******************************************************************
1439 * WINHELP_DeletePageLinks
1442 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page)
1447 for (curr = page->first_link; curr; curr = next)
1450 HeapFree(GetProcessHeap(), 0, curr);
1454 /***********************************************************************
1456 * WINHELP_DeleteWindow
1458 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1462 for (w = &Globals.win_list; *w; w = &(*w)->next)
1471 if (Globals.active_win == win)
1473 Globals.active_win = Globals.win_list;
1474 if (Globals.win_list)
1475 SetActiveWindow(Globals.win_list->hMainWnd);
1478 if (win == Globals.active_popup)
1479 Globals.active_popup = NULL;
1481 WINHELP_DeleteButtons(win);
1483 if (win->page) WINHELP_DeletePageLinks(win->page);
1484 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1485 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1487 DeleteObject(win->hBrush);
1489 WINHELP_DeleteBackSet(win);
1491 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1492 HeapFree(GetProcessHeap(), 0, win);
1495 /***********************************************************************
1499 static void WINHELP_InitFonts(HWND hWnd)
1501 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1502 LOGFONT logfontlist[] = {
1503 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1504 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1505 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1506 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1507 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1508 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1509 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
1510 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1512 static HFONT fonts[FONTS_LEN];
1513 static BOOL init = 0;
1515 win->fonts_len = FONTS_LEN;
1522 for (i = 0; i < FONTS_LEN; i++)
1524 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1531 /***********************************************************************
1533 * WINHELP_MessageBoxIDS_s
1535 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1537 CHAR text[MAX_STRING_LEN];
1538 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
1540 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1541 wsprintf(newtext, text, str);
1543 return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type);
1546 /**************************************************************************
1549 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1552 static void cb_KWBTree(void *p, void **next, void *cookie)
1554 HWND hListWnd = (HWND)cookie;
1557 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
1558 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
1559 count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0);
1560 SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p);
1561 *next = (char*)p + strlen((char*)p) + 7;
1571 /**************************************************************************
1572 * WINHELP_IndexDlgProc
1575 INT_PTR CALLBACK WINHELP_IndexDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1577 static struct index_data* id;
1583 id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam;
1584 HLPFILE_BPTreeEnum(id->hlpfile->kwbtree, cb_KWBTree,
1585 GetDlgItem(hWnd, IDC_INDEXLIST));
1590 switch (HIWORD(wParam))
1593 if (LOWORD(wParam) == IDC_INDEXLIST)
1594 SendMessage(GetParent(hWnd), PSM_PRESSBUTTON, PSBTN_OK, 0);
1599 switch (((NMHDR*)lParam)->code)
1602 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
1608 p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST,
1609 LB_GETITEMDATA, sel, 0);
1610 count = *(short*)((char *)p + strlen((char *)p) + 1);
1613 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
1614 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID);
1617 id->offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
1618 id->offset = *(long*)(id->hlpfile->kwdata + id->offset + 9);
1619 if (id->offset == 0xFFFFFFFF)
1621 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
1622 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID);
1626 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR);
1639 /**************************************************************************
1640 * WINHELP_SearchDlgProc
1643 INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1645 static struct index_data* id;
1650 id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam;
1653 switch (((NMHDR*)lParam)->code)
1656 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR);
1668 /**************************************************************************
1669 * WINHELP_CreateIndexWindow
1671 * Displays a dialog with keywords of current help file.
1674 BOOL WINHELP_CreateIndexWindow(BOOL is_search)
1676 HPROPSHEETPAGE psPage[3];
1678 PROPSHEETHEADER psHead;
1679 struct index_data id;
1682 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
1683 id.hlpfile = Globals.active_win->page->file;
1687 if (id.hlpfile->kwbtree == NULL)
1689 WINE_TRACE("No index provided\n");
1693 InitCommonControls();
1696 memset(&psp, 0, sizeof(psp));
1697 psp.dwSize = sizeof(psp);
1699 psp.hInstance = Globals.hInstance;
1701 psp.u.pszTemplate = MAKEINTRESOURCE(IDD_INDEX);
1702 psp.lParam = (LPARAM)&id;
1703 psp.pfnDlgProc = WINHELP_IndexDlgProc;
1704 psPage[0] = CreatePropertySheetPage(&psp);
1706 psp.u.pszTemplate = MAKEINTRESOURCE(IDD_SEARCH);
1707 psp.lParam = (LPARAM)&id;
1708 psp.pfnDlgProc = WINHELP_SearchDlgProc;
1709 psPage[1] = CreatePropertySheetPage(&psp);
1711 memset(&psHead, 0, sizeof(psHead));
1712 psHead.dwSize = sizeof(psHead);
1714 LoadString(Globals.hInstance, STID_PSH_INDEX, buf, sizeof(buf));
1715 strcat(buf, Globals.active_win->info->caption);
1717 psHead.pszCaption = buf;
1719 psHead.u2.nStartPage = is_search ? 1 : 0;
1720 psHead.hwndParent = Globals.active_win->hMainWnd;
1721 psHead.u3.phpage = psPage;
1722 psHead.dwFlags = PSH_NOAPPLYNOW;
1724 PropertySheet(&psHead);
1727 WINE_TRACE("got %d as an offset\n", id.offset);
1728 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset, id.hlpfile, id.offset,
1729 Globals.active_win->info, SW_NORMAL);