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_Fr(void);
21 static BOOL
WINHELP_RegisterWinClasses();
22 static LRESULT
WINHELP_MainWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
23 static LRESULT
WINHELP_TextWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
24 static LRESULT
WINHELP_ButtonBoxWndProc(HWND
, UINT
, WPARAM
, LPARAM
);
25 static VOID
WINHELP_CheckPopup(UINT
);
26 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE
);
27 static VOID
WINHELP_InitFonts(HWND hWnd
);
28 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*);
29 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*);
30 static VOID
WINHELP_SetupText(HWND hWnd
);
31 static BOOL
WINHELP_AppendText(WINHELP_LINE
***, WINHELP_LINE_PART
***,
32 LPSIZE
, LPSIZE
, INT
*, INT
, LPCSTR
, UINT
,
33 HFONT
, COLORREF
, HLPFILE_LINK
*);
35 WINHELP_GLOBALS Globals
= {3, 0, 0, 0, 0, 0};
37 static BOOL MacroTest
= FALSE
;
39 /***********************************************************************
44 int PASCAL
WinMain (HANDLE hInstance
, HANDLE prev
, LPSTR cmdline
, int show
)
46 LPCSTR opt_lang
= "En";
52 #if defined(WINELIB) && !defined(HAVE_WINE_CONSTRUCTOR)
53 /* Register resources */
54 LIBWINE_Register_De();
55 LIBWINE_Register_En();
56 LIBWINE_Register_Fr();
59 Globals
.hInstance
= hInstance
;
62 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
66 if (*cmdline
++ == ' ') continue;
69 if (option
) cmdline
++;
70 while (*cmdline
&& *cmdline
== ' ') cmdline
++;
76 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
77 if (*cmdline
) *cmdline
++ = '\0';
78 lHash
= HLPFILE_Hash(topic_id
);
83 Globals
.wVersion
= option
- '0';
93 opt_lang
= langNames
[Options
.language
];
96 /* Find language specific string table */
97 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
99 Globals
.wStringTableOffset
= langnum
* 0x100;
100 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)) &&
101 !lstrcmp(opt_lang
, lang
))
104 if (langnum
> MAX_LANGUAGE_NUMBER
)
106 /* Find fallback language */
107 for (langnum
= 0; langnum
<= MAX_LANGUAGE_NUMBER
; langnum
++)
109 Globals
.wStringTableOffset
= langnum
* 0x100;
110 if (LoadString(hInstance
, IDS_LANGUAGE_ID
, lang
, sizeof(lang
)))
113 if (langnum
> MAX_LANGUAGE_NUMBER
)
115 MessageBox(0, "No language found", "FATAL ERROR", MB_OK
);
120 /* Change Resource names */
121 lstrcpyn(STRING_MENU_Xx
+ lstrlen(STRING_MENU_Xx
) - 2, lang
, 3);
123 /* Create primary window */
124 WINHELP_RegisterWinClasses();
125 WINHELP_CreateHelpWindow(cmdline
, lHash
, "main", FALSE
, NULL
, NULL
, show
);
128 while (GetMessage (&msg
, 0, 0, 0))
130 TranslateMessage (&msg
);
131 DispatchMessage (&msg
);
136 /***********************************************************************
141 static BOOL
WINHELP_RegisterWinClasses()
143 WNDCLASS class_main
, class_button_box
, class_text
, class_shadow
;
145 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
146 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
147 class_main
.cbClsExtra
= 0;
148 class_main
.cbWndExtra
= sizeof(LONG
);
149 class_main
.hInstance
= Globals
.hInstance
;
150 class_main
.hIcon
= LoadIcon (0, IDI_APPLICATION
);
151 class_main
.hCursor
= LoadCursor (0, IDC_ARROW
);
152 class_main
.hbrBackground
= GetStockObject (WHITE_BRUSH
);
153 class_main
.lpszMenuName
= 0;
154 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
156 class_button_box
= class_main
;
157 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
158 class_button_box
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
159 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
161 class_text
= class_main
;
162 class_text
.lpfnWndProc
= WINHELP_TextWndProc
;
163 class_text
.lpszClassName
= TEXT_WIN_CLASS_NAME
;
165 class_shadow
= class_main
;
166 class_shadow
.lpfnWndProc
= DefWindowProc
;
167 class_shadow
.hbrBackground
= GetStockObject(GRAY_BRUSH
);
168 class_shadow
.lpszClassName
= SHADOW_WIN_CLASS_NAME
;
170 return (RegisterClass(&class_main
) &&
171 RegisterClass(&class_button_box
) &&
172 RegisterClass(&class_text
) &&
173 RegisterClass(&class_shadow
));
176 /***********************************************************************
178 * WINHELP_CreateHelpWindow
181 VOID
WINHELP_CreateHelpWindow(LPCSTR lpszFile
, LONG lHash
, LPCSTR lpszWindow
,
182 BOOL bPopup
, HWND hParentWnd
, LPPOINT mouse
, INT nCmdShow
)
184 CHAR szCaption
[MAX_STRING_LEN
];
185 CHAR szContents
[MAX_STRING_LEN
];
186 CHAR szSearch
[MAX_STRING_LEN
];
187 CHAR szBack
[MAX_STRING_LEN
];
188 CHAR szHistory
[MAX_STRING_LEN
];
189 SIZE size
= {CW_USEDEFAULT
, CW_USEDEFAULT
};
190 POINT origin
= {240, 0};
193 WINHELP_WINDOW
*win
, *oldwin
;
195 HLPFILE_MACRO
*macro
;
201 else if (!lpszWindow
|| !lpszWindow
[0])
202 lpszWindow
= Globals
.active_win
->lpszName
;
203 bPrimary
= lpszWindow
&& !lstrcmpi(lpszWindow
, "main");
208 page
= lHash
? HLPFILE_PageByHash(lpszFile
, lHash
) : HLPFILE_Contents(lpszFile
);
210 /* Add Suffix `.hlp' */
211 if (!page
&& lstrcmpi(lpszFile
+ strlen(lpszFile
) - 4, ".hlp"))
213 CHAR szFile_hlp
[MAX_PATHNAME_LEN
];
215 lstrcpyn(szFile_hlp
, lpszFile
, sizeof(szFile_hlp
) - 4);
216 szFile_hlp
[sizeof(szFile_hlp
) - 5] = '\0';
217 lstrcat(szFile_hlp
, ".hlp");
219 page
= lHash
? HLPFILE_PageByHash(szFile_hlp
, lHash
) : HLPFILE_Contents(szFile_hlp
);
222 WINHELP_MessageBoxIDS_s(IDS_HLPFILE_ERROR_s
, lpszFile
, IDS_ERROR
, MB_OK
);
223 if (Globals
.win_list
) return;
229 /* Calculate horizontal size and position of a popup window */
233 GetWindowRect(hParentWnd
, &parent_rect
);
234 size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
237 ClientToScreen(hParentWnd
, &origin
);
238 origin
.x
-= size
.cx
/ 2;
239 origin
.x
= MIN(origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - size
.cx
);
240 origin
.x
= MAX(origin
.x
, 0);
243 /* Initialize WINHELP_WINDOW struct */
244 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_WINDOW
) +
245 (lpszWindow
? strlen(lpszWindow
) + 1 : 0));
247 win
= GlobalLock(handle
);
249 win
->next
= Globals
.win_list
;
250 Globals
.win_list
= win
;
253 ptr
= GlobalLock(handle
);
254 ptr
+= sizeof(WINHELP_WINDOW
);
255 lstrcpy(ptr
, (LPSTR
) lpszWindow
);
258 else win
->lpszName
= NULL
;
260 win
->first_button
= 0;
263 win
->hButtonBoxWnd
= 0;
267 Globals
.active_win
= win
;
269 /* Initialize default pushbuttons */
270 if (MacroTest
&& !bPopup
)
271 MACRO_CreateButton("BTN_TEST", "&Test", "MacroTest");
272 if (bPrimary
&& page
)
274 LoadString(Globals
.hInstance
, IDS_CONTENTS
, szContents
, sizeof(szContents
));
275 LoadString(Globals
.hInstance
, IDS_SEARCH
, szSearch
, sizeof(szSearch
));
276 LoadString(Globals
.hInstance
, IDS_BACK
, szBack
, sizeof(szBack
));
277 LoadString(Globals
.hInstance
, IDS_HISTORY
, szHistory
, sizeof(szHistory
));
278 MACRO_CreateButton("BTN_CONTENTS", szContents
, "Contents()");
279 MACRO_CreateButton("BTN_SEARCH", szSearch
, "Search()");
280 MACRO_CreateButton("BTN_BACK", szBack
, "Back()");
281 MACRO_CreateButton("BTN_HISTORY", szHistory
, "History()");
284 /* Initialize file specific pushbuttons */
286 for (macro
= page
->file
->first_macro
; macro
; macro
= macro
->next
)
287 MACRO_ExecuteMacro(macro
->lpszMacro
);
289 /* Reuse existing window */
291 for (oldwin
= win
->next
; oldwin
; oldwin
= oldwin
->next
)
292 if (oldwin
->lpszName
&& !lstrcmpi(oldwin
->lpszName
, lpszWindow
))
294 WINHELP_BUTTON
*button
;
296 win
->hMainWnd
= oldwin
->hMainWnd
;
297 win
->hButtonBoxWnd
= oldwin
->hButtonBoxWnd
;
298 win
->hTextWnd
= oldwin
->hTextWnd
;
299 oldwin
->hMainWnd
= oldwin
->hButtonBoxWnd
= oldwin
->hTextWnd
= 0;
301 SetWindowLong(win
->hMainWnd
, 0, (LONG
) win
);
302 SetWindowLong(win
->hButtonBoxWnd
, 0, (LONG
) win
);
303 SetWindowLong(win
->hTextWnd
, 0, (LONG
) win
);
305 WINHELP_InitFonts(win
->hMainWnd
);
307 SetWindowText(win
->hMainWnd
, page
->file
->lpszTitle
);
309 WINHELP_SetupText(win
->hTextWnd
);
310 InvalidateRect(win
->hTextWnd
, NULL
, TRUE
);
311 SendMessage(win
->hMainWnd
, WM_USER
, 0, 0);
312 UpdateWindow(win
->hTextWnd
);
315 for (button
= oldwin
->first_button
; button
; button
= button
->next
)
316 DestroyWindow(button
->hWnd
);
318 WINHELP_DeleteWindow(oldwin
);
322 /* Create main Window */
323 if (!page
) LoadString(Globals
.hInstance
, IDS_WINE_HELP
, szCaption
, sizeof(szCaption
));
324 hWnd
= CreateWindow (bPopup
? TEXT_WIN_CLASS_NAME
: MAIN_WIN_CLASS_NAME
,
325 page
? page
->file
->lpszTitle
: szCaption
,
326 bPopup
? WS_POPUPWINDOW
| WS_BORDER
: WS_OVERLAPPEDWINDOW
,
327 origin
.x
, origin
.y
, size
.cx
, size
.cy
,
328 0, bPrimary
? LoadMenu(Globals
.hInstance
, STRING_MENU_Xx
) : 0,
329 Globals
.hInstance
, win
);
331 ShowWindow (hWnd
, nCmdShow
);
335 /***********************************************************************
337 * WINHELP_MainWndProc
340 static LRESULT
WINHELP_MainWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
343 WINHELP_BUTTON
*button
;
344 RECT rect
, button_box_rect
;
347 WINHELP_CheckPopup(msg
);
352 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
353 SetWindowLong(hWnd
, 0, (LONG
) win
);
354 win
->hMainWnd
= hWnd
;
358 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
360 /* Create button box and text Window */
361 CreateWindow(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
362 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
364 CreateWindow(TEXT_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
365 0, 0, 0, 0, hWnd
, 0, Globals
.hInstance
, win
);
369 case WM_WINDOWPOSCHANGED
:
370 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
371 GetClientRect(hWnd
, &rect
);
373 /* Update button box and text Window */
374 SetWindowPos(win
->hButtonBoxWnd
, HWND_TOP
,
376 rect
.right
- rect
.left
,
377 rect
.bottom
- rect
.top
, 0);
379 GetWindowRect(win
->hButtonBoxWnd
, &button_box_rect
);
380 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
382 SetWindowPos(win
->hTextWnd
, HWND_TOP
,
384 rect
.right
- rect
.left
,
385 rect
.bottom
- text_top
, 0);
390 Globals
.active_win
= win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
394 case WH_OPEN
: MACRO_FileOpen(); break;
395 case WH_PRINT
: MACRO_Print(); break;
396 case WH_PRINTER_SETUP
: MACRO_PrinterSetup(); break;
397 case WH_EXIT
: MACRO_Exit(); break;
400 case WH_COPY_DIALOG
: MACRO_CopyDialog(); break;
401 case WH_ANNOTATE
: MACRO_Annotate(); break;
404 case WH_BOOKMARK_DEFINE
: MACRO_BookmarkDefine(); break;
407 case WH_HELP_ON_HELP
: MACRO_HelpOn(); break;
408 case WH_HELP_ON_TOP
: MACRO_HelpOnTop(); break;
411 case WH_ABOUT
: MACRO_About(); break;
414 ShellAbout(hWnd
, "WINE", people
, 0);
420 for (button
= win
->first_button
; button
; button
= button
->next
)
421 if (wParam
== button
->wParam
) break;
423 MACRO_ExecuteMacro(button
->lpszMacro
);
425 WINHELP_MessageBoxIDS(IDS_NOT_IMPLEMENTED
, IDS_ERROR
, MB_OK
);
431 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
434 /***********************************************************************
436 * WINHELP_ButtonBoxWndProc
439 static LRESULT
WINHELP_ButtonBoxWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
443 WINHELP_BUTTON
*button
;
447 WINHELP_CheckPopup(msg
);
452 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
453 SetWindowLong(hWnd
, 0, (LONG
) win
);
454 win
->hButtonBoxWnd
= hWnd
;
457 case WM_WINDOWPOSCHANGING
:
458 winpos
= (WINDOWPOS
*) lParam
;
459 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
464 for (button
= win
->first_button
; button
; button
= button
->next
)
469 button
->hWnd
= CreateWindow(STRING_BUTTON
, (LPSTR
) button
->lpszName
,
470 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
472 hWnd
, (HMENU
) button
->wParam
,
473 Globals
.hInstance
, 0);
474 hDc
= GetDC(button
->hWnd
);
475 GetTextExtentPoint(hDc
, button
->lpszName
,
476 lstrlen(button
->lpszName
), &textsize
);
477 ReleaseDC(button
->hWnd
, hDc
);
479 button_size
.cx
= MAX(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
480 button_size
.cy
= MAX(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
485 for (button
= win
->first_button
; button
; button
= button
->next
)
487 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
489 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
492 x
= 0, y
+= button_size
.cy
;
494 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
498 SendMessage(GetParent(hWnd
), msg
, wParam
, lParam
);
502 return(DefWindowProc(hWnd
, msg
, wParam
, lParam
));
505 /***********************************************************************
507 * WINHELP_TextWndProc
510 static LRESULT
WINHELP_TextWndProc (HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
514 WINHELP_LINE_PART
*part
;
523 if (msg
!= WM_LBUTTONDOWN
)
524 WINHELP_CheckPopup(msg
);
529 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCT
) lParam
)->lpCreateParams
;
530 SetWindowLong(hWnd
, 0, (LONG
) win
);
531 win
->hTextWnd
= hWnd
;
532 if (!win
->lpszName
) Globals
.hPopupWnd
= win
->hMainWnd
= hWnd
;
533 WINHELP_InitFonts(hWnd
);
537 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
539 /* Calculate vertical size and position of a popup window */
543 RECT old_window_rect
;
544 RECT old_client_rect
;
545 SIZE old_window_size
;
546 SIZE old_client_size
;
547 SIZE new_client_size
;
548 SIZE new_window_size
;
550 GetWindowRect(hWnd
, &old_window_rect
);
551 origin
.x
= old_window_rect
.left
;
552 origin
.y
= old_window_rect
.top
;
553 old_window_size
.cx
= old_window_rect
.right
- old_window_rect
.left
;
554 old_window_size
.cy
= old_window_rect
.bottom
- old_window_rect
.top
;
556 GetClientRect(hWnd
, &old_client_rect
);
557 old_client_size
.cx
= old_client_rect
.right
- old_client_rect
.left
;
558 old_client_size
.cy
= old_client_rect
.bottom
- old_client_rect
.top
;
560 new_client_size
= old_client_size
;
561 WINHELP_SplitLines(hWnd
, &new_client_size
);
563 if (origin
.y
+ POPUP_YDISTANCE
+ new_client_size
.cy
<= GetSystemMetrics(SM_CYSCREEN
))
564 origin
.y
+= POPUP_YDISTANCE
;
566 origin
.y
-= POPUP_YDISTANCE
+ new_client_size
.cy
;
568 new_window_size
.cx
= old_window_size
.cx
- old_client_size
.cx
+ new_client_size
.cx
;
569 new_window_size
.cy
= old_window_size
.cy
- old_client_size
.cy
+ new_client_size
.cy
;
572 CreateWindow(SHADOW_WIN_CLASS_NAME
, "", WS_POPUP
| WS_VISIBLE
,
573 origin
.x
+ SHADOW_DX
, origin
.y
+ SHADOW_DY
,
574 new_window_size
.cx
, new_window_size
.cy
,
575 0, 0, Globals
.hInstance
, 0);
577 SetWindowPos(hWnd
, HWND_TOP
, origin
.x
, origin
.y
,
578 new_window_size
.cx
, new_window_size
.cy
,
579 SWP_NOZORDER
| SWP_NOACTIVATE
);
580 ShowWindow(win
->hShadowWnd
, SW_NORMAL
);
584 case WM_WINDOWPOSCHANGED
:
585 winpos
= (WINDOWPOS
*) lParam
;
586 if (!(winpos
->flags
& SWP_NOSIZE
)) WINHELP_SetupText(hWnd
);
594 INT CurPos
= GetScrollPos(hWnd
, SB_VERT
);
595 GetScrollRange(hWnd
, SB_VERT
, &Min
, &Max
);
596 GetClientRect(hWnd
, &rect
);
598 switch (wParam
& 0xffff)
601 case SB_THUMBPOSITION
: CurPos
= wParam
>> 16; break;
602 case SB_TOP
: CurPos
= Min
; break;
603 case SB_BOTTOM
: CurPos
= Max
; break;
604 case SB_PAGEUP
: CurPos
-= (rect
.bottom
- rect
.top
) / 2; break;
605 case SB_PAGEDOWN
: CurPos
+= (rect
.bottom
- rect
.top
) / 2; break;
606 case SB_LINEUP
: CurPos
-= GetSystemMetrics(SM_CXVSCROLL
); break;
607 case SB_LINEDOWN
: CurPos
+= GetSystemMetrics(SM_CXVSCROLL
); break;
608 default: update
= FALSE
;
612 INT dy
= GetScrollPos(hWnd
, SB_VERT
) - CurPos
;
613 SetScrollPos(hWnd
, SB_VERT
, CurPos
, TRUE
);
614 ScrollWindow(hWnd
, 0, dy
, NULL
, NULL
);
621 hDc
= BeginPaint (hWnd
, &ps
);
622 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
623 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
625 for (line
= win
->first_line
; line
; line
= line
->next
)
626 for (part
= &line
->first_part
; part
; part
= part
->next
)
628 SelectObject(hDc
, part
->hFont
);
629 SetTextColor(hDc
, part
->color
);
630 TextOut(hDc
, part
->rect
.left
, part
->rect
.top
- scroll_pos
,
631 (LPSTR
) part
->lpsText
, part
->wTextLen
);
634 EndPaint (hWnd
, &ps
);
638 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
639 scroll_pos
= GetScrollPos(hWnd
, SB_VERT
);
641 hPopupWnd
= Globals
.hPopupWnd
;
642 Globals
.hPopupWnd
= 0;
644 mouse
.x
= LOWORD(lParam
);
645 mouse
.y
= HIWORD(lParam
);
646 for (line
= win
->first_line
; line
; line
= line
->next
)
647 for (part
= &line
->first_part
; part
; part
= part
->next
)
648 if (part
->link
.lpszPath
&&
649 part
->rect
.left
<= mouse
.x
&&
650 part
->rect
.right
>= mouse
.x
&&
651 part
->rect
.top
<= mouse
.y
+ scroll_pos
&&
652 part
->rect
.bottom
>= mouse
.y
+ scroll_pos
)
653 WINHELP_CreateHelpWindow(part
->link
.lpszPath
, part
->link
.lHash
, NULL
,
654 part
->link
.bPopup
, hWnd
, &mouse
, SW_NORMAL
);
656 DestroyWindow(hPopupWnd
);
660 win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
662 if (hWnd
== Globals
.hPopupWnd
) Globals
.hPopupWnd
= 0;
664 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpi(win
->lpszName
, "main"));
666 WINHELP_DeleteWindow(win
);
668 if (bExit
) MACRO_Exit();
670 if (!Globals
.win_list
)
675 return DefWindowProc (hWnd
, msg
, wParam
, lParam
);
678 /***********************************************************************
683 static VOID
WINHELP_SetupText(HWND hWnd
)
685 HDC hDc
= GetDC(hWnd
);
689 ShowScrollBar(hWnd
, SB_VERT
, FALSE
);
690 if (!WINHELP_SplitLines(hWnd
, NULL
))
692 ShowScrollBar(hWnd
, SB_VERT
, TRUE
);
693 GetClientRect(hWnd
, &rect
);
695 WINHELP_SplitLines(hWnd
, &newsize
);
696 SetScrollRange(hWnd
, SB_VERT
, 0, rect
.top
+ newsize
.cy
- rect
.bottom
, TRUE
);
698 else SetScrollPos(hWnd
, SB_VERT
, 0, FALSE
);
700 ReleaseDC(hWnd
, hDc
);
703 /***********************************************************************
708 static BOOL
WINHELP_SplitLines(HWND hWnd
, LPSIZE newsize
)
710 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
711 HLPFILE_PARAGRAPH
*p
;
712 WINHELP_LINE
**line
= &win
->first_line
;
713 WINHELP_LINE_PART
**part
= 0;
719 if (newsize
) newsize
->cx
= newsize
->cy
= 0;
721 if (!win
->page
) return TRUE
;
723 WINHELP_DeleteLines(win
);
725 GetClientRect(hWnd
, &rect
);
727 rect
.top
+= INTERNAL_BORDER_WIDTH
;
728 rect
.left
+= INTERNAL_BORDER_WIDTH
;
729 rect
.right
-= INTERNAL_BORDER_WIDTH
;
730 rect
.bottom
-= INTERNAL_BORDER_WIDTH
;
734 space
.cx
= rect
.left
;
738 for (p
= win
->page
->first_paragraph
; p
; p
= p
->next
)
741 SIZE textsize
= {0, 0};
742 LPCSTR text
= p
->lpszText
;
743 UINT len
= strlen(text
);
746 UINT wFont
= (p
->wFont
< win
->fonts_len
) ? p
->wFont
: 0;
747 BOOL bUnderline
= p
->link
&& !p
->link
->bPopup
;
748 HFONT hFont
= win
->fonts
[wFont
][bUnderline
? 1 : 0];
750 COLORREF color
= RGB(0, 0, 0);
751 if (p
->link
) color
= RGB(0, 0x80, 0);
752 if (p
->bDebug
) color
= RGB(0xff, 0, 0);
754 SelectObject(hDc
, hFont
);
756 GetTextMetrics (hDc
, &tm
);
760 indent
= p
->wIndent
* 5 * tm
.tmAveCharWidth
;
762 space
.cx
= rect
.left
+ indent
- 2 * tm
.tmAveCharWidth
;
768 space
.cx
= rect
.left
+ indent
;
769 space
.cy
+= (p
->wVSpace
- 1) * tm
.tmHeight
;
774 space
.cx
+= p
->wHSpace
* 2 * tm
.tmAveCharWidth
;
779 INT free_width
= rect
.right
- (part
? (*line
)->rect
.right
: rect
.left
) - space
.cx
;
780 UINT low
= 0, curr
= len
, high
= len
, textlen
= 0;
786 GetTextExtentPoint(hDc
, text
, curr
, &textsize
);
788 if (textsize
.cx
<= free_width
) low
= curr
;
791 if (high
<= low
+ 1) break;
793 if (textsize
.cx
) curr
= (curr
* free_width
) / textsize
.cx
;
794 if (curr
<= low
) curr
= low
+ 1;
795 else if (curr
>= high
) curr
= high
- 1;
798 while (textlen
&& text
[textlen
] && text
[textlen
] != ' ') textlen
--;
800 if (!part
&& !textlen
) textlen
= MAX(low
, 1);
802 if (free_width
<= 0 || !textlen
)
805 space
.cx
= rect
.left
+ indent
;
806 space
.cx
= MIN(space
.cx
, rect
.right
- rect
.left
- 1);
810 if (!WINHELP_AppendText(&line
, &part
, &space
, &textsize
,
811 &line_ascent
, tm
.tmAscent
,
812 text
, textlen
, hFont
, color
, p
->link
) ||
813 (!newsize
&& (*line
)->rect
.bottom
> rect
.bottom
))
815 ReleaseDC(hWnd
, hDc
);
820 newsize
->cx
= MAX(newsize
->cx
, (*line
)->rect
.right
+ INTERNAL_BORDER_WIDTH
);
824 if (text
[0] == ' ') text
++, len
--;
829 newsize
->cy
= (*line
)->rect
.bottom
+ INTERNAL_BORDER_WIDTH
;
831 ReleaseDC(hWnd
, hDc
);
835 /***********************************************************************
840 static BOOL
WINHELP_AppendText(WINHELP_LINE
***linep
, WINHELP_LINE_PART
***partp
,
841 LPSIZE space
, LPSIZE textsize
,
842 INT
*line_ascent
, INT ascent
,
843 LPCSTR text
, UINT textlen
,
844 HFONT font
, COLORREF color
, HLPFILE_LINK
*link
)
848 WINHELP_LINE_PART
*part
;
851 if (!*partp
) /* New line */
853 *line_ascent
= ascent
;
855 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE
) + textlen
+
856 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
857 if (!handle
) return FALSE
;
858 line
= GlobalLock(handle
);
860 part
= &line
->first_part
;
861 ptr
= GlobalLock(handle
);
862 ptr
+= sizeof(WINHELP_LINE
);
864 line
->rect
.top
= (**linep
? (**linep
)->rect
.bottom
: 0) + space
->cy
;
865 line
->rect
.bottom
= line
->rect
.top
;
866 line
->rect
.left
= space
->cx
;
867 line
->rect
.right
= space
->cx
;
869 if (**linep
) *linep
= &(**linep
)->next
;
877 if (*line_ascent
< ascent
)
879 WINHELP_LINE_PART
*p
;
880 for (p
= &line
->first_part
; p
; p
= p
->next
)
882 p
->rect
.top
+= ascent
- *line_ascent
;
883 p
->rect
.bottom
+= ascent
- *line_ascent
;
885 line
->rect
.bottom
+= ascent
- *line_ascent
;
886 *line_ascent
= ascent
;
889 handle
= GlobalAlloc(GMEM_FIXED
, sizeof(WINHELP_LINE_PART
) + textlen
+
890 (link
? lstrlen(link
->lpszPath
) + 1 : 0));
891 if (!handle
) return FALSE
;
892 part
= GlobalLock(handle
);
894 ptr
= GlobalLock(handle
);
895 ptr
+= sizeof(WINHELP_LINE_PART
);
898 hmemcpy(ptr
, text
, textlen
);
899 part
->rect
.left
= line
->rect
.right
+ (*partp
? space
->cx
: 0);
900 part
->rect
.right
= part
->rect
.left
+ textsize
->cx
;
901 line
->rect
.right
= part
->rect
.right
;
903 ((*partp
) ? line
->rect
.top
: line
->rect
.bottom
) + *line_ascent
- ascent
;
904 part
->rect
.bottom
= part
->rect
.top
+ textsize
->cy
;
905 line
->rect
.bottom
= MAX(line
->rect
.bottom
, part
->rect
.bottom
);
906 part
->hSelf
= handle
;
908 part
->wTextLen
= textlen
;
913 strcpy(ptr
+ textlen
, link
->lpszPath
);
914 part
->link
.lpszPath
= ptr
+ textlen
;
915 part
->link
.lHash
= link
->lHash
;
916 part
->link
.bPopup
= link
->bPopup
;
918 else part
->link
.lpszPath
= 0;
921 *partp
= &part
->next
;
928 /***********************************************************************
933 static VOID
WINHELP_CheckPopup(UINT msg
)
935 if (!Globals
.hPopupWnd
) return;
943 case WM_NCLBUTTONDOWN
:
944 case WM_NCMBUTTONDOWN
:
945 case WM_NCRBUTTONDOWN
:
946 DestroyWindow(Globals
.hPopupWnd
);
947 Globals
.hPopupWnd
= 0;
951 /***********************************************************************
953 * WINHELP_DeleteLines
956 static VOID
WINHELP_DeleteLines(WINHELP_WINDOW
*win
)
958 WINHELP_LINE
*line
, *next_line
;
959 WINHELP_LINE_PART
*part
, *next_part
;
960 for(line
= win
->first_line
; line
; line
= next_line
)
962 next_line
= line
->next
;
963 for(part
= &line
->first_part
; part
; part
= next_part
)
965 next_part
= part
->next
;
966 GlobalFree(part
->hSelf
);
972 /***********************************************************************
974 * WINHELP_DeleteWindow
977 static VOID
WINHELP_DeleteWindow(WINHELP_WINDOW
*win
)
981 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
988 if (win
->hShadowWnd
) DestroyWindow(win
->hShadowWnd
);
989 HLPFILE_FreeHlpFilePage(win
->page
);
990 WINHELP_DeleteLines(win
);
991 GlobalFree(win
->hSelf
);
994 /***********************************************************************
999 static VOID
WINHELP_InitFonts(HWND hWnd
)
1001 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLong(hWnd
, 0);
1002 LOGFONT logfontlist
[] = {
1003 {-10, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1004 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1005 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1006 {-12, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1007 {-12, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1008 {-10, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"},
1009 { -8, 0, 0, 0, 400, 0, 0, 0, 0, 0, 0, 0, 32, "Helv"}};
1010 #define FONTS_LEN (sizeof(logfontlist)/sizeof(*logfontlist))
1012 static HFONT fonts
[FONTS_LEN
][2];
1013 static BOOL init
= 0;
1015 win
->fonts_len
= FONTS_LEN
;
1022 for(i
= 0; i
< FONTS_LEN
; i
++)
1024 LOGFONT logfont
= logfontlist
[i
];
1026 fonts
[i
][0] = CreateFontIndirect(&logfont
);
1027 logfont
.lfUnderline
= 1;
1028 fonts
[i
][1] = CreateFontIndirect(&logfont
);
1035 /***********************************************************************
1037 * WINHELP_MessageBoxIDS
1040 INT
WINHELP_MessageBoxIDS(UINT ids_text
, UINT ids_title
, WORD type
)
1042 CHAR text
[MAX_STRING_LEN
];
1043 CHAR title
[MAX_STRING_LEN
];
1045 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1046 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1048 return(MessageBox(0, text
, title
, type
));
1051 /***********************************************************************
1053 * MAIN_MessageBoxIDS_s
1056 INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
1058 CHAR text
[MAX_STRING_LEN
];
1059 CHAR title
[MAX_STRING_LEN
];
1060 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATHNAME_LEN
];
1062 LoadString(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
1063 LoadString(Globals
.hInstance
, ids_title
, title
, sizeof(title
));
1064 wsprintf(newtext
, text
, str
);
1066 return(MessageBox(0, newtext
, title
, type
));
1069 /* Local Variables: */
1070 /* c-file-style: "GNU" */