winhelp: Display keywords index dialog box.
[wine.git] / programs / winhelp / winhelp.c
blobf769153250c58c0d7dfa7d798e630abdd79150bc
1 /*
2 * Help Viewer
4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002 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
24 #include <assert.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "commdlg.h"
35 #include "winhelp.h"
36 #include "winhelp_res.h"
37 #include "shellapi.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
43 static BOOL WINHELP_RegisterWinClasses(void);
44 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
45 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
47 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
48 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
49 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
50 static void WINHELP_CheckPopup(UINT);
51 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
52 static void WINHELP_InitFonts(HWND hWnd);
53 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
54 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
55 static void WINHELP_SetupText(HWND hWnd);
56 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
58 WINHELP_GLOBALS Globals = {3, NULL, NULL, 0, TRUE, NULL, NULL, NULL, NULL};
61 /***********************************************************************
63 * WINHELP_GetOpenFileName
65 BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len)
67 OPENFILENAME openfilename;
68 CHAR szDir[MAX_PATH];
69 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
70 LPSTR p = szzFilter;
72 WINE_TRACE("()\n");
74 LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
75 p += strlen(p) + 1;
76 lstrcpy(p, "*.hlp");
77 p += strlen(p) + 1;
78 LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
79 p += strlen(p) + 1;
80 lstrcpy(p, "*.*");
81 p += strlen(p) + 1;
82 *p = '\0';
84 GetCurrentDirectory(sizeof(szDir), szDir);
86 lpszFile[0]='\0';
88 openfilename.lStructSize = sizeof(OPENFILENAME);
89 openfilename.hwndOwner = NULL;
90 openfilename.hInstance = Globals.hInstance;
91 openfilename.lpstrFilter = szzFilter;
92 openfilename.lpstrCustomFilter = 0;
93 openfilename.nMaxCustFilter = 0;
94 openfilename.nFilterIndex = 1;
95 openfilename.lpstrFile = lpszFile;
96 openfilename.nMaxFile = len;
97 openfilename.lpstrFileTitle = 0;
98 openfilename.nMaxFileTitle = 0;
99 openfilename.lpstrInitialDir = szDir;
100 openfilename.lpstrTitle = 0;
101 openfilename.Flags = 0;
102 openfilename.nFileOffset = 0;
103 openfilename.nFileExtension = 0;
104 openfilename.lpstrDefExt = 0;
105 openfilename.lCustData = 0;
106 openfilename.lpfnHook = 0;
107 openfilename.lpTemplateName = 0;
109 return GetOpenFileName(&openfilename);
112 /***********************************************************************
114 * WINHELP_LookupHelpFile
116 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
118 HLPFILE* hlpfile;
119 char szFullName[MAX_PATH];
120 char szAddPath[MAX_PATH];
121 char *p;
124 * NOTE: This is needed by popup windows only.
125 * In other cases it's not needed but does not hurt though.
127 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
129 strcpy(szAddPath, Globals.active_win->page->file->lpszPath);
130 p = strrchr(szAddPath, '\\');
131 if (p) *p = 0;
135 * FIXME: Should we swap conditions?
137 if (!SearchPath(NULL, lpszFile, ".hlp", MAX_PATH, szFullName, NULL) &&
138 !SearchPath(szAddPath, lpszFile, ".hlp", MAX_PATH, szFullName, NULL))
140 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s, lpszFile, STID_WHERROR,
141 MB_YESNO|MB_ICONQUESTION) != IDYES)
142 return NULL;
143 if (!WINHELP_GetOpenFileName(szFullName, MAX_PATH))
144 return NULL;
146 hlpfile = HLPFILE_ReadHlpFile(szFullName);
147 if (!hlpfile)
148 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile,
149 STID_WHERROR, MB_OK|MB_ICONSTOP);
150 return hlpfile;
153 /******************************************************************
154 * WINHELP_GetWindowInfo
158 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
160 static HLPFILE_WINDOWINFO mwi;
161 unsigned int i;
163 if (!name || !name[0])
164 name = Globals.active_win->lpszName;
166 if (hlpfile)
167 for (i = 0; i < hlpfile->numWindows; i++)
168 if (!strcmp(hlpfile->windows[i].name, name))
169 return &hlpfile->windows[i];
171 if (strcmp(name, "main") != 0)
173 WINE_FIXME("Couldn't find window info for %s\n", name);
174 assert(0);
175 return NULL;
177 if (!mwi.name[0])
179 strcpy(mwi.type, "primary");
180 strcpy(mwi.name, "main");
181 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
182 mwi.caption, sizeof(mwi.caption)))
183 strcpy(mwi.caption, hlpfile->lpszTitle);
184 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
185 mwi.style = SW_SHOW;
186 mwi.win_style = WS_OVERLAPPEDWINDOW;
187 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
189 return &mwi;
192 /******************************************************************
193 * HLPFILE_GetPopupWindowInfo
197 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
199 static HLPFILE_WINDOWINFO wi;
201 RECT parent_rect;
203 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
205 /* Calculate horizontal size and position of a popup window */
206 GetWindowRect(hParentWnd, &parent_rect);
207 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
208 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
210 wi.origin = *mouse;
211 ClientToScreen(hParentWnd, &wi.origin);
212 wi.origin.x -= wi.size.cx / 2;
213 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
214 wi.origin.x = max(wi.origin.x, 0);
216 wi.style = SW_SHOW;
217 wi.win_style = WS_POPUP | WS_BORDER;
218 wi.sr_color = wi.sr_color = 0xFFFFFF;
220 return &wi;
223 /***********************************************************************
225 * WinMain
227 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
229 MSG msg;
230 LONG lHash = 0;
231 HLPFILE* hlpfile;
232 static CHAR default_wndname[] = "main";
233 LPSTR wndname = default_wndname;
234 WINHELP_DLL* dll;
236 Globals.hInstance = hInstance;
238 /* Get options */
239 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
241 CHAR option;
242 LPCSTR topic_id;
243 if (*cmdline++ == ' ') continue;
245 option = *cmdline;
246 if (option) cmdline++;
247 while (*cmdline && *cmdline == ' ') cmdline++;
248 switch (option)
250 case 'i':
251 case 'I':
252 topic_id = cmdline;
253 while (*cmdline && *cmdline != ' ') cmdline++;
254 if (*cmdline) *cmdline++ = '\0';
255 lHash = HLPFILE_Hash(topic_id);
256 break;
258 case '3':
259 case '4':
260 Globals.wVersion = option - '0';
261 break;
263 case 'x':
264 show = SW_HIDE;
265 Globals.isBook = FALSE;
266 break;
268 default:
269 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
270 break;
274 /* Create primary window */
275 if (!WINHELP_RegisterWinClasses())
277 WINE_FIXME("Couldn't register classes\n");
278 return 0;
281 if (*cmdline)
283 char* ptr;
284 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
286 cmdline++;
287 *ptr = '\0';
289 if ((ptr = strchr(cmdline, '>')))
291 *ptr = '\0';
292 wndname = ptr + 1;
294 hlpfile = WINHELP_LookupHelpFile(cmdline);
295 if (!hlpfile) return 0;
297 else hlpfile = NULL;
298 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
299 WINHELP_GetWindowInfo(hlpfile, wndname), show);
301 /* Message loop */
302 while (GetMessage(&msg, 0, 0, 0))
304 TranslateMessage(&msg);
305 DispatchMessage(&msg);
307 for (dll = Globals.dlls; dll; dll = dll->next)
309 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
311 return 0;
314 /***********************************************************************
316 * RegisterWinClasses
318 static BOOL WINHELP_RegisterWinClasses(void)
320 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
322 class_main.style = CS_HREDRAW | CS_VREDRAW;
323 class_main.lpfnWndProc = WINHELP_MainWndProc;
324 class_main.cbClsExtra = 0;
325 class_main.cbWndExtra = sizeof(LONG);
326 class_main.hInstance = Globals.hInstance;
327 class_main.hIcon = LoadIcon(0, IDI_APPLICATION);
328 class_main.hCursor = LoadCursor(0, IDC_ARROW);
329 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
330 class_main.lpszMenuName = 0;
331 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
333 class_button_box = class_main;
334 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
335 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
336 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
338 class_text = class_main;
339 class_text.lpfnWndProc = WINHELP_TextWndProc;
340 class_text.hbrBackground = 0;
341 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
343 class_shadow = class_main;
344 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
345 class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
346 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
348 class_history = class_main;
349 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
350 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
352 return (RegisterClass(&class_main) &&
353 RegisterClass(&class_button_box) &&
354 RegisterClass(&class_text) &&
355 RegisterClass(&class_shadow) &&
356 RegisterClass(&class_history));
359 typedef struct
361 WORD size;
362 WORD command;
363 LONG data;
364 LONG reserved;
365 WORD ofsFilename;
366 WORD ofsData;
367 } WINHELP,*LPWINHELP;
369 /******************************************************************
370 * WINHELP_HandleCommand
374 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
376 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
377 WINHELP* wh;
379 if (cds->dwData != 0xA1DE505)
381 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
382 return 0;
385 wh = (WINHELP*)cds->lpData;
387 if (wh)
389 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
391 WINE_TRACE("Got[%u]: cmd=%u data=%08x fn=%s\n",
392 wh->size, wh->command, wh->data, ptr);
393 switch (wh->command)
395 case HELP_CONTEXT:
396 if (ptr)
398 MACRO_JumpContext(ptr, "main", wh->data);
400 break;
401 case HELP_QUIT:
402 MACRO_Exit();
403 break;
404 case HELP_CONTENTS:
405 if (ptr)
407 MACRO_JumpContents(ptr, "main");
409 break;
410 case HELP_HELPONHELP:
411 MACRO_HelpOn();
412 break;
413 /* case HELP_SETINDEX: */
414 case HELP_SETCONTENTS:
415 if (ptr)
417 MACRO_SetContents(ptr, wh->data);
419 break;
420 case HELP_CONTEXTPOPUP:
421 if (ptr)
423 MACRO_PopupContext(ptr, wh->data);
425 break;
426 /* case HELP_FORCEFILE:*/
427 /* case HELP_CONTEXTMENU: */
428 case HELP_FINDER:
429 /* in fact, should be the topic dialog box */
430 WINE_FIXME("HELP_FINDER: stub\n");
431 if (ptr)
433 MACRO_JumpHash(ptr, "main", 0);
435 break;
436 /* case HELP_WM_HELP: */
437 /* case HELP_SETPOPUP_POS: */
438 /* case HELP_KEY: */
439 /* case HELP_COMMAND: */
440 /* case HELP_PARTIALKEY: */
441 /* case HELP_MULTIKEY: */
442 /* case HELP_SETWINPOS: */
443 default:
444 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
445 break;
448 /* Always return success for now */
449 return 1;
452 /******************************************************************
453 * WINHELP_ReuseWindow
457 static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
458 HLPFILE_PAGE* page, int nCmdShow)
460 unsigned int i;
462 win->hMainWnd = oldwin->hMainWnd;
463 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
464 win->hTextWnd = oldwin->hTextWnd;
465 win->hHistoryWnd = oldwin->hHistoryWnd;
466 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
467 win->hBrush = oldwin->hBrush;
469 SetWindowLong(win->hMainWnd, 0, (LONG)win);
470 SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
471 SetWindowLong(win->hTextWnd, 0, (LONG)win);
472 SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
474 WINHELP_InitFonts(win->hMainWnd);
476 if (page)
477 SetWindowText(win->hMainWnd, page->file->lpszTitle);
479 WINHELP_SetupText(win->hTextWnd);
480 InvalidateRect(win->hTextWnd, NULL, TRUE);
481 SendMessage(win->hMainWnd, WM_USER, 0, 0);
482 ShowWindow(win->hMainWnd, nCmdShow);
483 UpdateWindow(win->hTextWnd);
485 if (!(win->info->win_style & WS_POPUP))
487 unsigned num;
489 memcpy(win->history, oldwin->history, sizeof(win->history));
490 win->histIndex = oldwin->histIndex;
492 /* FIXME: when using back, we shouldn't update the history... */
494 if (page)
496 for (i = 0; i < win->histIndex; i++)
497 if (win->history[i] == page) break;
499 /* if the new page is already in the history, do nothing */
500 if (i == win->histIndex)
502 num = sizeof(win->history) / sizeof(win->history[0]);
503 if (win->histIndex == num)
505 /* we're full, remove latest entry */
506 HLPFILE_FreeHlpFile(win->history[0]->file);
507 memmove(&win->history[0], &win->history[1],
508 (num - 1) * sizeof(win->history[0]));
509 win->histIndex--;
511 win->history[win->histIndex++] = page;
512 page->file->wRefCount++;
513 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
517 memcpy(win->back, oldwin->back, sizeof(win->back));
518 win->backIndex = oldwin->backIndex;
520 if (page)
522 num = sizeof(win->back) / sizeof(win->back[0]);
523 if (win->backIndex == num)
525 /* we're full, remove latest entry */
526 HLPFILE_FreeHlpFile(win->back[0]->file);
527 memmove(&win->back[0], &win->back[1],
528 (num - 1) * sizeof(win->back[0]));
529 win->backIndex--;
531 win->back[win->backIndex++] = page;
532 page->file->wRefCount++;
535 else
536 win->backIndex = win->histIndex = 0;
538 oldwin->histIndex = oldwin->backIndex = 0;
539 WINHELP_DeleteWindow(oldwin);
540 return TRUE;
543 /***********************************************************************
545 * WINHELP_CreateHelpWindow
547 BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
548 int nCmdShow)
550 WINHELP_WINDOW *win, *oldwin;
551 HWND hWnd;
552 BOOL bPrimary;
553 BOOL bPopup;
554 LPSTR name;
555 DWORD ex_style;
557 bPrimary = !lstrcmpi(wi->name, "main");
558 bPopup = wi->win_style & WS_POPUP;
560 /* Initialize WINHELP_WINDOW struct */
561 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
562 sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
563 if (!win) return FALSE;
565 win->next = Globals.win_list;
566 Globals.win_list = win;
568 name = (char*)win + sizeof(WINHELP_WINDOW);
569 lstrcpy(name, wi->name);
570 win->lpszName = name;
572 win->page = page;
574 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
575 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
577 win->info = wi;
579 Globals.active_win = win;
581 /* Initialize default pushbuttons */
582 if (bPrimary && page)
584 CHAR buffer[MAX_STRING_LEN];
586 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
587 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
588 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
589 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
590 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
591 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
592 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
593 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
594 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
595 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
598 /* Initialize file specific pushbuttons */
599 if (!(wi->win_style & WS_POPUP) && page)
601 HLPFILE_MACRO *macro;
602 for (macro = page->file->first_macro; macro; macro = macro->next)
603 MACRO_ExecuteMacro(macro->lpszMacro);
605 for (macro = page->first_macro; macro; macro = macro->next)
606 MACRO_ExecuteMacro(macro->lpszMacro);
609 /* Reuse existing window */
610 if (!bPopup)
612 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
614 if (!lstrcmpi(oldwin->lpszName, wi->name))
616 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
619 if (page)
621 win->histIndex = win->backIndex = 1;
622 win->history[0] = win->back[0] = page;
623 page->file->wRefCount += 2;
624 strcpy(wi->caption, page->file->lpszTitle);
628 ex_style = 0;
629 if (bPopup) ex_style = WS_EX_TOOLWINDOW;
630 hWnd = CreateWindowEx(ex_style, bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
631 wi->caption,
632 bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
633 wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
634 NULL, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
635 Globals.hInstance, win);
637 ShowWindow(hWnd, nCmdShow);
638 UpdateWindow(hWnd);
640 return TRUE;
643 /***********************************************************************
645 * WINHELP_CreateHelpWindowByHash
647 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
648 HLPFILE_WINDOWINFO* wi, int nCmdShow)
650 HLPFILE_PAGE* page = NULL;
652 if (hlpfile)
653 page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
654 HLPFILE_Contents(hlpfile);
655 if (page) page->file->wRefCount++;
656 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
659 /***********************************************************************
661 * WINHELP_CreateHelpWindowByMap
663 BOOL WINHELP_CreateHelpWindowByMap(HLPFILE* hlpfile, LONG lMap,
664 HLPFILE_WINDOWINFO* wi, int nCmdShow)
666 HLPFILE_PAGE* page = NULL;
668 page = HLPFILE_PageByMap(hlpfile, lMap);
669 if (page) page->file->wRefCount++;
670 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
673 /***********************************************************************
675 * WINHELP_CreateHelpWindowByOffset
677 BOOL WINHELP_CreateHelpWindowByOffset(HLPFILE* hlpfile, LONG lOffset,
678 HLPFILE_WINDOWINFO* wi, int nCmdShow)
680 HLPFILE_PAGE* page = NULL;
682 page = HLPFILE_PageByOffset(hlpfile, lOffset);
683 if (page) page->file->wRefCount++;
684 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
687 /***********************************************************************
689 * WINHELP_MainWndProc
691 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
693 WINHELP_WINDOW *win;
694 WINHELP_BUTTON *button;
695 RECT rect, button_box_rect;
696 INT text_top, curPos, min, max, dy, keyDelta;
698 WINHELP_CheckPopup(msg);
700 switch (msg)
702 case WM_NCCREATE:
703 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
704 SetWindowLong(hWnd, 0, (LONG) win);
705 win->hMainWnd = hWnd;
706 break;
708 case WM_CREATE:
709 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
711 /* Create button box and text Window */
712 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
713 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
715 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
716 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
718 /* Fall through */
719 case WM_USER:
720 case WM_WINDOWPOSCHANGED:
721 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
722 GetClientRect(hWnd, &rect);
724 /* Update button box and text Window */
725 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
726 rect.left, rect.top,
727 rect.right - rect.left,
728 rect.bottom - rect.top, 0);
730 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
731 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
733 SetWindowPos(win->hTextWnd, HWND_TOP,
734 rect.left, text_top,
735 rect.right - rect.left,
736 rect.bottom - text_top, 0);
738 break;
740 case WM_COMMAND:
741 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
742 switch (wParam)
744 /* Menu FILE */
745 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
746 case MNID_FILE_PRINT: MACRO_Print(); break;
747 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
748 case MNID_FILE_EXIT: MACRO_Exit(); break;
750 /* Menu EDIT */
751 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
752 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
754 /* Menu Bookmark */
755 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
757 /* Menu Help */
758 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
759 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
760 case MNID_HELP_ABOUT: MACRO_About(); break;
761 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
763 default:
764 /* Buttons */
765 for (button = win->first_button; button; button = button->next)
766 if (wParam == button->wParam) break;
767 if (button)
768 MACRO_ExecuteMacro(button->lpszMacro);
769 else
770 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
771 break;
773 break;
774 case WM_DESTROY:
775 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
776 break;
777 case WM_COPYDATA:
778 return WINHELP_HandleCommand((HWND)wParam, lParam);
780 case WM_KEYDOWN:
781 keyDelta = 0;
783 switch (wParam)
785 case VK_UP:
786 case VK_DOWN:
787 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
788 if (wParam == VK_UP)
789 keyDelta = -keyDelta;
791 case VK_PRIOR:
792 case VK_NEXT:
793 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
794 curPos = GetScrollPos(win->hTextWnd, SB_VERT);
795 GetScrollRange(win->hTextWnd, SB_VERT, &min, &max);
797 if (keyDelta == 0)
799 GetClientRect(win->hTextWnd, &rect);
800 keyDelta = (rect.bottom - rect.top) / 2;
801 if (wParam == VK_PRIOR)
802 keyDelta = -keyDelta;
805 curPos += keyDelta;
806 if (curPos > max)
807 curPos = max;
808 else if (curPos < min)
809 curPos = min;
811 dy = GetScrollPos(win->hTextWnd, SB_VERT) - curPos;
812 SetScrollPos(win->hTextWnd, SB_VERT, curPos, TRUE);
813 ScrollWindow(win->hTextWnd, 0, dy, NULL, NULL);
814 UpdateWindow(win->hTextWnd);
815 return 0;
817 case VK_ESCAPE:
818 MACRO_Exit();
819 return 0;
821 break;
823 return DefWindowProc(hWnd, msg, wParam, lParam);
826 /***********************************************************************
828 * WINHELP_ButtonBoxWndProc
830 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
832 WINDOWPOS *winpos;
833 WINHELP_WINDOW *win;
834 WINHELP_BUTTON *button;
835 SIZE button_size;
836 INT x, y;
838 WINHELP_CheckPopup(msg);
840 switch (msg)
842 case WM_NCCREATE:
843 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
844 SetWindowLong(hWnd, 0, (LONG) win);
845 win->hButtonBoxWnd = hWnd;
846 break;
848 case WM_WINDOWPOSCHANGING:
849 winpos = (WINDOWPOS*) lParam;
850 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
852 /* Update buttons */
853 button_size.cx = 0;
854 button_size.cy = 0;
855 for (button = win->first_button; button; button = button->next)
857 HDC hDc;
858 SIZE textsize;
859 if (!button->hWnd)
861 button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName,
862 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
863 0, 0, 0, 0,
864 hWnd, (HMENU) button->wParam,
865 Globals.hInstance, 0);
866 if (button->hWnd) {
867 if (Globals.button_proc == NULL)
868 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
869 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
872 hDc = GetDC(button->hWnd);
873 GetTextExtentPoint(hDc, button->lpszName,
874 lstrlen(button->lpszName), &textsize);
875 ReleaseDC(button->hWnd, hDc);
877 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
878 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
881 x = 0;
882 y = 0;
883 for (button = win->first_button; button; button = button->next)
885 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
887 if (x + 2 * button_size.cx <= winpos->cx)
888 x += button_size.cx;
889 else
890 x = 0, y += button_size.cy;
892 winpos->cy = y + (x ? button_size.cy : 0);
893 break;
895 case WM_COMMAND:
896 SendMessage(GetParent(hWnd), msg, wParam, lParam);
897 break;
899 case WM_KEYDOWN:
900 switch (wParam)
902 case VK_UP:
903 case VK_DOWN:
904 case VK_PRIOR:
905 case VK_NEXT:
906 case VK_ESCAPE:
907 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
909 break;
912 return DefWindowProc(hWnd, msg, wParam, lParam);
915 /***********************************************************************
917 * WINHELP_ButtonWndProc
919 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
921 if (msg == WM_KEYDOWN)
923 switch (wParam)
925 case VK_UP:
926 case VK_DOWN:
927 case VK_PRIOR:
928 case VK_NEXT:
929 case VK_ESCAPE:
930 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
934 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
937 /***********************************************************************
939 * WINHELP_TextWndProc
941 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
943 WINHELP_WINDOW *win;
944 WINHELP_LINE *line;
945 WINHELP_LINE_PART *part;
946 WINDOWPOS *winpos;
947 PAINTSTRUCT ps;
948 HDC hDc;
949 POINT mouse;
950 INT scroll_pos;
951 HWND hPopupWnd;
952 BOOL bExit;
954 if (msg != WM_LBUTTONDOWN)
955 WINHELP_CheckPopup(msg);
957 switch (msg)
959 case WM_NCCREATE:
960 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
961 SetWindowLong(hWnd, 0, (LONG) win);
962 win->hTextWnd = hWnd;
963 win->hBrush = CreateSolidBrush(win->info->sr_color);
964 if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
965 WINHELP_InitFonts(hWnd);
966 break;
968 case WM_CREATE:
969 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
971 /* Calculate vertical size and position of a popup window */
972 if (win->info->win_style & WS_POPUP)
974 POINT origin;
975 RECT old_window_rect;
976 RECT old_client_rect;
977 SIZE old_window_size;
978 SIZE old_client_size;
979 SIZE new_client_size;
980 SIZE new_window_size;
982 GetWindowRect(hWnd, &old_window_rect);
983 origin.x = old_window_rect.left;
984 origin.y = old_window_rect.top;
985 old_window_size.cx = old_window_rect.right - old_window_rect.left;
986 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
988 GetClientRect(hWnd, &old_client_rect);
989 old_client_size.cx = old_client_rect.right - old_client_rect.left;
990 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
992 new_client_size = old_client_size;
993 WINHELP_SplitLines(hWnd, &new_client_size);
995 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
996 origin.y += POPUP_YDISTANCE;
997 else
998 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
1000 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
1001 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
1003 win->hShadowWnd =
1004 CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
1005 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
1006 new_window_size.cx, new_window_size.cy,
1007 0, 0, Globals.hInstance, 0);
1009 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
1010 new_window_size.cx, new_window_size.cy,
1012 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
1013 ShowWindow(win->hShadowWnd, SW_NORMAL);
1014 SetActiveWindow(hWnd);
1016 break;
1018 case WM_WINDOWPOSCHANGED:
1019 winpos = (WINDOWPOS*) lParam;
1021 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
1022 break;
1024 case WM_MOUSEWHEEL:
1026 int wheelDelta = 0;
1027 UINT scrollLines = 3;
1028 int curPos = GetScrollPos(hWnd, SB_VERT);
1029 int min, max;
1031 GetScrollRange(hWnd, SB_VERT, &min, &max);
1033 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
1034 if (wParam & (MK_SHIFT | MK_CONTROL))
1035 return DefWindowProc(hWnd, msg, wParam, lParam);
1036 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
1037 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
1038 int dy;
1040 curPos += wheelDelta;
1041 if (curPos > max)
1042 curPos = max;
1043 else if (curPos < min)
1044 curPos = min;
1046 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
1047 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
1048 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1049 UpdateWindow(hWnd);
1052 break;
1054 case WM_VSCROLL:
1056 BOOL update = TRUE;
1057 RECT rect;
1058 INT Min, Max;
1059 INT CurPos = GetScrollPos(hWnd, SB_VERT);
1060 INT dy;
1062 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
1063 GetClientRect(hWnd, &rect);
1065 switch (wParam & 0xffff)
1067 case SB_THUMBTRACK:
1068 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
1069 case SB_TOP: CurPos = Min; break;
1070 case SB_BOTTOM: CurPos = Max; break;
1071 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
1072 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
1073 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
1074 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
1075 default: update = FALSE;
1077 if (update)
1079 if (CurPos > Max)
1080 CurPos = Max;
1081 else if (CurPos < Min)
1082 CurPos = Min;
1083 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
1084 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
1085 ScrollWindow(hWnd, 0, dy, NULL, NULL);
1086 UpdateWindow(hWnd);
1089 break;
1091 case WM_PAINT:
1092 hDc = BeginPaint(hWnd, &ps);
1093 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1094 scroll_pos = GetScrollPos(hWnd, SB_VERT);
1096 /* No DPtoLP needed - MM_TEXT map mode */
1097 if (ps.fErase) FillRect(hDc, &ps.rcPaint, win->hBrush);
1098 for (line = win->first_line; line; line = line->next)
1100 for (part = &line->first_part; part; part = part->next)
1102 switch (part->cookie)
1104 case hlp_line_part_text:
1105 SelectObject(hDc, part->u.text.hFont);
1106 SetTextColor(hDc, part->u.text.color);
1107 SetBkColor(hDc, win->info->sr_color);
1108 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
1109 part->u.text.lpsText, part->u.text.wTextLen);
1110 if (part->u.text.wUnderline)
1112 HPEN hPen;
1114 switch (part->u.text.wUnderline)
1116 case 1: /* simple */
1117 case 2: /* double */
1118 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
1119 break;
1120 case 3: /* dotted */
1121 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
1122 break;
1123 default:
1124 WINE_FIXME("Unknow underline type\n");
1125 continue;
1128 SelectObject(hDc, hPen);
1129 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
1130 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
1131 if (part->u.text.wUnderline == 2)
1133 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
1134 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
1136 DeleteObject(hPen);
1138 break;
1139 case hlp_line_part_bitmap:
1141 HDC hMemDC;
1143 hMemDC = CreateCompatibleDC(hDc);
1144 SelectObject(hMemDC, part->u.bitmap.hBitmap);
1145 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1146 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
1147 hMemDC, 0, 0, SRCCOPY);
1148 DeleteDC(hMemDC);
1150 break;
1151 case hlp_line_part_metafile:
1153 HDC hMemDC;
1154 HBITMAP hBitmap;
1155 SIZE sz;
1156 RECT rc;
1158 sz.cx = part->rect.right - part->rect.left;
1159 sz.cy = part->rect.bottom - part->rect.top;
1160 hMemDC = CreateCompatibleDC(hDc);
1161 hBitmap = CreateCompatibleBitmap(hDc, sz.cx, sz.cy);
1162 SelectObject(hMemDC, hBitmap);
1163 SelectObject(hMemDC, win->hBrush);
1164 rc.left = 0;
1165 rc.top = 0;
1166 rc.right = sz.cx;
1167 rc.bottom = sz.cy;
1168 FillRect(hMemDC, &rc, win->hBrush);
1169 SetMapMode(hMemDC, part->u.metafile.mm);
1170 SetWindowExtEx(hMemDC, sz.cx, sz.cy, 0);
1171 SetViewportExtEx(hMemDC, sz.cx, sz.cy, 0);
1172 SetWindowOrgEx(hMemDC, 0, 0, 0);
1173 SetViewportOrgEx(hMemDC, 0, 0, 0);
1174 PlayMetaFile(hMemDC, part->u.metafile.hMetaFile);
1175 SetMapMode(hMemDC, MM_TEXT);
1176 SetWindowOrgEx(hMemDC, 0, 0, 0);
1177 SetViewportOrgEx(hMemDC, 0, 0, 0);
1178 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1179 sz.cx, sz.cy, hMemDC, 0, 0, SRCCOPY);
1180 DeleteDC(hMemDC);
1181 DeleteObject(hBitmap);
1183 break;
1188 EndPaint(hWnd, &ps);
1189 break;
1191 case WM_MOUSEMOVE:
1192 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1194 if (WINHELP_IsOverLink(win, wParam, lParam))
1195 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
1196 else
1197 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
1199 break;
1201 case WM_LBUTTONDOWN:
1202 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1204 hPopupWnd = Globals.hPopupWnd;
1205 Globals.hPopupWnd = 0;
1207 part = WINHELP_IsOverLink(win, wParam, lParam);
1208 if (part)
1210 HLPFILE* hlpfile;
1211 HLPFILE_WINDOWINFO* wi;
1213 mouse.x = (short)LOWORD(lParam);
1214 mouse.y = (short)HIWORD(lParam);
1216 if (part->link) switch (part->link->cookie)
1218 case hlp_link_link:
1219 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1220 if (part->link->window == -1)
1221 wi = win->info;
1222 else if ((part->link->window >= 0) && (part->link->window < hlpfile->numWindows))
1223 wi = &hlpfile->windows[part->link->window];
1224 else
1226 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
1227 break;
1229 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
1230 SW_NORMAL);
1231 break;
1232 case hlp_link_popup:
1233 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1234 if (hlpfile) WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
1235 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
1236 SW_NORMAL);
1237 break;
1238 case hlp_link_macro:
1239 MACRO_ExecuteMacro(part->link->lpszString);
1240 break;
1241 default:
1242 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1246 if (hPopupWnd)
1247 DestroyWindow(hPopupWnd);
1248 break;
1250 case WM_NCDESTROY:
1251 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1253 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
1255 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1256 DeleteObject(win->hBrush);
1258 WINHELP_DeleteWindow(win);
1260 if (bExit) MACRO_Exit();
1262 if (!Globals.win_list)
1263 PostQuitMessage(0);
1264 break;
1267 return DefWindowProc(hWnd, msg, wParam, lParam);
1270 /******************************************************************
1271 * WINHELP_HistoryWndProc
1275 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1277 WINHELP_WINDOW* win;
1278 PAINTSTRUCT ps;
1279 HDC hDc;
1280 TEXTMETRIC tm;
1281 unsigned int i;
1282 RECT r;
1284 switch (msg)
1286 case WM_NCCREATE:
1287 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1288 SetWindowLong(hWnd, 0, (LONG)win);
1289 win->hHistoryWnd = hWnd;
1290 break;
1291 case WM_CREATE:
1292 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1293 hDc = GetDC(hWnd);
1294 GetTextMetrics(hDc, &tm);
1295 GetWindowRect(hWnd, &r);
1297 r.right = r.left + 30 * tm.tmAveCharWidth;
1298 r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
1299 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1300 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1301 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1303 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1304 ReleaseDC(hWnd, hDc);
1305 break;
1306 case WM_LBUTTONDOWN:
1307 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1308 hDc = GetDC(hWnd);
1309 GetTextMetrics(hDc, &tm);
1310 i = HIWORD(lParam) / tm.tmHeight;
1311 if (i < win->histIndex)
1312 WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
1313 ReleaseDC(hWnd, hDc);
1314 break;
1315 case WM_PAINT:
1316 hDc = BeginPaint(hWnd, &ps);
1317 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1318 GetTextMetrics(hDc, &tm);
1320 for (i = 0; i < win->histIndex; i++)
1322 TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle,
1323 strlen(win->history[i]->lpszTitle));
1325 EndPaint(hWnd, &ps);
1326 break;
1327 case WM_DESTROY:
1328 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1329 if (hWnd == win->hHistoryWnd)
1330 win->hHistoryWnd = 0;
1331 break;
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 WINHELP_CheckPopup(msg);
1343 return DefWindowProc(hWnd, msg, wParam, lParam);
1346 /***********************************************************************
1348 * SetupText
1350 static void WINHELP_SetupText(HWND hWnd)
1352 HDC hDc = GetDC(hWnd);
1353 RECT rect;
1354 SIZE newsize;
1356 ShowScrollBar(hWnd, SB_VERT, FALSE);
1357 if (!WINHELP_SplitLines(hWnd, NULL))
1359 ShowScrollBar(hWnd, SB_VERT, TRUE);
1360 GetClientRect(hWnd, &rect);
1362 WINHELP_SplitLines(hWnd, &newsize);
1363 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1365 else
1367 SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1368 SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
1371 ReleaseDC(hWnd, hDc);
1374 /***********************************************************************
1376 * WINHELP_AppendText
1378 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1379 LPSIZE space, LPSIZE textsize,
1380 INT *line_ascent, INT ascent,
1381 LPCSTR text, UINT textlen,
1382 HFONT font, COLORREF color, HLPFILE_LINK *link,
1383 unsigned underline)
1385 WINHELP_LINE *line;
1386 WINHELP_LINE_PART *part;
1387 LPSTR ptr;
1389 if (!*partp) /* New line */
1391 *line_ascent = ascent;
1393 line = HeapAlloc(GetProcessHeap(), 0,
1394 sizeof(WINHELP_LINE) + textlen);
1395 if (!line) return FALSE;
1397 line->next = 0;
1398 part = &line->first_part;
1399 ptr = (char*)line + sizeof(WINHELP_LINE);
1401 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1402 line->rect.bottom = line->rect.top;
1403 line->rect.left = space->cx;
1404 line->rect.right = space->cx;
1406 if (**linep) *linep = &(**linep)->next;
1407 **linep = line;
1408 space->cy = 0;
1410 else /* Same line */
1412 line = **linep;
1414 if (*line_ascent < ascent)
1416 WINHELP_LINE_PART *p;
1417 for (p = &line->first_part; p; p = p->next)
1419 p->rect.top += ascent - *line_ascent;
1420 p->rect.bottom += ascent - *line_ascent;
1422 line->rect.bottom += ascent - *line_ascent;
1423 *line_ascent = ascent;
1426 part = HeapAlloc(GetProcessHeap(), 0,
1427 sizeof(WINHELP_LINE_PART) + textlen);
1428 if (!part) return FALSE;
1429 **partp = part;
1430 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1433 memcpy(ptr, text, textlen);
1434 part->cookie = hlp_line_part_text;
1435 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1436 part->rect.right = part->rect.left + textsize->cx;
1437 line->rect.right = part->rect.right;
1438 part->rect.top =
1439 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1440 part->rect.bottom = part->rect.top + textsize->cy;
1441 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1442 part->u.text.lpsText = ptr;
1443 part->u.text.wTextLen = textlen;
1444 part->u.text.hFont = font;
1445 part->u.text.color = color;
1446 part->u.text.wUnderline = underline;
1448 WINE_TRACE("Appended text '%*.*s'[%d] @ (%d,%d-%d,%d)\n",
1449 part->u.text.wTextLen,
1450 part->u.text.wTextLen,
1451 part->u.text.lpsText,
1452 part->u.text.wTextLen,
1453 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1455 part->link = link;
1456 if (link) link->wRefCount++;
1458 part->next = 0;
1459 *partp = &part->next;
1461 space->cx = 0;
1463 return TRUE;
1466 /***********************************************************************
1468 * WINHELP_AppendGfxObject
1470 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1471 LPSIZE space, LPSIZE gfxSize,
1472 HLPFILE_LINK *link, unsigned pos)
1474 WINHELP_LINE *line;
1475 WINHELP_LINE_PART *part;
1476 LPSTR ptr;
1478 if (!*partp || pos == 1) /* New line */
1480 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1481 if (!line) return NULL;
1483 line->next = NULL;
1484 part = &line->first_part;
1486 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1487 line->rect.bottom = line->rect.top;
1488 line->rect.left = space->cx;
1489 line->rect.right = space->cx;
1491 if (**linep) *linep = &(**linep)->next;
1492 **linep = line;
1493 space->cy = 0;
1494 ptr = (char*)line + sizeof(WINHELP_LINE);
1496 else /* Same line */
1498 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1499 line = **linep;
1501 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1502 if (!part) return NULL;
1503 **partp = part;
1504 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1507 /* part->cookie should be set by caller (image or metafile) */
1508 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1509 part->rect.right = part->rect.left + gfxSize->cx;
1510 line->rect.right = part->rect.right;
1511 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1512 part->rect.bottom = part->rect.top + gfxSize->cy;
1513 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1515 WINE_TRACE("Appended gfx @ (%d,%d-%d,%d)\n",
1516 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1518 part->link = link;
1519 if (link) link->wRefCount++;
1521 part->next = NULL;
1522 *partp = &part->next;
1524 space->cx = 0;
1526 return part;
1530 /***********************************************************************
1532 * WINHELP_SplitLines
1534 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1536 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1537 HLPFILE_PARAGRAPH *p;
1538 WINHELP_LINE **line = &win->first_line;
1539 WINHELP_LINE_PART **part = 0;
1540 INT line_ascent = 0;
1541 SIZE space;
1542 RECT rect;
1543 HDC hDc;
1545 if (newsize) newsize->cx = newsize->cy = 0;
1547 if (!win->page) return TRUE;
1549 WINHELP_DeleteLines(win);
1551 GetClientRect(hWnd, &rect);
1553 rect.top += INTERNAL_BORDER_WIDTH;
1554 rect.left += INTERNAL_BORDER_WIDTH;
1555 rect.right -= INTERNAL_BORDER_WIDTH;
1556 rect.bottom -= INTERNAL_BORDER_WIDTH;
1558 space.cy = rect.top;
1559 space.cx = rect.left;
1561 hDc = GetDC(hWnd);
1563 for (p = win->page->first_paragraph; p; p = p->next)
1565 switch (p->cookie)
1567 case para_normal_text:
1568 case para_debug_text:
1570 TEXTMETRIC tm;
1571 SIZE textsize = {0, 0};
1572 LPCSTR text = p->u.text.lpszText;
1573 UINT indent = 0;
1574 UINT len = strlen(text);
1575 unsigned underline = 0;
1577 HFONT hFont = 0;
1578 COLORREF color = RGB(0, 0, 0);
1580 if (p->u.text.wFont < win->page->file->numFonts)
1582 HLPFILE* hlpfile = win->page->file;
1584 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1585 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1586 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1587 color = hlpfile->fonts[p->u.text.wFont].color;
1589 else
1591 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1593 hFont = win->fonts[wFont];
1596 if (p->link && p->link->bClrChange)
1598 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1599 color = RGB(0, 0x80, 0);
1601 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1603 SelectObject(hDc, hFont);
1605 GetTextMetrics(hDc, &tm);
1607 if (p->u.text.wIndent)
1609 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1610 if (!part)
1611 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1614 if (p->u.text.wVSpace)
1616 part = 0;
1617 space.cx = rect.left + indent;
1618 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1621 if (p->u.text.wHSpace)
1623 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1626 WINE_TRACE("splitting text %s\n", text);
1628 while (len)
1630 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1631 UINT low = 0, curr = len, high = len, textlen = 0;
1633 if (free_width > 0)
1635 while (1)
1637 GetTextExtentPoint(hDc, text, curr, &textsize);
1639 if (textsize.cx <= free_width) low = curr;
1640 else high = curr;
1642 if (high <= low + 1) break;
1644 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1645 if (curr <= low) curr = low + 1;
1646 else if (curr >= high) curr = high - 1;
1648 textlen = low;
1649 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1651 if (!part && !textlen) textlen = max(low, 1);
1653 if (free_width <= 0 || !textlen)
1655 part = 0;
1656 space.cx = rect.left + indent;
1657 space.cx = min(space.cx, rect.right - rect.left - 1);
1658 continue;
1661 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1663 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1664 &line_ascent, tm.tmAscent,
1665 text, textlen, hFont, color, p->link, underline) ||
1666 (!newsize && (*line)->rect.bottom > rect.bottom))
1668 ReleaseDC(hWnd, hDc);
1669 return FALSE;
1672 if (newsize)
1673 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1675 len -= textlen;
1676 text += textlen;
1677 if (text[0] == ' ') text++, len--;
1680 break;
1681 case para_bitmap:
1682 case para_metafile:
1684 SIZE gfxSize;
1685 INT free_width;
1686 WINHELP_LINE_PART* ref_part;
1688 if (p->u.gfx.pos & 0x8000)
1690 space.cx = rect.left;
1691 if (*line)
1692 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1693 part = 0;
1696 if (p->cookie == para_bitmap)
1698 DIBSECTION dibs;
1700 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1701 gfxSize.cx = dibs.dsBm.bmWidth;
1702 gfxSize.cy = dibs.dsBm.bmHeight;
1704 else
1706 LPMETAFILEPICT lpmfp = &p->u.gfx.u.mfp;
1707 if (lpmfp->mm == MM_ANISOTROPIC || lpmfp->mm == MM_ISOTROPIC)
1709 gfxSize.cx = MulDiv(lpmfp->xExt, GetDeviceCaps(hDc, HORZRES),
1710 100*GetDeviceCaps(hDc, HORZSIZE));
1711 gfxSize.cy = MulDiv(lpmfp->yExt, GetDeviceCaps(hDc, VERTRES),
1712 100*GetDeviceCaps(hDc, VERTSIZE));
1714 else
1716 gfxSize.cx = lpmfp->xExt;
1717 gfxSize.cy = lpmfp->yExt;
1721 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1722 if (free_width <= 0)
1724 part = NULL;
1725 space.cx = rect.left;
1726 space.cx = min(space.cx, rect.right - rect.left - 1);
1728 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1729 p->link, p->u.gfx.pos);
1730 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1732 return FALSE;
1734 if (p->cookie == para_bitmap)
1736 ref_part->cookie = hlp_line_part_bitmap;
1737 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1739 else
1741 ref_part->cookie = hlp_line_part_metafile;
1742 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mfp.hMF;
1743 ref_part->u.metafile.mm = p->u.gfx.u.mfp.mm;
1746 break;
1750 if (newsize)
1751 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1753 ReleaseDC(hWnd, hDc);
1754 return TRUE;
1757 /***********************************************************************
1759 * WINHELP_CheckPopup
1761 static void WINHELP_CheckPopup(UINT msg)
1763 if (!Globals.hPopupWnd) return;
1765 switch (msg)
1767 case WM_COMMAND:
1768 case WM_LBUTTONDOWN:
1769 case WM_MBUTTONDOWN:
1770 case WM_RBUTTONDOWN:
1771 case WM_NCLBUTTONDOWN:
1772 case WM_NCMBUTTONDOWN:
1773 case WM_NCRBUTTONDOWN:
1774 DestroyWindow(Globals.hPopupWnd);
1775 Globals.hPopupWnd = 0;
1779 /***********************************************************************
1781 * WINHELP_DeleteLines
1783 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1785 WINHELP_LINE *line, *next_line;
1786 WINHELP_LINE_PART *part, *next_part;
1787 for (line = win->first_line; line; line = next_line)
1789 next_line = line->next;
1790 for (part = &line->first_part; part; part = next_part)
1792 next_part = part->next;
1793 HLPFILE_FreeLink(part->link);
1794 HeapFree(GetProcessHeap(), 0, part);
1797 win->first_line = 0;
1800 /***********************************************************************
1802 * WINHELP_DeleteWindow
1804 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1806 WINHELP_WINDOW** w;
1807 unsigned int i;
1808 WINHELP_BUTTON* b;
1809 WINHELP_BUTTON* bp;
1811 for (w = &Globals.win_list; *w; w = &(*w)->next)
1813 if (*w == win)
1815 *w = win->next;
1816 break;
1820 if (Globals.active_win == win)
1822 Globals.active_win = Globals.win_list;
1823 if (Globals.win_list)
1824 SetActiveWindow(Globals.win_list->hMainWnd);
1827 for (b = win->first_button; b; b = bp)
1829 DestroyWindow(b->hWnd);
1830 bp = b->next;
1831 HeapFree(GetProcessHeap(), 0, b);
1834 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1835 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1837 for (i = 0; i < win->histIndex; i++)
1839 HLPFILE_FreeHlpFile(win->history[i]->file);
1842 for (i = 0; i < win->backIndex; i++)
1843 HLPFILE_FreeHlpFile(win->back[i]->file);
1845 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1846 WINHELP_DeleteLines(win);
1847 HeapFree(GetProcessHeap(), 0, win);
1850 /***********************************************************************
1852 * WINHELP_InitFonts
1854 static void WINHELP_InitFonts(HWND hWnd)
1856 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1857 LOGFONT logfontlist[] = {
1858 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1859 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1860 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1861 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1862 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1863 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
1864 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
1865 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1867 static HFONT fonts[FONTS_LEN];
1868 static BOOL init = 0;
1870 win->fonts_len = FONTS_LEN;
1871 win->fonts = fonts;
1873 if (!init)
1875 UINT i;
1877 for (i = 0; i < FONTS_LEN; i++)
1879 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1882 init = 1;
1886 /***********************************************************************
1888 * WINHELP_MessageBoxIDS
1890 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1892 CHAR text[MAX_STRING_LEN];
1893 CHAR title[MAX_STRING_LEN];
1895 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1896 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1898 return MessageBox(0, text, title, type);
1901 /***********************************************************************
1903 * MAIN_MessageBoxIDS_s
1905 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1907 CHAR text[MAX_STRING_LEN];
1908 CHAR title[MAX_STRING_LEN];
1909 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
1911 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1912 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1913 wsprintf(newtext, text, str);
1915 return MessageBox(0, newtext, title, type);
1918 /******************************************************************
1919 * WINHELP_IsOverLink
1923 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1925 POINT mouse;
1926 WINHELP_LINE *line;
1927 WINHELP_LINE_PART *part;
1928 int scroll_pos = GetScrollPos(win->hTextWnd, SB_VERT);
1930 mouse.x = LOWORD(lParam);
1931 mouse.y = HIWORD(lParam);
1932 for (line = win->first_line; line; line = line->next)
1934 for (part = &line->first_part; part; part = part->next)
1936 if (part->link &&
1937 part->link->lpszString &&
1938 part->rect.left <= mouse.x &&
1939 part->rect.right >= mouse.x &&
1940 part->rect.top <= mouse.y + scroll_pos &&
1941 part->rect.bottom >= mouse.y + scroll_pos)
1943 return part;
1948 return NULL;
1951 /**************************************************************************
1952 * cb_KWBTree
1954 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1957 static void cb_KWBTree(void *p, void **next, void *cookie)
1959 HWND hListWnd = (HWND)cookie;
1961 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
1962 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
1963 *next = (char*)p + strlen((char*)p) + 7;
1966 /**************************************************************************
1967 * comp_KWBTREE
1969 * HLPFILE_BPTreeCompare function for '|KWBTREE' internal file.
1972 static int comp_KWBTree(void *p, const void *key,
1973 int leaf, void** next)
1975 WINE_TRACE("comparing key '%s' with '%s'\n", (char *)p, (char *)key);
1976 *next = (char*)p+strlen(p)+1+(leaf?6:2);
1977 /* unlike directory, index is case insensitive */
1978 return lstrcmpi(p, key);
1981 /**************************************************************************
1982 * WINHELP_IndexDlgProc
1984 * Index dialog callback function.
1987 INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1989 static HLPFILE *file;
1990 int sel;
1991 ULONG offset = 1;
1993 switch (msg)
1995 case WM_INITDIALOG:
1996 file = (HLPFILE *)lParam;
1997 HLPFILE_BPTreeEnum(file->kwbtree, cb_KWBTree,
1998 GetDlgItem(hWnd, IDC_INDEXLIST));
1999 return TRUE;
2000 case WM_COMMAND:
2001 switch (LOWORD(wParam))
2003 case IDOK:
2004 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
2005 if (sel != LB_ERR)
2007 char buf[500]; /* enough */
2008 BYTE *p;
2009 int count;
2011 SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETTEXT,
2012 sel, (LPARAM)buf);
2013 p = HLPFILE_BPTreeSearch(file->kwbtree, buf, comp_KWBTree);
2014 if (p == NULL)
2017 * TODO:
2018 * This may happen if help file uses other locale than
2019 * system. We should honour charset provided in help file
2020 * and use UNICODE, but for now current implementation is
2021 * acceptable (almost all help files use ANSI).
2023 WINE_FIXME("item '%s' not found, locale mismatch???\n", buf);
2024 return TRUE;
2026 count = *(short*)((char *)p + strlen((char *)p) + 1);
2027 if (count > 1)
2029 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
2030 return TRUE;
2032 offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
2033 offset = *(long*)(file->kwdata + offset + 9);
2034 if (offset == 0xFFFFFFFF)
2036 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
2037 return TRUE;
2040 /* Fall through */
2041 case IDCANCEL:
2042 EndDialog(hWnd, offset);
2043 return TRUE;
2044 default:
2045 break;
2047 default:
2048 break;
2050 return FALSE;
2053 /**************************************************************************
2054 * WINHELP_CreateIndexWindow
2056 * Displays a dialog with keywords of current help file.
2059 BOOL WINHELP_CreateIndexWindow(void)
2061 int ret;
2062 HLPFILE *hlpfile;
2064 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
2065 hlpfile = Globals.active_win->page->file;
2066 else
2067 return FALSE;
2069 if (hlpfile->kwbtree == NULL)
2071 WINE_TRACE("No index provided\n");
2072 return FALSE;
2075 ret = DialogBoxParam(Globals.hInstance, MAKEINTRESOURCE(IDD_INDEX),
2076 Globals.active_win->hMainWnd, WINHELP_SearchDlgProc,
2077 (LPARAM)hlpfile);
2078 if (ret > 1)
2079 WINHELP_CreateHelpWindowByOffset(hlpfile, ret, Globals.active_win->info, SW_NORMAL);
2080 return TRUE;