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
31 #include "wine/unicode.h"
35 #include "webbrowser.h"
37 static void Help_OnSize(HWND hWnd);
39 /* Window type defaults */
41 #define WINTYPE_DEFAULT_X 280
42 #define WINTYPE_DEFAULT_Y 100
43 #define WINTYPE_DEFAULT_WIDTH 740
44 #define WINTYPE_DEFAULT_HEIGHT 640
45 #define WINTYPE_DEFAULT_NAVWIDTH 250
47 static const WCHAR szEmpty[] = {0};
49 typedef struct tagHHInfo
51 HH_WINTYPEW *pHHWinType;
61 extern HINSTANCE hhctrl_hinstance;
63 static LPWSTR HH_ANSIToUnicode(LPCSTR ansi)
68 count = MultiByteToWideChar(CP_ACP, 0, ansi, -1, NULL, 0);
69 unicode = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
70 MultiByteToWideChar(CP_ACP, 0, ansi, -1, unicode, count);
75 /* Loads a string from the resource file */
76 static LPWSTR HH_LoadString(DWORD dwID)
81 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
82 iSize += 2; /* some strings (tab text) needs double-null termination */
84 string = HeapAlloc(GetProcessHeap(), 0, iSize * sizeof(WCHAR));
85 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
92 #define SIZEBAR_WIDTH 4
94 static const WCHAR szSizeBarClass[] = {
95 'H','H',' ','S','i','z','e','B','a','r',0
98 /* Draw the SizeBar */
99 static void SB_OnPaint(HWND hWnd)
105 hdc = BeginPaint(hWnd, &ps);
107 GetClientRect(hWnd, &rc);
112 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
114 /* white highlight */
115 SelectObject(hdc, GetStockObject(WHITE_PEN));
116 MoveToEx(hdc, rc.right, 1, NULL);
118 LineTo(hdc, 1, rc.bottom - 1);
121 MoveToEx(hdc, 0, rc.bottom, NULL);
122 LineTo(hdc, rc.right, rc.bottom);
127 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
132 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
134 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
135 POINTS pt = MAKEPOINTS(lParam);
137 /* update the window sizes */
138 pHHInfo->pHHWinType->iNavWidth += pt.x;
144 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
146 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
147 if (!(wParam & MK_LBUTTON))
151 LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
156 SB_OnLButtonDown(hWnd, wParam, lParam);
159 SB_OnLButtonUp(hWnd, wParam, lParam);
162 SB_OnMouseMove(hWnd, wParam, lParam);
168 return DefWindowProcW(hWnd, message, wParam, lParam);
174 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
178 wcex.cbSize = sizeof(WNDCLASSEXW);
180 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
183 wcex.hInstance = pHHInfo->hInstance;
184 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
185 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
186 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
187 wcex.lpszMenuName = NULL;
188 wcex.lpszClassName = szSizeBarClass;
189 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
191 RegisterClassExW(&wcex);
194 static void SB_GetSizeBarRect(HHInfo *pHHInfo, RECT *rc)
196 RECT rectWND, rectTB, rectNP;
198 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
199 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
200 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
202 rc->left = rectNP.right;
203 rc->top = rectTB.bottom;
204 rc->bottom = rectWND.bottom - rectTB.bottom;
205 rc->right = SIZEBAR_WIDTH;
208 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
211 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
212 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
213 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
216 SB_GetSizeBarRect(pHHInfo, &rc);
218 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
219 rc.left, rc.top, rc.right, rc.bottom,
220 hwndParent, NULL, pHHInfo->hInstance, NULL);
224 /* store the pointer to the HH info struct */
225 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
227 pHHInfo->hwndSizeBar = hWnd;
233 static const WCHAR szChildClass[] = {
234 'H','H',' ','C','h','i','l','d',0
237 static void Child_OnPaint(HWND hWnd)
243 hdc = BeginPaint(hWnd, &ps);
245 /* Only paint the Navigation pane, identified by the fact
246 * that it has a child window
248 if (GetWindow(hWnd, GW_CHILD))
250 GetClientRect(hWnd, &rc);
252 /* set the border color */
253 SelectObject(hdc, GetStockObject(DC_PEN));
254 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
256 /* Draw the top border */
257 LineTo(hdc, rc.right, 0);
259 SelectObject(hdc, GetStockObject(WHITE_PEN));
260 MoveToEx(hdc, 0, 1, NULL);
261 LineTo(hdc, rc.right, 1);
267 LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
275 return DefWindowProcW(hWnd, message, wParam, lParam);
281 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
285 wcex.cbSize = sizeof(WNDCLASSEXW);
287 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
290 wcex.hInstance = pHHInfo->hInstance;
291 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
292 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
293 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
294 wcex.lpszMenuName = NULL;
295 wcex.lpszClassName = szChildClass;
296 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
298 RegisterClassExW(&wcex);
305 static void TB_OnClick(HWND hWnd, DWORD dwID)
307 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
312 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
315 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
318 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
322 WCHAR szUrl[MAX_PATH];
324 CHM_CreateITSUrl(pHHInfo->pCHMInfo, pHHInfo->pHHWinType->pszHome, szUrl);
325 WB_Navigate(pHHInfo->pWBInfo, szUrl);
329 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
336 case IDTB_BROWSE_FWD:
337 case IDTB_BROWSE_BACK:
348 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
350 /* FIXME: Load the correct button bitmaps */
351 pButtons[dwIndex].iBitmap = STD_PRINT;
352 pButtons[dwIndex].idCommand = dwID;
353 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
354 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
355 pButtons[dwIndex].dwData = 0;
356 pButtons[dwIndex].iString = 0;
359 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
363 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
364 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
366 if (dwButtonFlags & HHWIN_BUTTON_BACK)
367 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
369 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
370 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
372 if (dwButtonFlags & HHWIN_BUTTON_STOP)
373 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
375 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
376 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
378 if (dwButtonFlags & HHWIN_BUTTON_HOME)
379 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
381 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
382 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
384 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
385 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
387 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
388 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
390 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
391 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
393 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
394 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
396 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
397 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
399 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
400 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
402 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
403 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
406 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
409 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
411 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
413 DWORD dwStyles, dwExStyles;
414 DWORD dwNumButtons, dwIndex;
416 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PARAM_TB_FLAGS)
417 toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags;
419 toolbarFlags = HHWIN_DEF_BUTTONS;
421 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
423 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
424 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
425 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
427 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
428 0, 0, 0, 0, hwndParent, NULL,
429 pHHInfo->hInstance, NULL);
433 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
434 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
435 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
437 /* FIXME: Load correct icons for all buttons */
438 tbAB.hInst = HINST_COMMCTRL;
439 tbAB.nID = IDB_STD_LARGE_COLOR;
440 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
442 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
444 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
445 DWORD dwLen = strlenW(szBuf);
446 szBuf[dwLen + 2] = 0; /* Double-null terminate */
448 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
449 HeapFree(GetProcessHeap(), 0, szBuf);
452 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
453 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
454 ShowWindow(hToolbar, SW_SHOW);
456 pHHInfo->pHHWinType->hwndToolBar = hToolbar;
460 /* Navigation Pane */
462 #define TAB_TOP_PADDING 8
463 #define TAB_RIGHT_PADDING 4
465 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
467 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
468 HWND hwndToolbar = pHHInfo->pHHWinType->hwndToolBar;
469 RECT rectWND, rectTB;
471 GetClientRect(hwndParent, &rectWND);
472 GetClientRect(hwndToolbar, &rectTB);
475 rc->top = rectTB.bottom;
476 rc->bottom = rectWND.bottom - rectTB.bottom;
478 if (!(pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
479 pHHInfo->pHHWinType->iNavWidth == 0)
481 pHHInfo->pHHWinType->iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
484 rc->right = pHHInfo->pHHWinType->iNavWidth;
487 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
490 LPWSTR tabText = HH_LoadString(dwStrID);
492 tie.mask = TCIF_TEXT;
493 tie.pszText = tabText;
495 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
496 HeapFree(GetProcessHeap(), 0, tabText);
499 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
501 HWND hWnd, hwndTabCtrl;
502 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
503 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
504 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
508 NP_GetNavigationRect(pHHInfo, &rc);
510 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
511 rc.left, rc.top, rc.right, rc.bottom,
512 hwndParent, NULL, pHHInfo->hInstance, NULL);
516 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
518 rc.right - TAB_RIGHT_PADDING,
519 rc.bottom - TAB_TOP_PADDING,
520 hWnd, NULL, pHHInfo->hInstance, NULL);
524 if (*pHHInfo->pHHWinType->pszToc)
525 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
527 if (*pHHInfo->pHHWinType->pszIndex)
528 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
530 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_SEARCH)
531 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
533 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
534 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
536 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
538 pHHInfo->hwndTabCtrl = hwndTabCtrl;
539 pHHInfo->pHHWinType->hwndNavigation = hWnd;
545 static void HP_GetHTMLRect(HHInfo *pHHInfo, RECT *rc)
547 RECT rectTB, rectWND, rectNP, rectSB;
549 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
550 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
551 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
552 GetClientRect(pHHInfo->hwndSizeBar, &rectSB);
554 rc->left = rectNP.right + rectSB.right;
555 rc->top = rectTB.bottom;
556 rc->right = rectWND.right - rc->left;
557 rc->bottom = rectWND.bottom - rectTB.bottom;
560 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
563 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
564 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
565 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
568 HP_GetHTMLRect(pHHInfo, &rc);
570 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
571 rc.left, rc.top, rc.right, rc.bottom,
572 hwndParent, NULL, pHHInfo->hInstance, NULL);
576 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
579 /* store the pointer to the HH info struct */
580 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
582 ShowWindow(hWnd, SW_SHOW);
585 pHHInfo->pHHWinType->hwndHTML = hWnd;
591 static void Help_OnSize(HWND hWnd)
593 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
600 NP_GetNavigationRect(pHHInfo, &rc);
601 SetWindowPos(pHHInfo->pHHWinType->hwndNavigation, HWND_TOP, 0, 0,
602 rc.right, rc.bottom, SWP_NOMOVE);
604 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rc);
605 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
606 rc.right - TAB_RIGHT_PADDING,
607 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
609 SB_GetSizeBarRect(pHHInfo, &rc);
610 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
611 rc.right, rc.bottom, SWP_SHOWWINDOW);
613 HP_GetHTMLRect(pHHInfo, &rc);
614 SetWindowPos(pHHInfo->pHHWinType->hwndHTML, HWND_TOP, rc.left, rc.top,
615 rc.right, rc.bottom, SWP_SHOWWINDOW);
617 /* Resize browser window taking the frame size into account */
618 dwSize = GetSystemMetrics(SM_CXFRAME);
619 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
622 LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
630 if (HIWORD(wParam) == BN_CLICKED)
631 TB_OnClick(hWnd, LOWORD(wParam));
637 hdc = BeginPaint(hWnd, &ps);
645 return DefWindowProcW(hWnd, message, wParam, lParam);
651 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
654 HINSTANCE hInstance = pHHInfo->hInstance;
655 RECT winPos = pHHInfo->pHHWinType->rcWindowPos;
657 DWORD dwStyles, dwExStyles;
658 DWORD x, y, width, height;
660 static const WCHAR windowClassW[] = {
661 'H','H',' ', 'P','a','r','e','n','t',0
664 wcex.cbSize = sizeof(WNDCLASSEXW);
665 wcex.style = CS_HREDRAW | CS_VREDRAW;
666 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
669 wcex.hInstance = hInstance;
670 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
671 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
672 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
673 wcex.lpszMenuName = NULL;
674 wcex.lpszClassName = windowClassW;
675 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
677 RegisterClassExW(&wcex);
679 /* Read in window parameters if available */
680 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_STYLES)
681 dwStyles = pHHInfo->pHHWinType->dwStyles;
683 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
684 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
686 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_EXSTYLES)
687 dwExStyles = pHHInfo->pHHWinType->dwExStyles;
689 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
690 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
692 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_RECT)
696 width = winPos.right - x;
697 height = winPos.bottom - y;
701 x = WINTYPE_DEFAULT_X;
702 y = WINTYPE_DEFAULT_Y;
703 width = WINTYPE_DEFAULT_WIDTH;
704 height = WINTYPE_DEFAULT_HEIGHT;
707 hWnd = CreateWindowExW(dwExStyles, windowClassW, pHHInfo->pHHWinType->pszCaption,
708 dwStyles, x, y, width, height, NULL, NULL, hInstance, NULL);
712 ShowWindow(hWnd, SW_SHOW);
715 /* store the pointer to the HH info struct */
716 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
718 pHHInfo->pHHWinType->hwndHelp = hWnd;
722 static void HH_CreateFont(HHInfo *pHHInfo)
726 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
727 lf.lfWeight = FW_NORMAL;
729 lf.lfUnderline = FALSE;
731 pHHInfo->hFont = CreateFontIndirectW(&lf);
734 static void HH_InitRequiredControls(DWORD dwControls)
736 INITCOMMONCONTROLSEX icex;
738 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
739 icex.dwICC = dwControls;
740 InitCommonControlsEx(&icex);
743 /* Creates the whole package */
744 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
746 HH_CreateFont(pHHInfo);
748 if (!HH_CreateHelpWindow(pHHInfo))
751 HH_InitRequiredControls(ICC_BAR_CLASSES);
753 if (!HH_AddToolbar(pHHInfo))
756 HH_RegisterChildWndClass(pHHInfo);
758 if (!HH_AddNavigationPane(pHHInfo))
761 HH_RegisterSizeBarClass(pHHInfo);
763 if (!HH_AddSizeBar(pHHInfo))
766 if (!HH_AddHTMLPane(pHHInfo))
772 static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPWSTR szCmdLine)
774 HHInfo *pHHInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HHInfo));
776 pHHInfo->pHHWinType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HH_WINTYPEW));
777 pHHInfo->pCHMInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo));
778 pHHInfo->pWBInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo));
779 pHHInfo->hInstance = hInstance;
780 pHHInfo->szCmdLine = szCmdLine;
785 static void HH_Close(HHInfo *pHHInfo)
790 /* Free allocated strings */
791 if (pHHInfo->pHHWinType)
793 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType);
794 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszCaption);
795 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszToc);
796 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType);
797 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszIndex);
798 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszFile);
799 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszHome);
800 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump1);
801 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump2);
802 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
803 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
806 HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType);
807 HeapFree(GetProcessHeap(), 0, pHHInfo->szCmdLine);
809 if (pHHInfo->pCHMInfo)
811 CHM_CloseCHM(pHHInfo->pCHMInfo);
812 HeapFree(GetProcessHeap(), 0, pHHInfo->pCHMInfo);
815 if (pHHInfo->pWBInfo)
817 WB_UnEmbedBrowser(pHHInfo->pWBInfo);
818 HeapFree(GetProcessHeap(), 0, pHHInfo->pWBInfo);
822 static void HH_OpenDefaultTopic(HHInfo *pHHInfo)
825 LPCWSTR defTopic = pHHInfo->pHHWinType->pszFile;
827 CHM_CreateITSUrl(pHHInfo->pCHMInfo, defTopic, url);
828 WB_Navigate(pHHInfo->pWBInfo, url);
831 static BOOL HH_OpenCHM(HHInfo *pHHInfo)
833 if (!CHM_OpenCHM(pHHInfo->pCHMInfo, pHHInfo->szCmdLine))
836 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType))
842 /* FIXME: Check szCmdLine for bad arguments */
843 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
848 if (OleInitialize(NULL) != S_OK)
851 pHHInfo = HH_OpenHH(hInstance, HH_ANSIToUnicode(szCmdLine));
852 if (!pHHInfo || !HH_OpenCHM(pHHInfo) || !HH_CreateViewer(pHHInfo))
858 HH_OpenDefaultTopic(pHHInfo);
860 while (GetMessageW(&msg, 0, 0, 0))
862 TranslateMessage(&msg);
863 DispatchMessageW(&msg);
867 HeapFree(GetProcessHeap(), 0, pHHInfo);