configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / hhctrl.ocx / help.c
blob2ea01321043e3a94197a556a762c3818866051c1
1 /*
2 * Help Viewer Implementation
4 * Copyright 2005 James Hawkins
5 * Copyright 2007 Jacek Caban for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "hhctrl.h"
24 #include "wingdi.h"
25 #include "commctrl.h"
26 #include "wininet.h"
28 #include "wine/debug.h"
30 #include "resource.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp);
34 static LRESULT 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 #define TAB_TOP_PADDING 8
45 #define TAB_RIGHT_PADDING 4
46 #define TAB_MARGIN 8
47 #define EDIT_HEIGHT 20
49 static const WCHAR szEmpty[] = {0};
51 /* Loads a string from the resource file */
52 static LPWSTR HH_LoadString(DWORD dwID)
54 LPWSTR string = NULL;
55 LPCWSTR stringresource;
56 int iSize;
58 iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0);
60 string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */
61 memcpy(string, stringresource, iSize*sizeof(WCHAR));
62 string[iSize] = 0;
64 return string;
67 static HRESULT navigate_url(HHInfo *info, LPCWSTR surl)
69 VARIANT url;
70 HRESULT hres;
72 TRACE("%s\n", debugstr_w(surl));
74 V_VT(&url) = VT_BSTR;
75 V_BSTR(&url) = SysAllocString(surl);
77 hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0);
79 VariantClear(&url);
81 if(FAILED(hres))
82 TRACE("Navigation failed: %08x\n", hres);
84 return hres;
87 BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl)
89 ChmPath chm_path;
90 BOOL ret;
91 HRESULT hres;
93 static const WCHAR url_indicator[] = {':', '/', '/', 0};
95 TRACE("%s\n", debugstr_w(surl));
97 if (strstrW(surl, url_indicator)) {
98 hres = navigate_url(info, surl);
99 if(SUCCEEDED(hres))
100 return TRUE;
101 } /* look up in chm if it doesn't look like a full url */
103 SetChmPath(&chm_path, info->pCHMInfo->szFile, surl);
104 ret = NavigateToChm(info, chm_path.chm_file, chm_path.chm_index);
106 heap_free(chm_path.chm_file);
107 heap_free(chm_path.chm_index);
109 return ret;
112 BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index)
114 WCHAR buf[INTERNET_MAX_URL_LENGTH];
115 WCHAR full_path[MAX_PATH];
116 LPWSTR ptr;
118 static const WCHAR url_format[] =
119 {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0};
120 static const WCHAR slash[] = {'/',0};
121 static const WCHAR empty[] = {0};
123 TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index));
125 if (!info->web_browser)
126 return FALSE;
128 if(!GetFullPathNameW(file, sizeof(full_path)/sizeof(full_path[0]), full_path, NULL)) {
129 WARN("GetFullPathName failed: %u\n", GetLastError());
130 return FALSE;
133 wsprintfW(buf, url_format, full_path, (!index || index[0] == '/') ? empty : slash, index);
135 /* FIXME: HACK */
136 if((ptr = strchrW(buf, '#')))
137 *ptr = 0;
139 return SUCCEEDED(navigate_url(info, buf));
142 /* Size Bar */
144 #define SIZEBAR_WIDTH 4
146 static const WCHAR szSizeBarClass[] = {
147 'H','H',' ','S','i','z','e','B','a','r',0
150 /* Draw the SizeBar */
151 static void SB_OnPaint(HWND hWnd)
153 PAINTSTRUCT ps;
154 HDC hdc;
155 RECT rc;
157 hdc = BeginPaint(hWnd, &ps);
159 GetClientRect(hWnd, &rc);
161 /* dark frame */
162 rc.right += 1;
163 rc.bottom -= 1;
164 FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH));
166 /* white highlight */
167 SelectObject(hdc, GetStockObject(WHITE_PEN));
168 MoveToEx(hdc, rc.right, 1, NULL);
169 LineTo(hdc, 1, 1);
170 LineTo(hdc, 1, rc.bottom - 1);
173 MoveToEx(hdc, 0, rc.bottom, NULL);
174 LineTo(hdc, rc.right, rc.bottom);
176 EndPaint(hWnd, &ps);
179 static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam)
181 SetCapture(hWnd);
184 static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam)
186 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
187 POINT pt;
189 pt.x = (short)LOWORD(lParam);
190 pt.y = (short)HIWORD(lParam);
192 /* update the window sizes */
193 pHHInfo->WinType.iNavWidth += pt.x;
194 Help_OnSize(hWnd);
196 ReleaseCapture();
199 static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam)
201 /* ignore WM_MOUSEMOVE if not dragging the SizeBar */
202 if (!(wParam & MK_LBUTTON))
203 return;
206 static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
208 switch (message)
210 case WM_LBUTTONDOWN:
211 SB_OnLButtonDown(hWnd, wParam, lParam);
212 break;
213 case WM_LBUTTONUP:
214 SB_OnLButtonUp(hWnd, wParam, lParam);
215 break;
216 case WM_MOUSEMOVE:
217 SB_OnMouseMove(hWnd, wParam, lParam);
218 break;
219 case WM_PAINT:
220 SB_OnPaint(hWnd);
221 break;
222 default:
223 return DefWindowProcW(hWnd, message, wParam, lParam);
226 return 0;
229 static void HH_RegisterSizeBarClass(HHInfo *pHHInfo)
231 WNDCLASSEXW wcex;
233 wcex.cbSize = sizeof(WNDCLASSEXW);
234 wcex.style = 0;
235 wcex.lpfnWndProc = SizeBar_WndProc;
236 wcex.cbClsExtra = 0;
237 wcex.cbWndExtra = 0;
238 wcex.hInstance = hhctrl_hinstance;
239 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
240 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE);
241 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
242 wcex.lpszMenuName = NULL;
243 wcex.lpszClassName = szSizeBarClass;
244 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
246 RegisterClassExW(&wcex);
249 static void SB_GetSizeBarRect(HHInfo *info, RECT *rc)
251 RECT rectWND, rectTB, rectNP;
253 GetClientRect(info->WinType.hwndHelp, &rectWND);
254 GetClientRect(info->WinType.hwndToolBar, &rectTB);
255 GetClientRect(info->WinType.hwndNavigation, &rectNP);
257 rc->left = rectNP.right;
258 rc->top = rectTB.bottom;
259 rc->bottom = rectWND.bottom - rectTB.bottom;
260 rc->right = SIZEBAR_WIDTH;
263 static BOOL HH_AddSizeBar(HHInfo *pHHInfo)
265 HWND hWnd;
266 HWND hwndParent = pHHInfo->WinType.hwndHelp;
267 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_OVERLAPPED;
268 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
269 RECT rc;
271 SB_GetSizeBarRect(pHHInfo, &rc);
273 hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles,
274 rc.left, rc.top, rc.right, rc.bottom,
275 hwndParent, NULL, hhctrl_hinstance, NULL);
276 if (!hWnd)
277 return FALSE;
279 /* store the pointer to the HH info struct */
280 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
282 pHHInfo->hwndSizeBar = hWnd;
283 return TRUE;
286 /* Child Window */
288 static const WCHAR szChildClass[] = {
289 'H','H',' ','C','h','i','l','d',0
292 static LRESULT Child_OnPaint(HWND hWnd)
294 PAINTSTRUCT ps;
295 HDC hdc;
296 RECT rc;
298 hdc = BeginPaint(hWnd, &ps);
300 /* Only paint the Navigation pane, identified by the fact
301 * that it has a child window
303 if (GetWindow(hWnd, GW_CHILD))
305 GetClientRect(hWnd, &rc);
307 /* set the border color */
308 SelectObject(hdc, GetStockObject(DC_PEN));
309 SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW));
311 /* Draw the top border */
312 LineTo(hdc, rc.right, 0);
314 SelectObject(hdc, GetStockObject(WHITE_PEN));
315 MoveToEx(hdc, 0, 1, NULL);
316 LineTo(hdc, rc.right, 1);
319 EndPaint(hWnd, &ps);
321 return 0;
324 static void ResizeTabChild(HHInfo *info, int tab)
326 HWND hwnd = info->tabs[tab].hwnd;
327 INT width, height;
328 RECT rect, tabrc;
329 DWORD cnt;
331 GetClientRect(info->WinType.hwndNavigation, &rect);
332 SendMessageW(info->hwndTabCtrl, TCM_GETITEMRECT, 0, (LPARAM)&tabrc);
333 cnt = SendMessageW(info->hwndTabCtrl, TCM_GETROWCOUNT, 0, 0);
335 rect.left = TAB_MARGIN;
336 rect.top = TAB_TOP_PADDING + cnt*(tabrc.bottom-tabrc.top) + TAB_MARGIN;
337 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
338 rect.bottom -= TAB_MARGIN;
339 width = rect.right-rect.left;
340 height = rect.bottom-rect.top;
342 SetWindowPos(hwnd, NULL, rect.left, rect.top, width, height,
343 SWP_NOZORDER | SWP_NOACTIVATE);
345 switch (tab)
347 case TAB_INDEX: {
348 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
349 int border_width = GetSystemMetrics(SM_CXBORDER);
350 int edge_width = GetSystemMetrics(SM_CXEDGE);
352 /* Resize the tab widget column to perfectly fit the tab window and
353 * leave sufficient space for the scroll widget.
355 SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_SETCOLUMNWIDTH, 0,
356 width-scroll_width-2*border_width-2*edge_width);
358 break;
360 case TAB_SEARCH: {
361 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
362 int border_width = GetSystemMetrics(SM_CXBORDER);
363 int edge_width = GetSystemMetrics(SM_CXEDGE);
364 int top_pos = 0;
366 SetWindowPos(info->search.hwndEdit, NULL, 0, top_pos, width,
367 EDIT_HEIGHT, SWP_NOZORDER | SWP_NOACTIVATE);
368 top_pos += EDIT_HEIGHT + TAB_MARGIN;
369 SetWindowPos(info->search.hwndList, NULL, 0, top_pos, width,
370 height-top_pos, SWP_NOZORDER | SWP_NOACTIVATE);
371 /* Resize the tab widget column to perfectly fit the tab window and
372 * leave sufficient space for the scroll widget.
374 SendMessageW(info->search.hwndList, LVM_SETCOLUMNWIDTH, 0,
375 width-scroll_width-2*border_width-2*edge_width);
377 break;
382 static LRESULT Child_OnSize(HWND hwnd)
384 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
385 RECT rect;
387 if(!info || hwnd != info->WinType.hwndNavigation)
388 return 0;
390 GetClientRect(hwnd, &rect);
391 SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0,
392 rect.right - TAB_RIGHT_PADDING,
393 rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE);
395 ResizeTabChild(info, TAB_CONTENTS);
396 ResizeTabChild(info, TAB_INDEX);
397 return 0;
400 static LRESULT OnTabChange(HWND hwnd)
402 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, GWLP_USERDATA);
404 TRACE("%p\n", hwnd);
406 if (!info)
407 return 0;
409 if(info->tabs[info->current_tab].hwnd)
410 ShowWindow(info->tabs[info->current_tab].hwnd, SW_HIDE);
412 info->current_tab = SendMessageW(info->hwndTabCtrl, TCM_GETCURSEL, 0, 0);
414 if(info->tabs[info->current_tab].hwnd)
415 ShowWindow(info->tabs[info->current_tab].hwnd, SW_SHOW);
417 return 0;
420 static LRESULT OnTopicChange(HHInfo *info, void *user_data)
422 LPCWSTR chmfile = NULL, name = NULL, local = NULL;
423 ContentItem *citer;
424 SearchItem *siter;
425 IndexItem *iiter;
427 if(!user_data || !info)
428 return 0;
430 switch (info->current_tab)
432 case TAB_CONTENTS:
433 citer = (ContentItem *) user_data;
434 name = citer->name;
435 local = citer->local;
436 while(citer) {
437 if(citer->merge.chm_file) {
438 chmfile = citer->merge.chm_file;
439 break;
441 citer = citer->parent;
443 break;
444 case TAB_INDEX:
445 iiter = (IndexItem *) user_data;
446 if(iiter->nItems == 0) {
447 FIXME("No entries for this item!\n");
448 return 0;
450 if(iiter->nItems > 1) {
451 int i = 0;
452 LVITEMW lvi;
454 SendMessageW(info->popup.hwndList, LVM_DELETEALLITEMS, 0, 0);
455 for(i=0;i<iiter->nItems;i++) {
456 IndexSubItem *item = &iiter->items[i];
457 WCHAR *name = iiter->keyword;
459 if(item->name)
460 name = item->name;
461 memset(&lvi, 0, sizeof(lvi));
462 lvi.iItem = i;
463 lvi.mask = LVIF_TEXT|LVIF_PARAM;
464 lvi.cchTextMax = strlenW(name)+1;
465 lvi.pszText = name;
466 lvi.lParam = (LPARAM) item;
467 SendMessageW(info->popup.hwndList, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
469 ShowWindow(info->popup.hwndPopup, SW_SHOW);
470 return 0;
472 name = iiter->items[0].name;
473 local = iiter->items[0].local;
474 chmfile = iiter->merge.chm_file;
475 break;
476 case TAB_SEARCH:
477 siter = (SearchItem *) user_data;
478 name = siter->filename;
479 local = siter->filename;
480 chmfile = info->pCHMInfo->szFile;
481 break;
482 default:
483 FIXME("Unhandled operation for this tab!\n");
484 return 0;
487 if(!chmfile)
489 FIXME("No help file found for this item!\n");
490 return 0;
493 TRACE("name %s loal %s\n", debugstr_w(name), debugstr_w(local));
495 NavigateToChm(info, chmfile, local);
496 return 0;
499 /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */
500 static LRESULT CALLBACK EditChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
502 WNDPROC editWndProc = (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
504 if(message == WM_KEYUP && wParam == VK_RETURN)
506 NMHDR nmhdr;
508 nmhdr.hwndFrom = hWnd;
509 nmhdr.code = NM_RETURN;
510 SendMessageW(GetParent(GetParent(hWnd)), WM_NOTIFY, wParam, (LPARAM)&nmhdr);
512 return editWndProc(hWnd, message, wParam, lParam);
515 static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
517 switch (message)
519 case WM_PAINT:
520 return Child_OnPaint(hWnd);
521 case WM_SIZE:
522 return Child_OnSize(hWnd);
523 case WM_NOTIFY: {
524 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
525 NMHDR *nmhdr = (NMHDR*)lParam;
527 switch(nmhdr->code) {
528 case TCN_SELCHANGE:
529 return OnTabChange(hWnd);
530 case TVN_SELCHANGEDW:
531 return OnTopicChange(info, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam);
532 case NM_DBLCLK:
533 if(!info)
534 return 0;
535 switch(info->current_tab)
537 case TAB_INDEX:
538 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
539 case TAB_SEARCH:
540 return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam);
542 break;
543 case NM_RETURN:
544 if(!info)
545 return 0;
546 switch(info->current_tab) {
547 case TAB_INDEX: {
548 HWND hwndList = info->tabs[TAB_INDEX].hwnd;
549 LVITEMW lvItem;
551 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
552 lvItem.mask = TVIF_PARAM;
553 SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
554 OnTopicChange(info, (void*) lvItem.lParam);
555 return 0;
557 case TAB_SEARCH: {
558 if(nmhdr->hwndFrom == info->search.hwndEdit) {
559 char needle[100];
560 DWORD i, len;
562 len = GetWindowTextA(info->search.hwndEdit, needle, sizeof(needle));
563 if(!len)
565 FIXME("Unable to get search text.\n");
566 return 0;
568 /* Convert the requested text for comparison later against the
569 * lower case version of HTML file contents.
571 for(i=0;i<len;i++)
572 needle[i] = tolower(needle[i]);
573 InitSearch(info, needle);
574 return 0;
575 }else if(nmhdr->hwndFrom == info->search.hwndList) {
576 HWND hwndList = info->search.hwndList;
577 LVITEMW lvItem;
579 lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0);
580 lvItem.mask = TVIF_PARAM;
581 SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
582 OnTopicChange(info, (void*) lvItem.lParam);
583 return 0;
585 break;
588 break;
590 break;
592 default:
593 return DefWindowProcW(hWnd, message, wParam, lParam);
596 return 0;
599 static void HH_RegisterChildWndClass(HHInfo *pHHInfo)
601 WNDCLASSEXW wcex;
603 wcex.cbSize = sizeof(WNDCLASSEXW);
604 wcex.style = 0;
605 wcex.lpfnWndProc = Child_WndProc;
606 wcex.cbClsExtra = 0;
607 wcex.cbWndExtra = 0;
608 wcex.hInstance = hhctrl_hinstance;
609 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
610 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
611 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
612 wcex.lpszMenuName = NULL;
613 wcex.lpszClassName = szChildClass;
614 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
616 RegisterClassExW(&wcex);
619 /* Toolbar */
621 #define ICON_SIZE 20
623 static void TB_OnClick(HWND hWnd, DWORD dwID)
625 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
627 switch (dwID)
629 case IDTB_STOP:
630 DoPageAction(info, WB_STOP);
631 break;
632 case IDTB_REFRESH:
633 DoPageAction(info, WB_REFRESH);
634 break;
635 case IDTB_BACK:
636 DoPageAction(info, WB_GOBACK);
637 break;
638 case IDTB_HOME:
639 NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome);
640 break;
641 case IDTB_FORWARD:
642 DoPageAction(info, WB_GOFORWARD);
643 break;
644 case IDTB_EXPAND:
645 case IDTB_CONTRACT:
646 case IDTB_SYNC:
647 case IDTB_PRINT:
648 case IDTB_OPTIONS:
649 case IDTB_BROWSE_FWD:
650 case IDTB_BROWSE_BACK:
651 case IDTB_JUMP1:
652 case IDTB_JUMP2:
653 case IDTB_CUSTOMIZE:
654 case IDTB_ZOOM:
655 case IDTB_TOC_NEXT:
656 case IDTB_TOC_PREV:
657 break;
661 static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID)
663 /* FIXME: Load the correct button bitmaps */
664 pButtons[dwIndex].iBitmap = STD_PRINT;
665 pButtons[dwIndex].idCommand = dwID;
666 pButtons[dwIndex].fsState = TBSTATE_ENABLED;
667 pButtons[dwIndex].fsStyle = BTNS_BUTTON;
668 pButtons[dwIndex].dwData = 0;
669 pButtons[dwIndex].iString = 0;
672 static void TB_AddButtonsFromFlags(TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons)
674 *pdwNumButtons = 0;
676 if (dwButtonFlags & HHWIN_BUTTON_EXPAND)
677 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND);
679 if (dwButtonFlags & HHWIN_BUTTON_BACK)
680 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK);
682 if (dwButtonFlags & HHWIN_BUTTON_FORWARD)
683 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD);
685 if (dwButtonFlags & HHWIN_BUTTON_STOP)
686 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP);
688 if (dwButtonFlags & HHWIN_BUTTON_REFRESH)
689 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH);
691 if (dwButtonFlags & HHWIN_BUTTON_HOME)
692 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME);
694 if (dwButtonFlags & HHWIN_BUTTON_SYNC)
695 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC);
697 if (dwButtonFlags & HHWIN_BUTTON_OPTIONS)
698 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS);
700 if (dwButtonFlags & HHWIN_BUTTON_PRINT)
701 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT);
703 if (dwButtonFlags & HHWIN_BUTTON_JUMP1)
704 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_JUMP1);
706 if (dwButtonFlags & HHWIN_BUTTON_JUMP2)
707 TB_AddButton(pButtons,(*pdwNumButtons)++, IDTB_JUMP2);
709 if (dwButtonFlags & HHWIN_BUTTON_ZOOM)
710 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_ZOOM);
712 if (dwButtonFlags & HHWIN_BUTTON_TOC_NEXT)
713 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_NEXT);
715 if (dwButtonFlags & HHWIN_BUTTON_TOC_PREV)
716 TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_TOC_PREV);
719 static BOOL HH_AddToolbar(HHInfo *pHHInfo)
721 HWND hToolbar;
722 HWND hwndParent = pHHInfo->WinType.hwndHelp;
723 DWORD toolbarFlags;
724 TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND];
725 TBADDBITMAP tbAB;
726 DWORD dwStyles, dwExStyles;
727 DWORD dwNumButtons, dwIndex;
729 if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS)
730 toolbarFlags = pHHInfo->WinType.fsToolBarFlags;
731 else
732 toolbarFlags = HHWIN_DEF_BUTTONS;
734 TB_AddButtonsFromFlags(buttons, toolbarFlags, &dwNumButtons);
736 dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT |
737 TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER;
738 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
740 hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles,
741 0, 0, 0, 0, hwndParent, NULL,
742 hhctrl_hinstance, NULL);
743 if (!hToolbar)
744 return FALSE;
746 SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE));
747 SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
748 SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE);
750 /* FIXME: Load correct icons for all buttons */
751 tbAB.hInst = HINST_COMMCTRL;
752 tbAB.nID = IDB_STD_LARGE_COLOR;
753 SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB);
755 for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++)
757 LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand);
758 DWORD dwLen = strlenW(szBuf);
759 szBuf[dwLen + 1] = 0; /* Double-null terminate */
761 buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf);
762 heap_free(szBuf);
765 SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)buttons);
766 SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0);
767 ShowWindow(hToolbar, SW_SHOW);
769 pHHInfo->WinType.hwndToolBar = hToolbar;
770 return TRUE;
773 /* Navigation Pane */
775 static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc)
777 HWND hwndParent = pHHInfo->WinType.hwndHelp;
778 HWND hwndToolbar = pHHInfo->WinType.hwndToolBar;
779 RECT rectWND, rectTB;
781 GetClientRect(hwndParent, &rectWND);
782 GetClientRect(hwndToolbar, &rectTB);
784 rc->left = 0;
785 rc->top = rectTB.bottom;
786 rc->bottom = rectWND.bottom - rectTB.bottom;
788 if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) &&
789 pHHInfo->WinType.iNavWidth == 0)
791 pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH;
794 rc->right = pHHInfo->WinType.iNavWidth;
797 static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index)
799 TCITEMW tie;
800 LPWSTR tabText = HH_LoadString(index);
801 DWORD ret;
803 tie.mask = TCIF_TEXT;
804 tie.pszText = tabText;
806 ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie );
808 heap_free(tabText);
809 return ret;
812 static BOOL HH_AddNavigationPane(HHInfo *info)
814 HWND hWnd, hwndTabCtrl;
815 HWND hwndParent = info->WinType.hwndHelp;
816 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE;
817 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR;
818 RECT rc;
820 NP_GetNavigationRect(info, &rc);
822 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
823 rc.left, rc.top, rc.right, rc.bottom,
824 hwndParent, NULL, hhctrl_hinstance, NULL);
825 if (!hWnd)
826 return FALSE;
828 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
830 hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles,
831 0, TAB_TOP_PADDING,
832 rc.right - TAB_RIGHT_PADDING,
833 rc.bottom - TAB_TOP_PADDING,
834 hWnd, NULL, hhctrl_hinstance, NULL);
835 if (!hwndTabCtrl)
836 return FALSE;
838 if (*info->WinType.pszToc)
839 info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS);
841 if (*info->WinType.pszIndex)
842 info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX);
844 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH)
845 info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH);
847 if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES)
848 info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES);
850 SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE);
852 info->hwndTabCtrl = hwndTabCtrl;
853 info->WinType.hwndNavigation = hWnd;
854 return TRUE;
857 /* HTML Pane */
859 static void HP_GetHTMLRect(HHInfo *info, RECT *rc)
861 RECT rectTB, rectWND, rectNP, rectSB;
863 GetClientRect(info->WinType.hwndHelp, &rectWND);
864 GetClientRect(info->WinType.hwndToolBar, &rectTB);
865 GetClientRect(info->WinType.hwndNavigation, &rectNP);
866 GetClientRect(info->hwndSizeBar, &rectSB);
868 rc->left = rectNP.right + rectSB.right;
869 rc->top = rectTB.bottom;
870 rc->right = rectWND.right - rc->left;
871 rc->bottom = rectWND.bottom - rectTB.bottom;
874 static BOOL HH_AddHTMLPane(HHInfo *pHHInfo)
876 HWND hWnd;
877 HWND hwndParent = pHHInfo->WinType.hwndHelp;
878 DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN;
879 DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE;
880 RECT rc;
882 HP_GetHTMLRect(pHHInfo, &rc);
884 hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles,
885 rc.left, rc.top, rc.right, rc.bottom,
886 hwndParent, NULL, hhctrl_hinstance, NULL);
887 if (!hWnd)
888 return FALSE;
890 if (!InitWebBrowser(pHHInfo, hWnd))
891 return FALSE;
893 /* store the pointer to the HH info struct */
894 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)pHHInfo);
896 ShowWindow(hWnd, SW_SHOW);
897 UpdateWindow(hWnd);
899 pHHInfo->WinType.hwndHTML = hWnd;
900 return TRUE;
903 static BOOL AddContentTab(HHInfo *info)
905 if(info->tabs[TAB_CONTENTS].id == -1)
906 return TRUE; /* No "Contents" tab */
907 info->tabs[TAB_CONTENTS].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW,
908 szEmpty, WS_CHILD | WS_BORDER | 0x25, 50, 50, 100, 100,
909 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
910 if(!info->tabs[TAB_CONTENTS].hwnd) {
911 ERR("Could not create treeview control\n");
912 return FALSE;
915 ResizeTabChild(info, TAB_CONTENTS);
916 ShowWindow(info->tabs[TAB_CONTENTS].hwnd, SW_SHOW);
918 return TRUE;
921 static BOOL AddIndexTab(HHInfo *info)
923 char hidden_column[] = "Column";
924 LVCOLUMNA lvc;
926 if(info->tabs[TAB_INDEX].id == -1)
927 return TRUE; /* No "Index" tab */
928 info->tabs[TAB_INDEX].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW,
929 szEmpty, WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
930 info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL);
931 if(!info->tabs[TAB_INDEX].hwnd) {
932 ERR("Could not create ListView control\n");
933 return FALSE;
935 memset(&lvc, 0, sizeof(lvc));
936 lvc.mask = LVCF_TEXT;
937 lvc.pszText = hidden_column;
938 if(SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
940 ERR("Could not create ListView column\n");
941 return FALSE;
944 ResizeTabChild(info, TAB_INDEX);
945 ShowWindow(info->tabs[TAB_INDEX].hwnd, SW_HIDE);
947 return TRUE;
950 static BOOL AddSearchTab(HHInfo *info)
952 HWND hwndList, hwndEdit, hwndContainer;
953 char hidden_column[] = "Column";
954 WNDPROC editWndProc;
955 LVCOLUMNA lvc;
957 if(info->tabs[TAB_SEARCH].id == -1)
958 return TRUE; /* No "Search" tab */
959 hwndContainer = CreateWindowExW(WS_EX_CONTROLPARENT, szChildClass, szEmpty,
960 WS_CHILD, 0, 0, 0, 0, info->WinType.hwndNavigation,
961 NULL, hhctrl_hinstance, NULL);
962 if(!hwndContainer) {
963 ERR("Could not create search window container control.\n");
964 return FALSE;
966 hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, szEmpty, WS_CHILD
967 | WS_VISIBLE | ES_LEFT | SS_NOTIFY, 0, 0, 0, 0,
968 hwndContainer, NULL, hhctrl_hinstance, NULL);
969 if(!hwndEdit) {
970 ERR("Could not create search ListView control.\n");
971 return FALSE;
973 if(SendMessageW(hwndEdit, WM_SETFONT, (WPARAM) info->hFont, (LPARAM) FALSE) == -1)
975 ERR("Could not set font for edit control.\n");
976 return FALSE;
978 editWndProc = (WNDPROC) SetWindowLongPtrW(hwndEdit, GWLP_WNDPROC, (LONG_PTR)EditChild_WndProc);
979 if(!editWndProc) {
980 ERR("Could not redirect messages for edit control.\n");
981 return FALSE;
983 SetWindowLongPtrW(hwndEdit, GWLP_USERDATA, (LONG_PTR)editWndProc);
984 hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty,
985 WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL
986 | LVS_REPORT | LVS_NOCOLUMNHEADER, 0, 0, 0, 0,
987 hwndContainer, NULL, hhctrl_hinstance, NULL);
988 if(!hwndList) {
989 ERR("Could not create search ListView control.\n");
990 return FALSE;
992 memset(&lvc, 0, sizeof(lvc));
993 lvc.mask = LVCF_TEXT;
994 lvc.pszText = hidden_column;
995 if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
997 ERR("Could not create ListView column\n");
998 return FALSE;
1001 info->search.hwndEdit = hwndEdit;
1002 info->search.hwndList = hwndList;
1003 info->search.hwndContainer = hwndContainer;
1004 info->tabs[TAB_SEARCH].hwnd = hwndContainer;
1006 SetWindowLongPtrW(hwndContainer, GWLP_USERDATA, (LONG_PTR)info);
1008 ResizeTabChild(info, TAB_SEARCH);
1010 return TRUE;
1013 /* The Index tab's sub-topic popup */
1015 static void ResizePopupChild(HHInfo *info)
1017 int scroll_width = GetSystemMetrics(SM_CXVSCROLL);
1018 int border_width = GetSystemMetrics(SM_CXBORDER);
1019 int edge_width = GetSystemMetrics(SM_CXEDGE);
1020 INT width, height;
1021 RECT rect;
1023 if(!info)
1024 return;
1026 GetClientRect(info->popup.hwndPopup, &rect);
1027 SetWindowPos(info->popup.hwndCallback, HWND_TOP, 0, 0,
1028 rect.right, rect.bottom, SWP_NOMOVE);
1030 rect.left = TAB_MARGIN;
1031 rect.top = TAB_TOP_PADDING + TAB_MARGIN;
1032 rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN;
1033 rect.bottom -= TAB_MARGIN;
1034 width = rect.right-rect.left;
1035 height = rect.bottom-rect.top;
1037 SetWindowPos(info->popup.hwndList, NULL, rect.left, rect.top, width, height,
1038 SWP_NOZORDER | SWP_NOACTIVATE);
1040 SendMessageW(info->popup.hwndList, LVM_SETCOLUMNWIDTH, 0,
1041 width-scroll_width-2*border_width-2*edge_width);
1044 static LRESULT CALLBACK HelpPopup_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1046 HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1048 switch (message)
1050 case WM_SIZE:
1051 ResizePopupChild(info);
1052 return 0;
1053 case WM_DESTROY:
1054 DestroyWindow(hWnd);
1055 return 0;
1056 case WM_CLOSE:
1057 ShowWindow(hWnd, SW_HIDE);
1058 return 0;
1060 default:
1061 return DefWindowProcW(hWnd, message, wParam, lParam);
1064 return 0;
1067 static LRESULT CALLBACK PopupChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1069 switch (message)
1071 case WM_NOTIFY: {
1072 NMHDR *nmhdr = (NMHDR*)lParam;
1073 switch(nmhdr->code)
1075 case NM_DBLCLK: {
1076 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1077 IndexSubItem *iter;
1079 if(info == 0 || lParam == 0)
1080 return 0;
1081 iter = (IndexSubItem*) ((NMITEMACTIVATE *)lParam)->lParam;
1082 if(iter == 0)
1083 return 0;
1084 NavigateToChm(info, info->index->merge.chm_file, iter->local);
1085 ShowWindow(info->popup.hwndPopup, SW_HIDE);
1086 return 0;
1088 case NM_RETURN: {
1089 HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1090 IndexSubItem *iter;
1091 LVITEMW lvItem;
1093 if(info == 0)
1094 return 0;
1096 lvItem.iItem = (int) SendMessageW(info->popup.hwndList, LVM_GETSELECTIONMARK, 0, 0);
1097 lvItem.mask = TVIF_PARAM;
1098 SendMessageW(info->popup.hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem);
1099 iter = (IndexSubItem*) lvItem.lParam;
1100 NavigateToChm(info, info->index->merge.chm_file, iter->local);
1101 ShowWindow(info->popup.hwndPopup, SW_HIDE);
1102 return 0;
1105 break;
1107 default:
1108 return DefWindowProcW(hWnd, message, wParam, lParam);
1111 return 0;
1114 static BOOL AddIndexPopup(HHInfo *info)
1116 static const WCHAR szPopupChildClass[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0};
1117 static const WCHAR windowCaptionW[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0};
1118 static const WCHAR windowClassW[] = {'H','H',' ','P','o','p','u','p',0};
1119 HWND hwndList, hwndPopup, hwndCallback;
1120 char hidden_column[] = "Column";
1121 WNDCLASSEXW wcex;
1122 LVCOLUMNA lvc;
1124 if(info->tabs[TAB_INDEX].id == -1)
1125 return TRUE; /* No "Index" tab */
1127 wcex.cbSize = sizeof(WNDCLASSEXW);
1128 wcex.style = CS_HREDRAW | CS_VREDRAW;
1129 wcex.lpfnWndProc = HelpPopup_WndProc;
1130 wcex.cbClsExtra = 0;
1131 wcex.cbWndExtra = 0;
1132 wcex.hInstance = hhctrl_hinstance;
1133 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1134 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1135 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1136 wcex.lpszMenuName = NULL;
1137 wcex.lpszClassName = windowClassW;
1138 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1139 RegisterClassExW(&wcex);
1141 wcex.cbSize = sizeof(WNDCLASSEXW);
1142 wcex.style = 0;
1143 wcex.lpfnWndProc = PopupChild_WndProc;
1144 wcex.cbClsExtra = 0;
1145 wcex.cbWndExtra = 0;
1146 wcex.hInstance = hhctrl_hinstance;
1147 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1148 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1149 wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
1150 wcex.lpszMenuName = NULL;
1151 wcex.lpszClassName = szPopupChildClass;
1152 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1153 RegisterClassExW(&wcex);
1155 hwndPopup = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW
1156 | WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR,
1157 windowClassW, windowCaptionW, WS_POPUPWINDOW
1158 | WS_OVERLAPPEDWINDOW | WS_VISIBLE
1159 | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT,
1160 CW_USEDEFAULT, 300, 200, info->WinType.hwndHelp,
1161 NULL, hhctrl_hinstance, NULL);
1162 if (!hwndPopup)
1163 return FALSE;
1165 hwndCallback = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR,
1166 szPopupChildClass, szEmpty, WS_CHILDWINDOW | WS_VISIBLE,
1167 0, 0, 0, 0,
1168 hwndPopup, NULL, hhctrl_hinstance, NULL);
1169 if (!hwndCallback)
1170 return FALSE;
1172 ShowWindow(hwndPopup, SW_HIDE);
1173 hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty,
1174 WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT
1175 | LVS_NOCOLUMNHEADER, 50, 50, 100, 100,
1176 hwndCallback, NULL, hhctrl_hinstance, NULL);
1177 if(!hwndList) {
1178 ERR("Could not create popup ListView control\n");
1179 return FALSE;
1181 memset(&lvc, 0, sizeof(lvc));
1182 lvc.mask = LVCF_TEXT;
1183 lvc.pszText = hidden_column;
1184 if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1)
1186 ERR("Could not create popup ListView column\n");
1187 return FALSE;
1190 info->popup.hwndCallback = hwndCallback;
1191 info->popup.hwndPopup = hwndPopup;
1192 info->popup.hwndList = hwndList;
1193 SetWindowLongPtrW(hwndPopup, GWLP_USERDATA, (LONG_PTR)info);
1194 SetWindowLongPtrW(hwndCallback, GWLP_USERDATA, (LONG_PTR)info);
1196 ResizePopupChild(info);
1197 ShowWindow(hwndList, SW_SHOW);
1199 return TRUE;
1202 /* Viewer Window */
1204 static LRESULT Help_OnSize(HWND hWnd)
1206 HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA);
1207 DWORD dwSize;
1208 RECT rc;
1210 if (!pHHInfo)
1211 return 0;
1213 NP_GetNavigationRect(pHHInfo, &rc);
1214 SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0,
1215 rc.right, rc.bottom, SWP_NOMOVE);
1217 SB_GetSizeBarRect(pHHInfo, &rc);
1218 SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top,
1219 rc.right, rc.bottom, SWP_SHOWWINDOW);
1221 HP_GetHTMLRect(pHHInfo, &rc);
1222 SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top,
1223 rc.right, rc.bottom, SWP_SHOWWINDOW);
1225 /* Resize browser window taking the frame size into account */
1226 dwSize = GetSystemMetrics(SM_CXFRAME);
1227 ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize);
1229 return 0;
1232 static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
1234 switch (message)
1236 case WM_COMMAND:
1237 if (HIWORD(wParam) == BN_CLICKED)
1238 TB_OnClick(hWnd, LOWORD(wParam));
1239 break;
1240 case WM_SIZE:
1241 return Help_OnSize(hWnd);
1242 case WM_CLOSE:
1243 ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, GWLP_USERDATA));
1244 return 0;
1245 case WM_DESTROY:
1246 if(hh_process)
1247 PostQuitMessage(0);
1248 break;
1250 default:
1251 return DefWindowProcW(hWnd, message, wParam, lParam);
1254 return 0;
1257 static BOOL HH_CreateHelpWindow(HHInfo *info)
1259 HWND hWnd;
1260 RECT winPos = info->WinType.rcWindowPos;
1261 WNDCLASSEXW wcex;
1262 DWORD dwStyles, dwExStyles;
1263 DWORD x, y, width = 0, height = 0;
1264 LPCWSTR caption;
1266 static const WCHAR windowClassW[] = {
1267 'H','H',' ', 'P','a','r','e','n','t',0
1270 wcex.cbSize = sizeof(WNDCLASSEXW);
1271 wcex.style = CS_HREDRAW | CS_VREDRAW;
1272 wcex.lpfnWndProc = Help_WndProc;
1273 wcex.cbClsExtra = 0;
1274 wcex.cbWndExtra = 0;
1275 wcex.hInstance = hhctrl_hinstance;
1276 wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1277 wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW);
1278 wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1);
1279 wcex.lpszMenuName = NULL;
1280 wcex.lpszClassName = windowClassW;
1281 wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION);
1283 RegisterClassExW(&wcex);
1285 /* Read in window parameters if available */
1286 if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES)
1287 dwStyles = info->WinType.dwStyles | WS_OVERLAPPEDWINDOW;
1288 else
1289 dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE |
1290 WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
1292 if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES)
1293 dwExStyles = info->WinType.dwExStyles;
1294 else
1295 dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
1296 WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR;
1298 if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT)
1300 x = winPos.left;
1301 y = winPos.top;
1302 width = winPos.right - x;
1303 height = winPos.bottom - y;
1305 if (!width || !height)
1307 x = WINTYPE_DEFAULT_X;
1308 y = WINTYPE_DEFAULT_Y;
1309 width = WINTYPE_DEFAULT_WIDTH;
1310 height = WINTYPE_DEFAULT_HEIGHT;
1313 caption = info->WinType.pszCaption;
1314 if (!*caption) caption = info->pCHMInfo->defTitle;
1316 hWnd = CreateWindowExW(dwExStyles, windowClassW, caption,
1317 dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL);
1318 if (!hWnd)
1319 return FALSE;
1321 ShowWindow(hWnd, SW_SHOW);
1322 UpdateWindow(hWnd);
1324 /* store the pointer to the HH info struct */
1325 SetWindowLongPtrW(hWnd, GWLP_USERDATA, (LONG_PTR)info);
1327 info->WinType.hwndHelp = hWnd;
1328 return TRUE;
1331 static void HH_CreateFont(HHInfo *pHHInfo)
1333 LOGFONTW lf;
1335 GetObjectW(GetStockObject(ANSI_VAR_FONT), sizeof(LOGFONTW), &lf);
1336 lf.lfWeight = FW_NORMAL;
1337 lf.lfItalic = FALSE;
1338 lf.lfUnderline = FALSE;
1340 pHHInfo->hFont = CreateFontIndirectW(&lf);
1343 static void HH_InitRequiredControls(DWORD dwControls)
1345 INITCOMMONCONTROLSEX icex;
1347 icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
1348 icex.dwICC = dwControls;
1349 InitCommonControlsEx(&icex);
1352 /* Creates the whole package */
1353 static BOOL CreateViewer(HHInfo *pHHInfo)
1355 HH_CreateFont(pHHInfo);
1357 if (!HH_CreateHelpWindow(pHHInfo))
1358 return FALSE;
1360 HH_InitRequiredControls(ICC_BAR_CLASSES);
1362 if (!HH_AddToolbar(pHHInfo))
1363 return FALSE;
1365 HH_RegisterChildWndClass(pHHInfo);
1367 if (!HH_AddNavigationPane(pHHInfo))
1368 return FALSE;
1370 HH_RegisterSizeBarClass(pHHInfo);
1372 if (!HH_AddSizeBar(pHHInfo))
1373 return FALSE;
1375 if (!HH_AddHTMLPane(pHHInfo))
1376 return FALSE;
1378 if (!AddContentTab(pHHInfo))
1379 return FALSE;
1381 if (!AddIndexTab(pHHInfo))
1382 return FALSE;
1384 if (!AddIndexPopup(pHHInfo))
1385 return FALSE;
1387 if (!AddSearchTab(pHHInfo))
1388 return FALSE;
1390 InitContent(pHHInfo);
1391 InitIndex(pHHInfo);
1393 return TRUE;
1396 void ReleaseHelpViewer(HHInfo *info)
1398 TRACE("(%p)\n", info);
1400 if (!info)
1401 return;
1403 /* Free allocated strings */
1404 heap_free(info->pszType);
1405 heap_free(info->pszCaption);
1406 heap_free(info->pszToc);
1407 heap_free(info->pszIndex);
1408 heap_free(info->pszFile);
1409 heap_free(info->pszHome);
1410 heap_free(info->pszJump1);
1411 heap_free(info->pszJump2);
1412 heap_free(info->pszUrlJump1);
1413 heap_free(info->pszUrlJump2);
1415 if (info->pCHMInfo)
1416 CloseCHM(info->pCHMInfo);
1418 ReleaseWebBrowser(info);
1419 ReleaseContent(info);
1420 ReleaseIndex(info);
1421 ReleaseSearch(info);
1423 if(info->WinType.hwndHelp)
1424 DestroyWindow(info->WinType.hwndHelp);
1426 heap_free(info);
1427 OleUninitialize();
1430 HHInfo *CreateHelpViewer(LPCWSTR filename)
1432 HHInfo *info = heap_alloc_zero(sizeof(HHInfo));
1433 int i;
1435 /* Set the invalid tab ID (-1) as the default value for all
1436 * of the tabs, this matches a failed TCM_INSERTITEM call.
1438 for(i=0;i<sizeof(info->tabs)/sizeof(HHTab);i++)
1439 info->tabs[i].id = -1;
1441 OleInitialize(NULL);
1443 info->pCHMInfo = OpenCHM(filename);
1444 if(!info->pCHMInfo) {
1445 ReleaseHelpViewer(info);
1446 return NULL;
1449 if (!LoadWinTypeFromCHM(info)) {
1450 ReleaseHelpViewer(info);
1451 return NULL;
1454 if(!CreateViewer(info)) {
1455 ReleaseHelpViewer(info);
1456 return NULL;
1459 return info;