4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
17 static BOOL
WINHELP_RegisterWinClasses();
18 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
19 static LRESULT CALLBACK
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
20 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
21 static VOID
WINHELP_CheckPopup(UINT
);
22 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
23 static VOID
WINHELP_InitFonts(HWND hWnd
);
24 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*);
25 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*);
26 static VOID
WINHELP_SetupText(HWND hWnd
);
27 static BOOL
WINHELP_AppendText(WINHELP_LINE
***, WINHELP_LINE_PART
***,
28 LPSIZE
, LPSIZE
, INT
*, INT
, LPCSTR
, UINT
,
29 HFONT
, COLORREF
, HLPFILE_LINK
*);
31 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 0, 0};
33 static BOOL MacroTest
= FALSE
;
35 /***********************************************************************
40 int PASCAL
WinMain (HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
42 LPCSTR opt_lang
= "En";
48 Globals
.hInstance
= hInstance
;
51 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
55 if (*cmdline
++ == ' ') continue;
58 if (option
) cmdline
++;
59 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
65 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
66 if (*cmdline
) *cmdline
++ = '\0';
67 lHash
= HLPFILE_Hash(topic_id
);
72 Globals
.wVersion
= option
- '0';
81 /* Find language specific string table */
82 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
84 Globals
.wStringTableOffset
= langnum
* 0x100;
85 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)) &&
86 !lstrcmp(opt_lang
, lang
))
89 if (langnum
> MAX_LANGUAGE_NUMBER
)
91 /* Find fallback language */
92 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
94 Globals
.wStringTableOffset
= langnum
* 0x100;
95 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)))
98 if (langnum
> MAX_LANGUAGE_NUMBER
)
100 MessageBox(0, "No language found", "FATAL ERROR", MB_OK
);
105 /* Change Resource names */
106 lstrcpyn(STRING_MENU_Xx
+ lstrlen(STRING_MENU_Xx
) - 2, lang
, 3);
108 /* Create primary window */
109 WINHELP_RegisterWinClasses();
110 WINHELP_CreateHelpWindow(cmdline
, lHash
, "main", FALSE
, NULL
, NULL
, show
);
113 while (GetMessage (&msg
, 0, 0, 0))
115 TranslateMessage (&msg
);
116 DispatchMessage (&msg
);
121 /***********************************************************************
126 static BOOL
WINHELP_RegisterWinClasses()
128 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
;
130 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
131 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
132 class_main
.cbClsExtra
= 0;
133 class_main
.cbWndExtra
= sizeof(LONG
);
134 class_main
.hInstance
= Globals
.hInstance
;
135 class_main
.hIcon
= LoadIcon (0, IDI_APPLICATION
);
136 class_main
.hCursor
= LoadCursor (0, IDC_ARROW
);
137 class_main
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
138 class_main
.lpszMenuName
= 0;
139 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
141 class_button_box
= class_main
;
142 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
143 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
144 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
146 class_text
= class_main
;
147 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
148 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
150 class_shadow
= class_main
;
151 class_shadow
.lpfnWndProc
= DefWindowProc
;
152 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
153 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
155 return (RegisterClass(&class_main
) &&
156 RegisterClass(&class_button_box
) &&
157 RegisterClass(&class_text
) &&
158 RegisterClass(&class_shadow
));
161 /***********************************************************************
163 * WINHELP_CreateHelpWindow
166 VOID
WINHELP_CreateHelpWindow(LPCSTR lpszFile
, LONG lHash
, LPCSTR lpszWindow
,
167 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
169 CHAR szCaption
[MAX_STRING_LEN
];
170 CHAR szContents
[MAX_STRING_LEN
];
171 CHAR szSearch
[MAX_STRING_LEN
];
172 CHAR szBack
[MAX_STRING_LEN
];
173 CHAR szHistory
[MAX_STRING_LEN
];
174 SIZE size
= {CW_USEDEFAULT
, CW_USEDEFAULT
};
175 POINT origin
= {240, 0};
178 WINHELP_WINDOW
*win
, *oldwin
;
180 HLPFILE_MACRO
*macro
;
186 else if (!lpszWindow
|| !lpszWindow
[0])
187 lpszWindow
= Globals
.active_win
->lpszName
;
188 bPrimary
= lpszWindow
&& !lstrcmpi(lpszWindow
, "main");
193 page
= lHash
? HLPFILE_PageByHash(lpszFile
, lHash
) : HLPFILE_Contents(lpszFile
);
195 /* Add Suffix `.hlp' */
196 if (!page
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp"))
198 CHAR szFile_hlp
[MAX_PATHNAME_LEN
];
200 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
201 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
202 lstrcat(szFile_hlp
, ".hlp");
204 page
= lHash
? HLPFILE_PageByHash(szFile_hlp
, lHash
) : HLPFILE_Contents(szFile_hlp
);
207 WINHELP_MessageBoxIDS_s(IDS_HLPFILE_ERROR_s
, lpszFile
, IDS_ERROR
, MB_OK
);
208 if (Globals
.win_list
) return;
214 /* Calculate horizontal size and position of a popup window */
218 GetWindowRect(hParentWnd
, &parent_rect
);
219 size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
222 ClientToScreen(hParentWnd
, &origin
);
223 origin
.x
-= size
.cx
/ 2;
224 origin
.x
= min(origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - size
.cx
);
225 origin
.x
= max(origin
.x
, 0);
228 /* Initialize WINHELP_WINDOW struct */
229 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_WINDOW
) +
230 (lpszWindow
? strlen(lpszWindow
) + 1 : 0));
232 win
= GlobalLock(handle
);
234 win
->next
= Globals
.win_list
;
235 Globals
.win_list
= win
;
238 ptr
= GlobalLock(handle
);
239 ptr
+= sizeof(WINHELP_WINDOW
);
240 lstrcpy(ptr
, (LPSTR
) lpszWindow
);
243 else win
->lpszName
= NULL
;
245 win
->first_button
= 0;
248 win
->hButtonBoxWnd
= 0;
252 Globals
.active_win
= win
;
254 /* Initialize default pushbuttons */
255 if (MacroTest
&& !bPopup
)
256 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
257 if (bPrimary
&& page
)
259 LoadString(Globals
.hInstance
, IDS_CONTENTS
, szContents
, sizeof(szContents
));
260 LoadString(Globals
.hInstance
, IDS_SEARCH
, szSearch
, sizeof(szSearch
));
261 LoadString(Globals
.hInstance
, IDS_BACK
, szBack
, sizeof(szBack
));
262 LoadString(Globals
.hInstance
, IDS_HISTORY
, szHistory
, sizeof(szHistory
));
263 MACRO_CreateButton("BTN_CONTENTS", szContents
, "Contents()");
264 MACRO_CreateButton("BTN_SEARCH", szSearch
, "Search()");
265 MACRO_CreateButton("BTN_BACK", szBack
, "Back()");
266 MACRO_CreateButton("BTN_HISTORY", szHistory
, "History()");
269 /* Initialize file specific pushbuttons */
271 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
272 MACRO_ExecuteMacro(macro
->lpszMacro
);
274 /* Reuse existing window */
276 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
277 if (oldwin
->lpszName
&& !lstrcmpi(oldwin
->lpszName
, lpszWindow
))
279 WINHELP_BUTTON
*button
;
281 win
->hMainWnd
= oldwin
->hMainWnd
;
282 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
283 win
->hTextWnd
= oldwin
->hTextWnd
;
284 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= 0;
286 SetWindowLong(win
->hMainWnd
, 0, (LONG
) win
);
287 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
) win
);
288 SetWindowLong(win
->hTextWnd
, 0, (LONG
) win
);
290 WINHELP_InitFonts(win
->hMainWnd
);
293 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
296 WINHELP_SetupText(win
->hTextWnd
);
297 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
298 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
299 UpdateWindow(win
->hTextWnd
);
302 for (button
= oldwin
->first_button
; button
; button
= button
->next
)
303 DestroyWindow(button
->hWnd
);
305 WINHELP_DeleteWindow(oldwin
);
309 /* Create main Window */
310 if (!page
) LoadString(Globals
.hInstance
, IDS_WINE_HELP
, szCaption
, sizeof(szCaption
));
311 hWnd
= CreateWindow (bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
312 page
? page
->file
->lpszTitle
: szCaption
,
313 bPopup
? WS_POPUPWINDOW
| WS_BORDER
: WS_OVERLAPPEDWINDOW
,
314 origin
.x
, origin
.y
, size
.cx
, size
.cy
,
315 0, bPrimary
? LoadMenu(Globals
.hInstance
, STRING_MENU_Xx
) : 0,
316 Globals
.hInstance
, win
);
318 ShowWindow (hWnd
, nCmdShow
);
322 /***********************************************************************
324 * WINHELP_MainWndProc
327 static LRESULT CALLBACK
WINHELP_MainWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
330 WINHELP_BUTTON
*button
;
331 RECT rect
, button_box_rect
;
334 WINHELP_CheckPopup(msg
);
339 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
340 SetWindowLong(hWnd
, 0, (LONG
) win
);
341 win
->hMainWnd
= hWnd
;
345 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
347 /* Create button box and text Window */
348 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
349 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
351 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
352 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
356 case WM_WINDOWPOSCHANGED
:
357 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
358 GetClientRect(hWnd
, &rect
);
360 /* Update button box and text Window */
361 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
363 rect
.right
- rect
.left
,
364 rect
.bottom
- rect
.top
, 0);
366 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
367 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
369 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
371 rect
.right
- rect
.left
,
372 rect
.bottom
- text_top
, 0);
377 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
381 case WH_OPEN
: MACRO_FileOpen(); break;
382 case WH_PRINT
: MACRO_Print(); break;
383 case WH_PRINTER_SETUP
: MACRO_PrinterSetup(); break;
384 case WH_EXIT
: MACRO_Exit(); break;
387 case WH_COPY_DIALOG
: MACRO_CopyDialog(); break;
388 case WH_ANNOTATE
: MACRO_Annotate(); break;
391 case WH_BOOKMARK_DEFINE
: MACRO_BookmarkDefine(); break;
394 case WH_HELP_ON_HELP
: MACRO_HelpOn(); break;
395 case WH_HELP_ON_TOP
: MACRO_HelpOnTop(); break;
398 case WH_ABOUT
: MACRO_About(); break;
401 ShellAbout(hWnd
, "WINE", "Help", 0);
406 for (button
= win
->first_button
; button
; button
= button
->next
)
407 if (wParam
== button
->wParam
) break;
409 MACRO_ExecuteMacro(button
->lpszMacro
);
411 WINHELP_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
417 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
420 /***********************************************************************
422 * WINHELP_ButtonBoxWndProc
425 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
429 WINHELP_BUTTON
*button
;
433 WINHELP_CheckPopup(msg
);
438 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
439 SetWindowLong(hWnd
, 0, (LONG
) win
);
440 win
->hButtonBoxWnd
= hWnd
;
443 case WM_WINDOWPOSCHANGING
:
444 winpos
= (WINDOWPOS
*) lParam
;
445 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
450 for (button
= win
->first_button
; button
; button
= button
->next
)
455 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
456 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
458 hWnd
, (HMENU
) button
->wParam
,
459 Globals
.hInstance
, 0);
460 hDc
= GetDC(button
->hWnd
);
461 GetTextExtentPoint(hDc
, button
->lpszName
,
462 lstrlen(button
->lpszName
), &textsize
);
463 ReleaseDC(button
->hWnd
, hDc
);
465 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
466 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
471 for (button
= win
->first_button
; button
; button
= button
->next
)
473 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
475 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
478 x
= 0, y
+= button_size
.cy
;
480 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
484 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
488 return(DefWindowProc(hWnd
, msg
, wParam
, lParam
));
491 /***********************************************************************
493 * WINHELP_TextWndProc
496 static LRESULT CALLBACK
WINHELP_TextWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
500 WINHELP_LINE_PART
*part
;
509 if (msg
!= WM_LBUTTONDOWN
)
510 WINHELP_CheckPopup(msg
);
515 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
516 SetWindowLong(hWnd
, 0, (LONG
) win
);
517 win
->hTextWnd
= hWnd
;
518 if (!win
->lpszName
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
519 WINHELP_InitFonts(hWnd
);
523 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
525 /* Calculate vertical size and position of a popup window */
529 RECT old_window_rect
;
530 RECT old_client_rect
;
531 SIZE old_window_size
;
532 SIZE old_client_size
;
533 SIZE new_client_size
;
534 SIZE new_window_size
;
536 GetWindowRect(hWnd
, &old_window_rect
);
537 origin
.x
= old_window_rect
.left
;
538 origin
.y
= old_window_rect
.top
;
539 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
540 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
542 GetClientRect(hWnd
, &old_client_rect
);
543 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
544 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
546 new_client_size
= old_client_size
;
547 WINHELP_SplitLines(hWnd
, &new_client_size
);
549 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
550 origin
.y
+= POPUP_YDISTANCE
;
552 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
554 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
555 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
558 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
| WS_VISIBLE
,
559 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
560 new_window_size
.cx
, new_window_size
.cy
,
561 0, 0, Globals
.hInstance
, 0);
563 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
564 new_window_size
.cx
, new_window_size
.cy
,
565 SWP_NOZORDER
| SWP_NOACTIVATE
);
566 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
570 case WM_WINDOWPOSCHANGED
:
571 winpos
= (WINDOWPOS
*) lParam
;
572 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
580 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
581 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
582 GetClientRect(hWnd
, &rect
);
584 switch (wParam
& 0xffff)
587 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
588 case SB_TOP
: CurPos
= Min
; break;
589 case SB_BOTTOM
: CurPos
= Max
; break;
590 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
591 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
592 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
593 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
594 default: update
= FALSE
;
598 INT dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
599 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
600 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
607 hDc
= BeginPaint (hWnd
, &ps
);
608 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
609 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
611 for (line
= win
->first_line
; line
; line
= line
->next
)
612 for (part
= &line
->first_part
; part
; part
= part
->next
)
614 SelectObject(hDc
, part
->hFont
);
615 SetTextColor(hDc
, part
->color
);
616 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
617 (LPSTR
) part
->lpsText
, part
->wTextLen
);
620 EndPaint (hWnd
, &ps
);
624 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
625 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
627 hPopupWnd
= Globals
.hPopupWnd
;
628 Globals
.hPopupWnd
= 0;
630 mouse
.x
= LOWORD(lParam
);
631 mouse
.y
= HIWORD(lParam
);
632 for (line
= win
->first_line
; line
; line
= line
->next
)
633 for (part
= &line
->first_part
; part
; part
= part
->next
)
634 if (part
->link
.lpszPath
&&
635 part
->rect
.left
<= mouse
.x
&&
636 part
->rect
.right
>= mouse
.x
&&
637 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
638 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)
639 WINHELP_CreateHelpWindow(part
->link
.lpszPath
, part
->link
.lHash
, NULL
,
640 part
->link
.bPopup
, hWnd
, &mouse
, SW_NORMAL
);
642 DestroyWindow(hPopupWnd
);
646 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
648 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
650 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
652 WINHELP_DeleteWindow(win
);
654 if (bExit
) MACRO_Exit();
656 if (!Globals
.win_list
)
661 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
664 /***********************************************************************
669 static VOID
WINHELP_SetupText(HWND hWnd
)
671 HDC hDc
= GetDC(hWnd
);
675 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
676 if (!WINHELP_SplitLines(hWnd
, NULL
))
678 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
679 GetClientRect(hWnd
, &rect
);
681 WINHELP_SplitLines(hWnd
, &newsize
);
682 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
684 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
686 ReleaseDC(hWnd
, hDc
);
689 /***********************************************************************
694 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
696 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
697 HLPFILE_PARAGRAPH
*p
;
698 WINHELP_LINE
**line
= &win
->first_line
;
699 WINHELP_LINE_PART
**part
= 0;
705 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
707 if (!win
->page
) return TRUE
;
709 WINHELP_DeleteLines(win
);
711 GetClientRect(hWnd
, &rect
);
713 rect
.top
+= INTERNAL_BORDER_WIDTH
;
714 rect
.left
+= INTERNAL_BORDER_WIDTH
;
715 rect
.right
-= INTERNAL_BORDER_WIDTH
;
716 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
720 space
.cx
= rect
.left
;
724 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
727 SIZE textsize
= {0, 0};
728 LPCSTR text
= p
->lpszText
;
729 UINT len
= strlen(text
);
732 UINT wFont
= (p
->wFont
< win
->fonts_len
) ? p
->wFont
: 0;
733 BOOL bUnderline
= p
->link
&& !p
->link
->bPopup
;
734 HFONT hFont
= win
->fonts
[wFont
][bUnderline
? 1 : 0];
736 COLORREF color
= RGB(0, 0, 0);
737 if (p
->link
) color
= RGB(0, 0x80, 0);
738 if (p
->bDebug
) color
= RGB(0xff, 0, 0);
740 SelectObject(hDc
, hFont
);
742 GetTextMetrics (hDc
, &tm
);
746 indent
= p
->wIndent
* 5 * tm
.tmAveCharWidth
;
748 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
754 space
.cx
= rect
.left
+ indent
;
755 space
.cy
+= (p
->wVSpace
- 1) * tm
.tmHeight
;
760 space
.cx
+= p
->wHSpace
* 2 * tm
.tmAveCharWidth
;
765 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
766 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
772 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
774 if (textsize
.cx
<= free_width
) low
= curr
;
777 if (high
<= low
+ 1) break;
779 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
780 if (curr
<= low
) curr
= low
+ 1;
781 else if (curr
>= high
) curr
= high
- 1;
784 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
786 if (!part
&& !textlen
) textlen
= max(low
, 1);
788 if (free_width
<= 0 || !textlen
)
791 space
.cx
= rect
.left
+ indent
;
792 space
.cx
= min(space
.cx
, rect
.right
- rect
.left
- 1);
796 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
797 &line_ascent
, tm
.tmAscent
,
798 text
, textlen
, hFont
, color
, p
->link
) ||
799 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
801 ReleaseDC(hWnd
, hDc
);
806 newsize
->cx
= max(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
810 if (text
[0] == ' ') text
++, len
--;
815 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
817 ReleaseDC(hWnd
, hDc
);
821 /***********************************************************************
826 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
827 LPSIZE space
, LPSIZE textsize
,
828 INT
*line_ascent
, INT ascent
,
829 LPCSTR text
, UINT textlen
,
830 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
)
834 WINHELP_LINE_PART
*part
;
837 if (!*partp
) /* New line */
839 *line_ascent
= ascent
;
841 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE
) + textlen
+
842 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
843 if (!handle
) return FALSE
;
844 line
= GlobalLock(handle
);
846 part
= &line
->first_part
;
847 ptr
= GlobalLock(handle
);
848 ptr
+= sizeof(WINHELP_LINE
);
850 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
851 line
->rect
.bottom
= line
->rect
.top
;
852 line
->rect
.left
= space
->cx
;
853 line
->rect
.right
= space
->cx
;
855 if (**linep
) *linep
= &(**linep
)->next
;
863 if (*line_ascent
< ascent
)
865 WINHELP_LINE_PART
*p
;
866 for (p
= &line
->first_part
; p
; p
= p
->next
)
868 p
->rect
.top
+= ascent
- *line_ascent
;
869 p
->rect
.bottom
+= ascent
- *line_ascent
;
871 line
->rect
.bottom
+= ascent
- *line_ascent
;
872 *line_ascent
= ascent
;
875 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE_PART
) + textlen
+
876 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
877 if (!handle
) return FALSE
;
878 part
= GlobalLock(handle
);
880 ptr
= GlobalLock(handle
);
881 ptr
+= sizeof(WINHELP_LINE_PART
);
884 memcpy(ptr
, text
, textlen
);
885 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
886 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
887 line
->rect
.right
= part
->rect
.right
;
889 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
890 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
891 line
->rect
.bottom
= max(line
->rect
.bottom
, part
->rect
.bottom
);
892 part
->hSelf
= handle
;
894 part
->wTextLen
= textlen
;
899 strcpy(ptr
+ textlen
, link
->lpszPath
);
900 part
->link
.lpszPath
= ptr
+ textlen
;
901 part
->link
.lHash
= link
->lHash
;
902 part
->link
.bPopup
= link
->bPopup
;
904 else part
->link
.lpszPath
= 0;
907 *partp
= &part
->next
;
914 /***********************************************************************
919 static VOID
WINHELP_CheckPopup(UINT msg
)
921 if (!Globals
.hPopupWnd
) return;
929 case WM_NCLBUTTONDOWN
:
930 case WM_NCMBUTTONDOWN
:
931 case WM_NCRBUTTONDOWN
:
932 DestroyWindow(Globals
.hPopupWnd
);
933 Globals
.hPopupWnd
= 0;
937 /***********************************************************************
939 * WINHELP_DeleteLines
942 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
944 WINHELP_LINE
*line
, *next_line
;
945 WINHELP_LINE_PART
*part
, *next_part
;
946 for(line
= win
->first_line
; line
; line
= next_line
)
948 next_line
= line
->next
;
949 for(part
= &line
->first_part
; part
; part
= next_part
)
951 next_part
= part
->next
;
952 GlobalFree(part
->hSelf
);
958 /***********************************************************************
960 * WINHELP_DeleteWindow
963 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*win
)
967 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
974 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
975 HLPFILE_FreeHlpFilePage(win
->page
);
976 WINHELP_DeleteLines(win
);
977 GlobalFree(win
->hSelf
);
980 /***********************************************************************
985 static VOID
WINHELP_InitFonts(HWND hWnd
)
987 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
988 LOGFONT logfontlist
[] = {
989 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
990 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
991 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
992 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
993 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
994 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
995 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
996 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
998 static HFONT fonts
[FONTS_LEN
][2];
999 static BOOL init
= 0;
1001 win
->fonts_len
= FONTS_LEN
;
1008 for(i
= 0; i
< FONTS_LEN
; i
++)
1010 LOGFONT logfont
= logfontlist
[i
];
1012 fonts
[i
][0] = CreateFontIndirect(&logfont
);
1013 logfont
.lfUnderline
= 1;
1014 fonts
[i
][1] = CreateFontIndirect(&logfont
);
1021 /***********************************************************************
1023 * WINHELP_MessageBoxIDS
1026 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1028 CHAR text
[MAX_STRING_LEN
];
1029 CHAR title
[MAX_STRING_LEN
];
1031 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1032 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1034 return(MessageBox(0, text
, title
, type
));
1037 /***********************************************************************
1039 * MAIN_MessageBoxIDS_s
1042 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1044 CHAR text
[MAX_STRING_LEN
];
1045 CHAR title
[MAX_STRING_LEN
];
1046 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1048 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1049 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1050 wsprintf(newtext
, text
, str
);
1052 return(MessageBox(0, newtext
, title
, type
));
1055 /* Local Variables: */
1056 /* c-file-style: "GNU" */