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.

265 lines
11 KiB

  1. #include "pch.h"
  2. INT_PTR CALLBACK FavsProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
  3. {
  4. TCHAR szValue[16];
  5. TCHAR szUrl[INTERNET_MAX_URL_LENGTH];
  6. LPCTSTR pszValue;
  7. HWND hTv = GetDlgItem(hDlg, IDC_TREE1);
  8. BOOL fQL,
  9. fFavoritesOnTop, fFavoritesDelete, fIEAKFavoritesDelete, fCheckDirtyOnly;
  10. DWORD dwFavoritesDeleteFlags;
  11. switch (msg) {
  12. case WM_INITDIALOG:
  13. EnableDBCSChars(hDlg, IDC_TREE1);
  14. MigrateFavorites(g_szInsFile);
  15. ASSERT(GetFavoritesNumber(hTv, FALSE) == 0 && GetFavoritesNumber(hTv, TRUE) == 0);
  16. ImportFavorites (hTv, g_szDefInf, g_szInsFile, NULL, g_szWorkDir, FALSE);
  17. ImportQuickLinks(hTv, g_szDefInf, g_szInsFile, NULL, g_szWorkDir, FALSE);
  18. TreeView_SelectItem(hTv, TreeView_GetRoot(hTv));
  19. fFavoritesOnTop = GetPrivateProfileInt(IS_BRANDING, IK_FAVORITES_ONTOP, (int)FALSE, g_szInsFile);
  20. CheckDlgButton(hDlg, IDC_FAVONTOP, fFavoritesOnTop ? BST_CHECKED : BST_UNCHECKED);
  21. if (!fFavoritesOnTop) {
  22. DisableDlgItem(hDlg, IDC_FAVUP);
  23. DisableDlgItem(hDlg, IDC_FAVDOWN);
  24. }
  25. dwFavoritesDeleteFlags = (DWORD) GetPrivateProfileInt(IS_BRANDING, IK_FAVORITES_DELETE, (int)FD_DEFAULT, g_szInsFile);
  26. fFavoritesDelete = HasFlag(dwFavoritesDeleteFlags, ~FD_REMOVE_IEAK_CREATED);
  27. CheckDlgButton(hDlg, IDC_DELFAVORITES, fFavoritesDelete ? BST_CHECKED : BST_UNCHECKED);
  28. fIEAKFavoritesDelete = HasFlag(dwFavoritesDeleteFlags, FD_REMOVE_IEAK_CREATED);
  29. CheckDlgButton(hDlg, IDC_DELIEAKFAVORITES, fIEAKFavoritesDelete ? BST_CHECKED : BST_UNCHECKED);
  30. // only if delete Favorites is TRUE should the delete IEAK Favorites checkbox be enabled
  31. EnableWindow(GetDlgItem(hDlg, IDC_DELIEAKFAVORITES), fFavoritesDelete);
  32. break;
  33. case WM_COMMAND:
  34. switch (HIWORD(wParam)) {
  35. case BN_CLICKED:
  36. switch (LOWORD(wParam)) {
  37. case IDC_FAVONTOP:
  38. if (BST_CHECKED == IsDlgButtonChecked(hDlg, IDC_FAVONTOP)) {
  39. HTREEITEM hti;
  40. TV_ITEM tvi;
  41. EnableDlgItem(hDlg, IDC_FAVONTOP);
  42. hti = TreeView_GetSelection(hTv);
  43. if (hti != NULL) {
  44. ZeroMemory(&tvi, sizeof(tvi));
  45. tvi.mask = TVIF_STATE;
  46. tvi.hItem = hti;
  47. TreeView_GetItem(hTv, &tvi);
  48. if (!HasFlag(tvi.state, TVIS_BOLD)) {
  49. EnableDlgItem2(hDlg, IDC_FAVUP, (NULL != TreeView_GetPrevSibling(hTv, hti)));
  50. EnableDlgItem2(hDlg, IDC_FAVDOWN, (NULL != TreeView_GetNextSibling(hTv, hti)));
  51. }
  52. }
  53. }
  54. else {
  55. DisableDlgItem(hDlg, IDC_FAVUP);
  56. DisableDlgItem(hDlg, IDC_FAVDOWN);
  57. }
  58. break;
  59. case IDC_DELFAVORITES:
  60. fFavoritesDelete = (IsDlgButtonChecked(hDlg, IDC_DELFAVORITES) == BST_CHECKED);
  61. EnableWindow(GetDlgItem(hDlg, IDC_DELIEAKFAVORITES), fFavoritesDelete);
  62. break;
  63. case IDC_FAVUP:
  64. if (MoveUpFavorite(hTv, TreeView_GetSelection(hTv)))
  65. g_fInsDirty = TRUE;
  66. SetFocus(GetDlgItem(hDlg, IDC_TREE1));
  67. break;
  68. case IDC_FAVDOWN:
  69. if (MoveDownFavorite(hTv, TreeView_GetSelection(hTv)))
  70. g_fInsDirty = TRUE;
  71. SetFocus(GetDlgItem(hDlg, IDC_TREE1));
  72. break;
  73. case IDC_ADDURL:
  74. fQL = !IsFavoriteItem(hTv, TreeView_GetSelection(hTv));
  75. if (GetFavoritesNumber(hTv, fQL) >= GetFavoritesMaxNumber(fQL)) {
  76. UINT nID;
  77. nID = (!fQL ? IDS_ERROR_MAXFAVS : IDS_ERROR_MAXQLS);
  78. ErrorMessageBox(hDlg, nID);
  79. break;
  80. }
  81. if (NewUrl(hTv, g_szWorkDir, g_dwPlatformId, IEM_PROFMGR))
  82. g_fInsDirty = TRUE;
  83. RedrawWindow(hTv, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE);
  84. SetFocus(GetDlgItem(hDlg, IDC_ADDURL));
  85. break;
  86. case IDC_ADDFOLDER:
  87. ASSERT(IsFavoriteItem(hTv, TreeView_GetSelection(hTv)));
  88. if (GetFavoritesNumber(hTv) >= GetFavoritesMaxNumber()) {
  89. ErrorMessageBox(hDlg, IDS_ERROR_MAXFAVS);
  90. break;
  91. }
  92. if (NewFolder(hTv))
  93. g_fInsDirty = TRUE;
  94. RedrawWindow(hTv, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE);
  95. SetFocus(GetDlgItem(hDlg, IDC_ADDFOLDER));
  96. break;
  97. case IDC_MODIFY:
  98. if (ModifyFavorite(hTv, TreeView_GetSelection(hTv), g_szWorkDir, g_szWorkDir, g_dwPlatformId, IEM_PROFMGR))
  99. g_fInsDirty = TRUE;
  100. RedrawWindow(hTv, NULL, NULL, RDW_ERASE | RDW_FRAME | RDW_INVALIDATE);
  101. SetFocus(GetDlgItem(hDlg, IDC_MODIFY));
  102. break;
  103. case IDC_REMOVE:
  104. if (DeleteFavorite(hTv, TreeView_GetSelection(hTv), g_szWorkDir))
  105. g_fInsDirty = TRUE;
  106. break;
  107. case IDC_TESTFAVURL:
  108. if (GetFavoriteUrl(hTv, TreeView_GetSelection(hTv), szUrl, ARRAYSIZE(szUrl)))
  109. TestURL(szUrl);
  110. SetFocus(GetDlgItem(hDlg, IDC_TESTFAVURL));
  111. break;
  112. case IDC_IMPORT: {
  113. CNewCursor cursor(IDC_WAIT);
  114. if (ImportFavoritesCmd(hTv, g_szWorkDir) > 0)
  115. g_fInsDirty = TRUE;
  116. SetFocus(GetDlgItem(hDlg, IDC_IMPORT));
  117. break;
  118. }
  119. }
  120. break;
  121. default:
  122. break;
  123. }
  124. break;
  125. case WM_NOTIFY:
  126. switch(((NMHDR FAR *)lParam)->code) {
  127. case TVN_GETINFOTIP:
  128. ASSERT(wParam == IDC_TREE1);
  129. GetFavoritesInfoTip((NMTVGETINFOTIP *)lParam);
  130. break;
  131. case NM_DBLCLK:
  132. ASSERT(wParam == IDC_TREE1);
  133. if (IsWindowEnabled(GetDlgItem(hDlg, IDC_MODIFY)))
  134. SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDC_MODIFY, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDC_MODIFY));
  135. break;
  136. case TVN_KEYDOWN:
  137. ASSERT(wParam == IDC_TREE1);
  138. if (((LPNMTVKEYDOWN)lParam)->wVKey == VK_DELETE && IsWindowEnabled(GetDlgItem(hDlg, IDC_REMOVE)))
  139. SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDC_REMOVE, BN_CLICKED), (LPARAM)GetDlgItem(hDlg, IDC_REMOVE));
  140. break;
  141. case TVN_SELCHANGED:
  142. ASSERT(wParam == IDC_TREE1);
  143. ProcessFavSelChange(hDlg, hTv, (LPNMTREEVIEW)lParam);
  144. break;
  145. default:
  146. return FALSE;
  147. }
  148. break;
  149. case UM_SAVE:
  150. fCheckDirtyOnly = (BOOL) lParam;
  151. fFavoritesOnTop = (IsDlgButtonChecked(hDlg, IDC_FAVONTOP) == BST_CHECKED);
  152. dwFavoritesDeleteFlags = 0;
  153. szValue[0] = TEXT('\0');
  154. pszValue = NULL;
  155. fFavoritesDelete = (IsDlgButtonChecked(hDlg, IDC_DELFAVORITES) == BST_CHECKED);
  156. fIEAKFavoritesDelete = (IsDlgButtonChecked(hDlg, IDC_DELIEAKFAVORITES) == BST_CHECKED);
  157. if (!g_fInsDirty) {
  158. BOOL fTemp;
  159. DWORD dwTemp;
  160. // check to see if there is a old favorites section.
  161. // if there isn't a section, set the dirty flag to TRUE so that we write
  162. // the old section for backward compatibility.
  163. if (GetFavoritesNumber(hTv) > 1)
  164. {
  165. if (!GetPrivateProfileSection(IS_FAVORITES, szValue, countof(szValue), g_szInsFile))
  166. g_fInsDirty = TRUE;
  167. }
  168. dwTemp = (DWORD) GetPrivateProfileInt(IS_BRANDING, IK_FAVORITES_DELETE, (int)FD_DEFAULT, g_szInsFile);
  169. fTemp = HasFlag(dwTemp, ~FD_REMOVE_IEAK_CREATED);
  170. if (fTemp != fFavoritesDelete)
  171. g_fInsDirty = TRUE;
  172. fTemp = HasFlag(dwTemp, FD_REMOVE_IEAK_CREATED);
  173. if (fTemp != fIEAKFavoritesDelete)
  174. g_fInsDirty = TRUE;
  175. fTemp = GetPrivateProfileInt(IS_BRANDING, IK_FAVORITES_ONTOP, (int)FALSE, g_szInsFile);
  176. if (fTemp != fFavoritesOnTop)
  177. g_fInsDirty = TRUE;
  178. }
  179. if (!fCheckDirtyOnly) {
  180. if (fFavoritesDelete) {
  181. // NOTE. (andrewgu) flags explanation:
  182. // 1. FD_FAVORITES means "empty favorites";
  183. // 2. FD_CHANNELS means "don't delete channels folder";
  184. // 3. FD_SOFTWAREUPDATES means "don't delete sofware updates folder";
  185. // 4. FD_QUICKLINKS means "don't delete quick links folder";
  186. // 5. FD_EMPTY_QUICKLINKS means "but make it empty";
  187. // 6. FD_REMOVE_HIDDEN means "don't hesitate to party on HIDDEN folders and favorites";
  188. // 7. FD_REMOVE_SYSTEM means "don't hesitate to party on SYSTEM folders and favorites";
  189. dwFavoritesDeleteFlags |= FD_FAVORITES |
  190. FD_CHANNELS | FD_SOFTWAREUPDATES | FD_QUICKLINKS | FD_EMPTY_QUICKLINKS |
  191. FD_REMOVE_HIDDEN | FD_REMOVE_SYSTEM;
  192. }
  193. if (fIEAKFavoritesDelete)
  194. // FD_REMOVE_IEAK_CREATED means "delete those items created by the IEAK";
  195. dwFavoritesDeleteFlags |= FD_REMOVE_IEAK_CREATED;
  196. if (dwFavoritesDeleteFlags) {
  197. wsprintf(szValue, TEXT("0x%X"), dwFavoritesDeleteFlags);
  198. pszValue = szValue;
  199. }
  200. WritePrivateProfileString(IS_BRANDING, IK_FAVORITES_DELETE, pszValue, g_szInsFile);
  201. WritePrivateProfileString(IS_BRANDING, IK_FAVORITES_ONTOP, fFavoritesOnTop ? TEXT("1") : TEXT("0"), g_szInsFile);
  202. ExportFavorites (hTv, g_szInsFile, g_szWorkDir, TRUE);
  203. ExportQuickLinks(hTv, g_szInsFile, g_szWorkDir, TRUE);
  204. MigrateToOldFavorites(g_szInsFile);
  205. }
  206. *((LPBOOL)wParam) = TRUE;
  207. break;
  208. case WM_CLOSE:
  209. DeleteFavorite(hTv, TreeView_GetRoot(hTv), NULL);
  210. DeleteFavorite(hTv, TreeView_GetRoot(hTv), NULL);
  211. DestroyWindow(hDlg);
  212. return FALSE;
  213. default:
  214. return FALSE;
  215. }
  216. return TRUE;
  217. }