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
31 #define NONAMELESSUNION
39 #include "winhelp_res.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(winhelp
);
48 WINHELP_GLOBALS Globals
= {3, NULL
, TRUE
, NULL
, NULL
, NULL
, NULL
, NULL
, {{{NULL
,NULL
}},0}, NULL
};
50 #define CTL_ID_BUTTON 0x700
51 #define CTL_ID_TEXT 0x701
54 /***********************************************************************
58 static void WINHELP_InitFonts(HWND hWnd
)
60 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
61 LOGFONTW logfontlist
[] = {
62 {-10, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
63 {-12, 0, 0, 0, 700, 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 {-12, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
66 {-12, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
67 {-10, 0, 0, 0, 700, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}},
68 { -8, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET
, 0, 0, 0, 32, {'H','e','l','v',0}}};
70 static HFONT fonts
[ARRAY_SIZE(logfontlist
)];
71 static BOOL init
= FALSE
;
73 win
->fonts_len
= ARRAY_SIZE(logfontlist
);
80 for (i
= 0; i
< ARRAY_SIZE(logfontlist
); i
++)
82 fonts
[i
] = CreateFontIndirectW(&logfontlist
[i
]);
89 static DWORD CALLBACK
WINHELP_RtfStreamIn(DWORD_PTR cookie
, BYTE
* buff
,
92 struct RtfData
* rd
= (struct RtfData
*)cookie
;
94 if (rd
->where
>= rd
->ptr
) return 1;
95 if (rd
->where
+ cb
> rd
->ptr
)
96 cb
= rd
->ptr
- rd
->where
;
97 memcpy(buff
, rd
->where
, cb
);
103 static void WINHELP_SetupText(HWND hTextWnd
, WINHELP_WINDOW
* win
, ULONG relative
)
105 static const WCHAR emptyW
[1];
106 /* At first clear area - needed by EM_POSFROMCHAR/EM_SETSCROLLPOS */
107 SendMessageW(hTextWnd
, WM_SETTEXT
, 0, (LPARAM
)emptyW
);
108 SendMessageW(hTextWnd
, WM_SETREDRAW
, FALSE
, 0);
109 SendMessageW(hTextWnd
, EM_SETBKGNDCOLOR
, 0, (LPARAM
)win
->info
->sr_color
);
110 /* set word-wrap to window size (undocumented) */
111 SendMessageW(hTextWnd
, EM_SETTARGETDEVICE
, 0, 0);
121 if (HLPFILE_BrowsePage(win
->page
, &rd
, win
->font_scale
, relative
))
124 es
.dwCookie
= (DWORD_PTR
)&rd
;
126 es
.pfnCallback
= WINHELP_RtfStreamIn
;
128 SendMessageW(hTextWnd
, EM_STREAMIN
, SF_RTF
, (LPARAM
)&es
);
129 cp
= rd
.char_pos_rel
;
131 /* FIXME: else leaking potentially the rd.first_link chain */
133 SendMessageW(hTextWnd
, EM_POSFROMCHAR
, (WPARAM
)&ptl
, cp
? cp
- 1 : 0);
134 pt
.x
= 0; pt
.y
= ptl
.y
;
135 SendMessageW(hTextWnd
, EM_SETSCROLLPOS
, 0, (LPARAM
)&pt
);
137 SendMessageW(hTextWnd
, WM_SETREDRAW
, TRUE
, 0);
138 RedrawWindow(hTextWnd
, NULL
, NULL
, RDW_FRAME
|RDW_INVALIDATE
);
141 /***********************************************************************
143 * WINHELP_GetOpenFileName
145 BOOL
WINHELP_GetOpenFileName(LPSTR lpszFile
, int len
)
147 OPENFILENAMEA openfilename
;
148 CHAR szDir
[MAX_PATH
];
149 CHAR szzFilter
[2 * MAX_STRING_LEN
+ 100];
154 LoadStringA(Globals
.hInstance
, STID_HELP_FILES_HLP
, p
, MAX_STRING_LEN
);
158 LoadStringA(Globals
.hInstance
, STID_ALL_FILES
, p
, MAX_STRING_LEN
);
164 GetCurrentDirectoryA(sizeof(szDir
), szDir
);
168 openfilename
.lStructSize
= sizeof(openfilename
);
169 openfilename
.hwndOwner
= (Globals
.active_win
? Globals
.active_win
->hMainWnd
: 0);
170 openfilename
.hInstance
= Globals
.hInstance
;
171 openfilename
.lpstrFilter
= szzFilter
;
172 openfilename
.lpstrCustomFilter
= 0;
173 openfilename
.nMaxCustFilter
= 0;
174 openfilename
.nFilterIndex
= 1;
175 openfilename
.lpstrFile
= lpszFile
;
176 openfilename
.nMaxFile
= len
;
177 openfilename
.lpstrFileTitle
= 0;
178 openfilename
.nMaxFileTitle
= 0;
179 openfilename
.lpstrInitialDir
= szDir
;
180 openfilename
.lpstrTitle
= 0;
181 openfilename
.Flags
= OFN_ENABLESIZING
| OFN_HIDEREADONLY
| OFN_READONLY
;
182 openfilename
.nFileOffset
= 0;
183 openfilename
.nFileExtension
= 0;
184 openfilename
.lpstrDefExt
= 0;
185 openfilename
.lCustData
= 0;
186 openfilename
.lpfnHook
= 0;
187 openfilename
.lpTemplateName
= 0;
189 return GetOpenFileNameA(&openfilename
);
192 /***********************************************************************
194 * WINHELP_MessageBoxIDS_s
196 static INT
WINHELP_MessageBoxIDS_s(UINT ids_text
, LPCSTR str
, UINT ids_title
, WORD type
)
198 CHAR text
[MAX_STRING_LEN
];
199 CHAR newtext
[MAX_STRING_LEN
+ MAX_PATH
];
201 LoadStringA(Globals
.hInstance
, ids_text
, text
, sizeof(text
));
202 wsprintfA(newtext
, text
, str
);
204 return MessageBoxA(0, newtext
, MAKEINTRESOURCEA(ids_title
), type
);
207 /***********************************************************************
209 * WINHELP_LookupHelpFile
211 HLPFILE
* WINHELP_LookupHelpFile(LPCSTR lpszFile
)
214 char szFullName
[MAX_PATH
];
215 char szAddPath
[MAX_PATH
];
219 * NOTE: This is needed by popup windows only.
220 * In other cases it's not needed but does not hurt though.
222 if (Globals
.active_win
&& Globals
.active_win
->page
&& Globals
.active_win
->page
->file
)
224 strcpy(szAddPath
, Globals
.active_win
->page
->file
->lpszPath
);
225 p
= strrchr(szAddPath
, '\\');
230 * FIXME: Should we swap conditions?
232 if (!SearchPathA(NULL
, lpszFile
, ".hlp", MAX_PATH
, szFullName
, NULL
) &&
233 !SearchPathA(szAddPath
, lpszFile
, ".hlp", MAX_PATH
, szFullName
, NULL
))
235 if (WINHELP_MessageBoxIDS_s(STID_FILE_NOT_FOUND_s
, lpszFile
, STID_WHERROR
,
236 MB_YESNO
|MB_ICONQUESTION
) != IDYES
)
238 if (!WINHELP_GetOpenFileName(szFullName
, MAX_PATH
))
241 hlpfile
= HLPFILE_ReadHlpFile(szFullName
);
243 WINHELP_MessageBoxIDS_s(STID_HLPFILE_ERROR_s
, lpszFile
,
244 STID_WHERROR
, MB_OK
|MB_ICONSTOP
);
248 /******************************************************************
249 * WINHELP_GetWindowInfo
253 HLPFILE_WINDOWINFO
* WINHELP_GetWindowInfo(HLPFILE
* hlpfile
, LPCSTR name
)
255 static HLPFILE_WINDOWINFO mwi
;
258 if (!name
|| !name
[0])
259 name
= Globals
.active_win
->info
->name
;
262 for (i
= 0; i
< hlpfile
->numWindows
; i
++)
263 if (!lstrcmpiA(hlpfile
->windows
[i
].name
, name
))
264 return &hlpfile
->windows
[i
];
266 if (strcmp(name
, "main") != 0)
268 WINE_FIXME("Couldn't find window info for %s\n", debugstr_a(name
));
274 strcpy(mwi
.type
, "primary");
275 strcpy(mwi
.name
, "main");
276 if (hlpfile
&& hlpfile
->lpszTitle
[0])
279 LoadStringA(Globals
.hInstance
, STID_WINE_HELP
, tmp
, sizeof(tmp
));
280 _snprintf(mwi
.caption
, sizeof(mwi
.caption
), "%s %s - %s",
281 hlpfile
->lpszTitle
, tmp
, hlpfile
->lpszPath
);
284 LoadStringA(Globals
.hInstance
, STID_WINE_HELP
, mwi
.caption
, sizeof(mwi
.caption
));
285 mwi
.origin
.x
= mwi
.origin
.y
= mwi
.size
.cx
= mwi
.size
.cy
= CW_USEDEFAULT
;
287 mwi
.win_style
= WS_OVERLAPPEDWINDOW
;
288 mwi
.sr_color
= mwi
.nsr_color
= 0xFFFFFF;
293 /******************************************************************
294 * HLPFILE_GetPopupWindowInfo
298 static HLPFILE_WINDOWINFO
* WINHELP_GetPopupWindowInfo(HLPFILE
* hlpfile
,
299 WINHELP_WINDOW
* parent
, LPARAM mouse
)
301 static HLPFILE_WINDOWINFO wi
;
305 wi
.type
[0] = wi
.name
[0] = wi
.caption
[0] = '\0';
307 /* Calculate horizontal size and position of a popup window */
308 GetWindowRect(parent
->hMainWnd
, &parent_rect
);
309 wi
.size
.cx
= (parent_rect
.right
- parent_rect
.left
) / 2;
310 wi
.size
.cy
= 10; /* need a non null value, so that borders are taken into account while computing */
312 wi
.origin
.x
= (short)LOWORD(mouse
);
313 wi
.origin
.y
= (short)HIWORD(mouse
);
314 ClientToScreen(parent
->hMainWnd
, &wi
.origin
);
315 wi
.origin
.x
-= wi
.size
.cx
/ 2;
316 wi
.origin
.x
= min(wi
.origin
.x
, GetSystemMetrics(SM_CXSCREEN
) - wi
.size
.cx
);
317 wi
.origin
.x
= max(wi
.origin
.x
, 0);
320 wi
.win_style
= WS_POPUP
| WS_BORDER
;
321 if (parent
->page
->file
->has_popup_color
)
322 wi
.sr_color
= parent
->page
->file
->popup_color
;
324 wi
.sr_color
= parent
->info
->sr_color
;
325 wi
.nsr_color
= 0xFFFFFF;
338 } WINHELP
,*LPWINHELP
;
340 static BOOL
WINHELP_HasWorkingWindow(void)
342 if (!Globals
.active_win
) return FALSE
;
343 if (Globals
.active_win
->next
|| Globals
.win_list
!= Globals
.active_win
) return TRUE
;
344 return Globals
.active_win
->page
!= NULL
&& Globals
.active_win
->page
->file
!= NULL
;
347 /******************************************************************
348 * WINHELP_HandleCommand
352 static LRESULT
WINHELP_HandleCommand(HWND hSrcWnd
, LPARAM lParam
)
354 COPYDATASTRUCT
* cds
= (COPYDATASTRUCT
*)lParam
;
357 if (cds
->dwData
!= 0xA1DE505)
359 WINE_FIXME("Wrong magic number (%08Ix)\n", cds
->dwData
);
367 char* ptr
= (wh
->ofsFilename
) ? (LPSTR
)wh
+ wh
->ofsFilename
: NULL
;
369 WINE_TRACE("Got[%u]: cmd=%u data=%08lx fn=%s\n",
370 wh
->size
, wh
->command
, wh
->data
, debugstr_a(ptr
));
376 MACRO_JumpContext(ptr
, "main", wh
->data
);
378 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
386 MACRO_JumpContents(ptr
, "main");
388 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
390 case HELP_HELPONHELP
:
392 if (!WINHELP_HasWorkingWindow()) MACRO_Exit();
394 /* case HELP_SETINDEX: */
395 case HELP_SETCONTENTS
:
398 MACRO_SetContents(ptr
, wh
->data
);
401 case HELP_CONTEXTPOPUP
:
404 MACRO_PopupContext(ptr
, wh
->data
);
407 /* case HELP_FORCEFILE:*/
408 /* case HELP_CONTEXTMENU: */
410 /* in fact, should be the topic dialog box */
411 WINE_FIXME("HELP_FINDER: stub\n");
414 MACRO_JumpHash(ptr
, "main", 0);
417 /* case HELP_WM_HELP: */
418 /* case HELP_SETPOPUP_POS: */
420 /* case HELP_COMMAND: */
421 /* case HELP_PARTIALKEY: */
422 /* case HELP_MULTIKEY: */
423 /* case HELP_SETWINPOS: */
425 WINE_FIXME("Unhandled command (%x) for remote winhelp control\n", wh
->command
);
429 /* Always return success for now */
433 void WINHELP_LayoutMainWindow(WINHELP_WINDOW
* win
)
435 RECT rect
, button_box_rect
;
437 HWND hButtonBoxWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_BUTTON
);
438 HWND hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
440 GetClientRect(win
->hMainWnd
, &rect
);
442 /* Update button box and text Window */
443 SetWindowPos(hButtonBoxWnd
, HWND_TOP
,
445 rect
.right
- rect
.left
,
446 rect
.bottom
- rect
.top
, 0);
448 if (GetWindowRect(hButtonBoxWnd
, &button_box_rect
))
449 text_top
= rect
.top
+ button_box_rect
.bottom
- button_box_rect
.top
;
451 SetWindowPos(hTextWnd
, HWND_TOP
,
453 rect
.right
- rect
.left
,
454 rect
.bottom
- text_top
, 0);
458 /******************************************************************
459 * WINHELP_DeleteButtons
462 static void WINHELP_DeleteButtons(WINHELP_WINDOW
* win
)
467 for (b
= win
->first_button
; b
; b
= bp
)
469 DestroyWindow(b
->hWnd
);
473 win
->first_button
= NULL
;
476 /******************************************************************
477 * WINHELP_DeleteBackSet
480 void WINHELP_DeleteBackSet(WINHELP_WINDOW
* win
)
484 for (i
= 0; i
< win
->back
.index
; i
++)
486 HLPFILE_FreeHlpFile(win
->back
.set
[i
].page
->file
);
487 win
->back
.set
[i
].page
= NULL
;
492 /******************************************************************
493 * WINHELP_DeletePageLinks
496 static void WINHELP_DeletePageLinks(HLPFILE_PAGE
* page
)
501 for (curr
= page
->first_link
; curr
; curr
= next
)
508 /***********************************************************************
512 WINHELP_WINDOW
* WINHELP_GrabWindow(WINHELP_WINDOW
* win
)
514 WINE_TRACE("Grab %p#%d++\n", win
, win
->ref_count
);
519 /***********************************************************************
521 * WINHELP_ReleaseWindow
523 BOOL
WINHELP_ReleaseWindow(WINHELP_WINDOW
* win
)
525 WINE_TRACE("Release %p#%d--\n", win
, win
->ref_count
);
527 if (!--win
->ref_count
)
529 DestroyWindow(win
->hMainWnd
);
535 /***********************************************************************
537 * WINHELP_DeleteWindow
539 static void WINHELP_DeleteWindow(WINHELP_WINDOW
* win
)
545 for (w
= &Globals
.win_list
; *w
; w
= &(*w
)->next
)
553 bExit
= (Globals
.wVersion
>= 4 && !lstrcmpiA(win
->info
->name
, "main"));
555 if (Globals
.active_win
== win
)
557 Globals
.active_win
= Globals
.win_list
;
558 if (Globals
.win_list
)
559 SetActiveWindow(Globals
.win_list
->hMainWnd
);
562 if (win
== Globals
.active_popup
)
563 Globals
.active_popup
= NULL
;
565 hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
566 SetWindowLongPtrA(hTextWnd
, GWLP_WNDPROC
, (LONG_PTR
)win
->origRicheditWndProc
);
568 WINHELP_DeleteButtons(win
);
570 if (win
->page
) WINHELP_DeletePageLinks(win
->page
);
571 if (win
->hHistoryWnd
) DestroyWindow(win
->hHistoryWnd
);
573 DeleteObject(win
->hBrush
);
575 WINHELP_DeleteBackSet(win
);
577 if (win
->page
) HLPFILE_FreeHlpFile(win
->page
->file
);
580 if (bExit
) MACRO_Exit();
581 if (!Globals
.win_list
)
585 static char* WINHELP_GetCaption(WINHELP_WNDPAGE
* wpage
)
587 if (wpage
->wininfo
->caption
[0]) return wpage
->wininfo
->caption
;
588 return wpage
->page
->file
->lpszTitle
;
591 static void WINHELP_RememberPage(WINHELP_WINDOW
* win
, WINHELP_WNDPAGE
* wpage
)
595 if (!Globals
.history
.index
|| Globals
.history
.set
[0].page
!= wpage
->page
)
597 num
= ARRAY_SIZE(Globals
.history
.set
);
598 /* we're full, remove latest entry */
599 if (Globals
.history
.index
== num
)
601 HLPFILE_FreeHlpFile(Globals
.history
.set
[num
- 1].page
->file
);
602 Globals
.history
.index
--;
604 memmove(&Globals
.history
.set
[1], &Globals
.history
.set
[0],
605 Globals
.history
.index
* sizeof(Globals
.history
.set
[0]));
606 Globals
.history
.set
[0] = *wpage
;
607 Globals
.history
.index
++;
608 wpage
->page
->file
->wRefCount
++;
610 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
612 num
= ARRAY_SIZE(win
->back
.set
);
613 if (win
->back
.index
== num
)
615 /* we're full, remove latest entry */
616 HLPFILE_FreeHlpFile(win
->back
.set
[0].page
->file
);
617 memmove(&win
->back
.set
[0], &win
->back
.set
[1],
618 (num
- 1) * sizeof(win
->back
.set
[0]));
621 win
->back
.set
[win
->back
.index
++] = *wpage
;
622 wpage
->page
->file
->wRefCount
++;
625 /***********************************************************************
629 static HLPFILE_LINK
* WINHELP_FindLink(WINHELP_WINDOW
* win
, LPARAM pos
)
632 POINTL mouse_ptl
, char_ptl
, char_next_ptl
;
635 if (!win
->page
) return NULL
;
637 mouse_ptl
.x
= (short)LOWORD(pos
);
638 mouse_ptl
.y
= (short)HIWORD(pos
);
639 cp
= SendMessageW(GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
), EM_CHARFROMPOS
,
640 0, (LPARAM
)&mouse_ptl
);
642 for (link
= win
->page
->first_link
; link
; link
= link
->next
)
644 if (link
->cpMin
<= cp
&& cp
<= link
->cpMax
)
646 /* check whether we're at end of line */
647 SendMessageW(GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
), EM_POSFROMCHAR
,
648 (LPARAM
)&char_ptl
, cp
);
649 SendMessageW(GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
), EM_POSFROMCHAR
,
650 (LPARAM
)&char_next_ptl
, cp
+ 1);
653 HLPFILE_HOTSPOTLINK
* hslink
= (HLPFILE_HOTSPOTLINK
*)link
;
654 if ((mouse_ptl
.x
< char_ptl
.x
+ hslink
->x
) ||
655 (mouse_ptl
.x
>= char_ptl
.x
+ hslink
->x
+ hslink
->width
) ||
656 (mouse_ptl
.y
< char_ptl
.y
+ hslink
->y
) ||
657 (mouse_ptl
.y
>= char_ptl
.y
+ hslink
->y
+ hslink
->height
))
661 if (char_next_ptl
.y
!= char_ptl
.y
|| mouse_ptl
.x
>= char_next_ptl
.x
)
669 static LRESULT CALLBACK
WINHELP_RicheditWndProc(HWND hWnd
, UINT msg
,
670 WPARAM wParam
, LPARAM lParam
)
672 WINHELP_WINDOW
*win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(GetParent(hWnd
), 0);
678 messagePos
= GetMessagePos();
679 pt
.x
= (short)LOWORD(messagePos
);
680 pt
.y
= (short)HIWORD(messagePos
);
681 ScreenToClient(hWnd
, &pt
);
682 if (win
->page
&& WINHELP_FindLink(win
, MAKELPARAM(pt
.x
, pt
.y
)))
684 SetCursor(win
->hHandCur
);
689 return CallWindowProcA(win
->origRicheditWndProc
, hWnd
, msg
, wParam
, lParam
);
693 /***********************************************************************
695 * WINHELP_CreateHelpWindow
697 BOOL
WINHELP_CreateHelpWindow(WINHELP_WNDPAGE
* wpage
, int nCmdShow
, BOOL remember
)
699 WINHELP_WINDOW
* win
= NULL
;
700 BOOL bPrimary
, bPopup
, bReUsed
= FALSE
;
702 HWND hTextWnd
= NULL
;
704 bPrimary
= !lstrcmpiA(wpage
->wininfo
->name
, "main");
705 bPopup
= !bPrimary
&& (wpage
->wininfo
->win_style
& WS_POPUP
);
709 for (win
= Globals
.win_list
; win
; win
= win
->next
)
711 if (!lstrcmpiA(win
->info
->name
, wpage
->wininfo
->name
))
713 if (win
->page
== wpage
->page
&& win
->info
== wpage
->wininfo
)
715 /* see #22979, some hlp files have a macro (run at page opening), which
716 * jumps to the very same page
717 * Exit gracefully in that case
721 WINHELP_DeleteButtons(win
);
723 SetWindowTextA(win
->hMainWnd
, WINHELP_GetCaption(wpage
));
724 if (win
->info
!= wpage
->wininfo
)
728 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
;
730 if (wpage
->wininfo
->origin
.x
!= CW_USEDEFAULT
&&
731 wpage
->wininfo
->origin
.y
!= CW_USEDEFAULT
)
733 pt
= wpage
->wininfo
->origin
;
734 flags
&= ~SWP_NOSIZE
;
736 if (wpage
->wininfo
->size
.cx
!= CW_USEDEFAULT
&&
737 wpage
->wininfo
->size
.cy
!= CW_USEDEFAULT
)
739 sz
= wpage
->wininfo
->size
;
740 flags
&= ~SWP_NOMOVE
;
742 SetWindowPos(win
->hMainWnd
, HWND_TOP
, pt
.x
, pt
.y
, sz
.cx
, sz
.cy
, flags
);
745 if (wpage
->page
&& win
->page
&& wpage
->page
->file
!= win
->page
->file
)
746 WINHELP_DeleteBackSet(win
);
747 WINHELP_InitFonts(win
->hMainWnd
);
749 win
->page
= wpage
->page
;
750 win
->info
= wpage
->wininfo
;
751 hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
752 WINHELP_SetupText(hTextWnd
, win
, wpage
->relative
);
754 InvalidateRect(win
->hMainWnd
, NULL
, TRUE
);
755 if (win
->hHistoryWnd
) InvalidateRect(win
->hHistoryWnd
, NULL
, TRUE
);
764 /* Initialize WINHELP_WINDOW struct */
765 win
= calloc(1, sizeof(WINHELP_WINDOW
));
766 if (!win
) return FALSE
;
767 win
->next
= Globals
.win_list
;
768 Globals
.win_list
= win
;
770 win
->hHandCur
= LoadCursorW(0, (LPWSTR
)IDC_HAND
);
773 WINHELP_GrabWindow(win
);
775 win
->page
= wpage
->page
;
776 win
->info
= wpage
->wininfo
;
777 WINHELP_GrabWindow(win
);
779 if (!bPopup
&& wpage
->page
&& remember
)
781 WINHELP_RememberPage(win
, wpage
);
785 Globals
.active_popup
= win
;
787 Globals
.active_win
= win
;
789 /* Initialize default pushbuttons */
790 if (bPrimary
&& wpage
->page
)
792 CHAR buffer
[MAX_STRING_LEN
];
794 LoadStringA(Globals
.hInstance
, STID_CONTENTS
, buffer
, sizeof(buffer
));
795 MACRO_CreateButton("BTN_CONTENTS", buffer
, "Contents()");
796 LoadStringA(Globals
.hInstance
, STID_INDEX
, buffer
, sizeof(buffer
));
797 MACRO_CreateButton("BTN_INDEX", buffer
, "Finder()");
798 LoadStringA(Globals
.hInstance
, STID_BACK
, buffer
, sizeof(buffer
));
799 MACRO_CreateButton("BTN_BACK", buffer
, "Back()");
800 if (win
->back
.index
<= 1) MACRO_DisableButton("BTN_BACK");
805 win
->hMainWnd
= CreateWindowExA((bPopup
) ? WS_EX_TOOLWINDOW
: 0, MAIN_WIN_CLASS_NAME
,
806 WINHELP_GetCaption(wpage
),
807 bPrimary
? WS_OVERLAPPEDWINDOW
: wpage
->wininfo
->win_style
,
808 wpage
->wininfo
->origin
.x
, wpage
->wininfo
->origin
.y
,
809 wpage
->wininfo
->size
.cx
, wpage
->wininfo
->size
.cy
,
810 bPopup
? Globals
.active_win
->hMainWnd
: NULL
,
811 bPrimary
? LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(MAIN_MENU
)) : 0,
812 Globals
.hInstance
, win
);
814 /* Create button box and text Window */
815 CreateWindowA(BUTTON_BOX_WIN_CLASS_NAME
, "", WS_CHILD
| WS_VISIBLE
,
816 0, 0, 0, 0, win
->hMainWnd
, (HMENU
)CTL_ID_BUTTON
, Globals
.hInstance
, NULL
);
818 hTextWnd
= CreateWindowA(RICHEDIT_CLASS20A
, NULL
,
819 ES_MULTILINE
| ES_READONLY
| WS_CHILD
| WS_HSCROLL
| WS_VSCROLL
| WS_VISIBLE
,
820 0, 0, 0, 0, win
->hMainWnd
, (HMENU
)CTL_ID_TEXT
, Globals
.hInstance
, NULL
);
821 SendMessageW(hTextWnd
, EM_SETEVENTMASK
, 0,
822 SendMessageW(hTextWnd
, EM_GETEVENTMASK
, 0, 0) | ENM_MOUSEEVENTS
);
823 win
->origRicheditWndProc
= (WNDPROC
)SetWindowLongPtrA(hTextWnd
, GWLP_WNDPROC
,
824 (LONG_PTR
)WINHELP_RicheditWndProc
);
827 hIcon
= (wpage
->page
) ? wpage
->page
->file
->hIcon
: NULL
;
828 if (!hIcon
) hIcon
= LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINHELP
), IMAGE_ICON
,
829 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), LR_SHARED
);
830 SendMessageW(win
->hMainWnd
, WM_SETICON
, ICON_SMALL
, (DWORD_PTR
)hIcon
);
832 /* Initialize file specific pushbuttons */
833 if (!(wpage
->wininfo
->win_style
& WS_POPUP
) && wpage
->page
)
835 HLPFILE_MACRO
*macro
;
836 for (macro
= wpage
->page
->file
->first_macro
; macro
; macro
= macro
->next
)
837 MACRO_ExecuteMacro(win
, macro
->lpszMacro
);
839 for (macro
= wpage
->page
->first_macro
; macro
; macro
= macro
->next
)
840 MACRO_ExecuteMacro(win
, macro
->lpszMacro
);
842 /* See #17681, in some cases, the newly created window is closed by the macros it contains
843 * (braindead), so deal with this case
845 for (win
= Globals
.win_list
; win
; win
= win
->next
)
847 if (!lstrcmpiA(win
->info
->name
, wpage
->wininfo
->name
)) break;
849 if (!win
|| !WINHELP_ReleaseWindow(win
)) return TRUE
;
853 DWORD mask
= SendMessageW(hTextWnd
, EM_GETEVENTMASK
, 0, 0);
855 win
->font_scale
= Globals
.active_win
->font_scale
;
856 WINHELP_SetupText(hTextWnd
, win
, wpage
->relative
);
858 /* we need the window to be shown for richedit to compute the size */
859 ShowWindow(win
->hMainWnd
, nCmdShow
);
860 SendMessageW(hTextWnd
, EM_SETEVENTMASK
, 0, mask
| ENM_REQUESTRESIZE
);
861 SendMessageW(hTextWnd
, EM_REQUESTRESIZE
, 0, 0);
862 SendMessageW(hTextWnd
, EM_SETEVENTMASK
, 0, mask
);
866 WINHELP_SetupText(hTextWnd
, win
, wpage
->relative
);
867 WINHELP_LayoutMainWindow(win
);
868 ShowWindow(win
->hMainWnd
, nCmdShow
);
874 /******************************************************************
875 * WINHELP_OpenHelpWindow
876 * Main function to search for a page and display it in a window
878 BOOL
WINHELP_OpenHelpWindow(HLPFILE_PAGE
* (*lookup
)(HLPFILE
*, LONG
, ULONG
*),
879 HLPFILE
* hlpfile
, LONG val
, HLPFILE_WINDOWINFO
* wi
,
882 WINHELP_WNDPAGE wpage
;
884 wpage
.page
= lookup(hlpfile
, val
, &wpage
.relative
);
885 if (wpage
.page
) wpage
.page
->file
->wRefCount
++;
887 return WINHELP_CreateHelpWindow(&wpage
, nCmdShow
, TRUE
);
890 /******************************************************************
891 * WINHELP_HandleTextMouse
894 static BOOL
WINHELP_HandleTextMouse(WINHELP_WINDOW
* win
, UINT msg
, LPARAM lParam
)
903 if ((link
= WINHELP_FindLink(win
, lParam
)))
905 HLPFILE_WINDOWINFO
* wi
;
907 switch (link
->cookie
)
910 if ((hlpfile
= WINHELP_LookupHelpFile(link
->string
)))
912 if (link
->window
== -1)
915 if (wi
->win_style
& WS_POPUP
) wi
= Globals
.active_win
->info
;
917 else if (link
->window
< hlpfile
->numWindows
)
918 wi
= &hlpfile
->windows
[link
->window
];
921 WINE_WARN("link to window %d/%d\n", link
->window
, hlpfile
->numWindows
);
924 WINHELP_OpenHelpWindow(HLPFILE_PageByHash
, hlpfile
, link
->hash
, wi
, SW_NORMAL
);
928 if ((hlpfile
= WINHELP_LookupHelpFile(link
->string
)))
929 WINHELP_OpenHelpWindow(HLPFILE_PageByHash
, hlpfile
, link
->hash
,
930 WINHELP_GetPopupWindowInfo(hlpfile
, win
, lParam
),
934 MACRO_ExecuteMacro(win
, link
->string
);
937 WINE_FIXME("Unknown link cookie %d\n", link
->cookie
);
946 /***********************************************************************
950 static BOOL
WINHELP_CheckPopup(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* lret
)
952 WINHELP_WINDOW
* popup
;
954 if (!Globals
.active_popup
) return FALSE
;
960 MSGFILTER
* msgf
= (MSGFILTER
*)lParam
;
961 if (msgf
->nmhdr
.code
== EN_MSGFILTER
)
963 if (!WINHELP_CheckPopup(hWnd
, msgf
->msg
, msgf
->wParam
, msgf
->lParam
, NULL
))
971 if (LOWORD(wParam
) != WA_INACTIVE
|| (HWND
)lParam
== Globals
.active_win
->hMainWnd
||
972 (HWND
)lParam
== Globals
.active_popup
->hMainWnd
||
973 GetWindow((HWND
)lParam
, GW_OWNER
) == Globals
.active_win
->hMainWnd
)
977 if (msg
== WM_LBUTTONDOWN
)
978 WINHELP_HandleTextMouse(Globals
.active_popup
, msg
, lParam
);
982 case WM_NCLBUTTONDOWN
:
983 case WM_NCMBUTTONDOWN
:
984 case WM_NCRBUTTONDOWN
:
985 popup
= Globals
.active_popup
;
986 Globals
.active_popup
= NULL
;
987 WINHELP_ReleaseWindow(popup
);
994 /***********************************************************************
996 * WINHELP_ButtonWndProc
998 static LRESULT CALLBACK
WINHELP_ButtonWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1000 if (WINHELP_CheckPopup(hWnd
, msg
, wParam
, lParam
, NULL
)) return 0;
1002 if (msg
== WM_KEYDOWN
)
1011 return SendMessageA(GetParent(hWnd
), msg
, wParam
, lParam
);
1015 return CallWindowProcA(Globals
.button_proc
, hWnd
, msg
, wParam
, lParam
);
1018 /***********************************************************************
1020 * WINHELP_ButtonBoxWndProc
1022 static LRESULT CALLBACK
WINHELP_ButtonBoxWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1025 WINHELP_WINDOW
*win
;
1026 WINHELP_BUTTON
*button
;
1030 if (WINHELP_CheckPopup(hWnd
, msg
, wParam
, lParam
, NULL
)) return 0L;
1034 case WM_WINDOWPOSCHANGING
:
1035 winpos
= (WINDOWPOS
*) lParam
;
1036 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(GetParent(hWnd
), 0);
1038 /* Update buttons */
1041 for (button
= win
->first_button
; button
; button
= button
->next
)
1047 button
->hWnd
= CreateWindowA(STRING_BUTTON
, button
->lpszName
,
1048 WS_CHILD
| WS_VISIBLE
| BS_PUSHBUTTON
,
1050 hWnd
, (HMENU
) button
->wParam
,
1051 Globals
.hInstance
, 0);
1054 if (Globals
.button_proc
== NULL
)
1056 NONCLIENTMETRICSW ncm
;
1057 Globals
.button_proc
= (WNDPROC
) GetWindowLongPtrA(button
->hWnd
, GWLP_WNDPROC
);
1059 ncm
.cbSize
= sizeof(NONCLIENTMETRICSW
);
1060 SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
,
1061 sizeof(NONCLIENTMETRICSW
), &ncm
, 0);
1062 Globals
.hButtonFont
= CreateFontIndirectW(&ncm
.lfMenuFont
);
1064 SetWindowLongPtrA(button
->hWnd
, GWLP_WNDPROC
, (LONG_PTR
) WINHELP_ButtonWndProc
);
1065 if (Globals
.hButtonFont
)
1066 SendMessageW(button
->hWnd
, WM_SETFONT
, (WPARAM
)Globals
.hButtonFont
, TRUE
);
1069 hDc
= GetDC(button
->hWnd
);
1070 GetTextExtentPointA(hDc
, button
->lpszName
, strlen(button
->lpszName
), &textsize
);
1071 ReleaseDC(button
->hWnd
, hDc
);
1073 button_size
.cx
= max(button_size
.cx
, textsize
.cx
+ BUTTON_CX
);
1074 button_size
.cy
= max(button_size
.cy
, textsize
.cy
+ BUTTON_CY
);
1079 for (button
= win
->first_button
; button
; button
= button
->next
)
1081 SetWindowPos(button
->hWnd
, HWND_TOP
, x
, y
, button_size
.cx
, button_size
.cy
, 0);
1083 if (x
+ 2 * button_size
.cx
<= winpos
->cx
)
1084 x
+= button_size
.cx
;
1086 x
= 0, y
+= button_size
.cy
;
1088 winpos
->cy
= y
+ (x
? button_size
.cy
: 0);
1092 SendMessageW(GetParent(hWnd
), msg
, wParam
, lParam
);
1103 return SendMessageA(GetParent(hWnd
), msg
, wParam
, lParam
);
1108 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1111 /******************************************************************
1112 * WINHELP_HistoryWndProc
1116 static LRESULT CALLBACK
WINHELP_HistoryWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1118 WINHELP_WINDOW
* win
;
1128 win
= (WINHELP_WINDOW
*)((LPCREATESTRUCTA
)lParam
)->lpCreateParams
;
1129 SetWindowLongPtrW(hWnd
, 0, (ULONG_PTR
)win
);
1130 win
->hHistoryWnd
= hWnd
;
1134 GetTextMetricsW(hDc
, &tm
);
1135 GetWindowRect(hWnd
, &r
);
1137 r
.right
= r
.left
+ 30 * tm
.tmAveCharWidth
;
1138 r
.bottom
= r
.top
+ ARRAY_SIZE(Globals
.history
.set
) * tm
.tmHeight
;
1139 AdjustWindowRect(&r
, GetWindowLongW(hWnd
, GWL_STYLE
), FALSE
);
1140 if (r
.left
< 0) {r
.right
-= r
.left
; r
.left
= 0;}
1141 if (r
.top
< 0) {r
.bottom
-= r
.top
; r
.top
= 0;}
1143 MoveWindow(hWnd
, r
.left
, r
.top
, r
.right
, r
.bottom
, TRUE
);
1144 ReleaseDC(hWnd
, hDc
);
1146 case WM_LBUTTONDOWN
:
1148 GetTextMetricsW(hDc
, &tm
);
1149 i
= HIWORD(lParam
) / tm
.tmHeight
;
1150 if (i
< Globals
.history
.index
)
1151 WINHELP_CreateHelpWindow(&Globals
.history
.set
[i
], SW_SHOW
, TRUE
);
1152 ReleaseDC(hWnd
, hDc
);
1155 hDc
= BeginPaint(hWnd
, &ps
);
1156 GetTextMetricsW(hDc
, &tm
);
1158 for (i
= 0; i
< Globals
.history
.index
; i
++)
1160 if (Globals
.history
.set
[i
].page
->file
== Globals
.active_win
->page
->file
)
1162 TextOutA(hDc
, 0, i
* tm
.tmHeight
,
1163 Globals
.history
.set
[i
].page
->lpszTitle
,
1164 strlen(Globals
.history
.set
[i
].page
->lpszTitle
));
1173 ptr1
= strrchr(Globals
.history
.set
[i
].page
->file
->lpszPath
, '\\');
1174 if (!ptr1
) ptr1
= Globals
.history
.set
[i
].page
->file
->lpszPath
;
1176 ptr2
= strrchr(ptr1
, '.');
1177 len
= ptr2
? ptr2
- ptr1
: strlen(ptr1
);
1178 if (len
> sizeof(buffer
)) len
= sizeof(buffer
);
1179 memcpy(buffer
, ptr1
, len
);
1180 if (len
< sizeof(buffer
)) buffer
[len
++] = ':';
1181 lstrcpynA(&buffer
[len
], Globals
.history
.set
[i
].page
->lpszTitle
, sizeof(buffer
) - len
);
1182 TextOutA(hDc
, 0, i
* tm
.tmHeight
, buffer
, strlen(buffer
));
1185 EndPaint(hWnd
, &ps
);
1188 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1189 if (hWnd
== win
->hHistoryWnd
)
1190 win
->hHistoryWnd
= 0;
1193 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1196 /**************************************************************************
1199 * HLPFILE_BPTreeCallback enumeration function for '|KWBTREE' internal file.
1202 static void cb_KWBTree(void *p
, void **next
, void *cookie
)
1204 HWND hListWnd
= cookie
;
1207 WINE_TRACE("Adding %s to search list\n", debugstr_a((char *)p
));
1208 SendMessageA(hListWnd
, LB_INSERTSTRING
, -1, (LPARAM
)p
);
1209 count
= SendMessageW(hListWnd
, LB_GETCOUNT
, 0, 0);
1210 SendMessageW(hListWnd
, LB_SETITEMDATA
, count
-1, (LPARAM
)p
);
1211 *next
= (char*)p
+ strlen((char*)p
) + 7;
1221 /**************************************************************************
1222 * WINHELP_IndexDlgProc
1225 static INT_PTR CALLBACK
WINHELP_IndexDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1227 static struct index_data
* id
;
1233 id
= (struct index_data
*)((PROPSHEETPAGEA
*)lParam
)->lParam
;
1234 HLPFILE_BPTreeEnum(id
->hlpfile
->kwbtree
, cb_KWBTree
,
1235 GetDlgItem(hWnd
, IDC_INDEXLIST
));
1240 switch (HIWORD(wParam
))
1243 if (LOWORD(wParam
) == IDC_INDEXLIST
)
1244 SendMessageW(GetParent(hWnd
), PSM_PRESSBUTTON
, PSBTN_OK
, 0);
1249 switch (((NMHDR
*)lParam
)->code
)
1252 sel
= SendDlgItemMessageW(hWnd
, IDC_INDEXLIST
, LB_GETCURSEL
, 0, 0);
1258 p
= (BYTE
*)SendDlgItemMessageW(hWnd
, IDC_INDEXLIST
, LB_GETITEMDATA
, sel
, 0);
1259 count
= *(short*)((char *)p
+ strlen((char *)p
) + 1);
1262 MessageBoxA(hWnd
, "count > 1 not supported yet", "Error", MB_OK
| MB_ICONSTOP
);
1263 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_INVALID
);
1266 id
->offset
= *(ULONG
*)((char *)p
+ strlen((char *)p
) + 3);
1267 id
->offset
= *(long*)(id
->hlpfile
->kwdata
+ id
->offset
+ 9);
1268 if (id
->offset
== 0xFFFFFFFF)
1270 MessageBoxA(hWnd
, "macro keywords not supported yet", "Error", MB_OK
| MB_ICONSTOP
);
1271 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_INVALID
);
1275 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
1288 /**************************************************************************
1289 * WINHELP_SearchDlgProc
1292 static INT_PTR CALLBACK
WINHELP_SearchDlgProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1299 switch (((NMHDR
*)lParam
)->code
)
1302 SetWindowLongPtrW(hWnd
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
1314 /***********************************************************************
1316 * WINHELP_MainWndProc
1318 static LRESULT CALLBACK
WINHELP_MainWndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1320 WINHELP_WINDOW
*win
;
1321 WINHELP_BUTTON
*button
;
1325 if (WINHELP_CheckPopup(hWnd
, msg
, wParam
, lParam
, &ret
)) return ret
;
1330 win
= (WINHELP_WINDOW
*) ((LPCREATESTRUCTA
) lParam
)->lpCreateParams
;
1331 SetWindowLongPtrW(hWnd
, 0, (ULONG_PTR
) win
);
1332 if (!win
->page
&& Globals
.isBook
)
1333 PostMessageW(hWnd
, WM_COMMAND
, MNID_FILE_OPEN
, 0);
1334 win
->hMainWnd
= hWnd
;
1337 case WM_WINDOWPOSCHANGED
:
1338 WINHELP_LayoutMainWindow((WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0));
1342 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1343 switch (LOWORD(wParam
))
1346 case MNID_FILE_OPEN
: MACRO_FileOpen(); break;
1347 case MNID_FILE_PRINT
: MACRO_Print(); break;
1348 case MNID_FILE_SETUP
: MACRO_PrinterSetup(); break;
1349 case MNID_FILE_EXIT
: MACRO_Exit(); break;
1352 case MNID_EDIT_COPYDLG
:
1353 SendDlgItemMessageW(hWnd
, CTL_ID_TEXT
, WM_COPY
, 0, 0);
1355 case MNID_EDIT_ANNOTATE
:MACRO_Annotate(); break;
1358 case MNID_BKMK_DEFINE
: MACRO_BookmarkDefine(); break;
1361 case MNID_HELP_HELPON
: MACRO_HelpOn(); break;
1362 case MNID_HELP_HELPTOP
: MACRO_HelpOnTop(); break;
1363 case MNID_HELP_ABOUT
: MACRO_About(); break;
1366 case MNID_CTXT_ANNOTATE
:MACRO_Annotate(); break;
1367 case MNID_CTXT_COPY
: MACRO_CopyDialog(); break;
1368 case MNID_CTXT_PRINT
: MACRO_Print(); break;
1369 case MNID_OPTS_HISTORY
: MACRO_History(); break;
1370 case MNID_OPTS_FONTS_SMALL
:
1371 case MNID_CTXT_FONTS_SMALL
:
1372 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1373 if (win
->font_scale
!= 0)
1375 win
->font_scale
= 0;
1376 WINHELP_SetupText(GetDlgItem(hWnd
, CTL_ID_TEXT
), win
, 0 /* FIXME */);
1379 case MNID_OPTS_FONTS_NORMAL
:
1380 case MNID_CTXT_FONTS_NORMAL
:
1381 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1382 if (win
->font_scale
!= 1)
1384 win
->font_scale
= 1;
1385 WINHELP_SetupText(GetDlgItem(hWnd
, CTL_ID_TEXT
), win
, 0 /* FIXME */);
1388 case MNID_OPTS_FONTS_LARGE
:
1389 case MNID_CTXT_FONTS_LARGE
:
1390 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1391 if (win
->font_scale
!= 2)
1393 win
->font_scale
= 2;
1394 WINHELP_SetupText(GetDlgItem(hWnd
, CTL_ID_TEXT
), win
, 0 /* FIXME */);
1400 for (button
= win
->first_button
; button
; button
= button
->next
)
1401 if (wParam
== button
->wParam
) break;
1403 MACRO_ExecuteMacro(win
, button
->lpszMacro
);
1404 else if (!HIWORD(wParam
))
1405 MessageBoxW(0, MAKEINTRESOURCEW(STID_NOT_IMPLEMENTED
),
1406 MAKEINTRESOURCEW(STID_WHERROR
), MB_OK
);
1410 /* EPP case WM_DESTROY: */
1411 /* EPP if (Globals.hPopupWnd) DestroyWindow(Globals.hPopupWnd); */
1414 return WINHELP_HandleCommand((HWND
)wParam
, lParam
);
1419 SendDlgItemMessageW(hWnd
, CTL_ID_TEXT
, WM_COPY
, 0, 0);
1425 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1426 hTextWnd
= GetDlgItem(win
->hMainWnd
, CTL_ID_TEXT
);
1431 SendMessageW(hTextWnd
, EM_SCROLL
, SB_LINEUP
, 0);
1434 SendMessageW(hTextWnd
, EM_SCROLL
, SB_LINEDOWN
, 0);
1437 SendMessageW(hTextWnd
, EM_SCROLL
, SB_PAGEUP
, 0);
1440 SendMessageW(hTextWnd
, EM_SCROLL
, SB_PAGEDOWN
, 0);
1449 if (wParam
== CTL_ID_TEXT
)
1453 switch (((NMHDR
*)lParam
)->code
)
1457 const MSGFILTER
* msgf
= (const MSGFILTER
*)lParam
;
1461 if (msgf
->wParam
== VK_ESCAPE
)
1462 WINHELP_ReleaseWindow((WINHELP_WINDOW
*)GetWindowLongPtrW(hWnd
, 0));
1464 case WM_RBUTTONDOWN
:
1469 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1470 hMenu
= LoadMenuW(Globals
.hInstance
, MAKEINTRESOURCEW(CONTEXT_MENU
));
1471 switch (win
->font_scale
)
1474 CheckMenuItem(hMenu
, MNID_CTXT_FONTS_SMALL
,
1475 MF_BYCOMMAND
|MF_CHECKED
);
1478 WINE_FIXME("Unsupported %d\n", win
->font_scale
);
1481 CheckMenuItem(hMenu
, MNID_CTXT_FONTS_NORMAL
,
1482 MF_BYCOMMAND
|MF_CHECKED
);
1485 CheckMenuItem(hMenu
, MNID_CTXT_FONTS_LARGE
,
1486 MF_BYCOMMAND
|MF_CHECKED
);
1489 pt
.x
= (int)(short)LOWORD(msgf
->lParam
);
1490 pt
.y
= (int)(short)HIWORD(msgf
->lParam
);
1491 ClientToScreen(msgf
->nmhdr
.hwndFrom
, &pt
);
1492 TrackPopupMenu(GetSubMenu(hMenu
, 0), TPM_LEFTALIGN
|TPM_TOPALIGN
,
1493 pt
.x
, pt
.y
, 0, hWnd
, NULL
);
1498 return WINHELP_HandleTextMouse((WINHELP_WINDOW
*)GetWindowLongPtrW(hWnd
, 0),
1499 msgf
->msg
, msgf
->lParam
);
1504 case EN_REQUESTRESIZE
:
1505 rc
= ((REQRESIZE
*)lParam
)->rc
;
1506 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1507 AdjustWindowRect(&rc
, GetWindowLongW(win
->hMainWnd
, GWL_STYLE
),
1509 SetWindowPos(win
->hMainWnd
, HWND_TOP
, 0, 0,
1510 rc
.right
- rc
.left
, rc
.bottom
- rc
.top
,
1511 SWP_NOMOVE
| SWP_NOZORDER
);
1512 WINHELP_LayoutMainWindow(win
);
1518 case WM_INITMENUPOPUP
:
1519 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1520 CheckMenuItem((HMENU
)wParam
, MNID_OPTS_FONTS_SMALL
,
1521 (win
->font_scale
== 0) ? MF_CHECKED
: MF_UNCHECKED
);
1522 CheckMenuItem((HMENU
)wParam
, MNID_OPTS_FONTS_NORMAL
,
1523 (win
->font_scale
== 1) ? MF_CHECKED
: MF_UNCHECKED
);
1524 CheckMenuItem((HMENU
)wParam
, MNID_OPTS_FONTS_LARGE
,
1525 (win
->font_scale
== 2) ? MF_CHECKED
: MF_UNCHECKED
);
1528 win
= (WINHELP_WINDOW
*) GetWindowLongPtrW(hWnd
, 0);
1529 WINHELP_DeleteWindow(win
);
1532 return DefWindowProcA(hWnd
, msg
, wParam
, lParam
);
1535 /**************************************************************************
1536 * WINHELP_CreateIndexWindow
1538 * Displays a dialog with keywords of current help file.
1541 BOOL
WINHELP_CreateIndexWindow(BOOL is_search
)
1543 HPROPSHEETPAGE psPage
[3];
1545 PROPSHEETHEADERA psHead
;
1546 struct index_data id
;
1549 if (Globals
.active_win
&& Globals
.active_win
->page
&& Globals
.active_win
->page
->file
)
1550 id
.hlpfile
= Globals
.active_win
->page
->file
;
1554 if (id
.hlpfile
->kwbtree
== NULL
)
1556 WINE_TRACE("No index provided\n");
1560 InitCommonControls();
1563 memset(&psp
, 0, sizeof(psp
));
1564 psp
.dwSize
= sizeof(psp
);
1566 psp
.hInstance
= Globals
.hInstance
;
1568 psp
.u
.pszTemplate
= MAKEINTRESOURCEA(IDD_INDEX
);
1569 psp
.lParam
= (LPARAM
)&id
;
1570 psp
.pfnDlgProc
= WINHELP_IndexDlgProc
;
1571 psPage
[0] = CreatePropertySheetPageA(&psp
);
1573 psp
.u
.pszTemplate
= MAKEINTRESOURCEA(IDD_SEARCH
);
1574 psp
.lParam
= (LPARAM
)&id
;
1575 psp
.pfnDlgProc
= WINHELP_SearchDlgProc
;
1576 psPage
[1] = CreatePropertySheetPageA(&psp
);
1578 memset(&psHead
, 0, sizeof(psHead
));
1579 psHead
.dwSize
= sizeof(psHead
);
1581 LoadStringA(Globals
.hInstance
, STID_PSH_INDEX
, buf
, sizeof(buf
));
1582 strcat(buf
, Globals
.active_win
->info
->caption
);
1584 psHead
.pszCaption
= buf
;
1586 psHead
.u2
.nStartPage
= is_search
? 1 : 0;
1587 psHead
.hwndParent
= Globals
.active_win
->hMainWnd
;
1588 psHead
.u3
.phpage
= psPage
;
1589 psHead
.dwFlags
= PSH_NOAPPLYNOW
;
1591 PropertySheetA(&psHead
);
1594 WINE_TRACE("got %ld as an offset\n", id
.offset
);
1595 WINHELP_OpenHelpWindow(HLPFILE_PageByOffset
, id
.hlpfile
, id
.offset
,
1596 Globals
.active_win
->info
, SW_NORMAL
);
1601 /***********************************************************************
1603 * RegisterWinClasses
1605 static BOOL
WINHELP_RegisterWinClasses(void)
1607 WNDCLASSEXA class_main
, class_button_box
, class_history
;
1609 class_main
.cbSize
= sizeof(class_main
);
1610 class_main
.style
= CS_HREDRAW
| CS_VREDRAW
;
1611 class_main
.lpfnWndProc
= WINHELP_MainWndProc
;
1612 class_main
.cbClsExtra
= 0;
1613 class_main
.cbWndExtra
= sizeof(WINHELP_WINDOW
*);
1614 class_main
.hInstance
= Globals
.hInstance
;
1615 class_main
.hIcon
= LoadIconW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINHELP
));
1616 class_main
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
1617 class_main
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+1);
1618 class_main
.lpszMenuName
= 0;
1619 class_main
.lpszClassName
= MAIN_WIN_CLASS_NAME
;
1620 class_main
.hIconSm
= LoadImageW(Globals
.hInstance
, MAKEINTRESOURCEW(IDI_WINHELP
), IMAGE_ICON
,
1621 GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
1624 class_button_box
= class_main
;
1625 class_button_box
.lpfnWndProc
= WINHELP_ButtonBoxWndProc
;
1626 class_button_box
.cbWndExtra
= 0;
1627 class_button_box
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+1);
1628 class_button_box
.lpszClassName
= BUTTON_BOX_WIN_CLASS_NAME
;
1630 class_history
= class_main
;
1631 class_history
.lpfnWndProc
= WINHELP_HistoryWndProc
;
1632 class_history
.lpszClassName
= HISTORY_WIN_CLASS_NAME
;
1634 return (RegisterClassExA(&class_main
) &&
1635 RegisterClassExA(&class_button_box
) &&
1636 RegisterClassExA(&class_history
));
1639 /***********************************************************************
1643 int PASCAL
WinMain(HINSTANCE hInstance
, HINSTANCE prev
, LPSTR cmdline
, int show
)
1648 static CHAR default_wndname
[] = "main";
1649 LPSTR wndname
= default_wndname
;
1653 Globals
.hInstance
= hInstance
;
1655 if (LoadLibraryA("riched20.dll") == NULL
)
1656 return MessageBoxW(0, MAKEINTRESOURCEW(STID_NO_RICHEDIT
),
1657 MAKEINTRESOURCEW(STID_WHERROR
), MB_OK
);
1660 while (*cmdline
&& (*cmdline
== ' ' || *cmdline
== '-'))
1664 if (*cmdline
++ == ' ') continue;
1667 if (option
) cmdline
++;
1668 while (*cmdline
== ' ') cmdline
++;
1674 while (*cmdline
&& *cmdline
!= ' ') cmdline
++;
1675 if (*cmdline
) *cmdline
++ = '\0';
1676 lHash
= HLPFILE_Hash(topic_id
);
1681 Globals
.wVersion
= option
- '0';
1686 Globals
.isBook
= FALSE
;
1690 WINE_FIXME("Unsupported cmd line: %s\n", debugstr_a(cmdline
));
1695 /* Create primary window */
1696 if (!WINHELP_RegisterWinClasses())
1698 WINE_FIXME("Couldn't register classes\n");
1705 if ((*cmdline
== '"') && (ptr
= strchr(cmdline
+1, '"')))
1710 if ((ptr
= strchr(cmdline
, '>')))
1715 hlpfile
= WINHELP_LookupHelpFile(cmdline
);
1716 if (!hlpfile
) return 0;
1718 else hlpfile
= NULL
;
1719 WINHELP_OpenHelpWindow(HLPFILE_PageByHash
, hlpfile
, lHash
,
1720 WINHELP_GetWindowInfo(hlpfile
, wndname
), show
);
1723 hAccel
= LoadAcceleratorsW(hInstance
, MAKEINTRESOURCEW(MAIN_ACCEL
));
1724 while ((Globals
.win_list
|| Globals
.active_popup
) && GetMessageW(&msg
, 0, 0, 0))
1726 HWND hWnd
= Globals
.active_win
? Globals
.active_win
->hMainWnd
: NULL
;
1727 if (!TranslateAcceleratorW(hWnd
, hAccel
, &msg
))
1729 TranslateMessage(&msg
);
1730 DispatchMessageW(&msg
);
1733 for (dll
= Globals
.dlls
; dll
; dll
= dll
->next
)
1735 if (dll
->class & DC_INITTERM
) dll
->handler(DW_TERM
, 0, 0);