4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
13 extern const char people
[];
17 VOID
LIBWINE_Register_De(void);
18 VOID
LIBWINE_Register_En(void);
19 VOID
LIBWINE_Register_Fi(void);
20 VOID
LIBWINE_Register_Fr(void);
21 VOID
LIBWINE_Register_It(void);
22 VOID
LIBWINE_Register_Ko(void);
23 VOID
LIBWINE_Register_Hu(void);
25 static BOOL
WINHELP_RegisterWinClasses();
26 static LRESULT
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
27 static LRESULT
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
28 static LRESULT
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
29 static VOID
WINHELP_CheckPopup(UINT
);
30 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
31 static VOID
WINHELP_InitFonts(HWND hWnd
);
32 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*);
33 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*);
34 static VOID
WINHELP_SetupText(HWND hWnd
);
35 static BOOL
WINHELP_AppendText(WINHELP_LINE
***, WINHELP_LINE_PART
***,
36 LPSIZE
, LPSIZE
, INT
*, INT
, LPCSTR
, UINT
,
37 HFONT
, COLORREF
, HLPFILE_LINK
*);
39 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 0, 0};
41 static BOOL MacroTest
= FALSE
;
43 /***********************************************************************
48 int PASCAL
WinMain (HANDLE hInstance
, HANDLE prev
, LPSTR cmdline
, int show
)
50 LPCSTR opt_lang
= "En";
56 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
57 /* Register resources */
58 LIBWINE_Register_De();
59 LIBWINE_Register_En();
60 LIBWINE_Register_Fi();
61 LIBWINE_Register_Fr();
62 LIBWINE_Register_It();
63 LIBWINE_Register_Ko();
64 LIBWINE_Register_Hu();
67 Globals
.hInstance
= hInstance
;
70 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
74 if (*cmdline
++ == ' ') continue;
77 if (option
) cmdline
++;
78 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
84 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
85 if (*cmdline
) *cmdline
++ = '\0';
86 lHash
= HLPFILE_Hash(topic_id
);
91 Globals
.wVersion
= option
- '0';
101 opt_lang
= Languages
[Options
.language
].name
;
104 /* Find language specific string table */
105 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
107 Globals
.wStringTableOffset
= langnum
* 0x100;
108 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)) &&
109 !lstrcmp(opt_lang
, lang
))
112 if (langnum
> MAX_LANGUAGE_NUMBER
)
114 /* Find fallback language */
115 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
117 Globals
.wStringTableOffset
= langnum
* 0x100;
118 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)))
121 if (langnum
> MAX_LANGUAGE_NUMBER
)
123 MessageBox(0, "No language found", "FATAL ERROR", MB_OK
);
128 /* Change Resource names */
129 lstrcpyn(STRING_MENU_Xx
+ lstrlen(STRING_MENU_Xx
) - 2, lang
, 3);
131 /* Create primary window */
132 WINHELP_RegisterWinClasses();
133 WINHELP_CreateHelpWindow(cmdline
, lHash
, "main", FALSE
, NULL
, NULL
, show
);
136 while (GetMessage (&msg
, 0, 0, 0))
138 TranslateMessage (&msg
);
139 DispatchMessage (&msg
);
144 /***********************************************************************
149 static BOOL
WINHELP_RegisterWinClasses()
151 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
;
153 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
154 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
155 class_main
.cbClsExtra
= 0;
156 class_main
.cbWndExtra
= sizeof(LONG
);
157 class_main
.hInstance
= Globals
.hInstance
;
158 class_main
.hIcon
= LoadIcon (0, IDI_APPLICATION
);
159 class_main
.hCursor
= LoadCursor (0, IDC_ARROW
);
160 class_main
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
161 class_main
.lpszMenuName
= 0;
162 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
164 class_button_box
= class_main
;
165 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
166 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
167 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
169 class_text
= class_main
;
170 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
171 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
173 class_shadow
= class_main
;
174 class_shadow
.lpfnWndProc
= DefWindowProc
;
175 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
176 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
178 return (RegisterClass(&class_main
) &&
179 RegisterClass(&class_button_box
) &&
180 RegisterClass(&class_text
) &&
181 RegisterClass(&class_shadow
));
184 /***********************************************************************
186 * WINHELP_CreateHelpWindow
189 VOID
WINHELP_CreateHelpWindow(LPCSTR lpszFile
, LONG lHash
, LPCSTR lpszWindow
,
190 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
192 CHAR szCaption
[MAX_STRING_LEN
];
193 CHAR szContents
[MAX_STRING_LEN
];
194 CHAR szSearch
[MAX_STRING_LEN
];
195 CHAR szBack
[MAX_STRING_LEN
];
196 CHAR szHistory
[MAX_STRING_LEN
];
197 SIZE size
= {CW_USEDEFAULT
, CW_USEDEFAULT
};
198 POINT origin
= {240, 0};
201 WINHELP_WINDOW
*win
, *oldwin
;
203 HLPFILE_MACRO
*macro
;
209 else if (!lpszWindow
|| !lpszWindow
[0])
210 lpszWindow
= Globals
.active_win
->lpszName
;
211 bPrimary
= lpszWindow
&& !lstrcmpi(lpszWindow
, "main");
216 page
= lHash
? HLPFILE_PageByHash(lpszFile
, lHash
) : HLPFILE_Contents(lpszFile
);
218 /* Add Suffix `.hlp' */
219 if (!page
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp"))
221 CHAR szFile_hlp
[MAX_PATHNAME_LEN
];
223 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
224 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
225 lstrcat(szFile_hlp
, ".hlp");
227 page
= lHash
? HLPFILE_PageByHash(szFile_hlp
, lHash
) : HLPFILE_Contents(szFile_hlp
);
230 WINHELP_MessageBoxIDS_s(IDS_HLPFILE_ERROR_s
, lpszFile
, IDS_ERROR
, MB_OK
);
231 if (Globals
.win_list
) return;
237 /* Calculate horizontal size and position of a popup window */
241 GetWindowRect(hParentWnd
, &parent_rect
);
242 size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
245 ClientToScreen(hParentWnd
, &origin
);
246 origin
.x
-= size
.cx
/ 2;
247 origin
.x
= MIN(origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - size
.cx
);
248 origin
.x
= MAX(origin
.x
, 0);
251 /* Initialize WINHELP_WINDOW struct */
252 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_WINDOW
) +
253 (lpszWindow
? strlen(lpszWindow
) + 1 : 0));
255 win
= GlobalLock(handle
);
257 win
->next
= Globals
.win_list
;
258 Globals
.win_list
= win
;
261 ptr
= GlobalLock(handle
);
262 ptr
+= sizeof(WINHELP_WINDOW
);
263 lstrcpy(ptr
, (LPSTR
) lpszWindow
);
266 else win
->lpszName
= NULL
;
268 win
->first_button
= 0;
271 win
->hButtonBoxWnd
= 0;
275 Globals
.active_win
= win
;
277 /* Initialize default pushbuttons */
278 if (MacroTest
&& !bPopup
)
279 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
280 if (bPrimary
&& page
)
282 LoadString(Globals
.hInstance
, IDS_CONTENTS
, szContents
, sizeof(szContents
));
283 LoadString(Globals
.hInstance
, IDS_SEARCH
, szSearch
, sizeof(szSearch
));
284 LoadString(Globals
.hInstance
, IDS_BACK
, szBack
, sizeof(szBack
));
285 LoadString(Globals
.hInstance
, IDS_HISTORY
, szHistory
, sizeof(szHistory
));
286 MACRO_CreateButton("BTN_CONTENTS", szContents
, "Contents()");
287 MACRO_CreateButton("BTN_SEARCH", szSearch
, "Search()");
288 MACRO_CreateButton("BTN_BACK", szBack
, "Back()");
289 MACRO_CreateButton("BTN_HISTORY", szHistory
, "History()");
292 /* Initialize file specific pushbuttons */
294 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
295 MACRO_ExecuteMacro(macro
->lpszMacro
);
297 /* Reuse existing window */
299 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
300 if (oldwin
->lpszName
&& !lstrcmpi(oldwin
->lpszName
, lpszWindow
))
302 WINHELP_BUTTON
*button
;
304 win
->hMainWnd
= oldwin
->hMainWnd
;
305 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
306 win
->hTextWnd
= oldwin
->hTextWnd
;
307 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= 0;
309 SetWindowLong(win
->hMainWnd
, 0, (LONG
) win
);
310 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
) win
);
311 SetWindowLong(win
->hTextWnd
, 0, (LONG
) win
);
313 WINHELP_InitFonts(win
->hMainWnd
);
316 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
319 WINHELP_SetupText(win
->hTextWnd
);
320 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
321 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
322 UpdateWindow(win
->hTextWnd
);
325 for (button
= oldwin
->first_button
; button
; button
= button
->next
)
326 DestroyWindow(button
->hWnd
);
328 WINHELP_DeleteWindow(oldwin
);
332 /* Create main Window */
333 if (!page
) LoadString(Globals
.hInstance
, IDS_WINE_HELP
, szCaption
, sizeof(szCaption
));
334 hWnd
= CreateWindow (bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
335 page
? page
->file
->lpszTitle
: szCaption
,
336 bPopup
? WS_POPUPWINDOW
| WS_BORDER
: WS_OVERLAPPEDWINDOW
,
337 origin
.x
, origin
.y
, size
.cx
, size
.cy
,
338 0, bPrimary
? LoadMenu(Globals
.hInstance
, STRING_MENU_Xx
) : 0,
339 Globals
.hInstance
, win
);
341 ShowWindow (hWnd
, nCmdShow
);
345 /***********************************************************************
347 * WINHELP_MainWndProc
350 static LRESULT
WINHELP_MainWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
353 WINHELP_BUTTON
*button
;
354 RECT rect
, button_box_rect
;
357 WINHELP_CheckPopup(msg
);
362 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
363 SetWindowLong(hWnd
, 0, (LONG
) win
);
364 win
->hMainWnd
= hWnd
;
368 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
370 /* Create button box and text Window */
371 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
372 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
374 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
375 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
379 case WM_WINDOWPOSCHANGED
:
380 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
381 GetClientRect(hWnd
, &rect
);
383 /* Update button box and text Window */
384 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
386 rect
.right
- rect
.left
,
387 rect
.bottom
- rect
.top
, 0);
389 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
390 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
392 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
394 rect
.right
- rect
.left
,
395 rect
.bottom
- text_top
, 0);
400 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
404 case WH_OPEN
: MACRO_FileOpen(); break;
405 case WH_PRINT
: MACRO_Print(); break;
406 case WH_PRINTER_SETUP
: MACRO_PrinterSetup(); break;
407 case WH_EXIT
: MACRO_Exit(); break;
410 case WH_COPY_DIALOG
: MACRO_CopyDialog(); break;
411 case WH_ANNOTATE
: MACRO_Annotate(); break;
414 case WH_BOOKMARK_DEFINE
: MACRO_BookmarkDefine(); break;
417 case WH_HELP_ON_HELP
: MACRO_HelpOn(); break;
418 case WH_HELP_ON_TOP
: MACRO_HelpOnTop(); break;
421 case WH_ABOUT
: MACRO_About(); break;
424 ShellAbout(hWnd
, "WINE", people
, 0);
430 for (button
= win
->first_button
; button
; button
= button
->next
)
431 if (wParam
== button
->wParam
) break;
433 MACRO_ExecuteMacro(button
->lpszMacro
);
435 WINHELP_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
441 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
444 /***********************************************************************
446 * WINHELP_ButtonBoxWndProc
449 static LRESULT
WINHELP_ButtonBoxWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
453 WINHELP_BUTTON
*button
;
457 WINHELP_CheckPopup(msg
);
462 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
463 SetWindowLong(hWnd
, 0, (LONG
) win
);
464 win
->hButtonBoxWnd
= hWnd
;
467 case WM_WINDOWPOSCHANGING
:
468 winpos
= (WINDOWPOS
*) lParam
;
469 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
474 for (button
= win
->first_button
; button
; button
= button
->next
)
479 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
480 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
482 hWnd
, (HMENU
) button
->wParam
,
483 Globals
.hInstance
, 0);
484 hDc
= GetDC(button
->hWnd
);
485 GetTextExtentPoint(hDc
, button
->lpszName
,
486 lstrlen(button
->lpszName
), &textsize
);
487 ReleaseDC(button
->hWnd
, hDc
);
489 button_size
.cx
= MAX(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
490 button_size
.cy
= MAX(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
495 for (button
= win
->first_button
; button
; button
= button
->next
)
497 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
499 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
502 x
= 0, y
+= button_size
.cy
;
504 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
508 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
512 return(DefWindowProc(hWnd
, msg
, wParam
, lParam
));
515 /***********************************************************************
517 * WINHELP_TextWndProc
520 static LRESULT
WINHELP_TextWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
524 WINHELP_LINE_PART
*part
;
533 if (msg
!= WM_LBUTTONDOWN
)
534 WINHELP_CheckPopup(msg
);
539 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
540 SetWindowLong(hWnd
, 0, (LONG
) win
);
541 win
->hTextWnd
= hWnd
;
542 if (!win
->lpszName
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
543 WINHELP_InitFonts(hWnd
);
547 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
549 /* Calculate vertical size and position of a popup window */
553 RECT old_window_rect
;
554 RECT old_client_rect
;
555 SIZE old_window_size
;
556 SIZE old_client_size
;
557 SIZE new_client_size
;
558 SIZE new_window_size
;
560 GetWindowRect(hWnd
, &old_window_rect
);
561 origin
.x
= old_window_rect
.left
;
562 origin
.y
= old_window_rect
.top
;
563 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
564 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
566 GetClientRect(hWnd
, &old_client_rect
);
567 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
568 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
570 new_client_size
= old_client_size
;
571 WINHELP_SplitLines(hWnd
, &new_client_size
);
573 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
574 origin
.y
+= POPUP_YDISTANCE
;
576 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
578 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
579 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
582 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
| WS_VISIBLE
,
583 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
584 new_window_size
.cx
, new_window_size
.cy
,
585 0, 0, Globals
.hInstance
, 0);
587 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
588 new_window_size
.cx
, new_window_size
.cy
,
589 SWP_NOZORDER
| SWP_NOACTIVATE
);
590 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
594 case WM_WINDOWPOSCHANGED
:
595 winpos
= (WINDOWPOS
*) lParam
;
596 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
604 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
605 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
606 GetClientRect(hWnd
, &rect
);
608 switch (wParam
& 0xffff)
611 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
612 case SB_TOP
: CurPos
= Min
; break;
613 case SB_BOTTOM
: CurPos
= Max
; break;
614 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
615 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
616 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
617 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
618 default: update
= FALSE
;
622 INT dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
623 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
624 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
631 hDc
= BeginPaint (hWnd
, &ps
);
632 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
633 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
635 for (line
= win
->first_line
; line
; line
= line
->next
)
636 for (part
= &line
->first_part
; part
; part
= part
->next
)
638 SelectObject(hDc
, part
->hFont
);
639 SetTextColor(hDc
, part
->color
);
640 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
641 (LPSTR
) part
->lpsText
, part
->wTextLen
);
644 EndPaint (hWnd
, &ps
);
648 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
649 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
651 hPopupWnd
= Globals
.hPopupWnd
;
652 Globals
.hPopupWnd
= 0;
654 mouse
.x
= LOWORD(lParam
);
655 mouse
.y
= HIWORD(lParam
);
656 for (line
= win
->first_line
; line
; line
= line
->next
)
657 for (part
= &line
->first_part
; part
; part
= part
->next
)
658 if (part
->link
.lpszPath
&&
659 part
->rect
.left
<= mouse
.x
&&
660 part
->rect
.right
>= mouse
.x
&&
661 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
662 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)
663 WINHELP_CreateHelpWindow(part
->link
.lpszPath
, part
->link
.lHash
, NULL
,
664 part
->link
.bPopup
, hWnd
, &mouse
, SW_NORMAL
);
666 DestroyWindow(hPopupWnd
);
670 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
672 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
674 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
676 WINHELP_DeleteWindow(win
);
678 if (bExit
) MACRO_Exit();
680 if (!Globals
.win_list
)
685 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
688 /***********************************************************************
693 static VOID
WINHELP_SetupText(HWND hWnd
)
695 HDC hDc
= GetDC(hWnd
);
699 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
700 if (!WINHELP_SplitLines(hWnd
, NULL
))
702 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
703 GetClientRect(hWnd
, &rect
);
705 WINHELP_SplitLines(hWnd
, &newsize
);
706 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
708 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
710 ReleaseDC(hWnd
, hDc
);
713 /***********************************************************************
718 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
720 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
721 HLPFILE_PARAGRAPH
*p
;
722 WINHELP_LINE
**line
= &win
->first_line
;
723 WINHELP_LINE_PART
**part
= 0;
729 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
731 if (!win
->page
) return TRUE
;
733 WINHELP_DeleteLines(win
);
735 GetClientRect(hWnd
, &rect
);
737 rect
.top
+= INTERNAL_BORDER_WIDTH
;
738 rect
.left
+= INTERNAL_BORDER_WIDTH
;
739 rect
.right
-= INTERNAL_BORDER_WIDTH
;
740 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
744 space
.cx
= rect
.left
;
748 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
751 SIZE textsize
= {0, 0};
752 LPCSTR text
= p
->lpszText
;
753 UINT len
= strlen(text
);
756 UINT wFont
= (p
->wFont
< win
->fonts_len
) ? p
->wFont
: 0;
757 BOOL bUnderline
= p
->link
&& !p
->link
->bPopup
;
758 HFONT hFont
= win
->fonts
[wFont
][bUnderline
? 1 : 0];
760 COLORREF color
= RGB(0, 0, 0);
761 if (p
->link
) color
= RGB(0, 0x80, 0);
762 if (p
->bDebug
) color
= RGB(0xff, 0, 0);
764 SelectObject(hDc
, hFont
);
766 GetTextMetrics (hDc
, &tm
);
770 indent
= p
->wIndent
* 5 * tm
.tmAveCharWidth
;
772 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
778 space
.cx
= rect
.left
+ indent
;
779 space
.cy
+= (p
->wVSpace
- 1) * tm
.tmHeight
;
784 space
.cx
+= p
->wHSpace
* 2 * tm
.tmAveCharWidth
;
789 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
790 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
796 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
798 if (textsize
.cx
<= free_width
) low
= curr
;
801 if (high
<= low
+ 1) break;
803 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
804 if (curr
<= low
) curr
= low
+ 1;
805 else if (curr
>= high
) curr
= high
- 1;
808 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
810 if (!part
&& !textlen
) textlen
= MAX(low
, 1);
812 if (free_width
<= 0 || !textlen
)
815 space
.cx
= rect
.left
+ indent
;
816 space
.cx
= MIN(space
.cx
, rect
.right
- rect
.left
- 1);
820 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
821 &line_ascent
, tm
.tmAscent
,
822 text
, textlen
, hFont
, color
, p
->link
) ||
823 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
825 ReleaseDC(hWnd
, hDc
);
830 newsize
->cx
= MAX(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
834 if (text
[0] == ' ') text
++, len
--;
839 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
841 ReleaseDC(hWnd
, hDc
);
845 /***********************************************************************
850 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
851 LPSIZE space
, LPSIZE textsize
,
852 INT
*line_ascent
, INT ascent
,
853 LPCSTR text
, UINT textlen
,
854 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
)
858 WINHELP_LINE_PART
*part
;
861 if (!*partp
) /* New line */
863 *line_ascent
= ascent
;
865 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE
) + textlen
+
866 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
867 if (!handle
) return FALSE
;
868 line
= GlobalLock(handle
);
870 part
= &line
->first_part
;
871 ptr
= GlobalLock(handle
);
872 ptr
+= sizeof(WINHELP_LINE
);
874 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
875 line
->rect
.bottom
= line
->rect
.top
;
876 line
->rect
.left
= space
->cx
;
877 line
->rect
.right
= space
->cx
;
879 if (**linep
) *linep
= &(**linep
)->next
;
887 if (*line_ascent
< ascent
)
889 WINHELP_LINE_PART
*p
;
890 for (p
= &line
->first_part
; p
; p
= p
->next
)
892 p
->rect
.top
+= ascent
- *line_ascent
;
893 p
->rect
.bottom
+= ascent
- *line_ascent
;
895 line
->rect
.bottom
+= ascent
- *line_ascent
;
896 *line_ascent
= ascent
;
899 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE_PART
) + textlen
+
900 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
901 if (!handle
) return FALSE
;
902 part
= GlobalLock(handle
);
904 ptr
= GlobalLock(handle
);
905 ptr
+= sizeof(WINHELP_LINE_PART
);
908 hmemcpy(ptr
, text
, textlen
);
909 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
910 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
911 line
->rect
.right
= part
->rect
.right
;
913 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
914 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
915 line
->rect
.bottom
= MAX(line
->rect
.bottom
, part
->rect
.bottom
);
916 part
->hSelf
= handle
;
918 part
->wTextLen
= textlen
;
923 strcpy(ptr
+ textlen
, link
->lpszPath
);
924 part
->link
.lpszPath
= ptr
+ textlen
;
925 part
->link
.lHash
= link
->lHash
;
926 part
->link
.bPopup
= link
->bPopup
;
928 else part
->link
.lpszPath
= 0;
931 *partp
= &part
->next
;
938 /***********************************************************************
943 static VOID
WINHELP_CheckPopup(UINT msg
)
945 if (!Globals
.hPopupWnd
) return;
953 case WM_NCLBUTTONDOWN
:
954 case WM_NCMBUTTONDOWN
:
955 case WM_NCRBUTTONDOWN
:
956 DestroyWindow(Globals
.hPopupWnd
);
957 Globals
.hPopupWnd
= 0;
961 /***********************************************************************
963 * WINHELP_DeleteLines
966 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
968 WINHELP_LINE
*line
, *next_line
;
969 WINHELP_LINE_PART
*part
, *next_part
;
970 for(line
= win
->first_line
; line
; line
= next_line
)
972 next_line
= line
->next
;
973 for(part
= &line
->first_part
; part
; part
= next_part
)
975 next_part
= part
->next
;
976 GlobalFree(part
->hSelf
);
982 /***********************************************************************
984 * WINHELP_DeleteWindow
987 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*win
)
991 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
998 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
999 HLPFILE_FreeHlpFilePage(win
->page
);
1000 WINHELP_DeleteLines(win
);
1001 GlobalFree(win
->hSelf
);
1004 /***********************************************************************
1009 static VOID
WINHELP_InitFonts(HWND hWnd
)
1011 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1012 LOGFONT logfontlist
[] = {
1013 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1014 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1015 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1016 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1017 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1018 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1019 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1020 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1022 static HFONT fonts
[FONTS_LEN
][2];
1023 static BOOL init
= 0;
1025 win
->fonts_len
= FONTS_LEN
;
1032 for(i
= 0; i
< FONTS_LEN
; i
++)
1034 LOGFONT logfont
= logfontlist
[i
];
1036 fonts
[i
][0] = CreateFontIndirect(&logfont
);
1037 logfont
.lfUnderline
= 1;
1038 fonts
[i
][1] = CreateFontIndirect(&logfont
);
1045 /***********************************************************************
1047 * WINHELP_MessageBoxIDS
1050 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1052 CHAR text
[MAX_STRING_LEN
];
1053 CHAR title
[MAX_STRING_LEN
];
1055 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1056 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1058 return(MessageBox(0, text
, title
, type
));
1061 /***********************************************************************
1063 * MAIN_MessageBoxIDS_s
1066 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1068 CHAR text
[MAX_STRING_LEN
];
1069 CHAR title
[MAX_STRING_LEN
];
1070 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1072 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1073 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1074 wsprintf(newtext
, text
, str
);
1076 return(MessageBox(0, newtext
, title
, type
));
1079 /* Local Variables: */
1080 /* c-file-style: "GNU" */