4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002, 2008 Eric Pouech <eric.pouech@wanadoo.fr>
7 * 2004 Ken Belleau <jamez@ivic.qc.ca>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
36 #include "winhelp_res.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
44 static BOOL WINHELP_RegisterWinClasses(void);
45 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WINHELP_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 BOOL WINHELP_CheckPopup(HWND, UINT, WPARAM, LPARAM, LRESULT*);
51 static void WINHELP_InitFonts(HWND hWnd);
52 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
53 static void WINHELP_DeleteButtons(WINHELP_WINDOW*);
54 static void WINHELP_SetupText(HWND hWnd, WINHELP_WINDOW *win, ULONG relative);
55 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page);
57 WINHELP_GLOBALS Globals = {3, NULL, TRUE, NULL, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}};
59 #define CTL_ID_BUTTON 0x700
60 #define CTL_ID_TEXT 0x701
62 /***********************************************************************
64 * WINHELP_GetOpenFileName
66 BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len)
68 OPENFILENAME openfilename;
70 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
75 LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
79 LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
85 GetCurrentDirectory(sizeof(szDir), szDir);
89 openfilename.lStructSize = sizeof(OPENFILENAME);
90 openfilename.hwndOwner = NULL;
91 openfilename.hInstance = Globals.hInstance;
92 openfilename.lpstrFilter = szzFilter;
93 openfilename.lpstrCustomFilter = 0;
94 openfilename.nMaxCustFilter = 0;
95 openfilename.nFilterIndex = 1;
96 openfilename.lpstrFile = lpszFile;
97 openfilename.nMaxFile = len;
98 openfilename.lpstrFileTitle = 0;
99 openfilename.nMaxFileTitle = 0;
100 openfilename.lpstrInitialDir = szDir;
101 openfilename.lpstrTitle = 0;
102 openfilename.Flags = 0;
103 openfilename.nFileOffset = 0;
104 openfilename.nFileExtension = 0;
105 openfilename.lpstrDefExt = 0;
106 openfilename.lCustData = 0;
107 openfilename.lpfnHook = 0;
108 openfilename.lpTemplateName = 0;
110 return GetOpenFileName(&openfilename);
113 static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage)
115 if (wpage->wininfo->caption[0]) return wpage->wininfo->caption;
116 return wpage->page->file->lpszTitle;
119 /***********************************************************************
121 * WINHELP_LookupHelpFile
123 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
126 char szFullName[MAX_PATH];
127 char szAddPath[MAX_PATH];
131 * NOTE: This is needed by popup windows only.
132 * In other cases it's not needed but does not hurt though.
134 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
136 strcpy(szAddPath, Globals.active_win->page->file->lpszPath);
137 p = strrchr(szAddPath, '\\');
142 * FIXME: Should we swap conditions?
144 if (!SearchPath(NULL, lpszFile, ".hlp", MAX_PATH, szFullName, NULL) &&
145 !SearchPath(szAddPath, lpszFile, ".hlp", MAX_PATH, szFullName, NULL))
147 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s, lpszFile, STID_WHERROR,
148 MB_YESNO|MB_ICONQUESTION) != IDYES)
150 if (!WINHELP_GetOpenFileName(szFullName, MAX_PATH))
153 hlpfile = HLPFILE_ReadHlpFile(szFullName);
155 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile,
156 STID_WHERROR, MB_OK|MB_ICONSTOP);
160 /******************************************************************
161 * WINHELP_GetWindowInfo
165 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
167 static HLPFILE_WINDOWINFO mwi;
170 if (!name || !name[0])
171 name = Globals.active_win->lpszName;
174 for (i = 0; i < hlpfile->numWindows; i++)
175 if (!strcmp(hlpfile->windows[i].name, name))
176 return &hlpfile->windows[i];
178 if (strcmp(name, "main") != 0)
180 WINE_FIXME("Couldn't find window info for %s\n", name);
186 strcpy(mwi.type, "primary");
187 strcpy(mwi.name, "main");
188 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
189 mwi.caption, sizeof(mwi.caption)))
190 strcpy(mwi.caption, hlpfile->lpszTitle);
191 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
193 mwi.win_style = WS_OVERLAPPEDWINDOW;
194 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
199 /******************************************************************
200 * HLPFILE_GetPopupWindowInfo
204 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile,
205 WINHELP_WINDOW* parent, LPARAM mouse)
207 static HLPFILE_WINDOWINFO wi;
211 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
213 /* Calculate horizontal size and position of a popup window */
214 GetWindowRect(parent->hMainWnd, &parent_rect);
215 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
216 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
218 wi.origin.x = (short)LOWORD(mouse);
219 wi.origin.y = (short)HIWORD(mouse);
220 ClientToScreen(parent->hMainWnd, &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 = parent->info->sr_color;
228 wi.nsr_color = 0xFFFFFF;
233 /***********************************************************************
237 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
242 static CHAR default_wndname[] = "main";
243 LPSTR wndname = default_wndname;
246 Globals.hInstance = hInstance;
248 if (LoadLibrary("riched20.dll") == NULL)
249 return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT),
250 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
253 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
257 if (*cmdline++ == ' ') continue;
260 if (option) cmdline++;
261 while (*cmdline && *cmdline == ' ') cmdline++;
267 while (*cmdline && *cmdline != ' ') cmdline++;
268 if (*cmdline) *cmdline++ = '\0';
269 lHash = HLPFILE_Hash(topic_id);
274 Globals.wVersion = option - '0';
279 Globals.isBook = FALSE;
283 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
288 /* Create primary window */
289 if (!WINHELP_RegisterWinClasses())
291 WINE_FIXME("Couldn't register classes\n");
298 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
303 if ((ptr = strchr(cmdline, '>')))
308 hlpfile = WINHELP_LookupHelpFile(cmdline);
309 if (!hlpfile) return 0;
312 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
313 WINHELP_GetWindowInfo(hlpfile, wndname), show);
316 while (GetMessage(&msg, 0, 0, 0))
318 TranslateMessage(&msg);
319 DispatchMessage(&msg);
321 for (dll = Globals.dlls; dll; dll = dll->next)
323 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
328 /***********************************************************************
332 static BOOL WINHELP_RegisterWinClasses(void)
334 WNDCLASS class_main, class_button_box, class_shadow, class_history;
336 class_main.style = CS_HREDRAW | CS_VREDRAW;
337 class_main.lpfnWndProc = WINHELP_MainWndProc;
338 class_main.cbClsExtra = 0;
339 class_main.cbWndExtra = sizeof(LONG);
340 class_main.hInstance = Globals.hInstance;
341 class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
342 class_main.hCursor = LoadCursor(0, IDC_ARROW);
343 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
344 class_main.lpszMenuName = 0;
345 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
347 class_button_box = class_main;
348 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
349 class_button_box.cbWndExtra = 0;
350 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
351 class_button_box.lpszClassName = BUTTON_BOX_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_shadow) &&
366 RegisterClass(&class_history));
377 } WINHELP,*LPWINHELP;
379 /******************************************************************
380 * WINHELP_HandleCommand
384 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
386 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
389 if (cds->dwData != 0xA1DE505)
391 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
395 wh = (WINHELP*)cds->lpData;
399 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
401 WINE_TRACE("Got[%u]: cmd=%u data=%08x fn=%s\n",
402 wh->size, wh->command, wh->data, ptr);
408 MACRO_JumpContext(ptr, "main", wh->data);
417 MACRO_JumpContents(ptr, "main");
420 case HELP_HELPONHELP:
423 /* case HELP_SETINDEX: */
424 case HELP_SETCONTENTS:
427 MACRO_SetContents(ptr, wh->data);
430 case HELP_CONTEXTPOPUP:
433 MACRO_PopupContext(ptr, wh->data);
436 /* case HELP_FORCEFILE:*/
437 /* case HELP_CONTEXTMENU: */
439 /* in fact, should be the topic dialog box */
440 WINE_FIXME("HELP_FINDER: stub\n");
443 MACRO_JumpHash(ptr, "main", 0);
446 /* case HELP_WM_HELP: */
447 /* case HELP_SETPOPUP_POS: */
449 /* case HELP_COMMAND: */
450 /* case HELP_PARTIALKEY: */
451 /* case HELP_MULTIKEY: */
452 /* case HELP_SETWINPOS: */
454 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
458 /* Always return success for now */
462 void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
464 RECT rect, button_box_rect;
466 HWND hButtonBoxWnd = GetDlgItem(win->hMainWnd, CTL_ID_BUTTON);
467 HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
469 GetClientRect(win->hMainWnd, &rect);
471 /* Update button box and text Window */
472 SetWindowPos(hButtonBoxWnd, HWND_TOP,
474 rect.right - rect.left,
475 rect.bottom - rect.top, 0);
477 if (GetWindowRect(hButtonBoxWnd, &button_box_rect))
478 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
480 SetWindowPos(hTextWnd, HWND_TOP,
482 rect.right - rect.left,
483 rect.bottom - text_top, 0);
487 static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage)
491 if (!Globals.history.index || Globals.history.set[0].page != wpage->page)
493 num = sizeof(Globals.history.set) / sizeof(Globals.history.set[0]);
494 /* we're full, remove latest entry */
495 if (Globals.history.index == num)
497 HLPFILE_FreeHlpFile(Globals.history.set[num - 1].page->file);
498 Globals.history.index--;
500 memmove(&Globals.history.set[1], &Globals.history.set[0],
501 Globals.history.index * sizeof(Globals.history.set[0]));
502 Globals.history.set[0] = *wpage;
503 Globals.history.index++;
504 wpage->page->file->wRefCount++;
506 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
508 num = sizeof(win->back.set) / sizeof(win->back.set[0]);
509 if (win->back.index == num)
511 /* we're full, remove latest entry */
512 HLPFILE_FreeHlpFile(win->back.set[0].page->file);
513 memmove(&win->back.set[0], &win->back.set[1],
514 (num - 1) * sizeof(win->back.set[0]));
517 win->back.set[win->back.index++] = *wpage;
518 wpage->page->file->wRefCount++;
521 /***********************************************************************
523 * WINHELP_CreateHelpWindow
525 BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remember)
527 WINHELP_WINDOW* win = NULL;
528 BOOL bPrimary, bPopup, bReUsed = FALSE;
531 HWND hTextWnd = NULL;
533 bPrimary = !lstrcmpi(wpage->wininfo->name, "main");
534 bPopup = !bPrimary && (wpage->wininfo->win_style & WS_POPUP);
538 for (win = Globals.win_list; win; win = win->next)
540 if (!lstrcmpi(win->lpszName, wpage->wininfo->name))
544 DWORD flags = SWP_NOSIZE | SWP_NOMOVE;
546 WINHELP_DeleteButtons(win);
548 SetWindowText(win->hMainWnd, WINHELP_GetCaption(wpage));
549 if (wpage->wininfo->origin.x != CW_USEDEFAULT &&
550 wpage->wininfo->origin.y != CW_USEDEFAULT)
552 pt = wpage->wininfo->origin;
553 flags &= ~SWP_NOSIZE;
555 if (wpage->wininfo->size.cx != CW_USEDEFAULT &&
556 wpage->wininfo->size.cy != CW_USEDEFAULT)
558 sz = wpage->wininfo->size;
559 flags &= ~SWP_NOMOVE;
561 SetWindowPos(win->hMainWnd, HWND_TOP, pt.x, pt.y, sz.cx, sz.cy, flags);
563 if (wpage->page && win->page && wpage->page->file != win->page->file)
564 WINHELP_DeleteBackSet(win);
565 WINHELP_InitFonts(win->hMainWnd);
567 win->page = wpage->page;
568 win->info = wpage->wininfo;
569 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
570 WINHELP_SetupText(hTextWnd, win, wpage->relative);
572 InvalidateRect(win->hMainWnd, NULL, TRUE);
573 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
582 /* Initialize WINHELP_WINDOW struct */
583 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
584 sizeof(WINHELP_WINDOW) + strlen(wpage->wininfo->name) + 1);
585 if (!win) return FALSE;
586 win->next = Globals.win_list;
587 Globals.win_list = win;
589 name = (char*)win + sizeof(WINHELP_WINDOW);
590 lstrcpy(name, wpage->wininfo->name);
591 win->lpszName = name;
592 win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
596 win->page = wpage->page;
597 win->info = wpage->wininfo;
599 if (!bPopup && wpage->page && remember)
601 WINHELP_RememberPage(win, wpage);
605 Globals.active_popup = win;
607 Globals.active_win = win;
609 /* Initialize default pushbuttons */
610 if (bPrimary && wpage->page)
612 CHAR buffer[MAX_STRING_LEN];
614 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
615 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
616 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
617 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
618 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
619 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
620 if (win->back.index <= 1) MACRO_DisableButton("BTN_BACK");
621 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
622 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
623 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
624 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
629 win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
630 WINHELP_GetCaption(wpage),
631 bPrimary ? WS_OVERLAPPEDWINDOW : wpage->wininfo->win_style,
632 wpage->wininfo->origin.x, wpage->wininfo->origin.y,
633 wpage->wininfo->size.cx, wpage->wininfo->size.cy,
634 bPopup ? Globals.active_win->hMainWnd : NULL,
635 bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
636 Globals.hInstance, win);
638 /* Create button box and text Window */
639 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
640 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
642 hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
643 ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
644 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
645 SendMessage(hTextWnd, EM_SETEVENTMASK, 0,
646 SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0) | ENM_MOUSEEVENTS);
649 hIcon = (wpage->page) ? wpage->page->file->hIcon : NULL;
650 if (!hIcon) hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
651 SendMessage(win->hMainWnd, WM_SETICON, ICON_SMALL, (DWORD_PTR)hIcon);
653 /* Initialize file specific pushbuttons */
654 if (!(wpage->wininfo->win_style & WS_POPUP) && wpage->page)
656 HLPFILE_MACRO *macro;
657 for (macro = wpage->page->file->first_macro; macro; macro = macro->next)
658 MACRO_ExecuteMacro(macro->lpszMacro);
660 for (macro = wpage->page->first_macro; macro; macro = macro->next)
661 MACRO_ExecuteMacro(macro->lpszMacro);
666 DWORD mask = SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0);
669 win->font_scale = Globals.active_win->font_scale;
670 WINHELP_SetupText(hTextWnd, win, wpage->relative);
672 /* we need the window to be shown for richedit to compute the size */
673 ShowWindow(win->hMainWnd, nCmdShow);
674 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask | ENM_REQUESTRESIZE);
675 SendMessage(hTextWnd, EM_REQUESTRESIZE, 0, 0);
676 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask);
678 GetWindowRect(win->hMainWnd, &rect);
679 win->hShadowWnd = CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME,
680 "", WS_POPUP | WS_VISIBLE,
681 rect.left + SHADOW_DX, rect.top + SHADOW_DY,
682 rect.right - rect.left,
683 rect.bottom - rect.top,
684 Globals.active_win->hMainWnd, 0,
685 Globals.hInstance, NULL);
686 SetWindowPos(win->hMainWnd, win->hShadowWnd, 0, 0, 0, 0,
687 SWP_NOSIZE | SWP_NOMOVE);
691 WINHELP_SetupText(hTextWnd, win, wpage->relative);
692 WINHELP_LayoutMainWindow(win);
693 ShowWindow(win->hMainWnd, nCmdShow);
699 /******************************************************************
700 * WINHELP_OpenHelpWindow
701 * Main function to search for a page and display it in a window
703 BOOL WINHELP_OpenHelpWindow(HLPFILE_PAGE* (*lookup)(HLPFILE*, LONG, ULONG*),
704 HLPFILE* hlpfile, LONG val, HLPFILE_WINDOWINFO* wi,
707 WINHELP_WNDPAGE wpage;
709 wpage.page = lookup(hlpfile, val, &wpage.relative);
710 if (wpage.page) wpage.page->file->wRefCount++;
712 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
715 /***********************************************************************
719 static HLPFILE_LINK* WINHELP_FindLink(WINHELP_WINDOW* win, LPARAM pos)
722 POINTL mouse_ptl, char_ptl, char_next_ptl;
725 if (!win->page) return NULL;
727 mouse_ptl.x = (short)LOWORD(pos);
728 mouse_ptl.y = (short)HIWORD(pos);
729 cp = SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_CHARFROMPOS,
730 0, (LPARAM)&mouse_ptl);
732 for (link = win->page->first_link; link; link = link->next)
734 if (link->cpMin <= cp && cp <= link->cpMax)
736 /* check whether we're at end of line */
737 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
738 (LPARAM)&char_ptl, cp);
739 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
740 (LPARAM)&char_next_ptl, cp + 1);
741 if (char_next_ptl.y != char_ptl.y || mouse_ptl.x >= char_next_ptl.x)
749 /******************************************************************
750 * WINHELP_HandleTextMouse
753 static BOOL WINHELP_HandleTextMouse(WINHELP_WINDOW* win, UINT msg, LPARAM lParam)
762 if (WINHELP_FindLink(win, lParam))
763 SetCursor(win->hHandCur);
765 SetCursor(LoadCursor(0, IDC_ARROW));
769 if ((win->current_link = WINHELP_FindLink(win, lParam)))
774 if ((link = WINHELP_FindLink(win, lParam)) && link == win->current_link)
776 HLPFILE_WINDOWINFO* wi;
778 switch (link->cookie)
781 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
783 if (link->window == -1)
785 else if (link->window < hlpfile->numWindows)
786 wi = &hlpfile->windows[link->window];
789 WINE_WARN("link to window %d/%d\n", link->window, hlpfile->numWindows);
792 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash, wi, SW_NORMAL);
796 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
797 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash,
798 WINHELP_GetPopupWindowInfo(hlpfile, win, lParam),
802 MACRO_ExecuteMacro(link->string);
805 WINE_FIXME("Unknown link cookie %d\n", link->cookie);
809 win->current_link = NULL;
815 /***********************************************************************
817 * WINHELP_MainWndProc
819 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
822 WINHELP_BUTTON *button;
824 INT curPos, min, max, dy, keyDelta;
828 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, &ret)) return ret;
833 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
834 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
835 if (!win->page && Globals.isBook)
836 PostMessage(hWnd, WM_COMMAND, MNID_FILE_OPEN, 0);
837 win->hMainWnd = hWnd;
840 case WM_WINDOWPOSCHANGED:
841 WINHELP_LayoutMainWindow((WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0));
845 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
849 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
850 case MNID_FILE_PRINT: MACRO_Print(); break;
851 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
852 case MNID_FILE_EXIT: MACRO_Exit(); break;
855 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
856 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
859 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
862 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
863 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
864 case MNID_HELP_ABOUT: MACRO_About(); break;
865 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
868 case MNID_CTXT_ANNOTATE:MACRO_Annotate(); break;
869 case MNID_CTXT_COPY: MACRO_CopyDialog(); break;
870 case MNID_CTXT_PRINT: MACRO_Print(); break;
871 case MNID_CTXT_FONTS_SMALL:
872 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
873 if (win->font_scale != 0)
876 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
879 case MNID_CTXT_FONTS_NORMAL:
880 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
881 if (win->font_scale != 1)
884 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
887 case MNID_CTXT_FONTS_LARGE:
888 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
889 if (win->font_scale != 2)
892 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
895 case MNID_CTXT_HELP_DEFAULT:
896 case MNID_CTXT_HELP_VISIBLE:
897 case MNID_CTXT_HELP_NONVISIBLE:
898 case MNID_CTXT_SYSTEM_COLORS:
903 for (button = win->first_button; button; button = button->next)
904 if (wParam == button->wParam) break;
906 MACRO_ExecuteMacro(button->lpszMacro);
907 else if (!HIWORD(wParam))
908 MessageBox(0, MAKEINTRESOURCE(STID_NOT_IMPLEMENTED),
909 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
913 /* EPP case WM_DESTROY: */
914 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
917 return WINHELP_HandleCommand((HWND)wParam, lParam);
926 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
928 keyDelta = -keyDelta;
932 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
933 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
934 curPos = GetScrollPos(hTextWnd, SB_VERT);
935 GetScrollRange(hTextWnd, SB_VERT, &min, &max);
939 GetClientRect(hTextWnd, &rect);
940 keyDelta = (rect.bottom - rect.top) / 2;
941 if (wParam == VK_PRIOR)
942 keyDelta = -keyDelta;
948 else if (curPos < min)
951 dy = GetScrollPos(hTextWnd, SB_VERT) - curPos;
952 SetScrollPos(hTextWnd, SB_VERT, curPos, TRUE);
953 ScrollWindow(hTextWnd, 0, dy, NULL, NULL);
954 UpdateWindow(hTextWnd);
964 if (wParam == CTL_ID_TEXT)
968 switch (((NMHDR*)lParam)->code)
972 const MSGFILTER* msgf = (const MSGFILTER*)lParam;
976 if (msgf->wParam == VK_ESCAPE) DestroyWindow(hWnd);
983 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
984 hMenu = LoadMenu(Globals.hInstance, (LPSTR)CONTEXT_MENU);
985 switch (win->font_scale)
988 CheckMenuItem(hMenu, MNID_CTXT_FONTS_SMALL,
989 MF_BYCOMMAND|MF_CHECKED);
992 WINE_FIXME("Unsupported %d\n", win->font_scale);
994 CheckMenuItem(hMenu, MNID_CTXT_FONTS_NORMAL,
995 MF_BYCOMMAND|MF_CHECKED);
998 CheckMenuItem(hMenu, MNID_CTXT_FONTS_LARGE,
999 MF_BYCOMMAND|MF_CHECKED);
1002 pt.x = (int)(short)LOWORD(msgf->lParam);
1003 pt.y = (int)(short)HIWORD(msgf->lParam);
1004 ClientToScreen(msgf->nmhdr.hwndFrom, &pt);
1005 TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_LEFTALIGN|TPM_TOPALIGN,
1006 pt.x, pt.y, 0, hWnd, NULL);
1011 return WINHELP_HandleTextMouse((WINHELP_WINDOW*)GetWindowLongPtr(hWnd, 0),
1012 msgf->msg, msgf->lParam);
1017 case EN_REQUESTRESIZE:
1018 rc = ((REQRESIZE*)lParam)->rc;
1019 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1020 AdjustWindowRect(&rc, GetWindowLong(win->hMainWnd, GWL_STYLE),
1022 SetWindowPos(win->hMainWnd, HWND_TOP, 0, 0,
1023 rc.right - rc.left, rc.bottom - rc.top,
1024 SWP_NOMOVE | SWP_NOZORDER);
1025 WINHELP_LayoutMainWindow(win);
1034 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1035 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1036 WINHELP_DeleteWindow(win);
1038 if (bExit) MACRO_Exit();
1039 if (!Globals.win_list)
1044 return DefWindowProc(hWnd, msg, wParam, lParam);
1047 static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff,
1050 struct RtfData* rd = (struct RtfData*)cookie;
1052 if (rd->where >= rd->ptr) return 1;
1053 if (rd->where + cb > rd->ptr)
1054 cb = rd->ptr - rd->where;
1055 memcpy(buff, rd->where, cb);
1061 static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative)
1063 SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0);
1064 SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color);
1065 /* set word-wrap to window size (undocumented) */
1066 SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0);
1076 if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative))
1079 es.dwCookie = (DWORD_PTR)&rd;
1081 es.pfnCallback = WINHELP_RtfStreamIn;
1083 SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
1084 cp = rd.char_pos_rel;
1086 /* FIXME: else leaking potentially the rd.first_link chain */
1087 HeapFree(GetProcessHeap(), 0, rd.data);
1088 SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0);
1089 pt.x = 0; pt.y = ptl.y;
1090 SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt);
1094 SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)"");
1096 SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0);
1097 InvalidateRect(hTextWnd, NULL, TRUE);
1100 /***********************************************************************
1102 * WINHELP_ButtonBoxWndProc
1104 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1107 WINHELP_WINDOW *win;
1108 WINHELP_BUTTON *button;
1112 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0L;
1116 case WM_WINDOWPOSCHANGING:
1117 winpos = (WINDOWPOS*) lParam;
1118 win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0);
1120 /* Update buttons */
1123 for (button = win->first_button; button; button = button->next)
1129 button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName,
1130 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
1132 hWnd, (HMENU) button->wParam,
1133 Globals.hInstance, 0);
1135 if (Globals.button_proc == NULL)
1136 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
1137 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
1140 hDc = GetDC(button->hWnd);
1141 GetTextExtentPoint(hDc, button->lpszName,
1142 lstrlen(button->lpszName), &textsize);
1143 ReleaseDC(button->hWnd, hDc);
1145 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
1146 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
1151 for (button = win->first_button; button; button = button->next)
1153 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
1155 if (x + 2 * button_size.cx <= winpos->cx)
1156 x += button_size.cx;
1158 x = 0, y += button_size.cy;
1160 winpos->cy = y + (x ? button_size.cy : 0);
1164 SendMessage(GetParent(hWnd), msg, wParam, lParam);
1175 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1180 return DefWindowProc(hWnd, msg, wParam, lParam);
1183 /***********************************************************************
1185 * WINHELP_ButtonWndProc
1187 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1189 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1191 if (msg == WM_KEYDOWN)
1200 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1204 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
1207 /******************************************************************
1208 * WINHELP_HistoryWndProc
1212 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1214 WINHELP_WINDOW* win;
1224 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1225 SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win);
1226 win->hHistoryWnd = hWnd;
1229 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1231 GetTextMetrics(hDc, &tm);
1232 GetWindowRect(hWnd, &r);
1234 r.right = r.left + 30 * tm.tmAveCharWidth;
1235 r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight;
1236 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1237 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1238 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1240 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1241 ReleaseDC(hWnd, hDc);
1243 case WM_LBUTTONDOWN:
1244 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1246 GetTextMetrics(hDc, &tm);
1247 i = HIWORD(lParam) / tm.tmHeight;
1248 if (i < Globals.history.index)
1249 WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE);
1250 ReleaseDC(hWnd, hDc);
1253 hDc = BeginPaint(hWnd, &ps);
1254 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1255 GetTextMetrics(hDc, &tm);
1257 for (i = 0; i < Globals.history.index; i++)
1259 if (Globals.history.set[i].page->file == Globals.active_win->page->file)
1261 TextOut(hDc, 0, i * tm.tmHeight,
1262 Globals.history.set[i].page->lpszTitle,
1263 strlen(Globals.history.set[i].page->lpszTitle));
1272 ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\');
1273 if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath;
1275 ptr2 = strrchr(ptr1, '.');
1276 len = ptr2 ? ptr2 - ptr1 : strlen(ptr1);
1277 if (len > sizeof(buffer)) len = sizeof(buffer);
1278 memcpy(buffer, ptr1, len);
1279 if (len < sizeof(buffer)) buffer[len++] = ':';
1280 strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len);
1281 buffer[sizeof(buffer) - 1] = '\0';
1282 TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer));
1285 EndPaint(hWnd, &ps);
1288 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1289 if (hWnd == win->hHistoryWnd)
1290 win->hHistoryWnd = 0;
1293 return DefWindowProc(hWnd, msg, wParam, lParam);
1296 /***********************************************************************
1298 * WINHELP_ShadowWndProc
1300 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1302 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1303 return WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL) ? 0L : DefWindowProc(hWnd, msg, wParam, lParam);
1306 /***********************************************************************
1308 * WINHELP_CheckPopup
1310 static BOOL WINHELP_CheckPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* lret)
1314 if (!Globals.active_popup) return FALSE;
1320 MSGFILTER* msgf = (MSGFILTER*)lParam;
1321 if (msgf->nmhdr.code == EN_MSGFILTER)
1323 if (!WINHELP_CheckPopup(hWnd, msgf->msg, msgf->wParam, msgf->lParam, NULL))
1325 if (lret) *lret = 1;
1331 if (wParam != WA_INACTIVE || (HWND)lParam == Globals.active_win->hMainWnd ||
1332 (HWND)lParam == Globals.active_popup->hMainWnd ||
1333 GetWindow((HWND)lParam, GW_OWNER) == Globals.active_win->hMainWnd)
1336 case WM_LBUTTONDOWN:
1337 if (WINHELP_HandleTextMouse(Globals.active_popup, msg, lParam) && msg == WM_LBUTTONDOWN)
1340 case WM_MBUTTONDOWN:
1341 case WM_RBUTTONDOWN:
1342 case WM_NCLBUTTONDOWN:
1343 case WM_NCMBUTTONDOWN:
1344 case WM_NCRBUTTONDOWN:
1345 hPopup = Globals.active_popup->hMainWnd;
1346 Globals.active_popup = NULL;
1347 DestroyWindow(hPopup);
1353 /******************************************************************
1354 * WINHELP_DeleteButtons
1357 static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
1362 for (b = win->first_button; b; b = bp)
1364 DestroyWindow(b->hWnd);
1366 HeapFree(GetProcessHeap(), 0, b);
1368 win->first_button = NULL;
1371 /******************************************************************
1372 * WINHELP_DeleteBackSet
1375 void WINHELP_DeleteBackSet(WINHELP_WINDOW* win)
1379 for (i = 0; i < win->back.index; i++)
1381 HLPFILE_FreeHlpFile(win->back.set[i].page->file);
1382 win->back.set[i].page = NULL;
1384 win->back.index = 0;
1387 /******************************************************************
1388 * WINHELP_DeletePageLinks
1391 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page)
1396 for (curr = page->first_link; curr; curr = next)
1399 HeapFree(GetProcessHeap(), 0, curr);
1403 /***********************************************************************
1405 * WINHELP_DeleteWindow
1407 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1411 for (w = &Globals.win_list; *w; w = &(*w)->next)
1420 if (Globals.active_win == win)
1422 Globals.active_win = Globals.win_list;
1423 if (Globals.win_list)
1424 SetActiveWindow(Globals.win_list->hMainWnd);
1427 if (win == Globals.active_popup)
1428 Globals.active_popup = NULL;
1430 WINHELP_DeleteButtons(win);
1432 if (win->page) WINHELP_DeletePageLinks(win->page);
1433 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1434 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1436 DeleteObject(win->hBrush);
1438 WINHELP_DeleteBackSet(win);
1440 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1441 HeapFree(GetProcessHeap(), 0, win);
1444 /***********************************************************************
1448 static void WINHELP_InitFonts(HWND hWnd)
1450 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1451 LOGFONT logfontlist[] = {
1452 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1453 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1454 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1455 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1456 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1457 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1458 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
1459 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1461 static HFONT fonts[FONTS_LEN];
1462 static BOOL init = 0;
1464 win->fonts_len = FONTS_LEN;
1471 for (i = 0; i < FONTS_LEN; i++)
1473 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1480 /***********************************************************************
1482 * WINHELP_MessageBoxIDS_s
1484 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1486 CHAR text[MAX_STRING_LEN];
1487 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
1489 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1490 wsprintf(newtext, text, str);
1492 return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type);
1495 /**************************************************************************
1498 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1501 static void cb_KWBTree(void *p, void **next, void *cookie)
1503 HWND hListWnd = (HWND)cookie;
1506 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
1507 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
1508 count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0);
1509 SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p);
1510 *next = (char*)p + strlen((char*)p) + 7;
1513 /**************************************************************************
1514 * WINHELP_IndexDlgProc
1516 * Index dialog callback function.
1518 * nResult passed to EndDialog:
1520 * >1: valid offset value +2.
1521 * EndDialog itself can return 0 (error).
1523 INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1525 static HLPFILE *file;
1532 file = (HLPFILE *)lParam;
1533 HLPFILE_BPTreeEnum(file->kwbtree, cb_KWBTree,
1534 GetDlgItem(hWnd, IDC_INDEXLIST));
1537 switch (LOWORD(wParam))
1540 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
1546 p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST,
1547 LB_GETITEMDATA, sel, 0);
1548 count = *(short*)((char *)p + strlen((char *)p) + 1);
1551 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
1554 offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
1555 offset = *(long*)(file->kwdata + offset + 9);
1556 if (offset == 0xFFFFFFFF)
1558 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
1565 EndDialog(hWnd, offset);
1576 /**************************************************************************
1577 * WINHELP_CreateIndexWindow
1579 * Displays a dialog with keywords of current help file.
1582 BOOL WINHELP_CreateIndexWindow(void)
1587 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
1588 hlpfile = Globals.active_win->page->file;
1592 if (hlpfile->kwbtree == NULL)
1594 WINE_TRACE("No index provided\n");
1598 ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_INDEX),
1599 Globals.active_win->hMainWnd, WINHELP_SearchDlgProc,
1604 WINE_TRACE("got %d as an offset\n", ret);
1605 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset, hlpfile, ret,
1606 Globals.active_win->info, SW_NORMAL);