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.

965 lines
34 KiB

  1. #include "precomp.h"
  2. #include "rsop.h"
  3. #include "favsproc.h"
  4. #include <tchar.h>
  5. static INT_PTR CALLBACK addEditFavoriteRSoPProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  6. /////////////////////////////////////////////////////////////////////
  7. struct _FAV4RSOP
  8. {
  9. WORD wType;
  10. TCHAR szName[MAX_PATH];
  11. TCHAR szDisplayName[MAX_PATH];
  12. TCHAR szUrl[INTERNET_MAX_URL_LENGTH];
  13. TCHAR szIconFile[MAX_PATH];
  14. BOOL fOffline;
  15. };
  16. typedef _FAV4RSOP FAV4RSOP, *LPFAV4RSOP;
  17. //////////////////////////////////////////////////////////////////////
  18. BOOL ItemHasText(HWND htv, HTREEITEM hti, LPCTSTR szText)
  19. {
  20. BOOL bRet = FALSE;
  21. __try
  22. {
  23. if (NULL != hti)
  24. {
  25. TCHAR szBuffer[MAX_PATH];
  26. TVITEM tvi;
  27. ZeroMemory((void*)&tvi, sizeof(tvi));
  28. tvi.hItem = hti;
  29. tvi.mask = TVIF_TEXT;
  30. tvi.pszText = szBuffer;
  31. tvi.cchTextMax = countof(szBuffer);
  32. if (TreeView_GetItem(htv, &tvi))
  33. bRet = (!StrCmpI(tvi.pszText, szText)) ? TRUE : FALSE;
  34. }
  35. }
  36. __except(TRUE)
  37. {
  38. ASSERT(0);
  39. }
  40. return bRet;
  41. }
  42. //////////////////////////////////////////////////////////////////////
  43. LPARAM GetTVItemLParam(HWND htv, HTREEITEM hti)
  44. {
  45. LPARAM lpResult = 0;
  46. __try
  47. {
  48. if (NULL != hti)
  49. {
  50. TVITEM tvi;
  51. ZeroMemory((void*)&tvi, sizeof(tvi));
  52. tvi.hItem = hti;
  53. tvi.mask = TVIF_PARAM;
  54. if (TreeView_GetItem(htv, &tvi))
  55. lpResult = tvi.lParam;
  56. }
  57. }
  58. __except(TRUE)
  59. {
  60. ASSERT(0);
  61. }
  62. return lpResult;
  63. }
  64. /////////////////////////////////////////////////////////////////////
  65. void DestroyTVItemData(HWND htv, HTREEITEM hti)
  66. {
  67. __try
  68. {
  69. HTREEITEM htiCur = hti;
  70. if (NULL == hti)
  71. htiCur = TreeView_GetRoot(htv);
  72. HTREEITEM htiFirstChild = TreeView_GetChild(htv, htiCur);
  73. if (NULL != htiFirstChild)
  74. DestroyTVItemData(htv, htiFirstChild);
  75. while (NULL != htiCur)
  76. {
  77. htiCur = TreeView_GetNextSibling(htv, htiCur);
  78. if (NULL != htiCur)
  79. DestroyTVItemData(htv, htiCur);
  80. }
  81. LPARAM lp = GetTVItemLParam(htv, hti);
  82. if (NULL != hti && NULL != (void*)lp)
  83. CoTaskMemFree((void*)lp);
  84. }
  85. __except(TRUE)
  86. {
  87. }
  88. }
  89. /////////////////////////////////////////////////////////////////////
  90. HTREEITEM FindFolderItem(HWND htv, LPCTSTR szText, HTREEITEM htiParent = NULL)
  91. {
  92. HTREEITEM htiResult = NULL;
  93. __try
  94. {
  95. HTREEITEM htiFirstChild = NULL;
  96. if (NULL == htiParent)
  97. {
  98. HTREEITEM htiTempParent = TreeView_GetRoot(htv);
  99. htiFirstChild = TreeView_GetNextSibling(htv, TreeView_GetChild(htv, htiTempParent));
  100. }
  101. else
  102. htiFirstChild = TreeView_GetChild(htv, htiParent);
  103. // pass the "Favorites" marker at the top - 1st child of root
  104. HTREEITEM htiCur = htiFirstChild;
  105. while (NULL != htiCur)
  106. {
  107. // look at the current folder
  108. if (ItemHasText(htv, htiCur, szText))
  109. break;
  110. // then the folder's children
  111. htiCur = FindFolderItem(htv, szText, htiCur);
  112. if (ItemHasText(htv, htiCur, szText))
  113. break;
  114. // then the folder's siblings
  115. htiCur = TreeView_GetNextSibling(htv, htiCur);
  116. }
  117. htiResult = htiCur;
  118. }
  119. __except(TRUE)
  120. {
  121. }
  122. return htiResult;
  123. }
  124. /////////////////////////////////////////////////////////////////////
  125. HTREEITEM InsertTreeItem(HWND htv, LPFAV4RSOP pFav, LPCTSTR szText, WORD wType,
  126. HTREEITEM htiParent = NULL, HTREEITEM htiPrevious = NULL,
  127. UINT nChildren = 0)
  128. {
  129. HTREEITEM htiResult = NULL;
  130. __try
  131. {
  132. if (NULL != pFav)
  133. {
  134. LPFAV4RSOP pNewFav = (LPFAV4RSOP)CoTaskMemAlloc(sizeof(FAV4RSOP));
  135. if (NULL != pNewFav)
  136. {
  137. pNewFav->wType = wType;
  138. StrCpy(pNewFav->szDisplayName, szText);
  139. StrCpy(pNewFav->szName, pFav->szName);
  140. StrCpy(pNewFav->szUrl, pFav->szUrl);
  141. StrCpy(pNewFav->szIconFile, pFav->szIconFile);
  142. pNewFav->fOffline = pFav->fOffline;
  143. TV_ITEM tvi;
  144. ZeroMemory(&tvi, sizeof(tvi));
  145. tvi.mask = TVIF_TEXT | TVIF_PARAM;
  146. if (pFav->wType != FTYPE_URL)
  147. {
  148. tvi.mask |= TVIF_CHILDREN;
  149. tvi.cChildren = nChildren;
  150. }
  151. if (pFav->wType != FTYPE_URL && pFav->wType != FTYPE_FOLDER)
  152. {
  153. tvi.mask |= TVIF_STATE;
  154. tvi.stateMask = TVIS_BOLD;
  155. tvi.state = TVIS_BOLD;
  156. }
  157. tvi.lParam = (LPARAM)pNewFav;
  158. tvi.pszText = (LPTSTR)pNewFav->szDisplayName;
  159. tvi.cchTextMax = StrLen(pNewFav->szDisplayName) + 1;
  160. TVINSERTSTRUCT tvins;
  161. ZeroMemory(&tvins, sizeof(tvins));
  162. tvins.hParent = htiParent;
  163. tvins.hInsertAfter = htiPrevious;
  164. CopyMemory(&tvins.item, &tvi, sizeof(tvi));
  165. htiResult = TreeView_InsertItem(htv, &tvins);
  166. }
  167. }
  168. }
  169. __except(TRUE)
  170. {
  171. }
  172. return htiResult;
  173. }
  174. /////////////////////////////////////////////////////////////////////
  175. HTREEITEM InsertFavoriteItem(HWND htv, LPFAV4RSOP pFav, LPCTSTR szRemainingPath,
  176. HTREEITEM htiPrevious, HTREEITEM htiParent = NULL,
  177. BOOL bLink = FALSE)
  178. {
  179. HTREEITEM htiResult = NULL;
  180. __try
  181. {
  182. // Find the first folder in the path
  183. LPTSTR szSlash = StrChr(szRemainingPath, _T('\\'));
  184. if (NULL != szSlash)
  185. {
  186. TCHAR szCurFolder[MAX_PATH];
  187. ZeroMemory(szCurFolder, countof(szCurFolder));
  188. StrCpyN(szCurFolder, szRemainingPath, (int)(szSlash - szRemainingPath) + 1);
  189. // See if the folder exists in the tree
  190. // If so, store the HTREEITEM in a param.
  191. HTREEITEM htiCurFolder = FindFolderItem(htv, szCurFolder, htiParent);
  192. if (NULL == htiCurFolder)
  193. {
  194. // If not, create the folder with the lParam set to NULL.
  195. htiCurFolder = InsertTreeItem(htv, pFav, szCurFolder, FTYPE_FOLDER,
  196. htiParent, htiPrevious);
  197. }
  198. // Pass the remainder of the string to InsertFavoriteItem
  199. htiResult = InsertFavoriteItem(htv, pFav, ++szSlash, htiPrevious,
  200. htiCurFolder, bLink);
  201. }
  202. else
  203. {
  204. // If no more folders, create a new item under current folder
  205. htiResult = InsertTreeItem(htv, pFav, szRemainingPath, FTYPE_URL,
  206. htiParent, htiPrevious);
  207. TreeView_Expand(htv, htiParent, TVE_EXPAND);
  208. }
  209. }
  210. __except(TRUE)
  211. {
  212. }
  213. return htiResult;
  214. }
  215. /////////////////////////////////////////////////////////////////////
  216. DWORD AddItemsToTree(HWND hwndTree, CDlgRSoPData *pDRD, BSTR bstrTempClass,
  217. BOOL bLink)
  218. {
  219. DWORD dwRet = 0;
  220. __try
  221. {
  222. _bstr_t bstrClass = bstrTempClass;
  223. CPSObjData **paFavObj = NULL;
  224. long nFavObjects = 0;
  225. HRESULT hr = pDRD->GetArrayOfPSObjects(bstrClass, L"rsopPrecedence",
  226. &paFavObj, &nFavObjects);
  227. if (SUCCEEDED(hr))
  228. {
  229. FAV4RSOP tempFav;
  230. ZeroMemory(&tempFav, sizeof(FAV4RSOP));
  231. // Add "Favorites" or "Links" entry to tree
  232. LoadString(g_hUIInstance, bLink ? IDS_LINKS : IDS_FAVFOLDER,
  233. tempFav.szName, countof(tempFav.szName));
  234. HTREEITEM htiParent = InsertTreeItem(hwndTree, &tempFav, tempFav.szName, FTYPE_UNUSED,
  235. NULL, TVI_LAST, nFavObjects);
  236. // For each favorite returned from any GPO
  237. long nObj;
  238. for (nObj = 0; nObj < nFavObjects; nObj++)
  239. {
  240. _bstr_t bstrGPOName = L" (";
  241. bstrGPOName += pDRD->GetGPONameFromPSAssociation(paFavObj[nObj]->pObj,
  242. L"rsopPrecedence") +
  243. L")";
  244. tempFav.wType = FTYPE_URL;
  245. // name field
  246. _variant_t vtValue;
  247. hr = paFavObj[nObj]->pObj->Get(L"name", 0, &vtValue, NULL, NULL);
  248. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  249. {
  250. _bstr_t bstrValue = vtValue;
  251. _bstr_t bstrEntry = bstrValue + bstrGPOName;
  252. StrCpy(tempFav.szName, (LPCTSTR)bstrValue);
  253. // url field
  254. hr = paFavObj[nObj]->pObj->Get(L"url", 0, &vtValue, NULL, NULL);
  255. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  256. {
  257. bstrValue = vtValue;
  258. StrCpy(tempFav.szUrl, (LPCTSTR)bstrValue);
  259. }
  260. // iconPath field
  261. hr = paFavObj[nObj]->pObj->Get(L"iconPath", 0, &vtValue, NULL, NULL);
  262. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  263. {
  264. bstrValue = vtValue;
  265. StrCpy(tempFav.szIconFile, (LPCTSTR)bstrValue);
  266. }
  267. // makeAvailableOffline field
  268. hr = paFavObj[nObj]->pObj->Get(L"makeAvailableOffline", 0, &vtValue, NULL, NULL);
  269. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  270. tempFav.fOffline = (bool)vtValue ? TRUE : FALSE;
  271. InsertFavoriteItem(hwndTree, &tempFav, (LPCTSTR)bstrEntry, NULL, htiParent, bLink);
  272. }
  273. }
  274. dwRet = nObj;
  275. }
  276. }
  277. __except(TRUE)
  278. {
  279. }
  280. return dwRet;
  281. }
  282. /////////////////////////////////////////////////////////////////////
  283. DWORD InitFavsDlgInRSoPMode(HWND hDlg, CDlgRSoPData *pDRD)
  284. {
  285. DWORD dwRet = 0;
  286. __try
  287. {
  288. // First go through all PS objects and look for favorites data
  289. _bstr_t bstrClass = L"RSOP_IEAKPolicySetting";
  290. HRESULT hr = pDRD->GetArrayOfPSObjects(bstrClass);
  291. if (SUCCEEDED(hr))
  292. {
  293. CPSObjData **paPSObj = pDRD->GetPSObjArray();
  294. long nPSObjects = pDRD->GetPSObjCount();
  295. BOOL bPlaceAtTopHandled = FALSE;
  296. BOOL bDeleteHandled = FALSE;
  297. for (long nObj = 0; nObj < nPSObjects; nObj++)
  298. {
  299. // placeFavoritesAtTopOfList field
  300. _variant_t vtValue;
  301. if (!bPlaceAtTopHandled)
  302. {
  303. hr = paPSObj[nObj]->pObj->Get(L"placeFavoritesAtTopOfList", 0, &vtValue, NULL, NULL);
  304. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  305. {
  306. if ((bool)vtValue)
  307. CheckDlgButton(hDlg, IDC_FAVONTOP, BST_CHECKED);
  308. bPlaceAtTopHandled = TRUE;
  309. }
  310. }
  311. // deleteExistingChannels field
  312. if (!bDeleteHandled)
  313. {
  314. hr = paPSObj[nObj]->pObj->Get(L"deleteExistingChannels", 0, &vtValue, NULL, NULL);
  315. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  316. {
  317. if ((bool)vtValue)
  318. CheckDlgButton(hDlg, IDC_DELETECHANNELS, BST_CHECKED);
  319. bDeleteHandled = TRUE;
  320. }
  321. }
  322. // deleteExistingFavorites field
  323. if (!bDeleteHandled)
  324. {
  325. hr = paPSObj[nObj]->pObj->Get(L"deleteExistingFavorites", 0, &vtValue, NULL, NULL);
  326. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  327. {
  328. if ((bool)vtValue)
  329. CheckDlgButton(hDlg, IDC_DELFAVORITES, BST_CHECKED);
  330. bDeleteHandled = TRUE;
  331. // deleteAdminCreatedFavoritesOnly field
  332. hr = paPSObj[nObj]->pObj->Get(L"deleteAdminCreatedFavoritesOnly", 0, &vtValue, NULL, NULL);
  333. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  334. {
  335. if ((bool)vtValue)
  336. CheckDlgButton(hDlg, IDC_DELIEAKFAVORITES, BST_CHECKED);
  337. }
  338. }
  339. }
  340. // no need to process other GPOs since enabled properties have been found
  341. if (bPlaceAtTopHandled && bDeleteHandled)
  342. break;
  343. }
  344. }
  345. EnableDlgItem2(hDlg, IDC_FAVONTOP, FALSE);
  346. EnableDlgItem2(hDlg, IDC_DELFAVORITES, FALSE);
  347. EnableDlgItem2(hDlg, IDC_DELIEAKFAVORITES, FALSE);
  348. EnableDlgItem2(hDlg, IDC_DELETECHANNELS, FALSE);
  349. // Now go through all Favorite & Link objects and populate the tree ctrl
  350. HWND hwndTree = GetDlgItem(hDlg, IDC_TREE1);
  351. TreeView_DeleteAllItems(hwndTree);
  352. dwRet = AddItemsToTree(hwndTree, pDRD, L"RSOP_IEFavoriteItem", FALSE);
  353. dwRet += AddItemsToTree(hwndTree, pDRD, L"RSOP_IELinkItem", TRUE);
  354. TreeView_SelectItem(hwndTree, TreeView_GetRoot(hwndTree));
  355. EnableDlgItem2(hDlg, IDC_FAVUP, FALSE);
  356. EnableDlgItem2(hDlg, IDC_FAVDOWN, FALSE);
  357. EnableDlgItem2(hDlg, IDC_ADDURL, FALSE);
  358. EnableDlgItem2(hDlg, IDC_ADDFOLDER, FALSE);
  359. EnableDlgItem2(hDlg, IDC_MODIFY, FALSE);
  360. EnableDlgItem2(hDlg, IDC_REMOVE, FALSE);
  361. EnableDlgItem2(hDlg, IDC_TESTFAVURL, FALSE);
  362. EnableDlgItem2(hDlg, IDC_IMPORT, FALSE);
  363. }
  364. __except(TRUE)
  365. {
  366. }
  367. return dwRet;
  368. }
  369. /////////////////////////////////////////////////////////////////////
  370. HRESULT InitFavsPlacementPrecPage(CDlgRSoPData *pDRD, HWND hwndList)
  371. {
  372. HRESULT hr = NOERROR;
  373. __try
  374. {
  375. _bstr_t bstrClass = L"RSOP_IEAKPolicySetting";
  376. hr = pDRD->GetArrayOfPSObjects(bstrClass);
  377. if (SUCCEEDED(hr))
  378. {
  379. CPSObjData **paPSObj = pDRD->GetPSObjArray();
  380. long nPSObjects = pDRD->GetPSObjCount();
  381. for (long nObj = 0; nObj < nPSObjects; nObj++)
  382. {
  383. _bstr_t bstrGPOName = pDRD->GetGPONameFromPS(paPSObj[nObj]->pObj);
  384. // placeFavoritesAtTopOfList field
  385. BOOL bAtTop = FALSE;
  386. _variant_t vtValue;
  387. hr = paPSObj[nObj]->pObj->Get(L"placeFavoritesAtTopOfList", 0, &vtValue, NULL, NULL);
  388. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  389. bAtTop = (bool)vtValue ? TRUE : FALSE;
  390. _bstr_t bstrSetting;
  391. if (bAtTop)
  392. {
  393. TCHAR szTemp[MAX_PATH];
  394. LoadString(g_hInstance, IDS_PLACEATTOP_SETTING, szTemp, countof(szTemp));
  395. bstrSetting = szTemp;
  396. }
  397. else
  398. bstrSetting = GetDisabledString();
  399. InsertPrecedenceListItem(hwndList, nObj, bstrGPOName, bstrSetting);
  400. }
  401. }
  402. }
  403. __except(TRUE)
  404. {
  405. }
  406. return hr;
  407. }
  408. /////////////////////////////////////////////////////////////////////
  409. HRESULT InitFavsDeletionPrecPage(CDlgRSoPData *pDRD, HWND hwndList)
  410. {
  411. HRESULT hr = NOERROR;
  412. __try
  413. {
  414. _bstr_t bstrClass = L"RSOP_IEAKPolicySetting";
  415. hr = pDRD->GetArrayOfPSObjects(bstrClass);
  416. if (SUCCEEDED(hr))
  417. {
  418. CPSObjData **paPSObj = pDRD->GetPSObjArray();
  419. long nPSObjects = pDRD->GetPSObjCount();
  420. for (long nObj = 0; nObj < nPSObjects; nObj++)
  421. {
  422. _bstr_t bstrGPOName = pDRD->GetGPONameFromPS(paPSObj[nObj]->pObj);
  423. // deleteExistingFavorites field
  424. BOOL bDeleteExisting = FALSE;
  425. BOOL bAdminOnly = FALSE;
  426. _variant_t vtValue;
  427. hr = paPSObj[nObj]->pObj->Get(L"deleteExistingFavorites", 0, &vtValue, NULL, NULL);
  428. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  429. // deleteAdminCreatedFavoritesOnly field
  430. hr = paPSObj[nObj]->pObj->Get(L"deleteExistingFavorites", 0, &vtValue, NULL, NULL);
  431. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  432. {
  433. bDeleteExisting = (bool)vtValue ? TRUE : FALSE;
  434. // deleteAdminCreatedFavoritesOnly field
  435. hr = paPSObj[nObj]->pObj->Get(L"deleteAdminCreatedFavoritesOnly", 0, &vtValue, NULL, NULL);
  436. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  437. bAdminOnly = (bool)vtValue;
  438. }
  439. _bstr_t bstrSetting;
  440. if (bDeleteExisting > 0)
  441. {
  442. TCHAR szTemp[MAX_PATH];
  443. if (bAdminOnly)
  444. LoadString(g_hInstance, IDS_DELADMINCREATED_SETTING, szTemp, countof(szTemp));
  445. else
  446. LoadString(g_hInstance, IDS_DELEXISTING_SETTING, szTemp, countof(szTemp));
  447. bstrSetting = szTemp;
  448. }
  449. else
  450. bstrSetting = GetDisabledString();
  451. InsertPrecedenceListItem(hwndList, nObj, bstrGPOName, bstrSetting);
  452. }
  453. }
  454. }
  455. __except(TRUE)
  456. {
  457. }
  458. return hr;
  459. }
  460. /////////////////////////////////////////////////////////////////////
  461. HRESULT InitFavsPrecPage(CDlgRSoPData *pDRD, HWND hwndList)
  462. {
  463. HRESULT hr = NOERROR;
  464. __try
  465. {
  466. _bstr_t bstrClass = L"RSOP_IEAKPolicySetting";
  467. hr = pDRD->GetArrayOfPSObjects(bstrClass);
  468. if (SUCCEEDED(hr))
  469. {
  470. CPSObjData **paPSObj = pDRD->GetPSObjArray();
  471. long nPSObjects = pDRD->GetPSObjCount();
  472. for (long nObj = 0; nObj < nPSObjects; nObj++)
  473. {
  474. _bstr_t bstrGPOName = pDRD->GetGPONameFromPS(paPSObj[nObj]->pObj);
  475. // customFavorites field
  476. long nFavs = 0, nLinks = 0;
  477. _variant_t vtValue;
  478. hr = paPSObj[nObj]->pObj->Get(L"customFavorites", 0, &vtValue, NULL, NULL);
  479. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  480. nFavs = vtValue;
  481. // customLinks field
  482. hr = paPSObj[nObj]->pObj->Get(L"customLinks", 0, &vtValue, NULL, NULL);
  483. if (SUCCEEDED(hr) && !IsVariantNull(vtValue))
  484. nLinks = vtValue;
  485. _bstr_t bstrSetting;
  486. if (nFavs > 0 || nLinks > 0)
  487. {
  488. TCHAR szTemp[MAX_PATH];
  489. LoadString(g_hInstance, IDS_FAVS_AND_LINKS_SETTING, szTemp, countof(szTemp));
  490. TCHAR szSetting[MAX_PATH];
  491. wnsprintf(szSetting, countof(szSetting), szTemp, nFavs, nLinks);
  492. bstrSetting = szSetting;
  493. }
  494. else
  495. bstrSetting = GetDisabledString();
  496. InsertPrecedenceListItem(hwndList, nObj, bstrGPOName, bstrSetting);
  497. }
  498. }
  499. }
  500. __except(TRUE)
  501. {
  502. }
  503. return hr;
  504. }
  505. /////////////////////////////////////////////////////////////////////
  506. INT_PTR CALLBACK FavoritesDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  507. {
  508. // Retrieve Property Sheet Page info for each call into dlg proc.
  509. LPPROPSHEETCOOKIE psCookie = (LPPROPSHEETCOOKIE)GetWindowLongPtr(hDlg, DWLP_USER);
  510. TCHAR szWorkDir[MAX_PATH],
  511. szValue[16],
  512. szUrl[INTERNET_MAX_URL_LENGTH];
  513. HWND htv = GetDlgItem(hDlg, IDC_TREE1);
  514. LPCTSTR pszValue;
  515. BOOL fQL,
  516. fFavoritesOnTop, fFavoritesDelete, fIEAKFavoritesDelete;
  517. DWORD dwFavoritesDeleteFlags;
  518. switch (msg) {
  519. case WM_SETFONT:
  520. //a change to mmc requires us to do this logic for all our property pages that use common controls
  521. INITCOMMONCONTROLSEX iccx;
  522. iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  523. iccx.dwICC = ICC_ANIMATE_CLASS | ICC_BAR_CLASSES | ICC_LISTVIEW_CLASSES |ICC_TREEVIEW_CLASSES;
  524. InitCommonControlsEx(&iccx);
  525. break;
  526. case WM_INITDIALOG:
  527. SetPropSheetCookie(hDlg, lParam);
  528. EnableDBCSChars(hDlg, IDC_TREE1);
  529. ReadBoolAndCheckButton(IS_DESKTOPOBJS, IK_DELETECHANNELS, FALSE, GetInsFile(hDlg),
  530. hDlg, IDC_DELETECHANNELS);
  531. // find out if this dlg is in RSoP mode
  532. psCookie = (LPPROPSHEETCOOKIE)GetWindowLongPtr(hDlg, DWLP_USER);
  533. if (psCookie->pCS->IsRSoP())
  534. {
  535. TCHAR szView[64];
  536. LoadString(g_hInstance, IDS_VIEW, szView, countof(szView));
  537. SetDlgItemText(hDlg, IDC_MODIFY, szView);
  538. CDlgRSoPData *pDRD = GetDlgRSoPData(hDlg, psCookie->pCS);
  539. InitFavsDlgInRSoPMode(hDlg, pDRD);
  540. }
  541. else
  542. {
  543. MigrateFavorites(GetInsFile(hDlg));
  544. }
  545. #ifdef _UNICODE
  546. TreeView_SetUnicodeFormat(htv, TRUE);
  547. #else
  548. TreeView_SetUnicodeFormat(htv, FALSE);
  549. #endif
  550. break;
  551. case WM_DESTROY:
  552. if (psCookie->pCS->IsRSoP())
  553. {
  554. DestroyDlgRSoPData(hDlg);
  555. DestroyTVItemData(htv, NULL);
  556. }
  557. break;
  558. case WM_COMMAND:
  559. if (BN_CLICKED != GET_WM_COMMAND_CMD(wParam, lParam))
  560. return FALSE;
  561. switch (GET_WM_COMMAND_ID(wParam, lParam)) {
  562. case IDC_FAVONTOP:
  563. if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_FAVONTOP)) {
  564. HTREEITEM hti;
  565. TV_ITEM tvi;
  566. EnableDlgItem(hDlg, IDC_FAVONTOP);
  567. hti = TreeView_GetSelection(htv);
  568. if (NULL != hti) {
  569. ZeroMemory(&tvi, sizeof(tvi));
  570. tvi.mask = TVIF_STATE;
  571. tvi.hItem = hti;
  572. TreeView_GetItem(htv, &tvi);
  573. if (!HasFlag(tvi.state, TVIS_BOLD)) {
  574. EnableDlgItem2(hDlg, IDC_FAVUP, (NULL != TreeView_GetPrevSibling(htv, hti)));
  575. EnableDlgItem2(hDlg, IDC_FAVDOWN, (NULL != TreeView_GetNextSibling(htv, hti)));
  576. }
  577. }
  578. }
  579. else {
  580. DisableDlgItem(hDlg, IDC_FAVUP);
  581. DisableDlgItem(hDlg, IDC_FAVDOWN);
  582. }
  583. break;
  584. case IDC_DELFAVORITES:
  585. fFavoritesDelete = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_DELFAVORITES));
  586. EnableWindow(GetDlgItem(hDlg, IDC_DELIEAKFAVORITES), fFavoritesDelete);
  587. break;
  588. case IDC_FAVUP:
  589. MoveUpFavorite(htv, TreeView_GetSelection(htv));
  590. break;
  591. case IDC_FAVDOWN:
  592. MoveDownFavorite(htv, TreeView_GetSelection(htv));
  593. break;
  594. case IDC_ADDURL:
  595. fQL = !IsFavoriteItem(htv, TreeView_GetSelection(htv));
  596. if (GetFavoritesNumber(htv, fQL) >= GetFavoritesMaxNumber(fQL)) {
  597. UINT nID;
  598. nID = (!fQL ? IDS_ERROR_MAXFAVS : IDS_ERROR_MAXQLS);
  599. ErrorMessageBox(hDlg, nID);
  600. break;
  601. }
  602. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\favs"), szWorkDir);
  603. NewUrl(htv, szWorkDir, PLATFORM_WIN32, IEM_GP);
  604. break;
  605. case IDC_ADDFOLDER:
  606. ASSERT(IsFavoriteItem(htv, TreeView_GetSelection(htv)));
  607. if (GetFavoritesNumber(htv) >= GetFavoritesMaxNumber()) {
  608. ErrorMessageBox(hDlg, IDS_ERROR_MAXFAVS);
  609. break;
  610. }
  611. NewFolder(htv);
  612. break;
  613. case IDC_MODIFY:
  614. if (psCookie->pCS->IsRSoP())
  615. {
  616. LPFAV4RSOP pFav = (LPFAV4RSOP)GetTVItemLParam(htv, TreeView_GetSelection(htv));
  617. if (NULL != pFav)
  618. {
  619. DialogBoxParam(g_hUIInstance, MAKEINTRESOURCE(IDD_FAVPOPUP), GetParent(htv),
  620. addEditFavoriteRSoPProc, (LPARAM)pFav);
  621. }
  622. }
  623. else
  624. {
  625. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\favs"), szWorkDir);
  626. ModifyFavorite(htv, TreeView_GetSelection(htv), szWorkDir, szWorkDir, PLATFORM_WIN32, IEM_GP);
  627. }
  628. break;
  629. case IDC_REMOVE:
  630. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\favs"), szWorkDir);
  631. DeleteFavorite(htv, TreeView_GetSelection(htv), szWorkDir);
  632. break;
  633. case IDC_TESTFAVURL:
  634. if (GetFavoriteUrl(htv, TreeView_GetSelection(htv), szUrl, countof(szUrl)))
  635. TestURL(szUrl);
  636. break;
  637. case IDC_IMPORT: {
  638. CNewCursor cursor(IDC_WAIT);
  639. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\favs"), szWorkDir);
  640. ImportFavoritesCmd(htv, szWorkDir);
  641. break;
  642. }
  643. default:
  644. return FALSE;
  645. }
  646. break;
  647. case WM_NOTIFY:
  648. switch (((LPNMHDR)lParam)->code) {
  649. case PSN_SETACTIVE:
  650. // don't do any of this stuff in RSoP mode
  651. if (!psCookie->pCS->IsRSoP())
  652. {
  653. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\favs"), szWorkDir);
  654. ASSERT(0 == GetFavoritesNumber(htv, FALSE) && 0 == GetFavoritesNumber(htv, TRUE));
  655. ImportFavorites (htv, NULL, GetInsFile(hDlg), szWorkDir, NULL, FALSE);
  656. ImportQuickLinks(htv, NULL, GetInsFile(hDlg), szWorkDir, NULL, FALSE);
  657. TreeView_SelectItem(htv, TreeView_GetRoot(htv));
  658. fFavoritesOnTop = InsGetBool(IS_BRANDING, IK_FAVORITES_ONTOP, FALSE, GetInsFile(hDlg));
  659. CheckDlgButton(hDlg, IDC_FAVONTOP, fFavoritesOnTop ? BST_CHECKED : BST_UNCHECKED);
  660. if (!fFavoritesOnTop) {
  661. DisableDlgItem(hDlg, IDC_FAVUP);
  662. DisableDlgItem(hDlg, IDC_FAVDOWN);
  663. }
  664. dwFavoritesDeleteFlags = (DWORD)InsGetInt(IS_BRANDING, IK_FAVORITES_DELETE, (int)FD_DEFAULT, GetInsFile(hDlg));
  665. fFavoritesDelete = HasFlag(dwFavoritesDeleteFlags, ~FD_REMOVE_IEAK_CREATED);
  666. CheckDlgButton(hDlg, IDC_DELFAVORITES, fFavoritesDelete ? BST_CHECKED : BST_UNCHECKED);
  667. fIEAKFavoritesDelete = HasFlag(dwFavoritesDeleteFlags, FD_REMOVE_IEAK_CREATED);
  668. CheckDlgButton(hDlg, IDC_DELIEAKFAVORITES, fIEAKFavoritesDelete ? BST_CHECKED : BST_UNCHECKED);
  669. // only if delete Favorites is TRUE should the delete IEAK Favorites checkbox be enabled
  670. EnableWindow(GetDlgItem(hDlg, IDC_DELIEAKFAVORITES), fFavoritesDelete);
  671. }
  672. break;
  673. case TVN_GETINFOTIP:
  674. ASSERT(IDC_TREE1 == wParam);
  675. if (!psCookie->pCS->IsRSoP())
  676. GetFavoritesInfoTip((LPNMTVGETINFOTIP)lParam);
  677. break;
  678. case NM_DBLCLK:
  679. ASSERT(IDC_TREE1 == wParam);
  680. if (IsWindowEnabled(GetDlgItem(hDlg, IDC_MODIFY)))
  681. SendMessage(hDlg, WM_COMMAND, GET_WM_COMMAND_MPS(IDC_MODIFY, GetDlgItem(hDlg, IDC_MODIFY), BN_CLICKED));
  682. break;
  683. case TVN_KEYDOWN:
  684. ASSERT(wParam == IDC_TREE1);
  685. if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_DELETE && IsWindowEnabled(GetDlgItem(hDlg, IDC_REMOVE)))
  686. SendMessage(hDlg, WM_COMMAND, GET_WM_COMMAND_MPS(IDC_REMOVE, GetDlgItem(hDlg, IDC_REMOVE), BN_CLICKED));
  687. break;
  688. case TVN_SELCHANGED:
  689. ASSERT(IDC_TREE1 == wParam);
  690. if (psCookie->pCS->IsRSoP())
  691. {
  692. LPNMTREEVIEW pnmtv = (LPNMTREEVIEW)lParam;
  693. LPFAV4RSOP pFav = (LPFAV4RSOP)pnmtv->itemNew.lParam;
  694. if (NULL != pFav)
  695. EnableDlgItem2(hDlg, IDC_MODIFY, (FTYPE_UNUSED == pFav->wType) ? FALSE : TRUE);
  696. }
  697. else
  698. ProcessFavSelChange(hDlg, htv, (LPNMTREEVIEW)lParam);
  699. break;
  700. case PSN_HELP:
  701. ShowHelpTopic(hDlg);
  702. break;
  703. case PSN_APPLY:
  704. if (psCookie->pCS->IsRSoP())
  705. return FALSE;
  706. else
  707. {
  708. fFavoritesOnTop = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_FAVONTOP));
  709. dwFavoritesDeleteFlags = 0;
  710. szValue[0] = TEXT('\0');
  711. pszValue = NULL;
  712. fFavoritesDelete = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_DELFAVORITES));
  713. fIEAKFavoritesDelete = (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_DELIEAKFAVORITES));
  714. if (fFavoritesDelete) {
  715. // NOTE. (andrewgu) flags explanation:
  716. // 1. FD_FAVORITES means "empty favorites";
  717. // 2. FD_CHANNELS means "don't delete channels folder";
  718. // 3. FD_SOFTWAREUPDATES means "don't delete sofware updates folder";
  719. // 4. FD_QUICKLINKS means "don't delete quick links folder";
  720. // 5. FD_EMPTY_QUICKLINKS means "but make it empty";
  721. // 6. FD_REMOVE_HIDDEN means "don't hesitate to party on HIDDEN folders and favorites";
  722. // 7. FD_REMOVE_SYSTEM means "don't hesitate to party on SYSTEM folders and favorites";
  723. dwFavoritesDeleteFlags |= FD_FAVORITES |
  724. FD_CHANNELS | FD_SOFTWAREUPDATES | FD_QUICKLINKS | FD_EMPTY_QUICKLINKS |
  725. FD_REMOVE_HIDDEN | FD_REMOVE_SYSTEM;
  726. }
  727. if (fIEAKFavoritesDelete)
  728. // FD_REMOVE_IEAK_CREATED means "delete those items created by the IEAK";
  729. dwFavoritesDeleteFlags |= FD_REMOVE_IEAK_CREATED;
  730. if (dwFavoritesDeleteFlags) {
  731. wnsprintf(szValue, countof(szValue), TEXT("0x%X"), dwFavoritesDeleteFlags);
  732. pszValue = szValue;
  733. }
  734. if (!AcquireWriteCriticalSection(hDlg)) {
  735. SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_INVALID_NOCHANGEPAGE);
  736. break;
  737. }
  738. InsWriteString(IS_BRANDING, IK_FAVORITES_DELETE, pszValue, GetInsFile(hDlg));
  739. InsWriteBool(IS_BRANDING, IK_FAVORITES_ONTOP, fFavoritesOnTop, GetInsFile(hDlg));
  740. CheckButtonAndWriteBool(hDlg, IDC_DELETECHANNELS, IS_DESKTOPOBJS, IK_DELETECHANNELS, GetInsFile(hDlg));
  741. CreateWorkDir(GetInsFile(hDlg), IEAK_GPE_BRANDING_SUBDIR TEXT("\\favs"), szWorkDir);
  742. ExportFavorites (htv, GetInsFile(hDlg), szWorkDir, TRUE);
  743. ExportQuickLinks(htv, GetInsFile(hDlg), szWorkDir, TRUE);
  744. MigrateToOldFavorites(GetInsFile(hDlg));
  745. DeleteFavorite(htv, TreeView_GetRoot(htv), NULL);
  746. DeleteFavorite(htv, TreeView_GetRoot(htv), NULL);
  747. if (PathIsDirectoryEmpty(szWorkDir))
  748. PathRemovePath(szWorkDir);
  749. SignalPolicyChanged(hDlg, FALSE, TRUE, &g_guidClientExt, &g_guidSnapinExt);
  750. }
  751. break;
  752. case PSN_QUERYCANCEL:
  753. if (!psCookie->pCS->IsRSoP())
  754. {
  755. DeleteFavorite(htv, TreeView_GetRoot(htv), NULL);
  756. DeleteFavorite(htv, TreeView_GetRoot(htv), NULL);
  757. }
  758. break;
  759. default:
  760. return FALSE;
  761. }
  762. break;
  763. case WM_HELP:
  764. ShowHelpTopic(hDlg);
  765. break;
  766. default:
  767. return FALSE;
  768. }
  769. return TRUE;
  770. }
  771. /////////////////////////////////////////////////////////////////////
  772. INT_PTR CALLBACK addEditFavoriteRSoPProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  773. {
  774. BOOL fResult = FALSE;
  775. switch (message) {
  776. case WM_INITDIALOG:
  777. {
  778. LPFAV4RSOP pFav = (LPFAV4RSOP)lParam;
  779. //----- Initialize contols -----
  780. EnableDBCSChars(hDlg, IDE_FAVNAME);
  781. EnableDBCSChars(hDlg, IDE_FAVURL);
  782. EnableDBCSChars(hDlg, IDE_FAVICON);
  783. Edit_LimitText(GetDlgItem(hDlg, IDE_FAVNAME), _MAX_FNAME);
  784. Edit_LimitText(GetDlgItem(hDlg, IDE_FAVURL), INTERNET_MAX_URL_LENGTH-1);
  785. Edit_LimitText(GetDlgItem(hDlg, IDE_FAVICON), _MAX_FNAME);
  786. EnableWindow(GetDlgItem(hDlg, IDE_FAVNAME), FALSE);
  787. EnableWindow(GetDlgItem(hDlg, IDE_FAVURL), FALSE);
  788. EnableWindow(GetDlgItem(hDlg, IDE_FAVICON), FALSE);
  789. EnableWindow(GetDlgItem(hDlg, IDC_FAVICONBROWSE), FALSE);
  790. EnableWindow(GetDlgItem(hDlg, IDC_AVAILOFFLINE), FALSE);
  791. //----- Populate controls -----
  792. if (FTYPE_FOLDER == pFav->wType)
  793. SetDlgItemText(hDlg, IDE_FAVNAME, pFav->szDisplayName);
  794. else
  795. {
  796. LPTSTR szLastSlash = StrRChr(pFav->szName, NULL, _T('\\'));
  797. SetDlgItemText(hDlg, IDE_FAVNAME, (NULL != szLastSlash) ? szLastSlash + 1 : pFav->szName);
  798. SetDlgItemText(hDlg, IDE_FAVURL, pFav->szUrl);
  799. SetDlgItemText(hDlg, IDE_FAVICON, pFav->szIconFile);
  800. if (pFav->fOffline)
  801. CheckDlgButton(hDlg, IDC_AVAILOFFLINE, BST_CHECKED);
  802. }
  803. fResult = TRUE;
  804. break;
  805. }
  806. case WM_COMMAND:
  807. switch (LOWORD(wParam)) {
  808. case IDOK:
  809. EndDialog(hDlg, IDOK);
  810. fResult = TRUE;
  811. break;
  812. case IDCANCEL:
  813. EndDialog(hDlg, IDCANCEL);
  814. fResult = TRUE;
  815. break;
  816. }
  817. break;
  818. }
  819. return fResult;
  820. }