4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
15 static BOOL WINHELP_RegisterWinClasses();
16 static LRESULT WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
17 static LRESULT WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
18 static LRESULT WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
19 static VOID WINHELP_CheckPopup(UINT);
20 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
21 static VOID WINHELP_InitFonts(HWND hWnd);
22 static VOID WINHELP_DeleteLines(WINHELP_WINDOW*);
23 static VOID WINHELP_DeleteWindow(WINHELP_WINDOW*);
24 static VOID WINHELP_SetupText(HWND hWnd);
25 static BOOL WINHELP_AppendText(WINHELP_LINE***, WINHELP_LINE_PART***,
26 LPSIZE, LPSIZE, INT*, INT, LPCSTR, UINT,
27 HFONT, COLORREF, HLPFILE_LINK*);
29 WINHELP_GLOBALS Globals = {3, 0, 0, 0, 0, 0};
31 static BOOL MacroTest = FALSE;
33 /***********************************************************************
38 int PASCAL WinMain (HANDLE hInstance, HANDLE prev, LPSTR cmdline, int show)
40 LPCSTR opt_lang = "En";
46 Globals.hInstance = hInstance;
49 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
53 if (*cmdline++ == ' ') continue;
56 if (option) cmdline++;
57 while (*cmdline && *cmdline == ' ') cmdline++;
63 while (*cmdline && *cmdline != ' ') cmdline++;
64 if (*cmdline) *cmdline++ = '\0';
65 lHash = HLPFILE_Hash(topic_id);
70 Globals.wVersion = option - '0';
80 opt_lang = Languages[Options.language].name;
83 /* Find language specific string table */
84 for (langnum = 0; langnum <= MAX_LANGUAGE_NUMBER; langnum++)
86 Globals.wStringTableOffset = langnum * 0x100;
87 if (LoadString(hInstance, IDS_LANGUAGE_ID, lang, sizeof(lang)) &&
88 !lstrcmp(opt_lang, lang))
91 if (langnum > MAX_LANGUAGE_NUMBER)
93 /* Find fallback language */
94 for (langnum = 0; langnum <= MAX_LANGUAGE_NUMBER; langnum++)
96 Globals.wStringTableOffset = langnum * 0x100;
97 if (LoadString(hInstance, IDS_LANGUAGE_ID, lang, sizeof(lang)))
100 if (langnum > MAX_LANGUAGE_NUMBER)
102 MessageBox(0, "No language found", "FATAL ERROR", MB_OK);
107 /* Change Resource names */
108 lstrcpyn(STRING_MENU_Xx + lstrlen(STRING_MENU_Xx) - 2, lang, 3);
110 /* Create primary window */
111 WINHELP_RegisterWinClasses();
112 WINHELP_CreateHelpWindow(cmdline, lHash, "main", FALSE, NULL, NULL, show);
115 while (GetMessage (&msg, 0, 0, 0))
117 TranslateMessage (&msg);
118 DispatchMessage (&msg);
123 /***********************************************************************
128 static BOOL WINHELP_RegisterWinClasses()
130 WNDCLASS class_main, class_button_box, class_text, class_shadow;
132 class_main.style = CS_HREDRAW | CS_VREDRAW;
133 class_main.lpfnWndProc = WINHELP_MainWndProc;
134 class_main.cbClsExtra = 0;
135 class_main.cbWndExtra = sizeof(LONG);
136 class_main.hInstance = Globals.hInstance;
137 class_main.hIcon = LoadIcon (0, IDI_APPLICATION);
138 class_main.hCursor = LoadCursor (0, IDC_ARROW);
139 class_main.hbrBackground = GetStockObject (WHITE_BRUSH);
140 class_main.lpszMenuName = 0;
141 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
143 class_button_box = class_main;
144 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
145 class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
146 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
148 class_text = class_main;
149 class_text.lpfnWndProc = WINHELP_TextWndProc;
150 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
152 class_shadow = class_main;
153 class_shadow.lpfnWndProc = DefWindowProc;
154 class_shadow.hbrBackground = GetStockObject(GRAY_BRUSH);
155 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
157 return (RegisterClass(&class_main) &&
158 RegisterClass(&class_button_box) &&
159 RegisterClass(&class_text) &&
160 RegisterClass(&class_shadow));
163 /***********************************************************************
165 * WINHELP_CreateHelpWindow
168 VOID WINHELP_CreateHelpWindow(LPCSTR lpszFile, LONG lHash, LPCSTR lpszWindow,
169 BOOL bPopup, HWND hParentWnd, LPPOINT mouse, INT nCmdShow)
171 CHAR szCaption[MAX_STRING_LEN];
172 CHAR szContents[MAX_STRING_LEN];
173 CHAR szSearch[MAX_STRING_LEN];
174 CHAR szBack[MAX_STRING_LEN];
175 CHAR szHistory[MAX_STRING_LEN];
176 SIZE size = {CW_USEDEFAULT, CW_USEDEFAULT};
177 POINT origin = {240, 0};
180 WINHELP_WINDOW *win, *oldwin;
182 HLPFILE_MACRO *macro;
188 else if (!lpszWindow || !lpszWindow[0])
189 lpszWindow = Globals.active_win->lpszName;
190 bPrimary = lpszWindow && !lstrcmpi(lpszWindow, "main");
195 page = lHash ? HLPFILE_PageByHash(lpszFile, lHash) : HLPFILE_Contents(lpszFile);
197 /* Add Suffix `.hlp' */
198 if (!page && lstrcmpi(lpszFile + strlen(lpszFile) - 4, ".hlp"))
200 CHAR szFile_hlp[MAX_PATHNAME_LEN];
202 lstrcpyn(szFile_hlp, lpszFile, sizeof(szFile_hlp) - 4);
203 szFile_hlp[sizeof(szFile_hlp) - 5] = '\0';
204 lstrcat(szFile_hlp, ".hlp");
206 page = lHash ? HLPFILE_PageByHash(szFile_hlp, lHash) : HLPFILE_Contents(szFile_hlp);
209 WINHELP_MessageBoxIDS_s(IDS_HLPFILE_ERROR_s, lpszFile, IDS_ERROR, MB_OK);
210 if (Globals.win_list) return;
216 /* Calculate horizontal size and position of a popup window */
220 GetWindowRect(hParentWnd, &parent_rect);
221 size.cx = (parent_rect.right - parent_rect.left) / 2;
224 ClientToScreen(hParentWnd, &origin);
225 origin.x -= size.cx / 2;
226 origin.x = MIN(origin.x, GetSystemMetrics(SM_CXSCREEN) - size.cx);
227 origin.x = MAX(origin.x, 0);
230 /* Initialize WINHELP_WINDOW struct */
231 handle = GlobalAlloc(GMEM_FIXED, sizeof(WINHELP_WINDOW) +
232 (lpszWindow ? strlen(lpszWindow) + 1 : 0));
234 win = GlobalLock(handle);
236 win->next = Globals.win_list;
237 Globals.win_list = win;
240 ptr = GlobalLock(handle);
241 ptr += sizeof(WINHELP_WINDOW);
242 lstrcpy(ptr, (LPSTR) lpszWindow);
245 else win->lpszName = NULL;
247 win->first_button = 0;
250 win->hButtonBoxWnd = 0;
254 Globals.active_win = win;
256 /* Initialize default pushbuttons */
257 if (MacroTest && !bPopup)
258 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
259 if (bPrimary && page)
261 LoadString(Globals.hInstance, IDS_CONTENTS, szContents, sizeof(szContents));
262 LoadString(Globals.hInstance, IDS_SEARCH, szSearch, sizeof(szSearch));
263 LoadString(Globals.hInstance, IDS_BACK, szBack, sizeof(szBack));
264 LoadString(Globals.hInstance, IDS_HISTORY, szHistory, sizeof(szHistory));
265 MACRO_CreateButton("BTN_CONTENTS", szContents, "Contents()");
266 MACRO_CreateButton("BTN_SEARCH", szSearch, "Search()");
267 MACRO_CreateButton("BTN_BACK", szBack, "Back()");
268 MACRO_CreateButton("BTN_HISTORY", szHistory, "History()");
271 /* Initialize file specific pushbuttons */
273 for (macro = page->file->first_macro; macro; macro = macro->next)
274 MACRO_ExecuteMacro(macro->lpszMacro);
276 /* Reuse existing window */
278 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
279 if (oldwin->lpszName && !lstrcmpi(oldwin->lpszName, lpszWindow))
281 WINHELP_BUTTON *button;
283 win->hMainWnd = oldwin->hMainWnd;
284 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
285 win->hTextWnd = oldwin->hTextWnd;
286 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = 0;
288 SetWindowLong(win->hMainWnd, 0, (LONG) win);
289 SetWindowLong(win->hButtonBoxWnd, 0, (LONG) win);
290 SetWindowLong(win->hTextWnd, 0, (LONG) win);
292 WINHELP_InitFonts(win->hMainWnd);
295 SetWindowText(win->hMainWnd, page->file->lpszTitle);
298 WINHELP_SetupText(win->hTextWnd);
299 InvalidateRect(win->hTextWnd, NULL, TRUE);
300 SendMessage(win->hMainWnd, WM_USER, 0, 0);
301 UpdateWindow(win->hTextWnd);
304 for (button = oldwin->first_button; button; button = button->next)
305 DestroyWindow(button->hWnd);
307 WINHELP_DeleteWindow(oldwin);
311 /* Create main Window */
312 if (!page) LoadString(Globals.hInstance, IDS_WINE_HELP, szCaption, sizeof(szCaption));
313 hWnd = CreateWindow (bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
314 page ? page->file->lpszTitle : szCaption,
315 bPopup ? WS_POPUPWINDOW | WS_BORDER : WS_OVERLAPPEDWINDOW,
316 origin.x, origin.y, size.cx, size.cy,
317 0, bPrimary ? LoadMenu(Globals.hInstance, STRING_MENU_Xx) : 0,
318 Globals.hInstance, win);
320 ShowWindow (hWnd, nCmdShow);
324 /***********************************************************************
326 * WINHELP_MainWndProc
329 static LRESULT WINHELP_MainWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
332 WINHELP_BUTTON *button;
333 RECT rect, button_box_rect;
336 WINHELP_CheckPopup(msg);
341 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
342 SetWindowLong(hWnd, 0, (LONG) win);
343 win->hMainWnd = hWnd;
347 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
349 /* Create button box and text Window */
350 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
351 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
353 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
354 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
358 case WM_WINDOWPOSCHANGED:
359 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
360 GetClientRect(hWnd, &rect);
362 /* Update button box and text Window */
363 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
365 rect.right - rect.left,
366 rect.bottom - rect.top, 0);
368 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
369 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
371 SetWindowPos(win->hTextWnd, HWND_TOP,
373 rect.right - rect.left,
374 rect.bottom - text_top, 0);
379 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
383 case WH_OPEN: MACRO_FileOpen(); break;
384 case WH_PRINT: MACRO_Print(); break;
385 case WH_PRINTER_SETUP: MACRO_PrinterSetup(); break;
386 case WH_EXIT: MACRO_Exit(); break;
389 case WH_COPY_DIALOG: MACRO_CopyDialog(); break;
390 case WH_ANNOTATE: MACRO_Annotate(); break;
393 case WH_BOOKMARK_DEFINE: MACRO_BookmarkDefine(); break;
396 case WH_HELP_ON_HELP: MACRO_HelpOn(); break;
397 case WH_HELP_ON_TOP: MACRO_HelpOnTop(); break;
400 case WH_ABOUT: MACRO_About(); break;
403 ShellAbout(hWnd, "WINE", "Help", 0);
408 for (button = win->first_button; button; button = button->next)
409 if (wParam == button->wParam) break;
411 MACRO_ExecuteMacro(button->lpszMacro);
413 WINHELP_MessageBoxIDS(IDS_NOT_IMPLEMENTED, IDS_ERROR, MB_OK);
419 return DefWindowProc (hWnd, msg, wParam, lParam);
422 /***********************************************************************
424 * WINHELP_ButtonBoxWndProc
427 static LRESULT WINHELP_ButtonBoxWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
431 WINHELP_BUTTON *button;
435 WINHELP_CheckPopup(msg);
440 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
441 SetWindowLong(hWnd, 0, (LONG) win);
442 win->hButtonBoxWnd = hWnd;
445 case WM_WINDOWPOSCHANGING:
446 winpos = (WINDOWPOS*) lParam;
447 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
452 for (button = win->first_button; button; button = button->next)
457 button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
458 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
460 hWnd, (HMENU) button->wParam,
461 Globals.hInstance, 0);
462 hDc = GetDC(button->hWnd);
463 GetTextExtentPoint(hDc, button->lpszName,
464 lstrlen(button->lpszName), &textsize);
465 ReleaseDC(button->hWnd, hDc);
467 button_size.cx = MAX(button_size.cx, textsize.cx + BUTTON_CX);
468 button_size.cy = MAX(button_size.cy, textsize.cy + BUTTON_CY);
473 for (button = win->first_button; button; button = button->next)
475 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
477 if (x + 2 * button_size.cx <= winpos->cx)
480 x = 0, y += button_size.cy;
482 winpos->cy = y + (x ? button_size.cy : 0);
486 SendMessage(GetParent(hWnd), msg, wParam, lParam);
490 return(DefWindowProc(hWnd, msg, wParam, lParam));
493 /***********************************************************************
495 * WINHELP_TextWndProc
498 static LRESULT WINHELP_TextWndProc (HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
502 WINHELP_LINE_PART *part;
511 if (msg != WM_LBUTTONDOWN)
512 WINHELP_CheckPopup(msg);
517 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
518 SetWindowLong(hWnd, 0, (LONG) win);
519 win->hTextWnd = hWnd;
520 if (!win->lpszName) Globals.hPopupWnd = win->hMainWnd = hWnd;
521 WINHELP_InitFonts(hWnd);
525 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
527 /* Calculate vertical size and position of a popup window */
531 RECT old_window_rect;
532 RECT old_client_rect;
533 SIZE old_window_size;
534 SIZE old_client_size;
535 SIZE new_client_size;
536 SIZE new_window_size;
538 GetWindowRect(hWnd, &old_window_rect);
539 origin.x = old_window_rect.left;
540 origin.y = old_window_rect.top;
541 old_window_size.cx = old_window_rect.right - old_window_rect.left;
542 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
544 GetClientRect(hWnd, &old_client_rect);
545 old_client_size.cx = old_client_rect.right - old_client_rect.left;
546 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
548 new_client_size = old_client_size;
549 WINHELP_SplitLines(hWnd, &new_client_size);
551 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
552 origin.y += POPUP_YDISTANCE;
554 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
556 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
557 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
560 CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP | WS_VISIBLE,
561 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
562 new_window_size.cx, new_window_size.cy,
563 0, 0, Globals.hInstance, 0);
565 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
566 new_window_size.cx, new_window_size.cy,
567 SWP_NOZORDER | SWP_NOACTIVATE);
568 ShowWindow(win->hShadowWnd, SW_NORMAL);
572 case WM_WINDOWPOSCHANGED:
573 winpos = (WINDOWPOS*) lParam;
574 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
582 INT CurPos = GetScrollPos(hWnd, SB_VERT);
583 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
584 GetClientRect(hWnd, &rect);
586 switch (wParam & 0xffff)
589 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
590 case SB_TOP: CurPos = Min; break;
591 case SB_BOTTOM: CurPos = Max; break;
592 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
593 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
594 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
595 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
596 default: update = FALSE;
600 INT dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
601 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
602 ScrollWindow(hWnd, 0, dy, NULL, NULL);
609 hDc = BeginPaint (hWnd, &ps);
610 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
611 scroll_pos = GetScrollPos(hWnd, SB_VERT);
613 for (line = win->first_line; line; line = line->next)
614 for (part = &line->first_part; part; part = part->next)
616 SelectObject(hDc, part->hFont);
617 SetTextColor(hDc, part->color);
618 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
619 (LPSTR) part->lpsText, part->wTextLen);
622 EndPaint (hWnd, &ps);
626 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
627 scroll_pos = GetScrollPos(hWnd, SB_VERT);
629 hPopupWnd = Globals.hPopupWnd;
630 Globals.hPopupWnd = 0;
632 mouse.x = LOWORD(lParam);
633 mouse.y = HIWORD(lParam);
634 for (line = win->first_line; line; line = line->next)
635 for (part = &line->first_part; part; part = part->next)
636 if (part->link.lpszPath &&
637 part->rect.left <= mouse.x &&
638 part->rect.right >= mouse.x &&
639 part->rect.top <= mouse.y + scroll_pos &&
640 part->rect.bottom >= mouse.y + scroll_pos)
641 WINHELP_CreateHelpWindow(part->link.lpszPath, part->link.lHash, NULL,
642 part->link.bPopup, hWnd, &mouse, SW_NORMAL);
644 DestroyWindow(hPopupWnd);
648 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
650 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
652 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
654 WINHELP_DeleteWindow(win);
656 if (bExit) MACRO_Exit();
658 if (!Globals.win_list)
663 return DefWindowProc (hWnd, msg, wParam, lParam);
666 /***********************************************************************
671 static VOID WINHELP_SetupText(HWND hWnd)
673 HDC hDc = GetDC(hWnd);
677 ShowScrollBar(hWnd, SB_VERT, FALSE);
678 if (!WINHELP_SplitLines(hWnd, NULL))
680 ShowScrollBar(hWnd, SB_VERT, TRUE);
681 GetClientRect(hWnd, &rect);
683 WINHELP_SplitLines(hWnd, &newsize);
684 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
686 else SetScrollPos(hWnd, SB_VERT, 0, FALSE);
688 ReleaseDC(hWnd, hDc);
691 /***********************************************************************
696 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
698 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
699 HLPFILE_PARAGRAPH *p;
700 WINHELP_LINE **line = &win->first_line;
701 WINHELP_LINE_PART **part = 0;
707 if (newsize) newsize->cx = newsize->cy = 0;
709 if (!win->page) return TRUE;
711 WINHELP_DeleteLines(win);
713 GetClientRect(hWnd, &rect);
715 rect.top += INTERNAL_BORDER_WIDTH;
716 rect.left += INTERNAL_BORDER_WIDTH;
717 rect.right -= INTERNAL_BORDER_WIDTH;
718 rect.bottom -= INTERNAL_BORDER_WIDTH;
722 space.cx = rect.left;
726 for (p = win->page->first_paragraph; p; p = p->next)
729 SIZE textsize = {0, 0};
730 LPCSTR text = p->lpszText;
731 UINT len = strlen(text);
734 UINT wFont = (p->wFont < win->fonts_len) ? p->wFont : 0;
735 BOOL bUnderline = p->link && !p->link->bPopup;
736 HFONT hFont = win->fonts[wFont][bUnderline ? 1 : 0];
738 COLORREF color = RGB(0, 0, 0);
739 if (p->link) color = RGB(0, 0x80, 0);
740 if (p->bDebug) color = RGB(0xff, 0, 0);
742 SelectObject(hDc, hFont);
744 GetTextMetrics (hDc, &tm);
748 indent = p->wIndent * 5 * tm.tmAveCharWidth;
750 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
756 space.cx = rect.left + indent;
757 space.cy += (p->wVSpace - 1) * tm.tmHeight;
762 space.cx += p->wHSpace * 2 * tm.tmAveCharWidth;
767 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
768 UINT low = 0, curr = len, high = len, textlen = 0;
774 GetTextExtentPoint(hDc, text, curr, &textsize);
776 if (textsize.cx <= free_width) low = curr;
779 if (high <= low + 1) break;
781 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
782 if (curr <= low) curr = low + 1;
783 else if (curr >= high) curr = high - 1;
786 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
788 if (!part && !textlen) textlen = MAX(low, 1);
790 if (free_width <= 0 || !textlen)
793 space.cx = rect.left + indent;
794 space.cx = MIN(space.cx, rect.right - rect.left - 1);
798 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
799 &line_ascent, tm.tmAscent,
800 text, textlen, hFont, color, p->link) ||
801 (!newsize && (*line)->rect.bottom > rect.bottom))
803 ReleaseDC(hWnd, hDc);
808 newsize->cx = MAX(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
812 if (text[0] == ' ') text++, len--;
817 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
819 ReleaseDC(hWnd, hDc);
823 /***********************************************************************
828 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
829 LPSIZE space, LPSIZE textsize,
830 INT *line_ascent, INT ascent,
831 LPCSTR text, UINT textlen,
832 HFONT font, COLORREF color, HLPFILE_LINK *link)
836 WINHELP_LINE_PART *part;
839 if (!*partp) /* New line */
841 *line_ascent = ascent;
843 handle = GlobalAlloc(GMEM_FIXED, sizeof(WINHELP_LINE) + textlen +
844 (link ? lstrlen(link->lpszPath) + 1 : 0));
845 if (!handle) return FALSE;
846 line = GlobalLock(handle);
848 part = &line->first_part;
849 ptr = GlobalLock(handle);
850 ptr += sizeof(WINHELP_LINE);
852 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
853 line->rect.bottom = line->rect.top;
854 line->rect.left = space->cx;
855 line->rect.right = space->cx;
857 if (**linep) *linep = &(**linep)->next;
865 if (*line_ascent < ascent)
867 WINHELP_LINE_PART *p;
868 for (p = &line->first_part; p; p = p->next)
870 p->rect.top += ascent - *line_ascent;
871 p->rect.bottom += ascent - *line_ascent;
873 line->rect.bottom += ascent - *line_ascent;
874 *line_ascent = ascent;
877 handle = GlobalAlloc(GMEM_FIXED, sizeof(WINHELP_LINE_PART) + textlen +
878 (link ? lstrlen(link->lpszPath) + 1 : 0));
879 if (!handle) return FALSE;
880 part = GlobalLock(handle);
882 ptr = GlobalLock(handle);
883 ptr += sizeof(WINHELP_LINE_PART);
886 hmemcpy16(ptr, text, textlen);
887 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
888 part->rect.right = part->rect.left + textsize->cx;
889 line->rect.right = part->rect.right;
891 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
892 part->rect.bottom = part->rect.top + textsize->cy;
893 line->rect.bottom = MAX(line->rect.bottom, part->rect.bottom);
894 part->hSelf = handle;
896 part->wTextLen = textlen;
901 strcpy(ptr + textlen, link->lpszPath);
902 part->link.lpszPath = ptr + textlen;
903 part->link.lHash = link->lHash;
904 part->link.bPopup = link->bPopup;
906 else part->link.lpszPath = 0;
909 *partp = &part->next;
916 /***********************************************************************
921 static VOID WINHELP_CheckPopup(UINT msg)
923 if (!Globals.hPopupWnd) return;
931 case WM_NCLBUTTONDOWN:
932 case WM_NCMBUTTONDOWN:
933 case WM_NCRBUTTONDOWN:
934 DestroyWindow(Globals.hPopupWnd);
935 Globals.hPopupWnd = 0;
939 /***********************************************************************
941 * WINHELP_DeleteLines
944 static VOID WINHELP_DeleteLines(WINHELP_WINDOW *win)
946 WINHELP_LINE *line, *next_line;
947 WINHELP_LINE_PART *part, *next_part;
948 for(line = win->first_line; line; line = next_line)
950 next_line = line->next;
951 for(part = &line->first_part; part; part = next_part)
953 next_part = part->next;
954 GlobalFree(part->hSelf);
960 /***********************************************************************
962 * WINHELP_DeleteWindow
965 static VOID WINHELP_DeleteWindow(WINHELP_WINDOW *win)
969 for (w = &Globals.win_list; *w; w = &(*w)->next)
976 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
977 HLPFILE_FreeHlpFilePage(win->page);
978 WINHELP_DeleteLines(win);
979 GlobalFree(win->hSelf);
982 /***********************************************************************
987 static VOID WINHELP_InitFonts(HWND hWnd)
989 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
990 LOGFONT logfontlist[] = {
991 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
992 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
993 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
994 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
995 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
996 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
997 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
998 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1000 static HFONT fonts[FONTS_LEN][2];
1001 static BOOL init = 0;
1003 win->fonts_len = FONTS_LEN;
1010 for(i = 0; i < FONTS_LEN; i++)
1012 LOGFONT logfont = logfontlist[i];
1014 fonts[i][0] = CreateFontIndirect(&logfont);
1015 logfont.lfUnderline = 1;
1016 fonts[i][1] = CreateFontIndirect(&logfont);
1023 /***********************************************************************
1025 * WINHELP_MessageBoxIDS
1028 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1030 CHAR text[MAX_STRING_LEN];
1031 CHAR title[MAX_STRING_LEN];
1033 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1034 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1036 return(MessageBox(0, text, title, type));
1039 /***********************************************************************
1041 * MAIN_MessageBoxIDS_s
1044 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1046 CHAR text[MAX_STRING_LEN];
1047 CHAR title[MAX_STRING_LEN];
1048 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
1050 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1051 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1052 wsprintf(newtext, text, str);
1054 return(MessageBox(0, newtext, title, type));
1057 /* Local Variables: */
1058 /* c-file-style: "GNU" */