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 struct html_encoded_symbol html_encoded_symbols
[] =
168 /* Loads a string from the resource file */
169 static LPWSTR
HH_LoadString(DWORD dwID
)
171 LPWSTR string
= NULL
;
172 LPCWSTR stringresource
;
175 iSize
= LoadStringW(hhctrl_hinstance
, dwID
, (LPWSTR
)&stringresource
, 0);
177 string
= heap_alloc((iSize
+ 2) * sizeof(WCHAR
)); /* some strings (tab text) needs double-null termination */
178 memcpy(string
, stringresource
, iSize
*sizeof(WCHAR
));
184 static HRESULT
navigate_url(HHInfo
*info
, LPCWSTR surl
)
189 TRACE("%s\n", debugstr_w(surl
));
191 V_VT(&url
) = VT_BSTR
;
192 V_BSTR(&url
) = SysAllocString(surl
);
194 hres
= IWebBrowser2_Navigate2(info
->web_browser
, &url
, 0, 0, 0, 0);
199 TRACE("Navigation failed: %08x\n", hres
);
204 BOOL
NavigateToUrl(HHInfo
*info
, LPCWSTR surl
)
210 static const WCHAR url_indicator
[] = {':', '/', '/', 0};
212 TRACE("%s\n", debugstr_w(surl
));
214 if (strstrW(surl
, url_indicator
)) {
215 hres
= navigate_url(info
, surl
);
218 } /* look up in chm if it doesn't look like a full url */
220 SetChmPath(&chm_path
, info
->pCHMInfo
->szFile
, surl
);
221 ret
= NavigateToChm(info
, chm_path
.chm_file
, chm_path
.chm_index
);
223 heap_free(chm_path
.chm_file
);
224 heap_free(chm_path
.chm_index
);
229 static BOOL
AppendFullPathURL(LPCWSTR file
, LPWSTR buf
, LPCWSTR index
)
231 static const WCHAR url_format
[] =
232 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
233 static const WCHAR slash
[] = {'/',0};
234 static const WCHAR empty
[] = {0};
235 WCHAR full_path
[MAX_PATH
];
237 TRACE("%s %p %s\n", debugstr_w(file
), buf
, debugstr_w(index
));
239 if(!GetFullPathNameW(file
, sizeof(full_path
)/sizeof(full_path
[0]), full_path
, NULL
)) {
240 WARN("GetFullPathName failed: %u\n", GetLastError());
244 wsprintfW(buf
, url_format
, full_path
, (!index
|| index
[0] == '/') ? empty
: slash
, index
);
248 BOOL
NavigateToChm(HHInfo
*info
, LPCWSTR file
, LPCWSTR index
)
250 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
253 TRACE("%p %s %s\n", info
, debugstr_w(file
), debugstr_w(index
));
255 if ((!info
->web_browser
) || !AppendFullPathURL(file
, buf
, index
))
259 if((ptr
= strchrW(buf
, '#')))
262 return SUCCEEDED(navigate_url(info
, buf
));
265 static void DoSync(HHInfo
*info
)
267 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
272 hres
= IWebBrowser2_get_LocationURL(info
->web_browser
, &url
);
276 WARN("get_LocationURL failed: %08x\n", hres
);
280 /* If we're not currently viewing a page in the active .chm file, abort */
281 if ((!AppendFullPathURL(info
->pszFile
, buf
, NULL
)) || (len
= lstrlenW(buf
) > lstrlenW(url
)))
287 if (lstrcmpiW(buf
, url
) > 0)
289 static const WCHAR delimW
[] = {':',':','/',0};
292 index
= strstrW(url
, delimW
);
295 ActivateContentTopic(info
->tabs
[TAB_CONTENTS
].hwnd
, index
+ 3, info
->content
); /* skip over ::/ */
303 #define SIZEBAR_WIDTH 4
305 static const WCHAR szSizeBarClass
[] = {
306 'H','H',' ','S','i','z','e','B','a','r',0
309 /* Draw the SizeBar */
310 static void SB_OnPaint(HWND hWnd
)
316 hdc
= BeginPaint(hWnd
, &ps
);
318 GetClientRect(hWnd
, &rc
);
323 FrameRect(hdc
, &rc
, GetStockObject(GRAY_BRUSH
));
325 /* white highlight */
326 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
327 MoveToEx(hdc
, rc
.right
, 1, NULL
);
329 LineTo(hdc
, 1, rc
.bottom
- 1);
332 MoveToEx(hdc
, 0, rc
.bottom
, NULL
);
333 LineTo(hdc
, rc
.right
, rc
.bottom
);
338 static void SB_OnLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
343 static void SB_OnLButtonUp(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
345 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
348 pt
.x
= (short)LOWORD(lParam
);
349 pt
.y
= (short)HIWORD(lParam
);
351 /* update the window sizes */
352 pHHInfo
->WinType
.iNavWidth
+= pt
.x
;
358 static void SB_OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
360 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
361 if (!(wParam
& MK_LBUTTON
))
365 static LRESULT CALLBACK
SizeBar_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
370 SB_OnLButtonDown(hWnd
, wParam
, lParam
);
373 SB_OnLButtonUp(hWnd
, wParam
, lParam
);
376 SB_OnMouseMove(hWnd
, wParam
, lParam
);
382 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
388 static void HH_RegisterSizeBarClass(HHInfo
*pHHInfo
)
392 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
394 wcex
.lpfnWndProc
= SizeBar_WndProc
;
396 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
397 wcex
.hInstance
= hhctrl_hinstance
;
398 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
399 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_SIZEWE
);
400 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
401 wcex
.lpszMenuName
= NULL
;
402 wcex
.lpszClassName
= szSizeBarClass
;
403 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
405 RegisterClassExW(&wcex
);
408 static void SB_GetSizeBarRect(HHInfo
*info
, RECT
*rc
)
410 RECT rectWND
, rectTB
, rectNP
;
412 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
413 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
414 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
416 rc
->left
= rectNP
.right
;
417 rc
->top
= rectTB
.bottom
;
418 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
419 rc
->right
= SIZEBAR_WIDTH
;
422 static BOOL
HH_AddSizeBar(HHInfo
*pHHInfo
)
425 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
426 DWORD dwStyles
= WS_CHILDWINDOW
| WS_OVERLAPPED
;
427 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
430 if (!pHHInfo
->WinType
.fNotExpanded
)
431 dwStyles
|= WS_VISIBLE
;
433 SB_GetSizeBarRect(pHHInfo
, &rc
);
435 hWnd
= CreateWindowExW(dwExStyles
, szSizeBarClass
, szEmpty
, dwStyles
,
436 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
437 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
441 /* store the pointer to the HH info struct */
442 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
444 pHHInfo
->hwndSizeBar
= hWnd
;
450 static const WCHAR szChildClass
[] = {
451 'H','H',' ','C','h','i','l','d',0
454 static LRESULT
Child_OnPaint(HWND hWnd
)
460 hdc
= BeginPaint(hWnd
, &ps
);
462 /* Only paint the Navigation pane, identified by the fact
463 * that it has a child window
465 if (GetWindow(hWnd
, GW_CHILD
))
467 GetClientRect(hWnd
, &rc
);
469 /* set the border color */
470 SelectObject(hdc
, GetStockObject(DC_PEN
));
471 SetDCPenColor(hdc
, GetSysColor(COLOR_BTNSHADOW
));
473 /* Draw the top border */
474 LineTo(hdc
, rc
.right
, 0);
476 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
477 MoveToEx(hdc
, 0, 1, NULL
);
478 LineTo(hdc
, rc
.right
, 1);
486 static void ResizeTabChild(HHInfo
*info
, int tab
)
488 HWND hwnd
= info
->tabs
[tab
].hwnd
;
493 GetClientRect(info
->WinType
.hwndNavigation
, &rect
);
494 SendMessageW(info
->hwndTabCtrl
, TCM_GETITEMRECT
, 0, (LPARAM
)&tabrc
);
495 cnt
= SendMessageW(info
->hwndTabCtrl
, TCM_GETROWCOUNT
, 0, 0);
497 rect
.left
= TAB_MARGIN
;
498 rect
.top
= TAB_TOP_PADDING
+ cnt
*(tabrc
.bottom
-tabrc
.top
) + TAB_MARGIN
;
499 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
500 rect
.bottom
-= TAB_MARGIN
;
501 width
= rect
.right
-rect
.left
;
502 height
= rect
.bottom
-rect
.top
;
504 SetWindowPos(hwnd
, NULL
, rect
.left
, rect
.top
, width
, height
,
505 SWP_NOZORDER
| SWP_NOACTIVATE
);
510 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
511 int border_width
= GetSystemMetrics(SM_CXBORDER
);
512 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
514 /* Resize the tab widget column to perfectly fit the tab window and
515 * leave sufficient space for the scroll widget.
517 SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_SETCOLUMNWIDTH
, 0,
518 width
-scroll_width
-2*border_width
-2*edge_width
);
523 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
524 int border_width
= GetSystemMetrics(SM_CXBORDER
);
525 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
528 SetWindowPos(info
->search
.hwndEdit
, NULL
, 0, top_pos
, width
,
529 EDIT_HEIGHT
, SWP_NOZORDER
| SWP_NOACTIVATE
);
530 top_pos
+= EDIT_HEIGHT
+ TAB_MARGIN
;
531 SetWindowPos(info
->search
.hwndList
, NULL
, 0, top_pos
, width
,
532 height
-top_pos
, SWP_NOZORDER
| SWP_NOACTIVATE
);
533 /* Resize the tab widget column to perfectly fit the tab window and
534 * leave sufficient space for the scroll widget.
536 SendMessageW(info
->search
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
537 width
-scroll_width
-2*border_width
-2*edge_width
);
544 static LRESULT
Child_OnSize(HWND hwnd
)
546 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
549 if(!info
|| hwnd
!= info
->WinType
.hwndNavigation
)
552 GetClientRect(hwnd
, &rect
);
553 SetWindowPos(info
->hwndTabCtrl
, HWND_TOP
, 0, 0,
554 rect
.right
- TAB_RIGHT_PADDING
,
555 rect
.bottom
- TAB_TOP_PADDING
, SWP_NOMOVE
);
557 ResizeTabChild(info
, TAB_CONTENTS
);
558 ResizeTabChild(info
, TAB_INDEX
);
559 ResizeTabChild(info
, TAB_SEARCH
);
563 static LRESULT
OnTabChange(HWND hwnd
)
565 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
566 int tab_id
, tab_index
, i
;
573 if(info
->tabs
[info
->current_tab
].hwnd
)
574 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_HIDE
);
576 tab_id
= (int) SendMessageW(info
->hwndTabCtrl
, TCM_GETCURSEL
, 0, 0);
577 /* convert the ID of the tab to an index in our tab list */
579 for (i
=0; i
<TAB_NUMTABS
; i
++)
581 if (info
->tabs
[i
].id
== tab_id
)
589 FIXME("Tab ID %d does not correspond to a valid index in the tab list.\n", tab_id
);
592 info
->current_tab
= tab_index
;
594 if(info
->tabs
[info
->current_tab
].hwnd
)
595 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_SHOW
);
600 static LRESULT
OnTopicChange(HHInfo
*info
, void *user_data
)
602 LPCWSTR chmfile
= NULL
, name
= NULL
, local
= NULL
;
607 if(!user_data
|| !info
)
610 switch (info
->current_tab
)
613 citer
= (ContentItem
*) user_data
;
615 local
= citer
->local
;
617 if(citer
->merge
.chm_file
) {
618 chmfile
= citer
->merge
.chm_file
;
621 citer
= citer
->parent
;
625 iiter
= (IndexItem
*) user_data
;
626 if(iiter
->nItems
== 0) {
627 FIXME("No entries for this item!\n");
630 if(iiter
->nItems
> 1) {
634 SendMessageW(info
->popup
.hwndList
, LVM_DELETEALLITEMS
, 0, 0);
635 for(i
=0;i
<iiter
->nItems
;i
++) {
636 IndexSubItem
*item
= &iiter
->items
[i
];
637 WCHAR
*name
= iiter
->keyword
;
640 item
->name
= GetDocumentTitle(info
->pCHMInfo
, item
->local
);
643 memset(&lvi
, 0, sizeof(lvi
));
645 lvi
.mask
= LVIF_TEXT
|LVIF_PARAM
;
646 lvi
.cchTextMax
= strlenW(name
)+1;
648 lvi
.lParam
= (LPARAM
) item
;
649 SendMessageW(info
->popup
.hwndList
, LVM_INSERTITEMW
, 0, (LPARAM
)&lvi
);
651 ShowWindow(info
->popup
.hwndPopup
, SW_SHOW
);
654 name
= iiter
->items
[0].name
;
655 local
= iiter
->items
[0].local
;
656 chmfile
= iiter
->merge
.chm_file
;
659 siter
= (SearchItem
*) user_data
;
660 name
= siter
->filename
;
661 local
= siter
->filename
;
662 chmfile
= info
->pCHMInfo
->szFile
;
665 FIXME("Unhandled operation for this tab!\n");
671 FIXME("No help file found for this item!\n");
675 TRACE("name %s loal %s\n", debugstr_w(name
), debugstr_w(local
));
677 NavigateToChm(info
, chmfile
, local
);
681 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
682 static LRESULT CALLBACK
EditChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
684 WNDPROC editWndProc
= (WNDPROC
)GetWindowLongPtrW(hWnd
, GWLP_USERDATA
);
686 if(message
== WM_KEYUP
&& wParam
== VK_RETURN
)
690 nmhdr
.hwndFrom
= hWnd
;
691 nmhdr
.code
= NM_RETURN
;
692 SendMessageW(GetParent(GetParent(hWnd
)), WM_NOTIFY
, wParam
, (LPARAM
)&nmhdr
);
694 return editWndProc(hWnd
, message
, wParam
, lParam
);
697 static LRESULT CALLBACK
Child_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
702 return Child_OnPaint(hWnd
);
704 return Child_OnSize(hWnd
);
706 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
707 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
709 switch(nmhdr
->code
) {
711 return OnTabChange(hWnd
);
712 case TVN_SELCHANGEDW
:
713 return OnTopicChange(info
, (void*)((NMTREEVIEWW
*)lParam
)->itemNew
.lParam
);
714 case TVN_ITEMEXPANDINGW
: {
715 TVITEMW
*item
= &((NMTREEVIEWW
*)lParam
)->itemNew
;
716 HWND hwndTreeView
= info
->tabs
[TAB_CONTENTS
].hwnd
;
718 item
->mask
= TVIF_IMAGE
|TVIF_SELECTEDIMAGE
;
719 if (item
->state
& TVIS_EXPANDED
)
721 item
->iImage
= HHTV_FOLDER
;
722 item
->iSelectedImage
= HHTV_FOLDER
;
726 item
->iImage
= HHTV_OPENFOLDER
;
727 item
->iSelectedImage
= HHTV_OPENFOLDER
;
729 SendMessageW(hwndTreeView
, TVM_SETITEMW
, 0, (LPARAM
)item
);
735 switch(info
->current_tab
)
738 return OnTopicChange(info
, (void*)((NMITEMACTIVATE
*)lParam
)->lParam
);
740 return OnTopicChange(info
, (void*)((NMITEMACTIVATE
*)lParam
)->lParam
);
746 switch(info
->current_tab
) {
748 HWND hwndList
= info
->tabs
[TAB_INDEX
].hwnd
;
751 lvItem
.iItem
= (int) SendMessageW(hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
752 lvItem
.mask
= TVIF_PARAM
;
753 SendMessageW(hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
754 OnTopicChange(info
, (void*) lvItem
.lParam
);
758 if(nmhdr
->hwndFrom
== info
->search
.hwndEdit
) {
762 len
= GetWindowTextA(info
->search
.hwndEdit
, needle
, sizeof(needle
));
765 FIXME("Unable to get search text.\n");
768 /* Convert the requested text for comparison later against the
769 * lower case version of HTML file contents.
772 needle
[i
] = tolower(needle
[i
]);
773 InitSearch(info
, needle
);
775 }else if(nmhdr
->hwndFrom
== info
->search
.hwndList
) {
776 HWND hwndList
= info
->search
.hwndList
;
779 lvItem
.iItem
= (int) SendMessageW(hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
780 lvItem
.mask
= TVIF_PARAM
;
781 SendMessageW(hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
782 OnTopicChange(info
, (void*) lvItem
.lParam
);
793 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
799 static void HH_RegisterChildWndClass(HHInfo
*pHHInfo
)
803 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
805 wcex
.lpfnWndProc
= Child_WndProc
;
807 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
808 wcex
.hInstance
= hhctrl_hinstance
;
809 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
810 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
811 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
812 wcex
.lpszMenuName
= NULL
;
813 wcex
.lpszClassName
= szChildClass
;
814 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
816 RegisterClassExW(&wcex
);
823 static void DisplayPopupMenu(HHInfo
*info
)
826 TBBUTTONINFOW button
;
832 menu
= LoadMenuW(hhctrl_hinstance
, MAKEINTRESOURCEW(MENU_POPUP
));
837 submenu
= GetSubMenu(menu
, 0);
839 /* Update the Show/Hide menu item */
840 item
.cbSize
= sizeof(MENUITEMINFOW
);
841 item
.fMask
= MIIM_FTYPE
| MIIM_STATE
| MIIM_STRING
;
842 item
.fType
= MFT_STRING
;
843 item
.fState
= MF_ENABLED
;
845 if (info
->WinType
.fNotExpanded
)
846 item
.dwTypeData
= HH_LoadString(IDS_SHOWTABS
);
848 item
.dwTypeData
= HH_LoadString(IDS_HIDETABS
);
850 SetMenuItemInfoW(submenu
, IDTB_EXPAND
, FALSE
, &item
);
851 heap_free(item
.dwTypeData
);
853 /* Find the index toolbar button */
854 button
.cbSize
= sizeof(TBBUTTONINFOW
);
855 button
.dwMask
= TBIF_COMMAND
;
856 index
= SendMessageW(info
->WinType
.hwndToolBar
, TB_GETBUTTONINFOW
, IDTB_OPTIONS
, (LPARAM
) &button
);
862 SendMessageW(info
->WinType
.hwndToolBar
, TB_GETITEMRECT
, index
, (LPARAM
) &rect
);
864 coords
.x
= rect
.left
;
865 coords
.y
= rect
.bottom
;
867 ClientToScreen(info
->WinType
.hwndToolBar
, &coords
);
868 TrackPopupMenu(submenu
, TPM_LEFTALIGN
| TPM_TOPALIGN
| TPM_LEFTBUTTON
| TPM_NOANIMATION
, coords
.x
, coords
.y
, 0, info
->WinType
.hwndHelp
, NULL
);
871 static void TB_OnClick(HWND hWnd
, DWORD dwID
)
873 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
878 DoPageAction(info
, WB_STOP
);
881 DoPageAction(info
, WB_REFRESH
);
884 DoPageAction(info
, WB_GOBACK
);
887 NavigateToChm(info
, info
->pCHMInfo
->szFile
, info
->WinType
.pszHome
);
890 DoPageAction(info
, WB_GOFORWARD
);
893 DoPageAction(info
, WB_PRINT
);
897 ExpandContract(info
);
903 DisplayPopupMenu(info
);
911 /* These are officially unimplemented as of the Windows 7 SDK */
913 case IDTB_BROWSE_FWD
:
914 case IDTB_BROWSE_BACK
:
925 static void TB_AddButton(TBBUTTON
*pButtons
, DWORD dwIndex
, DWORD dwID
, DWORD dwBitmap
)
927 pButtons
[dwIndex
].iBitmap
= dwBitmap
;
928 pButtons
[dwIndex
].idCommand
= dwID
;
929 pButtons
[dwIndex
].fsState
= TBSTATE_ENABLED
;
930 pButtons
[dwIndex
].fsStyle
= BTNS_BUTTON
;
931 pButtons
[dwIndex
].dwData
= 0;
932 pButtons
[dwIndex
].iString
= 0;
935 static void TB_AddButtonsFromFlags(HHInfo
*pHHInfo
, TBBUTTON
*pButtons
, DWORD dwButtonFlags
, LPDWORD pdwNumButtons
)
937 int nHistBitmaps
= 0, nStdBitmaps
= 0, nHHBitmaps
= 0;
938 HWND hToolbar
= pHHInfo
->WinType
.hwndToolBar
;
943 tbAB
.hInst
= HINST_COMMCTRL
;
944 tbAB
.nID
= IDB_HIST_LARGE_COLOR
;
945 nHistBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
946 tbAB
.nID
= IDB_STD_LARGE_COLOR
;
947 nStdBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, 0, (LPARAM
)&tbAB
);
948 /* hhctrl.ocx bitmaps */
949 tbAB
.hInst
= hhctrl_hinstance
;
950 tbAB
.nID
= IDB_HHTOOLBAR
;
951 nHHBitmaps
= SendMessageW(hToolbar
, TB_ADDBITMAP
, HHTB_NUMBITMAPS
, (LPARAM
)&tbAB
);
955 unsupported
= dwButtonFlags
& (HHWIN_BUTTON_BROWSE_FWD
|
956 HHWIN_BUTTON_BROWSE_BCK
| HHWIN_BUTTON_NOTES
| HHWIN_BUTTON_CONTENTS
|
957 HHWIN_BUTTON_INDEX
| HHWIN_BUTTON_SEARCH
| HHWIN_BUTTON_HISTORY
|
958 HHWIN_BUTTON_FAVORITES
| HHWIN_BUTTON_JUMP1
| HHWIN_BUTTON_JUMP2
|
959 HHWIN_BUTTON_ZOOM
| HHWIN_BUTTON_TOC_NEXT
| HHWIN_BUTTON_TOC_PREV
);
961 FIXME("got asked for unsupported buttons: %06x\n", unsupported
);
963 if (dwButtonFlags
& HHWIN_BUTTON_EXPAND
)
965 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_EXPAND
, nHHBitmaps
+ HHTB_EXPAND
);
966 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_CONTRACT
, nHHBitmaps
+ HHTB_CONTRACT
);
968 if (pHHInfo
->WinType
.fNotExpanded
)
969 pButtons
[1].fsState
|= TBSTATE_HIDDEN
;
971 pButtons
[0].fsState
|= TBSTATE_HIDDEN
;
974 if (dwButtonFlags
& HHWIN_BUTTON_BACK
)
975 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_BACK
, nHistBitmaps
+ HIST_BACK
);
977 if (dwButtonFlags
& HHWIN_BUTTON_FORWARD
)
978 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_FORWARD
, nHistBitmaps
+ HIST_FORWARD
);
980 if (dwButtonFlags
& HHWIN_BUTTON_STOP
)
981 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_STOP
, nHHBitmaps
+ HHTB_STOP
);
983 if (dwButtonFlags
& HHWIN_BUTTON_REFRESH
)
984 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_REFRESH
, nHHBitmaps
+ HHTB_REFRESH
);
986 if (dwButtonFlags
& HHWIN_BUTTON_HOME
)
987 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_HOME
, nHHBitmaps
+ HHTB_HOME
);
989 if (dwButtonFlags
& HHWIN_BUTTON_SYNC
)
990 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_SYNC
, nHHBitmaps
+ HHTB_SYNC
);
992 if (dwButtonFlags
& HHWIN_BUTTON_OPTIONS
)
993 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_OPTIONS
, nStdBitmaps
+ STD_PROPERTIES
);
995 if (dwButtonFlags
& HHWIN_BUTTON_PRINT
)
996 TB_AddButton(pButtons
, (*pdwNumButtons
)++, IDTB_PRINT
, nStdBitmaps
+ STD_PRINT
);
999 static BOOL
HH_AddToolbar(HHInfo
*pHHInfo
)
1002 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1004 TBBUTTON buttons
[IDTB_TOC_PREV
- IDTB_EXPAND
];
1005 DWORD dwStyles
, dwExStyles
;
1006 DWORD dwNumButtons
, dwIndex
;
1008 if (pHHInfo
->WinType
.fsWinProperties
& HHWIN_PARAM_TB_FLAGS
)
1009 toolbarFlags
= pHHInfo
->WinType
.fsToolBarFlags
;
1011 toolbarFlags
= HHWIN_DEF_BUTTONS
;
1013 dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| TBSTYLE_FLAT
|
1014 TBSTYLE_WRAPABLE
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
;
1015 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1017 hToolbar
= CreateWindowExW(dwExStyles
, TOOLBARCLASSNAMEW
, NULL
, dwStyles
,
1018 0, 0, 0, 0, hwndParent
, NULL
,
1019 hhctrl_hinstance
, NULL
);
1022 pHHInfo
->WinType
.hwndToolBar
= hToolbar
;
1024 SendMessageW(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(ICON_SIZE
, ICON_SIZE
));
1025 SendMessageW(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
1026 SendMessageW(hToolbar
, WM_SETFONT
, (WPARAM
)pHHInfo
->hFont
, TRUE
);
1028 TB_AddButtonsFromFlags(pHHInfo
, buttons
, toolbarFlags
, &dwNumButtons
);
1030 for (dwIndex
= 0; dwIndex
< dwNumButtons
; dwIndex
++)
1032 LPWSTR szBuf
= HH_LoadString(buttons
[dwIndex
].idCommand
);
1033 DWORD dwLen
= strlenW(szBuf
);
1034 szBuf
[dwLen
+ 1] = 0; /* Double-null terminate */
1036 buttons
[dwIndex
].iString
= (DWORD
)SendMessageW(hToolbar
, TB_ADDSTRINGW
, 0, (LPARAM
)szBuf
);
1040 SendMessageW(hToolbar
, TB_ADDBUTTONSW
, dwNumButtons
, (LPARAM
)buttons
);
1041 SendMessageW(hToolbar
, TB_AUTOSIZE
, 0, 0);
1042 ShowWindow(hToolbar
, SW_SHOW
);
1047 /* Navigation Pane */
1049 static void NP_GetNavigationRect(HHInfo
*pHHInfo
, RECT
*rc
)
1051 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1052 HWND hwndToolbar
= pHHInfo
->WinType
.hwndToolBar
;
1053 RECT rectWND
, rectTB
;
1055 GetClientRect(hwndParent
, &rectWND
);
1056 GetClientRect(hwndToolbar
, &rectTB
);
1059 rc
->top
= rectTB
.bottom
;
1060 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
1062 if (!(pHHInfo
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1063 pHHInfo
->WinType
.iNavWidth
== 0)
1065 pHHInfo
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1068 rc
->right
= pHHInfo
->WinType
.iNavWidth
;
1071 static DWORD
NP_CreateTab(HINSTANCE hInstance
, HWND hwndTabCtrl
, DWORD index
)
1074 LPWSTR tabText
= HH_LoadString(index
);
1077 tie
.mask
= TCIF_TEXT
;
1078 tie
.pszText
= tabText
;
1080 ret
= SendMessageW( hwndTabCtrl
, TCM_INSERTITEMW
, index
, (LPARAM
)&tie
);
1086 static BOOL
HH_AddNavigationPane(HHInfo
*info
)
1088 HWND hWnd
, hwndTabCtrl
;
1089 HWND hwndParent
= info
->WinType
.hwndHelp
;
1090 DWORD dwStyles
= WS_CHILDWINDOW
;
1091 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1094 if (!info
->WinType
.fNotExpanded
)
1095 dwStyles
|= WS_VISIBLE
;
1097 NP_GetNavigationRect(info
, &rc
);
1099 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1100 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1101 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1105 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1107 hwndTabCtrl
= CreateWindowExW(dwExStyles
, WC_TABCONTROLW
, szEmpty
, dwStyles
| WS_VISIBLE
,
1109 rc
.right
- TAB_RIGHT_PADDING
,
1110 rc
.bottom
- TAB_TOP_PADDING
,
1111 hWnd
, NULL
, hhctrl_hinstance
, NULL
);
1115 if (*info
->WinType
.pszToc
)
1116 info
->tabs
[TAB_CONTENTS
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_CONTENTS
);
1118 if (*info
->WinType
.pszIndex
)
1119 info
->tabs
[TAB_INDEX
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_INDEX
);
1121 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TAB_SEARCH
)
1122 info
->tabs
[TAB_SEARCH
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_SEARCH
);
1124 if (info
->WinType
.fsWinProperties
& HHWIN_PROP_TAB_FAVORITES
)
1125 info
->tabs
[TAB_FAVORITES
].id
= NP_CreateTab(hhctrl_hinstance
, hwndTabCtrl
, IDS_FAVORITES
);
1127 SendMessageW(hwndTabCtrl
, WM_SETFONT
, (WPARAM
)info
->hFont
, TRUE
);
1129 info
->hwndTabCtrl
= hwndTabCtrl
;
1130 info
->WinType
.hwndNavigation
= hWnd
;
1136 static void HP_GetHTMLRect(HHInfo
*info
, RECT
*rc
)
1138 RECT rectTB
, rectWND
, rectNP
, rectSB
;
1140 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
1141 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
1142 GetClientRect(info
->hwndSizeBar
, &rectSB
);
1144 if (info
->WinType
.fNotExpanded
)
1148 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
1149 rc
->left
= rectNP
.right
+ rectSB
.right
;
1152 rc
->top
= rectTB
.bottom
;
1153 rc
->right
= rectWND
.right
- rc
->left
;
1154 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
1157 static BOOL
HH_AddHTMLPane(HHInfo
*pHHInfo
)
1160 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1161 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
;
1162 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
| WS_EX_CLIENTEDGE
;
1165 HP_GetHTMLRect(pHHInfo
, &rc
);
1167 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1168 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1169 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1173 if (!InitWebBrowser(pHHInfo
, hWnd
))
1176 /* store the pointer to the HH info struct */
1177 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
1179 ShowWindow(hWnd
, SW_SHOW
);
1182 pHHInfo
->WinType
.hwndHTML
= hWnd
;
1186 static BOOL
AddContentTab(HHInfo
*info
)
1188 HIMAGELIST hImageList
;
1192 if(info
->tabs
[TAB_CONTENTS
].id
== -1)
1193 return TRUE
; /* No "Contents" tab */
1194 hWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_TREEVIEWW
, szEmpty
, WS_CHILD
| WS_BORDER
| TVS_LINESATROOT
1195 | TVS_SHOWSELALWAYS
| TVS_HASBUTTONS
, 50, 50, 100, 100,
1196 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1198 ERR("Could not create treeview control\n");
1202 hImageList
= ImageList_Create(16, 16, ILC_COLOR32
, 0, HHTV_NUMBITMAPS
);
1203 hBitmap
= LoadBitmapW(hhctrl_hinstance
, MAKEINTRESOURCEW(IDB_HHTREEVIEW
));
1204 ImageList_Add(hImageList
, hBitmap
, NULL
);
1205 SendMessageW(hWnd
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
1207 info
->contents
.hImageList
= hImageList
;
1208 info
->tabs
[TAB_CONTENTS
].hwnd
= hWnd
;
1209 ResizeTabChild(info
, TAB_CONTENTS
);
1210 ShowWindow(hWnd
, SW_SHOW
);
1215 static BOOL
AddIndexTab(HHInfo
*info
)
1217 char hidden_column
[] = "Column";
1220 if(info
->tabs
[TAB_INDEX
].id
== -1)
1221 return TRUE
; /* No "Index" tab */
1222 info
->tabs
[TAB_INDEX
].hwnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
1223 szEmpty
, WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
| LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1224 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1225 if(!info
->tabs
[TAB_INDEX
].hwnd
) {
1226 ERR("Could not create ListView control\n");
1229 memset(&lvc
, 0, sizeof(lvc
));
1230 lvc
.mask
= LVCF_TEXT
;
1231 lvc
.pszText
= hidden_column
;
1232 if(SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1234 ERR("Could not create ListView column\n");
1238 ResizeTabChild(info
, TAB_INDEX
);
1239 ShowWindow(info
->tabs
[TAB_INDEX
].hwnd
, SW_HIDE
);
1244 static BOOL
AddSearchTab(HHInfo
*info
)
1246 HWND hwndList
, hwndEdit
, hwndContainer
;
1247 char hidden_column
[] = "Column";
1248 WNDPROC editWndProc
;
1251 if(info
->tabs
[TAB_SEARCH
].id
== -1)
1252 return TRUE
; /* No "Search" tab */
1253 hwndContainer
= CreateWindowExW(WS_EX_CONTROLPARENT
, szChildClass
, szEmpty
,
1254 WS_CHILD
, 0, 0, 0, 0, info
->WinType
.hwndNavigation
,
1255 NULL
, hhctrl_hinstance
, NULL
);
1256 if(!hwndContainer
) {
1257 ERR("Could not create search window container control.\n");
1260 hwndEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_EDITW
, szEmpty
, WS_CHILD
1261 | WS_VISIBLE
| ES_LEFT
| SS_NOTIFY
, 0, 0, 0, 0,
1262 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1264 ERR("Could not create search ListView control.\n");
1267 if(SendMessageW(hwndEdit
, WM_SETFONT
, (WPARAM
) info
->hFont
, (LPARAM
) FALSE
) == -1)
1269 ERR("Could not set font for edit control.\n");
1272 editWndProc
= (WNDPROC
) SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
, (LONG_PTR
)EditChild_WndProc
);
1274 ERR("Could not redirect messages for edit control.\n");
1277 SetWindowLongPtrW(hwndEdit
, GWLP_USERDATA
, (LONG_PTR
)editWndProc
);
1278 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1279 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| LVS_SINGLESEL
1280 | LVS_REPORT
| LVS_NOCOLUMNHEADER
, 0, 0, 0, 0,
1281 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1283 ERR("Could not create search ListView control.\n");
1286 memset(&lvc
, 0, sizeof(lvc
));
1287 lvc
.mask
= LVCF_TEXT
;
1288 lvc
.pszText
= hidden_column
;
1289 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1291 ERR("Could not create ListView column\n");
1295 info
->search
.hwndEdit
= hwndEdit
;
1296 info
->search
.hwndList
= hwndList
;
1297 info
->search
.hwndContainer
= hwndContainer
;
1298 info
->tabs
[TAB_SEARCH
].hwnd
= hwndContainer
;
1300 SetWindowLongPtrW(hwndContainer
, 0, (LONG_PTR
)info
);
1302 ResizeTabChild(info
, TAB_SEARCH
);
1307 /* The Index tab's sub-topic popup */
1309 static void ResizePopupChild(HHInfo
*info
)
1311 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
1312 int border_width
= GetSystemMetrics(SM_CXBORDER
);
1313 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
1320 GetClientRect(info
->popup
.hwndPopup
, &rect
);
1321 SetWindowPos(info
->popup
.hwndCallback
, HWND_TOP
, 0, 0,
1322 rect
.right
, rect
.bottom
, SWP_NOMOVE
);
1324 rect
.left
= TAB_MARGIN
;
1325 rect
.top
= TAB_TOP_PADDING
+ TAB_MARGIN
;
1326 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
1327 rect
.bottom
-= TAB_MARGIN
;
1328 width
= rect
.right
-rect
.left
;
1329 height
= rect
.bottom
-rect
.top
;
1331 SetWindowPos(info
->popup
.hwndList
, NULL
, rect
.left
, rect
.top
, width
, height
,
1332 SWP_NOZORDER
| SWP_NOACTIVATE
);
1334 SendMessageW(info
->popup
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
1335 width
-scroll_width
-2*border_width
-2*edge_width
);
1338 static LRESULT CALLBACK
HelpPopup_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1340 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1345 ResizePopupChild(info
);
1348 DestroyWindow(hWnd
);
1351 ShowWindow(hWnd
, SW_HIDE
);
1355 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1361 static LRESULT CALLBACK
PopupChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1366 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1370 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1373 if(info
== 0 || lParam
== 0)
1375 iter
= (IndexSubItem
*) ((NMITEMACTIVATE
*)lParam
)->lParam
;
1378 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1379 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1383 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1390 lvItem
.iItem
= (int) SendMessageW(info
->popup
.hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
1391 lvItem
.mask
= TVIF_PARAM
;
1392 SendMessageW(info
->popup
.hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
1393 iter
= (IndexSubItem
*) lvItem
.lParam
;
1394 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1395 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1402 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1408 static BOOL
AddIndexPopup(HHInfo
*info
)
1410 static const WCHAR szPopupChildClass
[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1411 static const WCHAR windowCaptionW
[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1412 static const WCHAR windowClassW
[] = {'H','H',' ','P','o','p','u','p',0};
1413 HWND hwndList
, hwndPopup
, hwndCallback
;
1414 char hidden_column
[] = "Column";
1418 if(info
->tabs
[TAB_INDEX
].id
== -1)
1419 return TRUE
; /* No "Index" tab */
1421 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1422 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1423 wcex
.lpfnWndProc
= HelpPopup_WndProc
;
1424 wcex
.cbClsExtra
= 0;
1425 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1426 wcex
.hInstance
= hhctrl_hinstance
;
1427 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1428 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1429 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1430 wcex
.lpszMenuName
= NULL
;
1431 wcex
.lpszClassName
= windowClassW
;
1432 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1433 RegisterClassExW(&wcex
);
1435 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1437 wcex
.lpfnWndProc
= PopupChild_WndProc
;
1438 wcex
.cbClsExtra
= 0;
1439 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1440 wcex
.hInstance
= hhctrl_hinstance
;
1441 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1442 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1443 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1444 wcex
.lpszMenuName
= NULL
;
1445 wcex
.lpszClassName
= szPopupChildClass
;
1446 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1447 RegisterClassExW(&wcex
);
1449 hwndPopup
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
1450 | WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
,
1451 windowClassW
, windowCaptionW
, WS_POPUPWINDOW
1452 | WS_OVERLAPPEDWINDOW
| WS_VISIBLE
1453 | WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, CW_USEDEFAULT
,
1454 CW_USEDEFAULT
, 300, 200, info
->WinType
.hwndHelp
,
1455 NULL
, hhctrl_hinstance
, NULL
);
1459 hwndCallback
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
,
1460 szPopupChildClass
, szEmpty
, WS_CHILDWINDOW
| WS_VISIBLE
,
1462 hwndPopup
, NULL
, hhctrl_hinstance
, NULL
);
1466 ShowWindow(hwndPopup
, SW_HIDE
);
1467 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1468 WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
1469 | LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1470 hwndCallback
, NULL
, hhctrl_hinstance
, NULL
);
1472 ERR("Could not create popup ListView control\n");
1475 memset(&lvc
, 0, sizeof(lvc
));
1476 lvc
.mask
= LVCF_TEXT
;
1477 lvc
.pszText
= hidden_column
;
1478 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1480 ERR("Could not create popup ListView column\n");
1484 info
->popup
.hwndCallback
= hwndCallback
;
1485 info
->popup
.hwndPopup
= hwndPopup
;
1486 info
->popup
.hwndList
= hwndList
;
1487 SetWindowLongPtrW(hwndPopup
, 0, (LONG_PTR
)info
);
1488 SetWindowLongPtrW(hwndCallback
, 0, (LONG_PTR
)info
);
1490 ResizePopupChild(info
);
1491 ShowWindow(hwndList
, SW_SHOW
);
1498 static void ExpandContract(HHInfo
*pHHInfo
)
1502 pHHInfo
->WinType
.fNotExpanded
= !pHHInfo
->WinType
.fNotExpanded
;
1503 GetWindowRect(pHHInfo
->WinType
.hwndHelp
, &r
);
1504 NP_GetNavigationRect(pHHInfo
, &nav
);
1506 /* hide/show both the nav bar and the size bar */
1507 if (pHHInfo
->WinType
.fNotExpanded
)
1509 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_HIDE
);
1510 ShowWindow(pHHInfo
->hwndSizeBar
, SW_HIDE
);
1511 r
.left
= r
.left
+ nav
.right
;
1513 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(FALSE
, 0));
1514 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(TRUE
, 0));
1518 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_SHOW
);
1519 ShowWindow(pHHInfo
->hwndSizeBar
, SW_SHOW
);
1520 r
.left
= r
.left
- nav
.right
;
1522 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(TRUE
, 0));
1523 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(FALSE
, 0));
1526 MoveWindow(pHHInfo
->WinType
.hwndHelp
, r
.left
, r
.top
, r
.right
-r
.left
, r
.bottom
-r
.top
, TRUE
);
1529 static LRESULT
Help_OnSize(HWND hWnd
)
1531 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1538 if (!pHHInfo
->WinType
.fNotExpanded
)
1540 NP_GetNavigationRect(pHHInfo
, &rc
);
1541 SetWindowPos(pHHInfo
->WinType
.hwndNavigation
, HWND_TOP
, 0, 0,
1542 rc
.right
, rc
.bottom
, SWP_NOMOVE
);
1544 SB_GetSizeBarRect(pHHInfo
, &rc
);
1545 SetWindowPos(pHHInfo
->hwndSizeBar
, HWND_TOP
, rc
.left
, rc
.top
,
1546 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1550 HP_GetHTMLRect(pHHInfo
, &rc
);
1551 SetWindowPos(pHHInfo
->WinType
.hwndHTML
, HWND_TOP
, rc
.left
, rc
.top
,
1552 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1554 /* Resize browser window taking the frame size into account */
1555 dwSize
= GetSystemMetrics(SM_CXFRAME
);
1556 ResizeWebBrowser(pHHInfo
, rc
.right
- dwSize
, rc
.bottom
- dwSize
);
1561 static LRESULT CALLBACK
Help_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1566 if (HIWORD(wParam
) == BN_CLICKED
)
1567 TB_OnClick(hWnd
, LOWORD(wParam
));
1570 return Help_OnSize(hWnd
);
1572 ReleaseHelpViewer((HHInfo
*)GetWindowLongPtrW(hWnd
, 0));
1580 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1586 static BOOL
HH_CreateHelpWindow(HHInfo
*info
)
1588 HWND hWnd
, parent
= 0;
1589 RECT winPos
= info
->WinType
.rcWindowPos
;
1591 DWORD dwStyles
, dwExStyles
;
1592 DWORD x
, y
, width
= 0, height
= 0;
1595 static const WCHAR windowClassW
[] = {
1596 'H','H',' ', 'P','a','r','e','n','t',0
1599 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1600 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1601 wcex
.lpfnWndProc
= Help_WndProc
;
1602 wcex
.cbClsExtra
= 0;
1603 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1604 wcex
.hInstance
= hhctrl_hinstance
;
1605 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1606 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1607 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1608 wcex
.lpszMenuName
= NULL
;
1609 wcex
.lpszClassName
= windowClassW
;
1610 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1612 RegisterClassExW(&wcex
);
1614 /* Read in window parameters if available */
1615 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_STYLES
)
1617 dwStyles
= info
->WinType
.dwStyles
;
1618 if (!(info
->WinType
.dwStyles
& WS_CHILD
))
1619 dwStyles
|= WS_OVERLAPPEDWINDOW
;
1622 dwStyles
= WS_OVERLAPPEDWINDOW
| WS_VISIBLE
|
1623 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1625 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_EXSTYLES
)
1626 dwExStyles
= info
->WinType
.dwExStyles
;
1628 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
|
1629 WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
;
1631 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_RECT
)
1635 width
= winPos
.right
- x
;
1636 height
= winPos
.bottom
- y
;
1638 if (!width
|| !height
)
1640 x
= WINTYPE_DEFAULT_X
;
1641 y
= WINTYPE_DEFAULT_Y
;
1642 width
= WINTYPE_DEFAULT_WIDTH
;
1643 height
= WINTYPE_DEFAULT_HEIGHT
;
1646 if (info
->WinType
.fNotExpanded
)
1648 if (!(info
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1649 info
->WinType
.iNavWidth
== 0)
1651 info
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1654 x
+= info
->WinType
.iNavWidth
;
1655 width
-= info
->WinType
.iNavWidth
;
1659 caption
= info
->WinType
.pszCaption
;
1660 if (!*caption
) caption
= info
->pCHMInfo
->defTitle
;
1662 if (info
->WinType
.dwStyles
& WS_CHILD
)
1663 parent
= info
->WinType
.hwndCaller
;
1665 hWnd
= CreateWindowExW(dwExStyles
, windowClassW
, caption
,
1666 dwStyles
, x
, y
, width
, height
, parent
, NULL
, hhctrl_hinstance
, NULL
);
1670 ShowWindow(hWnd
, SW_SHOW
);
1673 /* store the pointer to the HH info struct */
1674 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1676 info
->WinType
.hwndHelp
= hWnd
;
1680 static void HH_CreateFont(HHInfo
*pHHInfo
)
1684 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
), sizeof(LOGFONTW
), &lf
);
1685 lf
.lfWeight
= FW_NORMAL
;
1686 lf
.lfItalic
= FALSE
;
1687 lf
.lfUnderline
= FALSE
;
1689 pHHInfo
->hFont
= CreateFontIndirectW(&lf
);
1692 static void HH_InitRequiredControls(DWORD dwControls
)
1694 INITCOMMONCONTROLSEX icex
;
1696 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1697 icex
.dwICC
= dwControls
;
1698 InitCommonControlsEx(&icex
);
1701 /* Creates the whole package */
1702 static BOOL
CreateViewer(HHInfo
*pHHInfo
)
1704 HH_CreateFont(pHHInfo
);
1706 if (!HH_CreateHelpWindow(pHHInfo
))
1709 HH_InitRequiredControls(ICC_BAR_CLASSES
);
1711 if (!HH_AddToolbar(pHHInfo
))
1714 HH_RegisterChildWndClass(pHHInfo
);
1716 if (!HH_AddNavigationPane(pHHInfo
))
1719 HH_RegisterSizeBarClass(pHHInfo
);
1721 if (!HH_AddSizeBar(pHHInfo
))
1724 if (!HH_AddHTMLPane(pHHInfo
))
1727 if (!AddContentTab(pHHInfo
))
1730 if (!AddIndexTab(pHHInfo
))
1733 if (!AddIndexPopup(pHHInfo
))
1736 if (!AddSearchTab(pHHInfo
))
1739 InitContent(pHHInfo
);
1745 void ReleaseHelpViewer(HHInfo
*info
)
1747 TRACE("(%p)\n", info
);
1752 list_remove(&info
->entry
);
1754 /* Free allocated strings */
1755 heap_free(info
->pszType
);
1756 heap_free(info
->pszCaption
);
1757 heap_free(info
->pszToc
);
1758 heap_free(info
->pszIndex
);
1759 heap_free(info
->pszFile
);
1760 heap_free(info
->pszHome
);
1761 heap_free(info
->pszJump1
);
1762 heap_free(info
->pszJump2
);
1763 heap_free(info
->pszUrlJump1
);
1764 heap_free(info
->pszUrlJump2
);
1767 CloseCHM(info
->pCHMInfo
);
1769 ReleaseWebBrowser(info
);
1770 ReleaseContent(info
);
1772 ReleaseSearch(info
);
1774 if(info
->contents
.hImageList
)
1775 ImageList_Destroy(info
->contents
.hImageList
);
1776 if(info
->WinType
.hwndHelp
)
1777 DestroyWindow(info
->WinType
.hwndHelp
);
1783 HHInfo
*CreateHelpViewer(LPCWSTR filename
, HWND caller
)
1785 HHInfo
*info
= heap_alloc_zero(sizeof(HHInfo
));
1788 /* Set the invalid tab ID (-1) as the default value for all
1789 * of the tabs, this matches a failed TCM_INSERTITEM call.
1791 for(i
=0;i
<sizeof(info
->tabs
)/sizeof(HHTab
);i
++)
1792 info
->tabs
[i
].id
= -1;
1794 OleInitialize(NULL
);
1796 info
->pCHMInfo
= OpenCHM(filename
);
1797 if(!info
->pCHMInfo
) {
1798 ReleaseHelpViewer(info
);
1802 if (!LoadWinTypeFromCHM(info
)) {
1803 ReleaseHelpViewer(info
);
1806 info
->WinType
.hwndCaller
= caller
;
1808 if(!CreateViewer(info
)) {
1809 ReleaseHelpViewer(info
);
1813 list_add_tail(&window_list
, &info
->entry
);
1818 * Search the table of HTML entities and return the corresponding ANSI symbol.
1820 static char find_html_symbol(const char *entity
, int entity_len
)
1822 int max
= sizeof(html_encoded_symbols
)/sizeof(html_encoded_symbols
[0])-1;
1827 int pos
= (min
+max
)/2;
1828 const char *encoded_symbol
= html_encoded_symbols
[pos
].html_code
;
1829 dir
= strncmp(encoded_symbol
, entity
, entity_len
);
1830 if(dir
== 0 && !encoded_symbol
[entity_len
]) return html_encoded_symbols
[pos
].ansi_symbol
;
1840 * Decode a string containing HTML encoded characters into a unicode string.
1842 WCHAR
*decode_html(const char *html_fragment
, int html_fragment_len
, UINT code_page
)
1844 const char *h
= html_fragment
;
1845 char *amp
, *sem
, symbol
, *tmp
;
1846 int len
, tmp_len
= 0;
1847 WCHAR
*unicode_text
;
1849 tmp
= heap_alloc(html_fragment_len
+1);
1853 amp
= strchr(h
, '&');
1856 /* Copy the characters prior to the HTML encoded character */
1857 memcpy(&tmp
[tmp_len
], h
, len
);
1859 amp
++; /* skip ampersand */
1860 sem
= strchr(amp
, ';');
1861 /* Require a semicolon after the ampersand */
1865 tmp
[tmp_len
++] = '&';
1868 /* Find the symbol either by using the ANSI character number (prefixed by the pound symbol)
1869 * or by searching the HTML entity table */
1873 char *endnum
= NULL
;
1876 tmp
= (char) strtol(amp
, &endnum
, 10);
1881 symbol
= find_html_symbol(amp
, len
);
1884 FIXME("Failed to translate HTML encoded character '&%.*s;'.\n", len
, amp
);
1886 tmp
[tmp_len
++] = '&';
1889 /* Insert the new symbol */
1891 tmp
[tmp_len
++] = symbol
;
1893 /* Convert any remaining characters */
1894 len
= html_fragment_len
-(h
-html_fragment
);
1895 memcpy(&tmp
[tmp_len
], h
, len
);
1897 tmp
[tmp_len
++] = 0; /* NULL-terminate the string */
1899 len
= MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, NULL
, 0);
1900 unicode_text
= heap_alloc(len
*sizeof(WCHAR
));
1901 MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, unicode_text
, len
);
1903 return unicode_text
;