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
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
41 #include "webbrowser.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
45 static void Help_OnSize(HWND hWnd);
47 /* Window type defaults */
49 #define WINTYPE_DEFAULT_X 280
50 #define WINTYPE_DEFAULT_Y 100
51 #define WINTYPE_DEFAULT_WIDTH 740
52 #define WINTYPE_DEFAULT_HEIGHT 640
53 #define WINTYPE_DEFAULT_NAVWIDTH 250
55 static const WCHAR szEmpty[] = {0};
57 typedef struct tagHHInfo
59 HH_WINTYPEW *pHHWinType;
69 extern HINSTANCE hhctrl_hinstance;
71 static LPWSTR HH_ANSIToUnicode(LPCSTR ansi)
76 count = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0);
77 unicode = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
78 MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, count);
83 /* Loads a string from the resource file */
84 static LPWSTR HH_LoadString(DWORD dwID)
89 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
90 iSize += 2; /* some strings (tab text) needs double-null termination */
92 string = HeapAlloc(GetProcessHeap(), 0, iSize * sizeof(WCHAR));
93 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
98 static BOOL NavigateToChm(WBInfo *pWBInfo, LPCWSTR file, LPCWSTR index)
100 WCHAR buf[INTERNET_MAX_URL_LENGTH];
101 WCHAR full_path[MAX_PATH];
104 static const WCHAR url_format[] =
105 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
107 if (!pWBInfo->pWebBrowser2)
110 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
111 WARN("GetFullPathName failed: %u\n", GetLastError());
115 wsprintfW(buf, url_format, full_path, index);
117 V_VT(&url) = VT_BSTR;
118 V_BSTR(&url) = SysAllocString(buf);
120 IWebBrowser2_Navigate2(pWBInfo->pWebBrowser2, &url, 0, 0, 0, 0);
128 #define SIZEBAR_WIDTH 4
130 static const WCHAR szSizeBarClass[] = {
131 'H','H',' ','S','i','z','e','B','a','r',0
134 /* Draw the SizeBar */
135 static void SB_OnPaint(HWND hWnd)
141 hdc = BeginPaint(hWnd, &ps);
143 GetClientRect(hWnd, &rc);
148 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
150 /* white highlight */
151 SelectObject(hdc, GetStockObject(WHITE_PEN));
152 MoveToEx(hdc, rc.right, 1, NULL);
154 LineTo(hdc, 1, rc.bottom - 1);
157 MoveToEx(hdc, 0, rc.bottom, NULL);
158 LineTo(hdc, rc.right, rc.bottom);
163 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
168 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
170 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
173 pt.x = (short)LOWORD(lParam);
174 pt.y = (short)HIWORD(lParam);
176 /* update the window sizes */
177 pHHInfo->pHHWinType->iNavWidth += pt.x;
183 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
185 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
186 if (!(wParam & MK_LBUTTON))
190 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
195 SB_OnLButtonDown(hWnd, wParam, lParam);
198 SB_OnLButtonUp(hWnd, wParam, lParam);
201 SB_OnMouseMove(hWnd, wParam, lParam);
207 return DefWindowProcW(hWnd, message, wParam, lParam);
213 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
217 wcex.cbSize = sizeof(WNDCLASSEXW);
219 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
222 wcex.hInstance = pHHInfo->hInstance;
223 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
224 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
225 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
226 wcex.lpszMenuName = NULL;
227 wcex.lpszClassName = szSizeBarClass;
228 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
230 RegisterClassExW(&wcex);
233 static void SB_GetSizeBarRect(HHInfo *pHHInfo, RECT *rc)
235 RECT rectWND, rectTB, rectNP;
237 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
238 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
239 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
241 rc->left = rectNP.right;
242 rc->top = rectTB.bottom;
243 rc->bottom = rectWND.bottom - rectTB.bottom;
244 rc->right = SIZEBAR_WIDTH;
247 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
250 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
251 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
252 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
255 SB_GetSizeBarRect(pHHInfo, &rc);
257 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
258 rc.left, rc.top, rc.right, rc.bottom,
259 hwndParent, NULL, pHHInfo->hInstance, NULL);
263 /* store the pointer to the HH info struct */
264 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
266 pHHInfo->hwndSizeBar = hWnd;
272 static const WCHAR szChildClass[] = {
273 'H','H',' ','C','h','i','l','d',0
276 static void Child_OnPaint(HWND hWnd)
282 hdc = BeginPaint(hWnd, &ps);
284 /* Only paint the Navigation pane, identified by the fact
285 * that it has a child window
287 if (GetWindow(hWnd, GW_CHILD))
289 GetClientRect(hWnd, &rc);
291 /* set the border color */
292 SelectObject(hdc, GetStockObject(DC_PEN));
293 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
295 /* Draw the top border */
296 LineTo(hdc, rc.right, 0);
298 SelectObject(hdc, GetStockObject(WHITE_PEN));
299 MoveToEx(hdc, 0, 1, NULL);
300 LineTo(hdc, rc.right, 1);
306 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
314 return DefWindowProcW(hWnd, message, wParam, lParam);
320 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
324 wcex.cbSize = sizeof(WNDCLASSEXW);
326 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
329 wcex.hInstance = pHHInfo->hInstance;
330 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
331 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
332 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
333 wcex.lpszMenuName = NULL;
334 wcex.lpszClassName = szChildClass;
335 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
337 RegisterClassExW(&wcex);
344 static void TB_OnClick(HWND hWnd, DWORD dwID)
346 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
351 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
354 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
357 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
360 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszHome);
363 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
370 case IDTB_BROWSE_FWD:
371 case IDTB_BROWSE_BACK:
382 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
384 /* FIXME: Load the correct button bitmaps */
385 pButtons[dwIndex].iBitmap = STD_PRINT;
386 pButtons[dwIndex].idCommand = dwID;
387 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
388 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
389 pButtons[dwIndex].dwData = 0;
390 pButtons[dwIndex].iString = 0;
393 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
397 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
398 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
400 if (dwButtonFlags & HHWIN_BUTTON_BACK)
401 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
403 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
404 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
406 if (dwButtonFlags & HHWIN_BUTTON_STOP)
407 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
409 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
410 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
412 if (dwButtonFlags & HHWIN_BUTTON_HOME)
413 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
415 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
416 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
418 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
419 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
421 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
422 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
424 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
425 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
427 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
428 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
430 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
431 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
433 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
434 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
436 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
437 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
440 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
443 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
445 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
447 DWORD dwStyles, dwExStyles;
448 DWORD dwNumButtons, dwIndex;
450 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PARAM_TB_FLAGS)
451 toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags;
453 toolbarFlags = HHWIN_DEF_BUTTONS;
455 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
457 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
458 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
459 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
461 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
462 0, 0, 0, 0, hwndParent, NULL,
463 pHHInfo->hInstance, NULL);
467 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
468 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
469 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
471 /* FIXME: Load correct icons for all buttons */
472 tbAB.hInst = HINST_COMMCTRL;
473 tbAB.nID = IDB_STD_LARGE_COLOR;
474 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
476 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
478 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
479 DWORD dwLen = strlenW(szBuf);
480 szBuf[dwLen + 2] = 0; /* Double-null terminate */
482 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
483 HeapFree(GetProcessHeap(), 0, szBuf);
486 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
487 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
488 ShowWindow(hToolbar, SW_SHOW);
490 pHHInfo->pHHWinType->hwndToolBar = hToolbar;
494 /* Navigation Pane */
496 #define TAB_TOP_PADDING 8
497 #define TAB_RIGHT_PADDING 4
499 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
501 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
502 HWND hwndToolbar = pHHInfo->pHHWinType->hwndToolBar;
503 RECT rectWND, rectTB;
505 GetClientRect(hwndParent, &rectWND);
506 GetClientRect(hwndToolbar, &rectTB);
509 rc->top = rectTB.bottom;
510 rc->bottom = rectWND.bottom - rectTB.bottom;
512 if (!(pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
513 pHHInfo->pHHWinType->iNavWidth == 0)
515 pHHInfo->pHHWinType->iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
518 rc->right = pHHInfo->pHHWinType->iNavWidth;
521 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
524 LPWSTR tabText = HH_LoadString(dwStrID);
526 tie.mask = TCIF_TEXT;
527 tie.pszText = tabText;
529 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
530 HeapFree(GetProcessHeap(), 0, tabText);
533 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
535 HWND hWnd, hwndTabCtrl;
536 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
537 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
538 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
542 NP_GetNavigationRect(pHHInfo, &rc);
544 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
545 rc.left, rc.top, rc.right, rc.bottom,
546 hwndParent, NULL, pHHInfo->hInstance, NULL);
550 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
552 rc.right - TAB_RIGHT_PADDING,
553 rc.bottom - TAB_TOP_PADDING,
554 hWnd, NULL, pHHInfo->hInstance, NULL);
558 if (*pHHInfo->pHHWinType->pszToc)
559 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
561 if (*pHHInfo->pHHWinType->pszIndex)
562 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
564 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_SEARCH)
565 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
567 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
568 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
570 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
572 pHHInfo->hwndTabCtrl = hwndTabCtrl;
573 pHHInfo->pHHWinType->hwndNavigation = hWnd;
579 static void HP_GetHTMLRect(HHInfo *pHHInfo, RECT *rc)
581 RECT rectTB, rectWND, rectNP, rectSB;
583 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
584 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
585 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
586 GetClientRect(pHHInfo->hwndSizeBar, &rectSB);
588 rc->left = rectNP.right + rectSB.right;
589 rc->top = rectTB.bottom;
590 rc->right = rectWND.right - rc->left;
591 rc->bottom = rectWND.bottom - rectTB.bottom;
594 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
597 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
598 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
599 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
602 HP_GetHTMLRect(pHHInfo, &rc);
604 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
605 rc.left, rc.top, rc.right, rc.bottom,
606 hwndParent, NULL, pHHInfo->hInstance, NULL);
610 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
613 /* store the pointer to the HH info struct */
614 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
616 ShowWindow(hWnd, SW_SHOW);
619 pHHInfo->pHHWinType->hwndHTML = hWnd;
625 static void Help_OnSize(HWND hWnd)
627 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
634 NP_GetNavigationRect(pHHInfo, &rc);
635 SetWindowPos(pHHInfo->pHHWinType->hwndNavigation, HWND_TOP, 0, 0,
636 rc.right, rc.bottom, SWP_NOMOVE);
638 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rc);
639 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
640 rc.right - TAB_RIGHT_PADDING,
641 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
643 SB_GetSizeBarRect(pHHInfo, &rc);
644 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
645 rc.right, rc.bottom, SWP_SHOWWINDOW);
647 HP_GetHTMLRect(pHHInfo, &rc);
648 SetWindowPos(pHHInfo->pHHWinType->hwndHTML, HWND_TOP, rc.left, rc.top,
649 rc.right, rc.bottom, SWP_SHOWWINDOW);
651 /* Resize browser window taking the frame size into account */
652 dwSize = GetSystemMetrics(SM_CXFRAME);
653 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
656 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
664 if (HIWORD(wParam) == BN_CLICKED)
665 TB_OnClick(hWnd, LOWORD(wParam));
671 hdc = BeginPaint(hWnd, &ps);
679 return DefWindowProcW(hWnd, message, wParam, lParam);
685 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
688 HINSTANCE hInstance = pHHInfo->hInstance;
689 RECT winPos = pHHInfo->pHHWinType->rcWindowPos;
691 DWORD dwStyles, dwExStyles;
692 DWORD x, y, width, height;
694 static const WCHAR windowClassW[] = {
695 'H','H',' ', 'P','a','r','e','n','t',0
698 wcex.cbSize = sizeof(WNDCLASSEXW);
699 wcex.style = CS_HREDRAW | CS_VREDRAW;
700 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
703 wcex.hInstance = hInstance;
704 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
705 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
706 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
707 wcex.lpszMenuName = NULL;
708 wcex.lpszClassName = windowClassW;
709 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
711 RegisterClassExW(&wcex);
713 /* Read in window parameters if available */
714 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_STYLES)
715 dwStyles = pHHInfo->pHHWinType->dwStyles;
717 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
718 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
720 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_EXSTYLES)
721 dwExStyles = pHHInfo->pHHWinType->dwExStyles;
723 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
724 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
726 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_RECT)
730 width = winPos.right - x;
731 height = winPos.bottom - y;
735 x = WINTYPE_DEFAULT_X;
736 y = WINTYPE_DEFAULT_Y;
737 width = WINTYPE_DEFAULT_WIDTH;
738 height = WINTYPE_DEFAULT_HEIGHT;
741 hWnd = CreateWindowExW(dwExStyles, windowClassW, pHHInfo->pHHWinType->pszCaption,
742 dwStyles, x, y, width, height, NULL, NULL, hInstance, NULL);
746 ShowWindow(hWnd, SW_SHOW);
749 /* store the pointer to the HH info struct */
750 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
752 pHHInfo->pHHWinType->hwndHelp = hWnd;
756 static void HH_CreateFont(HHInfo *pHHInfo)
760 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
761 lf.lfWeight = FW_NORMAL;
763 lf.lfUnderline = FALSE;
765 pHHInfo->hFont = CreateFontIndirectW(&lf);
768 static void HH_InitRequiredControls(DWORD dwControls)
770 INITCOMMONCONTROLSEX icex;
772 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
773 icex.dwICC = dwControls;
774 InitCommonControlsEx(&icex);
777 /* Creates the whole package */
778 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
780 HH_CreateFont(pHHInfo);
782 if (!HH_CreateHelpWindow(pHHInfo))
785 HH_InitRequiredControls(ICC_BAR_CLASSES);
787 if (!HH_AddToolbar(pHHInfo))
790 HH_RegisterChildWndClass(pHHInfo);
792 if (!HH_AddNavigationPane(pHHInfo))
795 HH_RegisterSizeBarClass(pHHInfo);
797 if (!HH_AddSizeBar(pHHInfo))
800 if (!HH_AddHTMLPane(pHHInfo))
806 static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPWSTR szCmdLine)
808 HHInfo *pHHInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HHInfo));
810 pHHInfo->pHHWinType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HH_WINTYPEW));
811 pHHInfo->pCHMInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo));
812 pHHInfo->pWBInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo));
813 pHHInfo->hInstance = hInstance;
814 pHHInfo->szCmdLine = szCmdLine;
819 static void HH_Close(HHInfo *pHHInfo)
824 /* Free allocated strings */
825 if (pHHInfo->pHHWinType)
827 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType);
828 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszCaption);
829 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszToc);
830 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszIndex);
831 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszFile);
832 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszHome);
833 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump1);
834 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump2);
835 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
836 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
839 HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType);
840 HeapFree(GetProcessHeap(), 0, pHHInfo->szCmdLine);
842 if (pHHInfo->pCHMInfo)
844 CHM_CloseCHM(pHHInfo->pCHMInfo);
845 HeapFree(GetProcessHeap(), 0, pHHInfo->pCHMInfo);
848 if (pHHInfo->pWBInfo)
850 WB_UnEmbedBrowser(pHHInfo->pWBInfo);
851 HeapFree(GetProcessHeap(), 0, pHHInfo->pWBInfo);
855 static BOOL HH_OpenCHM(HHInfo *pHHInfo)
857 if (!CHM_OpenCHM(pHHInfo->pCHMInfo, pHHInfo->szCmdLine))
860 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType))
866 /* FIXME: Check szCmdLine for bad arguments */
867 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
872 if (FAILED(OleInitialize(NULL)))
875 pHHInfo = HH_OpenHH(hInstance, HH_ANSIToUnicode(szCmdLine));
876 if (!pHHInfo || !HH_OpenCHM(pHHInfo) || !HH_CreateViewer(pHHInfo))
882 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszFile);
884 while (GetMessageW(&msg, 0, 0, 0))
886 TranslateMessage(&msg);
887 DispatchMessageW(&msg);
891 HeapFree(GetProcessHeap(), 0, pHHInfo);