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 typedef struct tagHHInfo
56 /* Loads a string from the resource file */
57 static LPWSTR HH_LoadString(DWORD dwID)
62 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
63 iSize += 2; /* some strings (tab text) needs double-null termination */
65 string = hhctrl_alloc(iSize * sizeof(WCHAR));
66 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
71 static BOOL NavigateToChm(WBInfo *pWBInfo, LPCWSTR file, LPCWSTR index)
73 WCHAR buf[INTERNET_MAX_URL_LENGTH];
74 WCHAR full_path[MAX_PATH];
77 static const WCHAR url_format[] =
78 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
80 if (!pWBInfo->pWebBrowser2)
83 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
84 WARN("GetFullPathName failed: %u\n", GetLastError());
88 wsprintfW(buf, url_format, full_path, index);
91 V_BSTR(&url) = SysAllocString(buf);
93 IWebBrowser2_Navigate2(pWBInfo->pWebBrowser2, &url, 0, 0, 0, 0);
101 #define SIZEBAR_WIDTH 4
103 static const WCHAR szSizeBarClass[] = {
104 'H','H',' ','S','i','z','e','B','a','r',0
107 /* Draw the SizeBar */
108 static void SB_OnPaint(HWND hWnd)
114 hdc = BeginPaint(hWnd, &ps);
116 GetClientRect(hWnd, &rc);
121 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
123 /* white highlight */
124 SelectObject(hdc, GetStockObject(WHITE_PEN));
125 MoveToEx(hdc, rc.right, 1, NULL);
127 LineTo(hdc, 1, rc.bottom - 1);
130 MoveToEx(hdc, 0, rc.bottom, NULL);
131 LineTo(hdc, rc.right, rc.bottom);
136 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
141 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
143 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
146 pt.x = (short)LOWORD(lParam);
147 pt.y = (short)HIWORD(lParam);
149 /* update the window sizes */
150 pHHInfo->WinType.iNavWidth += pt.x;
156 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
158 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
159 if (!(wParam & MK_LBUTTON))
163 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
168 SB_OnLButtonDown(hWnd, wParam, lParam);
171 SB_OnLButtonUp(hWnd, wParam, lParam);
174 SB_OnMouseMove(hWnd, wParam, lParam);
180 return DefWindowProcW(hWnd, message, wParam, lParam);
186 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
190 wcex.cbSize = sizeof(WNDCLASSEXW);
192 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
195 wcex.hInstance = hhctrl_hinstance;
196 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
197 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
198 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
199 wcex.lpszMenuName = NULL;
200 wcex.lpszClassName = szSizeBarClass;
201 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
203 RegisterClassExW(&wcex);
206 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
208 RECT rectWND, rectTB, rectNP;
210 GetClientRect(info->WinType.hwndHelp, &rectWND);
211 GetClientRect(info->WinType.hwndToolBar, &rectTB);
212 GetClientRect(info->WinType.hwndNavigation, &rectNP);
214 rc->left = rectNP.right;
215 rc->top = rectTB.bottom;
216 rc->bottom = rectWND.bottom - rectTB.bottom;
217 rc->right = SIZEBAR_WIDTH;
220 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
223 HWND hwndParent = pHHInfo->WinType.hwndHelp;
224 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
225 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
228 SB_GetSizeBarRect(pHHInfo, &rc);
230 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
231 rc.left, rc.top, rc.right, rc.bottom,
232 hwndParent, NULL, hhctrl_hinstance, NULL);
236 /* store the pointer to the HH info struct */
237 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
239 pHHInfo->hwndSizeBar = hWnd;
245 static const WCHAR szChildClass[] = {
246 'H','H',' ','C','h','i','l','d',0
249 static void Child_OnPaint(HWND hWnd)
255 hdc = BeginPaint(hWnd, &ps);
257 /* Only paint the Navigation pane, identified by the fact
258 * that it has a child window
260 if (GetWindow(hWnd, GW_CHILD))
262 GetClientRect(hWnd, &rc);
264 /* set the border color */
265 SelectObject(hdc, GetStockObject(DC_PEN));
266 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
268 /* Draw the top border */
269 LineTo(hdc, rc.right, 0);
271 SelectObject(hdc, GetStockObject(WHITE_PEN));
272 MoveToEx(hdc, 0, 1, NULL);
273 LineTo(hdc, rc.right, 1);
279 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
287 return DefWindowProcW(hWnd, message, wParam, lParam);
293 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
297 wcex.cbSize = sizeof(WNDCLASSEXW);
299 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
302 wcex.hInstance = hhctrl_hinstance;
303 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
304 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
305 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
306 wcex.lpszMenuName = NULL;
307 wcex.lpszClassName = szChildClass;
308 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
310 RegisterClassExW(&wcex);
317 static void TB_OnClick(HWND hWnd, DWORD dwID)
319 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
324 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
327 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
330 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
333 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->WinType.pszHome);
336 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
343 case IDTB_BROWSE_FWD:
344 case IDTB_BROWSE_BACK:
355 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
357 /* FIXME: Load the correct button bitmaps */
358 pButtons[dwIndex].iBitmap = STD_PRINT;
359 pButtons[dwIndex].idCommand = dwID;
360 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
361 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
362 pButtons[dwIndex].dwData = 0;
363 pButtons[dwIndex].iString = 0;
366 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
370 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
371 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
373 if (dwButtonFlags & HHWIN_BUTTON_BACK)
374 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
376 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
377 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
379 if (dwButtonFlags & HHWIN_BUTTON_STOP)
380 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
382 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
383 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
385 if (dwButtonFlags & HHWIN_BUTTON_HOME)
386 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
388 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
389 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
391 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
392 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
394 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
395 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
397 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
398 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
400 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
401 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
403 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
404 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
406 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
407 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
409 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
410 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
413 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
416 HWND hwndParent = pHHInfo->WinType.hwndHelp;
418 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
420 DWORD dwStyles, dwExStyles;
421 DWORD dwNumButtons, dwIndex;
423 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
424 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
426 toolbarFlags = HHWIN_DEF_BUTTONS;
428 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
430 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
431 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
432 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
434 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
435 0, 0, 0, 0, hwndParent, NULL,
436 hhctrl_hinstance, NULL);
440 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
441 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
442 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
444 /* FIXME: Load correct icons for all buttons */
445 tbAB.hInst = HINST_COMMCTRL;
446 tbAB.nID = IDB_STD_LARGE_COLOR;
447 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
449 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
451 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
452 DWORD dwLen = strlenW(szBuf);
453 szBuf[dwLen + 2] = 0; /* Double-null terminate */
455 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
459 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
460 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
461 ShowWindow(hToolbar, SW_SHOW);
463 pHHInfo->WinType.hwndToolBar = hToolbar;
467 /* Navigation Pane */
469 #define TAB_TOP_PADDING 8
470 #define TAB_RIGHT_PADDING 4
472 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
474 HWND hwndParent = pHHInfo->WinType.hwndHelp;
475 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
476 RECT rectWND, rectTB;
478 GetClientRect(hwndParent, &rectWND);
479 GetClientRect(hwndToolbar, &rectTB);
482 rc->top = rectTB.bottom;
483 rc->bottom = rectWND.bottom - rectTB.bottom;
485 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
486 pHHInfo->WinType.iNavWidth == 0)
488 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
491 rc->right = pHHInfo->WinType.iNavWidth;
494 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
497 LPWSTR tabText = HH_LoadString(dwStrID);
499 tie.mask = TCIF_TEXT;
500 tie.pszText = tabText;
502 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
503 hhctrl_free(tabText);
506 static BOOL HH_AddNavigationPane(HHInfo *info)
508 HWND hWnd, hwndTabCtrl;
509 HWND hwndParent = info->WinType.hwndHelp;
510 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
511 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
515 NP_GetNavigationRect(info, &rc);
517 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
518 rc.left, rc.top, rc.right, rc.bottom,
519 hwndParent, NULL, hhctrl_hinstance, NULL);
523 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
525 rc.right - TAB_RIGHT_PADDING,
526 rc.bottom - TAB_TOP_PADDING,
527 hWnd, NULL, hhctrl_hinstance, NULL);
531 if (*info->WinType.pszToc)
532 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
534 if (*info->WinType.pszIndex)
535 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
537 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
538 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
540 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
541 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
543 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
545 info->hwndTabCtrl = hwndTabCtrl;
546 info->WinType.hwndNavigation = hWnd;
552 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
554 RECT rectTB, rectWND, rectNP, rectSB;
556 GetClientRect(info->WinType.hwndHelp, &rectWND);
557 GetClientRect(info->WinType.hwndToolBar, &rectTB);
558 GetClientRect(info->WinType.hwndNavigation, &rectNP);
559 GetClientRect(info->hwndSizeBar, &rectSB);
561 rc->left = rectNP.right + rectSB.right;
562 rc->top = rectTB.bottom;
563 rc->right = rectWND.right - rc->left;
564 rc->bottom = rectWND.bottom - rectTB.bottom;
567 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
570 HWND hwndParent = pHHInfo->WinType.hwndHelp;
571 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
572 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
575 HP_GetHTMLRect(pHHInfo, &rc);
577 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
578 rc.left, rc.top, rc.right, rc.bottom,
579 hwndParent, NULL, hhctrl_hinstance, NULL);
583 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
586 /* store the pointer to the HH info struct */
587 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
589 ShowWindow(hWnd, SW_SHOW);
592 pHHInfo->WinType.hwndHTML = hWnd;
598 static void Help_OnSize(HWND hWnd)
600 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
607 NP_GetNavigationRect(pHHInfo, &rc);
608 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
609 rc.right, rc.bottom, SWP_NOMOVE);
611 GetClientRect(pHHInfo->WinType.hwndNavigation, &rc);
612 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
613 rc.right - TAB_RIGHT_PADDING,
614 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
616 SB_GetSizeBarRect(pHHInfo, &rc);
617 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
618 rc.right, rc.bottom, SWP_SHOWWINDOW);
620 HP_GetHTMLRect(pHHInfo, &rc);
621 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
622 rc.right, rc.bottom, SWP_SHOWWINDOW);
624 /* Resize browser window taking the frame size into account */
625 dwSize = GetSystemMetrics(SM_CXFRAME);
626 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
629 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
637 if (HIWORD(wParam) == BN_CLICKED)
638 TB_OnClick(hWnd, LOWORD(wParam));
644 hdc = BeginPaint(hWnd, &ps);
652 return DefWindowProcW(hWnd, message, wParam, lParam);
658 static BOOL HH_CreateHelpWindow(HHInfo *info)
661 RECT winPos = info->WinType.rcWindowPos;
663 DWORD dwStyles, dwExStyles;
664 DWORD x, y, width, height;
666 static const WCHAR windowClassW[] = {
667 'H','H',' ', 'P','a','r','e','n','t',0
670 wcex.cbSize = sizeof(WNDCLASSEXW);
671 wcex.style = CS_HREDRAW | CS_VREDRAW;
672 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
675 wcex.hInstance = hhctrl_hinstance;
676 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
677 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
678 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
679 wcex.lpszMenuName = NULL;
680 wcex.lpszClassName = windowClassW;
681 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
683 RegisterClassExW(&wcex);
685 /* Read in window parameters if available */
686 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
687 dwStyles = info->WinType.dwStyles;
689 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
690 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
692 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
693 dwExStyles = info->WinType.dwExStyles;
695 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
696 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
698 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
702 width = winPos.right - x;
703 height = winPos.bottom - y;
707 x = WINTYPE_DEFAULT_X;
708 y = WINTYPE_DEFAULT_Y;
709 width = WINTYPE_DEFAULT_WIDTH;
710 height = WINTYPE_DEFAULT_HEIGHT;
713 hWnd = CreateWindowExW(dwExStyles, windowClassW, info->WinType.pszCaption,
714 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
718 ShowWindow(hWnd, SW_SHOW);
721 /* store the pointer to the HH info struct */
722 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
724 info->WinType.hwndHelp = hWnd;
728 static void HH_CreateFont(HHInfo *pHHInfo)
732 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
733 lf.lfWeight = FW_NORMAL;
735 lf.lfUnderline = FALSE;
737 pHHInfo->hFont = CreateFontIndirectW(&lf);
740 static void HH_InitRequiredControls(DWORD dwControls)
742 INITCOMMONCONTROLSEX icex;
744 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
745 icex.dwICC = dwControls;
746 InitCommonControlsEx(&icex);
749 /* Creates the whole package */
750 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
752 HH_CreateFont(pHHInfo);
754 if (!HH_CreateHelpWindow(pHHInfo))
757 HH_InitRequiredControls(ICC_BAR_CLASSES);
759 if (!HH_AddToolbar(pHHInfo))
762 HH_RegisterChildWndClass(pHHInfo);
764 if (!HH_AddNavigationPane(pHHInfo))
767 HH_RegisterSizeBarClass(pHHInfo);
769 if (!HH_AddSizeBar(pHHInfo))
772 if (!HH_AddHTMLPane(pHHInfo))
778 static void HH_Close(HHInfo *info)
783 /* Free allocated strings */
784 hhctrl_free((LPWSTR)info->WinType.pszType);
785 hhctrl_free((LPWSTR)info->WinType.pszCaption);
786 hhctrl_free((LPWSTR)info->WinType.pszToc);
787 hhctrl_free((LPWSTR)info->WinType.pszIndex);
788 hhctrl_free((LPWSTR)info->WinType.pszFile);
789 hhctrl_free((LPWSTR)info->WinType.pszHome);
790 hhctrl_free((LPWSTR)info->WinType.pszJump1);
791 hhctrl_free((LPWSTR)info->WinType.pszJump2);
792 hhctrl_free((LPWSTR)info->WinType.pszUrlJump1);
793 hhctrl_free((LPWSTR)info->WinType.pszUrlJump2);
796 CloseCHM(info->pCHMInfo);
800 WB_UnEmbedBrowser(info->pWBInfo);
801 hhctrl_free(info->pWBInfo);
805 static HHInfo *HH_OpenHH(LPWSTR filename)
807 HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
809 pHHInfo->pCHMInfo = OpenCHM(filename);
810 if(!pHHInfo->pCHMInfo) {
815 pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
817 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, &pHHInfo->WinType)) {
825 /* FIXME: Check szCmdLine for bad arguments */
826 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
831 if (FAILED(OleInitialize(NULL)))
834 pHHInfo = HH_OpenHH(strdupAtoW(szCmdLine));
835 if (!pHHInfo || !HH_CreateViewer(pHHInfo))
841 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->WinType.pszFile);
843 while (GetMessageW(&msg, 0, 0, 0))
845 TranslateMessage(&msg);
846 DispatchMessageW(&msg);
850 hhctrl_free(pHHInfo);