4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002, 2008 Eric Pouech <eric.pouech@wanadoo.fr>
7 * 2004 Ken Belleau <jamez@ivic.qc.ca>
8 * 2008 Kirill K. Smirnov <lich@math.spbu.ru>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #define NONAMELESSUNION
32 #define NONAMELESSSTRUCT
40 #include "winhelp_res.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
49 WINHELP_GLOBALS Globals = {3, NULL, TRUE, NULL, NULL, NULL, NULL, NULL, {{{NULL,NULL}},0}, NULL};
51 #define CTL_ID_BUTTON 0x700
52 #define CTL_ID_TEXT 0x701
55 /***********************************************************************
59 static void WINHELP_InitFonts(HWND hWnd)
61 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
62 LOGFONT logfontlist[] = {
63 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
64 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
65 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
66 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
67 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
68 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"},
69 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET, 0, 0, 0, 32, "Helv"}};
70 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
72 static HFONT fonts[FONTS_LEN];
75 win->fonts_len = FONTS_LEN;
82 for (i = 0; i < FONTS_LEN; i++)
84 fonts[i] = CreateFontIndirect(&logfontlist[i]);
91 static DWORD CALLBACK WINHELP_RtfStreamIn(DWORD_PTR cookie, BYTE* buff,
94 struct RtfData* rd = (struct RtfData*)cookie;
96 if (rd->where >= rd->ptr) return 1;
97 if (rd->where + cb > rd->ptr)
98 cb = rd->ptr - rd->where;
99 memcpy(buff, rd->where, cb);
105 static void WINHELP_SetupText(HWND hTextWnd, WINHELP_WINDOW* win, ULONG relative)
107 /* At first clear area - needed by EM_POSFROMCHAR/EM_SETSCROLLPOS */
108 SendMessage(hTextWnd, WM_SETTEXT, 0, (LPARAM)"");
109 SendMessage(hTextWnd, WM_SETREDRAW, FALSE, 0);
110 SendMessage(hTextWnd, EM_SETBKGNDCOLOR, 0, (LPARAM)win->info->sr_color);
111 /* set word-wrap to window size (undocumented) */
112 SendMessage(hTextWnd, EM_SETTARGETDEVICE, 0, 0);
122 if (HLPFILE_BrowsePage(win->page, &rd, win->font_scale, relative))
125 es.dwCookie = (DWORD_PTR)&rd;
127 es.pfnCallback = WINHELP_RtfStreamIn;
129 SendMessageW(hTextWnd, EM_STREAMIN, SF_RTF, (LPARAM)&es);
130 cp = rd.char_pos_rel;
132 /* FIXME: else leaking potentially the rd.first_link chain */
133 HeapFree(GetProcessHeap(), 0, rd.data);
134 SendMessage(hTextWnd, EM_POSFROMCHAR, (WPARAM)&ptl, cp ? cp - 1 : 0);
135 pt.x = 0; pt.y = ptl.y;
136 SendMessage(hTextWnd, EM_SETSCROLLPOS, 0, (LPARAM)&pt);
138 SendMessage(hTextWnd, WM_SETREDRAW, TRUE, 0);
139 RedrawWindow(hTextWnd, NULL, NULL, RDW_FRAME|RDW_INVALIDATE);
142 /***********************************************************************
144 * WINHELP_GetOpenFileName
146 BOOL WINHELP_GetOpenFileName(LPSTR lpszFile, int len)
148 OPENFILENAME openfilename;
149 CHAR szDir[MAX_PATH];
150 CHAR szzFilter[2 * MAX_STRING_LEN + 100];
155 LoadString(Globals.hInstance, STID_HELP_FILES_HLP, p, MAX_STRING_LEN);
159 LoadString(Globals.hInstance, STID_ALL_FILES, p, MAX_STRING_LEN);
165 GetCurrentDirectory(sizeof(szDir), szDir);
169 openfilename.lStructSize = sizeof(OPENFILENAME);
170 openfilename.hwndOwner = NULL;
171 openfilename.hInstance = Globals.hInstance;
172 openfilename.lpstrFilter = szzFilter;
173 openfilename.lpstrCustomFilter = 0;
174 openfilename.nMaxCustFilter = 0;
175 openfilename.nFilterIndex = 1;
176 openfilename.lpstrFile = lpszFile;
177 openfilename.nMaxFile = len;
178 openfilename.lpstrFileTitle = 0;
179 openfilename.nMaxFileTitle = 0;
180 openfilename.lpstrInitialDir = szDir;
181 openfilename.lpstrTitle = 0;
182 openfilename.Flags = OFN_ENABLESIZING;
183 openfilename.nFileOffset = 0;
184 openfilename.nFileExtension = 0;
185 openfilename.lpstrDefExt = 0;
186 openfilename.lCustData = 0;
187 openfilename.lpfnHook = 0;
188 openfilename.lpTemplateName = 0;
190 return GetOpenFileName(&openfilename);
193 /***********************************************************************
195 * WINHELP_MessageBoxIDS_s
197 static INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
199 CHAR text[MAX_STRING_LEN];
200 CHAR newtext[MAX_STRING_LEN + MAX_PATH];
202 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
203 wsprintf(newtext, text, str);
205 return MessageBox(0, newtext, MAKEINTRESOURCE(ids_title), type);
208 /***********************************************************************
210 * WINHELP_LookupHelpFile
212 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
215 char szFullName[MAX_PATH];
216 char szAddPath[MAX_PATH];
220 * NOTE: This is needed by popup windows only.
221 * In other cases it's not needed but does not hurt though.
223 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
225 strcpy(szAddPath, Globals.active_win->page->file->lpszPath);
226 p = strrchr(szAddPath, '\\');
231 * FIXME: Should we swap conditions?
233 if (!SearchPath(NULL, lpszFile, ".hlp", MAX_PATH, szFullName, NULL) &&
234 !SearchPath(szAddPath, lpszFile, ".hlp", MAX_PATH, szFullName, NULL))
236 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s, lpszFile, STID_WHERROR,
237 MB_YESNO|MB_ICONQUESTION) != IDYES)
239 if (!WINHELP_GetOpenFileName(szFullName, MAX_PATH))
242 hlpfile = HLPFILE_ReadHlpFile(szFullName);
244 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile,
245 STID_WHERROR, MB_OK|MB_ICONSTOP);
249 /******************************************************************
250 * WINHELP_GetWindowInfo
254 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
256 static HLPFILE_WINDOWINFO mwi;
259 if (!name || !name[0])
260 name = Globals.active_win->lpszName;
263 for (i = 0; i < hlpfile->numWindows; i++)
264 if (!strcmp(hlpfile->windows[i].name, name))
265 return &hlpfile->windows[i];
267 if (strcmp(name, "main") != 0)
269 WINE_FIXME("Couldn't find window info for %s\n", name);
275 strcpy(mwi.type, "primary");
276 strcpy(mwi.name, "main");
277 LoadString(Globals.hInstance, STID_WINE_HELP, mwi.caption, sizeof(mwi.caption));
278 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
280 mwi.win_style = WS_OVERLAPPEDWINDOW;
281 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
286 /******************************************************************
287 * HLPFILE_GetPopupWindowInfo
291 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile,
292 WINHELP_WINDOW* parent, LPARAM mouse)
294 static HLPFILE_WINDOWINFO wi;
298 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
300 /* Calculate horizontal size and position of a popup window */
301 GetWindowRect(parent->hMainWnd, &parent_rect);
302 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
303 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
305 wi.origin.x = (short)LOWORD(mouse);
306 wi.origin.y = (short)HIWORD(mouse);
307 ClientToScreen(parent->hMainWnd, &wi.origin);
308 wi.origin.x -= wi.size.cx / 2;
309 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
310 wi.origin.x = max(wi.origin.x, 0);
313 wi.win_style = WS_POPUP | WS_BORDER;
314 if (parent->page->file->has_popup_color)
315 wi.sr_color = parent->page->file->popup_color;
317 wi.sr_color = parent->info->sr_color;
318 wi.nsr_color = 0xFFFFFF;
331 } WINHELP,*LPWINHELP;
333 static BOOL WINHELP_HasWorkingWindow(void)
335 if (!Globals.active_win) return FALSE;
336 if (Globals.active_win->next || Globals.win_list != Globals.active_win) return TRUE;
337 return Globals.active_win->page != NULL && Globals.active_win->page->file != NULL;
340 /******************************************************************
341 * WINHELP_HandleCommand
345 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
347 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
350 if (cds->dwData != 0xA1DE505)
352 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
360 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
362 WINE_TRACE("Got[%u]: cmd=%u data=%08x fn=%s\n",
363 wh->size, wh->command, wh->data, ptr);
369 MACRO_JumpContext(ptr, "main", wh->data);
371 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
379 MACRO_JumpContents(ptr, "main");
381 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
383 case HELP_HELPONHELP:
385 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
387 /* case HELP_SETINDEX: */
388 case HELP_SETCONTENTS:
391 MACRO_SetContents(ptr, wh->data);
394 case HELP_CONTEXTPOPUP:
397 MACRO_PopupContext(ptr, wh->data);
400 /* case HELP_FORCEFILE:*/
401 /* case HELP_CONTEXTMENU: */
403 /* in fact, should be the topic dialog box */
404 WINE_FIXME("HELP_FINDER: stub\n");
407 MACRO_JumpHash(ptr, "main", 0);
410 /* case HELP_WM_HELP: */
411 /* case HELP_SETPOPUP_POS: */
413 /* case HELP_COMMAND: */
414 /* case HELP_PARTIALKEY: */
415 /* case HELP_MULTIKEY: */
416 /* case HELP_SETWINPOS: */
418 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh->command);
422 /* Always return success for now */
426 void WINHELP_LayoutMainWindow(WINHELP_WINDOW* win)
428 RECT rect, button_box_rect;
430 HWND hButtonBoxWnd = GetDlgItem(win->hMainWnd, CTL_ID_BUTTON);
431 HWND hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
433 GetClientRect(win->hMainWnd, &rect);
435 /* Update button box and text Window */
436 SetWindowPos(hButtonBoxWnd, HWND_TOP,
438 rect.right - rect.left,
439 rect.bottom - rect.top, 0);
441 if (GetWindowRect(hButtonBoxWnd, &button_box_rect))
442 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
444 SetWindowPos(hTextWnd, HWND_TOP,
446 rect.right - rect.left,
447 rect.bottom - text_top, 0);
451 /******************************************************************
452 * WINHELP_DeleteButtons
455 static void WINHELP_DeleteButtons(WINHELP_WINDOW* win)
460 for (b = win->first_button; b; b = bp)
462 DestroyWindow(b->hWnd);
464 HeapFree(GetProcessHeap(), 0, b);
466 win->first_button = NULL;
469 /******************************************************************
470 * WINHELP_DeleteBackSet
473 void WINHELP_DeleteBackSet(WINHELP_WINDOW* win)
477 for (i = 0; i < win->back.index; i++)
479 HLPFILE_FreeHlpFile(win->back.set[i].page->file);
480 win->back.set[i].page = NULL;
485 /******************************************************************
486 * WINHELP_DeletePageLinks
489 static void WINHELP_DeletePageLinks(HLPFILE_PAGE* page)
494 for (curr = page->first_link; curr; curr = next)
497 HeapFree(GetProcessHeap(), 0, curr);
501 /***********************************************************************
503 * WINHELP_DeleteWindow
505 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
509 for (w = &Globals.win_list; *w; w = &(*w)->next)
518 if (Globals.active_win == win)
520 Globals.active_win = Globals.win_list;
521 if (Globals.win_list)
522 SetActiveWindow(Globals.win_list->hMainWnd);
525 if (win == Globals.active_popup)
526 Globals.active_popup = NULL;
528 WINHELP_DeleteButtons(win);
530 if (win->page) WINHELP_DeletePageLinks(win->page);
531 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
532 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
534 DeleteObject(win->hBrush);
536 WINHELP_DeleteBackSet(win);
538 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
539 HeapFree(GetProcessHeap(), 0, win);
542 static char* WINHELP_GetCaption(WINHELP_WNDPAGE* wpage)
544 if (wpage->wininfo->caption[0]) return wpage->wininfo->caption;
545 return wpage->page->file->lpszTitle;
548 static void WINHELP_RememberPage(WINHELP_WINDOW* win, WINHELP_WNDPAGE* wpage)
552 if (!Globals.history.index || Globals.history.set[0].page != wpage->page)
554 num = sizeof(Globals.history.set) / sizeof(Globals.history.set[0]);
555 /* we're full, remove latest entry */
556 if (Globals.history.index == num)
558 HLPFILE_FreeHlpFile(Globals.history.set[num - 1].page->file);
559 Globals.history.index--;
561 memmove(&Globals.history.set[1], &Globals.history.set[0],
562 Globals.history.index * sizeof(Globals.history.set[0]));
563 Globals.history.set[0] = *wpage;
564 Globals.history.index++;
565 wpage->page->file->wRefCount++;
567 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
569 num = sizeof(win->back.set) / sizeof(win->back.set[0]);
570 if (win->back.index == num)
572 /* we're full, remove latest entry */
573 HLPFILE_FreeHlpFile(win->back.set[0].page->file);
574 memmove(&win->back.set[0], &win->back.set[1],
575 (num - 1) * sizeof(win->back.set[0]));
578 win->back.set[win->back.index++] = *wpage;
579 wpage->page->file->wRefCount++;
582 /***********************************************************************
586 static HLPFILE_LINK* WINHELP_FindLink(WINHELP_WINDOW* win, LPARAM pos)
589 POINTL mouse_ptl, char_ptl, char_next_ptl;
592 if (!win->page) return NULL;
594 mouse_ptl.x = (short)LOWORD(pos);
595 mouse_ptl.y = (short)HIWORD(pos);
596 cp = SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_CHARFROMPOS,
597 0, (LPARAM)&mouse_ptl);
599 for (link = win->page->first_link; link; link = link->next)
601 if (link->cpMin <= cp && cp <= link->cpMax)
603 /* check whether we're at end of line */
604 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
605 (LPARAM)&char_ptl, cp);
606 SendMessageW(GetDlgItem(win->hMainWnd, CTL_ID_TEXT), EM_POSFROMCHAR,
607 (LPARAM)&char_next_ptl, cp + 1);
608 if (char_next_ptl.y != char_ptl.y || mouse_ptl.x >= char_next_ptl.x)
616 static LRESULT CALLBACK WINHELP_RicheditWndProc(HWND hWnd, UINT msg,
617 WPARAM wParam, LPARAM lParam)
619 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0);
625 messagePos = GetMessagePos();
626 pt.x = (short)LOWORD(messagePos);
627 pt.y = (short)HIWORD(messagePos);
628 ScreenToClient(hWnd, &pt);
629 if (win->page && WINHELP_FindLink(win, MAKELPARAM(pt.x, pt.y)))
631 SetCursor(win->hHandCur);
636 return CallWindowProcA(win->origRicheditWndProc, hWnd, msg, wParam, lParam);
640 /***********************************************************************
642 * WINHELP_CreateHelpWindow
644 BOOL WINHELP_CreateHelpWindow(WINHELP_WNDPAGE* wpage, int nCmdShow, BOOL remember)
646 WINHELP_WINDOW* win = NULL;
647 BOOL bPrimary, bPopup, bReUsed = FALSE;
650 HWND hTextWnd = NULL;
652 bPrimary = !lstrcmpi(wpage->wininfo->name, "main");
653 bPopup = !bPrimary && (wpage->wininfo->win_style & WS_POPUP);
657 for (win = Globals.win_list; win; win = win->next)
659 if (!lstrcmpi(win->lpszName, wpage->wininfo->name))
663 DWORD flags = SWP_NOSIZE | SWP_NOMOVE;
665 WINHELP_DeleteButtons(win);
667 SetWindowText(win->hMainWnd, WINHELP_GetCaption(wpage));
668 if (wpage->wininfo->origin.x != CW_USEDEFAULT &&
669 wpage->wininfo->origin.y != CW_USEDEFAULT)
671 pt = wpage->wininfo->origin;
672 flags &= ~SWP_NOSIZE;
674 if (wpage->wininfo->size.cx != CW_USEDEFAULT &&
675 wpage->wininfo->size.cy != CW_USEDEFAULT)
677 sz = wpage->wininfo->size;
678 flags &= ~SWP_NOMOVE;
680 SetWindowPos(win->hMainWnd, HWND_TOP, pt.x, pt.y, sz.cx, sz.cy, flags);
682 if (wpage->page && win->page && wpage->page->file != win->page->file)
683 WINHELP_DeleteBackSet(win);
684 WINHELP_InitFonts(win->hMainWnd);
686 win->page = wpage->page;
687 win->info = wpage->wininfo;
688 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
689 WINHELP_SetupText(hTextWnd, win, wpage->relative);
691 InvalidateRect(win->hMainWnd, NULL, TRUE);
692 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
701 /* Initialize WINHELP_WINDOW struct */
702 win = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
703 sizeof(WINHELP_WINDOW) + strlen(wpage->wininfo->name) + 1);
704 if (!win) return FALSE;
705 win->next = Globals.win_list;
706 Globals.win_list = win;
708 name = (char*)win + sizeof(WINHELP_WINDOW);
709 lstrcpy(name, wpage->wininfo->name);
710 win->lpszName = name;
711 win->hHandCur = LoadCursorW(0, (LPWSTR)IDC_HAND);
715 win->page = wpage->page;
716 win->info = wpage->wininfo;
718 if (!bPopup && wpage->page && remember)
720 WINHELP_RememberPage(win, wpage);
724 Globals.active_popup = win;
726 Globals.active_win = win;
728 /* Initialize default pushbuttons */
729 if (bPrimary && wpage->page)
731 CHAR buffer[MAX_STRING_LEN];
733 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
734 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
735 LoadString(Globals.hInstance, STID_INDEX, buffer, sizeof(buffer));
736 MACRO_CreateButton("BTN_INDEX", buffer, "Finder()");
737 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
738 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
739 if (win->back.index <= 1) MACRO_DisableButton("BTN_BACK");
744 win->hMainWnd = CreateWindowEx((bPopup) ? WS_EX_TOOLWINDOW : 0, MAIN_WIN_CLASS_NAME,
745 WINHELP_GetCaption(wpage),
746 bPrimary ? WS_OVERLAPPEDWINDOW : wpage->wininfo->win_style,
747 wpage->wininfo->origin.x, wpage->wininfo->origin.y,
748 wpage->wininfo->size.cx, wpage->wininfo->size.cy,
749 bPopup ? Globals.active_win->hMainWnd : NULL,
750 bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
751 Globals.hInstance, win);
753 /* Create button box and text Window */
754 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
755 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_BUTTON, Globals.hInstance, NULL);
757 hTextWnd = CreateWindow(RICHEDIT_CLASS, NULL,
758 ES_MULTILINE | ES_READONLY | WS_CHILD | WS_HSCROLL | WS_VSCROLL | WS_VISIBLE,
759 0, 0, 0, 0, win->hMainWnd, (HMENU)CTL_ID_TEXT, Globals.hInstance, NULL);
760 SendMessage(hTextWnd, EM_SETEVENTMASK, 0,
761 SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0) | ENM_MOUSEEVENTS);
762 win->origRicheditWndProc = (WNDPROC)SetWindowLongPtr(hTextWnd, GWLP_WNDPROC,
763 (LONG_PTR)WINHELP_RicheditWndProc);
766 hIcon = (wpage->page) ? wpage->page->file->hIcon : NULL;
767 if (!hIcon) hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
768 SendMessage(win->hMainWnd, WM_SETICON, ICON_SMALL, (DWORD_PTR)hIcon);
770 /* Initialize file specific pushbuttons */
771 if (!(wpage->wininfo->win_style & WS_POPUP) && wpage->page)
773 HLPFILE_MACRO *macro;
774 for (macro = wpage->page->file->first_macro; macro; macro = macro->next)
775 MACRO_ExecuteMacro(macro->lpszMacro);
777 for (macro = wpage->page->first_macro; macro; macro = macro->next)
778 MACRO_ExecuteMacro(macro->lpszMacro);
783 DWORD mask = SendMessage(hTextWnd, EM_GETEVENTMASK, 0, 0);
786 win->font_scale = Globals.active_win->font_scale;
787 WINHELP_SetupText(hTextWnd, win, wpage->relative);
789 /* we need the window to be shown for richedit to compute the size */
790 ShowWindow(win->hMainWnd, nCmdShow);
791 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask | ENM_REQUESTRESIZE);
792 SendMessage(hTextWnd, EM_REQUESTRESIZE, 0, 0);
793 SendMessage(hTextWnd, EM_SETEVENTMASK, 0, mask);
795 GetWindowRect(win->hMainWnd, &rect);
796 win->hShadowWnd = CreateWindowEx(WS_EX_TOOLWINDOW, SHADOW_WIN_CLASS_NAME,
797 "", WS_POPUP | WS_VISIBLE,
798 rect.left + SHADOW_DX, rect.top + SHADOW_DY,
799 rect.right - rect.left,
800 rect.bottom - rect.top,
801 Globals.active_win->hMainWnd, 0,
802 Globals.hInstance, NULL);
803 SetWindowPos(win->hMainWnd, win->hShadowWnd, 0, 0, 0, 0,
804 SWP_NOSIZE | SWP_NOMOVE);
808 WINHELP_SetupText(hTextWnd, win, wpage->relative);
809 WINHELP_LayoutMainWindow(win);
810 ShowWindow(win->hMainWnd, nCmdShow);
816 /******************************************************************
817 * WINHELP_OpenHelpWindow
818 * Main function to search for a page and display it in a window
820 BOOL WINHELP_OpenHelpWindow(HLPFILE_PAGE* (*lookup)(HLPFILE*, LONG, ULONG*),
821 HLPFILE* hlpfile, LONG val, HLPFILE_WINDOWINFO* wi,
824 WINHELP_WNDPAGE wpage;
826 wpage.page = lookup(hlpfile, val, &wpage.relative);
827 if (wpage.page) wpage.page->file->wRefCount++;
829 return WINHELP_CreateHelpWindow(&wpage, nCmdShow, TRUE);
832 /******************************************************************
833 * WINHELP_HandleTextMouse
836 static BOOL WINHELP_HandleTextMouse(WINHELP_WINDOW* win, UINT msg, LPARAM lParam)
845 if ((link = WINHELP_FindLink(win, lParam)))
847 HLPFILE_WINDOWINFO* wi;
849 switch (link->cookie)
852 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
854 if (link->window == -1)
856 else if (link->window < hlpfile->numWindows)
857 wi = &hlpfile->windows[link->window];
860 WINE_WARN("link to window %d/%d\n", link->window, hlpfile->numWindows);
863 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash, wi, SW_NORMAL);
867 if ((hlpfile = WINHELP_LookupHelpFile(link->string)))
868 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, link->hash,
869 WINHELP_GetPopupWindowInfo(hlpfile, win, lParam),
873 MACRO_ExecuteMacro(link->string);
876 WINE_FIXME("Unknown link cookie %d\n", link->cookie);
885 /***********************************************************************
889 static BOOL WINHELP_CheckPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT* lret)
893 if (!Globals.active_popup) return FALSE;
899 MSGFILTER* msgf = (MSGFILTER*)lParam;
900 if (msgf->nmhdr.code == EN_MSGFILTER)
902 if (!WINHELP_CheckPopup(hWnd, msgf->msg, msgf->wParam, msgf->lParam, NULL))
910 if (wParam != WA_INACTIVE || (HWND)lParam == Globals.active_win->hMainWnd ||
911 (HWND)lParam == Globals.active_popup->hMainWnd ||
912 GetWindow((HWND)lParam, GW_OWNER) == Globals.active_win->hMainWnd)
915 if (WINHELP_HandleTextMouse(Globals.active_popup, msg, lParam))
921 case WM_NCLBUTTONDOWN:
922 case WM_NCMBUTTONDOWN:
923 case WM_NCRBUTTONDOWN:
924 hPopup = Globals.active_popup->hMainWnd;
925 Globals.active_popup = NULL;
926 DestroyWindow(hPopup);
932 /***********************************************************************
934 * WINHELP_ButtonWndProc
936 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
938 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
940 if (msg == WM_KEYDOWN)
949 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
953 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
956 /***********************************************************************
958 * WINHELP_ButtonBoxWndProc
960 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
964 WINHELP_BUTTON *button;
968 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0L;
972 case WM_WINDOWPOSCHANGING:
973 winpos = (WINDOWPOS*) lParam;
974 win = (WINHELP_WINDOW*) GetWindowLongPtr(GetParent(hWnd), 0);
979 for (button = win->first_button; button; button = button->next)
985 button->hWnd = CreateWindow(STRING_BUTTON, button->lpszName,
986 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
988 hWnd, (HMENU) button->wParam,
989 Globals.hInstance, 0);
992 if (Globals.button_proc == NULL)
994 NONCLIENTMETRICSW ncm;
995 Globals.button_proc = (WNDPROC) GetWindowLongPtr(button->hWnd, GWLP_WNDPROC);
997 ncm.cbSize = sizeof(NONCLIENTMETRICSW);
998 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS,
999 sizeof(NONCLIENTMETRICSW), &ncm, 0);
1000 Globals.hButtonFont = CreateFontIndirectW(&ncm.lfMenuFont);
1002 SetWindowLongPtr(button->hWnd, GWLP_WNDPROC, (LONG_PTR) WINHELP_ButtonWndProc);
1003 if (Globals.hButtonFont)
1004 SendMessage(button->hWnd, WM_SETFONT, (WPARAM)Globals.hButtonFont, TRUE);
1007 hDc = GetDC(button->hWnd);
1008 GetTextExtentPoint(hDc, button->lpszName,
1009 lstrlen(button->lpszName), &textsize);
1010 ReleaseDC(button->hWnd, hDc);
1012 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
1013 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
1018 for (button = win->first_button; button; button = button->next)
1020 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
1022 if (x + 2 * button_size.cx <= winpos->cx)
1023 x += button_size.cx;
1025 x = 0, y += button_size.cy;
1027 winpos->cy = y + (x ? button_size.cy : 0);
1031 SendMessage(GetParent(hWnd), msg, wParam, lParam);
1042 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
1047 return DefWindowProc(hWnd, msg, wParam, lParam);
1050 /******************************************************************
1051 * WINHELP_HistoryWndProc
1055 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1057 WINHELP_WINDOW* win;
1067 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1068 SetWindowLongPtr(hWnd, 0, (ULONG_PTR)win);
1069 win->hHistoryWnd = hWnd;
1072 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1074 GetTextMetrics(hDc, &tm);
1075 GetWindowRect(hWnd, &r);
1077 r.right = r.left + 30 * tm.tmAveCharWidth;
1078 r.bottom = r.top + (sizeof(Globals.history.set) / sizeof(Globals.history.set[0])) * tm.tmHeight;
1079 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1080 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1081 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1083 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1084 ReleaseDC(hWnd, hDc);
1086 case WM_LBUTTONDOWN:
1087 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1089 GetTextMetrics(hDc, &tm);
1090 i = HIWORD(lParam) / tm.tmHeight;
1091 if (i < Globals.history.index)
1092 WINHELP_CreateHelpWindow(&Globals.history.set[i], SW_SHOW, TRUE);
1093 ReleaseDC(hWnd, hDc);
1096 hDc = BeginPaint(hWnd, &ps);
1097 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1098 GetTextMetrics(hDc, &tm);
1100 for (i = 0; i < Globals.history.index; i++)
1102 if (Globals.history.set[i].page->file == Globals.active_win->page->file)
1104 TextOut(hDc, 0, i * tm.tmHeight,
1105 Globals.history.set[i].page->lpszTitle,
1106 strlen(Globals.history.set[i].page->lpszTitle));
1115 ptr1 = strrchr(Globals.history.set[i].page->file->lpszPath, '\\');
1116 if (!ptr1) ptr1 = Globals.history.set[i].page->file->lpszPath;
1118 ptr2 = strrchr(ptr1, '.');
1119 len = ptr2 ? ptr2 - ptr1 : strlen(ptr1);
1120 if (len > sizeof(buffer)) len = sizeof(buffer);
1121 memcpy(buffer, ptr1, len);
1122 if (len < sizeof(buffer)) buffer[len++] = ':';
1123 strncpy(&buffer[len], Globals.history.set[i].page->lpszTitle, sizeof(buffer) - len);
1124 buffer[sizeof(buffer) - 1] = '\0';
1125 TextOut(hDc, 0, i * tm.tmHeight, buffer, strlen(buffer));
1128 EndPaint(hWnd, &ps);
1131 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1132 if (hWnd == win->hHistoryWnd)
1133 win->hHistoryWnd = 0;
1136 return DefWindowProc(hWnd, msg, wParam, lParam);
1139 /***********************************************************************
1141 * WINHELP_ShadowWndProc
1143 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1145 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL)) return 0;
1146 return WINHELP_CheckPopup(hWnd, msg, wParam, lParam, NULL) ? 0L : DefWindowProc(hWnd, msg, wParam, lParam);
1149 /**************************************************************************
1152 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1155 static void cb_KWBTree(void *p, void **next, void *cookie)
1157 HWND hListWnd = cookie;
1160 WINE_TRACE("Adding '%s' to search list\n", (char *)p);
1161 SendMessage(hListWnd, LB_INSERTSTRING, -1, (LPARAM)p);
1162 count = SendMessage(hListWnd, LB_GETCOUNT, 0, 0);
1163 SendMessage(hListWnd, LB_SETITEMDATA, count-1, (LPARAM)p);
1164 *next = (char*)p + strlen((char*)p) + 7;
1174 /**************************************************************************
1175 * WINHELP_IndexDlgProc
1178 static INT_PTR CALLBACK WINHELP_IndexDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1180 static struct index_data* id;
1186 id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam;
1187 HLPFILE_BPTreeEnum(id->hlpfile->kwbtree, cb_KWBTree,
1188 GetDlgItem(hWnd, IDC_INDEXLIST));
1193 switch (HIWORD(wParam))
1196 if (LOWORD(wParam) == IDC_INDEXLIST)
1197 SendMessage(GetParent(hWnd), PSM_PRESSBUTTON, PSBTN_OK, 0);
1202 switch (((NMHDR*)lParam)->code)
1205 sel = SendDlgItemMessage(hWnd, IDC_INDEXLIST, LB_GETCURSEL, 0, 0);
1211 p = (BYTE*)SendDlgItemMessage(hWnd, IDC_INDEXLIST,
1212 LB_GETITEMDATA, sel, 0);
1213 count = *(short*)((char *)p + strlen((char *)p) + 1);
1216 MessageBox(hWnd, "count > 1 not supported yet", "Error", MB_OK | MB_ICONSTOP);
1217 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID);
1220 id->offset = *(ULONG*)((char *)p + strlen((char *)p) + 3);
1221 id->offset = *(long*)(id->hlpfile->kwdata + id->offset + 9);
1222 if (id->offset == 0xFFFFFFFF)
1224 MessageBox(hWnd, "macro keywords not supported yet", "Error", MB_OK | MB_ICONSTOP);
1225 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_INVALID);
1229 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR);
1242 /**************************************************************************
1243 * WINHELP_SearchDlgProc
1246 static INT_PTR CALLBACK WINHELP_SearchDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1248 static struct index_data* id;
1253 id = (struct index_data*)((PROPSHEETPAGE*)lParam)->lParam;
1256 switch (((NMHDR*)lParam)->code)
1259 SetWindowLongPtr(hWnd, DWLP_MSGRESULT, PSNRET_NOERROR);
1271 /***********************************************************************
1273 * WINHELP_MainWndProc
1275 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1277 WINHELP_WINDOW *win;
1278 WINHELP_BUTTON *button;
1283 if (WINHELP_CheckPopup(hWnd, msg, wParam, lParam, &ret)) return ret;
1288 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
1289 SetWindowLongPtr(hWnd, 0, (ULONG_PTR) win);
1290 if (!win->page && Globals.isBook)
1291 PostMessage(hWnd, WM_COMMAND, MNID_FILE_OPEN, 0);
1292 win->hMainWnd = hWnd;
1295 case WM_WINDOWPOSCHANGED:
1296 WINHELP_LayoutMainWindow((WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0));
1300 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1304 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
1305 case MNID_FILE_PRINT: MACRO_Print(); break;
1306 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
1307 case MNID_FILE_EXIT: MACRO_Exit(); break;
1310 case MNID_EDIT_COPYDLG:
1311 SendMessage(GetDlgItem(hWnd, CTL_ID_TEXT), WM_COPY, 0, 0);
1313 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
1316 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
1319 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
1320 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
1321 case MNID_HELP_ABOUT: MACRO_About(); break;
1322 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
1325 case MNID_CTXT_ANNOTATE:MACRO_Annotate(); break;
1326 case MNID_CTXT_COPY: MACRO_CopyDialog(); break;
1327 case MNID_CTXT_PRINT: MACRO_Print(); break;
1328 case MNID_OPTS_HISTORY: MACRO_History(); break;
1329 case MNID_OPTS_FONTS_SMALL:
1330 case MNID_CTXT_FONTS_SMALL:
1331 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1332 if (win->font_scale != 0)
1334 win->font_scale = 0;
1335 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
1338 case MNID_OPTS_FONTS_NORMAL:
1339 case MNID_CTXT_FONTS_NORMAL:
1340 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1341 if (win->font_scale != 1)
1343 win->font_scale = 1;
1344 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
1347 case MNID_OPTS_FONTS_LARGE:
1348 case MNID_CTXT_FONTS_LARGE:
1349 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1350 if (win->font_scale != 2)
1352 win->font_scale = 2;
1353 WINHELP_SetupText(GetDlgItem(hWnd, CTL_ID_TEXT), win, 0 /* FIXME */);
1356 case MNID_OPTS_HELP_DEFAULT:
1357 case MNID_OPTS_HELP_VISIBLE:
1358 case MNID_OPTS_HELP_NONVISIBLE:
1359 case MNID_OPTS_SYSTEM_COLORS:
1360 case MNID_CTXT_HELP_DEFAULT:
1361 case MNID_CTXT_HELP_VISIBLE:
1362 case MNID_CTXT_HELP_NONVISIBLE:
1363 case MNID_CTXT_SYSTEM_COLORS:
1368 for (button = win->first_button; button; button = button->next)
1369 if (wParam == button->wParam) break;
1371 MACRO_ExecuteMacro(button->lpszMacro);
1372 else if (!HIWORD(wParam))
1373 MessageBox(0, MAKEINTRESOURCE(STID_NOT_IMPLEMENTED),
1374 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
1378 /* EPP case WM_DESTROY: */
1379 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
1382 return WINHELP_HandleCommand((HWND)wParam, lParam);
1387 SendMessage(GetDlgItem(hWnd, CTL_ID_TEXT), WM_COPY, 0, 0);
1394 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1395 hTextWnd = GetDlgItem(win->hMainWnd, CTL_ID_TEXT);
1400 SendMessage(hTextWnd, EM_SCROLL, SB_LINEUP, 0);
1403 SendMessage(hTextWnd, EM_SCROLL, SB_LINEDOWN, 0);
1406 SendMessage(hTextWnd, EM_SCROLL, SB_PAGEUP, 0);
1409 SendMessage(hTextWnd, EM_SCROLL, SB_PAGEDOWN, 0);
1418 if (wParam == CTL_ID_TEXT)
1422 switch (((NMHDR*)lParam)->code)
1426 const MSGFILTER* msgf = (const MSGFILTER*)lParam;
1430 if (msgf->wParam == VK_ESCAPE) DestroyWindow(hWnd);
1432 case WM_RBUTTONDOWN:
1437 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1438 hMenu = LoadMenu(Globals.hInstance, (LPSTR)CONTEXT_MENU);
1439 switch (win->font_scale)
1442 CheckMenuItem(hMenu, MNID_CTXT_FONTS_SMALL,
1443 MF_BYCOMMAND|MF_CHECKED);
1446 WINE_FIXME("Unsupported %d\n", win->font_scale);
1448 CheckMenuItem(hMenu, MNID_CTXT_FONTS_NORMAL,
1449 MF_BYCOMMAND|MF_CHECKED);
1452 CheckMenuItem(hMenu, MNID_CTXT_FONTS_LARGE,
1453 MF_BYCOMMAND|MF_CHECKED);
1456 pt.x = (int)(short)LOWORD(msgf->lParam);
1457 pt.y = (int)(short)HIWORD(msgf->lParam);
1458 ClientToScreen(msgf->nmhdr.hwndFrom, &pt);
1459 TrackPopupMenu(GetSubMenu(hMenu, 0), TPM_LEFTALIGN|TPM_TOPALIGN,
1460 pt.x, pt.y, 0, hWnd, NULL);
1465 return WINHELP_HandleTextMouse((WINHELP_WINDOW*)GetWindowLongPtr(hWnd, 0),
1466 msgf->msg, msgf->lParam);
1471 case EN_REQUESTRESIZE:
1472 rc = ((REQRESIZE*)lParam)->rc;
1473 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1474 AdjustWindowRect(&rc, GetWindowLong(win->hMainWnd, GWL_STYLE),
1476 SetWindowPos(win->hMainWnd, HWND_TOP, 0, 0,
1477 rc.right - rc.left, rc.bottom - rc.top,
1478 SWP_NOMOVE | SWP_NOZORDER);
1479 WINHELP_LayoutMainWindow(win);
1485 case WM_INITMENUPOPUP:
1486 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1487 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_SMALL,
1488 MF_BYCOMMAND | (win->font_scale == 0) ? MF_CHECKED : 0);
1489 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_NORMAL,
1490 MF_BYCOMMAND | (win->font_scale == 1) ? MF_CHECKED : 0);
1491 CheckMenuItem((HMENU)wParam, MNID_OPTS_FONTS_LARGE,
1492 MF_BYCOMMAND | (win->font_scale == 2) ? MF_CHECKED : 0);
1498 win = (WINHELP_WINDOW*) GetWindowLongPtr(hWnd, 0);
1499 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1500 WINHELP_DeleteWindow(win);
1502 if (bExit) MACRO_Exit();
1503 if (!Globals.win_list)
1508 return DefWindowProc(hWnd, msg, wParam, lParam);
1511 /**************************************************************************
1512 * WINHELP_CreateIndexWindow
1514 * Displays a dialog with keywords of current help file.
1517 BOOL WINHELP_CreateIndexWindow(BOOL is_search)
1519 HPROPSHEETPAGE psPage[3];
1521 PROPSHEETHEADER psHead;
1522 struct index_data id;
1525 if (Globals.active_win && Globals.active_win->page && Globals.active_win->page->file)
1526 id.hlpfile = Globals.active_win->page->file;
1530 if (id.hlpfile->kwbtree == NULL)
1532 WINE_TRACE("No index provided\n");
1536 InitCommonControls();
1539 memset(&psp, 0, sizeof(psp));
1540 psp.dwSize = sizeof(psp);
1542 psp.hInstance = Globals.hInstance;
1544 psp.u.pszTemplate = MAKEINTRESOURCE(IDD_INDEX);
1545 psp.lParam = (LPARAM)&id;
1546 psp.pfnDlgProc = WINHELP_IndexDlgProc;
1547 psPage[0] = CreatePropertySheetPage(&psp);
1549 psp.u.pszTemplate = MAKEINTRESOURCE(IDD_SEARCH);
1550 psp.lParam = (LPARAM)&id;
1551 psp.pfnDlgProc = WINHELP_SearchDlgProc;
1552 psPage[1] = CreatePropertySheetPage(&psp);
1554 memset(&psHead, 0, sizeof(psHead));
1555 psHead.dwSize = sizeof(psHead);
1557 LoadString(Globals.hInstance, STID_PSH_INDEX, buf, sizeof(buf));
1558 strcat(buf, Globals.active_win->info->caption);
1560 psHead.pszCaption = buf;
1562 psHead.u2.nStartPage = is_search ? 1 : 0;
1563 psHead.hwndParent = Globals.active_win->hMainWnd;
1564 psHead.u3.phpage = psPage;
1565 psHead.dwFlags = PSH_NOAPPLYNOW;
1567 PropertySheet(&psHead);
1570 WINE_TRACE("got %d as an offset\n", id.offset);
1571 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset, id.hlpfile, id.offset,
1572 Globals.active_win->info, SW_NORMAL);
1577 /***********************************************************************
1579 * RegisterWinClasses
1581 static BOOL WINHELP_RegisterWinClasses(void)
1583 WNDCLASS class_main, class_button_box, class_shadow, class_history;
1585 class_main.style = CS_HREDRAW | CS_VREDRAW;
1586 class_main.lpfnWndProc = WINHELP_MainWndProc;
1587 class_main.cbClsExtra = 0;
1588 class_main.cbWndExtra = sizeof(WINHELP_WINDOW *);
1589 class_main.hInstance = Globals.hInstance;
1590 class_main.hIcon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_WINHELP));
1591 class_main.hCursor = LoadCursor(0, IDC_ARROW);
1592 class_main.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
1593 class_main.lpszMenuName = 0;
1594 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
1596 class_button_box = class_main;
1597 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
1598 class_button_box.cbWndExtra = 0;
1599 class_button_box.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
1600 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
1602 class_shadow = class_main;
1603 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
1604 class_shadow.cbWndExtra = 0;
1605 class_shadow.hbrBackground = (HBRUSH)(COLOR_3DDKSHADOW+1);
1606 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
1608 class_history = class_main;
1609 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
1610 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
1612 return (RegisterClass(&class_main) &&
1613 RegisterClass(&class_button_box) &&
1614 RegisterClass(&class_shadow) &&
1615 RegisterClass(&class_history));
1618 /***********************************************************************
1622 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
1627 static CHAR default_wndname[] = "main";
1628 LPSTR wndname = default_wndname;
1631 Globals.hInstance = hInstance;
1633 if (LoadLibrary("riched20.dll") == NULL)
1634 return MessageBox(0, MAKEINTRESOURCE(STID_NO_RICHEDIT),
1635 MAKEINTRESOURCE(STID_WHERROR), MB_OK);
1638 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
1642 if (*cmdline++ == ' ') continue;
1645 if (option) cmdline++;
1646 while (*cmdline && *cmdline == ' ') cmdline++;
1652 while (*cmdline && *cmdline != ' ') cmdline++;
1653 if (*cmdline) *cmdline++ = '\0';
1654 lHash = HLPFILE_Hash(topic_id);
1659 Globals.wVersion = option - '0';
1664 Globals.isBook = FALSE;
1668 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
1673 /* Create primary window */
1674 if (!WINHELP_RegisterWinClasses())
1676 WINE_FIXME("Couldn't register classes\n");
1683 if ((*cmdline == '"') && (ptr = strchr(cmdline+1, '"')))
1688 if ((ptr = strchr(cmdline, '>')))
1693 hlpfile = WINHELP_LookupHelpFile(cmdline);
1694 if (!hlpfile) return 0;
1696 else hlpfile = NULL;
1697 WINHELP_OpenHelpWindow(HLPFILE_PageByHash, hlpfile, lHash,
1698 WINHELP_GetWindowInfo(hlpfile, wndname), show);
1701 while (GetMessage(&msg, 0, 0, 0))
1703 TranslateMessage(&msg);
1704 DispatchMessage(&msg);
1706 for (dll = Globals.dlls; dll; dll = dll->next)
1708 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);