2 * Help Viewer Implementation
4 * Copyright 2005 James Hawkins
5 * Copyright 2007 Jacek Caban for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
34 static LRESULT Help_OnSize(HWND hWnd);
36 /* Window type defaults */
38 #define WINTYPE_DEFAULT_X 280
39 #define WINTYPE_DEFAULT_Y 100
40 #define WINTYPE_DEFAULT_WIDTH 740
41 #define WINTYPE_DEFAULT_HEIGHT 640
42 #define WINTYPE_DEFAULT_NAVWIDTH 250
44 #define TAB_TOP_PADDING 8
45 #define TAB_RIGHT_PADDING 4
47 #define EDIT_HEIGHT 20
49 static const WCHAR szEmpty[] = {0};
51 /* Loads a string from the resource file */
52 static LPWSTR HH_LoadString(DWORD dwID)
55 LPCWSTR stringresource;
58 iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0);
60 string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */
61 memcpy(string, stringresource, iSize*sizeof(WCHAR));
67 static HRESULT navigate_url(HHInfo *info, LPCWSTR surl)
72 TRACE("%s\n", debugstr_w(surl));
75 V_BSTR(&url) = SysAllocString(surl);
77 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
82 TRACE("Navigation failed: %08x\n", hres);
87 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
93 static const WCHAR url_indicator[] = {':', '/', '/', 0};
95 TRACE("%s\n", debugstr_w(surl));
97 if (strstrW(surl, url_indicator)) {
98 hres = navigate_url(info, surl);
101 } /* look up in chm if it doesn't look like a full url */
103 SetChmPath(&chm_path, info->pCHMInfo->szFile, surl);
104 ret = NavigateToChm(info, chm_path.chm_file, chm_path.chm_index);
106 heap_free(chm_path.chm_file);
107 heap_free(chm_path.chm_index);
112 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
114 WCHAR buf[INTERNET_MAX_URL_LENGTH];
115 WCHAR full_path[MAX_PATH];
118 static const WCHAR url_format[] =
119 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
120 static const WCHAR slash[] = {'/',0};
121 static const WCHAR empty[] = {0};
123 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
125 if (!info->web_browser)
128 if(!GetFullPathNameW(file, sizeof(full_path)/sizeof(full_path[0]), full_path, NULL)) {
129 WARN("GetFullPathName failed: %u\n", GetLastError());
133 wsprintfW(buf, url_format, full_path, (!index || index[0] == '/') ? empty : slash, index);
136 if((ptr = strchrW(buf, '#')))
139 return SUCCEEDED(navigate_url(info, buf));
144 #define SIZEBAR_WIDTH 4
146 static const WCHAR szSizeBarClass[] = {
147 'H','H',' ','S','i','z','e','B','a','r',0
150 /* Draw the SizeBar */
151 static void SB_OnPaint(HWND hWnd)
157 hdc = BeginPaint(hWnd, &ps);
159 GetClientRect(hWnd, &rc);
164 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
166 /* white highlight */
167 SelectObject(hdc, GetStockObject(WHITE_PEN));
168 MoveToEx(hdc, rc.right, 1, NULL);
170 LineTo(hdc, 1, rc.bottom - 1);
173 MoveToEx(hdc, 0, rc.bottom, NULL);
174 LineTo(hdc, rc.right, rc.bottom);
179 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
184 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
186 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
189 pt.x = (short)LOWORD(lParam);
190 pt.y = (short)HIWORD(lParam);
192 /* update the window sizes */
193 pHHInfo->WinType.iNavWidth += pt.x;
199 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
201 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
202 if (!(wParam & MK_LBUTTON))
206 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
211 SB_OnLButtonDown(hWnd, wParam, lParam);
214 SB_OnLButtonUp(hWnd, wParam, lParam);
217 SB_OnMouseMove(hWnd, wParam, lParam);
223 return DefWindowProcW(hWnd, message, wParam, lParam);
229 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
233 wcex.cbSize = sizeof(WNDCLASSEXW);
235 wcex.lpfnWndProc = SizeBar_WndProc;
238 wcex.hInstance = hhctrl_hinstance;
239 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
240 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
241 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
242 wcex.lpszMenuName = NULL;
243 wcex.lpszClassName = szSizeBarClass;
244 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
246 RegisterClassExW(&wcex);
249 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
251 RECT rectWND, rectTB, rectNP;
253 GetClientRect(info->WinType.hwndHelp, &rectWND);
254 GetClientRect(info->WinType.hwndToolBar, &rectTB);
255 GetClientRect(info->WinType.hwndNavigation, &rectNP);
257 rc->left = rectNP.right;
258 rc->top = rectTB.bottom;
259 rc->bottom = rectWND.bottom - rectTB.bottom;
260 rc->right = SIZEBAR_WIDTH;
263 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
266 HWND hwndParent = pHHInfo->WinType.hwndHelp;
267 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
268 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
271 SB_GetSizeBarRect(pHHInfo, &rc);
273 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
274 rc.left, rc.top, rc.right, rc.bottom,
275 hwndParent, NULL, hhctrl_hinstance, NULL);
279 /* store the pointer to the HH info struct */
280 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
282 pHHInfo->hwndSizeBar = hWnd;
288 static const WCHAR szChildClass[] = {
289 'H','H',' ','C','h','i','l','d',0
292 static LRESULT Child_OnPaint(HWND hWnd)
298 hdc = BeginPaint(hWnd, &ps);
300 /* Only paint the Navigation pane, identified by the fact
301 * that it has a child window
303 if (GetWindow(hWnd, GW_CHILD))
305 GetClientRect(hWnd, &rc);
307 /* set the border color */
308 SelectObject(hdc, GetStockObject(DC_PEN));
309 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
311 /* Draw the top border */
312 LineTo(hdc, rc.right, 0);
314 SelectObject(hdc, GetStockObject(WHITE_PEN));
315 MoveToEx(hdc, 0, 1, NULL);
316 LineTo(hdc, rc.right, 1);
324 static void ResizeTabChild(HHInfo *info, int tab)
326 HWND hwnd = info->tabs[tab].hwnd;
331 GetClientRect(info->WinType.hwndNavigation, &rect);
332 SendMessageW(info->hwndTabCtrl, TCM_GETITEMRECT, 0, (LPARAM)&tabrc);
333 cnt = SendMessageW(info->hwndTabCtrl, TCM_GETROWCOUNT, 0, 0);
335 rect.left = TAB_MARGIN;
336 rect.top = TAB_TOP_PADDING + cnt*(tabrc.bottom-tabrc.top) + TAB_MARGIN;
337 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
338 rect.bottom -= TAB_MARGIN;
339 width = rect.right-rect.left;
340 height = rect.bottom-rect.top;
342 SetWindowPos(hwnd, NULL, rect.left, rect.top, width, height,
343 SWP_NOZORDER | SWP_NOACTIVATE);
348 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
349 int border_width = GetSystemMetrics(SM_CXBORDER);
350 int edge_width = GetSystemMetrics(SM_CXEDGE);
352 /* Resize the tab widget column to perfectly fit the tab window and
353 * leave sufficient space for the scroll widget.
355 SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_SETCOLUMNWIDTH, 0,
356 width-scroll_width-2*border_width-2*edge_width);
361 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
362 int border_width = GetSystemMetrics(SM_CXBORDER);
363 int edge_width = GetSystemMetrics(SM_CXEDGE);
366 SetWindowPos(info->search.hwndEdit, NULL, 0, top_pos, width,
367 EDIT_HEIGHT, SWP_NOZORDER | SWP_NOACTIVATE);
368 top_pos += EDIT_HEIGHT + TAB_MARGIN;
369 SetWindowPos(info->search.hwndList, NULL, 0, top_pos, width,
370 height-top_pos, SWP_NOZORDER | SWP_NOACTIVATE);
371 /* Resize the tab widget column to perfectly fit the tab window and
372 * leave sufficient space for the scroll widget.
374 SendMessageW(info->search.hwndList, LVM_SETCOLUMNWIDTH, 0,
375 width-scroll_width-2*border_width-2*edge_width);
382 static LRESULT Child_OnSize(HWND hwnd)
384 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
387 if(!info || hwnd != info->WinType.hwndNavigation)
390 GetClientRect(hwnd, &rect);
391 SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0,
392 rect.right - TAB_RIGHT_PADDING,
393 rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
395 ResizeTabChild(info, TAB_CONTENTS);
396 ResizeTabChild(info, TAB_INDEX);
400 static LRESULT OnTabChange(HWND hwnd)
402 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
409 if(info->tabs[info->current_tab].hwnd)
410 ShowWindow(info->tabs[info->current_tab].hwnd, SW_HIDE);
412 info->current_tab = SendMessageW(info->hwndTabCtrl, TCM_GETCURSEL, 0, 0);
414 if(info->tabs[info->current_tab].hwnd)
415 ShowWindow(info->tabs[info->current_tab].hwnd, SW_SHOW);
420 static LRESULT OnTopicChange(HHInfo *info, void *user_data)
422 LPCWSTR chmfile = NULL, name = NULL, local = NULL;
426 if(!user_data || !info)
429 switch (info->current_tab)
432 citer = (ContentItem *) user_data;
434 local = citer->local;
436 if(citer->merge.chm_file) {
437 chmfile = citer->merge.chm_file;
440 citer = citer->parent;
444 iiter = (IndexItem *) user_data;
445 if(iiter->nItems == 0) {
446 FIXME("No entries for this item!\n");
449 if(iiter->nItems > 1) {
453 SendMessageW(info->popup.hwndList, LVM_DELETEALLITEMS, 0, 0);
454 for(i=0;i<iiter->nItems;i++) {
455 IndexSubItem *item = &iiter->items[i];
456 WCHAR *name = iiter->keyword;
460 memset(&lvi, 0, sizeof(lvi));
462 lvi.mask = LVIF_TEXT|LVIF_PARAM;
463 lvi.cchTextMax = strlenW(name)+1;
465 lvi.lParam = (LPARAM) item;
466 SendMessageW(info->popup.hwndList, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
468 ShowWindow(info->popup.hwndPopup, SW_SHOW);
471 name = iiter->items[0].name;
472 local = iiter->items[0].local;
473 chmfile = iiter->merge.chm_file;
476 FIXME("Unhandled operation for this tab!\n");
482 FIXME("No help file found for this item!\n");
486 TRACE("name %s loal %s\n", debugstr_w(name), debugstr_w(local));
488 NavigateToChm(info, chmfile, local);
492 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
493 static LRESULT CALLBACK EditChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
495 WNDPROC editWndProc = (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
497 if(message == WM_KEYUP && wParam == VK_RETURN)
501 nmhdr.hwndFrom = hWnd;
502 nmhdr.code = NM_RETURN;
503 SendMessageW(GetParent(GetParent(hWnd)), WM_NOTIFY, wParam, (LPARAM)&nmhdr);
505 return editWndProc(hWnd, message, wParam, lParam);
508 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
513 return Child_OnPaint(hWnd);
515 return Child_OnSize(hWnd);
517 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
518 NMHDR *nmhdr = (NMHDR*)lParam;
520 switch(nmhdr->code) {
522 return OnTabChange(hWnd);
523 case TVN_SELCHANGEDW:
524 return OnTopicChange(info, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam);
526 if(info && info->current_tab == TAB_INDEX)
527 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
531 switch(info->current_tab) {
533 HWND hwndList = info->tabs[TAB_INDEX].hwnd;
536 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
537 lvItem.mask = TVIF_PARAM;
538 ListView_GetItemW(hwndList, &lvItem);
539 OnTopicChange(info, (void*) lvItem.lParam);
545 GetWindowTextW(info->search.hwndEdit, needle, sizeof(needle)/sizeof(WCHAR));
546 FIXME("Search for text: %s\n", debugstr_w(needle));
555 return DefWindowProcW(hWnd, message, wParam, lParam);
561 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
565 wcex.cbSize = sizeof(WNDCLASSEXW);
567 wcex.lpfnWndProc = Child_WndProc;
570 wcex.hInstance = hhctrl_hinstance;
571 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
572 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
573 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
574 wcex.lpszMenuName = NULL;
575 wcex.lpszClassName = szChildClass;
576 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
578 RegisterClassExW(&wcex);
585 static void TB_OnClick(HWND hWnd, DWORD dwID)
587 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
592 DoPageAction(info, WB_STOP);
595 DoPageAction(info, WB_REFRESH);
598 DoPageAction(info, WB_GOBACK);
601 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
604 DoPageAction(info, WB_GOFORWARD);
611 case IDTB_BROWSE_FWD:
612 case IDTB_BROWSE_BACK:
623 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
625 /* FIXME: Load the correct button bitmaps */
626 pButtons[dwIndex].iBitmap = STD_PRINT;
627 pButtons[dwIndex].idCommand = dwID;
628 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
629 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
630 pButtons[dwIndex].dwData = 0;
631 pButtons[dwIndex].iString = 0;
634 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
638 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
639 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
641 if (dwButtonFlags & HHWIN_BUTTON_BACK)
642 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
644 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
645 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
647 if (dwButtonFlags & HHWIN_BUTTON_STOP)
648 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
650 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
651 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
653 if (dwButtonFlags & HHWIN_BUTTON_HOME)
654 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
656 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
657 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
659 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
660 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
662 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
663 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
665 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
666 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
668 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
669 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
671 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
672 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
674 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
675 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
677 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
678 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
681 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
684 HWND hwndParent = pHHInfo->WinType.hwndHelp;
686 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
688 DWORD dwStyles, dwExStyles;
689 DWORD dwNumButtons, dwIndex;
691 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
692 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
694 toolbarFlags = HHWIN_DEF_BUTTONS;
696 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
698 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
699 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
700 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
702 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
703 0, 0, 0, 0, hwndParent, NULL,
704 hhctrl_hinstance, NULL);
708 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
709 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
710 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
712 /* FIXME: Load correct icons for all buttons */
713 tbAB.hInst = HINST_COMMCTRL;
714 tbAB.nID = IDB_STD_LARGE_COLOR;
715 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
717 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
719 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
720 DWORD dwLen = strlenW(szBuf);
721 szBuf[dwLen + 1] = 0; /* Double-null terminate */
723 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
727 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)buttons);
728 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
729 ShowWindow(hToolbar, SW_SHOW);
731 pHHInfo->WinType.hwndToolBar = hToolbar;
735 /* Navigation Pane */
737 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
739 HWND hwndParent = pHHInfo->WinType.hwndHelp;
740 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
741 RECT rectWND, rectTB;
743 GetClientRect(hwndParent, &rectWND);
744 GetClientRect(hwndToolbar, &rectTB);
747 rc->top = rectTB.bottom;
748 rc->bottom = rectWND.bottom - rectTB.bottom;
750 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
751 pHHInfo->WinType.iNavWidth == 0)
753 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
756 rc->right = pHHInfo->WinType.iNavWidth;
759 static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index)
762 LPWSTR tabText = HH_LoadString(index);
765 tie.mask = TCIF_TEXT;
766 tie.pszText = tabText;
768 ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie );
774 static BOOL HH_AddNavigationPane(HHInfo *info)
776 HWND hWnd, hwndTabCtrl;
777 HWND hwndParent = info->WinType.hwndHelp;
778 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
779 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
782 NP_GetNavigationRect(info, &rc);
784 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
785 rc.left, rc.top, rc.right, rc.bottom,
786 hwndParent, NULL, hhctrl_hinstance, NULL);
790 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
792 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
794 rc.right - TAB_RIGHT_PADDING,
795 rc.bottom - TAB_TOP_PADDING,
796 hWnd, NULL, hhctrl_hinstance, NULL);
800 if (*info->WinType.pszToc)
801 info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS);
803 if (*info->WinType.pszIndex)
804 info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX);
806 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
807 info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH);
809 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
810 info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES);
812 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
814 info->hwndTabCtrl = hwndTabCtrl;
815 info->WinType.hwndNavigation = hWnd;
821 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
823 RECT rectTB, rectWND, rectNP, rectSB;
825 GetClientRect(info->WinType.hwndHelp, &rectWND);
826 GetClientRect(info->WinType.hwndToolBar, &rectTB);
827 GetClientRect(info->WinType.hwndNavigation, &rectNP);
828 GetClientRect(info->hwndSizeBar, &rectSB);
830 rc->left = rectNP.right + rectSB.right;
831 rc->top = rectTB.bottom;
832 rc->right = rectWND.right - rc->left;
833 rc->bottom = rectWND.bottom - rectTB.bottom;
836 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
839 HWND hwndParent = pHHInfo->WinType.hwndHelp;
840 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
841 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
844 HP_GetHTMLRect(pHHInfo, &rc);
846 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
847 rc.left, rc.top, rc.right, rc.bottom,
848 hwndParent, NULL, hhctrl_hinstance, NULL);
852 if (!InitWebBrowser(pHHInfo, hWnd))
855 /* store the pointer to the HH info struct */
856 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
858 ShowWindow(hWnd, SW_SHOW);
861 pHHInfo->WinType.hwndHTML = hWnd;
865 static BOOL AddContentTab(HHInfo *info)
867 if(info->tabs[TAB_CONTENTS].id == -1)
868 return TRUE; /* No "Contents" tab */
869 info->tabs[TAB_CONTENTS].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW,
870 szEmpty, WS_CHILD | WS_BORDER | 0x25, 50, 50, 100, 100,
871 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
872 if(!info->tabs[TAB_CONTENTS].hwnd) {
873 ERR("Could not create treeview control\n");
877 ResizeTabChild(info, TAB_CONTENTS);
878 ShowWindow(info->tabs[TAB_CONTENTS].hwnd, SW_SHOW);
883 static BOOL AddIndexTab(HHInfo *info)
885 char hidden_column[] = "Column";
888 if(info->tabs[TAB_INDEX].id == -1)
889 return TRUE; /* No "Index" tab */
890 info->tabs[TAB_INDEX].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW,
891 szEmpty, WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
892 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
893 if(!info->tabs[TAB_INDEX].hwnd) {
894 ERR("Could not create ListView control\n");
897 memset(&lvc, 0, sizeof(lvc));
898 lvc.mask = LVCF_TEXT;
899 lvc.pszText = hidden_column;
900 if(SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
902 ERR("Could not create ListView column\n");
906 ResizeTabChild(info, TAB_INDEX);
907 ShowWindow(info->tabs[TAB_INDEX].hwnd, SW_HIDE);
912 static BOOL AddSearchTab(HHInfo *info)
914 HWND hwndList, hwndEdit, hwndContainer;
915 char hidden_column[] = "Column";
919 if(info->tabs[TAB_SEARCH].id == -1)
920 return TRUE; /* No "Search" tab */
921 hwndContainer = CreateWindowExW(WS_EX_CONTROLPARENT, szChildClass, szEmpty,
922 WS_CHILD, 0, 0, 0, 0, info->WinType.hwndNavigation,
923 NULL, hhctrl_hinstance, NULL);
925 ERR("Could not create search window container control.\n");
928 hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, szEmpty, WS_CHILD
929 | WS_VISIBLE | ES_LEFT | SS_NOTIFY, 0, 0, 0, 0,
930 hwndContainer, NULL, hhctrl_hinstance, NULL);
932 ERR("Could not create search ListView control.\n");
935 if(SendMessageW(hwndEdit, WM_SETFONT, (WPARAM) info->hFont, (LPARAM) FALSE) == -1)
937 ERR("Could not set font for edit control.\n");
940 editWndProc = (WNDPROC) SetWindowLongPtrW(hwndEdit, GWLP_WNDPROC, (LONG_PTR)EditChild_WndProc);
942 ERR("Could not redirect messages for edit control.\n");
945 SetWindowLongPtrW(hwndEdit, GWLP_USERDATA, (LONG_PTR)editWndProc);
946 hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty,
947 WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL
948 | LVS_REPORT | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
949 hwndContainer, NULL, hhctrl_hinstance, NULL);
951 ERR("Could not create search ListView control.\n");
954 memset(&lvc, 0, sizeof(lvc));
955 lvc.mask = LVCF_TEXT;
956 lvc.pszText = hidden_column;
957 if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
959 ERR("Could not create ListView column\n");
963 info->search.hwndEdit = hwndEdit;
964 info->search.hwndList = hwndList;
965 info->search.hwndContainer = hwndContainer;
966 info->tabs[TAB_SEARCH].hwnd = hwndContainer;
968 SetWindowLongPtrW(hwndContainer, GWLP_USERDATA, (LONG_PTR)info);
970 ResizeTabChild(info, TAB_SEARCH);
975 /* The Index tab's sub-topic popup */
977 static void ResizePopupChild(HHInfo *info)
979 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
980 int border_width = GetSystemMetrics(SM_CXBORDER);
981 int edge_width = GetSystemMetrics(SM_CXEDGE);
988 GetClientRect(info->popup.hwndPopup, &rect);
989 SetWindowPos(info->popup.hwndCallback, HWND_TOP, 0, 0,
990 rect.right, rect.bottom, SWP_NOMOVE);
992 rect.left = TAB_MARGIN;
993 rect.top = TAB_TOP_PADDING + TAB_MARGIN;
994 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
995 rect.bottom -= TAB_MARGIN;
996 width = rect.right-rect.left;
997 height = rect.bottom-rect.top;
999 SetWindowPos(info->popup.hwndList, NULL, rect.left, rect.top, width, height,
1000 SWP_NOZORDER | SWP_NOACTIVATE);
1002 SendMessageW(info->popup.hwndList, LVM_SETCOLUMNWIDTH, 0,
1003 width-scroll_width-2*border_width-2*edge_width);
1006 static LRESULT CALLBACK HelpPopup_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1008 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1013 ResizePopupChild(info);
1016 DestroyWindow(hWnd);
1019 ShowWindow(hWnd, SW_HIDE);
1023 return DefWindowProcW(hWnd, message, wParam, lParam);
1029 static LRESULT CALLBACK PopupChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1034 NMHDR *nmhdr = (NMHDR*)lParam;
1038 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1041 if(info == 0 || lParam == 0)
1043 iter = (IndexSubItem*) ((NMITEMACTIVATE *)lParam)->lParam;
1046 NavigateToChm(info, info->index->merge.chm_file, iter->local);
1047 ShowWindow(info->popup.hwndPopup, SW_HIDE);
1051 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1058 lvItem.iItem = (int) SendMessageW(info->popup.hwndList, LVM_GETSELECTIONMARK, 0, 0);
1059 lvItem.mask = TVIF_PARAM;
1060 ListView_GetItemW(info->popup.hwndList, &lvItem);
1061 iter = (IndexSubItem*) lvItem.lParam;
1062 NavigateToChm(info, info->index->merge.chm_file, iter->local);
1063 ShowWindow(info->popup.hwndPopup, SW_HIDE);
1070 return DefWindowProcW(hWnd, message, wParam, lParam);
1076 static BOOL AddIndexPopup(HHInfo *info)
1078 static const WCHAR szPopupChildClass[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1079 static const WCHAR windowCaptionW[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1080 static const WCHAR windowClassW[] = {'H','H',' ','P','o','p','u','p',0};
1081 HWND hwndList, hwndPopup, hwndCallback;
1082 char hidden_column[] = "Column";
1086 if(info->tabs[TAB_INDEX].id == -1)
1087 return TRUE; /* No "Index" tab */
1089 wcex.cbSize = sizeof(WNDCLASSEXW);
1090 wcex.style = CS_HREDRAW | CS_VREDRAW;
1091 wcex.lpfnWndProc = HelpPopup_WndProc;
1092 wcex.cbClsExtra = 0;
1093 wcex.cbWndExtra = 0;
1094 wcex.hInstance = hhctrl_hinstance;
1095 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1096 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1097 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1098 wcex.lpszMenuName = NULL;
1099 wcex.lpszClassName = windowClassW;
1100 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1101 RegisterClassExW(&wcex);
1103 wcex.cbSize = sizeof(WNDCLASSEXW);
1105 wcex.lpfnWndProc = PopupChild_WndProc;
1106 wcex.cbClsExtra = 0;
1107 wcex.cbWndExtra = 0;
1108 wcex.hInstance = hhctrl_hinstance;
1109 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1110 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1111 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1112 wcex.lpszMenuName = NULL;
1113 wcex.lpszClassName = szPopupChildClass;
1114 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1115 RegisterClassExW(&wcex);
1117 hwndPopup = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW
1118 | WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR,
1119 windowClassW, windowCaptionW, WS_POPUPWINDOW
1120 | WS_OVERLAPPEDWINDOW | WS_VISIBLE
1121 | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT,
1122 CW_USEDEFAULT, 300, 200, info->WinType.hwndHelp,
1123 NULL, hhctrl_hinstance, NULL);
1127 hwndCallback = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
1128 szPopupChildClass, szEmpty, WS_CHILDWINDOW | WS_VISIBLE,
1130 hwndPopup, NULL, hhctrl_hinstance, NULL);
1134 ShowWindow(hwndPopup, SW_HIDE);
1135 hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty,
1136 WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT
1137 | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
1138 hwndCallback, NULL, hhctrl_hinstance, NULL);
1140 ERR("Could not create popup ListView control\n");
1143 memset(&lvc, 0, sizeof(lvc));
1144 lvc.mask = LVCF_TEXT;
1145 lvc.pszText = hidden_column;
1146 if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
1148 ERR("Could not create popup ListView column\n");
1152 info->popup.hwndCallback = hwndCallback;
1153 info->popup.hwndPopup = hwndPopup;
1154 info->popup.hwndList = hwndList;
1155 SetWindowLongPtrW(hwndPopup, GWLP_USERDATA, (LONG_PTR)info);
1156 SetWindowLongPtrW(hwndCallback, GWLP_USERDATA, (LONG_PTR)info);
1158 ResizePopupChild(info);
1159 ShowWindow(hwndList, SW_SHOW);
1166 static LRESULT Help_OnSize(HWND hWnd)
1168 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1175 NP_GetNavigationRect(pHHInfo, &rc);
1176 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
1177 rc.right, rc.bottom, SWP_NOMOVE);
1179 SB_GetSizeBarRect(pHHInfo, &rc);
1180 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
1181 rc.right, rc.bottom, SWP_SHOWWINDOW);
1183 HP_GetHTMLRect(pHHInfo, &rc);
1184 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
1185 rc.right, rc.bottom, SWP_SHOWWINDOW);
1187 /* Resize browser window taking the frame size into account */
1188 dwSize = GetSystemMetrics(SM_CXFRAME);
1189 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
1194 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1199 if (HIWORD(wParam) == BN_CLICKED)
1200 TB_OnClick(hWnd, LOWORD(wParam));
1203 return Help_OnSize(hWnd);
1205 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
1213 return DefWindowProcW(hWnd, message, wParam, lParam);
1219 static BOOL HH_CreateHelpWindow(HHInfo *info)
1222 RECT winPos = info->WinType.rcWindowPos;
1224 DWORD dwStyles, dwExStyles;
1225 DWORD x, y, width, height;
1227 static const WCHAR windowClassW[] = {
1228 'H','H',' ', 'P','a','r','e','n','t',0
1231 wcex.cbSize = sizeof(WNDCLASSEXW);
1232 wcex.style = CS_HREDRAW | CS_VREDRAW;
1233 wcex.lpfnWndProc = Help_WndProc;
1234 wcex.cbClsExtra = 0;
1235 wcex.cbWndExtra = 0;
1236 wcex.hInstance = hhctrl_hinstance;
1237 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1238 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1239 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1240 wcex.lpszMenuName = NULL;
1241 wcex.lpszClassName = windowClassW;
1242 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1244 RegisterClassExW(&wcex);
1246 /* Read in window parameters if available */
1247 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
1248 dwStyles = info->WinType.dwStyles | WS_OVERLAPPEDWINDOW;
1250 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
1251 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1253 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
1254 dwExStyles = info->WinType.dwExStyles;
1256 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
1257 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
1259 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
1263 width = winPos.right - x;
1264 height = winPos.bottom - y;
1268 x = WINTYPE_DEFAULT_X;
1269 y = WINTYPE_DEFAULT_Y;
1270 width = WINTYPE_DEFAULT_WIDTH;
1271 height = WINTYPE_DEFAULT_HEIGHT;
1274 hWnd = CreateWindowExW(dwExStyles, windowClassW, info->WinType.pszCaption,
1275 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
1279 ShowWindow(hWnd, SW_SHOW);
1282 /* store the pointer to the HH info struct */
1283 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
1285 info->WinType.hwndHelp = hWnd;
1289 static void HH_CreateFont(HHInfo *pHHInfo)
1293 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
1294 lf.lfWeight = FW_NORMAL;
1295 lf.lfItalic = FALSE;
1296 lf.lfUnderline = FALSE;
1298 pHHInfo->hFont = CreateFontIndirectW(&lf);
1301 static void HH_InitRequiredControls(DWORD dwControls)
1303 INITCOMMONCONTROLSEX icex;
1305 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1306 icex.dwICC = dwControls;
1307 InitCommonControlsEx(&icex);
1310 /* Creates the whole package */
1311 static BOOL CreateViewer(HHInfo *pHHInfo)
1313 HH_CreateFont(pHHInfo);
1315 if (!HH_CreateHelpWindow(pHHInfo))
1318 HH_InitRequiredControls(ICC_BAR_CLASSES);
1320 if (!HH_AddToolbar(pHHInfo))
1323 HH_RegisterChildWndClass(pHHInfo);
1325 if (!HH_AddNavigationPane(pHHInfo))
1328 HH_RegisterSizeBarClass(pHHInfo);
1330 if (!HH_AddSizeBar(pHHInfo))
1333 if (!HH_AddHTMLPane(pHHInfo))
1336 if (!AddContentTab(pHHInfo))
1339 if (!AddIndexTab(pHHInfo))
1342 if (!AddIndexPopup(pHHInfo))
1345 if (!AddSearchTab(pHHInfo))
1348 InitContent(pHHInfo);
1354 void ReleaseHelpViewer(HHInfo *info)
1356 TRACE("(%p)\n", info);
1361 /* Free allocated strings */
1362 heap_free(info->pszType);
1363 heap_free(info->pszCaption);
1364 heap_free(info->pszToc);
1365 heap_free(info->pszIndex);
1366 heap_free(info->pszFile);
1367 heap_free(info->pszHome);
1368 heap_free(info->pszJump1);
1369 heap_free(info->pszJump2);
1370 heap_free(info->pszUrlJump1);
1371 heap_free(info->pszUrlJump2);
1374 CloseCHM(info->pCHMInfo);
1376 ReleaseWebBrowser(info);
1377 ReleaseContent(info);
1380 if(info->WinType.hwndHelp)
1381 DestroyWindow(info->WinType.hwndHelp);
1387 HHInfo *CreateHelpViewer(LPCWSTR filename)
1389 HHInfo *info = heap_alloc_zero(sizeof(HHInfo));
1392 /* Set the invalid tab ID (-1) as the default value for all
1393 * of the tabs, this matches a failed TCM_INSERTITEM call.
1395 for(i=0;i<sizeof(info->tabs)/sizeof(HHTab);i++)
1396 info->tabs[i].id = -1;
1398 OleInitialize(NULL);
1400 info->pCHMInfo = OpenCHM(filename);
1401 if(!info->pCHMInfo) {
1402 ReleaseHelpViewer(info);
1406 if (!LoadWinTypeFromCHM(info)) {
1407 ReleaseHelpViewer(info);
1411 if(!CreateViewer(info)) {
1412 ReleaseHelpViewer(info);