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;
58 extern HINSTANCE hhctrl_hinstance;
60 static LPWSTR HH_ANSIToUnicode(LPCSTR ansi)
65 count = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0);
66 unicode = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
67 MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, count);
72 /* Loads a string from the resource file */
73 static LPWSTR HH_LoadString(DWORD dwID)
78 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
79 iSize += 2; /* some strings (tab text) needs double-null termination */
81 string = HeapAlloc(GetProcessHeap(), 0, iSize * sizeof(WCHAR));
82 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
87 static BOOL NavigateToChm(WBInfo *pWBInfo, LPCWSTR file, LPCWSTR index)
89 WCHAR buf[INTERNET_MAX_URL_LENGTH];
90 WCHAR full_path[MAX_PATH];
93 static const WCHAR url_format[] =
94 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
96 if (!pWBInfo->pWebBrowser2)
99 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
100 WARN("GetFullPathName failed: %u\n", GetLastError());
104 wsprintfW(buf, url_format, full_path, index);
106 V_VT(&url) = VT_BSTR;
107 V_BSTR(&url) = SysAllocString(buf);
109 IWebBrowser2_Navigate2(pWBInfo->pWebBrowser2, &url, 0, 0, 0, 0);
117 #define SIZEBAR_WIDTH 4
119 static const WCHAR szSizeBarClass[] = {
120 'H','H',' ','S','i','z','e','B','a','r',0
123 /* Draw the SizeBar */
124 static void SB_OnPaint(HWND hWnd)
130 hdc = BeginPaint(hWnd, &ps);
132 GetClientRect(hWnd, &rc);
137 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
139 /* white highlight */
140 SelectObject(hdc, GetStockObject(WHITE_PEN));
141 MoveToEx(hdc, rc.right, 1, NULL);
143 LineTo(hdc, 1, rc.bottom - 1);
146 MoveToEx(hdc, 0, rc.bottom, NULL);
147 LineTo(hdc, rc.right, rc.bottom);
152 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
157 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
159 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
162 pt.x = (short)LOWORD(lParam);
163 pt.y = (short)HIWORD(lParam);
165 /* update the window sizes */
166 pHHInfo->pHHWinType->iNavWidth += pt.x;
172 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
174 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
175 if (!(wParam & MK_LBUTTON))
179 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
184 SB_OnLButtonDown(hWnd, wParam, lParam);
187 SB_OnLButtonUp(hWnd, wParam, lParam);
190 SB_OnMouseMove(hWnd, wParam, lParam);
196 return DefWindowProcW(hWnd, message, wParam, lParam);
202 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
206 wcex.cbSize = sizeof(WNDCLASSEXW);
208 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
211 wcex.hInstance = pHHInfo->hInstance;
212 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
213 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
214 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
215 wcex.lpszMenuName = NULL;
216 wcex.lpszClassName = szSizeBarClass;
217 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
219 RegisterClassExW(&wcex);
222 static void SB_GetSizeBarRect(HHInfo *pHHInfo, RECT *rc)
224 RECT rectWND, rectTB, rectNP;
226 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
227 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
228 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
230 rc->left = rectNP.right;
231 rc->top = rectTB.bottom;
232 rc->bottom = rectWND.bottom - rectTB.bottom;
233 rc->right = SIZEBAR_WIDTH;
236 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
239 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
240 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
241 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
244 SB_GetSizeBarRect(pHHInfo, &rc);
246 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
247 rc.left, rc.top, rc.right, rc.bottom,
248 hwndParent, NULL, pHHInfo->hInstance, NULL);
252 /* store the pointer to the HH info struct */
253 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
255 pHHInfo->hwndSizeBar = hWnd;
261 static const WCHAR szChildClass[] = {
262 'H','H',' ','C','h','i','l','d',0
265 static void Child_OnPaint(HWND hWnd)
271 hdc = BeginPaint(hWnd, &ps);
273 /* Only paint the Navigation pane, identified by the fact
274 * that it has a child window
276 if (GetWindow(hWnd, GW_CHILD))
278 GetClientRect(hWnd, &rc);
280 /* set the border color */
281 SelectObject(hdc, GetStockObject(DC_PEN));
282 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
284 /* Draw the top border */
285 LineTo(hdc, rc.right, 0);
287 SelectObject(hdc, GetStockObject(WHITE_PEN));
288 MoveToEx(hdc, 0, 1, NULL);
289 LineTo(hdc, rc.right, 1);
295 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
303 return DefWindowProcW(hWnd, message, wParam, lParam);
309 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
313 wcex.cbSize = sizeof(WNDCLASSEXW);
315 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
318 wcex.hInstance = pHHInfo->hInstance;
319 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
320 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
321 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
322 wcex.lpszMenuName = NULL;
323 wcex.lpszClassName = szChildClass;
324 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
326 RegisterClassExW(&wcex);
333 static void TB_OnClick(HWND hWnd, DWORD dwID)
335 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
340 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
343 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
346 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
349 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszHome);
352 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
359 case IDTB_BROWSE_FWD:
360 case IDTB_BROWSE_BACK:
371 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
373 /* FIXME: Load the correct button bitmaps */
374 pButtons[dwIndex].iBitmap = STD_PRINT;
375 pButtons[dwIndex].idCommand = dwID;
376 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
377 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
378 pButtons[dwIndex].dwData = 0;
379 pButtons[dwIndex].iString = 0;
382 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
386 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
387 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
389 if (dwButtonFlags & HHWIN_BUTTON_BACK)
390 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
392 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
393 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
395 if (dwButtonFlags & HHWIN_BUTTON_STOP)
396 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
398 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
399 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
401 if (dwButtonFlags & HHWIN_BUTTON_HOME)
402 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
404 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
405 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
407 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
408 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
410 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
411 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
413 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
414 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
416 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
417 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
419 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
420 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
422 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
423 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
425 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
426 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
429 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
432 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
434 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
436 DWORD dwStyles, dwExStyles;
437 DWORD dwNumButtons, dwIndex;
439 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PARAM_TB_FLAGS)
440 toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags;
442 toolbarFlags = HHWIN_DEF_BUTTONS;
444 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
446 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
447 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
448 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
450 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
451 0, 0, 0, 0, hwndParent, NULL,
452 pHHInfo->hInstance, NULL);
456 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
457 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
458 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
460 /* FIXME: Load correct icons for all buttons */
461 tbAB.hInst = HINST_COMMCTRL;
462 tbAB.nID = IDB_STD_LARGE_COLOR;
463 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
465 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
467 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
468 DWORD dwLen = strlenW(szBuf);
469 szBuf[dwLen + 2] = 0; /* Double-null terminate */
471 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
472 HeapFree(GetProcessHeap(), 0, szBuf);
475 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
476 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
477 ShowWindow(hToolbar, SW_SHOW);
479 pHHInfo->pHHWinType->hwndToolBar = hToolbar;
483 /* Navigation Pane */
485 #define TAB_TOP_PADDING 8
486 #define TAB_RIGHT_PADDING 4
488 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
490 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
491 HWND hwndToolbar = pHHInfo->pHHWinType->hwndToolBar;
492 RECT rectWND, rectTB;
494 GetClientRect(hwndParent, &rectWND);
495 GetClientRect(hwndToolbar, &rectTB);
498 rc->top = rectTB.bottom;
499 rc->bottom = rectWND.bottom - rectTB.bottom;
501 if (!(pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
502 pHHInfo->pHHWinType->iNavWidth == 0)
504 pHHInfo->pHHWinType->iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
507 rc->right = pHHInfo->pHHWinType->iNavWidth;
510 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
513 LPWSTR tabText = HH_LoadString(dwStrID);
515 tie.mask = TCIF_TEXT;
516 tie.pszText = tabText;
518 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
519 HeapFree(GetProcessHeap(), 0, tabText);
522 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
524 HWND hWnd, hwndTabCtrl;
525 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
526 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
527 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
531 NP_GetNavigationRect(pHHInfo, &rc);
533 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
534 rc.left, rc.top, rc.right, rc.bottom,
535 hwndParent, NULL, pHHInfo->hInstance, NULL);
539 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
541 rc.right - TAB_RIGHT_PADDING,
542 rc.bottom - TAB_TOP_PADDING,
543 hWnd, NULL, pHHInfo->hInstance, NULL);
547 if (*pHHInfo->pHHWinType->pszToc)
548 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
550 if (*pHHInfo->pHHWinType->pszIndex)
551 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
553 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_SEARCH)
554 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
556 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
557 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
559 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
561 pHHInfo->hwndTabCtrl = hwndTabCtrl;
562 pHHInfo->pHHWinType->hwndNavigation = hWnd;
568 static void HP_GetHTMLRect(HHInfo *pHHInfo, RECT *rc)
570 RECT rectTB, rectWND, rectNP, rectSB;
572 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
573 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
574 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
575 GetClientRect(pHHInfo->hwndSizeBar, &rectSB);
577 rc->left = rectNP.right + rectSB.right;
578 rc->top = rectTB.bottom;
579 rc->right = rectWND.right - rc->left;
580 rc->bottom = rectWND.bottom - rectTB.bottom;
583 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
586 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
587 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
588 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
591 HP_GetHTMLRect(pHHInfo, &rc);
593 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
594 rc.left, rc.top, rc.right, rc.bottom,
595 hwndParent, NULL, pHHInfo->hInstance, NULL);
599 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
602 /* store the pointer to the HH info struct */
603 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
605 ShowWindow(hWnd, SW_SHOW);
608 pHHInfo->pHHWinType->hwndHTML = hWnd;
614 static void Help_OnSize(HWND hWnd)
616 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
623 NP_GetNavigationRect(pHHInfo, &rc);
624 SetWindowPos(pHHInfo->pHHWinType->hwndNavigation, HWND_TOP, 0, 0,
625 rc.right, rc.bottom, SWP_NOMOVE);
627 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rc);
628 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
629 rc.right - TAB_RIGHT_PADDING,
630 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
632 SB_GetSizeBarRect(pHHInfo, &rc);
633 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
634 rc.right, rc.bottom, SWP_SHOWWINDOW);
636 HP_GetHTMLRect(pHHInfo, &rc);
637 SetWindowPos(pHHInfo->pHHWinType->hwndHTML, HWND_TOP, rc.left, rc.top,
638 rc.right, rc.bottom, SWP_SHOWWINDOW);
640 /* Resize browser window taking the frame size into account */
641 dwSize = GetSystemMetrics(SM_CXFRAME);
642 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
645 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
653 if (HIWORD(wParam) == BN_CLICKED)
654 TB_OnClick(hWnd, LOWORD(wParam));
660 hdc = BeginPaint(hWnd, &ps);
668 return DefWindowProcW(hWnd, message, wParam, lParam);
674 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
677 HINSTANCE hInstance = pHHInfo->hInstance;
678 RECT winPos = pHHInfo->pHHWinType->rcWindowPos;
680 DWORD dwStyles, dwExStyles;
681 DWORD x, y, width, height;
683 static const WCHAR windowClassW[] = {
684 'H','H',' ', 'P','a','r','e','n','t',0
687 wcex.cbSize = sizeof(WNDCLASSEXW);
688 wcex.style = CS_HREDRAW | CS_VREDRAW;
689 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
692 wcex.hInstance = hInstance;
693 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
694 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
695 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
696 wcex.lpszMenuName = NULL;
697 wcex.lpszClassName = windowClassW;
698 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
700 RegisterClassExW(&wcex);
702 /* Read in window parameters if available */
703 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_STYLES)
704 dwStyles = pHHInfo->pHHWinType->dwStyles;
706 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
707 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
709 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_EXSTYLES)
710 dwExStyles = pHHInfo->pHHWinType->dwExStyles;
712 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
713 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
715 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_RECT)
719 width = winPos.right - x;
720 height = winPos.bottom - y;
724 x = WINTYPE_DEFAULT_X;
725 y = WINTYPE_DEFAULT_Y;
726 width = WINTYPE_DEFAULT_WIDTH;
727 height = WINTYPE_DEFAULT_HEIGHT;
730 hWnd = CreateWindowExW(dwExStyles, windowClassW, pHHInfo->pHHWinType->pszCaption,
731 dwStyles, x, y, width, height, NULL, NULL, hInstance, NULL);
735 ShowWindow(hWnd, SW_SHOW);
738 /* store the pointer to the HH info struct */
739 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
741 pHHInfo->pHHWinType->hwndHelp = hWnd;
745 static void HH_CreateFont(HHInfo *pHHInfo)
749 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
750 lf.lfWeight = FW_NORMAL;
752 lf.lfUnderline = FALSE;
754 pHHInfo->hFont = CreateFontIndirectW(&lf);
757 static void HH_InitRequiredControls(DWORD dwControls)
759 INITCOMMONCONTROLSEX icex;
761 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
762 icex.dwICC = dwControls;
763 InitCommonControlsEx(&icex);
766 /* Creates the whole package */
767 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
769 HH_CreateFont(pHHInfo);
771 if (!HH_CreateHelpWindow(pHHInfo))
774 HH_InitRequiredControls(ICC_BAR_CLASSES);
776 if (!HH_AddToolbar(pHHInfo))
779 HH_RegisterChildWndClass(pHHInfo);
781 if (!HH_AddNavigationPane(pHHInfo))
784 HH_RegisterSizeBarClass(pHHInfo);
786 if (!HH_AddSizeBar(pHHInfo))
789 if (!HH_AddHTMLPane(pHHInfo))
795 static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPWSTR szCmdLine)
797 HHInfo *pHHInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HHInfo));
799 pHHInfo->pHHWinType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HH_WINTYPEW));
800 pHHInfo->pCHMInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo));
801 pHHInfo->pWBInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo));
802 pHHInfo->hInstance = hInstance;
803 pHHInfo->szCmdLine = szCmdLine;
808 static void HH_Close(HHInfo *pHHInfo)
813 /* Free allocated strings */
814 if (pHHInfo->pHHWinType)
816 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType);
817 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszCaption);
818 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszToc);
819 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszIndex);
820 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszFile);
821 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszHome);
822 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump1);
823 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump2);
824 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
825 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
828 HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType);
829 HeapFree(GetProcessHeap(), 0, pHHInfo->szCmdLine);
831 if (pHHInfo->pCHMInfo)
833 CHM_CloseCHM(pHHInfo->pCHMInfo);
834 HeapFree(GetProcessHeap(), 0, pHHInfo->pCHMInfo);
837 if (pHHInfo->pWBInfo)
839 WB_UnEmbedBrowser(pHHInfo->pWBInfo);
840 HeapFree(GetProcessHeap(), 0, pHHInfo->pWBInfo);
844 static BOOL HH_OpenCHM(HHInfo *pHHInfo)
846 if (!CHM_OpenCHM(pHHInfo->pCHMInfo, pHHInfo->szCmdLine))
849 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType))
855 /* FIXME: Check szCmdLine for bad arguments */
856 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
861 if (FAILED(OleInitialize(NULL)))
864 pHHInfo = HH_OpenHH(hInstance, HH_ANSIToUnicode(szCmdLine));
865 if (!pHHInfo || !HH_OpenCHM(pHHInfo) || !HH_CreateViewer(pHHInfo))
871 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszFile);
873 while (GetMessageW(&msg, 0, 0, 0))
875 TranslateMessage(&msg);
876 DispatchMessageW(&msg);
880 HeapFree(GetProcessHeap(), 0, pHHInfo);