- bNtfUnicode is a dup' of bUnicode so remove it and fix the few
[wine/testsucceed.git] / programs / winhelp / winhelp.c
blob6879b673cac4eca70e35496718c45aa3a7299825
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, 0, 0, 0, 1, 0, 0, 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 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;
169 Globals.hInstance = hInstance;
171 /* Get options */
172 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
174 CHAR option;
175 LPCSTR topic_id;
176 if (*cmdline++ == ' ') continue;
178 option = *cmdline;
179 if (option) cmdline++;
180 while (*cmdline && *cmdline == ' ') cmdline++;
181 switch (option)
183 case 'i':
184 case 'I':
185 topic_id = cmdline;
186 while (*cmdline && *cmdline != ' ') cmdline++;
187 if (*cmdline) *cmdline++ = '\0';
188 lHash = HLPFILE_Hash(topic_id);
189 break;
191 case '3':
192 case '4':
193 Globals.wVersion = option - '0';
194 break;
196 case 'x':
197 show = SW_HIDE;
198 Globals.isBook = FALSE;
199 break;
201 default:
202 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
203 break;
207 /* Create primary window */
208 WINHELP_RegisterWinClasses();
209 if (*cmdline)
211 if ((*cmdline == '"') && (quote = strchr(cmdline+1, '"')))
213 cmdline++;
214 *quote = '\0';
216 hlpfile = WINHELP_LookupHelpFile(cmdline);
217 if (!hlpfile) return 0;
219 else hlpfile = NULL;
220 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
221 WINHELP_GetWindowInfo(hlpfile, "main"), show);
223 /* Message loop */
224 while (GetMessage(&msg, 0, 0, 0))
226 TranslateMessage(&msg);
227 DispatchMessage(&msg);
229 return 0;
232 /***********************************************************************
234 * RegisterWinClasses
236 static BOOL WINHELP_RegisterWinClasses(void)
238 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
240 class_main.style = CS_HREDRAW | CS_VREDRAW;
241 class_main.lpfnWndProc = WINHELP_MainWndProc;
242 class_main.cbClsExtra = 0;
243 class_main.cbWndExtra = sizeof(LONG);
244 class_main.hInstance = Globals.hInstance;
245 class_main.hIcon = LoadIcon(0, IDI_APPLICATION);
246 class_main.hCursor = LoadCursor(0, IDC_ARROW);
247 class_main.hbrBackground = GetStockObject(WHITE_BRUSH);
248 class_main.lpszMenuName = 0;
249 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
251 class_button_box = class_main;
252 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
253 class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
254 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
256 class_text = class_main;
257 class_text.lpfnWndProc = WINHELP_TextWndProc;
258 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
260 class_shadow = class_main;
261 class_shadow.lpfnWndProc = WINHELP_ShadowWndProc;
262 class_shadow.hbrBackground = GetStockObject(GRAY_BRUSH);
263 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
265 class_history = class_main;
266 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
267 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
269 return (RegisterClass(&class_main) &&
270 RegisterClass(&class_button_box) &&
271 RegisterClass(&class_text) &&
272 RegisterClass(&class_shadow) &&
273 RegisterClass(&class_history));
276 typedef struct
278 WORD size;
279 WORD command;
280 LONG data;
281 LONG reserved;
282 WORD ofsFilename;
283 WORD ofsData;
284 } WINHELP,*LPWINHELP;
286 /******************************************************************
287 * WINHELP_HandleCommand
291 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
293 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
294 WINHELP* wh;
296 if (cds->dwData != 0xA1DE505)
298 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
299 return 0;
302 wh = (WINHELP*)cds->lpData;
304 if (wh)
306 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
308 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
309 wh->size, wh->command, wh->data, ptr);
310 switch (wh->command)
312 case HELP_CONTEXT:
313 if (ptr)
315 MACRO_JumpContext(ptr, "main", wh->data);
317 break;
318 case HELP_QUIT:
319 MACRO_Exit();
320 break;
321 case HELP_CONTENTS:
322 if (ptr)
324 MACRO_JumpContents(ptr, "main");
326 break;
327 case HELP_HELPONHELP:
328 MACRO_HelpOn();
329 break;
330 /* case HELP_SETINDEX: */
331 case HELP_SETCONTENTS:
332 if (ptr)
334 MACRO_SetContents(ptr, wh->data);
336 break;
337 case HELP_CONTEXTPOPUP:
338 if (ptr)
340 MACRO_PopupContext(ptr, wh->data);
342 break;
343 /* case HELP_FORCEFILE:*/
344 /* case HELP_CONTEXTMENU: */
345 case HELP_FINDER:
346 /* in fact, should be the topic dialog box */
347 if (ptr)
349 MACRO_JumpHash(ptr, "main", 0);
351 break;
352 /* case HELP_WM_HELP: */
353 /* case HELP_SETPOPUP_POS: */
354 /* case HELP_KEY: */
355 /* case HELP_COMMAND: */
356 /* case HELP_PARTIALKEY: */
357 /* case HELP_MULTIKEY: */
358 /* case HELP_SETWINPOS: */
359 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
360 break;
363 return 0L;
366 /******************************************************************
367 * WINHELP_ReuseWindow
371 static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
372 HLPFILE_PAGE* page, int nCmdShow)
374 unsigned int i;
376 win->hMainWnd = oldwin->hMainWnd;
377 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
378 win->hTextWnd = oldwin->hTextWnd;
379 win->hHistoryWnd = oldwin->hHistoryWnd;
380 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
382 SetWindowLong(win->hMainWnd, 0, (LONG)win);
383 SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
384 SetWindowLong(win->hTextWnd, 0, (LONG)win);
385 SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
387 WINHELP_InitFonts(win->hMainWnd);
389 if (page)
390 SetWindowText(win->hMainWnd, page->file->lpszTitle);
392 WINHELP_SetupText(win->hTextWnd);
393 InvalidateRect(win->hTextWnd, NULL, TRUE);
394 SendMessage(win->hMainWnd, WM_USER, 0, 0);
395 ShowWindow(win->hMainWnd, nCmdShow);
396 UpdateWindow(win->hTextWnd);
398 if (!(win->info->win_style & WS_POPUP))
400 unsigned num;
402 memcpy(win->history, oldwin->history, sizeof(win->history));
403 win->histIndex = oldwin->histIndex;
405 /* FIXME: when using back, we shouldn't update the history... */
407 if (page)
409 for (i = 0; i < win->histIndex; i++)
410 if (win->history[i] == page) break;
412 /* if the new page is already in the history, do nothing */
413 if (i == win->histIndex)
415 num = sizeof(win->history) / sizeof(win->history[0]);
416 if (win->histIndex == num)
418 /* we're full, remove latest entry */
419 HLPFILE_FreeHlpFile(win->history[0]->file);
420 memmove(&win->history[0], &win->history[1],
421 (num - 1) * sizeof(win->history[0]));
422 win->histIndex--;
424 win->history[win->histIndex++] = page;
425 page->file->wRefCount++;
426 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
430 memcpy(win->back, oldwin->back, sizeof(win->back));
431 win->backIndex = oldwin->backIndex;
433 if (page)
435 num = sizeof(win->back) / sizeof(win->back[0]);
436 if (win->backIndex == num)
438 /* we're full, remove latest entry */
439 HLPFILE_FreeHlpFile(win->back[0]->file);
440 memmove(&win->back[0], &win->back[1],
441 (num - 1) * sizeof(win->back[0]));
442 win->backIndex--;
444 win->back[win->backIndex++] = page;
445 page->file->wRefCount++;
448 else
449 win->backIndex = win->histIndex = 0;
451 oldwin->histIndex = oldwin->backIndex = 0;
452 WINHELP_DeleteWindow(oldwin);
453 return TRUE;
456 /***********************************************************************
458 * WINHELP_CreateHelpWindow
460 BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
461 int nCmdShow)
463 WINHELP_WINDOW *win, *oldwin;
464 HWND hWnd;
465 BOOL bPrimary;
466 BOOL bPopup;
468 bPrimary = !lstrcmpi(wi->name, "main");
469 bPopup = wi->win_style & WS_POPUP;
471 /* Initialize WINHELP_WINDOW struct */
472 win = HeapAlloc(GetProcessHeap(), 0,
473 sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
474 if (!win) return FALSE;
476 win->next = Globals.win_list;
477 Globals.win_list = win;
479 win->lpszName = (char*)win + sizeof(WINHELP_WINDOW);
480 lstrcpy((char*)win->lpszName, wi->name);
482 win->page = page;
483 win->first_button = 0;
484 win->first_line = 0;
485 win->hMainWnd = 0;
486 win->hButtonBoxWnd = 0;
487 win->hTextWnd = 0;
488 win->hShadowWnd = 0;
489 win->hHistoryWnd = 0;
491 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
492 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
494 win->info = wi;
496 Globals.active_win = win;
498 /* Initialize default pushbuttons */
499 if (bPrimary && page)
501 CHAR buffer[MAX_STRING_LEN];
503 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
504 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
505 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
506 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
507 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
508 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
509 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
510 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
511 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
512 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
515 /* Initialize file specific pushbuttons */
516 if (!(wi->win_style & WS_POPUP) && page)
518 HLPFILE_MACRO *macro;
519 for (macro = page->file->first_macro; macro; macro = macro->next)
520 MACRO_ExecuteMacro(macro->lpszMacro);
522 for (macro = page->first_macro; macro; macro = macro->next)
523 MACRO_ExecuteMacro(macro->lpszMacro);
526 win->histIndex = win->backIndex = 0;
527 /* Reuse existing window */
528 if (!bPopup)
530 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
532 if (!lstrcmpi(oldwin->lpszName, wi->name))
534 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
537 if (page)
539 win->histIndex = win->backIndex = 1;
540 win->history[0] = win->back[0] = page;
541 page->file->wRefCount += 2;
542 strcpy(wi->caption, page->file->lpszTitle);
546 hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
547 wi->caption, wi->win_style,
548 wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
549 0, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
550 Globals.hInstance, win);
552 ShowWindow(hWnd, nCmdShow);
553 UpdateWindow(hWnd);
555 return TRUE;
558 /***********************************************************************
560 * WINHELP_CreateHelpWindowByHash
562 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
563 HLPFILE_WINDOWINFO* wi, int nCmdShow)
565 HLPFILE_PAGE* page = NULL;
567 if (hlpfile)
568 page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
569 HLPFILE_Contents(hlpfile);
570 if (page) page->file->wRefCount++;
571 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
574 /***********************************************************************
576 * WINHELP_MainWndProc
578 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
580 WINHELP_WINDOW *win;
581 WINHELP_BUTTON *button;
582 RECT rect, button_box_rect;
583 INT text_top, curPos, min, max, dy, keyDelta;
585 WINHELP_CheckPopup(msg);
587 switch (msg)
589 case WM_NCCREATE:
590 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
591 SetWindowLong(hWnd, 0, (LONG) win);
592 win->hMainWnd = hWnd;
593 break;
595 case WM_CREATE:
596 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
598 /* Create button box and text Window */
599 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
600 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
602 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
603 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
605 /* Fall through */
606 case WM_USER:
607 case WM_WINDOWPOSCHANGED:
608 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
609 GetClientRect(hWnd, &rect);
611 /* Update button box and text Window */
612 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
613 rect.left, rect.top,
614 rect.right - rect.left,
615 rect.bottom - rect.top, 0);
617 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
618 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
620 SetWindowPos(win->hTextWnd, HWND_TOP,
621 rect.left, text_top,
622 rect.right - rect.left,
623 rect.bottom - text_top, 0);
625 break;
627 case WM_COMMAND:
628 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
629 switch (wParam)
631 /* Menu FILE */
632 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
633 case MNID_FILE_PRINT: MACRO_Print(); break;
634 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
635 case MNID_FILE_EXIT: MACRO_Exit(); break;
637 /* Menu EDIT */
638 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
639 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
641 /* Menu Bookmark */
642 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
644 /* Menu Help */
645 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
646 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
647 case MNID_HELP_ABOUT: MACRO_About(); break;
648 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
650 default:
651 /* Buttons */
652 for (button = win->first_button; button; button = button->next)
653 if (wParam == button->wParam) break;
654 if (button)
655 MACRO_ExecuteMacro(button->lpszMacro);
656 else
657 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
658 break;
660 break;
661 case WM_DESTROY:
662 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
663 break;
664 case WM_COPYDATA:
665 return WINHELP_HandleCommand((HWND)wParam, lParam);
667 case WM_KEYDOWN:
668 keyDelta = 0;
670 switch (wParam)
672 case VK_UP:
673 case VK_DOWN:
674 keyDelta = GetSystemMetrics(SM_CXVSCROLL);
675 if (wParam == VK_UP)
676 keyDelta = -keyDelta;
678 case VK_PRIOR:
679 case VK_NEXT:
680 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
681 curPos = GetScrollPos(win->hTextWnd, SB_VERT);
682 GetScrollRange(win->hTextWnd, SB_VERT, &min, &max);
684 if (keyDelta == 0)
686 GetClientRect(win->hTextWnd, &rect);
687 keyDelta = (rect.bottom - rect.top) / 2;
688 if (wParam == VK_PRIOR)
689 keyDelta = -keyDelta;
692 curPos += keyDelta;
693 if (curPos > max)
694 curPos = max;
695 else if (curPos < min)
696 curPos = min;
698 dy = GetScrollPos(win->hTextWnd, SB_VERT) - curPos;
699 SetScrollPos(win->hTextWnd, SB_VERT, curPos, TRUE);
700 ScrollWindow(win->hTextWnd, 0, dy, NULL, NULL);
701 UpdateWindow(win->hTextWnd);
702 return 0;
704 case VK_ESCAPE:
705 MACRO_Exit();
706 return 0;
708 break;
710 return DefWindowProc(hWnd, msg, wParam, lParam);
713 /***********************************************************************
715 * WINHELP_ButtonBoxWndProc
717 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
719 WINDOWPOS *winpos;
720 WINHELP_WINDOW *win;
721 WINHELP_BUTTON *button;
722 SIZE button_size;
723 INT x, y;
725 WINHELP_CheckPopup(msg);
727 switch (msg)
729 case WM_NCCREATE:
730 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
731 SetWindowLong(hWnd, 0, (LONG) win);
732 win->hButtonBoxWnd = hWnd;
733 break;
735 case WM_WINDOWPOSCHANGING:
736 winpos = (WINDOWPOS*) lParam;
737 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
739 /* Update buttons */
740 button_size.cx = 0;
741 button_size.cy = 0;
742 for (button = win->first_button; button; button = button->next)
744 HDC hDc;
745 SIZE textsize;
746 if (!button->hWnd)
748 button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
749 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
750 0, 0, 0, 0,
751 hWnd, (HMENU) button->wParam,
752 Globals.hInstance, 0);
753 if (button->hWnd) {
754 if (Globals.button_proc == NULL)
755 Globals.button_proc = (WNDPROC) GetWindowLong(button->hWnd, GWL_WNDPROC);
756 SetWindowLong(button->hWnd, GWL_WNDPROC, (LONG) WINHELP_ButtonWndProc);
759 hDc = GetDC(button->hWnd);
760 GetTextExtentPoint(hDc, button->lpszName,
761 lstrlen(button->lpszName), &textsize);
762 ReleaseDC(button->hWnd, hDc);
764 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
765 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
768 x = 0;
769 y = 0;
770 for (button = win->first_button; button; button = button->next)
772 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
774 if (x + 2 * button_size.cx <= winpos->cx)
775 x += button_size.cx;
776 else
777 x = 0, y += button_size.cy;
779 winpos->cy = y + (x ? button_size.cy : 0);
780 break;
782 case WM_COMMAND:
783 SendMessage(GetParent(hWnd), msg, wParam, lParam);
784 break;
786 case WM_KEYDOWN:
787 switch (wParam)
789 case VK_UP:
790 case VK_DOWN:
791 case VK_PRIOR:
792 case VK_NEXT:
793 case VK_ESCAPE:
794 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
796 break;
799 return DefWindowProc(hWnd, msg, wParam, lParam);
802 /***********************************************************************
804 * WINHELP_ButtonWndProc
806 static LRESULT CALLBACK WINHELP_ButtonWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
808 if (msg == WM_KEYDOWN)
810 switch (wParam)
812 case VK_UP:
813 case VK_DOWN:
814 case VK_PRIOR:
815 case VK_NEXT:
816 case VK_ESCAPE:
817 return SendMessage(GetParent(hWnd), msg, wParam, lParam);
821 return CallWindowProc(Globals.button_proc, hWnd, msg, wParam, lParam);
824 /***********************************************************************
826 * WINHELP_TextWndProc
828 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
830 WINHELP_WINDOW *win;
831 WINHELP_LINE *line;
832 WINHELP_LINE_PART *part;
833 WINDOWPOS *winpos;
834 PAINTSTRUCT ps;
835 HDC hDc;
836 POINT mouse;
837 INT scroll_pos;
838 HWND hPopupWnd;
839 BOOL bExit;
841 if (msg != WM_LBUTTONDOWN)
842 WINHELP_CheckPopup(msg);
844 switch (msg)
846 case WM_NCCREATE:
847 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
848 SetWindowLong(hWnd, 0, (LONG) win);
849 win->hTextWnd = hWnd;
850 if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
851 WINHELP_InitFonts(hWnd);
852 break;
854 case WM_CREATE:
855 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
857 /* Calculate vertical size and position of a popup window */
858 if (win->info->win_style & WS_POPUP)
860 POINT origin;
861 RECT old_window_rect;
862 RECT old_client_rect;
863 SIZE old_window_size;
864 SIZE old_client_size;
865 SIZE new_client_size;
866 SIZE new_window_size;
868 GetWindowRect(hWnd, &old_window_rect);
869 origin.x = old_window_rect.left;
870 origin.y = old_window_rect.top;
871 old_window_size.cx = old_window_rect.right - old_window_rect.left;
872 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
874 GetClientRect(hWnd, &old_client_rect);
875 old_client_size.cx = old_client_rect.right - old_client_rect.left;
876 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
878 new_client_size = old_client_size;
879 WINHELP_SplitLines(hWnd, &new_client_size);
881 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
882 origin.y += POPUP_YDISTANCE;
883 else
884 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
886 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
887 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
889 win->hShadowWnd =
890 CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
891 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
892 new_window_size.cx, new_window_size.cy,
893 0, 0, Globals.hInstance, 0);
895 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
896 new_window_size.cx, new_window_size.cy,
898 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
899 ShowWindow(win->hShadowWnd, SW_NORMAL);
900 SetActiveWindow(hWnd);
902 break;
904 case WM_WINDOWPOSCHANGED:
905 winpos = (WINDOWPOS*) lParam;
907 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
908 break;
910 case WM_MOUSEWHEEL:
912 int wheelDelta = 0;
913 UINT scrollLines = 3;
914 int curPos = GetScrollPos(hWnd, SB_VERT);
915 int min, max;
917 GetScrollRange(hWnd, SB_VERT, &min, &max);
919 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
920 if (wParam & (MK_SHIFT | MK_CONTROL))
921 return DefWindowProc(hWnd, msg, wParam, lParam);
922 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
923 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
924 int dy;
926 curPos += wheelDelta;
927 if (curPos > max)
928 curPos = max;
929 else if (curPos < min)
930 curPos = min;
932 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
933 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
934 ScrollWindow(hWnd, 0, dy, NULL, NULL);
935 UpdateWindow(hWnd);
938 break;
940 case WM_VSCROLL:
942 BOOL update = TRUE;
943 RECT rect;
944 INT Min, Max;
945 INT CurPos = GetScrollPos(hWnd, SB_VERT);
946 INT dy;
948 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
949 GetClientRect(hWnd, &rect);
951 switch (wParam & 0xffff)
953 case SB_THUMBTRACK:
954 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
955 case SB_TOP: CurPos = Min; break;
956 case SB_BOTTOM: CurPos = Max; break;
957 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
958 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
959 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
960 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
961 default: update = FALSE;
963 if (update)
965 if (CurPos > Max)
966 CurPos = Max;
967 else if (CurPos < Min)
968 CurPos = Min;
969 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
970 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
971 ScrollWindow(hWnd, 0, dy, NULL, NULL);
972 UpdateWindow(hWnd);
975 break;
977 case WM_PAINT:
978 hDc = BeginPaint(hWnd, &ps);
979 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
980 scroll_pos = GetScrollPos(hWnd, SB_VERT);
982 for (line = win->first_line; line; line = line->next)
984 for (part = &line->first_part; part; part = part->next)
986 switch (part->cookie)
988 case hlp_line_part_text:
989 SelectObject(hDc, part->u.text.hFont);
990 SetTextColor(hDc, part->u.text.color);
991 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
992 part->u.text.lpsText, part->u.text.wTextLen);
993 if (part->u.text.wUnderline)
995 HPEN hPen;
997 switch (part->u.text.wUnderline)
999 case 1: /* simple */
1000 case 2: /* double */
1001 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
1002 break;
1003 case 3: /* dotted */
1004 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
1005 break;
1006 default:
1007 WINE_FIXME("Unknow underline type\n");
1008 continue;
1011 SelectObject(hDc, hPen);
1012 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
1013 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
1014 if (part->u.text.wUnderline == 2)
1016 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
1017 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
1019 DeleteObject(hPen);
1021 break;
1022 case hlp_line_part_bitmap:
1024 HDC hMemDC;
1026 hMemDC = CreateCompatibleDC(hDc);
1027 SelectObject(hMemDC, part->u.bitmap.hBitmap);
1028 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
1029 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
1030 hMemDC, 0, 0, SRCCOPY);
1031 DeleteDC(hMemDC);
1033 break;
1034 case hlp_line_part_metafile:
1036 POINT pt;
1038 SetViewportOrgEx(hDc, part->rect.left, part->rect.top - scroll_pos, &pt);
1039 PlayMetaFile(hDc, part->u.metafile.hMetaFile);
1040 SetViewportOrgEx(hDc, pt.x, pt.y, NULL);
1042 break;
1047 EndPaint(hWnd, &ps);
1048 break;
1050 case WM_MOUSEMOVE:
1051 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1053 if (WINHELP_IsOverLink(win, wParam, lParam))
1054 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
1055 else
1056 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
1058 break;
1060 case WM_LBUTTONDOWN:
1061 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1063 hPopupWnd = Globals.hPopupWnd;
1064 Globals.hPopupWnd = 0;
1066 part = WINHELP_IsOverLink(win, wParam, lParam);
1067 if (part)
1069 HLPFILE* hlpfile;
1070 HLPFILE_WINDOWINFO* wi;
1072 mouse.x = LOWORD(lParam);
1073 mouse.y = HIWORD(lParam);
1075 if (part->link) switch (part->link->cookie)
1077 case hlp_link_link:
1078 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1079 if (part->link->window == -1)
1080 wi = win->info;
1081 else if (part->link->window < hlpfile->numWindows)
1082 wi = &hlpfile->windows[part->link->window];
1083 else
1085 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
1086 break;
1088 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
1089 SW_NORMAL);
1090 break;
1091 case hlp_link_popup:
1092 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
1093 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
1094 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
1095 SW_NORMAL);
1096 break;
1097 case hlp_link_macro:
1098 MACRO_ExecuteMacro(part->link->lpszString);
1099 break;
1100 default:
1101 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1105 if (hPopupWnd)
1106 DestroyWindow(hPopupWnd);
1107 break;
1109 case WM_NCDESTROY:
1110 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1112 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
1114 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1116 WINHELP_DeleteWindow(win);
1118 if (bExit) MACRO_Exit();
1120 if (!Globals.win_list)
1121 PostQuitMessage(0);
1122 break;
1125 return DefWindowProc(hWnd, msg, wParam, lParam);
1128 /******************************************************************
1129 * WINHELP_HistoryWndProc
1133 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1135 WINHELP_WINDOW* win;
1136 PAINTSTRUCT ps;
1137 HDC hDc;
1138 TEXTMETRIC tm;
1139 unsigned int i;
1140 RECT r;
1142 switch (msg)
1144 case WM_NCCREATE:
1145 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1146 SetWindowLong(hWnd, 0, (LONG)win);
1147 win->hHistoryWnd = hWnd;
1148 break;
1149 case WM_CREATE:
1150 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1151 hDc = GetDC(hWnd);
1152 GetTextMetrics(hDc, &tm);
1153 GetWindowRect(hWnd, &r);
1155 r.right = r.left + 30 * tm.tmAveCharWidth;
1156 r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
1157 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1158 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1159 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1161 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1162 ReleaseDC(hWnd, hDc);
1163 break;
1164 case WM_LBUTTONDOWN:
1165 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1166 hDc = GetDC(hWnd);
1167 GetTextMetrics(hDc, &tm);
1168 i = HIWORD(lParam) / tm.tmHeight;
1169 if (i < win->histIndex)
1170 WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
1171 ReleaseDC(hWnd, hDc);
1172 break;
1173 case WM_PAINT:
1174 hDc = BeginPaint(hWnd, &ps);
1175 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1176 GetTextMetrics(hDc, &tm);
1178 for (i = 0; i < win->histIndex; i++)
1180 TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle,
1181 strlen(win->history[i]->lpszTitle));
1183 EndPaint(hWnd, &ps);
1184 break;
1185 case WM_DESTROY:
1186 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1187 if (hWnd == win->hHistoryWnd)
1188 win->hHistoryWnd = 0;
1189 break;
1191 return DefWindowProc(hWnd, msg, wParam, lParam);
1194 /***********************************************************************
1196 * WINHELP_ShadowWndProc
1198 static LRESULT CALLBACK WINHELP_ShadowWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1200 WINHELP_CheckPopup(msg);
1201 return DefWindowProc(hWnd, msg, wParam, lParam);
1204 /***********************************************************************
1206 * SetupText
1208 static void WINHELP_SetupText(HWND hWnd)
1210 HDC hDc = GetDC(hWnd);
1211 RECT rect;
1212 SIZE newsize;
1214 ShowScrollBar(hWnd, SB_VERT, FALSE);
1215 if (!WINHELP_SplitLines(hWnd, NULL))
1217 ShowScrollBar(hWnd, SB_VERT, TRUE);
1218 GetClientRect(hWnd, &rect);
1220 WINHELP_SplitLines(hWnd, &newsize);
1221 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1223 else
1225 SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1226 SetScrollRange(hWnd, SB_VERT, 0, 0, FALSE);
1229 ReleaseDC(hWnd, hDc);
1232 /***********************************************************************
1234 * WINHELP_AppendText
1236 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1237 LPSIZE space, LPSIZE textsize,
1238 INT *line_ascent, INT ascent,
1239 LPCSTR text, UINT textlen,
1240 HFONT font, COLORREF color, HLPFILE_LINK *link,
1241 unsigned underline)
1243 WINHELP_LINE *line;
1244 WINHELP_LINE_PART *part;
1245 LPSTR ptr;
1247 if (!*partp) /* New line */
1249 *line_ascent = ascent;
1251 line = HeapAlloc(GetProcessHeap(), 0,
1252 sizeof(WINHELP_LINE) + textlen);
1253 if (!line) return FALSE;
1255 line->next = 0;
1256 part = &line->first_part;
1257 ptr = (char*)line + sizeof(WINHELP_LINE);
1259 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1260 line->rect.bottom = line->rect.top;
1261 line->rect.left = space->cx;
1262 line->rect.right = space->cx;
1264 if (**linep) *linep = &(**linep)->next;
1265 **linep = line;
1266 space->cy = 0;
1268 else /* Same line */
1270 line = **linep;
1272 if (*line_ascent < ascent)
1274 WINHELP_LINE_PART *p;
1275 for (p = &line->first_part; p; p = p->next)
1277 p->rect.top += ascent - *line_ascent;
1278 p->rect.bottom += ascent - *line_ascent;
1280 line->rect.bottom += ascent - *line_ascent;
1281 *line_ascent = ascent;
1284 part = HeapAlloc(GetProcessHeap(), 0,
1285 sizeof(WINHELP_LINE_PART) + textlen);
1286 if (!part) return FALSE;
1287 **partp = part;
1288 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1291 memcpy(ptr, text, textlen);
1292 part->cookie = hlp_line_part_text;
1293 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1294 part->rect.right = part->rect.left + textsize->cx;
1295 line->rect.right = part->rect.right;
1296 part->rect.top =
1297 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1298 part->rect.bottom = part->rect.top + textsize->cy;
1299 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1300 part->u.text.lpsText = ptr;
1301 part->u.text.wTextLen = textlen;
1302 part->u.text.hFont = font;
1303 part->u.text.color = color;
1304 part->u.text.wUnderline = underline;
1306 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1307 part->u.text.wTextLen,
1308 part->u.text.wTextLen,
1309 part->u.text.lpsText,
1310 part->u.text.wTextLen,
1311 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1313 part->link = link;
1314 if (link) link->wRefCount++;
1316 part->next = 0;
1317 *partp = &part->next;
1319 space->cx = 0;
1321 return TRUE;
1324 /***********************************************************************
1326 * WINHELP_AppendGfxObject
1328 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1329 LPSIZE space, LPSIZE gfxSize,
1330 HLPFILE_LINK *link, unsigned pos)
1332 WINHELP_LINE *line;
1333 WINHELP_LINE_PART *part;
1334 LPSTR ptr;
1336 if (!*partp || pos == 1) /* New line */
1338 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1339 if (!line) return NULL;
1341 line->next = NULL;
1342 part = &line->first_part;
1344 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1345 line->rect.bottom = line->rect.top;
1346 line->rect.left = space->cx;
1347 line->rect.right = space->cx;
1349 if (**linep) *linep = &(**linep)->next;
1350 **linep = line;
1351 space->cy = 0;
1352 ptr = (char*)line + sizeof(WINHELP_LINE);
1354 else /* Same line */
1356 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1357 line = **linep;
1359 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1360 if (!part) return NULL;
1361 **partp = part;
1362 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1365 /* part->cookie should be set by caller (image or metafile) */
1366 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1367 part->rect.right = part->rect.left + gfxSize->cx;
1368 line->rect.right = part->rect.right;
1369 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1370 part->rect.bottom = part->rect.top + gfxSize->cy;
1371 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1373 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1374 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1376 part->link = link;
1377 if (link) link->wRefCount++;
1379 part->next = NULL;
1380 *partp = &part->next;
1382 space->cx = 0;
1384 return part;
1388 /***********************************************************************
1390 * WINHELP_SplitLines
1392 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1394 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1395 HLPFILE_PARAGRAPH *p;
1396 WINHELP_LINE **line = &win->first_line;
1397 WINHELP_LINE_PART **part = 0;
1398 INT line_ascent = 0;
1399 SIZE space;
1400 RECT rect;
1401 HDC hDc;
1403 if (newsize) newsize->cx = newsize->cy = 0;
1405 if (!win->page) return TRUE;
1407 WINHELP_DeleteLines(win);
1409 GetClientRect(hWnd, &rect);
1411 rect.top += INTERNAL_BORDER_WIDTH;
1412 rect.left += INTERNAL_BORDER_WIDTH;
1413 rect.right -= INTERNAL_BORDER_WIDTH;
1414 rect.bottom -= INTERNAL_BORDER_WIDTH;
1416 space.cy = rect.top;
1417 space.cx = rect.left;
1419 hDc = GetDC(hWnd);
1421 for (p = win->page->first_paragraph; p; p = p->next)
1423 switch (p->cookie)
1425 case para_normal_text:
1426 case para_debug_text:
1428 TEXTMETRIC tm;
1429 SIZE textsize = {0, 0};
1430 LPCSTR text = p->u.text.lpszText;
1431 UINT indent = 0;
1432 UINT len = strlen(text);
1433 unsigned underline = 0;
1435 HFONT hFont = 0;
1436 COLORREF color = RGB(0, 0, 0);
1438 if (p->u.text.wFont < win->page->file->numFonts)
1440 HLPFILE* hlpfile = win->page->file;
1442 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1443 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1444 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1445 color = hlpfile->fonts[p->u.text.wFont].color;
1447 else
1449 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1451 hFont = win->fonts[wFont];
1454 if (p->link && p->link->bClrChange)
1456 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1457 color = RGB(0, 0x80, 0);
1459 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1461 SelectObject(hDc, hFont);
1463 GetTextMetrics(hDc, &tm);
1465 if (p->u.text.wIndent)
1467 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1468 if (!part)
1469 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1472 if (p->u.text.wVSpace)
1474 part = 0;
1475 space.cx = rect.left + indent;
1476 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1479 if (p->u.text.wHSpace)
1481 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1484 WINE_TRACE("splitting text %s\n", text);
1486 while (len)
1488 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1489 UINT low = 0, curr = len, high = len, textlen = 0;
1491 if (free_width > 0)
1493 while (1)
1495 GetTextExtentPoint(hDc, text, curr, &textsize);
1497 if (textsize.cx <= free_width) low = curr;
1498 else high = curr;
1500 if (high <= low + 1) break;
1502 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1503 if (curr <= low) curr = low + 1;
1504 else if (curr >= high) curr = high - 1;
1506 textlen = low;
1507 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1509 if (!part && !textlen) textlen = max(low, 1);
1511 if (free_width <= 0 || !textlen)
1513 part = 0;
1514 space.cx = rect.left + indent;
1515 space.cx = min(space.cx, rect.right - rect.left - 1);
1516 continue;
1519 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1521 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1522 &line_ascent, tm.tmAscent,
1523 text, textlen, hFont, color, p->link, underline) ||
1524 (!newsize && (*line)->rect.bottom > rect.bottom))
1526 ReleaseDC(hWnd, hDc);
1527 return FALSE;
1530 if (newsize)
1531 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1533 len -= textlen;
1534 text += textlen;
1535 if (text[0] == ' ') text++, len--;
1538 break;
1539 case para_bitmap:
1540 case para_metafile:
1542 SIZE gfxSize;
1543 INT free_width;
1544 WINHELP_LINE_PART* ref_part;
1546 if (p->u.gfx.pos & 0x8000)
1548 space.cx = rect.left;
1549 if (*line)
1550 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1551 part = 0;
1554 if (p->cookie == para_bitmap)
1556 DIBSECTION dibs;
1558 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1559 gfxSize.cx = dibs.dsBm.bmWidth;
1560 gfxSize.cy = dibs.dsBm.bmHeight;
1562 else gfxSize = p->u.gfx.u.mf.mfSize;
1564 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1565 if (free_width <= 0)
1567 part = NULL;
1568 space.cx = rect.left;
1569 space.cx = min(space.cx, rect.right - rect.left - 1);
1571 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1572 p->link, p->u.gfx.pos);
1573 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1575 return FALSE;
1577 if (p->cookie == para_bitmap)
1579 ref_part->cookie = hlp_line_part_bitmap;
1580 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1582 else
1584 ref_part->cookie = hlp_line_part_metafile;
1585 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mf.hMetaFile;
1588 break;
1592 if (newsize)
1593 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1595 ReleaseDC(hWnd, hDc);
1596 return TRUE;
1599 /***********************************************************************
1601 * WINHELP_CheckPopup
1603 static void WINHELP_CheckPopup(UINT msg)
1605 if (!Globals.hPopupWnd) return;
1607 switch (msg)
1609 case WM_COMMAND:
1610 case WM_LBUTTONDOWN:
1611 case WM_MBUTTONDOWN:
1612 case WM_RBUTTONDOWN:
1613 case WM_NCLBUTTONDOWN:
1614 case WM_NCMBUTTONDOWN:
1615 case WM_NCRBUTTONDOWN:
1616 DestroyWindow(Globals.hPopupWnd);
1617 Globals.hPopupWnd = 0;
1621 /***********************************************************************
1623 * WINHELP_DeleteLines
1625 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1627 WINHELP_LINE *line, *next_line;
1628 WINHELP_LINE_PART *part, *next_part;
1629 for (line = win->first_line; line; line = next_line)
1631 next_line = line->next;
1632 for (part = &line->first_part; part; part = next_part)
1634 next_part = part->next;
1635 HLPFILE_FreeLink(part->link);
1636 HeapFree(GetProcessHeap(), 0, part);
1639 win->first_line = 0;
1642 /***********************************************************************
1644 * WINHELP_DeleteWindow
1646 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1648 WINHELP_WINDOW** w;
1649 unsigned int i;
1650 WINHELP_BUTTON* b;
1651 WINHELP_BUTTON* bp;
1653 for (w = &Globals.win_list; *w; w = &(*w)->next)
1655 if (*w == win)
1657 *w = win->next;
1658 break;
1662 for (b = win->first_button; b; b = bp)
1664 DestroyWindow(b->hWnd);
1665 bp = b->next;
1666 HeapFree(GetProcessHeap(), 0, b);
1669 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1670 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1672 for (i = 0; i < win->histIndex; i++)
1674 HLPFILE_FreeHlpFile(win->history[i]->file);
1677 for (i = 0; i < win->backIndex; i++)
1678 HLPFILE_FreeHlpFile(win->back[i]->file);
1680 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1681 WINHELP_DeleteLines(win);
1682 HeapFree(GetProcessHeap(), 0, win);
1685 /***********************************************************************
1687 * WINHELP_InitFonts
1689 static void WINHELP_InitFonts(HWND hWnd)
1691 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1692 LOGFONT logfontlist[] = {
1693 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1694 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1695 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1696 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1697 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1698 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1699 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1700 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1702 static HFONT fonts[FONTS_LEN];
1703 static BOOL init = 0;
1705 win->fonts_len = FONTS_LEN;
1706 win->fonts = fonts;
1708 if (!init)
1710 UINT i;
1712 for (i = 0; i < FONTS_LEN; i++)
1714 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1717 init = 1;
1721 /***********************************************************************
1723 * WINHELP_MessageBoxIDS
1725 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1727 CHAR text[MAX_STRING_LEN];
1728 CHAR title[MAX_STRING_LEN];
1730 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1731 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1733 return MessageBox(0, text, title, type);
1736 /***********************************************************************
1738 * MAIN_MessageBoxIDS_s
1740 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1742 CHAR text[MAX_STRING_LEN];
1743 CHAR title[MAX_STRING_LEN];
1744 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
1746 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1747 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1748 wsprintf(newtext, text, str);
1750 return MessageBox(0, newtext, title, type);
1753 /******************************************************************
1754 * WINHELP_IsOverLink
1758 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1760 POINT mouse;
1761 WINHELP_LINE *line;
1762 WINHELP_LINE_PART *part;
1763 int scroll_pos = GetScrollPos(win->hTextWnd, SB_VERT);
1765 mouse.x = LOWORD(lParam);
1766 mouse.y = HIWORD(lParam);
1767 for (line = win->first_line; line; line = line->next)
1769 for (part = &line->first_part; part; part = part->next)
1771 if (part->link &&
1772 part->link->lpszString &&
1773 part->rect.left <= mouse.x &&
1774 part->rect.right >= mouse.x &&
1775 part->rect.top <= mouse.y + scroll_pos &&
1776 part->rect.bottom >= mouse.y + scroll_pos)
1778 return part;
1783 return NULL;