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 /* Loads a string from the resource file */
54 static LPWSTR HH_LoadString(DWORD dwID)
57 LPCWSTR stringresource;
60 iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0);
62 string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */
63 memcpy(string, stringresource, iSize*sizeof(WCHAR));
69 static HRESULT navigate_url(HHInfo *info, LPCWSTR surl)
74 TRACE("%s\n", debugstr_w(surl));
77 V_BSTR(&url) = SysAllocString(surl);
79 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
84 TRACE("Navigation failed: %08x\n", hres);
89 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
95 static const WCHAR url_indicator[] = {':', '/', '/', 0};
97 TRACE("%s\n", debugstr_w(surl));
99 if (strstrW(surl, url_indicator)) {
100 hres = navigate_url(info, surl);
103 } /* look up in chm if it doesn't look like a full url */
105 SetChmPath(&chm_path, info->pCHMInfo->szFile, surl);
106 ret = NavigateToChm(info, chm_path.chm_file, chm_path.chm_index);
108 heap_free(chm_path.chm_file);
109 heap_free(chm_path.chm_index);
114 BOOL AppendFullPathURL(LPCWSTR file, LPWSTR buf, LPCWSTR index)
116 static const WCHAR url_format[] =
117 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
118 static const WCHAR slash[] = {'/',0};
119 static const WCHAR empty[] = {0};
120 WCHAR full_path[MAX_PATH];
122 TRACE("%s %p %s\n", debugstr_w(file), buf, debugstr_w(index));
124 if(!GetFullPathNameW(file, sizeof(full_path)/sizeof(full_path[0]), full_path, NULL)) {
125 WARN("GetFullPathName failed: %u\n", GetLastError());
129 wsprintfW(buf, url_format, full_path, (!index || index[0] == '/') ? empty : slash, index);
133 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
135 WCHAR buf[INTERNET_MAX_URL_LENGTH];
138 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
140 if ((!info->web_browser) || !AppendFullPathURL(file, buf, index))
144 if((ptr = strchrW(buf, '#')))
147 return SUCCEEDED(navigate_url(info, buf));
150 static void DoSync(HHInfo *info)
152 WCHAR buf[INTERNET_MAX_URL_LENGTH];
157 hres = IWebBrowser2_get_LocationURL(info->web_browser, &url);
161 WARN("get_LocationURL failed: %08x\n", hres);
165 /* If we're not currently viewing a page in the active .chm file, abort */
166 if ((!AppendFullPathURL(info->pszFile, buf, NULL)) || (len = lstrlenW(buf) > lstrlenW(url)))
172 if (lstrcmpiW(buf, url) > 0)
174 static const WCHAR delimW[] = {':',':','/',0};
177 index = strstrW(url, delimW);
180 ActivateContentTopic(info->tabs[TAB_CONTENTS].hwnd, index + 3, info->content); /* skip over ::/ */
188 #define SIZEBAR_WIDTH 4
190 static const WCHAR szSizeBarClass[] = {
191 'H','H',' ','S','i','z','e','B','a','r',0
194 /* Draw the SizeBar */
195 static void SB_OnPaint(HWND hWnd)
201 hdc = BeginPaint(hWnd, &ps);
203 GetClientRect(hWnd, &rc);
208 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
210 /* white highlight */
211 SelectObject(hdc, GetStockObject(WHITE_PEN));
212 MoveToEx(hdc, rc.right, 1, NULL);
214 LineTo(hdc, 1, rc.bottom - 1);
217 MoveToEx(hdc, 0, rc.bottom, NULL);
218 LineTo(hdc, rc.right, rc.bottom);
223 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
228 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
230 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
233 pt.x = (short)LOWORD(lParam);
234 pt.y = (short)HIWORD(lParam);
236 /* update the window sizes */
237 pHHInfo->WinType.iNavWidth += pt.x;
243 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
245 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
246 if (!(wParam & MK_LBUTTON))
250 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
255 SB_OnLButtonDown(hWnd, wParam, lParam);
258 SB_OnLButtonUp(hWnd, wParam, lParam);
261 SB_OnMouseMove(hWnd, wParam, lParam);
267 return DefWindowProcW(hWnd, message, wParam, lParam);
273 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
277 wcex.cbSize = sizeof(WNDCLASSEXW);
279 wcex.lpfnWndProc = SizeBar_WndProc;
282 wcex.hInstance = hhctrl_hinstance;
283 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
284 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
285 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
286 wcex.lpszMenuName = NULL;
287 wcex.lpszClassName = szSizeBarClass;
288 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
290 RegisterClassExW(&wcex);
293 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
295 RECT rectWND, rectTB, rectNP;
297 GetClientRect(info->WinType.hwndHelp, &rectWND);
298 GetClientRect(info->WinType.hwndToolBar, &rectTB);
299 GetClientRect(info->WinType.hwndNavigation, &rectNP);
301 rc->left = rectNP.right;
302 rc->top = rectTB.bottom;
303 rc->bottom = rectWND.bottom - rectTB.bottom;
304 rc->right = SIZEBAR_WIDTH;
307 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
310 HWND hwndParent = pHHInfo->WinType.hwndHelp;
311 DWORD dwStyles = WS_CHILDWINDOW | WS_OVERLAPPED;
312 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
315 if (!pHHInfo->WinType.fNotExpanded)
316 dwStyles |= WS_VISIBLE;
318 SB_GetSizeBarRect(pHHInfo, &rc);
320 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
321 rc.left, rc.top, rc.right, rc.bottom,
322 hwndParent, NULL, hhctrl_hinstance, NULL);
326 /* store the pointer to the HH info struct */
327 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
329 pHHInfo->hwndSizeBar = hWnd;
335 static const WCHAR szChildClass[] = {
336 'H','H',' ','C','h','i','l','d',0
339 static LRESULT Child_OnPaint(HWND hWnd)
345 hdc = BeginPaint(hWnd, &ps);
347 /* Only paint the Navigation pane, identified by the fact
348 * that it has a child window
350 if (GetWindow(hWnd, GW_CHILD))
352 GetClientRect(hWnd, &rc);
354 /* set the border color */
355 SelectObject(hdc, GetStockObject(DC_PEN));
356 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
358 /* Draw the top border */
359 LineTo(hdc, rc.right, 0);
361 SelectObject(hdc, GetStockObject(WHITE_PEN));
362 MoveToEx(hdc, 0, 1, NULL);
363 LineTo(hdc, rc.right, 1);
371 static void ResizeTabChild(HHInfo *info, int tab)
373 HWND hwnd = info->tabs[tab].hwnd;
378 GetClientRect(info->WinType.hwndNavigation, &rect);
379 SendMessageW(info->hwndTabCtrl, TCM_GETITEMRECT, 0, (LPARAM)&tabrc);
380 cnt = SendMessageW(info->hwndTabCtrl, TCM_GETROWCOUNT, 0, 0);
382 rect.left = TAB_MARGIN;
383 rect.top = TAB_TOP_PADDING + cnt*(tabrc.bottom-tabrc.top) + TAB_MARGIN;
384 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
385 rect.bottom -= TAB_MARGIN;
386 width = rect.right-rect.left;
387 height = rect.bottom-rect.top;
389 SetWindowPos(hwnd, NULL, rect.left, rect.top, width, height,
390 SWP_NOZORDER | SWP_NOACTIVATE);
395 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
396 int border_width = GetSystemMetrics(SM_CXBORDER);
397 int edge_width = GetSystemMetrics(SM_CXEDGE);
399 /* Resize the tab widget column to perfectly fit the tab window and
400 * leave sufficient space for the scroll widget.
402 SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_SETCOLUMNWIDTH, 0,
403 width-scroll_width-2*border_width-2*edge_width);
408 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
409 int border_width = GetSystemMetrics(SM_CXBORDER);
410 int edge_width = GetSystemMetrics(SM_CXEDGE);
413 SetWindowPos(info->search.hwndEdit, NULL, 0, top_pos, width,
414 EDIT_HEIGHT, SWP_NOZORDER | SWP_NOACTIVATE);
415 top_pos += EDIT_HEIGHT + TAB_MARGIN;
416 SetWindowPos(info->search.hwndList, NULL, 0, top_pos, width,
417 height-top_pos, SWP_NOZORDER | SWP_NOACTIVATE);
418 /* Resize the tab widget column to perfectly fit the tab window and
419 * leave sufficient space for the scroll widget.
421 SendMessageW(info->search.hwndList, LVM_SETCOLUMNWIDTH, 0,
422 width-scroll_width-2*border_width-2*edge_width);
429 static LRESULT Child_OnSize(HWND hwnd)
431 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
434 if(!info || hwnd != info->WinType.hwndNavigation)
437 GetClientRect(hwnd, &rect);
438 SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0,
439 rect.right - TAB_RIGHT_PADDING,
440 rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
442 ResizeTabChild(info, TAB_CONTENTS);
443 ResizeTabChild(info, TAB_INDEX);
447 static LRESULT OnTabChange(HWND hwnd)
449 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
456 if(info->tabs[info->current_tab].hwnd)
457 ShowWindow(info->tabs[info->current_tab].hwnd, SW_HIDE);
459 info->current_tab = SendMessageW(info->hwndTabCtrl, TCM_GETCURSEL, 0, 0);
461 if(info->tabs[info->current_tab].hwnd)
462 ShowWindow(info->tabs[info->current_tab].hwnd, SW_SHOW);
467 static LRESULT OnTopicChange(HHInfo *info, void *user_data)
469 LPCWSTR chmfile = NULL, name = NULL, local = NULL;
474 if(!user_data || !info)
477 switch (info->current_tab)
480 citer = (ContentItem *) user_data;
482 local = citer->local;
484 if(citer->merge.chm_file) {
485 chmfile = citer->merge.chm_file;
488 citer = citer->parent;
492 iiter = (IndexItem *) user_data;
493 if(iiter->nItems == 0) {
494 FIXME("No entries for this item!\n");
497 if(iiter->nItems > 1) {
501 SendMessageW(info->popup.hwndList, LVM_DELETEALLITEMS, 0, 0);
502 for(i=0;i<iiter->nItems;i++) {
503 IndexSubItem *item = &iiter->items[i];
504 WCHAR *name = iiter->keyword;
508 memset(&lvi, 0, sizeof(lvi));
510 lvi.mask = LVIF_TEXT|LVIF_PARAM;
511 lvi.cchTextMax = strlenW(name)+1;
513 lvi.lParam = (LPARAM) item;
514 SendMessageW(info->popup.hwndList, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
516 ShowWindow(info->popup.hwndPopup, SW_SHOW);
519 name = iiter->items[0].name;
520 local = iiter->items[0].local;
521 chmfile = iiter->merge.chm_file;
524 siter = (SearchItem *) user_data;
525 name = siter->filename;
526 local = siter->filename;
527 chmfile = info->pCHMInfo->szFile;
530 FIXME("Unhandled operation for this tab!\n");
536 FIXME("No help file found for this item!\n");
540 TRACE("name %s loal %s\n", debugstr_w(name), debugstr_w(local));
542 NavigateToChm(info, chmfile, local);
546 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
547 static LRESULT CALLBACK EditChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
549 WNDPROC editWndProc = (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
551 if(message == WM_KEYUP && wParam == VK_RETURN)
555 nmhdr.hwndFrom = hWnd;
556 nmhdr.code = NM_RETURN;
557 SendMessageW(GetParent(GetParent(hWnd)), WM_NOTIFY, wParam, (LPARAM)&nmhdr);
559 return editWndProc(hWnd, message, wParam, lParam);
562 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
567 return Child_OnPaint(hWnd);
569 return Child_OnSize(hWnd);
571 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
572 NMHDR *nmhdr = (NMHDR*)lParam;
574 switch(nmhdr->code) {
576 return OnTabChange(hWnd);
577 case TVN_SELCHANGEDW:
578 return OnTopicChange(info, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam);
582 switch(info->current_tab)
585 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
587 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
593 switch(info->current_tab) {
595 HWND hwndList = info->tabs[TAB_INDEX].hwnd;
598 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
599 lvItem.mask = TVIF_PARAM;
600 SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
601 OnTopicChange(info, (void*) lvItem.lParam);
605 if(nmhdr->hwndFrom == info->search.hwndEdit) {
609 len = GetWindowTextA(info->search.hwndEdit, needle, sizeof(needle));
612 FIXME("Unable to get search text.\n");
615 /* Convert the requested text for comparison later against the
616 * lower case version of HTML file contents.
619 needle[i] = tolower(needle[i]);
620 InitSearch(info, needle);
622 }else if(nmhdr->hwndFrom == info->search.hwndList) {
623 HWND hwndList = info->search.hwndList;
626 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
627 lvItem.mask = TVIF_PARAM;
628 SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
629 OnTopicChange(info, (void*) lvItem.lParam);
640 return DefWindowProcW(hWnd, message, wParam, lParam);
646 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
650 wcex.cbSize = sizeof(WNDCLASSEXW);
652 wcex.lpfnWndProc = Child_WndProc;
655 wcex.hInstance = hhctrl_hinstance;
656 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
657 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
658 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
659 wcex.lpszMenuName = NULL;
660 wcex.lpszClassName = szChildClass;
661 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
663 RegisterClassExW(&wcex);
670 static void DisplayPopupMenu(HHInfo *info)
673 TBBUTTONINFOW button;
679 menu = LoadMenuW(hhctrl_hinstance, MAKEINTRESOURCEW(MENU_POPUP));
684 submenu = GetSubMenu(menu, 0);
686 /* Update the Show/Hide menu item */
687 item.cbSize = sizeof(MENUITEMINFOW);
688 item.fMask = MIIM_STRING;
690 if (info->WinType.fNotExpanded)
691 item.dwTypeData = HH_LoadString(IDS_SHOWTABS);
693 item.dwTypeData = HH_LoadString(IDS_HIDETABS);
695 SetMenuItemInfoW(submenu, IDTB_EXPAND, FALSE, &item);
696 heap_free(item.dwTypeData);
698 /* Find the index toolbar button */
699 button.cbSize = sizeof(TBBUTTONINFOW);
700 button.dwMask = TBIF_COMMAND;
701 index = SendMessageW(info->WinType.hwndToolBar, TB_GETBUTTONINFOW, IDTB_OPTIONS, (LPARAM) &button);
707 SendMessageW(info->WinType.hwndToolBar, TB_GETITEMRECT, index, (LPARAM) &rect);
709 coords.x = rect.left;
710 coords.y = rect.bottom;
712 ClientToScreen(info->WinType.hwndToolBar, &coords);
713 TrackPopupMenu(submenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_NOANIMATION, coords.x, coords.y, 0, info->WinType.hwndHelp, NULL);
716 static void TB_OnClick(HWND hWnd, DWORD dwID)
718 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
723 DoPageAction(info, WB_STOP);
726 DoPageAction(info, WB_REFRESH);
729 DoPageAction(info, WB_GOBACK);
732 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
735 DoPageAction(info, WB_GOFORWARD);
738 DoPageAction(info, WB_PRINT);
742 ExpandContract(info);
748 DisplayPopupMenu(info);
750 case IDTB_BROWSE_FWD:
751 case IDTB_BROWSE_BACK:
762 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
764 /* FIXME: Load the correct button bitmaps */
765 pButtons[dwIndex].iBitmap = STD_PRINT;
766 pButtons[dwIndex].idCommand = dwID;
767 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
768 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
769 pButtons[dwIndex].dwData = 0;
770 pButtons[dwIndex].iString = 0;
773 static void TB_AddButtonsFromFlags(HHInfo *pHHInfo, TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
777 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
779 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
780 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_CONTRACT);
782 if (pHHInfo->WinType.fNotExpanded)
783 pButtons[1].fsState |= TBSTATE_HIDDEN;
785 pButtons[0].fsState |= TBSTATE_HIDDEN;
788 if (dwButtonFlags & HHWIN_BUTTON_BACK)
789 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
791 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
792 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
794 if (dwButtonFlags & HHWIN_BUTTON_STOP)
795 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
797 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
798 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
800 if (dwButtonFlags & HHWIN_BUTTON_HOME)
801 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
803 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
804 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
806 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
807 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
809 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
810 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
812 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
813 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
815 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
816 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
818 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
819 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
821 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
822 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
824 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
825 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
828 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
831 HWND hwndParent = pHHInfo->WinType.hwndHelp;
833 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
835 DWORD dwStyles, dwExStyles;
836 DWORD dwNumButtons, dwIndex;
838 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
839 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
841 toolbarFlags = HHWIN_DEF_BUTTONS;
843 TB_AddButtonsFromFlags(pHHInfo, buttons, toolbarFlags, &dwNumButtons);
845 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
846 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
847 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
849 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
850 0, 0, 0, 0, hwndParent, NULL,
851 hhctrl_hinstance, NULL);
855 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
856 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
857 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
859 /* FIXME: Load correct icons for all buttons */
860 tbAB.hInst = HINST_COMMCTRL;
861 tbAB.nID = IDB_STD_LARGE_COLOR;
862 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
864 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
866 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
867 DWORD dwLen = strlenW(szBuf);
868 szBuf[dwLen + 1] = 0; /* Double-null terminate */
870 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
874 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)buttons);
875 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
876 ShowWindow(hToolbar, SW_SHOW);
878 pHHInfo->WinType.hwndToolBar = hToolbar;
882 /* Navigation Pane */
884 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
886 HWND hwndParent = pHHInfo->WinType.hwndHelp;
887 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
888 RECT rectWND, rectTB;
890 GetClientRect(hwndParent, &rectWND);
891 GetClientRect(hwndToolbar, &rectTB);
894 rc->top = rectTB.bottom;
895 rc->bottom = rectWND.bottom - rectTB.bottom;
897 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
898 pHHInfo->WinType.iNavWidth == 0)
900 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
903 rc->right = pHHInfo->WinType.iNavWidth;
906 static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index)
909 LPWSTR tabText = HH_LoadString(index);
912 tie.mask = TCIF_TEXT;
913 tie.pszText = tabText;
915 ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie );
921 static BOOL HH_AddNavigationPane(HHInfo *info)
923 HWND hWnd, hwndTabCtrl;
924 HWND hwndParent = info->WinType.hwndHelp;
925 DWORD dwStyles = WS_CHILDWINDOW;
926 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
929 if (!info->WinType.fNotExpanded)
930 dwStyles |= WS_VISIBLE;
932 NP_GetNavigationRect(info, &rc);
934 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
935 rc.left, rc.top, rc.right, rc.bottom,
936 hwndParent, NULL, hhctrl_hinstance, NULL);
940 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
942 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles | WS_VISIBLE,
944 rc.right - TAB_RIGHT_PADDING,
945 rc.bottom - TAB_TOP_PADDING,
946 hWnd, NULL, hhctrl_hinstance, NULL);
950 if (*info->WinType.pszToc)
951 info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS);
953 if (*info->WinType.pszIndex)
954 info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX);
956 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
957 info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH);
959 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
960 info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES);
962 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
964 info->hwndTabCtrl = hwndTabCtrl;
965 info->WinType.hwndNavigation = hWnd;
971 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
973 RECT rectTB, rectWND, rectNP, rectSB;
975 GetClientRect(info->WinType.hwndHelp, &rectWND);
976 GetClientRect(info->WinType.hwndToolBar, &rectTB);
977 GetClientRect(info->hwndSizeBar, &rectSB);
979 if (info->WinType.fNotExpanded)
983 GetClientRect(info->WinType.hwndNavigation, &rectNP);
984 rc->left = rectNP.right + rectSB.right;
987 rc->top = rectTB.bottom;
988 rc->right = rectWND.right - rc->left;
989 rc->bottom = rectWND.bottom - rectTB.bottom;
992 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
995 HWND hwndParent = pHHInfo->WinType.hwndHelp;
996 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
997 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
1000 HP_GetHTMLRect(pHHInfo, &rc);
1002 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
1003 rc.left, rc.top, rc.right, rc.bottom,
1004 hwndParent, NULL, hhctrl_hinstance, NULL);
1008 if (!InitWebBrowser(pHHInfo, hWnd))
1011 /* store the pointer to the HH info struct */
1012 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
1014 ShowWindow(hWnd, SW_SHOW);
1017 pHHInfo->WinType.hwndHTML = hWnd;
1021 static BOOL AddContentTab(HHInfo *info)
1023 if(info->tabs[TAB_CONTENTS].id == -1)
1024 return TRUE; /* No "Contents" tab */
1025 info->tabs[TAB_CONTENTS].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW,
1026 szEmpty, WS_CHILD | WS_BORDER | 0x25, 50, 50, 100, 100,
1027 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
1028 if(!info->tabs[TAB_CONTENTS].hwnd) {
1029 ERR("Could not create treeview control\n");
1033 ResizeTabChild(info, TAB_CONTENTS);
1034 ShowWindow(info->tabs[TAB_CONTENTS].hwnd, SW_SHOW);
1039 static BOOL AddIndexTab(HHInfo *info)
1041 char hidden_column[] = "Column";
1044 if(info->tabs[TAB_INDEX].id == -1)
1045 return TRUE; /* No "Index" tab */
1046 info->tabs[TAB_INDEX].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW,
1047 szEmpty, WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
1048 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
1049 if(!info->tabs[TAB_INDEX].hwnd) {
1050 ERR("Could not create ListView control\n");
1053 memset(&lvc, 0, sizeof(lvc));
1054 lvc.mask = LVCF_TEXT;
1055 lvc.pszText = hidden_column;
1056 if(SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
1058 ERR("Could not create ListView column\n");
1062 ResizeTabChild(info, TAB_INDEX);
1063 ShowWindow(info->tabs[TAB_INDEX].hwnd, SW_HIDE);
1068 static BOOL AddSearchTab(HHInfo *info)
1070 HWND hwndList, hwndEdit, hwndContainer;
1071 char hidden_column[] = "Column";
1072 WNDPROC editWndProc;
1075 if(info->tabs[TAB_SEARCH].id == -1)
1076 return TRUE; /* No "Search" tab */
1077 hwndContainer = CreateWindowExW(WS_EX_CONTROLPARENT, szChildClass, szEmpty,
1078 WS_CHILD, 0, 0, 0, 0, info->WinType.hwndNavigation,
1079 NULL, hhctrl_hinstance, NULL);
1080 if(!hwndContainer) {
1081 ERR("Could not create search window container control.\n");
1084 hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, szEmpty, WS_CHILD
1085 | WS_VISIBLE | ES_LEFT | SS_NOTIFY, 0, 0, 0, 0,
1086 hwndContainer, NULL, hhctrl_hinstance, NULL);
1088 ERR("Could not create search ListView control.\n");
1091 if(SendMessageW(hwndEdit, WM_SETFONT, (WPARAM) info->hFont, (LPARAM) FALSE) == -1)
1093 ERR("Could not set font for edit control.\n");
1096 editWndProc = (WNDPROC) SetWindowLongPtrW(hwndEdit, GWLP_WNDPROC, (LONG_PTR)EditChild_WndProc);
1098 ERR("Could not redirect messages for edit control.\n");
1101 SetWindowLongPtrW(hwndEdit, GWLP_USERDATA, (LONG_PTR)editWndProc);
1102 hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty,
1103 WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL
1104 | LVS_REPORT | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
1105 hwndContainer, NULL, hhctrl_hinstance, NULL);
1107 ERR("Could not create search ListView control.\n");
1110 memset(&lvc, 0, sizeof(lvc));
1111 lvc.mask = LVCF_TEXT;
1112 lvc.pszText = hidden_column;
1113 if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
1115 ERR("Could not create ListView column\n");
1119 info->search.hwndEdit = hwndEdit;
1120 info->search.hwndList = hwndList;
1121 info->search.hwndContainer = hwndContainer;
1122 info->tabs[TAB_SEARCH].hwnd = hwndContainer;
1124 SetWindowLongPtrW(hwndContainer, GWLP_USERDATA, (LONG_PTR)info);
1126 ResizeTabChild(info, TAB_SEARCH);
1131 /* The Index tab's sub-topic popup */
1133 static void ResizePopupChild(HHInfo *info)
1135 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
1136 int border_width = GetSystemMetrics(SM_CXBORDER);
1137 int edge_width = GetSystemMetrics(SM_CXEDGE);
1144 GetClientRect(info->popup.hwndPopup, &rect);
1145 SetWindowPos(info->popup.hwndCallback, HWND_TOP, 0, 0,
1146 rect.right, rect.bottom, SWP_NOMOVE);
1148 rect.left = TAB_MARGIN;
1149 rect.top = TAB_TOP_PADDING + TAB_MARGIN;
1150 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
1151 rect.bottom -= TAB_MARGIN;
1152 width = rect.right-rect.left;
1153 height = rect.bottom-rect.top;
1155 SetWindowPos(info->popup.hwndList, NULL, rect.left, rect.top, width, height,
1156 SWP_NOZORDER | SWP_NOACTIVATE);
1158 SendMessageW(info->popup.hwndList, LVM_SETCOLUMNWIDTH, 0,
1159 width-scroll_width-2*border_width-2*edge_width);
1162 static LRESULT CALLBACK HelpPopup_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1164 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1169 ResizePopupChild(info);
1172 DestroyWindow(hWnd);
1175 ShowWindow(hWnd, SW_HIDE);
1179 return DefWindowProcW(hWnd, message, wParam, lParam);
1185 static LRESULT CALLBACK PopupChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1190 NMHDR *nmhdr = (NMHDR*)lParam;
1194 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1197 if(info == 0 || lParam == 0)
1199 iter = (IndexSubItem*) ((NMITEMACTIVATE *)lParam)->lParam;
1202 NavigateToChm(info, info->index->merge.chm_file, iter->local);
1203 ShowWindow(info->popup.hwndPopup, SW_HIDE);
1207 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1214 lvItem.iItem = (int) SendMessageW(info->popup.hwndList, LVM_GETSELECTIONMARK, 0, 0);
1215 lvItem.mask = TVIF_PARAM;
1216 SendMessageW(info->popup.hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
1217 iter = (IndexSubItem*) lvItem.lParam;
1218 NavigateToChm(info, info->index->merge.chm_file, iter->local);
1219 ShowWindow(info->popup.hwndPopup, SW_HIDE);
1226 return DefWindowProcW(hWnd, message, wParam, lParam);
1232 static BOOL AddIndexPopup(HHInfo *info)
1234 static const WCHAR szPopupChildClass[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1235 static const WCHAR windowCaptionW[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1236 static const WCHAR windowClassW[] = {'H','H',' ','P','o','p','u','p',0};
1237 HWND hwndList, hwndPopup, hwndCallback;
1238 char hidden_column[] = "Column";
1242 if(info->tabs[TAB_INDEX].id == -1)
1243 return TRUE; /* No "Index" tab */
1245 wcex.cbSize = sizeof(WNDCLASSEXW);
1246 wcex.style = CS_HREDRAW | CS_VREDRAW;
1247 wcex.lpfnWndProc = HelpPopup_WndProc;
1248 wcex.cbClsExtra = 0;
1249 wcex.cbWndExtra = 0;
1250 wcex.hInstance = hhctrl_hinstance;
1251 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1252 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1253 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1254 wcex.lpszMenuName = NULL;
1255 wcex.lpszClassName = windowClassW;
1256 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1257 RegisterClassExW(&wcex);
1259 wcex.cbSize = sizeof(WNDCLASSEXW);
1261 wcex.lpfnWndProc = PopupChild_WndProc;
1262 wcex.cbClsExtra = 0;
1263 wcex.cbWndExtra = 0;
1264 wcex.hInstance = hhctrl_hinstance;
1265 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1266 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1267 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1268 wcex.lpszMenuName = NULL;
1269 wcex.lpszClassName = szPopupChildClass;
1270 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1271 RegisterClassExW(&wcex);
1273 hwndPopup = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW
1274 | WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR,
1275 windowClassW, windowCaptionW, WS_POPUPWINDOW
1276 | WS_OVERLAPPEDWINDOW | WS_VISIBLE
1277 | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT,
1278 CW_USEDEFAULT, 300, 200, info->WinType.hwndHelp,
1279 NULL, hhctrl_hinstance, NULL);
1283 hwndCallback = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
1284 szPopupChildClass, szEmpty, WS_CHILDWINDOW | WS_VISIBLE,
1286 hwndPopup, NULL, hhctrl_hinstance, NULL);
1290 ShowWindow(hwndPopup, SW_HIDE);
1291 hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty,
1292 WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT
1293 | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
1294 hwndCallback, NULL, hhctrl_hinstance, NULL);
1296 ERR("Could not create popup ListView control\n");
1299 memset(&lvc, 0, sizeof(lvc));
1300 lvc.mask = LVCF_TEXT;
1301 lvc.pszText = hidden_column;
1302 if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
1304 ERR("Could not create popup ListView column\n");
1308 info->popup.hwndCallback = hwndCallback;
1309 info->popup.hwndPopup = hwndPopup;
1310 info->popup.hwndList = hwndList;
1311 SetWindowLongPtrW(hwndPopup, GWLP_USERDATA, (LONG_PTR)info);
1312 SetWindowLongPtrW(hwndCallback, GWLP_USERDATA, (LONG_PTR)info);
1314 ResizePopupChild(info);
1315 ShowWindow(hwndList, SW_SHOW);
1322 static void ExpandContract(HHInfo *pHHInfo)
1326 pHHInfo->WinType.fNotExpanded = !pHHInfo->WinType.fNotExpanded;
1327 GetWindowRect(pHHInfo->WinType.hwndHelp, &r);
1328 NP_GetNavigationRect(pHHInfo, &nav);
1330 /* hide/show both the nav bar and the size bar */
1331 if (pHHInfo->WinType.fNotExpanded)
1333 ShowWindow(pHHInfo->WinType.hwndNavigation, SW_HIDE);
1334 ShowWindow(pHHInfo->hwndSizeBar, SW_HIDE);
1335 r.left = r.left + nav.right;
1337 SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_EXPAND, MAKELPARAM(FALSE, 0));
1338 SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_CONTRACT, MAKELPARAM(TRUE, 0));
1342 ShowWindow(pHHInfo->WinType.hwndNavigation, SW_SHOW);
1343 ShowWindow(pHHInfo->hwndSizeBar, SW_SHOW);
1344 r.left = r.left - nav.right;
1346 SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_EXPAND, MAKELPARAM(TRUE, 0));
1347 SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_CONTRACT, MAKELPARAM(FALSE, 0));
1350 MoveWindow(pHHInfo->WinType.hwndHelp, r.left, r.top, r.right-r.left, r.bottom-r.top, TRUE);
1353 static LRESULT Help_OnSize(HWND hWnd)
1355 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1362 if (!pHHInfo->WinType.fNotExpanded)
1364 NP_GetNavigationRect(pHHInfo, &rc);
1365 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
1366 rc.right, rc.bottom, SWP_NOMOVE);
1368 SB_GetSizeBarRect(pHHInfo, &rc);
1369 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
1370 rc.right, rc.bottom, SWP_SHOWWINDOW);
1374 HP_GetHTMLRect(pHHInfo, &rc);
1375 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
1376 rc.right, rc.bottom, SWP_SHOWWINDOW);
1378 /* Resize browser window taking the frame size into account */
1379 dwSize = GetSystemMetrics(SM_CXFRAME);
1380 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
1385 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1390 if (HIWORD(wParam) == BN_CLICKED)
1391 TB_OnClick(hWnd, LOWORD(wParam));
1394 return Help_OnSize(hWnd);
1396 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
1404 return DefWindowProcW(hWnd, message, wParam, lParam);
1410 static BOOL HH_CreateHelpWindow(HHInfo *info)
1413 RECT winPos = info->WinType.rcWindowPos;
1415 DWORD dwStyles, dwExStyles;
1416 DWORD x, y, width = 0, height = 0;
1419 static const WCHAR windowClassW[] = {
1420 'H','H',' ', 'P','a','r','e','n','t',0
1423 wcex.cbSize = sizeof(WNDCLASSEXW);
1424 wcex.style = CS_HREDRAW | CS_VREDRAW;
1425 wcex.lpfnWndProc = Help_WndProc;
1426 wcex.cbClsExtra = 0;
1427 wcex.cbWndExtra = 0;
1428 wcex.hInstance = hhctrl_hinstance;
1429 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1430 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1431 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1432 wcex.lpszMenuName = NULL;
1433 wcex.lpszClassName = windowClassW;
1434 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1436 RegisterClassExW(&wcex);
1438 /* Read in window parameters if available */
1439 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
1440 dwStyles = info->WinType.dwStyles | WS_OVERLAPPEDWINDOW;
1442 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
1443 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1445 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
1446 dwExStyles = info->WinType.dwExStyles;
1448 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
1449 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
1451 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
1455 width = winPos.right - x;
1456 height = winPos.bottom - y;
1458 if (!width || !height)
1460 x = WINTYPE_DEFAULT_X;
1461 y = WINTYPE_DEFAULT_Y;
1462 width = WINTYPE_DEFAULT_WIDTH;
1463 height = WINTYPE_DEFAULT_HEIGHT;
1466 if (info->WinType.fNotExpanded)
1468 if (!(info->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
1469 info->WinType.iNavWidth == 0)
1471 info->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
1474 x += info->WinType.iNavWidth;
1475 width -= info->WinType.iNavWidth;
1479 caption = info->WinType.pszCaption;
1480 if (!*caption) caption = info->pCHMInfo->defTitle;
1482 hWnd = CreateWindowExW(dwExStyles, windowClassW, caption,
1483 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
1487 ShowWindow(hWnd, SW_SHOW);
1490 /* store the pointer to the HH info struct */
1491 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
1493 info->WinType.hwndHelp = hWnd;
1497 static void HH_CreateFont(HHInfo *pHHInfo)
1501 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
1502 lf.lfWeight = FW_NORMAL;
1503 lf.lfItalic = FALSE;
1504 lf.lfUnderline = FALSE;
1506 pHHInfo->hFont = CreateFontIndirectW(&lf);
1509 static void HH_InitRequiredControls(DWORD dwControls)
1511 INITCOMMONCONTROLSEX icex;
1513 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1514 icex.dwICC = dwControls;
1515 InitCommonControlsEx(&icex);
1518 /* Creates the whole package */
1519 static BOOL CreateViewer(HHInfo *pHHInfo)
1521 HH_CreateFont(pHHInfo);
1523 if (!HH_CreateHelpWindow(pHHInfo))
1526 HH_InitRequiredControls(ICC_BAR_CLASSES);
1528 if (!HH_AddToolbar(pHHInfo))
1531 HH_RegisterChildWndClass(pHHInfo);
1533 if (!HH_AddNavigationPane(pHHInfo))
1536 HH_RegisterSizeBarClass(pHHInfo);
1538 if (!HH_AddSizeBar(pHHInfo))
1541 if (!HH_AddHTMLPane(pHHInfo))
1544 if (!AddContentTab(pHHInfo))
1547 if (!AddIndexTab(pHHInfo))
1550 if (!AddIndexPopup(pHHInfo))
1553 if (!AddSearchTab(pHHInfo))
1556 InitContent(pHHInfo);
1562 void ReleaseHelpViewer(HHInfo *info)
1564 TRACE("(%p)\n", info);
1569 /* Free allocated strings */
1570 heap_free(info->pszType);
1571 heap_free(info->pszCaption);
1572 heap_free(info->pszToc);
1573 heap_free(info->pszIndex);
1574 heap_free(info->pszFile);
1575 heap_free(info->pszHome);
1576 heap_free(info->pszJump1);
1577 heap_free(info->pszJump2);
1578 heap_free(info->pszUrlJump1);
1579 heap_free(info->pszUrlJump2);
1582 CloseCHM(info->pCHMInfo);
1584 ReleaseWebBrowser(info);
1585 ReleaseContent(info);
1587 ReleaseSearch(info);
1589 if(info->WinType.hwndHelp)
1590 DestroyWindow(info->WinType.hwndHelp);
1596 HHInfo *CreateHelpViewer(LPCWSTR filename)
1598 HHInfo *info = heap_alloc_zero(sizeof(HHInfo));
1601 /* Set the invalid tab ID (-1) as the default value for all
1602 * of the tabs, this matches a failed TCM_INSERTITEM call.
1604 for(i=0;i<sizeof(info->tabs)/sizeof(HHTab);i++)
1605 info->tabs[i].id = -1;
1607 OleInitialize(NULL);
1609 info->pCHMInfo = OpenCHM(filename);
1610 if(!info->pCHMInfo) {
1611 ReleaseHelpViewer(info);
1615 if (!LoadWinTypeFromCHM(info)) {
1616 ReleaseHelpViewer(info);
1620 if(!CreateViewer(info)) {
1621 ReleaseHelpViewer(info);