Set win_style of the main window to WS_OVERLAPPEDWINDOW.
[wine/wine64.git] / programs / winhelp / winhelp.c
blobd16f263f04c202cd7403ffe91ef4f46c4a575392
1 /*
2 * Help Viewer
4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002 Eric Pouech <eric.pouech@wanadoo.fr>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <assert.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winhelp.h"
34 #include "winhelp_res.h"
35 #include "shellapi.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(winhelp);
41 static BOOL WINHELP_RegisterWinClasses(void);
42 static LRESULT CALLBACK WINHELP_MainWndProc(HWND, UINT, WPARAM, LPARAM);
43 static LRESULT CALLBACK WINHELP_TextWndProc(HWND, UINT, WPARAM, LPARAM);
44 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND, UINT, WPARAM, LPARAM);
45 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND, UINT, WPARAM, LPARAM);
46 static void WINHELP_CheckPopup(UINT);
47 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE);
48 static void WINHELP_InitFonts(HWND hWnd);
49 static void WINHELP_DeleteLines(WINHELP_WINDOW*);
50 static void WINHELP_DeleteWindow(WINHELP_WINDOW*);
51 static void WINHELP_SetupText(HWND hWnd);
52 static WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW*, WPARAM, LPARAM);
54 WINHELP_GLOBALS Globals = {3, 0, 0, 0, 1, 0, 0};
56 /***********************************************************************
58 * WINHELP_LookupHelpFile
60 HLPFILE* WINHELP_LookupHelpFile(LPCSTR lpszFile)
62 HLPFILE* hlpfile;
64 hlpfile = HLPFILE_ReadHlpFile(lpszFile);
66 /* Add Suffix `.hlp' */
67 if (!hlpfile && lstrcmpi(lpszFile + strlen(lpszFile) - 4, ".hlp") != 0)
69 char szFile_hlp[MAX_PATHNAME_LEN];
71 lstrcpyn(szFile_hlp, lpszFile, sizeof(szFile_hlp) - 4);
72 szFile_hlp[sizeof(szFile_hlp) - 5] = '\0';
73 lstrcat(szFile_hlp, ".hlp");
75 hlpfile = HLPFILE_ReadHlpFile(szFile_hlp);
77 if (!hlpfile)
79 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s, lpszFile, STID_WHERROR, MB_OK);
80 if (Globals.win_list) return NULL;
82 return hlpfile;
85 /******************************************************************
86 * WINHELP_GetWindowInfo
90 HLPFILE_WINDOWINFO* WINHELP_GetWindowInfo(HLPFILE* hlpfile, LPCSTR name)
92 static HLPFILE_WINDOWINFO mwi;
93 int i;
95 if (!name || !name[0])
96 name = Globals.active_win->lpszName;
98 if (hlpfile)
99 for (i = 0; i < hlpfile->numWindows; i++)
100 if (!strcmp(hlpfile->windows[i].name, name))
101 return &hlpfile->windows[i];
103 if (strcmp(name, "main") != 0)
105 WINE_FIXME("Couldn't find window info for %s\n", name);
106 assert(0);
107 return NULL;
109 if (!mwi.name[0])
111 strcpy(mwi.type, "primary");
112 strcpy(mwi.name, "main");
113 if (!LoadString(Globals.hInstance, STID_WINE_HELP,
114 mwi.caption, sizeof(mwi.caption)))
115 strcpy(mwi.caption, hlpfile->lpszTitle);
116 mwi.origin.x = mwi.origin.y = mwi.size.cx = mwi.size.cy = CW_USEDEFAULT;
117 mwi.style = SW_SHOW;
118 mwi.win_style = WS_OVERLAPPEDWINDOW;
119 mwi.sr_color = mwi.sr_color = 0xFFFFFF;
121 return &mwi;
124 /******************************************************************
125 * HLPFILE_GetPopupWindowInfo
129 HLPFILE_WINDOWINFO* WINHELP_GetPopupWindowInfo(HLPFILE* hlpfile, HWND hParentWnd, POINT* mouse)
131 static HLPFILE_WINDOWINFO wi;
133 RECT parent_rect;
135 wi.type[0] = wi.name[0] = wi.caption[0] = '\0';
137 /* Calculate horizontal size and position of a popup window */
138 GetWindowRect(hParentWnd, &parent_rect);
139 wi.size.cx = (parent_rect.right - parent_rect.left) / 2;
140 wi.size.cy = 10; /* need a non null value, so that border are taken into account while computing */
142 wi.origin = *mouse;
143 ClientToScreen(hParentWnd, &wi.origin);
144 wi.origin.x -= wi.size.cx / 2;
145 wi.origin.x = min(wi.origin.x, GetSystemMetrics(SM_CXSCREEN) - wi.size.cx);
146 wi.origin.x = max(wi.origin.x, 0);
148 wi.style = SW_SHOW;
149 wi.win_style = WS_POPUPWINDOW;
150 wi.sr_color = wi.sr_color = 0xFFFFFF;
152 return &wi;
155 /***********************************************************************
157 * WinMain
159 int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE prev, LPSTR cmdline, int show)
161 MSG msg;
162 LONG lHash = 0;
163 HLPFILE* hlpfile;
165 Globals.hInstance = hInstance;
167 /* Get options */
168 while (*cmdline && (*cmdline == ' ' || *cmdline == '-'))
170 CHAR option;
171 LPCSTR topic_id;
172 if (*cmdline++ == ' ') continue;
174 option = *cmdline;
175 if (option) cmdline++;
176 while (*cmdline && *cmdline == ' ') cmdline++;
177 switch (option)
179 case 'i':
180 case 'I':
181 topic_id = cmdline;
182 while (*cmdline && *cmdline != ' ') cmdline++;
183 if (*cmdline) *cmdline++ = '\0';
184 lHash = HLPFILE_Hash(topic_id);
185 break;
187 case '3':
188 case '4':
189 Globals.wVersion = option - '0';
190 break;
192 case 'x':
193 show = SW_HIDE;
194 Globals.isBook = FALSE;
195 break;
197 default:
198 WINE_FIXME("Unsupported cmd line: %s\n", cmdline);
199 break;
203 /* Create primary window */
204 WINHELP_RegisterWinClasses();
205 if (*cmdline)
207 hlpfile = WINHELP_LookupHelpFile(cmdline);
208 if (!hlpfile) return 0;
210 else hlpfile = NULL;
211 WINHELP_CreateHelpWindowByHash(hlpfile, lHash,
212 WINHELP_GetWindowInfo(hlpfile, "main"), show);
214 /* Message loop */
215 while (GetMessage(&msg, 0, 0, 0))
217 TranslateMessage(&msg);
218 DispatchMessage(&msg);
220 return 0;
223 /***********************************************************************
225 * RegisterWinClasses
227 static BOOL WINHELP_RegisterWinClasses(void)
229 WNDCLASS class_main, class_button_box, class_text, class_shadow, class_history;
231 class_main.style = CS_HREDRAW | CS_VREDRAW;
232 class_main.lpfnWndProc = WINHELP_MainWndProc;
233 class_main.cbClsExtra = 0;
234 class_main.cbWndExtra = sizeof(LONG);
235 class_main.hInstance = Globals.hInstance;
236 class_main.hIcon = LoadIcon(0, IDI_APPLICATION);
237 class_main.hCursor = LoadCursor(0, IDC_ARROW);
238 class_main.hbrBackground = GetStockObject(WHITE_BRUSH);
239 class_main.lpszMenuName = 0;
240 class_main.lpszClassName = MAIN_WIN_CLASS_NAME;
242 class_button_box = class_main;
243 class_button_box.lpfnWndProc = WINHELP_ButtonBoxWndProc;
244 class_button_box.hbrBackground = GetStockObject(GRAY_BRUSH);
245 class_button_box.lpszClassName = BUTTON_BOX_WIN_CLASS_NAME;
247 class_text = class_main;
248 class_text.lpfnWndProc = WINHELP_TextWndProc;
249 class_text.lpszClassName = TEXT_WIN_CLASS_NAME;
251 class_shadow = class_main;
252 class_shadow.lpfnWndProc = DefWindowProc;
253 class_shadow.hbrBackground = GetStockObject(GRAY_BRUSH);
254 class_shadow.lpszClassName = SHADOW_WIN_CLASS_NAME;
256 class_history = class_main;
257 class_history.lpfnWndProc = WINHELP_HistoryWndProc;
258 class_history.lpszClassName = HISTORY_WIN_CLASS_NAME;
260 return (RegisterClass(&class_main) &&
261 RegisterClass(&class_button_box) &&
262 RegisterClass(&class_text) &&
263 RegisterClass(&class_shadow) &&
264 RegisterClass(&class_history));
267 typedef struct
269 WORD size;
270 WORD command;
271 LONG data;
272 LONG reserved;
273 WORD ofsFilename;
274 WORD ofsData;
275 } WINHELP,*LPWINHELP;
277 /******************************************************************
278 * WINHELP_HandleCommand
282 static LRESULT WINHELP_HandleCommand(HWND hSrcWnd, LPARAM lParam)
284 COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lParam;
285 WINHELP* wh;
287 if (cds->dwData != 0xA1DE505)
289 WINE_FIXME("Wrong magic number (%08lx)\n", cds->dwData);
290 return 0;
293 wh = (WINHELP*)cds->lpData;
295 if (wh)
297 char* ptr = (wh->ofsFilename) ? (LPSTR)wh + wh->ofsFilename : NULL;
299 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
300 wh->size, wh->command, wh->data, ptr);
301 switch (wh->command)
303 case HELP_CONTEXT:
304 if (ptr)
306 MACRO_JumpContext(ptr, "main", wh->data);
308 break;
309 case HELP_QUIT:
310 MACRO_Exit();
311 break;
312 case HELP_CONTENTS:
313 if (ptr)
315 MACRO_JumpContents(ptr, "main");
317 break;
318 case HELP_HELPONHELP:
319 MACRO_HelpOn();
320 break;
321 /* case HELP_SETINDEX: */
322 case HELP_SETCONTENTS:
323 if (ptr)
325 MACRO_SetContents(ptr, wh->data);
327 break;
328 case HELP_CONTEXTPOPUP:
329 if (ptr)
331 MACRO_PopupContext(ptr, wh->data);
333 break;
334 /* case HELP_FORCEFILE:*/
335 /* case HELP_CONTEXTMENU: */
336 case HELP_FINDER:
337 /* in fact, should be the topic dialog box */
338 if (ptr)
340 MACRO_JumpHash(ptr, "main", 0);
342 break;
343 /* case HELP_WM_HELP: */
344 /* case HELP_SETPOPUP_POS: */
345 /* case HELP_KEY: */
346 /* case HELP_COMMAND: */
347 /* case HELP_PARTIALKEY: */
348 /* case HELP_MULTIKEY: */
349 /* case HELP_SETWINPOS: */
350 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh->command);
351 break;
354 return 0L;
357 /******************************************************************
358 * WINHELP_ReuseWindow
362 static BOOL WINHELP_ReuseWindow(WINHELP_WINDOW* win, WINHELP_WINDOW* oldwin,
363 HLPFILE_PAGE* page, int nCmdShow)
365 int i;
367 win->hMainWnd = oldwin->hMainWnd;
368 win->hButtonBoxWnd = oldwin->hButtonBoxWnd;
369 win->hTextWnd = oldwin->hTextWnd;
370 win->hHistoryWnd = oldwin->hHistoryWnd;
371 oldwin->hMainWnd = oldwin->hButtonBoxWnd = oldwin->hTextWnd = oldwin->hHistoryWnd = 0;
373 SetWindowLong(win->hMainWnd, 0, (LONG)win);
374 SetWindowLong(win->hButtonBoxWnd, 0, (LONG)win);
375 SetWindowLong(win->hTextWnd, 0, (LONG)win);
376 SetWindowLong(win->hHistoryWnd, 0, (LONG)win);
378 WINHELP_InitFonts(win->hMainWnd);
380 if (page)
381 SetWindowText(win->hMainWnd, page->file->lpszTitle);
383 WINHELP_SetupText(win->hTextWnd);
384 InvalidateRect(win->hTextWnd, NULL, TRUE);
385 SendMessage(win->hMainWnd, WM_USER, 0, 0);
386 ShowWindow(win->hMainWnd, nCmdShow);
387 UpdateWindow(win->hTextWnd);
389 if (!(win->info->win_style & WS_POPUP))
391 unsigned num;
393 memcpy(win->history, oldwin->history, sizeof(win->history));
394 win->histIndex = oldwin->histIndex;
396 /* FIXME: when using back, we shouldn't update the history... */
398 if (page)
400 for (i = 0; i < win->histIndex; i++)
401 if (win->history[i] == page) break;
403 /* if the new page is already in the history, do nothing */
404 if (i == win->histIndex)
406 num = sizeof(win->history) / sizeof(win->history[0]);
407 if (win->histIndex == num)
409 /* we're full, remove latest entry */
410 HLPFILE_FreeHlpFile(win->history[0]->file);
411 memmove(&win->history[0], &win->history[1],
412 (num - 1) * sizeof(win->history[0]));
413 win->histIndex--;
415 win->history[win->histIndex++] = page;
416 page->file->wRefCount++;
417 if (win->hHistoryWnd) InvalidateRect(win->hHistoryWnd, NULL, TRUE);
421 memcpy(win->back, oldwin->back, sizeof(win->back));
422 win->backIndex = oldwin->backIndex;
424 if (page)
426 num = sizeof(win->back) / sizeof(win->back[0]);
427 if (win->backIndex == num)
429 /* we're full, remove latest entry */
430 HLPFILE_FreeHlpFile(win->back[0]->file);
431 memmove(&win->back[0], &win->back[1],
432 (num - 1) * sizeof(win->back[0]));
433 win->backIndex--;
435 win->back[win->backIndex++] = page;
436 page->file->wRefCount++;
439 else
440 win->backIndex = win->histIndex = 0;
442 oldwin->histIndex = oldwin->backIndex = 0;
443 WINHELP_DeleteWindow(oldwin);
444 return TRUE;
447 /***********************************************************************
449 * WINHELP_CreateHelpWindow
451 BOOL WINHELP_CreateHelpWindow(HLPFILE_PAGE* page, HLPFILE_WINDOWINFO* wi,
452 int nCmdShow)
454 WINHELP_WINDOW *win, *oldwin;
455 HWND hWnd;
456 BOOL bPrimary;
457 BOOL bPopup;
459 bPrimary = !lstrcmpi(wi->name, "main");
460 bPopup = wi->win_style & WS_POPUP;
462 /* Initialize WINHELP_WINDOW struct */
463 win = HeapAlloc(GetProcessHeap(), 0,
464 sizeof(WINHELP_WINDOW) + strlen(wi->name) + 1);
465 if (!win) return FALSE;
467 win->next = Globals.win_list;
468 Globals.win_list = win;
470 win->lpszName = (char*)win + sizeof(WINHELP_WINDOW);
471 lstrcpy((char*)win->lpszName, wi->name);
473 win->page = page;
474 win->first_button = 0;
475 win->first_line = 0;
476 win->hMainWnd = 0;
477 win->hButtonBoxWnd = 0;
478 win->hTextWnd = 0;
479 win->hShadowWnd = 0;
480 win->hHistoryWnd = 0;
482 win->hArrowCur = LoadCursorA(0, (LPSTR)IDC_ARROW);
483 win->hHandCur = LoadCursorA(0, (LPSTR)IDC_HAND);
485 win->info = wi;
487 Globals.active_win = win;
489 /* Initialize default pushbuttons */
490 if (bPrimary && page)
492 CHAR buffer[MAX_STRING_LEN];
494 LoadString(Globals.hInstance, STID_CONTENTS, buffer, sizeof(buffer));
495 MACRO_CreateButton("BTN_CONTENTS", buffer, "Contents()");
496 LoadString(Globals.hInstance, STID_SEARCH,buffer, sizeof(buffer));
497 MACRO_CreateButton("BTN_SEARCH", buffer, "Search()");
498 LoadString(Globals.hInstance, STID_BACK, buffer, sizeof(buffer));
499 MACRO_CreateButton("BTN_BACK", buffer, "Back()");
500 LoadString(Globals.hInstance, STID_HISTORY, buffer, sizeof(buffer));
501 MACRO_CreateButton("BTN_HISTORY", buffer, "History()");
502 LoadString(Globals.hInstance, STID_TOPICS, buffer, sizeof(buffer));
503 MACRO_CreateButton("BTN_TOPICS", buffer, "Finder()");
506 /* Initialize file specific pushbuttons */
507 if (!(wi->win_style & WS_POPUP) && page)
509 HLPFILE_MACRO *macro;
510 for (macro = page->file->first_macro; macro; macro = macro->next)
511 MACRO_ExecuteMacro(macro->lpszMacro);
513 for (macro = page->first_macro; macro; macro = macro->next)
514 MACRO_ExecuteMacro(macro->lpszMacro);
517 win->histIndex = win->backIndex = 0;
518 /* Reuse existing window */
519 if (!bPopup)
521 for (oldwin = win->next; oldwin; oldwin = oldwin->next)
523 if (!lstrcmpi(oldwin->lpszName, wi->name))
525 return WINHELP_ReuseWindow(win, oldwin, page, nCmdShow);
528 if (page)
530 win->histIndex = win->backIndex = 1;
531 win->history[0] = win->back[0] = page;
532 page->file->wRefCount += 2;
536 hWnd = CreateWindow(bPopup ? TEXT_WIN_CLASS_NAME : MAIN_WIN_CLASS_NAME,
537 wi->caption, wi->win_style,
538 wi->origin.x, wi->origin.y, wi->size.cx, wi->size.cy,
539 0, bPrimary ? LoadMenu(Globals.hInstance, MAKEINTRESOURCE(MAIN_MENU)) : 0,
540 Globals.hInstance, win);
542 ShowWindow(hWnd, nCmdShow);
543 UpdateWindow(hWnd);
545 return TRUE;
548 /***********************************************************************
550 * WINHELP_CreateHelpWindowByHash
552 BOOL WINHELP_CreateHelpWindowByHash(HLPFILE* hlpfile, LONG lHash,
553 HLPFILE_WINDOWINFO* wi, int nCmdShow)
555 HLPFILE_PAGE* page = NULL;
557 if (hlpfile)
558 page = lHash ? HLPFILE_PageByHash(hlpfile, lHash) :
559 HLPFILE_Contents(hlpfile);
560 if (page) page->file->wRefCount++;
561 return WINHELP_CreateHelpWindow(page, wi, nCmdShow);
564 /***********************************************************************
566 * WINHELP_MainWndProc
568 static LRESULT CALLBACK WINHELP_MainWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
570 WINHELP_WINDOW *win;
571 WINHELP_BUTTON *button;
572 RECT rect, button_box_rect;
573 INT text_top;
575 WINHELP_CheckPopup(msg);
577 switch (msg)
579 case WM_NCCREATE:
580 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
581 SetWindowLong(hWnd, 0, (LONG) win);
582 win->hMainWnd = hWnd;
583 break;
585 case WM_CREATE:
586 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
588 /* Create button box and text Window */
589 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
590 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
592 CreateWindow(TEXT_WIN_CLASS_NAME, "", WS_CHILD | WS_VISIBLE,
593 0, 0, 0, 0, hWnd, 0, Globals.hInstance, win);
595 /* Fall through */
596 case WM_USER:
597 case WM_WINDOWPOSCHANGED:
598 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
599 GetClientRect(hWnd, &rect);
601 /* Update button box and text Window */
602 SetWindowPos(win->hButtonBoxWnd, HWND_TOP,
603 rect.left, rect.top,
604 rect.right - rect.left,
605 rect.bottom - rect.top, 0);
607 GetWindowRect(win->hButtonBoxWnd, &button_box_rect);
608 text_top = rect.top + button_box_rect.bottom - button_box_rect.top;
610 SetWindowPos(win->hTextWnd, HWND_TOP,
611 rect.left, text_top,
612 rect.right - rect.left,
613 rect.bottom - text_top, 0);
615 break;
617 case WM_COMMAND:
618 Globals.active_win = win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
619 switch (wParam)
621 /* Menu FILE */
622 case MNID_FILE_OPEN: MACRO_FileOpen(); break;
623 case MNID_FILE_PRINT: MACRO_Print(); break;
624 case MNID_FILE_SETUP: MACRO_PrinterSetup(); break;
625 case MNID_FILE_EXIT: MACRO_Exit(); break;
627 /* Menu EDIT */
628 case MNID_EDIT_COPYDLG: MACRO_CopyDialog(); break;
629 case MNID_EDIT_ANNOTATE:MACRO_Annotate(); break;
631 /* Menu Bookmark */
632 case MNID_BKMK_DEFINE: MACRO_BookmarkDefine(); break;
634 /* Menu Help */
635 case MNID_HELP_HELPON: MACRO_HelpOn(); break;
636 case MNID_HELP_HELPTOP: MACRO_HelpOnTop(); break;
637 case MNID_HELP_ABOUT: MACRO_About(); break;
638 case MNID_HELP_WINE: ShellAbout(hWnd, "WINE", "Help", 0); break;
640 default:
641 /* Buttons */
642 for (button = win->first_button; button; button = button->next)
643 if (wParam == button->wParam) break;
644 if (button)
645 MACRO_ExecuteMacro(button->lpszMacro);
646 else
647 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED, 0x121, MB_OK);
648 break;
650 break;
651 case WM_DESTROY:
652 if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd);
653 break;
654 case WM_COPYDATA:
655 return WINHELP_HandleCommand((HWND)wParam, lParam);
657 return DefWindowProc(hWnd, msg, wParam, lParam);
660 /***********************************************************************
662 * WINHELP_ButtonBoxWndProc
664 static LRESULT CALLBACK WINHELP_ButtonBoxWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
666 WINDOWPOS *winpos;
667 WINHELP_WINDOW *win;
668 WINHELP_BUTTON *button;
669 SIZE button_size;
670 INT x, y;
672 WINHELP_CheckPopup(msg);
674 switch (msg)
676 case WM_NCCREATE:
677 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
678 SetWindowLong(hWnd, 0, (LONG) win);
679 win->hButtonBoxWnd = hWnd;
680 break;
682 case WM_WINDOWPOSCHANGING:
683 winpos = (WINDOWPOS*) lParam;
684 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
686 /* Update buttons */
687 button_size.cx = 0;
688 button_size.cy = 0;
689 for (button = win->first_button; button; button = button->next)
691 HDC hDc;
692 SIZE textsize;
693 if (!button->hWnd)
694 button->hWnd = CreateWindow(STRING_BUTTON, (LPSTR) button->lpszName,
695 WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
696 0, 0, 0, 0,
697 hWnd, (HMENU) button->wParam,
698 Globals.hInstance, 0);
699 hDc = GetDC(button->hWnd);
700 GetTextExtentPoint(hDc, button->lpszName,
701 lstrlen(button->lpszName), &textsize);
702 ReleaseDC(button->hWnd, hDc);
704 button_size.cx = max(button_size.cx, textsize.cx + BUTTON_CX);
705 button_size.cy = max(button_size.cy, textsize.cy + BUTTON_CY);
708 x = 0;
709 y = 0;
710 for (button = win->first_button; button; button = button->next)
712 SetWindowPos(button->hWnd, HWND_TOP, x, y, button_size.cx, button_size.cy, 0);
714 if (x + 2 * button_size.cx <= winpos->cx)
715 x += button_size.cx;
716 else
717 x = 0, y += button_size.cy;
719 winpos->cy = y + (x ? button_size.cy : 0);
720 break;
722 case WM_COMMAND:
723 SendMessage(GetParent(hWnd), msg, wParam, lParam);
724 break;
727 return DefWindowProc(hWnd, msg, wParam, lParam);
730 /***********************************************************************
732 * WINHELP_TextWndProc
734 static LRESULT CALLBACK WINHELP_TextWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
736 WINHELP_WINDOW *win;
737 WINHELP_LINE *line;
738 WINHELP_LINE_PART *part;
739 WINDOWPOS *winpos;
740 PAINTSTRUCT ps;
741 HDC hDc;
742 POINT mouse;
743 INT scroll_pos;
744 HWND hPopupWnd;
745 BOOL bExit;
747 if (msg != WM_LBUTTONDOWN)
748 WINHELP_CheckPopup(msg);
750 switch (msg)
752 case WM_NCCREATE:
753 win = (WINHELP_WINDOW*) ((LPCREATESTRUCT) lParam)->lpCreateParams;
754 SetWindowLong(hWnd, 0, (LONG) win);
755 win->hTextWnd = hWnd;
756 if (win->info->win_style & WS_POPUP) Globals.hPopupWnd = win->hMainWnd = hWnd;
757 WINHELP_InitFonts(hWnd);
758 break;
760 case WM_CREATE:
761 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
763 /* Calculate vertical size and position of a popup window */
764 if (win->info->win_style & WS_POPUP)
766 POINT origin;
767 RECT old_window_rect;
768 RECT old_client_rect;
769 SIZE old_window_size;
770 SIZE old_client_size;
771 SIZE new_client_size;
772 SIZE new_window_size;
774 GetWindowRect(hWnd, &old_window_rect);
775 origin.x = old_window_rect.left;
776 origin.y = old_window_rect.top;
777 old_window_size.cx = old_window_rect.right - old_window_rect.left;
778 old_window_size.cy = old_window_rect.bottom - old_window_rect.top;
780 GetClientRect(hWnd, &old_client_rect);
781 old_client_size.cx = old_client_rect.right - old_client_rect.left;
782 old_client_size.cy = old_client_rect.bottom - old_client_rect.top;
784 new_client_size = old_client_size;
785 WINHELP_SplitLines(hWnd, &new_client_size);
787 if (origin.y + POPUP_YDISTANCE + new_client_size.cy <= GetSystemMetrics(SM_CYSCREEN))
788 origin.y += POPUP_YDISTANCE;
789 else
790 origin.y -= POPUP_YDISTANCE + new_client_size.cy;
792 new_window_size.cx = old_window_size.cx - old_client_size.cx + new_client_size.cx;
793 new_window_size.cy = old_window_size.cy - old_client_size.cy + new_client_size.cy;
795 win->hShadowWnd =
796 CreateWindow(SHADOW_WIN_CLASS_NAME, "", WS_POPUP,
797 origin.x + SHADOW_DX, origin.y + SHADOW_DY,
798 new_window_size.cx, new_window_size.cy,
799 0, 0, Globals.hInstance, 0);
801 SetWindowPos(hWnd, HWND_TOP, origin.x, origin.y,
802 new_window_size.cx, new_window_size.cy,
804 SetWindowPos(win->hShadowWnd, hWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
805 ShowWindow(win->hShadowWnd, SW_NORMAL);
806 SetActiveWindow(hWnd);
808 break;
810 case WM_WINDOWPOSCHANGED:
811 winpos = (WINDOWPOS*) lParam;
813 if (!(winpos->flags & SWP_NOSIZE)) WINHELP_SetupText(hWnd);
814 break;
816 case WM_MOUSEWHEEL:
818 int wheelDelta = 0;
819 UINT scrollLines = 3;
820 int curPos = GetScrollPos(hWnd, SB_VERT);
821 int min, max;
823 GetScrollRange(hWnd, SB_VERT, &min, &max);
825 SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0, &scrollLines, 0);
826 if (wParam & (MK_SHIFT | MK_CONTROL))
827 return DefWindowProc(hWnd, msg, wParam, lParam);
828 wheelDelta -= GET_WHEEL_DELTA_WPARAM(wParam);
829 if (abs(wheelDelta) >= WHEEL_DELTA && scrollLines) {
830 int dy;
832 curPos += wheelDelta;
833 if (curPos > max)
834 curPos = max;
835 else if (curPos < min)
836 curPos = min;
838 dy = GetScrollPos(hWnd, SB_VERT) - curPos;
839 SetScrollPos(hWnd, SB_VERT, curPos, TRUE);
840 ScrollWindow(hWnd, 0, dy, NULL, NULL);
841 UpdateWindow(hWnd);
844 break;
846 case WM_VSCROLL:
848 BOOL update = TRUE;
849 RECT rect;
850 INT Min, Max;
851 INT CurPos = GetScrollPos(hWnd, SB_VERT);
852 INT dy;
854 GetScrollRange(hWnd, SB_VERT, &Min, &Max);
855 GetClientRect(hWnd, &rect);
857 switch (wParam & 0xffff)
859 case SB_THUMBTRACK:
860 case SB_THUMBPOSITION: CurPos = wParam >> 16; break;
861 case SB_TOP: CurPos = Min; break;
862 case SB_BOTTOM: CurPos = Max; break;
863 case SB_PAGEUP: CurPos -= (rect.bottom - rect.top) / 2; break;
864 case SB_PAGEDOWN: CurPos += (rect.bottom - rect.top) / 2; break;
865 case SB_LINEUP: CurPos -= GetSystemMetrics(SM_CXVSCROLL); break;
866 case SB_LINEDOWN: CurPos += GetSystemMetrics(SM_CXVSCROLL); break;
867 default: update = FALSE;
869 if (update)
871 if (CurPos > Max)
872 CurPos = Max;
873 else if (CurPos < Min)
874 CurPos = Min;
875 dy = GetScrollPos(hWnd, SB_VERT) - CurPos;
876 SetScrollPos(hWnd, SB_VERT, CurPos, TRUE);
877 ScrollWindow(hWnd, 0, dy, NULL, NULL);
878 UpdateWindow(hWnd);
881 break;
883 case WM_PAINT:
884 hDc = BeginPaint(hWnd, &ps);
885 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
886 scroll_pos = GetScrollPos(hWnd, SB_VERT);
888 for (line = win->first_line; line; line = line->next)
890 for (part = &line->first_part; part; part = part->next)
892 switch (part->cookie)
894 case hlp_line_part_text:
895 SelectObject(hDc, part->u.text.hFont);
896 SetTextColor(hDc, part->u.text.color);
897 TextOut(hDc, part->rect.left, part->rect.top - scroll_pos,
898 part->u.text.lpsText, part->u.text.wTextLen);
899 if (part->u.text.wUnderline)
901 HPEN hPen;
903 switch (part->u.text.wUnderline)
905 case 1: /* simple */
906 case 2: /* double */
907 hPen = CreatePen(PS_SOLID, 1, part->u.text.color);
908 break;
909 case 3: /* dotted */
910 hPen = CreatePen(PS_DOT, 1, part->u.text.color);
911 break;
912 default:
913 WINE_FIXME("Unknow underline type\n");
914 continue;
917 SelectObject(hDc, hPen);
918 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos - 1, NULL);
919 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos - 1);
920 if (part->u.text.wUnderline == 2)
922 MoveToEx(hDc, part->rect.left, part->rect.bottom - scroll_pos + 1, NULL);
923 LineTo(hDc, part->rect.right, part->rect.bottom - scroll_pos + 1);
925 DeleteObject(hPen);
927 break;
928 case hlp_line_part_bitmap:
930 HDC hMemDC;
932 hMemDC = CreateCompatibleDC(hDc);
933 SelectObject(hMemDC, part->u.bitmap.hBitmap);
934 BitBlt(hDc, part->rect.left, part->rect.top - scroll_pos,
935 part->rect.right - part->rect.left, part->rect.bottom - part->rect.top,
936 hMemDC, 0, 0, SRCCOPY);
937 DeleteDC(hMemDC);
939 break;
940 case hlp_line_part_metafile:
942 POINT pt;
944 SetViewportOrgEx(hDc, part->rect.left, part->rect.top - scroll_pos, &pt);
945 PlayMetaFile(hDc, part->u.metafile.hMetaFile);
946 SetViewportOrgEx(hDc, pt.x, pt.y, NULL);
948 break;
953 EndPaint(hWnd, &ps);
954 break;
956 case WM_MOUSEMOVE:
957 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
959 if (WINHELP_IsOverLink(win, wParam, lParam))
960 SetCursor(win->hHandCur); /* set to hand pointer cursor to indicate a link */
961 else
962 SetCursor(win->hArrowCur); /* set to hand pointer cursor to indicate a link */
964 break;
966 case WM_LBUTTONDOWN:
967 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
969 hPopupWnd = Globals.hPopupWnd;
970 Globals.hPopupWnd = 0;
972 part = WINHELP_IsOverLink(win, wParam, lParam);
973 if (part)
975 HLPFILE* hlpfile;
976 HLPFILE_WINDOWINFO* wi;
978 mouse.x = LOWORD(lParam);
979 mouse.y = HIWORD(lParam);
981 if (part->link) switch (part->link->cookie)
983 case hlp_link_link:
984 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
985 if (part->link->window == -1)
986 wi = win->info;
987 else if (part->link->window < hlpfile->numWindows)
988 wi = &hlpfile->windows[part->link->window];
989 else
991 WINE_WARN("link to window %d/%d\n", part->link->window, hlpfile->numWindows);
992 break;
994 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash, wi,
995 SW_NORMAL);
996 break;
997 case hlp_link_popup:
998 hlpfile = WINHELP_LookupHelpFile(part->link->lpszString);
999 WINHELP_CreateHelpWindowByHash(hlpfile, part->link->lHash,
1000 WINHELP_GetPopupWindowInfo(hlpfile, hWnd, &mouse),
1001 SW_NORMAL);
1002 break;
1003 case hlp_link_macro:
1004 MACRO_ExecuteMacro(part->link->lpszString);
1005 break;
1006 default:
1007 WINE_FIXME("Unknown link cookie %d\n", part->link->cookie);
1011 if (hPopupWnd)
1012 DestroyWindow(hPopupWnd);
1013 break;
1015 case WM_NCDESTROY:
1016 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1018 if (hWnd == Globals.hPopupWnd) Globals.hPopupWnd = 0;
1020 bExit = (Globals.wVersion >= 4 && !lstrcmpi(win->lpszName, "main"));
1022 WINHELP_DeleteWindow(win);
1024 if (bExit) MACRO_Exit();
1026 if (!Globals.win_list)
1027 PostQuitMessage(0);
1028 break;
1031 return DefWindowProc(hWnd, msg, wParam, lParam);
1034 /******************************************************************
1035 * WINHELP_HistoryWndProc
1039 static LRESULT CALLBACK WINHELP_HistoryWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
1041 WINHELP_WINDOW* win;
1042 PAINTSTRUCT ps;
1043 HDC hDc;
1044 TEXTMETRIC tm;
1045 int i;
1046 RECT r;
1048 switch (msg)
1050 case WM_NCCREATE:
1051 win = (WINHELP_WINDOW*)((LPCREATESTRUCT)lParam)->lpCreateParams;
1052 SetWindowLong(hWnd, 0, (LONG)win);
1053 win->hHistoryWnd = hWnd;
1054 break;
1055 case WM_CREATE:
1056 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1057 hDc = GetDC(hWnd);
1058 GetTextMetrics(hDc, &tm);
1059 GetWindowRect(hWnd, &r);
1061 r.right = r.left + 30 * tm.tmAveCharWidth;
1062 r.bottom = r.top + (sizeof(win->history) / sizeof(win->history[0])) * tm.tmHeight;
1063 AdjustWindowRect(&r, GetWindowLong(hWnd, GWL_STYLE), FALSE);
1064 if (r.left < 0) {r.right -= r.left; r.left = 0;}
1065 if (r.top < 0) {r.bottom -= r.top; r.top = 0;}
1067 MoveWindow(hWnd, r.left, r.top, r.right, r.bottom, TRUE);
1068 ReleaseDC(hWnd, hDc);
1069 break;
1070 case WM_LBUTTONDOWN:
1071 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1072 hDc = GetDC(hWnd);
1073 GetTextMetrics(hDc, &tm);
1074 i = HIWORD(lParam) / tm.tmHeight;
1075 if (i < win->histIndex)
1076 WINHELP_CreateHelpWindow(win->history[i], win->info, SW_SHOW);
1077 ReleaseDC(hWnd, hDc);
1078 break;
1079 case WM_PAINT:
1080 hDc = BeginPaint(hWnd, &ps);
1081 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1082 GetTextMetrics(hDc, &tm);
1084 for (i = 0; i < win->histIndex; i++)
1086 TextOut(hDc, 0, i * tm.tmHeight, win->history[i]->lpszTitle,
1087 strlen(win->history[i]->lpszTitle));
1089 EndPaint(hWnd, &ps);
1090 break;
1091 case WM_DESTROY:
1092 win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1093 if (hWnd == win->hHistoryWnd)
1094 win->hHistoryWnd = 0;
1095 break;
1097 return DefWindowProc(hWnd, msg, wParam, lParam);
1100 /***********************************************************************
1102 * SetupText
1104 static void WINHELP_SetupText(HWND hWnd)
1106 HDC hDc = GetDC(hWnd);
1107 RECT rect;
1108 SIZE newsize;
1110 ShowScrollBar(hWnd, SB_VERT, FALSE);
1111 if (!WINHELP_SplitLines(hWnd, NULL))
1113 ShowScrollBar(hWnd, SB_VERT, TRUE);
1114 GetClientRect(hWnd, &rect);
1116 WINHELP_SplitLines(hWnd, &newsize);
1117 SetScrollRange(hWnd, SB_VERT, 0, rect.top + newsize.cy - rect.bottom, TRUE);
1119 else SetScrollPos(hWnd, SB_VERT, 0, FALSE);
1121 ReleaseDC(hWnd, hDc);
1124 /***********************************************************************
1126 * WINHELP_AppendText
1128 static BOOL WINHELP_AppendText(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1129 LPSIZE space, LPSIZE textsize,
1130 INT *line_ascent, INT ascent,
1131 LPCSTR text, UINT textlen,
1132 HFONT font, COLORREF color, HLPFILE_LINK *link,
1133 unsigned underline)
1135 WINHELP_LINE *line;
1136 WINHELP_LINE_PART *part;
1137 LPSTR ptr;
1139 if (!*partp) /* New line */
1141 *line_ascent = ascent;
1143 line = HeapAlloc(GetProcessHeap(), 0,
1144 sizeof(WINHELP_LINE) + textlen);
1145 if (!line) return FALSE;
1147 line->next = 0;
1148 part = &line->first_part;
1149 ptr = (char*)line + sizeof(WINHELP_LINE);
1151 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1152 line->rect.bottom = line->rect.top;
1153 line->rect.left = space->cx;
1154 line->rect.right = space->cx;
1156 if (**linep) *linep = &(**linep)->next;
1157 **linep = line;
1158 space->cy = 0;
1160 else /* Same line */
1162 line = **linep;
1164 if (*line_ascent < ascent)
1166 WINHELP_LINE_PART *p;
1167 for (p = &line->first_part; p; p = p->next)
1169 p->rect.top += ascent - *line_ascent;
1170 p->rect.bottom += ascent - *line_ascent;
1172 line->rect.bottom += ascent - *line_ascent;
1173 *line_ascent = ascent;
1176 part = HeapAlloc(GetProcessHeap(), 0,
1177 sizeof(WINHELP_LINE_PART) + textlen);
1178 if (!part) return FALSE;
1179 **partp = part;
1180 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1183 memcpy(ptr, text, textlen);
1184 part->cookie = hlp_line_part_text;
1185 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1186 part->rect.right = part->rect.left + textsize->cx;
1187 line->rect.right = part->rect.right;
1188 part->rect.top =
1189 ((*partp) ? line->rect.top : line->rect.bottom) + *line_ascent - ascent;
1190 part->rect.bottom = part->rect.top + textsize->cy;
1191 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1192 part->u.text.lpsText = ptr;
1193 part->u.text.wTextLen = textlen;
1194 part->u.text.hFont = font;
1195 part->u.text.color = color;
1196 part->u.text.wUnderline = underline;
1198 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1199 part->u.text.wTextLen,
1200 part->u.text.wTextLen,
1201 part->u.text.lpsText,
1202 part->u.text.wTextLen,
1203 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1205 part->link = link;
1206 if (link) link->wRefCount++;
1208 part->next = 0;
1209 *partp = &part->next;
1211 space->cx = 0;
1213 return TRUE;
1216 /***********************************************************************
1218 * WINHELP_AppendGfxObject
1220 static WINHELP_LINE_PART* WINHELP_AppendGfxObject(WINHELP_LINE ***linep, WINHELP_LINE_PART ***partp,
1221 LPSIZE space, LPSIZE gfxSize,
1222 HLPFILE_LINK *link, unsigned pos)
1224 WINHELP_LINE *line;
1225 WINHELP_LINE_PART *part;
1226 LPSTR ptr;
1228 if (!*partp || pos == 1) /* New line */
1230 line = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE));
1231 if (!line) return NULL;
1233 line->next = NULL;
1234 part = &line->first_part;
1236 line->rect.top = (**linep ? (**linep)->rect.bottom : 0) + space->cy;
1237 line->rect.bottom = line->rect.top;
1238 line->rect.left = space->cx;
1239 line->rect.right = space->cx;
1241 if (**linep) *linep = &(**linep)->next;
1242 **linep = line;
1243 space->cy = 0;
1244 ptr = (char*)line + sizeof(WINHELP_LINE);
1246 else /* Same line */
1248 if (pos == 2) WINE_FIXME("Left alignment not handled\n");
1249 line = **linep;
1251 part = HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART));
1252 if (!part) return NULL;
1253 **partp = part;
1254 ptr = (char*)part + sizeof(WINHELP_LINE_PART);
1257 /* part->cookie should be set by caller (image or metafile) */
1258 part->rect.left = line->rect.right + (*partp ? space->cx : 0);
1259 part->rect.right = part->rect.left + gfxSize->cx;
1260 line->rect.right = part->rect.right;
1261 part->rect.top = (*partp) ? line->rect.top : line->rect.bottom;
1262 part->rect.bottom = part->rect.top + gfxSize->cy;
1263 line->rect.bottom = max(line->rect.bottom, part->rect.bottom);
1265 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1266 part->rect.left, part->rect.top, part->rect.right, part->rect.bottom);
1268 part->link = link;
1269 if (link) link->wRefCount++;
1271 part->next = NULL;
1272 *partp = &part->next;
1274 space->cx = 0;
1276 return part;
1280 /***********************************************************************
1282 * WINHELP_SplitLines
1284 static BOOL WINHELP_SplitLines(HWND hWnd, LPSIZE newsize)
1286 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1287 HLPFILE_PARAGRAPH *p;
1288 WINHELP_LINE **line = &win->first_line;
1289 WINHELP_LINE_PART **part = 0;
1290 INT line_ascent = 0;
1291 SIZE space;
1292 RECT rect;
1293 HDC hDc;
1295 if (newsize) newsize->cx = newsize->cy = 0;
1297 if (!win->page) return TRUE;
1299 WINHELP_DeleteLines(win);
1301 GetClientRect(hWnd, &rect);
1303 rect.top += INTERNAL_BORDER_WIDTH;
1304 rect.left += INTERNAL_BORDER_WIDTH;
1305 rect.right -= INTERNAL_BORDER_WIDTH;
1306 rect.bottom -= INTERNAL_BORDER_WIDTH;
1308 space.cy = rect.top;
1309 space.cx = rect.left;
1311 hDc = GetDC(hWnd);
1313 for (p = win->page->first_paragraph; p; p = p->next)
1315 switch (p->cookie)
1317 case para_normal_text:
1318 case para_debug_text:
1320 TEXTMETRIC tm;
1321 SIZE textsize = {0, 0};
1322 LPCSTR text = p->u.text.lpszText;
1323 UINT indent = 0;
1324 UINT len = strlen(text);
1325 unsigned underline = 0;
1327 HFONT hFont = 0;
1328 COLORREF color = RGB(0, 0, 0);
1330 if (p->u.text.wFont < win->page->file->numFonts)
1332 HLPFILE* hlpfile = win->page->file;
1334 if (!hlpfile->fonts[p->u.text.wFont].hFont)
1335 hlpfile->fonts[p->u.text.wFont].hFont = CreateFontIndirect(&hlpfile->fonts[p->u.text.wFont].LogFont);
1336 hFont = hlpfile->fonts[p->u.text.wFont].hFont;
1337 color = hlpfile->fonts[p->u.text.wFont].color;
1339 else
1341 UINT wFont = (p->u.text.wFont < win->fonts_len) ? p->u.text.wFont : 0;
1343 hFont = win->fonts[wFont];
1346 if (p->link && p->link->bClrChange)
1348 underline = (p->link->cookie == hlp_link_popup) ? 3 : 1;
1349 color = RGB(0, 0x80, 0);
1351 if (p->cookie == para_debug_text) color = RGB(0xff, 0, 0);
1353 SelectObject(hDc, hFont);
1355 GetTextMetrics(hDc, &tm);
1357 if (p->u.text.wIndent)
1359 indent = p->u.text.wIndent * 5 * tm.tmAveCharWidth;
1360 if (!part)
1361 space.cx = rect.left + indent - 2 * tm.tmAveCharWidth;
1364 if (p->u.text.wVSpace)
1366 part = 0;
1367 space.cx = rect.left + indent;
1368 space.cy += (p->u.text.wVSpace - 1) * tm.tmHeight;
1371 if (p->u.text.wHSpace)
1373 space.cx += p->u.text.wHSpace * 2 * tm.tmAveCharWidth;
1376 WINE_TRACE("splitting text %s\n", text);
1378 while (len)
1380 INT free_width = rect.right - (part ? (*line)->rect.right : rect.left) - space.cx;
1381 UINT low = 0, curr = len, high = len, textlen = 0;
1383 if (free_width > 0)
1385 while (1)
1387 GetTextExtentPoint(hDc, text, curr, &textsize);
1389 if (textsize.cx <= free_width) low = curr;
1390 else high = curr;
1392 if (high <= low + 1) break;
1394 if (textsize.cx) curr = (curr * free_width) / textsize.cx;
1395 if (curr <= low) curr = low + 1;
1396 else if (curr >= high) curr = high - 1;
1398 textlen = low;
1399 while (textlen && text[textlen] && text[textlen] != ' ') textlen--;
1401 if (!part && !textlen) textlen = max(low, 1);
1403 if (free_width <= 0 || !textlen)
1405 part = 0;
1406 space.cx = rect.left + indent;
1407 space.cx = min(space.cx, rect.right - rect.left - 1);
1408 continue;
1411 WINE_TRACE("\t => %d %*s\n", textlen, textlen, text);
1413 if (!WINHELP_AppendText(&line, &part, &space, &textsize,
1414 &line_ascent, tm.tmAscent,
1415 text, textlen, hFont, color, p->link, underline) ||
1416 (!newsize && (*line)->rect.bottom > rect.bottom))
1418 ReleaseDC(hWnd, hDc);
1419 return FALSE;
1422 if (newsize)
1423 newsize->cx = max(newsize->cx, (*line)->rect.right + INTERNAL_BORDER_WIDTH);
1425 len -= textlen;
1426 text += textlen;
1427 if (text[0] == ' ') text++, len--;
1430 break;
1431 case para_bitmap:
1432 case para_metafile:
1434 SIZE gfxSize;
1435 INT free_width;
1436 WINHELP_LINE_PART* ref_part;
1438 if (p->u.gfx.pos & 0x8000)
1440 space.cx = rect.left;
1441 if (*line)
1442 space.cy += (*line)->rect.bottom - (*line)->rect.top;
1443 part = 0;
1446 if (p->cookie == para_bitmap)
1448 DIBSECTION dibs;
1450 GetObject(p->u.gfx.u.bmp.hBitmap, sizeof(dibs), &dibs);
1451 gfxSize.cx = dibs.dsBm.bmWidth;
1452 gfxSize.cy = dibs.dsBm.bmHeight;
1454 else gfxSize = p->u.gfx.u.mf.mfSize;
1456 free_width = rect.right - ((part && *line) ? (*line)->rect.right : rect.left) - space.cx;
1457 if (free_width <= 0)
1459 part = NULL;
1460 space.cx = rect.left;
1461 space.cx = min(space.cx, rect.right - rect.left - 1);
1463 ref_part = WINHELP_AppendGfxObject(&line, &part, &space, &gfxSize,
1464 p->link, p->u.gfx.pos);
1465 if (!ref_part || (!newsize && (*line)->rect.bottom > rect.bottom))
1467 return FALSE;
1469 if (p->cookie == para_bitmap)
1471 ref_part->cookie = hlp_line_part_bitmap;
1472 ref_part->u.bitmap.hBitmap = p->u.gfx.u.bmp.hBitmap;
1474 else
1476 ref_part->cookie = hlp_line_part_metafile;
1477 ref_part->u.metafile.hMetaFile = p->u.gfx.u.mf.hMetaFile;
1480 break;
1484 if (newsize)
1485 newsize->cy = (*line)->rect.bottom + INTERNAL_BORDER_WIDTH;
1487 ReleaseDC(hWnd, hDc);
1488 return TRUE;
1491 /***********************************************************************
1493 * WINHELP_CheckPopup
1495 static void WINHELP_CheckPopup(UINT msg)
1497 if (!Globals.hPopupWnd) return;
1499 switch (msg)
1501 case WM_COMMAND:
1502 case WM_LBUTTONDOWN:
1503 case WM_MBUTTONDOWN:
1504 case WM_RBUTTONDOWN:
1505 case WM_NCLBUTTONDOWN:
1506 case WM_NCMBUTTONDOWN:
1507 case WM_NCRBUTTONDOWN:
1508 DestroyWindow(Globals.hPopupWnd);
1509 Globals.hPopupWnd = 0;
1513 /***********************************************************************
1515 * WINHELP_DeleteLines
1517 static void WINHELP_DeleteLines(WINHELP_WINDOW *win)
1519 WINHELP_LINE *line, *next_line;
1520 WINHELP_LINE_PART *part, *next_part;
1521 for (line = win->first_line; line; line = next_line)
1523 next_line = line->next;
1524 for (part = &line->first_part; part; part = next_part)
1526 next_part = part->next;
1527 HLPFILE_FreeLink(part->link);
1528 HeapFree(GetProcessHeap(), 0, part);
1531 win->first_line = 0;
1534 /***********************************************************************
1536 * WINHELP_DeleteWindow
1538 static void WINHELP_DeleteWindow(WINHELP_WINDOW* win)
1540 WINHELP_WINDOW** w;
1541 int i;
1542 WINHELP_BUTTON* b;
1543 WINHELP_BUTTON* bp;
1545 for (w = &Globals.win_list; *w; w = &(*w)->next)
1547 if (*w == win)
1549 *w = win->next;
1550 break;
1554 for (b = win->first_button; b; b = bp)
1556 DestroyWindow(b->hWnd);
1557 bp = b->next;
1558 HeapFree(GetProcessHeap(), 0, b);
1561 if (win->hShadowWnd) DestroyWindow(win->hShadowWnd);
1562 if (win->hHistoryWnd) DestroyWindow(win->hHistoryWnd);
1564 for (i = 0; i < win->histIndex; i++)
1566 HLPFILE_FreeHlpFile(win->history[i]->file);
1569 for (i = 0; i < win->backIndex; i++)
1570 HLPFILE_FreeHlpFile(win->back[i]->file);
1572 if (win->page) HLPFILE_FreeHlpFile(win->page->file);
1573 WINHELP_DeleteLines(win);
1574 HeapFree(GetProcessHeap(), 0, win);
1577 /***********************************************************************
1579 * WINHELP_InitFonts
1581 static void WINHELP_InitFonts(HWND hWnd)
1583 WINHELP_WINDOW *win = (WINHELP_WINDOW*) GetWindowLong(hWnd, 0);
1584 LOGFONT logfontlist[] = {
1585 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1586 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1587 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1588 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1589 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1590 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1591 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1592 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1594 static HFONT fonts[FONTS_LEN];
1595 static BOOL init = 0;
1597 win->fonts_len = FONTS_LEN;
1598 win->fonts = fonts;
1600 if (!init)
1602 INT i;
1604 for (i = 0; i < FONTS_LEN; i++)
1606 fonts[i] = CreateFontIndirect(&logfontlist[i]);
1609 init = 1;
1613 /***********************************************************************
1615 * WINHELP_MessageBoxIDS
1617 INT WINHELP_MessageBoxIDS(UINT ids_text, UINT ids_title, WORD type)
1619 CHAR text[MAX_STRING_LEN];
1620 CHAR title[MAX_STRING_LEN];
1622 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1623 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1625 return MessageBox(0, text, title, type);
1628 /***********************************************************************
1630 * MAIN_MessageBoxIDS_s
1632 INT WINHELP_MessageBoxIDS_s(UINT ids_text, LPCSTR str, UINT ids_title, WORD type)
1634 CHAR text[MAX_STRING_LEN];
1635 CHAR title[MAX_STRING_LEN];
1636 CHAR newtext[MAX_STRING_LEN + MAX_PATHNAME_LEN];
1638 LoadString(Globals.hInstance, ids_text, text, sizeof(text));
1639 LoadString(Globals.hInstance, ids_title, title, sizeof(title));
1640 wsprintf(newtext, text, str);
1642 return MessageBox(0, newtext, title, type);
1645 /******************************************************************
1646 * WINHELP_IsOverLink
1650 WINHELP_LINE_PART* WINHELP_IsOverLink(WINHELP_WINDOW* win, WPARAM wParam, LPARAM lParam)
1652 POINT mouse;
1653 WINHELP_LINE *line;
1654 WINHELP_LINE_PART *part;
1655 int scroll_pos = GetScrollPos(win->hMainWnd, SB_VERT);
1657 mouse.x = LOWORD(lParam);
1658 mouse.y = HIWORD(lParam);
1659 for (line = win->first_line; line; line = line->next)
1661 for (part = &line->first_part; part; part = part->next)
1663 if (part->link &&
1664 part->link->lpszString &&
1665 part->rect.left <= mouse.x &&
1666 part->rect.right >= mouse.x &&
1667 part->rect.top <= mouse.y + scroll_pos &&
1668 part->rect.bottom >= mouse.y + scroll_pos)
1670 return part;
1675 return NULL;