2 * Help Viewer Implementation
4 * Copyright 2005 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 #include "wine/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
33 static LRESULT Help_OnSize(HWND hWnd);
35 /* Window type defaults */
37 #define WINTYPE_DEFAULT_X 280
38 #define WINTYPE_DEFAULT_Y 100
39 #define WINTYPE_DEFAULT_WIDTH 740
40 #define WINTYPE_DEFAULT_HEIGHT 640
41 #define WINTYPE_DEFAULT_NAVWIDTH 250
43 static const WCHAR szEmpty[] = {0};
45 /* Loads a string from the resource file */
46 static LPWSTR HH_LoadString(DWORD dwID)
51 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
52 iSize += 2; /* some strings (tab text) needs double-null termination */
54 string = hhctrl_alloc(iSize * sizeof(WCHAR));
55 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
60 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
66 V_BSTR(&url) = SysAllocString(surl);
68 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
72 return SUCCEEDED(hres);
75 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
77 WCHAR buf[INTERNET_MAX_URL_LENGTH];
78 WCHAR full_path[MAX_PATH];
81 static const WCHAR url_format[] =
82 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
84 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
86 if (!info->web_browser)
89 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
90 WARN("GetFullPathName failed: %u\n", GetLastError());
94 wsprintfW(buf, url_format, full_path, index);
97 if((ptr = strchrW(buf, '#')))
100 return NavigateToUrl(info, buf);
105 #define SIZEBAR_WIDTH 4
107 static const WCHAR szSizeBarClass[] = {
108 'H','H',' ','S','i','z','e','B','a','r',0
111 /* Draw the SizeBar */
112 static void SB_OnPaint(HWND hWnd)
118 hdc = BeginPaint(hWnd, &ps);
120 GetClientRect(hWnd, &rc);
125 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
127 /* white highlight */
128 SelectObject(hdc, GetStockObject(WHITE_PEN));
129 MoveToEx(hdc, rc.right, 1, NULL);
131 LineTo(hdc, 1, rc.bottom - 1);
134 MoveToEx(hdc, 0, rc.bottom, NULL);
135 LineTo(hdc, rc.right, rc.bottom);
140 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
145 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
147 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
150 pt.x = (short)LOWORD(lParam);
151 pt.y = (short)HIWORD(lParam);
153 /* update the window sizes */
154 pHHInfo->WinType.iNavWidth += pt.x;
160 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
162 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
163 if (!(wParam & MK_LBUTTON))
167 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
172 SB_OnLButtonDown(hWnd, wParam, lParam);
175 SB_OnLButtonUp(hWnd, wParam, lParam);
178 SB_OnMouseMove(hWnd, wParam, lParam);
184 return DefWindowProcW(hWnd, message, wParam, lParam);
190 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
194 wcex.cbSize = sizeof(WNDCLASSEXW);
196 wcex.lpfnWndProc = SizeBar_WndProc;
199 wcex.hInstance = hhctrl_hinstance;
200 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
201 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
202 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
203 wcex.lpszMenuName = NULL;
204 wcex.lpszClassName = szSizeBarClass;
205 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
207 RegisterClassExW(&wcex);
210 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
212 RECT rectWND, rectTB, rectNP;
214 GetClientRect(info->WinType.hwndHelp, &rectWND);
215 GetClientRect(info->WinType.hwndToolBar, &rectTB);
216 GetClientRect(info->WinType.hwndNavigation, &rectNP);
218 rc->left = rectNP.right;
219 rc->top = rectTB.bottom;
220 rc->bottom = rectWND.bottom - rectTB.bottom;
221 rc->right = SIZEBAR_WIDTH;
224 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
227 HWND hwndParent = pHHInfo->WinType.hwndHelp;
228 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
229 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
232 SB_GetSizeBarRect(pHHInfo, &rc);
234 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
235 rc.left, rc.top, rc.right, rc.bottom,
236 hwndParent, NULL, hhctrl_hinstance, NULL);
240 /* store the pointer to the HH info struct */
241 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
243 pHHInfo->hwndSizeBar = hWnd;
249 static const WCHAR szChildClass[] = {
250 'H','H',' ','C','h','i','l','d',0
253 static void Child_OnPaint(HWND hWnd)
259 hdc = BeginPaint(hWnd, &ps);
261 /* Only paint the Navigation pane, identified by the fact
262 * that it has a child window
264 if (GetWindow(hWnd, GW_CHILD))
266 GetClientRect(hWnd, &rc);
268 /* set the border color */
269 SelectObject(hdc, GetStockObject(DC_PEN));
270 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
272 /* Draw the top border */
273 LineTo(hdc, rc.right, 0);
275 SelectObject(hdc, GetStockObject(WHITE_PEN));
276 MoveToEx(hdc, 0, 1, NULL);
277 LineTo(hdc, rc.right, 1);
283 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
291 return DefWindowProcW(hWnd, message, wParam, lParam);
297 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
301 wcex.cbSize = sizeof(WNDCLASSEXW);
303 wcex.lpfnWndProc = Child_WndProc;
306 wcex.hInstance = hhctrl_hinstance;
307 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
308 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
309 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
310 wcex.lpszMenuName = NULL;
311 wcex.lpszClassName = szChildClass;
312 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
314 RegisterClassExW(&wcex);
321 static void TB_OnClick(HWND hWnd, DWORD dwID)
323 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
328 DoPageAction(info, WB_STOP);
331 DoPageAction(info, WB_REFRESH);
334 DoPageAction(info, WB_GOBACK);
337 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
340 DoPageAction(info, WB_GOFORWARD);
347 case IDTB_BROWSE_FWD:
348 case IDTB_BROWSE_BACK:
359 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
361 /* FIXME: Load the correct button bitmaps */
362 pButtons[dwIndex].iBitmap = STD_PRINT;
363 pButtons[dwIndex].idCommand = dwID;
364 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
365 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
366 pButtons[dwIndex].dwData = 0;
367 pButtons[dwIndex].iString = 0;
370 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
374 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
375 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
377 if (dwButtonFlags & HHWIN_BUTTON_BACK)
378 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
380 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
381 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
383 if (dwButtonFlags & HHWIN_BUTTON_STOP)
384 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
386 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
387 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
389 if (dwButtonFlags & HHWIN_BUTTON_HOME)
390 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
392 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
393 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
395 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
396 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
398 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
399 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
401 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
402 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
404 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
405 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
407 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
408 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
410 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
411 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
413 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
414 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
417 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
420 HWND hwndParent = pHHInfo->WinType.hwndHelp;
422 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
424 DWORD dwStyles, dwExStyles;
425 DWORD dwNumButtons, dwIndex;
427 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
428 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
430 toolbarFlags = HHWIN_DEF_BUTTONS;
432 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
434 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
435 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
436 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
438 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
439 0, 0, 0, 0, hwndParent, NULL,
440 hhctrl_hinstance, NULL);
444 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
445 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
446 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
448 /* FIXME: Load correct icons for all buttons */
449 tbAB.hInst = HINST_COMMCTRL;
450 tbAB.nID = IDB_STD_LARGE_COLOR;
451 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
453 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
455 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
456 DWORD dwLen = strlenW(szBuf);
457 szBuf[dwLen + 2] = 0; /* Double-null terminate */
459 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
463 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
464 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
465 ShowWindow(hToolbar, SW_SHOW);
467 pHHInfo->WinType.hwndToolBar = hToolbar;
471 /* Navigation Pane */
473 #define TAB_TOP_PADDING 8
474 #define TAB_RIGHT_PADDING 4
476 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
478 HWND hwndParent = pHHInfo->WinType.hwndHelp;
479 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
480 RECT rectWND, rectTB;
482 GetClientRect(hwndParent, &rectWND);
483 GetClientRect(hwndToolbar, &rectTB);
486 rc->top = rectTB.bottom;
487 rc->bottom = rectWND.bottom - rectTB.bottom;
489 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
490 pHHInfo->WinType.iNavWidth == 0)
492 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
495 rc->right = pHHInfo->WinType.iNavWidth;
498 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
501 LPWSTR tabText = HH_LoadString(dwStrID);
503 tie.mask = TCIF_TEXT;
504 tie.pszText = tabText;
506 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
507 hhctrl_free(tabText);
510 static BOOL HH_AddNavigationPane(HHInfo *info)
512 HWND hWnd, hwndTabCtrl;
513 HWND hwndParent = info->WinType.hwndHelp;
514 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
515 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
519 NP_GetNavigationRect(info, &rc);
521 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
522 rc.left, rc.top, rc.right, rc.bottom,
523 hwndParent, NULL, hhctrl_hinstance, NULL);
527 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
529 rc.right - TAB_RIGHT_PADDING,
530 rc.bottom - TAB_TOP_PADDING,
531 hWnd, NULL, hhctrl_hinstance, NULL);
535 if (*info->WinType.pszToc)
536 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
538 if (*info->WinType.pszIndex)
539 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
541 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
542 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
544 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
545 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
547 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
549 info->hwndTabCtrl = hwndTabCtrl;
550 info->WinType.hwndNavigation = hWnd;
556 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
558 RECT rectTB, rectWND, rectNP, rectSB;
560 GetClientRect(info->WinType.hwndHelp, &rectWND);
561 GetClientRect(info->WinType.hwndToolBar, &rectTB);
562 GetClientRect(info->WinType.hwndNavigation, &rectNP);
563 GetClientRect(info->hwndSizeBar, &rectSB);
565 rc->left = rectNP.right + rectSB.right;
566 rc->top = rectTB.bottom;
567 rc->right = rectWND.right - rc->left;
568 rc->bottom = rectWND.bottom - rectTB.bottom;
571 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
574 HWND hwndParent = pHHInfo->WinType.hwndHelp;
575 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
576 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
579 HP_GetHTMLRect(pHHInfo, &rc);
581 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
582 rc.left, rc.top, rc.right, rc.bottom,
583 hwndParent, NULL, hhctrl_hinstance, NULL);
587 if (!InitWebBrowser(pHHInfo, hWnd))
590 /* store the pointer to the HH info struct */
591 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
593 ShowWindow(hWnd, SW_SHOW);
596 pHHInfo->WinType.hwndHTML = hWnd;
602 static LRESULT Help_OnSize(HWND hWnd)
604 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
611 NP_GetNavigationRect(pHHInfo, &rc);
612 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
613 rc.right, rc.bottom, SWP_NOMOVE);
615 GetClientRect(pHHInfo->WinType.hwndNavigation, &rc);
616 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
617 rc.right - TAB_RIGHT_PADDING,
618 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
620 SB_GetSizeBarRect(pHHInfo, &rc);
621 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
622 rc.right, rc.bottom, SWP_SHOWWINDOW);
624 HP_GetHTMLRect(pHHInfo, &rc);
625 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
626 rc.right, rc.bottom, SWP_SHOWWINDOW);
628 /* Resize browser window taking the frame size into account */
629 dwSize = GetSystemMetrics(SM_CXFRAME);
630 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
635 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
640 if (HIWORD(wParam) == BN_CLICKED)
641 TB_OnClick(hWnd, LOWORD(wParam));
644 return Help_OnSize(hWnd);
646 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
654 return DefWindowProcW(hWnd, message, wParam, lParam);
660 static BOOL HH_CreateHelpWindow(HHInfo *info)
663 RECT winPos = info->WinType.rcWindowPos;
665 DWORD dwStyles, dwExStyles;
666 DWORD x, y, width, height;
668 static const WCHAR windowClassW[] = {
669 'H','H',' ', 'P','a','r','e','n','t',0
672 wcex.cbSize = sizeof(WNDCLASSEXW);
673 wcex.style = CS_HREDRAW | CS_VREDRAW;
674 wcex.lpfnWndProc = Help_WndProc;
677 wcex.hInstance = hhctrl_hinstance;
678 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
679 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
680 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
681 wcex.lpszMenuName = NULL;
682 wcex.lpszClassName = windowClassW;
683 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
685 RegisterClassExW(&wcex);
687 /* Read in window parameters if available */
688 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
689 dwStyles = info->WinType.dwStyles;
691 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
692 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
694 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
695 dwExStyles = info->WinType.dwExStyles;
697 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
698 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
700 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
704 width = winPos.right - x;
705 height = winPos.bottom - y;
709 x = WINTYPE_DEFAULT_X;
710 y = WINTYPE_DEFAULT_Y;
711 width = WINTYPE_DEFAULT_WIDTH;
712 height = WINTYPE_DEFAULT_HEIGHT;
715 hWnd = CreateWindowExW(dwExStyles, windowClassW, info->WinType.pszCaption,
716 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
720 ShowWindow(hWnd, SW_SHOW);
723 /* store the pointer to the HH info struct */
724 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
726 info->WinType.hwndHelp = hWnd;
730 static void HH_CreateFont(HHInfo *pHHInfo)
734 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
735 lf.lfWeight = FW_NORMAL;
737 lf.lfUnderline = FALSE;
739 pHHInfo->hFont = CreateFontIndirectW(&lf);
742 static void HH_InitRequiredControls(DWORD dwControls)
744 INITCOMMONCONTROLSEX icex;
746 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
747 icex.dwICC = dwControls;
748 InitCommonControlsEx(&icex);
751 /* Creates the whole package */
752 static BOOL CreateViewer(HHInfo *pHHInfo)
754 HH_CreateFont(pHHInfo);
756 if (!HH_CreateHelpWindow(pHHInfo))
759 HH_InitRequiredControls(ICC_BAR_CLASSES);
761 if (!HH_AddToolbar(pHHInfo))
764 HH_RegisterChildWndClass(pHHInfo);
766 if (!HH_AddNavigationPane(pHHInfo))
769 HH_RegisterSizeBarClass(pHHInfo);
771 if (!HH_AddSizeBar(pHHInfo))
774 if (!HH_AddHTMLPane(pHHInfo))
780 void ReleaseHelpViewer(HHInfo *info)
785 /* Free allocated strings */
786 hhctrl_free((LPWSTR)info->WinType.pszType);
787 hhctrl_free((LPWSTR)info->WinType.pszCaption);
788 hhctrl_free((LPWSTR)info->WinType.pszToc);
789 hhctrl_free((LPWSTR)info->WinType.pszIndex);
790 hhctrl_free((LPWSTR)info->WinType.pszFile);
791 hhctrl_free((LPWSTR)info->WinType.pszHome);
792 hhctrl_free((LPWSTR)info->WinType.pszJump1);
793 hhctrl_free((LPWSTR)info->WinType.pszJump2);
794 hhctrl_free((LPWSTR)info->WinType.pszUrlJump1);
795 hhctrl_free((LPWSTR)info->WinType.pszUrlJump2);
798 CloseCHM(info->pCHMInfo);
800 ReleaseWebBrowser(info);
802 if(info->WinType.hwndHelp)
803 DestroyWindow(info->WinType.hwndHelp);
809 HHInfo *CreateHelpViewer(LPCWSTR filename)
811 HHInfo *info = hhctrl_alloc_zero(sizeof(HHInfo));
815 info->pCHMInfo = OpenCHM(filename);
816 if(!info->pCHMInfo) {
817 ReleaseHelpViewer(info);
821 if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) {
822 ReleaseHelpViewer(info);
826 if(!CreateViewer(info)) {
827 ReleaseHelpViewer(info);