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
48 HH_WINTYPEW *pHHWinType;
57 extern HINSTANCE hhctrl_hinstance;
59 /* Loads a string from the resource file */
60 static LPWSTR HH_LoadString(DWORD dwID)
65 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
66 iSize += 2; /* some strings (tab text) needs double-null termination */
68 string = hhctrl_alloc(iSize * sizeof(WCHAR));
69 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
74 static BOOL NavigateToChm(WBInfo *pWBInfo, LPCWSTR file, LPCWSTR index)
76 WCHAR buf[INTERNET_MAX_URL_LENGTH];
77 WCHAR full_path[MAX_PATH];
80 static const WCHAR url_format[] =
81 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
83 if (!pWBInfo->pWebBrowser2)
86 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
87 WARN("GetFullPathName failed: %u\n", GetLastError());
91 wsprintfW(buf, url_format, full_path, index);
94 V_BSTR(&url) = SysAllocString(buf);
96 IWebBrowser2_Navigate2(pWBInfo->pWebBrowser2, &url, 0, 0, 0, 0);
104 #define SIZEBAR_WIDTH 4
106 static const WCHAR szSizeBarClass[] = {
107 'H','H',' ','S','i','z','e','B','a','r',0
110 /* Draw the SizeBar */
111 static void SB_OnPaint(HWND hWnd)
117 hdc = BeginPaint(hWnd, &ps);
119 GetClientRect(hWnd, &rc);
124 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
126 /* white highlight */
127 SelectObject(hdc, GetStockObject(WHITE_PEN));
128 MoveToEx(hdc, rc.right, 1, NULL);
130 LineTo(hdc, 1, rc.bottom - 1);
133 MoveToEx(hdc, 0, rc.bottom, NULL);
134 LineTo(hdc, rc.right, rc.bottom);
139 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
144 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
146 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
149 pt.x = (short)LOWORD(lParam);
150 pt.y = (short)HIWORD(lParam);
152 /* update the window sizes */
153 pHHInfo->pHHWinType->iNavWidth += pt.x;
159 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
161 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
162 if (!(wParam & MK_LBUTTON))
166 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
171 SB_OnLButtonDown(hWnd, wParam, lParam);
174 SB_OnLButtonUp(hWnd, wParam, lParam);
177 SB_OnMouseMove(hWnd, wParam, lParam);
183 return DefWindowProcW(hWnd, message, wParam, lParam);
189 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
193 wcex.cbSize = sizeof(WNDCLASSEXW);
195 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
198 wcex.hInstance = hhctrl_hinstance;
199 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
200 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
201 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
202 wcex.lpszMenuName = NULL;
203 wcex.lpszClassName = szSizeBarClass;
204 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
206 RegisterClassExW(&wcex);
209 static void SB_GetSizeBarRect(HHInfo *pHHInfo, RECT *rc)
211 RECT rectWND, rectTB, rectNP;
213 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
214 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
215 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
217 rc->left = rectNP.right;
218 rc->top = rectTB.bottom;
219 rc->bottom = rectWND.bottom - rectTB.bottom;
220 rc->right = SIZEBAR_WIDTH;
223 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
226 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
227 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
228 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
231 SB_GetSizeBarRect(pHHInfo, &rc);
233 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
234 rc.left, rc.top, rc.right, rc.bottom,
235 hwndParent, NULL, hhctrl_hinstance, NULL);
239 /* store the pointer to the HH info struct */
240 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
242 pHHInfo->hwndSizeBar = hWnd;
248 static const WCHAR szChildClass[] = {
249 'H','H',' ','C','h','i','l','d',0
252 static void Child_OnPaint(HWND hWnd)
258 hdc = BeginPaint(hWnd, &ps);
260 /* Only paint the Navigation pane, identified by the fact
261 * that it has a child window
263 if (GetWindow(hWnd, GW_CHILD))
265 GetClientRect(hWnd, &rc);
267 /* set the border color */
268 SelectObject(hdc, GetStockObject(DC_PEN));
269 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
271 /* Draw the top border */
272 LineTo(hdc, rc.right, 0);
274 SelectObject(hdc, GetStockObject(WHITE_PEN));
275 MoveToEx(hdc, 0, 1, NULL);
276 LineTo(hdc, rc.right, 1);
282 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
290 return DefWindowProcW(hWnd, message, wParam, lParam);
296 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
300 wcex.cbSize = sizeof(WNDCLASSEXW);
302 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
305 wcex.hInstance = hhctrl_hinstance;
306 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
307 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
308 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
309 wcex.lpszMenuName = NULL;
310 wcex.lpszClassName = szChildClass;
311 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
313 RegisterClassExW(&wcex);
320 static void TB_OnClick(HWND hWnd, DWORD dwID)
322 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
327 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
330 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
333 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
336 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszHome);
339 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
346 case IDTB_BROWSE_FWD:
347 case IDTB_BROWSE_BACK:
358 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
360 /* FIXME: Load the correct button bitmaps */
361 pButtons[dwIndex].iBitmap = STD_PRINT;
362 pButtons[dwIndex].idCommand = dwID;
363 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
364 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
365 pButtons[dwIndex].dwData = 0;
366 pButtons[dwIndex].iString = 0;
369 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
373 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
374 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
376 if (dwButtonFlags & HHWIN_BUTTON_BACK)
377 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
379 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
380 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
382 if (dwButtonFlags & HHWIN_BUTTON_STOP)
383 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
385 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
386 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
388 if (dwButtonFlags & HHWIN_BUTTON_HOME)
389 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
391 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
392 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
394 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
395 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
397 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
398 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
400 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
401 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
403 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
404 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
406 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
407 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
409 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
410 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
412 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
413 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
416 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
419 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
421 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
423 DWORD dwStyles, dwExStyles;
424 DWORD dwNumButtons, dwIndex;
426 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PARAM_TB_FLAGS)
427 toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags;
429 toolbarFlags = HHWIN_DEF_BUTTONS;
431 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
433 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
434 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
435 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
437 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
438 0, 0, 0, 0, hwndParent, NULL,
439 hhctrl_hinstance, NULL);
443 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
444 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
445 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
447 /* FIXME: Load correct icons for all buttons */
448 tbAB.hInst = HINST_COMMCTRL;
449 tbAB.nID = IDB_STD_LARGE_COLOR;
450 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
452 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
454 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
455 DWORD dwLen = strlenW(szBuf);
456 szBuf[dwLen + 2] = 0; /* Double-null terminate */
458 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
462 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
463 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
464 ShowWindow(hToolbar, SW_SHOW);
466 pHHInfo->pHHWinType->hwndToolBar = hToolbar;
470 /* Navigation Pane */
472 #define TAB_TOP_PADDING 8
473 #define TAB_RIGHT_PADDING 4
475 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
477 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
478 HWND hwndToolbar = pHHInfo->pHHWinType->hwndToolBar;
479 RECT rectWND, rectTB;
481 GetClientRect(hwndParent, &rectWND);
482 GetClientRect(hwndToolbar, &rectTB);
485 rc->top = rectTB.bottom;
486 rc->bottom = rectWND.bottom - rectTB.bottom;
488 if (!(pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
489 pHHInfo->pHHWinType->iNavWidth == 0)
491 pHHInfo->pHHWinType->iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
494 rc->right = pHHInfo->pHHWinType->iNavWidth;
497 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
500 LPWSTR tabText = HH_LoadString(dwStrID);
502 tie.mask = TCIF_TEXT;
503 tie.pszText = tabText;
505 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
506 hhctrl_free(tabText);
509 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
511 HWND hWnd, hwndTabCtrl;
512 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
513 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
514 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
518 NP_GetNavigationRect(pHHInfo, &rc);
520 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
521 rc.left, rc.top, rc.right, rc.bottom,
522 hwndParent, NULL, hhctrl_hinstance, NULL);
526 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
528 rc.right - TAB_RIGHT_PADDING,
529 rc.bottom - TAB_TOP_PADDING,
530 hWnd, NULL, hhctrl_hinstance, NULL);
534 if (*pHHInfo->pHHWinType->pszToc)
535 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
537 if (*pHHInfo->pHHWinType->pszIndex)
538 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
540 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_SEARCH)
541 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
543 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
544 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
546 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
548 pHHInfo->hwndTabCtrl = hwndTabCtrl;
549 pHHInfo->pHHWinType->hwndNavigation = hWnd;
555 static void HP_GetHTMLRect(HHInfo *pHHInfo, RECT *rc)
557 RECT rectTB, rectWND, rectNP, rectSB;
559 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
560 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
561 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
562 GetClientRect(pHHInfo->hwndSizeBar, &rectSB);
564 rc->left = rectNP.right + rectSB.right;
565 rc->top = rectTB.bottom;
566 rc->right = rectWND.right - rc->left;
567 rc->bottom = rectWND.bottom - rectTB.bottom;
570 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
573 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
574 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
575 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
578 HP_GetHTMLRect(pHHInfo, &rc);
580 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
581 rc.left, rc.top, rc.right, rc.bottom,
582 hwndParent, NULL, hhctrl_hinstance, NULL);
586 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
589 /* store the pointer to the HH info struct */
590 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
592 ShowWindow(hWnd, SW_SHOW);
595 pHHInfo->pHHWinType->hwndHTML = hWnd;
601 static void Help_OnSize(HWND hWnd)
603 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
610 NP_GetNavigationRect(pHHInfo, &rc);
611 SetWindowPos(pHHInfo->pHHWinType->hwndNavigation, HWND_TOP, 0, 0,
612 rc.right, rc.bottom, SWP_NOMOVE);
614 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rc);
615 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
616 rc.right - TAB_RIGHT_PADDING,
617 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
619 SB_GetSizeBarRect(pHHInfo, &rc);
620 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
621 rc.right, rc.bottom, SWP_SHOWWINDOW);
623 HP_GetHTMLRect(pHHInfo, &rc);
624 SetWindowPos(pHHInfo->pHHWinType->hwndHTML, HWND_TOP, rc.left, rc.top,
625 rc.right, rc.bottom, SWP_SHOWWINDOW);
627 /* Resize browser window taking the frame size into account */
628 dwSize = GetSystemMetrics(SM_CXFRAME);
629 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
632 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));
647 hdc = BeginPaint(hWnd, &ps);
655 return DefWindowProcW(hWnd, message, wParam, lParam);
661 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
664 RECT winPos = pHHInfo->pHHWinType->rcWindowPos;
666 DWORD dwStyles, dwExStyles;
667 DWORD x, y, width, height;
669 static const WCHAR windowClassW[] = {
670 'H','H',' ', 'P','a','r','e','n','t',0
673 wcex.cbSize = sizeof(WNDCLASSEXW);
674 wcex.style = CS_HREDRAW | CS_VREDRAW;
675 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
678 wcex.hInstance = hhctrl_hinstance;
679 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
680 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
681 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
682 wcex.lpszMenuName = NULL;
683 wcex.lpszClassName = windowClassW;
684 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
686 RegisterClassExW(&wcex);
688 /* Read in window parameters if available */
689 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_STYLES)
690 dwStyles = pHHInfo->pHHWinType->dwStyles;
692 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
693 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
695 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_EXSTYLES)
696 dwExStyles = pHHInfo->pHHWinType->dwExStyles;
698 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
699 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
701 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_RECT)
705 width = winPos.right - x;
706 height = winPos.bottom - y;
710 x = WINTYPE_DEFAULT_X;
711 y = WINTYPE_DEFAULT_Y;
712 width = WINTYPE_DEFAULT_WIDTH;
713 height = WINTYPE_DEFAULT_HEIGHT;
716 hWnd = CreateWindowExW(dwExStyles, windowClassW, pHHInfo->pHHWinType->pszCaption,
717 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
721 ShowWindow(hWnd, SW_SHOW);
724 /* store the pointer to the HH info struct */
725 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
727 pHHInfo->pHHWinType->hwndHelp = hWnd;
731 static void HH_CreateFont(HHInfo *pHHInfo)
735 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
736 lf.lfWeight = FW_NORMAL;
738 lf.lfUnderline = FALSE;
740 pHHInfo->hFont = CreateFontIndirectW(&lf);
743 static void HH_InitRequiredControls(DWORD dwControls)
745 INITCOMMONCONTROLSEX icex;
747 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
748 icex.dwICC = dwControls;
749 InitCommonControlsEx(&icex);
752 /* Creates the whole package */
753 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
755 HH_CreateFont(pHHInfo);
757 if (!HH_CreateHelpWindow(pHHInfo))
760 HH_InitRequiredControls(ICC_BAR_CLASSES);
762 if (!HH_AddToolbar(pHHInfo))
765 HH_RegisterChildWndClass(pHHInfo);
767 if (!HH_AddNavigationPane(pHHInfo))
770 HH_RegisterSizeBarClass(pHHInfo);
772 if (!HH_AddSizeBar(pHHInfo))
775 if (!HH_AddHTMLPane(pHHInfo))
781 static HHInfo *HH_OpenHH(LPWSTR szCmdLine)
783 HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
785 pHHInfo->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW));
786 pHHInfo->pCHMInfo = hhctrl_alloc(sizeof(CHMInfo));
787 pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
788 pHHInfo->szCmdLine = szCmdLine;
793 static void HH_Close(HHInfo *pHHInfo)
798 /* Free allocated strings */
799 if (pHHInfo->pHHWinType)
801 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszType);
802 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszCaption);
803 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszToc);
804 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszIndex);
805 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszFile);
806 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszHome);
807 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump1);
808 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump2);
809 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
810 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
813 hhctrl_free(pHHInfo->pHHWinType);
814 hhctrl_free(pHHInfo->szCmdLine);
816 if (pHHInfo->pCHMInfo)
818 CHM_CloseCHM(pHHInfo->pCHMInfo);
819 hhctrl_free(pHHInfo->pCHMInfo);
822 if (pHHInfo->pWBInfo)
824 WB_UnEmbedBrowser(pHHInfo->pWBInfo);
825 hhctrl_free(pHHInfo->pWBInfo);
829 static BOOL HH_OpenCHM(HHInfo *pHHInfo)
831 if (!CHM_OpenCHM(pHHInfo->pCHMInfo, pHHInfo->szCmdLine))
834 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType))
840 /* FIXME: Check szCmdLine for bad arguments */
841 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
846 if (FAILED(OleInitialize(NULL)))
849 pHHInfo = HH_OpenHH(strdupAtoW(szCmdLine));
850 if (!pHHInfo || !HH_OpenCHM(pHHInfo) || !HH_CreateViewer(pHHInfo))
856 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszFile);
858 while (GetMessageW(&msg, 0, 0, 0))
860 TranslateMessage(&msg);
861 DispatchMessageW(&msg);
865 hhctrl_free(pHHInfo);