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
34 #include "winhelp_res.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
41 static BOOL
WINHELP_RegisterWinClasses(void);
42 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
43 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
44 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
45 static LRESULT CALLBACK
WINHELP_HistoryWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
46 static void WINHELP_CheckPopup(UINT
);
47 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
48 static void WINHELP_InitFonts(HWND hWnd
);
49 static void WINHELP_DeleteLines(WINHELP_WINDOW
*);
50 static void WINHELP_DeleteWindow(WINHELP_WINDOW
*);
51 static void WINHELP_SetupText(HWND hWnd
);
52 static WINHELP_LINE_PART
* WINHELP_IsOverLink(WINHELP_WINDOW
*, WPARAM
, LPARAM
);
54 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 1, 0, 0};
56 /***********************************************************************
58 * WINHELP_LookupHelpFile
60 HLPFILE
* WINHELP_LookupHelpFile(LPCSTR lpszFile
)
64 hlpfile
= HLPFILE_ReadHlpFile(lpszFile
);
66 /* Add Suffix `.hlp' */
67 if (!hlpfile
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp") != 0)
69 char szFile_hlp
[MAX_PATHNAME_LEN
];
71 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
72 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
73 lstrcat(szFile_hlp
, ".hlp");
75 hlpfile
= HLPFILE_ReadHlpFile(szFile_hlp
);
79 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s
, lpszFile
, STID_WHERROR
, MB_OK
);
80 if (Globals
.win_list
) return NULL
;
85 /******************************************************************
86 * WINHELP_GetWindowInfo
90 HLPFILE_WINDOWINFO
* WINHELP_GetWindowInfo(HLPFILE
* hlpfile
, LPCSTR name
)
92 static HLPFILE_WINDOWINFO mwi
;
95 if (!name
|| !name
[0])
96 name
= Globals
.active_win
->lpszName
;
99 for (i
= 0; i
< hlpfile
->numWindows
; i
++)
100 if (!strcmp(hlpfile
->windows
[i
].name
, name
))
101 return &hlpfile
->windows
[i
];
103 if (strcmp(name
, "main") != 0)
105 WINE_FIXME("Couldn't find window info for %s\n", name
);
111 strcpy(mwi
.type
, "primary");
112 strcpy(mwi
.name
, "main");
113 if (!LoadString(Globals
.hInstance
, STID_WINE_HELP
,
114 mwi
.caption
, sizeof(mwi
.caption
)))
115 strcpy(mwi
.caption
, hlpfile
->lpszTitle
);
116 mwi
.origin
.x
= mwi
.origin
.y
= mwi
.size
.cx
= mwi
.size
.cy
= CW_USEDEFAULT
;
118 mwi
.win_style
= WS_OVERLAPPEDWINDOW
;
119 mwi
.sr_color
= mwi
.sr_color
= 0xFFFFFF;
124 /******************************************************************
125 * HLPFILE_GetPopupWindowInfo
129 HLPFILE_WINDOWINFO
* WINHELP_GetPopupWindowInfo(HLPFILE
* hlpfile
, HWND hParentWnd
, POINT
* mouse
)
131 static HLPFILE_WINDOWINFO wi
;
135 wi
.type
[0] = wi
.name
[0] = wi
.caption
[0] = '\0';
137 /* Calculate horizontal size and position of a popup window */
138 GetWindowRect(hParentWnd
, &parent_rect
);
139 wi
.size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
140 wi
.size
.cy
= 10; /* need a non null value, so that border are taken into account while computing */
143 ClientToScreen(hParentWnd
, &wi
.origin
);
144 wi
.origin
.x
-= wi
.size
.cx
/ 2;
145 wi
.origin
.x
= min(wi
.origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - wi
.size
.cx
);
146 wi
.origin
.x
= max(wi
.origin
.x
, 0);
149 wi
.win_style
= WS_POPUPWINDOW
;
150 wi
.sr_color
= wi
.sr_color
= 0xFFFFFF;
155 /***********************************************************************
159 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
165 Globals
.hInstance
= hInstance
;
168 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
172 if (*cmdline
++ == ' ') continue;
175 if (option
) cmdline
++;
176 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
182 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
183 if (*cmdline
) *cmdline
++ = '\0';
184 lHash
= HLPFILE_Hash(topic_id
);
189 Globals
.wVersion
= option
- '0';
194 Globals
.isBook
= FALSE
;
198 WINE_FIXME("Unsupported cmd line: %s\n", cmdline
);
203 /* Create primary window */
204 WINHELP_RegisterWinClasses();
207 hlpfile
= WINHELP_LookupHelpFile(cmdline
);
208 if (!hlpfile
) return 0;
211 WINHELP_CreateHelpWindowByHash(hlpfile
, lHash
,
212 WINHELP_GetWindowInfo(hlpfile
, "main"), show
);
215 while (GetMessage(&msg
, 0, 0, 0))
217 TranslateMessage(&msg
);
218 DispatchMessage(&msg
);
223 /***********************************************************************
227 static BOOL
WINHELP_RegisterWinClasses(void)
229 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
, class_history
;
231 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
232 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
233 class_main
.cbClsExtra
= 0;
234 class_main
.cbWndExtra
= sizeof(LONG
);
235 class_main
.hInstance
= Globals
.hInstance
;
236 class_main
.hIcon
= LoadIcon(0, IDI_APPLICATION
);
237 class_main
.hCursor
= LoadCursor(0, IDC_ARROW
);
238 class_main
.hbrBackground
= GetStockObject(WHITE_BRUSH
);
239 class_main
.lpszMenuName
= 0;
240 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
242 class_button_box
= class_main
;
243 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
244 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
245 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
247 class_text
= class_main
;
248 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
249 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
251 class_shadow
= class_main
;
252 class_shadow
.lpfnWndProc
= DefWindowProc
;
253 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
254 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
256 class_history
= class_main
;
257 class_history
.lpfnWndProc
= WINHELP_HistoryWndProc
;
258 class_history
.lpszClassName
= HISTORY_WIN_CLASS_NAME
;
260 return (RegisterClass(&class_main
) &&
261 RegisterClass(&class_button_box
) &&
262 RegisterClass(&class_text
) &&
263 RegisterClass(&class_shadow
) &&
264 RegisterClass(&class_history
));
275 } WINHELP
,*LPWINHELP
;
277 /******************************************************************
278 * WINHELP_HandleCommand
282 static LRESULT
WINHELP_HandleCommand(HWND hSrcWnd
, LPARAM lParam
)
284 COPYDATASTRUCT
* cds
= (COPYDATASTRUCT
*)lParam
;
287 if (cds
->dwData
!= 0xA1DE505)
289 WINE_FIXME("Wrong magic number (%08lx)\n", cds
->dwData
);
293 wh
= (WINHELP
*)cds
->lpData
;
297 char* ptr
= (wh
->ofsFilename
) ? (LPSTR
)wh
+ wh
->ofsFilename
: NULL
;
299 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
300 wh
->size
, wh
->command
, wh
->data
, ptr
);
306 MACRO_JumpContext(ptr
, "main", wh
->data
);
315 MACRO_JumpContents(ptr
, "main");
318 case HELP_HELPONHELP
:
321 /* case HELP_SETINDEX: */
322 case HELP_SETCONTENTS
:
325 MACRO_SetContents(ptr
, wh
->data
);
328 case HELP_CONTEXTPOPUP
:
331 MACRO_PopupContext(ptr
, wh
->data
);
334 /* case HELP_FORCEFILE:*/
335 /* case HELP_CONTEXTMENU: */
337 /* in fact, should be the topic dialog box */
340 MACRO_JumpHash(ptr
, "main", 0);
343 /* case HELP_WM_HELP: */
344 /* case HELP_SETPOPUP_POS: */
346 /* case HELP_COMMAND: */
347 /* case HELP_PARTIALKEY: */
348 /* case HELP_MULTIKEY: */
349 /* case HELP_SETWINPOS: */
350 WINE_FIXME("Unknown command (%x) for remote winhelp control\n", wh
->command
);
357 /******************************************************************
358 * WINHELP_ReuseWindow
362 static BOOL
WINHELP_ReuseWindow(WINHELP_WINDOW
* win
, WINHELP_WINDOW
* oldwin
,
363 HLPFILE_PAGE
* page
, int nCmdShow
)
367 win
->hMainWnd
= oldwin
->hMainWnd
;
368 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
369 win
->hTextWnd
= oldwin
->hTextWnd
;
370 win
->hHistoryWnd
= oldwin
->hHistoryWnd
;
371 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= oldwin
->hHistoryWnd
= 0;
373 SetWindowLong(win
->hMainWnd
, 0, (LONG
)win
);
374 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
)win
);
375 SetWindowLong(win
->hTextWnd
, 0, (LONG
)win
);
376 SetWindowLong(win
->hHistoryWnd
, 0, (LONG
)win
);
378 WINHELP_InitFonts(win
->hMainWnd
);
381 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
383 WINHELP_SetupText(win
->hTextWnd
);
384 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
385 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
386 ShowWindow(win
->hMainWnd
, nCmdShow
);
387 UpdateWindow(win
->hTextWnd
);
389 if (!(win
->info
->win_style
& WS_POPUP
))
393 memcpy(win
->history
, oldwin
->history
, sizeof(win
->history
));
394 win
->histIndex
= oldwin
->histIndex
;
396 /* FIXME: when using back, we shouldn't update the history... */
400 for (i
= 0; i
< win
->histIndex
; i
++)
401 if (win
->history
[i
] == page
) break;
403 /* if the new page is already in the history, do nothing */
404 if (i
== win
->histIndex
)
406 num
= sizeof(win
->history
) / sizeof(win
->history
[0]);
407 if (win
->histIndex
== num
)
409 /* we're full, remove latest entry */
410 HLPFILE_FreeHlpFile(win
->history
[0]->file
);
411 memmove(&win
->history
[0], &win
->history
[1],
412 (num
- 1) * sizeof(win
->history
[0]));
415 win
->history
[win
->histIndex
++] = page
;
416 page
->file
->wRefCount
++;
417 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
421 memcpy(win
->back
, oldwin
->back
, sizeof(win
->back
));
422 win
->backIndex
= oldwin
->backIndex
;
426 num
= sizeof(win
->back
) / sizeof(win
->back
[0]);
427 if (win
->backIndex
== num
)
429 /* we're full, remove latest entry */
430 HLPFILE_FreeHlpFile(win
->back
[0]->file
);
431 memmove(&win
->back
[0], &win
->back
[1],
432 (num
- 1) * sizeof(win
->back
[0]));
435 win
->back
[win
->backIndex
++] = page
;
436 page
->file
->wRefCount
++;
440 win
->backIndex
= win
->histIndex
= 0;
442 oldwin
->histIndex
= oldwin
->backIndex
= 0;
443 WINHELP_DeleteWindow(oldwin
);
447 /***********************************************************************
449 * WINHELP_CreateHelpWindow
451 BOOL
WINHELP_CreateHelpWindow(HLPFILE_PAGE
* page
, HLPFILE_WINDOWINFO
* wi
,
454 WINHELP_WINDOW
*win
, *oldwin
;
459 bPrimary
= !lstrcmpi(wi
->name
, "main");
460 bPopup
= wi
->win_style
& WS_POPUP
;
462 /* Initialize WINHELP_WINDOW struct */
463 win
= HeapAlloc(GetProcessHeap(), 0,
464 sizeof(WINHELP_WINDOW
) + strlen(wi
->name
) + 1);
465 if (!win
) return FALSE
;
467 win
->next
= Globals
.win_list
;
468 Globals
.win_list
= win
;
470 win
->lpszName
= (char*)win
+ sizeof(WINHELP_WINDOW
);
471 lstrcpy((char*)win
->lpszName
, wi
->name
);
474 win
->first_button
= 0;
477 win
->hButtonBoxWnd
= 0;
480 win
->hHistoryWnd
= 0;
482 win
->hArrowCur
= LoadCursorA(0, (LPSTR
)IDC_ARROW
);
483 win
->hHandCur
= LoadCursorA(0, (LPSTR
)IDC_HAND
);
487 Globals
.active_win
= win
;
489 /* Initialize default pushbuttons */
490 if (bPrimary
&& page
)
492 CHAR buffer
[MAX_STRING_LEN
];
494 LoadString(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
495 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
496 LoadString(Globals
.hInstance
, STID_SEARCH
,buffer
, sizeof(buffer
));
497 MACRO_CreateButton("BTN_SEARCH", buffer
, "Search()");
498 LoadString(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
499 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
500 LoadString(Globals
.hInstance
, STID_HISTORY
, buffer
, sizeof(buffer
));
501 MACRO_CreateButton("BTN_HISTORY", buffer
, "History()");
502 LoadString(Globals
.hInstance
, STID_TOPICS
, buffer
, sizeof(buffer
));
503 MACRO_CreateButton("BTN_TOPICS", buffer
, "Finder()");
506 /* Initialize file specific pushbuttons */
507 if (!(wi
->win_style
& WS_POPUP
) && page
)
509 HLPFILE_MACRO
*macro
;
510 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
511 MACRO_ExecuteMacro(macro
->lpszMacro
);
513 for (macro
= page
->first_macro
; macro
; macro
= macro
->next
)
514 MACRO_ExecuteMacro(macro
->lpszMacro
);
517 win
->histIndex
= win
->backIndex
= 0;
518 /* Reuse existing window */
521 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
523 if (!lstrcmpi(oldwin
->lpszName
, wi
->name
))
525 return WINHELP_ReuseWindow(win
, oldwin
, page
, nCmdShow
);
530 win
->histIndex
= win
->backIndex
= 1;
531 win
->history
[0] = win
->back
[0] = page
;
532 page
->file
->wRefCount
+= 2;
536 hWnd
= CreateWindow(bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
537 wi
->caption
, wi
->win_style
,
538 wi
->origin
.x
, wi
->origin
.y
, wi
->size
.cx
, wi
->size
.cy
,
539 0, bPrimary
? LoadMenu(Globals
.hInstance
, MAKEINTRESOURCE(MAIN_MENU
)) : 0,
540 Globals
.hInstance
, win
);
542 ShowWindow(hWnd
, nCmdShow
);
548 /***********************************************************************
550 * WINHELP_CreateHelpWindowByHash
552 BOOL
WINHELP_CreateHelpWindowByHash(HLPFILE
* hlpfile
, LONG lHash
,
553 HLPFILE_WINDOWINFO
* wi
, int nCmdShow
)
555 HLPFILE_PAGE
* page
= NULL
;
558 page
= lHash
? HLPFILE_PageByHash(hlpfile
, lHash
) :
559 HLPFILE_Contents(hlpfile
);
560 if (page
) page
->file
->wRefCount
++;
561 return WINHELP_CreateHelpWindow(page
, wi
, nCmdShow
);
564 /***********************************************************************
566 * WINHELP_MainWndProc
568 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
571 WINHELP_BUTTON
*button
;
572 RECT rect
, button_box_rect
;
575 WINHELP_CheckPopup(msg
);
580 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
581 SetWindowLong(hWnd
, 0, (LONG
) win
);
582 win
->hMainWnd
= hWnd
;
586 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
588 /* Create button box and text Window */
589 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
590 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
592 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
593 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
597 case WM_WINDOWPOSCHANGED
:
598 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
599 GetClientRect(hWnd
, &rect
);
601 /* Update button box and text Window */
602 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
604 rect
.right
- rect
.left
,
605 rect
.bottom
- rect
.top
, 0);
607 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
608 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
610 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
612 rect
.right
- rect
.left
,
613 rect
.bottom
- text_top
, 0);
618 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
622 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
623 case MNID_FILE_PRINT
: MACRO_Print(); break;
624 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
625 case MNID_FILE_EXIT
: MACRO_Exit(); break;
628 case MNID_EDIT_COPYDLG
: MACRO_CopyDialog(); break;
629 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
632 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
635 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
636 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
637 case MNID_HELP_ABOUT
: MACRO_About(); break;
638 case MNID_HELP_WINE
: ShellAbout(hWnd
, "WINE", "Help", 0); break;
642 for (button
= win
->first_button
; button
; button
= button
->next
)
643 if (wParam
== button
->wParam
) break;
645 MACRO_ExecuteMacro(button
->lpszMacro
);
647 WINHELP_MessageBoxIDS(STID_NOT_IMPLEMENTED
, 0x121, MB_OK
);
652 if (Globals
.hPopupWnd
) DestroyWindow(Globals
.hPopupWnd
);
655 return WINHELP_HandleCommand((HWND
)wParam
, lParam
);
657 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
660 /***********************************************************************
662 * WINHELP_ButtonBoxWndProc
664 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
668 WINHELP_BUTTON
*button
;
672 WINHELP_CheckPopup(msg
);
677 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
678 SetWindowLong(hWnd
, 0, (LONG
) win
);
679 win
->hButtonBoxWnd
= hWnd
;
682 case WM_WINDOWPOSCHANGING
:
683 winpos
= (WINDOWPOS
*) lParam
;
684 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
689 for (button
= win
->first_button
; button
; button
= button
->next
)
694 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
695 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
697 hWnd
, (HMENU
) button
->wParam
,
698 Globals
.hInstance
, 0);
699 hDc
= GetDC(button
->hWnd
);
700 GetTextExtentPoint(hDc
, button
->lpszName
,
701 lstrlen(button
->lpszName
), &textsize
);
702 ReleaseDC(button
->hWnd
, hDc
);
704 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
705 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
710 for (button
= win
->first_button
; button
; button
= button
->next
)
712 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
714 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
717 x
= 0, y
+= button_size
.cy
;
719 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
723 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
727 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
730 /***********************************************************************
732 * WINHELP_TextWndProc
734 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
738 WINHELP_LINE_PART
*part
;
747 if (msg
!= WM_LBUTTONDOWN
)
748 WINHELP_CheckPopup(msg
);
753 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
754 SetWindowLong(hWnd
, 0, (LONG
) win
);
755 win
->hTextWnd
= hWnd
;
756 if (win
->info
->win_style
& WS_POPUP
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
757 WINHELP_InitFonts(hWnd
);
761 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
763 /* Calculate vertical size and position of a popup window */
764 if (win
->info
->win_style
& WS_POPUP
)
767 RECT old_window_rect
;
768 RECT old_client_rect
;
769 SIZE old_window_size
;
770 SIZE old_client_size
;
771 SIZE new_client_size
;
772 SIZE new_window_size
;
774 GetWindowRect(hWnd
, &old_window_rect
);
775 origin
.x
= old_window_rect
.left
;
776 origin
.y
= old_window_rect
.top
;
777 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
778 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
780 GetClientRect(hWnd
, &old_client_rect
);
781 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
782 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
784 new_client_size
= old_client_size
;
785 WINHELP_SplitLines(hWnd
, &new_client_size
);
787 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
788 origin
.y
+= POPUP_YDISTANCE
;
790 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
792 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
793 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
796 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
,
797 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
798 new_window_size
.cx
, new_window_size
.cy
,
799 0, 0, Globals
.hInstance
, 0);
801 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
802 new_window_size
.cx
, new_window_size
.cy
,
804 SetWindowPos(win
->hShadowWnd
, hWnd
, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
805 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
806 SetActiveWindow(hWnd
);
810 case WM_WINDOWPOSCHANGED
:
811 winpos
= (WINDOWPOS
*) lParam
;
813 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
819 UINT scrollLines
= 3;
820 int curPos
= GetScrollPos(hWnd
, SB_VERT
);
823 GetScrollRange(hWnd
, SB_VERT
, &min
, &max
);
825 SystemParametersInfo(SPI_GETWHEELSCROLLLINES
,0, &scrollLines
, 0);
826 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
827 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
828 wheelDelta
-= GET_WHEEL_DELTA_WPARAM(wParam
);
829 if (abs(wheelDelta
) >= WHEEL_DELTA
&& scrollLines
) {
832 curPos
+= wheelDelta
;
835 else if (curPos
< min
)
838 dy
= GetScrollPos(hWnd
, SB_VERT
) - curPos
;
839 SetScrollPos(hWnd
, SB_VERT
, curPos
, TRUE
);
840 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
851 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
854 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
855 GetClientRect(hWnd
, &rect
);
857 switch (wParam
& 0xffff)
860 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
861 case SB_TOP
: CurPos
= Min
; break;
862 case SB_BOTTOM
: CurPos
= Max
; break;
863 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
864 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
865 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
866 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
867 default: update
= FALSE
;
873 else if (CurPos
< Min
)
875 dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
876 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
877 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
884 hDc
= BeginPaint(hWnd
, &ps
);
885 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
886 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
888 for (line
= win
->first_line
; line
; line
= line
->next
)
890 for (part
= &line
->first_part
; part
; part
= part
->next
)
892 switch (part
->cookie
)
894 case hlp_line_part_text
:
895 SelectObject(hDc
, part
->u
.text
.hFont
);
896 SetTextColor(hDc
, part
->u
.text
.color
);
897 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
898 part
->u
.text
.lpsText
, part
->u
.text
.wTextLen
);
899 if (part
->u
.text
.wUnderline
)
903 switch (part
->u
.text
.wUnderline
)
907 hPen
= CreatePen(PS_SOLID
, 1, part
->u
.text
.color
);
910 hPen
= CreatePen(PS_DOT
, 1, part
->u
.text
.color
);
913 WINE_FIXME("Unknow underline type\n");
917 SelectObject(hDc
, hPen
);
918 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
- 1, NULL
);
919 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
- 1);
920 if (part
->u
.text
.wUnderline
== 2)
922 MoveToEx(hDc
, part
->rect
.left
, part
->rect
.bottom
- scroll_pos
+ 1, NULL
);
923 LineTo(hDc
, part
->rect
.right
, part
->rect
.bottom
- scroll_pos
+ 1);
928 case hlp_line_part_bitmap
:
932 hMemDC
= CreateCompatibleDC(hDc
);
933 SelectObject(hMemDC
, part
->u
.bitmap
.hBitmap
);
934 BitBlt(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
935 part
->rect
.right
- part
->rect
.left
, part
->rect
.bottom
- part
->rect
.top
,
936 hMemDC
, 0, 0, SRCCOPY
);
940 case hlp_line_part_metafile
:
944 SetViewportOrgEx(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
, &pt
);
945 PlayMetaFile(hDc
, part
->u
.metafile
.hMetaFile
);
946 SetViewportOrgEx(hDc
, pt
.x
, pt
.y
, NULL
);
957 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
959 if (WINHELP_IsOverLink(win
, wParam
, lParam
))
960 SetCursor(win
->hHandCur
); /* set to hand pointer cursor to indicate a link */
962 SetCursor(win
->hArrowCur
); /* set to hand pointer cursor to indicate a link */
967 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
969 hPopupWnd
= Globals
.hPopupWnd
;
970 Globals
.hPopupWnd
= 0;
972 part
= WINHELP_IsOverLink(win
, wParam
, lParam
);
976 HLPFILE_WINDOWINFO
* wi
;
978 mouse
.x
= LOWORD(lParam
);
979 mouse
.y
= HIWORD(lParam
);
981 if (part
->link
) switch (part
->link
->cookie
)
984 hlpfile
= WINHELP_LookupHelpFile(part
->link
->lpszString
);
985 if (part
->link
->window
== -1)
987 else if (part
->link
->window
< hlpfile
->numWindows
)
988 wi
= &hlpfile
->windows
[part
->link
->window
];
991 WINE_WARN("link to window %d/%d\n", part
->link
->window
, hlpfile
->numWindows
);
994 WINHELP_CreateHelpWindowByHash(hlpfile
, part
->link
->lHash
, wi
,
998 hlpfile
= WINHELP_LookupHelpFile(part
->link
->lpszString
);
999 WINHELP_CreateHelpWindowByHash(hlpfile
, part
->link
->lHash
,
1000 WINHELP_GetPopupWindowInfo(hlpfile
, hWnd
, &mouse
),
1003 case hlp_link_macro
:
1004 MACRO_ExecuteMacro(part
->link
->lpszString
);
1007 WINE_FIXME("Unknown link cookie %d\n", part
->link
->cookie
);
1012 DestroyWindow(hPopupWnd
);
1016 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1018 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
1020 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
1022 WINHELP_DeleteWindow(win
);
1024 if (bExit
) MACRO_Exit();
1026 if (!Globals
.win_list
)
1031 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1034 /******************************************************************
1035 * WINHELP_HistoryWndProc
1039 static LRESULT CALLBACK
WINHELP_HistoryWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1041 WINHELP_WINDOW
* win
;
1051 win
= (WINHELP_WINDOW
*)((LPCREATESTRUCT
)lParam
)->lpCreateParams
;
1052 SetWindowLong(hWnd
, 0, (LONG
)win
);
1053 win
->hHistoryWnd
= hWnd
;
1056 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1058 GetTextMetrics(hDc
, &tm
);
1059 GetWindowRect(hWnd
, &r
);
1061 r
.right
= r
.left
+ 30 * tm
.tmAveCharWidth
;
1062 r
.bottom
= r
.top
+ (sizeof(win
->history
) / sizeof(win
->history
[0])) * tm
.tmHeight
;
1063 AdjustWindowRect(&r
, GetWindowLong(hWnd
, GWL_STYLE
), FALSE
);
1064 if (r
.left
< 0) {r
.right
-= r
.left
; r
.left
= 0;}
1065 if (r
.top
< 0) {r
.bottom
-= r
.top
; r
.top
= 0;}
1067 MoveWindow(hWnd
, r
.left
, r
.top
, r
.right
, r
.bottom
, TRUE
);
1068 ReleaseDC(hWnd
, hDc
);
1070 case WM_LBUTTONDOWN
:
1071 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1073 GetTextMetrics(hDc
, &tm
);
1074 i
= HIWORD(lParam
) / tm
.tmHeight
;
1075 if (i
< win
->histIndex
)
1076 WINHELP_CreateHelpWindow(win
->history
[i
], win
->info
, SW_SHOW
);
1077 ReleaseDC(hWnd
, hDc
);
1080 hDc
= BeginPaint(hWnd
, &ps
);
1081 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1082 GetTextMetrics(hDc
, &tm
);
1084 for (i
= 0; i
< win
->histIndex
; i
++)
1086 TextOut(hDc
, 0, i
* tm
.tmHeight
, win
->history
[i
]->lpszTitle
,
1087 strlen(win
->history
[i
]->lpszTitle
));
1089 EndPaint(hWnd
, &ps
);
1092 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1093 if (hWnd
== win
->hHistoryWnd
)
1094 win
->hHistoryWnd
= 0;
1097 return DefWindowProc(hWnd
, msg
, wParam
, lParam
);
1100 /***********************************************************************
1104 static void WINHELP_SetupText(HWND hWnd
)
1106 HDC hDc
= GetDC(hWnd
);
1110 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
1111 if (!WINHELP_SplitLines(hWnd
, NULL
))
1113 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
1114 GetClientRect(hWnd
, &rect
);
1116 WINHELP_SplitLines(hWnd
, &newsize
);
1117 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
1119 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
1121 ReleaseDC(hWnd
, hDc
);
1124 /***********************************************************************
1126 * WINHELP_AppendText
1128 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
1129 LPSIZE space
, LPSIZE textsize
,
1130 INT
*line_ascent
, INT ascent
,
1131 LPCSTR text
, UINT textlen
,
1132 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
,
1136 WINHELP_LINE_PART
*part
;
1139 if (!*partp
) /* New line */
1141 *line_ascent
= ascent
;
1143 line
= HeapAlloc(GetProcessHeap(), 0,
1144 sizeof(WINHELP_LINE
) + textlen
);
1145 if (!line
) return FALSE
;
1148 part
= &line
->first_part
;
1149 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
1151 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
1152 line
->rect
.bottom
= line
->rect
.top
;
1153 line
->rect
.left
= space
->cx
;
1154 line
->rect
.right
= space
->cx
;
1156 if (**linep
) *linep
= &(**linep
)->next
;
1160 else /* Same line */
1164 if (*line_ascent
< ascent
)
1166 WINHELP_LINE_PART
*p
;
1167 for (p
= &line
->first_part
; p
; p
= p
->next
)
1169 p
->rect
.top
+= ascent
- *line_ascent
;
1170 p
->rect
.bottom
+= ascent
- *line_ascent
;
1172 line
->rect
.bottom
+= ascent
- *line_ascent
;
1173 *line_ascent
= ascent
;
1176 part
= HeapAlloc(GetProcessHeap(), 0,
1177 sizeof(WINHELP_LINE_PART
) + textlen
);
1178 if (!part
) return FALSE
;
1180 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
1183 memcpy(ptr
, text
, textlen
);
1184 part
->cookie
= hlp_line_part_text
;
1185 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
1186 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
1187 line
->rect
.right
= part
->rect
.right
;
1189 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
1190 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
1191 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
1192 part
->u
.text
.lpsText
= ptr
;
1193 part
->u
.text
.wTextLen
= textlen
;
1194 part
->u
.text
.hFont
= font
;
1195 part
->u
.text
.color
= color
;
1196 part
->u
.text
.wUnderline
= underline
;
1198 WINE_TRACE("Appended text '%*.*s'[%d] @ (%ld,%ld-%ld,%ld)\n",
1199 part
->u
.text
.wTextLen
,
1200 part
->u
.text
.wTextLen
,
1201 part
->u
.text
.lpsText
,
1202 part
->u
.text
.wTextLen
,
1203 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1206 if (link
) link
->wRefCount
++;
1209 *partp
= &part
->next
;
1216 /***********************************************************************
1218 * WINHELP_AppendGfxObject
1220 static WINHELP_LINE_PART
* WINHELP_AppendGfxObject(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
1221 LPSIZE space
, LPSIZE gfxSize
,
1222 HLPFILE_LINK
*link
, unsigned pos
)
1225 WINHELP_LINE_PART
*part
;
1228 if (!*partp
|| pos
== 1) /* New line */
1230 line
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE
));
1231 if (!line
) return NULL
;
1234 part
= &line
->first_part
;
1236 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
1237 line
->rect
.bottom
= line
->rect
.top
;
1238 line
->rect
.left
= space
->cx
;
1239 line
->rect
.right
= space
->cx
;
1241 if (**linep
) *linep
= &(**linep
)->next
;
1244 ptr
= (char*)line
+ sizeof(WINHELP_LINE
);
1246 else /* Same line */
1248 if (pos
== 2) WINE_FIXME("Left alignment not handled\n");
1251 part
= HeapAlloc(GetProcessHeap(), 0, sizeof(WINHELP_LINE_PART
));
1252 if (!part
) return NULL
;
1254 ptr
= (char*)part
+ sizeof(WINHELP_LINE_PART
);
1257 /* part->cookie should be set by caller (image or metafile) */
1258 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
1259 part
->rect
.right
= part
->rect
.left
+ gfxSize
->cx
;
1260 line
->rect
.right
= part
->rect
.right
;
1261 part
->rect
.top
= (*partp
) ? line
->rect
.top
: line
->rect
.bottom
;
1262 part
->rect
.bottom
= part
->rect
.top
+ gfxSize
->cy
;
1263 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
1265 WINE_TRACE("Appended gfx @ (%ld,%ld-%ld,%ld)\n",
1266 part
->rect
.left
, part
->rect
.top
, part
->rect
.right
, part
->rect
.bottom
);
1269 if (link
) link
->wRefCount
++;
1272 *partp
= &part
->next
;
1280 /***********************************************************************
1282 * WINHELP_SplitLines
1284 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
1286 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1287 HLPFILE_PARAGRAPH
*p
;
1288 WINHELP_LINE
**line
= &win
->first_line
;
1289 WINHELP_LINE_PART
**part
= 0;
1290 INT line_ascent
= 0;
1295 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
1297 if (!win
->page
) return TRUE
;
1299 WINHELP_DeleteLines(win
);
1301 GetClientRect(hWnd
, &rect
);
1303 rect
.top
+= INTERNAL_BORDER_WIDTH
;
1304 rect
.left
+= INTERNAL_BORDER_WIDTH
;
1305 rect
.right
-= INTERNAL_BORDER_WIDTH
;
1306 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
1308 space
.cy
= rect
.top
;
1309 space
.cx
= rect
.left
;
1313 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
1317 case para_normal_text
:
1318 case para_debug_text
:
1321 SIZE textsize
= {0, 0};
1322 LPCSTR text
= p
->u
.text
.lpszText
;
1324 UINT len
= strlen(text
);
1325 unsigned underline
= 0;
1328 COLORREF color
= RGB(0, 0, 0);
1330 if (p
->u
.text
.wFont
< win
->page
->file
->numFonts
)
1332 HLPFILE
* hlpfile
= win
->page
->file
;
1334 if (!hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
)
1335 hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
= CreateFontIndirect(&hlpfile
->fonts
[p
->u
.text
.wFont
].LogFont
);
1336 hFont
= hlpfile
->fonts
[p
->u
.text
.wFont
].hFont
;
1337 color
= hlpfile
->fonts
[p
->u
.text
.wFont
].color
;
1341 UINT wFont
= (p
->u
.text
.wFont
< win
->fonts_len
) ? p
->u
.text
.wFont
: 0;
1343 hFont
= win
->fonts
[wFont
];
1346 if (p
->link
&& p
->link
->bClrChange
)
1348 underline
= (p
->link
->cookie
== hlp_link_popup
) ? 3 : 1;
1349 color
= RGB(0, 0x80, 0);
1351 if (p
->cookie
== para_debug_text
) color
= RGB(0xff, 0, 0);
1353 SelectObject(hDc
, hFont
);
1355 GetTextMetrics(hDc
, &tm
);
1357 if (p
->u
.text
.wIndent
)
1359 indent
= p
->u
.text
.wIndent
* 5 * tm
.tmAveCharWidth
;
1361 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
1364 if (p
->u
.text
.wVSpace
)
1367 space
.cx
= rect
.left
+ indent
;
1368 space
.cy
+= (p
->u
.text
.wVSpace
- 1) * tm
.tmHeight
;
1371 if (p
->u
.text
.wHSpace
)
1373 space
.cx
+= p
->u
.text
.wHSpace
* 2 * tm
.tmAveCharWidth
;
1376 WINE_TRACE("splitting text %s\n", text
);
1380 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1381 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
1387 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
1389 if (textsize
.cx
<= free_width
) low
= curr
;
1392 if (high
<= low
+ 1) break;
1394 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
1395 if (curr
<= low
) curr
= low
+ 1;
1396 else if (curr
>= high
) curr
= high
- 1;
1399 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
1401 if (!part
&& !textlen
) textlen
= max(low
, 1);
1403 if (free_width
<= 0 || !textlen
)
1406 space
.cx
= rect
.left
+ indent
;
1407 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1411 WINE_TRACE("\t => %d %*s\n", textlen
, textlen
, text
);
1413 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
1414 &line_ascent
, tm
.tmAscent
,
1415 text
, textlen
, hFont
, color
, p
->link
, underline
) ||
1416 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1418 ReleaseDC(hWnd
, hDc
);
1423 newsize
->cx
= max(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
1427 if (text
[0] == ' ') text
++, len
--;
1436 WINHELP_LINE_PART
* ref_part
;
1438 if (p
->u
.gfx
.pos
& 0x8000)
1440 space
.cx
= rect
.left
;
1442 space
.cy
+= (*line
)->rect
.bottom
- (*line
)->rect
.top
;
1446 if (p
->cookie
== para_bitmap
)
1450 GetObject(p
->u
.gfx
.u
.bmp
.hBitmap
, sizeof(dibs
), &dibs
);
1451 gfxSize
.cx
= dibs
.dsBm
.bmWidth
;
1452 gfxSize
.cy
= dibs
.dsBm
.bmHeight
;
1454 else gfxSize
= p
->u
.gfx
.u
.mf
.mfSize
;
1456 free_width
= rect
.right
- ((part
&& *line
) ? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
1457 if (free_width
<= 0)
1460 space
.cx
= rect
.left
;
1461 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
1463 ref_part
= WINHELP_AppendGfxObject(&line
, &part
, &space
, &gfxSize
,
1464 p
->link
, p
->u
.gfx
.pos
);
1465 if (!ref_part
|| (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
1469 if (p
->cookie
== para_bitmap
)
1471 ref_part
->cookie
= hlp_line_part_bitmap
;
1472 ref_part
->u
.bitmap
.hBitmap
= p
->u
.gfx
.u
.bmp
.hBitmap
;
1476 ref_part
->cookie
= hlp_line_part_metafile
;
1477 ref_part
->u
.metafile
.hMetaFile
= p
->u
.gfx
.u
.mf
.hMetaFile
;
1485 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
1487 ReleaseDC(hWnd
, hDc
);
1491 /***********************************************************************
1493 * WINHELP_CheckPopup
1495 static void WINHELP_CheckPopup(UINT msg
)
1497 if (!Globals
.hPopupWnd
) return;
1502 case WM_LBUTTONDOWN
:
1503 case WM_MBUTTONDOWN
:
1504 case WM_RBUTTONDOWN
:
1505 case WM_NCLBUTTONDOWN
:
1506 case WM_NCMBUTTONDOWN
:
1507 case WM_NCRBUTTONDOWN
:
1508 DestroyWindow(Globals
.hPopupWnd
);
1509 Globals
.hPopupWnd
= 0;
1513 /***********************************************************************
1515 * WINHELP_DeleteLines
1517 static void WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
1519 WINHELP_LINE
*line
, *next_line
;
1520 WINHELP_LINE_PART
*part
, *next_part
;
1521 for (line
= win
->first_line
; line
; line
= next_line
)
1523 next_line
= line
->next
;
1524 for (part
= &line
->first_part
; part
; part
= next_part
)
1526 next_part
= part
->next
;
1527 HLPFILE_FreeLink(part
->link
);
1528 HeapFree(GetProcessHeap(), 0, part
);
1531 win
->first_line
= 0;
1534 /***********************************************************************
1536 * WINHELP_DeleteWindow
1538 static void WINHELP_DeleteWindow(WINHELP_WINDOW
* win
)
1545 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
1554 for (b
= win
->first_button
; b
; b
= bp
)
1556 DestroyWindow(b
->hWnd
);
1558 HeapFree(GetProcessHeap(), 0, b
);
1561 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
1562 if (win
->hHistoryWnd
) DestroyWindow(win
->hHistoryWnd
);
1564 for (i
= 0; i
< win
->histIndex
; i
++)
1566 HLPFILE_FreeHlpFile(win
->history
[i
]->file
);
1569 for (i
= 0; i
< win
->backIndex
; i
++)
1570 HLPFILE_FreeHlpFile(win
->back
[i
]->file
);
1572 if (win
->page
) HLPFILE_FreeHlpFile(win
->page
->file
);
1573 WINHELP_DeleteLines(win
);
1574 HeapFree(GetProcessHeap(), 0, win
);
1577 /***********************************************************************
1581 static void WINHELP_InitFonts(HWND hWnd
)
1583 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1584 LOGFONT logfontlist
[] = {
1585 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1586 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1587 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1588 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1589 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1590 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1591 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1592 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1594 static HFONT fonts
[FONTS_LEN
];
1595 static BOOL init
= 0;
1597 win
->fonts_len
= FONTS_LEN
;
1604 for (i
= 0; i
< FONTS_LEN
; i
++)
1606 fonts
[i
] = CreateFontIndirect(&logfontlist
[i
]);
1613 /***********************************************************************
1615 * WINHELP_MessageBoxIDS
1617 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1619 CHAR text
[MAX_STRING_LEN
];
1620 CHAR title
[MAX_STRING_LEN
];
1622 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1623 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1625 return MessageBox(0, text
, title
, type
);
1628 /***********************************************************************
1630 * MAIN_MessageBoxIDS_s
1632 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1634 CHAR text
[MAX_STRING_LEN
];
1635 CHAR title
[MAX_STRING_LEN
];
1636 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1638 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1639 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1640 wsprintf(newtext
, text
, str
);
1642 return MessageBox(0, newtext
, title
, type
);
1645 /******************************************************************
1646 * WINHELP_IsOverLink
1650 WINHELP_LINE_PART
* WINHELP_IsOverLink(WINHELP_WINDOW
* win
, WPARAM wParam
, LPARAM lParam
)
1654 WINHELP_LINE_PART
*part
;
1655 int scroll_pos
= GetScrollPos(win
->hMainWnd
, SB_VERT
);
1657 mouse
.x
= LOWORD(lParam
);
1658 mouse
.y
= HIWORD(lParam
);
1659 for (line
= win
->first_line
; line
; line
= line
->next
)
1661 for (part
= &line
->first_part
; part
; part
= part
->next
)
1664 part
->link
->lpszString
&&
1665 part
->rect
.left
<= mouse
.x
&&
1666 part
->rect
.right
>= mouse
.x
&&
1667 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
1668 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)