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
48 static const WCHAR szEmpty[] = {0};
50 /* Loads a string from the resource file */
51 static LPWSTR HH_LoadString(DWORD dwID)
54 LPCWSTR stringresource;
57 iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0);
59 string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */
60 memcpy(string, stringresource, iSize*sizeof(WCHAR));
66 static HRESULT navigate_url(HHInfo *info, LPCWSTR surl)
71 TRACE("%s\n", debugstr_w(surl));
74 V_BSTR(&url) = SysAllocString(surl);
76 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
81 TRACE("Navigation failed: %08x\n", hres);
86 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
92 static const WCHAR url_indicator[] = {':', '/', '/', 0};
94 TRACE("%s\n", debugstr_w(surl));
96 if (strstrW(surl, url_indicator)) {
97 hres = navigate_url(info, surl);
100 } /* look up in chm if it doesn't look like a full url */
102 SetChmPath(&chm_path, info->pCHMInfo->szFile, surl);
103 ret = NavigateToChm(info, chm_path.chm_file, chm_path.chm_index);
105 heap_free(chm_path.chm_file);
106 heap_free(chm_path.chm_index);
111 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
113 WCHAR buf[INTERNET_MAX_URL_LENGTH];
114 WCHAR full_path[MAX_PATH];
117 static const WCHAR url_format[] =
118 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
119 static const WCHAR slash[] = {'/',0};
120 static const WCHAR empty[] = {0};
122 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
124 if (!info->web_browser)
127 if(!GetFullPathNameW(file, sizeof(full_path)/sizeof(full_path[0]), full_path, NULL)) {
128 WARN("GetFullPathName failed: %u\n", GetLastError());
132 wsprintfW(buf, url_format, full_path, (!index || index[0] == '/') ? empty : slash, index);
135 if((ptr = strchrW(buf, '#')))
138 return SUCCEEDED(navigate_url(info, buf));
143 #define SIZEBAR_WIDTH 4
145 static const WCHAR szSizeBarClass[] = {
146 'H','H',' ','S','i','z','e','B','a','r',0
149 /* Draw the SizeBar */
150 static void SB_OnPaint(HWND hWnd)
156 hdc = BeginPaint(hWnd, &ps);
158 GetClientRect(hWnd, &rc);
163 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
165 /* white highlight */
166 SelectObject(hdc, GetStockObject(WHITE_PEN));
167 MoveToEx(hdc, rc.right, 1, NULL);
169 LineTo(hdc, 1, rc.bottom - 1);
172 MoveToEx(hdc, 0, rc.bottom, NULL);
173 LineTo(hdc, rc.right, rc.bottom);
178 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
183 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
185 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
188 pt.x = (short)LOWORD(lParam);
189 pt.y = (short)HIWORD(lParam);
191 /* update the window sizes */
192 pHHInfo->WinType.iNavWidth += pt.x;
198 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
200 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
201 if (!(wParam & MK_LBUTTON))
205 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
210 SB_OnLButtonDown(hWnd, wParam, lParam);
213 SB_OnLButtonUp(hWnd, wParam, lParam);
216 SB_OnMouseMove(hWnd, wParam, lParam);
222 return DefWindowProcW(hWnd, message, wParam, lParam);
228 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
232 wcex.cbSize = sizeof(WNDCLASSEXW);
234 wcex.lpfnWndProc = SizeBar_WndProc;
237 wcex.hInstance = hhctrl_hinstance;
238 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
239 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
240 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
241 wcex.lpszMenuName = NULL;
242 wcex.lpszClassName = szSizeBarClass;
243 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
245 RegisterClassExW(&wcex);
248 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
250 RECT rectWND, rectTB, rectNP;
252 GetClientRect(info->WinType.hwndHelp, &rectWND);
253 GetClientRect(info->WinType.hwndToolBar, &rectTB);
254 GetClientRect(info->WinType.hwndNavigation, &rectNP);
256 rc->left = rectNP.right;
257 rc->top = rectTB.bottom;
258 rc->bottom = rectWND.bottom - rectTB.bottom;
259 rc->right = SIZEBAR_WIDTH;
262 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
265 HWND hwndParent = pHHInfo->WinType.hwndHelp;
266 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
267 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
270 SB_GetSizeBarRect(pHHInfo, &rc);
272 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
273 rc.left, rc.top, rc.right, rc.bottom,
274 hwndParent, NULL, hhctrl_hinstance, NULL);
278 /* store the pointer to the HH info struct */
279 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
281 pHHInfo->hwndSizeBar = hWnd;
287 static const WCHAR szChildClass[] = {
288 'H','H',' ','C','h','i','l','d',0
291 static LRESULT Child_OnPaint(HWND hWnd)
297 hdc = BeginPaint(hWnd, &ps);
299 /* Only paint the Navigation pane, identified by the fact
300 * that it has a child window
302 if (GetWindow(hWnd, GW_CHILD))
304 GetClientRect(hWnd, &rc);
306 /* set the border color */
307 SelectObject(hdc, GetStockObject(DC_PEN));
308 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
310 /* Draw the top border */
311 LineTo(hdc, rc.right, 0);
313 SelectObject(hdc, GetStockObject(WHITE_PEN));
314 MoveToEx(hdc, 0, 1, NULL);
315 LineTo(hdc, rc.right, 1);
323 static void ResizeTabChild(HHInfo *info, int tab)
325 HWND hwnd = info->tabs[tab].hwnd;
330 GetClientRect(info->WinType.hwndNavigation, &rect);
331 SendMessageW(info->hwndTabCtrl, TCM_GETITEMRECT, 0, (LPARAM)&tabrc);
332 cnt = SendMessageW(info->hwndTabCtrl, TCM_GETROWCOUNT, 0, 0);
334 rect.left = TAB_MARGIN;
335 rect.top = TAB_TOP_PADDING + cnt*(tabrc.bottom-tabrc.top) + TAB_MARGIN;
336 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
337 rect.bottom -= TAB_MARGIN;
338 width = rect.right-rect.left;
339 height = rect.bottom-rect.top;
341 SetWindowPos(hwnd, NULL, rect.left, rect.top, width, height,
342 SWP_NOZORDER | SWP_NOACTIVATE);
344 /* Resize the tab widget column to perfectly fit the tab window and
345 * leave sufficient space for the scroll widget.
350 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
351 int border_width = GetSystemMetrics(SM_CXBORDER);
352 int edge_width = GetSystemMetrics(SM_CXEDGE);
354 SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_SETCOLUMNWIDTH, 0,
355 width-scroll_width-2*border_width-2*edge_width);
362 static LRESULT Child_OnSize(HWND hwnd)
364 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
367 if(!info || hwnd != info->WinType.hwndNavigation)
370 GetClientRect(hwnd, &rect);
371 SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0,
372 rect.right - TAB_RIGHT_PADDING,
373 rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
375 ResizeTabChild(info, TAB_CONTENTS);
376 ResizeTabChild(info, TAB_INDEX);
380 static LRESULT OnTabChange(HWND hwnd)
382 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
389 if(info->tabs[info->current_tab].hwnd)
390 ShowWindow(info->tabs[info->current_tab].hwnd, SW_HIDE);
392 info->current_tab = SendMessageW(info->hwndTabCtrl, TCM_GETCURSEL, 0, 0);
394 if(info->tabs[info->current_tab].hwnd)
395 ShowWindow(info->tabs[info->current_tab].hwnd, SW_SHOW);
400 static LRESULT OnTopicChange(HWND hwnd, void *user_data)
402 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
403 LPCWSTR chmfile = NULL, name = NULL, local = NULL;
407 if(!user_data || !info)
410 switch (info->current_tab)
413 citer = (ContentItem *) user_data;
415 local = citer->local;
417 if(citer->merge.chm_file) {
418 chmfile = citer->merge.chm_file;
421 citer = citer->parent;
423 chmfile = citer->merge.chm_file;
426 iiter = (IndexItem *) user_data;
427 if(iiter->nItems == 0) {
428 FIXME("No entries for this item!\n");
431 if(iiter->nItems > 1) {
432 FIXME("Support for sub-topics not implemented.\n");
435 name = iiter->items[0].name;
436 local = iiter->items[0].local;
437 chmfile = iiter->merge.chm_file;
440 FIXME("Unhandled operation for this tab!\n");
444 TRACE("name %s loal %s\n", debugstr_w(name), debugstr_w(local));
446 NavigateToChm(info, chmfile, local);
450 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
455 return Child_OnPaint(hWnd);
457 return Child_OnSize(hWnd);
459 NMHDR *nmhdr = (NMHDR*)lParam;
460 switch(nmhdr->code) {
462 return OnTabChange(hWnd);
463 case TVN_SELCHANGEDW:
464 return OnTopicChange(hWnd, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam);
466 return OnTopicChange(hWnd, (void*)((NMITEMACTIVATE *)lParam)->lParam);
471 return DefWindowProcW(hWnd, message, wParam, lParam);
477 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
481 wcex.cbSize = sizeof(WNDCLASSEXW);
483 wcex.lpfnWndProc = Child_WndProc;
486 wcex.hInstance = hhctrl_hinstance;
487 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
488 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
489 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
490 wcex.lpszMenuName = NULL;
491 wcex.lpszClassName = szChildClass;
492 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
494 RegisterClassExW(&wcex);
501 static void TB_OnClick(HWND hWnd, DWORD dwID)
503 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
508 DoPageAction(info, WB_STOP);
511 DoPageAction(info, WB_REFRESH);
514 DoPageAction(info, WB_GOBACK);
517 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
520 DoPageAction(info, WB_GOFORWARD);
527 case IDTB_BROWSE_FWD:
528 case IDTB_BROWSE_BACK:
539 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
541 /* FIXME: Load the correct button bitmaps */
542 pButtons[dwIndex].iBitmap = STD_PRINT;
543 pButtons[dwIndex].idCommand = dwID;
544 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
545 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
546 pButtons[dwIndex].dwData = 0;
547 pButtons[dwIndex].iString = 0;
550 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
554 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
555 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
557 if (dwButtonFlags & HHWIN_BUTTON_BACK)
558 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
560 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
561 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
563 if (dwButtonFlags & HHWIN_BUTTON_STOP)
564 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
566 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
567 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
569 if (dwButtonFlags & HHWIN_BUTTON_HOME)
570 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
572 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
573 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
575 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
576 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
578 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
579 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
581 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
582 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
584 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
585 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
587 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
588 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
590 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
591 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
593 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
594 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
597 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
600 HWND hwndParent = pHHInfo->WinType.hwndHelp;
602 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
604 DWORD dwStyles, dwExStyles;
605 DWORD dwNumButtons, dwIndex;
607 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
608 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
610 toolbarFlags = HHWIN_DEF_BUTTONS;
612 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
614 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
615 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
616 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
618 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
619 0, 0, 0, 0, hwndParent, NULL,
620 hhctrl_hinstance, NULL);
624 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
625 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
626 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
628 /* FIXME: Load correct icons for all buttons */
629 tbAB.hInst = HINST_COMMCTRL;
630 tbAB.nID = IDB_STD_LARGE_COLOR;
631 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
633 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
635 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
636 DWORD dwLen = strlenW(szBuf);
637 szBuf[dwLen + 1] = 0; /* Double-null terminate */
639 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
643 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)buttons);
644 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
645 ShowWindow(hToolbar, SW_SHOW);
647 pHHInfo->WinType.hwndToolBar = hToolbar;
651 /* Navigation Pane */
653 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
655 HWND hwndParent = pHHInfo->WinType.hwndHelp;
656 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
657 RECT rectWND, rectTB;
659 GetClientRect(hwndParent, &rectWND);
660 GetClientRect(hwndToolbar, &rectTB);
663 rc->top = rectTB.bottom;
664 rc->bottom = rectWND.bottom - rectTB.bottom;
666 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
667 pHHInfo->WinType.iNavWidth == 0)
669 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
672 rc->right = pHHInfo->WinType.iNavWidth;
675 static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index)
678 LPWSTR tabText = HH_LoadString(index);
681 tie.mask = TCIF_TEXT;
682 tie.pszText = tabText;
684 ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie );
690 static BOOL HH_AddNavigationPane(HHInfo *info)
692 HWND hWnd, hwndTabCtrl;
693 HWND hwndParent = info->WinType.hwndHelp;
694 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
695 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
698 NP_GetNavigationRect(info, &rc);
700 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
701 rc.left, rc.top, rc.right, rc.bottom,
702 hwndParent, NULL, hhctrl_hinstance, NULL);
706 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
708 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
710 rc.right - TAB_RIGHT_PADDING,
711 rc.bottom - TAB_TOP_PADDING,
712 hWnd, NULL, hhctrl_hinstance, NULL);
716 if (*info->WinType.pszToc)
717 info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS);
719 if (*info->WinType.pszIndex)
720 info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX);
722 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
723 info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH);
725 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
726 info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES);
728 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
730 info->hwndTabCtrl = hwndTabCtrl;
731 info->WinType.hwndNavigation = hWnd;
737 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
739 RECT rectTB, rectWND, rectNP, rectSB;
741 GetClientRect(info->WinType.hwndHelp, &rectWND);
742 GetClientRect(info->WinType.hwndToolBar, &rectTB);
743 GetClientRect(info->WinType.hwndNavigation, &rectNP);
744 GetClientRect(info->hwndSizeBar, &rectSB);
746 rc->left = rectNP.right + rectSB.right;
747 rc->top = rectTB.bottom;
748 rc->right = rectWND.right - rc->left;
749 rc->bottom = rectWND.bottom - rectTB.bottom;
752 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
755 HWND hwndParent = pHHInfo->WinType.hwndHelp;
756 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
757 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
760 HP_GetHTMLRect(pHHInfo, &rc);
762 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
763 rc.left, rc.top, rc.right, rc.bottom,
764 hwndParent, NULL, hhctrl_hinstance, NULL);
768 if (!InitWebBrowser(pHHInfo, hWnd))
771 /* store the pointer to the HH info struct */
772 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
774 ShowWindow(hWnd, SW_SHOW);
777 pHHInfo->WinType.hwndHTML = hWnd;
781 static BOOL AddContentTab(HHInfo *info)
783 if(info->tabs[TAB_CONTENTS].id == -1)
784 return TRUE; /* No "Contents" tab */
785 info->tabs[TAB_CONTENTS].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW,
786 szEmpty, WS_CHILD | WS_BORDER | 0x25, 50, 50, 100, 100,
787 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
788 if(!info->tabs[TAB_CONTENTS].hwnd) {
789 ERR("Could not create treeview control\n");
793 ResizeTabChild(info, TAB_CONTENTS);
794 ShowWindow(info->tabs[TAB_CONTENTS].hwnd, SW_SHOW);
799 static BOOL AddIndexTab(HHInfo *info)
801 char hidden_column[] = "Column";
804 if(info->tabs[TAB_INDEX].id == -1)
805 return TRUE; /* No "Index" tab */
806 info->tabs[TAB_INDEX].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW,
807 szEmpty, WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
808 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
809 if(!info->tabs[TAB_INDEX].hwnd) {
810 ERR("Could not create ListView control\n");
813 memset(&lvc, 0, sizeof(lvc));
814 lvc.mask = LVCF_TEXT;
815 lvc.pszText = hidden_column;
816 if(SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
818 ERR("Could not create ListView column\n");
822 ResizeTabChild(info, TAB_INDEX);
823 ShowWindow(info->tabs[TAB_INDEX].hwnd, SW_HIDE);
830 static LRESULT Help_OnSize(HWND hWnd)
832 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
839 NP_GetNavigationRect(pHHInfo, &rc);
840 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
841 rc.right, rc.bottom, SWP_NOMOVE);
843 SB_GetSizeBarRect(pHHInfo, &rc);
844 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
845 rc.right, rc.bottom, SWP_SHOWWINDOW);
847 HP_GetHTMLRect(pHHInfo, &rc);
848 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
849 rc.right, rc.bottom, SWP_SHOWWINDOW);
851 /* Resize browser window taking the frame size into account */
852 dwSize = GetSystemMetrics(SM_CXFRAME);
853 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
858 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
863 if (HIWORD(wParam) == BN_CLICKED)
864 TB_OnClick(hWnd, LOWORD(wParam));
867 return Help_OnSize(hWnd);
869 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
877 return DefWindowProcW(hWnd, message, wParam, lParam);
883 static BOOL HH_CreateHelpWindow(HHInfo *info)
886 RECT winPos = info->WinType.rcWindowPos;
888 DWORD dwStyles, dwExStyles;
889 DWORD x, y, width, height;
891 static const WCHAR windowClassW[] = {
892 'H','H',' ', 'P','a','r','e','n','t',0
895 wcex.cbSize = sizeof(WNDCLASSEXW);
896 wcex.style = CS_HREDRAW | CS_VREDRAW;
897 wcex.lpfnWndProc = Help_WndProc;
900 wcex.hInstance = hhctrl_hinstance;
901 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
902 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
903 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
904 wcex.lpszMenuName = NULL;
905 wcex.lpszClassName = windowClassW;
906 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
908 RegisterClassExW(&wcex);
910 /* Read in window parameters if available */
911 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
912 dwStyles = info->WinType.dwStyles | WS_OVERLAPPEDWINDOW;
914 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
915 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
917 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
918 dwExStyles = info->WinType.dwExStyles;
920 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
921 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
923 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
927 width = winPos.right - x;
928 height = winPos.bottom - y;
932 x = WINTYPE_DEFAULT_X;
933 y = WINTYPE_DEFAULT_Y;
934 width = WINTYPE_DEFAULT_WIDTH;
935 height = WINTYPE_DEFAULT_HEIGHT;
938 hWnd = CreateWindowExW(dwExStyles, windowClassW, info->WinType.pszCaption,
939 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
943 ShowWindow(hWnd, SW_SHOW);
946 /* store the pointer to the HH info struct */
947 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
949 info->WinType.hwndHelp = hWnd;
953 static void HH_CreateFont(HHInfo *pHHInfo)
957 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
958 lf.lfWeight = FW_NORMAL;
960 lf.lfUnderline = FALSE;
962 pHHInfo->hFont = CreateFontIndirectW(&lf);
965 static void HH_InitRequiredControls(DWORD dwControls)
967 INITCOMMONCONTROLSEX icex;
969 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
970 icex.dwICC = dwControls;
971 InitCommonControlsEx(&icex);
974 /* Creates the whole package */
975 static BOOL CreateViewer(HHInfo *pHHInfo)
977 HH_CreateFont(pHHInfo);
979 if (!HH_CreateHelpWindow(pHHInfo))
982 HH_InitRequiredControls(ICC_BAR_CLASSES);
984 if (!HH_AddToolbar(pHHInfo))
987 HH_RegisterChildWndClass(pHHInfo);
989 if (!HH_AddNavigationPane(pHHInfo))
992 HH_RegisterSizeBarClass(pHHInfo);
994 if (!HH_AddSizeBar(pHHInfo))
997 if (!HH_AddHTMLPane(pHHInfo))
1000 if (!AddContentTab(pHHInfo))
1003 if (!AddIndexTab(pHHInfo))
1006 InitContent(pHHInfo);
1012 void ReleaseHelpViewer(HHInfo *info)
1014 TRACE("(%p)\n", info);
1019 /* Free allocated strings */
1020 heap_free(info->pszType);
1021 heap_free(info->pszCaption);
1022 heap_free(info->pszToc);
1023 heap_free(info->pszIndex);
1024 heap_free(info->pszFile);
1025 heap_free(info->pszHome);
1026 heap_free(info->pszJump1);
1027 heap_free(info->pszJump2);
1028 heap_free(info->pszUrlJump1);
1029 heap_free(info->pszUrlJump2);
1032 CloseCHM(info->pCHMInfo);
1034 ReleaseWebBrowser(info);
1035 ReleaseContent(info);
1038 if(info->WinType.hwndHelp)
1039 DestroyWindow(info->WinType.hwndHelp);
1045 HHInfo *CreateHelpViewer(LPCWSTR filename)
1047 HHInfo *info = heap_alloc_zero(sizeof(HHInfo));
1050 /* Set the invalid tab ID (-1) as the default value for all
1051 * of the tabs, this matches a failed TCM_INSERTITEM call.
1053 for(i=0;i<sizeof(info->tabs)/sizeof(HHTab);i++)
1054 info->tabs[i].id = -1;
1056 OleInitialize(NULL);
1058 info->pCHMInfo = OpenCHM(filename);
1059 if(!info->pCHMInfo) {
1060 ReleaseHelpViewer(info);
1064 if (!LoadWinTypeFromCHM(info)) {
1065 ReleaseHelpViewer(info);
1069 if(!CreateViewer(info)) {
1070 ReleaseHelpViewer(info);