2 * Help Viewer Implementation
4 * Copyright 2005 James Hawkins
5 * Copyright 2007 Jacek Caban for CodeWeavers
6 * Copyright 2011 Owen Rudge for CodeWeavers
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 static LRESULT
Help_OnSize(HWND hWnd
);
29 static void ExpandContract(HHInfo
*pHHInfo
);
31 /* Window type defaults */
33 #define WINTYPE_DEFAULT_X 280
34 #define WINTYPE_DEFAULT_Y 100
35 #define WINTYPE_DEFAULT_WIDTH 740
36 #define WINTYPE_DEFAULT_HEIGHT 640
37 #define WINTYPE_DEFAULT_NAVWIDTH 250
39 #define TAB_TOP_PADDING 8
40 #define TAB_RIGHT_PADDING 4
42 #define EDIT_HEIGHT 20
44 struct list window_list
= LIST_INIT(window_list
);
46 static const WCHAR szEmpty
[] = {0};
48 struct html_encoded_symbol
{
49 const char *html_code
;
54 * Table mapping the conversion between HTML encoded symbols and their ANSI code page equivalent.
55 * Note: Add additional entries in proper alphabetical order (a binary search is used on this table).
57 static struct html_encoded_symbol html_encoded_symbols
[] =
161 static inline BOOL
navigation_visible(HHInfo
*info
)
163 return ((info
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
) && !info
->WinType
.fNotExpanded
);
166 /* Loads a string from the resource file */
167 static LPWSTR
HH_LoadString(DWORD dwID
)
169 LPWSTR string
= NULL
;
170 LPCWSTR stringresource
;
173 iSize
= LoadStringW(hhctrl_hinstance
, dwID
, (LPWSTR
)&stringresource
, 0);
175 string
= heap_alloc((iSize
+ 2) * sizeof(WCHAR
)); /* some strings (tab text) needs double-null termination */
176 memcpy(string
, stringresource
, iSize
*sizeof(WCHAR
));
182 static HRESULT
navigate_url(HHInfo
*info
, LPCWSTR surl
)
187 TRACE("%s\n", debugstr_w(surl
));
189 V_VT(&url
) = VT_BSTR
;
190 V_BSTR(&url
) = SysAllocString(surl
);
192 hres
= IWebBrowser2_Navigate2(info
->web_browser
->web_browser
, &url
, 0, 0, 0, 0);
197 TRACE("Navigation failed: %08x\n", hres
);
202 BOOL
NavigateToUrl(HHInfo
*info
, LPCWSTR surl
)
208 static const WCHAR url_indicator
[] = {':', '/', '/', 0};
210 TRACE("%s\n", debugstr_w(surl
));
212 if (strstrW(surl
, url_indicator
)) {
213 hres
= navigate_url(info
, surl
);
216 } /* look up in chm if it doesn't look like a full url */
218 SetChmPath(&chm_path
, info
->pCHMInfo
->szFile
, surl
);
219 ret
= NavigateToChm(info
, chm_path
.chm_file
, chm_path
.chm_index
);
221 heap_free(chm_path
.chm_file
);
222 heap_free(chm_path
.chm_index
);
227 static BOOL
AppendFullPathURL(LPCWSTR file
, LPWSTR buf
, LPCWSTR index
)
229 static const WCHAR url_format
[] =
230 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
231 static const WCHAR slash
[] = {'/',0};
232 static const WCHAR empty
[] = {0};
233 WCHAR full_path
[MAX_PATH
];
235 TRACE("%s %p %s\n", debugstr_w(file
), buf
, debugstr_w(index
));
237 if(!GetFullPathNameW(file
, sizeof(full_path
)/sizeof(full_path
[0]), full_path
, NULL
)) {
238 WARN("GetFullPathName failed: %u\n", GetLastError());
242 wsprintfW(buf
, url_format
, full_path
, (!index
|| index
[0] == '/') ? empty
: slash
, index
);
246 BOOL
NavigateToChm(HHInfo
*info
, LPCWSTR file
, LPCWSTR index
)
248 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
250 TRACE("%p %s %s\n", info
, debugstr_w(file
), debugstr_w(index
));
252 if ((!info
->web_browser
) || !AppendFullPathURL(file
, buf
, index
))
255 return SUCCEEDED(navigate_url(info
, buf
));
258 static void DoSync(HHInfo
*info
)
260 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
264 hres
= IWebBrowser2_get_LocationURL(info
->web_browser
->web_browser
, &url
);
268 WARN("get_LocationURL failed: %08x\n", hres
);
272 /* If we're not currently viewing a page in the active .chm file, abort */
273 if ((!AppendFullPathURL(info
->WinType
.pszFile
, buf
, NULL
)) || (lstrlenW(buf
) > lstrlenW(url
)))
279 if (lstrcmpiW(buf
, url
) > 0)
281 static const WCHAR delimW
[] = {':',':','/',0};
284 index
= strstrW(url
, delimW
);
287 ActivateContentTopic(info
->tabs
[TAB_CONTENTS
].hwnd
, index
+ 3, info
->content
); /* skip over ::/ */
295 #define SIZEBAR_WIDTH 4
297 static const WCHAR szSizeBarClass
[] = {
298 'H','H',' ','S','i','z','e','B','a','r',0
301 /* Draw the SizeBar */
302 static void SB_OnPaint(HWND hWnd
)
308 hdc
= BeginPaint(hWnd
, &ps
);
310 GetClientRect(hWnd
, &rc
);
315 FrameRect(hdc
, &rc
, GetStockObject(GRAY_BRUSH
));
317 /* white highlight */
318 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
319 MoveToEx(hdc
, rc
.right
, 1, NULL
);
321 LineTo(hdc
, 1, rc
.bottom
- 1);
324 MoveToEx(hdc
, 0, rc
.bottom
, NULL
);
325 LineTo(hdc
, rc
.right
, rc
.bottom
);
330 static void SB_OnLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
335 static void SB_OnLButtonUp(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
337 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
340 pt
.x
= (short)LOWORD(lParam
);
341 pt
.y
= (short)HIWORD(lParam
);
343 /* update the window sizes */
344 pHHInfo
->WinType
.iNavWidth
+= pt
.x
;
350 static void SB_OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
352 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
353 if (!(wParam
& MK_LBUTTON
))
357 static LRESULT CALLBACK
SizeBar_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
362 SB_OnLButtonDown(hWnd
, wParam
, lParam
);
365 SB_OnLButtonUp(hWnd
, wParam
, lParam
);
368 SB_OnMouseMove(hWnd
, wParam
, lParam
);
374 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
380 static void HH_RegisterSizeBarClass(HHInfo
*pHHInfo
)
384 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
386 wcex
.lpfnWndProc
= SizeBar_WndProc
;
388 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
389 wcex
.hInstance
= hhctrl_hinstance
;
390 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
391 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_SIZEWE
);
392 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
393 wcex
.lpszMenuName
= NULL
;
394 wcex
.lpszClassName
= szSizeBarClass
;
395 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
397 RegisterClassExW(&wcex
);
400 static void SB_GetSizeBarRect(HHInfo
*info
, RECT
*rc
)
402 RECT rectWND
, rectTB
, rectNP
;
404 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
405 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
406 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
408 SetRect(rc
, rectNP
.right
, rectTB
.bottom
, SIZEBAR_WIDTH
, rectWND
.bottom
- rectTB
.bottom
);
411 static BOOL
HH_AddSizeBar(HHInfo
*pHHInfo
)
414 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
415 DWORD dwStyles
= WS_CHILDWINDOW
| WS_OVERLAPPED
;
416 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
419 if (navigation_visible(pHHInfo
))
420 dwStyles
|= WS_VISIBLE
;
422 SB_GetSizeBarRect(pHHInfo
, &rc
);
424 hWnd
= CreateWindowExW(dwExStyles
, szSizeBarClass
, szEmpty
, dwStyles
,
425 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
426 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
430 /* store the pointer to the HH info struct */
431 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
433 pHHInfo
->hwndSizeBar
= hWnd
;
439 static const WCHAR szChildClass
[] = {
440 'H','H',' ','C','h','i','l','d',0
443 static LRESULT
Child_OnPaint(HWND hWnd
)
449 hdc
= BeginPaint(hWnd
, &ps
);
451 /* Only paint the Navigation pane, identified by the fact
452 * that it has a child window
454 if (GetWindow(hWnd
, GW_CHILD
))
456 GetClientRect(hWnd
, &rc
);
458 /* set the border color */
459 SelectObject(hdc
, GetStockObject(DC_PEN
));
460 SetDCPenColor(hdc
, GetSysColor(COLOR_BTNSHADOW
));
462 /* Draw the top border */
463 LineTo(hdc
, rc
.right
, 0);
465 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
466 MoveToEx(hdc
, 0, 1, NULL
);
467 LineTo(hdc
, rc
.right
, 1);
475 static void ResizeTabChild(HHInfo
*info
, int tab
)
477 HWND hwnd
= info
->tabs
[tab
].hwnd
;
482 GetClientRect(info
->WinType
.hwndNavigation
, &rect
);
483 SendMessageW(info
->hwndTabCtrl
, TCM_GETITEMRECT
, 0, (LPARAM
)&tabrc
);
484 cnt
= SendMessageW(info
->hwndTabCtrl
, TCM_GETROWCOUNT
, 0, 0);
486 rect
.left
= TAB_MARGIN
;
487 rect
.top
= TAB_TOP_PADDING
+ cnt
*(tabrc
.bottom
-tabrc
.top
) + TAB_MARGIN
;
488 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
489 rect
.bottom
-= TAB_MARGIN
;
490 width
= rect
.right
-rect
.left
;
491 height
= rect
.bottom
-rect
.top
;
493 SetWindowPos(hwnd
, NULL
, rect
.left
, rect
.top
, width
, height
,
494 SWP_NOZORDER
| SWP_NOACTIVATE
);
499 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
500 int border_width
= GetSystemMetrics(SM_CXBORDER
);
501 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
503 /* Resize the tab widget column to perfectly fit the tab window and
504 * leave sufficient space for the scroll widget.
506 SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_SETCOLUMNWIDTH
, 0,
507 width
-scroll_width
-2*border_width
-2*edge_width
);
512 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
513 int border_width
= GetSystemMetrics(SM_CXBORDER
);
514 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
517 SetWindowPos(info
->search
.hwndEdit
, NULL
, 0, top_pos
, width
,
518 EDIT_HEIGHT
, SWP_NOZORDER
| SWP_NOACTIVATE
);
519 top_pos
+= EDIT_HEIGHT
+ TAB_MARGIN
;
520 SetWindowPos(info
->search
.hwndList
, NULL
, 0, top_pos
, width
,
521 height
-top_pos
, SWP_NOZORDER
| SWP_NOACTIVATE
);
522 /* Resize the tab widget column to perfectly fit the tab window and
523 * leave sufficient space for the scroll widget.
525 SendMessageW(info
->search
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
526 width
-scroll_width
-2*border_width
-2*edge_width
);
533 static LRESULT
Child_OnSize(HWND hwnd
)
535 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
538 if(!info
|| hwnd
!= info
->WinType
.hwndNavigation
)
541 GetClientRect(hwnd
, &rect
);
542 SetWindowPos(info
->hwndTabCtrl
, HWND_TOP
, 0, 0,
543 rect
.right
- TAB_RIGHT_PADDING
,
544 rect
.bottom
- TAB_TOP_PADDING
, SWP_NOMOVE
);
546 ResizeTabChild(info
, TAB_CONTENTS
);
547 ResizeTabChild(info
, TAB_INDEX
);
548 ResizeTabChild(info
, TAB_SEARCH
);
552 static LRESULT
OnTabChange(HWND hwnd
)
554 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
555 int tab_id
, tab_index
, i
;
562 if(info
->tabs
[info
->current_tab
].hwnd
)
563 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_HIDE
);
565 tab_id
= (int) SendMessageW(info
->hwndTabCtrl
, TCM_GETCURSEL
, 0, 0);
566 /* convert the ID of the tab to an index in our tab list */
568 for (i
=0; i
<TAB_NUMTABS
; i
++)
570 if (info
->tabs
[i
].id
== tab_id
)
578 FIXME("Tab ID %d does not correspond to a valid index in the tab list.\n", tab_id
);
581 info
->current_tab
= tab_index
;
583 if(info
->tabs
[info
->current_tab
].hwnd
)
584 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_SHOW
);
589 static LRESULT
OnTopicChange(HHInfo
*info
, void *user_data
)
591 LPCWSTR chmfile
= NULL
, name
= NULL
, local
= NULL
;
596 if(!user_data
|| !info
)
599 switch (info
->current_tab
)
602 citer
= (ContentItem
*) user_data
;
604 local
= citer
->local
;
606 if(citer
->merge
.chm_file
) {
607 chmfile
= citer
->merge
.chm_file
;
610 citer
= citer
->parent
;
614 iiter
= (IndexItem
*) user_data
;
615 if(iiter
->nItems
== 0) {
616 FIXME("No entries for this item!\n");
619 if(iiter
->nItems
> 1) {
623 SendMessageW(info
->popup
.hwndList
, LVM_DELETEALLITEMS
, 0, 0);
624 for(i
=0;i
<iiter
->nItems
;i
++) {
625 IndexSubItem
*item
= &iiter
->items
[i
];
626 WCHAR
*name
= iiter
->keyword
;
629 item
->name
= GetDocumentTitle(info
->pCHMInfo
, item
->local
);
632 memset(&lvi
, 0, sizeof(lvi
));
634 lvi
.mask
= LVIF_TEXT
|LVIF_PARAM
;
635 lvi
.cchTextMax
= strlenW(name
)+1;
637 lvi
.lParam
= (LPARAM
) item
;
638 SendMessageW(info
->popup
.hwndList
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvi
);
640 ShowWindow(info
->popup
.hwndPopup
, SW_SHOW
);
643 name
= iiter
->items
[0].name
;
644 local
= iiter
->items
[0].local
;
645 chmfile
= iiter
->merge
.chm_file
;
648 siter
= (SearchItem
*) user_data
;
649 name
= siter
->filename
;
650 local
= siter
->filename
;
651 chmfile
= info
->pCHMInfo
->szFile
;
654 FIXME("Unhandled operation for this tab!\n");
660 FIXME("No help file found for this item!\n");
664 TRACE("name %s loal %s\n", debugstr_w(name
), debugstr_w(local
));
666 NavigateToChm(info
, chmfile
, local
);
670 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
671 static LRESULT CALLBACK
EditChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
673 WNDPROC editWndProc
= (WNDPROC
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
675 if(message
== WM_KEYUP
&& wParam
== VK_RETURN
)
679 nmhdr
.hwndFrom
= hWnd
;
680 nmhdr
.code
= NM_RETURN
;
681 SendMessageW(GetParent(GetParent(hWnd
)), WM_NOTIFY
, wParam
, (LPARAM
)&nmhdr
);
683 return editWndProc(hWnd
, message
, wParam
, lParam
);
686 static LRESULT CALLBACK
Child_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
691 return Child_OnPaint(hWnd
);
693 return Child_OnSize(hWnd
);
695 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
696 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
698 switch(nmhdr
->code
) {
700 return OnTabChange(hWnd
);
701 case TVN_SELCHANGEDW
:
702 return OnTopicChange(info
, (void*)((NMTREEVIEWW
*)lParam
)->itemNew
.lParam
);
703 case TVN_ITEMEXPANDINGW
: {
704 TVITEMW
*item
= &((NMTREEVIEWW
*)lParam
)->itemNew
;
705 HWND hwndTreeView
= info
->tabs
[TAB_CONTENTS
].hwnd
;
707 item
->mask
= TVIF_IMAGE
|TVIF_SELECTEDIMAGE
;
708 if (item
->state
& TVIS_EXPANDED
)
710 item
->iImage
= HHTV_FOLDER
;
711 item
->iSelectedImage
= HHTV_FOLDER
;
715 item
->iImage
= HHTV_OPENFOLDER
;
716 item
->iSelectedImage
= HHTV_OPENFOLDER
;
718 SendMessageW(hwndTreeView
, TVM_SETITEMW
, 0, (LPARAM
)item
);
724 switch(info
->current_tab
)
727 return OnTopicChange(info
, (void*)((NMITEMACTIVATE
*)lParam
)->lParam
);
729 return OnTopicChange(info
, (void*)((NMITEMACTIVATE
*)lParam
)->lParam
);
735 switch(info
->current_tab
) {
737 HWND hwndList
= info
->tabs
[TAB_INDEX
].hwnd
;
740 lvItem
.iItem
= (int) SendMessageW(hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
741 lvItem
.mask
= TVIF_PARAM
;
742 SendMessageW(hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
743 OnTopicChange(info
, (void*) lvItem
.lParam
);
747 if(nmhdr
->hwndFrom
== info
->search
.hwndEdit
) {
751 len
= GetWindowTextA(info
->search
.hwndEdit
, needle
, sizeof(needle
));
754 FIXME("Unable to get search text.\n");
757 /* Convert the requested text for comparison later against the
758 * lower case version of HTML file contents.
761 needle
[i
] = tolower(needle
[i
]);
762 InitSearch(info
, needle
);
764 }else if(nmhdr
->hwndFrom
== info
->search
.hwndList
) {
765 HWND hwndList
= info
->search
.hwndList
;
768 lvItem
.iItem
= (int) SendMessageW(hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
769 lvItem
.mask
= TVIF_PARAM
;
770 SendMessageW(hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
771 OnTopicChange(info
, (void*) lvItem
.lParam
);
782 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
788 static void HH_RegisterChildWndClass(HHInfo
*pHHInfo
)
792 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
794 wcex
.lpfnWndProc
= Child_WndProc
;
796 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
797 wcex
.hInstance
= hhctrl_hinstance
;
798 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
799 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
800 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
801 wcex
.lpszMenuName
= NULL
;
802 wcex
.lpszClassName
= szChildClass
;
803 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
805 RegisterClassExW(&wcex
);
812 static void DisplayPopupMenu(HHInfo
*info
)
815 TBBUTTONINFOW button
;
821 menu
= LoadMenuW(hhctrl_hinstance
, MAKEINTRESOURCEW(MENU_POPUP
));
826 submenu
= GetSubMenu(menu
, 0);
828 /* Update the Show/Hide menu item */
829 item
.cbSize
= sizeof(MENUITEMINFOW
);
830 item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
831 item
.fType
= MFT_STRING
;
832 item
.fState
= MF_ENABLED
;
834 if (info
->WinType
.fNotExpanded
)
835 item
.dwTypeData
= HH_LoadString(IDS_SHOWTABS
);
837 item
.dwTypeData
= HH_LoadString(IDS_HIDETABS
);
839 SetMenuItemInfoW(submenu
, IDTB_EXPAND
, FALSE
, &item
);
840 heap_free(item
.dwTypeData
);
842 /* Find the index toolbar button */
843 button
.cbSize
= sizeof(TBBUTTONINFOW
);
844 button
.dwMask
= TBIF_COMMAND
;
845 index
= SendMessageW(info
->WinType
.hwndToolBar
, TB_GETBUTTONINFOW
, IDTB_OPTIONS
, (LPARAM
) &button
);
851 SendMessageW(info
->WinType
.hwndToolBar
, TB_GETITEMRECT
, index
, (LPARAM
) &rect
);
853 coords
.x
= rect
.left
;
854 coords
.y
= rect
.bottom
;
856 ClientToScreen(info
->WinType
.hwndToolBar
, &coords
);
857 TrackPopupMenu(submenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_LEFTBUTTON
| TPM_NOANIMATION
, coords
.x
, coords
.y
, 0, info
->WinType
.hwndHelp
, NULL
);
860 static void TB_OnClick(HWND hWnd
, DWORD dwID
)
862 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
867 DoPageAction(info
->web_browser
, WB_STOP
);
870 DoPageAction(info
->web_browser
, WB_REFRESH
);
873 DoPageAction(info
->web_browser
, WB_GOBACK
);
876 NavigateToChm(info
, info
->pCHMInfo
->szFile
, info
->WinType
.pszHome
);
879 DoPageAction(info
->web_browser
, WB_GOFORWARD
);
882 DoPageAction(info
->web_browser
, WB_PRINT
);
886 ExpandContract(info
);
892 DisplayPopupMenu(info
);
900 /* These are officially unimplemented as of the Windows 7 SDK */
902 case IDTB_BROWSE_FWD
:
903 case IDTB_BROWSE_BACK
:
914 static void TB_AddButton(TBBUTTON
*pButtons
, DWORD dwIndex
, DWORD dwID
, DWORD dwBitmap
)
916 pButtons
[dwIndex
].iBitmap
= dwBitmap
;
917 pButtons
[dwIndex
].idCommand
= dwID
;
918 pButtons
[dwIndex
].fsState
= TBSTATE_ENABLED
;
919 pButtons
[dwIndex
].fsStyle
= BTNS_BUTTON
;
920 pButtons
[dwIndex
].dwData
= 0;
921 pButtons
[dwIndex
].iString
= 0;
924 static void TB_AddButtonsFromFlags(HHInfo
*pHHInfo
, TBBUTTON
*pButtons
, DWORD dwButtonFlags
, LPDWORD pdwNumButtons
)
926 int nHistBitmaps
= 0, nStdBitmaps
= 0, nHHBitmaps
= 0;
927 HWND hToolbar
= pHHInfo
->WinType
.hwndToolBar
;
932 tbAB
.hInst
= HINST_COMMCTRL
;
933 tbAB
.nID
= IDB_HIST_LARGE_COLOR
;
934 nHistBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
935 tbAB
.nID
= IDB_STD_LARGE_COLOR
;
936 nStdBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
937 /* hhctrl.ocx bitmaps */
938 tbAB
.hInst
= hhctrl_hinstance
;
939 tbAB
.nID
= IDB_HHTOOLBAR
;
940 nHHBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, HHTB_NUMBITMAPS
, (LPARAM
)&tbAB
);
944 unsupported
= dwButtonFlags
& (HHWIN_BUTTON_BROWSE_FWD
|
945 HHWIN_BUTTON_BROWSE_BCK
| HHWIN_BUTTON_NOTES
| HHWIN_BUTTON_CONTENTS
|
946 HHWIN_BUTTON_INDEX
| HHWIN_BUTTON_SEARCH
| HHWIN_BUTTON_HISTORY
|
947 HHWIN_BUTTON_FAVORITES
| HHWIN_BUTTON_JUMP1
| HHWIN_BUTTON_JUMP2
|
948 HHWIN_BUTTON_ZOOM
| HHWIN_BUTTON_TOC_NEXT
| HHWIN_BUTTON_TOC_PREV
);
950 FIXME("got asked for unsupported buttons: %06x\n", unsupported
);
952 if (dwButtonFlags
& HHWIN_BUTTON_EXPAND
)
954 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_EXPAND
, nHHBitmaps
+ HHTB_EXPAND
);
955 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_CONTRACT
, nHHBitmaps
+ HHTB_CONTRACT
);
957 if (pHHInfo
->WinType
.fNotExpanded
)
958 pButtons
[1].fsState
|= TBSTATE_HIDDEN
;
960 pButtons
[0].fsState
|= TBSTATE_HIDDEN
;
963 if (dwButtonFlags
& HHWIN_BUTTON_BACK
)
964 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_BACK
, nHistBitmaps
+ HIST_BACK
);
966 if (dwButtonFlags
& HHWIN_BUTTON_FORWARD
)
967 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_FORWARD
, nHistBitmaps
+ HIST_FORWARD
);
969 if (dwButtonFlags
& HHWIN_BUTTON_STOP
)
970 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_STOP
, nHHBitmaps
+ HHTB_STOP
);
972 if (dwButtonFlags
& HHWIN_BUTTON_REFRESH
)
973 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_REFRESH
, nHHBitmaps
+ HHTB_REFRESH
);
975 if (dwButtonFlags
& HHWIN_BUTTON_HOME
)
976 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_HOME
, nHHBitmaps
+ HHTB_HOME
);
978 if (dwButtonFlags
& HHWIN_BUTTON_SYNC
)
979 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_SYNC
, nHHBitmaps
+ HHTB_SYNC
);
981 if (dwButtonFlags
& HHWIN_BUTTON_OPTIONS
)
982 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_OPTIONS
, nStdBitmaps
+ STD_PROPERTIES
);
984 if (dwButtonFlags
& HHWIN_BUTTON_PRINT
)
985 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_PRINT
, nStdBitmaps
+ STD_PRINT
);
988 static BOOL
HH_AddToolbar(HHInfo
*pHHInfo
)
991 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
993 TBBUTTON buttons
[IDTB_TOC_PREV
- IDTB_EXPAND
];
994 DWORD dwStyles
, dwExStyles
;
995 DWORD dwNumButtons
, dwIndex
;
997 if (pHHInfo
->WinType
.fsWinProperties
& HHWIN_PARAM_TB_FLAGS
)
998 toolbarFlags
= pHHInfo
->WinType
.fsToolBarFlags
;
1000 toolbarFlags
= HHWIN_DEF_BUTTONS
;
1002 dwStyles
= WS_CHILDWINDOW
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
;
1003 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1005 hToolbar
= CreateWindowExW(dwExStyles
, TOOLBARCLASSNAMEW
, NULL
, dwStyles
,
1006 0, 0, 0, 0, hwndParent
, NULL
,
1007 hhctrl_hinstance
, NULL
);
1010 pHHInfo
->WinType
.hwndToolBar
= hToolbar
;
1012 SendMessageW(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(ICON_SIZE
, ICON_SIZE
));
1013 SendMessageW(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
1014 SendMessageW(hToolbar
, WM_SETFONT
, (WPARAM
)pHHInfo
->hFont
, TRUE
);
1016 TB_AddButtonsFromFlags(pHHInfo
, buttons
, toolbarFlags
, &dwNumButtons
);
1018 for (dwIndex
= 0; dwIndex
< dwNumButtons
; dwIndex
++)
1020 LPWSTR szBuf
= HH_LoadString(buttons
[dwIndex
].idCommand
);
1021 DWORD dwLen
= strlenW(szBuf
);
1022 szBuf
[dwLen
+ 1] = 0; /* Double-null terminate */
1024 buttons
[dwIndex
].iString
= (DWORD
)SendMessageW(hToolbar
, TB_ADDSTRINGW
, 0, (LPARAM
)szBuf
);
1028 SendMessageW(hToolbar
, TB_ADDBUTTONSW
, dwNumButtons
, (LPARAM
)buttons
);
1029 SendMessageW(hToolbar
, TB_AUTOSIZE
, 0, 0);
1030 if (pHHInfo
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
)
1031 ShowWindow(hToolbar
, SW_SHOW
);
1036 /* Navigation Pane */
1038 static void NP_GetNavigationRect(HHInfo
*pHHInfo
, RECT
*rc
)
1040 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1041 HWND hwndToolbar
= pHHInfo
->WinType
.hwndToolBar
;
1042 RECT rectWND
, rectTB
;
1044 GetClientRect(hwndParent
, &rectWND
);
1045 GetClientRect(hwndToolbar
, &rectTB
);
1048 rc
->top
= rectTB
.bottom
;
1049 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
1051 if (!(pHHInfo
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1052 pHHInfo
->WinType
.iNavWidth
== 0)
1054 pHHInfo
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1057 rc
->right
= pHHInfo
->WinType
.iNavWidth
;
1060 static DWORD
NP_CreateTab(HINSTANCE hInstance
, HWND hwndTabCtrl
, DWORD index
)
1063 LPWSTR tabText
= HH_LoadString(index
);
1066 tie
.mask
= TCIF_TEXT
;
1067 tie
.pszText
= tabText
;
1069 ret
= SendMessageW( hwndTabCtrl
, TCM_INSERTITEMW
, index
, (LPARAM
)&tie
);
1075 static BOOL
HH_AddNavigationPane(HHInfo
*info
)
1077 HWND hWnd
, hwndTabCtrl
;
1078 HWND hwndParent
= info
->WinType
.hwndHelp
;
1079 DWORD dwStyles
= WS_CHILDWINDOW
;
1080 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1083 if (navigation_visible(info
))
1084 dwStyles
|= WS_VISIBLE
;
1086 NP_GetNavigationRect(info
, &rc
);
1088 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1089 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1090 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1094 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1096 hwndTabCtrl
= CreateWindowExW(dwExStyles
, WC_TABCONTROLW
, szEmpty
, dwStyles
| WS_VISIBLE
,
1098 rc
.right
- TAB_RIGHT_PADDING
,
1099 rc
.bottom
- TAB_TOP_PADDING
,
1100 hWnd
, NULL
, hhctrl_hinstance
, NULL
);
1104 if (*info
->WinType
.pszToc
)
1105 info
->tabs
[TAB_CONTENTS
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_CONTENTS
);
1107 if (*info
->WinType
.pszIndex
)
1108 info
->tabs
[TAB_INDEX
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_INDEX
);
1110 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TAB_SEARCH
)
1111 info
->tabs
[TAB_SEARCH
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_SEARCH
);
1113 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TAB_FAVORITES
)
1114 info
->tabs
[TAB_FAVORITES
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_FAVORITES
);
1116 SendMessageW(hwndTabCtrl
, WM_SETFONT
, (WPARAM
)info
->hFont
, TRUE
);
1118 info
->hwndTabCtrl
= hwndTabCtrl
;
1119 info
->WinType
.hwndNavigation
= hWnd
;
1125 static void HP_GetHTMLRect(HHInfo
*info
, RECT
*rc
)
1127 RECT rectTB
, rectWND
, rectNP
, rectSB
;
1129 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
1130 GetClientRect(info
->hwndSizeBar
, &rectSB
);
1134 if (navigation_visible(info
))
1136 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
1137 rc
->left
+= rectNP
.right
+ rectSB
.right
;
1139 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
)
1141 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
1142 rc
->top
+= rectTB
.bottom
;
1144 rc
->right
= rectWND
.right
- rc
->left
;
1145 rc
->bottom
= rectWND
.bottom
- rc
->top
;
1148 static BOOL
HH_AddHTMLPane(HHInfo
*pHHInfo
)
1151 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1152 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
;
1153 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
| WS_EX_CLIENTEDGE
;
1156 HP_GetHTMLRect(pHHInfo
, &rc
);
1158 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1159 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1160 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1164 if (!InitWebBrowser(pHHInfo
, hWnd
))
1167 /* store the pointer to the HH info struct */
1168 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
1170 ShowWindow(hWnd
, SW_SHOW
);
1173 pHHInfo
->WinType
.hwndHTML
= hWnd
;
1177 static BOOL
AddContentTab(HHInfo
*info
)
1179 HIMAGELIST hImageList
;
1183 if(info
->tabs
[TAB_CONTENTS
].id
== -1)
1184 return TRUE
; /* No "Contents" tab */
1185 hWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_TREEVIEWW
, szEmpty
, WS_CHILD
| WS_BORDER
| TVS_LINESATROOT
1186 | TVS_SHOWSELALWAYS
| TVS_HASBUTTONS
, 50, 50, 100, 100,
1187 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1189 ERR("Could not create treeview control\n");
1193 hImageList
= ImageList_Create(16, 16, ILC_COLOR32
, 0, HHTV_NUMBITMAPS
);
1194 hBitmap
= LoadBitmapW(hhctrl_hinstance
, MAKEINTRESOURCEW(IDB_HHTREEVIEW
));
1195 ImageList_Add(hImageList
, hBitmap
, NULL
);
1196 SendMessageW(hWnd
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
1198 info
->contents
.hImageList
= hImageList
;
1199 info
->tabs
[TAB_CONTENTS
].hwnd
= hWnd
;
1200 ResizeTabChild(info
, TAB_CONTENTS
);
1201 ShowWindow(hWnd
, SW_SHOW
);
1206 static BOOL
AddIndexTab(HHInfo
*info
)
1208 char hidden_column
[] = "Column";
1211 if(info
->tabs
[TAB_INDEX
].id
== -1)
1212 return TRUE
; /* No "Index" tab */
1213 info
->tabs
[TAB_INDEX
].hwnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
1214 szEmpty
, WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
| LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1215 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1216 if(!info
->tabs
[TAB_INDEX
].hwnd
) {
1217 ERR("Could not create ListView control\n");
1220 memset(&lvc
, 0, sizeof(lvc
));
1221 lvc
.mask
= LVCF_TEXT
;
1222 lvc
.pszText
= hidden_column
;
1223 if(SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1225 ERR("Could not create ListView column\n");
1229 ResizeTabChild(info
, TAB_INDEX
);
1230 ShowWindow(info
->tabs
[TAB_INDEX
].hwnd
, SW_HIDE
);
1235 static BOOL
AddSearchTab(HHInfo
*info
)
1237 HWND hwndList
, hwndEdit
, hwndContainer
;
1238 char hidden_column
[] = "Column";
1239 WNDPROC editWndProc
;
1242 if(info
->tabs
[TAB_SEARCH
].id
== -1)
1243 return TRUE
; /* No "Search" tab */
1244 hwndContainer
= CreateWindowExW(WS_EX_CONTROLPARENT
, szChildClass
, szEmpty
,
1245 WS_CHILD
, 0, 0, 0, 0, info
->WinType
.hwndNavigation
,
1246 NULL
, hhctrl_hinstance
, NULL
);
1247 if(!hwndContainer
) {
1248 ERR("Could not create search window container control.\n");
1251 hwndEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_EDITW
, szEmpty
, WS_CHILD
1252 | WS_VISIBLE
| ES_LEFT
| SS_NOTIFY
, 0, 0, 0, 0,
1253 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1255 ERR("Could not create search ListView control.\n");
1258 if(SendMessageW(hwndEdit
, WM_SETFONT
, (WPARAM
) info
->hFont
, (LPARAM
) FALSE
) == -1)
1260 ERR("Could not set font for edit control.\n");
1263 editWndProc
= (WNDPROC
) SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
, (LONG_PTR
)EditChild_WndProc
);
1265 ERR("Could not redirect messages for edit control.\n");
1268 SetWindowLongPtrW(hwndEdit
, GWLP_USERDATA
, (LONG_PTR
)editWndProc
);
1269 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1270 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| LVS_SINGLESEL
1271 | LVS_REPORT
| LVS_NOCOLUMNHEADER
, 0, 0, 0, 0,
1272 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1274 ERR("Could not create search ListView control.\n");
1277 memset(&lvc
, 0, sizeof(lvc
));
1278 lvc
.mask
= LVCF_TEXT
;
1279 lvc
.pszText
= hidden_column
;
1280 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1282 ERR("Could not create ListView column\n");
1286 info
->search
.hwndEdit
= hwndEdit
;
1287 info
->search
.hwndList
= hwndList
;
1288 info
->search
.hwndContainer
= hwndContainer
;
1289 info
->tabs
[TAB_SEARCH
].hwnd
= hwndContainer
;
1291 SetWindowLongPtrW(hwndContainer
, 0, (LONG_PTR
)info
);
1293 ResizeTabChild(info
, TAB_SEARCH
);
1298 /* The Index tab's sub-topic popup */
1300 static void ResizePopupChild(HHInfo
*info
)
1302 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
1303 int border_width
= GetSystemMetrics(SM_CXBORDER
);
1304 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
1311 GetClientRect(info
->popup
.hwndPopup
, &rect
);
1312 SetWindowPos(info
->popup
.hwndCallback
, HWND_TOP
, 0, 0,
1313 rect
.right
, rect
.bottom
, SWP_NOMOVE
);
1315 rect
.left
= TAB_MARGIN
;
1316 rect
.top
= TAB_TOP_PADDING
+ TAB_MARGIN
;
1317 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
1318 rect
.bottom
-= TAB_MARGIN
;
1319 width
= rect
.right
-rect
.left
;
1320 height
= rect
.bottom
-rect
.top
;
1322 SetWindowPos(info
->popup
.hwndList
, NULL
, rect
.left
, rect
.top
, width
, height
,
1323 SWP_NOZORDER
| SWP_NOACTIVATE
);
1325 SendMessageW(info
->popup
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
1326 width
-scroll_width
-2*border_width
-2*edge_width
);
1329 static LRESULT CALLBACK
HelpPopup_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1331 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1336 ResizePopupChild(info
);
1339 DestroyWindow(hWnd
);
1342 ShowWindow(hWnd
, SW_HIDE
);
1346 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1352 static LRESULT CALLBACK
PopupChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1357 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1361 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1364 if(info
== 0 || lParam
== 0)
1366 iter
= (IndexSubItem
*) ((NMITEMACTIVATE
*)lParam
)->lParam
;
1369 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1370 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1374 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1381 lvItem
.iItem
= (int) SendMessageW(info
->popup
.hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
1382 lvItem
.mask
= TVIF_PARAM
;
1383 SendMessageW(info
->popup
.hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
1384 iter
= (IndexSubItem
*) lvItem
.lParam
;
1385 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1386 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1393 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1399 static BOOL
AddIndexPopup(HHInfo
*info
)
1401 static const WCHAR szPopupChildClass
[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1402 static const WCHAR windowCaptionW
[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1403 static const WCHAR windowClassW
[] = {'H','H',' ','P','o','p','u','p',0};
1404 HWND hwndList
, hwndPopup
, hwndCallback
;
1405 char hidden_column
[] = "Column";
1409 if(info
->tabs
[TAB_INDEX
].id
== -1)
1410 return TRUE
; /* No "Index" tab */
1412 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1413 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1414 wcex
.lpfnWndProc
= HelpPopup_WndProc
;
1415 wcex
.cbClsExtra
= 0;
1416 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1417 wcex
.hInstance
= hhctrl_hinstance
;
1418 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1419 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1420 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1421 wcex
.lpszMenuName
= NULL
;
1422 wcex
.lpszClassName
= windowClassW
;
1423 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1424 RegisterClassExW(&wcex
);
1426 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1428 wcex
.lpfnWndProc
= PopupChild_WndProc
;
1429 wcex
.cbClsExtra
= 0;
1430 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1431 wcex
.hInstance
= hhctrl_hinstance
;
1432 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1433 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1434 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1435 wcex
.lpszMenuName
= NULL
;
1436 wcex
.lpszClassName
= szPopupChildClass
;
1437 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1438 RegisterClassExW(&wcex
);
1440 hwndPopup
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
1441 | WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
,
1442 windowClassW
, windowCaptionW
, WS_POPUPWINDOW
1443 | WS_OVERLAPPEDWINDOW
| WS_VISIBLE
1444 | WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, CW_USEDEFAULT
,
1445 CW_USEDEFAULT
, 300, 200, info
->WinType
.hwndHelp
,
1446 NULL
, hhctrl_hinstance
, NULL
);
1450 hwndCallback
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
,
1451 szPopupChildClass
, szEmpty
, WS_CHILDWINDOW
| WS_VISIBLE
,
1453 hwndPopup
, NULL
, hhctrl_hinstance
, NULL
);
1457 ShowWindow(hwndPopup
, SW_HIDE
);
1458 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1459 WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
1460 | LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1461 hwndCallback
, NULL
, hhctrl_hinstance
, NULL
);
1463 ERR("Could not create popup ListView control\n");
1466 memset(&lvc
, 0, sizeof(lvc
));
1467 lvc
.mask
= LVCF_TEXT
;
1468 lvc
.pszText
= hidden_column
;
1469 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1471 ERR("Could not create popup ListView column\n");
1475 info
->popup
.hwndCallback
= hwndCallback
;
1476 info
->popup
.hwndPopup
= hwndPopup
;
1477 info
->popup
.hwndList
= hwndList
;
1478 SetWindowLongPtrW(hwndPopup
, 0, (LONG_PTR
)info
);
1479 SetWindowLongPtrW(hwndCallback
, 0, (LONG_PTR
)info
);
1481 ResizePopupChild(info
);
1482 ShowWindow(hwndList
, SW_SHOW
);
1489 static void ExpandContract(HHInfo
*pHHInfo
)
1493 pHHInfo
->WinType
.fNotExpanded
= !pHHInfo
->WinType
.fNotExpanded
;
1494 GetWindowRect(pHHInfo
->WinType
.hwndHelp
, &r
);
1495 NP_GetNavigationRect(pHHInfo
, &nav
);
1497 /* hide/show both the nav bar and the size bar */
1498 if (pHHInfo
->WinType
.fNotExpanded
)
1500 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_HIDE
);
1501 ShowWindow(pHHInfo
->hwndSizeBar
, SW_HIDE
);
1502 r
.left
= r
.left
+ nav
.right
;
1504 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(FALSE
, 0));
1505 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(TRUE
, 0));
1509 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_SHOW
);
1510 ShowWindow(pHHInfo
->hwndSizeBar
, SW_SHOW
);
1511 r
.left
= r
.left
- nav
.right
;
1513 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(TRUE
, 0));
1514 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(FALSE
, 0));
1517 MoveWindow(pHHInfo
->WinType
.hwndHelp
, r
.left
, r
.top
, r
.right
-r
.left
, r
.bottom
-r
.top
, TRUE
);
1520 static LRESULT
Help_OnSize(HWND hWnd
)
1522 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1529 if (navigation_visible(pHHInfo
))
1531 NP_GetNavigationRect(pHHInfo
, &rc
);
1532 SetWindowPos(pHHInfo
->WinType
.hwndNavigation
, HWND_TOP
, 0, 0,
1533 rc
.right
, rc
.bottom
, SWP_NOMOVE
);
1535 SB_GetSizeBarRect(pHHInfo
, &rc
);
1536 SetWindowPos(pHHInfo
->hwndSizeBar
, HWND_TOP
, rc
.left
, rc
.top
,
1537 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1541 HP_GetHTMLRect(pHHInfo
, &rc
);
1542 SetWindowPos(pHHInfo
->WinType
.hwndHTML
, HWND_TOP
, rc
.left
, rc
.top
,
1543 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1545 /* Resize browser window taking the frame size into account */
1546 dwSize
= GetSystemMetrics(SM_CXFRAME
);
1547 ResizeWebBrowser(pHHInfo
, rc
.right
- dwSize
, rc
.bottom
- dwSize
);
1552 void UpdateHelpWindow(HHInfo
*info
)
1554 if (!info
->WinType
.hwndHelp
)
1557 WARN("Only the size of the window is currently updated.\n");
1558 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_RECT
)
1560 RECT
*rect
= &info
->WinType
.rcWindowPos
;
1561 INT x
, y
, width
, height
;
1565 width
= rect
->right
- x
;
1566 height
= rect
->bottom
- y
;
1567 SetWindowPos(info
->WinType
.hwndHelp
, NULL
, rect
->left
, rect
->top
, width
, height
,
1568 SWP_NOZORDER
| SWP_NOACTIVATE
);
1572 static LRESULT CALLBACK
Help_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1577 if (HIWORD(wParam
) == BN_CLICKED
)
1578 TB_OnClick(hWnd
, LOWORD(wParam
));
1581 return Help_OnSize(hWnd
);
1583 ReleaseHelpViewer((HHInfo
*)GetWindowLongPtrW(hWnd
, 0));
1591 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1597 static BOOL
HH_CreateHelpWindow(HHInfo
*info
)
1599 HWND hWnd
, parent
= 0;
1600 RECT winPos
= info
->WinType
.rcWindowPos
;
1602 DWORD dwStyles
, dwExStyles
;
1603 DWORD x
, y
, width
= 0, height
= 0;
1606 static const WCHAR windowClassW
[] = {
1607 'H','H',' ', 'P','a','r','e','n','t',0
1610 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1611 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1612 wcex
.lpfnWndProc
= Help_WndProc
;
1613 wcex
.cbClsExtra
= 0;
1614 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1615 wcex
.hInstance
= hhctrl_hinstance
;
1616 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1617 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1618 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1619 wcex
.lpszMenuName
= NULL
;
1620 wcex
.lpszClassName
= windowClassW
;
1621 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1623 RegisterClassExW(&wcex
);
1625 /* Read in window parameters if available */
1626 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_STYLES
)
1628 dwStyles
= info
->WinType
.dwStyles
;
1629 if (!(info
->WinType
.dwStyles
& WS_CHILD
))
1630 dwStyles
|= WS_OVERLAPPEDWINDOW
;
1633 dwStyles
= WS_OVERLAPPEDWINDOW
| WS_VISIBLE
|
1634 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1636 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_EXSTYLES
)
1637 dwExStyles
= info
->WinType
.dwExStyles
;
1639 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
|
1640 WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
;
1642 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_RECT
)
1646 width
= winPos
.right
- x
;
1647 height
= winPos
.bottom
- y
;
1649 if (!width
|| !height
)
1651 x
= WINTYPE_DEFAULT_X
;
1652 y
= WINTYPE_DEFAULT_Y
;
1653 width
= WINTYPE_DEFAULT_WIDTH
;
1654 height
= WINTYPE_DEFAULT_HEIGHT
;
1657 if (!(info
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
) && info
->WinType
.fNotExpanded
)
1659 if (!(info
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1660 info
->WinType
.iNavWidth
== 0)
1662 info
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1665 x
+= info
->WinType
.iNavWidth
;
1666 width
-= info
->WinType
.iNavWidth
;
1670 caption
= info
->WinType
.pszCaption
;
1671 if (!*caption
) caption
= info
->pCHMInfo
->defTitle
;
1673 if (info
->WinType
.dwStyles
& WS_CHILD
)
1674 parent
= info
->WinType
.hwndCaller
;
1676 hWnd
= CreateWindowExW(dwExStyles
, windowClassW
, caption
,
1677 dwStyles
, x
, y
, width
, height
, parent
, NULL
, hhctrl_hinstance
, NULL
);
1681 ShowWindow(hWnd
, SW_SHOW
);
1684 /* store the pointer to the HH info struct */
1685 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1687 info
->WinType
.hwndHelp
= hWnd
;
1691 static void HH_CreateFont(HHInfo
*pHHInfo
)
1695 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
), sizeof(LOGFONTW
), &lf
);
1696 lf
.lfWeight
= FW_NORMAL
;
1697 lf
.lfItalic
= FALSE
;
1698 lf
.lfUnderline
= FALSE
;
1700 pHHInfo
->hFont
= CreateFontIndirectW(&lf
);
1703 static void HH_InitRequiredControls(DWORD dwControls
)
1705 INITCOMMONCONTROLSEX icex
;
1707 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1708 icex
.dwICC
= dwControls
;
1709 InitCommonControlsEx(&icex
);
1712 /* Creates the whole package */
1713 static BOOL
CreateViewer(HHInfo
*pHHInfo
)
1715 HH_CreateFont(pHHInfo
);
1717 if (!HH_CreateHelpWindow(pHHInfo
))
1720 HH_InitRequiredControls(ICC_BAR_CLASSES
);
1722 if (!HH_AddToolbar(pHHInfo
))
1725 HH_RegisterChildWndClass(pHHInfo
);
1727 if (!HH_AddNavigationPane(pHHInfo
))
1730 HH_RegisterSizeBarClass(pHHInfo
);
1732 if (!HH_AddSizeBar(pHHInfo
))
1735 if (!HH_AddHTMLPane(pHHInfo
))
1738 if (!AddContentTab(pHHInfo
))
1741 if (!AddIndexTab(pHHInfo
))
1744 if (!AddIndexPopup(pHHInfo
))
1747 if (!AddSearchTab(pHHInfo
))
1750 InitContent(pHHInfo
);
1753 pHHInfo
->viewer_initialized
= TRUE
;
1757 void wintype_stringsW_free(struct wintype_stringsW
*stringsW
)
1759 heap_free(stringsW
->pszType
);
1760 heap_free(stringsW
->pszCaption
);
1761 heap_free(stringsW
->pszToc
);
1762 heap_free(stringsW
->pszIndex
);
1763 heap_free(stringsW
->pszFile
);
1764 heap_free(stringsW
->pszHome
);
1765 heap_free(stringsW
->pszJump1
);
1766 heap_free(stringsW
->pszJump2
);
1767 heap_free(stringsW
->pszUrlJump1
);
1768 heap_free(stringsW
->pszUrlJump2
);
1771 void wintype_stringsA_free(struct wintype_stringsA
*stringsA
)
1773 heap_free(stringsA
->pszType
);
1774 heap_free(stringsA
->pszCaption
);
1775 heap_free(stringsA
->pszToc
);
1776 heap_free(stringsA
->pszIndex
);
1777 heap_free(stringsA
->pszFile
);
1778 heap_free(stringsA
->pszHome
);
1779 heap_free(stringsA
->pszJump1
);
1780 heap_free(stringsA
->pszJump2
);
1781 heap_free(stringsA
->pszUrlJump1
);
1782 heap_free(stringsA
->pszUrlJump2
);
1783 heap_free(stringsA
->pszCustomTabs
);
1786 void ReleaseHelpViewer(HHInfo
*info
)
1788 TRACE("(%p)\n", info
);
1793 list_remove(&info
->entry
);
1795 wintype_stringsA_free(&info
->stringsA
);
1796 wintype_stringsW_free(&info
->stringsW
);
1799 CloseCHM(info
->pCHMInfo
);
1801 ReleaseWebBrowser(info
);
1802 ReleaseContent(info
);
1804 ReleaseSearch(info
);
1806 if(info
->contents
.hImageList
)
1807 ImageList_Destroy(info
->contents
.hImageList
);
1808 if(info
->WinType
.hwndHelp
)
1809 DestroyWindow(info
->WinType
.hwndHelp
);
1815 HHInfo
*CreateHelpViewer(HHInfo
*info
, LPCWSTR filename
, HWND caller
)
1822 info
= heap_alloc_zero(sizeof(HHInfo
));
1823 list_add_tail(&window_list
, &info
->entry
);
1826 /* Set the invalid tab ID (-1) as the default value for all
1827 * of the tabs, this matches a failed TCM_INSERTITEM call.
1829 for(i
=0;i
<sizeof(info
->tabs
)/sizeof(HHTab
);i
++)
1830 info
->tabs
[i
].id
= -1;
1832 OleInitialize(NULL
);
1834 info
->pCHMInfo
= OpenCHM(filename
);
1835 if(!info
->pCHMInfo
) {
1836 ReleaseHelpViewer(info
);
1840 if (!LoadWinTypeFromCHM(info
)) {
1841 ReleaseHelpViewer(info
);
1844 info
->WinType
.hwndCaller
= caller
;
1846 /* If the window is already open then load the file in that existing window */
1847 if ((tmp_info
= find_window(info
->WinType
.pszType
)) && tmp_info
!= info
)
1849 ReleaseHelpViewer(info
);
1850 return CreateHelpViewer(tmp_info
, filename
, caller
);
1853 if(!info
->viewer_initialized
&& !CreateViewer(info
)) {
1854 ReleaseHelpViewer(info
);
1862 * Search the table of HTML entities and return the corresponding ANSI symbol.
1864 static char find_html_symbol(const char *entity
, int entity_len
)
1866 int max
= sizeof(html_encoded_symbols
)/sizeof(html_encoded_symbols
[0])-1;
1871 int pos
= (min
+max
)/2;
1872 const char *encoded_symbol
= html_encoded_symbols
[pos
].html_code
;
1873 dir
= strncmp(encoded_symbol
, entity
, entity_len
);
1874 if(dir
== 0 && !encoded_symbol
[entity_len
]) return html_encoded_symbols
[pos
].ansi_symbol
;
1884 * Decode a string containing HTML encoded characters into a unicode string.
1886 WCHAR
*decode_html(const char *html_fragment
, int html_fragment_len
, UINT code_page
)
1888 const char *h
= html_fragment
, *amp
, *sem
;
1890 int len
, tmp_len
= 0;
1891 WCHAR
*unicode_text
;
1893 tmp
= heap_alloc(html_fragment_len
+1);
1897 amp
= strchr(h
, '&');
1900 /* Copy the characters prior to the HTML encoded character */
1901 memcpy(&tmp
[tmp_len
], h
, len
);
1903 amp
++; /* skip ampersand */
1904 sem
= strchr(amp
, ';');
1905 /* Require a semicolon after the ampersand */
1909 tmp
[tmp_len
++] = '&';
1912 /* Find the symbol either by using the ANSI character number (prefixed by the pound symbol)
1913 * or by searching the HTML entity table */
1917 char *endnum
= NULL
;
1920 tmp
= (char) strtol(amp
, &endnum
, 10);
1925 symbol
= find_html_symbol(amp
, len
);
1928 FIXME("Failed to translate HTML encoded character '&%.*s;'.\n", len
, amp
);
1930 tmp
[tmp_len
++] = '&';
1933 /* Insert the new symbol */
1935 tmp
[tmp_len
++] = symbol
;
1937 /* Convert any remaining characters */
1938 len
= html_fragment_len
-(h
-html_fragment
);
1939 memcpy(&tmp
[tmp_len
], h
, len
);
1941 tmp
[tmp_len
++] = 0; /* NULL-terminate the string */
1943 len
= MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, NULL
, 0);
1944 unicode_text
= heap_alloc(len
*sizeof(WCHAR
));
1945 MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, unicode_text
, len
);
1947 return unicode_text
;
1950 /* Find the HTMLHelp structure for an existing window title */
1951 HHInfo
*find_window(const WCHAR
*window
)
1955 LIST_FOR_EACH_ENTRY(info
, &window_list
, HHInfo
, entry
)
1957 if (strcmpW(info
->WinType
.pszType
, window
) == 0)