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 static const WCHAR szEmpty
[] = {0};
53 struct html_encoded_symbol
{
54 const char *html_code
;
59 * Table mapping the conversion between HTML encoded symbols and their ANSI code page equivalent.
60 * Note: Add additional entries in proper alphabetical order (a binary search is used on this table).
62 struct html_encoded_symbol html_encoded_symbols
[] =
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
, &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
];
251 TRACE("%p %s %s\n", info
, debugstr_w(file
), debugstr_w(index
));
253 if ((!info
->web_browser
) || !AppendFullPathURL(file
, buf
, index
))
257 if((ptr
= strchrW(buf
, '#')))
260 return SUCCEEDED(navigate_url(info
, buf
));
263 static void DoSync(HHInfo
*info
)
265 WCHAR buf
[INTERNET_MAX_URL_LENGTH
];
270 hres
= IWebBrowser2_get_LocationURL(info
->web_browser
, &url
);
274 WARN("get_LocationURL failed: %08x\n", hres
);
278 /* If we're not currently viewing a page in the active .chm file, abort */
279 if ((!AppendFullPathURL(info
->pszFile
, buf
, NULL
)) || (len
= lstrlenW(buf
) > lstrlenW(url
)))
285 if (lstrcmpiW(buf
, url
) > 0)
287 static const WCHAR delimW
[] = {':',':','/',0};
290 index
= strstrW(url
, delimW
);
293 ActivateContentTopic(info
->tabs
[TAB_CONTENTS
].hwnd
, index
+ 3, info
->content
); /* skip over ::/ */
301 #define SIZEBAR_WIDTH 4
303 static const WCHAR szSizeBarClass
[] = {
304 'H','H',' ','S','i','z','e','B','a','r',0
307 /* Draw the SizeBar */
308 static void SB_OnPaint(HWND hWnd
)
314 hdc
= BeginPaint(hWnd
, &ps
);
316 GetClientRect(hWnd
, &rc
);
321 FrameRect(hdc
, &rc
, GetStockObject(GRAY_BRUSH
));
323 /* white highlight */
324 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
325 MoveToEx(hdc
, rc
.right
, 1, NULL
);
327 LineTo(hdc
, 1, rc
.bottom
- 1);
330 MoveToEx(hdc
, 0, rc
.bottom
, NULL
);
331 LineTo(hdc
, rc
.right
, rc
.bottom
);
336 static void SB_OnLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
341 static void SB_OnLButtonUp(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
343 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
346 pt
.x
= (short)LOWORD(lParam
);
347 pt
.y
= (short)HIWORD(lParam
);
349 /* update the window sizes */
350 pHHInfo
->WinType
.iNavWidth
+= pt
.x
;
356 static void SB_OnMouseMove(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
358 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
359 if (!(wParam
& MK_LBUTTON
))
363 static LRESULT CALLBACK
SizeBar_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
368 SB_OnLButtonDown(hWnd
, wParam
, lParam
);
371 SB_OnLButtonUp(hWnd
, wParam
, lParam
);
374 SB_OnMouseMove(hWnd
, wParam
, lParam
);
380 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
386 static void HH_RegisterSizeBarClass(HHInfo
*pHHInfo
)
390 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
392 wcex
.lpfnWndProc
= SizeBar_WndProc
;
394 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
395 wcex
.hInstance
= hhctrl_hinstance
;
396 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
397 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_SIZEWE
);
398 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
399 wcex
.lpszMenuName
= NULL
;
400 wcex
.lpszClassName
= szSizeBarClass
;
401 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
403 RegisterClassExW(&wcex
);
406 static void SB_GetSizeBarRect(HHInfo
*info
, RECT
*rc
)
408 RECT rectWND
, rectTB
, rectNP
;
410 GetClientRect(info
->WinType
.hwndHelp
, &rectWND
);
411 GetClientRect(info
->WinType
.hwndToolBar
, &rectTB
);
412 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
414 rc
->left
= rectNP
.right
;
415 rc
->top
= rectTB
.bottom
;
416 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
417 rc
->right
= SIZEBAR_WIDTH
;
420 static BOOL
HH_AddSizeBar(HHInfo
*pHHInfo
)
423 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
424 DWORD dwStyles
= WS_CHILDWINDOW
| WS_OVERLAPPED
;
425 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
428 if (!pHHInfo
->WinType
.fNotExpanded
)
429 dwStyles
|= WS_VISIBLE
;
431 SB_GetSizeBarRect(pHHInfo
, &rc
);
433 hWnd
= CreateWindowExW(dwExStyles
, szSizeBarClass
, szEmpty
, dwStyles
,
434 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
435 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
439 /* store the pointer to the HH info struct */
440 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
442 pHHInfo
->hwndSizeBar
= hWnd
;
448 static const WCHAR szChildClass
[] = {
449 'H','H',' ','C','h','i','l','d',0
452 static LRESULT
Child_OnPaint(HWND hWnd
)
458 hdc
= BeginPaint(hWnd
, &ps
);
460 /* Only paint the Navigation pane, identified by the fact
461 * that it has a child window
463 if (GetWindow(hWnd
, GW_CHILD
))
465 GetClientRect(hWnd
, &rc
);
467 /* set the border color */
468 SelectObject(hdc
, GetStockObject(DC_PEN
));
469 SetDCPenColor(hdc
, GetSysColor(COLOR_BTNSHADOW
));
471 /* Draw the top border */
472 LineTo(hdc
, rc
.right
, 0);
474 SelectObject(hdc
, GetStockObject(WHITE_PEN
));
475 MoveToEx(hdc
, 0, 1, NULL
);
476 LineTo(hdc
, rc
.right
, 1);
484 static void ResizeTabChild(HHInfo
*info
, int tab
)
486 HWND hwnd
= info
->tabs
[tab
].hwnd
;
491 GetClientRect(info
->WinType
.hwndNavigation
, &rect
);
492 SendMessageW(info
->hwndTabCtrl
, TCM_GETITEMRECT
, 0, (LPARAM
)&tabrc
);
493 cnt
= SendMessageW(info
->hwndTabCtrl
, TCM_GETROWCOUNT
, 0, 0);
495 rect
.left
= TAB_MARGIN
;
496 rect
.top
= TAB_TOP_PADDING
+ cnt
*(tabrc
.bottom
-tabrc
.top
) + TAB_MARGIN
;
497 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
498 rect
.bottom
-= TAB_MARGIN
;
499 width
= rect
.right
-rect
.left
;
500 height
= rect
.bottom
-rect
.top
;
502 SetWindowPos(hwnd
, NULL
, rect
.left
, rect
.top
, width
, height
,
503 SWP_NOZORDER
| SWP_NOACTIVATE
);
508 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
509 int border_width
= GetSystemMetrics(SM_CXBORDER
);
510 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
512 /* Resize the tab widget column to perfectly fit the tab window and
513 * leave sufficient space for the scroll widget.
515 SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_SETCOLUMNWIDTH
, 0,
516 width
-scroll_width
-2*border_width
-2*edge_width
);
521 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
522 int border_width
= GetSystemMetrics(SM_CXBORDER
);
523 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
526 SetWindowPos(info
->search
.hwndEdit
, NULL
, 0, top_pos
, width
,
527 EDIT_HEIGHT
, SWP_NOZORDER
| SWP_NOACTIVATE
);
528 top_pos
+= EDIT_HEIGHT
+ TAB_MARGIN
;
529 SetWindowPos(info
->search
.hwndList
, NULL
, 0, top_pos
, width
,
530 height
-top_pos
, SWP_NOZORDER
| SWP_NOACTIVATE
);
531 /* Resize the tab widget column to perfectly fit the tab window and
532 * leave sufficient space for the scroll widget.
534 SendMessageW(info
->search
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
535 width
-scroll_width
-2*border_width
-2*edge_width
);
542 static LRESULT
Child_OnSize(HWND hwnd
)
544 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
547 if(!info
|| hwnd
!= info
->WinType
.hwndNavigation
)
550 GetClientRect(hwnd
, &rect
);
551 SetWindowPos(info
->hwndTabCtrl
, HWND_TOP
, 0, 0,
552 rect
.right
- TAB_RIGHT_PADDING
,
553 rect
.bottom
- TAB_TOP_PADDING
, SWP_NOMOVE
);
555 ResizeTabChild(info
, TAB_CONTENTS
);
556 ResizeTabChild(info
, TAB_INDEX
);
557 ResizeTabChild(info
, TAB_SEARCH
);
561 static LRESULT
OnTabChange(HWND hwnd
)
563 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hwnd
, 0);
564 int tab_id
, tab_index
, i
;
571 if(info
->tabs
[info
->current_tab
].hwnd
)
572 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_HIDE
);
574 tab_id
= (int) SendMessageW(info
->hwndTabCtrl
, TCM_GETCURSEL
, 0, 0);
575 /* convert the ID of the tab to an index in our tab list */
577 for (i
=0; i
<TAB_NUMTABS
; i
++)
579 if (info
->tabs
[i
].id
== tab_id
)
587 FIXME("Tab ID %d does not correspond to a valid index in the tab list.\n", tab_id
);
590 info
->current_tab
= tab_index
;
592 if(info
->tabs
[info
->current_tab
].hwnd
)
593 ShowWindow(info
->tabs
[info
->current_tab
].hwnd
, SW_SHOW
);
598 static LRESULT
OnTopicChange(HHInfo
*info
, void *user_data
)
600 LPCWSTR chmfile
= NULL
, name
= NULL
, local
= NULL
;
605 if(!user_data
|| !info
)
608 switch (info
->current_tab
)
611 citer
= (ContentItem
*) user_data
;
613 local
= citer
->local
;
615 if(citer
->merge
.chm_file
) {
616 chmfile
= citer
->merge
.chm_file
;
619 citer
= citer
->parent
;
623 iiter
= (IndexItem
*) user_data
;
624 if(iiter
->nItems
== 0) {
625 FIXME("No entries for this item!\n");
628 if(iiter
->nItems
> 1) {
632 SendMessageW(info
->popup
.hwndList
, LVM_DELETEALLITEMS
, 0, 0);
633 for(i
=0;i
<iiter
->nItems
;i
++) {
634 IndexSubItem
*item
= &iiter
->items
[i
];
635 WCHAR
*name
= iiter
->keyword
;
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
, WB_STOP
);
877 DoPageAction(info
, WB_REFRESH
);
880 DoPageAction(info
, WB_GOBACK
);
883 NavigateToChm(info
, info
->pCHMInfo
->szFile
, info
->WinType
.pszHome
);
886 DoPageAction(info
, WB_GOFORWARD
);
889 DoPageAction(info
, 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
| WS_VISIBLE
| TBSTYLE_FLAT
|
1010 TBSTYLE_WRAPABLE
| TBSTYLE_TOOLTIPS
| CCS_NODIVIDER
;
1011 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
;
1013 hToolbar
= CreateWindowExW(dwExStyles
, TOOLBARCLASSNAMEW
, NULL
, dwStyles
,
1014 0, 0, 0, 0, hwndParent
, NULL
,
1015 hhctrl_hinstance
, NULL
);
1018 pHHInfo
->WinType
.hwndToolBar
= hToolbar
;
1020 SendMessageW(hToolbar
, TB_SETBITMAPSIZE
, 0, MAKELONG(ICON_SIZE
, ICON_SIZE
));
1021 SendMessageW(hToolbar
, TB_BUTTONSTRUCTSIZE
, sizeof(TBBUTTON
), 0);
1022 SendMessageW(hToolbar
, WM_SETFONT
, (WPARAM
)pHHInfo
->hFont
, TRUE
);
1024 TB_AddButtonsFromFlags(pHHInfo
, buttons
, toolbarFlags
, &dwNumButtons
);
1026 for (dwIndex
= 0; dwIndex
< dwNumButtons
; dwIndex
++)
1028 LPWSTR szBuf
= HH_LoadString(buttons
[dwIndex
].idCommand
);
1029 DWORD dwLen
= strlenW(szBuf
);
1030 szBuf
[dwLen
+ 1] = 0; /* Double-null terminate */
1032 buttons
[dwIndex
].iString
= (DWORD
)SendMessageW(hToolbar
, TB_ADDSTRINGW
, 0, (LPARAM
)szBuf
);
1036 SendMessageW(hToolbar
, TB_ADDBUTTONSW
, dwNumButtons
, (LPARAM
)buttons
);
1037 SendMessageW(hToolbar
, TB_AUTOSIZE
, 0, 0);
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 (!info
->WinType
.fNotExpanded
)
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
->WinType
.hwndToolBar
, &rectTB
);
1138 GetClientRect(info
->hwndSizeBar
, &rectSB
);
1140 if (info
->WinType
.fNotExpanded
)
1144 GetClientRect(info
->WinType
.hwndNavigation
, &rectNP
);
1145 rc
->left
= rectNP
.right
+ rectSB
.right
;
1148 rc
->top
= rectTB
.bottom
;
1149 rc
->right
= rectWND
.right
- rc
->left
;
1150 rc
->bottom
= rectWND
.bottom
- rectTB
.bottom
;
1153 static BOOL
HH_AddHTMLPane(HHInfo
*pHHInfo
)
1156 HWND hwndParent
= pHHInfo
->WinType
.hwndHelp
;
1157 DWORD dwStyles
= WS_CHILDWINDOW
| WS_VISIBLE
| WS_CLIPCHILDREN
;
1158 DWORD dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
| WS_EX_CLIENTEDGE
;
1161 HP_GetHTMLRect(pHHInfo
, &rc
);
1163 hWnd
= CreateWindowExW(dwExStyles
, szChildClass
, szEmpty
, dwStyles
,
1164 rc
.left
, rc
.top
, rc
.right
, rc
.bottom
,
1165 hwndParent
, NULL
, hhctrl_hinstance
, NULL
);
1169 if (!InitWebBrowser(pHHInfo
, hWnd
))
1172 /* store the pointer to the HH info struct */
1173 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)pHHInfo
);
1175 ShowWindow(hWnd
, SW_SHOW
);
1178 pHHInfo
->WinType
.hwndHTML
= hWnd
;
1182 static BOOL
AddContentTab(HHInfo
*info
)
1184 HIMAGELIST hImageList
;
1188 if(info
->tabs
[TAB_CONTENTS
].id
== -1)
1189 return TRUE
; /* No "Contents" tab */
1190 hWnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_TREEVIEWW
, szEmpty
, WS_CHILD
| WS_BORDER
| TVS_LINESATROOT
1191 | TVS_SHOWSELALWAYS
| TVS_HASBUTTONS
, 50, 50, 100, 100,
1192 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1194 ERR("Could not create treeview control\n");
1198 hImageList
= ImageList_Create(16, 16, ILC_COLOR32
, 0, HHTV_NUMBITMAPS
);
1199 hBitmap
= LoadBitmapW(hhctrl_hinstance
, MAKEINTRESOURCEW(IDB_HHTREEVIEW
));
1200 ImageList_Add(hImageList
, hBitmap
, NULL
);
1201 SendMessageW(hWnd
, TVM_SETIMAGELIST
, TVSIL_NORMAL
, (LPARAM
)hImageList
);
1203 info
->contents
.hImageList
= hImageList
;
1204 info
->tabs
[TAB_CONTENTS
].hwnd
= hWnd
;
1205 ResizeTabChild(info
, TAB_CONTENTS
);
1206 ShowWindow(hWnd
, SW_SHOW
);
1211 static BOOL
AddIndexTab(HHInfo
*info
)
1213 char hidden_column
[] = "Column";
1216 if(info
->tabs
[TAB_INDEX
].id
== -1)
1217 return TRUE
; /* No "Index" tab */
1218 info
->tabs
[TAB_INDEX
].hwnd
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
,
1219 szEmpty
, WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
| LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1220 info
->WinType
.hwndNavigation
, NULL
, hhctrl_hinstance
, NULL
);
1221 if(!info
->tabs
[TAB_INDEX
].hwnd
) {
1222 ERR("Could not create ListView control\n");
1225 memset(&lvc
, 0, sizeof(lvc
));
1226 lvc
.mask
= LVCF_TEXT
;
1227 lvc
.pszText
= hidden_column
;
1228 if(SendMessageW(info
->tabs
[TAB_INDEX
].hwnd
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1230 ERR("Could not create ListView column\n");
1234 ResizeTabChild(info
, TAB_INDEX
);
1235 ShowWindow(info
->tabs
[TAB_INDEX
].hwnd
, SW_HIDE
);
1240 static BOOL
AddSearchTab(HHInfo
*info
)
1242 HWND hwndList
, hwndEdit
, hwndContainer
;
1243 char hidden_column
[] = "Column";
1244 WNDPROC editWndProc
;
1247 if(info
->tabs
[TAB_SEARCH
].id
== -1)
1248 return TRUE
; /* No "Search" tab */
1249 hwndContainer
= CreateWindowExW(WS_EX_CONTROLPARENT
, szChildClass
, szEmpty
,
1250 WS_CHILD
, 0, 0, 0, 0, info
->WinType
.hwndNavigation
,
1251 NULL
, hhctrl_hinstance
, NULL
);
1252 if(!hwndContainer
) {
1253 ERR("Could not create search window container control.\n");
1256 hwndEdit
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_EDITW
, szEmpty
, WS_CHILD
1257 | WS_VISIBLE
| ES_LEFT
| SS_NOTIFY
, 0, 0, 0, 0,
1258 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1260 ERR("Could not create search ListView control.\n");
1263 if(SendMessageW(hwndEdit
, WM_SETFONT
, (WPARAM
) info
->hFont
, (LPARAM
) FALSE
) == -1)
1265 ERR("Could not set font for edit control.\n");
1268 editWndProc
= (WNDPROC
) SetWindowLongPtrW(hwndEdit
, GWLP_WNDPROC
, (LONG_PTR
)EditChild_WndProc
);
1270 ERR("Could not redirect messages for edit control.\n");
1273 SetWindowLongPtrW(hwndEdit
, GWLP_USERDATA
, (LONG_PTR
)editWndProc
);
1274 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1275 WS_CHILD
| WS_VISIBLE
| WS_BORDER
| LVS_SINGLESEL
1276 | LVS_REPORT
| LVS_NOCOLUMNHEADER
, 0, 0, 0, 0,
1277 hwndContainer
, NULL
, hhctrl_hinstance
, NULL
);
1279 ERR("Could not create search ListView control.\n");
1282 memset(&lvc
, 0, sizeof(lvc
));
1283 lvc
.mask
= LVCF_TEXT
;
1284 lvc
.pszText
= hidden_column
;
1285 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1287 ERR("Could not create ListView column\n");
1291 info
->search
.hwndEdit
= hwndEdit
;
1292 info
->search
.hwndList
= hwndList
;
1293 info
->search
.hwndContainer
= hwndContainer
;
1294 info
->tabs
[TAB_SEARCH
].hwnd
= hwndContainer
;
1296 SetWindowLongPtrW(hwndContainer
, 0, (LONG_PTR
)info
);
1298 ResizeTabChild(info
, TAB_SEARCH
);
1303 /* The Index tab's sub-topic popup */
1305 static void ResizePopupChild(HHInfo
*info
)
1307 int scroll_width
= GetSystemMetrics(SM_CXVSCROLL
);
1308 int border_width
= GetSystemMetrics(SM_CXBORDER
);
1309 int edge_width
= GetSystemMetrics(SM_CXEDGE
);
1316 GetClientRect(info
->popup
.hwndPopup
, &rect
);
1317 SetWindowPos(info
->popup
.hwndCallback
, HWND_TOP
, 0, 0,
1318 rect
.right
, rect
.bottom
, SWP_NOMOVE
);
1320 rect
.left
= TAB_MARGIN
;
1321 rect
.top
= TAB_TOP_PADDING
+ TAB_MARGIN
;
1322 rect
.right
-= TAB_RIGHT_PADDING
+ TAB_MARGIN
;
1323 rect
.bottom
-= TAB_MARGIN
;
1324 width
= rect
.right
-rect
.left
;
1325 height
= rect
.bottom
-rect
.top
;
1327 SetWindowPos(info
->popup
.hwndList
, NULL
, rect
.left
, rect
.top
, width
, height
,
1328 SWP_NOZORDER
| SWP_NOACTIVATE
);
1330 SendMessageW(info
->popup
.hwndList
, LVM_SETCOLUMNWIDTH
, 0,
1331 width
-scroll_width
-2*border_width
-2*edge_width
);
1334 static LRESULT CALLBACK
HelpPopup_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1336 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1341 ResizePopupChild(info
);
1344 DestroyWindow(hWnd
);
1347 ShowWindow(hWnd
, SW_HIDE
);
1351 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1357 static LRESULT CALLBACK
PopupChild_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1362 NMHDR
*nmhdr
= (NMHDR
*)lParam
;
1366 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1369 if(info
== 0 || lParam
== 0)
1371 iter
= (IndexSubItem
*) ((NMITEMACTIVATE
*)lParam
)->lParam
;
1374 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1375 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1379 HHInfo
*info
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1386 lvItem
.iItem
= (int) SendMessageW(info
->popup
.hwndList
, LVM_GETSELECTIONMARK
, 0, 0);
1387 lvItem
.mask
= TVIF_PARAM
;
1388 SendMessageW(info
->popup
.hwndList
, LVM_GETITEMW
, 0, (LPARAM
)&lvItem
);
1389 iter
= (IndexSubItem
*) lvItem
.lParam
;
1390 NavigateToChm(info
, info
->index
->merge
.chm_file
, iter
->local
);
1391 ShowWindow(info
->popup
.hwndPopup
, SW_HIDE
);
1398 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1404 static BOOL
AddIndexPopup(HHInfo
*info
)
1406 static const WCHAR szPopupChildClass
[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1407 static const WCHAR windowCaptionW
[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1408 static const WCHAR windowClassW
[] = {'H','H',' ','P','o','p','u','p',0};
1409 HWND hwndList
, hwndPopup
, hwndCallback
;
1410 char hidden_column
[] = "Column";
1414 if(info
->tabs
[TAB_INDEX
].id
== -1)
1415 return TRUE
; /* No "Index" tab */
1417 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1418 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1419 wcex
.lpfnWndProc
= HelpPopup_WndProc
;
1420 wcex
.cbClsExtra
= 0;
1421 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1422 wcex
.hInstance
= hhctrl_hinstance
;
1423 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1424 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1425 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1426 wcex
.lpszMenuName
= NULL
;
1427 wcex
.lpszClassName
= windowClassW
;
1428 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1429 RegisterClassExW(&wcex
);
1431 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1433 wcex
.lpfnWndProc
= PopupChild_WndProc
;
1434 wcex
.cbClsExtra
= 0;
1435 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1436 wcex
.hInstance
= hhctrl_hinstance
;
1437 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1438 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1439 wcex
.hbrBackground
= (HBRUSH
)(COLOR_BTNFACE
+ 1);
1440 wcex
.lpszMenuName
= NULL
;
1441 wcex
.lpszClassName
= szPopupChildClass
;
1442 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1443 RegisterClassExW(&wcex
);
1445 hwndPopup
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
1446 | WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
,
1447 windowClassW
, windowCaptionW
, WS_POPUPWINDOW
1448 | WS_OVERLAPPEDWINDOW
| WS_VISIBLE
1449 | WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
, CW_USEDEFAULT
,
1450 CW_USEDEFAULT
, 300, 200, info
->WinType
.hwndHelp
,
1451 NULL
, hhctrl_hinstance
, NULL
);
1455 hwndCallback
= CreateWindowExW(WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_RIGHTSCROLLBAR
,
1456 szPopupChildClass
, szEmpty
, WS_CHILDWINDOW
| WS_VISIBLE
,
1458 hwndPopup
, NULL
, hhctrl_hinstance
, NULL
);
1462 ShowWindow(hwndPopup
, SW_HIDE
);
1463 hwndList
= CreateWindowExW(WS_EX_CLIENTEDGE
, WC_LISTVIEWW
, szEmpty
,
1464 WS_CHILD
| WS_BORDER
| LVS_SINGLESEL
| LVS_REPORT
1465 | LVS_NOCOLUMNHEADER
, 50, 50, 100, 100,
1466 hwndCallback
, NULL
, hhctrl_hinstance
, NULL
);
1468 ERR("Could not create popup ListView control\n");
1471 memset(&lvc
, 0, sizeof(lvc
));
1472 lvc
.mask
= LVCF_TEXT
;
1473 lvc
.pszText
= hidden_column
;
1474 if(SendMessageW(hwndList
, LVM_INSERTCOLUMNA
, 0, (LPARAM
) &lvc
) == -1)
1476 ERR("Could not create popup ListView column\n");
1480 info
->popup
.hwndCallback
= hwndCallback
;
1481 info
->popup
.hwndPopup
= hwndPopup
;
1482 info
->popup
.hwndList
= hwndList
;
1483 SetWindowLongPtrW(hwndPopup
, 0, (LONG_PTR
)info
);
1484 SetWindowLongPtrW(hwndCallback
, 0, (LONG_PTR
)info
);
1486 ResizePopupChild(info
);
1487 ShowWindow(hwndList
, SW_SHOW
);
1494 static void ExpandContract(HHInfo
*pHHInfo
)
1498 pHHInfo
->WinType
.fNotExpanded
= !pHHInfo
->WinType
.fNotExpanded
;
1499 GetWindowRect(pHHInfo
->WinType
.hwndHelp
, &r
);
1500 NP_GetNavigationRect(pHHInfo
, &nav
);
1502 /* hide/show both the nav bar and the size bar */
1503 if (pHHInfo
->WinType
.fNotExpanded
)
1505 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_HIDE
);
1506 ShowWindow(pHHInfo
->hwndSizeBar
, SW_HIDE
);
1507 r
.left
= r
.left
+ nav
.right
;
1509 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(FALSE
, 0));
1510 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(TRUE
, 0));
1514 ShowWindow(pHHInfo
->WinType
.hwndNavigation
, SW_SHOW
);
1515 ShowWindow(pHHInfo
->hwndSizeBar
, SW_SHOW
);
1516 r
.left
= r
.left
- nav
.right
;
1518 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_EXPAND
, MAKELPARAM(TRUE
, 0));
1519 SendMessageW(pHHInfo
->WinType
.hwndToolBar
, TB_HIDEBUTTON
, IDTB_CONTRACT
, MAKELPARAM(FALSE
, 0));
1522 MoveWindow(pHHInfo
->WinType
.hwndHelp
, r
.left
, r
.top
, r
.right
-r
.left
, r
.bottom
-r
.top
, TRUE
);
1525 static LRESULT
Help_OnSize(HWND hWnd
)
1527 HHInfo
*pHHInfo
= (HHInfo
*)GetWindowLongPtrW(hWnd
, 0);
1534 if (!pHHInfo
->WinType
.fNotExpanded
)
1536 NP_GetNavigationRect(pHHInfo
, &rc
);
1537 SetWindowPos(pHHInfo
->WinType
.hwndNavigation
, HWND_TOP
, 0, 0,
1538 rc
.right
, rc
.bottom
, SWP_NOMOVE
);
1540 SB_GetSizeBarRect(pHHInfo
, &rc
);
1541 SetWindowPos(pHHInfo
->hwndSizeBar
, HWND_TOP
, rc
.left
, rc
.top
,
1542 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1546 HP_GetHTMLRect(pHHInfo
, &rc
);
1547 SetWindowPos(pHHInfo
->WinType
.hwndHTML
, HWND_TOP
, rc
.left
, rc
.top
,
1548 rc
.right
, rc
.bottom
, SWP_SHOWWINDOW
);
1550 /* Resize browser window taking the frame size into account */
1551 dwSize
= GetSystemMetrics(SM_CXFRAME
);
1552 ResizeWebBrowser(pHHInfo
, rc
.right
- dwSize
, rc
.bottom
- dwSize
);
1557 static LRESULT CALLBACK
Help_WndProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1562 if (HIWORD(wParam
) == BN_CLICKED
)
1563 TB_OnClick(hWnd
, LOWORD(wParam
));
1566 return Help_OnSize(hWnd
);
1568 ReleaseHelpViewer((HHInfo
*)GetWindowLongPtrW(hWnd
, 0));
1576 return DefWindowProcW(hWnd
, message
, wParam
, lParam
);
1582 static BOOL
HH_CreateHelpWindow(HHInfo
*info
)
1585 RECT winPos
= info
->WinType
.rcWindowPos
;
1587 DWORD dwStyles
, dwExStyles
;
1588 DWORD x
, y
, width
= 0, height
= 0;
1591 static const WCHAR windowClassW
[] = {
1592 'H','H',' ', 'P','a','r','e','n','t',0
1595 wcex
.cbSize
= sizeof(WNDCLASSEXW
);
1596 wcex
.style
= CS_HREDRAW
| CS_VREDRAW
;
1597 wcex
.lpfnWndProc
= Help_WndProc
;
1598 wcex
.cbClsExtra
= 0;
1599 wcex
.cbWndExtra
= sizeof(LONG_PTR
);
1600 wcex
.hInstance
= hhctrl_hinstance
;
1601 wcex
.hIcon
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1602 wcex
.hCursor
= LoadCursorW(NULL
, (LPCWSTR
)IDC_ARROW
);
1603 wcex
.hbrBackground
= (HBRUSH
)(COLOR_MENU
+ 1);
1604 wcex
.lpszMenuName
= NULL
;
1605 wcex
.lpszClassName
= windowClassW
;
1606 wcex
.hIconSm
= LoadIconW(NULL
, (LPCWSTR
)IDI_APPLICATION
);
1608 RegisterClassExW(&wcex
);
1610 /* Read in window parameters if available */
1611 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_STYLES
)
1612 dwStyles
= info
->WinType
.dwStyles
| WS_OVERLAPPEDWINDOW
;
1614 dwStyles
= WS_OVERLAPPEDWINDOW
| WS_VISIBLE
|
1615 WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
1617 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_EXSTYLES
)
1618 dwExStyles
= info
->WinType
.dwExStyles
;
1620 dwExStyles
= WS_EX_LEFT
| WS_EX_LTRREADING
| WS_EX_APPWINDOW
|
1621 WS_EX_WINDOWEDGE
| WS_EX_RIGHTSCROLLBAR
;
1623 if (info
->WinType
.fsValidMembers
& HHWIN_PARAM_RECT
)
1627 width
= winPos
.right
- x
;
1628 height
= winPos
.bottom
- y
;
1630 if (!width
|| !height
)
1632 x
= WINTYPE_DEFAULT_X
;
1633 y
= WINTYPE_DEFAULT_Y
;
1634 width
= WINTYPE_DEFAULT_WIDTH
;
1635 height
= WINTYPE_DEFAULT_HEIGHT
;
1638 if (info
->WinType
.fNotExpanded
)
1640 if (!(info
->WinType
.fsValidMembers
& HHWIN_PARAM_NAV_WIDTH
) &&
1641 info
->WinType
.iNavWidth
== 0)
1643 info
->WinType
.iNavWidth
= WINTYPE_DEFAULT_NAVWIDTH
;
1646 x
+= info
->WinType
.iNavWidth
;
1647 width
-= info
->WinType
.iNavWidth
;
1651 caption
= info
->WinType
.pszCaption
;
1652 if (!*caption
) caption
= info
->pCHMInfo
->defTitle
;
1654 hWnd
= CreateWindowExW(dwExStyles
, windowClassW
, caption
,
1655 dwStyles
, x
, y
, width
, height
, NULL
, NULL
, hhctrl_hinstance
, NULL
);
1659 ShowWindow(hWnd
, SW_SHOW
);
1662 /* store the pointer to the HH info struct */
1663 SetWindowLongPtrW(hWnd
, 0, (LONG_PTR
)info
);
1665 info
->WinType
.hwndHelp
= hWnd
;
1669 static void HH_CreateFont(HHInfo
*pHHInfo
)
1673 GetObjectW(GetStockObject(DEFAULT_GUI_FONT
), sizeof(LOGFONTW
), &lf
);
1674 lf
.lfWeight
= FW_NORMAL
;
1675 lf
.lfItalic
= FALSE
;
1676 lf
.lfUnderline
= FALSE
;
1678 pHHInfo
->hFont
= CreateFontIndirectW(&lf
);
1681 static void HH_InitRequiredControls(DWORD dwControls
)
1683 INITCOMMONCONTROLSEX icex
;
1685 icex
.dwSize
= sizeof(INITCOMMONCONTROLSEX
);
1686 icex
.dwICC
= dwControls
;
1687 InitCommonControlsEx(&icex
);
1690 /* Creates the whole package */
1691 static BOOL
CreateViewer(HHInfo
*pHHInfo
)
1693 HH_CreateFont(pHHInfo
);
1695 if (!HH_CreateHelpWindow(pHHInfo
))
1698 HH_InitRequiredControls(ICC_BAR_CLASSES
);
1700 if (!HH_AddToolbar(pHHInfo
))
1703 HH_RegisterChildWndClass(pHHInfo
);
1705 if (!HH_AddNavigationPane(pHHInfo
))
1708 HH_RegisterSizeBarClass(pHHInfo
);
1710 if (!HH_AddSizeBar(pHHInfo
))
1713 if (!HH_AddHTMLPane(pHHInfo
))
1716 if (!AddContentTab(pHHInfo
))
1719 if (!AddIndexTab(pHHInfo
))
1722 if (!AddIndexPopup(pHHInfo
))
1725 if (!AddSearchTab(pHHInfo
))
1728 InitContent(pHHInfo
);
1734 void ReleaseHelpViewer(HHInfo
*info
)
1736 TRACE("(%p)\n", info
);
1741 /* Free allocated strings */
1742 heap_free(info
->pszType
);
1743 heap_free(info
->pszCaption
);
1744 heap_free(info
->pszToc
);
1745 heap_free(info
->pszIndex
);
1746 heap_free(info
->pszFile
);
1747 heap_free(info
->pszHome
);
1748 heap_free(info
->pszJump1
);
1749 heap_free(info
->pszJump2
);
1750 heap_free(info
->pszUrlJump1
);
1751 heap_free(info
->pszUrlJump2
);
1754 CloseCHM(info
->pCHMInfo
);
1756 ReleaseWebBrowser(info
);
1757 ReleaseContent(info
);
1759 ReleaseSearch(info
);
1761 if(info
->contents
.hImageList
)
1762 ImageList_Destroy(info
->contents
.hImageList
);
1763 if(info
->WinType
.hwndHelp
)
1764 DestroyWindow(info
->WinType
.hwndHelp
);
1770 HHInfo
*CreateHelpViewer(LPCWSTR filename
)
1772 HHInfo
*info
= heap_alloc_zero(sizeof(HHInfo
));
1775 /* Set the invalid tab ID (-1) as the default value for all
1776 * of the tabs, this matches a failed TCM_INSERTITEM call.
1778 for(i
=0;i
<sizeof(info
->tabs
)/sizeof(HHTab
);i
++)
1779 info
->tabs
[i
].id
= -1;
1781 OleInitialize(NULL
);
1783 info
->pCHMInfo
= OpenCHM(filename
);
1784 if(!info
->pCHMInfo
) {
1785 ReleaseHelpViewer(info
);
1789 if (!LoadWinTypeFromCHM(info
)) {
1790 ReleaseHelpViewer(info
);
1794 if(!CreateViewer(info
)) {
1795 ReleaseHelpViewer(info
);
1803 * Search the table of HTML entities and return the corresponding ANSI symbol.
1805 static char find_html_symbol(const char *entity
, int entity_len
)
1807 int max
= sizeof(html_encoded_symbols
)/sizeof(html_encoded_symbols
[0])-1;
1812 int pos
= (min
+max
)/2;
1813 const char *encoded_symbol
= html_encoded_symbols
[pos
].html_code
;
1814 dir
= strncmp(encoded_symbol
, entity
, entity_len
);
1815 if(dir
== 0 && !encoded_symbol
[entity_len
]) return html_encoded_symbols
[pos
].ansi_symbol
;
1825 * Decode a string containing HTML encoded characters into a unicode string.
1827 WCHAR
*decode_html(const char *html_fragment
, int html_fragment_len
, UINT code_page
)
1829 const char *h
= html_fragment
;
1830 char *amp
, *sem
, symbol
, *tmp
;
1831 int len
, tmp_len
= 0;
1832 WCHAR
*unicode_text
;
1834 tmp
= heap_alloc(html_fragment_len
+1);
1838 amp
= strchr(h
, '&');
1841 /* Copy the characters prior to the HTML encoded character */
1842 memcpy(&tmp
[tmp_len
], h
, len
);
1844 amp
++; /* skip ampersand */
1845 sem
= strchr(amp
, ';');
1846 /* Require a semicolon after the ampersand */
1850 tmp
[tmp_len
++] = '&';
1853 /* Find the symbol either by using the ANSI character number (prefixed by the pound symbol)
1854 * or by searching the HTML entity table */
1858 char *endnum
= NULL
;
1861 tmp
= (char) strtol(amp
, &endnum
, 10);
1866 symbol
= find_html_symbol(amp
, len
);
1869 FIXME("Failed to translate HTML encoded character '&%.*s;'.\n", len
, amp
);
1871 tmp
[tmp_len
++] = '&';
1874 /* Insert the new symbol */
1876 tmp
[tmp_len
++] = symbol
;
1878 /* Convert any remaining characters */
1879 len
= html_fragment_len
-(h
-html_fragment
);
1880 memcpy(&tmp
[tmp_len
], h
, len
);
1882 tmp
[tmp_len
++] = 0; /* NULL-terminate the string */
1884 len
= MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, NULL
, 0);
1885 unicode_text
= heap_alloc(len
*sizeof(WCHAR
));
1886 MultiByteToWideChar(code_page
, 0, tmp
, tmp_len
, unicode_text
, len
);
1888 return unicode_text
;