4 * Copyright 1996 Ulrich Schmid <uschmid@mail.hh.provi.de>
5 * 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * 2002, 2008 Eric Pouech <eric.pouech@wanadoo.fr>
7 * 2004 Ken Belleau <jamez@ivic.qc.ca>
8 * 2008 Kirill K. Smirnov <lich@math.spbu.ru>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
37 #include "winhelp_res.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
46 WINHELP_GLOBALS Globals
= {3, NULL
, TRUE
, NULL
, NULL
, NULL
, NULL
, NULL
, {{{NULL
,NULL
}},0}, NULL
};
48 #define CTL_ID_BUTTON 0x700
49 #define CTL_ID_TEXT 0x701
52 /***********************************************************************
56 static void WINHELP_InitFonts(HWND hWnd
)
58 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
59 LOGFONTW logfontlist
[] = {
60 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
61 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
62 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
63 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
64 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
65 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
66 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}}};
68 static HFONT fonts
[ARRAY_SIZE(logfontlist
)];
69 static BOOL init
= FALSE
;
71 win
->fonts_len
= ARRAY_SIZE(logfontlist
);
78 for (i
= 0; i
< ARRAY_SIZE(logfontlist
); i
++)
80 fonts
[i
] = CreateFontIndirectW(&logfontlist
[i
]);
87 static DWORD CALLBACK
WINHELP_RtfStreamIn(DWORD_PTR cookie
, BYTE
* buff
,
90 struct RtfData
* rd
= (struct RtfData
*)cookie
;
92 if (rd
->where
>= rd
->ptr
) return 1;
93 if (rd
->where
+ cb
> rd
->ptr
)
94 cb
= rd
->ptr
- rd
->where
;
95 memcpy(buff
, rd
->where
, cb
);
101 static void WINHELP_SetupText(HWND hTextWnd
, WINHELP_WINDOW
* win
, ULONG relative
)
103 static const WCHAR emptyW
[1];
104 /* At first clear area - needed by EM_POSFROMCHAR/EM_SETSCROLLPOS */
105 SendMessageW(hTextWnd
, WM_SETTEXT
, 0, (LPARAM
)emptyW
);
106 SendMessageW(hTextWnd
, WM_SETREDRAW
, FALSE
, 0);
107 SendMessageW(hTextWnd
, EM_SETBKGNDCOLOR
, 0, (LPARAM
)win
->info
->sr_color
);
108 /* set word-wrap to window size (undocumented) */
109 SendMessageW(hTextWnd
, EM_SETTARGETDEVICE
, 0, 0);
119 if (HLPFILE_BrowsePage(win
->page
, &rd
, win
->font_scale
, relative
))
122 es
.dwCookie
= (DWORD_PTR
)&rd
;
124 es
.pfnCallback
= WINHELP_RtfStreamIn
;
126 SendMessageW(hTextWnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
)&es
);
127 cp
= rd
.char_pos_rel
;
129 /* FIXME: else leaking potentially the rd.first_link chain */
131 SendMessageW(hTextWnd
, EM_POSFROMCHAR
, (WPARAM
)&ptl
, cp
? cp
- 1 : 0);
132 pt
.x
= 0; pt
.y
= ptl
.y
;
133 SendMessageW(hTextWnd
, EM_SETSCROLLPOS
, 0, (LPARAM
)&pt
);
135 SendMessageW(hTextWnd
, WM_SETREDRAW
, TRUE
, 0);
136 RedrawWindow(hTextWnd
, NULL
, NULL
, RDW_FRAME
|RDW_INVALIDATE
);
139 /***********************************************************************
141 * WINHELP_GetOpenFileName
143 BOOL
WINHELP_GetOpenFileName(LPSTR lpszFile
, int len
)
145 OPENFILENAMEA openfilename
;
146 CHAR szDir
[MAX_PATH
];
147 CHAR szzFilter
[2 * MAX_STRING_LEN
+ 100];
152 LoadStringA(Globals
.hInstance
, STID_HELP_FILES_HLP
, p
, MAX_STRING_LEN
);
156 LoadStringA(Globals
.hInstance
, STID_ALL_FILES
, p
, MAX_STRING_LEN
);
162 GetCurrentDirectoryA(sizeof(szDir
), szDir
);
166 openfilename
.lStructSize
= sizeof(openfilename
);
167 openfilename
.hwndOwner
= (Globals
.active_win
? Globals
.active_win
->hMainWnd
: 0);
168 openfilename
.hInstance
= Globals
.hInstance
;
169 openfilename
.lpstrFilter
= szzFilter
;
170 openfilename
.lpstrCustomFilter
= 0;
171 openfilename
.nMaxCustFilter
= 0;
172 openfilename
.nFilterIndex
= 1;
173 openfilename
.lpstrFile
= lpszFile
;
174 openfilename
.nMaxFile
= len
;
175 openfilename
.lpstrFileTitle
= 0;
176 openfilename
.nMaxFileTitle
= 0;
177 openfilename
.lpstrInitialDir
= szDir
;
178 openfilename
.lpstrTitle
= 0;
179 openfilename
.Flags
= OFN_ENABLESIZING
| OFN_HIDEREADONLY
| OFN_READONLY
;
180 openfilename
.nFileOffset
= 0;
181 openfilename
.nFileExtension
= 0;
182 openfilename
.lpstrDefExt
= 0;
183 openfilename
.lCustData
= 0;
184 openfilename
.lpfnHook
= 0;
185 openfilename
.lpTemplateName
= 0;
187 return GetOpenFileNameA(&openfilename
);
190 /***********************************************************************
192 * WINHELP_MessageBoxIDS_s
194 static INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
196 CHAR text
[MAX_STRING_LEN
];
197 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATH
];
199 LoadStringA(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
200 wsprintfA(newtext
, text
, str
);
202 return MessageBoxA(0, newtext
, MAKEINTRESOURCEA(ids_title
), type
);
205 /***********************************************************************
207 * WINHELP_LookupHelpFile
209 HLPFILE
* WINHELP_LookupHelpFile(LPCSTR lpszFile
)
212 char szFullName
[MAX_PATH
];
213 char szAddPath
[MAX_PATH
];
217 * NOTE: This is needed by popup windows only.
218 * In other cases it's not needed but does not hurt though.
220 if (Globals
.active_win
&& Globals
.active_win
->page
&& Globals
.active_win
->page
->file
)
222 strcpy(szAddPath
, Globals
.active_win
->page
->file
->lpszPath
);
223 p
= strrchr(szAddPath
, '\\');
228 * FIXME: Should we swap conditions?
230 if (!SearchPathA(NULL
, lpszFile
, ".hlp", MAX_PATH
, szFullName
, NULL
) &&
231 !SearchPathA(szAddPath
, lpszFile
, ".hlp", MAX_PATH
, szFullName
, NULL
))
233 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s
, lpszFile
, STID_WHERROR
,
234 MB_YESNO
|MB_ICONQUESTION
) != IDYES
)
236 if (!WINHELP_GetOpenFileName(szFullName
, MAX_PATH
))
239 hlpfile
= HLPFILE_ReadHlpFile(szFullName
);
241 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s
, lpszFile
,
242 STID_WHERROR
, MB_OK
|MB_ICONSTOP
);
246 /******************************************************************
247 * WINHELP_GetWindowInfo
251 HLPFILE_WINDOWINFO
* WINHELP_GetWindowInfo(HLPFILE
* hlpfile
, LPCSTR name
)
253 static HLPFILE_WINDOWINFO mwi
;
256 if (!name
|| !name
[0])
257 name
= Globals
.active_win
->info
->name
;
260 for (i
= 0; i
< hlpfile
->numWindows
; i
++)
261 if (!lstrcmpiA(hlpfile
->windows
[i
].name
, name
))
262 return &hlpfile
->windows
[i
];
264 if (strcmp(name
, "main") != 0)
266 WINE_FIXME("Couldn't find window info for %s\n", debugstr_a(name
));
272 strcpy(mwi
.type
, "primary");
273 strcpy(mwi
.name
, "main");
274 if (hlpfile
&& hlpfile
->lpszTitle
[0])
277 LoadStringA(Globals
.hInstance
, STID_WINE_HELP
, tmp
, sizeof(tmp
));
278 _snprintf(mwi
.caption
, sizeof(mwi
.caption
), "%s %s - %s",
279 hlpfile
->lpszTitle
, tmp
, hlpfile
->lpszPath
);
282 LoadStringA(Globals
.hInstance
, STID_WINE_HELP
, mwi
.caption
, sizeof(mwi
.caption
));
283 mwi
.origin
.x
= mwi
.origin
.y
= mwi
.size
.cx
= mwi
.size
.cy
= CW_USEDEFAULT
;
285 mwi
.win_style
= WS_OVERLAPPEDWINDOW
;
286 mwi
.sr_color
= mwi
.nsr_color
= 0xFFFFFF;
291 /******************************************************************
292 * HLPFILE_GetPopupWindowInfo
296 static HLPFILE_WINDOWINFO
* WINHELP_GetPopupWindowInfo(HLPFILE
* hlpfile
,
297 WINHELP_WINDOW
* parent
, LPARAM mouse
)
299 static HLPFILE_WINDOWINFO wi
;
303 wi
.type
[0] = wi
.name
[0] = wi
.caption
[0] = '\0';
305 /* Calculate horizontal size and position of a popup window */
306 GetWindowRect(parent
->hMainWnd
, &parent_rect
);
307 wi
.size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
308 wi
.size
.cy
= 10; /* need a non null value, so that borders are taken into account while computing */
310 wi
.origin
.x
= (short)LOWORD(mouse
);
311 wi
.origin
.y
= (short)HIWORD(mouse
);
312 ClientToScreen(parent
->hMainWnd
, &wi
.origin
);
313 wi
.origin
.x
-= wi
.size
.cx
/ 2;
314 wi
.origin
.x
= min(wi
.origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - wi
.size
.cx
);
315 wi
.origin
.x
= max(wi
.origin
.x
, 0);
318 wi
.win_style
= WS_POPUP
| WS_BORDER
;
319 if (parent
->page
->file
->has_popup_color
)
320 wi
.sr_color
= parent
->page
->file
->popup_color
;
322 wi
.sr_color
= parent
->info
->sr_color
;
323 wi
.nsr_color
= 0xFFFFFF;
336 } WINHELP
,*LPWINHELP
;
338 static BOOL
WINHELP_HasWorkingWindow(void)
340 if (!Globals
.active_win
) return FALSE
;
341 if (Globals
.active_win
->next
|| Globals
.win_list
!= Globals
.active_win
) return TRUE
;
342 return Globals
.active_win
->page
!= NULL
&& Globals
.active_win
->page
->file
!= NULL
;
345 /******************************************************************
346 * WINHELP_HandleCommand
350 static LRESULT
WINHELP_HandleCommand(HWND hSrcWnd
, LPARAM lParam
)
352 COPYDATASTRUCT
* cds
= (COPYDATASTRUCT
*)lParam
;
355 if (cds
->dwData
!= 0xA1DE505)
357 WINE_FIXME("Wrong magic number (%08Ix)\n", cds
->dwData
);
365 char* ptr
= (wh
->ofsFilename
) ? (LPSTR
)wh
+ wh
->ofsFilename
: NULL
;
367 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
368 wh
->size
, wh
->command
, wh
->data
, debugstr_a(ptr
));
374 MACRO_JumpContext(ptr
, "main", wh
->data
);
376 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
384 MACRO_JumpContents(ptr
, "main");
386 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
388 case HELP_HELPONHELP
:
390 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
392 /* case HELP_SETINDEX: */
393 case HELP_SETCONTENTS
:
396 MACRO_SetContents(ptr
, wh
->data
);
399 case HELP_CONTEXTPOPUP
:
402 MACRO_PopupContext(ptr
, wh
->data
);
405 /* case HELP_FORCEFILE:*/
406 /* case HELP_CONTEXTMENU: */
408 /* in fact, should be the topic dialog box */
409 WINE_FIXME("HELP_FINDER: stub\n");
412 MACRO_JumpHash(ptr
, "main", 0);
415 /* case HELP_WM_HELP: */
416 /* case HELP_SETPOPUP_POS: */
418 /* case HELP_COMMAND: */
419 /* case HELP_PARTIALKEY: */
420 /* case HELP_MULTIKEY: */
421 /* case HELP_SETWINPOS: */
423 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh
->command
);
427 /* Always return success for now */
431 void WINHELP_LayoutMainWindow(WINHELP_WINDOW
* win
)
433 RECT rect
, button_box_rect
;
435 HWND hButtonBoxWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_BUTTON
);
436 HWND hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
438 GetClientRect(win
->hMainWnd
, &rect
);
440 /* Update button box and text Window */
441 SetWindowPos(hButtonBoxWnd
, HWND_TOP
,
443 rect
.right
- rect
.left
,
444 rect
.bottom
- rect
.top
, 0);
446 if (GetWindowRect(hButtonBoxWnd
, &button_box_rect
))
447 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
449 SetWindowPos(hTextWnd
, HWND_TOP
,
451 rect
.right
- rect
.left
,
452 rect
.bottom
- text_top
, 0);
456 /******************************************************************
457 * WINHELP_DeleteButtons
460 static void WINHELP_DeleteButtons(WINHELP_WINDOW
* win
)
465 for (b
= win
->first_button
; b
; b
= bp
)
467 DestroyWindow(b
->hWnd
);
471 win
->first_button
= NULL
;
474 /******************************************************************
475 * WINHELP_DeleteBackSet
478 void WINHELP_DeleteBackSet(WINHELP_WINDOW
* win
)
482 for (i
= 0; i
< win
->back
.index
; i
++)
484 HLPFILE_FreeHlpFile(win
->back
.set
[i
].page
->file
);
485 win
->back
.set
[i
].page
= NULL
;
490 /******************************************************************
491 * WINHELP_DeletePageLinks
494 static void WINHELP_DeletePageLinks(HLPFILE_PAGE
* page
)
499 for (curr
= page
->first_link
; curr
; curr
= next
)
506 /***********************************************************************
510 WINHELP_WINDOW
* WINHELP_GrabWindow(WINHELP_WINDOW
* win
)
512 WINE_TRACE("Grab %p#%d++\n", win
, win
->ref_count
);
517 /***********************************************************************
519 * WINHELP_ReleaseWindow
521 BOOL
WINHELP_ReleaseWindow(WINHELP_WINDOW
* win
)
523 WINE_TRACE("Release %p#%d--\n", win
, win
->ref_count
);
525 if (!--win
->ref_count
)
527 DestroyWindow(win
->hMainWnd
);
533 /***********************************************************************
535 * WINHELP_DeleteWindow
537 static void WINHELP_DeleteWindow(WINHELP_WINDOW
* win
)
543 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
551 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpiA(win
->info
->name
, "main"));
553 if (Globals
.active_win
== win
)
555 Globals
.active_win
= Globals
.win_list
;
556 if (Globals
.win_list
)
557 SetActiveWindow(Globals
.win_list
->hMainWnd
);
560 if (win
== Globals
.active_popup
)
561 Globals
.active_popup
= NULL
;
563 hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
564 SetWindowLongPtrA(hTextWnd
, GWLP_WNDPROC
, (LONG_PTR
)win
->origRicheditWndProc
);
566 WINHELP_DeleteButtons(win
);
568 if (win
->page
) WINHELP_DeletePageLinks(win
->page
);
569 if (win
->hHistoryWnd
) DestroyWindow(win
->hHistoryWnd
);
571 DeleteObject(win
->hBrush
);
573 WINHELP_DeleteBackSet(win
);
575 if (win
->page
) HLPFILE_FreeHlpFile(win
->page
->file
);
578 if (bExit
) MACRO_Exit();
579 if (!Globals
.win_list
)
583 static char* WINHELP_GetCaption(WINHELP_WNDPAGE
* wpage
)
585 if (wpage
->wininfo
->caption
[0]) return wpage
->wininfo
->caption
;
586 return wpage
->page
->file
->lpszTitle
;
589 static void WINHELP_RememberPage(WINHELP_WINDOW
* win
, WINHELP_WNDPAGE
* wpage
)
593 if (!Globals
.history
.index
|| Globals
.history
.set
[0].page
!= wpage
->page
)
595 num
= ARRAY_SIZE(Globals
.history
.set
);
596 /* we're full, remove latest entry */
597 if (Globals
.history
.index
== num
)
599 HLPFILE_FreeHlpFile(Globals
.history
.set
[num
- 1].page
->file
);
600 Globals
.history
.index
--;
602 memmove(&Globals
.history
.set
[1], &Globals
.history
.set
[0],
603 Globals
.history
.index
* sizeof(Globals
.history
.set
[0]));
604 Globals
.history
.set
[0] = *wpage
;
605 Globals
.history
.index
++;
606 wpage
->page
->file
->wRefCount
++;
608 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
610 num
= ARRAY_SIZE(win
->back
.set
);
611 if (win
->back
.index
== num
)
613 /* we're full, remove latest entry */
614 HLPFILE_FreeHlpFile(win
->back
.set
[0].page
->file
);
615 memmove(&win
->back
.set
[0], &win
->back
.set
[1],
616 (num
- 1) * sizeof(win
->back
.set
[0]));
619 win
->back
.set
[win
->back
.index
++] = *wpage
;
620 wpage
->page
->file
->wRefCount
++;
623 /***********************************************************************
627 static HLPFILE_LINK
* WINHELP_FindLink(WINHELP_WINDOW
* win
, LPARAM pos
)
630 POINTL mouse_ptl
, char_ptl
, char_next_ptl
;
633 if (!win
->page
) return NULL
;
635 mouse_ptl
.x
= (short)LOWORD(pos
);
636 mouse_ptl
.y
= (short)HIWORD(pos
);
637 cp
= SendMessageW(GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
), EM_CHARFROMPOS
,
638 0, (LPARAM
)&mouse_ptl
);
640 for (link
= win
->page
->first_link
; link
; link
= link
->next
)
642 if (link
->cpMin
<= cp
&& cp
<= link
->cpMax
)
644 /* check whether we're at end of line */
645 SendMessageW(GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
), EM_POSFROMCHAR
,
646 (LPARAM
)&char_ptl
, cp
);
647 SendMessageW(GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
), EM_POSFROMCHAR
,
648 (LPARAM
)&char_next_ptl
, cp
+ 1);
651 HLPFILE_HOTSPOTLINK
* hslink
= (HLPFILE_HOTSPOTLINK
*)link
;
652 if ((mouse_ptl
.x
< char_ptl
.x
+ hslink
->x
) ||
653 (mouse_ptl
.x
>= char_ptl
.x
+ hslink
->x
+ hslink
->width
) ||
654 (mouse_ptl
.y
< char_ptl
.y
+ hslink
->y
) ||
655 (mouse_ptl
.y
>= char_ptl
.y
+ hslink
->y
+ hslink
->height
))
659 if (char_next_ptl
.y
!= char_ptl
.y
|| mouse_ptl
.x
>= char_next_ptl
.x
)
667 static LRESULT CALLBACK
WINHELP_RicheditWndProc(HWND hWnd
, UINT msg
,
668 WPARAM wParam
, LPARAM lParam
)
670 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(GetParent(hWnd
), 0);
676 messagePos
= GetMessagePos();
677 pt
.x
= (short)LOWORD(messagePos
);
678 pt
.y
= (short)HIWORD(messagePos
);
679 ScreenToClient(hWnd
, &pt
);
680 if (win
->page
&& WINHELP_FindLink(win
, MAKELPARAM(pt
.x
, pt
.y
)))
682 SetCursor(win
->hHandCur
);
687 return CallWindowProcA(win
->origRicheditWndProc
, hWnd
, msg
, wParam
, lParam
);
691 /***********************************************************************
693 * WINHELP_CreateHelpWindow
695 BOOL
WINHELP_CreateHelpWindow(WINHELP_WNDPAGE
* wpage
, int nCmdShow
, BOOL remember
)
697 WINHELP_WINDOW
* win
= NULL
;
698 BOOL bPrimary
, bPopup
, bReUsed
= FALSE
;
700 HWND hTextWnd
= NULL
;
702 bPrimary
= !lstrcmpiA(wpage
->wininfo
->name
, "main");
703 bPopup
= !bPrimary
&& (wpage
->wininfo
->win_style
& WS_POPUP
);
707 for (win
= Globals
.win_list
; win
; win
= win
->next
)
709 if (!lstrcmpiA(win
->info
->name
, wpage
->wininfo
->name
))
711 if (win
->page
== wpage
->page
&& win
->info
== wpage
->wininfo
)
713 /* see #22979, some hlp files have a macro (run at page opening), which
714 * jumps to the very same page
715 * Exit gracefully in that case
719 WINHELP_DeleteButtons(win
);
721 SetWindowTextA(win
->hMainWnd
, WINHELP_GetCaption(wpage
));
722 if (win
->info
!= wpage
->wininfo
)
726 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
;
728 if (wpage
->wininfo
->origin
.x
!= CW_USEDEFAULT
&&
729 wpage
->wininfo
->origin
.y
!= CW_USEDEFAULT
)
731 pt
= wpage
->wininfo
->origin
;
732 flags
&= ~SWP_NOSIZE
;
734 if (wpage
->wininfo
->size
.cx
!= CW_USEDEFAULT
&&
735 wpage
->wininfo
->size
.cy
!= CW_USEDEFAULT
)
737 sz
= wpage
->wininfo
->size
;
738 flags
&= ~SWP_NOMOVE
;
740 SetWindowPos(win
->hMainWnd
, HWND_TOP
, pt
.x
, pt
.y
, sz
.cx
, sz
.cy
, flags
);
743 if (wpage
->page
&& win
->page
&& wpage
->page
->file
!= win
->page
->file
)
744 WINHELP_DeleteBackSet(win
);
745 WINHELP_InitFonts(win
->hMainWnd
);
747 win
->page
= wpage
->page
;
748 win
->info
= wpage
->wininfo
;
749 hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
750 WINHELP_SetupText(hTextWnd
, win
, wpage
->relative
);
752 InvalidateRect(win
->hMainWnd
, NULL
, TRUE
);
753 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
762 /* Initialize WINHELP_WINDOW struct */
763 win
= calloc(1, sizeof(WINHELP_WINDOW
));
764 if (!win
) return FALSE
;
765 win
->next
= Globals
.win_list
;
766 Globals
.win_list
= win
;
768 win
->hHandCur
= LoadCursorW(0, (LPWSTR
)IDC_HAND
);
771 WINHELP_GrabWindow(win
);
773 win
->page
= wpage
->page
;
774 win
->info
= wpage
->wininfo
;
775 WINHELP_GrabWindow(win
);
777 if (!bPopup
&& wpage
->page
&& remember
)
779 WINHELP_RememberPage(win
, wpage
);
783 Globals
.active_popup
= win
;
785 Globals
.active_win
= win
;
787 /* Initialize default pushbuttons */
788 if (bPrimary
&& wpage
->page
)
790 CHAR buffer
[MAX_STRING_LEN
];
792 LoadStringA(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
793 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
794 LoadStringA(Globals
.hInstance
, STID_INDEX
, buffer
, sizeof(buffer
));
795 MACRO_CreateButton("BTN_INDEX", buffer
, "Finder()");
796 LoadStringA(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
797 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
798 if (win
->back
.index
<= 1) MACRO_DisableButton("BTN_BACK");
803 win
->hMainWnd
= CreateWindowExA((bPopup
) ? WS_EX_TOOLWINDOW
: 0, MAIN_WIN_CLASS_NAME
,
804 WINHELP_GetCaption(wpage
),
805 bPrimary
? WS_OVERLAPPEDWINDOW
: wpage
->wininfo
->win_style
,
806 wpage
->wininfo
->origin
.x
, wpage
->wininfo
->origin
.y
,
807 wpage
->wininfo
->size
.cx
, wpage
->wininfo
->size
.cy
,
808 bPopup
? Globals
.active_win
->hMainWnd
: NULL
,
809 bPrimary
? LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(MAIN_MENU
)) : 0,
810 Globals
.hInstance
, win
);
812 /* Create button box and text Window */
813 CreateWindowA(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
814 0, 0, 0, 0, win
->hMainWnd
, (HMENU
)CTL_ID_BUTTON
, Globals
.hInstance
, NULL
);
816 hTextWnd
= CreateWindowA(RICHEDIT_CLASS20A
, NULL
,
817 ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
,
818 0, 0, 0, 0, win
->hMainWnd
, (HMENU
)CTL_ID_TEXT
, Globals
.hInstance
, NULL
);
819 SendMessageW(hTextWnd
, EM_SETEVENTMASK
, 0,
820 SendMessageW(hTextWnd
, EM_GETEVENTMASK
, 0, 0) | ENM_MOUSEEVENTS
);
821 win
->origRicheditWndProc
= (WNDPROC
)SetWindowLongPtrA(hTextWnd
, GWLP_WNDPROC
,
822 (LONG_PTR
)WINHELP_RicheditWndProc
);
825 hIcon
= (wpage
->page
) ? wpage
->page
->file
->hIcon
: NULL
;
826 if (!hIcon
) hIcon
= LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINHELP
), IMAGE_ICON
,
827 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
828 SendMessageW(win
->hMainWnd
, WM_SETICON
, ICON_SMALL
, (DWORD_PTR
)hIcon
);
830 /* Initialize file specific pushbuttons */
831 if (!(wpage
->wininfo
->win_style
& WS_POPUP
) && wpage
->page
)
833 HLPFILE_MACRO
*macro
;
834 for (macro
= wpage
->page
->file
->first_macro
; macro
; macro
= macro
->next
)
835 MACRO_ExecuteMacro(win
, macro
->lpszMacro
);
837 for (macro
= wpage
->page
->first_macro
; macro
; macro
= macro
->next
)
838 MACRO_ExecuteMacro(win
, macro
->lpszMacro
);
840 /* See #17681, in some cases, the newly created window is closed by the macros it contains
841 * (braindead), so deal with this case
843 for (win
= Globals
.win_list
; win
; win
= win
->next
)
845 if (!lstrcmpiA(win
->info
->name
, wpage
->wininfo
->name
)) break;
847 if (!win
|| !WINHELP_ReleaseWindow(win
)) return TRUE
;
851 DWORD mask
= SendMessageW(hTextWnd
, EM_GETEVENTMASK
, 0, 0);
853 win
->font_scale
= Globals
.active_win
->font_scale
;
854 WINHELP_SetupText(hTextWnd
, win
, wpage
->relative
);
856 /* we need the window to be shown for richedit to compute the size */
857 ShowWindow(win
->hMainWnd
, nCmdShow
);
858 SendMessageW(hTextWnd
, EM_SETEVENTMASK
, 0, mask
| ENM_REQUESTRESIZE
);
859 SendMessageW(hTextWnd
, EM_REQUESTRESIZE
, 0, 0);
860 SendMessageW(hTextWnd
, EM_SETEVENTMASK
, 0, mask
);
864 WINHELP_SetupText(hTextWnd
, win
, wpage
->relative
);
865 WINHELP_LayoutMainWindow(win
);
866 ShowWindow(win
->hMainWnd
, nCmdShow
);
872 /******************************************************************
873 * WINHELP_OpenHelpWindow
874 * Main function to search for a page and display it in a window
876 BOOL
WINHELP_OpenHelpWindow(HLPFILE_PAGE
* (*lookup
)(HLPFILE
*, LONG
, ULONG
*),
877 HLPFILE
* hlpfile
, LONG val
, HLPFILE_WINDOWINFO
* wi
,
880 WINHELP_WNDPAGE wpage
;
882 wpage
.page
= lookup(hlpfile
, val
, &wpage
.relative
);
883 if (wpage
.page
) wpage
.page
->file
->wRefCount
++;
885 return WINHELP_CreateHelpWindow(&wpage
, nCmdShow
, TRUE
);
888 /******************************************************************
889 * WINHELP_HandleTextMouse
892 static BOOL
WINHELP_HandleTextMouse(WINHELP_WINDOW
* win
, UINT msg
, LPARAM lParam
)
901 if ((link
= WINHELP_FindLink(win
, lParam
)))
903 HLPFILE_WINDOWINFO
* wi
;
905 switch (link
->cookie
)
908 if ((hlpfile
= WINHELP_LookupHelpFile(link
->string
)))
910 if (link
->window
== -1)
913 if (wi
->win_style
& WS_POPUP
) wi
= Globals
.active_win
->info
;
915 else if (link
->window
< hlpfile
->numWindows
)
916 wi
= &hlpfile
->windows
[link
->window
];
919 WINE_WARN("link to window %d/%d\n", link
->window
, hlpfile
->numWindows
);
922 WINHELP_OpenHelpWindow(HLPFILE_PageByHash
, hlpfile
, link
->hash
, wi
, SW_NORMAL
);
926 if ((hlpfile
= WINHELP_LookupHelpFile(link
->string
)))
927 WINHELP_OpenHelpWindow(HLPFILE_PageByHash
, hlpfile
, link
->hash
,
928 WINHELP_GetPopupWindowInfo(hlpfile
, win
, lParam
),
932 MACRO_ExecuteMacro(win
, link
->string
);
935 WINE_FIXME("Unknown link cookie %d\n", link
->cookie
);
944 /***********************************************************************
948 static BOOL
WINHELP_CheckPopup(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* lret
)
950 WINHELP_WINDOW
* popup
;
952 if (!Globals
.active_popup
) return FALSE
;
958 MSGFILTER
* msgf
= (MSGFILTER
*)lParam
;
959 if (msgf
->nmhdr
.code
== EN_MSGFILTER
)
961 if (!WINHELP_CheckPopup(hWnd
, msgf
->msg
, msgf
->wParam
, msgf
->lParam
, NULL
))
969 if (LOWORD(wParam
) != WA_INACTIVE
|| (HWND
)lParam
== Globals
.active_win
->hMainWnd
||
970 (HWND
)lParam
== Globals
.active_popup
->hMainWnd
||
971 GetWindow((HWND
)lParam
, GW_OWNER
) == Globals
.active_win
->hMainWnd
)
975 if (msg
== WM_LBUTTONDOWN
)
976 WINHELP_HandleTextMouse(Globals
.active_popup
, msg
, lParam
);
980 case WM_NCLBUTTONDOWN
:
981 case WM_NCMBUTTONDOWN
:
982 case WM_NCRBUTTONDOWN
:
983 popup
= Globals
.active_popup
;
984 Globals
.active_popup
= NULL
;
985 WINHELP_ReleaseWindow(popup
);
992 /***********************************************************************
994 * WINHELP_ButtonWndProc
996 static LRESULT CALLBACK
WINHELP_ButtonWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
998 if (WINHELP_CheckPopup(hWnd
, msg
, wParam
, lParam
, NULL
)) return 0;
1000 if (msg
== WM_KEYDOWN
)
1009 return SendMessageA(GetParent(hWnd
), msg
, wParam
, lParam
);
1013 return CallWindowProcA(Globals
.button_proc
, hWnd
, msg
, wParam
, lParam
);
1016 /***********************************************************************
1018 * WINHELP_ButtonBoxWndProc
1020 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1023 WINHELP_WINDOW
*win
;
1024 WINHELP_BUTTON
*button
;
1028 if (WINHELP_CheckPopup(hWnd
, msg
, wParam
, lParam
, NULL
)) return 0L;
1032 case WM_WINDOWPOSCHANGING
:
1033 winpos
= (WINDOWPOS
*) lParam
;
1034 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(GetParent(hWnd
), 0);
1036 /* Update buttons */
1039 for (button
= win
->first_button
; button
; button
= button
->next
)
1045 button
->hWnd
= CreateWindowA(STRING_BUTTON
, button
->lpszName
,
1046 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
1048 hWnd
, (HMENU
) button
->wParam
,
1049 Globals
.hInstance
, 0);
1052 if (Globals
.button_proc
== NULL
)
1054 NONCLIENTMETRICSW ncm
;
1055 Globals
.button_proc
= (WNDPROC
) GetWindowLongPtrA(button
->hWnd
, GWLP_WNDPROC
);
1057 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
1058 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
1059 sizeof(NONCLIENTMETRICSW
), &ncm
, 0);
1060 Globals
.hButtonFont
= CreateFontIndirectW(&ncm
.lfMenuFont
);
1062 SetWindowLongPtrA(button
->hWnd
, GWLP_WNDPROC
, (LONG_PTR
) WINHELP_ButtonWndProc
);
1063 if (Globals
.hButtonFont
)
1064 SendMessageW(button
->hWnd
, WM_SETFONT
, (WPARAM
)Globals
.hButtonFont
, TRUE
);
1067 hDc
= GetDC(button
->hWnd
);
1068 GetTextExtentPointA(hDc
, button
->lpszName
, strlen(button
->lpszName
), &textsize
);
1069 ReleaseDC(button
->hWnd
, hDc
);
1071 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
1072 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
1077 for (button
= win
->first_button
; button
; button
= button
->next
)
1079 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
1081 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
1082 x
+= button_size
.cx
;
1084 x
= 0, y
+= button_size
.cy
;
1086 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
1090 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1101 return SendMessageA(GetParent(hWnd
), msg
, wParam
, lParam
);
1106 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1109 /******************************************************************
1110 * WINHELP_HistoryWndProc
1114 static LRESULT CALLBACK
WINHELP_HistoryWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1116 WINHELP_WINDOW
* win
;
1126 win
= (WINHELP_WINDOW
*)((LPCREATESTRUCTA
)lParam
)->lpCreateParams
;
1127 SetWindowLongPtrW(hWnd
, 0, (ULONG_PTR
)win
);
1128 win
->hHistoryWnd
= hWnd
;
1132 GetTextMetricsW(hDc
, &tm
);
1133 GetWindowRect(hWnd
, &r
);
1135 r
.right
= r
.left
+ 30 * tm
.tmAveCharWidth
;
1136 r
.bottom
= r
.top
+ ARRAY_SIZE(Globals
.history
.set
) * tm
.tmHeight
;
1137 AdjustWindowRect(&r
, GetWindowLongW(hWnd
, GWL_STYLE
), FALSE
);
1138 if (r
.left
< 0) {r
.right
-= r
.left
; r
.left
= 0;}
1139 if (r
.top
< 0) {r
.bottom
-= r
.top
; r
.top
= 0;}
1141 MoveWindow(hWnd
, r
.left
, r
.top
, r
.right
, r
.bottom
, TRUE
);
1142 ReleaseDC(hWnd
, hDc
);
1144 case WM_LBUTTONDOWN
:
1146 GetTextMetricsW(hDc
, &tm
);
1147 i
= HIWORD(lParam
) / tm
.tmHeight
;
1148 if (i
< Globals
.history
.index
)
1149 WINHELP_CreateHelpWindow(&Globals
.history
.set
[i
], SW_SHOW
, TRUE
);
1150 ReleaseDC(hWnd
, hDc
);
1153 hDc
= BeginPaint(hWnd
, &ps
);
1154 GetTextMetricsW(hDc
, &tm
);
1156 for (i
= 0; i
< Globals
.history
.index
; i
++)
1158 if (Globals
.history
.set
[i
].page
->file
== Globals
.active_win
->page
->file
)
1160 TextOutA(hDc
, 0, i
* tm
.tmHeight
,
1161 Globals
.history
.set
[i
].page
->lpszTitle
,
1162 strlen(Globals
.history
.set
[i
].page
->lpszTitle
));
1171 ptr1
= strrchr(Globals
.history
.set
[i
].page
->file
->lpszPath
, '\\');
1172 if (!ptr1
) ptr1
= Globals
.history
.set
[i
].page
->file
->lpszPath
;
1174 ptr2
= strrchr(ptr1
, '.');
1175 len
= ptr2
? ptr2
- ptr1
: strlen(ptr1
);
1176 if (len
> sizeof(buffer
)) len
= sizeof(buffer
);
1177 memcpy(buffer
, ptr1
, len
);
1178 if (len
< sizeof(buffer
)) buffer
[len
++] = ':';
1179 lstrcpynA(&buffer
[len
], Globals
.history
.set
[i
].page
->lpszTitle
, sizeof(buffer
) - len
);
1180 TextOutA(hDc
, 0, i
* tm
.tmHeight
, buffer
, strlen(buffer
));
1183 EndPaint(hWnd
, &ps
);
1186 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1187 if (hWnd
== win
->hHistoryWnd
)
1188 win
->hHistoryWnd
= 0;
1191 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1194 /**************************************************************************
1197 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1200 static void cb_KWBTree(void *p
, void **next
, void *cookie
)
1202 HWND hListWnd
= cookie
;
1205 WINE_TRACE("Adding %s to search list\n", debugstr_a((char *)p
));
1206 SendMessageA(hListWnd
, LB_INSERTSTRING
, -1, (LPARAM
)p
);
1207 count
= SendMessageW(hListWnd
, LB_GETCOUNT
, 0, 0);
1208 SendMessageW(hListWnd
, LB_SETITEMDATA
, count
-1, (LPARAM
)p
);
1209 *next
= (char*)p
+ strlen((char*)p
) + 7;
1219 /**************************************************************************
1220 * WINHELP_IndexDlgProc
1223 static INT_PTR CALLBACK
WINHELP_IndexDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1225 static struct index_data
* id
;
1231 id
= (struct index_data
*)((PROPSHEETPAGEA
*)lParam
)->lParam
;
1232 HLPFILE_BPTreeEnum(id
->hlpfile
->kwbtree
, cb_KWBTree
,
1233 GetDlgItem(hWnd
, IDC_INDEXLIST
));
1238 switch (HIWORD(wParam
))
1241 if (LOWORD(wParam
) == IDC_INDEXLIST
)
1242 SendMessageW(GetParent(hWnd
), PSM_PRESSBUTTON
, PSBTN_OK
, 0);
1247 switch (((NMHDR
*)lParam
)->code
)
1250 sel
= SendDlgItemMessageW(hWnd
, IDC_INDEXLIST
, LB_GETCURSEL
, 0, 0);
1256 p
= (BYTE
*)SendDlgItemMessageW(hWnd
, IDC_INDEXLIST
, LB_GETITEMDATA
, sel
, 0);
1257 count
= *(short*)((char *)p
+ strlen((char *)p
) + 1);
1260 MessageBoxA(hWnd
, "count > 1 not supported yet", "Error", MB_OK
| MB_ICONSTOP
);
1261 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_INVALID
);
1264 id
->offset
= *(ULONG
*)((char *)p
+ strlen((char *)p
) + 3);
1265 id
->offset
= *(long*)(id
->hlpfile
->kwdata
+ id
->offset
+ 9);
1266 if (id
->offset
== 0xFFFFFFFF)
1268 MessageBoxA(hWnd
, "macro keywords not supported yet", "Error", MB_OK
| MB_ICONSTOP
);
1269 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_INVALID
);
1273 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
1286 /**************************************************************************
1287 * WINHELP_SearchDlgProc
1290 static INT_PTR CALLBACK
WINHELP_SearchDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1297 switch (((NMHDR
*)lParam
)->code
)
1300 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
1312 /***********************************************************************
1314 * WINHELP_MainWndProc
1316 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1318 WINHELP_WINDOW
*win
;
1319 WINHELP_BUTTON
*button
;
1323 if (WINHELP_CheckPopup(hWnd
, msg
, wParam
, lParam
, &ret
)) return ret
;
1328 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCTA
) lParam
)->lpCreateParams
;
1329 SetWindowLongPtrW(hWnd
, 0, (ULONG_PTR
) win
);
1330 if (!win
->page
&& Globals
.isBook
)
1331 PostMessageW(hWnd
, WM_COMMAND
, MNID_FILE_OPEN
, 0);
1332 win
->hMainWnd
= hWnd
;
1335 case WM_WINDOWPOSCHANGED
:
1336 WINHELP_LayoutMainWindow((WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0));
1340 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1341 switch (LOWORD(wParam
))
1344 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
1345 case MNID_FILE_PRINT
: MACRO_Print(); break;
1346 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
1347 case MNID_FILE_EXIT
: MACRO_Exit(); break;
1350 case MNID_EDIT_COPYDLG
:
1351 SendDlgItemMessageW(hWnd
, CTL_ID_TEXT
, WM_COPY
, 0, 0);
1353 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
1356 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
1359 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
1360 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
1361 case MNID_HELP_ABOUT
: MACRO_About(); break;
1364 case MNID_CTXT_ANNOTATE
:MACRO_Annotate(); break;
1365 case MNID_CTXT_COPY
: MACRO_CopyDialog(); break;
1366 case MNID_CTXT_PRINT
: MACRO_Print(); break;
1367 case MNID_OPTS_HISTORY
: MACRO_History(); break;
1368 case MNID_OPTS_FONTS_SMALL
:
1369 case MNID_CTXT_FONTS_SMALL
:
1370 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1371 if (win
->font_scale
!= 0)
1373 win
->font_scale
= 0;
1374 WINHELP_SetupText(GetDlgItem(hWnd
, CTL_ID_TEXT
), win
, 0 /* FIXME */);
1377 case MNID_OPTS_FONTS_NORMAL
:
1378 case MNID_CTXT_FONTS_NORMAL
:
1379 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1380 if (win
->font_scale
!= 1)
1382 win
->font_scale
= 1;
1383 WINHELP_SetupText(GetDlgItem(hWnd
, CTL_ID_TEXT
), win
, 0 /* FIXME */);
1386 case MNID_OPTS_FONTS_LARGE
:
1387 case MNID_CTXT_FONTS_LARGE
:
1388 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1389 if (win
->font_scale
!= 2)
1391 win
->font_scale
= 2;
1392 WINHELP_SetupText(GetDlgItem(hWnd
, CTL_ID_TEXT
), win
, 0 /* FIXME */);
1398 for (button
= win
->first_button
; button
; button
= button
->next
)
1399 if (wParam
== button
->wParam
) break;
1401 MACRO_ExecuteMacro(win
, button
->lpszMacro
);
1402 else if (!HIWORD(wParam
))
1403 MessageBoxW(0, MAKEINTRESOURCEW(STID_NOT_IMPLEMENTED
),
1404 MAKEINTRESOURCEW(STID_WHERROR
), MB_OK
);
1408 /* EPP case WM_DESTROY: */
1409 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
1412 return WINHELP_HandleCommand((HWND
)wParam
, lParam
);
1417 SendDlgItemMessageW(hWnd
, CTL_ID_TEXT
, WM_COPY
, 0, 0);
1423 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1424 hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
1429 SendMessageW(hTextWnd
, EM_SCROLL
, SB_LINEUP
, 0);
1432 SendMessageW(hTextWnd
, EM_SCROLL
, SB_LINEDOWN
, 0);
1435 SendMessageW(hTextWnd
, EM_SCROLL
, SB_PAGEUP
, 0);
1438 SendMessageW(hTextWnd
, EM_SCROLL
, SB_PAGEDOWN
, 0);
1447 if (wParam
== CTL_ID_TEXT
)
1451 switch (((NMHDR
*)lParam
)->code
)
1455 const MSGFILTER
* msgf
= (const MSGFILTER
*)lParam
;
1459 if (msgf
->wParam
== VK_ESCAPE
)
1460 WINHELP_ReleaseWindow((WINHELP_WINDOW
*)GetWindowLongPtrW(hWnd
, 0));
1462 case WM_RBUTTONDOWN
:
1467 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1468 hMenu
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(CONTEXT_MENU
));
1469 switch (win
->font_scale
)
1472 CheckMenuItem(hMenu
, MNID_CTXT_FONTS_SMALL
,
1473 MF_BYCOMMAND
|MF_CHECKED
);
1476 WINE_FIXME("Unsupported %d\n", win
->font_scale
);
1479 CheckMenuItem(hMenu
, MNID_CTXT_FONTS_NORMAL
,
1480 MF_BYCOMMAND
|MF_CHECKED
);
1483 CheckMenuItem(hMenu
, MNID_CTXT_FONTS_LARGE
,
1484 MF_BYCOMMAND
|MF_CHECKED
);
1487 pt
.x
= (int)(short)LOWORD(msgf
->lParam
);
1488 pt
.y
= (int)(short)HIWORD(msgf
->lParam
);
1489 ClientToScreen(msgf
->nmhdr
.hwndFrom
, &pt
);
1490 TrackPopupMenu(GetSubMenu(hMenu
, 0), TPM_LEFTALIGN
|TPM_TOPALIGN
,
1491 pt
.x
, pt
.y
, 0, hWnd
, NULL
);
1496 return WINHELP_HandleTextMouse((WINHELP_WINDOW
*)GetWindowLongPtrW(hWnd
, 0),
1497 msgf
->msg
, msgf
->lParam
);
1502 case EN_REQUESTRESIZE
:
1503 rc
= ((REQRESIZE
*)lParam
)->rc
;
1504 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1505 AdjustWindowRect(&rc
, GetWindowLongW(win
->hMainWnd
, GWL_STYLE
),
1507 SetWindowPos(win
->hMainWnd
, HWND_TOP
, 0, 0,
1508 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1509 SWP_NOMOVE
| SWP_NOZORDER
);
1510 WINHELP_LayoutMainWindow(win
);
1516 case WM_INITMENUPOPUP
:
1517 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1518 CheckMenuItem((HMENU
)wParam
, MNID_OPTS_FONTS_SMALL
,
1519 (win
->font_scale
== 0) ? MF_CHECKED
: MF_UNCHECKED
);
1520 CheckMenuItem((HMENU
)wParam
, MNID_OPTS_FONTS_NORMAL
,
1521 (win
->font_scale
== 1) ? MF_CHECKED
: MF_UNCHECKED
);
1522 CheckMenuItem((HMENU
)wParam
, MNID_OPTS_FONTS_LARGE
,
1523 (win
->font_scale
== 2) ? MF_CHECKED
: MF_UNCHECKED
);
1526 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1527 WINHELP_DeleteWindow(win
);
1530 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1533 /**************************************************************************
1534 * WINHELP_CreateIndexWindow
1536 * Displays a dialog with keywords of current help file.
1539 BOOL
WINHELP_CreateIndexWindow(BOOL is_search
)
1541 HPROPSHEETPAGE psPage
[3];
1543 PROPSHEETHEADERA psHead
;
1544 struct index_data id
;
1547 if (Globals
.active_win
&& Globals
.active_win
->page
&& Globals
.active_win
->page
->file
)
1548 id
.hlpfile
= Globals
.active_win
->page
->file
;
1552 if (id
.hlpfile
->kwbtree
== NULL
)
1554 WINE_TRACE("No index provided\n");
1558 InitCommonControls();
1561 memset(&psp
, 0, sizeof(psp
));
1562 psp
.dwSize
= sizeof(psp
);
1564 psp
.hInstance
= Globals
.hInstance
;
1566 psp
.pszTemplate
= MAKEINTRESOURCEA(IDD_INDEX
);
1567 psp
.lParam
= (LPARAM
)&id
;
1568 psp
.pfnDlgProc
= WINHELP_IndexDlgProc
;
1569 psPage
[0] = CreatePropertySheetPageA(&psp
);
1571 psp
.pszTemplate
= MAKEINTRESOURCEA(IDD_SEARCH
);
1572 psp
.lParam
= (LPARAM
)&id
;
1573 psp
.pfnDlgProc
= WINHELP_SearchDlgProc
;
1574 psPage
[1] = CreatePropertySheetPageA(&psp
);
1576 memset(&psHead
, 0, sizeof(psHead
));
1577 psHead
.dwSize
= sizeof(psHead
);
1579 LoadStringA(Globals
.hInstance
, STID_PSH_INDEX
, buf
, sizeof(buf
));
1580 strcat(buf
, Globals
.active_win
->info
->caption
);
1582 psHead
.pszCaption
= buf
;
1584 psHead
.nStartPage
= is_search
? 1 : 0;
1585 psHead
.hwndParent
= Globals
.active_win
->hMainWnd
;
1586 psHead
.phpage
= psPage
;
1587 psHead
.dwFlags
= PSH_NOAPPLYNOW
;
1589 PropertySheetA(&psHead
);
1592 WINE_TRACE("got %ld as an offset\n", id
.offset
);
1593 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset
, id
.hlpfile
, id
.offset
,
1594 Globals
.active_win
->info
, SW_NORMAL
);
1599 /***********************************************************************
1601 * RegisterWinClasses
1603 static BOOL
WINHELP_RegisterWinClasses(void)
1605 WNDCLASSEXA class_main
, class_button_box
, class_history
;
1607 class_main
.cbSize
= sizeof(class_main
);
1608 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
1609 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
1610 class_main
.cbClsExtra
= 0;
1611 class_main
.cbWndExtra
= sizeof(WINHELP_WINDOW
*);
1612 class_main
.hInstance
= Globals
.hInstance
;
1613 class_main
.hIcon
= LoadIconW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINHELP
));
1614 class_main
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1615 class_main
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1616 class_main
.lpszMenuName
= 0;
1617 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
1618 class_main
.hIconSm
= LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINHELP
), IMAGE_ICON
,
1619 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
1622 class_button_box
= class_main
;
1623 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
1624 class_button_box
.cbWndExtra
= 0;
1625 class_button_box
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1626 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
1628 class_history
= class_main
;
1629 class_history
.lpfnWndProc
= WINHELP_HistoryWndProc
;
1630 class_history
.lpszClassName
= HISTORY_WIN_CLASS_NAME
;
1632 return (RegisterClassExA(&class_main
) &&
1633 RegisterClassExA(&class_button_box
) &&
1634 RegisterClassExA(&class_history
));
1637 /***********************************************************************
1641 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
1646 static CHAR default_wndname
[] = "main";
1647 LPSTR wndname
= default_wndname
;
1651 Globals
.hInstance
= hInstance
;
1653 if (LoadLibraryA("riched20.dll") == NULL
)
1654 return MessageBoxW(0, MAKEINTRESOURCEW(STID_NO_RICHEDIT
),
1655 MAKEINTRESOURCEW(STID_WHERROR
), MB_OK
);
1658 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
1662 if (*cmdline
++ == ' ') continue;
1665 if (option
) cmdline
++;
1666 while (*cmdline
== ' ') cmdline
++;
1672 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
1673 if (*cmdline
) *cmdline
++ = '\0';
1674 lHash
= HLPFILE_Hash(topic_id
);
1679 Globals
.wVersion
= option
- '0';
1684 Globals
.isBook
= FALSE
;
1688 WINE_FIXME("Unsupported cmd line: %s\n", debugstr_a(cmdline
));
1693 /* Create primary window */
1694 if (!WINHELP_RegisterWinClasses())
1696 WINE_FIXME("Couldn't register classes\n");
1703 if ((*cmdline
== '"') && (ptr
= strchr(cmdline
+1, '"')))
1708 if ((ptr
= strchr(cmdline
, '>')))
1713 hlpfile
= WINHELP_LookupHelpFile(cmdline
);
1714 if (!hlpfile
) return 0;
1716 else hlpfile
= NULL
;
1717 WINHELP_OpenHelpWindow(HLPFILE_PageByHash
, hlpfile
, lHash
,
1718 WINHELP_GetWindowInfo(hlpfile
, wndname
), show
);
1721 hAccel
= LoadAcceleratorsW(hInstance
, MAKEINTRESOURCEW(MAIN_ACCEL
));
1722 while ((Globals
.win_list
|| Globals
.active_popup
) && GetMessageW(&msg
, 0, 0, 0))
1724 HWND hWnd
= Globals
.active_win
? Globals
.active_win
->hMainWnd
: NULL
;
1725 if (!TranslateAcceleratorW(hWnd
, hAccel
, &msg
))
1727 TranslateMessage(&msg
);
1728 DispatchMessageW(&msg
);
1731 for (dll
= Globals
.dlls
; dll
; dll
= dll
->next
)
1733 if (dll
->class & DC_INITTERM
) dll
->handler(DW_TERM
, 0, 0);