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 /* Loads a string from the resource file */
61 static LPWSTR HH_LoadString(DWORD dwID)
66 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
67 iSize += 2; /* some strings (tab text) needs double-null termination */
69 string = HeapAlloc(GetProcessHeap(), 0, iSize * sizeof(WCHAR));
70 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
75 static BOOL NavigateToChm(WBInfo *pWBInfo, LPCWSTR file, LPCWSTR index)
77 WCHAR buf[INTERNET_MAX_URL_LENGTH];
78 WCHAR full_path[MAX_PATH];
81 static const WCHAR url_format[] =
82 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
84 if (!pWBInfo->pWebBrowser2)
87 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
88 WARN("GetFullPathName failed: %u\n", GetLastError());
92 wsprintfW(buf, url_format, full_path, index);
95 V_BSTR(&url) = SysAllocString(buf);
97 IWebBrowser2_Navigate2(pWBInfo->pWebBrowser2, &url, 0, 0, 0, 0);
105 #define SIZEBAR_WIDTH 4
107 static const WCHAR szSizeBarClass[] = {
108 'H','H',' ','S','i','z','e','B','a','r',0
111 /* Draw the SizeBar */
112 static void SB_OnPaint(HWND hWnd)
118 hdc = BeginPaint(hWnd, &ps);
120 GetClientRect(hWnd, &rc);
125 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
127 /* white highlight */
128 SelectObject(hdc, GetStockObject(WHITE_PEN));
129 MoveToEx(hdc, rc.right, 1, NULL);
131 LineTo(hdc, 1, rc.bottom - 1);
134 MoveToEx(hdc, 0, rc.bottom, NULL);
135 LineTo(hdc, rc.right, rc.bottom);
140 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
145 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
147 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
150 pt.x = (short)LOWORD(lParam);
151 pt.y = (short)HIWORD(lParam);
153 /* update the window sizes */
154 pHHInfo->pHHWinType->iNavWidth += pt.x;
160 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
162 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
163 if (!(wParam & MK_LBUTTON))
167 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
172 SB_OnLButtonDown(hWnd, wParam, lParam);
175 SB_OnLButtonUp(hWnd, wParam, lParam);
178 SB_OnMouseMove(hWnd, wParam, lParam);
184 return DefWindowProcW(hWnd, message, wParam, lParam);
190 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
194 wcex.cbSize = sizeof(WNDCLASSEXW);
196 wcex.lpfnWndProc = (WNDPROC)SizeBar_WndProc;
199 wcex.hInstance = pHHInfo->hInstance;
200 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
201 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
202 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
203 wcex.lpszMenuName = NULL;
204 wcex.lpszClassName = szSizeBarClass;
205 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
207 RegisterClassExW(&wcex);
210 static void SB_GetSizeBarRect(HHInfo *pHHInfo, RECT *rc)
212 RECT rectWND, rectTB, rectNP;
214 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
215 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
216 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
218 rc->left = rectNP.right;
219 rc->top = rectTB.bottom;
220 rc->bottom = rectWND.bottom - rectTB.bottom;
221 rc->right = SIZEBAR_WIDTH;
224 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
227 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
228 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
229 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
232 SB_GetSizeBarRect(pHHInfo, &rc);
234 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
235 rc.left, rc.top, rc.right, rc.bottom,
236 hwndParent, NULL, pHHInfo->hInstance, NULL);
240 /* store the pointer to the HH info struct */
241 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
243 pHHInfo->hwndSizeBar = hWnd;
249 static const WCHAR szChildClass[] = {
250 'H','H',' ','C','h','i','l','d',0
253 static void Child_OnPaint(HWND hWnd)
259 hdc = BeginPaint(hWnd, &ps);
261 /* Only paint the Navigation pane, identified by the fact
262 * that it has a child window
264 if (GetWindow(hWnd, GW_CHILD))
266 GetClientRect(hWnd, &rc);
268 /* set the border color */
269 SelectObject(hdc, GetStockObject(DC_PEN));
270 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
272 /* Draw the top border */
273 LineTo(hdc, rc.right, 0);
275 SelectObject(hdc, GetStockObject(WHITE_PEN));
276 MoveToEx(hdc, 0, 1, NULL);
277 LineTo(hdc, rc.right, 1);
283 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
291 return DefWindowProcW(hWnd, message, wParam, lParam);
297 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
301 wcex.cbSize = sizeof(WNDCLASSEXW);
303 wcex.lpfnWndProc = (WNDPROC)Child_WndProc;
306 wcex.hInstance = pHHInfo->hInstance;
307 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
308 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
309 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
310 wcex.lpszMenuName = NULL;
311 wcex.lpszClassName = szChildClass;
312 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
314 RegisterClassExW(&wcex);
321 static void TB_OnClick(HWND hWnd, DWORD dwID)
323 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
328 WB_DoPageAction(pHHInfo->pWBInfo, WB_STOP);
331 WB_DoPageAction(pHHInfo->pWBInfo, WB_REFRESH);
334 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOBACK);
337 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszHome);
340 WB_DoPageAction(pHHInfo->pWBInfo, WB_GOFORWARD);
347 case IDTB_BROWSE_FWD:
348 case IDTB_BROWSE_BACK:
359 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
361 /* FIXME: Load the correct button bitmaps */
362 pButtons[dwIndex].iBitmap = STD_PRINT;
363 pButtons[dwIndex].idCommand = dwID;
364 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
365 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
366 pButtons[dwIndex].dwData = 0;
367 pButtons[dwIndex].iString = 0;
370 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
374 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
375 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
377 if (dwButtonFlags & HHWIN_BUTTON_BACK)
378 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
380 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
381 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
383 if (dwButtonFlags & HHWIN_BUTTON_STOP)
384 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
386 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
387 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
389 if (dwButtonFlags & HHWIN_BUTTON_HOME)
390 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
392 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
393 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
395 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
396 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
398 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
399 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
401 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
402 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
404 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
405 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
407 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
408 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
410 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
411 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
413 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
414 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
417 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
420 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
422 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
424 DWORD dwStyles, dwExStyles;
425 DWORD dwNumButtons, dwIndex;
427 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PARAM_TB_FLAGS)
428 toolbarFlags = pHHInfo->pHHWinType->fsToolBarFlags;
430 toolbarFlags = HHWIN_DEF_BUTTONS;
432 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
434 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
435 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
436 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
438 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
439 0, 0, 0, 0, hwndParent, NULL,
440 pHHInfo->hInstance, NULL);
444 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
445 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
446 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
448 /* FIXME: Load correct icons for all buttons */
449 tbAB.hInst = HINST_COMMCTRL;
450 tbAB.nID = IDB_STD_LARGE_COLOR;
451 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
453 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
455 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
456 DWORD dwLen = strlenW(szBuf);
457 szBuf[dwLen + 2] = 0; /* Double-null terminate */
459 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
460 HeapFree(GetProcessHeap(), 0, szBuf);
463 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
464 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
465 ShowWindow(hToolbar, SW_SHOW);
467 pHHInfo->pHHWinType->hwndToolBar = hToolbar;
471 /* Navigation Pane */
473 #define TAB_TOP_PADDING 8
474 #define TAB_RIGHT_PADDING 4
476 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
478 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
479 HWND hwndToolbar = pHHInfo->pHHWinType->hwndToolBar;
480 RECT rectWND, rectTB;
482 GetClientRect(hwndParent, &rectWND);
483 GetClientRect(hwndToolbar, &rectTB);
486 rc->top = rectTB.bottom;
487 rc->bottom = rectWND.bottom - rectTB.bottom;
489 if (!(pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
490 pHHInfo->pHHWinType->iNavWidth == 0)
492 pHHInfo->pHHWinType->iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
495 rc->right = pHHInfo->pHHWinType->iNavWidth;
498 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
501 LPWSTR tabText = HH_LoadString(dwStrID);
503 tie.mask = TCIF_TEXT;
504 tie.pszText = tabText;
506 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
507 HeapFree(GetProcessHeap(), 0, tabText);
510 static BOOL HH_AddNavigationPane(HHInfo *pHHInfo)
512 HWND hWnd, hwndTabCtrl;
513 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
514 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
515 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
519 NP_GetNavigationRect(pHHInfo, &rc);
521 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
522 rc.left, rc.top, rc.right, rc.bottom,
523 hwndParent, NULL, pHHInfo->hInstance, NULL);
527 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
529 rc.right - TAB_RIGHT_PADDING,
530 rc.bottom - TAB_TOP_PADDING,
531 hWnd, NULL, pHHInfo->hInstance, NULL);
535 if (*pHHInfo->pHHWinType->pszToc)
536 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
538 if (*pHHInfo->pHHWinType->pszIndex)
539 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
541 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_SEARCH)
542 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
544 if (pHHInfo->pHHWinType->fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
545 NP_CreateTab(pHHInfo->hInstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
547 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
549 pHHInfo->hwndTabCtrl = hwndTabCtrl;
550 pHHInfo->pHHWinType->hwndNavigation = hWnd;
556 static void HP_GetHTMLRect(HHInfo *pHHInfo, RECT *rc)
558 RECT rectTB, rectWND, rectNP, rectSB;
560 GetClientRect(pHHInfo->pHHWinType->hwndHelp, &rectWND);
561 GetClientRect(pHHInfo->pHHWinType->hwndToolBar, &rectTB);
562 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rectNP);
563 GetClientRect(pHHInfo->hwndSizeBar, &rectSB);
565 rc->left = rectNP.right + rectSB.right;
566 rc->top = rectTB.bottom;
567 rc->right = rectWND.right - rc->left;
568 rc->bottom = rectWND.bottom - rectTB.bottom;
571 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
574 HWND hwndParent = pHHInfo->pHHWinType->hwndHelp;
575 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
576 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
579 HP_GetHTMLRect(pHHInfo, &rc);
581 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
582 rc.left, rc.top, rc.right, rc.bottom,
583 hwndParent, NULL, pHHInfo->hInstance, NULL);
587 if (!WB_EmbedBrowser(pHHInfo->pWBInfo, hWnd))
590 /* store the pointer to the HH info struct */
591 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
593 ShowWindow(hWnd, SW_SHOW);
596 pHHInfo->pHHWinType->hwndHTML = hWnd;
602 static void Help_OnSize(HWND hWnd)
604 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
611 NP_GetNavigationRect(pHHInfo, &rc);
612 SetWindowPos(pHHInfo->pHHWinType->hwndNavigation, HWND_TOP, 0, 0,
613 rc.right, rc.bottom, SWP_NOMOVE);
615 GetClientRect(pHHInfo->pHHWinType->hwndNavigation, &rc);
616 SetWindowPos(pHHInfo->hwndTabCtrl, HWND_TOP, 0, 0,
617 rc.right - TAB_RIGHT_PADDING,
618 rc.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
620 SB_GetSizeBarRect(pHHInfo, &rc);
621 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
622 rc.right, rc.bottom, SWP_SHOWWINDOW);
624 HP_GetHTMLRect(pHHInfo, &rc);
625 SetWindowPos(pHHInfo->pHHWinType->hwndHTML, HWND_TOP, rc.left, rc.top,
626 rc.right, rc.bottom, SWP_SHOWWINDOW);
628 /* Resize browser window taking the frame size into account */
629 dwSize = GetSystemMetrics(SM_CXFRAME);
630 WB_ResizeBrowser(pHHInfo->pWBInfo, rc.right - dwSize, rc.bottom - dwSize);
633 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
641 if (HIWORD(wParam) == BN_CLICKED)
642 TB_OnClick(hWnd, LOWORD(wParam));
648 hdc = BeginPaint(hWnd, &ps);
656 return DefWindowProcW(hWnd, message, wParam, lParam);
662 static BOOL HH_CreateHelpWindow(HHInfo *pHHInfo)
665 HINSTANCE hInstance = pHHInfo->hInstance;
666 RECT winPos = pHHInfo->pHHWinType->rcWindowPos;
668 DWORD dwStyles, dwExStyles;
669 DWORD x, y, width, height;
671 static const WCHAR windowClassW[] = {
672 'H','H',' ', 'P','a','r','e','n','t',0
675 wcex.cbSize = sizeof(WNDCLASSEXW);
676 wcex.style = CS_HREDRAW | CS_VREDRAW;
677 wcex.lpfnWndProc = (WNDPROC)Help_WndProc;
680 wcex.hInstance = hInstance;
681 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
682 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
683 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
684 wcex.lpszMenuName = NULL;
685 wcex.lpszClassName = windowClassW;
686 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
688 RegisterClassExW(&wcex);
690 /* Read in window parameters if available */
691 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_STYLES)
692 dwStyles = pHHInfo->pHHWinType->dwStyles;
694 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
695 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
697 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_EXSTYLES)
698 dwExStyles = pHHInfo->pHHWinType->dwExStyles;
700 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
701 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
703 if (pHHInfo->pHHWinType->fsValidMembers & HHWIN_PARAM_RECT)
707 width = winPos.right - x;
708 height = winPos.bottom - y;
712 x = WINTYPE_DEFAULT_X;
713 y = WINTYPE_DEFAULT_Y;
714 width = WINTYPE_DEFAULT_WIDTH;
715 height = WINTYPE_DEFAULT_HEIGHT;
718 hWnd = CreateWindowExW(dwExStyles, windowClassW, pHHInfo->pHHWinType->pszCaption,
719 dwStyles, x, y, width, height, NULL, NULL, hInstance, NULL);
723 ShowWindow(hWnd, SW_SHOW);
726 /* store the pointer to the HH info struct */
727 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
729 pHHInfo->pHHWinType->hwndHelp = hWnd;
733 static void HH_CreateFont(HHInfo *pHHInfo)
737 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
738 lf.lfWeight = FW_NORMAL;
740 lf.lfUnderline = FALSE;
742 pHHInfo->hFont = CreateFontIndirectW(&lf);
745 static void HH_InitRequiredControls(DWORD dwControls)
747 INITCOMMONCONTROLSEX icex;
749 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
750 icex.dwICC = dwControls;
751 InitCommonControlsEx(&icex);
754 /* Creates the whole package */
755 static BOOL HH_CreateViewer(HHInfo *pHHInfo)
757 HH_CreateFont(pHHInfo);
759 if (!HH_CreateHelpWindow(pHHInfo))
762 HH_InitRequiredControls(ICC_BAR_CLASSES);
764 if (!HH_AddToolbar(pHHInfo))
767 HH_RegisterChildWndClass(pHHInfo);
769 if (!HH_AddNavigationPane(pHHInfo))
772 HH_RegisterSizeBarClass(pHHInfo);
774 if (!HH_AddSizeBar(pHHInfo))
777 if (!HH_AddHTMLPane(pHHInfo))
783 static HHInfo *HH_OpenHH(HINSTANCE hInstance, LPWSTR szCmdLine)
785 HHInfo *pHHInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HHInfo));
787 pHHInfo->pHHWinType = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(HH_WINTYPEW));
788 pHHInfo->pCHMInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(CHMInfo));
789 pHHInfo->pWBInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(WBInfo));
790 pHHInfo->hInstance = hInstance;
791 pHHInfo->szCmdLine = szCmdLine;
796 static void HH_Close(HHInfo *pHHInfo)
801 /* Free allocated strings */
802 if (pHHInfo->pHHWinType)
804 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszType);
805 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszCaption);
806 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszToc);
807 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszIndex);
808 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszFile);
809 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszHome);
810 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump1);
811 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszJump2);
812 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump1);
813 HeapFree(GetProcessHeap(), 0, (LPWSTR)pHHInfo->pHHWinType->pszUrlJump2);
816 HeapFree(GetProcessHeap(), 0, pHHInfo->pHHWinType);
817 HeapFree(GetProcessHeap(), 0, pHHInfo->szCmdLine);
819 if (pHHInfo->pCHMInfo)
821 CHM_CloseCHM(pHHInfo->pCHMInfo);
822 HeapFree(GetProcessHeap(), 0, pHHInfo->pCHMInfo);
825 if (pHHInfo->pWBInfo)
827 WB_UnEmbedBrowser(pHHInfo->pWBInfo);
828 HeapFree(GetProcessHeap(), 0, pHHInfo->pWBInfo);
832 static BOOL HH_OpenCHM(HHInfo *pHHInfo)
834 if (!CHM_OpenCHM(pHHInfo->pCHMInfo, pHHInfo->szCmdLine))
837 if (!CHM_LoadWinTypeFromCHM(pHHInfo->pCHMInfo, pHHInfo->pHHWinType))
843 /* FIXME: Check szCmdLine for bad arguments */
844 int WINAPI doWinMain(HINSTANCE hInstance, LPSTR szCmdLine)
849 if (FAILED(OleInitialize(NULL)))
852 pHHInfo = HH_OpenHH(hInstance, strdupAtoW(szCmdLine));
853 if (!pHHInfo || !HH_OpenCHM(pHHInfo) || !HH_CreateViewer(pHHInfo))
859 NavigateToChm(pHHInfo->pWBInfo, pHHInfo->pCHMInfo->szFile, pHHInfo->pHHWinType->pszFile);
861 while (GetMessageW(&msg, 0, 0, 0))
863 TranslateMessage(&msg);
864 DispatchMessageW(&msg);
868 HeapFree(GetProcessHeap(), 0, pHHInfo);