Precisely compute the necessary pidl length in UNIXFS_path_to_pidl.
[wine/multimedia.git] / programs / winhelp / winhelp.c
blob930ab0950c5a30a57ff026692fbc388c1a77f8f7
1 /*
2 * Help Viewer
4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002 Eric Pouech <eric.pouech@wanadoo.fr>
7 * 2004 Ken Belleau <jamez@ivic.qc.ca>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <assert.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdarg.h>
28 #include <stdlib.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winhelp.h"
35 #include "winhelp_res.h"
36 #include "shellapi.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
42 static BOOL WINHELP_RegisterWinClasses(void);
43 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
44 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
45 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
46 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND, UINT, WPARAM, LPARAM);
47 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
48 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND, UINT, WPARAM, LPARAM);
49 static void WINHELP_CheckPopup(UINT);
50 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
51 static void WINHELP_InitFonts(HWND hWnd);
52 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
53 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
54 static void WINHELP_SetupText(HWND hWnd);
55 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
57 WINHELP_GLOBALS Globals = {3, NULL, NULL, 0, TRUE, NULL, NULL, NULL, NULL};
59 /***********************************************************************
61 * WINHELP_LookupHelpFile
63 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
65 HLPFILE* hlpfile;
67 hlpfile = HLPFILE_ReadHlpFile(lpszFile);
69 /* Add Suffix `.hlp' */
70 if (!hlpfile && lstrcmpi(lpszFile + strlen(lpszFile) - 4, ".hlp") != 0)
72 char szFile_hlp[MAX_PATHNAME_LEN];
74 lstrcpyn(szFile_hlp, lpszFile, sizeof(szFile_hlp) - 4);
75 szFile_hlp[sizeof(szFile_hlp) - 5] = '\0';
76 lstrcat(szFile_hlp, ".hlp");
78 hlpfile = HLPFILE_ReadHlpFile(szFile_hlp);
80 if (!hlpfile)
82 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile, STID_WHERROR, MB_OK);
83 if (Globals.win_list) return NULL;
85 return hlpfile;
88 /******************************************************************
89 * WINHELP_GetWindowInfo
93 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
95 static HLPFILE_WINDOWINFO mwi;
96 unsigned int i;
98 if (!name || !name[0])
99 name = Globals.active_win->lpszName;
101 if (hlpfile)
102 for (i = 0; i < hlpfile->numWindows; i++)
103 if (!strcmp(hlpfile->windows[i].name, name))
104 return &hlpfile->windows[i];
106 if (strcmp(name, "main") != 0)
108 WINE_FIXME("Couldn't find window info for %s\n", name);
109 assert(0);
110 return NULL;
112 if (!mwi.name[0])
114 strcpy(mwi.type, "primary");
115 strcpy(mwi.name, "main");
116 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
117 mwi.caption, sizeof(mwi.caption)))
118 strcpy(mwi.caption, hlpfile->lpszTitle);
119 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
120 mwi.style = SW_SHOW;
121 mwi.win_style = WS_OVERLAPPEDWINDOW;
122 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
124 return &mwi;
127 /******************************************************************
128 * HLPFILE_GetPopupWindowInfo
132 static HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
134 static HLPFILE_WINDOWINFO wi;
136 RECT parent_rect;
138 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
140 /* Calculate horizontal size and position of a popup window */
141 GetWindowRect(hParentWnd, &parent_rect);
142 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
143 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
145 wi.origin = *mouse;
146 ClientToScreen(hParentWnd, &wi.origin);
147 wi.origin.x -= wi.size.cx / 2;
148 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
149 wi.origin.x = max(wi.origin.x, 0);
151 wi.style = SW_SHOW;
152 wi.win_style = WS_POPUPWINDOW;
153 wi.sr_color = wi.sr_color = 0xFFFFFF;
155 return &wi;
158 /***********************************************************************
160 * WinMain
162 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
164 MSG msg;
165 LONG lHash = 0;
166 HLPFILE* hlpfile;
167 CHAR* quote;
168 WINHELP_DLL* dll;
170 Globals.hInstance = hInstance;
172 /* Get options */
173 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
175 CHAR option;
176 LPCSTR topic_id;
177 if (*cmdline++ == ' ') continue;
179 option = *cmdline;
180 if (option) cmdline++;
181 while (*cmdline && *cmdline == ' ') cmdline++;
182 switch (option)
184 case 'i':
185 case 'I':
186 topic_id = cmdline;
187 while (*cmdline && *cmdline != ' ') cmdline++;
188 if (*cmdline) *cmdline++ = '\0';
189 lHash = HLPFILE_Hash(topic_id);
190 break;
192 case '3':
193 case '4':
194 Globals.wVersion = option - '0';
195 break;
197 case 'x':
198 show = SW_HIDE;
199 Globals.isBook = FALSE;
200 break;
202 default:
203 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
204 break;
208 /* Create primary window */
209 if (!WINHELP_RegisterWinClasses())
211 WINE_FIXME("Couldn't register classes\n");
212 return 0;
215 if (*cmdline)
217 if ((*cmdline == '"') && (quote = strchr(cmdline+1, '"')))
219 cmdline++;
220 *quote = '\0';
222 hlpfile = WINHELP_LookupHelpFile(cmdline);
223 if (!hlpfile) return 0;
225 else hlpfile = NULL;
226 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
227 WINHELP_GetWindowInfo(hlpfile, "main"), show);
229 /* Message loop */
230 while (GetMessage(&msg, 0, 0, 0))
232 TranslateMessage(&msg);
233 DispatchMessage(&msg);
235 for (dll = Globals.dlls; dll; dll = dll->next)
237 if (dll->class & DC_INITTERM) dll->handler(DW_TERM, 0, 0);
239 return 0;
242 /***********************************************************************
244 * RegisterWinClasses
246 static BOOL WINHELP_RegisterWinClasses(void)
248 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
250 class_main.style = CS_HREDRAW | CS_VREDRAW;
251 class_main.lpfnWndProc = WINHELP_MainWndProc;
252 class_main.cbClsExtra = 0;
253 class_main.cbWndExtra = sizeof(LONG);
254 class_main.hInstance = Globals.hInstance;
255 class_main.hIcon = LoadIcon(0, IDI_APPLICATION);
256 class_main.hCursor = LoadCursor(0, IDC_ARROW);
257 class_main.hbrBackground = GetStockObject(WHITE_BRUSH);
258 class_main.lpszMenuName = 0;
259 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
261 class_button_box = class_main;
262 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
263 class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
264 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
266 class_text = class_main;
267 class_text.lpfnWndProc = WINHELP_TextWndProc;
268 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
270 class_shadow = class_main;
271 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
272 class_shadow.hbrBackground = GetStockObject(GRAY_BRUSH);
273 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
275 class_history = class_main;
276 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
277 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
279 return (RegisterClass(&class_main) &&
280 RegisterClass(&class_button_box) &&
281 RegisterClass(&class_text) &&
282 RegisterClass(&class_shadow) &&
283 RegisterClass(&class_history));
286 typedef struct
288 WORD size;
289 WORD command;
290 LONG data;
291 LONG reserved;
292 WORD ofsFilename;
293 WORD ofsData;
294 } WINHELP,*LPWINHELP;
296 /******************************************************************
297 * WINHELP_HandleCommand
301 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
303 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
304 WINHELP* wh;
306 if (cds->dwData != 0xA1DE505)
308 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
309 return 0;
312 wh = (WINHELP*)cds->lpData;
314 if (wh)
316 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
318 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
319 wh->size, wh->command, wh->data, ptr);
320 switch (wh->command)
322 case HELP_CONTEXT:
323 if (ptr)
325 MACRO_JumpContext(ptr, "main", wh->data);
327 break;
328 case HELP_QUIT:
329 MACRO_Exit();
330 break;
331 case HELP_CONTENTS:
332 if (ptr)
334 MACRO_JumpContents(ptr, "main");
336 break;
337 case HELP_HELPONHELP:
338 MACRO_HelpOn();
339 break;
340 /* case HELP_SETINDEX: */
341 case HELP_SETCONTENTS:
342 if (ptr)
344 MACRO_SetContents(ptr, wh->data);
346 break;
347 case HELP_CONTEXTPOPUP:
348 if (ptr)
350 MACRO_PopupContext(ptr, wh->data);
352 break;
353 /* case HELP_FORCEFILE:*/
354 /* case HELP_CONTEXTMENU: */
355 case HELP_FINDER:
356 /* in fact, should be the topic dialog box */
357 if (ptr)
359 MACRO_JumpHash(ptr, "main", 0);
361 break;
362 /* case HELP_WM_HELP: */
363 /* case HELP_SETPOPUP_POS: */
364 /* case HELP_KEY: */
365 /* case HELP_COMMAND: */
366 /* case HELP_PARTIALKEY: */
367 /* case HELP_MULTIKEY: */
368 /* case HELP_SETWINPOS: */
369 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
370 break;
373 return 0L;
376 /******************************************************************
377 * WINHELP_ReuseWindow
381 static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
382 HLPFILE_PAGE* page, int nCmdShow)
384 unsigned int i;
386 win->hMainWnd = oldwin->hMainWnd;
387 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
388 win->hTextWnd = oldwin->hTextWnd;
389 win->hHistoryWnd = oldwin->hHistoryWnd;
390 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
392 SetWindowLong(win->hMainWnd, 0, (LONG)win);
393 SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
394 SetWindowLong(win->hTextWnd, 0, (LONG)win);
395 SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
397 WINHELP_InitFonts(win->hMainWnd);
399 if (page)
400 SetWindowText(win->hMainWnd, page->file->lpszTitle);
402 WINHELP_SetupText(win->hTextWnd);
403 InvalidateRect(win->hTextWnd, NULL, TRUE);
404 SendMessage(win->hMainWnd, WM_USER, 0, 0);
405 ShowWindow(win->hMainWnd, nCmdShow);
406 UpdateWindow(win->hTextWnd);
408 if (!(win->info->win_style & WS_POPUP))
410 unsigned num;
412 memcpy(win->history, oldwin->history, sizeof(win->history));
413 win->histIndex = oldwin->histIndex;
415 /* FIXME: when using back, we shouldn't update the history... */
417 if (page)
419 for (i = 0; i < win->histIndex; i++)
420 if (win->history[i] == page) break;
422 /* if the new page is already in the history, do nothing */
423 if (i == win->histIndex)
425 num = sizeof(win->history) / sizeof(win->history[0]);
426 if (win->histIndex == num)
428 /* we're full, remove latest entry */
429 HLPFILE_FreeHlpFile(win->history[0]->file);
430 memmove(&win->history[0], &win->history[1],
431 (num - 1) * sizeof(win->history[0]));
432 win->histIndex--;
434 win->history[win->histIndex++] = page;
435 page->file->wRefCount++;
436 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
440 memcpy(win->back, oldwin->back, sizeof(win->back));
441 win->backIndex = oldwin->backIndex;
443 if (page)
445 num = sizeof(win->back) / sizeof(win->back[0]);
446 if (win->backIndex == num)
448 /* we're full, remove latest entry */
449 HLPFILE_FreeHlpFile(win->back[0]->file);
450 memmove(&win->back[0], &win->back[1],
451 (num - 1) * sizeof(win->back[0]));
452 win->backIndex--;
454 win->back[win->backIndex++] = page;
455 page->file->wRefCount++;
458 else
459 win->backIndex = win->histIndex = 0;
461 oldwin->histIndex = oldwin->backIndex = 0;
462 WINHELP_DeleteWindow(oldwin);
463 return TRUE;
466 /***********************************************************************
468 * WINHELP_CreateHelpWindow
470 BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
471 int nCmdShow)
473 WINHELP_WINDOW *win, *oldwin;
474 HWND hWnd;
475 BOOL bPrimary;
476 BOOL bPopup;
478 bPrimary = !lstrcmpi(wi->name, "main");
479 bPopup = wi->win_style & WS_POPUP;
481 /* Initialize WINHELP_WINDOW struct */
482 win = HeapAlloc(GetProcessHeap(), 0,
483 sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
484 if (!win) return FALSE;
486 win->next = Globals.win_list;
487 Globals.win_list = win;
489 win->lpszName = (char*)win + sizeof(WINHELP_WINDOW);
490 lstrcpy((char*)win->lpszName, wi->name);
492 win->page = page;
493 win->first_button = 0;
494 win->first_line = 0;
495 win->hMainWnd = 0;
496 win->hButtonBoxWnd = 0;
497 win->hTextWnd = 0;
498 win->hShadowWnd = 0;
499 win->hHistoryWnd = 0;
501 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
502 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
504 win->info = wi;
506 Globals.active_win = win;
508 /* Initialize default pushbuttons */
509 if (bPrimary && page)
511 CHAR buffer[MAX_STRING_LEN];
513 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
514 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
515 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
516 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
517 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
518 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
519 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
520 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
521 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
522 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
525 /* Initialize file specific pushbuttons */
526 if (!(wi->win_style & WS_POPUP) && page)
528 HLPFILE_MACRO *macro;
529 for (macro = page->file->first_macro; macro; macro = macro->next)
530 MACRO_ExecuteMacro(macro->lpszMacro);
532 for (macro = page->first_macro; macro; macro = macro->next)
533 MACRO_ExecuteMacro(macro->lpszMacro);
536 win->histIndex = win->backIndex = 0;
537 /* Reuse existing window */
538 if (!bPopup)
540 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
542 if (!lstrcmpi(oldwin->lpszName, wi->name))
544 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
547 if (page)
549 win->histIndex = win->backIndex = 1;
550 win->history[0] = win->back[0] = page;
551 page->file->wRefCount += 2;
552 strcpy(wi->caption, page->file->lpszTitle);
556 hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
557 wi->caption,
558 bPrimary ? WS_OVERLAPPEDWINDOW : wi->win_style,
559 wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
560 NULL, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
561 Globals.hInstance, win);
563 ShowWindow(hWnd, nCmdShow);
564 UpdateWindow(hWnd);
566 return TRUE;
569 /***********************************************************************
571 * WINHELP_CreateHelpWindowByHash
573 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
574 HLPFILE_WINDOWINFO* wi, int nCmdShow)
576 HLPFILE_PAGE* page = NULL;
578 if (hlpfile)
579 page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
580 HLPFILE_Contents(hlpfile);
581 if (page) page->file->wRefCount++;
582 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
585 /***********************************************************************
587 * WINHELP_MainWndProc
589 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
591 WINHELP_WINDOW *win;
592 WINHELP_BUTTON *button;
593 RECT rect, button_box_rect;
594 INT text_top, curPos, min, max, dy, keyDelta;
596 WINHELP_CheckPopup(msg);
598 switch (msg)
600 case WM_NCCREATE:
601 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
602 SetWindowLong(hWnd, 0, (LONG) win);
603 win->hMainWnd = hWnd;
604 break;
606 case WM_CREATE:
607 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
609 /* Create button box and text Window */
610 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
611 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
613 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
614 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
616 /* Fall through */
617 case WM_USER:
618 case WM_WINDOWPOSCHANGED:
619 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
620 GetClientRect(hWnd, &rect);
622 /* Update button box and text Window */
623 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
624 rect.left, rect.top,
625 rect.right - rect.left,
626 rect.bottom - rect.top, 0);
628 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
629 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
631 SetWindowPos(win->hTextWnd, HWND_TOP,
632 rect.left, text_top,
633 rect.right - rect.left,
634 rect.bottom - text_top, 0);
636 break;
638 case WM_COMMAND:
639 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
640 switch (wParam)
642 /* Menu FILE */
643 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
644 case MNID_FILE_PRINT: MACRO_Print(); break;
645 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
646 case MNID_FILE_EXIT: MACRO_Exit(); break;
648 /* Menu EDIT */
649 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
650 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
652 /* Menu Bookmark */
653 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
655 /* Menu Help */
656 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
657 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
658 case MNID_HELP_ABOUT: MACRO_About(); break;
659 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
661 default:
662 /* Buttons */
663 for (button = win->first_button; button; button = button->next)
664 if (wParam == button->wParam) break;
665 if (button)
666 MACRO_ExecuteMacro(button->lpszMacro);
667 else
668 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
669 break;
671 break;
672 case WM_DESTROY:
673 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
674 break;
675 case WM_COPYDATA:
676 return WINHELP_HandleCommand((HWND)wParam, lParam);
678 case WM_KEYDOWN:
679 keyDelta = 0;
681 switch (wParam)
683 case VK_UP:
684 case VK_DOWN:
685 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
686 if (wParam == VK_UP)
687 keyDelta = -keyDelta;
689 case VK_PRIOR:
690 case VK_NEXT:
691 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
692 curPos = GetScrollPos(win->hTextWnd, SB_VERT);
693 GetScrollRange(win->hTextWnd, SB_VERT, &min, &max);
695 if (keyDelta == 0)
697 GetClientRect(win->hTextWnd, &rect);
698 keyDelta = (rect.bottom - rect.top) / 2;
699 if (wParam == VK_PRIOR)
700 keyDelta = -keyDelta;
703 curPos += keyDelta;
704 if (curPos > max)
705 curPos = max;
706 else if (curPos < min)
707 curPos = min;
709 dy = GetScrollPos(win->hTextWnd, SB_VERT) - curPos;
710 SetScrollPos(win->hTextWnd, SB_VERT, curPos, TRUE);
711 ScrollWindow(win->hTextWnd, 0, dy, NULL, NULL);
712 UpdateWindow(win->hTextWnd);
713 return 0;
715 case VK_ESCAPE:
716 MACRO_Exit();
717 return 0;
719 break;
721 return DefWindowProc(hWnd, msg, wParam, lParam);
724 /***********************************************************************
726 * WINHELP_ButtonBoxWndProc
728 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
730 WINDOWPOS *winpos;
731 WINHELP_WINDOW *win;
732 WINHELP_BUTTON *button;
733 SIZE button_size;
734 INT x, y;
736 WINHELP_CheckPopup(msg);
738 switch (msg)
740 case WM_NCCREATE:
741 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
742 SetWindowLong(hWnd, 0, (LONG) win);
743 win->hButtonBoxWnd = hWnd;
744 break;
746 case WM_WINDOWPOSCHANGING:
747 winpos = (WINDOWPOS*) lParam;
748 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
750 /* Update buttons */
751 button_size.cx = 0;
752 button_size.cy = 0;
753 for (button = win->first_button; button; button = button->next)
755 HDC hDc;
756 SIZE textsize;
757 if (!button->hWnd)
759 button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
760 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
761 0, 0, 0, 0,
762 hWnd, (HMENU) button->wParam,
763 Globals.hInstance, 0);
764 if (button->hWnd) {
765 if (Globals.button_proc == NULL)
766 Globals.button_proc = (WNDPROC) GetWindowLong(button->hWnd, GWL_WNDPROC);
767 SetWindowLong(button->hWnd, GWL_WNDPROC, (LONG) WINHELP_ButtonWndProc);
770 hDc = GetDC(button->hWnd);
771 GetTextExtentPoint(hDc, button->lpszName,
772 lstrlen(button->lpszName), &textsize);
773 ReleaseDC(button->hWnd, hDc);
775 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
776 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
779 x = 0;
780 y = 0;
781 for (button = win->first_button; button; button = button->next)
783 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
785 if (x + 2 * button_size.cx <= winpos->cx)
786 x += button_size.cx;
787 else
788 x = 0, y += button_size.cy;
790 winpos->cy = y + (x ? button_size.cy : 0);
791 break;
793 case WM_COMMAND:
794 SendMessage(GetParent(hWnd), msg, wParam, lParam);
795 break;
797 case WM_KEYDOWN:
798 switch (wParam)
800 case VK_UP:
801 case VK_DOWN:
802 case VK_PRIOR:
803 case VK_NEXT:
804 case VK_ESCAPE:
805 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
807 break;
810 return DefWindowProc(hWnd, msg, wParam, lParam);
813 /***********************************************************************
815 * WINHELP_ButtonWndProc
817 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
819 if (msg == WM_KEYDOWN)
821 switch (wParam)
823 case VK_UP:
824 case VK_DOWN:
825 case VK_PRIOR:
826 case VK_NEXT:
827 case VK_ESCAPE:
828 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
832 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
835 /***********************************************************************
837 * WINHELP_TextWndProc
839 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
841 WINHELP_WINDOW *win;
842 WINHELP_LINE *line;
843 WINHELP_LINE_PART *part;
844 WINDOWPOS *winpos;
845 PAINTSTRUCT ps;
846 HDC hDc;
847 POINT mouse;
848 INT scroll_pos;
849 HWND hPopupWnd;
850 BOOL bExit;
852 if (msg != WM_LBUTTONDOWN)
853 WINHELP_CheckPopup(msg);
855 switch (msg)
857 case WM_NCCREATE:
858 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
859 SetWindowLong(hWnd, 0, (LONG) win);
860 win->hTextWnd = hWnd;
861 if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
862 WINHELP_InitFonts(hWnd);
863 break;
865 case WM_CREATE:
866 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
868 /* Calculate vertical size and position of a popup window */
869 if (win->info->win_style & WS_POPUP)
871 POINT origin;
872 RECT old_window_rect;
873 RECT old_client_rect;
874 SIZE old_window_size;
875 SIZE old_client_size;
876 SIZE new_client_size;
877 SIZE new_window_size;
879 GetWindowRect(hWnd, &old_window_rect);
880 origin.x = old_window_rect.left;
881 origin.y = old_window_rect.top;
882 old_window_size.cx = old_window_rect.right - old_window_rect.left;
883 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
885 GetClientRect(hWnd, &old_client_rect);
886 old_client_size.cx = old_client_rect.right - old_client_rect.left;
887 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
889 new_client_size = old_client_size;
890 WINHELP_SplitLines(hWnd, &new_client_size);
892 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
893 origin.y += POPUP_YDISTANCE;
894 else
895 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
897 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
898 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
900 win->hShadowWnd =
901 CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
902 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
903 new_window_size.cx, new_window_size.cy,
904 0, 0, Globals.hInstance, 0);
906 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
907 new_window_size.cx, new_window_size.cy,
909 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
910 ShowWindow(win->hShadowWnd, SW_NORMAL);
911 SetActiveWindow(hWnd);
913 break;
915 case WM_WINDOWPOSCHANGED:
916 winpos = (WINDOWPOS*) lParam;
918 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
919 break;
921 case WM_MOUSEWHEEL:
923 int wheelDelta = 0;
924 UINT scrollLines = 3;
925 int curPos = GetScrollPos(hWnd, SB_VERT);
926 int min, max;
928 GetScrollRange(hWnd, SB_VERT, &min, &max);
930 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
931 if (wParam & (MK_SHIFT | MK_CONTROL))
932 return DefWindowProc(hWnd, msg, wParam, lParam);
933 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
934 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
935 int dy;
937 curPos += wheelDelta;
938 if (curPos > max)
939 curPos = max;
940 else if (curPos < min)
941 curPos = min;
943 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
944 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
945 ScrollWindow(hWnd, 0, dy, NULL, NULL);
946 UpdateWindow(hWnd);
949 break;
951 case WM_VSCROLL:
953 BOOL update = TRUE;
954 RECT rect;
955 INT Min, Max;
956 INT CurPos = GetScrollPos(hWnd, SB_VERT);
957 INT dy;
959 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
960 GetClientRect(hWnd, &rect);
962 switch (wParam & 0xffff)
964 case SB_THUMBTRACK:
965 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
966 case SB_TOP: CurPos = Min; break;
967 case SB_BOTTOM: CurPos = Max; break;
968 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
969 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
970 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
971 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
972 default: update = FALSE;
974 if (update)
976 if (CurPos > Max)
977 CurPos = Max;
978 else if (CurPos < Min)
979 CurPos = Min;
980 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
981 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
982 ScrollWindow(hWnd, 0, dy, NULL, NULL);
983 UpdateWindow(hWnd);
986 break;
988 case WM_PAINT:
989 hDc = BeginPaint(hWnd, &ps);
990 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
991 scroll_pos = GetScrollPos(hWnd, SB_VERT);
993 for (line = win->first_line; line; line = line->next)
995 for (part = &line->first_part; part; part = part->next)
997 switch (part->cookie)
999 case hlp_line_part_text:
1000 SelectObject(hDc, part->u.text.hFont);
1001 SetTextColor(hDc, part->u.text.color);
1002 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
1003 part->u.text.lpsText, part->u.text.wTextLen);
1004 if (part->u.text.wUnderline)
1006 HPEN hPen;
1008 switch (part->u.text.wUnderline)
1010 case 1: /* simple */
1011 case 2: /* double */
1012 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
1013 break;
1014 case 3: /* dotted */
1015 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
1016 break;
1017 default:
1018 WINE_FIXME("Unknow underline type\n");
1019 continue;
1022 SelectObject(hDc, hPen);
1023 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
1024 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
1025 if (part->u.text.wUnderline == 2)
1027 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
1028 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
1030 DeleteObject(hPen);
1032 break;
1033 case hlp_line_part_bitmap:
1035 HDC hMemDC;
1037 hMemDC = CreateCompatibleDC(hDc);
1038 SelectObject(hMemDC, part->u.bitmap.hBitmap);
1039 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1040 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
1041 hMemDC, 0, 0, SRCCOPY);
1042 DeleteDC(hMemDC);
1044 break;
1045 case hlp_line_part_metafile:
1047 POINT pt;
1049 SetViewportOrgEx(hDc, part->rect.left, part->rect.top - scroll_pos, &pt);
1050 PlayMetaFile(hDc, part->u.metafile.hMetaFile);
1051 SetViewportOrgEx(hDc, pt.x, pt.y, NULL);
1053 break;
1058 EndPaint(hWnd, &ps);
1059 break;
1061 case WM_MOUSEMOVE:
1062 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1064 if (WINHELP_IsOverLink(win, wParam, lParam))
1065 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
1066 else
1067 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
1069 break;
1071 case WM_LBUTTONDOWN:
1072 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1074 hPopupWnd = Globals.hPopupWnd;
1075 Globals.hPopupWnd = 0;
1077 part = WINHELP_IsOverLink(win, wParam, lParam);
1078 if (part)
1080 HLPFILE* hlpfile;
1081 HLPFILE_WINDOWINFO* wi;
1083 mouse.x = LOWORD(lParam);
1084 mouse.y = HIWORD(lParam);
1086 if (part->link) switch (part->link->cookie)
1088 case hlp_link_link:
1089 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1090 if (part->link->window == -1)
1091 wi = win->info;
1092 else if ((part->link->window >= 0) && (part->link->window < hlpfile->numWindows))
1093 wi = &hlpfile->windows[part->link->window];
1094 else
1096 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
1097 break;
1099 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
1100 SW_NORMAL);
1101 break;
1102 case hlp_link_popup:
1103 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1104 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
1105 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
1106 SW_NORMAL);
1107 break;
1108 case hlp_link_macro:
1109 MACRO_ExecuteMacro(part->link->lpszString);
1110 break;
1111 default:
1112 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1116 if (hPopupWnd)
1117 DestroyWindow(hPopupWnd);
1118 break;
1120 case WM_NCDESTROY:
1121 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1123 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
1125 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1127 WINHELP_DeleteWindow(win);
1129 if (bExit) MACRO_Exit();
1131 if (!Globals.win_list)
1132 PostQuitMessage(0);
1133 break;
1136 return DefWindowProc(hWnd, msg, wParam, lParam);
1139 /******************************************************************
1140 * WINHELP_HistoryWndProc
1144 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1146 WINHELP_WINDOW* win;
1147 PAINTSTRUCT ps;
1148 HDC hDc;
1149 TEXTMETRIC tm;
1150 unsigned int i;
1151 RECT r;
1153 switch (msg)
1155 case WM_NCCREATE:
1156 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1157 SetWindowLong(hWnd, 0, (LONG)win);
1158 win->hHistoryWnd = hWnd;
1159 break;
1160 case WM_CREATE:
1161 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1162 hDc = GetDC(hWnd);
1163 GetTextMetrics(hDc, &tm);
1164 GetWindowRect(hWnd, &r);
1166 r.right = r.left + 30 * tm.tmAveCharWidth;
1167 r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
1168 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1169 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1170 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1172 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1173 ReleaseDC(hWnd, hDc);
1174 break;
1175 case WM_LBUTTONDOWN:
1176 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1177 hDc = GetDC(hWnd);
1178 GetTextMetrics(hDc, &tm);
1179 i = HIWORD(lParam) / tm.tmHeight;
1180 if (i < win->histIndex)
1181 WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
1182 ReleaseDC(hWnd, hDc);
1183 break;
1184 case WM_PAINT:
1185 hDc = BeginPaint(hWnd, &ps);
1186 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1187 GetTextMetrics(hDc, &tm);
1189 for (i = 0; i < win->histIndex; i++)
1191 TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle,
1192 strlen(win->history[i]->lpszTitle));
1194 EndPaint(hWnd, &ps);
1195 break;
1196 case WM_DESTROY:
1197 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1198 if (hWnd == win->hHistoryWnd)
1199 win->hHistoryWnd = 0;
1200 break;
1202 return DefWindowProc(hWnd, msg, wParam, lParam);
1205 /***********************************************************************
1207 * WINHELP_ShadowWndProc
1209 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1211 WINHELP_CheckPopup(msg);
1212 return DefWindowProc(hWnd, msg, wParam, lParam);
1215 /***********************************************************************
1217 * SetupText
1219 static void WINHELP_SetupText(HWND hWnd)
1221 HDC hDc = GetDC(hWnd);
1222 RECT rect;
1223 SIZE newsize;
1225 ShowScrollBar(hWnd, SB_VERT, FALSE);
1226 if (!WINHELP_SplitLines(hWnd, NULL))
1228 ShowScrollBar(hWnd, SB_VERT, TRUE);
1229 GetClientRect(hWnd, &rect);
1231 WINHELP_SplitLines(hWnd, &newsize);
1232 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1234 else
1236 SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1237 SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
1240 ReleaseDC(hWnd, hDc);
1243 /***********************************************************************
1245 * WINHELP_AppendText
1247 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1248 LPSIZE space, LPSIZE textsize,
1249 INT *line_ascent, INT ascent,
1250 LPCSTR text, UINT textlen,
1251 HFONT font, COLORREF color, HLPFILE_LINK *link,
1252 unsigned underline)
1254 WINHELP_LINE *line;
1255 WINHELP_LINE_PART *part;
1256 LPSTR ptr;
1258 if (!*partp) /* New line */
1260 *line_ascent = ascent;
1262 line = HeapAlloc(GetProcessHeap(), 0,
1263 sizeof(WINHELP_LINE) + textlen);
1264 if (!line) return FALSE;
1266 line->next = 0;
1267 part = &line->first_part;
1268 ptr = (char*)line + sizeof(WINHELP_LINE);
1270 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1271 line->rect.bottom = line->rect.top;
1272 line->rect.left = space->cx;
1273 line->rect.right = space->cx;
1275 if (**linep) *linep = &(**linep)->next;
1276 **linep = line;
1277 space->cy = 0;
1279 else /* Same line */
1281 line = **linep;
1283 if (*line_ascent < ascent)
1285 WINHELP_LINE_PART *p;
1286 for (p = &line->first_part; p; p = p->next)
1288 p->rect.top += ascent - *line_ascent;
1289 p->rect.bottom += ascent - *line_ascent;
1291 line->rect.bottom += ascent - *line_ascent;
1292 *line_ascent = ascent;
1295 part = HeapAlloc(GetProcessHeap(), 0,
1296 sizeof(WINHELP_LINE_PART) + textlen);
1297 if (!part) return FALSE;
1298 **partp = part;
1299 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1302 memcpy(ptr, text, textlen);
1303 part->cookie = hlp_line_part_text;
1304 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1305 part->rect.right = part->rect.left + textsize->cx;
1306 line->rect.right = part->rect.right;
1307 part->rect.top =
1308 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1309 part->rect.bottom = part->rect.top + textsize->cy;
1310 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1311 part->u.text.lpsText = ptr;
1312 part->u.text.wTextLen = textlen;
1313 part->u.text.hFont = font;
1314 part->u.text.color = color;
1315 part->u.text.wUnderline = underline;
1317 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1318 part->u.text.wTextLen,
1319 part->u.text.wTextLen,
1320 part->u.text.lpsText,
1321 part->u.text.wTextLen,
1322 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1324 part->link = link;
1325 if (link) link->wRefCount++;
1327 part->next = 0;
1328 *partp = &part->next;
1330 space->cx = 0;
1332 return TRUE;
1335 /***********************************************************************
1337 * WINHELP_AppendGfxObject
1339 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1340 LPSIZE space, LPSIZE gfxSize,
1341 HLPFILE_LINK *link, unsigned pos)
1343 WINHELP_LINE *line;
1344 WINHELP_LINE_PART *part;
1345 LPSTR ptr;
1347 if (!*partp || pos == 1) /* New line */
1349 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1350 if (!line) return NULL;
1352 line->next = NULL;
1353 part = &line->first_part;
1355 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1356 line->rect.bottom = line->rect.top;
1357 line->rect.left = space->cx;
1358 line->rect.right = space->cx;
1360 if (**linep) *linep = &(**linep)->next;
1361 **linep = line;
1362 space->cy = 0;
1363 ptr = (char*)line + sizeof(WINHELP_LINE);
1365 else /* Same line */
1367 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1368 line = **linep;
1370 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1371 if (!part) return NULL;
1372 **partp = part;
1373 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1376 /* part->cookie should be set by caller (image or metafile) */
1377 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1378 part->rect.right = part->rect.left + gfxSize->cx;
1379 line->rect.right = part->rect.right;
1380 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1381 part->rect.bottom = part->rect.top + gfxSize->cy;
1382 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1384 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1385 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1387 part->link = link;
1388 if (link) link->wRefCount++;
1390 part->next = NULL;
1391 *partp = &part->next;
1393 space->cx = 0;
1395 return part;
1399 /***********************************************************************
1401 * WINHELP_SplitLines
1403 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1405 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1406 HLPFILE_PARAGRAPH *p;
1407 WINHELP_LINE **line = &win->first_line;
1408 WINHELP_LINE_PART **part = 0;
1409 INT line_ascent = 0;
1410 SIZE space;
1411 RECT rect;
1412 HDC hDc;
1414 if (newsize) newsize->cx = newsize->cy = 0;
1416 if (!win->page) return TRUE;
1418 WINHELP_DeleteLines(win);
1420 GetClientRect(hWnd, &rect);
1422 rect.top += INTERNAL_BORDER_WIDTH;
1423 rect.left += INTERNAL_BORDER_WIDTH;
1424 rect.right -= INTERNAL_BORDER_WIDTH;
1425 rect.bottom -= INTERNAL_BORDER_WIDTH;
1427 space.cy = rect.top;
1428 space.cx = rect.left;
1430 hDc = GetDC(hWnd);
1432 for (p = win->page->first_paragraph; p; p = p->next)
1434 switch (p->cookie)
1436 case para_normal_text:
1437 case para_debug_text:
1439 TEXTMETRIC tm;
1440 SIZE textsize = {0, 0};
1441 LPCSTR text = p->u.text.lpszText;
1442 UINT indent = 0;
1443 UINT len = strlen(text);
1444 unsigned underline = 0;
1446 HFONT hFont = 0;
1447 COLORREF color = RGB(0, 0, 0);
1449 if (p->u.text.wFont < win->page->file->numFonts)
1451 HLPFILE* hlpfile = win->page->file;
1453 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1454 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1455 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1456 color = hlpfile->fonts[p->u.text.wFont].color;
1458 else
1460 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1462 hFont = win->fonts[wFont];
1465 if (p->link && p->link->bClrChange)
1467 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1468 color = RGB(0, 0x80, 0);
1470 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1472 SelectObject(hDc, hFont);
1474 GetTextMetrics(hDc, &tm);
1476 if (p->u.text.wIndent)
1478 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1479 if (!part)
1480 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1483 if (p->u.text.wVSpace)
1485 part = 0;
1486 space.cx = rect.left + indent;
1487 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1490 if (p->u.text.wHSpace)
1492 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1495 WINE_TRACE("splitting text %s\n", text);
1497 while (len)
1499 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1500 UINT low = 0, curr = len, high = len, textlen = 0;
1502 if (free_width > 0)
1504 while (1)
1506 GetTextExtentPoint(hDc, text, curr, &textsize);
1508 if (textsize.cx <= free_width) low = curr;
1509 else high = curr;
1511 if (high <= low + 1) break;
1513 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1514 if (curr <= low) curr = low + 1;
1515 else if (curr >= high) curr = high - 1;
1517 textlen = low;
1518 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1520 if (!part && !textlen) textlen = max(low, 1);
1522 if (free_width <= 0 || !textlen)
1524 part = 0;
1525 space.cx = rect.left + indent;
1526 space.cx = min(space.cx, rect.right - rect.left - 1);
1527 continue;
1530 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1532 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1533 &line_ascent, tm.tmAscent,
1534 text, textlen, hFont, color, p->link, underline) ||
1535 (!newsize && (*line)->rect.bottom > rect.bottom))
1537 ReleaseDC(hWnd, hDc);
1538 return FALSE;
1541 if (newsize)
1542 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1544 len -= textlen;
1545 text += textlen;
1546 if (text[0] == ' ') text++, len--;
1549 break;
1550 case para_bitmap:
1551 case para_metafile:
1553 SIZE gfxSize;
1554 INT free_width;
1555 WINHELP_LINE_PART* ref_part;
1557 if (p->u.gfx.pos & 0x8000)
1559 space.cx = rect.left;
1560 if (*line)
1561 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1562 part = 0;
1565 if (p->cookie == para_bitmap)
1567 DIBSECTION dibs;
1569 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1570 gfxSize.cx = dibs.dsBm.bmWidth;
1571 gfxSize.cy = dibs.dsBm.bmHeight;
1573 else gfxSize = p->u.gfx.u.mf.mfSize;
1575 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1576 if (free_width <= 0)
1578 part = NULL;
1579 space.cx = rect.left;
1580 space.cx = min(space.cx, rect.right - rect.left - 1);
1582 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1583 p->link, p->u.gfx.pos);
1584 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1586 return FALSE;
1588 if (p->cookie == para_bitmap)
1590 ref_part->cookie = hlp_line_part_bitmap;
1591 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1593 else
1595 ref_part->cookie = hlp_line_part_metafile;
1596 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mf.hMetaFile;
1599 break;
1603 if (newsize)
1604 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1606 ReleaseDC(hWnd, hDc);
1607 return TRUE;
1610 /***********************************************************************
1612 * WINHELP_CheckPopup
1614 static void WINHELP_CheckPopup(UINT msg)
1616 if (!Globals.hPopupWnd) return;
1618 switch (msg)
1620 case WM_COMMAND:
1621 case WM_LBUTTONDOWN:
1622 case WM_MBUTTONDOWN:
1623 case WM_RBUTTONDOWN:
1624 case WM_NCLBUTTONDOWN:
1625 case WM_NCMBUTTONDOWN:
1626 case WM_NCRBUTTONDOWN:
1627 DestroyWindow(Globals.hPopupWnd);
1628 Globals.hPopupWnd = 0;
1632 /***********************************************************************
1634 * WINHELP_DeleteLines
1636 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1638 WINHELP_LINE *line, *next_line;
1639 WINHELP_LINE_PART *part, *next_part;
1640 for (line = win->first_line; line; line = next_line)
1642 next_line = line->next;
1643 for (part = &line->first_part; part; part = next_part)
1645 next_part = part->next;
1646 HLPFILE_FreeLink(part->link);
1647 HeapFree(GetProcessHeap(), 0, part);
1650 win->first_line = 0;
1653 /***********************************************************************
1655 * WINHELP_DeleteWindow
1657 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1659 WINHELP_WINDOW** w;
1660 unsigned int i;
1661 WINHELP_BUTTON* b;
1662 WINHELP_BUTTON* bp;
1664 for (w = &Globals.win_list; *w; w = &(*w)->next)
1666 if (*w == win)
1668 *w = win->next;
1669 break;
1673 for (b = win->first_button; b; b = bp)
1675 DestroyWindow(b->hWnd);
1676 bp = b->next;
1677 HeapFree(GetProcessHeap(), 0, b);
1680 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1681 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1683 for (i = 0; i < win->histIndex; i++)
1685 HLPFILE_FreeHlpFile(win->history[i]->file);
1688 for (i = 0; i < win->backIndex; i++)
1689 HLPFILE_FreeHlpFile(win->back[i]->file);
1691 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1692 WINHELP_DeleteLines(win);
1693 HeapFree(GetProcessHeap(), 0, win);
1696 /***********************************************************************
1698 * WINHELP_InitFonts
1700 static void WINHELP_InitFonts(HWND hWnd)
1702 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1703 LOGFONT logfontlist[] = {
1704 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1705 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1706 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1707 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1708 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1709 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1710 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1711 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1713 static HFONT fonts[FONTS_LEN];
1714 static BOOL init = 0;
1716 win->fonts_len = FONTS_LEN;
1717 win->fonts = fonts;
1719 if (!init)
1721 UINT i;
1723 for (i = 0; i < FONTS_LEN; i++)
1725 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1728 init = 1;
1732 /***********************************************************************
1734 * WINHELP_MessageBoxIDS
1736 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1738 CHAR text[MAX_STRING_LEN];
1739 CHAR title[MAX_STRING_LEN];
1741 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1742 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1744 return MessageBox(0, text, title, type);
1747 /***********************************************************************
1749 * MAIN_MessageBoxIDS_s
1751 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1753 CHAR text[MAX_STRING_LEN];
1754 CHAR title[MAX_STRING_LEN];
1755 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
1757 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1758 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1759 wsprintf(newtext, text, str);
1761 return MessageBox(0, newtext, title, type);
1764 /******************************************************************
1765 * WINHELP_IsOverLink
1769 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1771 POINT mouse;
1772 WINHELP_LINE *line;
1773 WINHELP_LINE_PART *part;
1774 int scroll_pos = GetScrollPos(win->hTextWnd, SB_VERT);
1776 mouse.x = LOWORD(lParam);
1777 mouse.y = HIWORD(lParam);
1778 for (line = win->first_line; line; line = line->next)
1780 for (part = &line->first_part; part; part = part->next)
1782 if (part->link &&
1783 part->link->lpszString &&
1784 part->rect.left <= mouse.x &&
1785 part->rect.right >= mouse.x &&
1786 part->rect.top <= mouse.y + scroll_pos &&
1787 part->rect.bottom >= mouse.y + scroll_pos)
1789 return part;
1794 return NULL;