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;
638 item->name = GetDocumentTitle(info->pCHMInfo, item->local);
641 memset(&lvi, 0, sizeof(lvi));
643 lvi.mask = LVIF_TEXT|LVIF_PARAM;
644 lvi.cchTextMax = strlenW(name)+1;
646 lvi.lParam = (LPARAM) item;
647 SendMessageW(info->popup.hwndList, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
649 ShowWindow(info->popup.hwndPopup, SW_SHOW);
652 name = iiter->items[0].name;
653 local = iiter->items[0].local;
654 chmfile = iiter->merge.chm_file;
657 siter = (SearchItem *) user_data;
658 name = siter->filename;
659 local = siter->filename;
660 chmfile = info->pCHMInfo->szFile;
663 FIXME("Unhandled operation for this tab!\n");
669 FIXME("No help file found for this item!\n");
673 TRACE("name %s loal %s\n", debugstr_w(name), debugstr_w(local));
675 NavigateToChm(info, chmfile, local);
679 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
680 static LRESULT CALLBACK EditChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
682 WNDPROC editWndProc = (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
684 if(message == WM_KEYUP && wParam == VK_RETURN)
688 nmhdr.hwndFrom = hWnd;
689 nmhdr.code = NM_RETURN;
690 SendMessageW(GetParent(GetParent(hWnd)), WM_NOTIFY, wParam, (LPARAM)&nmhdr);
692 return editWndProc(hWnd, message, wParam, lParam);
695 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
700 return Child_OnPaint(hWnd);
702 return Child_OnSize(hWnd);
704 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, 0);
705 NMHDR *nmhdr = (NMHDR*)lParam;
707 switch(nmhdr->code) {
709 return OnTabChange(hWnd);
710 case TVN_SELCHANGEDW:
711 return OnTopicChange(info, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam);
712 case TVN_ITEMEXPANDINGW: {
713 TVITEMW *item = &((NMTREEVIEWW *)lParam)->itemNew;
714 HWND hwndTreeView = info->tabs[TAB_CONTENTS].hwnd;
716 item->mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE;
717 if (item->state & TVIS_EXPANDED)
719 item->iImage = HHTV_FOLDER;
720 item->iSelectedImage = HHTV_FOLDER;
724 item->iImage = HHTV_OPENFOLDER;
725 item->iSelectedImage = HHTV_OPENFOLDER;
727 SendMessageW(hwndTreeView, TVM_SETITEMW, 0, (LPARAM)item);
733 switch(info->current_tab)
736 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
738 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
744 switch(info->current_tab) {
746 HWND hwndList = info->tabs[TAB_INDEX].hwnd;
749 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
750 lvItem.mask = TVIF_PARAM;
751 SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
752 OnTopicChange(info, (void*) lvItem.lParam);
756 if(nmhdr->hwndFrom == info->search.hwndEdit) {
760 len = GetWindowTextA(info->search.hwndEdit, needle, sizeof(needle));
763 FIXME("Unable to get search text.\n");
766 /* Convert the requested text for comparison later against the
767 * lower case version of HTML file contents.
770 needle[i] = tolower(needle[i]);
771 InitSearch(info, needle);
773 }else if(nmhdr->hwndFrom == info->search.hwndList) {
774 HWND hwndList = info->search.hwndList;
777 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
778 lvItem.mask = TVIF_PARAM;
779 SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
780 OnTopicChange(info, (void*) lvItem.lParam);
791 return DefWindowProcW(hWnd, message, wParam, lParam);
797 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
801 wcex.cbSize = sizeof(WNDCLASSEXW);
803 wcex.lpfnWndProc = Child_WndProc;
805 wcex.cbWndExtra = sizeof(LONG_PTR);
806 wcex.hInstance = hhctrl_hinstance;
807 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
808 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
809 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
810 wcex.lpszMenuName = NULL;
811 wcex.lpszClassName = szChildClass;
812 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
814 RegisterClassExW(&wcex);
821 static void DisplayPopupMenu(HHInfo *info)
824 TBBUTTONINFOW button;
830 menu = LoadMenuW(hhctrl_hinstance, MAKEINTRESOURCEW(MENU_POPUP));
835 submenu = GetSubMenu(menu, 0);
837 /* Update the Show/Hide menu item */
838 item.cbSize = sizeof(MENUITEMINFOW);
839 item.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_STRING;
840 item.fType = MFT_STRING;
841 item.fState = MF_ENABLED;
843 if (info->WinType.fNotExpanded)
844 item.dwTypeData = HH_LoadString(IDS_SHOWTABS);
846 item.dwTypeData = HH_LoadString(IDS_HIDETABS);
848 SetMenuItemInfoW(submenu, IDTB_EXPAND, FALSE, &item);
849 heap_free(item.dwTypeData);
851 /* Find the index toolbar button */
852 button.cbSize = sizeof(TBBUTTONINFOW);
853 button.dwMask = TBIF_COMMAND;
854 index = SendMessageW(info->WinType.hwndToolBar, TB_GETBUTTONINFOW, IDTB_OPTIONS, (LPARAM) &button);
860 SendMessageW(info->WinType.hwndToolBar, TB_GETITEMRECT, index, (LPARAM) &rect);
862 coords.x = rect.left;
863 coords.y = rect.bottom;
865 ClientToScreen(info->WinType.hwndToolBar, &coords);
866 TrackPopupMenu(submenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_NOANIMATION, coords.x, coords.y, 0, info->WinType.hwndHelp, NULL);
869 static void TB_OnClick(HWND hWnd, DWORD dwID)
871 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, 0);
876 DoPageAction(info, WB_STOP);
879 DoPageAction(info, WB_REFRESH);
882 DoPageAction(info, WB_GOBACK);
885 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
888 DoPageAction(info, WB_GOFORWARD);
891 DoPageAction(info, WB_PRINT);
895 ExpandContract(info);
901 DisplayPopupMenu(info);
909 /* These are officially unimplemented as of the Windows 7 SDK */
911 case IDTB_BROWSE_FWD:
912 case IDTB_BROWSE_BACK:
923 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID, DWORD dwBitmap)
925 pButtons[dwIndex].iBitmap = dwBitmap;
926 pButtons[dwIndex].idCommand = dwID;
927 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
928 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
929 pButtons[dwIndex].dwData = 0;
930 pButtons[dwIndex].iString = 0;
933 static void TB_AddButtonsFromFlags(HHInfo *pHHInfo, TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
935 int nHistBitmaps = 0, nStdBitmaps = 0, nHHBitmaps = 0;
936 HWND hToolbar = pHHInfo->WinType.hwndToolBar;
941 tbAB.hInst = HINST_COMMCTRL;
942 tbAB.nID = IDB_HIST_LARGE_COLOR;
943 nHistBitmaps = SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
944 tbAB.nID = IDB_STD_LARGE_COLOR;
945 nStdBitmaps = SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
946 /* hhctrl.ocx bitmaps */
947 tbAB.hInst = hhctrl_hinstance;
948 tbAB.nID = IDB_HHTOOLBAR;
949 nHHBitmaps = SendMessageW(hToolbar, TB_ADDBITMAP, HHTB_NUMBITMAPS, (LPARAM)&tbAB);
953 unsupported = dwButtonFlags & (HHWIN_BUTTON_BROWSE_FWD |
954 HHWIN_BUTTON_BROWSE_BCK | HHWIN_BUTTON_NOTES | HHWIN_BUTTON_CONTENTS |
955 HHWIN_BUTTON_INDEX | HHWIN_BUTTON_SEARCH | HHWIN_BUTTON_HISTORY |
956 HHWIN_BUTTON_FAVORITES | HHWIN_BUTTON_JUMP1 | HHWIN_BUTTON_JUMP2 |
957 HHWIN_BUTTON_ZOOM | HHWIN_BUTTON_TOC_NEXT | HHWIN_BUTTON_TOC_PREV);
959 FIXME("got asked for unsupported buttons: %06x\n", unsupported);
961 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
963 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND, nHHBitmaps + HHTB_EXPAND);
964 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_CONTRACT, nHHBitmaps + HHTB_CONTRACT);
966 if (pHHInfo->WinType.fNotExpanded)
967 pButtons[1].fsState |= TBSTATE_HIDDEN;
969 pButtons[0].fsState |= TBSTATE_HIDDEN;
972 if (dwButtonFlags & HHWIN_BUTTON_BACK)
973 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK, nHistBitmaps + HIST_BACK);
975 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
976 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD, nHistBitmaps + HIST_FORWARD);
978 if (dwButtonFlags & HHWIN_BUTTON_STOP)
979 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP, nHHBitmaps + HHTB_STOP);
981 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
982 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH, nHHBitmaps + HHTB_REFRESH);
984 if (dwButtonFlags & HHWIN_BUTTON_HOME)
985 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME, nHHBitmaps + HHTB_HOME);
987 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
988 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC, nHHBitmaps + HHTB_SYNC);
990 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
991 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS, nStdBitmaps + STD_PROPERTIES);
993 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
994 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT, nStdBitmaps + STD_PRINT);
997 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
1000 HWND hwndParent = pHHInfo->WinType.hwndHelp;
1002 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
1003 DWORD dwStyles, dwExStyles;
1004 DWORD dwNumButtons, dwIndex;
1006 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
1007 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
1009 toolbarFlags = HHWIN_DEF_BUTTONS;
1011 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
1012 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
1013 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
1015 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
1016 0, 0, 0, 0, hwndParent, NULL,
1017 hhctrl_hinstance, NULL);
1020 pHHInfo->WinType.hwndToolBar = hToolbar;
1022 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
1023 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
1024 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
1026 TB_AddButtonsFromFlags(pHHInfo, buttons, toolbarFlags, &dwNumButtons);
1028 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
1030 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
1031 DWORD dwLen = strlenW(szBuf);
1032 szBuf[dwLen + 1] = 0; /* Double-null terminate */
1034 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
1038 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)buttons);
1039 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
1040 ShowWindow(hToolbar, SW_SHOW);
1045 /* Navigation Pane */
1047 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
1049 HWND hwndParent = pHHInfo->WinType.hwndHelp;
1050 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
1051 RECT rectWND, rectTB;
1053 GetClientRect(hwndParent, &rectWND);
1054 GetClientRect(hwndToolbar, &rectTB);
1057 rc->top = rectTB.bottom;
1058 rc->bottom = rectWND.bottom - rectTB.bottom;
1060 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
1061 pHHInfo->WinType.iNavWidth == 0)
1063 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
1066 rc->right = pHHInfo->WinType.iNavWidth;
1069 static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index)
1072 LPWSTR tabText = HH_LoadString(index);
1075 tie.mask = TCIF_TEXT;
1076 tie.pszText = tabText;
1078 ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie );
1084 static BOOL HH_AddNavigationPane(HHInfo *info)
1086 HWND hWnd, hwndTabCtrl;
1087 HWND hwndParent = info->WinType.hwndHelp;
1088 DWORD dwStyles = WS_CHILDWINDOW;
1089 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
1092 if (!info->WinType.fNotExpanded)
1093 dwStyles |= WS_VISIBLE;
1095 NP_GetNavigationRect(info, &rc);
1097 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
1098 rc.left, rc.top, rc.right, rc.bottom,
1099 hwndParent, NULL, hhctrl_hinstance, NULL);
1103 SetWindowLongPtrW(hWnd, 0, (LONG_PTR)info);
1105 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles | WS_VISIBLE,
1107 rc.right - TAB_RIGHT_PADDING,
1108 rc.bottom - TAB_TOP_PADDING,
1109 hWnd, NULL, hhctrl_hinstance, NULL);
1113 if (*info->WinType.pszToc)
1114 info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS);
1116 if (*info->WinType.pszIndex)
1117 info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX);
1119 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
1120 info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH);
1122 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
1123 info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES);
1125 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
1127 info->hwndTabCtrl = hwndTabCtrl;
1128 info->WinType.hwndNavigation = hWnd;
1134 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
1136 RECT rectTB, rectWND, rectNP, rectSB;
1138 GetClientRect(info->WinType.hwndHelp, &rectWND);
1139 GetClientRect(info->WinType.hwndToolBar, &rectTB);
1140 GetClientRect(info->hwndSizeBar, &rectSB);
1142 if (info->WinType.fNotExpanded)
1146 GetClientRect(info->WinType.hwndNavigation, &rectNP);
1147 rc->left = rectNP.right + rectSB.right;
1150 rc->top = rectTB.bottom;
1151 rc->right = rectWND.right - rc->left;
1152 rc->bottom = rectWND.bottom - rectTB.bottom;
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 (!pHHInfo->WinType.fNotExpanded)
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 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1564 if (HIWORD(wParam) == BN_CLICKED)
1565 TB_OnClick(hWnd, LOWORD(wParam));
1568 return Help_OnSize(hWnd);
1570 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, 0));
1578 return DefWindowProcW(hWnd, message, wParam, lParam);
1584 static BOOL HH_CreateHelpWindow(HHInfo *info)
1587 RECT winPos = info->WinType.rcWindowPos;
1589 DWORD dwStyles, dwExStyles;
1590 DWORD x, y, width = 0, height = 0;
1593 static const WCHAR windowClassW[] = {
1594 'H','H',' ', 'P','a','r','e','n','t',0
1597 wcex.cbSize = sizeof(WNDCLASSEXW);
1598 wcex.style = CS_HREDRAW | CS_VREDRAW;
1599 wcex.lpfnWndProc = Help_WndProc;
1600 wcex.cbClsExtra = 0;
1601 wcex.cbWndExtra = sizeof(LONG_PTR);
1602 wcex.hInstance = hhctrl_hinstance;
1603 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1604 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1605 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1606 wcex.lpszMenuName = NULL;
1607 wcex.lpszClassName = windowClassW;
1608 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1610 RegisterClassExW(&wcex);
1612 /* Read in window parameters if available */
1613 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
1614 dwStyles = info->WinType.dwStyles | WS_OVERLAPPEDWINDOW;
1616 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
1617 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1619 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
1620 dwExStyles = info->WinType.dwExStyles;
1622 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
1623 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
1625 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
1629 width = winPos.right - x;
1630 height = winPos.bottom - y;
1632 if (!width || !height)
1634 x = WINTYPE_DEFAULT_X;
1635 y = WINTYPE_DEFAULT_Y;
1636 width = WINTYPE_DEFAULT_WIDTH;
1637 height = WINTYPE_DEFAULT_HEIGHT;
1640 if (info->WinType.fNotExpanded)
1642 if (!(info->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
1643 info->WinType.iNavWidth == 0)
1645 info->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
1648 x += info->WinType.iNavWidth;
1649 width -= info->WinType.iNavWidth;
1653 caption = info->WinType.pszCaption;
1654 if (!*caption) caption = info->pCHMInfo->defTitle;
1656 hWnd = CreateWindowExW(dwExStyles, windowClassW, caption,
1657 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
1661 ShowWindow(hWnd, SW_SHOW);
1664 /* store the pointer to the HH info struct */
1665 SetWindowLongPtrW(hWnd, 0, (LONG_PTR)info);
1667 info->WinType.hwndHelp = hWnd;
1671 static void HH_CreateFont(HHInfo *pHHInfo)
1675 GetObjectW(GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONTW), &lf);
1676 lf.lfWeight = FW_NORMAL;
1677 lf.lfItalic = FALSE;
1678 lf.lfUnderline = FALSE;
1680 pHHInfo->hFont = CreateFontIndirectW(&lf);
1683 static void HH_InitRequiredControls(DWORD dwControls)
1685 INITCOMMONCONTROLSEX icex;
1687 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1688 icex.dwICC = dwControls;
1689 InitCommonControlsEx(&icex);
1692 /* Creates the whole package */
1693 static BOOL CreateViewer(HHInfo *pHHInfo)
1695 HH_CreateFont(pHHInfo);
1697 if (!HH_CreateHelpWindow(pHHInfo))
1700 HH_InitRequiredControls(ICC_BAR_CLASSES);
1702 if (!HH_AddToolbar(pHHInfo))
1705 HH_RegisterChildWndClass(pHHInfo);
1707 if (!HH_AddNavigationPane(pHHInfo))
1710 HH_RegisterSizeBarClass(pHHInfo);
1712 if (!HH_AddSizeBar(pHHInfo))
1715 if (!HH_AddHTMLPane(pHHInfo))
1718 if (!AddContentTab(pHHInfo))
1721 if (!AddIndexTab(pHHInfo))
1724 if (!AddIndexPopup(pHHInfo))
1727 if (!AddSearchTab(pHHInfo))
1730 InitContent(pHHInfo);
1736 void ReleaseHelpViewer(HHInfo *info)
1738 TRACE("(%p)\n", info);
1743 /* Free allocated strings */
1744 heap_free(info->pszType);
1745 heap_free(info->pszCaption);
1746 heap_free(info->pszToc);
1747 heap_free(info->pszIndex);
1748 heap_free(info->pszFile);
1749 heap_free(info->pszHome);
1750 heap_free(info->pszJump1);
1751 heap_free(info->pszJump2);
1752 heap_free(info->pszUrlJump1);
1753 heap_free(info->pszUrlJump2);
1756 CloseCHM(info->pCHMInfo);
1758 ReleaseWebBrowser(info);
1759 ReleaseContent(info);
1761 ReleaseSearch(info);
1763 if(info->contents.hImageList)
1764 ImageList_Destroy(info->contents.hImageList);
1765 if(info->WinType.hwndHelp)
1766 DestroyWindow(info->WinType.hwndHelp);
1772 HHInfo *CreateHelpViewer(LPCWSTR filename)
1774 HHInfo *info = heap_alloc_zero(sizeof(HHInfo));
1777 /* Set the invalid tab ID (-1) as the default value for all
1778 * of the tabs, this matches a failed TCM_INSERTITEM call.
1780 for(i=0;i<sizeof(info->tabs)/sizeof(HHTab);i++)
1781 info->tabs[i].id = -1;
1783 OleInitialize(NULL);
1785 info->pCHMInfo = OpenCHM(filename);
1786 if(!info->pCHMInfo) {
1787 ReleaseHelpViewer(info);
1791 if (!LoadWinTypeFromCHM(info)) {
1792 ReleaseHelpViewer(info);
1796 if(!CreateViewer(info)) {
1797 ReleaseHelpViewer(info);
1805 * Search the table of HTML entities and return the corresponding ANSI symbol.
1807 static char find_html_symbol(const char *entity, int entity_len)
1809 int max = sizeof(html_encoded_symbols)/sizeof(html_encoded_symbols[0])-1;
1814 int pos = (min+max)/2;
1815 const char *encoded_symbol = html_encoded_symbols[pos].html_code;
1816 dir = strncmp(encoded_symbol, entity, entity_len);
1817 if(dir == 0 && !encoded_symbol[entity_len]) return html_encoded_symbols[pos].ansi_symbol;
1827 * Decode a string containing HTML encoded characters into a unicode string.
1829 WCHAR *decode_html(const char *html_fragment, int html_fragment_len, UINT code_page)
1831 const char *h = html_fragment;
1832 char *amp, *sem, symbol, *tmp;
1833 int len, tmp_len = 0;
1834 WCHAR *unicode_text;
1836 tmp = heap_alloc(html_fragment_len+1);
1840 amp = strchr(h, '&');
1843 /* Copy the characters prior to the HTML encoded character */
1844 memcpy(&tmp[tmp_len], h, len);
1846 amp++; /* skip ampersand */
1847 sem = strchr(amp, ';');
1848 /* Require a semicolon after the ampersand */
1852 tmp[tmp_len++] = '&';
1855 /* Find the symbol either by using the ANSI character number (prefixed by the pound symbol)
1856 * or by searching the HTML entity table */
1860 char *endnum = NULL;
1863 tmp = (char) strtol(amp, &endnum, 10);
1868 symbol = find_html_symbol(amp, len);
1871 FIXME("Failed to translate HTML encoded character '&%.*s;'.\n", len, amp);
1873 tmp[tmp_len++] = '&';
1876 /* Insert the new symbol */
1878 tmp[tmp_len++] = symbol;
1880 /* Convert any remaining characters */
1881 len = html_fragment_len-(h-html_fragment);
1882 memcpy(&tmp[tmp_len], h, len);
1884 tmp[tmp_len++] = 0; /* NULL-terminate the string */
1886 len = MultiByteToWideChar(code_page, 0, tmp, tmp_len, NULL, 0);
1887 unicode_text = heap_alloc(len*sizeof(WCHAR));
1888 MultiByteToWideChar(code_page, 0, tmp, tmp_len, unicode_text, len);
1890 return unicode_text;