Fixed header dependencies to be fully compatible with the Windows
[wine/multimedia.git] / programs / winhelp / winhelp.c
blob771447beaec99413c8137ac4569387496176c538
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>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <assert.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winhelp.h"
33 #include "winhelp_res.h"
34 #include "shellapi.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
40 static BOOL WINHELP_RegisterWinClasses(void);
41 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
42 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
43 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
44 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
45 static void WINHELP_CheckPopup(UINT);
46 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
47 static void WINHELP_InitFonts(HWND hWnd);
48 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
49 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
50 static void WINHELP_SetupText(HWND hWnd);
51 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
53 WINHELP_GLOBALS Globals = {3, 0, 0, 0, 1, 0, 0};
55 /***********************************************************************
57 * WINHELP_LookupHelpFile
59 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
61 HLPFILE* hlpfile;
63 hlpfile = HLPFILE_ReadHlpFile(lpszFile);
65 /* Add Suffix `.hlp' */
66 if (!hlpfile && lstrcmpi(lpszFile + strlen(lpszFile) - 4, ".hlp") != 0)
68 char szFile_hlp[MAX_PATHNAME_LEN];
70 lstrcpyn(szFile_hlp, lpszFile, sizeof(szFile_hlp) - 4);
71 szFile_hlp[sizeof(szFile_hlp) - 5] = '\0';
72 lstrcat(szFile_hlp, ".hlp");
74 hlpfile = HLPFILE_ReadHlpFile(szFile_hlp);
76 if (!hlpfile)
78 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile, STID_WHERROR, MB_OK);
79 if (Globals.win_list) return NULL;
81 return hlpfile;
84 /******************************************************************
85 * WINHELP_GetWindowInfo
89 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
91 static HLPFILE_WINDOWINFO mwi;
92 int i;
94 if (!name || !name[0])
95 name = Globals.active_win->lpszName;
97 if (hlpfile)
98 for (i = 0; i < hlpfile->numWindows; i++)
99 if (!strcmp(hlpfile->windows[i].name, name))
100 return &hlpfile->windows[i];
102 if (strcmp(name, "main") != 0)
104 WINE_FIXME("Couldn't find window info for %s\n", name);
105 assert(0);
106 return NULL;
108 if (!mwi.name[0])
110 strcpy(mwi.type, "primary");
111 strcpy(mwi.name, "main");
112 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
113 mwi.caption, sizeof(mwi.caption)))
114 strcpy(mwi.caption, hlpfile->lpszTitle);
115 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
116 mwi.style = SW_SHOW;
117 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
119 return &mwi;
122 /******************************************************************
123 * HLPFILE_GetPopupWindowInfo
127 HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
129 static HLPFILE_WINDOWINFO wi;
131 RECT parent_rect;
133 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
135 /* Calculate horizontal size and position of a popup window */
136 GetWindowRect(hParentWnd, &parent_rect);
137 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
138 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
140 wi.origin = *mouse;
141 ClientToScreen(hParentWnd, &wi.origin);
142 wi.origin.x -= wi.size.cx / 2;
143 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
144 wi.origin.x = max(wi.origin.x, 0);
146 wi.style = SW_SHOW;
147 wi.win_style = WS_POPUPWINDOW;
148 wi.sr_color = wi.sr_color = 0xFFFFFF;
150 return &wi;
153 /***********************************************************************
155 * WinMain
157 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
159 MSG msg;
160 LONG lHash = 0;
161 HLPFILE* hlpfile;
163 Globals.hInstance = hInstance;
165 /* Get options */
166 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
168 CHAR option;
169 LPCSTR topic_id;
170 if (*cmdline++ == ' ') continue;
172 option = *cmdline;
173 if (option) cmdline++;
174 while (*cmdline && *cmdline == ' ') cmdline++;
175 switch (option)
177 case 'i':
178 case 'I':
179 topic_id = cmdline;
180 while (*cmdline && *cmdline != ' ') cmdline++;
181 if (*cmdline) *cmdline++ = '\0';
182 lHash = HLPFILE_Hash(topic_id);
183 break;
185 case '3':
186 case '4':
187 Globals.wVersion = option - '0';
188 break;
190 case 'x':
191 show = SW_HIDE;
192 Globals.isBook = FALSE;
193 break;
195 default:
196 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
197 break;
201 /* Create primary window */
202 WINHELP_RegisterWinClasses();
203 if (*cmdline)
205 hlpfile = WINHELP_LookupHelpFile(cmdline);
206 if (!hlpfile) return 0;
208 else hlpfile = NULL;
209 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
210 WINHELP_GetWindowInfo(hlpfile, "main"), show);
212 /* Message loop */
213 while (GetMessage(&msg, 0, 0, 0))
215 TranslateMessage(&msg);
216 DispatchMessage(&msg);
218 return 0;
221 /***********************************************************************
223 * RegisterWinClasses
225 static BOOL WINHELP_RegisterWinClasses(void)
227 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
229 class_main.style = CS_HREDRAW | CS_VREDRAW;
230 class_main.lpfnWndProc = WINHELP_MainWndProc;
231 class_main.cbClsExtra = 0;
232 class_main.cbWndExtra = sizeof(LONG);
233 class_main.hInstance = Globals.hInstance;
234 class_main.hIcon = LoadIcon(0, IDI_APPLICATION);
235 class_main.hCursor = LoadCursor(0, IDC_ARROW);
236 class_main.hbrBackground = GetStockObject(WHITE_BRUSH);
237 class_main.lpszMenuName = 0;
238 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
240 class_button_box = class_main;
241 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
242 class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
243 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
245 class_text = class_main;
246 class_text.lpfnWndProc = WINHELP_TextWndProc;
247 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
249 class_shadow = class_main;
250 class_shadow.lpfnWndProc = DefWindowProc;
251 class_shadow.hbrBackground = GetStockObject(GRAY_BRUSH);
252 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
254 class_history = class_main;
255 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
256 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
258 return (RegisterClass(&class_main) &&
259 RegisterClass(&class_button_box) &&
260 RegisterClass(&class_text) &&
261 RegisterClass(&class_shadow) &&
262 RegisterClass(&class_history));
265 typedef struct
267 WORD size;
268 WORD command;
269 LONG data;
270 LONG reserved;
271 WORD ofsFilename;
272 WORD ofsData;
273 } WINHELP,*LPWINHELP;
275 /******************************************************************
276 * WINHELP_HandleCommand
280 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
282 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
283 WINHELP* wh;
285 if (cds->dwData != 0xA1DE505)
287 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
288 return 0;
291 wh = (WINHELP*)cds->lpData;
293 if (wh)
295 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
297 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
298 wh->size, wh->command, wh->data, ptr);
299 switch (wh->command)
301 case HELP_CONTEXT:
302 if (ptr)
304 MACRO_JumpContext(ptr, "main", wh->data);
306 break;
307 case HELP_QUIT:
308 MACRO_Exit();
309 break;
310 case HELP_CONTENTS:
311 if (ptr)
313 MACRO_JumpContents(ptr, "main");
315 break;
316 case HELP_HELPONHELP:
317 MACRO_HelpOn();
318 break;
319 /* case HELP_SETINDEX: */
320 case HELP_SETCONTENTS:
321 if (ptr)
323 MACRO_SetContents(ptr, wh->data);
325 break;
326 case HELP_CONTEXTPOPUP:
327 if (ptr)
329 MACRO_PopupContext(ptr, wh->data);
331 break;
332 /* case HELP_FORCEFILE:*/
333 /* case HELP_CONTEXTMENU: */
334 case HELP_FINDER:
335 /* in fact, should be the topic dialog box */
336 if (ptr)
338 MACRO_JumpHash(ptr, "main", 0);
340 break;
341 /* case HELP_WM_HELP: */
342 /* case HELP_SETPOPUP_POS: */
343 /* case HELP_KEY: */
344 /* case HELP_COMMAND: */
345 /* case HELP_PARTIALKEY: */
346 /* case HELP_MULTIKEY: */
347 /* case HELP_SETWINPOS: */
348 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
349 break;
352 return 0L;
355 /******************************************************************
356 * WINHELP_ReuseWindow
360 static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
361 HLPFILE_PAGE* page, int nCmdShow)
363 int i;
365 win->hMainWnd = oldwin->hMainWnd;
366 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
367 win->hTextWnd = oldwin->hTextWnd;
368 win->hHistoryWnd = oldwin->hHistoryWnd;
369 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
371 SetWindowLong(win->hMainWnd, 0, (LONG)win);
372 SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
373 SetWindowLong(win->hTextWnd, 0, (LONG)win);
374 SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
376 WINHELP_InitFonts(win->hMainWnd);
378 if (page)
379 SetWindowText(win->hMainWnd, page->file->lpszTitle);
381 WINHELP_SetupText(win->hTextWnd);
382 InvalidateRect(win->hTextWnd, NULL, TRUE);
383 SendMessage(win->hMainWnd, WM_USER, 0, 0);
384 ShowWindow(win->hMainWnd, nCmdShow);
385 UpdateWindow(win->hTextWnd);
387 if (!(win->info->win_style & WS_POPUP))
389 unsigned num;
391 memcpy(win->history, oldwin->history, sizeof(win->history));
392 win->histIndex = oldwin->histIndex;
394 /* FIXME: when using back, we shouldn't update the history... */
396 if (page)
398 for (i = 0; i < win->histIndex; i++)
399 if (win->history[i] == page) break;
401 /* if the new page is already in the history, do nothing */
402 if (i == win->histIndex)
404 num = sizeof(win->history) / sizeof(win->history[0]);
405 if (win->histIndex == num)
407 /* we're full, remove latest entry */
408 HLPFILE_FreeHlpFile(win->history[0]->file);
409 memmove(&win->history[0], &win->history[1],
410 (num - 1) * sizeof(win->history[0]));
411 win->histIndex--;
413 win->history[win->histIndex++] = page;
414 page->file->wRefCount++;
415 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
419 memcpy(win->back, oldwin->back, sizeof(win->back));
420 win->backIndex = oldwin->backIndex;
422 if (page)
424 num = sizeof(win->back) / sizeof(win->back[0]);
425 if (win->backIndex == num)
427 /* we're full, remove latest entry */
428 HLPFILE_FreeHlpFile(win->back[0]->file);
429 memmove(&win->back[0], &win->back[1],
430 (num - 1) * sizeof(win->back[0]));
431 win->backIndex--;
433 win->back[win->backIndex++] = page;
434 page->file->wRefCount++;
437 else
438 win->backIndex = win->histIndex = 0;
440 oldwin->histIndex = oldwin->backIndex = 0;
441 WINHELP_DeleteWindow(oldwin);
442 return TRUE;
445 /***********************************************************************
447 * WINHELP_CreateHelpWindow
449 BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
450 int nCmdShow)
452 WINHELP_WINDOW *win, *oldwin;
453 HWND hWnd;
454 BOOL bPrimary;
455 BOOL bPopup;
457 bPrimary = !lstrcmpi(wi->name, "main");
458 bPopup = wi->win_style & WS_POPUP;
460 /* Initialize WINHELP_WINDOW struct */
461 win = HeapAlloc(GetProcessHeap(), 0,
462 sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
463 if (!win) return FALSE;
465 win->next = Globals.win_list;
466 Globals.win_list = win;
468 win->lpszName = (char*)win + sizeof(WINHELP_WINDOW);
469 lstrcpy((char*)win->lpszName, wi->name);
471 win->page = page;
472 win->first_button = 0;
473 win->first_line = 0;
474 win->hMainWnd = 0;
475 win->hButtonBoxWnd = 0;
476 win->hTextWnd = 0;
477 win->hShadowWnd = 0;
478 win->hHistoryWnd = 0;
480 win->hArrowCur = LoadCursorA(0, IDC_ARROWA);
481 win->hHandCur = LoadCursorA(0, IDC_HANDA);
483 win->info = wi;
485 Globals.active_win = win;
487 /* Initialize default pushbuttons */
488 if (bPrimary && page)
490 CHAR buffer[MAX_STRING_LEN];
492 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
493 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
494 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
495 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
496 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
497 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
498 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
499 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
500 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
501 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
504 /* Initialize file specific pushbuttons */
505 if (!(wi->win_style & WS_POPUP) && page)
507 HLPFILE_MACRO *macro;
508 for (macro = page->file->first_macro; macro; macro = macro->next)
509 MACRO_ExecuteMacro(macro->lpszMacro);
511 for (macro = page->first_macro; macro; macro = macro->next)
512 MACRO_ExecuteMacro(macro->lpszMacro);
515 win->histIndex = win->backIndex = 0;
516 /* Reuse existing window */
517 if (!bPopup)
519 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
521 if (!lstrcmpi(oldwin->lpszName, wi->name))
523 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
526 if (page)
528 win->histIndex = win->backIndex = 1;
529 win->history[0] = win->back[0] = page;
530 page->file->wRefCount += 2;
534 hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
535 wi->caption, wi->win_style,
536 wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
537 0, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
538 Globals.hInstance, win);
540 ShowWindow(hWnd, nCmdShow);
541 UpdateWindow(hWnd);
543 return TRUE;
546 /***********************************************************************
548 * WINHELP_CreateHelpWindowByHash
550 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
551 HLPFILE_WINDOWINFO* wi, int nCmdShow)
553 HLPFILE_PAGE* page = NULL;
555 if (hlpfile)
556 page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
557 HLPFILE_Contents(hlpfile);
558 if (page) page->file->wRefCount++;
559 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
562 /***********************************************************************
564 * WINHELP_MainWndProc
566 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
568 WINHELP_WINDOW *win;
569 WINHELP_BUTTON *button;
570 RECT rect, button_box_rect;
571 INT text_top;
573 WINHELP_CheckPopup(msg);
575 switch (msg)
577 case WM_NCCREATE:
578 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
579 SetWindowLong(hWnd, 0, (LONG) win);
580 win->hMainWnd = hWnd;
581 break;
583 case WM_CREATE:
584 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
586 /* Create button box and text Window */
587 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
588 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
590 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
591 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
593 /* Fall through */
594 case WM_USER:
595 case WM_WINDOWPOSCHANGED:
596 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
597 GetClientRect(hWnd, &rect);
599 /* Update button box and text Window */
600 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
601 rect.left, rect.top,
602 rect.right - rect.left,
603 rect.bottom - rect.top, 0);
605 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
606 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
608 SetWindowPos(win->hTextWnd, HWND_TOP,
609 rect.left, text_top,
610 rect.right - rect.left,
611 rect.bottom - text_top, 0);
613 break;
615 case WM_COMMAND:
616 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
617 switch (wParam)
619 /* Menu FILE */
620 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
621 case MNID_FILE_PRINT: MACRO_Print(); break;
622 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
623 case MNID_FILE_EXIT: MACRO_Exit(); break;
625 /* Menu EDIT */
626 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
627 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
629 /* Menu Bookmark */
630 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
632 /* Menu Help */
633 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
634 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
635 case MNID_HELP_ABOUT: MACRO_About(); break;
636 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
638 default:
639 /* Buttons */
640 for (button = win->first_button; button; button = button->next)
641 if (wParam == button->wParam) break;
642 if (button)
643 MACRO_ExecuteMacro(button->lpszMacro);
644 else
645 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
646 break;
648 break;
649 case WM_DESTROY:
650 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
651 break;
652 case WM_COPYDATA:
653 return WINHELP_HandleCommand((HWND)wParam, lParam);
655 return DefWindowProc(hWnd, msg, wParam, lParam);
658 /***********************************************************************
660 * WINHELP_ButtonBoxWndProc
662 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
664 WINDOWPOS *winpos;
665 WINHELP_WINDOW *win;
666 WINHELP_BUTTON *button;
667 SIZE button_size;
668 INT x, y;
670 WINHELP_CheckPopup(msg);
672 switch (msg)
674 case WM_NCCREATE:
675 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
676 SetWindowLong(hWnd, 0, (LONG) win);
677 win->hButtonBoxWnd = hWnd;
678 break;
680 case WM_WINDOWPOSCHANGING:
681 winpos = (WINDOWPOS*) lParam;
682 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
684 /* Update buttons */
685 button_size.cx = 0;
686 button_size.cy = 0;
687 for (button = win->first_button; button; button = button->next)
689 HDC hDc;
690 SIZE textsize;
691 if (!button->hWnd)
692 button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
693 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
694 0, 0, 0, 0,
695 hWnd, (HMENU) button->wParam,
696 Globals.hInstance, 0);
697 hDc = GetDC(button->hWnd);
698 GetTextExtentPoint(hDc, button->lpszName,
699 lstrlen(button->lpszName), &textsize);
700 ReleaseDC(button->hWnd, hDc);
702 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
703 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
706 x = 0;
707 y = 0;
708 for (button = win->first_button; button; button = button->next)
710 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
712 if (x + 2 * button_size.cx <= winpos->cx)
713 x += button_size.cx;
714 else
715 x = 0, y += button_size.cy;
717 winpos->cy = y + (x ? button_size.cy : 0);
718 break;
720 case WM_COMMAND:
721 SendMessage(GetParent(hWnd), msg, wParam, lParam);
722 break;
725 return DefWindowProc(hWnd, msg, wParam, lParam);
728 /***********************************************************************
730 * WINHELP_TextWndProc
732 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
734 WINHELP_WINDOW *win;
735 WINHELP_LINE *line;
736 WINHELP_LINE_PART *part;
737 WINDOWPOS *winpos;
738 PAINTSTRUCT ps;
739 HDC hDc;
740 POINT mouse;
741 INT scroll_pos;
742 HWND hPopupWnd;
743 BOOL bExit;
745 if (msg != WM_LBUTTONDOWN)
746 WINHELP_CheckPopup(msg);
748 switch (msg)
750 case WM_NCCREATE:
751 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
752 SetWindowLong(hWnd, 0, (LONG) win);
753 win->hTextWnd = hWnd;
754 if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
755 WINHELP_InitFonts(hWnd);
756 break;
758 case WM_CREATE:
759 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
761 /* Calculate vertical size and position of a popup window */
762 if (win->info->win_style & WS_POPUP)
764 POINT origin;
765 RECT old_window_rect;
766 RECT old_client_rect;
767 SIZE old_window_size;
768 SIZE old_client_size;
769 SIZE new_client_size;
770 SIZE new_window_size;
772 GetWindowRect(hWnd, &old_window_rect);
773 origin.x = old_window_rect.left;
774 origin.y = old_window_rect.top;
775 old_window_size.cx = old_window_rect.right - old_window_rect.left;
776 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
778 GetClientRect(hWnd, &old_client_rect);
779 old_client_size.cx = old_client_rect.right - old_client_rect.left;
780 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
782 new_client_size = old_client_size;
783 WINHELP_SplitLines(hWnd, &new_client_size);
785 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
786 origin.y += POPUP_YDISTANCE;
787 else
788 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
790 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
791 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
793 win->hShadowWnd =
794 CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
795 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
796 new_window_size.cx, new_window_size.cy,
797 0, 0, Globals.hInstance, 0);
799 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
800 new_window_size.cx, new_window_size.cy,
802 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
803 ShowWindow(win->hShadowWnd, SW_NORMAL);
804 SetActiveWindow(hWnd);
806 break;
808 case WM_WINDOWPOSCHANGED:
809 winpos = (WINDOWPOS*) lParam;
811 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
812 break;
814 case WM_VSCROLL:
816 BOOL update = TRUE;
817 RECT rect;
818 INT Min, Max;
819 INT CurPos = GetScrollPos(hWnd, SB_VERT);
820 INT dy;
822 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
823 GetClientRect(hWnd, &rect);
825 switch (wParam & 0xffff)
827 case SB_THUMBTRACK:
828 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
829 case SB_TOP: CurPos = Min; break;
830 case SB_BOTTOM: CurPos = Max; break;
831 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
832 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
833 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
834 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
835 default: update = FALSE;
837 if (update)
839 if (CurPos > Max)
840 CurPos = Max;
841 else if (CurPos < Min)
842 CurPos = Min;
843 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
844 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
845 ScrollWindow(hWnd, 0, dy, NULL, NULL);
846 UpdateWindow(hWnd);
849 break;
851 case WM_PAINT:
852 hDc = BeginPaint(hWnd, &ps);
853 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
854 scroll_pos = GetScrollPos(hWnd, SB_VERT);
856 for (line = win->first_line; line; line = line->next)
858 for (part = &line->first_part; part; part = part->next)
860 switch (part->cookie)
862 case hlp_line_part_text:
863 SelectObject(hDc, part->u.text.hFont);
864 SetTextColor(hDc, part->u.text.color);
865 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
866 part->u.text.lpsText, part->u.text.wTextLen);
867 if (part->u.text.wUnderline)
869 HPEN hPen;
871 switch (part->u.text.wUnderline)
873 case 1: /* simple */
874 case 2: /* double */
875 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
876 break;
877 case 3: /* dotted */
878 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
879 break;
880 default:
881 WINE_FIXME("Unknow underline type\n");
882 continue;
885 SelectObject(hDc, hPen);
886 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
887 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
888 if (part->u.text.wUnderline == 2)
890 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
891 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
893 DeleteObject(hPen);
895 break;
896 case hlp_line_part_bitmap:
898 HDC hMemDC;
900 hMemDC = CreateCompatibleDC(hDc);
901 SelectObject(hMemDC, part->u.bitmap.hBitmap);
902 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
903 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
904 hMemDC, 0, 0, SRCCOPY);
905 DeleteDC(hMemDC);
907 break;
908 case hlp_line_part_metafile:
910 POINT pt;
912 SetViewportOrgEx(hDc, part->rect.left, part->rect.top - scroll_pos, &pt);
913 PlayMetaFile(hDc, part->u.metafile.hMetaFile);
914 SetViewportOrgEx(hDc, pt.x, pt.y, NULL);
916 break;
921 EndPaint(hWnd, &ps);
922 break;
924 case WM_MOUSEMOVE:
925 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
927 if (WINHELP_IsOverLink(win, wParam, lParam))
928 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
929 else
930 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
932 break;
934 case WM_LBUTTONDOWN:
935 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
937 hPopupWnd = Globals.hPopupWnd;
938 Globals.hPopupWnd = 0;
940 part = WINHELP_IsOverLink(win, wParam, lParam);
941 if (part)
943 HLPFILE* hlpfile;
944 HLPFILE_WINDOWINFO* wi;
946 mouse.x = LOWORD(lParam);
947 mouse.y = HIWORD(lParam);
949 if (part->link) switch (part->link->cookie)
951 case hlp_link_link:
952 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
953 if (part->link->window == -1)
954 wi = win->info;
955 else if (part->link->window < hlpfile->numWindows)
956 wi = &hlpfile->windows[part->link->window];
957 else
959 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
960 break;
962 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
963 SW_NORMAL);
964 break;
965 case hlp_link_popup:
966 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
967 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
968 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
969 SW_NORMAL);
970 break;
971 case hlp_link_macro:
972 MACRO_ExecuteMacro(part->link->lpszString);
973 break;
974 default:
975 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
979 if (hPopupWnd)
980 DestroyWindow(hPopupWnd);
981 break;
983 case WM_NCDESTROY:
984 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
986 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
988 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
990 WINHELP_DeleteWindow(win);
992 if (bExit) MACRO_Exit();
994 if (!Globals.win_list)
995 PostQuitMessage(0);
996 break;
999 return DefWindowProc(hWnd, msg, wParam, lParam);
1002 /******************************************************************
1003 * WINHELP_HistoryWndProc
1007 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1009 WINHELP_WINDOW* win;
1010 PAINTSTRUCT ps;
1011 HDC hDc;
1012 TEXTMETRIC tm;
1013 int i;
1014 RECT r;
1016 switch (msg)
1018 case WM_NCCREATE:
1019 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1020 SetWindowLong(hWnd, 0, (LONG)win);
1021 win->hHistoryWnd = hWnd;
1022 break;
1023 case WM_CREATE:
1024 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1025 hDc = GetDC(hWnd);
1026 GetTextMetrics(hDc, &tm);
1027 GetWindowRect(hWnd, &r);
1029 r.right = r.left + 30 * tm.tmAveCharWidth;
1030 r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
1031 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1032 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1033 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1035 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1036 ReleaseDC(hWnd, hDc);
1037 break;
1038 case WM_LBUTTONDOWN:
1039 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1040 hDc = GetDC(hWnd);
1041 GetTextMetrics(hDc, &tm);
1042 i = HIWORD(lParam) / tm.tmHeight;
1043 if (i < win->histIndex)
1044 WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
1045 ReleaseDC(hWnd, hDc);
1046 break;
1047 case WM_PAINT:
1048 hDc = BeginPaint(hWnd, &ps);
1049 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1050 GetTextMetrics(hDc, &tm);
1052 for (i = 0; i < win->histIndex; i++)
1054 TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle,
1055 strlen(win->history[i]->lpszTitle));
1057 EndPaint(hWnd, &ps);
1058 break;
1059 case WM_DESTROY:
1060 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1061 if (hWnd == win->hHistoryWnd)
1062 win->hHistoryWnd = 0;
1063 break;
1065 return DefWindowProc(hWnd, msg, wParam, lParam);
1068 /***********************************************************************
1070 * SetupText
1072 static void WINHELP_SetupText(HWND hWnd)
1074 HDC hDc = GetDC(hWnd);
1075 RECT rect;
1076 SIZE newsize;
1078 ShowScrollBar(hWnd, SB_VERT, FALSE);
1079 if (!WINHELP_SplitLines(hWnd, NULL))
1081 ShowScrollBar(hWnd, SB_VERT, TRUE);
1082 GetClientRect(hWnd, &rect);
1084 WINHELP_SplitLines(hWnd, &newsize);
1085 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1087 else SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1089 ReleaseDC(hWnd, hDc);
1092 /***********************************************************************
1094 * WINHELP_AppendText
1096 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1097 LPSIZE space, LPSIZE textsize,
1098 INT *line_ascent, INT ascent,
1099 LPCSTR text, UINT textlen,
1100 HFONT font, COLORREF color, HLPFILE_LINK *link,
1101 unsigned underline)
1103 WINHELP_LINE *line;
1104 WINHELP_LINE_PART *part;
1105 LPSTR ptr;
1107 if (!*partp) /* New line */
1109 *line_ascent = ascent;
1111 line = HeapAlloc(GetProcessHeap(), 0,
1112 sizeof(WINHELP_LINE) + textlen);
1113 if (!line) return FALSE;
1115 line->next = 0;
1116 part = &line->first_part;
1117 ptr = (char*)line + sizeof(WINHELP_LINE);
1119 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1120 line->rect.bottom = line->rect.top;
1121 line->rect.left = space->cx;
1122 line->rect.right = space->cx;
1124 if (**linep) *linep = &(**linep)->next;
1125 **linep = line;
1126 space->cy = 0;
1128 else /* Same line */
1130 line = **linep;
1132 if (*line_ascent < ascent)
1134 WINHELP_LINE_PART *p;
1135 for (p = &line->first_part; p; p = p->next)
1137 p->rect.top += ascent - *line_ascent;
1138 p->rect.bottom += ascent - *line_ascent;
1140 line->rect.bottom += ascent - *line_ascent;
1141 *line_ascent = ascent;
1144 part = HeapAlloc(GetProcessHeap(), 0,
1145 sizeof(WINHELP_LINE_PART) + textlen);
1146 if (!part) return FALSE;
1147 **partp = part;
1148 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1151 memcpy(ptr, text, textlen);
1152 part->cookie = hlp_line_part_text;
1153 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1154 part->rect.right = part->rect.left + textsize->cx;
1155 line->rect.right = part->rect.right;
1156 part->rect.top =
1157 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1158 part->rect.bottom = part->rect.top + textsize->cy;
1159 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1160 part->u.text.lpsText = ptr;
1161 part->u.text.wTextLen = textlen;
1162 part->u.text.hFont = font;
1163 part->u.text.color = color;
1164 part->u.text.wUnderline = underline;
1166 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1167 part->u.text.wTextLen,
1168 part->u.text.wTextLen,
1169 part->u.text.lpsText,
1170 part->u.text.wTextLen,
1171 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1173 part->link = link;
1174 if (link) link->wRefCount++;
1176 part->next = 0;
1177 *partp = &part->next;
1179 space->cx = 0;
1181 return TRUE;
1184 /***********************************************************************
1186 * WINHELP_AppendGfxObject
1188 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1189 LPSIZE space, LPSIZE gfxSize,
1190 HLPFILE_LINK *link, unsigned pos)
1192 WINHELP_LINE *line;
1193 WINHELP_LINE_PART *part;
1194 LPSTR ptr;
1196 if (!*partp || pos == 1) /* New line */
1198 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1199 if (!line) return NULL;
1201 line->next = NULL;
1202 part = &line->first_part;
1204 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1205 line->rect.bottom = line->rect.top;
1206 line->rect.left = space->cx;
1207 line->rect.right = space->cx;
1209 if (**linep) *linep = &(**linep)->next;
1210 **linep = line;
1211 space->cy = 0;
1212 ptr = (char*)line + sizeof(WINHELP_LINE);
1214 else /* Same line */
1216 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1217 line = **linep;
1219 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1220 if (!part) return NULL;
1221 **partp = part;
1222 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1225 /* part->cookie should be set by caller (image or metafile) */
1226 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1227 part->rect.right = part->rect.left + gfxSize->cx;
1228 line->rect.right = part->rect.right;
1229 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1230 part->rect.bottom = part->rect.top + gfxSize->cy;
1231 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1233 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1234 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1236 part->link = link;
1237 if (link) link->wRefCount++;
1239 part->next = NULL;
1240 *partp = &part->next;
1242 space->cx = 0;
1244 return part;
1248 /***********************************************************************
1250 * WINHELP_SplitLines
1252 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1254 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1255 HLPFILE_PARAGRAPH *p;
1256 WINHELP_LINE **line = &win->first_line;
1257 WINHELP_LINE_PART **part = 0;
1258 INT line_ascent = 0;
1259 SIZE space;
1260 RECT rect;
1261 HDC hDc;
1263 if (newsize) newsize->cx = newsize->cy = 0;
1265 if (!win->page) return TRUE;
1267 WINHELP_DeleteLines(win);
1269 GetClientRect(hWnd, &rect);
1271 rect.top += INTERNAL_BORDER_WIDTH;
1272 rect.left += INTERNAL_BORDER_WIDTH;
1273 rect.right -= INTERNAL_BORDER_WIDTH;
1274 rect.bottom -= INTERNAL_BORDER_WIDTH;
1276 space.cy = rect.top;
1277 space.cx = rect.left;
1279 hDc = GetDC(hWnd);
1281 for (p = win->page->first_paragraph; p; p = p->next)
1283 switch (p->cookie)
1285 case para_normal_text:
1286 case para_debug_text:
1288 TEXTMETRIC tm;
1289 SIZE textsize = {0, 0};
1290 LPCSTR text = p->u.text.lpszText;
1291 UINT indent = 0;
1292 UINT len = strlen(text);
1293 unsigned underline = 0;
1295 HFONT hFont = 0;
1296 COLORREF color = RGB(0, 0, 0);
1298 if (p->u.text.wFont < win->page->file->numFonts)
1300 HLPFILE* hlpfile = win->page->file;
1302 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1303 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1304 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1305 color = hlpfile->fonts[p->u.text.wFont].color;
1307 else
1309 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1311 hFont = win->fonts[wFont];
1314 if (p->link && p->link->bClrChange)
1316 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1317 color = RGB(0, 0x80, 0);
1319 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1321 SelectObject(hDc, hFont);
1323 GetTextMetrics(hDc, &tm);
1325 if (p->u.text.wIndent)
1327 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1328 if (!part)
1329 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1332 if (p->u.text.wVSpace)
1334 part = 0;
1335 space.cx = rect.left + indent;
1336 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1339 if (p->u.text.wHSpace)
1341 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1344 WINE_TRACE("splitting text %s\n", text);
1346 while (len)
1348 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1349 UINT low = 0, curr = len, high = len, textlen = 0;
1351 if (free_width > 0)
1353 while (1)
1355 GetTextExtentPoint(hDc, text, curr, &textsize);
1357 if (textsize.cx <= free_width) low = curr;
1358 else high = curr;
1360 if (high <= low + 1) break;
1362 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1363 if (curr <= low) curr = low + 1;
1364 else if (curr >= high) curr = high - 1;
1366 textlen = low;
1367 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1369 if (!part && !textlen) textlen = max(low, 1);
1371 if (free_width <= 0 || !textlen)
1373 part = 0;
1374 space.cx = rect.left + indent;
1375 space.cx = min(space.cx, rect.right - rect.left - 1);
1376 continue;
1379 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1381 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1382 &line_ascent, tm.tmAscent,
1383 text, textlen, hFont, color, p->link, underline) ||
1384 (!newsize && (*line)->rect.bottom > rect.bottom))
1386 ReleaseDC(hWnd, hDc);
1387 return FALSE;
1390 if (newsize)
1391 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1393 len -= textlen;
1394 text += textlen;
1395 if (text[0] == ' ') text++, len--;
1398 break;
1399 case para_bitmap:
1400 case para_metafile:
1402 SIZE gfxSize;
1403 INT free_width;
1404 WINHELP_LINE_PART* ref_part;
1406 if (p->u.gfx.pos & 0x8000)
1408 space.cx = rect.left;
1409 if (*line)
1410 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1411 part = 0;
1414 if (p->cookie == para_bitmap)
1416 DIBSECTION dibs;
1418 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1419 gfxSize.cx = dibs.dsBm.bmWidth;
1420 gfxSize.cy = dibs.dsBm.bmHeight;
1422 else gfxSize = p->u.gfx.u.mf.mfSize;
1424 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1425 if (free_width <= 0)
1427 part = NULL;
1428 space.cx = rect.left;
1429 space.cx = min(space.cx, rect.right - rect.left - 1);
1431 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1432 p->link, p->u.gfx.pos);
1433 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1435 return FALSE;
1437 if (p->cookie == para_bitmap)
1439 ref_part->cookie = hlp_line_part_bitmap;
1440 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1442 else
1444 ref_part->cookie = hlp_line_part_metafile;
1445 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mf.hMetaFile;
1448 break;
1452 if (newsize)
1453 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1455 ReleaseDC(hWnd, hDc);
1456 return TRUE;
1459 /***********************************************************************
1461 * WINHELP_CheckPopup
1463 static void WINHELP_CheckPopup(UINT msg)
1465 if (!Globals.hPopupWnd) return;
1467 switch (msg)
1469 case WM_COMMAND:
1470 case WM_LBUTTONDOWN:
1471 case WM_MBUTTONDOWN:
1472 case WM_RBUTTONDOWN:
1473 case WM_NCLBUTTONDOWN:
1474 case WM_NCMBUTTONDOWN:
1475 case WM_NCRBUTTONDOWN:
1476 DestroyWindow(Globals.hPopupWnd);
1477 Globals.hPopupWnd = 0;
1481 /***********************************************************************
1483 * WINHELP_DeleteLines
1485 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1487 WINHELP_LINE *line, *next_line;
1488 WINHELP_LINE_PART *part, *next_part;
1489 for (line = win->first_line; line; line = next_line)
1491 next_line = line->next;
1492 for (part = &line->first_part; part; part = next_part)
1494 next_part = part->next;
1495 HLPFILE_FreeLink(part->link);
1496 HeapFree(GetProcessHeap(), 0, part);
1499 win->first_line = 0;
1502 /***********************************************************************
1504 * WINHELP_DeleteWindow
1506 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1508 WINHELP_WINDOW** w;
1509 int i;
1510 WINHELP_BUTTON* b;
1511 WINHELP_BUTTON* bp;
1513 for (w = &Globals.win_list; *w; w = &(*w)->next)
1515 if (*w == win)
1517 *w = win->next;
1518 break;
1522 for (b = win->first_button; b; b = bp)
1524 DestroyWindow(b->hWnd);
1525 bp = b->next;
1526 HeapFree(GetProcessHeap(), 0, b);
1529 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1530 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1532 for (i = 0; i < win->histIndex; i++)
1534 HLPFILE_FreeHlpFile(win->history[i]->file);
1537 for (i = 0; i < win->backIndex; i++)
1538 HLPFILE_FreeHlpFile(win->back[i]->file);
1540 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1541 WINHELP_DeleteLines(win);
1542 HeapFree(GetProcessHeap(), 0, win);
1545 /***********************************************************************
1547 * WINHELP_InitFonts
1549 static void WINHELP_InitFonts(HWND hWnd)
1551 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1552 LOGFONT logfontlist[] = {
1553 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1554 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1555 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1556 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1557 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1558 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1559 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1560 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1562 static HFONT fonts[FONTS_LEN];
1563 static BOOL init = 0;
1565 win->fonts_len = FONTS_LEN;
1566 win->fonts = fonts;
1568 if (!init)
1570 INT i;
1572 for (i = 0; i < FONTS_LEN; i++)
1574 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1577 init = 1;
1581 /***********************************************************************
1583 * WINHELP_MessageBoxIDS
1585 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1587 CHAR text[MAX_STRING_LEN];
1588 CHAR title[MAX_STRING_LEN];
1590 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1591 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1593 return MessageBox(0, text, title, type);
1596 /***********************************************************************
1598 * MAIN_MessageBoxIDS_s
1600 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1602 CHAR text[MAX_STRING_LEN];
1603 CHAR title[MAX_STRING_LEN];
1604 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
1606 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1607 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1608 wsprintf(newtext, text, str);
1610 return MessageBox(0, newtext, title, type);
1613 /******************************************************************
1614 * WINHELP_IsOverLink
1618 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1620 POINT mouse;
1621 WINHELP_LINE *line;
1622 WINHELP_LINE_PART *part;
1623 int scroll_pos = GetScrollPos(win->hMainWnd, SB_VERT);
1625 mouse.x = LOWORD(lParam);
1626 mouse.y = HIWORD(lParam);
1627 for (line = win->first_line; line; line = line->next)
1629 for (part = &line->first_part; part; part = part->next)
1631 if (part->link &&
1632 part->link->lpszString &&
1633 part->rect.left <= mouse.x &&
1634 part->rect.right >= mouse.x &&
1635 part->rect.top <= mouse.y + scroll_pos &&
1636 part->rect.bottom >= mouse.y + scroll_pos)
1638 return part;
1643 return NULL;