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;
56 extern HINSTANCE hhctrl_hinstance;
58 /* Loads a string from the resource file */
59 static LPWSTR HH_LoadString(DWORD dwID)
64 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
65 iSize += 2; /* some strings (tab text) needs double-null termination */
67 string = hhctrl_alloc(iSize * sizeof(WCHAR));
68 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
73 static BOOL NavigateToChm(WBInfo *pWBInfo, LPCWSTR file, LPCWSTR index)
75 WCHAR buf[INTERNET_MAX_URL_LENGTH];
76 WCHAR full_path[MAX_PATH];
79 static const WCHAR url_format[] =
80 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
82 if (!pWBInfo->pWebBrowser2)
85 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
86 WARN("GetFullPathName failed: %u\n", GetLastError());
90 wsprintfW(buf, url_format, full_path, index);
93 V_BSTR(&url) = SysAllocString(buf);
95 IWebBrowser2_Navigate2(pWBInfo->pWebBrowser2, &url, 0, 0, 0, 0);
103 #define SIZEBAR_WIDTH 4
105 static const WCHAR szSizeBarClass[] = {
106 'H','H',' ','S','i','z','e','B','a','r',0
109 /* Draw the SizeBar */
110 static void SB_OnPaint(HWND hWnd)
116 hdc = BeginPaint(hWnd, &ps);
118 GetClientRect(hWnd, &rc);
123 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
125 /* white highlight */
126 SelectObject(hdc, GetStockObject(WHITE_PEN));
127 MoveToEx(hdc, rc.right, 1, NULL);
129 LineTo(hdc, 1, rc.bottom - 1);
132 MoveToEx(hdc, 0, rc.bottom, NULL);
133 LineTo(hdc, rc.right, rc.bottom);
138 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
143 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
145 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
148 pt.x = (short)LOWORD(lParam);
149 pt.y = (short)HIWORD(lParam);
151 /* update the window sizes */
152 pHHInfo->pHHWinType->iNavWidth += pt.x;
158 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
160 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
161 if (!(wParam & MK_LBUTTON))
165 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
170 SB_OnLButtonDown(hWnd, wParam, lParam);
173 SB_OnLButtonUp(hWnd, wParam, lParam);
176 SB_OnMouseMove(hWnd, wParam, lParam);
182 return DefWindowProcW(hWnd, message, wParam, lParam);
188 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
192 wcex.cbSize = sizeof(WNDCLASSEXW);
194 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
197 wcex.hInstance = hhctrl_hinstance;
198 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
199 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
200 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
201 wcex.lpszMenuName = NULL;
202 wcex.lpszClassName = szSizeBarClass;
203 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
205 RegisterClassExW(&wcex);
208 static void SB_GetSizeBarRect(HHInfo *pHHInfo, RECT *rc)
210 RECT rectWND, rectTB, rectNP;
212 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
213 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
214 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
216 rc->left = rectNP.right;
217 rc->top = rectTB.bottom;
218 rc->bottom = rectWND.bottom - rectTB.bottom;
219 rc->right = SIZEBAR_WIDTH;
222 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
225 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
226 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
227 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
230 SB_GetSizeBarRect(pHHInfo, &rc);
232 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
233 rc.left, rc.top, rc.right, rc.bottom,
234 hwndParent, NULL, hhctrl_hinstance, NULL);
238 /* store the pointer to the HH info struct */
239 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
241 pHHInfo->hwndSizeBar = hWnd;
247 static const WCHAR szChildClass[] = {
248 'H','H',' ','C','h','i','l','d',0
251 static void Child_OnPaint(HWND hWnd)
257 hdc = BeginPaint(hWnd, &ps);
259 /* Only paint the Navigation pane, identified by the fact
260 * that it has a child window
262 if (GetWindow(hWnd, GW_CHILD))
264 GetClientRect(hWnd, &rc);
266 /* set the border color */
267 SelectObject(hdc, GetStockObject(DC_PEN));
268 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
270 /* Draw the top border */
271 LineTo(hdc, rc.right, 0);
273 SelectObject(hdc, GetStockObject(WHITE_PEN));
274 MoveToEx(hdc, 0, 1, NULL);
275 LineTo(hdc, rc.right, 1);
281 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
289 return DefWindowProcW(hWnd, message, wParam, lParam);
295 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
299 wcex.cbSize = sizeof(WNDCLASSEXW);
301 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
304 wcex.hInstance = hhctrl_hinstance;
305 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
306 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
307 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
308 wcex.lpszMenuName = NULL;
309 wcex.lpszClassName = szChildClass;
310 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
312 RegisterClassExW(&wcex);
319 static void TB_OnClick(HWND hWnd, DWORD dwID)
321 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
326 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
329 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
332 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
335 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszHome);
338 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
345 case IDTB_BROWSE_FWD:
346 case IDTB_BROWSE_BACK:
357 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
359 /* FIXME: Load the correct button bitmaps */
360 pButtons[dwIndex].iBitmap = STD_PRINT;
361 pButtons[dwIndex].idCommand = dwID;
362 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
363 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
364 pButtons[dwIndex].dwData = 0;
365 pButtons[dwIndex].iString = 0;
368 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
372 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
373 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
375 if (dwButtonFlags & HHWIN_BUTTON_BACK)
376 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
378 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
379 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
381 if (dwButtonFlags & HHWIN_BUTTON_STOP)
382 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
384 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
385 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
387 if (dwButtonFlags & HHWIN_BUTTON_HOME)
388 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
390 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
391 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
393 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
394 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
396 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
397 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
399 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
400 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
402 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
403 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
405 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
406 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
408 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
409 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
411 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
412 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
415 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
418 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
420 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
422 DWORD dwStyles, dwExStyles;
423 DWORD dwNumButtons, dwIndex;
425 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PARAM_TB_FLAGS)
426 toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags;
428 toolbarFlags = HHWIN_DEF_BUTTONS;
430 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
432 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
433 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
434 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
436 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
437 0, 0, 0, 0, hwndParent, NULL,
438 hhctrl_hinstance, NULL);
442 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
443 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
444 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
446 /* FIXME: Load correct icons for all buttons */
447 tbAB.hInst = HINST_COMMCTRL;
448 tbAB.nID = IDB_STD_LARGE_COLOR;
449 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
451 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
453 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
454 DWORD dwLen = strlenW(szBuf);
455 szBuf[dwLen + 2] = 0; /* Double-null terminate */
457 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
461 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
462 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
463 ShowWindow(hToolbar, SW_SHOW);
465 pHHInfo->pHHWinType->hwndToolBar = hToolbar;
469 /* Navigation Pane */
471 #define TAB_TOP_PADDING 8
472 #define TAB_RIGHT_PADDING 4
474 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
476 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
477 HWND hwndToolbar = pHHInfo->pHHWinType->hwndToolBar;
478 RECT rectWND, rectTB;
480 GetClientRect(hwndParent, &rectWND);
481 GetClientRect(hwndToolbar, &rectTB);
484 rc->top = rectTB.bottom;
485 rc->bottom = rectWND.bottom - rectTB.bottom;
487 if (!(pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
488 pHHInfo->pHHWinType->iNavWidth == 0)
490 pHHInfo->pHHWinType->iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
493 rc->right = pHHInfo->pHHWinType->iNavWidth;
496 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
499 LPWSTR tabText = HH_LoadString(dwStrID);
501 tie.mask = TCIF_TEXT;
502 tie.pszText = tabText;
504 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
505 hhctrl_free(tabText);
508 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
510 HWND hWnd, hwndTabCtrl;
511 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
512 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
513 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
517 NP_GetNavigationRect(pHHInfo, &rc);
519 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
520 rc.left, rc.top, rc.right, rc.bottom,
521 hwndParent, NULL, hhctrl_hinstance, NULL);
525 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
527 rc.right - TAB_RIGHT_PADDING,
528 rc.bottom - TAB_TOP_PADDING,
529 hWnd, NULL, hhctrl_hinstance, NULL);
533 if (*pHHInfo->pHHWinType->pszToc)
534 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
536 if (*pHHInfo->pHHWinType->pszIndex)
537 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
539 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_SEARCH)
540 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
542 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
543 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
545 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
547 pHHInfo->hwndTabCtrl = hwndTabCtrl;
548 pHHInfo->pHHWinType->hwndNavigation = hWnd;
554 static void HP_GetHTMLRect(HHInfo *pHHInfo, RECT *rc)
556 RECT rectTB, rectWND, rectNP, rectSB;
558 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
559 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
560 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
561 GetClientRect(pHHInfo->hwndSizeBar, &rectSB);
563 rc->left = rectNP.right + rectSB.right;
564 rc->top = rectTB.bottom;
565 rc->right = rectWND.right - rc->left;
566 rc->bottom = rectWND.bottom - rectTB.bottom;
569 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
572 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
573 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
574 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
577 HP_GetHTMLRect(pHHInfo, &rc);
579 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
580 rc.left, rc.top, rc.right, rc.bottom,
581 hwndParent, NULL, hhctrl_hinstance, NULL);
585 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
588 /* store the pointer to the HH info struct */
589 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
591 ShowWindow(hWnd, SW_SHOW);
594 pHHInfo->pHHWinType->hwndHTML = hWnd;
600 static void Help_OnSize(HWND hWnd)
602 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
609 NP_GetNavigationRect(pHHInfo, &rc);
610 SetWindowPos(pHHInfo->pHHWinType->hwndNavigation, HWND_TOP, 0, 0,
611 rc.right, rc.bottom, SWP_NOMOVE);
613 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rc);
614 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
615 rc.right - TAB_RIGHT_PADDING,
616 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
618 SB_GetSizeBarRect(pHHInfo, &rc);
619 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
620 rc.right, rc.bottom, SWP_SHOWWINDOW);
622 HP_GetHTMLRect(pHHInfo, &rc);
623 SetWindowPos(pHHInfo->pHHWinType->hwndHTML, HWND_TOP, rc.left, rc.top,
624 rc.right, rc.bottom, SWP_SHOWWINDOW);
626 /* Resize browser window taking the frame size into account */
627 dwSize = GetSystemMetrics(SM_CXFRAME);
628 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
631 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
639 if (HIWORD(wParam) == BN_CLICKED)
640 TB_OnClick(hWnd, LOWORD(wParam));
646 hdc = BeginPaint(hWnd, &ps);
654 return DefWindowProcW(hWnd, message, wParam, lParam);
660 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
663 RECT winPos = pHHInfo->pHHWinType->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 = (WNDPROC)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 (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_STYLES)
689 dwStyles = pHHInfo->pHHWinType->dwStyles;
691 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
692 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
694 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_EXSTYLES)
695 dwExStyles = pHHInfo->pHHWinType->dwExStyles;
697 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
698 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
700 if (pHHInfo->pHHWinType->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, pHHInfo->pHHWinType->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)pHHInfo);
726 pHHInfo->pHHWinType->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 HH_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 static void HH_Close(HHInfo *pHHInfo)
785 /* Free allocated strings */
786 if (pHHInfo->pHHWinType)
788 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszType);
789 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszCaption);
790 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszToc);
791 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszIndex);
792 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszFile);
793 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszHome);
794 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump1);
795 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszJump2);
796 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
797 hhctrl_free((LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
800 hhctrl_free(pHHInfo->pHHWinType);
802 if (pHHInfo->pCHMInfo)
803 CloseCHM(pHHInfo->pCHMInfo);
805 if (pHHInfo->pWBInfo)
807 WB_UnEmbedBrowser(pHHInfo->pWBInfo);
808 hhctrl_free(pHHInfo->pWBInfo);
812 static HHInfo *HH_OpenHH(LPWSTR filename)
814 HHInfo *pHHInfo = hhctrl_alloc_zero(sizeof(HHInfo));
816 pHHInfo->pCHMInfo = OpenCHM(filename);
817 if(!pHHInfo->pCHMInfo) {
822 pHHInfo->pHHWinType = hhctrl_alloc_zero(sizeof(HH_WINTYPEW));
823 pHHInfo->pWBInfo = hhctrl_alloc(sizeof(WBInfo));
825 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType)) {
833 /* FIXME: Check szCmdLine for bad arguments */
834 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
839 if (FAILED(OleInitialize(NULL)))
842 pHHInfo = HH_OpenHH(strdupAtoW(szCmdLine));
843 if (!pHHInfo || !HH_CreateViewer(pHHInfo))
849 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszFile);
851 while (GetMessageW(&msg, 0, 0, 0))
853 TranslateMessage(&msg);
854 DispatchMessageW(&msg);
858 hhctrl_free(pHHInfo);