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.

515 lines
14 KiB

  1. /*
  2. * ie4 - IE4 settings
  3. */
  4. #include "tweakui.h"
  5. #include <lmcons.h>
  6. #include <lmjoin.h>
  7. #include <lmerr.h>
  8. #pragma BEGIN_CONST_DATA
  9. KL const c_klSingleClick = {&g_hkCUSMWCV, c_tszExplorerAdvanced,
  10. c_tszUseDoubleClickTimer };
  11. const static DWORD CODESEG rgdwHelp[] = {
  12. IDC_SETTINGSGROUP, IDH_GROUP,
  13. IDC_LISTVIEW, IDH_IE4LV,
  14. 0, 0,
  15. };
  16. #pragma END_CONST_DATA
  17. /*****************************************************************************
  18. *
  19. * IE4_GetDword
  20. *
  21. * Read a DWORD somewhere.
  22. *
  23. * Always returns exactly 0 or 1.
  24. *
  25. *****************************************************************************/
  26. BOOL PASCAL
  27. IE4_GetDword(LPARAM lParam, LPVOID pvRef)
  28. {
  29. PKL pkl = (PKL)lParam;
  30. return GetDwordPkl(pkl, TRUE) != 0;
  31. }
  32. /*****************************************************************************
  33. *
  34. * IE4_SetDword
  35. *
  36. * Save a DWORD somewhere.
  37. *
  38. * Always given exactly 0 or 1.
  39. *
  40. *****************************************************************************/
  41. BOOL PASCAL
  42. IE4_SetDword(BOOL f, LPARAM lParam, LPVOID pvRef)
  43. {
  44. PKL pkl = (PKL)lParam;
  45. PBOOL pf = (PBOOL)pvRef;
  46. if (pf) {
  47. *pf = TRUE;
  48. }
  49. return SetDwordPkl(pkl, f);
  50. }
  51. /*****************************************************************************
  52. *
  53. * IE4_GetRest
  54. *
  55. * Read a restriction. The first character of the restriction is
  56. * `+' if it is positive sense. All restrictions default to 0.
  57. *
  58. * Always returns exactly 0 or 1.
  59. *
  60. *****************************************************************************/
  61. BOOL PASCAL
  62. IE4_GetRest(LPARAM lParam, LPVOID pvRef)
  63. {
  64. LPCTSTR ptszRest = (LPCTSTR)lParam;
  65. if (ptszRest[0] == TEXT('+')) {
  66. return !GetRestriction(ptszRest+1);
  67. } else {
  68. return GetRestriction(ptszRest);
  69. }
  70. }
  71. /*****************************************************************************
  72. *
  73. * IE4_GetRest4
  74. *
  75. * Just like IE4_GetRest, except fails if shell version 5 or better.
  76. *
  77. *****************************************************************************/
  78. BOOL PASCAL
  79. IE4_GetRest4(LPARAM lParam, LPVOID pvRef)
  80. {
  81. if (g_fShell5) {
  82. return -1;
  83. } else {
  84. return IE4_GetRest(lParam, pvRef);
  85. }
  86. }
  87. /*****************************************************************************
  88. *
  89. * IE4_GetRest5
  90. *
  91. * Just like IE4_GetRest, except requires shell version 5 or better.
  92. *
  93. *****************************************************************************/
  94. BOOL PASCAL
  95. IE4_GetRest5(LPARAM lParam, LPVOID pvRef)
  96. {
  97. if (g_fShell5) {
  98. return IE4_GetRest(lParam, pvRef);
  99. } else {
  100. return -1;
  101. }
  102. }
  103. /*****************************************************************************
  104. *
  105. * IE4_GetRest55
  106. *
  107. * Just like IE4_GetRest, except requires shell version 5.5 or better.
  108. *
  109. *****************************************************************************/
  110. BOOL PASCAL
  111. IE4_GetRest55(LPARAM lParam, LPVOID pvRef)
  112. {
  113. if (g_fShell55) {
  114. return IE4_GetRest(lParam, pvRef);
  115. } else {
  116. return -1;
  117. }
  118. }
  119. /*****************************************************************************
  120. *
  121. * HasComputersNearMe
  122. *
  123. * See if "Computers Near Me" is enabled.
  124. *
  125. * Shell 4 or lower: Disabled.
  126. *
  127. * Shell 5 on 9x: Enabled.
  128. *
  129. * Shell 5 on NT: Only if you are joined to a workgroup.
  130. *
  131. *****************************************************************************/
  132. typedef NET_API_STATUS (CALLBACK *NETGETJOININFORMATION)(LPCWSTR, LPWSTR*, PNETSETUP_JOIN_STATUS);
  133. typedef NET_API_STATUS (CALLBACK *NETAPIBUFFERFREE)(LPVOID);
  134. BOOL s_bHasComputersNearMe = -1;
  135. BOOL PASCAL
  136. HasComputersNearMe(void)
  137. {
  138. if (!g_fShell5) {
  139. return FALSE;
  140. }
  141. if (!g_fNT) {
  142. return TRUE;
  143. }
  144. if (s_bHasComputersNearMe < 0) {
  145. NETSETUP_JOIN_STATUS nsjs = NetSetupUnknownStatus;
  146. HINSTANCE hinst = LoadLibrary("netapi32.dll");
  147. if (hinst) {
  148. NETGETJOININFORMATION _NetGetJoinInformation =
  149. (NETGETJOININFORMATION)GetProcAddress(hinst, "NetGetJoinInformation");
  150. NETAPIBUFFERFREE _NetApiBufferFree =
  151. (NETAPIBUFFERFREE)GetProcAddress(hinst, "NetApiBufferFree");
  152. if (_NetGetJoinInformation && _NetApiBufferFree) {
  153. LPWSTR pszDomain;
  154. if (_NetGetJoinInformation(NULL, &pszDomain, &nsjs) == NERR_Success) {
  155. _NetApiBufferFree(pszDomain);
  156. }
  157. }
  158. FreeLibrary(hinst);
  159. }
  160. s_bHasComputersNearMe = (nsjs == NetSetupWorkgroupName);
  161. }
  162. return s_bHasComputersNearMe;
  163. }
  164. /*****************************************************************************
  165. *
  166. * IE4_GetRestCNM
  167. *
  168. * Special function just for "Computers Near Me".
  169. *
  170. *****************************************************************************/
  171. BOOL PASCAL
  172. IE4_GetRestCNM(LPARAM lParam, LPVOID pvRef)
  173. {
  174. if (HasComputersNearMe()) {
  175. return IE4_GetRest(lParam, pvRef);
  176. } else {
  177. return -1;
  178. }
  179. }
  180. /*****************************************************************************
  181. *
  182. * IE4_SetRest
  183. *
  184. * Set the new restriction setting.
  185. *
  186. * The first character of the restriction is
  187. * `+' if it is positive sense.
  188. *
  189. *****************************************************************************/
  190. BOOL PASCAL
  191. IE4_SetRest(BOOL f, LPARAM lParam, LPVOID pvRef)
  192. {
  193. LPCTSTR ptszRest = (LPCTSTR)lParam;
  194. PBOOL pf = (PBOOL)pvRef;
  195. if (pf) {
  196. *pf = ptszRest ? TRUE : FALSE;
  197. }
  198. if (ptszRest[0] == TEXT('+')) {
  199. f = !f;
  200. ptszRest++;
  201. }
  202. return SetRestriction(ptszRest, f);
  203. }
  204. /*****************************************************************************
  205. *
  206. * IE4_GetLinksFolderName
  207. *
  208. *****************************************************************************/
  209. KL const c_klLinksFolder = {&g_hkCUSMIE, TEXT("Toolbar"), TEXT("LinksFolderName") };
  210. KL const c_klLinksFolder2= {&g_hkLMSMWCV, NULL, TEXT("LinksFolderName") };
  211. BOOL PASCAL
  212. IE4_GetLinksFolderName(LPTSTR pszBuf, UINT cchBuf)
  213. {
  214. PIDL pidl;
  215. BOOL fRc = FALSE;
  216. if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl))) {
  217. if (SHGetPathFromIDList(pidl, pszBuf)) {
  218. /*
  219. * Find the name of the links folder underneath Favorites.
  220. */
  221. TCHAR szLinks[MAX_PATH];
  222. if (!GetStrPkl(szLinks, sizeof(szLinks), &c_klLinksFolder) &&
  223. !GetStrPkl(szLinks, sizeof(szLinks), &c_klLinksFolder2)) {
  224. lstrcpy(szLinks, TEXT("Links"));
  225. }
  226. Path_Append(pszBuf, szLinks);
  227. fRc = TRUE;
  228. }
  229. Ole_Free(pidl);
  230. }
  231. return fRc;
  232. }
  233. /*****************************************************************************
  234. *
  235. * IE4_GetFavLink
  236. *
  237. * Say whether the Favorites\Links directory is hidden.
  238. *
  239. * -1 = No links directory at all
  240. * 0 = Links is hidden
  241. * 1 = Links is visible
  242. *
  243. *****************************************************************************/
  244. BOOL PASCAL
  245. IE4_GetFavLink(LPARAM lParam, LPVOID pvRef)
  246. {
  247. BOOL fRc = -1;
  248. TCHAR szFavLink[MAX_PATH];
  249. if (IE4_GetLinksFolderName(szFavLink, cA(szFavLink))) {
  250. DWORD dwAttrib = GetFileAttributes(szFavLink);
  251. if (dwAttrib != 0xFFFFFFFF) {
  252. fRc = !(dwAttrib & FILE_ATTRIBUTE_HIDDEN);
  253. }
  254. }
  255. return fRc;
  256. }
  257. /*****************************************************************************
  258. *
  259. * IE4_SetFavLink
  260. *
  261. * 0 = Make links hidden
  262. * 1 = Make links visible
  263. *
  264. *****************************************************************************/
  265. BOOL PASCAL
  266. IE4_SetFavLink(BOOL f, LPARAM lParam, LPVOID pvRef)
  267. {
  268. BOOL fRc = FALSE;
  269. PBOOL pf = (PBOOL)pvRef;
  270. TCHAR szFavLink[MAX_PATH];
  271. if (IE4_GetLinksFolderName(szFavLink, cA(szFavLink))) {
  272. DWORD dwAttrib = GetFileAttributes(szFavLink);
  273. if (dwAttrib != 0xFFFFFFFF) {
  274. dwAttrib &= ~FILE_ATTRIBUTE_HIDDEN;
  275. if (!f)
  276. dwAttrib |= FILE_ATTRIBUTE_HIDDEN;
  277. if (SetFileAttributes(szFavLink, dwAttrib)) {
  278. fRc = TRUE;
  279. *pf = TRUE;
  280. }
  281. }
  282. }
  283. return fRc;
  284. }
  285. /*
  286. * Note that this needs to be in sync with the IDS_IE4 strings.
  287. */
  288. CHECKLISTITEM c_rgcliIE4[] = {
  289. #ifdef NOINTERNET_WORKS
  290. // WARNING! If you turn this on, make sure to renumber the IDS_IE4
  291. // strings and fix IE4_OnWhatsThis
  292. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszNoInternetIcon, },
  293. #endif
  294. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszNoRecentDocsHistory, },
  295. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszNoRecentDocsMenu, },
  296. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszNoActiveDesktop, },
  297. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszNoActiveDesktopChanges,},
  298. /*
  299. * Sigh. Shell5 changed the restriction key for NoFavoritesMenu.
  300. * Fortunately, it's in the UI so I don't need to expose it any more.
  301. */
  302. { IE4_GetRest4, IE4_SetRest, (LPARAM)c_tszNoFavoritesMenu, },
  303. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszClearRecentDocsOnExit, },
  304. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszClassicShell, },
  305. { IE4_GetRest, IE4_SetRest, (LPARAM)c_tszNoLogoff, },
  306. { IE4_GetDword, IE4_SetDword, (LPARAM)&c_klSingleClick, },
  307. { IE4_GetFavLink, IE4_SetFavLink, 0, },
  308. { IE4_GetRest5, IE4_SetRest, (LPARAM)TEXT("NoSMHelp"), },
  309. { IE4_GetRest5, IE4_SetRest, (LPARAM)TEXT("NoControlPanel") },
  310. { IE4_GetRest5, IE4_SetRest, (LPARAM)TEXT("NoNetworkConnections")},
  311. { IE4_GetRest5, IE4_SetRest, (LPARAM)TEXT("NoWinKeys") },
  312. { IE4_GetRestCNM,IE4_SetRest, (LPARAM)TEXT("NoComputersNearMe") },
  313. { IE4_GetRest5, IE4_SetRest, (LPARAM)TEXT("NoSMMyDocs") },
  314. { IE4_GetRest55,IE4_SetRest, (LPARAM)TEXT("NoSMMyPictures") },
  315. };
  316. /*****************************************************************************
  317. *
  318. * IE4_OnWhatsThis
  319. *
  320. *****************************************************************************/
  321. void PASCAL
  322. IE4_OnWhatsThis(HWND hwnd, int iItem)
  323. {
  324. LV_ITEM lvi;
  325. Misc_LV_GetItemInfo(hwnd, &lvi, iItem, LVIF_PARAM);
  326. WinHelp(hwnd, c_tszMyHelp, HELP_CONTEXTPOPUP,
  327. IDH_ADDTODOCSMENU + lvi.lParam);
  328. }
  329. /*****************************************************************************
  330. *
  331. * IE4_OnCommand
  332. *
  333. * Ooh, we got a command.
  334. *
  335. *****************************************************************************/
  336. void PASCAL
  337. IE4_OnCommand(HWND hdlg, int id, UINT codeNotify)
  338. {
  339. }
  340. /*****************************************************************************
  341. *
  342. * IE4_OnInitDialog
  343. *
  344. * Initialize the listview with the current restrictions.
  345. *
  346. *****************************************************************************/
  347. BOOL PASCAL
  348. IE4_OnInitDialog(HWND hwnd)
  349. {
  350. #if 0
  351. HWND hdlg = GetParent(hwnd);
  352. TCHAR tsz[MAX_PATH];
  353. int dids;
  354. for (dids = 0; dids < cA(c_rgrest); dids++) {
  355. BOOL fState;
  356. #ifdef NOINTERNET_WORKS
  357. LoadString(hinstCur, IDS_IE4+dids, tsz, cA(tsz));
  358. #else
  359. LoadString(hinstCur, IDS_IE4+1+dids, tsz, cA(tsz));
  360. #endif
  361. fState = GetRestriction(c_rgrest[dids].ptsz);
  362. LV_AddItem(hwnd, dids, tsz, -1, fState);
  363. }
  364. #endif
  365. #ifdef NOINTERNET_WORKS
  366. Checklist_OnInitDialog(hwnd, c_rgcliIE4, cA(c_rgcliIE4), IDS_IE4, 0);
  367. #else
  368. Checklist_OnInitDialog(hwnd, c_rgcliIE4, cA(c_rgcliIE4), IDS_IE4+1, 0);
  369. #endif
  370. return 1;
  371. }
  372. /*****************************************************************************
  373. *
  374. * IE4_OnApply
  375. *
  376. *****************************************************************************/
  377. void PASCAL
  378. IE4_OnApply(HWND hdlg)
  379. {
  380. BOOL fChanged = FALSE;
  381. Checklist_OnApply(hdlg, c_rgcliIE4, &fChanged, FALSE);
  382. if (fChanged) {
  383. PIDL pidl;
  384. /*
  385. * Tell the shell that we changed the policies.
  386. */
  387. SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0,
  388. (LPARAM)c_tszIE4RegKeyChange);
  389. /*
  390. * Tickle the Start Menu folder to force the Start Menu
  391. * to rebuild with the new policies in effect.
  392. */
  393. if (SUCCEEDED(SHGetSpecialFolderLocation(hdlg,
  394. CSIDL_STARTMENU, &pidl))) {
  395. SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_IDLIST, pidl, 0);
  396. Ole_Free(pidl);
  397. }
  398. }
  399. }
  400. /*****************************************************************************
  401. *
  402. * Oh yeah, we need this too.
  403. *
  404. *****************************************************************************/
  405. #pragma BEGIN_CONST_DATA
  406. LVCI lvciIE4[] = {
  407. { IDC_WHATSTHIS, IE4_OnWhatsThis },
  408. { 0, 0 },
  409. };
  410. LVV lvvIE4 = {
  411. IE4_OnCommand,
  412. 0, /* IE4_OnInitContextMenu */
  413. 0, /* IE4_Dirtify */
  414. 0, /* IE4_GetIcon */
  415. IE4_OnInitDialog,
  416. IE4_OnApply,
  417. 0, /* IE4_OnDestroy */
  418. 0, /* IE4_OnSelChange */
  419. 6, /* iMenu */
  420. rgdwHelp,
  421. 0, /* Double-click action */
  422. lvvflCanCheck, /* We need check boxes */
  423. lvciIE4,
  424. };
  425. #pragma END_CONST_DATA
  426. /*****************************************************************************
  427. *
  428. * Our window procedure.
  429. *
  430. *****************************************************************************/
  431. INT_PTR EXPORT
  432. IE4_DlgProc(HWND hdlg, UINT wm, WPARAM wParam, LPARAM lParam)
  433. {
  434. return LV_DlgProc(&lvvIE4, hdlg, wm, wParam, lParam);
  435. }