4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002 Eric Pouech <eric.pouech@wanadoo.fr>
7 * 2004 Ken Belleau <jamez@ivic.qc.ca>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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, 0, 0, 0, 1, 0, 0, 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 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
)
169 Globals
.hInstance
= hInstance
;
172 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
176 if (*cmdline
++ == ' ') continue;
179 if (option
) cmdline
++;
180 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
186 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
187 if (*cmdline
) *cmdline
++ = '\0';
188 lHash
= HLPFILE_Hash(topic_id
);
193 Globals
.wVersion
= option
- '0';
198 Globals
.isBook
= FALSE
;
202 WINE_FIXME("Unsupported cmd line: %s\n", cmdline
);
207 /* Create primary window */
208 WINHELP_RegisterWinClasses();
211 if ((*cmdline
== '"') && (quote
= strchr(cmdline
+1, '"')))
216 hlpfile
= WINHELP_LookupHelpFile(cmdline
);
217 if (!hlpfile
) return 0;
220 WINHELP_CreateHelpWindowByHash(hlpfile
, lHash
,
221 WINHELP_GetWindowInfo(hlpfile
, "main"), show
);
224 while (GetMessage(&msg
, 0, 0, 0))
226 TranslateMessage(&msg
);
227 DispatchMessage(&msg
);
232 /***********************************************************************
236 static BOOL
WINHELP_RegisterWinClasses(void)
238 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
, class_history
;
240 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
241 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
242 class_main
.cbClsExtra
= 0;
243 class_main
.cbWndExtra
= sizeof(LONG
);
244 class_main
.hInstance
= Globals
.hInstance
;
245 class_main
.hIcon
= LoadIcon(0, IDI_APPLICATION
);
246 class_main
.hCursor
= LoadCursor(0, IDC_ARROW
);
247 class_main
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
248 class_main
.lpszMenuName
= 0;
249 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
251 class_button_box
= class_main
;
252 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
253 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
254 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
256 class_text
= class_main
;
257 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
258 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
260 class_shadow
= class_main
;
261 class_shadow
.lpfnWndProc
= WINHELP_ShadowWndProc
;
262 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
263 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
265 class_history
= class_main
;
266 class_history
.lpfnWndProc
= WINHELP_HistoryWndProc
;
267 class_history
.lpszClassName
= HISTORY_WIN_CLASS_NAME
;
269 return (RegisterClass(&class_main
) &&
270 RegisterClass(&class_button_box
) &&
271 RegisterClass(&class_text
) &&
272 RegisterClass(&class_shadow
) &&
273 RegisterClass(&class_history
));
284 } WINHELP
,*LPWINHELP
;
286 /******************************************************************
287 * WINHELP_HandleCommand
291 static LRESULT
WINHELP_HandleCommand(HWND hSrcWnd
, LPARAM lParam
)
293 COPYDATASTRUCT
* cds
= (COPYDATASTRUCT
*)lParam
;
296 if (cds
->dwData
!= 0xA1DE505)
298 WINE_FIXME("Wrong magic number (%08lx)\n", cds
->dwData
);
302 wh
= (WINHELP
*)cds
->lpData
;
306 char* ptr
= (wh
->ofsFilename
) ? (LPSTR
)wh
+ wh
->ofsFilename
: NULL
;
308 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
309 wh
->size
, wh
->command
, wh
->data
, ptr
);
315 MACRO_JumpContext(ptr
, "main", wh
->data
);
324 MACRO_JumpContents(ptr
, "main");
327 case HELP_HELPONHELP
:
330 /* case HELP_SETINDEX: */
331 case HELP_SETCONTENTS
:
334 MACRO_SetContents(ptr
, wh
->data
);
337 case HELP_CONTEXTPOPUP
:
340 MACRO_PopupContext(ptr
, wh
->data
);
343 /* case HELP_FORCEFILE:*/
344 /* case HELP_CONTEXTMENU: */
346 /* in fact, should be the topic dialog box */
349 MACRO_JumpHash(ptr
, "main", 0);
352 /* case HELP_WM_HELP: */
353 /* case HELP_SETPOPUP_POS: */
355 /* case HELP_COMMAND: */
356 /* case HELP_PARTIALKEY: */
357 /* case HELP_MULTIKEY: */
358 /* case HELP_SETWINPOS: */
359 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh
->command
);
366 /******************************************************************
367 * WINHELP_ReuseWindow
371 static BOOL
WINHELP_ReuseWindow(WINHELP_WINDOW
* win
, WINHELP_WINDOW
* oldwin
,
372 HLPFILE_PAGE
* page
, int nCmdShow
)
376 win
->hMainWnd
= oldwin
->hMainWnd
;
377 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
378 win
->hTextWnd
= oldwin
->hTextWnd
;
379 win
->hHistoryWnd
= oldwin
->hHistoryWnd
;
380 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= oldwin
->hHistoryWnd
= 0;
382 SetWindowLong(win
->hMainWnd
, 0, (LONG
)win
);
383 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
)win
);
384 SetWindowLong(win
->hTextWnd
, 0, (LONG
)win
);
385 SetWindowLong(win
->hHistoryWnd
, 0, (LONG
)win
);
387 WINHELP_InitFonts(win
->hMainWnd
);
390 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
392 WINHELP_SetupText(win
->hTextWnd
);
393 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
394 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
395 ShowWindow(win
->hMainWnd
, nCmdShow
);
396 UpdateWindow(win
->hTextWnd
);
398 if (!(win
->info
->win_style
& WS_POPUP
))
402 memcpy(win
->history
, oldwin
->history
, sizeof(win
->history
));
403 win
->histIndex
= oldwin
->histIndex
;
405 /* FIXME: when using back, we shouldn't update the history... */
409 for (i
= 0; i
< win
->histIndex
; i
++)
410 if (win
->history
[i
] == page
) break;
412 /* if the new page is already in the history, do nothing */
413 if (i
== win
->histIndex
)
415 num
= sizeof(win
->history
) / sizeof(win
->history
[0]);
416 if (win
->histIndex
== num
)
418 /* we're full, remove latest entry */
419 HLPFILE_FreeHlpFile(win
->history
[0]->file
);
420 memmove(&win
->history
[0], &win
->history
[1],
421 (num
- 1) * sizeof(win
->history
[0]));
424 win
->history
[win
->histIndex
++] = page
;
425 page
->file
->wRefCount
++;
426 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
430 memcpy(win
->back
, oldwin
->back
, sizeof(win
->back
));
431 win
->backIndex
= oldwin
->backIndex
;
435 num
= sizeof(win
->back
) / sizeof(win
->back
[0]);
436 if (win
->backIndex
== num
)
438 /* we're full, remove latest entry */
439 HLPFILE_FreeHlpFile(win
->back
[0]->file
);
440 memmove(&win
->back
[0], &win
->back
[1],
441 (num
- 1) * sizeof(win
->back
[0]));
444 win
->back
[win
->backIndex
++] = page
;
445 page
->file
->wRefCount
++;
449 win
->backIndex
= win
->histIndex
= 0;
451 oldwin
->histIndex
= oldwin
->backIndex
= 0;
452 WINHELP_DeleteWindow(oldwin
);
456 /***********************************************************************
458 * WINHELP_CreateHelpWindow
460 BOOL
WINHELP_CreateHelpWindow(HLPFILE_PAGE
* page
, HLPFILE_WINDOWINFO
* wi
,
463 WINHELP_WINDOW
*win
, *oldwin
;
468 bPrimary
= !lstrcmpi(wi
->name
, "main");
469 bPopup
= wi
->win_style
& WS_POPUP
;
471 /* Initialize WINHELP_WINDOW struct */
472 win
= HeapAlloc(GetProcessHeap(), 0,
473 sizeof(WINHELP_WINDOW
) + strlen(wi
->name
) + 1);
474 if (!win
) return FALSE
;
476 win
->next
= Globals
.win_list
;
477 Globals
.win_list
= win
;
479 win
->lpszName
= (char*)win
+ sizeof(WINHELP_WINDOW
);
480 lstrcpy((char*)win
->lpszName
, wi
->name
);
483 win
->first_button
= 0;
486 win
->hButtonBoxWnd
= 0;
489 win
->hHistoryWnd
= 0;
491 win
->hArrowCur
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
492 win
->hHandCur
= LoadCursorA(0, (LPSTR
)IDC_HAND
);
496 Globals
.active_win
= win
;
498 /* Initialize default pushbuttons */
499 if (bPrimary
&& page
)
501 CHAR buffer
[MAX_STRING_LEN
];
503 LoadString(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
504 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
505 LoadString(Globals
.hInstance
, STID_SEARCH
,buffer
, sizeof(buffer
));
506 MACRO_CreateButton("BTN_SEARCH", buffer
, "Search()");
507 LoadString(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
508 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
509 LoadString(Globals
.hInstance
, STID_HISTORY
, buffer
, sizeof(buffer
));
510 MACRO_CreateButton("BTN_HISTORY", buffer
, "History()");
511 LoadString(Globals
.hInstance
, STID_TOPICS
, buffer
, sizeof(buffer
));
512 MACRO_CreateButton("BTN_TOPICS", buffer
, "Finder()");
515 /* Initialize file specific pushbuttons */
516 if (!(wi
->win_style
& WS_POPUP
) && page
)
518 HLPFILE_MACRO
*macro
;
519 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
520 MACRO_ExecuteMacro(macro
->lpszMacro
);
522 for (macro
= page
->first_macro
; macro
; macro
= macro
->next
)
523 MACRO_ExecuteMacro(macro
->lpszMacro
);
526 win
->histIndex
= win
->backIndex
= 0;
527 /* Reuse existing window */
530 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
532 if (!lstrcmpi(oldwin
->lpszName
, wi
->name
))
534 return WINHELP_ReuseWindow(win
, oldwin
, page
, nCmdShow
);
539 win
->histIndex
= win
->backIndex
= 1;
540 win
->history
[0] = win
->back
[0] = page
;
541 page
->file
->wRefCount
+= 2;
542 strcpy(wi
->caption
, page
->file
->lpszTitle
);
546 hWnd
= CreateWindow(bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
547 wi
->caption
, wi
->win_style
,
548 wi
->origin
.x
, wi
->origin
.y
, wi
->size
.cx
, wi
->size
.cy
,
549 0, bPrimary
? LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(MAIN_MENU
)) : 0,
550 Globals
.hInstance
, win
);
552 ShowWindow(hWnd
, nCmdShow
);
558 /***********************************************************************
560 * WINHELP_CreateHelpWindowByHash
562 BOOL
WINHELP_CreateHelpWindowByHash(HLPFILE
* hlpfile
, LONG lHash
,
563 HLPFILE_WINDOWINFO
* wi
, int nCmdShow
)
565 HLPFILE_PAGE
* page
= NULL
;
568 page
= lHash
? HLPFILE_PageByHash(hlpfile
, lHash
) :
569 HLPFILE_Contents(hlpfile
);
570 if (page
) page
->file
->wRefCount
++;
571 return WINHELP_CreateHelpWindow(page
, wi
, nCmdShow
);
574 /***********************************************************************
576 * WINHELP_MainWndProc
578 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
581 WINHELP_BUTTON
*button
;
582 RECT rect
, button_box_rect
;
583 INT text_top
, curPos
, min
, max
, dy
, keyDelta
;
585 WINHELP_CheckPopup(msg
);
590 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
591 SetWindowLong(hWnd
, 0, (LONG
) win
);
592 win
->hMainWnd
= hWnd
;
596 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
598 /* Create button box and text Window */
599 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
600 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
602 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
603 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
607 case WM_WINDOWPOSCHANGED
:
608 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
609 GetClientRect(hWnd
, &rect
);
611 /* Update button box and text Window */
612 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
614 rect
.right
- rect
.left
,
615 rect
.bottom
- rect
.top
, 0);
617 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
618 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
620 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
622 rect
.right
- rect
.left
,
623 rect
.bottom
- text_top
, 0);
628 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
632 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
633 case MNID_FILE_PRINT
: MACRO_Print(); break;
634 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
635 case MNID_FILE_EXIT
: MACRO_Exit(); break;
638 case MNID_EDIT_COPYDLG
: MACRO_CopyDialog(); break;
639 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
642 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
645 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
646 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
647 case MNID_HELP_ABOUT
: MACRO_About(); break;
648 case MNID_HELP_WINE
: ShellAbout(hWnd
, "WINE", "Help", 0); break;
652 for (button
= win
->first_button
; button
; button
= button
->next
)
653 if (wParam
== button
->wParam
) break;
655 MACRO_ExecuteMacro(button
->lpszMacro
);
657 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED
, 0x121, MB_OK
);
662 if (Globals
.hPopupWnd
) DestroyWindow(Globals
.hPopupWnd
);
665 return WINHELP_HandleCommand((HWND
)wParam
, lParam
);
674 keyDelta
= GetSystemMetrics(SM_CXVSCROLL
);
676 keyDelta
= -keyDelta
;
680 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
681 curPos
= GetScrollPos(win
->hTextWnd
, SB_VERT
);
682 GetScrollRange(win
->hTextWnd
, SB_VERT
, &min
, &max
);
686 GetClientRect(win
->hTextWnd
, &rect
);
687 keyDelta
= (rect
.bottom
- rect
.top
) / 2;
688 if (wParam
== VK_PRIOR
)
689 keyDelta
= -keyDelta
;
695 else if (curPos
< min
)
698 dy
= GetScrollPos(win
->hTextWnd
, SB_VERT
) - curPos
;
699 SetScrollPos(win
->hTextWnd
, SB_VERT
, curPos
, TRUE
);
700 ScrollWindow(win
->hTextWnd
, 0, dy
, NULL
, NULL
);
701 UpdateWindow(win
->hTextWnd
);
710 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
713 /***********************************************************************
715 * WINHELP_ButtonBoxWndProc
717 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
721 WINHELP_BUTTON
*button
;
725 WINHELP_CheckPopup(msg
);
730 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
731 SetWindowLong(hWnd
, 0, (LONG
) win
);
732 win
->hButtonBoxWnd
= hWnd
;
735 case WM_WINDOWPOSCHANGING
:
736 winpos
= (WINDOWPOS
*) lParam
;
737 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
742 for (button
= win
->first_button
; button
; button
= button
->next
)
748 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
749 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
751 hWnd
, (HMENU
) button
->wParam
,
752 Globals
.hInstance
, 0);
754 if (Globals
.button_proc
== NULL
)
755 Globals
.button_proc
= (WNDPROC
) GetWindowLong(button
->hWnd
, GWL_WNDPROC
);
756 SetWindowLong(button
->hWnd
, GWL_WNDPROC
, (LONG
) WINHELP_ButtonWndProc
);
759 hDc
= GetDC(button
->hWnd
);
760 GetTextExtentPoint(hDc
, button
->lpszName
,
761 lstrlen(button
->lpszName
), &textsize
);
762 ReleaseDC(button
->hWnd
, hDc
);
764 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
765 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
770 for (button
= win
->first_button
; button
; button
= button
->next
)
772 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
774 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
777 x
= 0, y
+= button_size
.cy
;
779 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
783 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
794 return SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
799 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
802 /***********************************************************************
804 * WINHELP_ButtonWndProc
806 static LRESULT CALLBACK
WINHELP_ButtonWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
808 if (msg
== WM_KEYDOWN
)
817 return SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
821 return CallWindowProc(Globals
.button_proc
, hWnd
, msg
, wParam
, lParam
);
824 /***********************************************************************
826 * WINHELP_TextWndProc
828 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
832 WINHELP_LINE_PART
*part
;
841 if (msg
!= WM_LBUTTONDOWN
)
842 WINHELP_CheckPopup(msg
);
847 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
848 SetWindowLong(hWnd
, 0, (LONG
) win
);
849 win
->hTextWnd
= hWnd
;
850 if (win
->info
->win_style
& WS_POPUP
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
851 WINHELP_InitFonts(hWnd
);
855 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
857 /* Calculate vertical size and position of a popup window */
858 if (win
->info
->win_style
& WS_POPUP
)
861 RECT old_window_rect
;
862 RECT old_client_rect
;
863 SIZE old_window_size
;
864 SIZE old_client_size
;
865 SIZE new_client_size
;
866 SIZE new_window_size
;
868 GetWindowRect(hWnd
, &old_window_rect
);
869 origin
.x
= old_window_rect
.left
;
870 origin
.y
= old_window_rect
.top
;
871 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
872 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
874 GetClientRect(hWnd
, &old_client_rect
);
875 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
876 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
878 new_client_size
= old_client_size
;
879 WINHELP_SplitLines(hWnd
, &new_client_size
);
881 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
882 origin
.y
+= POPUP_YDISTANCE
;
884 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
886 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
887 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
890 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
,
891 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
892 new_window_size
.cx
, new_window_size
.cy
,
893 0, 0, Globals
.hInstance
, 0);
895 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
896 new_window_size
.cx
, new_window_size
.cy
,
898 SetWindowPos(win
->hShadowWnd
, hWnd
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
899 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
900 SetActiveWindow(hWnd
);
904 case WM_WINDOWPOSCHANGED
:
905 winpos
= (WINDOWPOS
*) lParam
;
907 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
913 UINT scrollLines
= 3;
914 int curPos
= GetScrollPos(hWnd
, SB_VERT
);
917 GetScrollRange(hWnd
, SB_VERT
, &min
, &max
);
919 SystemParametersInfo(SPI_GETWHEELSCROLLLINES
,0, &scrollLines
, 0);
920 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
921 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
922 wheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
923 if (abs(wheelDelta
) >= WHEEL_DELTA
&& scrollLines
) {
926 curPos
+= wheelDelta
;
929 else if (curPos
< min
)
932 dy
= GetScrollPos(hWnd
, SB_VERT
) - curPos
;
933 SetScrollPos(hWnd
, SB_VERT
, curPos
, TRUE
);
934 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
945 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
948 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
949 GetClientRect(hWnd
, &rect
);
951 switch (wParam
& 0xffff)
954 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
955 case SB_TOP
: CurPos
= Min
; break;
956 case SB_BOTTOM
: CurPos
= Max
; break;
957 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
958 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
959 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
960 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
961 default: update
= FALSE
;
967 else if (CurPos
< Min
)
969 dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
970 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
971 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
978 hDc
= BeginPaint(hWnd
, &ps
);
979 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
980 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
982 for (line
= win
->first_line
; line
; line
= line
->next
)
984 for (part
= &line
->first_part
; part
; part
= part
->next
)
986 switch (part
->cookie
)
988 case hlp_line_part_text
:
989 SelectObject(hDc
, part
->u
.text
.hFont
);
990 SetTextColor(hDc
, part
->u
.text
.color
);
991 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
992 part
->u
.text
.lpsText
, part
->u
.text
.wTextLen
);
993 if (part
->u
.text
.wUnderline
)
997 switch (part
->u
.text
.wUnderline
)
1000 case 2: /* double */
1001 hPen
= CreatePen(PS_SOLID
, 1, part
->u
.text
.color
);
1003 case 3: /* dotted */
1004 hPen
= CreatePen(PS_DOT
, 1, part
->u
.text
.color
);
1007 WINE_FIXME("Unknow underline type\n");
1011 SelectObject(hDc
, hPen
);
1012 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
- 1, NULL
);
1013 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
- 1);
1014 if (part
->u
.text
.wUnderline
== 2)
1016 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
+ 1, NULL
);
1017 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
+ 1);
1022 case hlp_line_part_bitmap
:
1026 hMemDC
= CreateCompatibleDC(hDc
);
1027 SelectObject(hMemDC
, part
->u
.bitmap
.hBitmap
);
1028 BitBlt(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
1029 part
->rect
.right
- part
->rect
.left
, part
->rect
.bottom
- part
->rect
.top
,
1030 hMemDC
, 0, 0, SRCCOPY
);
1034 case hlp_line_part_metafile
:
1038 SetViewportOrgEx(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
, &pt
);
1039 PlayMetaFile(hDc
, part
->u
.metafile
.hMetaFile
);
1040 SetViewportOrgEx(hDc
, pt
.x
, pt
.y
, NULL
);
1047 EndPaint(hWnd
, &ps
);
1051 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1053 if (WINHELP_IsOverLink(win
, wParam
, lParam
))
1054 SetCursor(win
->hHandCur
); /* set to hand pointer cursor to indicate a link */
1056 SetCursor(win
->hArrowCur
); /* set to hand pointer cursor to indicate a link */
1060 case WM_LBUTTONDOWN
:
1061 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1063 hPopupWnd
= Globals
.hPopupWnd
;
1064 Globals
.hPopupWnd
= 0;
1066 part
= WINHELP_IsOverLink(win
, wParam
, lParam
);
1070 HLPFILE_WINDOWINFO
* wi
;
1072 mouse
.x
= LOWORD(lParam
);
1073 mouse
.y
= HIWORD(lParam
);
1075 if (part
->link
) switch (part
->link
->cookie
)
1078 hlpfile
= WINHELP_LookupHelpFile(part
->link
->lpszString
);
1079 if (part
->link
->window
== -1)
1081 else if (part
->link
->window
< hlpfile
->numWindows
)
1082 wi
= &hlpfile
->windows
[part
->link
->window
];
1085 WINE_WARN("link to window %d/%d\n", part
->link
->window
, hlpfile
->numWindows
);
1088 WINHELP_CreateHelpWindowByHash(hlpfile
, part
->link
->lHash
, wi
,
1091 case hlp_link_popup
:
1092 hlpfile
= WINHELP_LookupHelpFile(part
->link
->lpszString
);
1093 WINHELP_CreateHelpWindowByHash(hlpfile
, part
->link
->lHash
,
1094 WINHELP_GetPopupWindowInfo(hlpfile
, hWnd
, &mouse
),
1097 case hlp_link_macro
:
1098 MACRO_ExecuteMacro(part
->link
->lpszString
);
1101 WINE_FIXME("Unknown link cookie %d\n", part
->link
->cookie
);
1106 DestroyWindow(hPopupWnd
);
1110 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1112 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
1114 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
1116 WINHELP_DeleteWindow(win
);
1118 if (bExit
) MACRO_Exit();
1120 if (!Globals
.win_list
)
1125 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1128 /******************************************************************
1129 * WINHELP_HistoryWndProc
1133 static LRESULT CALLBACK
WINHELP_HistoryWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1135 WINHELP_WINDOW
* win
;
1145 win
= (WINHELP_WINDOW
*)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
1146 SetWindowLong(hWnd
, 0, (LONG
)win
);
1147 win
->hHistoryWnd
= hWnd
;
1150 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1152 GetTextMetrics(hDc
, &tm
);
1153 GetWindowRect(hWnd
, &r
);
1155 r
.right
= r
.left
+ 30 * tm
.tmAveCharWidth
;
1156 r
.bottom
= r
.top
+ (sizeof(win
->history
) / sizeof(win
->history
[0])) * tm
.tmHeight
;
1157 AdjustWindowRect(&r
, GetWindowLong(hWnd
, GWL_STYLE
), FALSE
);
1158 if (r
.left
< 0) {r
.right
-= r
.left
; r
.left
= 0;}
1159 if (r
.top
< 0) {r
.bottom
-= r
.top
; r
.top
= 0;}
1161 MoveWindow(hWnd
, r
.left
, r
.top
, r
.right
, r
.bottom
, TRUE
);
1162 ReleaseDC(hWnd
, hDc
);
1164 case WM_LBUTTONDOWN
:
1165 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1167 GetTextMetrics(hDc
, &tm
);
1168 i
= HIWORD(lParam
) / tm
.tmHeight
;
1169 if (i
< win
->histIndex
)
1170 WINHELP_CreateHelpWindow(win
->history
[i
], win
->info
, SW_SHOW
);
1171 ReleaseDC(hWnd
, hDc
);
1174 hDc
= BeginPaint(hWnd
, &ps
);
1175 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1176 GetTextMetrics(hDc
, &tm
);
1178 for (i
= 0; i
< win
->histIndex
; i
++)
1180 TextOut(hDc
, 0, i
* tm
.tmHeight
, win
->history
[i
]->lpszTitle
,
1181 strlen(win
->history
[i
]->lpszTitle
));
1183 EndPaint(hWnd
, &ps
);
1186 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1187 if (hWnd
== win
->hHistoryWnd
)
1188 win
->hHistoryWnd
= 0;
1191 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1194 /***********************************************************************
1196 * WINHELP_ShadowWndProc
1198 static LRESULT CALLBACK
WINHELP_ShadowWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1200 WINHELP_CheckPopup(msg
);
1201 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1204 /***********************************************************************
1208 static void WINHELP_SetupText(HWND hWnd
)
1210 HDC hDc
= GetDC(hWnd
);
1214 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
1215 if (!WINHELP_SplitLines(hWnd
, NULL
))
1217 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
1218 GetClientRect(hWnd
, &rect
);
1220 WINHELP_SplitLines(hWnd
, &newsize
);
1221 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
1225 SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
1226 SetScrollRange(hWnd
, SB_VERT
, 0, 0, FALSE
);
1229 ReleaseDC(hWnd
, hDc
);
1232 /***********************************************************************
1234 * WINHELP_AppendText
1236 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
1237 LPSIZE space
, LPSIZE textsize
,
1238 INT
*line_ascent
, INT ascent
,
1239 LPCSTR text
, UINT textlen
,
1240 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
,
1244 WINHELP_LINE_PART
*part
;
1247 if (!*partp
) /* New line */
1249 *line_ascent
= ascent
;
1251 line
= HeapAlloc(GetProcessHeap(), 0,
1252 sizeof(WINHELP_LINE
) + textlen
);
1253 if (!line
) return FALSE
;
1256 part
= &line
->first_part
;
1257 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
1259 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
1260 line
->rect
.bottom
= line
->rect
.top
;
1261 line
->rect
.left
= space
->cx
;
1262 line
->rect
.right
= space
->cx
;
1264 if (**linep
) *linep
= &(**linep
)->next
;
1268 else /* Same line */
1272 if (*line_ascent
< ascent
)
1274 WINHELP_LINE_PART
*p
;
1275 for (p
= &line
->first_part
; p
; p
= p
->next
)
1277 p
->rect
.top
+= ascent
- *line_ascent
;
1278 p
->rect
.bottom
+= ascent
- *line_ascent
;
1280 line
->rect
.bottom
+= ascent
- *line_ascent
;
1281 *line_ascent
= ascent
;
1284 part
= HeapAlloc(GetProcessHeap(), 0,
1285 sizeof(WINHELP_LINE_PART
) + textlen
);
1286 if (!part
) return FALSE
;
1288 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
1291 memcpy(ptr
, text
, textlen
);
1292 part
->cookie
= hlp_line_part_text
;
1293 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
1294 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
1295 line
->rect
.right
= part
->rect
.right
;
1297 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
1298 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
1299 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
1300 part
->u
.text
.lpsText
= ptr
;
1301 part
->u
.text
.wTextLen
= textlen
;
1302 part
->u
.text
.hFont
= font
;
1303 part
->u
.text
.color
= color
;
1304 part
->u
.text
.wUnderline
= underline
;
1306 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1307 part
->u
.text
.wTextLen
,
1308 part
->u
.text
.wTextLen
,
1309 part
->u
.text
.lpsText
,
1310 part
->u
.text
.wTextLen
,
1311 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1314 if (link
) link
->wRefCount
++;
1317 *partp
= &part
->next
;
1324 /***********************************************************************
1326 * WINHELP_AppendGfxObject
1328 static WINHELP_LINE_PART
* WINHELP_AppendGfxObject(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
1329 LPSIZE space
, LPSIZE gfxSize
,
1330 HLPFILE_LINK
*link
, unsigned pos
)
1333 WINHELP_LINE_PART
*part
;
1336 if (!*partp
|| pos
== 1) /* New line */
1338 line
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE
));
1339 if (!line
) return NULL
;
1342 part
= &line
->first_part
;
1344 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
1345 line
->rect
.bottom
= line
->rect
.top
;
1346 line
->rect
.left
= space
->cx
;
1347 line
->rect
.right
= space
->cx
;
1349 if (**linep
) *linep
= &(**linep
)->next
;
1352 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
1354 else /* Same line */
1356 if (pos
== 2) WINE_FIXME("Left alignment not handled\n");
1359 part
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART
));
1360 if (!part
) return NULL
;
1362 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
1365 /* part->cookie should be set by caller (image or metafile) */
1366 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
1367 part
->rect
.right
= part
->rect
.left
+ gfxSize
->cx
;
1368 line
->rect
.right
= part
->rect
.right
;
1369 part
->rect
.top
= (*partp
) ? line
->rect
.top
: line
->rect
.bottom
;
1370 part
->rect
.bottom
= part
->rect
.top
+ gfxSize
->cy
;
1371 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
1373 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1374 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1377 if (link
) link
->wRefCount
++;
1380 *partp
= &part
->next
;
1388 /***********************************************************************
1390 * WINHELP_SplitLines
1392 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
1394 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1395 HLPFILE_PARAGRAPH
*p
;
1396 WINHELP_LINE
**line
= &win
->first_line
;
1397 WINHELP_LINE_PART
**part
= 0;
1398 INT line_ascent
= 0;
1403 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
1405 if (!win
->page
) return TRUE
;
1407 WINHELP_DeleteLines(win
);
1409 GetClientRect(hWnd
, &rect
);
1411 rect
.top
+= INTERNAL_BORDER_WIDTH
;
1412 rect
.left
+= INTERNAL_BORDER_WIDTH
;
1413 rect
.right
-= INTERNAL_BORDER_WIDTH
;
1414 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
1416 space
.cy
= rect
.top
;
1417 space
.cx
= rect
.left
;
1421 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
1425 case para_normal_text
:
1426 case para_debug_text
:
1429 SIZE textsize
= {0, 0};
1430 LPCSTR text
= p
->u
.text
.lpszText
;
1432 UINT len
= strlen(text
);
1433 unsigned underline
= 0;
1436 COLORREF color
= RGB(0, 0, 0);
1438 if (p
->u
.text
.wFont
< win
->page
->file
->numFonts
)
1440 HLPFILE
* hlpfile
= win
->page
->file
;
1442 if (!hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
)
1443 hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
= CreateFontIndirect(&hlpfile
->fonts
[p
->u
.text
.wFont
].LogFont
);
1444 hFont
= hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
;
1445 color
= hlpfile
->fonts
[p
->u
.text
.wFont
].color
;
1449 UINT wFont
= (p
->u
.text
.wFont
< win
->fonts_len
) ? p
->u
.text
.wFont
: 0;
1451 hFont
= win
->fonts
[wFont
];
1454 if (p
->link
&& p
->link
->bClrChange
)
1456 underline
= (p
->link
->cookie
== hlp_link_popup
) ? 3 : 1;
1457 color
= RGB(0, 0x80, 0);
1459 if (p
->cookie
== para_debug_text
) color
= RGB(0xff, 0, 0);
1461 SelectObject(hDc
, hFont
);
1463 GetTextMetrics(hDc
, &tm
);
1465 if (p
->u
.text
.wIndent
)
1467 indent
= p
->u
.text
.wIndent
* 5 * tm
.tmAveCharWidth
;
1469 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
1472 if (p
->u
.text
.wVSpace
)
1475 space
.cx
= rect
.left
+ indent
;
1476 space
.cy
+= (p
->u
.text
.wVSpace
- 1) * tm
.tmHeight
;
1479 if (p
->u
.text
.wHSpace
)
1481 space
.cx
+= p
->u
.text
.wHSpace
* 2 * tm
.tmAveCharWidth
;
1484 WINE_TRACE("splitting text %s\n", text
);
1488 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1489 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
1495 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
1497 if (textsize
.cx
<= free_width
) low
= curr
;
1500 if (high
<= low
+ 1) break;
1502 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
1503 if (curr
<= low
) curr
= low
+ 1;
1504 else if (curr
>= high
) curr
= high
- 1;
1507 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
1509 if (!part
&& !textlen
) textlen
= max(low
, 1);
1511 if (free_width
<= 0 || !textlen
)
1514 space
.cx
= rect
.left
+ indent
;
1515 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1519 WINE_TRACE("\t => %d %*s\n", textlen
, textlen
, text
);
1521 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
1522 &line_ascent
, tm
.tmAscent
,
1523 text
, textlen
, hFont
, color
, p
->link
, underline
) ||
1524 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1526 ReleaseDC(hWnd
, hDc
);
1531 newsize
->cx
= max(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
1535 if (text
[0] == ' ') text
++, len
--;
1544 WINHELP_LINE_PART
* ref_part
;
1546 if (p
->u
.gfx
.pos
& 0x8000)
1548 space
.cx
= rect
.left
;
1550 space
.cy
+= (*line
)->rect
.bottom
- (*line
)->rect
.top
;
1554 if (p
->cookie
== para_bitmap
)
1558 GetObject(p
->u
.gfx
.u
.bmp
.hBitmap
, sizeof(dibs
), &dibs
);
1559 gfxSize
.cx
= dibs
.dsBm
.bmWidth
;
1560 gfxSize
.cy
= dibs
.dsBm
.bmHeight
;
1562 else gfxSize
= p
->u
.gfx
.u
.mf
.mfSize
;
1564 free_width
= rect
.right
- ((part
&& *line
) ? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1565 if (free_width
<= 0)
1568 space
.cx
= rect
.left
;
1569 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1571 ref_part
= WINHELP_AppendGfxObject(&line
, &part
, &space
, &gfxSize
,
1572 p
->link
, p
->u
.gfx
.pos
);
1573 if (!ref_part
|| (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1577 if (p
->cookie
== para_bitmap
)
1579 ref_part
->cookie
= hlp_line_part_bitmap
;
1580 ref_part
->u
.bitmap
.hBitmap
= p
->u
.gfx
.u
.bmp
.hBitmap
;
1584 ref_part
->cookie
= hlp_line_part_metafile
;
1585 ref_part
->u
.metafile
.hMetaFile
= p
->u
.gfx
.u
.mf
.hMetaFile
;
1593 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
1595 ReleaseDC(hWnd
, hDc
);
1599 /***********************************************************************
1601 * WINHELP_CheckPopup
1603 static void WINHELP_CheckPopup(UINT msg
)
1605 if (!Globals
.hPopupWnd
) return;
1610 case WM_LBUTTONDOWN
:
1611 case WM_MBUTTONDOWN
:
1612 case WM_RBUTTONDOWN
:
1613 case WM_NCLBUTTONDOWN
:
1614 case WM_NCMBUTTONDOWN
:
1615 case WM_NCRBUTTONDOWN
:
1616 DestroyWindow(Globals
.hPopupWnd
);
1617 Globals
.hPopupWnd
= 0;
1621 /***********************************************************************
1623 * WINHELP_DeleteLines
1625 static void WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
1627 WINHELP_LINE
*line
, *next_line
;
1628 WINHELP_LINE_PART
*part
, *next_part
;
1629 for (line
= win
->first_line
; line
; line
= next_line
)
1631 next_line
= line
->next
;
1632 for (part
= &line
->first_part
; part
; part
= next_part
)
1634 next_part
= part
->next
;
1635 HLPFILE_FreeLink(part
->link
);
1636 HeapFree(GetProcessHeap(), 0, part
);
1639 win
->first_line
= 0;
1642 /***********************************************************************
1644 * WINHELP_DeleteWindow
1646 static void WINHELP_DeleteWindow(WINHELP_WINDOW
* win
)
1653 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
1662 for (b
= win
->first_button
; b
; b
= bp
)
1664 DestroyWindow(b
->hWnd
);
1666 HeapFree(GetProcessHeap(), 0, b
);
1669 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
1670 if (win
->hHistoryWnd
) DestroyWindow(win
->hHistoryWnd
);
1672 for (i
= 0; i
< win
->histIndex
; i
++)
1674 HLPFILE_FreeHlpFile(win
->history
[i
]->file
);
1677 for (i
= 0; i
< win
->backIndex
; i
++)
1678 HLPFILE_FreeHlpFile(win
->back
[i
]->file
);
1680 if (win
->page
) HLPFILE_FreeHlpFile(win
->page
->file
);
1681 WINHELP_DeleteLines(win
);
1682 HeapFree(GetProcessHeap(), 0, win
);
1685 /***********************************************************************
1689 static void WINHELP_InitFonts(HWND hWnd
)
1691 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1692 LOGFONT logfontlist
[] = {
1693 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1694 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1695 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1696 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1697 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1698 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1699 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1700 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1702 static HFONT fonts
[FONTS_LEN
];
1703 static BOOL init
= 0;
1705 win
->fonts_len
= FONTS_LEN
;
1712 for (i
= 0; i
< FONTS_LEN
; i
++)
1714 fonts
[i
] = CreateFontIndirect(&logfontlist
[i
]);
1721 /***********************************************************************
1723 * WINHELP_MessageBoxIDS
1725 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1727 CHAR text
[MAX_STRING_LEN
];
1728 CHAR title
[MAX_STRING_LEN
];
1730 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1731 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1733 return MessageBox(0, text
, title
, type
);
1736 /***********************************************************************
1738 * MAIN_MessageBoxIDS_s
1740 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1742 CHAR text
[MAX_STRING_LEN
];
1743 CHAR title
[MAX_STRING_LEN
];
1744 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1746 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1747 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1748 wsprintf(newtext
, text
, str
);
1750 return MessageBox(0, newtext
, title
, type
);
1753 /******************************************************************
1754 * WINHELP_IsOverLink
1758 WINHELP_LINE_PART
* WINHELP_IsOverLink(WINHELP_WINDOW
* win
, WPARAM wParam
, LPARAM lParam
)
1762 WINHELP_LINE_PART
*part
;
1763 int scroll_pos
= GetScrollPos(win
->hTextWnd
, SB_VERT
);
1765 mouse
.x
= LOWORD(lParam
);
1766 mouse
.y
= HIWORD(lParam
);
1767 for (line
= win
->first_line
; line
; line
= line
->next
)
1769 for (part
= &line
->first_part
; part
; part
= part
->next
)
1772 part
->link
->lpszString
&&
1773 part
->rect
.left
<= mouse
.x
&&
1774 part
->rect
.right
>= mouse
.x
&&
1775 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
1776 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)