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
29 #include "winhelp_res.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
35 static BOOL
WINHELP_RegisterWinClasses(void);
36 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
37 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
38 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
39 static void WINHELP_CheckPopup(UINT
);
40 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
41 static void WINHELP_InitFonts(HWND hWnd
);
42 static void WINHELP_DeleteLines(WINHELP_WINDOW
*);
43 static void WINHELP_DeleteWindow(WINHELP_WINDOW
*);
44 static void WINHELP_SetupText(HWND hWnd
);
45 static WINHELP_LINE_PART
* WINHELP_IsOverLink(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
47 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 0, 0};
49 static BOOL MacroTest
= FALSE
;
51 /***********************************************************************
55 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
60 Globals
.hInstance
= hInstance
;
63 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
67 if (*cmdline
++ == ' ') continue;
70 if (option
) cmdline
++;
71 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
77 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
78 if (*cmdline
) *cmdline
++ = '\0';
79 lHash
= HLPFILE_Hash(topic_id
);
84 Globals
.wVersion
= option
- '0';
93 /* Create primary window */
94 WINHELP_RegisterWinClasses();
95 WINHELP_CreateHelpWindowByHash(cmdline
, lHash
, "main", FALSE
, NULL
, NULL
, show
);
98 while (GetMessage(&msg
, 0, 0, 0))
100 TranslateMessage(&msg
);
101 DispatchMessage(&msg
);
106 /***********************************************************************
110 static BOOL
WINHELP_RegisterWinClasses(void)
112 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
;
114 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
115 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
116 class_main
.cbClsExtra
= 0;
117 class_main
.cbWndExtra
= sizeof(LONG
);
118 class_main
.hInstance
= Globals
.hInstance
;
119 class_main
.hIcon
= LoadIcon(0, IDI_APPLICATION
);
120 class_main
.hCursor
= LoadCursor(0, IDC_ARROW
);
121 class_main
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
122 class_main
.lpszMenuName
= 0;
123 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
125 class_button_box
= class_main
;
126 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
127 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
128 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
130 class_text
= class_main
;
131 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
132 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
134 class_shadow
= class_main
;
135 class_shadow
.lpfnWndProc
= DefWindowProc
;
136 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
137 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
139 return (RegisterClass(&class_main
) &&
140 RegisterClass(&class_button_box
) &&
141 RegisterClass(&class_text
) &&
142 RegisterClass(&class_shadow
));
145 /***********************************************************************
147 * WINHELP_CreateHelpWindow
150 static BOOL
WINHELP_CreateHelpWindow(HLPFILE_PAGE
* page
, LPCSTR lpszWindow
,
151 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
153 CHAR szCaption
[MAX_STRING_LEN
];
154 SIZE size
= {CW_USEDEFAULT
, 0/*CW_USEDEFAULT*/};
155 POINT origin
= {240, 0};
157 WINHELP_WINDOW
*win
, *oldwin
;
158 HLPFILE_MACRO
*macro
;
164 else if (!lpszWindow
|| !lpszWindow
[0])
165 lpszWindow
= Globals
.active_win
->lpszName
;
166 bPrimary
= lpszWindow
&& !lstrcmpi(lpszWindow
, "main");
168 /* Calculate horizontal size and position of a popup window */
172 GetWindowRect(hParentWnd
, &parent_rect
);
173 size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
174 size
.cy
= 10; /* need a non null value, so that border are taken into account while computing */
177 ClientToScreen(hParentWnd
, &origin
);
178 origin
.x
-= size
.cx
/ 2;
179 origin
.x
= min(origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - size
.cx
);
180 origin
.x
= max(origin
.x
, 0);
183 /* Initialize WINHELP_WINDOW struct */
184 win
= HeapAlloc(GetProcessHeap(), 0,
185 sizeof(WINHELP_WINDOW
) + (lpszWindow
? strlen(lpszWindow
) + 1 : 0));
186 if (!win
) return FALSE
;
188 win
->next
= Globals
.win_list
;
189 Globals
.win_list
= win
;
192 ptr
= (char*)win
+ sizeof(WINHELP_WINDOW
);
193 lstrcpy(ptr
, (LPSTR
) lpszWindow
);
196 else win
->lpszName
= NULL
;
199 win
->first_button
= 0;
202 win
->hButtonBoxWnd
= 0;
206 win
->hArrowCur
= LoadCursorA(0, IDC_ARROWA
);
207 win
->hHandCur
= LoadCursorA(0, IDC_HANDA
);
209 Globals
.active_win
= win
;
211 /* Initialize default pushbuttons */
212 if (MacroTest
&& !bPopup
)
213 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
214 if (bPrimary
&& page
)
216 CHAR buffer
[MAX_STRING_LEN
];
218 LoadString(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
219 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
220 LoadString(Globals
.hInstance
, STID_SEARCH
,buffer
, sizeof(buffer
));
221 MACRO_CreateButton("BTN_SEARCH", buffer
, "Search()");
222 LoadString(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
223 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
224 LoadString(Globals
.hInstance
, STID_HISTORY
, buffer
, sizeof(buffer
));
225 MACRO_CreateButton("BTN_HISTORY", buffer
, "History()");
226 LoadString(Globals
.hInstance
, STID_TOPICS
, buffer
, sizeof(buffer
));
227 MACRO_CreateButton("BTN_TOPICS", buffer
, "Finder()");
230 /* Initialize file specific pushbuttons */
232 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
233 MACRO_ExecuteMacro(macro
->lpszMacro
);
235 /* Reuse existing window */
237 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
238 if (oldwin
->lpszName
&& !lstrcmpi(oldwin
->lpszName
, lpszWindow
))
240 WINHELP_BUTTON
*button
;
242 win
->hMainWnd
= oldwin
->hMainWnd
;
243 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
244 win
->hTextWnd
= oldwin
->hTextWnd
;
245 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= 0;
247 SetWindowLong(win
->hMainWnd
, 0, (LONG
) win
);
248 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
) win
);
249 SetWindowLong(win
->hTextWnd
, 0, (LONG
) win
);
251 WINHELP_InitFonts(win
->hMainWnd
);
254 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
257 WINHELP_SetupText(win
->hTextWnd
);
258 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
259 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
260 UpdateWindow(win
->hTextWnd
);
263 for (button
= oldwin
->first_button
; button
; button
= button
->next
)
264 DestroyWindow(button
->hWnd
);
266 WINHELP_DeleteWindow(oldwin
);
270 /* Create main Window */
271 if (!page
) LoadString(Globals
.hInstance
, STID_WINE_HELP
, szCaption
, sizeof(szCaption
));
272 hWnd
= CreateWindow(bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
273 page
? page
->file
->lpszTitle
: szCaption
,
274 bPopup
? WS_POPUPWINDOW
| WS_BORDER
: WS_OVERLAPPEDWINDOW
,
275 origin
.x
, origin
.y
, size
.cx
, size
.cy
,
276 0, bPrimary
? LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(MAIN_MENU
)) : 0,
277 Globals
.hInstance
, win
);
279 ShowWindow(hWnd
, nCmdShow
);
285 /***********************************************************************
287 * WINHELP_CreateHelpWindowByPage
289 BOOL
WINHELP_CreateHelpWindowByPage(HLPFILE_PAGE
* page
, LPCSTR lpszWindow
,
290 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
292 if (page
) page
->file
->wRefCount
++;
293 return WINHELP_CreateHelpWindow(page
, lpszWindow
, bPopup
, hParentWnd
, mouse
, nCmdShow
);
296 /***********************************************************************
298 * WINHELP_CreateHelpWindowByHash
300 BOOL
WINHELP_CreateHelpWindowByHash(LPCSTR lpszFile
, LONG lHash
, LPCSTR lpszWindow
,
301 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
308 page
= lHash
? HLPFILE_PageByHash(lpszFile
, lHash
) : HLPFILE_Contents(lpszFile
);
310 /* Add Suffix `.hlp' */
311 if (!page
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp"))
313 CHAR szFile_hlp
[MAX_PATHNAME_LEN
];
315 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
316 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
317 lstrcat(szFile_hlp
, ".hlp");
319 page
= lHash
? HLPFILE_PageByHash(szFile_hlp
, lHash
) : HLPFILE_Contents(szFile_hlp
);
322 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s
, lpszFile
, STID_WHERROR
, MB_OK
);
323 if (Globals
.win_list
) return FALSE
;
328 return WINHELP_CreateHelpWindowByPage(page
, lpszWindow
, bPopup
, hParentWnd
, mouse
, nCmdShow
);
331 /***********************************************************************
333 * WINHELP_MainWndProc
335 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
338 WINHELP_BUTTON
*button
;
339 RECT rect
, button_box_rect
;
342 WINHELP_CheckPopup(msg
);
347 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
348 SetWindowLong(hWnd
, 0, (LONG
) win
);
349 win
->hMainWnd
= hWnd
;
353 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
355 /* Create button box and text Window */
356 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
357 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
359 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
360 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
364 case WM_WINDOWPOSCHANGED
:
365 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
366 GetClientRect(hWnd
, &rect
);
368 /* Update button box and text Window */
369 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
371 rect
.right
- rect
.left
,
372 rect
.bottom
- rect
.top
, 0);
374 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
375 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
377 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
379 rect
.right
- rect
.left
,
380 rect
.bottom
- text_top
, 0);
385 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
389 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
390 case MNID_FILE_PRINT
: MACRO_Print(); break;
391 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
392 case MNID_FILE_EXIT
: MACRO_Exit(); break;
395 case MNID_EDIT_COPYDLG
: MACRO_CopyDialog(); break;
396 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
399 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
402 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
403 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
404 case MNID_HELP_ABOUT
: MACRO_About(); break;
405 case MNID_HELP_WINE
: ShellAbout(hWnd
, "WINE", "Help", 0); break;
409 for (button
= win
->first_button
; button
; button
= button
->next
)
410 if (wParam
== button
->wParam
) break;
412 MACRO_ExecuteMacro(button
->lpszMacro
);
414 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED
, 0x121, MB_OK
);
419 if (Globals
.hPopupWnd
) DestroyWindow(Globals
.hPopupWnd
);
423 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
426 /***********************************************************************
428 * WINHELP_ButtonBoxWndProc
430 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
434 WINHELP_BUTTON
*button
;
438 WINHELP_CheckPopup(msg
);
443 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
444 SetWindowLong(hWnd
, 0, (LONG
) win
);
445 win
->hButtonBoxWnd
= hWnd
;
448 case WM_WINDOWPOSCHANGING
:
449 winpos
= (WINDOWPOS
*) lParam
;
450 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
455 for (button
= win
->first_button
; button
; button
= button
->next
)
460 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
461 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
463 hWnd
, (HMENU
) button
->wParam
,
464 Globals
.hInstance
, 0);
465 hDc
= GetDC(button
->hWnd
);
466 GetTextExtentPoint(hDc
, button
->lpszName
,
467 lstrlen(button
->lpszName
), &textsize
);
468 ReleaseDC(button
->hWnd
, hDc
);
470 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
471 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
476 for (button
= win
->first_button
; button
; button
= button
->next
)
478 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
480 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
483 x
= 0, y
+= button_size
.cy
;
485 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
489 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
493 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
496 /***********************************************************************
498 * WINHELP_TextWndProc
500 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
504 WINHELP_LINE_PART
*part
;
513 if (msg
!= WM_LBUTTONDOWN
)
514 WINHELP_CheckPopup(msg
);
519 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
520 SetWindowLong(hWnd
, 0, (LONG
) win
);
521 win
->hTextWnd
= hWnd
;
522 if (!win
->lpszName
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
523 WINHELP_InitFonts(hWnd
);
527 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
529 /* Calculate vertical size and position of a popup window */
533 RECT old_window_rect
;
534 RECT old_client_rect
;
535 SIZE old_window_size
;
536 SIZE old_client_size
;
537 SIZE new_client_size
;
538 SIZE new_window_size
;
540 GetWindowRect(hWnd
, &old_window_rect
);
541 origin
.x
= old_window_rect
.left
;
542 origin
.y
= old_window_rect
.top
;
543 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
544 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
546 GetClientRect(hWnd
, &old_client_rect
);
547 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
548 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
550 new_client_size
= old_client_size
;
551 WINHELP_SplitLines(hWnd
, &new_client_size
);
553 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
554 origin
.y
+= POPUP_YDISTANCE
;
556 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
558 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
559 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
562 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
,
563 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
564 new_window_size
.cx
, new_window_size
.cy
,
565 0, 0, Globals
.hInstance
, 0);
567 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
568 new_window_size
.cx
, new_window_size
.cy
,
570 SetWindowPos(win
->hShadowWnd
, hWnd
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
571 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
572 SetActiveWindow(hWnd
);
576 case WM_WINDOWPOSCHANGED
:
577 winpos
= (WINDOWPOS
*) lParam
;
579 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
587 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
588 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
589 GetClientRect(hWnd
, &rect
);
591 switch (wParam
& 0xffff)
594 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
595 case SB_TOP
: CurPos
= Min
; break;
596 case SB_BOTTOM
: CurPos
= Max
; break;
597 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
598 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
599 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
600 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
601 default: update
= FALSE
;
605 INT dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
606 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
607 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
614 hDc
= BeginPaint(hWnd
, &ps
);
615 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
616 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
618 for (line
= win
->first_line
; line
; line
= line
->next
)
620 for (part
= &line
->first_part
; part
; part
= part
->next
)
622 switch (part
->cookie
)
624 case hlp_line_part_text
:
625 SelectObject(hDc
, part
->u
.text
.hFont
);
626 SetTextColor(hDc
, part
->u
.text
.color
);
627 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
628 part
->u
.text
.lpsText
, part
->u
.text
.wTextLen
);
629 if (part
->u
.text
.wUnderline
)
633 switch (part
->u
.text
.wUnderline
)
637 hPen
= CreatePen(PS_SOLID
, 1, part
->u
.text
.color
);
640 hPen
= CreatePen(PS_DOT
, 1, part
->u
.text
.color
);
643 WINE_FIXME("Unknow underline type\n");
647 SelectObject(hDc
, hPen
);
648 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
- 1, NULL
);
649 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
- 1);
650 if (part
->u
.text
.wUnderline
== 2)
652 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
+ 1, NULL
);
653 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
+ 1);
658 case hlp_line_part_image
:
662 hMemDC
= CreateCompatibleDC(hDc
);
663 SelectObject(hMemDC
, part
->u
.image
.hBitmap
);
664 BitBlt(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
665 part
->rect
.right
- part
->rect
.left
, part
->rect
.bottom
- part
->rect
.top
,
666 hMemDC
, 0, 0, SRCCOPY
);
678 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
680 if (WINHELP_IsOverLink(hWnd
, wParam
, lParam
))
681 SetCursor(win
->hHandCur
); /* set to hand pointer cursor to indicate a link */
683 SetCursor(win
->hArrowCur
); /* set to hand pointer cursor to indicate a link */
688 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
690 hPopupWnd
= Globals
.hPopupWnd
;
691 Globals
.hPopupWnd
= 0;
693 part
= WINHELP_IsOverLink(hWnd
, wParam
, lParam
);
696 mouse
.x
= LOWORD(lParam
);
697 mouse
.y
= HIWORD(lParam
);
699 switch (part
->link
.cookie
)
704 WINHELP_CreateHelpWindowByHash(part
->link
.lpszString
, part
->link
.lHash
, NULL
,
705 FALSE
, hWnd
, &mouse
, SW_NORMAL
);
708 WINHELP_CreateHelpWindowByHash(part
->link
.lpszString
, part
->link
.lHash
, NULL
,
709 TRUE
, hWnd
, &mouse
, SW_NORMAL
);
712 MACRO_ExecuteMacro(part
->link
.lpszString
);
715 WINE_FIXME("Unknown link cookie %d\n", part
->link
.cookie
);
720 DestroyWindow(hPopupWnd
);
724 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
726 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
727 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
729 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
731 WINHELP_DeleteWindow(win
);
733 if (bExit
) MACRO_Exit();
735 if (!Globals
.win_list
)
740 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
743 /***********************************************************************
747 static void WINHELP_SetupText(HWND hWnd
)
749 HDC hDc
= GetDC(hWnd
);
753 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
754 if (!WINHELP_SplitLines(hWnd
, NULL
))
756 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
757 GetClientRect(hWnd
, &rect
);
759 WINHELP_SplitLines(hWnd
, &newsize
);
760 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
762 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
764 ReleaseDC(hWnd
, hDc
);
767 /***********************************************************************
771 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
772 LPSIZE space
, LPSIZE textsize
,
773 INT
*line_ascent
, INT ascent
,
774 LPCSTR text
, UINT textlen
,
775 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
,
779 WINHELP_LINE_PART
*part
;
782 if (!*partp
) /* New line */
784 *line_ascent
= ascent
;
786 line
= HeapAlloc(GetProcessHeap(), 0,
787 sizeof(WINHELP_LINE
) + textlen
+ (link
? lstrlen(link
->lpszString
) + 1 : 0));
788 if (!line
) return FALSE
;
791 part
= &line
->first_part
;
792 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
794 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
795 line
->rect
.bottom
= line
->rect
.top
;
796 line
->rect
.left
= space
->cx
;
797 line
->rect
.right
= space
->cx
;
799 if (**linep
) *linep
= &(**linep
)->next
;
807 if (*line_ascent
< ascent
)
809 WINHELP_LINE_PART
*p
;
810 for (p
= &line
->first_part
; p
; p
= p
->next
)
812 p
->rect
.top
+= ascent
- *line_ascent
;
813 p
->rect
.bottom
+= ascent
- *line_ascent
;
815 line
->rect
.bottom
+= ascent
- *line_ascent
;
816 *line_ascent
= ascent
;
819 part
= HeapAlloc(GetProcessHeap(), 0,
820 sizeof(WINHELP_LINE_PART
) + textlen
+
821 (link
? lstrlen(link
->lpszString
) + 1 : 0));
822 if (!part
) return FALSE
;
824 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
827 memcpy(ptr
, text
, textlen
);
828 part
->cookie
= hlp_line_part_text
;
829 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
830 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
831 line
->rect
.right
= part
->rect
.right
;
833 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
834 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
835 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
836 part
->u
.text
.lpsText
= ptr
;
837 part
->u
.text
.wTextLen
= textlen
;
838 part
->u
.text
.hFont
= font
;
839 part
->u
.text
.color
= color
;
840 part
->u
.text
.wUnderline
= underline
;
842 WINE_TRACE("Appended text '%*.*s'[%d] @ (%d,%d-%d,%d)\n",
843 part
->u
.text
.wTextLen
,
844 part
->u
.text
.wTextLen
,
845 part
->u
.text
.lpsText
,
846 part
->u
.text
.wTextLen
,
847 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
850 strcpy(ptr
+ textlen
, link
->lpszString
);
851 part
->link
.lpszString
= ptr
+ textlen
;
852 part
->link
.cookie
= link
->cookie
;
853 part
->link
.lHash
= link
->lHash
;
854 part
->link
.bClrChange
= link
->bClrChange
;
856 else part
->link
.cookie
= hlp_link_none
;
859 *partp
= &part
->next
;
866 /***********************************************************************
868 * WINHELP_AppendBitmap
870 static BOOL
WINHELP_AppendBitmap(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
872 HBITMAP hBmp
, LPSIZE bmpSize
,
873 HLPFILE_LINK
*link
, unsigned pos
)
876 WINHELP_LINE_PART
*part
;
879 if (!*partp
|| pos
== 1) /* New line */
881 line
= HeapAlloc(GetProcessHeap(), 0,
882 sizeof(WINHELP_LINE
) + (link
? lstrlen(link
->lpszString
) + 1 : 0));
883 if (!line
) return FALSE
;
886 part
= &line
->first_part
;
888 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
889 line
->rect
.bottom
= line
->rect
.top
;
890 line
->rect
.left
= space
->cx
;
891 line
->rect
.right
= space
->cx
;
893 if (**linep
) *linep
= &(**linep
)->next
;
896 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
900 if (pos
== 2) WINE_FIXME("Left alignment not handled\n");
903 part
= HeapAlloc(GetProcessHeap(), 0,
904 sizeof(WINHELP_LINE_PART
) +
905 (link
? lstrlen(link
->lpszString
) + 1 : 0));
906 if (!part
) return FALSE
;
908 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
911 part
->cookie
= hlp_line_part_image
;
912 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
913 part
->rect
.right
= part
->rect
.left
+ bmpSize
->cx
;
914 line
->rect
.right
= part
->rect
.right
;
916 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
);
917 part
->rect
.bottom
= part
->rect
.top
+ bmpSize
->cy
;
918 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
919 part
->u
.image
.hBitmap
= hBmp
;
921 WINE_TRACE("Appended bitmap '%d' @ (%d,%d-%d,%d)\n",
922 (unsigned)part
->u
.image
.hBitmap
,
923 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
927 strcpy(ptr
, link
->lpszString
);
928 part
->link
.lpszString
= ptr
;
929 part
->link
.cookie
= link
->cookie
;
930 part
->link
.lHash
= link
->lHash
;
931 part
->link
.bClrChange
= link
->bClrChange
;
933 else part
->link
.cookie
= hlp_link_none
;
936 *partp
= &part
->next
;
944 /***********************************************************************
948 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
950 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
951 HLPFILE_PARAGRAPH
*p
;
952 WINHELP_LINE
**line
= &win
->first_line
;
953 WINHELP_LINE_PART
**part
= 0;
959 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
961 if (!win
->page
) return TRUE
;
963 WINHELP_DeleteLines(win
);
965 GetClientRect(hWnd
, &rect
);
967 rect
.top
+= INTERNAL_BORDER_WIDTH
;
968 rect
.left
+= INTERNAL_BORDER_WIDTH
;
969 rect
.right
-= INTERNAL_BORDER_WIDTH
;
970 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
973 space
.cx
= rect
.left
;
977 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
981 case para_normal_text
:
982 case para_debug_text
:
985 SIZE textsize
= {0, 0};
986 LPCSTR text
= p
->u
.text
.lpszText
;
988 UINT len
= strlen(text
);
989 unsigned underline
= 0;
992 COLORREF color
= RGB(0, 0, 0);
994 if (p
->u
.text
.wFont
< win
->page
->file
->numFonts
)
996 HLPFILE
* hlpfile
= win
->page
->file
;
998 if (!hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
)
999 hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
= CreateFontIndirect(&hlpfile
->fonts
[p
->u
.text
.wFont
].LogFont
);
1000 hFont
= hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
;
1001 color
= hlpfile
->fonts
[p
->u
.text
.wFont
].color
;
1005 UINT wFont
= (p
->u
.text
.wFont
< win
->fonts_len
) ? p
->u
.text
.wFont
: 0;
1007 hFont
= win
->fonts
[wFont
];
1012 underline
= (p
->link
->cookie
== hlp_link_popup
) ? 3 : 1;
1013 color
= RGB(0, 0x80, 0);
1015 if (p
->cookie
== para_debug_text
) color
= RGB(0xff, 0, 0);
1017 SelectObject(hDc
, hFont
);
1019 GetTextMetrics(hDc
, &tm
);
1021 if (p
->u
.text
.wIndent
)
1023 indent
= p
->u
.text
.wIndent
* 5 * tm
.tmAveCharWidth
;
1025 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
1028 if (p
->u
.text
.wVSpace
)
1031 space
.cx
= rect
.left
+ indent
;
1032 space
.cy
+= (p
->u
.text
.wVSpace
- 1) * tm
.tmHeight
;
1035 if (p
->u
.text
.wHSpace
)
1037 space
.cx
+= p
->u
.text
.wHSpace
* 2 * tm
.tmAveCharWidth
;
1040 WINE_TRACE("splitting text %s\n", text
);
1044 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1045 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
1051 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
1053 if (textsize
.cx
<= free_width
) low
= curr
;
1056 if (high
<= low
+ 1) break;
1058 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
1059 if (curr
<= low
) curr
= low
+ 1;
1060 else if (curr
>= high
) curr
= high
- 1;
1063 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
1065 if (!part
&& !textlen
) textlen
= max(low
, 1);
1067 if (free_width
<= 0 || !textlen
)
1070 space
.cx
= rect
.left
+ indent
;
1071 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1075 WINE_TRACE("\t => %d %*s\n", textlen
, textlen
, text
);
1077 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
1078 &line_ascent
, tm
.tmAscent
,
1079 text
, textlen
, hFont
, color
, p
->link
, underline
) ||
1080 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1082 ReleaseDC(hWnd
, hDc
);
1087 newsize
->cx
= max(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
1091 if (text
[0] == ' ') text
++, len
--;
1101 if (p
->u
.image
.pos
& 0x8000)
1103 space
.cx
= rect
.left
;
1105 space
.cy
+= (*line
)->rect
.bottom
- (*line
)->rect
.top
;
1109 GetObject(p
->u
.image
.hBitmap
, sizeof(dibs
), &dibs
);
1110 bmpSize
.cx
= dibs
.dsBm
.bmWidth
;
1111 bmpSize
.cy
= dibs
.dsBm
.bmHeight
;
1113 free_width
= rect
.right
- ((part
&& *line
) ? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1114 if (free_width
<= 0)
1117 space
.cx
= rect
.left
;
1118 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1120 if (!WINHELP_AppendBitmap(&line
, &part
, &space
,
1121 p
->u
.image
.hBitmap
, &bmpSize
,
1122 p
->link
, p
->u
.image
.pos
) ||
1123 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1134 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
1136 ReleaseDC(hWnd
, hDc
);
1140 /***********************************************************************
1142 * WINHELP_CheckPopup
1144 static void WINHELP_CheckPopup(UINT msg
)
1146 if (!Globals
.hPopupWnd
) return;
1151 case WM_LBUTTONDOWN
:
1152 case WM_MBUTTONDOWN
:
1153 case WM_RBUTTONDOWN
:
1154 case WM_NCLBUTTONDOWN
:
1155 case WM_NCMBUTTONDOWN
:
1156 case WM_NCRBUTTONDOWN
:
1157 DestroyWindow(Globals
.hPopupWnd
);
1158 Globals
.hPopupWnd
= 0;
1162 /***********************************************************************
1164 * WINHELP_DeleteLines
1166 static void WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
1168 WINHELP_LINE
*line
, *next_line
;
1169 WINHELP_LINE_PART
*part
, *next_part
;
1170 for (line
= win
->first_line
; line
; line
= next_line
)
1172 next_line
= line
->next
;
1173 for (part
= &line
->first_part
; part
; part
= next_part
)
1175 next_part
= part
->next
;
1176 HeapFree(GetProcessHeap(), 0, part
);
1179 win
->first_line
= 0;
1182 /***********************************************************************
1184 * WINHELP_DeleteWindow
1186 static void WINHELP_DeleteWindow(WINHELP_WINDOW
*win
)
1190 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
1197 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
1198 HLPFILE_FreeHlpFilePage(win
->page
);
1199 WINHELP_DeleteLines(win
);
1200 HeapFree(GetProcessHeap(), 0, win
);
1203 /***********************************************************************
1207 static void WINHELP_InitFonts(HWND hWnd
)
1209 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1210 LOGFONT logfontlist
[] = {
1211 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1212 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1213 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1214 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1215 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1216 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1217 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1218 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1220 static HFONT fonts
[FONTS_LEN
];
1221 static BOOL init
= 0;
1223 win
->fonts_len
= FONTS_LEN
;
1230 for(i
= 0; i
< FONTS_LEN
; i
++)
1232 fonts
[i
] = CreateFontIndirect(&logfontlist
[i
]);
1239 /***********************************************************************
1241 * WINHELP_MessageBoxIDS
1243 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1245 CHAR text
[MAX_STRING_LEN
];
1246 CHAR title
[MAX_STRING_LEN
];
1248 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1249 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1251 return MessageBox(0, text
, title
, type
);
1254 /***********************************************************************
1256 * MAIN_MessageBoxIDS_s
1258 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1260 CHAR text
[MAX_STRING_LEN
];
1261 CHAR title
[MAX_STRING_LEN
];
1262 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1264 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1265 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1266 wsprintf(newtext
, text
, str
);
1268 return MessageBox(0, newtext
, title
, type
);
1271 /******************************************************************
1272 * WINHELP_IsOverLink
1276 WINHELP_LINE_PART
* WINHELP_IsOverLink(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1278 WINHELP_WINDOW
* win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1281 WINHELP_LINE_PART
*part
;
1282 int scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
1284 mouse
.x
= LOWORD(lParam
);
1285 mouse
.y
= HIWORD(lParam
);
1286 for (line
= win
->first_line
; line
; line
= line
->next
)
1288 for (part
= &line
->first_part
; part
; part
= part
->next
)
1290 if (part
->link
.cookie
!= hlp_link_none
&&
1291 part
->link
.lpszString
&&
1292 part
->rect
.left
<= mouse
.x
&&
1293 part
->rect
.right
>= mouse
.x
&&
1294 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
1295 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)