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
29 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp
);
35 static LRESULT
Help_OnSize(HWND hWnd
);
36 static void ExpandContract(HHInfo
*pHHInfo
);
38 /* Window type defaults */
40 #define WINTYPE_DEFAULT_X 280
41 #define WINTYPE_DEFAULT_Y 100
42 #define WINTYPE_DEFAULT_WIDTH 740
43 #define WINTYPE_DEFAULT_HEIGHT 640
44 #define WINTYPE_DEFAULT_NAVWIDTH 250
46 #define TAB_TOP_PADDING 8
47 #define TAB_RIGHT_PADDING 4
49 #define EDIT_HEIGHT 20
51 struct list window_list
= LIST_INIT(window_list
);
53 static const WCHAR szEmpty
[] = {0};
55 struct html_encoded_symbol
{
56 const char *html_code
;
61 * Table mapping the conversion between HTML encoded symbols and their ANSI code page equivalent.
62 * Note: Add additional entries in proper alphabetical order (a binary search is used on this table).
64 static struct html_encoded_symbol html_encoded_symbols
[] =
168 static inline BOOL
navigation_visible(HHInfo
*info
)
170 return ((info
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
) && !info
->WinType
.fNotExpanded
);
173 /* Loads a string from the resource file */
174 static LPWSTR
HH_LoadString(DWORD dwID
)
176 LPWSTR string
= NULL
;
177 LPCWSTR stringresource
;
180 iSize
= LoadStringW(hhctrl_hinstance
, dwID
, (LPWSTR
)&stringresource
, 0);
182 string
= heap_alloc((iSize
+ 2) * sizeof(WCHAR
)); /* some strings (tab text) needs double-null termination */
183 memcpy(string
, stringresource
, iSize
*sizeof(WCHAR
));
189 static HRESULT
navigate_url(HHInfo
*info
, LPCWSTR surl
)
194 TRACE("%s\n", debugstr_w(surl
));
196 V_VT(&url
) = VT_BSTR
;
197 V_BSTR(&url
) = SysAllocString(surl
);
199 hres
= IWebBrowser2_Navigate2(info
->web_browser
->web_browser
, &url
, 0, 0, 0, 0);
204 TRACE("Navigation failed: %08x\n", hres
);
209 BOOL
NavigateToUrl(HHInfo
*info
, LPCWSTR surl
)
215 static const WCHAR url_indicator
[] = {':', '/', '/', 0};
217 TRACE("%s\n", debugstr_w(surl
));
219 if (strstrW(surl
, url_indicator
)) {
220 hres
= navigate_url(info
, surl
);
223 } /* look up in chm if it doesn't look like a full url */
225 SetChmPath(&chm_path
, info
->pCHMInfo
->szFile
, surl
);
226 ret
= NavigateToChm(info
, chm_path
.chm_file
, chm_path
.chm_index
);
228 heap_free(chm_path
.chm_file
);
229 heap_free(chm_path
.chm_index
);
234 static BOOL
AppendFullPathURL(LPCWSTR file
, LPWSTR buf
, LPCWSTR index
)
236 static const WCHAR url_format
[] =
237 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
238 static const WCHAR slash
[] = {'/',0};
239 static const WCHAR empty
[] = {0};
240 WCHAR full_path
[MAX_PATH
];
242 TRACE("%s %p %s\n", debugstr_w(file
), buf
, debugstr_w(index
));
244 if(!GetFullPathNameW(file
, sizeof(full_path
)/sizeof(full_path
[0]), full_path
, NULL
)) {
245 WARN("GetFullPathName failed: %u\n", GetLastError());
249 wsprintfW(buf
, url_format
, full_path
, (!index
|| index
[0] == '/') ? empty
: slash
, index
);
253 BOOL
NavigateToChm(HHInfo
*info
, LPCWSTR file
, LPCWSTR index
)
255 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
257 TRACE("%p %s %s\n", info
, debugstr_w(file
), debugstr_w(index
));
259 if ((!info
->web_browser
) || !AppendFullPathURL(file
, buf
, index
))
262 return SUCCEEDED(navigate_url(info
, buf
));
265 static void DoSync(HHInfo
*info
)
267 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
271 hres
= IWebBrowser2_get_LocationURL(info
->web_browser
->web_browser
, &url
);
275 WARN("get_LocationURL failed: %08x\n", hres
);
279 /* If we're not currently viewing a page in the active .chm file, abort */
280 if ((!AppendFullPathURL(info
->WinType
.pszFile
, buf
, NULL
)) || (lstrlenW(buf
) > lstrlenW(url
)))
286 if (lstrcmpiW(buf
, url
) > 0)
288 static const WCHAR delimW
[] = {':',':','/',0};
291 index
= strstrW(url
, delimW
);
294 ActivateContentTopic(info
->tabs
[TAB_CONTENTS
].hwnd
, index
+ 3, info
->content
); /* skip over ::/ */
302 #define SIZEBAR_WIDTH 4
304 static const WCHAR szSizeBarClass
[] = {
305 'H','H',' ','S','i','z','e','B','a','r',0
308 /* Draw the SizeBar */
309 static void SB_OnPaint(HWND hWnd
)
315 hdc
= BeginPaint(hWnd
, &ps
);
317 GetClientRect(hWnd
, &rc
);
322 FrameRect(hdc
, &rc
, GetStockObject(GRAY_BRUSH
));
324 /* white highlight */
325 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
326 MoveToEx(hdc
, rc
.right
, 1, NULL
);
328 LineTo(hdc
, 1, rc
.bottom
- 1);
331 MoveToEx(hdc
, 0, rc
.bottom
, NULL
);
332 LineTo(hdc
, rc
.right
, rc
.bottom
);
337 static void SB_OnLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
342 static void SB_OnLButtonUp(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
344 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
347 pt
.x
= (short)LOWORD(lParam
);
348 pt
.y
= (short)HIWORD(lParam
);
350 /* update the window sizes */
351 pHHInfo
->WinType
.iNavWidth
+= pt
.x
;
357 static void SB_OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
359 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
360 if (!(wParam
& MK_LBUTTON
))
364 static LRESULT CALLBACK
SizeBar_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
369 SB_OnLButtonDown(hWnd
, wParam
, lParam
);
372 SB_OnLButtonUp(hWnd
, wParam
, lParam
);
375 SB_OnMouseMove(hWnd
, wParam
, lParam
);
381 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
387 static void HH_RegisterSizeBarClass(HHInfo
*pHHInfo
)
391 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
393 wcex
.lpfnWndProc
= SizeBar_WndProc
;
395 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
396 wcex
.hInstance
= hhctrl_hinstance
;
397 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
398 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_SIZEWE
);
399 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
400 wcex
.lpszMenuName
= NULL
;
401 wcex
.lpszClassName
= szSizeBarClass
;
402 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
404 RegisterClassExW(&wcex
);
407 static void SB_GetSizeBarRect(HHInfo
*info
, RECT
*rc
)
409 RECT rectWND
, rectTB
, rectNP
;
411 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
412 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
413 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
415 SetRect(rc
, rectNP
.right
, rectTB
.bottom
, SIZEBAR_WIDTH
, rectWND
.bottom
- rectTB
.bottom
);
418 static BOOL
HH_AddSizeBar(HHInfo
*pHHInfo
)
421 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
422 DWORD dwStyles
= WS_CHILDWINDOW
| WS_OVERLAPPED
;
423 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
426 if (navigation_visible(pHHInfo
))
427 dwStyles
|= WS_VISIBLE
;
429 SB_GetSizeBarRect(pHHInfo
, &rc
);
431 hWnd
= CreateWindowExW(dwExStyles
, szSizeBarClass
, szEmpty
, dwStyles
,
432 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
433 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
437 /* store the pointer to the HH info struct */
438 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
440 pHHInfo
->hwndSizeBar
= hWnd
;
446 static const WCHAR szChildClass
[] = {
447 'H','H',' ','C','h','i','l','d',0
450 static LRESULT
Child_OnPaint(HWND hWnd
)
456 hdc
= BeginPaint(hWnd
, &ps
);
458 /* Only paint the Navigation pane, identified by the fact
459 * that it has a child window
461 if (GetWindow(hWnd
, GW_CHILD
))
463 GetClientRect(hWnd
, &rc
);
465 /* set the border color */
466 SelectObject(hdc
, GetStockObject(DC_PEN
));
467 SetDCPenColor(hdc
, GetSysColor(COLOR_BTNSHADOW
));
469 /* Draw the top border */
470 LineTo(hdc
, rc
.right
, 0);
472 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
473 MoveToEx(hdc
, 0, 1, NULL
);
474 LineTo(hdc
, rc
.right
, 1);
482 static void ResizeTabChild(HHInfo
*info
, int tab
)
484 HWND hwnd
= info
->tabs
[tab
].hwnd
;
489 GetClientRect(info
->WinType
.hwndNavigation
, &rect
);
490 SendMessageW(info
->hwndTabCtrl
, TCM_GETITEMRECT
, 0, (LPARAM
)&tabrc
);
491 cnt
= SendMessageW(info
->hwndTabCtrl
, TCM_GETROWCOUNT
, 0, 0);
493 rect
.left
= TAB_MARGIN
;
494 rect
.top
= TAB_TOP_PADDING
+ cnt
*(tabrc
.bottom
-tabrc
.top
) + TAB_MARGIN
;
495 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
496 rect
.bottom
-= TAB_MARGIN
;
497 width
= rect
.right
-rect
.left
;
498 height
= rect
.bottom
-rect
.top
;
500 SetWindowPos(hwnd
, NULL
, rect
.left
, rect
.top
, width
, height
,
501 SWP_NOZORDER
| SWP_NOACTIVATE
);
506 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
507 int border_width
= GetSystemMetrics(SM_CXBORDER
);
508 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
510 /* Resize the tab widget column to perfectly fit the tab window and
511 * leave sufficient space for the scroll widget.
513 SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_SETCOLUMNWIDTH
, 0,
514 width
-scroll_width
-2*border_width
-2*edge_width
);
519 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
520 int border_width
= GetSystemMetrics(SM_CXBORDER
);
521 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
524 SetWindowPos(info
->search
.hwndEdit
, NULL
, 0, top_pos
, width
,
525 EDIT_HEIGHT
, SWP_NOZORDER
| SWP_NOACTIVATE
);
526 top_pos
+= EDIT_HEIGHT
+ TAB_MARGIN
;
527 SetWindowPos(info
->search
.hwndList
, NULL
, 0, top_pos
, width
,
528 height
-top_pos
, SWP_NOZORDER
| SWP_NOACTIVATE
);
529 /* Resize the tab widget column to perfectly fit the tab window and
530 * leave sufficient space for the scroll widget.
532 SendMessageW(info
->search
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
533 width
-scroll_width
-2*border_width
-2*edge_width
);
540 static LRESULT
Child_OnSize(HWND hwnd
)
542 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
545 if(!info
|| hwnd
!= info
->WinType
.hwndNavigation
)
548 GetClientRect(hwnd
, &rect
);
549 SetWindowPos(info
->hwndTabCtrl
, HWND_TOP
, 0, 0,
550 rect
.right
- TAB_RIGHT_PADDING
,
551 rect
.bottom
- TAB_TOP_PADDING
, SWP_NOMOVE
);
553 ResizeTabChild(info
, TAB_CONTENTS
);
554 ResizeTabChild(info
, TAB_INDEX
);
555 ResizeTabChild(info
, TAB_SEARCH
);
559 static LRESULT
OnTabChange(HWND hwnd
)
561 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
562 int tab_id
, tab_index
, i
;
569 if(info
->tabs
[info
->current_tab
].hwnd
)
570 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_HIDE
);
572 tab_id
= (int) SendMessageW(info
->hwndTabCtrl
, TCM_GETCURSEL
, 0, 0);
573 /* convert the ID of the tab to an index in our tab list */
575 for (i
=0; i
<TAB_NUMTABS
; i
++)
577 if (info
->tabs
[i
].id
== tab_id
)
585 FIXME("Tab ID %d does not correspond to a valid index in the tab list.\n", tab_id
);
588 info
->current_tab
= tab_index
;
590 if(info
->tabs
[info
->current_tab
].hwnd
)
591 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_SHOW
);
596 static LRESULT
OnTopicChange(HHInfo
*info
, void *user_data
)
598 LPCWSTR chmfile
= NULL
, name
= NULL
, local
= NULL
;
603 if(!user_data
|| !info
)
606 switch (info
->current_tab
)
609 citer
= (ContentItem
*) user_data
;
611 local
= citer
->local
;
613 if(citer
->merge
.chm_file
) {
614 chmfile
= citer
->merge
.chm_file
;
617 citer
= citer
->parent
;
621 iiter
= (IndexItem
*) user_data
;
622 if(iiter
->nItems
== 0) {
623 FIXME("No entries for this item!\n");
626 if(iiter
->nItems
> 1) {
630 SendMessageW(info
->popup
.hwndList
, LVM_DELETEALLITEMS
, 0, 0);
631 for(i
=0;i
<iiter
->nItems
;i
++) {
632 IndexSubItem
*item
= &iiter
->items
[i
];
633 WCHAR
*name
= iiter
->keyword
;
636 item
->name
= GetDocumentTitle(info
->pCHMInfo
, item
->local
);
639 memset(&lvi
, 0, sizeof(lvi
));
641 lvi
.mask
= LVIF_TEXT
|LVIF_PARAM
;
642 lvi
.cchTextMax
= strlenW(name
)+1;
644 lvi
.lParam
= (LPARAM
) item
;
645 SendMessageW(info
->popup
.hwndList
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvi
);
647 ShowWindow(info
->popup
.hwndPopup
, SW_SHOW
);
650 name
= iiter
->items
[0].name
;
651 local
= iiter
->items
[0].local
;
652 chmfile
= iiter
->merge
.chm_file
;
655 siter
= (SearchItem
*) user_data
;
656 name
= siter
->filename
;
657 local
= siter
->filename
;
658 chmfile
= info
->pCHMInfo
->szFile
;
661 FIXME("Unhandled operation for this tab!\n");
667 FIXME("No help file found for this item!\n");
671 TRACE("name %s loal %s\n", debugstr_w(name
), debugstr_w(local
));
673 NavigateToChm(info
, chmfile
, local
);
677 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
678 static LRESULT CALLBACK
EditChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
680 WNDPROC editWndProc
= (WNDPROC
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
682 if(message
== WM_KEYUP
&& wParam
== VK_RETURN
)
686 nmhdr
.hwndFrom
= hWnd
;
687 nmhdr
.code
= NM_RETURN
;
688 SendMessageW(GetParent(GetParent(hWnd
)), WM_NOTIFY
, wParam
, (LPARAM
)&nmhdr
);
690 return editWndProc(hWnd
, message
, wParam
, lParam
);
693 static LRESULT CALLBACK
Child_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
698 return Child_OnPaint(hWnd
);
700 return Child_OnSize(hWnd
);
702 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
703 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
705 switch(nmhdr
->code
) {
707 return OnTabChange(hWnd
);
708 case TVN_SELCHANGEDW
:
709 return OnTopicChange(info
, (void*)((NMTREEVIEWW
*)lParam
)->itemNew
.lParam
);
710 case TVN_ITEMEXPANDINGW
: {
711 TVITEMW
*item
= &((NMTREEVIEWW
*)lParam
)->itemNew
;
712 HWND hwndTreeView
= info
->tabs
[TAB_CONTENTS
].hwnd
;
714 item
->mask
= TVIF_IMAGE
|TVIF_SELECTEDIMAGE
;
715 if (item
->state
& TVIS_EXPANDED
)
717 item
->iImage
= HHTV_FOLDER
;
718 item
->iSelectedImage
= HHTV_FOLDER
;
722 item
->iImage
= HHTV_OPENFOLDER
;
723 item
->iSelectedImage
= HHTV_OPENFOLDER
;
725 SendMessageW(hwndTreeView
, TVM_SETITEMW
, 0, (LPARAM
)item
);
731 switch(info
->current_tab
)
734 return OnTopicChange(info
, (void*)((NMITEMACTIVATE
*)lParam
)->lParam
);
736 return OnTopicChange(info
, (void*)((NMITEMACTIVATE
*)lParam
)->lParam
);
742 switch(info
->current_tab
) {
744 HWND hwndList
= info
->tabs
[TAB_INDEX
].hwnd
;
747 lvItem
.iItem
= (int) SendMessageW(hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
748 lvItem
.mask
= TVIF_PARAM
;
749 SendMessageW(hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
750 OnTopicChange(info
, (void*) lvItem
.lParam
);
754 if(nmhdr
->hwndFrom
== info
->search
.hwndEdit
) {
758 len
= GetWindowTextA(info
->search
.hwndEdit
, needle
, sizeof(needle
));
761 FIXME("Unable to get search text.\n");
764 /* Convert the requested text for comparison later against the
765 * lower case version of HTML file contents.
768 needle
[i
] = tolower(needle
[i
]);
769 InitSearch(info
, needle
);
771 }else if(nmhdr
->hwndFrom
== info
->search
.hwndList
) {
772 HWND hwndList
= info
->search
.hwndList
;
775 lvItem
.iItem
= (int) SendMessageW(hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
776 lvItem
.mask
= TVIF_PARAM
;
777 SendMessageW(hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
778 OnTopicChange(info
, (void*) lvItem
.lParam
);
789 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
795 static void HH_RegisterChildWndClass(HHInfo
*pHHInfo
)
799 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
801 wcex
.lpfnWndProc
= Child_WndProc
;
803 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
804 wcex
.hInstance
= hhctrl_hinstance
;
805 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
806 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
807 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
808 wcex
.lpszMenuName
= NULL
;
809 wcex
.lpszClassName
= szChildClass
;
810 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
812 RegisterClassExW(&wcex
);
819 static void DisplayPopupMenu(HHInfo
*info
)
822 TBBUTTONINFOW button
;
828 menu
= LoadMenuW(hhctrl_hinstance
, MAKEINTRESOURCEW(MENU_POPUP
));
833 submenu
= GetSubMenu(menu
, 0);
835 /* Update the Show/Hide menu item */
836 item
.cbSize
= sizeof(MENUITEMINFOW
);
837 item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
838 item
.fType
= MFT_STRING
;
839 item
.fState
= MF_ENABLED
;
841 if (info
->WinType
.fNotExpanded
)
842 item
.dwTypeData
= HH_LoadString(IDS_SHOWTABS
);
844 item
.dwTypeData
= HH_LoadString(IDS_HIDETABS
);
846 SetMenuItemInfoW(submenu
, IDTB_EXPAND
, FALSE
, &item
);
847 heap_free(item
.dwTypeData
);
849 /* Find the index toolbar button */
850 button
.cbSize
= sizeof(TBBUTTONINFOW
);
851 button
.dwMask
= TBIF_COMMAND
;
852 index
= SendMessageW(info
->WinType
.hwndToolBar
, TB_GETBUTTONINFOW
, IDTB_OPTIONS
, (LPARAM
) &button
);
858 SendMessageW(info
->WinType
.hwndToolBar
, TB_GETITEMRECT
, index
, (LPARAM
) &rect
);
860 coords
.x
= rect
.left
;
861 coords
.y
= rect
.bottom
;
863 ClientToScreen(info
->WinType
.hwndToolBar
, &coords
);
864 TrackPopupMenu(submenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_LEFTBUTTON
| TPM_NOANIMATION
, coords
.x
, coords
.y
, 0, info
->WinType
.hwndHelp
, NULL
);
867 static void TB_OnClick(HWND hWnd
, DWORD dwID
)
869 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
874 DoPageAction(info
->web_browser
, WB_STOP
);
877 DoPageAction(info
->web_browser
, WB_REFRESH
);
880 DoPageAction(info
->web_browser
, WB_GOBACK
);
883 NavigateToChm(info
, info
->pCHMInfo
->szFile
, info
->WinType
.pszHome
);
886 DoPageAction(info
->web_browser
, WB_GOFORWARD
);
889 DoPageAction(info
->web_browser
, WB_PRINT
);
893 ExpandContract(info
);
899 DisplayPopupMenu(info
);
907 /* These are officially unimplemented as of the Windows 7 SDK */
909 case IDTB_BROWSE_FWD
:
910 case IDTB_BROWSE_BACK
:
921 static void TB_AddButton(TBBUTTON
*pButtons
, DWORD dwIndex
, DWORD dwID
, DWORD dwBitmap
)
923 pButtons
[dwIndex
].iBitmap
= dwBitmap
;
924 pButtons
[dwIndex
].idCommand
= dwID
;
925 pButtons
[dwIndex
].fsState
= TBSTATE_ENABLED
;
926 pButtons
[dwIndex
].fsStyle
= BTNS_BUTTON
;
927 pButtons
[dwIndex
].dwData
= 0;
928 pButtons
[dwIndex
].iString
= 0;
931 static void TB_AddButtonsFromFlags(HHInfo
*pHHInfo
, TBBUTTON
*pButtons
, DWORD dwButtonFlags
, LPDWORD pdwNumButtons
)
933 int nHistBitmaps
= 0, nStdBitmaps
= 0, nHHBitmaps
= 0;
934 HWND hToolbar
= pHHInfo
->WinType
.hwndToolBar
;
939 tbAB
.hInst
= HINST_COMMCTRL
;
940 tbAB
.nID
= IDB_HIST_LARGE_COLOR
;
941 nHistBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
942 tbAB
.nID
= IDB_STD_LARGE_COLOR
;
943 nStdBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
944 /* hhctrl.ocx bitmaps */
945 tbAB
.hInst
= hhctrl_hinstance
;
946 tbAB
.nID
= IDB_HHTOOLBAR
;
947 nHHBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, HHTB_NUMBITMAPS
, (LPARAM
)&tbAB
);
951 unsupported
= dwButtonFlags
& (HHWIN_BUTTON_BROWSE_FWD
|
952 HHWIN_BUTTON_BROWSE_BCK
| HHWIN_BUTTON_NOTES
| HHWIN_BUTTON_CONTENTS
|
953 HHWIN_BUTTON_INDEX
| HHWIN_BUTTON_SEARCH
| HHWIN_BUTTON_HISTORY
|
954 HHWIN_BUTTON_FAVORITES
| HHWIN_BUTTON_JUMP1
| HHWIN_BUTTON_JUMP2
|
955 HHWIN_BUTTON_ZOOM
| HHWIN_BUTTON_TOC_NEXT
| HHWIN_BUTTON_TOC_PREV
);
957 FIXME("got asked for unsupported buttons: %06x\n", unsupported
);
959 if (dwButtonFlags
& HHWIN_BUTTON_EXPAND
)
961 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_EXPAND
, nHHBitmaps
+ HHTB_EXPAND
);
962 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_CONTRACT
, nHHBitmaps
+ HHTB_CONTRACT
);
964 if (pHHInfo
->WinType
.fNotExpanded
)
965 pButtons
[1].fsState
|= TBSTATE_HIDDEN
;
967 pButtons
[0].fsState
|= TBSTATE_HIDDEN
;
970 if (dwButtonFlags
& HHWIN_BUTTON_BACK
)
971 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_BACK
, nHistBitmaps
+ HIST_BACK
);
973 if (dwButtonFlags
& HHWIN_BUTTON_FORWARD
)
974 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_FORWARD
, nHistBitmaps
+ HIST_FORWARD
);
976 if (dwButtonFlags
& HHWIN_BUTTON_STOP
)
977 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_STOP
, nHHBitmaps
+ HHTB_STOP
);
979 if (dwButtonFlags
& HHWIN_BUTTON_REFRESH
)
980 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_REFRESH
, nHHBitmaps
+ HHTB_REFRESH
);
982 if (dwButtonFlags
& HHWIN_BUTTON_HOME
)
983 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_HOME
, nHHBitmaps
+ HHTB_HOME
);
985 if (dwButtonFlags
& HHWIN_BUTTON_SYNC
)
986 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_SYNC
, nHHBitmaps
+ HHTB_SYNC
);
988 if (dwButtonFlags
& HHWIN_BUTTON_OPTIONS
)
989 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_OPTIONS
, nStdBitmaps
+ STD_PROPERTIES
);
991 if (dwButtonFlags
& HHWIN_BUTTON_PRINT
)
992 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_PRINT
, nStdBitmaps
+ STD_PRINT
);
995 static BOOL
HH_AddToolbar(HHInfo
*pHHInfo
)
998 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1000 TBBUTTON buttons
[IDTB_TOC_PREV
- IDTB_EXPAND
];
1001 DWORD dwStyles
, dwExStyles
;
1002 DWORD dwNumButtons
, dwIndex
;
1004 if (pHHInfo
->WinType
.fsWinProperties
& HHWIN_PARAM_TB_FLAGS
)
1005 toolbarFlags
= pHHInfo
->WinType
.fsToolBarFlags
;
1007 toolbarFlags
= HHWIN_DEF_BUTTONS
;
1009 dwStyles
= WS_CHILDWINDOW
| TBSTYLE_FLAT
| TBSTYLE_WRAPABLE
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
;
1010 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1012 hToolbar
= CreateWindowExW(dwExStyles
, TOOLBARCLASSNAMEW
, NULL
, dwStyles
,
1013 0, 0, 0, 0, hwndParent
, NULL
,
1014 hhctrl_hinstance
, NULL
);
1017 pHHInfo
->WinType
.hwndToolBar
= hToolbar
;
1019 SendMessageW(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(ICON_SIZE
, ICON_SIZE
));
1020 SendMessageW(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
1021 SendMessageW(hToolbar
, WM_SETFONT
, (WPARAM
)pHHInfo
->hFont
, TRUE
);
1023 TB_AddButtonsFromFlags(pHHInfo
, buttons
, toolbarFlags
, &dwNumButtons
);
1025 for (dwIndex
= 0; dwIndex
< dwNumButtons
; dwIndex
++)
1027 LPWSTR szBuf
= HH_LoadString(buttons
[dwIndex
].idCommand
);
1028 DWORD dwLen
= strlenW(szBuf
);
1029 szBuf
[dwLen
+ 1] = 0; /* Double-null terminate */
1031 buttons
[dwIndex
].iString
= (DWORD
)SendMessageW(hToolbar
, TB_ADDSTRINGW
, 0, (LPARAM
)szBuf
);
1035 SendMessageW(hToolbar
, TB_ADDBUTTONSW
, dwNumButtons
, (LPARAM
)buttons
);
1036 SendMessageW(hToolbar
, TB_AUTOSIZE
, 0, 0);
1037 if (pHHInfo
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
)
1038 ShowWindow(hToolbar
, SW_SHOW
);
1043 /* Navigation Pane */
1045 static void NP_GetNavigationRect(HHInfo
*pHHInfo
, RECT
*rc
)
1047 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1048 HWND hwndToolbar
= pHHInfo
->WinType
.hwndToolBar
;
1049 RECT rectWND
, rectTB
;
1051 GetClientRect(hwndParent
, &rectWND
);
1052 GetClientRect(hwndToolbar
, &rectTB
);
1055 rc
->top
= rectTB
.bottom
;
1056 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
1058 if (!(pHHInfo
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1059 pHHInfo
->WinType
.iNavWidth
== 0)
1061 pHHInfo
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1064 rc
->right
= pHHInfo
->WinType
.iNavWidth
;
1067 static DWORD
NP_CreateTab(HINSTANCE hInstance
, HWND hwndTabCtrl
, DWORD index
)
1070 LPWSTR tabText
= HH_LoadString(index
);
1073 tie
.mask
= TCIF_TEXT
;
1074 tie
.pszText
= tabText
;
1076 ret
= SendMessageW( hwndTabCtrl
, TCM_INSERTITEMW
, index
, (LPARAM
)&tie
);
1082 static BOOL
HH_AddNavigationPane(HHInfo
*info
)
1084 HWND hWnd
, hwndTabCtrl
;
1085 HWND hwndParent
= info
->WinType
.hwndHelp
;
1086 DWORD dwStyles
= WS_CHILDWINDOW
;
1087 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1090 if (navigation_visible(info
))
1091 dwStyles
|= WS_VISIBLE
;
1093 NP_GetNavigationRect(info
, &rc
);
1095 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1096 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1097 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1101 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1103 hwndTabCtrl
= CreateWindowExW(dwExStyles
, WC_TABCONTROLW
, szEmpty
, dwStyles
| WS_VISIBLE
,
1105 rc
.right
- TAB_RIGHT_PADDING
,
1106 rc
.bottom
- TAB_TOP_PADDING
,
1107 hWnd
, NULL
, hhctrl_hinstance
, NULL
);
1111 if (*info
->WinType
.pszToc
)
1112 info
->tabs
[TAB_CONTENTS
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_CONTENTS
);
1114 if (*info
->WinType
.pszIndex
)
1115 info
->tabs
[TAB_INDEX
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_INDEX
);
1117 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TAB_SEARCH
)
1118 info
->tabs
[TAB_SEARCH
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_SEARCH
);
1120 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TAB_FAVORITES
)
1121 info
->tabs
[TAB_FAVORITES
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_FAVORITES
);
1123 SendMessageW(hwndTabCtrl
, WM_SETFONT
, (WPARAM
)info
->hFont
, TRUE
);
1125 info
->hwndTabCtrl
= hwndTabCtrl
;
1126 info
->WinType
.hwndNavigation
= hWnd
;
1132 static void HP_GetHTMLRect(HHInfo
*info
, RECT
*rc
)
1134 RECT rectTB
, rectWND
, rectNP
, rectSB
;
1136 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
1137 GetClientRect(info
->hwndSizeBar
, &rectSB
);
1141 if (navigation_visible(info
))
1143 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
1144 rc
->left
+= rectNP
.right
+ rectSB
.right
;
1146 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
)
1148 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
1149 rc
->top
+= rectTB
.bottom
;
1151 rc
->right
= rectWND
.right
- rc
->left
;
1152 rc
->bottom
= rectWND
.bottom
- rc
->top
;
1155 static BOOL
HH_AddHTMLPane(HHInfo
*pHHInfo
)
1158 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1159 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
;
1160 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
| WS_EX_CLIENTEDGE
;
1163 HP_GetHTMLRect(pHHInfo
, &rc
);
1165 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1166 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1167 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1171 if (!InitWebBrowser(pHHInfo
, hWnd
))
1174 /* store the pointer to the HH info struct */
1175 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
1177 ShowWindow(hWnd
, SW_SHOW
);
1180 pHHInfo
->WinType
.hwndHTML
= hWnd
;
1184 static BOOL
AddContentTab(HHInfo
*info
)
1186 HIMAGELIST hImageList
;
1190 if(info
->tabs
[TAB_CONTENTS
].id
== -1)
1191 return TRUE
; /* No "Contents" tab */
1192 hWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_TREEVIEWW
, szEmpty
, WS_CHILD
| WS_BORDER
| TVS_LINESATROOT
1193 | TVS_SHOWSELALWAYS
| TVS_HASBUTTONS
, 50, 50, 100, 100,
1194 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1196 ERR("Could not create treeview control\n");
1200 hImageList
= ImageList_Create(16, 16, ILC_COLOR32
, 0, HHTV_NUMBITMAPS
);
1201 hBitmap
= LoadBitmapW(hhctrl_hinstance
, MAKEINTRESOURCEW(IDB_HHTREEVIEW
));
1202 ImageList_Add(hImageList
, hBitmap
, NULL
);
1203 SendMessageW(hWnd
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
1205 info
->contents
.hImageList
= hImageList
;
1206 info
->tabs
[TAB_CONTENTS
].hwnd
= hWnd
;
1207 ResizeTabChild(info
, TAB_CONTENTS
);
1208 ShowWindow(hWnd
, SW_SHOW
);
1213 static BOOL
AddIndexTab(HHInfo
*info
)
1215 char hidden_column
[] = "Column";
1218 if(info
->tabs
[TAB_INDEX
].id
== -1)
1219 return TRUE
; /* No "Index" tab */
1220 info
->tabs
[TAB_INDEX
].hwnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
1221 szEmpty
, WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
| LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1222 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1223 if(!info
->tabs
[TAB_INDEX
].hwnd
) {
1224 ERR("Could not create ListView control\n");
1227 memset(&lvc
, 0, sizeof(lvc
));
1228 lvc
.mask
= LVCF_TEXT
;
1229 lvc
.pszText
= hidden_column
;
1230 if(SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1232 ERR("Could not create ListView column\n");
1236 ResizeTabChild(info
, TAB_INDEX
);
1237 ShowWindow(info
->tabs
[TAB_INDEX
].hwnd
, SW_HIDE
);
1242 static BOOL
AddSearchTab(HHInfo
*info
)
1244 HWND hwndList
, hwndEdit
, hwndContainer
;
1245 char hidden_column
[] = "Column";
1246 WNDPROC editWndProc
;
1249 if(info
->tabs
[TAB_SEARCH
].id
== -1)
1250 return TRUE
; /* No "Search" tab */
1251 hwndContainer
= CreateWindowExW(WS_EX_CONTROLPARENT
, szChildClass
, szEmpty
,
1252 WS_CHILD
, 0, 0, 0, 0, info
->WinType
.hwndNavigation
,
1253 NULL
, hhctrl_hinstance
, NULL
);
1254 if(!hwndContainer
) {
1255 ERR("Could not create search window container control.\n");
1258 hwndEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_EDITW
, szEmpty
, WS_CHILD
1259 | WS_VISIBLE
| ES_LEFT
| SS_NOTIFY
, 0, 0, 0, 0,
1260 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1262 ERR("Could not create search ListView control.\n");
1265 if(SendMessageW(hwndEdit
, WM_SETFONT
, (WPARAM
) info
->hFont
, (LPARAM
) FALSE
) == -1)
1267 ERR("Could not set font for edit control.\n");
1270 editWndProc
= (WNDPROC
) SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
, (LONG_PTR
)EditChild_WndProc
);
1272 ERR("Could not redirect messages for edit control.\n");
1275 SetWindowLongPtrW(hwndEdit
, GWLP_USERDATA
, (LONG_PTR
)editWndProc
);
1276 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1277 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| LVS_SINGLESEL
1278 | LVS_REPORT
| LVS_NOCOLUMNHEADER
, 0, 0, 0, 0,
1279 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1281 ERR("Could not create search ListView control.\n");
1284 memset(&lvc
, 0, sizeof(lvc
));
1285 lvc
.mask
= LVCF_TEXT
;
1286 lvc
.pszText
= hidden_column
;
1287 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1289 ERR("Could not create ListView column\n");
1293 info
->search
.hwndEdit
= hwndEdit
;
1294 info
->search
.hwndList
= hwndList
;
1295 info
->search
.hwndContainer
= hwndContainer
;
1296 info
->tabs
[TAB_SEARCH
].hwnd
= hwndContainer
;
1298 SetWindowLongPtrW(hwndContainer
, 0, (LONG_PTR
)info
);
1300 ResizeTabChild(info
, TAB_SEARCH
);
1305 /* The Index tab's sub-topic popup */
1307 static void ResizePopupChild(HHInfo
*info
)
1309 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
1310 int border_width
= GetSystemMetrics(SM_CXBORDER
);
1311 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
1318 GetClientRect(info
->popup
.hwndPopup
, &rect
);
1319 SetWindowPos(info
->popup
.hwndCallback
, HWND_TOP
, 0, 0,
1320 rect
.right
, rect
.bottom
, SWP_NOMOVE
);
1322 rect
.left
= TAB_MARGIN
;
1323 rect
.top
= TAB_TOP_PADDING
+ TAB_MARGIN
;
1324 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
1325 rect
.bottom
-= TAB_MARGIN
;
1326 width
= rect
.right
-rect
.left
;
1327 height
= rect
.bottom
-rect
.top
;
1329 SetWindowPos(info
->popup
.hwndList
, NULL
, rect
.left
, rect
.top
, width
, height
,
1330 SWP_NOZORDER
| SWP_NOACTIVATE
);
1332 SendMessageW(info
->popup
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
1333 width
-scroll_width
-2*border_width
-2*edge_width
);
1336 static LRESULT CALLBACK
HelpPopup_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1338 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1343 ResizePopupChild(info
);
1346 DestroyWindow(hWnd
);
1349 ShowWindow(hWnd
, SW_HIDE
);
1353 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1359 static LRESULT CALLBACK
PopupChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1364 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1368 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1371 if(info
== 0 || lParam
== 0)
1373 iter
= (IndexSubItem
*) ((NMITEMACTIVATE
*)lParam
)->lParam
;
1376 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1377 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1381 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1388 lvItem
.iItem
= (int) SendMessageW(info
->popup
.hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
1389 lvItem
.mask
= TVIF_PARAM
;
1390 SendMessageW(info
->popup
.hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
1391 iter
= (IndexSubItem
*) lvItem
.lParam
;
1392 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1393 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1400 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1406 static BOOL
AddIndexPopup(HHInfo
*info
)
1408 static const WCHAR szPopupChildClass
[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1409 static const WCHAR windowCaptionW
[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1410 static const WCHAR windowClassW
[] = {'H','H',' ','P','o','p','u','p',0};
1411 HWND hwndList
, hwndPopup
, hwndCallback
;
1412 char hidden_column
[] = "Column";
1416 if(info
->tabs
[TAB_INDEX
].id
== -1)
1417 return TRUE
; /* No "Index" tab */
1419 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1420 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1421 wcex
.lpfnWndProc
= HelpPopup_WndProc
;
1422 wcex
.cbClsExtra
= 0;
1423 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1424 wcex
.hInstance
= hhctrl_hinstance
;
1425 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1426 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1427 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1428 wcex
.lpszMenuName
= NULL
;
1429 wcex
.lpszClassName
= windowClassW
;
1430 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1431 RegisterClassExW(&wcex
);
1433 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1435 wcex
.lpfnWndProc
= PopupChild_WndProc
;
1436 wcex
.cbClsExtra
= 0;
1437 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1438 wcex
.hInstance
= hhctrl_hinstance
;
1439 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1440 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1441 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1442 wcex
.lpszMenuName
= NULL
;
1443 wcex
.lpszClassName
= szPopupChildClass
;
1444 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1445 RegisterClassExW(&wcex
);
1447 hwndPopup
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
1448 | WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
,
1449 windowClassW
, windowCaptionW
, WS_POPUPWINDOW
1450 | WS_OVERLAPPEDWINDOW
| WS_VISIBLE
1451 | WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, CW_USEDEFAULT
,
1452 CW_USEDEFAULT
, 300, 200, info
->WinType
.hwndHelp
,
1453 NULL
, hhctrl_hinstance
, NULL
);
1457 hwndCallback
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
,
1458 szPopupChildClass
, szEmpty
, WS_CHILDWINDOW
| WS_VISIBLE
,
1460 hwndPopup
, NULL
, hhctrl_hinstance
, NULL
);
1464 ShowWindow(hwndPopup
, SW_HIDE
);
1465 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1466 WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
1467 | LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1468 hwndCallback
, NULL
, hhctrl_hinstance
, NULL
);
1470 ERR("Could not create popup ListView control\n");
1473 memset(&lvc
, 0, sizeof(lvc
));
1474 lvc
.mask
= LVCF_TEXT
;
1475 lvc
.pszText
= hidden_column
;
1476 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1478 ERR("Could not create popup ListView column\n");
1482 info
->popup
.hwndCallback
= hwndCallback
;
1483 info
->popup
.hwndPopup
= hwndPopup
;
1484 info
->popup
.hwndList
= hwndList
;
1485 SetWindowLongPtrW(hwndPopup
, 0, (LONG_PTR
)info
);
1486 SetWindowLongPtrW(hwndCallback
, 0, (LONG_PTR
)info
);
1488 ResizePopupChild(info
);
1489 ShowWindow(hwndList
, SW_SHOW
);
1496 static void ExpandContract(HHInfo
*pHHInfo
)
1500 pHHInfo
->WinType
.fNotExpanded
= !pHHInfo
->WinType
.fNotExpanded
;
1501 GetWindowRect(pHHInfo
->WinType
.hwndHelp
, &r
);
1502 NP_GetNavigationRect(pHHInfo
, &nav
);
1504 /* hide/show both the nav bar and the size bar */
1505 if (pHHInfo
->WinType
.fNotExpanded
)
1507 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_HIDE
);
1508 ShowWindow(pHHInfo
->hwndSizeBar
, SW_HIDE
);
1509 r
.left
= r
.left
+ nav
.right
;
1511 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(FALSE
, 0));
1512 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(TRUE
, 0));
1516 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_SHOW
);
1517 ShowWindow(pHHInfo
->hwndSizeBar
, SW_SHOW
);
1518 r
.left
= r
.left
- nav
.right
;
1520 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(TRUE
, 0));
1521 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(FALSE
, 0));
1524 MoveWindow(pHHInfo
->WinType
.hwndHelp
, r
.left
, r
.top
, r
.right
-r
.left
, r
.bottom
-r
.top
, TRUE
);
1527 static LRESULT
Help_OnSize(HWND hWnd
)
1529 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1536 if (navigation_visible(pHHInfo
))
1538 NP_GetNavigationRect(pHHInfo
, &rc
);
1539 SetWindowPos(pHHInfo
->WinType
.hwndNavigation
, HWND_TOP
, 0, 0,
1540 rc
.right
, rc
.bottom
, SWP_NOMOVE
);
1542 SB_GetSizeBarRect(pHHInfo
, &rc
);
1543 SetWindowPos(pHHInfo
->hwndSizeBar
, HWND_TOP
, rc
.left
, rc
.top
,
1544 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1548 HP_GetHTMLRect(pHHInfo
, &rc
);
1549 SetWindowPos(pHHInfo
->WinType
.hwndHTML
, HWND_TOP
, rc
.left
, rc
.top
,
1550 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1552 /* Resize browser window taking the frame size into account */
1553 dwSize
= GetSystemMetrics(SM_CXFRAME
);
1554 ResizeWebBrowser(pHHInfo
, rc
.right
- dwSize
, rc
.bottom
- dwSize
);
1559 void UpdateHelpWindow(HHInfo
*info
)
1561 if (!info
->WinType
.hwndHelp
)
1564 WARN("Only the size of the window is currently updated.\n");
1565 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_RECT
)
1567 RECT
*rect
= &info
->WinType
.rcWindowPos
;
1568 INT x
, y
, width
, height
;
1572 width
= rect
->right
- x
;
1573 height
= rect
->bottom
- y
;
1574 SetWindowPos(info
->WinType
.hwndHelp
, NULL
, rect
->left
, rect
->top
, width
, height
,
1575 SWP_NOZORDER
| SWP_NOACTIVATE
);
1579 static LRESULT CALLBACK
Help_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1584 if (HIWORD(wParam
) == BN_CLICKED
)
1585 TB_OnClick(hWnd
, LOWORD(wParam
));
1588 return Help_OnSize(hWnd
);
1590 ReleaseHelpViewer((HHInfo
*)GetWindowLongPtrW(hWnd
, 0));
1598 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1604 static BOOL
HH_CreateHelpWindow(HHInfo
*info
)
1606 HWND hWnd
, parent
= 0;
1607 RECT winPos
= info
->WinType
.rcWindowPos
;
1609 DWORD dwStyles
, dwExStyles
;
1610 DWORD x
, y
, width
= 0, height
= 0;
1613 static const WCHAR windowClassW
[] = {
1614 'H','H',' ', 'P','a','r','e','n','t',0
1617 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1618 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1619 wcex
.lpfnWndProc
= Help_WndProc
;
1620 wcex
.cbClsExtra
= 0;
1621 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1622 wcex
.hInstance
= hhctrl_hinstance
;
1623 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1624 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1625 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1626 wcex
.lpszMenuName
= NULL
;
1627 wcex
.lpszClassName
= windowClassW
;
1628 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1630 RegisterClassExW(&wcex
);
1632 /* Read in window parameters if available */
1633 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_STYLES
)
1635 dwStyles
= info
->WinType
.dwStyles
;
1636 if (!(info
->WinType
.dwStyles
& WS_CHILD
))
1637 dwStyles
|= WS_OVERLAPPEDWINDOW
;
1640 dwStyles
= WS_OVERLAPPEDWINDOW
| WS_VISIBLE
|
1641 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1643 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_EXSTYLES
)
1644 dwExStyles
= info
->WinType
.dwExStyles
;
1646 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
|
1647 WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
;
1649 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_RECT
)
1653 width
= winPos
.right
- x
;
1654 height
= winPos
.bottom
- y
;
1656 if (!width
|| !height
)
1658 x
= WINTYPE_DEFAULT_X
;
1659 y
= WINTYPE_DEFAULT_Y
;
1660 width
= WINTYPE_DEFAULT_WIDTH
;
1661 height
= WINTYPE_DEFAULT_HEIGHT
;
1664 if (!(info
->WinType
.fsWinProperties
& HHWIN_PROP_TRI_PANE
) && info
->WinType
.fNotExpanded
)
1666 if (!(info
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1667 info
->WinType
.iNavWidth
== 0)
1669 info
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1672 x
+= info
->WinType
.iNavWidth
;
1673 width
-= info
->WinType
.iNavWidth
;
1677 caption
= info
->WinType
.pszCaption
;
1678 if (!*caption
) caption
= info
->pCHMInfo
->defTitle
;
1680 if (info
->WinType
.dwStyles
& WS_CHILD
)
1681 parent
= info
->WinType
.hwndCaller
;
1683 hWnd
= CreateWindowExW(dwExStyles
, windowClassW
, caption
,
1684 dwStyles
, x
, y
, width
, height
, parent
, NULL
, hhctrl_hinstance
, NULL
);
1688 ShowWindow(hWnd
, SW_SHOW
);
1691 /* store the pointer to the HH info struct */
1692 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1694 info
->WinType
.hwndHelp
= hWnd
;
1698 static void HH_CreateFont(HHInfo
*pHHInfo
)
1702 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
), sizeof(LOGFONTW
), &lf
);
1703 lf
.lfWeight
= FW_NORMAL
;
1704 lf
.lfItalic
= FALSE
;
1705 lf
.lfUnderline
= FALSE
;
1707 pHHInfo
->hFont
= CreateFontIndirectW(&lf
);
1710 static void HH_InitRequiredControls(DWORD dwControls
)
1712 INITCOMMONCONTROLSEX icex
;
1714 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1715 icex
.dwICC
= dwControls
;
1716 InitCommonControlsEx(&icex
);
1719 /* Creates the whole package */
1720 static BOOL
CreateViewer(HHInfo
*pHHInfo
)
1722 HH_CreateFont(pHHInfo
);
1724 if (!HH_CreateHelpWindow(pHHInfo
))
1727 HH_InitRequiredControls(ICC_BAR_CLASSES
);
1729 if (!HH_AddToolbar(pHHInfo
))
1732 HH_RegisterChildWndClass(pHHInfo
);
1734 if (!HH_AddNavigationPane(pHHInfo
))
1737 HH_RegisterSizeBarClass(pHHInfo
);
1739 if (!HH_AddSizeBar(pHHInfo
))
1742 if (!HH_AddHTMLPane(pHHInfo
))
1745 if (!AddContentTab(pHHInfo
))
1748 if (!AddIndexTab(pHHInfo
))
1751 if (!AddIndexPopup(pHHInfo
))
1754 if (!AddSearchTab(pHHInfo
))
1757 InitContent(pHHInfo
);
1760 pHHInfo
->viewer_initialized
= TRUE
;
1764 void wintype_stringsW_free(struct wintype_stringsW
*stringsW
)
1766 heap_free(stringsW
->pszType
);
1767 heap_free(stringsW
->pszCaption
);
1768 heap_free(stringsW
->pszToc
);
1769 heap_free(stringsW
->pszIndex
);
1770 heap_free(stringsW
->pszFile
);
1771 heap_free(stringsW
->pszHome
);
1772 heap_free(stringsW
->pszJump1
);
1773 heap_free(stringsW
->pszJump2
);
1774 heap_free(stringsW
->pszUrlJump1
);
1775 heap_free(stringsW
->pszUrlJump2
);
1778 void wintype_stringsA_free(struct wintype_stringsA
*stringsA
)
1780 heap_free(stringsA
->pszType
);
1781 heap_free(stringsA
->pszCaption
);
1782 heap_free(stringsA
->pszToc
);
1783 heap_free(stringsA
->pszIndex
);
1784 heap_free(stringsA
->pszFile
);
1785 heap_free(stringsA
->pszHome
);
1786 heap_free(stringsA
->pszJump1
);
1787 heap_free(stringsA
->pszJump2
);
1788 heap_free(stringsA
->pszUrlJump1
);
1789 heap_free(stringsA
->pszUrlJump2
);
1790 heap_free(stringsA
->pszCustomTabs
);
1793 void ReleaseHelpViewer(HHInfo
*info
)
1795 TRACE("(%p)\n", info
);
1800 list_remove(&info
->entry
);
1802 wintype_stringsA_free(&info
->stringsA
);
1803 wintype_stringsW_free(&info
->stringsW
);
1806 CloseCHM(info
->pCHMInfo
);
1808 ReleaseWebBrowser(info
);
1809 ReleaseContent(info
);
1811 ReleaseSearch(info
);
1813 if(info
->contents
.hImageList
)
1814 ImageList_Destroy(info
->contents
.hImageList
);
1815 if(info
->WinType
.hwndHelp
)
1816 DestroyWindow(info
->WinType
.hwndHelp
);
1822 HHInfo
*CreateHelpViewer(HHInfo
*info
, LPCWSTR filename
, HWND caller
)
1829 info
= heap_alloc_zero(sizeof(HHInfo
));
1830 list_add_tail(&window_list
, &info
->entry
);
1833 /* Set the invalid tab ID (-1) as the default value for all
1834 * of the tabs, this matches a failed TCM_INSERTITEM call.
1836 for(i
=0;i
<sizeof(info
->tabs
)/sizeof(HHTab
);i
++)
1837 info
->tabs
[i
].id
= -1;
1839 OleInitialize(NULL
);
1841 info
->pCHMInfo
= OpenCHM(filename
);
1842 if(!info
->pCHMInfo
) {
1843 ReleaseHelpViewer(info
);
1847 if (!LoadWinTypeFromCHM(info
)) {
1848 ReleaseHelpViewer(info
);
1851 info
->WinType
.hwndCaller
= caller
;
1853 /* If the window is already open then load the file in that existing window */
1854 if ((tmp_info
= find_window(info
->WinType
.pszType
)) && tmp_info
!= info
)
1856 ReleaseHelpViewer(info
);
1857 return CreateHelpViewer(tmp_info
, filename
, caller
);
1860 if(!info
->viewer_initialized
&& !CreateViewer(info
)) {
1861 ReleaseHelpViewer(info
);
1869 * Search the table of HTML entities and return the corresponding ANSI symbol.
1871 static char find_html_symbol(const char *entity
, int entity_len
)
1873 int max
= sizeof(html_encoded_symbols
)/sizeof(html_encoded_symbols
[0])-1;
1878 int pos
= (min
+max
)/2;
1879 const char *encoded_symbol
= html_encoded_symbols
[pos
].html_code
;
1880 dir
= strncmp(encoded_symbol
, entity
, entity_len
);
1881 if(dir
== 0 && !encoded_symbol
[entity_len
]) return html_encoded_symbols
[pos
].ansi_symbol
;
1891 * Decode a string containing HTML encoded characters into a unicode string.
1893 WCHAR
*decode_html(const char *html_fragment
, int html_fragment_len
, UINT code_page
)
1895 const char *h
= html_fragment
, *amp
, *sem
;
1897 int len
, tmp_len
= 0;
1898 WCHAR
*unicode_text
;
1900 tmp
= heap_alloc(html_fragment_len
+1);
1904 amp
= strchr(h
, '&');
1907 /* Copy the characters prior to the HTML encoded character */
1908 memcpy(&tmp
[tmp_len
], h
, len
);
1910 amp
++; /* skip ampersand */
1911 sem
= strchr(amp
, ';');
1912 /* Require a semicolon after the ampersand */
1916 tmp
[tmp_len
++] = '&';
1919 /* Find the symbol either by using the ANSI character number (prefixed by the pound symbol)
1920 * or by searching the HTML entity table */
1924 char *endnum
= NULL
;
1927 tmp
= (char) strtol(amp
, &endnum
, 10);
1932 symbol
= find_html_symbol(amp
, len
);
1935 FIXME("Failed to translate HTML encoded character '&%.*s;'.\n", len
, amp
);
1937 tmp
[tmp_len
++] = '&';
1940 /* Insert the new symbol */
1942 tmp
[tmp_len
++] = symbol
;
1944 /* Convert any remaining characters */
1945 len
= html_fragment_len
-(h
-html_fragment
);
1946 memcpy(&tmp
[tmp_len
], h
, len
);
1948 tmp
[tmp_len
++] = 0; /* NULL-terminate the string */
1950 len
= MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, NULL
, 0);
1951 unicode_text
= heap_alloc(len
*sizeof(WCHAR
));
1952 MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, unicode_text
, len
);
1954 return unicode_text
;
1957 /* Find the HTMLHelp structure for an existing window title */
1958 HHInfo
*find_window(const WCHAR
*window
)
1962 LIST_FOR_EACH_ENTRY(info
, &window_list
, HHInfo
, entry
)
1964 if (strcmpW(info
->WinType
.pszType
, window
) == 0)