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/debug.h"
31 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
33 static LRESULT Help_OnSize(HWND hWnd);
35 /* Window type defaults */
37 #define WINTYPE_DEFAULT_X 280
38 #define WINTYPE_DEFAULT_Y 100
39 #define WINTYPE_DEFAULT_WIDTH 740
40 #define WINTYPE_DEFAULT_HEIGHT 640
41 #define WINTYPE_DEFAULT_NAVWIDTH 250
43 #define TAB_TOP_PADDING 8
44 #define TAB_RIGHT_PADDING 4
46 static const WCHAR szEmpty[] = {0};
48 /* Loads a string from the resource file */
49 static LPWSTR HH_LoadString(DWORD dwID)
54 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
55 iSize += 2; /* some strings (tab text) needs double-null termination */
57 string = hhctrl_alloc(iSize * sizeof(WCHAR));
58 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
63 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
69 V_BSTR(&url) = SysAllocString(surl);
71 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
75 return SUCCEEDED(hres);
78 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
80 WCHAR buf[INTERNET_MAX_URL_LENGTH];
81 WCHAR full_path[MAX_PATH];
84 static const WCHAR url_format[] =
85 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
87 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
89 if (!info->web_browser)
92 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
93 WARN("GetFullPathName failed: %u\n", GetLastError());
97 wsprintfW(buf, url_format, full_path, index);
100 if((ptr = strchrW(buf, '#')))
103 return NavigateToUrl(info, buf);
108 #define SIZEBAR_WIDTH 4
110 static const WCHAR szSizeBarClass[] = {
111 'H','H',' ','S','i','z','e','B','a','r',0
114 /* Draw the SizeBar */
115 static void SB_OnPaint(HWND hWnd)
121 hdc = BeginPaint(hWnd, &ps);
123 GetClientRect(hWnd, &rc);
128 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
130 /* white highlight */
131 SelectObject(hdc, GetStockObject(WHITE_PEN));
132 MoveToEx(hdc, rc.right, 1, NULL);
134 LineTo(hdc, 1, rc.bottom - 1);
137 MoveToEx(hdc, 0, rc.bottom, NULL);
138 LineTo(hdc, rc.right, rc.bottom);
143 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
148 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
150 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
153 pt.x = (short)LOWORD(lParam);
154 pt.y = (short)HIWORD(lParam);
156 /* update the window sizes */
157 pHHInfo->WinType.iNavWidth += pt.x;
163 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
165 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
166 if (!(wParam & MK_LBUTTON))
170 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
175 SB_OnLButtonDown(hWnd, wParam, lParam);
178 SB_OnLButtonUp(hWnd, wParam, lParam);
181 SB_OnMouseMove(hWnd, wParam, lParam);
187 return DefWindowProcW(hWnd, message, wParam, lParam);
193 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
197 wcex.cbSize = sizeof(WNDCLASSEXW);
199 wcex.lpfnWndProc = SizeBar_WndProc;
202 wcex.hInstance = hhctrl_hinstance;
203 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
204 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
205 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
206 wcex.lpszMenuName = NULL;
207 wcex.lpszClassName = szSizeBarClass;
208 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
210 RegisterClassExW(&wcex);
213 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
215 RECT rectWND, rectTB, rectNP;
217 GetClientRect(info->WinType.hwndHelp, &rectWND);
218 GetClientRect(info->WinType.hwndToolBar, &rectTB);
219 GetClientRect(info->WinType.hwndNavigation, &rectNP);
221 rc->left = rectNP.right;
222 rc->top = rectTB.bottom;
223 rc->bottom = rectWND.bottom - rectTB.bottom;
224 rc->right = SIZEBAR_WIDTH;
227 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
230 HWND hwndParent = pHHInfo->WinType.hwndHelp;
231 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
232 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
235 SB_GetSizeBarRect(pHHInfo, &rc);
237 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
238 rc.left, rc.top, rc.right, rc.bottom,
239 hwndParent, NULL, hhctrl_hinstance, NULL);
243 /* store the pointer to the HH info struct */
244 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
246 pHHInfo->hwndSizeBar = hWnd;
252 static const WCHAR szChildClass[] = {
253 'H','H',' ','C','h','i','l','d',0
256 static LRESULT Child_OnPaint(HWND hWnd)
262 hdc = BeginPaint(hWnd, &ps);
264 /* Only paint the Navigation pane, identified by the fact
265 * that it has a child window
267 if (GetWindow(hWnd, GW_CHILD))
269 GetClientRect(hWnd, &rc);
271 /* set the border color */
272 SelectObject(hdc, GetStockObject(DC_PEN));
273 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
275 /* Draw the top border */
276 LineTo(hdc, rc.right, 0);
278 SelectObject(hdc, GetStockObject(WHITE_PEN));
279 MoveToEx(hdc, 0, 1, NULL);
280 LineTo(hdc, rc.right, 1);
288 static LRESULT Child_OnSize(HWND hwnd)
290 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
293 if(!info || hwnd != info->WinType.hwndNavigation)
296 GetClientRect(hwnd, &rect);
297 SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0,
298 rect.right - TAB_RIGHT_PADDING,
299 rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
303 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
308 return Child_OnPaint(hWnd);
310 return Child_OnSize(hWnd);
312 return DefWindowProcW(hWnd, message, wParam, lParam);
318 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
322 wcex.cbSize = sizeof(WNDCLASSEXW);
324 wcex.lpfnWndProc = Child_WndProc;
327 wcex.hInstance = hhctrl_hinstance;
328 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
329 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
330 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
331 wcex.lpszMenuName = NULL;
332 wcex.lpszClassName = szChildClass;
333 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
335 RegisterClassExW(&wcex);
342 static void TB_OnClick(HWND hWnd, DWORD dwID)
344 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
349 DoPageAction(info, WB_STOP);
352 DoPageAction(info, WB_REFRESH);
355 DoPageAction(info, WB_GOBACK);
358 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
361 DoPageAction(info, WB_GOFORWARD);
368 case IDTB_BROWSE_FWD:
369 case IDTB_BROWSE_BACK:
380 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
382 /* FIXME: Load the correct button bitmaps */
383 pButtons[dwIndex].iBitmap = STD_PRINT;
384 pButtons[dwIndex].idCommand = dwID;
385 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
386 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
387 pButtons[dwIndex].dwData = 0;
388 pButtons[dwIndex].iString = 0;
391 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
395 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
396 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
398 if (dwButtonFlags & HHWIN_BUTTON_BACK)
399 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
401 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
402 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
404 if (dwButtonFlags & HHWIN_BUTTON_STOP)
405 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
407 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
408 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
410 if (dwButtonFlags & HHWIN_BUTTON_HOME)
411 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
413 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
414 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
416 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
417 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
419 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
420 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
422 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
423 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
425 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
426 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
428 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
429 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
431 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
432 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
434 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
435 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
438 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
441 HWND hwndParent = pHHInfo->WinType.hwndHelp;
443 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
445 DWORD dwStyles, dwExStyles;
446 DWORD dwNumButtons, dwIndex;
448 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
449 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
451 toolbarFlags = HHWIN_DEF_BUTTONS;
453 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
455 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
456 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
457 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
459 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
460 0, 0, 0, 0, hwndParent, NULL,
461 hhctrl_hinstance, NULL);
465 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
466 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
467 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
469 /* FIXME: Load correct icons for all buttons */
470 tbAB.hInst = HINST_COMMCTRL;
471 tbAB.nID = IDB_STD_LARGE_COLOR;
472 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
474 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
476 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
477 DWORD dwLen = strlenW(szBuf);
478 szBuf[dwLen + 2] = 0; /* Double-null terminate */
480 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
484 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
485 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
486 ShowWindow(hToolbar, SW_SHOW);
488 pHHInfo->WinType.hwndToolBar = hToolbar;
492 /* Navigation Pane */
494 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
496 HWND hwndParent = pHHInfo->WinType.hwndHelp;
497 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
498 RECT rectWND, rectTB;
500 GetClientRect(hwndParent, &rectWND);
501 GetClientRect(hwndToolbar, &rectTB);
504 rc->top = rectTB.bottom;
505 rc->bottom = rectWND.bottom - rectTB.bottom;
507 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
508 pHHInfo->WinType.iNavWidth == 0)
510 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
513 rc->right = pHHInfo->WinType.iNavWidth;
516 static void NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD dwStrID, DWORD dwIndex)
519 LPWSTR tabText = HH_LoadString(dwStrID);
521 tie.mask = TCIF_TEXT;
522 tie.pszText = tabText;
524 SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, dwIndex, (LPARAM)&tie );
525 hhctrl_free(tabText);
528 static BOOL HH_AddNavigationPane(HHInfo *info)
530 HWND hWnd, hwndTabCtrl;
531 HWND hwndParent = info->WinType.hwndHelp;
532 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
533 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
537 NP_GetNavigationRect(info, &rc);
539 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
540 rc.left, rc.top, rc.right, rc.bottom,
541 hwndParent, NULL, hhctrl_hinstance, NULL);
545 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
547 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
549 rc.right - TAB_RIGHT_PADDING,
550 rc.bottom - TAB_TOP_PADDING,
551 hWnd, NULL, hhctrl_hinstance, NULL);
555 if (*info->WinType.pszToc)
556 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS, dwIndex++);
558 if (*info->WinType.pszIndex)
559 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX, dwIndex++);
561 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
562 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH, dwIndex++);
564 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
565 NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES, dwIndex++);
567 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
569 info->hwndTabCtrl = hwndTabCtrl;
570 info->WinType.hwndNavigation = hWnd;
576 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
578 RECT rectTB, rectWND, rectNP, rectSB;
580 GetClientRect(info->WinType.hwndHelp, &rectWND);
581 GetClientRect(info->WinType.hwndToolBar, &rectTB);
582 GetClientRect(info->WinType.hwndNavigation, &rectNP);
583 GetClientRect(info->hwndSizeBar, &rectSB);
585 rc->left = rectNP.right + rectSB.right;
586 rc->top = rectTB.bottom;
587 rc->right = rectWND.right - rc->left;
588 rc->bottom = rectWND.bottom - rectTB.bottom;
591 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
594 HWND hwndParent = pHHInfo->WinType.hwndHelp;
595 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
596 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
599 HP_GetHTMLRect(pHHInfo, &rc);
601 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
602 rc.left, rc.top, rc.right, rc.bottom,
603 hwndParent, NULL, hhctrl_hinstance, NULL);
607 if (!InitWebBrowser(pHHInfo, hWnd))
610 /* store the pointer to the HH info struct */
611 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
613 ShowWindow(hWnd, SW_SHOW);
616 pHHInfo->WinType.hwndHTML = hWnd;
622 static LRESULT Help_OnSize(HWND hWnd)
624 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
631 NP_GetNavigationRect(pHHInfo, &rc);
632 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
633 rc.right, rc.bottom, SWP_NOMOVE);
635 SB_GetSizeBarRect(pHHInfo, &rc);
636 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
637 rc.right, rc.bottom, SWP_SHOWWINDOW);
639 HP_GetHTMLRect(pHHInfo, &rc);
640 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
641 rc.right, rc.bottom, SWP_SHOWWINDOW);
643 /* Resize browser window taking the frame size into account */
644 dwSize = GetSystemMetrics(SM_CXFRAME);
645 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
650 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
655 if (HIWORD(wParam) == BN_CLICKED)
656 TB_OnClick(hWnd, LOWORD(wParam));
659 return Help_OnSize(hWnd);
661 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
669 return DefWindowProcW(hWnd, message, wParam, lParam);
675 static BOOL HH_CreateHelpWindow(HHInfo *info)
678 RECT winPos = info->WinType.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 = Help_WndProc;
692 wcex.hInstance = hhctrl_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 (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
704 dwStyles = info->WinType.dwStyles;
706 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
707 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
709 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
710 dwExStyles = info->WinType.dwExStyles;
712 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
713 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
715 if (info->WinType.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, info->WinType.pszCaption,
731 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
735 ShowWindow(hWnd, SW_SHOW);
738 /* store the pointer to the HH info struct */
739 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
741 info->WinType.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 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 void ReleaseHelpViewer(HHInfo *info)
800 /* Free allocated strings */
801 hhctrl_free((LPWSTR)info->WinType.pszType);
802 hhctrl_free((LPWSTR)info->WinType.pszCaption);
803 hhctrl_free((LPWSTR)info->WinType.pszToc);
804 hhctrl_free((LPWSTR)info->WinType.pszIndex);
805 hhctrl_free((LPWSTR)info->WinType.pszFile);
806 hhctrl_free((LPWSTR)info->WinType.pszHome);
807 hhctrl_free((LPWSTR)info->WinType.pszJump1);
808 hhctrl_free((LPWSTR)info->WinType.pszJump2);
809 hhctrl_free((LPWSTR)info->WinType.pszUrlJump1);
810 hhctrl_free((LPWSTR)info->WinType.pszUrlJump2);
813 CloseCHM(info->pCHMInfo);
815 ReleaseWebBrowser(info);
817 if(info->WinType.hwndHelp)
818 DestroyWindow(info->WinType.hwndHelp);
824 HHInfo *CreateHelpViewer(LPCWSTR filename)
826 HHInfo *info = hhctrl_alloc_zero(sizeof(HHInfo));
830 info->pCHMInfo = OpenCHM(filename);
831 if(!info->pCHMInfo) {
832 ReleaseHelpViewer(info);
836 if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) {
837 ReleaseHelpViewer(info);
841 if(!CreateViewer(info)) {
842 ReleaseHelpViewer(info);