James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Help Viewer Implementation |
| 3 | * |
| 4 | * Copyright 2005 James Hawkins |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 5 | * Copyright 2007 Jacek Caban for CodeWeavers |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 6 | * Copyright 2011 Owen Rudge for CodeWeavers |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
Jacek Caban | 6e72b26 | 2007-02-22 22:45:16 +0100 | [diff] [blame] | 23 | #include "hhctrl.h" |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 24 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 25 | #include "wingdi.h" |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 26 | #include "commctrl.h" |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 27 | #include "wininet.h" |
| 28 | |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 29 | #include "wine/debug.h" |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 30 | |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 31 | #include "resource.h" |
| 32 | |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 33 | WINE_DEFAULT_DEBUG_CHANNEL(htmlhelp); |
| 34 | |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 35 | static LRESULT Help_OnSize(HWND hWnd); |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 36 | static void ExpandContract(HHInfo *pHHInfo); |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 37 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 38 | /* Window type defaults */ |
| 39 | |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 40 | #define WINTYPE_DEFAULT_X 280 |
| 41 | #define WINTYPE_DEFAULT_Y 100 |
| 42 | #define WINTYPE_DEFAULT_WIDTH 740 |
| 43 | #define WINTYPE_DEFAULT_HEIGHT 640 |
James Hawkins | 2a4cbe0 | 2005-09-20 12:00:46 +0000 | [diff] [blame] | 44 | #define WINTYPE_DEFAULT_NAVWIDTH 250 |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 45 | |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 46 | #define TAB_TOP_PADDING 8 |
| 47 | #define TAB_RIGHT_PADDING 4 |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 48 | #define TAB_MARGIN 8 |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 49 | #define EDIT_HEIGHT 20 |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 50 | |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 51 | static const WCHAR szEmpty[] = {0}; |
| 52 | |
Erich Hoover | 9033b14 | 2012-06-20 14:31:10 -0600 | [diff] [blame] | 53 | struct html_encoded_symbol { |
| 54 | const char *html_code; |
| 55 | char ansi_symbol; |
| 56 | }; |
| 57 | |
| 58 | /* |
| 59 | * Table mapping the conversion between HTML encoded symbols and their ANSI code page equivalent. |
| 60 | * Note: Add additional entries in proper alphabetical order (a binary search is used on this table). |
| 61 | */ |
| 62 | struct html_encoded_symbol html_encoded_symbols[] = |
| 63 | { |
| 64 | {"AElig", 0xC6}, |
| 65 | {"Aacute", 0xC1}, |
| 66 | {"Acirc", 0xC2}, |
| 67 | {"Agrave", 0xC0}, |
| 68 | {"Aring", 0xC5}, |
| 69 | {"Atilde", 0xC3}, |
| 70 | {"Auml", 0xC4}, |
| 71 | {"Ccedil", 0xC7}, |
| 72 | {"ETH", 0xD0}, |
| 73 | {"Eacute", 0xC9}, |
| 74 | {"Ecirc", 0xCA}, |
| 75 | {"Egrave", 0xC8}, |
| 76 | {"Euml", 0xCB}, |
| 77 | {"Iacute", 0xCD}, |
| 78 | {"Icirc", 0xCE}, |
| 79 | {"Igrave", 0xCC}, |
| 80 | {"Iuml", 0xCF}, |
| 81 | {"Ntilde", 0xD1}, |
| 82 | {"Oacute", 0xD3}, |
| 83 | {"Ocirc", 0xD4}, |
| 84 | {"Ograve", 0xD2}, |
| 85 | {"Oslash", 0xD8}, |
| 86 | {"Otilde", 0xD5}, |
| 87 | {"Ouml", 0xD6}, |
| 88 | {"THORN", 0xDE}, |
| 89 | {"Uacute", 0xDA}, |
| 90 | {"Ucirc", 0xDB}, |
| 91 | {"Ugrave", 0xD9}, |
| 92 | {"Uuml", 0xDC}, |
| 93 | {"Yacute", 0xDD}, |
| 94 | {"aacute", 0xE1}, |
| 95 | {"acirc", 0xE2}, |
| 96 | {"acute", 0xB4}, |
| 97 | {"aelig", 0xE6}, |
| 98 | {"agrave", 0xE0}, |
| 99 | {"amp", '&'}, |
| 100 | {"aring", 0xE5}, |
| 101 | {"atilde", 0xE3}, |
| 102 | {"auml", 0xE4}, |
| 103 | {"brvbar", 0xA6}, |
| 104 | {"ccedil", 0xE7}, |
| 105 | {"cedil", 0xB8}, |
| 106 | {"cent", 0xA2}, |
| 107 | {"copy", 0xA9}, |
| 108 | {"curren", 0xA4}, |
| 109 | {"deg", 0xB0}, |
| 110 | {"divide", 0xF7}, |
| 111 | {"eacute", 0xE9}, |
| 112 | {"ecirc", 0xEA}, |
| 113 | {"egrave", 0xE8}, |
| 114 | {"eth", 0xF0}, |
| 115 | {"euml", 0xEB}, |
| 116 | {"frac12", 0xBD}, |
| 117 | {"frac14", 0xBC}, |
| 118 | {"frac34", 0xBE}, |
| 119 | {"gt", '>'}, |
| 120 | {"iacute", 0xED}, |
| 121 | {"icirc", 0xEE}, |
| 122 | {"iexcl", 0xA1}, |
| 123 | {"igrave", 0xEC}, |
| 124 | {"iquest", 0xBF}, |
| 125 | {"iuml", 0xEF}, |
| 126 | {"laquo", 0xAB}, |
| 127 | {"lt", '<'}, |
| 128 | {"macr", 0xAF}, |
| 129 | {"micro", 0xB5}, |
| 130 | {"middot", 0xB7}, |
| 131 | {"nbsp", ' '}, |
| 132 | {"not", 0xAC}, |
| 133 | {"ntilde", 0xF1}, |
| 134 | {"oacute", 0xF3}, |
| 135 | {"ocirc", 0xF4}, |
| 136 | {"ograve", 0xF2}, |
| 137 | {"ordf", 0xAA}, |
| 138 | {"ordm", 0xBA}, |
| 139 | {"oslash", 0xF8}, |
| 140 | {"otilde", 0xF5}, |
| 141 | {"ouml", 0xF6}, |
| 142 | {"para", 0xB6}, |
| 143 | {"plusmn", 0xB1}, |
| 144 | {"pound", 0xA3}, |
| 145 | {"quot", '"'}, |
| 146 | {"raquo", 0xBB}, |
| 147 | {"reg", 0xAE}, |
| 148 | {"sect", 0xA7}, |
| 149 | {"shy", 0xAD}, |
| 150 | {"sup1", 0xB9}, |
| 151 | {"sup2", 0xB2}, |
| 152 | {"sup3", 0xB3}, |
| 153 | {"szlig", 0xDF}, |
| 154 | {"thorn", 0xFE}, |
| 155 | {"times", 0xD7}, |
| 156 | {"uacute", 0xFA}, |
| 157 | {"ucirc", 0xFB}, |
| 158 | {"ugrave", 0xF9}, |
| 159 | {"uml", 0xA8}, |
| 160 | {"uuml", 0xFC}, |
| 161 | {"yacute", 0xFD}, |
| 162 | {"yen", 0xA5}, |
| 163 | {"yuml", 0xFF} |
| 164 | }; |
| 165 | |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 166 | /* Loads a string from the resource file */ |
| 167 | static LPWSTR HH_LoadString(DWORD dwID) |
| 168 | { |
| 169 | LPWSTR string = NULL; |
Christopher Berner | 9978cc9 | 2008-03-05 12:28:54 -0800 | [diff] [blame] | 170 | LPCWSTR stringresource; |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 171 | int iSize; |
| 172 | |
Christopher Berner | 9978cc9 | 2008-03-05 12:28:54 -0800 | [diff] [blame] | 173 | iSize = LoadStringW(hhctrl_hinstance, dwID, (LPWSTR)&stringresource, 0); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 174 | |
Christopher Berner | 9978cc9 | 2008-03-05 12:28:54 -0800 | [diff] [blame] | 175 | string = heap_alloc((iSize + 2) * sizeof(WCHAR)); /* some strings (tab text) needs double-null termination */ |
| 176 | memcpy(string, stringresource, iSize*sizeof(WCHAR)); |
| 177 | string[iSize] = 0; |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 178 | |
| 179 | return string; |
| 180 | } |
| 181 | |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 182 | static HRESULT navigate_url(HHInfo *info, LPCWSTR surl) |
Jacek Caban | 736ef40 | 2007-02-28 03:55:39 +0100 | [diff] [blame] | 183 | { |
| 184 | VARIANT url; |
| 185 | HRESULT hres; |
| 186 | |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 187 | TRACE("%s\n", debugstr_w(surl)); |
| 188 | |
Jacek Caban | 736ef40 | 2007-02-28 03:55:39 +0100 | [diff] [blame] | 189 | V_VT(&url) = VT_BSTR; |
| 190 | V_BSTR(&url) = SysAllocString(surl); |
| 191 | |
| 192 | hres = IWebBrowser2_Navigate2(info->web_browser, &url, 0, 0, 0, 0); |
| 193 | |
| 194 | VariantClear(&url); |
| 195 | |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 196 | if(FAILED(hres)) |
Michael Stefaniuc | eff5b13 | 2007-03-05 13:48:23 +0100 | [diff] [blame] | 197 | TRACE("Navigation failed: %08x\n", hres); |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 198 | |
| 199 | return hres; |
| 200 | } |
| 201 | |
| 202 | BOOL NavigateToUrl(HHInfo *info, LPCWSTR surl) |
| 203 | { |
| 204 | ChmPath chm_path; |
| 205 | BOOL ret; |
| 206 | HRESULT hres; |
| 207 | |
Rob Shearman | 89b479c | 2008-08-17 18:33:01 +0100 | [diff] [blame] | 208 | static const WCHAR url_indicator[] = {':', '/', '/', 0}; |
Hin-Tak Leung | 8988ab8 | 2008-04-14 20:17:27 +0000 | [diff] [blame] | 209 | |
| 210 | TRACE("%s\n", debugstr_w(surl)); |
| 211 | |
| 212 | if (strstrW(surl, url_indicator)) { |
| 213 | hres = navigate_url(info, surl); |
| 214 | if(SUCCEEDED(hres)) |
| 215 | return TRUE; |
| 216 | } /* look up in chm if it doesn't look like a full url */ |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 217 | |
| 218 | SetChmPath(&chm_path, info->pCHMInfo->szFile, surl); |
| 219 | ret = NavigateToChm(info, chm_path.chm_file, chm_path.chm_index); |
| 220 | |
Michael Stefaniuc | 7e8d79f | 2007-12-09 16:29:44 +0100 | [diff] [blame] | 221 | heap_free(chm_path.chm_file); |
| 222 | heap_free(chm_path.chm_index); |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 223 | |
| 224 | return ret; |
Jacek Caban | 736ef40 | 2007-02-28 03:55:39 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Francois Gouget | f814b5a | 2011-03-16 08:32:01 +0100 | [diff] [blame] | 227 | static BOOL AppendFullPathURL(LPCWSTR file, LPWSTR buf, LPCWSTR index) |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 228 | { |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 229 | static const WCHAR url_format[] = |
Vincent Povirk | c689451 | 2009-08-07 15:27:18 +0200 | [diff] [blame] | 230 | {'m','k',':','@','M','S','I','T','S','t','o','r','e',':','%','s',':',':','%','s','%','s',0}; |
| 231 | static const WCHAR slash[] = {'/',0}; |
| 232 | static const WCHAR empty[] = {0}; |
Owen Rudge | 16b35e0 | 2011-01-17 22:26:46 +0000 | [diff] [blame] | 233 | WCHAR full_path[MAX_PATH]; |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 234 | |
Owen Rudge | 16b35e0 | 2011-01-17 22:26:46 +0000 | [diff] [blame] | 235 | TRACE("%s %p %s\n", debugstr_w(file), buf, debugstr_w(index)); |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 236 | |
Rob Shearman | cedf630 | 2008-02-14 14:38:44 +0000 | [diff] [blame] | 237 | if(!GetFullPathNameW(file, sizeof(full_path)/sizeof(full_path[0]), full_path, NULL)) { |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 238 | WARN("GetFullPathName failed: %u\n", GetLastError()); |
| 239 | return FALSE; |
| 240 | } |
| 241 | |
Vladimir Pankratov | 01128fa | 2009-08-11 17:07:00 +0500 | [diff] [blame] | 242 | wsprintfW(buf, url_format, full_path, (!index || index[0] == '/') ? empty : slash, index); |
Owen Rudge | 16b35e0 | 2011-01-17 22:26:46 +0000 | [diff] [blame] | 243 | return TRUE; |
| 244 | } |
| 245 | |
| 246 | BOOL NavigateToChm(HHInfo *info, LPCWSTR file, LPCWSTR index) |
| 247 | { |
| 248 | WCHAR buf[INTERNET_MAX_URL_LENGTH]; |
| 249 | LPWSTR ptr; |
| 250 | |
| 251 | TRACE("%p %s %s\n", info, debugstr_w(file), debugstr_w(index)); |
| 252 | |
| 253 | if ((!info->web_browser) || !AppendFullPathURL(file, buf, index)) |
| 254 | return FALSE; |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 255 | |
Jacek Caban | 736ef40 | 2007-02-28 03:55:39 +0100 | [diff] [blame] | 256 | /* FIXME: HACK */ |
| 257 | if((ptr = strchrW(buf, '#'))) |
| 258 | *ptr = 0; |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 259 | |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 260 | return SUCCEEDED(navigate_url(info, buf)); |
Jacek Caban | 719bfaf | 2007-02-06 20:47:29 +0100 | [diff] [blame] | 261 | } |
| 262 | |
Owen Rudge | 16b35e0 | 2011-01-17 22:26:46 +0000 | [diff] [blame] | 263 | static void DoSync(HHInfo *info) |
| 264 | { |
| 265 | WCHAR buf[INTERNET_MAX_URL_LENGTH]; |
| 266 | HRESULT hres; |
| 267 | DWORD len; |
| 268 | BSTR url; |
| 269 | |
| 270 | hres = IWebBrowser2_get_LocationURL(info->web_browser, &url); |
| 271 | |
| 272 | if (FAILED(hres)) |
| 273 | { |
| 274 | WARN("get_LocationURL failed: %08x\n", hres); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | /* If we're not currently viewing a page in the active .chm file, abort */ |
| 279 | if ((!AppendFullPathURL(info->pszFile, buf, NULL)) || (len = lstrlenW(buf) > lstrlenW(url))) |
| 280 | { |
| 281 | SysFreeString(url); |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | if (lstrcmpiW(buf, url) > 0) |
| 286 | { |
| 287 | static const WCHAR delimW[] = {':',':','/',0}; |
| 288 | const WCHAR *index; |
| 289 | |
| 290 | index = strstrW(url, delimW); |
| 291 | |
| 292 | if (index) |
| 293 | ActivateContentTopic(info->tabs[TAB_CONTENTS].hwnd, index + 3, info->content); /* skip over ::/ */ |
| 294 | } |
| 295 | |
| 296 | SysFreeString(url); |
| 297 | } |
| 298 | |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 299 | /* Size Bar */ |
| 300 | |
| 301 | #define SIZEBAR_WIDTH 4 |
| 302 | |
| 303 | static const WCHAR szSizeBarClass[] = { |
| 304 | 'H','H',' ','S','i','z','e','B','a','r',0 |
| 305 | }; |
| 306 | |
| 307 | /* Draw the SizeBar */ |
| 308 | static void SB_OnPaint(HWND hWnd) |
| 309 | { |
| 310 | PAINTSTRUCT ps; |
| 311 | HDC hdc; |
| 312 | RECT rc; |
| 313 | |
| 314 | hdc = BeginPaint(hWnd, &ps); |
| 315 | |
| 316 | GetClientRect(hWnd, &rc); |
| 317 | |
| 318 | /* dark frame */ |
| 319 | rc.right += 1; |
| 320 | rc.bottom -= 1; |
| 321 | FrameRect(hdc, &rc, GetStockObject(GRAY_BRUSH)); |
| 322 | |
| 323 | /* white highlight */ |
| 324 | SelectObject(hdc, GetStockObject(WHITE_PEN)); |
| 325 | MoveToEx(hdc, rc.right, 1, NULL); |
| 326 | LineTo(hdc, 1, 1); |
| 327 | LineTo(hdc, 1, rc.bottom - 1); |
| 328 | |
| 329 | |
| 330 | MoveToEx(hdc, 0, rc.bottom, NULL); |
| 331 | LineTo(hdc, rc.right, rc.bottom); |
| 332 | |
| 333 | EndPaint(hWnd, &ps); |
| 334 | } |
| 335 | |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 336 | static void SB_OnLButtonDown(HWND hWnd, WPARAM wParam, LPARAM lParam) |
| 337 | { |
| 338 | SetCapture(hWnd); |
| 339 | } |
| 340 | |
| 341 | static void SB_OnLButtonUp(HWND hWnd, WPARAM wParam, LPARAM lParam) |
| 342 | { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 343 | HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, 0); |
Alexandre Julliard | 44e8ead | 2006-10-25 17:41:58 +0200 | [diff] [blame] | 344 | POINT pt; |
| 345 | |
| 346 | pt.x = (short)LOWORD(lParam); |
| 347 | pt.y = (short)HIWORD(lParam); |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 348 | |
| 349 | /* update the window sizes */ |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 350 | pHHInfo->WinType.iNavWidth += pt.x; |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 351 | Help_OnSize(hWnd); |
| 352 | |
| 353 | ReleaseCapture(); |
| 354 | } |
| 355 | |
| 356 | static void SB_OnMouseMove(HWND hWnd, WPARAM wParam, LPARAM lParam) |
| 357 | { |
| 358 | /* ignore WM_MOUSEMOVE if not dragging the SizeBar */ |
| 359 | if (!(wParam & MK_LBUTTON)) |
| 360 | return; |
| 361 | } |
| 362 | |
Alexandre Julliard | 9d5d7bf | 2006-08-02 22:02:25 +0200 | [diff] [blame] | 363 | static LRESULT CALLBACK SizeBar_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 364 | { |
| 365 | switch (message) |
| 366 | { |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 367 | case WM_LBUTTONDOWN: |
| 368 | SB_OnLButtonDown(hWnd, wParam, lParam); |
| 369 | break; |
| 370 | case WM_LBUTTONUP: |
| 371 | SB_OnLButtonUp(hWnd, wParam, lParam); |
| 372 | break; |
| 373 | case WM_MOUSEMOVE: |
| 374 | SB_OnMouseMove(hWnd, wParam, lParam); |
| 375 | break; |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 376 | case WM_PAINT: |
| 377 | SB_OnPaint(hWnd); |
| 378 | break; |
| 379 | default: |
| 380 | return DefWindowProcW(hWnd, message, wParam, lParam); |
| 381 | } |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
| 386 | static void HH_RegisterSizeBarClass(HHInfo *pHHInfo) |
| 387 | { |
| 388 | WNDCLASSEXW wcex; |
| 389 | |
| 390 | wcex.cbSize = sizeof(WNDCLASSEXW); |
| 391 | wcex.style = 0; |
Jacek Caban | 74fffe6 | 2007-02-28 03:50:14 +0100 | [diff] [blame] | 392 | wcex.lpfnWndProc = SizeBar_WndProc; |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 393 | wcex.cbClsExtra = 0; |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 394 | wcex.cbWndExtra = sizeof(LONG_PTR); |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 395 | wcex.hInstance = hhctrl_hinstance; |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 396 | wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 397 | wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_SIZEWE); |
| 398 | wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1); |
| 399 | wcex.lpszMenuName = NULL; |
| 400 | wcex.lpszClassName = szSizeBarClass; |
| 401 | wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 402 | |
| 403 | RegisterClassExW(&wcex); |
| 404 | } |
| 405 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 406 | static void SB_GetSizeBarRect(HHInfo *info, RECT *rc) |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 407 | { |
| 408 | RECT rectWND, rectTB, rectNP; |
| 409 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 410 | GetClientRect(info->WinType.hwndHelp, &rectWND); |
| 411 | GetClientRect(info->WinType.hwndToolBar, &rectTB); |
| 412 | GetClientRect(info->WinType.hwndNavigation, &rectNP); |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 413 | |
| 414 | rc->left = rectNP.right; |
| 415 | rc->top = rectTB.bottom; |
| 416 | rc->bottom = rectWND.bottom - rectTB.bottom; |
| 417 | rc->right = SIZEBAR_WIDTH; |
| 418 | } |
| 419 | |
| 420 | static BOOL HH_AddSizeBar(HHInfo *pHHInfo) |
| 421 | { |
| 422 | HWND hWnd; |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 423 | HWND hwndParent = pHHInfo->WinType.hwndHelp; |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 424 | DWORD dwStyles = WS_CHILDWINDOW | WS_OVERLAPPED; |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 425 | DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR; |
| 426 | RECT rc; |
| 427 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 428 | if (!pHHInfo->WinType.fNotExpanded) |
| 429 | dwStyles |= WS_VISIBLE; |
| 430 | |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 431 | SB_GetSizeBarRect(pHHInfo, &rc); |
| 432 | |
| 433 | hWnd = CreateWindowExW(dwExStyles, szSizeBarClass, szEmpty, dwStyles, |
| 434 | rc.left, rc.top, rc.right, rc.bottom, |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 435 | hwndParent, NULL, hhctrl_hinstance, NULL); |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 436 | if (!hWnd) |
| 437 | return FALSE; |
| 438 | |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 439 | /* store the pointer to the HH info struct */ |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 440 | SetWindowLongPtrW(hWnd, 0, (LONG_PTR)pHHInfo); |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 441 | |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 442 | pHHInfo->hwndSizeBar = hWnd; |
| 443 | return TRUE; |
| 444 | } |
| 445 | |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 446 | /* Child Window */ |
| 447 | |
| 448 | static const WCHAR szChildClass[] = { |
| 449 | 'H','H',' ','C','h','i','l','d',0 |
| 450 | }; |
| 451 | |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 452 | static LRESULT Child_OnPaint(HWND hWnd) |
James Hawkins | 33eb060 | 2005-08-15 09:40:24 +0000 | [diff] [blame] | 453 | { |
| 454 | PAINTSTRUCT ps; |
| 455 | HDC hdc; |
| 456 | RECT rc; |
| 457 | |
| 458 | hdc = BeginPaint(hWnd, &ps); |
| 459 | |
| 460 | /* Only paint the Navigation pane, identified by the fact |
| 461 | * that it has a child window |
| 462 | */ |
| 463 | if (GetWindow(hWnd, GW_CHILD)) |
| 464 | { |
| 465 | GetClientRect(hWnd, &rc); |
| 466 | |
| 467 | /* set the border color */ |
| 468 | SelectObject(hdc, GetStockObject(DC_PEN)); |
| 469 | SetDCPenColor(hdc, GetSysColor(COLOR_BTNSHADOW)); |
| 470 | |
James Hawkins | 2a4cbe0 | 2005-09-20 12:00:46 +0000 | [diff] [blame] | 471 | /* Draw the top border */ |
| 472 | LineTo(hdc, rc.right, 0); |
James Hawkins | 33eb060 | 2005-08-15 09:40:24 +0000 | [diff] [blame] | 473 | |
James Hawkins | 2a4cbe0 | 2005-09-20 12:00:46 +0000 | [diff] [blame] | 474 | SelectObject(hdc, GetStockObject(WHITE_PEN)); |
| 475 | MoveToEx(hdc, 0, 1, NULL); |
| 476 | LineTo(hdc, rc.right, 1); |
James Hawkins | 33eb060 | 2005-08-15 09:40:24 +0000 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | EndPaint(hWnd, &ps); |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 480 | |
| 481 | return 0; |
| 482 | } |
| 483 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 484 | static void ResizeTabChild(HHInfo *info, int tab) |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 485 | { |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 486 | HWND hwnd = info->tabs[tab].hwnd; |
| 487 | INT width, height; |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 488 | RECT rect, tabrc; |
| 489 | DWORD cnt; |
| 490 | |
| 491 | GetClientRect(info->WinType.hwndNavigation, &rect); |
| 492 | SendMessageW(info->hwndTabCtrl, TCM_GETITEMRECT, 0, (LPARAM)&tabrc); |
| 493 | cnt = SendMessageW(info->hwndTabCtrl, TCM_GETROWCOUNT, 0, 0); |
| 494 | |
| 495 | rect.left = TAB_MARGIN; |
| 496 | rect.top = TAB_TOP_PADDING + cnt*(tabrc.bottom-tabrc.top) + TAB_MARGIN; |
| 497 | rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN; |
| 498 | rect.bottom -= TAB_MARGIN; |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 499 | width = rect.right-rect.left; |
| 500 | height = rect.bottom-rect.top; |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 501 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 502 | SetWindowPos(hwnd, NULL, rect.left, rect.top, width, height, |
| 503 | SWP_NOZORDER | SWP_NOACTIVATE); |
| 504 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 505 | switch (tab) |
| 506 | { |
| 507 | case TAB_INDEX: { |
| 508 | int scroll_width = GetSystemMetrics(SM_CXVSCROLL); |
| 509 | int border_width = GetSystemMetrics(SM_CXBORDER); |
| 510 | int edge_width = GetSystemMetrics(SM_CXEDGE); |
| 511 | |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 512 | /* Resize the tab widget column to perfectly fit the tab window and |
| 513 | * leave sufficient space for the scroll widget. |
| 514 | */ |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 515 | SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_SETCOLUMNWIDTH, 0, |
| 516 | width-scroll_width-2*border_width-2*edge_width); |
| 517 | |
| 518 | break; |
| 519 | } |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 520 | case TAB_SEARCH: { |
| 521 | int scroll_width = GetSystemMetrics(SM_CXVSCROLL); |
| 522 | int border_width = GetSystemMetrics(SM_CXBORDER); |
| 523 | int edge_width = GetSystemMetrics(SM_CXEDGE); |
| 524 | int top_pos = 0; |
| 525 | |
| 526 | SetWindowPos(info->search.hwndEdit, NULL, 0, top_pos, width, |
| 527 | EDIT_HEIGHT, SWP_NOZORDER | SWP_NOACTIVATE); |
| 528 | top_pos += EDIT_HEIGHT + TAB_MARGIN; |
| 529 | SetWindowPos(info->search.hwndList, NULL, 0, top_pos, width, |
| 530 | height-top_pos, SWP_NOZORDER | SWP_NOACTIVATE); |
| 531 | /* Resize the tab widget column to perfectly fit the tab window and |
| 532 | * leave sufficient space for the scroll widget. |
| 533 | */ |
| 534 | SendMessageW(info->search.hwndList, LVM_SETCOLUMNWIDTH, 0, |
| 535 | width-scroll_width-2*border_width-2*edge_width); |
| 536 | |
| 537 | break; |
| 538 | } |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 539 | } |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 542 | static LRESULT Child_OnSize(HWND hwnd) |
| 543 | { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 544 | HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, 0); |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 545 | RECT rect; |
| 546 | |
| 547 | if(!info || hwnd != info->WinType.hwndNavigation) |
| 548 | return 0; |
| 549 | |
| 550 | GetClientRect(hwnd, &rect); |
| 551 | SetWindowPos(info->hwndTabCtrl, HWND_TOP, 0, 0, |
| 552 | rect.right - TAB_RIGHT_PADDING, |
| 553 | rect.bottom - TAB_TOP_PADDING, SWP_NOMOVE); |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 554 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 555 | ResizeTabChild(info, TAB_CONTENTS); |
| 556 | ResizeTabChild(info, TAB_INDEX); |
André Hentschel | 3510329 | 2011-04-16 17:31:15 +0200 | [diff] [blame] | 557 | ResizeTabChild(info, TAB_SEARCH); |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 558 | return 0; |
| 559 | } |
| 560 | |
| 561 | static LRESULT OnTabChange(HWND hwnd) |
| 562 | { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 563 | HHInfo *info = (HHInfo*)GetWindowLongPtrW(hwnd, 0); |
Erich Hoover | 3228b4d | 2011-09-27 20:00:10 -0600 | [diff] [blame] | 564 | int tab_id, tab_index, i; |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 565 | |
| 566 | TRACE("%p\n", hwnd); |
| 567 | |
| 568 | if (!info) |
| 569 | return 0; |
| 570 | |
| 571 | if(info->tabs[info->current_tab].hwnd) |
| 572 | ShowWindow(info->tabs[info->current_tab].hwnd, SW_HIDE); |
| 573 | |
Erich Hoover | 3228b4d | 2011-09-27 20:00:10 -0600 | [diff] [blame] | 574 | tab_id = (int) SendMessageW(info->hwndTabCtrl, TCM_GETCURSEL, 0, 0); |
| 575 | /* convert the ID of the tab to an index in our tab list */ |
| 576 | tab_index = -1; |
| 577 | for (i=0; i<TAB_NUMTABS; i++) |
| 578 | { |
| 579 | if (info->tabs[i].id == tab_id) |
| 580 | { |
| 581 | tab_index = i; |
| 582 | break; |
| 583 | } |
| 584 | } |
| 585 | if (tab_index == -1) |
| 586 | { |
| 587 | FIXME("Tab ID %d does not correspond to a valid index in the tab list.\n", tab_id); |
| 588 | return 0; |
| 589 | } |
| 590 | info->current_tab = tab_index; |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 591 | |
| 592 | if(info->tabs[info->current_tab].hwnd) |
| 593 | ShowWindow(info->tabs[info->current_tab].hwnd, SW_SHOW); |
| 594 | |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 595 | return 0; |
James Hawkins | 33eb060 | 2005-08-15 09:40:24 +0000 | [diff] [blame] | 596 | } |
| 597 | |
Erich Hoover | 3a82454 | 2010-01-28 16:16:02 -0700 | [diff] [blame] | 598 | static LRESULT OnTopicChange(HHInfo *info, void *user_data) |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 599 | { |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 600 | LPCWSTR chmfile = NULL, name = NULL, local = NULL; |
| 601 | ContentItem *citer; |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 602 | SearchItem *siter; |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 603 | IndexItem *iiter; |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 604 | |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 605 | if(!user_data || !info) |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 606 | return 0; |
| 607 | |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 608 | switch (info->current_tab) |
| 609 | { |
| 610 | case TAB_CONTENTS: |
| 611 | citer = (ContentItem *) user_data; |
| 612 | name = citer->name; |
| 613 | local = citer->local; |
| 614 | while(citer) { |
| 615 | if(citer->merge.chm_file) { |
| 616 | chmfile = citer->merge.chm_file; |
| 617 | break; |
| 618 | } |
| 619 | citer = citer->parent; |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 620 | } |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 621 | break; |
| 622 | case TAB_INDEX: |
| 623 | iiter = (IndexItem *) user_data; |
| 624 | if(iiter->nItems == 0) { |
| 625 | FIXME("No entries for this item!\n"); |
| 626 | return 0; |
| 627 | } |
| 628 | if(iiter->nItems > 1) { |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 629 | int i = 0; |
| 630 | LVITEMW lvi; |
| 631 | |
| 632 | SendMessageW(info->popup.hwndList, LVM_DELETEALLITEMS, 0, 0); |
| 633 | for(i=0;i<iiter->nItems;i++) { |
| 634 | IndexSubItem *item = &iiter->items[i]; |
| 635 | WCHAR *name = iiter->keyword; |
| 636 | |
Erich Hoover | 43ecfe0 | 2012-06-26 10:05:19 -0600 | [diff] [blame] | 637 | if(!item->name) |
| 638 | item->name = GetDocumentTitle(info->pCHMInfo, item->local); |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 639 | if(item->name) |
| 640 | name = item->name; |
| 641 | memset(&lvi, 0, sizeof(lvi)); |
| 642 | lvi.iItem = i; |
| 643 | lvi.mask = LVIF_TEXT|LVIF_PARAM; |
| 644 | lvi.cchTextMax = strlenW(name)+1; |
| 645 | lvi.pszText = name; |
| 646 | lvi.lParam = (LPARAM) item; |
| 647 | SendMessageW(info->popup.hwndList, LVM_INSERTITEMW, 0, (LPARAM)&lvi); |
| 648 | } |
| 649 | ShowWindow(info->popup.hwndPopup, SW_SHOW); |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 650 | return 0; |
| 651 | } |
| 652 | name = iiter->items[0].name; |
| 653 | local = iiter->items[0].local; |
| 654 | chmfile = iiter->merge.chm_file; |
| 655 | break; |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 656 | case TAB_SEARCH: |
| 657 | siter = (SearchItem *) user_data; |
| 658 | name = siter->filename; |
| 659 | local = siter->filename; |
| 660 | chmfile = info->pCHMInfo->szFile; |
| 661 | break; |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 662 | default: |
| 663 | FIXME("Unhandled operation for this tab!\n"); |
| 664 | return 0; |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 665 | } |
| 666 | |
Erich Hoover | 425c30f | 2010-01-29 08:00:30 -0700 | [diff] [blame] | 667 | if(!chmfile) |
| 668 | { |
| 669 | FIXME("No help file found for this item!\n"); |
| 670 | return 0; |
| 671 | } |
| 672 | |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 673 | TRACE("name %s loal %s\n", debugstr_w(name), debugstr_w(local)); |
| 674 | |
| 675 | NavigateToChm(info, chmfile, local); |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 676 | return 0; |
| 677 | } |
| 678 | |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 679 | /* Capture the Enter/Return key and send it up to Child_WndProc as an NM_RETURN message */ |
| 680 | static LRESULT CALLBACK EditChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 681 | { |
| 682 | WNDPROC editWndProc = (WNDPROC)GetWindowLongPtrW(hWnd, GWLP_USERDATA); |
| 683 | |
| 684 | if(message == WM_KEYUP && wParam == VK_RETURN) |
| 685 | { |
| 686 | NMHDR nmhdr; |
| 687 | |
| 688 | nmhdr.hwndFrom = hWnd; |
| 689 | nmhdr.code = NM_RETURN; |
| 690 | SendMessageW(GetParent(GetParent(hWnd)), WM_NOTIFY, wParam, (LPARAM)&nmhdr); |
| 691 | } |
| 692 | return editWndProc(hWnd, message, wParam, lParam); |
| 693 | } |
| 694 | |
Alexandre Julliard | 9d5d7bf | 2006-08-02 22:02:25 +0200 | [diff] [blame] | 695 | static LRESULT CALLBACK Child_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 696 | { |
| 697 | switch (message) |
| 698 | { |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 699 | case WM_PAINT: |
| 700 | return Child_OnPaint(hWnd); |
| 701 | case WM_SIZE: |
| 702 | return Child_OnSize(hWnd); |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 703 | case WM_NOTIFY: { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 704 | HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, 0); |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 705 | NMHDR *nmhdr = (NMHDR*)lParam; |
Erich Hoover | 3a82454 | 2010-01-28 16:16:02 -0700 | [diff] [blame] | 706 | |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 707 | switch(nmhdr->code) { |
| 708 | case TCN_SELCHANGE: |
| 709 | return OnTabChange(hWnd); |
Jacek Caban | f1919c6 | 2007-02-28 04:00:35 +0100 | [diff] [blame] | 710 | case TVN_SELCHANGEDW: |
Erich Hoover | 3a82454 | 2010-01-28 16:16:02 -0700 | [diff] [blame] | 711 | return OnTopicChange(info, (void*)((NMTREEVIEWW *)lParam)->itemNew.lParam); |
Erich Hoover | fc413c7 | 2012-06-22 11:07:19 -0600 | [diff] [blame] | 712 | case TVN_ITEMEXPANDINGW: { |
| 713 | TVITEMW *item = &((NMTREEVIEWW *)lParam)->itemNew; |
| 714 | HWND hwndTreeView = info->tabs[TAB_CONTENTS].hwnd; |
| 715 | |
| 716 | item->mask = TVIF_IMAGE|TVIF_SELECTEDIMAGE; |
| 717 | if (item->state & TVIS_EXPANDED) |
| 718 | { |
| 719 | item->iImage = HHTV_FOLDER; |
| 720 | item->iSelectedImage = HHTV_FOLDER; |
| 721 | } |
| 722 | else |
| 723 | { |
| 724 | item->iImage = HHTV_OPENFOLDER; |
| 725 | item->iSelectedImage = HHTV_OPENFOLDER; |
| 726 | } |
| 727 | SendMessageW(hwndTreeView, TVM_SETITEMW, 0, (LPARAM)item); |
| 728 | return 0; |
| 729 | } |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 730 | case NM_DBLCLK: |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 731 | if(!info) |
| 732 | return 0; |
| 733 | switch(info->current_tab) |
| 734 | { |
| 735 | case TAB_INDEX: |
Erich Hoover | 3a82454 | 2010-01-28 16:16:02 -0700 | [diff] [blame] | 736 | return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam); |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 737 | case TAB_SEARCH: |
| 738 | return OnTopicChange(info, (void*)((NMITEMACTIVATE *)lParam)->lParam); |
| 739 | } |
| 740 | break; |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 741 | case NM_RETURN: |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 742 | if(!info) |
| 743 | return 0; |
| 744 | switch(info->current_tab) { |
| 745 | case TAB_INDEX: { |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 746 | HWND hwndList = info->tabs[TAB_INDEX].hwnd; |
| 747 | LVITEMW lvItem; |
| 748 | |
| 749 | lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0); |
| 750 | lvItem.mask = TVIF_PARAM; |
Michael Stefaniuc | 968f214 | 2010-02-09 23:02:03 +0100 | [diff] [blame] | 751 | SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem); |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 752 | OnTopicChange(info, (void*) lvItem.lParam); |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 753 | return 0; |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 754 | } |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 755 | case TAB_SEARCH: { |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 756 | if(nmhdr->hwndFrom == info->search.hwndEdit) { |
| 757 | char needle[100]; |
| 758 | DWORD i, len; |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 759 | |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 760 | len = GetWindowTextA(info->search.hwndEdit, needle, sizeof(needle)); |
| 761 | if(!len) |
| 762 | { |
| 763 | FIXME("Unable to get search text.\n"); |
| 764 | return 0; |
| 765 | } |
| 766 | /* Convert the requested text for comparison later against the |
| 767 | * lower case version of HTML file contents. |
| 768 | */ |
| 769 | for(i=0;i<len;i++) |
| 770 | needle[i] = tolower(needle[i]); |
| 771 | InitSearch(info, needle); |
| 772 | return 0; |
| 773 | }else if(nmhdr->hwndFrom == info->search.hwndList) { |
| 774 | HWND hwndList = info->search.hwndList; |
| 775 | LVITEMW lvItem; |
| 776 | |
| 777 | lvItem.iItem = (int) SendMessageW(hwndList, LVM_GETSELECTIONMARK, 0, 0); |
| 778 | lvItem.mask = TVIF_PARAM; |
Michael Stefaniuc | 968f214 | 2010-02-09 23:02:03 +0100 | [diff] [blame] | 779 | SendMessageW(hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem); |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 780 | OnTopicChange(info, (void*) lvItem.lParam); |
| 781 | return 0; |
| 782 | } |
| 783 | break; |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 784 | } |
| 785 | } |
| 786 | break; |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 787 | } |
| 788 | break; |
| 789 | } |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 790 | default: |
| 791 | return DefWindowProcW(hWnd, message, wParam, lParam); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 792 | } |
| 793 | |
| 794 | return 0; |
| 795 | } |
| 796 | |
| 797 | static void HH_RegisterChildWndClass(HHInfo *pHHInfo) |
| 798 | { |
| 799 | WNDCLASSEXW wcex; |
| 800 | |
| 801 | wcex.cbSize = sizeof(WNDCLASSEXW); |
| 802 | wcex.style = 0; |
Jacek Caban | 74fffe6 | 2007-02-28 03:50:14 +0100 | [diff] [blame] | 803 | wcex.lpfnWndProc = Child_WndProc; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 804 | wcex.cbClsExtra = 0; |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 805 | wcex.cbWndExtra = sizeof(LONG_PTR); |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 806 | wcex.hInstance = hhctrl_hinstance; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 807 | wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 808 | wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW); |
James Hawkins | 2a4cbe0 | 2005-09-20 12:00:46 +0000 | [diff] [blame] | 809 | wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 810 | wcex.lpszMenuName = NULL; |
| 811 | wcex.lpszClassName = szChildClass; |
| 812 | wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 813 | |
| 814 | RegisterClassExW(&wcex); |
| 815 | } |
| 816 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 817 | /* Toolbar */ |
| 818 | |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 819 | #define ICON_SIZE 20 |
| 820 | |
Owen Rudge | 27048ce | 2011-01-17 22:26:50 +0000 | [diff] [blame] | 821 | static void DisplayPopupMenu(HHInfo *info) |
| 822 | { |
| 823 | HMENU menu, submenu; |
| 824 | TBBUTTONINFOW button; |
| 825 | MENUITEMINFOW item; |
| 826 | POINT coords; |
| 827 | RECT rect; |
| 828 | DWORD index; |
| 829 | |
| 830 | menu = LoadMenuW(hhctrl_hinstance, MAKEINTRESOURCEW(MENU_POPUP)); |
| 831 | |
| 832 | if (!menu) |
| 833 | return; |
| 834 | |
| 835 | submenu = GetSubMenu(menu, 0); |
| 836 | |
| 837 | /* Update the Show/Hide menu item */ |
| 838 | item.cbSize = sizeof(MENUITEMINFOW); |
Alexandre Julliard | d38571a | 2011-01-19 23:45:34 +0100 | [diff] [blame] | 839 | item.fMask = MIIM_FTYPE | MIIM_STATE | MIIM_STRING; |
| 840 | item.fType = MFT_STRING; |
| 841 | item.fState = MF_ENABLED; |
Owen Rudge | 27048ce | 2011-01-17 22:26:50 +0000 | [diff] [blame] | 842 | |
| 843 | if (info->WinType.fNotExpanded) |
| 844 | item.dwTypeData = HH_LoadString(IDS_SHOWTABS); |
| 845 | else |
| 846 | item.dwTypeData = HH_LoadString(IDS_HIDETABS); |
| 847 | |
| 848 | SetMenuItemInfoW(submenu, IDTB_EXPAND, FALSE, &item); |
| 849 | heap_free(item.dwTypeData); |
| 850 | |
| 851 | /* Find the index toolbar button */ |
| 852 | button.cbSize = sizeof(TBBUTTONINFOW); |
| 853 | button.dwMask = TBIF_COMMAND; |
| 854 | index = SendMessageW(info->WinType.hwndToolBar, TB_GETBUTTONINFOW, IDTB_OPTIONS, (LPARAM) &button); |
| 855 | |
| 856 | if (index == -1) |
| 857 | return; |
| 858 | |
| 859 | /* Get position */ |
| 860 | SendMessageW(info->WinType.hwndToolBar, TB_GETITEMRECT, index, (LPARAM) &rect); |
| 861 | |
| 862 | coords.x = rect.left; |
| 863 | coords.y = rect.bottom; |
| 864 | |
| 865 | ClientToScreen(info->WinType.hwndToolBar, &coords); |
| 866 | TrackPopupMenu(submenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON | TPM_NOANIMATION, coords.x, coords.y, 0, info->WinType.hwndHelp, NULL); |
| 867 | } |
| 868 | |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 869 | static void TB_OnClick(HWND hWnd, DWORD dwID) |
| 870 | { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 871 | HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, 0); |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 872 | |
| 873 | switch (dwID) |
| 874 | { |
| 875 | case IDTB_STOP: |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 876 | DoPageAction(info, WB_STOP); |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 877 | break; |
| 878 | case IDTB_REFRESH: |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 879 | DoPageAction(info, WB_REFRESH); |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 880 | break; |
| 881 | case IDTB_BACK: |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 882 | DoPageAction(info, WB_GOBACK); |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 883 | break; |
| 884 | case IDTB_HOME: |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 885 | NavigateToChm(info, info->pCHMInfo->szFile, info->WinType.pszHome); |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 886 | break; |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 887 | case IDTB_FORWARD: |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 888 | DoPageAction(info, WB_GOFORWARD); |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 889 | break; |
Erich Hoover | 037d58c | 2011-01-14 15:16:31 -0700 | [diff] [blame] | 890 | case IDTB_PRINT: |
| 891 | DoPageAction(info, WB_PRINT); |
| 892 | break; |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 893 | case IDTB_EXPAND: |
| 894 | case IDTB_CONTRACT: |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 895 | ExpandContract(info); |
| 896 | break; |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 897 | case IDTB_SYNC: |
Owen Rudge | 16b35e0 | 2011-01-17 22:26:46 +0000 | [diff] [blame] | 898 | DoSync(info); |
| 899 | break; |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 900 | case IDTB_OPTIONS: |
Owen Rudge | 27048ce | 2011-01-17 22:26:50 +0000 | [diff] [blame] | 901 | DisplayPopupMenu(info); |
| 902 | break; |
Francois Gouget | c103d6d | 2011-08-31 16:53:54 +0200 | [diff] [blame] | 903 | case IDTB_NOTES: |
| 904 | case IDTB_CONTENTS: |
| 905 | case IDTB_INDEX: |
| 906 | case IDTB_SEARCH: |
| 907 | case IDTB_HISTORY: |
| 908 | case IDTB_FAVORITES: |
| 909 | /* These are officially unimplemented as of the Windows 7 SDK */ |
| 910 | break; |
James Hawkins | 5d5de03 | 2005-09-19 15:25:18 +0000 | [diff] [blame] | 911 | case IDTB_BROWSE_FWD: |
| 912 | case IDTB_BROWSE_BACK: |
| 913 | case IDTB_JUMP1: |
| 914 | case IDTB_JUMP2: |
| 915 | case IDTB_CUSTOMIZE: |
| 916 | case IDTB_ZOOM: |
| 917 | case IDTB_TOC_NEXT: |
| 918 | case IDTB_TOC_PREV: |
| 919 | break; |
| 920 | } |
| 921 | } |
| 922 | |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 923 | static void TB_AddButton(TBBUTTON *pButtons, DWORD dwIndex, DWORD dwID, DWORD dwBitmap) |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 924 | { |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 925 | pButtons[dwIndex].iBitmap = dwBitmap; |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 926 | pButtons[dwIndex].idCommand = dwID; |
| 927 | pButtons[dwIndex].fsState = TBSTATE_ENABLED; |
| 928 | pButtons[dwIndex].fsStyle = BTNS_BUTTON; |
| 929 | pButtons[dwIndex].dwData = 0; |
| 930 | pButtons[dwIndex].iString = 0; |
| 931 | } |
| 932 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 933 | static void TB_AddButtonsFromFlags(HHInfo *pHHInfo, TBBUTTON *pButtons, DWORD dwButtonFlags, LPDWORD pdwNumButtons) |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 934 | { |
Erich Hoover | 1115e32 | 2011-01-20 11:01:03 -0700 | [diff] [blame] | 935 | int nHistBitmaps = 0, nStdBitmaps = 0, nHHBitmaps = 0; |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 936 | HWND hToolbar = pHHInfo->WinType.hwndToolBar; |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 937 | TBADDBITMAP tbAB; |
Francois Gouget | 083abe3 | 2011-09-01 15:03:44 +0200 | [diff] [blame] | 938 | DWORD unsupported; |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 939 | |
Erich Hoover | 1115e32 | 2011-01-20 11:01:03 -0700 | [diff] [blame] | 940 | /* Common bitmaps */ |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 941 | tbAB.hInst = HINST_COMMCTRL; |
| 942 | tbAB.nID = IDB_HIST_LARGE_COLOR; |
| 943 | nHistBitmaps = SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB); |
| 944 | tbAB.nID = IDB_STD_LARGE_COLOR; |
| 945 | nStdBitmaps = SendMessageW(hToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAB); |
Erich Hoover | 1115e32 | 2011-01-20 11:01:03 -0700 | [diff] [blame] | 946 | /* hhctrl.ocx bitmaps */ |
| 947 | tbAB.hInst = hhctrl_hinstance; |
| 948 | tbAB.nID = IDB_HHTOOLBAR; |
Erich Hoover | 54bb7bc | 2011-09-27 08:11:05 -0600 | [diff] [blame] | 949 | nHHBitmaps = SendMessageW(hToolbar, TB_ADDBITMAP, HHTB_NUMBITMAPS, (LPARAM)&tbAB); |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 950 | |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 951 | *pdwNumButtons = 0; |
| 952 | |
Francois Gouget | 083abe3 | 2011-09-01 15:03:44 +0200 | [diff] [blame] | 953 | unsupported = dwButtonFlags & (HHWIN_BUTTON_BROWSE_FWD | |
| 954 | HHWIN_BUTTON_BROWSE_BCK | HHWIN_BUTTON_NOTES | HHWIN_BUTTON_CONTENTS | |
| 955 | HHWIN_BUTTON_INDEX | HHWIN_BUTTON_SEARCH | HHWIN_BUTTON_HISTORY | |
| 956 | HHWIN_BUTTON_FAVORITES | HHWIN_BUTTON_JUMP1 | HHWIN_BUTTON_JUMP2 | |
| 957 | HHWIN_BUTTON_ZOOM | HHWIN_BUTTON_TOC_NEXT | HHWIN_BUTTON_TOC_PREV); |
| 958 | if (unsupported) |
| 959 | FIXME("got asked for unsupported buttons: %06x\n", unsupported); |
| 960 | |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 961 | if (dwButtonFlags & HHWIN_BUTTON_EXPAND) |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 962 | { |
Erich Hoover | 442343a | 2011-09-27 08:11:36 -0600 | [diff] [blame] | 963 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_EXPAND, nHHBitmaps + HHTB_EXPAND); |
| 964 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_CONTRACT, nHHBitmaps + HHTB_CONTRACT); |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 965 | |
| 966 | if (pHHInfo->WinType.fNotExpanded) |
| 967 | pButtons[1].fsState |= TBSTATE_HIDDEN; |
| 968 | else |
| 969 | pButtons[0].fsState |= TBSTATE_HIDDEN; |
| 970 | } |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 971 | |
| 972 | if (dwButtonFlags & HHWIN_BUTTON_BACK) |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 973 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_BACK, nHistBitmaps + HIST_BACK); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 974 | |
| 975 | if (dwButtonFlags & HHWIN_BUTTON_FORWARD) |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 976 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_FORWARD, nHistBitmaps + HIST_FORWARD); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 977 | |
| 978 | if (dwButtonFlags & HHWIN_BUTTON_STOP) |
Erich Hoover | 54bb7bc | 2011-09-27 08:11:05 -0600 | [diff] [blame] | 979 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_STOP, nHHBitmaps + HHTB_STOP); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 980 | |
| 981 | if (dwButtonFlags & HHWIN_BUTTON_REFRESH) |
Erich Hoover | 54bb7bc | 2011-09-27 08:11:05 -0600 | [diff] [blame] | 982 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_REFRESH, nHHBitmaps + HHTB_REFRESH); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 983 | |
| 984 | if (dwButtonFlags & HHWIN_BUTTON_HOME) |
Erich Hoover | 54bb7bc | 2011-09-27 08:11:05 -0600 | [diff] [blame] | 985 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_HOME, nHHBitmaps + HHTB_HOME); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 986 | |
| 987 | if (dwButtonFlags & HHWIN_BUTTON_SYNC) |
Erich Hoover | 54bb7bc | 2011-09-27 08:11:05 -0600 | [diff] [blame] | 988 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_SYNC, nHHBitmaps + HHTB_SYNC); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 989 | |
| 990 | if (dwButtonFlags & HHWIN_BUTTON_OPTIONS) |
Erich Hoover | 1cabe30 | 2011-09-27 08:10:13 -0600 | [diff] [blame] | 991 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_OPTIONS, nStdBitmaps + STD_PROPERTIES); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 992 | |
| 993 | if (dwButtonFlags & HHWIN_BUTTON_PRINT) |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 994 | TB_AddButton(pButtons, (*pdwNumButtons)++, IDTB_PRINT, nStdBitmaps + STD_PRINT); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 995 | } |
| 996 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 997 | static BOOL HH_AddToolbar(HHInfo *pHHInfo) |
| 998 | { |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 999 | HWND hToolbar; |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1000 | HWND hwndParent = pHHInfo->WinType.hwndHelp; |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1001 | DWORD toolbarFlags; |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1002 | TBBUTTON buttons[IDTB_TOC_PREV - IDTB_EXPAND]; |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1003 | DWORD dwStyles, dwExStyles; |
| 1004 | DWORD dwNumButtons, dwIndex; |
| 1005 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1006 | if (pHHInfo->WinType.fsWinProperties & HHWIN_PARAM_TB_FLAGS) |
| 1007 | toolbarFlags = pHHInfo->WinType.fsToolBarFlags; |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1008 | else |
| 1009 | toolbarFlags = HHWIN_DEF_BUTTONS; |
| 1010 | |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1011 | dwStyles = WS_CHILDWINDOW | WS_VISIBLE | TBSTYLE_FLAT | |
| 1012 | TBSTYLE_WRAPABLE | TBSTYLE_TOOLTIPS | CCS_NODIVIDER; |
| 1013 | dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR; |
| 1014 | |
| 1015 | hToolbar = CreateWindowExW(dwExStyles, TOOLBARCLASSNAMEW, NULL, dwStyles, |
| 1016 | 0, 0, 0, 0, hwndParent, NULL, |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 1017 | hhctrl_hinstance, NULL); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1018 | if (!hToolbar) |
| 1019 | return FALSE; |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 1020 | pHHInfo->WinType.hwndToolBar = hToolbar; |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1021 | |
| 1022 | SendMessageW(hToolbar, TB_SETBITMAPSIZE, 0, MAKELONG(ICON_SIZE, ICON_SIZE)); |
| 1023 | SendMessageW(hToolbar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); |
| 1024 | SendMessageW(hToolbar, WM_SETFONT, (WPARAM)pHHInfo->hFont, TRUE); |
| 1025 | |
Erich Hoover | d127f00 | 2011-01-20 10:56:24 -0700 | [diff] [blame] | 1026 | TB_AddButtonsFromFlags(pHHInfo, buttons, toolbarFlags, &dwNumButtons); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1027 | |
| 1028 | for (dwIndex = 0; dwIndex < dwNumButtons; dwIndex++) |
| 1029 | { |
| 1030 | LPWSTR szBuf = HH_LoadString(buttons[dwIndex].idCommand); |
| 1031 | DWORD dwLen = strlenW(szBuf); |
Tomasz Jezierski | 0b64b86 | 2008-04-09 10:03:58 +0200 | [diff] [blame] | 1032 | szBuf[dwLen + 1] = 0; /* Double-null terminate */ |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1033 | |
| 1034 | buttons[dwIndex].iString = (DWORD)SendMessageW(hToolbar, TB_ADDSTRINGW, 0, (LPARAM)szBuf); |
Michael Stefaniuc | 7e8d79f | 2007-12-09 16:29:44 +0100 | [diff] [blame] | 1035 | heap_free(szBuf); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Andrew Talbot | ab6d29e | 2008-07-10 23:08:56 +0100 | [diff] [blame] | 1038 | SendMessageW(hToolbar, TB_ADDBUTTONSW, dwNumButtons, (LPARAM)buttons); |
James Hawkins | 3e00dec | 2005-08-02 14:55:11 +0000 | [diff] [blame] | 1039 | SendMessageW(hToolbar, TB_AUTOSIZE, 0, 0); |
| 1040 | ShowWindow(hToolbar, SW_SHOW); |
| 1041 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1042 | return TRUE; |
| 1043 | } |
| 1044 | |
| 1045 | /* Navigation Pane */ |
| 1046 | |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1047 | static void NP_GetNavigationRect(HHInfo *pHHInfo, RECT *rc) |
| 1048 | { |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1049 | HWND hwndParent = pHHInfo->WinType.hwndHelp; |
| 1050 | HWND hwndToolbar = pHHInfo->WinType.hwndToolBar; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1051 | RECT rectWND, rectTB; |
| 1052 | |
| 1053 | GetClientRect(hwndParent, &rectWND); |
| 1054 | GetClientRect(hwndToolbar, &rectTB); |
| 1055 | |
| 1056 | rc->left = 0; |
| 1057 | rc->top = rectTB.bottom; |
| 1058 | rc->bottom = rectWND.bottom - rectTB.bottom; |
| 1059 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1060 | if (!(pHHInfo->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) && |
| 1061 | pHHInfo->WinType.iNavWidth == 0) |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 1062 | { |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1063 | pHHInfo->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH; |
James Hawkins | 6f4977d | 2005-09-28 10:16:02 +0000 | [diff] [blame] | 1064 | } |
| 1065 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1066 | rc->right = pHHInfo->WinType.iNavWidth; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1069 | static DWORD NP_CreateTab(HINSTANCE hInstance, HWND hwndTabCtrl, DWORD index) |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1070 | { |
| 1071 | TCITEMW tie; |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1072 | LPWSTR tabText = HH_LoadString(index); |
| 1073 | DWORD ret; |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1074 | |
| 1075 | tie.mask = TCIF_TEXT; |
| 1076 | tie.pszText = tabText; |
| 1077 | |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1078 | ret = SendMessageW( hwndTabCtrl, TCM_INSERTITEMW, index, (LPARAM)&tie ); |
| 1079 | |
Michael Stefaniuc | 7e8d79f | 2007-12-09 16:29:44 +0100 | [diff] [blame] | 1080 | heap_free(tabText); |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1081 | return ret; |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1084 | static BOOL HH_AddNavigationPane(HHInfo *info) |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1085 | { |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1086 | HWND hWnd, hwndTabCtrl; |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1087 | HWND hwndParent = info->WinType.hwndHelp; |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1088 | DWORD dwStyles = WS_CHILDWINDOW; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1089 | DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR; |
| 1090 | RECT rc; |
| 1091 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1092 | if (!info->WinType.fNotExpanded) |
| 1093 | dwStyles |= WS_VISIBLE; |
| 1094 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1095 | NP_GetNavigationRect(info, &rc); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1096 | |
| 1097 | hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles, |
| 1098 | rc.left, rc.top, rc.right, rc.bottom, |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 1099 | hwndParent, NULL, hhctrl_hinstance, NULL); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1100 | if (!hWnd) |
| 1101 | return FALSE; |
| 1102 | |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1103 | SetWindowLongPtrW(hWnd, 0, (LONG_PTR)info); |
Jacek Caban | c6774f7 | 2007-02-28 03:56:33 +0100 | [diff] [blame] | 1104 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1105 | hwndTabCtrl = CreateWindowExW(dwExStyles, WC_TABCONTROLW, szEmpty, dwStyles | WS_VISIBLE, |
James Hawkins | 2a4cbe0 | 2005-09-20 12:00:46 +0000 | [diff] [blame] | 1106 | 0, TAB_TOP_PADDING, |
| 1107 | rc.right - TAB_RIGHT_PADDING, |
| 1108 | rc.bottom - TAB_TOP_PADDING, |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 1109 | hWnd, NULL, hhctrl_hinstance, NULL); |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1110 | if (!hwndTabCtrl) |
| 1111 | return FALSE; |
| 1112 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1113 | if (*info->WinType.pszToc) |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1114 | info->tabs[TAB_CONTENTS].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_CONTENTS); |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1115 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1116 | if (*info->WinType.pszIndex) |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1117 | info->tabs[TAB_INDEX].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_INDEX); |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1118 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1119 | if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_SEARCH) |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1120 | info->tabs[TAB_SEARCH].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_SEARCH); |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1121 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1122 | if (info->WinType.fsWinProperties & HHWIN_PROP_TAB_FAVORITES) |
Jacek Caban | 0ecadff | 2007-02-28 03:57:12 +0100 | [diff] [blame] | 1123 | info->tabs[TAB_FAVORITES].id = NP_CreateTab(hhctrl_hinstance, hwndTabCtrl, IDS_FAVORITES); |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1124 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1125 | SendMessageW(hwndTabCtrl, WM_SETFONT, (WPARAM)info->hFont, TRUE); |
James Hawkins | 90bb481 | 2005-08-03 11:46:52 +0000 | [diff] [blame] | 1126 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1127 | info->hwndTabCtrl = hwndTabCtrl; |
| 1128 | info->WinType.hwndNavigation = hWnd; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1129 | return TRUE; |
| 1130 | } |
| 1131 | |
| 1132 | /* HTML Pane */ |
| 1133 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1134 | static void HP_GetHTMLRect(HHInfo *info, RECT *rc) |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1135 | { |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 1136 | RECT rectTB, rectWND, rectNP, rectSB; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1137 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1138 | GetClientRect(info->WinType.hwndHelp, &rectWND); |
| 1139 | GetClientRect(info->WinType.hwndToolBar, &rectTB); |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1140 | GetClientRect(info->hwndSizeBar, &rectSB); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1141 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1142 | if (info->WinType.fNotExpanded) |
| 1143 | rc->left = 0; |
| 1144 | else |
| 1145 | { |
| 1146 | GetClientRect(info->WinType.hwndNavigation, &rectNP); |
| 1147 | rc->left = rectNP.right + rectSB.right; |
| 1148 | } |
| 1149 | |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1150 | rc->top = rectTB.bottom; |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 1151 | rc->right = rectWND.right - rc->left; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1152 | rc->bottom = rectWND.bottom - rectTB.bottom; |
| 1153 | } |
| 1154 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1155 | static BOOL HH_AddHTMLPane(HHInfo *pHHInfo) |
| 1156 | { |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1157 | HWND hWnd; |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1158 | HWND hwndParent = pHHInfo->WinType.hwndHelp; |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1159 | DWORD dwStyles = WS_CHILDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN; |
| 1160 | DWORD dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_CLIENTEDGE; |
| 1161 | RECT rc; |
| 1162 | |
| 1163 | HP_GetHTMLRect(pHHInfo, &rc); |
| 1164 | |
| 1165 | hWnd = CreateWindowExW(dwExStyles, szChildClass, szEmpty, dwStyles, |
| 1166 | rc.left, rc.top, rc.right, rc.bottom, |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 1167 | hwndParent, NULL, hhctrl_hinstance, NULL); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1168 | if (!hWnd) |
| 1169 | return FALSE; |
| 1170 | |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 1171 | if (!InitWebBrowser(pHHInfo, hWnd)) |
James Hawkins | 3e507e3 | 2005-09-13 10:32:47 +0000 | [diff] [blame] | 1172 | return FALSE; |
| 1173 | |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1174 | /* store the pointer to the HH info struct */ |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1175 | SetWindowLongPtrW(hWnd, 0, (LONG_PTR)pHHInfo); |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1176 | |
| 1177 | ShowWindow(hWnd, SW_SHOW); |
| 1178 | UpdateWindow(hWnd); |
| 1179 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1180 | pHHInfo->WinType.hwndHTML = hWnd; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1181 | return TRUE; |
| 1182 | } |
| 1183 | |
Jacek Caban | 6b68e8d | 2007-02-28 03:58:18 +0100 | [diff] [blame] | 1184 | static BOOL AddContentTab(HHInfo *info) |
| 1185 | { |
Erich Hoover | fc413c7 | 2012-06-22 11:07:19 -0600 | [diff] [blame] | 1186 | HIMAGELIST hImageList; |
| 1187 | HBITMAP hBitmap; |
| 1188 | HWND hWnd; |
| 1189 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 1190 | if(info->tabs[TAB_CONTENTS].id == -1) |
| 1191 | return TRUE; /* No "Contents" tab */ |
Erich Hoover | fc413c7 | 2012-06-22 11:07:19 -0600 | [diff] [blame] | 1192 | hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_TREEVIEWW, szEmpty, WS_CHILD | WS_BORDER | TVS_LINESATROOT |
| 1193 | | TVS_SHOWSELALWAYS | TVS_HASBUTTONS, 50, 50, 100, 100, |
| 1194 | info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL); |
| 1195 | if(!hWnd) { |
Jacek Caban | 6b68e8d | 2007-02-28 03:58:18 +0100 | [diff] [blame] | 1196 | ERR("Could not create treeview control\n"); |
| 1197 | return FALSE; |
| 1198 | } |
| 1199 | |
Erich Hoover | fc413c7 | 2012-06-22 11:07:19 -0600 | [diff] [blame] | 1200 | hImageList = ImageList_Create(16, 16, ILC_COLOR32, 0, HHTV_NUMBITMAPS); |
| 1201 | hBitmap = LoadBitmapW(hhctrl_hinstance, MAKEINTRESOURCEW(IDB_HHTREEVIEW)); |
| 1202 | ImageList_Add(hImageList, hBitmap, NULL); |
| 1203 | SendMessageW(hWnd, TVM_SETIMAGELIST, TVSIL_NORMAL, (LPARAM)hImageList); |
| 1204 | |
| 1205 | info->contents.hImageList = hImageList; |
| 1206 | info->tabs[TAB_CONTENTS].hwnd = hWnd; |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 1207 | ResizeTabChild(info, TAB_CONTENTS); |
Erich Hoover | fc413c7 | 2012-06-22 11:07:19 -0600 | [diff] [blame] | 1208 | ShowWindow(hWnd, SW_SHOW); |
Jacek Caban | 6b68e8d | 2007-02-28 03:58:18 +0100 | [diff] [blame] | 1209 | |
| 1210 | return TRUE; |
| 1211 | } |
| 1212 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 1213 | static BOOL AddIndexTab(HHInfo *info) |
| 1214 | { |
| 1215 | char hidden_column[] = "Column"; |
| 1216 | LVCOLUMNA lvc; |
| 1217 | |
| 1218 | if(info->tabs[TAB_INDEX].id == -1) |
| 1219 | return TRUE; /* No "Index" tab */ |
| 1220 | info->tabs[TAB_INDEX].hwnd = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, |
| 1221 | szEmpty, WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT | LVS_NOCOLUMNHEADER, 50, 50, 100, 100, |
| 1222 | info->WinType.hwndNavigation, NULL, hhctrl_hinstance, NULL); |
| 1223 | if(!info->tabs[TAB_INDEX].hwnd) { |
| 1224 | ERR("Could not create ListView control\n"); |
| 1225 | return FALSE; |
| 1226 | } |
| 1227 | memset(&lvc, 0, sizeof(lvc)); |
| 1228 | lvc.mask = LVCF_TEXT; |
| 1229 | lvc.pszText = hidden_column; |
| 1230 | if(SendMessageW(info->tabs[TAB_INDEX].hwnd, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1) |
| 1231 | { |
| 1232 | ERR("Could not create ListView column\n"); |
| 1233 | return FALSE; |
| 1234 | } |
| 1235 | |
| 1236 | ResizeTabChild(info, TAB_INDEX); |
| 1237 | ShowWindow(info->tabs[TAB_INDEX].hwnd, SW_HIDE); |
| 1238 | |
| 1239 | return TRUE; |
| 1240 | } |
| 1241 | |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 1242 | static BOOL AddSearchTab(HHInfo *info) |
| 1243 | { |
| 1244 | HWND hwndList, hwndEdit, hwndContainer; |
| 1245 | char hidden_column[] = "Column"; |
| 1246 | WNDPROC editWndProc; |
| 1247 | LVCOLUMNA lvc; |
| 1248 | |
| 1249 | if(info->tabs[TAB_SEARCH].id == -1) |
| 1250 | return TRUE; /* No "Search" tab */ |
| 1251 | hwndContainer = CreateWindowExW(WS_EX_CONTROLPARENT, szChildClass, szEmpty, |
| 1252 | WS_CHILD, 0, 0, 0, 0, info->WinType.hwndNavigation, |
| 1253 | NULL, hhctrl_hinstance, NULL); |
| 1254 | if(!hwndContainer) { |
| 1255 | ERR("Could not create search window container control.\n"); |
| 1256 | return FALSE; |
| 1257 | } |
| 1258 | hwndEdit = CreateWindowExW(WS_EX_CLIENTEDGE, WC_EDITW, szEmpty, WS_CHILD |
| 1259 | | WS_VISIBLE | ES_LEFT | SS_NOTIFY, 0, 0, 0, 0, |
| 1260 | hwndContainer, NULL, hhctrl_hinstance, NULL); |
| 1261 | if(!hwndEdit) { |
| 1262 | ERR("Could not create search ListView control.\n"); |
| 1263 | return FALSE; |
| 1264 | } |
| 1265 | if(SendMessageW(hwndEdit, WM_SETFONT, (WPARAM) info->hFont, (LPARAM) FALSE) == -1) |
| 1266 | { |
| 1267 | ERR("Could not set font for edit control.\n"); |
| 1268 | return FALSE; |
| 1269 | } |
| 1270 | editWndProc = (WNDPROC) SetWindowLongPtrW(hwndEdit, GWLP_WNDPROC, (LONG_PTR)EditChild_WndProc); |
| 1271 | if(!editWndProc) { |
| 1272 | ERR("Could not redirect messages for edit control.\n"); |
| 1273 | return FALSE; |
| 1274 | } |
| 1275 | SetWindowLongPtrW(hwndEdit, GWLP_USERDATA, (LONG_PTR)editWndProc); |
| 1276 | hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty, |
| 1277 | WS_CHILD | WS_VISIBLE | WS_BORDER | LVS_SINGLESEL |
| 1278 | | LVS_REPORT | LVS_NOCOLUMNHEADER, 0, 0, 0, 0, |
| 1279 | hwndContainer, NULL, hhctrl_hinstance, NULL); |
| 1280 | if(!hwndList) { |
| 1281 | ERR("Could not create search ListView control.\n"); |
| 1282 | return FALSE; |
| 1283 | } |
| 1284 | memset(&lvc, 0, sizeof(lvc)); |
| 1285 | lvc.mask = LVCF_TEXT; |
| 1286 | lvc.pszText = hidden_column; |
| 1287 | if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1) |
| 1288 | { |
| 1289 | ERR("Could not create ListView column\n"); |
| 1290 | return FALSE; |
| 1291 | } |
| 1292 | |
| 1293 | info->search.hwndEdit = hwndEdit; |
| 1294 | info->search.hwndList = hwndList; |
| 1295 | info->search.hwndContainer = hwndContainer; |
| 1296 | info->tabs[TAB_SEARCH].hwnd = hwndContainer; |
| 1297 | |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1298 | SetWindowLongPtrW(hwndContainer, 0, (LONG_PTR)info); |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 1299 | |
| 1300 | ResizeTabChild(info, TAB_SEARCH); |
| 1301 | |
| 1302 | return TRUE; |
| 1303 | } |
| 1304 | |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1305 | /* The Index tab's sub-topic popup */ |
| 1306 | |
| 1307 | static void ResizePopupChild(HHInfo *info) |
| 1308 | { |
| 1309 | int scroll_width = GetSystemMetrics(SM_CXVSCROLL); |
| 1310 | int border_width = GetSystemMetrics(SM_CXBORDER); |
| 1311 | int edge_width = GetSystemMetrics(SM_CXEDGE); |
| 1312 | INT width, height; |
| 1313 | RECT rect; |
| 1314 | |
| 1315 | if(!info) |
| 1316 | return; |
| 1317 | |
| 1318 | GetClientRect(info->popup.hwndPopup, &rect); |
| 1319 | SetWindowPos(info->popup.hwndCallback, HWND_TOP, 0, 0, |
| 1320 | rect.right, rect.bottom, SWP_NOMOVE); |
| 1321 | |
| 1322 | rect.left = TAB_MARGIN; |
| 1323 | rect.top = TAB_TOP_PADDING + TAB_MARGIN; |
| 1324 | rect.right -= TAB_RIGHT_PADDING + TAB_MARGIN; |
| 1325 | rect.bottom -= TAB_MARGIN; |
| 1326 | width = rect.right-rect.left; |
| 1327 | height = rect.bottom-rect.top; |
| 1328 | |
| 1329 | SetWindowPos(info->popup.hwndList, NULL, rect.left, rect.top, width, height, |
| 1330 | SWP_NOZORDER | SWP_NOACTIVATE); |
| 1331 | |
| 1332 | SendMessageW(info->popup.hwndList, LVM_SETCOLUMNWIDTH, 0, |
| 1333 | width-scroll_width-2*border_width-2*edge_width); |
| 1334 | } |
| 1335 | |
| 1336 | static LRESULT CALLBACK HelpPopup_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 1337 | { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1338 | HHInfo *info = (HHInfo *)GetWindowLongPtrW(hWnd, 0); |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1339 | |
| 1340 | switch (message) |
| 1341 | { |
| 1342 | case WM_SIZE: |
| 1343 | ResizePopupChild(info); |
| 1344 | return 0; |
| 1345 | case WM_DESTROY: |
| 1346 | DestroyWindow(hWnd); |
| 1347 | return 0; |
| 1348 | case WM_CLOSE: |
| 1349 | ShowWindow(hWnd, SW_HIDE); |
| 1350 | return 0; |
| 1351 | |
| 1352 | default: |
| 1353 | return DefWindowProcW(hWnd, message, wParam, lParam); |
| 1354 | } |
| 1355 | |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
| 1359 | static LRESULT CALLBACK PopupChild_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
| 1360 | { |
| 1361 | switch (message) |
| 1362 | { |
| 1363 | case WM_NOTIFY: { |
| 1364 | NMHDR *nmhdr = (NMHDR*)lParam; |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 1365 | switch(nmhdr->code) |
| 1366 | { |
| 1367 | case NM_DBLCLK: { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1368 | HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, 0); |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1369 | IndexSubItem *iter; |
| 1370 | |
| 1371 | if(info == 0 || lParam == 0) |
| 1372 | return 0; |
| 1373 | iter = (IndexSubItem*) ((NMITEMACTIVATE *)lParam)->lParam; |
| 1374 | if(iter == 0) |
| 1375 | return 0; |
| 1376 | NavigateToChm(info, info->index->merge.chm_file, iter->local); |
| 1377 | ShowWindow(info->popup.hwndPopup, SW_HIDE); |
| 1378 | return 0; |
| 1379 | } |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 1380 | case NM_RETURN: { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1381 | HHInfo *info = (HHInfo*)GetWindowLongPtrW(hWnd, 0); |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 1382 | IndexSubItem *iter; |
| 1383 | LVITEMW lvItem; |
| 1384 | |
| 1385 | if(info == 0) |
| 1386 | return 0; |
| 1387 | |
| 1388 | lvItem.iItem = (int) SendMessageW(info->popup.hwndList, LVM_GETSELECTIONMARK, 0, 0); |
| 1389 | lvItem.mask = TVIF_PARAM; |
Michael Stefaniuc | 968f214 | 2010-02-09 23:02:03 +0100 | [diff] [blame] | 1390 | SendMessageW(info->popup.hwndList, LVM_GETITEMW, 0, (LPARAM)&lvItem); |
Erich Hoover | 6ab9812 | 2010-02-07 10:08:38 -0700 | [diff] [blame] | 1391 | iter = (IndexSubItem*) lvItem.lParam; |
| 1392 | NavigateToChm(info, info->index->merge.chm_file, iter->local); |
| 1393 | ShowWindow(info->popup.hwndPopup, SW_HIDE); |
| 1394 | return 0; |
| 1395 | } |
| 1396 | } |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1397 | break; |
| 1398 | } |
| 1399 | default: |
| 1400 | return DefWindowProcW(hWnd, message, wParam, lParam); |
| 1401 | } |
| 1402 | |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
| 1406 | static BOOL AddIndexPopup(HHInfo *info) |
| 1407 | { |
| 1408 | static const WCHAR szPopupChildClass[] = {'H','H',' ','P','o','p','u','p',' ','C','h','i','l','d',0}; |
| 1409 | static const WCHAR windowCaptionW[] = {'S','e','l','e','c','t',' ','T','o','p','i','c',':',0}; |
| 1410 | static const WCHAR windowClassW[] = {'H','H',' ','P','o','p','u','p',0}; |
| 1411 | HWND hwndList, hwndPopup, hwndCallback; |
| 1412 | char hidden_column[] = "Column"; |
| 1413 | WNDCLASSEXW wcex; |
| 1414 | LVCOLUMNA lvc; |
| 1415 | |
| 1416 | if(info->tabs[TAB_INDEX].id == -1) |
| 1417 | return TRUE; /* No "Index" tab */ |
| 1418 | |
| 1419 | wcex.cbSize = sizeof(WNDCLASSEXW); |
| 1420 | wcex.style = CS_HREDRAW | CS_VREDRAW; |
| 1421 | wcex.lpfnWndProc = HelpPopup_WndProc; |
| 1422 | wcex.cbClsExtra = 0; |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1423 | wcex.cbWndExtra = sizeof(LONG_PTR); |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1424 | wcex.hInstance = hhctrl_hinstance; |
| 1425 | wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 1426 | wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW); |
| 1427 | wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1); |
| 1428 | wcex.lpszMenuName = NULL; |
| 1429 | wcex.lpszClassName = windowClassW; |
| 1430 | wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 1431 | RegisterClassExW(&wcex); |
| 1432 | |
| 1433 | wcex.cbSize = sizeof(WNDCLASSEXW); |
| 1434 | wcex.style = 0; |
| 1435 | wcex.lpfnWndProc = PopupChild_WndProc; |
| 1436 | wcex.cbClsExtra = 0; |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1437 | wcex.cbWndExtra = sizeof(LONG_PTR); |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1438 | wcex.hInstance = hhctrl_hinstance; |
| 1439 | wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 1440 | wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW); |
| 1441 | wcex.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1); |
| 1442 | wcex.lpszMenuName = NULL; |
| 1443 | wcex.lpszClassName = szPopupChildClass; |
| 1444 | wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 1445 | RegisterClassExW(&wcex); |
| 1446 | |
| 1447 | hwndPopup = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW |
| 1448 | | WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR, |
| 1449 | windowClassW, windowCaptionW, WS_POPUPWINDOW |
| 1450 | | WS_OVERLAPPEDWINDOW | WS_VISIBLE |
| 1451 | | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, CW_USEDEFAULT, |
| 1452 | CW_USEDEFAULT, 300, 200, info->WinType.hwndHelp, |
| 1453 | NULL, hhctrl_hinstance, NULL); |
| 1454 | if (!hwndPopup) |
| 1455 | return FALSE; |
| 1456 | |
| 1457 | hwndCallback = CreateWindowExW(WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR, |
| 1458 | szPopupChildClass, szEmpty, WS_CHILDWINDOW | WS_VISIBLE, |
| 1459 | 0, 0, 0, 0, |
| 1460 | hwndPopup, NULL, hhctrl_hinstance, NULL); |
| 1461 | if (!hwndCallback) |
| 1462 | return FALSE; |
| 1463 | |
| 1464 | ShowWindow(hwndPopup, SW_HIDE); |
| 1465 | hwndList = CreateWindowExW(WS_EX_CLIENTEDGE, WC_LISTVIEWW, szEmpty, |
| 1466 | WS_CHILD | WS_BORDER | LVS_SINGLESEL | LVS_REPORT |
| 1467 | | LVS_NOCOLUMNHEADER, 50, 50, 100, 100, |
| 1468 | hwndCallback, NULL, hhctrl_hinstance, NULL); |
| 1469 | if(!hwndList) { |
| 1470 | ERR("Could not create popup ListView control\n"); |
| 1471 | return FALSE; |
| 1472 | } |
| 1473 | memset(&lvc, 0, sizeof(lvc)); |
| 1474 | lvc.mask = LVCF_TEXT; |
| 1475 | lvc.pszText = hidden_column; |
| 1476 | if(SendMessageW(hwndList, LVM_INSERTCOLUMNA, 0, (LPARAM) &lvc) == -1) |
| 1477 | { |
| 1478 | ERR("Could not create popup ListView column\n"); |
| 1479 | return FALSE; |
| 1480 | } |
| 1481 | |
| 1482 | info->popup.hwndCallback = hwndCallback; |
| 1483 | info->popup.hwndPopup = hwndPopup; |
| 1484 | info->popup.hwndList = hwndList; |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1485 | SetWindowLongPtrW(hwndPopup, 0, (LONG_PTR)info); |
| 1486 | SetWindowLongPtrW(hwndCallback, 0, (LONG_PTR)info); |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1487 | |
| 1488 | ResizePopupChild(info); |
| 1489 | ShowWindow(hwndList, SW_SHOW); |
| 1490 | |
| 1491 | return TRUE; |
| 1492 | } |
| 1493 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1494 | /* Viewer Window */ |
| 1495 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1496 | static void ExpandContract(HHInfo *pHHInfo) |
| 1497 | { |
| 1498 | RECT r, nav; |
| 1499 | |
| 1500 | pHHInfo->WinType.fNotExpanded = !pHHInfo->WinType.fNotExpanded; |
| 1501 | GetWindowRect(pHHInfo->WinType.hwndHelp, &r); |
| 1502 | NP_GetNavigationRect(pHHInfo, &nav); |
| 1503 | |
| 1504 | /* hide/show both the nav bar and the size bar */ |
| 1505 | if (pHHInfo->WinType.fNotExpanded) |
| 1506 | { |
| 1507 | ShowWindow(pHHInfo->WinType.hwndNavigation, SW_HIDE); |
| 1508 | ShowWindow(pHHInfo->hwndSizeBar, SW_HIDE); |
| 1509 | r.left = r.left + nav.right; |
| 1510 | |
| 1511 | SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_EXPAND, MAKELPARAM(FALSE, 0)); |
| 1512 | SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_CONTRACT, MAKELPARAM(TRUE, 0)); |
| 1513 | } |
| 1514 | else |
| 1515 | { |
| 1516 | ShowWindow(pHHInfo->WinType.hwndNavigation, SW_SHOW); |
| 1517 | ShowWindow(pHHInfo->hwndSizeBar, SW_SHOW); |
| 1518 | r.left = r.left - nav.right; |
| 1519 | |
| 1520 | SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_EXPAND, MAKELPARAM(TRUE, 0)); |
| 1521 | SendMessageW(pHHInfo->WinType.hwndToolBar, TB_HIDEBUTTON, IDTB_CONTRACT, MAKELPARAM(FALSE, 0)); |
| 1522 | } |
| 1523 | |
| 1524 | MoveWindow(pHHInfo->WinType.hwndHelp, r.left, r.top, r.right-r.left, r.bottom-r.top, TRUE); |
| 1525 | } |
| 1526 | |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1527 | static LRESULT Help_OnSize(HWND hWnd) |
James Hawkins | 756d8e1 | 2005-08-15 10:21:56 +0000 | [diff] [blame] | 1528 | { |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1529 | HHInfo *pHHInfo = (HHInfo *)GetWindowLongPtrW(hWnd, 0); |
James Hawkins | 240e762 | 2005-09-25 15:17:42 +0000 | [diff] [blame] | 1530 | DWORD dwSize; |
James Hawkins | 756d8e1 | 2005-08-15 10:21:56 +0000 | [diff] [blame] | 1531 | RECT rc; |
| 1532 | |
| 1533 | if (!pHHInfo) |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1534 | return 0; |
James Hawkins | 756d8e1 | 2005-08-15 10:21:56 +0000 | [diff] [blame] | 1535 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1536 | if (!pHHInfo->WinType.fNotExpanded) |
| 1537 | { |
| 1538 | NP_GetNavigationRect(pHHInfo, &rc); |
| 1539 | SetWindowPos(pHHInfo->WinType.hwndNavigation, HWND_TOP, 0, 0, |
| 1540 | rc.right, rc.bottom, SWP_NOMOVE); |
James Hawkins | 756d8e1 | 2005-08-15 10:21:56 +0000 | [diff] [blame] | 1541 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1542 | SB_GetSizeBarRect(pHHInfo, &rc); |
| 1543 | SetWindowPos(pHHInfo->hwndSizeBar, HWND_TOP, rc.left, rc.top, |
| 1544 | rc.right, rc.bottom, SWP_SHOWWINDOW); |
| 1545 | |
| 1546 | } |
James Hawkins | 756d8e1 | 2005-08-15 10:21:56 +0000 | [diff] [blame] | 1547 | |
| 1548 | HP_GetHTMLRect(pHHInfo, &rc); |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1549 | SetWindowPos(pHHInfo->WinType.hwndHTML, HWND_TOP, rc.left, rc.top, |
James Hawkins | 240e762 | 2005-09-25 15:17:42 +0000 | [diff] [blame] | 1550 | rc.right, rc.bottom, SWP_SHOWWINDOW); |
| 1551 | |
| 1552 | /* Resize browser window taking the frame size into account */ |
| 1553 | dwSize = GetSystemMetrics(SM_CXFRAME); |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 1554 | ResizeWebBrowser(pHHInfo, rc.right - dwSize, rc.bottom - dwSize); |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1555 | |
| 1556 | return 0; |
James Hawkins | 756d8e1 | 2005-08-15 10:21:56 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
Alexandre Julliard | 9d5d7bf | 2006-08-02 22:02:25 +0200 | [diff] [blame] | 1559 | static LRESULT CALLBACK Help_WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1560 | { |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1561 | switch (message) |
| 1562 | { |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1563 | case WM_COMMAND: |
| 1564 | if (HIWORD(wParam) == BN_CLICKED) |
| 1565 | TB_OnClick(hWnd, LOWORD(wParam)); |
| 1566 | break; |
| 1567 | case WM_SIZE: |
| 1568 | return Help_OnSize(hWnd); |
Jacek Caban | ae9c043 | 2007-02-28 03:52:39 +0100 | [diff] [blame] | 1569 | case WM_CLOSE: |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1570 | ReleaseHelpViewer((HHInfo *)GetWindowLongPtrW(hWnd, 0)); |
Jacek Caban | ae9c043 | 2007-02-28 03:52:39 +0100 | [diff] [blame] | 1571 | return 0; |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1572 | case WM_DESTROY: |
Jacek Caban | 90fcc09 | 2007-02-28 03:54:25 +0100 | [diff] [blame] | 1573 | if(hh_process) |
| 1574 | PostQuitMessage(0); |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1575 | break; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1576 | |
Jacek Caban | 803cf4f | 2007-02-28 03:51:59 +0100 | [diff] [blame] | 1577 | default: |
| 1578 | return DefWindowProcW(hWnd, message, wParam, lParam); |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | return 0; |
| 1582 | } |
| 1583 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1584 | static BOOL HH_CreateHelpWindow(HHInfo *info) |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1585 | { |
| 1586 | HWND hWnd; |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1587 | RECT winPos = info->WinType.rcWindowPos; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1588 | WNDCLASSEXW wcex; |
| 1589 | DWORD dwStyles, dwExStyles; |
Dmitry Timoshkov | a314027 | 2010-06-01 15:26:13 +0900 | [diff] [blame] | 1590 | DWORD x, y, width = 0, height = 0; |
| 1591 | LPCWSTR caption; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1592 | |
| 1593 | static const WCHAR windowClassW[] = { |
| 1594 | 'H','H',' ', 'P','a','r','e','n','t',0 |
| 1595 | }; |
| 1596 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1597 | wcex.cbSize = sizeof(WNDCLASSEXW); |
| 1598 | wcex.style = CS_HREDRAW | CS_VREDRAW; |
Jacek Caban | 74fffe6 | 2007-02-28 03:50:14 +0100 | [diff] [blame] | 1599 | wcex.lpfnWndProc = Help_WndProc; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1600 | wcex.cbClsExtra = 0; |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1601 | wcex.cbWndExtra = sizeof(LONG_PTR); |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 1602 | wcex.hInstance = hhctrl_hinstance; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1603 | wcex.hIcon = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 1604 | wcex.hCursor = LoadCursorW(NULL, (LPCWSTR)IDC_ARROW); |
James Hawkins | 33eb060 | 2005-08-15 09:40:24 +0000 | [diff] [blame] | 1605 | wcex.hbrBackground = (HBRUSH)(COLOR_MENU + 1); |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1606 | wcex.lpszMenuName = NULL; |
| 1607 | wcex.lpszClassName = windowClassW; |
| 1608 | wcex.hIconSm = LoadIconW(NULL, (LPCWSTR)IDI_APPLICATION); |
| 1609 | |
| 1610 | RegisterClassExW(&wcex); |
| 1611 | |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1612 | /* Read in window parameters if available */ |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1613 | if (info->WinType.fsValidMembers & HHWIN_PARAM_STYLES) |
Jeff Zaroyko | 8595ffa | 2008-10-02 15:10:27 +1000 | [diff] [blame] | 1614 | dwStyles = info->WinType.dwStyles | WS_OVERLAPPEDWINDOW; |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1615 | else |
| 1616 | dwStyles = WS_OVERLAPPEDWINDOW | WS_VISIBLE | |
| 1617 | WS_CLIPSIBLINGS | WS_CLIPCHILDREN; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1618 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1619 | if (info->WinType.fsValidMembers & HHWIN_PARAM_EXSTYLES) |
| 1620 | dwExStyles = info->WinType.dwExStyles; |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1621 | else |
| 1622 | dwExStyles = WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_APPWINDOW | |
| 1623 | WS_EX_WINDOWEDGE | WS_EX_RIGHTSCROLLBAR; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1624 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1625 | if (info->WinType.fsValidMembers & HHWIN_PARAM_RECT) |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1626 | { |
| 1627 | x = winPos.left; |
| 1628 | y = winPos.top; |
| 1629 | width = winPos.right - x; |
| 1630 | height = winPos.bottom - y; |
| 1631 | } |
Dmitry Timoshkov | a314027 | 2010-06-01 15:26:13 +0900 | [diff] [blame] | 1632 | if (!width || !height) |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1633 | { |
| 1634 | x = WINTYPE_DEFAULT_X; |
| 1635 | y = WINTYPE_DEFAULT_Y; |
| 1636 | width = WINTYPE_DEFAULT_WIDTH; |
| 1637 | height = WINTYPE_DEFAULT_HEIGHT; |
| 1638 | } |
| 1639 | |
Owen Rudge | deda1b2 | 2011-01-17 22:26:40 +0000 | [diff] [blame] | 1640 | if (info->WinType.fNotExpanded) |
| 1641 | { |
| 1642 | if (!(info->WinType.fsValidMembers & HHWIN_PARAM_NAV_WIDTH) && |
| 1643 | info->WinType.iNavWidth == 0) |
| 1644 | { |
| 1645 | info->WinType.iNavWidth = WINTYPE_DEFAULT_NAVWIDTH; |
| 1646 | } |
| 1647 | |
| 1648 | x += info->WinType.iNavWidth; |
| 1649 | width -= info->WinType.iNavWidth; |
| 1650 | } |
| 1651 | |
| 1652 | |
Dmitry Timoshkov | a314027 | 2010-06-01 15:26:13 +0900 | [diff] [blame] | 1653 | caption = info->WinType.pszCaption; |
| 1654 | if (!*caption) caption = info->pCHMInfo->defTitle; |
| 1655 | |
| 1656 | hWnd = CreateWindowExW(dwExStyles, windowClassW, caption, |
Jacek Caban | 0262fb5 | 2007-02-22 22:57:40 +0100 | [diff] [blame] | 1657 | dwStyles, x, y, width, height, NULL, NULL, hhctrl_hinstance, NULL); |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1658 | if (!hWnd) |
| 1659 | return FALSE; |
| 1660 | |
| 1661 | ShowWindow(hWnd, SW_SHOW); |
| 1662 | UpdateWindow(hWnd); |
| 1663 | |
| 1664 | /* store the pointer to the HH info struct */ |
Andrew Eikum | 8041c9b | 2012-06-19 13:22:46 -0500 | [diff] [blame] | 1665 | SetWindowLongPtrW(hWnd, 0, (LONG_PTR)info); |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1666 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1667 | info->WinType.hwndHelp = hWnd; |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1668 | return TRUE; |
| 1669 | } |
| 1670 | |
| 1671 | static void HH_CreateFont(HHInfo *pHHInfo) |
| 1672 | { |
| 1673 | LOGFONTW lf; |
| 1674 | |
Akihiro Sagawa | e7efd14 | 2011-02-26 20:31:26 +0900 | [diff] [blame] | 1675 | GetObjectW(GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONTW), &lf); |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1676 | lf.lfWeight = FW_NORMAL; |
| 1677 | lf.lfItalic = FALSE; |
| 1678 | lf.lfUnderline = FALSE; |
| 1679 | |
| 1680 | pHHInfo->hFont = CreateFontIndirectW(&lf); |
| 1681 | } |
| 1682 | |
| 1683 | static void HH_InitRequiredControls(DWORD dwControls) |
| 1684 | { |
| 1685 | INITCOMMONCONTROLSEX icex; |
| 1686 | |
| 1687 | icex.dwSize = sizeof(INITCOMMONCONTROLSEX); |
| 1688 | icex.dwICC = dwControls; |
| 1689 | InitCommonControlsEx(&icex); |
| 1690 | } |
| 1691 | |
| 1692 | /* Creates the whole package */ |
Jacek Caban | 1a2456c | 2007-02-28 03:48:45 +0100 | [diff] [blame] | 1693 | static BOOL CreateViewer(HHInfo *pHHInfo) |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1694 | { |
| 1695 | HH_CreateFont(pHHInfo); |
| 1696 | |
| 1697 | if (!HH_CreateHelpWindow(pHHInfo)) |
| 1698 | return FALSE; |
| 1699 | |
| 1700 | HH_InitRequiredControls(ICC_BAR_CLASSES); |
| 1701 | |
| 1702 | if (!HH_AddToolbar(pHHInfo)) |
| 1703 | return FALSE; |
| 1704 | |
James Hawkins | eece303 | 2005-08-03 10:56:55 +0000 | [diff] [blame] | 1705 | HH_RegisterChildWndClass(pHHInfo); |
| 1706 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1707 | if (!HH_AddNavigationPane(pHHInfo)) |
| 1708 | return FALSE; |
| 1709 | |
James Hawkins | 6a09a4f | 2005-09-21 11:42:41 +0000 | [diff] [blame] | 1710 | HH_RegisterSizeBarClass(pHHInfo); |
| 1711 | |
| 1712 | if (!HH_AddSizeBar(pHHInfo)) |
| 1713 | return FALSE; |
| 1714 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1715 | if (!HH_AddHTMLPane(pHHInfo)) |
| 1716 | return FALSE; |
| 1717 | |
Jacek Caban | 6b68e8d | 2007-02-28 03:58:18 +0100 | [diff] [blame] | 1718 | if (!AddContentTab(pHHInfo)) |
| 1719 | return FALSE; |
| 1720 | |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 1721 | if (!AddIndexTab(pHHInfo)) |
| 1722 | return FALSE; |
| 1723 | |
Erich Hoover | 6ae7fe6 | 2010-01-27 01:12:32 -0700 | [diff] [blame] | 1724 | if (!AddIndexPopup(pHHInfo)) |
| 1725 | return FALSE; |
| 1726 | |
Erich Hoover | 796c4de | 2010-02-07 10:09:04 -0700 | [diff] [blame] | 1727 | if (!AddSearchTab(pHHInfo)) |
| 1728 | return FALSE; |
| 1729 | |
Jacek Caban | cdb67b2 | 2007-02-28 03:59:07 +0100 | [diff] [blame] | 1730 | InitContent(pHHInfo); |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 1731 | InitIndex(pHHInfo); |
Jacek Caban | cdb67b2 | 2007-02-28 03:59:07 +0100 | [diff] [blame] | 1732 | |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1733 | return TRUE; |
| 1734 | } |
| 1735 | |
Jacek Caban | e0b952b | 2007-02-28 03:49:20 +0100 | [diff] [blame] | 1736 | void ReleaseHelpViewer(HHInfo *info) |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1737 | { |
Jacek Caban | aa1b38c | 2007-03-02 18:21:02 +0100 | [diff] [blame] | 1738 | TRACE("(%p)\n", info); |
| 1739 | |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1740 | if (!info) |
James Hawkins | 8db2c26 | 2005-08-01 09:21:53 +0000 | [diff] [blame] | 1741 | return; |
| 1742 | |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1743 | /* Free allocated strings */ |
Alexandre Julliard | 7293f00 | 2007-12-13 13:48:00 +0100 | [diff] [blame] | 1744 | heap_free(info->pszType); |
| 1745 | heap_free(info->pszCaption); |
| 1746 | heap_free(info->pszToc); |
| 1747 | heap_free(info->pszIndex); |
| 1748 | heap_free(info->pszFile); |
| 1749 | heap_free(info->pszHome); |
| 1750 | heap_free(info->pszJump1); |
| 1751 | heap_free(info->pszJump2); |
| 1752 | heap_free(info->pszUrlJump1); |
| 1753 | heap_free(info->pszUrlJump2); |
Jacek Caban | 5a01e10 | 2007-02-28 03:46:15 +0100 | [diff] [blame] | 1754 | |
| 1755 | if (info->pCHMInfo) |
| 1756 | CloseCHM(info->pCHMInfo); |
| 1757 | |
Jacek Caban | 24c13b9 | 2007-02-28 03:47:13 +0100 | [diff] [blame] | 1758 | ReleaseWebBrowser(info); |
Jacek Caban | cdb67b2 | 2007-02-28 03:59:07 +0100 | [diff] [blame] | 1759 | ReleaseContent(info); |
Erich Hoover | 50f67cb | 2010-01-27 01:12:25 -0700 | [diff] [blame] | 1760 | ReleaseIndex(info); |
Erich Hoover | cff5f60 | 2010-02-07 10:39:33 -0700 | [diff] [blame] | 1761 | ReleaseSearch(info); |
Jacek Caban | 1a2456c | 2007-02-28 03:48:45 +0100 | [diff] [blame] | 1762 | |
Erich Hoover | fc413c7 | 2012-06-22 11:07:19 -0600 | [diff] [blame] | 1763 | if(info->contents.hImageList) |
| 1764 | ImageList_Destroy(info->contents.hImageList); |
Jacek Caban | ae9c043 | 2007-02-28 03:52:39 +0100 | [diff] [blame] | 1765 | if(info->WinType.hwndHelp) |
| 1766 | DestroyWindow(info->WinType.hwndHelp); |
| 1767 | |
Michael Stefaniuc | 7e8d79f | 2007-12-09 16:29:44 +0100 | [diff] [blame] | 1768 | heap_free(info); |
Jacek Caban | 1a2456c | 2007-02-28 03:48:45 +0100 | [diff] [blame] | 1769 | OleUninitialize(); |
James Hawkins | 3e507e3 | 2005-09-13 10:32:47 +0000 | [diff] [blame] | 1770 | } |
| 1771 | |
Jacek Caban | e0b952b | 2007-02-28 03:49:20 +0100 | [diff] [blame] | 1772 | HHInfo *CreateHelpViewer(LPCWSTR filename) |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1773 | { |
Michael Stefaniuc | 7e8d79f | 2007-12-09 16:29:44 +0100 | [diff] [blame] | 1774 | HHInfo *info = heap_alloc_zero(sizeof(HHInfo)); |
Erich Hoover | d3bd40d | 2010-01-27 01:11:56 -0700 | [diff] [blame] | 1775 | int i; |
| 1776 | |
| 1777 | /* Set the invalid tab ID (-1) as the default value for all |
| 1778 | * of the tabs, this matches a failed TCM_INSERTITEM call. |
| 1779 | */ |
| 1780 | for(i=0;i<sizeof(info->tabs)/sizeof(HHTab);i++) |
| 1781 | info->tabs[i].id = -1; |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1782 | |
Jacek Caban | 1a2456c | 2007-02-28 03:48:45 +0100 | [diff] [blame] | 1783 | OleInitialize(NULL); |
| 1784 | |
| 1785 | info->pCHMInfo = OpenCHM(filename); |
| 1786 | if(!info->pCHMInfo) { |
| 1787 | ReleaseHelpViewer(info); |
Jacek Caban | 1711c3a | 2007-02-23 03:30:38 +0100 | [diff] [blame] | 1788 | return NULL; |
| 1789 | } |
| 1790 | |
Alexandre Julliard | 7293f00 | 2007-12-13 13:48:00 +0100 | [diff] [blame] | 1791 | if (!LoadWinTypeFromCHM(info)) { |
Jacek Caban | 1a2456c | 2007-02-28 03:48:45 +0100 | [diff] [blame] | 1792 | ReleaseHelpViewer(info); |
Jacek Caban | 976f2db | 2007-02-23 03:30:02 +0100 | [diff] [blame] | 1793 | return NULL; |
| 1794 | } |
| 1795 | |
Jacek Caban | 1a2456c | 2007-02-28 03:48:45 +0100 | [diff] [blame] | 1796 | if(!CreateViewer(info)) { |
| 1797 | ReleaseHelpViewer(info); |
| 1798 | return NULL; |
| 1799 | } |
| 1800 | |
| 1801 | return info; |
James Hawkins | e9ce577 | 2005-09-06 09:20:42 +0000 | [diff] [blame] | 1802 | } |
Erich Hoover | 9033b14 | 2012-06-20 14:31:10 -0600 | [diff] [blame] | 1803 | |
| 1804 | /* |
| 1805 | * Search the table of HTML entities and return the corresponding ANSI symbol. |
| 1806 | */ |
| 1807 | static char find_html_symbol(const char *entity, int entity_len) |
| 1808 | { |
| 1809 | int max = sizeof(html_encoded_symbols)/sizeof(html_encoded_symbols[0])-1; |
| 1810 | int min = 0, dir; |
| 1811 | |
| 1812 | while(min <= max) |
| 1813 | { |
| 1814 | int pos = (min+max)/2; |
| 1815 | const char *encoded_symbol = html_encoded_symbols[pos].html_code; |
| 1816 | dir = strncmp(encoded_symbol, entity, entity_len); |
| 1817 | if(dir == 0 && !encoded_symbol[entity_len]) return html_encoded_symbols[pos].ansi_symbol; |
| 1818 | if(dir < 0) |
| 1819 | min = pos+1; |
| 1820 | else |
| 1821 | max = pos-1; |
| 1822 | } |
| 1823 | return 0; |
| 1824 | } |
| 1825 | |
| 1826 | /* |
| 1827 | * Decode a string containing HTML encoded characters into a unicode string. |
| 1828 | */ |
Erich Hoover | a02ad10 | 2012-06-20 14:31:19 -0600 | [diff] [blame] | 1829 | WCHAR *decode_html(const char *html_fragment, int html_fragment_len, UINT code_page) |
Erich Hoover | 9033b14 | 2012-06-20 14:31:10 -0600 | [diff] [blame] | 1830 | { |
| 1831 | const char *h = html_fragment; |
| 1832 | char *amp, *sem, symbol, *tmp; |
| 1833 | int len, tmp_len = 0; |
| 1834 | WCHAR *unicode_text; |
| 1835 | |
| 1836 | tmp = heap_alloc(html_fragment_len+1); |
| 1837 | while(1) |
| 1838 | { |
| 1839 | symbol = 0; |
| 1840 | amp = strchr(h, '&'); |
| 1841 | if(!amp) break; |
| 1842 | len = amp-h; |
| 1843 | /* Copy the characters prior to the HTML encoded character */ |
| 1844 | memcpy(&tmp[tmp_len], h, len); |
| 1845 | tmp_len += len; |
| 1846 | amp++; /* skip ampersand */ |
| 1847 | sem = strchr(amp, ';'); |
| 1848 | /* Require a semicolon after the ampersand */ |
| 1849 | if(!sem) |
| 1850 | { |
| 1851 | h = amp; |
| 1852 | tmp[tmp_len++] = '&'; |
| 1853 | continue; |
| 1854 | } |
| 1855 | /* Find the symbol either by using the ANSI character number (prefixed by the pound symbol) |
| 1856 | * or by searching the HTML entity table */ |
| 1857 | len = sem-amp; |
| 1858 | if(amp[0] == '#') |
| 1859 | { |
| 1860 | char *endnum = NULL; |
| 1861 | int tmp; |
| 1862 | |
| 1863 | tmp = (char) strtol(amp, &endnum, 10); |
| 1864 | if(endnum == sem) |
| 1865 | symbol = tmp; |
| 1866 | } |
| 1867 | else |
| 1868 | symbol = find_html_symbol(amp, len); |
| 1869 | if(!symbol) |
| 1870 | { |
| 1871 | FIXME("Failed to translate HTML encoded character '&%.*s;'.\n", len, amp); |
| 1872 | h = amp; |
| 1873 | tmp[tmp_len++] = '&'; |
| 1874 | continue; |
| 1875 | } |
| 1876 | /* Insert the new symbol */ |
| 1877 | h = sem+1; |
| 1878 | tmp[tmp_len++] = symbol; |
| 1879 | } |
| 1880 | /* Convert any remaining characters */ |
| 1881 | len = html_fragment_len-(h-html_fragment); |
| 1882 | memcpy(&tmp[tmp_len], h, len); |
| 1883 | tmp_len += len; |
| 1884 | tmp[tmp_len++] = 0; /* NULL-terminate the string */ |
| 1885 | |
Erich Hoover | a02ad10 | 2012-06-20 14:31:19 -0600 | [diff] [blame] | 1886 | len = MultiByteToWideChar(code_page, 0, tmp, tmp_len, NULL, 0); |
Erich Hoover | 9033b14 | 2012-06-20 14:31:10 -0600 | [diff] [blame] | 1887 | unicode_text = heap_alloc(len*sizeof(WCHAR)); |
Erich Hoover | a02ad10 | 2012-06-20 14:31:19 -0600 | [diff] [blame] | 1888 | MultiByteToWideChar(code_page, 0, tmp, tmp_len, unicode_text, len); |
Erich Hoover | 9033b14 | 2012-06-20 14:31:10 -0600 | [diff] [blame] | 1889 | heap_free(tmp); |
| 1890 | return unicode_text; |
| 1891 | } |