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);
24 VOID
LIBWINE_Register_Va(void);
26 static BOOL
WINHELP_RegisterWinClasses();
27 static LRESULT
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
28 static LRESULT
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
29 static LRESULT
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
30 static VOID
WINHELP_CheckPopup(UINT
);
31 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
32 static VOID
WINHELP_InitFonts(HWND hWnd
);
33 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*);
34 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*);
35 static VOID
WINHELP_SetupText(HWND hWnd
);
36 static BOOL
WINHELP_AppendText(WINHELP_LINE
***, WINHELP_LINE_PART
***,
37 LPSIZE
, LPSIZE
, INT
*, INT
, LPCSTR
, UINT
,
38 HFONT
, COLORREF
, HLPFILE_LINK
*);
40 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 0, 0};
42 static BOOL MacroTest
= FALSE
;
44 /***********************************************************************
49 int PASCAL
WinMain (HANDLE hInstance
, HANDLE prev
, LPSTR cmdline
, int show
)
51 LPCSTR opt_lang
= "En";
57 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
58 /* Register resources */
59 LIBWINE_Register_De();
60 LIBWINE_Register_En();
61 LIBWINE_Register_Fi();
62 LIBWINE_Register_Fr();
63 LIBWINE_Register_It();
64 LIBWINE_Register_Ko();
65 LIBWINE_Register_Hu();
66 LIBWINE_Register_Va();
69 Globals
.hInstance
= hInstance
;
72 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
76 if (*cmdline
++ == ' ') continue;
79 if (option
) cmdline
++;
80 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
86 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
87 if (*cmdline
) *cmdline
++ = '\0';
88 lHash
= HLPFILE_Hash(topic_id
);
93 Globals
.wVersion
= option
- '0';
103 opt_lang
= Languages
[Options
.language
].name
;
106 /* Find language specific string table */
107 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
109 Globals
.wStringTableOffset
= langnum
* 0x100;
110 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)) &&
111 !lstrcmp(opt_lang
, lang
))
114 if (langnum
> MAX_LANGUAGE_NUMBER
)
116 /* Find fallback language */
117 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
119 Globals
.wStringTableOffset
= langnum
* 0x100;
120 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)))
123 if (langnum
> MAX_LANGUAGE_NUMBER
)
125 MessageBox(0, "No language found", "FATAL ERROR", MB_OK
);
130 /* Change Resource names */
131 lstrcpyn(STRING_MENU_Xx
+ lstrlen(STRING_MENU_Xx
) - 2, lang
, 3);
133 /* Create primary window */
134 WINHELP_RegisterWinClasses();
135 WINHELP_CreateHelpWindow(cmdline
, lHash
, "main", FALSE
, NULL
, NULL
, show
);
138 while (GetMessage (&msg
, 0, 0, 0))
140 TranslateMessage (&msg
);
141 DispatchMessage (&msg
);
146 /***********************************************************************
151 static BOOL
WINHELP_RegisterWinClasses()
153 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
;
155 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
156 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
157 class_main
.cbClsExtra
= 0;
158 class_main
.cbWndExtra
= sizeof(LONG
);
159 class_main
.hInstance
= Globals
.hInstance
;
160 class_main
.hIcon
= LoadIcon (0, IDI_APPLICATION
);
161 class_main
.hCursor
= LoadCursor (0, IDC_ARROW
);
162 class_main
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
163 class_main
.lpszMenuName
= 0;
164 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
166 class_button_box
= class_main
;
167 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
168 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
169 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
171 class_text
= class_main
;
172 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
173 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
175 class_shadow
= class_main
;
176 class_shadow
.lpfnWndProc
= DefWindowProc
;
177 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
178 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
180 return (RegisterClass(&class_main
) &&
181 RegisterClass(&class_button_box
) &&
182 RegisterClass(&class_text
) &&
183 RegisterClass(&class_shadow
));
186 /***********************************************************************
188 * WINHELP_CreateHelpWindow
191 VOID
WINHELP_CreateHelpWindow(LPCSTR lpszFile
, LONG lHash
, LPCSTR lpszWindow
,
192 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
194 CHAR szCaption
[MAX_STRING_LEN
];
195 CHAR szContents
[MAX_STRING_LEN
];
196 CHAR szSearch
[MAX_STRING_LEN
];
197 CHAR szBack
[MAX_STRING_LEN
];
198 CHAR szHistory
[MAX_STRING_LEN
];
199 SIZE size
= {CW_USEDEFAULT
, CW_USEDEFAULT
};
200 POINT origin
= {240, 0};
203 WINHELP_WINDOW
*win
, *oldwin
;
205 HLPFILE_MACRO
*macro
;
211 else if (!lpszWindow
|| !lpszWindow
[0])
212 lpszWindow
= Globals
.active_win
->lpszName
;
213 bPrimary
= lpszWindow
&& !lstrcmpi(lpszWindow
, "main");
218 page
= lHash
? HLPFILE_PageByHash(lpszFile
, lHash
) : HLPFILE_Contents(lpszFile
);
220 /* Add Suffix `.hlp' */
221 if (!page
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp"))
223 CHAR szFile_hlp
[MAX_PATHNAME_LEN
];
225 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
226 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
227 lstrcat(szFile_hlp
, ".hlp");
229 page
= lHash
? HLPFILE_PageByHash(szFile_hlp
, lHash
) : HLPFILE_Contents(szFile_hlp
);
232 WINHELP_MessageBoxIDS_s(IDS_HLPFILE_ERROR_s
, lpszFile
, IDS_ERROR
, MB_OK
);
233 if (Globals
.win_list
) return;
239 /* Calculate horizontal size and position of a popup window */
243 GetWindowRect(hParentWnd
, &parent_rect
);
244 size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
247 ClientToScreen(hParentWnd
, &origin
);
248 origin
.x
-= size
.cx
/ 2;
249 origin
.x
= MIN(origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - size
.cx
);
250 origin
.x
= MAX(origin
.x
, 0);
253 /* Initialize WINHELP_WINDOW struct */
254 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_WINDOW
) +
255 (lpszWindow
? strlen(lpszWindow
) + 1 : 0));
257 win
= GlobalLock(handle
);
259 win
->next
= Globals
.win_list
;
260 Globals
.win_list
= win
;
263 ptr
= GlobalLock(handle
);
264 ptr
+= sizeof(WINHELP_WINDOW
);
265 lstrcpy(ptr
, (LPSTR
) lpszWindow
);
268 else win
->lpszName
= NULL
;
270 win
->first_button
= 0;
273 win
->hButtonBoxWnd
= 0;
277 Globals
.active_win
= win
;
279 /* Initialize default pushbuttons */
280 if (MacroTest
&& !bPopup
)
281 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
282 if (bPrimary
&& page
)
284 LoadString(Globals
.hInstance
, IDS_CONTENTS
, szContents
, sizeof(szContents
));
285 LoadString(Globals
.hInstance
, IDS_SEARCH
, szSearch
, sizeof(szSearch
));
286 LoadString(Globals
.hInstance
, IDS_BACK
, szBack
, sizeof(szBack
));
287 LoadString(Globals
.hInstance
, IDS_HISTORY
, szHistory
, sizeof(szHistory
));
288 MACRO_CreateButton("BTN_CONTENTS", szContents
, "Contents()");
289 MACRO_CreateButton("BTN_SEARCH", szSearch
, "Search()");
290 MACRO_CreateButton("BTN_BACK", szBack
, "Back()");
291 MACRO_CreateButton("BTN_HISTORY", szHistory
, "History()");
294 /* Initialize file specific pushbuttons */
296 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
297 MACRO_ExecuteMacro(macro
->lpszMacro
);
299 /* Reuse existing window */
301 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
302 if (oldwin
->lpszName
&& !lstrcmpi(oldwin
->lpszName
, lpszWindow
))
304 WINHELP_BUTTON
*button
;
306 win
->hMainWnd
= oldwin
->hMainWnd
;
307 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
308 win
->hTextWnd
= oldwin
->hTextWnd
;
309 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= 0;
311 SetWindowLong(win
->hMainWnd
, 0, (LONG
) win
);
312 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
) win
);
313 SetWindowLong(win
->hTextWnd
, 0, (LONG
) win
);
315 WINHELP_InitFonts(win
->hMainWnd
);
318 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
321 WINHELP_SetupText(win
->hTextWnd
);
322 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
323 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
324 UpdateWindow(win
->hTextWnd
);
327 for (button
= oldwin
->first_button
; button
; button
= button
->next
)
328 DestroyWindow(button
->hWnd
);
330 WINHELP_DeleteWindow(oldwin
);
334 /* Create main Window */
335 if (!page
) LoadString(Globals
.hInstance
, IDS_WINE_HELP
, szCaption
, sizeof(szCaption
));
336 hWnd
= CreateWindow (bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
337 page
? page
->file
->lpszTitle
: szCaption
,
338 bPopup
? WS_POPUPWINDOW
| WS_BORDER
: WS_OVERLAPPEDWINDOW
,
339 origin
.x
, origin
.y
, size
.cx
, size
.cy
,
340 0, bPrimary
? LoadMenu(Globals
.hInstance
, STRING_MENU_Xx
) : 0,
341 Globals
.hInstance
, win
);
343 ShowWindow (hWnd
, nCmdShow
);
347 /***********************************************************************
349 * WINHELP_MainWndProc
352 static LRESULT
WINHELP_MainWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
355 WINHELP_BUTTON
*button
;
356 RECT rect
, button_box_rect
;
359 WINHELP_CheckPopup(msg
);
364 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
365 SetWindowLong(hWnd
, 0, (LONG
) win
);
366 win
->hMainWnd
= hWnd
;
370 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
372 /* Create button box and text Window */
373 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
374 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
376 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
377 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
381 case WM_WINDOWPOSCHANGED
:
382 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
383 GetClientRect(hWnd
, &rect
);
385 /* Update button box and text Window */
386 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
388 rect
.right
- rect
.left
,
389 rect
.bottom
- rect
.top
, 0);
391 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
392 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
394 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
396 rect
.right
- rect
.left
,
397 rect
.bottom
- text_top
, 0);
402 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
406 case WH_OPEN
: MACRO_FileOpen(); break;
407 case WH_PRINT
: MACRO_Print(); break;
408 case WH_PRINTER_SETUP
: MACRO_PrinterSetup(); break;
409 case WH_EXIT
: MACRO_Exit(); break;
412 case WH_COPY_DIALOG
: MACRO_CopyDialog(); break;
413 case WH_ANNOTATE
: MACRO_Annotate(); break;
416 case WH_BOOKMARK_DEFINE
: MACRO_BookmarkDefine(); break;
419 case WH_HELP_ON_HELP
: MACRO_HelpOn(); break;
420 case WH_HELP_ON_TOP
: MACRO_HelpOnTop(); break;
423 case WH_ABOUT
: MACRO_About(); break;
426 ShellAbout(hWnd
, "WINE", people
, 0);
432 for (button
= win
->first_button
; button
; button
= button
->next
)
433 if (wParam
== button
->wParam
) break;
435 MACRO_ExecuteMacro(button
->lpszMacro
);
437 WINHELP_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
443 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
446 /***********************************************************************
448 * WINHELP_ButtonBoxWndProc
451 static LRESULT
WINHELP_ButtonBoxWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
455 WINHELP_BUTTON
*button
;
459 WINHELP_CheckPopup(msg
);
464 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
465 SetWindowLong(hWnd
, 0, (LONG
) win
);
466 win
->hButtonBoxWnd
= hWnd
;
469 case WM_WINDOWPOSCHANGING
:
470 winpos
= (WINDOWPOS
*) lParam
;
471 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
476 for (button
= win
->first_button
; button
; button
= button
->next
)
481 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
482 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
484 hWnd
, (HMENU
) button
->wParam
,
485 Globals
.hInstance
, 0);
486 hDc
= GetDC(button
->hWnd
);
487 GetTextExtentPoint(hDc
, button
->lpszName
,
488 lstrlen(button
->lpszName
), &textsize
);
489 ReleaseDC(button
->hWnd
, hDc
);
491 button_size
.cx
= MAX(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
492 button_size
.cy
= MAX(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
497 for (button
= win
->first_button
; button
; button
= button
->next
)
499 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
501 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
504 x
= 0, y
+= button_size
.cy
;
506 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
510 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
514 return(DefWindowProc(hWnd
, msg
, wParam
, lParam
));
517 /***********************************************************************
519 * WINHELP_TextWndProc
522 static LRESULT
WINHELP_TextWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
526 WINHELP_LINE_PART
*part
;
535 if (msg
!= WM_LBUTTONDOWN
)
536 WINHELP_CheckPopup(msg
);
541 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
542 SetWindowLong(hWnd
, 0, (LONG
) win
);
543 win
->hTextWnd
= hWnd
;
544 if (!win
->lpszName
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
545 WINHELP_InitFonts(hWnd
);
549 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
551 /* Calculate vertical size and position of a popup window */
555 RECT old_window_rect
;
556 RECT old_client_rect
;
557 SIZE old_window_size
;
558 SIZE old_client_size
;
559 SIZE new_client_size
;
560 SIZE new_window_size
;
562 GetWindowRect(hWnd
, &old_window_rect
);
563 origin
.x
= old_window_rect
.left
;
564 origin
.y
= old_window_rect
.top
;
565 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
566 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
568 GetClientRect(hWnd
, &old_client_rect
);
569 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
570 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
572 new_client_size
= old_client_size
;
573 WINHELP_SplitLines(hWnd
, &new_client_size
);
575 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
576 origin
.y
+= POPUP_YDISTANCE
;
578 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
580 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
581 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
584 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
| WS_VISIBLE
,
585 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
586 new_window_size
.cx
, new_window_size
.cy
,
587 0, 0, Globals
.hInstance
, 0);
589 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
590 new_window_size
.cx
, new_window_size
.cy
,
591 SWP_NOZORDER
| SWP_NOACTIVATE
);
592 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
596 case WM_WINDOWPOSCHANGED
:
597 winpos
= (WINDOWPOS
*) lParam
;
598 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
606 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
607 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
608 GetClientRect(hWnd
, &rect
);
610 switch (wParam
& 0xffff)
613 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
614 case SB_TOP
: CurPos
= Min
; break;
615 case SB_BOTTOM
: CurPos
= Max
; break;
616 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
617 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
618 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
619 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
620 default: update
= FALSE
;
624 INT dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
625 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
626 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
633 hDc
= BeginPaint (hWnd
, &ps
);
634 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
635 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
637 for (line
= win
->first_line
; line
; line
= line
->next
)
638 for (part
= &line
->first_part
; part
; part
= part
->next
)
640 SelectObject(hDc
, part
->hFont
);
641 SetTextColor(hDc
, part
->color
);
642 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
643 (LPSTR
) part
->lpsText
, part
->wTextLen
);
646 EndPaint (hWnd
, &ps
);
650 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
651 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
653 hPopupWnd
= Globals
.hPopupWnd
;
654 Globals
.hPopupWnd
= 0;
656 mouse
.x
= LOWORD(lParam
);
657 mouse
.y
= HIWORD(lParam
);
658 for (line
= win
->first_line
; line
; line
= line
->next
)
659 for (part
= &line
->first_part
; part
; part
= part
->next
)
660 if (part
->link
.lpszPath
&&
661 part
->rect
.left
<= mouse
.x
&&
662 part
->rect
.right
>= mouse
.x
&&
663 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
664 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)
665 WINHELP_CreateHelpWindow(part
->link
.lpszPath
, part
->link
.lHash
, NULL
,
666 part
->link
.bPopup
, hWnd
, &mouse
, SW_NORMAL
);
668 DestroyWindow(hPopupWnd
);
672 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
674 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
676 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
678 WINHELP_DeleteWindow(win
);
680 if (bExit
) MACRO_Exit();
682 if (!Globals
.win_list
)
687 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
690 /***********************************************************************
695 static VOID
WINHELP_SetupText(HWND hWnd
)
697 HDC hDc
= GetDC(hWnd
);
701 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
702 if (!WINHELP_SplitLines(hWnd
, NULL
))
704 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
705 GetClientRect(hWnd
, &rect
);
707 WINHELP_SplitLines(hWnd
, &newsize
);
708 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
710 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
712 ReleaseDC(hWnd
, hDc
);
715 /***********************************************************************
720 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
722 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
723 HLPFILE_PARAGRAPH
*p
;
724 WINHELP_LINE
**line
= &win
->first_line
;
725 WINHELP_LINE_PART
**part
= 0;
731 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
733 if (!win
->page
) return TRUE
;
735 WINHELP_DeleteLines(win
);
737 GetClientRect(hWnd
, &rect
);
739 rect
.top
+= INTERNAL_BORDER_WIDTH
;
740 rect
.left
+= INTERNAL_BORDER_WIDTH
;
741 rect
.right
-= INTERNAL_BORDER_WIDTH
;
742 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
746 space
.cx
= rect
.left
;
750 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
753 SIZE textsize
= {0, 0};
754 LPCSTR text
= p
->lpszText
;
755 UINT len
= strlen(text
);
758 UINT wFont
= (p
->wFont
< win
->fonts_len
) ? p
->wFont
: 0;
759 BOOL bUnderline
= p
->link
&& !p
->link
->bPopup
;
760 HFONT hFont
= win
->fonts
[wFont
][bUnderline
? 1 : 0];
762 COLORREF color
= RGB(0, 0, 0);
763 if (p
->link
) color
= RGB(0, 0x80, 0);
764 if (p
->bDebug
) color
= RGB(0xff, 0, 0);
766 SelectObject(hDc
, hFont
);
768 GetTextMetrics (hDc
, &tm
);
772 indent
= p
->wIndent
* 5 * tm
.tmAveCharWidth
;
774 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
780 space
.cx
= rect
.left
+ indent
;
781 space
.cy
+= (p
->wVSpace
- 1) * tm
.tmHeight
;
786 space
.cx
+= p
->wHSpace
* 2 * tm
.tmAveCharWidth
;
791 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
792 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
798 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
800 if (textsize
.cx
<= free_width
) low
= curr
;
803 if (high
<= low
+ 1) break;
805 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
806 if (curr
<= low
) curr
= low
+ 1;
807 else if (curr
>= high
) curr
= high
- 1;
810 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
812 if (!part
&& !textlen
) textlen
= MAX(low
, 1);
814 if (free_width
<= 0 || !textlen
)
817 space
.cx
= rect
.left
+ indent
;
818 space
.cx
= MIN(space
.cx
, rect
.right
- rect
.left
- 1);
822 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
823 &line_ascent
, tm
.tmAscent
,
824 text
, textlen
, hFont
, color
, p
->link
) ||
825 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
827 ReleaseDC(hWnd
, hDc
);
832 newsize
->cx
= MAX(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
836 if (text
[0] == ' ') text
++, len
--;
841 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
843 ReleaseDC(hWnd
, hDc
);
847 /***********************************************************************
852 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
853 LPSIZE space
, LPSIZE textsize
,
854 INT
*line_ascent
, INT ascent
,
855 LPCSTR text
, UINT textlen
,
856 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
)
860 WINHELP_LINE_PART
*part
;
863 if (!*partp
) /* New line */
865 *line_ascent
= ascent
;
867 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE
) + textlen
+
868 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
869 if (!handle
) return FALSE
;
870 line
= GlobalLock(handle
);
872 part
= &line
->first_part
;
873 ptr
= GlobalLock(handle
);
874 ptr
+= sizeof(WINHELP_LINE
);
876 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
877 line
->rect
.bottom
= line
->rect
.top
;
878 line
->rect
.left
= space
->cx
;
879 line
->rect
.right
= space
->cx
;
881 if (**linep
) *linep
= &(**linep
)->next
;
889 if (*line_ascent
< ascent
)
891 WINHELP_LINE_PART
*p
;
892 for (p
= &line
->first_part
; p
; p
= p
->next
)
894 p
->rect
.top
+= ascent
- *line_ascent
;
895 p
->rect
.bottom
+= ascent
- *line_ascent
;
897 line
->rect
.bottom
+= ascent
- *line_ascent
;
898 *line_ascent
= ascent
;
901 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE_PART
) + textlen
+
902 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
903 if (!handle
) return FALSE
;
904 part
= GlobalLock(handle
);
906 ptr
= GlobalLock(handle
);
907 ptr
+= sizeof(WINHELP_LINE_PART
);
910 hmemcpy(ptr
, text
, textlen
);
911 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
912 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
913 line
->rect
.right
= part
->rect
.right
;
915 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
916 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
917 line
->rect
.bottom
= MAX(line
->rect
.bottom
, part
->rect
.bottom
);
918 part
->hSelf
= handle
;
920 part
->wTextLen
= textlen
;
925 strcpy(ptr
+ textlen
, link
->lpszPath
);
926 part
->link
.lpszPath
= ptr
+ textlen
;
927 part
->link
.lHash
= link
->lHash
;
928 part
->link
.bPopup
= link
->bPopup
;
930 else part
->link
.lpszPath
= 0;
933 *partp
= &part
->next
;
940 /***********************************************************************
945 static VOID
WINHELP_CheckPopup(UINT msg
)
947 if (!Globals
.hPopupWnd
) return;
955 case WM_NCLBUTTONDOWN
:
956 case WM_NCMBUTTONDOWN
:
957 case WM_NCRBUTTONDOWN
:
958 DestroyWindow(Globals
.hPopupWnd
);
959 Globals
.hPopupWnd
= 0;
963 /***********************************************************************
965 * WINHELP_DeleteLines
968 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
970 WINHELP_LINE
*line
, *next_line
;
971 WINHELP_LINE_PART
*part
, *next_part
;
972 for(line
= win
->first_line
; line
; line
= next_line
)
974 next_line
= line
->next
;
975 for(part
= &line
->first_part
; part
; part
= next_part
)
977 next_part
= part
->next
;
978 GlobalFree(part
->hSelf
);
984 /***********************************************************************
986 * WINHELP_DeleteWindow
989 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*win
)
993 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
1000 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
1001 HLPFILE_FreeHlpFilePage(win
->page
);
1002 WINHELP_DeleteLines(win
);
1003 GlobalFree(win
->hSelf
);
1006 /***********************************************************************
1011 static VOID
WINHELP_InitFonts(HWND hWnd
)
1013 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1014 LOGFONT logfontlist
[] = {
1015 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1016 {-12, 0, 0, 0, 700, 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 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1019 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1020 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1021 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1022 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1024 static HFONT fonts
[FONTS_LEN
][2];
1025 static BOOL init
= 0;
1027 win
->fonts_len
= FONTS_LEN
;
1034 for(i
= 0; i
< FONTS_LEN
; i
++)
1036 LOGFONT logfont
= logfontlist
[i
];
1038 fonts
[i
][0] = CreateFontIndirect(&logfont
);
1039 logfont
.lfUnderline
= 1;
1040 fonts
[i
][1] = CreateFontIndirect(&logfont
);
1047 /***********************************************************************
1049 * WINHELP_MessageBoxIDS
1052 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1054 CHAR text
[MAX_STRING_LEN
];
1055 CHAR title
[MAX_STRING_LEN
];
1057 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1058 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1060 return(MessageBox(0, text
, title
, type
));
1063 /***********************************************************************
1065 * MAIN_MessageBoxIDS_s
1068 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1070 CHAR text
[MAX_STRING_LEN
];
1071 CHAR title
[MAX_STRING_LEN
];
1072 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1074 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1075 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1076 wsprintf(newtext
, text
, str
);
1078 return(MessageBox(0, newtext
, title
, type
));
1081 /* Local Variables: */
1082 /* c-file-style: "GNU" */