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/unicode.h"
28 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
34 static void 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 static const WCHAR szEmpty[] = {0};
46 /* Loads a string from the resource file */
47 static LPWSTR HH_LoadString(DWORD dwID)
52 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
53 iSize += 2; /* some strings (tab text) needs double-null termination */
55 string = hhctrl_alloc(iSize * sizeof(WCHAR));
56 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
61 static BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
63 WCHAR buf[INTERNET_MAX_URL_LENGTH];
64 WCHAR full_path[MAX_PATH];
67 static const WCHAR url_format[] =
68 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
70 if (!info->web_browser)
73 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
74 WARN("GetFullPathName failed: %u\n", GetLastError());
78 wsprintfW(buf, url_format, full_path, index);
81 V_BSTR(&url) = SysAllocString(buf);
83 IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
91 #define SIZEBAR_WIDTH 4
93 static const WCHAR szSizeBarClass[] = {
94 'H','H',' ','S','i','z','e','B','a','r',0
97 /* Draw the SizeBar */
98 static void SB_OnPaint(HWND hWnd)
104 hdc = BeginPaint(hWnd, &ps);
106 GetClientRect(hWnd, &rc);
111 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
113 /* white highlight */
114 SelectObject(hdc, GetStockObject(WHITE_PEN));
115 MoveToEx(hdc, rc.right, 1, NULL);
117 LineTo(hdc, 1, rc.bottom - 1);
120 MoveToEx(hdc, 0, rc.bottom, NULL);
121 LineTo(hdc, rc.right, rc.bottom);
126 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
131 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
133 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
136 pt.x = (short)LOWORD(lParam);
137 pt.y = (short)HIWORD(lParam);
139 /* update the window sizes */
140 pHHInfo->WinType.iNavWidth += pt.x;
146 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
148 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
149 if (!(wParam & MK_LBUTTON))
153 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
158 SB_OnLButtonDown(hWnd, wParam, lParam);
161 SB_OnLButtonUp(hWnd, wParam, lParam);
164 SB_OnMouseMove(hWnd, wParam, lParam);
170 return DefWindowProcW(hWnd, message, wParam, lParam);
176 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
180 wcex.cbSize = sizeof(WNDCLASSEXW);
182 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
185 wcex.hInstance = hhctrl_hinstance;
186 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
187 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
188 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
189 wcex.lpszMenuName = NULL;
190 wcex.lpszClassName = szSizeBarClass;
191 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
193 RegisterClassExW(&wcex);
196 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
198 RECT rectWND, rectTB, rectNP;
200 GetClientRect(info->WinType.hwndHelp, &rectWND);
201 GetClientRect(info->WinType.hwndToolBar, &rectTB);
202 GetClientRect(info->WinType.hwndNavigation, &rectNP);
204 rc->left = rectNP.right;
205 rc->top = rectTB.bottom;
206 rc->bottom = rectWND.bottom - rectTB.bottom;
207 rc->right = SIZEBAR_WIDTH;
210 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
213 HWND hwndParent = pHHInfo->WinType.hwndHelp;
214 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
215 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
218 SB_GetSizeBarRect(pHHInfo, &rc);
220 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
221 rc.left, rc.top, rc.right, rc.bottom,
222 hwndParent, NULL, hhctrl_hinstance, NULL);
226 /* store the pointer to the HH info struct */
227 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
229 pHHInfo->hwndSizeBar = hWnd;
235 static const WCHAR szChildClass[] = {
236 'H','H',' ','C','h','i','l','d',0
239 static void Child_OnPaint(HWND hWnd)
245 hdc = BeginPaint(hWnd, &ps);
247 /* Only paint the Navigation pane, identified by the fact
248 * that it has a child window
250 if (GetWindow(hWnd, GW_CHILD))
252 GetClientRect(hWnd, &rc);
254 /* set the border color */
255 SelectObject(hdc, GetStockObject(DC_PEN));
256 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
258 /* Draw the top border */
259 LineTo(hdc, rc.right, 0);
261 SelectObject(hdc, GetStockObject(WHITE_PEN));
262 MoveToEx(hdc, 0, 1, NULL);
263 LineTo(hdc, rc.right, 1);
269 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
277 return DefWindowProcW(hWnd, message, wParam, lParam);
283 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
287 wcex.cbSize = sizeof(WNDCLASSEXW);
289 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
292 wcex.hInstance = hhctrl_hinstance;
293 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
294 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
295 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
296 wcex.lpszMenuName = NULL;
297 wcex.lpszClassName = szChildClass;
298 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
300 RegisterClassExW(&wcex);
307 static void TB_OnClick(HWND hWnd, DWORD dwID)
309 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
314 DoPageAction(info, WB_STOP);
317 DoPageAction(info, WB_REFRESH);
320 DoPageAction(info, WB_GOBACK);
323 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
326 DoPageAction(info, WB_GOFORWARD);
333 case IDTB_BROWSE_FWD:
334 case IDTB_BROWSE_BACK:
345 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
347 /* FIXME: Load the correct button bitmaps */
348 pButtons[dwIndex].iBitmap = STD_PRINT;
349 pButtons[dwIndex].idCommand = dwID;
350 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
351 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
352 pButtons[dwIndex].dwData = 0;
353 pButtons[dwIndex].iString = 0;
356 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
360 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
361 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
363 if (dwButtonFlags & HHWIN_BUTTON_BACK)
364 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
366 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
367 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
369 if (dwButtonFlags & HHWIN_BUTTON_STOP)
370 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
372 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
373 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
375 if (dwButtonFlags & HHWIN_BUTTON_HOME)
376 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
378 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
379 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
381 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
382 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
384 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
385 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
387 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
388 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
390 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
391 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
393 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
394 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
396 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
397 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
399 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
400 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
403 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
406 HWND hwndParent = pHHInfo->WinType.hwndHelp;
408 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
410 DWORD dwStyles, dwExStyles;
411 DWORD dwNumButtons, dwIndex;
413 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
414 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
416 toolbarFlags = HHWIN_DEF_BUTTONS;
418 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
420 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
421 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
422 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
424 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
425 0, 0, 0, 0, hwndParent, NULL,
426 hhctrl_hinstance, NULL);
430 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
431 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
432 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
434 /* FIXME: Load correct icons for all buttons */
435 tbAB.hInst = HINST_COMMCTRL;
436 tbAB.nID = IDB_STD_LARGE_COLOR;
437 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
439 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
441 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
442 DWORD dwLen = strlenW(szBuf);
443 szBuf[dwLen + 2] = 0; /* Double-null terminate */
445 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
449 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
450 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
451 ShowWindow(hToolbar, SW_SHOW);
453 pHHInfo->WinType.hwndToolBar = hToolbar;
457 /* Navigation Pane */
459 #define TAB_TOP_PADDING 8
460 #define TAB_RIGHT_PADDING 4
462 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
464 HWND hwndParent = pHHInfo->WinType.hwndHelp;
465 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
466 RECT rectWND, rectTB;
468 GetClientRect(hwndParent, &rectWND);
469 GetClientRect(hwndToolbar, &rectTB);
472 rc->top = rectTB.bottom;
473 rc->bottom = rectWND.bottom - rectTB.bottom;
475 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
476 pHHInfo->WinType.iNavWidth == 0)
478 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
481 rc->right = pHHInfo->WinType.iNavWidth;
484 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
487 LPWSTR tabText = HH_LoadString(dwStrID);
489 tie.mask = TCIF_TEXT;
490 tie.pszText = tabText;
492 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
493 hhctrl_free(tabText);
496 static BOOL HH_AddNavigationPane(HHInfo *info)
498 HWND hWnd, hwndTabCtrl;
499 HWND hwndParent = info->WinType.hwndHelp;
500 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
501 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
505 NP_GetNavigationRect(info, &rc);
507 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
508 rc.left, rc.top, rc.right, rc.bottom,
509 hwndParent, NULL, hhctrl_hinstance, NULL);
513 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
515 rc.right - TAB_RIGHT_PADDING,
516 rc.bottom - TAB_TOP_PADDING,
517 hWnd, NULL, hhctrl_hinstance, NULL);
521 if (*info->WinType.pszToc)
522 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
524 if (*info->WinType.pszIndex)
525 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
527 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
528 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
530 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
531 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
533 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
535 info->hwndTabCtrl = hwndTabCtrl;
536 info->WinType.hwndNavigation = hWnd;
542 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
544 RECT rectTB, rectWND, rectNP, rectSB;
546 GetClientRect(info->WinType.hwndHelp, &rectWND);
547 GetClientRect(info->WinType.hwndToolBar, &rectTB);
548 GetClientRect(info->WinType.hwndNavigation, &rectNP);
549 GetClientRect(info->hwndSizeBar, &rectSB);
551 rc->left = rectNP.right + rectSB.right;
552 rc->top = rectTB.bottom;
553 rc->right = rectWND.right - rc->left;
554 rc->bottom = rectWND.bottom - rectTB.bottom;
557 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
560 HWND hwndParent = pHHInfo->WinType.hwndHelp;
561 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
562 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
565 HP_GetHTMLRect(pHHInfo, &rc);
567 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
568 rc.left, rc.top, rc.right, rc.bottom,
569 hwndParent, NULL, hhctrl_hinstance, NULL);
573 if (!InitWebBrowser(pHHInfo, hWnd))
576 /* store the pointer to the HH info struct */
577 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
579 ShowWindow(hWnd, SW_SHOW);
582 pHHInfo->WinType.hwndHTML = hWnd;
588 static void Help_OnSize(HWND hWnd)
590 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
597 NP_GetNavigationRect(pHHInfo, &rc);
598 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
599 rc.right, rc.bottom, SWP_NOMOVE);
601 GetClientRect(pHHInfo->WinType.hwndNavigation, &rc);
602 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
603 rc.right - TAB_RIGHT_PADDING,
604 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
606 SB_GetSizeBarRect(pHHInfo, &rc);
607 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
608 rc.right, rc.bottom, SWP_SHOWWINDOW);
610 HP_GetHTMLRect(pHHInfo, &rc);
611 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
612 rc.right, rc.bottom, SWP_SHOWWINDOW);
614 /* Resize browser window taking the frame size into account */
615 dwSize = GetSystemMetrics(SM_CXFRAME);
616 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
619 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
627 if (HIWORD(wParam) == BN_CLICKED)
628 TB_OnClick(hWnd, LOWORD(wParam));
634 hdc = BeginPaint(hWnd, &ps);
642 return DefWindowProcW(hWnd, message, wParam, lParam);
648 static BOOL HH_CreateHelpWindow(HHInfo *info)
651 RECT winPos = info->WinType.rcWindowPos;
653 DWORD dwStyles, dwExStyles;
654 DWORD x, y, width, height;
656 static const WCHAR windowClassW[] = {
657 'H','H',' ', 'P','a','r','e','n','t',0
660 wcex.cbSize = sizeof(WNDCLASSEXW);
661 wcex.style = CS_HREDRAW | CS_VREDRAW;
662 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
665 wcex.hInstance = hhctrl_hinstance;
666 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
667 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
668 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
669 wcex.lpszMenuName = NULL;
670 wcex.lpszClassName = windowClassW;
671 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
673 RegisterClassExW(&wcex);
675 /* Read in window parameters if available */
676 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
677 dwStyles = info->WinType.dwStyles;
679 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
680 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
682 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
683 dwExStyles = info->WinType.dwExStyles;
685 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
686 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
688 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
692 width = winPos.right - x;
693 height = winPos.bottom - y;
697 x = WINTYPE_DEFAULT_X;
698 y = WINTYPE_DEFAULT_Y;
699 width = WINTYPE_DEFAULT_WIDTH;
700 height = WINTYPE_DEFAULT_HEIGHT;
703 hWnd = CreateWindowExW(dwExStyles, windowClassW, info->WinType.pszCaption,
704 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
708 ShowWindow(hWnd, SW_SHOW);
711 /* store the pointer to the HH info struct */
712 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
714 info->WinType.hwndHelp = hWnd;
718 static void HH_CreateFont(HHInfo *pHHInfo)
722 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
723 lf.lfWeight = FW_NORMAL;
725 lf.lfUnderline = FALSE;
727 pHHInfo->hFont = CreateFontIndirectW(&lf);
730 static void HH_InitRequiredControls(DWORD dwControls)
732 INITCOMMONCONTROLSEX icex;
734 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
735 icex.dwICC = dwControls;
736 InitCommonControlsEx(&icex);
739 /* Creates the whole package */
740 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
742 HH_CreateFont(pHHInfo);
744 if (!HH_CreateHelpWindow(pHHInfo))
747 HH_InitRequiredControls(ICC_BAR_CLASSES);
749 if (!HH_AddToolbar(pHHInfo))
752 HH_RegisterChildWndClass(pHHInfo);
754 if (!HH_AddNavigationPane(pHHInfo))
757 HH_RegisterSizeBarClass(pHHInfo);
759 if (!HH_AddSizeBar(pHHInfo))
762 if (!HH_AddHTMLPane(pHHInfo))
768 static void HH_Close(HHInfo *info)
773 /* Free allocated strings */
774 hhctrl_free((LPWSTR)info->WinType.pszType);
775 hhctrl_free((LPWSTR)info->WinType.pszCaption);
776 hhctrl_free((LPWSTR)info->WinType.pszToc);
777 hhctrl_free((LPWSTR)info->WinType.pszIndex);
778 hhctrl_free((LPWSTR)info->WinType.pszFile);
779 hhctrl_free((LPWSTR)info->WinType.pszHome);
780 hhctrl_free((LPWSTR)info->WinType.pszJump1);
781 hhctrl_free((LPWSTR)info->WinType.pszJump2);
782 hhctrl_free((LPWSTR)info->WinType.pszUrlJump1);
783 hhctrl_free((LPWSTR)info->WinType.pszUrlJump2);
786 CloseCHM(info->pCHMInfo);
788 ReleaseWebBrowser(info);
791 static HHInfo *HH_OpenHH(LPWSTR filename)
793 HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
795 pHHInfo->pCHMInfo = OpenCHM(filename);
796 if(!pHHInfo->pCHMInfo) {
801 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, &pHHInfo->WinType)) {
809 /* FIXME: Check szCmdLine for bad arguments */
810 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
815 if (FAILED(OleInitialize(NULL)))
818 pHHInfo = HH_OpenHH(strdupAtoW(szCmdLine));
819 if (!pHHInfo || !HH_CreateViewer(pHHInfo))
825 NavigateToChm(pHHInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->WinType.pszFile);
827 while (GetMessageW(&msg, 0, 0, 0))
829 TranslateMessage(&msg);
830 DispatchMessageW(&msg);
834 hhctrl_free(pHHInfo);