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
47 static const WCHAR szEmpty[] = {0};
49 /* Loads a string from the resource file */
50 static LPWSTR HH_LoadString(DWORD dwID)
55 iSize = LoadStringW(hhctrl_hinstance, dwID, NULL, 0);
56 iSize += 2; /* some strings (tab text) needs double-null termination */
58 string = hhctrl_alloc(iSize * sizeof(WCHAR));
59 LoadStringW(hhctrl_hinstance, dwID, string, iSize);
64 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
70 V_BSTR(&url) = SysAllocString(surl);
72 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
76 return SUCCEEDED(hres);
79 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
81 WCHAR buf[INTERNET_MAX_URL_LENGTH];
82 WCHAR full_path[MAX_PATH];
85 static const WCHAR url_format[] =
86 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','/','%','s',0};
88 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
90 if (!info->web_browser)
93 if(!GetFullPathNameW(file, sizeof(full_path), full_path, NULL)) {
94 WARN("GetFullPathName failed: %u\n", GetLastError());
98 wsprintfW(buf, url_format, full_path, index);
101 if((ptr = strchrW(buf, '#')))
104 return NavigateToUrl(info, buf);
109 #define SIZEBAR_WIDTH 4
111 static const WCHAR szSizeBarClass[] = {
112 'H','H',' ','S','i','z','e','B','a','r',0
115 /* Draw the SizeBar */
116 static void SB_OnPaint(HWND hWnd)
122 hdc = BeginPaint(hWnd, &ps);
124 GetClientRect(hWnd, &rc);
129 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
131 /* white highlight */
132 SelectObject(hdc, GetStockObject(WHITE_PEN));
133 MoveToEx(hdc, rc.right, 1, NULL);
135 LineTo(hdc, 1, rc.bottom - 1);
138 MoveToEx(hdc, 0, rc.bottom, NULL);
139 LineTo(hdc, rc.right, rc.bottom);
144 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
149 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
151 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
154 pt.x = (short)LOWORD(lParam);
155 pt.y = (short)HIWORD(lParam);
157 /* update the window sizes */
158 pHHInfo->WinType.iNavWidth += pt.x;
164 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
166 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
167 if (!(wParam & MK_LBUTTON))
171 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
176 SB_OnLButtonDown(hWnd, wParam, lParam);
179 SB_OnLButtonUp(hWnd, wParam, lParam);
182 SB_OnMouseMove(hWnd, wParam, lParam);
188 return DefWindowProcW(hWnd, message, wParam, lParam);
194 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
198 wcex.cbSize = sizeof(WNDCLASSEXW);
200 wcex.lpfnWndProc = SizeBar_WndProc;
203 wcex.hInstance = hhctrl_hinstance;
204 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
205 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
206 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
207 wcex.lpszMenuName = NULL;
208 wcex.lpszClassName = szSizeBarClass;
209 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
211 RegisterClassExW(&wcex);
214 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
216 RECT rectWND, rectTB, rectNP;
218 GetClientRect(info->WinType.hwndHelp, &rectWND);
219 GetClientRect(info->WinType.hwndToolBar, &rectTB);
220 GetClientRect(info->WinType.hwndNavigation, &rectNP);
222 rc->left = rectNP.right;
223 rc->top = rectTB.bottom;
224 rc->bottom = rectWND.bottom - rectTB.bottom;
225 rc->right = SIZEBAR_WIDTH;
228 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
231 HWND hwndParent = pHHInfo->WinType.hwndHelp;
232 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
233 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
236 SB_GetSizeBarRect(pHHInfo, &rc);
238 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
239 rc.left, rc.top, rc.right, rc.bottom,
240 hwndParent, NULL, hhctrl_hinstance, NULL);
244 /* store the pointer to the HH info struct */
245 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
247 pHHInfo->hwndSizeBar = hWnd;
253 static const WCHAR szChildClass[] = {
254 'H','H',' ','C','h','i','l','d',0
257 static LRESULT Child_OnPaint(HWND hWnd)
263 hdc = BeginPaint(hWnd, &ps);
265 /* Only paint the Navigation pane, identified by the fact
266 * that it has a child window
268 if (GetWindow(hWnd, GW_CHILD))
270 GetClientRect(hWnd, &rc);
272 /* set the border color */
273 SelectObject(hdc, GetStockObject(DC_PEN));
274 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
276 /* Draw the top border */
277 LineTo(hdc, rc.right, 0);
279 SelectObject(hdc, GetStockObject(WHITE_PEN));
280 MoveToEx(hdc, 0, 1, NULL);
281 LineTo(hdc, rc.right, 1);
289 static void ResizeTabChild(HHInfo *info, HWND hwnd)
294 GetClientRect(info->WinType.hwndNavigation, &rect);
295 SendMessageW(info->hwndTabCtrl, TCM_GETITEMRECT, 0, (LPARAM)&tabrc);
296 cnt = SendMessageW(info->hwndTabCtrl, TCM_GETROWCOUNT, 0, 0);
298 rect.left = TAB_MARGIN;
299 rect.top = TAB_TOP_PADDING + cnt*(tabrc.bottom-tabrc.top) + TAB_MARGIN;
300 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
301 rect.bottom -= TAB_MARGIN;
303 SetWindowPos(hwnd, NULL, rect.left, rect.top, rect.right-rect.left,
304 rect.bottom-rect.top, SWP_NOZORDER | SWP_NOACTIVATE);
307 static LRESULT Child_OnSize(HWND hwnd)
309 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
312 if(!info || hwnd != info->WinType.hwndNavigation)
315 GetClientRect(hwnd, &rect);
316 SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0,
317 rect.right - TAB_RIGHT_PADDING,
318 rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
320 ResizeTabChild(info, info->tabs[TAB_CONTENTS].hwnd);
324 static LRESULT OnTabChange(HWND hwnd)
326 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
333 if(info->tabs[info->current_tab].hwnd)
334 ShowWindow(info->tabs[info->current_tab].hwnd, SW_HIDE);
336 info->current_tab = SendMessageW(info->hwndTabCtrl, TCM_GETCURSEL, 0, 0);
338 if(info->tabs[info->current_tab].hwnd)
339 ShowWindow(info->tabs[info->current_tab].hwnd, SW_SHOW);
344 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
349 return Child_OnPaint(hWnd);
351 return Child_OnSize(hWnd);
353 NMHDR *nmhdr = (NMHDR*)lParam;
354 switch(nmhdr->code) {
356 return OnTabChange(hWnd);
361 return DefWindowProcW(hWnd, message, wParam, lParam);
367 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
371 wcex.cbSize = sizeof(WNDCLASSEXW);
373 wcex.lpfnWndProc = Child_WndProc;
376 wcex.hInstance = hhctrl_hinstance;
377 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
378 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
379 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
380 wcex.lpszMenuName = NULL;
381 wcex.lpszClassName = szChildClass;
382 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
384 RegisterClassExW(&wcex);
391 static void TB_OnClick(HWND hWnd, DWORD dwID)
393 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
398 DoPageAction(info, WB_STOP);
401 DoPageAction(info, WB_REFRESH);
404 DoPageAction(info, WB_GOBACK);
407 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
410 DoPageAction(info, WB_GOFORWARD);
417 case IDTB_BROWSE_FWD:
418 case IDTB_BROWSE_BACK:
429 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
431 /* FIXME: Load the correct button bitmaps */
432 pButtons[dwIndex].iBitmap = STD_PRINT;
433 pButtons[dwIndex].idCommand = dwID;
434 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
435 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
436 pButtons[dwIndex].dwData = 0;
437 pButtons[dwIndex].iString = 0;
440 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
444 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
445 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
447 if (dwButtonFlags & HHWIN_BUTTON_BACK)
448 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
450 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
451 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
453 if (dwButtonFlags & HHWIN_BUTTON_STOP)
454 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
456 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
457 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
459 if (dwButtonFlags & HHWIN_BUTTON_HOME)
460 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
462 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
463 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
465 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
466 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
468 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
469 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
471 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
472 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
474 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
475 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
477 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
478 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
480 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
481 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
483 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
484 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
487 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
490 HWND hwndParent = pHHInfo->WinType.hwndHelp;
492 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
494 DWORD dwStyles, dwExStyles;
495 DWORD dwNumButtons, dwIndex;
497 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
498 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
500 toolbarFlags = HHWIN_DEF_BUTTONS;
502 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
504 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
505 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
506 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
508 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
509 0, 0, 0, 0, hwndParent, NULL,
510 hhctrl_hinstance, NULL);
514 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
515 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
516 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
518 /* FIXME: Load correct icons for all buttons */
519 tbAB.hInst = HINST_COMMCTRL;
520 tbAB.nID = IDB_STD_LARGE_COLOR;
521 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
523 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
525 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
526 DWORD dwLen = strlenW(szBuf);
527 szBuf[dwLen + 2] = 0; /* Double-null terminate */
529 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
533 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)&buttons);
534 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
535 ShowWindow(hToolbar, SW_SHOW);
537 pHHInfo->WinType.hwndToolBar = hToolbar;
541 /* Navigation Pane */
543 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
545 HWND hwndParent = pHHInfo->WinType.hwndHelp;
546 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
547 RECT rectWND, rectTB;
549 GetClientRect(hwndParent, &rectWND);
550 GetClientRect(hwndToolbar, &rectTB);
553 rc->top = rectTB.bottom;
554 rc->bottom = rectWND.bottom - rectTB.bottom;
556 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
557 pHHInfo->WinType.iNavWidth == 0)
559 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
562 rc->right = pHHInfo->WinType.iNavWidth;
565 static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index)
568 LPWSTR tabText = HH_LoadString(index);
571 tie.mask = TCIF_TEXT;
572 tie.pszText = tabText;
574 ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie );
576 hhctrl_free(tabText);
580 static BOOL HH_AddNavigationPane(HHInfo *info)
582 HWND hWnd, hwndTabCtrl;
583 HWND hwndParent = info->WinType.hwndHelp;
584 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
585 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
588 NP_GetNavigationRect(info, &rc);
590 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
591 rc.left, rc.top, rc.right, rc.bottom,
592 hwndParent, NULL, hhctrl_hinstance, NULL);
596 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
598 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
600 rc.right - TAB_RIGHT_PADDING,
601 rc.bottom - TAB_TOP_PADDING,
602 hWnd, NULL, hhctrl_hinstance, NULL);
606 if (*info->WinType.pszToc)
607 info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS);
609 if (*info->WinType.pszIndex)
610 info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX);
612 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
613 info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH);
615 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
616 info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES);
618 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
620 info->hwndTabCtrl = hwndTabCtrl;
621 info->WinType.hwndNavigation = hWnd;
627 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
629 RECT rectTB, rectWND, rectNP, rectSB;
631 GetClientRect(info->WinType.hwndHelp, &rectWND);
632 GetClientRect(info->WinType.hwndToolBar, &rectTB);
633 GetClientRect(info->WinType.hwndNavigation, &rectNP);
634 GetClientRect(info->hwndSizeBar, &rectSB);
636 rc->left = rectNP.right + rectSB.right;
637 rc->top = rectTB.bottom;
638 rc->right = rectWND.right - rc->left;
639 rc->bottom = rectWND.bottom - rectTB.bottom;
642 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
645 HWND hwndParent = pHHInfo->WinType.hwndHelp;
646 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
647 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
650 HP_GetHTMLRect(pHHInfo, &rc);
652 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
653 rc.left, rc.top, rc.right, rc.bottom,
654 hwndParent, NULL, hhctrl_hinstance, NULL);
658 if (!InitWebBrowser(pHHInfo, hWnd))
661 /* store the pointer to the HH info struct */
662 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
664 ShowWindow(hWnd, SW_SHOW);
667 pHHInfo->WinType.hwndHTML = hWnd;
673 static LRESULT Help_OnSize(HWND hWnd)
675 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
682 NP_GetNavigationRect(pHHInfo, &rc);
683 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
684 rc.right, rc.bottom, SWP_NOMOVE);
686 SB_GetSizeBarRect(pHHInfo, &rc);
687 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
688 rc.right, rc.bottom, SWP_SHOWWINDOW);
690 HP_GetHTMLRect(pHHInfo, &rc);
691 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
692 rc.right, rc.bottom, SWP_SHOWWINDOW);
694 /* Resize browser window taking the frame size into account */
695 dwSize = GetSystemMetrics(SM_CXFRAME);
696 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
701 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
706 if (HIWORD(wParam) == BN_CLICKED)
707 TB_OnClick(hWnd, LOWORD(wParam));
710 return Help_OnSize(hWnd);
712 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
720 return DefWindowProcW(hWnd, message, wParam, lParam);
726 static BOOL HH_CreateHelpWindow(HHInfo *info)
729 RECT winPos = info->WinType.rcWindowPos;
731 DWORD dwStyles, dwExStyles;
732 DWORD x, y, width, height;
734 static const WCHAR windowClassW[] = {
735 'H','H',' ', 'P','a','r','e','n','t',0
738 wcex.cbSize = sizeof(WNDCLASSEXW);
739 wcex.style = CS_HREDRAW | CS_VREDRAW;
740 wcex.lpfnWndProc = Help_WndProc;
743 wcex.hInstance = hhctrl_hinstance;
744 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
745 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
746 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
747 wcex.lpszMenuName = NULL;
748 wcex.lpszClassName = windowClassW;
749 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
751 RegisterClassExW(&wcex);
753 /* Read in window parameters if available */
754 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
755 dwStyles = info->WinType.dwStyles;
757 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
758 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
760 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
761 dwExStyles = info->WinType.dwExStyles;
763 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
764 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
766 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
770 width = winPos.right - x;
771 height = winPos.bottom - y;
775 x = WINTYPE_DEFAULT_X;
776 y = WINTYPE_DEFAULT_Y;
777 width = WINTYPE_DEFAULT_WIDTH;
778 height = WINTYPE_DEFAULT_HEIGHT;
781 hWnd = CreateWindowExW(dwExStyles, windowClassW, info->WinType.pszCaption,
782 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
786 ShowWindow(hWnd, SW_SHOW);
789 /* store the pointer to the HH info struct */
790 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
792 info->WinType.hwndHelp = hWnd;
796 static void HH_CreateFont(HHInfo *pHHInfo)
800 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
801 lf.lfWeight = FW_NORMAL;
803 lf.lfUnderline = FALSE;
805 pHHInfo->hFont = CreateFontIndirectW(&lf);
808 static void HH_InitRequiredControls(DWORD dwControls)
810 INITCOMMONCONTROLSEX icex;
812 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
813 icex.dwICC = dwControls;
814 InitCommonControlsEx(&icex);
817 /* Creates the whole package */
818 static BOOL CreateViewer(HHInfo *pHHInfo)
820 HH_CreateFont(pHHInfo);
822 if (!HH_CreateHelpWindow(pHHInfo))
825 HH_InitRequiredControls(ICC_BAR_CLASSES);
827 if (!HH_AddToolbar(pHHInfo))
830 HH_RegisterChildWndClass(pHHInfo);
832 if (!HH_AddNavigationPane(pHHInfo))
835 HH_RegisterSizeBarClass(pHHInfo);
837 if (!HH_AddSizeBar(pHHInfo))
840 if (!HH_AddHTMLPane(pHHInfo))
846 void ReleaseHelpViewer(HHInfo *info)
851 /* Free allocated strings */
852 hhctrl_free((LPWSTR)info->WinType.pszType);
853 hhctrl_free((LPWSTR)info->WinType.pszCaption);
854 hhctrl_free((LPWSTR)info->WinType.pszToc);
855 hhctrl_free((LPWSTR)info->WinType.pszIndex);
856 hhctrl_free((LPWSTR)info->WinType.pszFile);
857 hhctrl_free((LPWSTR)info->WinType.pszHome);
858 hhctrl_free((LPWSTR)info->WinType.pszJump1);
859 hhctrl_free((LPWSTR)info->WinType.pszJump2);
860 hhctrl_free((LPWSTR)info->WinType.pszUrlJump1);
861 hhctrl_free((LPWSTR)info->WinType.pszUrlJump2);
864 CloseCHM(info->pCHMInfo);
866 ReleaseWebBrowser(info);
868 if(info->WinType.hwndHelp)
869 DestroyWindow(info->WinType.hwndHelp);
875 HHInfo *CreateHelpViewer(LPCWSTR filename)
877 HHInfo *info = hhctrl_alloc_zero(sizeof(HHInfo));
881 info->pCHMInfo = OpenCHM(filename);
882 if(!info->pCHMInfo) {
883 ReleaseHelpViewer(info);
887 if (!LoadWinTypeFromCHM(info->pCHMInfo, &info->WinType)) {
888 ReleaseHelpViewer(info);
892 if(!CreateViewer(info)) {
893 ReleaseHelpViewer(info);