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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
35 #include "winhelp_res.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
)
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
);
82 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s
, lpszFile
, STID_WHERROR
, MB_OK
);
83 if (Globals
.win_list
) return NULL
;
88 /******************************************************************
89 * WINHELP_GetWindowInfo
93 HLPFILE_WINDOWINFO
* WINHELP_GetWindowInfo(HLPFILE
* hlpfile
, LPCSTR name
)
95 static HLPFILE_WINDOWINFO mwi
;
98 if (!name
|| !name
[0])
99 name
= Globals
.active_win
->lpszName
;
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
);
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
;
121 mwi
.win_style
= WS_OVERLAPPEDWINDOW
;
122 mwi
.sr_color
= mwi
.sr_color
= 0xFFFFFF;
127 /******************************************************************
128 * HLPFILE_GetPopupWindowInfo
132 static HLPFILE_WINDOWINFO
* WINHELP_GetPopupWindowInfo(HLPFILE
* hlpfile
, HWND hParentWnd
, POINT
* mouse
)
134 static HLPFILE_WINDOWINFO wi
;
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 */
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);
152 wi
.win_style
= WS_POPUPWINDOW
;
153 wi
.sr_color
= wi
.sr_color
= 0xFFFFFF;
158 /***********************************************************************
162 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
167 char* wndname
= "main";
170 Globals
.hInstance
= hInstance
;
173 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
177 if (*cmdline
++ == ' ') continue;
180 if (option
) cmdline
++;
181 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
187 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
188 if (*cmdline
) *cmdline
++ = '\0';
189 lHash
= HLPFILE_Hash(topic_id
);
194 Globals
.wVersion
= option
- '0';
199 Globals
.isBook
= FALSE
;
203 WINE_FIXME("Unsupported cmd line: %s\n", cmdline
);
208 /* Create primary window */
209 if (!WINHELP_RegisterWinClasses())
211 WINE_FIXME("Couldn't register classes\n");
218 if ((*cmdline
== '"') && (ptr
= strchr(cmdline
+1, '"')))
223 if ((ptr
= strchr(cmdline
, '>')))
228 hlpfile
= WINHELP_LookupHelpFile(cmdline
);
229 if (!hlpfile
) return 0;
232 WINHELP_CreateHelpWindowByHash(hlpfile
, lHash
,
233 WINHELP_GetWindowInfo(hlpfile
, wndname
), show
);
236 while (GetMessage(&msg
, 0, 0, 0))
238 TranslateMessage(&msg
);
239 DispatchMessage(&msg
);
241 for (dll
= Globals
.dlls
; dll
; dll
= dll
->next
)
243 if (dll
->class & DC_INITTERM
) dll
->handler(DW_TERM
, 0, 0);
248 /***********************************************************************
252 static BOOL
WINHELP_RegisterWinClasses(void)
254 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
, class_history
;
256 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
257 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
258 class_main
.cbClsExtra
= 0;
259 class_main
.cbWndExtra
= sizeof(LONG
);
260 class_main
.hInstance
= Globals
.hInstance
;
261 class_main
.hIcon
= LoadIcon(0, IDI_APPLICATION
);
262 class_main
.hCursor
= LoadCursor(0, IDC_ARROW
);
263 class_main
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
264 class_main
.lpszMenuName
= 0;
265 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
267 class_button_box
= class_main
;
268 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
269 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
270 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
272 class_text
= class_main
;
273 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
274 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
276 class_shadow
= class_main
;
277 class_shadow
.lpfnWndProc
= WINHELP_ShadowWndProc
;
278 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
279 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
281 class_history
= class_main
;
282 class_history
.lpfnWndProc
= WINHELP_HistoryWndProc
;
283 class_history
.lpszClassName
= HISTORY_WIN_CLASS_NAME
;
285 return (RegisterClass(&class_main
) &&
286 RegisterClass(&class_button_box
) &&
287 RegisterClass(&class_text
) &&
288 RegisterClass(&class_shadow
) &&
289 RegisterClass(&class_history
));
300 } WINHELP
,*LPWINHELP
;
302 /******************************************************************
303 * WINHELP_HandleCommand
307 static LRESULT
WINHELP_HandleCommand(HWND hSrcWnd
, LPARAM lParam
)
309 COPYDATASTRUCT
* cds
= (COPYDATASTRUCT
*)lParam
;
312 if (cds
->dwData
!= 0xA1DE505)
314 WINE_FIXME("Wrong magic number (%08lx)\n", cds
->dwData
);
318 wh
= (WINHELP
*)cds
->lpData
;
322 char* ptr
= (wh
->ofsFilename
) ? (LPSTR
)wh
+ wh
->ofsFilename
: NULL
;
324 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
325 wh
->size
, wh
->command
, wh
->data
, ptr
);
331 MACRO_JumpContext(ptr
, "main", wh
->data
);
340 MACRO_JumpContents(ptr
, "main");
343 case HELP_HELPONHELP
:
346 /* case HELP_SETINDEX: */
347 case HELP_SETCONTENTS
:
350 MACRO_SetContents(ptr
, wh
->data
);
353 case HELP_CONTEXTPOPUP
:
356 MACRO_PopupContext(ptr
, wh
->data
);
359 /* case HELP_FORCEFILE:*/
360 /* case HELP_CONTEXTMENU: */
362 /* in fact, should be the topic dialog box */
365 MACRO_JumpHash(ptr
, "main", 0);
368 /* case HELP_WM_HELP: */
369 /* case HELP_SETPOPUP_POS: */
371 /* case HELP_COMMAND: */
372 /* case HELP_PARTIALKEY: */
373 /* case HELP_MULTIKEY: */
374 /* case HELP_SETWINPOS: */
375 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh
->command
);
382 /******************************************************************
383 * WINHELP_ReuseWindow
387 static BOOL
WINHELP_ReuseWindow(WINHELP_WINDOW
* win
, WINHELP_WINDOW
* oldwin
,
388 HLPFILE_PAGE
* page
, int nCmdShow
)
392 win
->hMainWnd
= oldwin
->hMainWnd
;
393 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
394 win
->hTextWnd
= oldwin
->hTextWnd
;
395 win
->hHistoryWnd
= oldwin
->hHistoryWnd
;
396 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= oldwin
->hHistoryWnd
= 0;
398 SetWindowLong(win
->hMainWnd
, 0, (LONG
)win
);
399 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
)win
);
400 SetWindowLong(win
->hTextWnd
, 0, (LONG
)win
);
401 SetWindowLong(win
->hHistoryWnd
, 0, (LONG
)win
);
403 WINHELP_InitFonts(win
->hMainWnd
);
406 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
408 WINHELP_SetupText(win
->hTextWnd
);
409 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
410 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
411 ShowWindow(win
->hMainWnd
, nCmdShow
);
412 UpdateWindow(win
->hTextWnd
);
414 if (!(win
->info
->win_style
& WS_POPUP
))
418 memcpy(win
->history
, oldwin
->history
, sizeof(win
->history
));
419 win
->histIndex
= oldwin
->histIndex
;
421 /* FIXME: when using back, we shouldn't update the history... */
425 for (i
= 0; i
< win
->histIndex
; i
++)
426 if (win
->history
[i
] == page
) break;
428 /* if the new page is already in the history, do nothing */
429 if (i
== win
->histIndex
)
431 num
= sizeof(win
->history
) / sizeof(win
->history
[0]);
432 if (win
->histIndex
== num
)
434 /* we're full, remove latest entry */
435 HLPFILE_FreeHlpFile(win
->history
[0]->file
);
436 memmove(&win
->history
[0], &win
->history
[1],
437 (num
- 1) * sizeof(win
->history
[0]));
440 win
->history
[win
->histIndex
++] = page
;
441 page
->file
->wRefCount
++;
442 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
446 memcpy(win
->back
, oldwin
->back
, sizeof(win
->back
));
447 win
->backIndex
= oldwin
->backIndex
;
451 num
= sizeof(win
->back
) / sizeof(win
->back
[0]);
452 if (win
->backIndex
== num
)
454 /* we're full, remove latest entry */
455 HLPFILE_FreeHlpFile(win
->back
[0]->file
);
456 memmove(&win
->back
[0], &win
->back
[1],
457 (num
- 1) * sizeof(win
->back
[0]));
460 win
->back
[win
->backIndex
++] = page
;
461 page
->file
->wRefCount
++;
465 win
->backIndex
= win
->histIndex
= 0;
467 oldwin
->histIndex
= oldwin
->backIndex
= 0;
468 WINHELP_DeleteWindow(oldwin
);
472 /***********************************************************************
474 * WINHELP_CreateHelpWindow
476 BOOL
WINHELP_CreateHelpWindow(HLPFILE_PAGE
* page
, HLPFILE_WINDOWINFO
* wi
,
479 WINHELP_WINDOW
*win
, *oldwin
;
484 bPrimary
= !lstrcmpi(wi
->name
, "main");
485 bPopup
= wi
->win_style
& WS_POPUP
;
487 /* Initialize WINHELP_WINDOW struct */
488 win
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
489 sizeof(WINHELP_WINDOW
) + strlen(wi
->name
) + 1);
490 if (!win
) return FALSE
;
492 win
->next
= Globals
.win_list
;
493 Globals
.win_list
= win
;
495 win
->lpszName
= (char*)win
+ sizeof(WINHELP_WINDOW
);
496 lstrcpy((char*)win
->lpszName
, wi
->name
);
500 win
->hArrowCur
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
501 win
->hHandCur
= LoadCursorA(0, (LPSTR
)IDC_HAND
);
505 Globals
.active_win
= win
;
507 /* Initialize default pushbuttons */
508 if (bPrimary
&& page
)
510 CHAR buffer
[MAX_STRING_LEN
];
512 LoadString(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
513 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
514 LoadString(Globals
.hInstance
, STID_SEARCH
,buffer
, sizeof(buffer
));
515 MACRO_CreateButton("BTN_SEARCH", buffer
, "Search()");
516 LoadString(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
517 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
518 LoadString(Globals
.hInstance
, STID_HISTORY
, buffer
, sizeof(buffer
));
519 MACRO_CreateButton("BTN_HISTORY", buffer
, "History()");
520 LoadString(Globals
.hInstance
, STID_TOPICS
, buffer
, sizeof(buffer
));
521 MACRO_CreateButton("BTN_TOPICS", buffer
, "Finder()");
524 /* Initialize file specific pushbuttons */
525 if (!(wi
->win_style
& WS_POPUP
) && page
)
527 HLPFILE_MACRO
*macro
;
528 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
529 MACRO_ExecuteMacro(macro
->lpszMacro
);
531 for (macro
= page
->first_macro
; macro
; macro
= macro
->next
)
532 MACRO_ExecuteMacro(macro
->lpszMacro
);
535 /* Reuse existing window */
538 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
540 if (!lstrcmpi(oldwin
->lpszName
, wi
->name
))
542 return WINHELP_ReuseWindow(win
, oldwin
, page
, nCmdShow
);
547 win
->histIndex
= win
->backIndex
= 1;
548 win
->history
[0] = win
->back
[0] = page
;
549 page
->file
->wRefCount
+= 2;
550 strcpy(wi
->caption
, page
->file
->lpszTitle
);
554 hWnd
= CreateWindow(bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
556 bPrimary
? WS_OVERLAPPEDWINDOW
: wi
->win_style
,
557 wi
->origin
.x
, wi
->origin
.y
, wi
->size
.cx
, wi
->size
.cy
,
558 NULL
, bPrimary
? LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(MAIN_MENU
)) : 0,
559 Globals
.hInstance
, win
);
561 ShowWindow(hWnd
, nCmdShow
);
567 /***********************************************************************
569 * WINHELP_CreateHelpWindowByHash
571 BOOL
WINHELP_CreateHelpWindowByHash(HLPFILE
* hlpfile
, LONG lHash
,
572 HLPFILE_WINDOWINFO
* wi
, int nCmdShow
)
574 HLPFILE_PAGE
* page
= NULL
;
577 page
= lHash
? HLPFILE_PageByHash(hlpfile
, lHash
) :
578 HLPFILE_Contents(hlpfile
);
579 if (page
) page
->file
->wRefCount
++;
580 return WINHELP_CreateHelpWindow(page
, wi
, nCmdShow
);
583 /***********************************************************************
585 * WINHELP_MainWndProc
587 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
590 WINHELP_BUTTON
*button
;
591 RECT rect
, button_box_rect
;
592 INT text_top
, curPos
, min
, max
, dy
, keyDelta
;
594 WINHELP_CheckPopup(msg
);
599 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
600 SetWindowLong(hWnd
, 0, (LONG
) win
);
601 win
->hMainWnd
= hWnd
;
605 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
607 /* Create button box and text Window */
608 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
609 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
611 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
612 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
616 case WM_WINDOWPOSCHANGED
:
617 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
618 GetClientRect(hWnd
, &rect
);
620 /* Update button box and text Window */
621 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
623 rect
.right
- rect
.left
,
624 rect
.bottom
- rect
.top
, 0);
626 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
627 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
629 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
631 rect
.right
- rect
.left
,
632 rect
.bottom
- text_top
, 0);
637 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
641 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
642 case MNID_FILE_PRINT
: MACRO_Print(); break;
643 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
644 case MNID_FILE_EXIT
: MACRO_Exit(); break;
647 case MNID_EDIT_COPYDLG
: MACRO_CopyDialog(); break;
648 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
651 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
654 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
655 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
656 case MNID_HELP_ABOUT
: MACRO_About(); break;
657 case MNID_HELP_WINE
: ShellAbout(hWnd
, "WINE", "Help", 0); break;
661 for (button
= win
->first_button
; button
; button
= button
->next
)
662 if (wParam
== button
->wParam
) break;
664 MACRO_ExecuteMacro(button
->lpszMacro
);
666 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED
, 0x121, MB_OK
);
671 if (Globals
.hPopupWnd
) DestroyWindow(Globals
.hPopupWnd
);
674 return WINHELP_HandleCommand((HWND
)wParam
, lParam
);
683 keyDelta
= GetSystemMetrics(SM_CXVSCROLL
);
685 keyDelta
= -keyDelta
;
689 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
690 curPos
= GetScrollPos(win
->hTextWnd
, SB_VERT
);
691 GetScrollRange(win
->hTextWnd
, SB_VERT
, &min
, &max
);
695 GetClientRect(win
->hTextWnd
, &rect
);
696 keyDelta
= (rect
.bottom
- rect
.top
) / 2;
697 if (wParam
== VK_PRIOR
)
698 keyDelta
= -keyDelta
;
704 else if (curPos
< min
)
707 dy
= GetScrollPos(win
->hTextWnd
, SB_VERT
) - curPos
;
708 SetScrollPos(win
->hTextWnd
, SB_VERT
, curPos
, TRUE
);
709 ScrollWindow(win
->hTextWnd
, 0, dy
, NULL
, NULL
);
710 UpdateWindow(win
->hTextWnd
);
719 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
722 /***********************************************************************
724 * WINHELP_ButtonBoxWndProc
726 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
730 WINHELP_BUTTON
*button
;
734 WINHELP_CheckPopup(msg
);
739 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
740 SetWindowLong(hWnd
, 0, (LONG
) win
);
741 win
->hButtonBoxWnd
= hWnd
;
744 case WM_WINDOWPOSCHANGING
:
745 winpos
= (WINDOWPOS
*) lParam
;
746 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
751 for (button
= win
->first_button
; button
; button
= button
->next
)
757 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
758 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
760 hWnd
, (HMENU
) button
->wParam
,
761 Globals
.hInstance
, 0);
763 if (Globals
.button_proc
== NULL
)
764 Globals
.button_proc
= (WNDPROC
) GetWindowLongPtr(button
->hWnd
, GWLP_WNDPROC
);
765 SetWindowLongPtr(button
->hWnd
, GWLP_WNDPROC
, (LONG_PTR
) WINHELP_ButtonWndProc
);
768 hDc
= GetDC(button
->hWnd
);
769 GetTextExtentPoint(hDc
, button
->lpszName
,
770 lstrlen(button
->lpszName
), &textsize
);
771 ReleaseDC(button
->hWnd
, hDc
);
773 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
774 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
779 for (button
= win
->first_button
; button
; button
= button
->next
)
781 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
783 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
786 x
= 0, y
+= button_size
.cy
;
788 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
792 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
803 return SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
808 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
811 /***********************************************************************
813 * WINHELP_ButtonWndProc
815 static LRESULT CALLBACK
WINHELP_ButtonWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
817 if (msg
== WM_KEYDOWN
)
826 return SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
830 return CallWindowProc(Globals
.button_proc
, hWnd
, msg
, wParam
, lParam
);
833 /***********************************************************************
835 * WINHELP_TextWndProc
837 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
841 WINHELP_LINE_PART
*part
;
850 if (msg
!= WM_LBUTTONDOWN
)
851 WINHELP_CheckPopup(msg
);
856 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
857 SetWindowLong(hWnd
, 0, (LONG
) win
);
858 win
->hTextWnd
= hWnd
;
859 if (win
->info
->win_style
& WS_POPUP
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
860 WINHELP_InitFonts(hWnd
);
864 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
866 /* Calculate vertical size and position of a popup window */
867 if (win
->info
->win_style
& WS_POPUP
)
870 RECT old_window_rect
;
871 RECT old_client_rect
;
872 SIZE old_window_size
;
873 SIZE old_client_size
;
874 SIZE new_client_size
;
875 SIZE new_window_size
;
877 GetWindowRect(hWnd
, &old_window_rect
);
878 origin
.x
= old_window_rect
.left
;
879 origin
.y
= old_window_rect
.top
;
880 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
881 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
883 GetClientRect(hWnd
, &old_client_rect
);
884 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
885 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
887 new_client_size
= old_client_size
;
888 WINHELP_SplitLines(hWnd
, &new_client_size
);
890 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
891 origin
.y
+= POPUP_YDISTANCE
;
893 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
895 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
896 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
899 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
,
900 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
901 new_window_size
.cx
, new_window_size
.cy
,
902 0, 0, Globals
.hInstance
, 0);
904 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
905 new_window_size
.cx
, new_window_size
.cy
,
907 SetWindowPos(win
->hShadowWnd
, hWnd
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
908 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
909 SetActiveWindow(hWnd
);
913 case WM_WINDOWPOSCHANGED
:
914 winpos
= (WINDOWPOS
*) lParam
;
916 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
922 UINT scrollLines
= 3;
923 int curPos
= GetScrollPos(hWnd
, SB_VERT
);
926 GetScrollRange(hWnd
, SB_VERT
, &min
, &max
);
928 SystemParametersInfo(SPI_GETWHEELSCROLLLINES
,0, &scrollLines
, 0);
929 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
930 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
931 wheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
932 if (abs(wheelDelta
) >= WHEEL_DELTA
&& scrollLines
) {
935 curPos
+= wheelDelta
;
938 else if (curPos
< min
)
941 dy
= GetScrollPos(hWnd
, SB_VERT
) - curPos
;
942 SetScrollPos(hWnd
, SB_VERT
, curPos
, TRUE
);
943 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
954 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
957 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
958 GetClientRect(hWnd
, &rect
);
960 switch (wParam
& 0xffff)
963 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
964 case SB_TOP
: CurPos
= Min
; break;
965 case SB_BOTTOM
: CurPos
= Max
; break;
966 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
967 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
968 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
969 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
970 default: update
= FALSE
;
976 else if (CurPos
< Min
)
978 dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
979 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
980 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
987 hDc
= BeginPaint(hWnd
, &ps
);
988 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
989 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
991 for (line
= win
->first_line
; line
; line
= line
->next
)
993 for (part
= &line
->first_part
; part
; part
= part
->next
)
995 switch (part
->cookie
)
997 case hlp_line_part_text
:
998 SelectObject(hDc
, part
->u
.text
.hFont
);
999 SetTextColor(hDc
, part
->u
.text
.color
);
1000 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
1001 part
->u
.text
.lpsText
, part
->u
.text
.wTextLen
);
1002 if (part
->u
.text
.wUnderline
)
1006 switch (part
->u
.text
.wUnderline
)
1008 case 1: /* simple */
1009 case 2: /* double */
1010 hPen
= CreatePen(PS_SOLID
, 1, part
->u
.text
.color
);
1012 case 3: /* dotted */
1013 hPen
= CreatePen(PS_DOT
, 1, part
->u
.text
.color
);
1016 WINE_FIXME("Unknow underline type\n");
1020 SelectObject(hDc
, hPen
);
1021 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
- 1, NULL
);
1022 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
- 1);
1023 if (part
->u
.text
.wUnderline
== 2)
1025 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
+ 1, NULL
);
1026 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
+ 1);
1031 case hlp_line_part_bitmap
:
1035 hMemDC
= CreateCompatibleDC(hDc
);
1036 SelectObject(hMemDC
, part
->u
.bitmap
.hBitmap
);
1037 BitBlt(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
1038 part
->rect
.right
- part
->rect
.left
, part
->rect
.bottom
- part
->rect
.top
,
1039 hMemDC
, 0, 0, SRCCOPY
);
1043 case hlp_line_part_metafile
:
1047 SetViewportOrgEx(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
, &pt
);
1048 PlayMetaFile(hDc
, part
->u
.metafile
.hMetaFile
);
1049 SetViewportOrgEx(hDc
, pt
.x
, pt
.y
, NULL
);
1056 EndPaint(hWnd
, &ps
);
1060 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1062 if (WINHELP_IsOverLink(win
, wParam
, lParam
))
1063 SetCursor(win
->hHandCur
); /* set to hand pointer cursor to indicate a link */
1065 SetCursor(win
->hArrowCur
); /* set to hand pointer cursor to indicate a link */
1069 case WM_LBUTTONDOWN
:
1070 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1072 hPopupWnd
= Globals
.hPopupWnd
;
1073 Globals
.hPopupWnd
= 0;
1075 part
= WINHELP_IsOverLink(win
, wParam
, lParam
);
1079 HLPFILE_WINDOWINFO
* wi
;
1081 mouse
.x
= LOWORD(lParam
);
1082 mouse
.y
= HIWORD(lParam
);
1084 if (part
->link
) switch (part
->link
->cookie
)
1087 hlpfile
= WINHELP_LookupHelpFile(part
->link
->lpszString
);
1088 if (part
->link
->window
== -1)
1090 else if ((part
->link
->window
>= 0) && (part
->link
->window
< hlpfile
->numWindows
))
1091 wi
= &hlpfile
->windows
[part
->link
->window
];
1094 WINE_WARN("link to window %d/%d\n", part
->link
->window
, hlpfile
->numWindows
);
1097 WINHELP_CreateHelpWindowByHash(hlpfile
, part
->link
->lHash
, wi
,
1100 case hlp_link_popup
:
1101 hlpfile
= WINHELP_LookupHelpFile(part
->link
->lpszString
);
1102 WINHELP_CreateHelpWindowByHash(hlpfile
, part
->link
->lHash
,
1103 WINHELP_GetPopupWindowInfo(hlpfile
, hWnd
, &mouse
),
1106 case hlp_link_macro
:
1107 MACRO_ExecuteMacro(part
->link
->lpszString
);
1110 WINE_FIXME("Unknown link cookie %d\n", part
->link
->cookie
);
1115 DestroyWindow(hPopupWnd
);
1119 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1121 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
1123 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
1125 WINHELP_DeleteWindow(win
);
1127 if (bExit
) MACRO_Exit();
1129 if (!Globals
.win_list
)
1134 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1137 /******************************************************************
1138 * WINHELP_HistoryWndProc
1142 static LRESULT CALLBACK
WINHELP_HistoryWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1144 WINHELP_WINDOW
* win
;
1154 win
= (WINHELP_WINDOW
*)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
1155 SetWindowLong(hWnd
, 0, (LONG
)win
);
1156 win
->hHistoryWnd
= hWnd
;
1159 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1161 GetTextMetrics(hDc
, &tm
);
1162 GetWindowRect(hWnd
, &r
);
1164 r
.right
= r
.left
+ 30 * tm
.tmAveCharWidth
;
1165 r
.bottom
= r
.top
+ (sizeof(win
->history
) / sizeof(win
->history
[0])) * tm
.tmHeight
;
1166 AdjustWindowRect(&r
, GetWindowLong(hWnd
, GWL_STYLE
), FALSE
);
1167 if (r
.left
< 0) {r
.right
-= r
.left
; r
.left
= 0;}
1168 if (r
.top
< 0) {r
.bottom
-= r
.top
; r
.top
= 0;}
1170 MoveWindow(hWnd
, r
.left
, r
.top
, r
.right
, r
.bottom
, TRUE
);
1171 ReleaseDC(hWnd
, hDc
);
1173 case WM_LBUTTONDOWN
:
1174 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1176 GetTextMetrics(hDc
, &tm
);
1177 i
= HIWORD(lParam
) / tm
.tmHeight
;
1178 if (i
< win
->histIndex
)
1179 WINHELP_CreateHelpWindow(win
->history
[i
], win
->info
, SW_SHOW
);
1180 ReleaseDC(hWnd
, hDc
);
1183 hDc
= BeginPaint(hWnd
, &ps
);
1184 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1185 GetTextMetrics(hDc
, &tm
);
1187 for (i
= 0; i
< win
->histIndex
; i
++)
1189 TextOut(hDc
, 0, i
* tm
.tmHeight
, win
->history
[i
]->lpszTitle
,
1190 strlen(win
->history
[i
]->lpszTitle
));
1192 EndPaint(hWnd
, &ps
);
1195 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1196 if (hWnd
== win
->hHistoryWnd
)
1197 win
->hHistoryWnd
= 0;
1200 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1203 /***********************************************************************
1205 * WINHELP_ShadowWndProc
1207 static LRESULT CALLBACK
WINHELP_ShadowWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1209 WINHELP_CheckPopup(msg
);
1210 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1213 /***********************************************************************
1217 static void WINHELP_SetupText(HWND hWnd
)
1219 HDC hDc
= GetDC(hWnd
);
1223 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
1224 if (!WINHELP_SplitLines(hWnd
, NULL
))
1226 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
1227 GetClientRect(hWnd
, &rect
);
1229 WINHELP_SplitLines(hWnd
, &newsize
);
1230 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
1234 SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
1235 SetScrollRange(hWnd
, SB_VERT
, 0, 0, FALSE
);
1238 ReleaseDC(hWnd
, hDc
);
1241 /***********************************************************************
1243 * WINHELP_AppendText
1245 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
1246 LPSIZE space
, LPSIZE textsize
,
1247 INT
*line_ascent
, INT ascent
,
1248 LPCSTR text
, UINT textlen
,
1249 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
,
1253 WINHELP_LINE_PART
*part
;
1256 if (!*partp
) /* New line */
1258 *line_ascent
= ascent
;
1260 line
= HeapAlloc(GetProcessHeap(), 0,
1261 sizeof(WINHELP_LINE
) + textlen
);
1262 if (!line
) return FALSE
;
1265 part
= &line
->first_part
;
1266 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
1268 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
1269 line
->rect
.bottom
= line
->rect
.top
;
1270 line
->rect
.left
= space
->cx
;
1271 line
->rect
.right
= space
->cx
;
1273 if (**linep
) *linep
= &(**linep
)->next
;
1277 else /* Same line */
1281 if (*line_ascent
< ascent
)
1283 WINHELP_LINE_PART
*p
;
1284 for (p
= &line
->first_part
; p
; p
= p
->next
)
1286 p
->rect
.top
+= ascent
- *line_ascent
;
1287 p
->rect
.bottom
+= ascent
- *line_ascent
;
1289 line
->rect
.bottom
+= ascent
- *line_ascent
;
1290 *line_ascent
= ascent
;
1293 part
= HeapAlloc(GetProcessHeap(), 0,
1294 sizeof(WINHELP_LINE_PART
) + textlen
);
1295 if (!part
) return FALSE
;
1297 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
1300 memcpy(ptr
, text
, textlen
);
1301 part
->cookie
= hlp_line_part_text
;
1302 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
1303 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
1304 line
->rect
.right
= part
->rect
.right
;
1306 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
1307 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
1308 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
1309 part
->u
.text
.lpsText
= ptr
;
1310 part
->u
.text
.wTextLen
= textlen
;
1311 part
->u
.text
.hFont
= font
;
1312 part
->u
.text
.color
= color
;
1313 part
->u
.text
.wUnderline
= underline
;
1315 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1316 part
->u
.text
.wTextLen
,
1317 part
->u
.text
.wTextLen
,
1318 part
->u
.text
.lpsText
,
1319 part
->u
.text
.wTextLen
,
1320 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1323 if (link
) link
->wRefCount
++;
1326 *partp
= &part
->next
;
1333 /***********************************************************************
1335 * WINHELP_AppendGfxObject
1337 static WINHELP_LINE_PART
* WINHELP_AppendGfxObject(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
1338 LPSIZE space
, LPSIZE gfxSize
,
1339 HLPFILE_LINK
*link
, unsigned pos
)
1342 WINHELP_LINE_PART
*part
;
1345 if (!*partp
|| pos
== 1) /* New line */
1347 line
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE
));
1348 if (!line
) return NULL
;
1351 part
= &line
->first_part
;
1353 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
1354 line
->rect
.bottom
= line
->rect
.top
;
1355 line
->rect
.left
= space
->cx
;
1356 line
->rect
.right
= space
->cx
;
1358 if (**linep
) *linep
= &(**linep
)->next
;
1361 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
1363 else /* Same line */
1365 if (pos
== 2) WINE_FIXME("Left alignment not handled\n");
1368 part
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART
));
1369 if (!part
) return NULL
;
1371 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
1374 /* part->cookie should be set by caller (image or metafile) */
1375 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
1376 part
->rect
.right
= part
->rect
.left
+ gfxSize
->cx
;
1377 line
->rect
.right
= part
->rect
.right
;
1378 part
->rect
.top
= (*partp
) ? line
->rect
.top
: line
->rect
.bottom
;
1379 part
->rect
.bottom
= part
->rect
.top
+ gfxSize
->cy
;
1380 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
1382 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1383 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1386 if (link
) link
->wRefCount
++;
1389 *partp
= &part
->next
;
1397 /***********************************************************************
1399 * WINHELP_SplitLines
1401 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
1403 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1404 HLPFILE_PARAGRAPH
*p
;
1405 WINHELP_LINE
**line
= &win
->first_line
;
1406 WINHELP_LINE_PART
**part
= 0;
1407 INT line_ascent
= 0;
1412 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
1414 if (!win
->page
) return TRUE
;
1416 WINHELP_DeleteLines(win
);
1418 GetClientRect(hWnd
, &rect
);
1420 rect
.top
+= INTERNAL_BORDER_WIDTH
;
1421 rect
.left
+= INTERNAL_BORDER_WIDTH
;
1422 rect
.right
-= INTERNAL_BORDER_WIDTH
;
1423 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
1425 space
.cy
= rect
.top
;
1426 space
.cx
= rect
.left
;
1430 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
1434 case para_normal_text
:
1435 case para_debug_text
:
1438 SIZE textsize
= {0, 0};
1439 LPCSTR text
= p
->u
.text
.lpszText
;
1441 UINT len
= strlen(text
);
1442 unsigned underline
= 0;
1445 COLORREF color
= RGB(0, 0, 0);
1447 if (p
->u
.text
.wFont
< win
->page
->file
->numFonts
)
1449 HLPFILE
* hlpfile
= win
->page
->file
;
1451 if (!hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
)
1452 hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
= CreateFontIndirect(&hlpfile
->fonts
[p
->u
.text
.wFont
].LogFont
);
1453 hFont
= hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
;
1454 color
= hlpfile
->fonts
[p
->u
.text
.wFont
].color
;
1458 UINT wFont
= (p
->u
.text
.wFont
< win
->fonts_len
) ? p
->u
.text
.wFont
: 0;
1460 hFont
= win
->fonts
[wFont
];
1463 if (p
->link
&& p
->link
->bClrChange
)
1465 underline
= (p
->link
->cookie
== hlp_link_popup
) ? 3 : 1;
1466 color
= RGB(0, 0x80, 0);
1468 if (p
->cookie
== para_debug_text
) color
= RGB(0xff, 0, 0);
1470 SelectObject(hDc
, hFont
);
1472 GetTextMetrics(hDc
, &tm
);
1474 if (p
->u
.text
.wIndent
)
1476 indent
= p
->u
.text
.wIndent
* 5 * tm
.tmAveCharWidth
;
1478 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
1481 if (p
->u
.text
.wVSpace
)
1484 space
.cx
= rect
.left
+ indent
;
1485 space
.cy
+= (p
->u
.text
.wVSpace
- 1) * tm
.tmHeight
;
1488 if (p
->u
.text
.wHSpace
)
1490 space
.cx
+= p
->u
.text
.wHSpace
* 2 * tm
.tmAveCharWidth
;
1493 WINE_TRACE("splitting text %s\n", text
);
1497 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1498 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
1504 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
1506 if (textsize
.cx
<= free_width
) low
= curr
;
1509 if (high
<= low
+ 1) break;
1511 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
1512 if (curr
<= low
) curr
= low
+ 1;
1513 else if (curr
>= high
) curr
= high
- 1;
1516 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
1518 if (!part
&& !textlen
) textlen
= max(low
, 1);
1520 if (free_width
<= 0 || !textlen
)
1523 space
.cx
= rect
.left
+ indent
;
1524 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1528 WINE_TRACE("\t => %d %*s\n", textlen
, textlen
, text
);
1530 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
1531 &line_ascent
, tm
.tmAscent
,
1532 text
, textlen
, hFont
, color
, p
->link
, underline
) ||
1533 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1535 ReleaseDC(hWnd
, hDc
);
1540 newsize
->cx
= max(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
1544 if (text
[0] == ' ') text
++, len
--;
1553 WINHELP_LINE_PART
* ref_part
;
1555 if (p
->u
.gfx
.pos
& 0x8000)
1557 space
.cx
= rect
.left
;
1559 space
.cy
+= (*line
)->rect
.bottom
- (*line
)->rect
.top
;
1563 if (p
->cookie
== para_bitmap
)
1567 GetObject(p
->u
.gfx
.u
.bmp
.hBitmap
, sizeof(dibs
), &dibs
);
1568 gfxSize
.cx
= dibs
.dsBm
.bmWidth
;
1569 gfxSize
.cy
= dibs
.dsBm
.bmHeight
;
1571 else gfxSize
= p
->u
.gfx
.u
.mf
.mfSize
;
1573 free_width
= rect
.right
- ((part
&& *line
) ? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1574 if (free_width
<= 0)
1577 space
.cx
= rect
.left
;
1578 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1580 ref_part
= WINHELP_AppendGfxObject(&line
, &part
, &space
, &gfxSize
,
1581 p
->link
, p
->u
.gfx
.pos
);
1582 if (!ref_part
|| (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1586 if (p
->cookie
== para_bitmap
)
1588 ref_part
->cookie
= hlp_line_part_bitmap
;
1589 ref_part
->u
.bitmap
.hBitmap
= p
->u
.gfx
.u
.bmp
.hBitmap
;
1593 ref_part
->cookie
= hlp_line_part_metafile
;
1594 ref_part
->u
.metafile
.hMetaFile
= p
->u
.gfx
.u
.mf
.hMetaFile
;
1602 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
1604 ReleaseDC(hWnd
, hDc
);
1608 /***********************************************************************
1610 * WINHELP_CheckPopup
1612 static void WINHELP_CheckPopup(UINT msg
)
1614 if (!Globals
.hPopupWnd
) return;
1619 case WM_LBUTTONDOWN
:
1620 case WM_MBUTTONDOWN
:
1621 case WM_RBUTTONDOWN
:
1622 case WM_NCLBUTTONDOWN
:
1623 case WM_NCMBUTTONDOWN
:
1624 case WM_NCRBUTTONDOWN
:
1625 DestroyWindow(Globals
.hPopupWnd
);
1626 Globals
.hPopupWnd
= 0;
1630 /***********************************************************************
1632 * WINHELP_DeleteLines
1634 static void WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
1636 WINHELP_LINE
*line
, *next_line
;
1637 WINHELP_LINE_PART
*part
, *next_part
;
1638 for (line
= win
->first_line
; line
; line
= next_line
)
1640 next_line
= line
->next
;
1641 for (part
= &line
->first_part
; part
; part
= next_part
)
1643 next_part
= part
->next
;
1644 HLPFILE_FreeLink(part
->link
);
1645 HeapFree(GetProcessHeap(), 0, part
);
1648 win
->first_line
= 0;
1651 /***********************************************************************
1653 * WINHELP_DeleteWindow
1655 static void WINHELP_DeleteWindow(WINHELP_WINDOW
* win
)
1662 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
1671 for (b
= win
->first_button
; b
; b
= bp
)
1673 DestroyWindow(b
->hWnd
);
1675 HeapFree(GetProcessHeap(), 0, b
);
1678 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
1679 if (win
->hHistoryWnd
) DestroyWindow(win
->hHistoryWnd
);
1681 for (i
= 0; i
< win
->histIndex
; i
++)
1683 HLPFILE_FreeHlpFile(win
->history
[i
]->file
);
1686 for (i
= 0; i
< win
->backIndex
; i
++)
1687 HLPFILE_FreeHlpFile(win
->back
[i
]->file
);
1689 if (win
->page
) HLPFILE_FreeHlpFile(win
->page
->file
);
1690 WINHELP_DeleteLines(win
);
1691 HeapFree(GetProcessHeap(), 0, win
);
1694 /***********************************************************************
1698 static void WINHELP_InitFonts(HWND hWnd
)
1700 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1701 LOGFONT logfontlist
[] = {
1702 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1703 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1704 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1705 {-12, 0, 0, 0, 400, 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 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1708 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1709 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1711 static HFONT fonts
[FONTS_LEN
];
1712 static BOOL init
= 0;
1714 win
->fonts_len
= FONTS_LEN
;
1721 for (i
= 0; i
< FONTS_LEN
; i
++)
1723 fonts
[i
] = CreateFontIndirect(&logfontlist
[i
]);
1730 /***********************************************************************
1732 * WINHELP_MessageBoxIDS
1734 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1736 CHAR text
[MAX_STRING_LEN
];
1737 CHAR title
[MAX_STRING_LEN
];
1739 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1740 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1742 return MessageBox(0, text
, title
, type
);
1745 /***********************************************************************
1747 * MAIN_MessageBoxIDS_s
1749 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1751 CHAR text
[MAX_STRING_LEN
];
1752 CHAR title
[MAX_STRING_LEN
];
1753 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1755 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1756 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1757 wsprintf(newtext
, text
, str
);
1759 return MessageBox(0, newtext
, title
, type
);
1762 /******************************************************************
1763 * WINHELP_IsOverLink
1767 WINHELP_LINE_PART
* WINHELP_IsOverLink(WINHELP_WINDOW
* win
, WPARAM wParam
, LPARAM lParam
)
1771 WINHELP_LINE_PART
*part
;
1772 int scroll_pos
= GetScrollPos(win
->hTextWnd
, SB_VERT
);
1774 mouse
.x
= LOWORD(lParam
);
1775 mouse
.y
= HIWORD(lParam
);
1776 for (line
= win
->first_line
; line
; line
= line
->next
)
1778 for (part
= &line
->first_part
; part
; part
= part
->next
)
1781 part
->link
->lpszString
&&
1782 part
->rect
.left
<= mouse
.x
&&
1783 part
->rect
.right
>= mouse
.x
&&
1784 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
1785 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)