Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

921 lines
28 KiB

  1. ///////////////////////////////////////////////////////////////////////
  2. // Microsoft Windows //
  3. // Copyright(c) Microsoft Corp., 1995 //
  4. ///////////////////////////////////////////////////////////////////////
  5. //
  6. // GENERAL.C - "General" property page for InetCpl
  7. //
  8. // HISTORY:
  9. //
  10. // 6/22/96 t-gpease moved code from dialdlg.c - no changes
  11. //
  12. #include "inetcplp.h"
  13. #include <urlhist.h>
  14. #include <initguid.h>
  15. #include <shlguid.h>
  16. #include <cleanoc.h>
  17. #include <mluisupp.h>
  18. //#include <shdocvw.h>
  19. SHDOCAPI_(BOOL) ParseURLFromOutsideSourceA (LPCSTR psz, LPSTR pszOut, LPDWORD pcchOut, LPBOOL pbWasSearchURL);
  20. SHDOCAPI_(BOOL) ParseURLFromOutsideSourceW (LPCWSTR psz, LPWSTR pszOut, LPDWORD pcchOut, LPBOOL pbWasSearchURL);
  21. #ifdef UNICODE
  22. #define ParseURLFromOutsideSource ParseURLFromOutsideSourceW
  23. #else
  24. #define ParseURLFromOutsideSource ParseURLFromOutsideSourceA
  25. #endif
  26. //
  27. // See inetcplp.h for documentation on this flag
  28. //
  29. BOOL g_fReloadHomePage = FALSE;
  30. //
  31. // Private Functions and Structures
  32. //
  33. // from cachecpl.c
  34. #define CONTENT 0
  35. BOOL InvokeCachevu(HWND hDlg);
  36. INT_PTR CALLBACK EmptyCacheDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  37. INT_PTR CALLBACK EmptyCacheCookiesDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  38. BOOL DeleteCacheCookies();
  39. INT_PTR CALLBACK ColorsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  40. INT_PTR CALLBACK AccessibilityDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam);
  41. /////// General Tab Info Structure ///////
  42. typedef struct _GeneralTabInfo {
  43. HWND hDlg;
  44. HWND hwndUrl;
  45. TCHAR szCurrentURL[INTERNET_MAX_URL_LENGTH]; // current url in browser
  46. TCHAR szStartPageURL[INTERNET_MAX_URL_LENGTH]; // current url for start page
  47. BOOL fInternalChange;
  48. BOOL fChanged;
  49. HRESULT hrOle; // result of com initialization
  50. } GeneralTabInfo, *LPGENERALTABINFO, GENERALTABINFO;
  51. void SetandSelectText(LPGENERALTABINFO pgti, HWND hwnd, LPTSTR psz);
  52. BOOL GetHistoryFolderPath(LPTSTR pszPath);
  53. void EmptyHistory(LPGENERALTABINFO pgti);
  54. void HistorySave(LPGENERALTABINFO pgti);
  55. static DWORD GetDaysToKeep(VOID);
  56. VOID SetDaysToKeep(DWORD dwDays);
  57. void GetDefaultStartPage(LPGENERALTABINFO pgti);
  58. HRESULT _GetStdLocation(LPTSTR pszPath, DWORD cbPathSize, UINT id);
  59. HRESULT _SetStdLocation(LPTSTR szPath, UINT id);
  60. // from shdocvw
  61. #define IDS_DEF_HOME 998 //// WARNING!!! DO NOT CHANGE THESE VALUES
  62. #define IDS_DEF_SEARCH 999 //// WARNING!!! INETCPL RELIES ON THEM
  63. #define IDS_SEARCHPAGE IDS_DEF_SEARCH
  64. #define IDS_STARTPAGE IDS_DEF_HOME
  65. #if defined(ux10) && defined(UNIX)
  66. //Work around for mmap limitation in hp-ux10
  67. #define MAX_HISTORY_DAYS 30
  68. #else
  69. #define MAX_HISTORY_DAYS 999
  70. #endif
  71. #define DEFAULT_DAYS_TO_KEEP 14
  72. #define SAFERELEASE(p) if(p) {(p)->Release(); (p) = NULL;}
  73. TCHAR szDefURLValueNames[] = TEXT("Default_Page_URL");
  74. //
  75. // Functions
  76. //
  77. BOOL General_InitDialog(HWND hDlg)
  78. {
  79. DWORD cb = sizeof(DWORD);
  80. LPGENERALTABINFO pgti;
  81. #ifdef UNIX
  82. BOOL bCacheIsReadOnly = FALSE;
  83. #endif /* UNIX */
  84. // allocate memory for a structure which will hold all the info
  85. // gathered from this page
  86. //
  87. pgti = (LPGENERALTABINFO)LocalAlloc(LPTR, sizeof(GENERALTABINFO));
  88. if (!pgti)
  89. {
  90. EndDialog(hDlg, 0);
  91. return FALSE;
  92. }
  93. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM)pgti);
  94. // NOTE (andrewgu): ie5.5 b#106468 - need to initialize COM before calling SHAutoComplete.
  95. // it will be uninitialized during WM_DESTROY.
  96. pgti->hrOle = SHCoInitialize();
  97. // cross-lang platform support
  98. SHSetDefaultDialogFont(hDlg, IDC_START_ADDRESS);
  99. SHAutoComplete(GetDlgItem(hDlg, IDC_START_ADDRESS), SHACF_DEFAULT);
  100. pgti->hDlg = hDlg;
  101. // enable the "Use Current" button if we have a current url
  102. StrCpyN(pgti->szCurrentURL, g_szCurrentURL, ARRAYSIZE(pgti->szCurrentURL));
  103. EnableWindow(GetDlgItem(hDlg, IDC_USECURRENT), pgti->szCurrentURL[0]);
  104. // get the url edit control and set the text limit
  105. pgti->hwndUrl = GetDlgItem(hDlg, IDC_START_ADDRESS);
  106. SendMessage(pgti->hwndUrl, EM_LIMITTEXT, ARRAYSIZE(pgti->szStartPageURL)-1, 0);
  107. GetDefaultStartPage(pgti);
  108. _GetStdLocation(pgti->szStartPageURL, ARRAYSIZE(pgti->szStartPageURL), IDS_STARTPAGE);
  109. SetandSelectText(pgti, pgti->hwndUrl, (LPTSTR)pgti->szStartPageURL);
  110. // set restrictions on history controls
  111. SendDlgItemMessage(pgti->hDlg, IDC_HISTORY_SPIN,
  112. UDM_SETRANGE, 0, MAKELPARAM(MAX_HISTORY_DAYS, 0));
  113. SendDlgItemMessage(pgti->hDlg, IDC_HISTORY_SPIN,
  114. UDM_SETPOS, 0, MAKELPARAM((WORD) GetDaysToKeep(), 0));
  115. Edit_LimitText(GetDlgItem(hDlg,IDC_HISTORY_DAYS),3); // limit edit ctrl to 3 chars
  116. // only when invoked from View|Options
  117. if (g_szCurrentURL[0])
  118. {
  119. TCHAR szTitle[128];
  120. MLLoadString(IDS_INTERNETOPTIONS, szTitle, ARRAYSIZE(szTitle));
  121. SendMessage(GetParent(hDlg), WM_SETTEXT, 0, (LPARAM)szTitle);
  122. }
  123. // disable stuff based on restrictions
  124. if (g_restrict.fPlaces)
  125. {
  126. EnableWindow(GetDlgItem(hDlg, IDC_START_ADDRESS), FALSE);
  127. EnableWindow(GetDlgItem(hDlg, IDC_USEDEFAULT), FALSE);
  128. EnableWindow(GetDlgItem(hDlg, IDC_USEBLANK), FALSE);
  129. EnableWindow(GetDlgItem(hDlg, IDC_USECURRENT), FALSE);
  130. }
  131. if (g_restrict.fCacheReadOnly)
  132. {
  133. EnableWindow(GetDlgItem(hDlg, IDC_CACHE_DELETE_COOKIES), FALSE);
  134. EnableWindow(GetDlgItem(hDlg, IDC_CACHE_DELETE_FILES), FALSE);
  135. EnableWindow(GetDlgItem(hDlg, IDC_CACHE_SETTINGS), FALSE);
  136. }
  137. #ifdef UNIX
  138. bCacheIsReadOnly = IsCacheReadOnly();
  139. if (bCacheIsReadOnly)
  140. {
  141. EnableWindow(GetDlgItem(hDlg, IDC_CACHE_DELETE_COOKIES), FALSE);
  142. EnableWindow(GetDlgItem(hDlg, IDC_CACHE_DELETE_FILES), FALSE);
  143. EnableWindow(GetDlgItem(hDlg, IDC_CACHE_SETTINGS), FALSE);
  144. }
  145. if (g_restrict.fCache || bCacheIsReadOnly)
  146. {
  147. TCHAR szText[1024];
  148. MLLoadString(IDS_READONLY_CACHE_TEXT, szText, ARRAYSIZE(szText));
  149. SetWindowText(GetDlgItem(hDlg, IDC_READONLY_CACHE_WARNING), szText);
  150. ShowWindow( GetDlgItem(hDlg, IDC_READONLY_CACHE_WARNING), SW_SHOW );
  151. ShowWindow( GetDlgItem(hDlg, IDC_TEMP_INTERNET_TEXT), SW_HIDE);
  152. }
  153. #endif /* !UNIX */
  154. if (g_restrict.fHistory)
  155. {
  156. EnableWindow(GetDlgItem(hDlg, IDC_HISTORY_DAYS), FALSE);
  157. EnableWindow(GetDlgItem(hDlg, IDC_HISTORY_SPIN), FALSE);
  158. EnableWindow(GetDlgItem(hDlg, IDC_HISTORY_CLEAR), FALSE);
  159. }
  160. return TRUE;
  161. }
  162. BOOL General_OnCommand(LPGENERALTABINFO pgti, UINT id, UINT nCmd)
  163. {
  164. switch (id)
  165. {
  166. case IDC_START_ADDRESS:
  167. switch (nCmd)
  168. {
  169. case EN_CHANGE:
  170. if (!pgti->fInternalChange)
  171. {
  172. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  173. pgti->fChanged = TRUE;
  174. }
  175. break;
  176. }
  177. break;
  178. case IDC_USECURRENT:
  179. if (nCmd == BN_CLICKED)
  180. {
  181. StrCpyN(pgti->szStartPageURL, pgti->szCurrentURL, ARRAYSIZE(pgti->szStartPageURL));
  182. SetandSelectText(pgti, pgti->hwndUrl, pgti->szStartPageURL);
  183. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  184. pgti->fChanged = TRUE;
  185. }
  186. break;
  187. case IDC_USEDEFAULT:
  188. if (nCmd == BN_CLICKED)
  189. {
  190. GetDefaultStartPage(pgti);
  191. SetandSelectText(pgti, pgti->hwndUrl, pgti->szStartPageURL);
  192. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  193. pgti->fChanged = TRUE;
  194. }
  195. break;
  196. case IDC_USEBLANK:
  197. if (nCmd == BN_CLICKED)
  198. {
  199. StrCpyN(pgti->szStartPageURL, TEXT("about:blank"), ARRAYSIZE(pgti->szStartPageURL));
  200. SetandSelectText(pgti, pgti->hwndUrl, pgti->szStartPageURL);
  201. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  202. pgti->fChanged = TRUE;
  203. }
  204. break;
  205. case IDC_HISTORY_SPIN:
  206. case IDC_HISTORY_DAYS:
  207. if (pgti && (nCmd == EN_CHANGE))
  208. {
  209. PropSheet_Changed(GetParent(pgti->hDlg),pgti->hDlg);
  210. pgti->fChanged = TRUE;
  211. }
  212. break;
  213. case IDC_HISTORY_VIEW:
  214. {
  215. TCHAR szPath[MAX_PATH];
  216. if (!GetHistoryFolderPath(szPath))
  217. {
  218. GetWindowsDirectory(szPath, ARRAYSIZE(szPath));
  219. PathAppend(szPath, TEXT("history"));
  220. }
  221. SHELLEXECUTEINFO shei= { 0 };
  222. shei.cbSize = sizeof(shei);
  223. shei.lpFile = szPath;
  224. shei.lpClass = TEXT("Folder");
  225. shei.fMask = SEE_MASK_CLASSNAME;
  226. shei.nShow = SW_SHOWNORMAL;
  227. ShellExecuteEx(&shei);
  228. break;
  229. }
  230. case IDC_HISTORY_CLEAR:
  231. if (MsgBox(pgti->hDlg, IDS_ClearHistory, MB_ICONQUESTION,
  232. MB_YESNO | MB_DEFBUTTON2 )
  233. == IDYES)
  234. {
  235. HCURSOR hOldCursor = NULL;
  236. HCURSOR hNewCursor = NULL;
  237. // IEUNIX-Removing redundant use of MAKEINTRESOURCE
  238. #ifndef UNIX
  239. hNewCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
  240. #else
  241. hNewCursor = LoadCursor(NULL, IDC_WAIT);
  242. #endif
  243. if (hNewCursor)
  244. hOldCursor = SetCursor(hNewCursor);
  245. EmptyHistory(pgti);
  246. if(hOldCursor)
  247. SetCursor(hOldCursor);
  248. }
  249. break;
  250. case IDC_CACHE_SETTINGS:
  251. DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_TEMP_FILES),
  252. pgti->hDlg, TemporaryDlgProc);
  253. break; // IDC_ADVANCED_CACHE_FILES_BUTTON
  254. case IDC_CACHE_DELETE_COOKIES:
  255. {
  256. INT_PTR iRet = DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_CACHE_COOKIES_EMPTY),
  257. pgti->hDlg, EmptyCacheCookiesDlgProc);
  258. if (iRet == 1)
  259. {
  260. HCURSOR hOldCursor = NULL;
  261. HCURSOR hAdvancedCursor = NULL;
  262. #ifndef UNIX
  263. hAdvancedCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
  264. #else
  265. //IEUNIX-Removing redundant use of MAKEINTRESOURCE
  266. hAdvancedCursor = LoadCursor(NULL, IDC_WAIT);
  267. #endif
  268. if (hAdvancedCursor)
  269. hOldCursor = SetCursor(hAdvancedCursor);
  270. DeleteCacheCookies();
  271. if (hOldCursor)
  272. SetCursor(hOldCursor);
  273. }
  274. break;
  275. }
  276. case IDC_CACHE_DELETE_FILES:
  277. {
  278. INT_PTR iRet = DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_CACHE_EMPTY),
  279. pgti->hDlg, EmptyCacheDlgProc);
  280. if ((iRet == 1) || (iRet == 3))
  281. {
  282. HCURSOR hOldCursor = NULL;
  283. HCURSOR hAdvancedCursor = NULL;
  284. INTERNET_CACHE_CONFIG_INFOA icci;
  285. icci.dwContainer = CONTENT;
  286. GetUrlCacheConfigInfoA(&icci, NULL, CACHE_CONFIG_DISK_CACHE_PATHS_FC);
  287. #ifndef UNIX
  288. hAdvancedCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT));
  289. #else
  290. //IEUNIX-Removing redundant use of MAKEINTRESOURCE
  291. hAdvancedCursor = LoadCursor(NULL, IDC_WAIT);
  292. #endif
  293. if (hAdvancedCursor)
  294. hOldCursor = SetCursor(hAdvancedCursor);
  295. switch (iRet) {
  296. case 1:
  297. FreeUrlCacheSpaceA(icci.CachePath, 100, STICKY_CACHE_ENTRY);
  298. TraceMsg(TF_GENERAL, "Call FreeUrlCacheSpace with 0x%x",STICKY_CACHE_ENTRY);
  299. break;
  300. case 3:
  301. FreeUrlCacheSpaceA(icci.CachePath, 100, 0 /*remove all*/);
  302. TraceMsg(TF_GENERAL, "Call FreeUrlCacheSpace with 0");
  303. break;
  304. default:
  305. break;
  306. }
  307. // Remove expired controls from Downloaded Program Files ( OCCache )
  308. // We'll do this silently, which leaves uncertain stuff behing, cuz
  309. // this is preferrable to raising a variable number of confirmation dialogs.
  310. RemoveExpiredControls( REC_SILENT, 0);
  311. TraceMsg(TF_GENERAL, "Call RemoveExpiredControls (silent)");
  312. if (hOldCursor)
  313. SetCursor(hOldCursor);
  314. }
  315. break;
  316. }
  317. case IDC_LANGUAGES:
  318. if (nCmd == BN_CLICKED)
  319. {
  320. KickLanguageDialog(pgti->hDlg);
  321. }
  322. break;
  323. case IDC_FONTS:
  324. if (nCmd == BN_CLICKED)
  325. OpenFontsDialogEx( pgti->hDlg, NULL );
  326. break;
  327. case IDC_COLORS:
  328. if (nCmd == BN_CLICKED)
  329. DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_COLORS), pgti->hDlg, ColorsDlgProc);
  330. break;
  331. case IDC_ACCESSIBILITY:
  332. if (nCmd == BN_CLICKED)
  333. DialogBox(MLGetHinst(), MAKEINTRESOURCE(IDD_ACCESSIBILITY), pgti->hDlg, AccessibilityDlgProc);
  334. break;
  335. }
  336. return TRUE;
  337. }
  338. void General_Apply(HWND hDlg)
  339. {
  340. LPGENERALTABINFO pgti = (LPGENERALTABINFO) GetWindowLongPtr(hDlg, DWLP_USER);
  341. if (pgti->fChanged)
  342. {
  343. INT_PTR iDays = SendDlgItemMessage(pgti->hDlg, IDC_HISTORY_SPIN, UDM_GETPOS, 0, 0 );
  344. TCHAR szStartPageURL[MAX_URL_STRING];
  345. SendMessage(pgti->hwndUrl, WM_GETTEXT, (WPARAM)ARRAYSIZE(szStartPageURL), (LPARAM)(szStartPageURL));
  346. if (szStartPageURL[0])
  347. {
  348. StrCpyN(pgti->szStartPageURL, szStartPageURL, ARRAYSIZE(pgti->szStartPageURL));
  349. PathRemoveBlanks(pgti->szStartPageURL);
  350. _SetStdLocation(pgti->szStartPageURL, IDS_STARTPAGE);
  351. }
  352. else
  353. {
  354. SendMessage(pgti->hwndUrl, WM_SETTEXT, (WPARAM)ARRAYSIZE(pgti->szStartPageURL), (LPARAM)(pgti->szStartPageURL));
  355. }
  356. // make sure that the edit box is not beyond the maximum allowed value
  357. if (iDays>=0xFFFF)
  358. iDays = MAX_HISTORY_DAYS;
  359. SetDaysToKeep((DWORD)iDays);
  360. UpdateAllWindows();
  361. // reset this flag, now that we've applied the changes
  362. pgti->fChanged = FALSE;
  363. }
  364. }
  365. void ReloadHomePageIfNeeded(LPGENERALTABINFO pgti)
  366. {
  367. ASSERT(pgti);
  368. if (!pgti)
  369. return;
  370. if (g_fReloadHomePage)
  371. {
  372. //
  373. // If needed, reload the homepage url from the registry
  374. //
  375. _GetStdLocation(pgti->szStartPageURL, ARRAYSIZE(pgti->szStartPageURL), IDS_STARTPAGE);
  376. SetandSelectText(pgti, pgti->hwndUrl, (LPTSTR)pgti->szStartPageURL);
  377. g_fReloadHomePage = FALSE;
  378. }
  379. }
  380. INT_PTR CALLBACK General_DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  381. {
  382. // get our tab info structure
  383. LPGENERALTABINFO pgti;
  384. if (uMsg == WM_INITDIALOG)
  385. return General_InitDialog(hDlg);
  386. else
  387. pgti = (LPGENERALTABINFO) GetWindowLongPtr(hDlg, DWLP_USER);
  388. if (!pgti)
  389. return FALSE;
  390. switch (uMsg)
  391. {
  392. case WM_NOTIFY:
  393. {
  394. NMHDR *lpnm = (NMHDR *) lParam;
  395. switch (lpnm->code)
  396. {
  397. case PSN_SETACTIVE:
  398. ReloadHomePageIfNeeded(pgti);
  399. return TRUE;
  400. case PSN_KILLACTIVE:
  401. #if defined(ux10) && defined(UNIX)
  402. //Work around for mmap limitation in hp-ux10
  403. INT_PTR iDays = SendDlgItemMessage(pgti->hDlg, IDC_HISTORY_SPIN, UDM_GETPOS, 0, 0 );
  404. if (iDays > MAX_HISTORY_DAYS)
  405. {
  406. MessageBox(pgti->hDlg, TEXT("Days to keep pages in history cannot be greater 30."), NULL, MB_OK);
  407. Edit_SetText(GetDlgItem(hDlg,IDC_HISTORY_DAYS), TEXT("30"));
  408. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, TRUE);
  409. return TRUE;
  410. }
  411. else
  412. {
  413. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  414. return TRUE;
  415. }
  416. #endif
  417. case PSN_QUERYCANCEL:
  418. case PSN_RESET:
  419. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
  420. return TRUE;
  421. case PSN_APPLY:
  422. ReloadHomePageIfNeeded(pgti);
  423. General_Apply(hDlg);
  424. break;
  425. }
  426. break;
  427. }
  428. case WM_COMMAND:
  429. General_OnCommand(pgti, LOWORD(wParam), HIWORD(wParam));
  430. break;
  431. case WM_HELP: // F1
  432. ResWinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle, IDS_HELPFILE,
  433. HELP_WM_HELP, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  434. break;
  435. case WM_CONTEXTMENU: // right mouse click
  436. ResWinHelp( (HWND) wParam, IDS_HELPFILE,
  437. HELP_CONTEXTMENU, (DWORD_PTR)(LPSTR)mapIDCsToIDHs);
  438. break;
  439. case WM_DESTROY:
  440. // destroying this deliberately flushes its update (see WM_DESTROY in the UpdateWndProc);
  441. SHRemoveDefaultDialogFont(hDlg);
  442. #ifndef UNIX
  443. // Should only be destroyed in process detach
  444. if (g_hwndUpdate)
  445. DestroyWindow(g_hwndUpdate);
  446. #endif
  447. SHCoUninitialize(pgti->hrOle);
  448. if (pgti)
  449. LocalFree(pgti);
  450. SetWindowLongPtr(hDlg, DWLP_USER, (LONG_PTR)NULL); // make sure we don't re-enter
  451. break;
  452. }
  453. return FALSE;
  454. }
  455. ////////////////////////////////////////////////////////
  456. //
  457. // helper functions
  458. //
  459. ////////////////////////////////////////////////////////
  460. VOID SetDaysToKeep(DWORD dwDays)
  461. {
  462. HKEY hk;
  463. DWORD dwDisp;
  464. DWORD Error = RegCreateKeyEx(
  465. HKEY_CURRENT_USER,
  466. REGSTR_PATH_URLHISTORY,
  467. 0, NULL, 0,
  468. KEY_WRITE,
  469. NULL,
  470. &hk,
  471. &dwDisp);
  472. if(ERROR_SUCCESS != Error)
  473. {
  474. ASSERT(FALSE);
  475. return;
  476. }
  477. Error = RegSetValueEx(
  478. hk,
  479. REGSTR_VAL_DAYSTOKEEP,
  480. 0,
  481. REG_DWORD,
  482. (LPBYTE) &dwDays,
  483. sizeof(dwDays));
  484. ASSERT(ERROR_SUCCESS == Error);
  485. RegCloseKey(hk);
  486. return;
  487. }
  488. static DWORD GetDaysToKeep(VOID)
  489. {
  490. HKEY hk;
  491. DWORD cbDays = sizeof(DWORD);
  492. DWORD dwDays = DEFAULT_DAYS_TO_KEEP;
  493. DWORD Error = RegOpenKeyEx(
  494. HKEY_CURRENT_USER,
  495. REGSTR_PATH_URLHISTORY,
  496. 0,
  497. KEY_READ,
  498. &hk);
  499. if(Error)
  500. {
  501. Error = RegOpenKeyEx(
  502. HKEY_LOCAL_MACHINE,
  503. REGSTR_PATH_URLHISTORY,
  504. 0,
  505. KEY_READ,
  506. &hk);
  507. }
  508. if(!Error)
  509. {
  510. Error = RegQueryValueEx(
  511. hk,
  512. REGSTR_VAL_DAYSTOKEEP,
  513. 0,
  514. NULL,
  515. (LPBYTE) &dwDays,
  516. &cbDays);
  517. RegCloseKey(hk);
  518. }
  519. return dwDays;
  520. }
  521. typedef HRESULT (* PCOINIT) (LPVOID);
  522. typedef VOID (* PCOUNINIT) (VOID);
  523. typedef VOID (* PCOMEMFREE) (LPVOID);
  524. typedef HRESULT (* PCOCREINST) (REFCLSID, LPUNKNOWN, DWORD, REFIID, LPVOID * );
  525. HMODULE hOLE32 = NULL;
  526. PCOINIT pCoInitialize = NULL;
  527. PCOUNINIT pCoUninitialize = NULL;
  528. PCOMEMFREE pCoTaskMemFree = NULL;
  529. PCOCREINST pCoCreateInstance = NULL;
  530. BOOL _StartOLE32()
  531. {
  532. if (!hOLE32)
  533. hOLE32 = LoadLibrary(TEXT("OLE32.DLL"));
  534. if(!hOLE32)
  535. return FALSE;
  536. pCoInitialize = (PCOINIT) GetProcAddress(hOLE32, "CoInitialize");
  537. pCoUninitialize = (PCOUNINIT) GetProcAddress(hOLE32, "CoUninitialize");
  538. pCoTaskMemFree = (PCOMEMFREE) GetProcAddress(hOLE32, "CoTaskMemFree");
  539. pCoCreateInstance = (PCOCREINST) GetProcAddress(hOLE32, "CoCreateInstance");
  540. if(!pCoInitialize || !pCoUninitialize || !pCoTaskMemFree || !pCoCreateInstance)
  541. return FALSE;
  542. return TRUE;
  543. }
  544. void EmptyHistory(LPGENERALTABINFO pgti)
  545. {
  546. HRESULT hr = S_OK;
  547. IUrlHistoryStg2 *piuhs = NULL;
  548. #ifdef UNIX
  549. LONG lResult;
  550. HKEY hkSubKey;
  551. DWORD dwIndex;
  552. TCHAR szSubKeyName[MAX_PATH + 1];
  553. DWORD cchSubKeyName = ARRAYSIZE(szSubKeyName);
  554. TCHAR szClass[MAX_PATH];
  555. DWORD cbClass = ARRAYSIZE(szClass);
  556. /* v-sriran: 12/18/97
  557. * In shdocvw/aclmru.cpp, we keep m_hKey as a handle to the key TypedURLs.
  558. * After deleting history, if somebody types something in the address bar,
  559. * we create the key again. So, here we are just deleting the contents of
  560. * the key TypedURLs and not the key itself.
  561. */
  562. /* Open the subkey so we can enumerate any children */
  563. lResult = RegOpenKeyEx(HKEY_CURRENT_USER,
  564. TEXT("Software\\Microsoft\\Internet Explorer\\TypedURLs"),
  565. 0,
  566. KEY_ALL_ACCESS,
  567. &hkSubKey);
  568. if (ERROR_SUCCESS == lResult)
  569. {
  570. /* I can't just call RegEnumKey with an ever-increasing index, because */
  571. /* I'm deleting the subkeys as I go, which alters the indices of the */
  572. /* remaining subkeys in an implementation-dependent way. In order to */
  573. /* be safe, I have to count backwards while deleting the subkeys. */
  574. /* Find out how many subkeys there are */
  575. lResult = RegQueryInfoKey(hkSubKey,
  576. szClass,
  577. &cbClass,
  578. NULL,
  579. &dwIndex, /* The # of subkeys -- all we need */
  580. NULL,
  581. NULL,
  582. NULL,
  583. NULL,
  584. NULL,
  585. NULL,
  586. NULL);
  587. if (ERROR_SUCCESS == lResult) {
  588. /* dwIndex is now the count of subkeys, but it needs to be */
  589. /* zero-based for RegEnumKey, so I'll pre-decrement, rather */
  590. /* than post-decrement. */
  591. while (ERROR_SUCCESS == RegEnumKey(hkSubKey, --dwIndex, szSubKeyName, cchSubKeyName))
  592. {
  593. RegDeleteKey(hkSubKey, szSubKeyName);
  594. }
  595. }
  596. RegCloseKey(hkSubKey);
  597. }
  598. #else
  599. // Warning : if you ever have subkeys - this will fail on NT
  600. RegDeleteKey(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Internet Explorer\\TypedURLs"));
  601. #endif
  602. // Warning : if you ever have subkeys - this will fail on NT
  603. RegDeleteKey(HKEY_CURRENT_USER, TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU"));
  604. // this broadcast will nuke the address bars
  605. SendBroadcastMessage(WM_SETTINGCHANGE, 0, (LPARAM)TEXT("Software\\Microsoft\\Internet Explorer\\TypedURLs"));
  606. SendBroadcastMessage(WM_SETTINGCHANGE, 0, (LPARAM)TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU"));
  607. //
  608. // As requested (bug 60089) we remove these reg values when history is
  609. // cleared. This will reset the encoding menu UI to the defaults.
  610. //
  611. HKEY hkeyInternational = NULL;
  612. if (ERROR_SUCCESS ==
  613. RegOpenKeyEx(
  614. HKEY_CURRENT_USER,
  615. REGSTR_PATH_INTERNATIONAL,
  616. 0,
  617. KEY_WRITE,
  618. &hkeyInternational))
  619. {
  620. ASSERT(hkeyInternational);
  621. RegDeleteValue(hkeyInternational, TEXT("CpCache"));
  622. RegDeleteValue(hkeyInternational, TEXT("CNum_CpCache"));
  623. RegCloseKey(hkeyInternational);
  624. }
  625. // we will enumerate and kill each entry. <gryn>
  626. // this way we only kill peruser
  627. if (FAILED(pgti->hrOle))
  628. return;
  629. hr = SHCoCreateInstance(NULL, &CLSID_CUrlHistory, NULL, IID_IUrlHistoryStg2, (LPVOID *)&piuhs);
  630. if (SUCCEEDED(hr))
  631. piuhs->ClearHistory();
  632. else
  633. AssertMsg(FALSE, TEXT("Couldn't create CLSID_CUrlHistory object!"));
  634. SAFERELEASE(piuhs);
  635. }
  636. #define HISTORY 2
  637. BOOL GetHistoryFolderPath(LPTSTR pszPath)
  638. {
  639. INTERNET_CACHE_CONFIG_INFOA cci;
  640. cci.dwContainer = HISTORY;
  641. if (GetUrlCacheConfigInfoA(&cci, NULL, CACHE_CONFIG_DISK_CACHE_PATHS_FC))
  642. {
  643. #ifdef UNICODE
  644. SHAnsiToUnicode(cci.CachePath, pszPath, MAX_PATH);
  645. #else
  646. StrCpyN(pszPath, cci.CachePath, MAX_PATH);
  647. #endif
  648. return TRUE;
  649. }
  650. return FALSE;
  651. }
  652. void SetandSelectText(LPGENERALTABINFO pgti, HWND hwnd, LPTSTR psz)
  653. {
  654. pgti->fInternalChange = TRUE;
  655. SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM)psz);
  656. Edit_SetSel(hwnd, 0, 0); // makesure everything is scrolled over first
  657. Edit_SetSel(hwnd, 0, -1); // select everything
  658. pgti->fInternalChange = FALSE;
  659. }
  660. void GetDefaultStartPage(LPGENERALTABINFO pgti)
  661. {
  662. #ifdef UNICODE
  663. CHAR szPath[MAX_PATH];
  664. CHAR szValue[MAX_PATH];
  665. CHAR szURL[INTERNET_MAX_URL_LENGTH];
  666. SHUnicodeToAnsi(REGSTR_PATH_MAIN,szPath,ARRAYSIZE(szPath));
  667. SHUnicodeToAnsi(szDefURLValueNames,szValue,ARRAYSIZE(szValue));
  668. URLSubRegQueryA(szPath,
  669. szValue,
  670. TRUE,
  671. szURL,
  672. ARRAYSIZE(pgti->szStartPageURL),
  673. URLSUB_ALL);
  674. SHAnsiToUnicode(szURL,pgti->szStartPageURL,ARRAYSIZE(pgti->szStartPageURL));
  675. #else
  676. URLSubRegQueryA(REGSTR_PATH_MAIN,
  677. szDefURLValueNames,
  678. TRUE,
  679. pgti->szStartPageURL,
  680. ARRAYSIZE(pgti->szStartPageURL),
  681. URLSUB_ALL);
  682. #endif
  683. }
  684. HRESULT _GetStdLocation(LPTSTR pszPath, DWORD cbPathSize, UINT id)
  685. {
  686. HRESULT hres = E_FAIL;
  687. LPCTSTR pszName;
  688. switch(id) {
  689. case IDS_STARTPAGE:
  690. pszName = REGSTR_VAL_STARTPAGE;
  691. break;
  692. case IDS_SEARCHPAGE:
  693. pszName = REGSTR_VAL_SEARCHPAGE;
  694. break;
  695. #if 0
  696. case IDM_GOLOCALPAGE:
  697. pszName = REGSTR_VAL_LOCALPAGE;
  698. break;
  699. #endif
  700. default:
  701. return E_INVALIDARG;
  702. }
  703. #ifdef UNICODE
  704. CHAR szPath[MAX_PATH];
  705. CHAR szValue[MAX_PATH];
  706. CHAR szURL[INTERNET_MAX_URL_LENGTH];
  707. SHUnicodeToAnsi(REGSTR_PATH_MAIN,szPath,ARRAYSIZE(szPath));
  708. SHUnicodeToAnsi(pszName,szValue,ARRAYSIZE(szValue));
  709. if (SUCCEEDED(hres = URLSubRegQueryA(szPath, szValue, TRUE,
  710. szURL, ARRAYSIZE(szURL), URLSUB_ALL)))
  711. #else
  712. TCHAR szPath[MAX_URL_STRING];
  713. if (SUCCEEDED(hres = URLSubRegQueryA(REGSTR_PATH_MAIN, pszName, TRUE,
  714. szPath, ARRAYSIZE(szPath), URLSUB_ALL)))
  715. #endif
  716. {
  717. #ifdef UNICODE
  718. SHAnsiToUnicode(szURL,pszPath,cbPathSize);
  719. #else
  720. StrCpyN(pszPath, szPath, cbPathSize);
  721. #endif
  722. }
  723. return hres;
  724. }
  725. HRESULT _SetStdLocation(LPTSTR szPath, UINT id)
  726. {
  727. HRESULT hres = E_FAIL;
  728. HKEY hkey;
  729. TCHAR szPage[MAX_URL_STRING];
  730. TCHAR szNewPage[MAX_URL_STRING];
  731. DWORD cchNewPage = ARRAYSIZE(szNewPage);
  732. BOOL bSearch = FALSE;
  733. // FEATURE: Share this code!!!
  734. // This is Internet Explorer Specific
  735. _GetStdLocation(szPage, ARRAYSIZE(szPage), IDS_STARTPAGE);
  736. if ( ParseURLFromOutsideSource(szPath, szNewPage, &cchNewPage, &bSearch) &&
  737. (StrCmp(szPage, szNewPage) != 0) )
  738. {
  739. if (RegOpenKeyEx(HKEY_CURRENT_USER,
  740. REGSTR_PATH_MAIN,
  741. 0,
  742. KEY_WRITE,
  743. &hkey)==ERROR_SUCCESS)
  744. {
  745. DWORD cbSize = (lstrlen(szNewPage)+1)*sizeof(TCHAR);
  746. if (RegSetValueEx(hkey,
  747. REGSTR_VAL_STARTPAGE,
  748. 0,
  749. REG_SZ,
  750. (LPBYTE)szNewPage, cbSize)==ERROR_SUCCESS)
  751. {
  752. hres = S_OK;
  753. }
  754. RegCloseKey(hkey);
  755. }
  756. }
  757. return hres;
  758. }