Leaked source code of windows server 2003
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.

2020 lines
65 KiB

  1. #include "stdafx.h"
  2. #pragma hdrstop
  3. #define _BROWSEUI_ // Make functions exported from browseui as stdapi (as they are delay loaded)
  4. #include "iethread.h"
  5. #include "browseui.h"
  6. #include "securent.h"
  7. #include <cfgmgr32.h> // MAX_GUID_STRING_LEN
  8. static void EmptyListview(IActiveDesktop * pActiveDesktop, HWND hwndLV);
  9. #define DXA_GROWTH_CONST 10
  10. #define COMP_CHECKED 0x00002000
  11. #define COMP_UNCHECKED 0x00001000
  12. #define GALRET_NO 0x00000001
  13. #define GALRET_NEVER 0x00000002
  14. #define CCompPropSheetPage CCompPropSheetPage
  15. const static DWORD aDesktopItemsHelpIDs[] = { // Context Help IDs
  16. IDC_COMP_DESKTOPWEBPAGES_TITLE1, IDH_DISPLAY_WEB_ACTIVEDESKTOP_LIST,
  17. IDC_COMP_LIST, IDH_DISPLAY_WEB_ACTIVEDESKTOP_LIST,
  18. IDC_COMP_NEW, IDH_DISPLAY_WEB_NEW_BUTTON,
  19. IDC_COMP_DELETE, IDH_DISPLAY_WEB_DELETE_BUTTON,
  20. IDC_COMP_PROPERTIES, IDH_DISPLAY_WEB_PROPERTIES_BUTTON,
  21. IDC_COMP_SYNCHRONIZE,IDH_DISPLAY_WEB_SYNCHRONIZE_BUTTON,
  22. IDC_COMP_DESKTOPICONS_GROUP, IDH_DESKTOPITEMS_DESKTOPICONS_GROUP,
  23. IDC_DESKTOP_ICON_MYDOCS, IDH_DESKTOPITEMS_DESKTOPICONS_GROUP,
  24. IDC_DESKTOP_ICON_MYCOMP, IDH_DESKTOPITEMS_DESKTOPICONS_GROUP,
  25. IDC_DESKTOP_ICON_MYNET, IDH_DESKTOPITEMS_DESKTOPICONS_GROUP,
  26. IDC_DESKTOP_ICON_IE, IDH_DESKTOPITEMS_DESKTOPICONS_GROUP,
  27. IDC_COMP_CHANGEDESKTOPICON_LABEL, IDH_DESKTOPITEMS_ICONS,
  28. IDC_DESKTOP_ICONS, IDH_DESKTOPITEMS_ICONS, // List of icons
  29. IDC_CHANGEICON2, IDH_DESKTOPITEMS_CHANGEICON2, // Change Icon Button
  30. IDC_ICONDEFAULT, IDH_DESKTOPITEMS_ICONDEFAULT, // Default Icon Button
  31. IDC_COMP_DESKTOPWEBPAGES_LABEL, IDH_DISPLAY_WEB_ACTIVEDESKTOP_LIST,
  32. IDC_DESKCLNR_CHECK, IDH_DESKTOPITEMS_DESKCLNR_CHECK,
  33. IDC_DESKCLNR_MOVEUNUSED, IDH_DESKTOPITEMS_DESKCLNR_CHECK,
  34. IDC_DESKCLNR_RUNWIZARD, IDH_DESKTOPITEMS_DESKCLNR_RUNNOW,
  35. IDC_COMP_DESKTOPWEBPAGES_CHECK, IDH_DESKTOPITEMS_LOCKDESKITEMS_CHECK,
  36. IDC_COMP_DESKTOPWEBPAGES_TITLE2, IDH_DESKTOPITEMS_LOCKDESKITEMS_CHECK,
  37. 0, 0
  38. };
  39. #define SZ_HELPFILE_DESKTOPITEMS TEXT("display.hlp")
  40. // registry paths defined in shell\applet\cleanup\fldrclnr\cleanupwiz.h
  41. #define REGSTR_DESKTOP_CLEANUP TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Desktop\\CleanupWiz")
  42. #define REGSTR_VAL_DONTRUN TEXT("NoRun")
  43. extern int g_iRunDesktopCleanup;
  44. typedef struct
  45. {
  46. WCHAR wszURL[INTERNET_MAX_URL_LENGTH];
  47. SUBSCRIPTIONINFO si;
  48. } BACKUPSUBSCRIPTION;
  49. const LPCWSTR s_Icons[] =
  50. {
  51. L"CLSID\\{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\DefaultIcon:DefaultValue", // My Computer
  52. L"CLSID\\{450D8FBA-AD25-11D0-98A8-0800361B1103}\\DefaultIcon:DefaultValue", // My Documents
  53. L"CLSID\\{208D2C60-3AEA-1069-A2D7-08002B30309D}\\DefaultIcon:DefaultValue", // My Network Places
  54. L"CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon:full", // Recycle Bin (Full)
  55. L"CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\DefaultIcon:empty", // Recycle Bin (Empty)
  56. };
  57. IActiveDesktop * g_pActiveDeskAdv = NULL; // We need to keep a different copy than g_pActiveDesk
  58. extern DWORD g_dwApplyFlags;
  59. // Extract Icon from a file in proper Hi or Lo color for current system display
  60. //
  61. // from FrancisH on 6/22/95 with mods by TimBragg
  62. HRESULT ExtractPlusColorIcon(LPCTSTR szPath, int nIndex, HICON *phIcon, UINT uSizeLarge, UINT uSizeSmall)
  63. {
  64. IShellLink * psl;
  65. HRESULT hres;
  66. HICON hIcons[2]; // MUST! - provide for TWO return icons
  67. *phIcon = NULL;
  68. if (SUCCEEDED(hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellLink, &psl))))
  69. {
  70. if (SUCCEEDED(hres = psl->SetIconLocation(szPath, nIndex)))
  71. {
  72. IExtractIcon *pei;
  73. if (SUCCEEDED(hres = psl->QueryInterface(IID_PPV_ARG(IExtractIcon, &pei))))
  74. {
  75. if (SUCCEEDED(hres = pei->Extract(szPath, nIndex, &hIcons[0], &hIcons[1], (UINT)MAKEWPARAM((WORD)uSizeLarge, (WORD)uSizeSmall))))
  76. {
  77. DestroyIcon(hIcons[1]);
  78. *phIcon = hIcons[0]; // Return first icon to caller
  79. }
  80. pei->Release();
  81. }
  82. }
  83. psl->Release();
  84. }
  85. return hres;
  86. } // end ExtractPlusColorIcon()
  87. BOOL AreEditAndDisplaySchemesDifferent(IActiveDesktop * pActiveDesktop)
  88. {
  89. BOOL fAreDifferent = FALSE;
  90. IActiveDesktopP * piadp;
  91. if (SUCCEEDED(pActiveDesktop->QueryInterface(IID_PPV_ARG(IActiveDesktopP, &piadp))))
  92. {
  93. WCHAR wszEdit[MAX_PATH];
  94. WCHAR wszDisplay[MAX_PATH];
  95. DWORD dwcch = ARRAYSIZE(wszEdit);
  96. // If the edit scheme and display scheme are different, then we need to make
  97. // sure we force an update.
  98. if (SUCCEEDED(piadp->GetScheme(wszEdit, &dwcch, SCHEME_GLOBAL | SCHEME_EDIT)))
  99. {
  100. dwcch = ARRAYSIZE(wszDisplay);
  101. if (SUCCEEDED(piadp->GetScheme(wszDisplay, &dwcch, SCHEME_GLOBAL | SCHEME_DISPLAY)))
  102. {
  103. if (StrCmpW(wszDisplay, wszEdit))
  104. {
  105. fAreDifferent = TRUE;
  106. }
  107. }
  108. }
  109. piadp->Release();
  110. }
  111. return fAreDifferent;
  112. }
  113. HRESULT ActiveDesktop_CopyDesktopComponentsState(IN IActiveDesktop * pADSource, IN IActiveDesktop * pADDest)
  114. {
  115. int nCompCount;
  116. int nIndex;
  117. COMPONENT comp = {sizeof(comp)};
  118. IPropertyBag *iPropBag = NULL;
  119. if(SUCCEEDED(pADDest->QueryInterface(IID_PPV_ARG(IPropertyBag, &iPropBag))))
  120. {
  121. //Inform the AD object to ignore policies. Otherwise, the following Remove and AddDesktopItem
  122. //calls will generate error messages if those policies were in effect.
  123. SHPropertyBag_WriteBOOL(iPropBag, c_wszPropName_IgnorePolicies, TRUE);
  124. }
  125. // Remove the desktop components from g_pActiveDesk because they will be replaced
  126. // with the ones from g_pActiveDeskAdv.
  127. pADDest->GetDesktopItemCount(&nCompCount, 0);
  128. for (nIndex = (nCompCount - 1); nIndex >= 0; nIndex--)
  129. {
  130. if (SUCCEEDED(pADDest->GetDesktopItem(nIndex, &comp, 0)))
  131. {
  132. pADDest->RemoveDesktopItem(&comp, 0);
  133. }
  134. }
  135. // Now copy the Desktop Components from g_pActiveDeskAdv to g_pActiveDesk.
  136. pADSource->GetDesktopItemCount(&nCompCount, 0);
  137. for (nIndex = 0; nIndex < nCompCount; nIndex++)
  138. {
  139. if (SUCCEEDED(pADSource->GetDesktopItem(nIndex, &comp, 0)))
  140. {
  141. pADDest->AddDesktopItem(&comp, 0);
  142. }
  143. }
  144. if(iPropBag)
  145. {
  146. //We have removed and added all the desktop items. We are done manipulating the AD object.
  147. // Now, signal the AD object to reset the policies bit.
  148. SHPropertyBag_WriteBOOL(iPropBag, c_wszPropName_IgnorePolicies, FALSE);
  149. iPropBag->Release();
  150. }
  151. return S_OK;
  152. }
  153. HRESULT ActiveDesktop_CopyComponentOptionsState(IN IActiveDesktop * pADSource, IN IActiveDesktop * pADDest)
  154. {
  155. HRESULT hr;
  156. COMPONENTSOPT co;
  157. // Copy over the on or off state of ActiveDesktop
  158. co.dwSize = sizeof(COMPONENTSOPT);
  159. hr = pADSource->GetDesktopItemOptions(&co, 0);
  160. if (SUCCEEDED(hr))
  161. {
  162. hr = pADDest->SetDesktopItemOptions(&co, 0);
  163. }
  164. return hr;
  165. }
  166. // In ActiveDesktop_CopyState, we try to do as much as we can. If we fail, we keep going,
  167. // but we still have to return E_FAIL if any part of our work failed.
  168. HRESULT ActiveDesktop_CopyState(IN IActiveDesktop * pADSource, IN IActiveDesktop * pADDest)
  169. {
  170. HRESULT hr = S_OK;
  171. WCHAR szPath[MAX_PATH];
  172. WALLPAPEROPT wallPaperOtp = {0};
  173. // The Advanced page allowed the user to change the state. We need to merge
  174. // the state from g_pActiveDeskAdv back into g_pActiveDesk
  175. if (FAILED(ActiveDesktop_CopyDesktopComponentsState(pADSource, pADDest)))
  176. {
  177. hr = E_FAIL;
  178. }
  179. if (FAILED(ActiveDesktop_CopyComponentOptionsState(pADSource, pADDest)))
  180. {
  181. hr = E_FAIL;
  182. }
  183. if (FAILED(pADSource->GetWallpaper(szPath, ARRAYSIZE(szPath), 0)) ||
  184. FAILED(pADDest->SetWallpaper(szPath, 0)))
  185. {
  186. hr = E_FAIL;
  187. }
  188. if (FAILED(pADSource->GetPattern(szPath, ARRAYSIZE(szPath), 0)) ||
  189. FAILED(pADDest->SetPattern(szPath, 0)))
  190. {
  191. hr = E_FAIL;
  192. }
  193. wallPaperOtp.dwSize = sizeof(wallPaperOtp);
  194. if (FAILED(pADSource->GetWallpaperOptions(&wallPaperOtp, 0)) ||
  195. FAILED(pADDest->SetWallpaperOptions(&wallPaperOtp, 0)))
  196. {
  197. hr = E_FAIL;
  198. }
  199. return hr;
  200. }
  201. HRESULT MergeState()
  202. {
  203. // The Advanced page allowed the user to change the state. We need to merge
  204. // the state from g_pActiveDeskAdv back into g_pActiveDesk
  205. ActiveDesktop_CopyDesktopComponentsState(g_pActiveDeskAdv, g_pActiveDesk);
  206. // Copy over the on or off state of ActiveDesktop
  207. COMPONENTSOPT co;
  208. co.dwSize = sizeof(COMPONENTSOPT);
  209. g_pActiveDeskAdv->GetDesktopItemOptions(&co, 0);
  210. BOOL fActiveDesktop = co.fActiveDesktop;
  211. g_pActiveDesk->GetDesktopItemOptions(&co, 0);
  212. co.fActiveDesktop = fActiveDesktop; // Replace only this option.
  213. g_pActiveDesk->SetDesktopItemOptions(&co, 0);
  214. // If the edit scheme and display scheme are different, then we need to make
  215. // sure we force an update.
  216. if (AreEditAndDisplaySchemesDifferent(g_pActiveDeskAdv))
  217. {
  218. g_dwApplyFlags |= AD_APPLY_FORCE;
  219. }
  220. return S_OK;
  221. }
  222. HRESULT SHPropertyBag_ReadIcon(IN IPropertyBag * pAdvPage, IN BOOL fOldIcon, IN int nIndex, IN LPWSTR pszPath, IN DWORD cchSize, IN int * pnIcon)
  223. {
  224. HRESULT hr = E_INVALIDARG;
  225. if (nIndex < ARRAYSIZE(s_Icons))
  226. {
  227. WCHAR szPropName[MAX_URL_STRING];
  228. hr = StringCchCopy(szPropName, ARRAYSIZE(szPropName), s_Icons[nIndex]);
  229. if (SUCCEEDED(hr))
  230. {
  231. if (fOldIcon)
  232. {
  233. // Indicate we want the old icon
  234. LPWSTR pszToken = StrChrW(szPropName, L':');
  235. if (pszToken)
  236. {
  237. pszToken[0] = L';';
  238. }
  239. }
  240. hr = SHPropertyBag_ReadStr(pAdvPage, szPropName, pszPath, cchSize);
  241. if (SUCCEEDED(hr))
  242. {
  243. *pnIcon= PathParseIconLocation(pszPath);
  244. }
  245. }
  246. }
  247. return hr;
  248. }
  249. HRESULT SHPropertyBag_WriteIcon(IN IPropertyBag * pAdvPage, IN int nIndex, IN LPCWSTR pszPath, IN int nIcon)
  250. {
  251. HRESULT hr;
  252. if (nIndex >= ARRAYSIZE(s_Icons))
  253. {
  254. hr = E_INVALIDARG;
  255. }
  256. else
  257. {
  258. WCHAR szPathAndIcon[MAX_PATH];
  259. hr = StringCchPrintf(szPathAndIcon, ARRAYSIZE(szPathAndIcon), L"%s,%d", pszPath, nIcon);
  260. if (SUCCEEDED(hr))
  261. {
  262. hr = SHPropertyBag_WriteStr(pAdvPage, s_Icons[nIndex], szPathAndIcon);
  263. }
  264. }
  265. return hr;
  266. }
  267. HRESULT CCompPropSheetPage::_LoadIconState(IN IPropertyBag * pAdvPage)
  268. {
  269. HRESULT hr = S_OK;
  270. int nIndex;
  271. // Move the values to the base dialog
  272. for (nIndex = 0; SUCCEEDED(hr) && (nIndex < ARRAYSIZE(_IconData)); nIndex++)
  273. {
  274. hr = SHPropertyBag_ReadIcon(pAdvPage, TRUE, nIndex, _IconData[nIndex].szOldFile, ARRAYSIZE(_IconData[nIndex].szOldFile), &_IconData[nIndex].iOldIndex);
  275. if (SUCCEEDED(hr))
  276. {
  277. hr = SHPropertyBag_ReadIcon(pAdvPage, FALSE, nIndex, _IconData[nIndex].szNewFile, ARRAYSIZE(_IconData[nIndex].szNewFile), &_IconData[nIndex].iNewIndex);
  278. }
  279. }
  280. return hr;
  281. }
  282. HRESULT CCompPropSheetPage::_LoadDeskIconState(IN IPropertyBag * pAdvPage)
  283. {
  284. HRESULT hr = S_OK;
  285. // Copy the values from the base dialog
  286. for (int iStartPanel = 0; iStartPanel <= 1; iStartPanel++)
  287. {
  288. WCHAR wszPropName[MAX_GUID_STRING_LEN + 20];
  289. for (int nIndex = 0; SUCCEEDED(hr) && (nIndex < NUM_DESKICONS); nIndex++)
  290. {
  291. // set defaults in case we fail the printfs
  292. _afHideIcon[iStartPanel][nIndex] = FALSE;
  293. if (iStartPanel == 1)
  294. {
  295. _afDisableCheckBox[nIndex] = FALSE;
  296. }
  297. hr = StringCchPrintf(wszPropName, ARRAYSIZE(wszPropName), c_wszPropNameFormat, c_awszSP[iStartPanel], c_aDeskIconId[nIndex].pwszCLSID);
  298. if (SUCCEEDED(hr))
  299. {
  300. _afHideIcon[iStartPanel][nIndex] = SHPropertyBag_ReadBOOLDefRet(pAdvPage, wszPropName, FALSE);
  301. if(iStartPanel == 1)
  302. {
  303. hr = StringCchPrintf(wszPropName, ARRAYSIZE(wszPropName), c_wszPropNameFormat, POLICY_PREFIX, c_aDeskIconId[nIndex].pwszCLSID);
  304. if (SUCCEEDED(hr))
  305. {
  306. _afDisableCheckBox[nIndex] = SHPropertyBag_ReadBOOLDefRet(pAdvPage, wszPropName, FALSE);
  307. }
  308. }
  309. }
  310. }
  311. }
  312. return hr;
  313. }
  314. HRESULT CCompPropSheetPage::_MergeDeskIconState(IN IPropertyBag * pAdvPage)
  315. {
  316. HRESULT hr = S_OK;
  317. // Move the values to the base dialog
  318. for (int iStartPanel = 0; SUCCEEDED(hr) && iStartPanel <= 1; iStartPanel++)
  319. {
  320. WCHAR wszPropName[MAX_GUID_STRING_LEN + 20];
  321. for (int nIndex = 0; SUCCEEDED(hr) && (nIndex < NUM_DESKICONS); nIndex++)
  322. {
  323. hr = StringCchPrintf(wszPropName, ARRAYSIZE(wszPropName), c_wszPropNameFormat, c_awszSP[iStartPanel], c_aDeskIconId[nIndex].pwszCLSID);
  324. if (SUCCEEDED(hr))
  325. {
  326. // Check if any icons have changed.
  327. hr = SHPropertyBag_WriteBOOL(pAdvPage, wszPropName, _afHideIcon[iStartPanel][nIndex]);
  328. }
  329. }
  330. }
  331. return hr;
  332. }
  333. HRESULT CCompPropSheetPage::_MergeIconState(IN IPropertyBag * pAdvPage)
  334. {
  335. HRESULT hr = S_OK;
  336. BOOL fHasIconsChanged = FALSE;
  337. int nIndex;
  338. // Move the values to the base dialog
  339. for (nIndex = 0; nIndex < ARRAYSIZE(_IconData); nIndex++)
  340. {
  341. // Check if any icons have changed.
  342. if ((_IconData[nIndex].iNewIndex != _IconData[nIndex].iOldIndex) ||
  343. StrCmpI(_IconData[nIndex].szNewFile, _IconData[nIndex].szOldFile))
  344. {
  345. hr = SHPropertyBag_WriteIcon(pAdvPage, nIndex, _IconData[nIndex].szNewFile, _IconData[nIndex].iNewIndex);
  346. fHasIconsChanged = TRUE;
  347. }
  348. }
  349. // Only switch to "Custom" if the icons changed.
  350. if (_punkSite && fHasIconsChanged)
  351. {
  352. // We need to tell the Theme tab to customize the theme.
  353. IPropertyBag * pPropertyBag;
  354. hr = _punkSite->QueryInterface(IID_PPV_ARG(IPropertyBag, &pPropertyBag));
  355. if (SUCCEEDED(hr))
  356. {
  357. // Tell the theme that we have customized the values.
  358. hr = SHPropertyBag_WriteInt(pPropertyBag, SZ_PBPROP_CUSTOMIZE_THEME, 0);
  359. pPropertyBag->Release();
  360. }
  361. }
  362. return hr;
  363. }
  364. void CCompPropSheetPage::_AddComponentToLV(COMPONENTA *pcomp)
  365. {
  366. TCHAR szBuf[INTERNET_MAX_URL_LENGTH + 40];
  367. if (SUCCEEDED(StringCchCopy(szBuf, ARRAYSIZE(szBuf),
  368. pcomp->szFriendlyName[0] ? pcomp->szFriendlyName : pcomp->szSource)))
  369. {
  370. //
  371. // Construct the listview item.
  372. //
  373. LV_ITEM lvi = {0};
  374. lvi.mask = LVIF_TEXT | LVIF_PARAM;
  375. lvi.iItem = 0x7FFFFFFF;
  376. lvi.pszText = szBuf;
  377. lvi.lParam = pcomp->dwID;
  378. int index = ListView_InsertItem(_hwndLV, &lvi);
  379. if (index != -1)
  380. {
  381. ListView_SetItemState(_hwndLV, index, pcomp->fChecked ? COMP_CHECKED : COMP_UNCHECKED, LVIS_STATEIMAGEMASK);
  382. ListView_SetColumnWidth(_hwndLV, 0, LVSCW_AUTOSIZE);
  383. }
  384. }
  385. }
  386. void CCompPropSheetPage::_SetUIFromDeskState(BOOL fEmpty)
  387. {
  388. //
  389. // Disable redraws while we mess repeatedly with the listview contents.
  390. //
  391. SendMessage(_hwndLV, WM_SETREDRAW, FALSE, 0);
  392. if (fEmpty)
  393. {
  394. EmptyListview(g_pActiveDeskAdv, _hwndLV);
  395. }
  396. //
  397. // Add each component to the listview.
  398. //
  399. int cComp;
  400. g_pActiveDeskAdv->GetDesktopItemCount(&cComp, 0);
  401. for (int i=0; i<cComp; i++)
  402. {
  403. COMPONENT comp;
  404. comp.dwSize = sizeof(comp);
  405. if (SUCCEEDED(g_pActiveDeskAdv->GetDesktopItem(i, &comp, 0)))
  406. {
  407. COMPONENTA compA;
  408. compA.dwSize = sizeof(compA);
  409. WideCompToMultiComp(&comp, &compA);
  410. _AddComponentToLV(&compA);
  411. }
  412. }
  413. _fInitialized = TRUE;
  414. //
  415. // Reenable redraws.
  416. //
  417. SendMessage(_hwndLV, WM_SETREDRAW, TRUE, 0);
  418. InvalidateRect(_hwndLV, NULL, TRUE);
  419. }
  420. void CCompPropSheetPage::_EnableControls(HWND hwnd)
  421. {
  422. BOOL fEnable;
  423. COMPONENT comp = { sizeof(comp) };
  424. BOOL fHaveSelection = FALSE;
  425. BOOL fSpecialComp = FALSE; //Is this a special component that can't be deleted?
  426. LPTSTR pszSource = NULL;
  427. // Read in the information about the selected component (if any).
  428. int iIndex = ListView_GetNextItem(_hwndLV, -1, LVNI_SELECTED);
  429. if (iIndex > -1)
  430. {
  431. LV_ITEM lvi = {0};
  432. lvi.mask = LVIF_PARAM;
  433. lvi.iItem = iIndex;
  434. ListView_GetItem(_hwndLV, &lvi);
  435. if (SUCCEEDED(g_pActiveDeskAdv->GetDesktopItemByID( lvi.lParam, &comp, 0)))
  436. {
  437. fHaveSelection = TRUE;
  438. //Check if this is a special component.
  439. #ifdef UNICODE
  440. pszSource = (LPTSTR)comp.wszSource;
  441. #else
  442. SHUnicodeToAnsi(comp.wszSource, szCompSource, ARRAYSIZE(szCompSource));
  443. pszSource = szCompSource;
  444. #endif
  445. fSpecialComp = !lstrcmpi(pszSource, MY_HOMEPAGE_SOURCE);
  446. }
  447. }
  448. // 98/08/19 vtan #142332: If there was a previously selected item
  449. // then reselect it and mark that there is now no previously selected
  450. // item.
  451. else if (_iPreviousSelection > -1)
  452. {
  453. ListView_SetItemState(_hwndLV, _iPreviousSelection, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  454. _iPreviousSelection = -1;
  455. // The above ListView_SetItemState results in LVN_ITEMCHANGED notification to _onNotify
  456. // function which inturn calls this _EnableControls again (recursively) and that call
  457. // enables/disables the buttons properly because now an item is selected. Nothing more
  458. // to do and hence this return.
  459. // This is done to fix Bug #276568.
  460. return;
  461. }
  462. EnableWindow(GetDlgItem(hwnd, IDC_COMP_NEW), _fAllowAdd);
  463. //
  464. // Delete button only enabled when an item is selected AND if it is NOT a special comp.
  465. //
  466. fEnable = _fAllowDel && fHaveSelection && !fSpecialComp;
  467. EnableWindow(GetDlgItem(hwnd, IDC_COMP_DELETE), fEnable);
  468. //
  469. // Properties button only enabled on URL based pictures
  470. // and websites.
  471. //
  472. fEnable = FALSE;
  473. if (_fAllowEdit && fHaveSelection)
  474. {
  475. switch (comp.iComponentType)
  476. {
  477. case COMP_TYPE_PICTURE:
  478. case COMP_TYPE_WEBSITE:
  479. //pszSource is already initialized if fHaveSelection is TRUE.
  480. if (PathIsURL(pszSource))
  481. {
  482. fEnable = TRUE;
  483. }
  484. break;
  485. }
  486. }
  487. EnableWindow(GetDlgItem(hwnd, IDC_COMP_PROPERTIES), fEnable);
  488. // initialize the Lock Desktop Items button
  489. CheckDlgButton(hwnd, IDC_COMP_DESKTOPWEBPAGES_CHECK, _fLockDesktopItems);
  490. }
  491. HWND CCompPropSheetPage::_CreateListView(HWND hWndParent)
  492. {
  493. LV_ITEM lvI; // List view item structure
  494. TCHAR szTemp[MAX_PATH];
  495. BOOL bEnable = FALSE;
  496. #ifdef JIGGLE_FIX
  497. RECT rc;
  498. #endif
  499. UINT flags = ILC_MASK | ILC_COLOR32;
  500. // Create a device independant size and location
  501. LONG lWndunits = GetDialogBaseUnits();
  502. int iWndx = LOWORD(lWndunits);
  503. int iWndy = HIWORD(lWndunits);
  504. int iX = ((11 * iWndx) / 4);
  505. int iY = ((15 * iWndy) / 8);
  506. int iWidth = ((163 * iWndx) / 4);
  507. int iHeight = ((40 * iWndy) / 8);
  508. int nIndex;
  509. // Ensure that the common control DLL is loaded.
  510. InitCommonControls();
  511. // Get the list view window
  512. _hWndList = GetDlgItem(hWndParent, IDC_DESKTOP_ICONS);
  513. if(_hWndList == NULL)
  514. return NULL;
  515. if(IS_WINDOW_RTL_MIRRORED(hWndParent))
  516. {
  517. flags |= ILC_MIRROR;
  518. }
  519. // initialize the list view window
  520. // First, initialize the image lists we will need
  521. _hIconList = ImageList_Create(32, 32, flags, ARRAYSIZE(c_aIconRegKeys), 0 ); // create an image list for the icons
  522. // load the icons and add them to the image lists
  523. // get the icon files and indexes from the registry, including for the Default recycle bin
  524. for (nIndex = 0; nIndex < ARRAYSIZE(_IconData); nIndex++)
  525. {
  526. HICON hIcon = NULL;
  527. ExtractPlusColorIcon(_IconData[nIndex].szNewFile, _IconData[nIndex].iNewIndex, &hIcon, 0, 0);
  528. // Added this "if" to fix bug 2831. We want to use SHELL32.DLL
  529. // icon 0 if there is no icon in the file specified in the
  530. // registry (or if the registry didn't specify a file).
  531. if(hIcon == NULL)
  532. {
  533. if (GetSystemDirectory(szTemp, ARRAYSIZE(szTemp)) &&
  534. PathAppend(szTemp, TEXT("shell32.dll")) &&
  535. SUCCEEDED(StringCchCopy(_IconData[nIndex].szOldFile, ARRAYSIZE(_IconData[nIndex].szOldFile), szTemp)) &&
  536. SUCCEEDED(StringCchCopy(_IconData[nIndex].szNewFile, ARRAYSIZE(_IconData[nIndex].szNewFile), szTemp)))
  537. {
  538. _IconData[nIndex].iOldIndex = _IconData[nIndex].iNewIndex = 0;
  539. ExtractPlusColorIcon(szTemp, 0, &hIcon, 0, 0);
  540. }
  541. }
  542. if (hIcon)
  543. {
  544. DWORD dwResult = ImageList_AddIcon(_hIconList, hIcon);
  545. // ImageList_AddIcon() does not take ownership of the icon, so we need to free it.
  546. DestroyIcon(hIcon);
  547. if (-1 == dwResult)
  548. {
  549. ImageList_Destroy(_hIconList);
  550. _hIconList = NULL;
  551. return NULL;
  552. }
  553. }
  554. }
  555. // Make sure that all of the icons were added
  556. if (ImageList_GetImageCount(_hIconList) < ARRAYSIZE(c_aIconRegKeys))
  557. {
  558. ImageList_Destroy(_hIconList);
  559. _hIconList = NULL;
  560. return FALSE;
  561. }
  562. ListView_SetImageList(_hWndList, _hIconList, LVSIL_NORMAL);
  563. // Make sure the listview has WS_HSCROLL set on it.
  564. DWORD dwStyle = GetWindowLong(_hWndList, GWL_STYLE);
  565. SetWindowLong(_hWndList, GWL_STYLE, (dwStyle & (~WS_VSCROLL)) | WS_HSCROLL);
  566. // Finally, let's add the actual items to the control. Fill in the LV_ITEM
  567. // structure for each of the items to add to the list. The mask specifies
  568. // the the .pszText, .iImage, and .state members of the LV_ITEM structure are valid.
  569. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
  570. lvI.state = 0;
  571. lvI.stateMask = 0;
  572. for(nIndex = 0; nIndex < ARRAYSIZE(c_aIconRegKeys); nIndex++ )
  573. {
  574. TCHAR szAppend[64];
  575. BOOL bRet = FALSE;
  576. if (IsEqualCLSID(*c_aIconRegKeys[nIndex].pclsid, CLSID_MyDocuments))
  577. {
  578. LPITEMIDLIST pidl;
  579. HRESULT hr = SHGetSpecialFolderLocation(_hWndList, CSIDL_PERSONAL, &pidl);
  580. // Treat "My Files" differently because we will probably customize the "My" at run time.
  581. if (SUCCEEDED(hr))
  582. {
  583. hr = SHGetNameAndFlags(pidl, SHGDN_INFOLDER, szTemp, ARRAYSIZE(szTemp), NULL);
  584. if (SUCCEEDED(hr))
  585. {
  586. bRet = TRUE;
  587. }
  588. ILFree(pidl);
  589. }
  590. }
  591. else
  592. {
  593. bRet = IconGetRegNameString(c_aIconRegKeys[nIndex].pclsid, szTemp, ARRAYSIZE(szTemp));
  594. }
  595. // if the title string was in the registry, else we have to use the default in our resources
  596. if( (bRet) && (lstrlen(szTemp) > 0))
  597. {
  598. if( LoadString(HINST_THISDLL, c_aIconRegKeys[nIndex].iTitleResource, szAppend, ARRAYSIZE(szAppend)) != 0)
  599. {
  600. StringCchCat(szTemp, ARRAYSIZE(szTemp), szAppend); // display string, truncation ok
  601. }
  602. }
  603. else
  604. {
  605. LoadString(HINST_THISDLL, c_aIconRegKeys[nIndex].iDefaultTitleResource, szTemp, ARRAYSIZE(szTemp));
  606. }
  607. lvI.iItem = nIndex;
  608. lvI.iSubItem = 0;
  609. lvI.pszText = szTemp;
  610. lvI.iImage = nIndex;
  611. if(ListView_InsertItem(_hWndList, &lvI) == -1)
  612. return NULL;
  613. }
  614. #ifdef JIGGLE_FIX
  615. // To fix long standing listview bug, we need to "jiggle" the listview
  616. // window size so that it will do a recompute and realize that we need a
  617. // scroll bar...
  618. GetWindowRect(_hWndList, &rc);
  619. MapWindowPoints( NULL, hWndParent, (LPPOINT)&rc, 2 );
  620. MoveWindow(_hWndList, rc.left, rc.top, rc.right - rc.left+1, rc.bottom - rc.top, FALSE );
  621. MoveWindow(_hWndList, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, FALSE );
  622. #endif
  623. // Set First item to selected
  624. ListView_SetItemState (_hWndList, 0, LVIS_SELECTED, LVIS_SELECTED);
  625. // Get Selected item
  626. for (m_nIndex = 0; m_nIndex < ARRAYSIZE(c_aIconRegKeys); m_nIndex++)
  627. {
  628. if (ListView_GetItemState(_hWndList, m_nIndex, LVIS_SELECTED))
  629. {
  630. bEnable = TRUE;
  631. break;
  632. }
  633. }
  634. if (m_nIndex >= ARRAYSIZE(c_aIconRegKeys))
  635. {
  636. m_nIndex = -1;
  637. }
  638. EnableWindow(GetDlgItem(hWndParent, IDC_CHANGEICON2), bEnable);
  639. EnableWindow(GetDlgItem(hWndParent, IDC_ICONDEFAULT), bEnable);
  640. return _hWndList;
  641. }
  642. #define CUSTOMIZE_DLGPROC 1
  643. #define CUSTOMIZE_WEB_DLGPROC 2
  644. void CCompPropSheetPage::_OnInitDialog(HWND hwnd, INT iPage)
  645. {
  646. if (FAILED(GetActiveDesktop(&g_pActiveDeskAdv)))
  647. {
  648. return;
  649. }
  650. switch (iPage)
  651. {
  652. case CUSTOMIZE_DLGPROC :
  653. {
  654. //
  655. // Read in the restrictions.
  656. //
  657. // Init the Icon UI
  658. // Create our list view and fill it with the system icons
  659. m_nIndex = 0;
  660. _CreateListView(hwnd);
  661. _OnInitDesktopOptionsUI(hwnd);
  662. //
  663. // Enable the Desktop Cleanup Wizard if we are on the right version
  664. // of the OS and the DesktopCleanup NoRun policy is not set
  665. //
  666. //
  667. BOOL fCleanupEnabled = (IsOS(OS_PERSONAL) || IsOS(OS_PROFESSIONAL)) &&
  668. !IsUserAGuest() &&
  669. !SHRestricted(REST_NODESKTOPCLEANUP);
  670. if (fCleanupEnabled)
  671. {
  672. if (BST_INDETERMINATE == g_iRunDesktopCleanup)
  673. {
  674. DWORD dwData = 0;
  675. DWORD dwType;
  676. DWORD cch = sizeof (DWORD);
  677. if (ERROR_SUCCESS == SHRegGetUSValue(REGSTR_DESKTOP_CLEANUP,REGSTR_VAL_DONTRUN,
  678. &dwType, &dwData, &cch, FALSE, NULL, 0) &&
  679. dwData != 0)
  680. {
  681. g_iRunDesktopCleanup = BST_UNCHECKED;
  682. }
  683. else
  684. {
  685. g_iRunDesktopCleanup = BST_CHECKED;
  686. }
  687. }
  688. CheckDlgButton(hwnd, IDC_DESKCLNR_CHECK, g_iRunDesktopCleanup);
  689. }
  690. else
  691. {
  692. ShowWindow(GetDlgItem(hwnd, IDC_COMP_CLEANUP_GROUP), FALSE);
  693. ShowWindow(GetDlgItem(hwnd, IDC_DESKCLNR_MOVEUNUSED), FALSE);
  694. ShowWindow(GetDlgItem(hwnd, IDC_DESKCLNR_CHECK), FALSE);
  695. ShowWindow(GetDlgItem(hwnd, IDC_DESKCLNR_RUNWIZARD), FALSE);
  696. }
  697. }
  698. break;
  699. case CUSTOMIZE_WEB_DLGPROC:
  700. {
  701. _fLaunchGallery = FALSE;
  702. _fAllowAdd = !SHRestricted(REST_NOADDDESKCOMP);
  703. _fAllowDel = !SHRestricted(REST_NODELDESKCOMP);
  704. _fAllowEdit = !SHRestricted(REST_NOEDITDESKCOMP);
  705. _fAllowClose = !SHRestricted(REST_NOCLOSEDESKCOMP);
  706. _fAllowReset = _fAllowAdd && _fAllowDel && _fAllowEdit &&
  707. _fAllowClose && !SHRestricted(REST_NOCHANGINGWALLPAPER);
  708. _fForceAD = SHRestricted(REST_FORCEACTIVEDESKTOPON);
  709. _hwndLV = GetDlgItem(hwnd, IDC_COMP_LIST);
  710. EnableWindow(GetDlgItem(hwnd, IDC_COMP_NEW), _fAllowAdd);
  711. EnableWindow(GetDlgItem(hwnd, IDC_COMP_DELETE), _fAllowDel);
  712. EnableWindow(GetDlgItem(hwnd, IDC_COMP_PROPERTIES), _fAllowEdit);
  713. EnableWindow(GetDlgItem(hwnd, IDC_COMP_SYNCHRONIZE), _fAllowEdit);
  714. if (_fAllowClose)
  715. {
  716. ListView_SetExtendedListViewStyle(_hwndLV, LVS_EX_CHECKBOXES);
  717. }
  718. //
  719. // Add the single column that we want.
  720. //
  721. LV_COLUMN lvc;
  722. lvc.mask = LVCF_FMT | LVCF_SUBITEM;
  723. lvc.fmt = LVCFMT_LEFT;
  724. lvc.iSubItem = 0;
  725. ListView_InsertColumn(_hwndLV, 0, &lvc);
  726. //
  727. // Now make the UI match the g_pActiveDeskAdv object.
  728. //
  729. _SetUIFromDeskState(FALSE);
  730. //
  731. // Select the first item, if it exists.
  732. //
  733. int cComp;
  734. g_pActiveDeskAdv->GetDesktopItemCount(&cComp, 0);
  735. if (cComp)
  736. {
  737. ListView_SetItemState(_hwndLV, 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  738. }
  739. _EnableControls(hwnd);
  740. }
  741. break;
  742. }
  743. }
  744. HRESULT CCompPropSheetPage::_OnInitDesktopOptionsUI(HWND hwnd)
  745. {
  746. SHELLSTATE ss = {0};
  747. SHGetSetSettings(&ss, SSF_STARTPANELON, FALSE); //See if the StartPanel is on!
  748. _iStartPanelOn = ss.fStartPanelOn ? 1 : 0; //Remember this in the class!
  749. // Check or uncheck the various icons based on whether they are on/off now.
  750. _UpdateDesktopIconsUI(hwnd);
  751. return S_OK;
  752. }
  753. HRESULT CCompPropSheetPage::_UpdateDesktopIconsUI(HWND hwnd)
  754. {
  755. // Check or uncheck the various icons based on whether they are on/off now.
  756. for (int iIndex = 0; iIndex < NUM_DESKICONS; iIndex++)
  757. {
  758. // If HideDeskIcon[][] is true, uncheck the checkbox! If it is FALSE, check the checkbox.
  759. CheckDlgButton(hwnd, c_aDeskIconId[iIndex].iDeskIconDlgItemId, !_afHideIcon[_iStartPanelOn][iIndex]);
  760. // If the policy is set, disable this CheckBox!
  761. EnableWindow(GetDlgItem(hwnd, c_aDeskIconId[iIndex].iDeskIconDlgItemId), !_afDisableCheckBox[iIndex]);
  762. }
  763. return S_OK;
  764. }
  765. void CCompPropSheetPage::_OnNotify(HWND hwnd, WPARAM wParam, LPNMHDR lpnm)
  766. {
  767. switch (wParam)
  768. {
  769. case IDC_COMP_DESKTOPWEBPAGES_CHECK:
  770. _fLockDesktopItems = IsDlgButtonChecked(hwnd, IDC_COMP_DESKTOPWEBPAGES_CHECK);
  771. break;
  772. case IDC_DESKTOP_ICONS:
  773. {
  774. switch (lpnm->code)
  775. case LVN_ITEMCHANGED:
  776. {
  777. BOOL fSomethingSelected = FALSE;
  778. // Find out who's selected now
  779. for( m_nIndex = 0; m_nIndex < ARRAYSIZE(c_aIconRegKeys); m_nIndex++)
  780. {
  781. if( ListView_GetItemState(_hWndList, m_nIndex, LVIS_SELECTED))
  782. {
  783. fSomethingSelected = TRUE;
  784. break;
  785. }
  786. }
  787. if (m_nIndex >= ARRAYSIZE(c_aIconRegKeys))
  788. {
  789. m_nIndex = -1;
  790. }
  791. EnableWindow(GetDlgItem(hwnd, IDC_CHANGEICON2), fSomethingSelected);
  792. EnableWindow(GetDlgItem(hwnd, IDC_ICONDEFAULT), fSomethingSelected);
  793. }
  794. }
  795. break;
  796. case IDC_COMP_LIST:
  797. {
  798. switch (lpnm->code)
  799. {
  800. case LVN_ITEMCHANGED:
  801. NM_LISTVIEW *pnmlv = (NM_LISTVIEW *)lpnm;
  802. if ((pnmlv->uChanged & LVIF_STATE) &&
  803. ((pnmlv->uNewState ^ pnmlv->uOldState) & COMP_CHECKED))
  804. {
  805. LV_ITEM lvi = {0};
  806. lvi.iItem = pnmlv->iItem;
  807. lvi.mask = LVIF_PARAM;
  808. ListView_GetItem(_hwndLV, &lvi);
  809. COMPONENT comp;
  810. comp.dwSize = sizeof(COMPONENT);
  811. if (SUCCEEDED(g_pActiveDeskAdv->GetDesktopItemByID(lvi.lParam, &comp, 0)))
  812. {
  813. comp.fChecked = (pnmlv->uNewState & COMP_CHECKED) != 0;
  814. g_pActiveDeskAdv->ModifyDesktopItem(&comp, COMP_ELEM_CHECKED);
  815. }
  816. if (_fInitialized)
  817. {
  818. g_fDirtyAdvanced = TRUE;
  819. }
  820. }
  821. if ((pnmlv->uChanged & LVIF_STATE) &&
  822. ((pnmlv->uNewState ^ pnmlv->uOldState) & LVIS_SELECTED))
  823. {
  824. _EnableControls(hwnd); // toggle delete, properties
  825. }
  826. break;
  827. }
  828. }
  829. break;
  830. default:
  831. {
  832. switch (lpnm->code)
  833. {
  834. case PSN_APPLY:
  835. {
  836. // store desktop flags
  837. DWORD dwFlags, dwFlagsPrev;
  838. dwFlags = dwFlagsPrev = GetDesktopFlags();
  839. if (_fLockDesktopItems)
  840. {
  841. dwFlags |= COMPONENTS_LOCKED;
  842. }
  843. else
  844. {
  845. dwFlags &= ~COMPONENTS_LOCKED;
  846. }
  847. if (dwFlags != dwFlagsPrev)
  848. {
  849. g_fDirtyAdvanced = TRUE;
  850. SetDesktopFlags(COMPONENTS_LOCKED, dwFlags);
  851. }
  852. _fCustomizeDesktopOK = TRUE;
  853. }
  854. break;
  855. }
  856. }
  857. break;
  858. }
  859. }
  860. //
  861. // Returns TRUE if the string looks like a candidate for
  862. // getting qualified as "file:".
  863. //
  864. BOOL LooksLikeFile(LPCTSTR psz)
  865. {
  866. BOOL fRet = FALSE;
  867. if (psz[0] &&
  868. psz[1] &&
  869. #ifndef UNICODE
  870. !IsDBCSLeadByte(psz[0]) &&
  871. !IsDBCSLeadByte(psz[1]) &&
  872. #endif
  873. ((psz[0] == TEXT('\\')) ||
  874. (psz[1] == TEXT(':')) ||
  875. (psz[1] == TEXT('|'))))
  876. {
  877. fRet = TRUE;
  878. }
  879. return fRet;
  880. }
  881. #define GOTO_GALLERY (-2)
  882. BOOL_PTR CALLBACK AddComponentDlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  883. {
  884. LPTSTR pszSource = (LPTSTR)GetWindowLongPtr(hdlg, DWLP_USER);
  885. TCHAR szBuf[INTERNET_MAX_URL_LENGTH];
  886. switch (uMsg)
  887. {
  888. case WM_INITDIALOG:
  889. pszSource = (LPTSTR)lParam;
  890. SetWindowLongPtr(hdlg, DWLP_USER, (LONG_PTR)pszSource);
  891. SetDlgItemText(hdlg, IDC_CPROP_SOURCE, c_szNULL);
  892. EnableWindow(GetDlgItem(hdlg, IDOK), FALSE);
  893. SHAutoComplete(GetDlgItem(hdlg, IDC_CPROP_SOURCE), 0);
  894. return TRUE;
  895. case WM_COMMAND:
  896. switch (GET_WM_COMMAND_ID(wParam, lParam))
  897. {
  898. case IDC_CPROP_BROWSE:
  899. {
  900. GetDlgItemText(hdlg, IDC_CPROP_SOURCE, szBuf, ARRAYSIZE(szBuf));
  901. if (!LooksLikeFile(szBuf))
  902. {
  903. //
  904. // Open the favorites folder when we aren't
  905. // looking at a specific file.
  906. //
  907. SHGetSpecialFolderPath(hdlg, szBuf, CSIDL_FAVORITES, FALSE);
  908. //
  909. // Append a slash because GetFileName breaks the
  910. // string into a file & dir, and we want to make sure
  911. // the entire favorites path is treated as a dir.
  912. //
  913. PathAddBackslash(szBuf);
  914. }
  915. else
  916. {
  917. PathRemoveArgs(szBuf);
  918. }
  919. DWORD adwFlags[] = {
  920. GFN_ALL,
  921. GFN_PICTURE,
  922. (GFN_LOCALHTM | GFN_LOCALMHTML | GFN_CDF | GFN_URL),
  923. 0
  924. };
  925. int aiTypes[] = {
  926. IDS_COMP_FILETYPES,
  927. IDS_ALL_PICTURES,
  928. IDS_ALL_HTML,
  929. 0
  930. };
  931. if (GetFileName(hdlg, szBuf, ARRAYSIZE(szBuf), aiTypes, adwFlags) &&
  932. CheckAndResolveLocalUrlFile(szBuf, ARRAYSIZE(szBuf)))
  933. {
  934. SetDlgItemText(hdlg, IDC_CPROP_SOURCE, szBuf);
  935. }
  936. }
  937. break;
  938. case IDC_CPROP_SOURCE:
  939. if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
  940. {
  941. EnableWindow(GetDlgItem(hdlg, IDOK), GetWindowTextLength(GetDlgItem(hdlg, IDC_CPROP_SOURCE)) > 0);
  942. }
  943. break;
  944. case IDOK:
  945. GetDlgItemText(hdlg, IDC_CPROP_SOURCE, pszSource, INTERNET_MAX_URL_LENGTH);
  946. ASSERT(pszSource[0]);
  947. if (ValidateFileName(hdlg, pszSource, IDS_COMP_TYPE1) &&
  948. CheckAndResolveLocalUrlFile(pszSource, INTERNET_MAX_URL_LENGTH))
  949. {
  950. //
  951. // Qualify non file-protocol strings.
  952. //
  953. if (!LooksLikeFile(pszSource))
  954. {
  955. DWORD cchSize = INTERNET_MAX_URL_LENGTH;
  956. PathRemoveBlanks(pszSource);
  957. ParseURLFromOutsideSource(pszSource, pszSource, &cchSize, NULL);
  958. }
  959. EndDialog(hdlg, 0);
  960. }
  961. break;
  962. case IDCANCEL:
  963. EndDialog(hdlg, -1);
  964. break;
  965. case IDC_GOTO_GALLERY:
  966. EndDialog(hdlg, GOTO_GALLERY);
  967. break;
  968. }
  969. break;
  970. }
  971. return FALSE;
  972. }
  973. BOOL IsUrlPicture(LPCTSTR pszUrl)
  974. {
  975. BOOL fRet = FALSE;
  976. if(pszUrl[0] == TEXT('\0'))
  977. {
  978. fRet = TRUE;
  979. }
  980. else
  981. {
  982. LPTSTR pszExt = PathFindExtension(pszUrl);
  983. if ((lstrcmpi(pszExt, TEXT(".BMP")) == 0) ||
  984. (StrCmpIC(pszExt, TEXT(".GIF")) == 0) || // 368690: Strange, but we must compare 'i' in both caps and lower case.
  985. (lstrcmpi(pszExt, TEXT(".JPG")) == 0) ||
  986. (lstrcmpi(pszExt, TEXT(".JPE")) == 0) ||
  987. (lstrcmpi(pszExt, TEXT(".JPEG")) == 0) ||
  988. (lstrcmpi(pszExt, TEXT(".DIB")) == 0) ||
  989. (lstrcmpi(pszExt, TEXT(".PNG")) == 0))
  990. {
  991. fRet = TRUE;
  992. }
  993. }
  994. return(fRet);
  995. }
  996. int GetComponentType(LPCTSTR pszUrl)
  997. {
  998. return IsUrlPicture(pszUrl) ? COMP_TYPE_PICTURE : COMP_TYPE_WEBSITE;
  999. }
  1000. void CreateComponent(COMPONENTA *pcomp, LPCTSTR pszUrl)
  1001. {
  1002. pcomp->dwSize = sizeof(*pcomp);
  1003. pcomp->dwID = (DWORD)-1;
  1004. pcomp->iComponentType = GetComponentType(pszUrl);
  1005. pcomp->fChecked = TRUE;
  1006. pcomp->fDirty = FALSE;
  1007. pcomp->fNoScroll = FALSE;
  1008. pcomp->cpPos.dwSize = sizeof(pcomp->cpPos);
  1009. pcomp->cpPos.iLeft = COMPONENT_DEFAULT_LEFT;
  1010. pcomp->cpPos.iTop = COMPONENT_DEFAULT_TOP;
  1011. pcomp->cpPos.dwWidth = COMPONENT_DEFAULT_WIDTH;
  1012. pcomp->cpPos.dwHeight = COMPONENT_DEFAULT_HEIGHT;
  1013. pcomp->cpPos.izIndex = COMPONENT_TOP;
  1014. pcomp->cpPos.fCanResize = TRUE;
  1015. pcomp->cpPos.fCanResizeX = pcomp->cpPos.fCanResizeY = TRUE;
  1016. pcomp->cpPos.iPreferredLeftPercent = pcomp->cpPos.iPreferredTopPercent = 0;
  1017. if (FAILED(StringCchCopy(pcomp->szSource, ARRAYSIZE(pcomp->szSource), pszUrl)))
  1018. {
  1019. pcomp->szSource[0] = TEXT('\0');
  1020. }
  1021. if (FAILED(StringCchCopy(pcomp->szSubscribedURL, ARRAYSIZE(pcomp->szSubscribedURL), pszUrl)))
  1022. {
  1023. pcomp->szSubscribedURL[0] = TEXT('\0');
  1024. }
  1025. pcomp->szFriendlyName[0] = TEXT('\0');
  1026. }
  1027. BOOL FindComponent(IN LPCTSTR pszUrl, IN IActiveDesktop * pActiveDesktop)
  1028. {
  1029. BOOL fRet = FALSE;
  1030. int i, ccomp;
  1031. LPWSTR pwszUrl;
  1032. #ifndef UNICODE
  1033. WCHAR wszUrl[INTERNET_MAX_URL_LENGTH];
  1034. SHAnsiToUnicode(pszUrl, wszUrl, ARRAYSIZE(wszUrl));
  1035. pwszUrl = wszUrl;
  1036. #else
  1037. pwszUrl = (LPWSTR)pszUrl;
  1038. #endif
  1039. if (pActiveDesktop)
  1040. {
  1041. pActiveDesktop->GetDesktopItemCount(&ccomp, 0);
  1042. for (i=0; i<ccomp; i++)
  1043. {
  1044. COMPONENT comp;
  1045. comp.dwSize = sizeof(COMPONENT);
  1046. if (SUCCEEDED(pActiveDesktop->GetDesktopItem(i, &comp, 0)))
  1047. {
  1048. if (StrCmpIW(pwszUrl, comp.wszSource) == 0)
  1049. {
  1050. fRet = TRUE;
  1051. break;
  1052. }
  1053. }
  1054. }
  1055. }
  1056. return fRet;
  1057. }
  1058. void EmptyListview(IActiveDesktop * pActiveDesktop, HWND hwndLV)
  1059. {
  1060. //
  1061. // Delete all the old components.
  1062. //
  1063. int cComp;
  1064. pActiveDesktop->GetDesktopItemCount(&cComp, 0);
  1065. int i;
  1066. COMPONENT comp;
  1067. comp.dwSize = sizeof(COMPONENT);
  1068. for (i=0; i<cComp; i++)
  1069. {
  1070. ListView_DeleteItem(hwndLV, 0);
  1071. }
  1072. }
  1073. void CCompPropSheetPage::_SelectComponent(LPWSTR pwszUrl)
  1074. {
  1075. //
  1076. // Look for the component with our URL.
  1077. //
  1078. int cComp;
  1079. COMPONENT comp = { sizeof(comp) };
  1080. g_pActiveDeskAdv->GetDesktopItemCount(&cComp, 0);
  1081. for (int i=0; i<cComp; i++)
  1082. {
  1083. if (SUCCEEDED(g_pActiveDeskAdv->GetDesktopItem(i, &comp, 0)))
  1084. {
  1085. if (StrCmpW(pwszUrl, comp.wszSource) == 0)
  1086. {
  1087. break;
  1088. }
  1089. }
  1090. }
  1091. //
  1092. // Find the matching listview entry (search for dwID).
  1093. //
  1094. if (i != cComp)
  1095. {
  1096. int nItems = ListView_GetItemCount(_hwndLV);
  1097. for (i=0; i<nItems; i++)
  1098. {
  1099. LV_ITEM lvi = {0};
  1100. lvi.iItem = i;
  1101. lvi.mask = LVIF_PARAM;
  1102. ListView_GetItem(_hwndLV, &lvi);
  1103. if (lvi.lParam == (LPARAM)comp.dwID)
  1104. {
  1105. //
  1106. // Found it, select it and exit.
  1107. //
  1108. ListView_SetItemState(_hwndLV, i, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  1109. ListView_EnsureVisible(_hwndLV, i, FALSE);
  1110. break;
  1111. }
  1112. }
  1113. }
  1114. }
  1115. INT_PTR NewComponent(HWND hwndOwner, IActiveDesktop * pad, BOOL fDeferGallery, COMPONENT * pcomp)
  1116. {
  1117. HRESULT hrInit = SHCoInitialize();
  1118. TCHAR szSource[INTERNET_MAX_URL_LENGTH];
  1119. COMPONENT comp;
  1120. INT_PTR iChoice = DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(IDD_ADDCOMPONENT), hwndOwner, AddComponentDlgProc, (LPARAM)szSource);
  1121. if (!pcomp)
  1122. {
  1123. pcomp = &comp;
  1124. pcomp->dwSize = sizeof(comp);
  1125. pcomp->dwCurItemState = IS_NORMAL;
  1126. }
  1127. if (iChoice == GOTO_GALLERY) // the user wants to launch the gallery
  1128. {
  1129. if (!fDeferGallery)
  1130. {
  1131. WCHAR szGalleryUrl[INTERNET_MAX_URL_LENGTH];
  1132. if (SUCCEEDED(URLSubLoadString(HINST_THISDLL, IDS_VISIT_URL, szGalleryUrl, ARRAYSIZE(szGalleryUrl), URLSUB_ALL)))
  1133. {
  1134. NavToUrlUsingIEW(szGalleryUrl, TRUE);
  1135. }
  1136. }
  1137. }
  1138. else if (iChoice >= 0)
  1139. { // the user has entered a URL address
  1140. WCHAR szSourceW[INTERNET_MAX_URL_LENGTH];
  1141. SHTCharToUnicode(szSource, szSourceW, ARRAYSIZE(szSourceW));
  1142. if (!SUCCEEDED(pad->AddUrl(hwndOwner, szSourceW, pcomp, 0)))
  1143. iChoice = -1;
  1144. }
  1145. SHCoUninitialize(hrInit);
  1146. return iChoice;
  1147. }
  1148. void CCompPropSheetPage::_NewComponent(HWND hwnd)
  1149. {
  1150. COMPONENT comp;
  1151. comp.dwSize = sizeof(comp);
  1152. comp.dwCurItemState = IS_NORMAL;
  1153. INT_PTR iChoice = NewComponent(hwnd, g_pActiveDeskAdv, TRUE, &comp);
  1154. if (iChoice == GOTO_GALLERY) // the user wants to launch the gallery
  1155. {
  1156. _fLaunchGallery = TRUE;
  1157. g_fLaunchGallery = TRUE;
  1158. g_fDirtyAdvanced = TRUE;
  1159. PropSheet_PressButton(GetParent(hwnd), PSBTN_OK);
  1160. }
  1161. else
  1162. {
  1163. if (iChoice >= 0) // the user has entered a URL address
  1164. {
  1165. // Add component to listview.
  1166. //
  1167. // Need to reload the entire listview so that it is shown in
  1168. // the correct zorder.
  1169. _SetUIFromDeskState(TRUE);
  1170. // Select the newly added component.
  1171. _SelectComponent(comp.wszSource);
  1172. }
  1173. g_fDirtyAdvanced = TRUE;
  1174. }
  1175. }
  1176. void CCompPropSheetPage::_EditComponent(HWND hwnd)
  1177. {
  1178. int iIndex = ListView_GetNextItem(_hwndLV, -1, LVNI_SELECTED);
  1179. if (iIndex > -1)
  1180. {
  1181. LV_ITEM lvi = {0};
  1182. lvi.mask = LVIF_PARAM;
  1183. lvi.iItem = iIndex;
  1184. ListView_GetItem(_hwndLV, &lvi);
  1185. COMPONENT comp = { sizeof(comp) };
  1186. if (SUCCEEDED(g_pActiveDeskAdv->GetDesktopItemByID(lvi.lParam, &comp, 0)))
  1187. {
  1188. LPTSTR pszSubscribedURL;
  1189. #ifndef UNICODE
  1190. TCHAR szSubscribedURL[INTERNET_MAX_URL_LENGTH];
  1191. SHUnicodeToAnsi(comp.wszSubscribedURL, szSubscribedURL, ARRAYSIZE(szSubscribedURL));
  1192. pszSubscribedURL = szSubscribedURL;
  1193. #else
  1194. pszSubscribedURL = (LPTSTR)comp.wszSubscribedURL;
  1195. #endif
  1196. if (SUCCEEDED(ShowSubscriptionProperties(pszSubscribedURL, hwnd)))
  1197. {
  1198. g_fDirtyAdvanced = TRUE;
  1199. }
  1200. }
  1201. }
  1202. }
  1203. void CCompPropSheetPage::_DeleteComponent(HWND hwnd)
  1204. {
  1205. int iIndex = ListView_GetNextItem(_hwndLV, -1, LVNI_ALL | LVNI_SELECTED);
  1206. if (iIndex > -1)
  1207. {
  1208. LV_ITEM lvi = {0};
  1209. lvi.mask = LVIF_PARAM;
  1210. lvi.iItem = iIndex;
  1211. ListView_GetItem(_hwndLV, &lvi);
  1212. COMPONENT comp;
  1213. comp.dwSize = sizeof(COMPONENT);
  1214. if (SUCCEEDED(g_pActiveDeskAdv->GetDesktopItemByID(lvi.lParam, &comp, 0)))
  1215. {
  1216. TCHAR szMsg[1024];
  1217. TCHAR szTitle[MAX_PATH];
  1218. LoadString(HINST_THISDLL, IDS_COMP_CONFIRMDEL, szMsg, ARRAYSIZE(szMsg));
  1219. LoadString(HINST_THISDLL, IDS_COMP_TITLE, szTitle, ARRAYSIZE(szTitle));
  1220. if (MessageBox(hwnd, szMsg, szTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
  1221. {
  1222. g_pActiveDeskAdv->RemoveDesktopItem(&comp, 0);
  1223. ListView_DeleteItem(_hwndLV, iIndex);
  1224. int cComp = ListView_GetItemCount(_hwndLV);
  1225. if (cComp == 0)
  1226. {
  1227. SendMessage(hwnd, WM_NEXTDLGCTL, (WPARAM)GetDlgItem(hwnd, IDC_COMP_NEW), TRUE);
  1228. }
  1229. else
  1230. {
  1231. int iSel = (iIndex > cComp - 1 ? cComp - 1 : iIndex);
  1232. ListView_SetItemState(_hwndLV, iSel, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED);
  1233. }
  1234. LPTSTR pszSubscribedURL;
  1235. #ifndef UNICODE
  1236. TCHAR szSubscribedURL[INTERNET_MAX_URL_LENGTH];
  1237. SHUnicodeToAnsi(comp.wszSubscribedURL, szSubscribedURL, ARRAYSIZE(szSubscribedURL));
  1238. pszSubscribedURL = szSubscribedURL;
  1239. #else
  1240. pszSubscribedURL = comp.wszSubscribedURL;
  1241. #endif
  1242. DeleteFromSubscriptionList(pszSubscribedURL);
  1243. }
  1244. g_fDirtyAdvanced = TRUE;
  1245. }
  1246. }
  1247. }
  1248. //
  1249. // Desktop Cleanup stuff
  1250. //
  1251. STDAPI ApplyDesktopCleanupSettings()
  1252. {
  1253. // set the registry value
  1254. DWORD dwData = (BST_CHECKED == g_iRunDesktopCleanup) ? 0 : 1;
  1255. SHRegSetUSValue(REGSTR_DESKTOP_CLEANUP, REGSTR_VAL_DONTRUN,
  1256. REG_DWORD, &dwData, sizeof(dwData), SHREGSET_FORCE_HKCU);
  1257. return S_OK;
  1258. }
  1259. void CCompPropSheetPage::_DesktopCleaner(HWND hwnd)
  1260. {
  1261. TCHAR szRunDLL[MAX_PATH];
  1262. if (GetSystemDirectory(szRunDLL, ARRAYSIZE(szRunDLL)) &&
  1263. PathAppend(szRunDLL, TEXT("rundll32.exe")))
  1264. {
  1265. SHELLEXECUTEINFO sei = {0};
  1266. sei.cbSize = sizeof(sei);
  1267. sei.hwnd = hwnd;
  1268. sei.lpFile = szRunDLL;
  1269. sei.lpParameters = TEXT("fldrclnr.dll,Wizard_RunDLL all");
  1270. sei.nShow = SW_SHOWNORMAL;
  1271. ShellExecuteEx(&sei);
  1272. }
  1273. }
  1274. void CCompPropSheetPage::_SynchronizeAllComponents(IActiveDesktop *pActDesktop)
  1275. {
  1276. IADesktopP2* padp2;
  1277. if (SUCCEEDED(pActDesktop->QueryInterface(IID_PPV_ARG(IADesktopP2, &padp2))))
  1278. {
  1279. padp2->UpdateAllDesktopSubscriptions();
  1280. padp2->Release();
  1281. }
  1282. }
  1283. void CCompPropSheetPage::_OnCommand(HWND hwnd, WORD wNotifyCode, WORD wID, HWND hwndCtl)
  1284. {
  1285. BOOL fFocusToList = FALSE;
  1286. switch (wID)
  1287. {
  1288. case IDC_COMP_NEW:
  1289. _NewComponent(hwnd);
  1290. // 98/08/19 vtan #152418: Set the default border to "New". This
  1291. // will be changed when the focus is changed to the component list
  1292. // but this allows the dialog handling code to draw the default
  1293. // border correctly.
  1294. (BOOL)SendMessage(hwnd, WM_NEXTDLGCTL, reinterpret_cast<WPARAM>(GetDlgItem(hwnd, IDC_COMP_NEW)), static_cast<BOOL>(TRUE));
  1295. fFocusToList = TRUE;
  1296. break;
  1297. case IDC_COMP_PROPERTIES:
  1298. _EditComponent(hwnd);
  1299. // 98/08/19 vtan #152418: Same as above.
  1300. (BOOL)SendMessage(hwnd, WM_NEXTDLGCTL, reinterpret_cast<WPARAM>(GetDlgItem(hwnd, IDC_COMP_PROPERTIES)), static_cast<BOOL>(TRUE));
  1301. fFocusToList = TRUE;
  1302. break;
  1303. case IDC_COMP_DELETE:
  1304. _DeleteComponent(hwnd);
  1305. // 98/08/19 vtan #152418: Same as above.
  1306. (BOOL)SendMessage(hwnd, WM_NEXTDLGCTL, reinterpret_cast<WPARAM>(GetDlgItem(hwnd, IDC_COMP_DELETE)), static_cast<BOOL>(TRUE));
  1307. fFocusToList = TRUE;
  1308. break;
  1309. case IDC_DESKCLNR_RUNWIZARD:
  1310. _DesktopCleaner(hwnd);
  1311. break;
  1312. case IDC_DESKCLNR_CHECK:
  1313. // if the button is clicked, update the global
  1314. {
  1315. int iButState = IsDlgButtonChecked(hwnd, IDC_DESKCLNR_CHECK);
  1316. if (iButState != g_iRunDesktopCleanup)
  1317. {
  1318. ASSERT(iButState != BST_INDETERMINATE);
  1319. g_iRunDesktopCleanup = iButState;
  1320. g_fDirtyAdvanced = TRUE;
  1321. }
  1322. }
  1323. break;
  1324. case IDC_COMP_SYNCHRONIZE:
  1325. _SynchronizeAllComponents(g_pActiveDeskAdv);
  1326. break;
  1327. case IDC_CHANGEICON2:
  1328. if (-1 != m_nIndex)
  1329. {
  1330. WCHAR szExp[MAX_PATH];
  1331. INT i = _IconData[m_nIndex].iOldIndex;
  1332. ExpandEnvironmentStringsW(_IconData[m_nIndex].szOldFile, szExp, ARRAYSIZE(szExp));
  1333. if (PickIconDlg(hwnd, szExp, ARRAYSIZE(szExp), &i) == TRUE)
  1334. {
  1335. HICON hIcon;
  1336. if (SUCCEEDED(StringCchCopy(_IconData[m_nIndex].szNewFile, ARRAYSIZE(_IconData[m_nIndex].szNewFile), szExp)))
  1337. {
  1338. _IconData[m_nIndex].iNewIndex = i;
  1339. if (SUCCEEDED(ExtractPlusColorIcon(_IconData[m_nIndex].szNewFile, _IconData[m_nIndex].iNewIndex, &hIcon, 0, 0)))
  1340. {
  1341. ImageList_ReplaceIcon(_hIconList, m_nIndex, hIcon);
  1342. ListView_RedrawItems(_hWndList, m_nIndex, m_nIndex);
  1343. }
  1344. }
  1345. }
  1346. SetFocus(_hWndList);
  1347. }
  1348. break;
  1349. case IDC_ICONDEFAULT:
  1350. if (-1 != m_nIndex)
  1351. {
  1352. TCHAR szPath[MAX_PATH];
  1353. HICON hIcon;
  1354. if (!ExpandEnvironmentStrings(c_aIconRegKeys[m_nIndex].pszDefault, szPath, ARRAYSIZE(szPath)) ||
  1355. FAILED(StringCchCopy(szPath, ARRAYSIZE(szPath), c_aIconRegKeys[m_nIndex].pszDefault)))
  1356. {
  1357. break;
  1358. }
  1359. if (SUCCEEDED(StringCchCopy(_IconData[m_nIndex].szNewFile, ARRAYSIZE(_IconData[m_nIndex].szNewFile), szPath)))
  1360. {
  1361. _IconData[m_nIndex].iNewIndex = c_aIconRegKeys[m_nIndex].nDefaultIndex;
  1362. ExtractPlusColorIcon(_IconData[m_nIndex].szNewFile, _IconData[m_nIndex].iNewIndex, &hIcon, 0, 0);
  1363. ImageList_ReplaceIcon(_hIconList, m_nIndex, hIcon);
  1364. ListView_RedrawItems(_hWndList, m_nIndex, m_nIndex);
  1365. SetFocus(_hWndList);
  1366. }
  1367. }
  1368. break;
  1369. case IDC_DESKTOP_ICON_MYDOCS:
  1370. case IDC_DESKTOP_ICON_MYCOMP:
  1371. case IDC_DESKTOP_ICON_MYNET:
  1372. case IDC_DESKTOP_ICON_IE:
  1373. {
  1374. //Get the current button state and save it.
  1375. BOOL fOriginalBtnState = IsDlgButtonChecked(hwnd, wID);
  1376. //Toggle the button from checked to unchecked (or vice-versa).
  1377. CheckDlgButton(hwnd, wID, (fOriginalBtnState ? BST_UNCHECKED : BST_CHECKED));
  1378. for(int iIndex = 0; iIndex < NUM_DESKICONS; iIndex++)
  1379. {
  1380. if(wID == c_aDeskIconId[iIndex].iDeskIconDlgItemId)
  1381. {
  1382. // Note#1: The inverse logic is used below. If the originally button is checked,
  1383. // it means that now it is unchecked, which means that icon should now be hidden;
  1384. // (i.e) the HideDeskIcon[][] should be set to TRUE.
  1385. //
  1386. // Note#2: When the end-user toggles these, we want to set the same setting for
  1387. // both the modes now!
  1388. _afHideIcon[0][iIndex] = _afHideIcon[1][iIndex] = fOriginalBtnState;
  1389. }
  1390. }
  1391. }
  1392. break;
  1393. }
  1394. //Set the focus back to the components list, if necessary
  1395. if (fFocusToList)
  1396. {
  1397. int iIndex = ListView_GetNextItem(_hwndLV, -1, LVNI_SELECTED);
  1398. if (iIndex > -1)
  1399. {
  1400. SetFocus(GetDlgItem(hwnd, IDC_COMP_LIST));
  1401. }
  1402. }
  1403. }
  1404. void CCompPropSheetPage::_OnDestroy(INT iPage)
  1405. {
  1406. if (CUSTOMIZE_DLGPROC == iPage)
  1407. {
  1408. ReleaseActiveDesktop(&g_pActiveDeskAdv);
  1409. if (_fLaunchGallery)
  1410. {
  1411. WCHAR szGalleryUrl[INTERNET_MAX_URL_LENGTH];
  1412. if (SUCCEEDED(URLSubLoadString(HINST_THISDLL, IDS_VISIT_URL, szGalleryUrl, ARRAYSIZE(szGalleryUrl), URLSUB_ALL)))
  1413. {
  1414. NavToUrlUsingIEW(szGalleryUrl, TRUE);
  1415. }
  1416. }
  1417. }
  1418. }
  1419. void CCompPropSheetPage::_OnGetCurSel(int *piIndex)
  1420. {
  1421. if (_hwndLV)
  1422. {
  1423. *piIndex = ListView_GetNextItem(_hwndLV, -1, LVNI_ALL | LVNI_SELECTED);
  1424. }
  1425. else
  1426. {
  1427. *piIndex = -1;
  1428. }
  1429. }
  1430. INT_PTR CCompPropSheetPage::_CustomizeDlgProcHelper(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam, INT iPage)
  1431. {
  1432. CCompPropSheetPage * pThis;
  1433. if (WM_INITDIALOG == wMsg)
  1434. {
  1435. pThis = (CCompPropSheetPage *) ((PROPSHEETPAGE*)lParam)->lParam;
  1436. if (pThis)
  1437. {
  1438. SetWindowLongPtr(hDlg, DWLP_USER, (LPARAM) pThis);
  1439. }
  1440. }
  1441. else
  1442. {
  1443. pThis = (CCompPropSheetPage *)GetWindowLongPtr(hDlg, DWLP_USER);
  1444. }
  1445. if (pThis)
  1446. return pThis->_CustomizeDlgProc(hDlg, wMsg, wParam, lParam, iPage);
  1447. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  1448. }
  1449. INT_PTR CALLBACK CCompPropSheetPage::CustomizeDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  1450. {
  1451. return _CustomizeDlgProcHelper(hDlg, wMsg, wParam, lParam, CUSTOMIZE_DLGPROC);
  1452. }
  1453. INT_PTR CALLBACK CCompPropSheetPage::WebDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  1454. {
  1455. return _CustomizeDlgProcHelper(hDlg, wMsg, wParam, lParam, CUSTOMIZE_WEB_DLGPROC);
  1456. }
  1457. BOOL_PTR CCompPropSheetPage::_CustomizeDlgProc(HWND hdlg, UINT uMsg, WPARAM wParam, LPARAM lParam, INT iPage)
  1458. {
  1459. switch(uMsg)
  1460. {
  1461. case WM_INITDIALOG:
  1462. _OnInitDialog(hdlg, iPage);
  1463. break;
  1464. case WM_NOTIFY:
  1465. _OnNotify(hdlg, wParam, (LPNMHDR)lParam);
  1466. break;
  1467. case WM_COMMAND:
  1468. _OnCommand(hdlg, HIWORD(wParam), LOWORD(wParam), (HWND)lParam);
  1469. break;
  1470. case WM_SETTINGCHANGE:
  1471. //Check if this is a shell StateChange?
  1472. if(lstrcmpi((LPTSTR)(lParam), TEXT("ShellState")) == 0)
  1473. {
  1474. //Check if the StartPanel on/off state has changed.
  1475. SHELLSTATE ss = {0};
  1476. SHGetSetSettings(&ss, SSF_STARTPANELON, FALSE); //See if the StartPanel is on!
  1477. //See if the StartPanel on/off state has changed
  1478. if(BOOLIFY(ss.fStartPanelOn) != BOOLIFY((BOOL)_iStartPanelOn))
  1479. {
  1480. _iStartPanelOn = (ss.fStartPanelOn ? 1 : 0); //Save the new state.
  1481. //Refresh the UI based on the new state.
  1482. _UpdateDesktopIconsUI(hdlg);
  1483. }
  1484. }
  1485. // Intentional fallthrough....
  1486. case WM_SYSCOLORCHANGE:
  1487. case WM_DISPLAYCHANGE:
  1488. SHPropagateMessage(hdlg, uMsg, wParam, lParam, TRUE);
  1489. break;
  1490. case WM_DESTROY:
  1491. _OnDestroy(iPage);
  1492. break;
  1493. case WM_COMP_GETCURSEL:
  1494. _OnGetCurSel((int *)lParam);
  1495. break;
  1496. case WM_HELP:
  1497. WinHelp((HWND)((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_DESKTOPITEMS, HELP_WM_HELP, (ULONG_PTR)(void *)aDesktopItemsHelpIDs);
  1498. break;
  1499. case WM_CONTEXTMENU:
  1500. WinHelp((HWND) wParam, SZ_HELPFILE_DESKTOPITEMS, HELP_CONTEXTMENU, (ULONG_PTR)(void *) aDesktopItemsHelpIDs);
  1501. break;
  1502. }
  1503. return FALSE;
  1504. }
  1505. HRESULT CCompPropSheetPage::_IsDirty(IN BOOL * pIsDirty)
  1506. {
  1507. HRESULT hr = E_INVALIDARG;
  1508. if (pIsDirty)
  1509. {
  1510. *pIsDirty = g_fDirtyAdvanced;
  1511. if (!*pIsDirty)
  1512. {
  1513. // Check if any of the icons have changed.
  1514. for (int nIndex = 0; nIndex < ARRAYSIZE(_IconData); nIndex++)
  1515. {
  1516. if ((_IconData[nIndex].iNewIndex != _IconData[nIndex].iOldIndex) ||
  1517. (StrCmpI(_IconData[nIndex].szNewFile, _IconData[nIndex].szOldFile)))
  1518. {
  1519. *pIsDirty = TRUE;
  1520. break;
  1521. }
  1522. }
  1523. }
  1524. hr = S_OK;
  1525. }
  1526. return hr;
  1527. }
  1528. HRESULT CCompPropSheetPage::DisplayAdvancedDialog(IN HWND hwndParent, IN IPropertyBag * pAdvPage, IN BOOL * pfEnableApply)
  1529. {
  1530. HRESULT hr = S_OK;
  1531. // Load State Into Advanced Dialog
  1532. *pfEnableApply = FALSE;
  1533. GetActiveDesktop(&g_pActiveDesk);
  1534. GetActiveDesktop(&g_pActiveDeskAdv);
  1535. ActiveDesktop_CopyState(g_pActiveDesk, g_pActiveDeskAdv);
  1536. hr = _LoadIconState(pAdvPage);
  1537. if (SUCCEEDED(hr))
  1538. {
  1539. hr = _LoadDeskIconState(pAdvPage);
  1540. if (SUCCEEDED(hr))
  1541. {
  1542. int iNumberOfPages = 2;
  1543. PROPSHEETPAGE psp = {0};
  1544. psp.dwSize = sizeof(psp);
  1545. psp.hInstance = HINST_THISDLL;
  1546. psp.dwFlags = PSP_DEFAULT;
  1547. psp.lParam = (LPARAM) this;
  1548. psp.pszTemplate = MAKEINTRESOURCE(IDD_CUSTOMIZE);
  1549. psp.pfnDlgProc = CCompPropSheetPage::CustomizeDlgProc;
  1550. HPROPSHEETPAGE rghpsp[2];
  1551. rghpsp[0] = CreatePropertySheetPage(&psp);
  1552. // Any of the following policies can disable the Web tab.
  1553. // 1. If no active desktop policy set, don't put up the property page
  1554. // 2. If policy is set to lock down active desktop, don't put up the
  1555. // property page
  1556. // 3. If policy is set to not allow components, don't put up the
  1557. // property page
  1558. if (((!SHRestricted(REST_FORCEACTIVEDESKTOPON)) && PolicyNoActiveDesktop()) || // 1.
  1559. (SHRestricted(REST_NOACTIVEDESKTOPCHANGES)) || // 2.
  1560. (SHRestricted(REST_NODESKCOMP)) || // 3.
  1561. (SHRestricted(REST_CLASSICSHELL))) // 4
  1562. {
  1563. // It's restricted, so don't add Web page.
  1564. iNumberOfPages = 1; //"General" page is the only page in this property sheet!
  1565. }
  1566. else
  1567. {
  1568. // No active desktop restriction! Go ahead and add the "Web" tab!
  1569. psp.pszTemplate = MAKEINTRESOURCE(IDD_CUSTOMIZE_WEB);
  1570. psp.pfnDlgProc = CCompPropSheetPage::WebDlgProc;
  1571. rghpsp[1] = CreatePropertySheetPage(&psp);
  1572. iNumberOfPages = 2; //"General" and "Web" are the two pages in this Property sheet!
  1573. }
  1574. PROPSHEETHEADER psh = {0};
  1575. psh.dwSize = sizeof(psh);
  1576. psh.dwFlags = PSH_NOAPPLYNOW;
  1577. psh.hwndParent = hwndParent;
  1578. psh.hInstance = HINST_THISDLL;
  1579. TCHAR szTitle[MAX_PATH];
  1580. LoadString(HINST_THISDLL, IDS_PROPSHEET_TITLE, szTitle, ARRAYSIZE(szTitle));
  1581. psh.pszCaption = szTitle;
  1582. psh.nPages = iNumberOfPages;
  1583. psh.phpage = rghpsp;
  1584. _fCustomizeDesktopOK = FALSE;
  1585. PropertySheet(&psh);
  1586. if (_fCustomizeDesktopOK)
  1587. {
  1588. // The user clicked OK, so merge modified state back into base dialog
  1589. _IsDirty(pfEnableApply);
  1590. // The user clicked Okay in the dialog so merge the dirty state from the
  1591. // advanced dialog into the base dialog.
  1592. MergeState();
  1593. _MergeIconState(pAdvPage);
  1594. _MergeDeskIconState(pAdvPage);
  1595. }
  1596. // If the user selected to open the component gallery in Web->New, then
  1597. // we want to close both the Advanced dlg and the base Dlg with "OK".
  1598. // This way we persist the changes they have made so far, and then the web
  1599. // page will allow them to add more.
  1600. if (TRUE == g_fLaunchGallery)
  1601. {
  1602. IThemeUIPages * pThemeUIPages;
  1603. HWND hwndBasePropDlg = GetParent(hwndParent);
  1604. PropSheet_PressButton(hwndBasePropDlg, PSBTN_OK);
  1605. hr = IUnknown_GetSite(pAdvPage, IID_PPV_ARG(IThemeUIPages, &pThemeUIPages));
  1606. if (SUCCEEDED(hr))
  1607. {
  1608. // We now want to tell the base dialog to close too.
  1609. hr = pThemeUIPages->ApplyPressed(TUIAP_CLOSE_DIALOG);
  1610. pThemeUIPages->Release();
  1611. }
  1612. }
  1613. }
  1614. }
  1615. ReleaseActiveDesktop(&g_pActiveDesk);
  1616. ReleaseActiveDesktop(&g_pActiveDeskAdv);
  1617. return hr;
  1618. }
  1619. ULONG CCompPropSheetPage::AddRef()
  1620. {
  1621. _cRef++;
  1622. return _cRef;
  1623. }
  1624. ULONG CCompPropSheetPage::Release()
  1625. {
  1626. ASSERT(_cRef > 0);
  1627. _cRef--;
  1628. if (_cRef > 0)
  1629. return _cRef;
  1630. delete this;
  1631. return 0;
  1632. }
  1633. HRESULT CCompPropSheetPage::QueryInterface(REFIID riid, void **ppvObj)
  1634. {
  1635. HRESULT hr = E_NOINTERFACE;
  1636. static const QITAB qit[] = {
  1637. QITABENT(CCompPropSheetPage, IObjectWithSite),
  1638. QITABENT(CCompPropSheetPage, IAdvancedDialog),
  1639. { 0 },
  1640. };
  1641. return QISearch(this, qit, riid, ppvObj);
  1642. }
  1643. CCompPropSheetPage::CCompPropSheetPage() : _iPreviousSelection(-1), _cRef(1)
  1644. {
  1645. _fInitialized = FALSE;
  1646. _fLaunchGallery = FALSE;
  1647. _punkSite = NULL;
  1648. _hWndList = NULL;
  1649. _hIconList = NULL;
  1650. _fLockDesktopItems = GetDesktopFlags() & COMPONENTS_LOCKED;
  1651. // We don't need to do any work here but it's a good cue to
  1652. // reset our state because the Advance dialog is opening.
  1653. g_fDirtyAdvanced = FALSE; // The advanced page isn't dirty yet.
  1654. g_fLaunchGallery = FALSE; // Will be true if they launch the gallery.
  1655. RegisterCompPreviewClass();
  1656. }
  1657. CCompPropSheetPage::~CCompPropSheetPage()
  1658. {
  1659. }
  1660. //
  1661. // The following function updates the registry such that the given icon can be hidden or shown
  1662. // on the desktop.
  1663. // This function is called from RegFldr.cpp to selectively hide RegItems like MyComputer,
  1664. // RecycleBin, MyDocuments and MyNetplaces Icons.
  1665. //
  1666. HRESULT ShowHideIconOnlyOnDesktop(const CLSID *pclsid, int StartIndex, int EndIndex, BOOL fHide)
  1667. {
  1668. HRESULT hr = S_OK;
  1669. int iStartPanel;
  1670. TCHAR szRegPath[MAX_PATH];
  1671. TCHAR szValueName[MAX_GUID_STRING_LEN];
  1672. SHStringFromGUID(*pclsid, szValueName, ARRAYSIZE(szValueName));
  1673. // i = 0 is for StartPanel off and i = 1 is for StartPanel ON!
  1674. for(iStartPanel = StartIndex; SUCCEEDED(hr) && iStartPanel <= EndIndex; iStartPanel++)
  1675. {
  1676. //Get the proper registry path based on if StartPanel is ON/OFF
  1677. hr = StringCchPrintf(szRegPath, ARRAYSIZE(szRegPath), REGSTR_PATH_HIDDEN_DESKTOP_ICONS, c_apstrRegLocation[iStartPanel]);
  1678. if (SUCCEEDED(hr))
  1679. {
  1680. //Write the setting to the registry!
  1681. DWORD dwHide = (DWORD)fHide;
  1682. LONG lRet = SHRegSetUSValue(szRegPath, szValueName, REG_DWORD, &dwHide, sizeof(dwHide), SHREGSET_FORCE_HKCU);
  1683. hr = HRESULT_FROM_WIN32(lRet);
  1684. }
  1685. }
  1686. return hr;
  1687. }