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"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
36 static BOOL
WINHELP_RegisterWinClasses(void);
37 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
38 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
39 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
40 static void WINHELP_CheckPopup(UINT
);
41 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
42 static void WINHELP_InitFonts(HWND hWnd
);
43 static void WINHELP_DeleteLines(WINHELP_WINDOW
*);
44 static void WINHELP_DeleteWindow(WINHELP_WINDOW
*);
45 static void WINHELP_SetupText(HWND hWnd
);
46 static WINHELP_LINE_PART
* WINHELP_IsOverLink(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
48 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 1, 0, 0};
50 static BOOL MacroTest
= FALSE
;
52 /***********************************************************************
56 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
61 Globals
.hInstance
= hInstance
;
64 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
68 if (*cmdline
++ == ' ') continue;
71 if (option
) cmdline
++;
72 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
78 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
79 if (*cmdline
) *cmdline
++ = '\0';
80 lHash
= HLPFILE_Hash(topic_id
);
85 Globals
.wVersion
= option
- '0';
94 Globals
.isBook
= FALSE
;
98 WINE_FIXME("Unsupported cmd line: %s\n", cmdline
);
103 /* Create primary window */
104 WINHELP_RegisterWinClasses();
105 WINHELP_CreateHelpWindowByHash(cmdline
, lHash
, "main", FALSE
, NULL
, NULL
, show
);
108 while (GetMessage(&msg
, 0, 0, 0))
110 TranslateMessage(&msg
);
111 DispatchMessage(&msg
);
116 /***********************************************************************
120 static BOOL
WINHELP_RegisterWinClasses(void)
122 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
;
124 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
125 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
126 class_main
.cbClsExtra
= 0;
127 class_main
.cbWndExtra
= sizeof(LONG
);
128 class_main
.hInstance
= Globals
.hInstance
;
129 class_main
.hIcon
= LoadIcon(0, IDI_APPLICATION
);
130 class_main
.hCursor
= LoadCursor(0, IDC_ARROW
);
131 class_main
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
132 class_main
.lpszMenuName
= 0;
133 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
135 class_button_box
= class_main
;
136 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
137 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
138 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
140 class_text
= class_main
;
141 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
142 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
144 class_shadow
= class_main
;
145 class_shadow
.lpfnWndProc
= DefWindowProc
;
146 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
147 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
149 return (RegisterClass(&class_main
) &&
150 RegisterClass(&class_button_box
) &&
151 RegisterClass(&class_text
) &&
152 RegisterClass(&class_shadow
));
163 } WINHELP
,*LPWINHELP
;
165 /******************************************************************
166 * WINHELP_HandleCommand
170 static LRESULT
WINHELP_HandleCommand(HWND hSrcWnd
, LPARAM lParam
)
172 COPYDATASTRUCT
* cds
= (COPYDATASTRUCT
*)lParam
;
175 if (cds
->dwData
!= 0xA1DE505)
177 WINE_FIXME("Wrong magic number (%08lx)\n", cds
->dwData
);
181 wh
= (WINHELP
*)cds
->lpData
;
185 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
186 wh
->size
, wh
->command
, wh
->data
,
187 wh
->ofsFilename
? (LPSTR
)wh
+ wh
->ofsFilename
: "");
194 /* in fact, should be the topic dialog box */
197 MACRO_JumpHash((LPSTR
)wh
+ wh
->ofsFilename
, "main", 0);
201 case HELP_SETCONTENTS
:
203 case HELP_CONTEXTPOPUP
:
205 case HELP_HELPONHELP
:
207 case HELP_PARTIALKEY
:
218 /***********************************************************************
220 * WINHELP_CreateHelpWindow
223 static BOOL
WINHELP_CreateHelpWindow(HLPFILE_PAGE
* page
, LPCSTR lpszWindow
,
224 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
226 CHAR szCaption
[MAX_STRING_LEN
];
227 SIZE size
= {CW_USEDEFAULT
, 0/*CW_USEDEFAULT*/};
228 POINT origin
= {240, 0};
230 WINHELP_WINDOW
*win
, *oldwin
;
231 HLPFILE_MACRO
*macro
;
237 else if (!lpszWindow
|| !lpszWindow
[0])
238 lpszWindow
= Globals
.active_win
->lpszName
;
239 bPrimary
= lpszWindow
&& !lstrcmpi(lpszWindow
, "main");
241 /* Calculate horizontal size and position of a popup window */
245 GetWindowRect(hParentWnd
, &parent_rect
);
246 size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
247 size
.cy
= 10; /* need a non null value, so that border are taken into account while computing */
250 ClientToScreen(hParentWnd
, &origin
);
251 origin
.x
-= size
.cx
/ 2;
252 origin
.x
= min(origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - size
.cx
);
253 origin
.x
= max(origin
.x
, 0);
256 /* Initialize WINHELP_WINDOW struct */
257 win
= HeapAlloc(GetProcessHeap(), 0,
258 sizeof(WINHELP_WINDOW
) + (lpszWindow
? strlen(lpszWindow
) + 1 : 0));
259 if (!win
) return FALSE
;
261 win
->next
= Globals
.win_list
;
262 Globals
.win_list
= win
;
265 ptr
= (char*)win
+ sizeof(WINHELP_WINDOW
);
266 lstrcpy(ptr
, (LPSTR
) lpszWindow
);
269 else win
->lpszName
= NULL
;
272 win
->first_button
= 0;
275 win
->hButtonBoxWnd
= 0;
279 win
->hArrowCur
= LoadCursorA(0, IDC_ARROWA
);
280 win
->hHandCur
= LoadCursorA(0, IDC_HANDA
);
282 Globals
.active_win
= win
;
284 /* Initialize default pushbuttons */
285 if (MacroTest
&& !bPopup
)
286 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
287 if (bPrimary
&& page
)
289 CHAR buffer
[MAX_STRING_LEN
];
291 LoadString(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
292 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
293 LoadString(Globals
.hInstance
, STID_SEARCH
,buffer
, sizeof(buffer
));
294 MACRO_CreateButton("BTN_SEARCH", buffer
, "Search()");
295 LoadString(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
296 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
297 LoadString(Globals
.hInstance
, STID_HISTORY
, buffer
, sizeof(buffer
));
298 MACRO_CreateButton("BTN_HISTORY", buffer
, "History()");
299 LoadString(Globals
.hInstance
, STID_TOPICS
, buffer
, sizeof(buffer
));
300 MACRO_CreateButton("BTN_TOPICS", buffer
, "Finder()");
303 /* Initialize file specific pushbuttons */
305 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
306 MACRO_ExecuteMacro(macro
->lpszMacro
);
308 /* Reuse existing window */
310 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
311 if (oldwin
->lpszName
&& !lstrcmpi(oldwin
->lpszName
, lpszWindow
))
313 WINHELP_BUTTON
*button
;
315 win
->hMainWnd
= oldwin
->hMainWnd
;
316 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
317 win
->hTextWnd
= oldwin
->hTextWnd
;
318 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= 0;
320 SetWindowLong(win
->hMainWnd
, 0, (LONG
) win
);
321 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
) win
);
322 SetWindowLong(win
->hTextWnd
, 0, (LONG
) win
);
324 WINHELP_InitFonts(win
->hMainWnd
);
327 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
330 WINHELP_SetupText(win
->hTextWnd
);
331 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
332 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
333 ShowWindow(win
->hMainWnd
, nCmdShow
);
334 UpdateWindow(win
->hTextWnd
);
337 for (button
= oldwin
->first_button
; button
; button
= button
->next
)
338 DestroyWindow(button
->hWnd
);
340 WINHELP_DeleteWindow(oldwin
);
344 /* Create main Window */
345 if (!page
) LoadString(Globals
.hInstance
, STID_WINE_HELP
, szCaption
, sizeof(szCaption
));
346 hWnd
= CreateWindow(bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
347 page
? page
->file
->lpszTitle
: szCaption
,
348 bPopup
? WS_POPUPWINDOW
| WS_BORDER
: WS_OVERLAPPEDWINDOW
,
349 origin
.x
, origin
.y
, size
.cx
, size
.cy
,
350 0, bPrimary
? LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(MAIN_MENU
)) : 0,
351 Globals
.hInstance
, win
);
353 ShowWindow(hWnd
, nCmdShow
);
359 /***********************************************************************
361 * WINHELP_CreateHelpWindowByPage
363 BOOL
WINHELP_CreateHelpWindowByPage(HLPFILE_PAGE
* page
, LPCSTR lpszWindow
,
364 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
366 if (page
) page
->file
->wRefCount
++;
367 return WINHELP_CreateHelpWindow(page
, lpszWindow
, bPopup
, hParentWnd
, mouse
, nCmdShow
);
370 /***********************************************************************
372 * WINHELP_CreateHelpWindowByHash
374 BOOL
WINHELP_CreateHelpWindowByHash(LPCSTR lpszFile
, LONG lHash
, LPCSTR lpszWindow
,
375 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
377 HLPFILE_PAGE
* page
= NULL
;
384 hlpfile
= HLPFILE_ReadHlpFile(lpszFile
);
386 /* Add Suffix `.hlp' */
387 if (!hlpfile
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp") != 0)
389 CHAR szFile_hlp
[MAX_PATHNAME_LEN
];
391 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
392 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
393 lstrcat(szFile_hlp
, ".hlp");
395 hlpfile
= HLPFILE_ReadHlpFile(szFile_hlp
);
399 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s
, lpszFile
, STID_WHERROR
, MB_OK
);
400 if (Globals
.win_list
) return FALSE
;
403 page
= lHash
? HLPFILE_PageByHash(hlpfile
, lHash
) :
404 HLPFILE_Contents(hlpfile
);
407 return WINHELP_CreateHelpWindowByPage(page
, lpszWindow
, bPopup
, hParentWnd
, mouse
, nCmdShow
);
410 /***********************************************************************
412 * WINHELP_MainWndProc
414 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
417 WINHELP_BUTTON
*button
;
418 RECT rect
, button_box_rect
;
421 WINHELP_CheckPopup(msg
);
426 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
427 SetWindowLong(hWnd
, 0, (LONG
) win
);
428 win
->hMainWnd
= hWnd
;
432 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
434 /* Create button box and text Window */
435 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
436 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
438 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
439 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
443 case WM_WINDOWPOSCHANGED
:
444 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
445 GetClientRect(hWnd
, &rect
);
447 /* Update button box and text Window */
448 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
450 rect
.right
- rect
.left
,
451 rect
.bottom
- rect
.top
, 0);
453 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
454 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
456 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
458 rect
.right
- rect
.left
,
459 rect
.bottom
- text_top
, 0);
464 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
468 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
469 case MNID_FILE_PRINT
: MACRO_Print(); break;
470 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
471 case MNID_FILE_EXIT
: MACRO_Exit(); break;
474 case MNID_EDIT_COPYDLG
: MACRO_CopyDialog(); break;
475 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
478 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
481 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
482 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
483 case MNID_HELP_ABOUT
: MACRO_About(); break;
484 case MNID_HELP_WINE
: ShellAbout(hWnd
, "WINE", "Help", 0); break;
488 for (button
= win
->first_button
; button
; button
= button
->next
)
489 if (wParam
== button
->wParam
) break;
491 MACRO_ExecuteMacro(button
->lpszMacro
);
493 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED
, 0x121, MB_OK
);
498 if (Globals
.hPopupWnd
) DestroyWindow(Globals
.hPopupWnd
);
501 return WINHELP_HandleCommand((HWND
)wParam
, lParam
);
503 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
506 /***********************************************************************
508 * WINHELP_ButtonBoxWndProc
510 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
514 WINHELP_BUTTON
*button
;
518 WINHELP_CheckPopup(msg
);
523 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
524 SetWindowLong(hWnd
, 0, (LONG
) win
);
525 win
->hButtonBoxWnd
= hWnd
;
528 case WM_WINDOWPOSCHANGING
:
529 winpos
= (WINDOWPOS
*) lParam
;
530 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
535 for (button
= win
->first_button
; button
; button
= button
->next
)
540 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
541 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
543 hWnd
, (HMENU
) button
->wParam
,
544 Globals
.hInstance
, 0);
545 hDc
= GetDC(button
->hWnd
);
546 GetTextExtentPoint(hDc
, button
->lpszName
,
547 lstrlen(button
->lpszName
), &textsize
);
548 ReleaseDC(button
->hWnd
, hDc
);
550 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
551 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
556 for (button
= win
->first_button
; button
; button
= button
->next
)
558 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
560 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
563 x
= 0, y
+= button_size
.cy
;
565 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
569 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
573 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
576 /***********************************************************************
578 * WINHELP_TextWndProc
580 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
584 WINHELP_LINE_PART
*part
;
593 if (msg
!= WM_LBUTTONDOWN
)
594 WINHELP_CheckPopup(msg
);
599 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
600 SetWindowLong(hWnd
, 0, (LONG
) win
);
601 win
->hTextWnd
= hWnd
;
602 if (!win
->lpszName
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
603 WINHELP_InitFonts(hWnd
);
607 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
609 /* Calculate vertical size and position of a popup window */
613 RECT old_window_rect
;
614 RECT old_client_rect
;
615 SIZE old_window_size
;
616 SIZE old_client_size
;
617 SIZE new_client_size
;
618 SIZE new_window_size
;
620 GetWindowRect(hWnd
, &old_window_rect
);
621 origin
.x
= old_window_rect
.left
;
622 origin
.y
= old_window_rect
.top
;
623 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
624 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
626 GetClientRect(hWnd
, &old_client_rect
);
627 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
628 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
630 new_client_size
= old_client_size
;
631 WINHELP_SplitLines(hWnd
, &new_client_size
);
633 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
634 origin
.y
+= POPUP_YDISTANCE
;
636 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
638 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
639 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
642 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
,
643 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
644 new_window_size
.cx
, new_window_size
.cy
,
645 0, 0, Globals
.hInstance
, 0);
647 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
648 new_window_size
.cx
, new_window_size
.cy
,
650 SetWindowPos(win
->hShadowWnd
, hWnd
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
651 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
652 SetActiveWindow(hWnd
);
656 case WM_WINDOWPOSCHANGED
:
657 winpos
= (WINDOWPOS
*) lParam
;
659 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
667 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
668 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
669 GetClientRect(hWnd
, &rect
);
671 switch (wParam
& 0xffff)
674 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
675 case SB_TOP
: CurPos
= Min
; break;
676 case SB_BOTTOM
: CurPos
= Max
; break;
677 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
678 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
679 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
680 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
681 default: update
= FALSE
;
685 INT dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
686 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
687 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
694 hDc
= BeginPaint(hWnd
, &ps
);
695 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
696 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
698 for (line
= win
->first_line
; line
; line
= line
->next
)
700 for (part
= &line
->first_part
; part
; part
= part
->next
)
702 switch (part
->cookie
)
704 case hlp_line_part_text
:
705 SelectObject(hDc
, part
->u
.text
.hFont
);
706 SetTextColor(hDc
, part
->u
.text
.color
);
707 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
708 part
->u
.text
.lpsText
, part
->u
.text
.wTextLen
);
709 if (part
->u
.text
.wUnderline
)
713 switch (part
->u
.text
.wUnderline
)
717 hPen
= CreatePen(PS_SOLID
, 1, part
->u
.text
.color
);
720 hPen
= CreatePen(PS_DOT
, 1, part
->u
.text
.color
);
723 WINE_FIXME("Unknow underline type\n");
727 SelectObject(hDc
, hPen
);
728 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
- 1, NULL
);
729 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
- 1);
730 if (part
->u
.text
.wUnderline
== 2)
732 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
+ 1, NULL
);
733 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
+ 1);
738 case hlp_line_part_image
:
742 hMemDC
= CreateCompatibleDC(hDc
);
743 SelectObject(hMemDC
, part
->u
.image
.hBitmap
);
744 BitBlt(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
745 part
->rect
.right
- part
->rect
.left
, part
->rect
.bottom
- part
->rect
.top
,
746 hMemDC
, 0, 0, SRCCOPY
);
758 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
760 if (WINHELP_IsOverLink(hWnd
, wParam
, lParam
))
761 SetCursor(win
->hHandCur
); /* set to hand pointer cursor to indicate a link */
763 SetCursor(win
->hArrowCur
); /* set to hand pointer cursor to indicate a link */
768 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
770 hPopupWnd
= Globals
.hPopupWnd
;
771 Globals
.hPopupWnd
= 0;
773 part
= WINHELP_IsOverLink(hWnd
, wParam
, lParam
);
776 mouse
.x
= LOWORD(lParam
);
777 mouse
.y
= HIWORD(lParam
);
779 switch (part
->link
.cookie
)
784 WINHELP_CreateHelpWindowByHash(part
->link
.lpszString
, part
->link
.lHash
, NULL
,
785 FALSE
, hWnd
, &mouse
, SW_NORMAL
);
788 WINHELP_CreateHelpWindowByHash(part
->link
.lpszString
, part
->link
.lHash
, NULL
,
789 TRUE
, hWnd
, &mouse
, SW_NORMAL
);
792 MACRO_ExecuteMacro(part
->link
.lpszString
);
795 WINE_FIXME("Unknown link cookie %d\n", part
->link
.cookie
);
800 DestroyWindow(hPopupWnd
);
804 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
806 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
807 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
809 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
811 WINHELP_DeleteWindow(win
);
813 if (bExit
) MACRO_Exit();
815 if (!Globals
.win_list
)
820 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
823 /***********************************************************************
827 static void WINHELP_SetupText(HWND hWnd
)
829 HDC hDc
= GetDC(hWnd
);
833 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
834 if (!WINHELP_SplitLines(hWnd
, NULL
))
836 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
837 GetClientRect(hWnd
, &rect
);
839 WINHELP_SplitLines(hWnd
, &newsize
);
840 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
842 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
844 ReleaseDC(hWnd
, hDc
);
847 /***********************************************************************
851 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
852 LPSIZE space
, LPSIZE textsize
,
853 INT
*line_ascent
, INT ascent
,
854 LPCSTR text
, UINT textlen
,
855 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
,
859 WINHELP_LINE_PART
*part
;
862 if (!*partp
) /* New line */
864 *line_ascent
= ascent
;
866 line
= HeapAlloc(GetProcessHeap(), 0,
867 sizeof(WINHELP_LINE
) + textlen
+ (link
? lstrlen(link
->lpszString
) + 1 : 0));
868 if (!line
) return FALSE
;
871 part
= &line
->first_part
;
872 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
874 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
875 line
->rect
.bottom
= line
->rect
.top
;
876 line
->rect
.left
= space
->cx
;
877 line
->rect
.right
= space
->cx
;
879 if (**linep
) *linep
= &(**linep
)->next
;
887 if (*line_ascent
< ascent
)
889 WINHELP_LINE_PART
*p
;
890 for (p
= &line
->first_part
; p
; p
= p
->next
)
892 p
->rect
.top
+= ascent
- *line_ascent
;
893 p
->rect
.bottom
+= ascent
- *line_ascent
;
895 line
->rect
.bottom
+= ascent
- *line_ascent
;
896 *line_ascent
= ascent
;
899 part
= HeapAlloc(GetProcessHeap(), 0,
900 sizeof(WINHELP_LINE_PART
) + textlen
+
901 (link
? lstrlen(link
->lpszString
) + 1 : 0));
902 if (!part
) return FALSE
;
904 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
907 memcpy(ptr
, text
, textlen
);
908 part
->cookie
= hlp_line_part_text
;
909 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
910 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
911 line
->rect
.right
= part
->rect
.right
;
913 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
914 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
915 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
916 part
->u
.text
.lpsText
= ptr
;
917 part
->u
.text
.wTextLen
= textlen
;
918 part
->u
.text
.hFont
= font
;
919 part
->u
.text
.color
= color
;
920 part
->u
.text
.wUnderline
= underline
;
922 WINE_TRACE("Appended text '%*.*s'[%d] @ (%d,%d-%d,%d)\n",
923 part
->u
.text
.wTextLen
,
924 part
->u
.text
.wTextLen
,
925 part
->u
.text
.lpsText
,
926 part
->u
.text
.wTextLen
,
927 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
930 strcpy(ptr
+ textlen
, link
->lpszString
);
931 part
->link
.lpszString
= ptr
+ textlen
;
932 part
->link
.cookie
= link
->cookie
;
933 part
->link
.lHash
= link
->lHash
;
934 part
->link
.bClrChange
= link
->bClrChange
;
936 else part
->link
.cookie
= hlp_link_none
;
939 *partp
= &part
->next
;
946 /***********************************************************************
948 * WINHELP_AppendBitmap
950 static BOOL
WINHELP_AppendBitmap(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
952 HBITMAP hBmp
, LPSIZE bmpSize
,
953 HLPFILE_LINK
*link
, unsigned pos
)
956 WINHELP_LINE_PART
*part
;
959 if (!*partp
|| pos
== 1) /* New line */
961 line
= HeapAlloc(GetProcessHeap(), 0,
962 sizeof(WINHELP_LINE
) + (link
? lstrlen(link
->lpszString
) + 1 : 0));
963 if (!line
) return FALSE
;
966 part
= &line
->first_part
;
968 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
969 line
->rect
.bottom
= line
->rect
.top
;
970 line
->rect
.left
= space
->cx
;
971 line
->rect
.right
= space
->cx
;
973 if (**linep
) *linep
= &(**linep
)->next
;
976 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
980 if (pos
== 2) WINE_FIXME("Left alignment not handled\n");
983 part
= HeapAlloc(GetProcessHeap(), 0,
984 sizeof(WINHELP_LINE_PART
) +
985 (link
? lstrlen(link
->lpszString
) + 1 : 0));
986 if (!part
) return FALSE
;
988 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
991 part
->cookie
= hlp_line_part_image
;
992 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
993 part
->rect
.right
= part
->rect
.left
+ bmpSize
->cx
;
994 line
->rect
.right
= part
->rect
.right
;
996 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
);
997 part
->rect
.bottom
= part
->rect
.top
+ bmpSize
->cy
;
998 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
999 part
->u
.image
.hBitmap
= hBmp
;
1001 WINE_TRACE("Appended bitmap '%d' @ (%d,%d-%d,%d)\n",
1002 (unsigned)part
->u
.image
.hBitmap
,
1003 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1007 strcpy(ptr
, link
->lpszString
);
1008 part
->link
.lpszString
= ptr
;
1009 part
->link
.cookie
= link
->cookie
;
1010 part
->link
.lHash
= link
->lHash
;
1011 part
->link
.bClrChange
= link
->bClrChange
;
1013 else part
->link
.cookie
= hlp_link_none
;
1016 *partp
= &part
->next
;
1024 /***********************************************************************
1026 * WINHELP_SplitLines
1028 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
1030 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1031 HLPFILE_PARAGRAPH
*p
;
1032 WINHELP_LINE
**line
= &win
->first_line
;
1033 WINHELP_LINE_PART
**part
= 0;
1034 INT line_ascent
= 0;
1039 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
1041 if (!win
->page
) return TRUE
;
1043 WINHELP_DeleteLines(win
);
1045 GetClientRect(hWnd
, &rect
);
1047 rect
.top
+= INTERNAL_BORDER_WIDTH
;
1048 rect
.left
+= INTERNAL_BORDER_WIDTH
;
1049 rect
.right
-= INTERNAL_BORDER_WIDTH
;
1050 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
1052 space
.cy
= rect
.top
;
1053 space
.cx
= rect
.left
;
1057 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
1061 case para_normal_text
:
1062 case para_debug_text
:
1065 SIZE textsize
= {0, 0};
1066 LPCSTR text
= p
->u
.text
.lpszText
;
1068 UINT len
= strlen(text
);
1069 unsigned underline
= 0;
1072 COLORREF color
= RGB(0, 0, 0);
1074 if (p
->u
.text
.wFont
< win
->page
->file
->numFonts
)
1076 HLPFILE
* hlpfile
= win
->page
->file
;
1078 if (!hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
)
1079 hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
= CreateFontIndirect(&hlpfile
->fonts
[p
->u
.text
.wFont
].LogFont
);
1080 hFont
= hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
;
1081 color
= hlpfile
->fonts
[p
->u
.text
.wFont
].color
;
1085 UINT wFont
= (p
->u
.text
.wFont
< win
->fonts_len
) ? p
->u
.text
.wFont
: 0;
1087 hFont
= win
->fonts
[wFont
];
1092 underline
= (p
->link
->cookie
== hlp_link_popup
) ? 3 : 1;
1093 color
= RGB(0, 0x80, 0);
1095 if (p
->cookie
== para_debug_text
) color
= RGB(0xff, 0, 0);
1097 SelectObject(hDc
, hFont
);
1099 GetTextMetrics(hDc
, &tm
);
1101 if (p
->u
.text
.wIndent
)
1103 indent
= p
->u
.text
.wIndent
* 5 * tm
.tmAveCharWidth
;
1105 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
1108 if (p
->u
.text
.wVSpace
)
1111 space
.cx
= rect
.left
+ indent
;
1112 space
.cy
+= (p
->u
.text
.wVSpace
- 1) * tm
.tmHeight
;
1115 if (p
->u
.text
.wHSpace
)
1117 space
.cx
+= p
->u
.text
.wHSpace
* 2 * tm
.tmAveCharWidth
;
1120 WINE_TRACE("splitting text %s\n", text
);
1124 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1125 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
1131 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
1133 if (textsize
.cx
<= free_width
) low
= curr
;
1136 if (high
<= low
+ 1) break;
1138 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
1139 if (curr
<= low
) curr
= low
+ 1;
1140 else if (curr
>= high
) curr
= high
- 1;
1143 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
1145 if (!part
&& !textlen
) textlen
= max(low
, 1);
1147 if (free_width
<= 0 || !textlen
)
1150 space
.cx
= rect
.left
+ indent
;
1151 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1155 WINE_TRACE("\t => %d %*s\n", textlen
, textlen
, text
);
1157 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
1158 &line_ascent
, tm
.tmAscent
,
1159 text
, textlen
, hFont
, color
, p
->link
, underline
) ||
1160 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1162 ReleaseDC(hWnd
, hDc
);
1167 newsize
->cx
= max(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
1171 if (text
[0] == ' ') text
++, len
--;
1181 if (p
->u
.image
.pos
& 0x8000)
1183 space
.cx
= rect
.left
;
1185 space
.cy
+= (*line
)->rect
.bottom
- (*line
)->rect
.top
;
1189 GetObject(p
->u
.image
.hBitmap
, sizeof(dibs
), &dibs
);
1190 bmpSize
.cx
= dibs
.dsBm
.bmWidth
;
1191 bmpSize
.cy
= dibs
.dsBm
.bmHeight
;
1193 free_width
= rect
.right
- ((part
&& *line
) ? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1194 if (free_width
<= 0)
1197 space
.cx
= rect
.left
;
1198 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1200 if (!WINHELP_AppendBitmap(&line
, &part
, &space
,
1201 p
->u
.image
.hBitmap
, &bmpSize
,
1202 p
->link
, p
->u
.image
.pos
) ||
1203 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1214 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
1216 ReleaseDC(hWnd
, hDc
);
1220 /***********************************************************************
1222 * WINHELP_CheckPopup
1224 static void WINHELP_CheckPopup(UINT msg
)
1226 if (!Globals
.hPopupWnd
) return;
1231 case WM_LBUTTONDOWN
:
1232 case WM_MBUTTONDOWN
:
1233 case WM_RBUTTONDOWN
:
1234 case WM_NCLBUTTONDOWN
:
1235 case WM_NCMBUTTONDOWN
:
1236 case WM_NCRBUTTONDOWN
:
1237 DestroyWindow(Globals
.hPopupWnd
);
1238 Globals
.hPopupWnd
= 0;
1242 /***********************************************************************
1244 * WINHELP_DeleteLines
1246 static void WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
1248 WINHELP_LINE
*line
, *next_line
;
1249 WINHELP_LINE_PART
*part
, *next_part
;
1250 for (line
= win
->first_line
; line
; line
= next_line
)
1252 next_line
= line
->next
;
1253 for (part
= &line
->first_part
; part
; part
= next_part
)
1255 next_part
= part
->next
;
1256 HeapFree(GetProcessHeap(), 0, part
);
1259 win
->first_line
= 0;
1262 /***********************************************************************
1264 * WINHELP_DeleteWindow
1266 static void WINHELP_DeleteWindow(WINHELP_WINDOW
*win
)
1270 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
1277 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
1278 HLPFILE_FreeHlpFilePage(win
->page
);
1279 WINHELP_DeleteLines(win
);
1280 HeapFree(GetProcessHeap(), 0, win
);
1283 /***********************************************************************
1287 static void WINHELP_InitFonts(HWND hWnd
)
1289 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1290 LOGFONT logfontlist
[] = {
1291 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1292 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1293 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1294 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1295 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1296 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1297 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1298 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1300 static HFONT fonts
[FONTS_LEN
];
1301 static BOOL init
= 0;
1303 win
->fonts_len
= FONTS_LEN
;
1310 for(i
= 0; i
< FONTS_LEN
; i
++)
1312 fonts
[i
] = CreateFontIndirect(&logfontlist
[i
]);
1319 /***********************************************************************
1321 * WINHELP_MessageBoxIDS
1323 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1325 CHAR text
[MAX_STRING_LEN
];
1326 CHAR title
[MAX_STRING_LEN
];
1328 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1329 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1331 return MessageBox(0, text
, title
, type
);
1334 /***********************************************************************
1336 * MAIN_MessageBoxIDS_s
1338 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1340 CHAR text
[MAX_STRING_LEN
];
1341 CHAR title
[MAX_STRING_LEN
];
1342 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1344 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1345 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1346 wsprintf(newtext
, text
, str
);
1348 return MessageBox(0, newtext
, title
, type
);
1351 /******************************************************************
1352 * WINHELP_IsOverLink
1356 WINHELP_LINE_PART
* WINHELP_IsOverLink(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
1358 WINHELP_WINDOW
* win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1361 WINHELP_LINE_PART
*part
;
1362 int scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
1364 mouse
.x
= LOWORD(lParam
);
1365 mouse
.y
= HIWORD(lParam
);
1366 for (line
= win
->first_line
; line
; line
= line
->next
)
1368 for (part
= &line
->first_part
; part
; part
= part
->next
)
1370 if (part
->link
.cookie
!= hlp_link_none
&&
1371 part
->link
.lpszString
&&
1372 part
->rect
.left
<= mouse
.x
&&
1373 part
->rect
.right
>= mouse
.x
&&
1374 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
1375 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)