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

397 lines
11 KiB

  1. /*++
  2. Microsoft Windows
  3. Copyright (C) Microsoft Corporation, 1981 - 1998
  4. Module Name:
  5. prefs.cxx
  6. Abstract:
  7. Code for the property page that is used to obtaining the redirection
  8. preferences e.g. Move Contents, Apply ACLs,... etc.
  9. Author:
  10. Rahul Thombre (RahulTh) 11/8/1998
  11. Notes:
  12. Revision History:
  13. 11/8/1998 RahulTh Created this module.
  14. 1/26/1999 RahulTh converted the dialog into a property page
  15. --*/
  16. #include "precomp.hxx"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. //
  23. //mapping between help ids and control ids for context sensitive help
  24. //
  25. const DWORD g_aHelpIDMap_IDD_REDIRMETHOD[] =
  26. {
  27. IDC_PREF_ICON, IDH_DISABLEHELP,
  28. IDC_PREF_TITLE, IDH_DISABLEHELP,
  29. IDC_PREF_APPLYSECURITY, IDH_PREF_APPLYSECURITY,
  30. IDC_PREF_MOVE, IDH_PREF_MOVE,
  31. IDC_GROUP_ORPHAN, IDH_DISABLEHELP,
  32. IDC_PREF_ORPHAN, IDH_PREF_ORPHAN,
  33. IDC_PREF_RELOCATE, IDH_PREF_RELOCATE,
  34. IDC_PREF_MYPICS_GROUP, IDH_DISABLEHELP,
  35. IDC_PREF_CHANGEMYPICS, IDH_PREF_CHANGEMYPICS,
  36. IDC_PREF_LEAVEMYPICS, IDH_PREF_LEAVEMYPICS,
  37. 0, 0
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. // CRedirPref property page
  41. CRedirPref::CRedirPref()
  42. : CPropertyPage (CRedirPref::IDD)
  43. {
  44. //{{AFX_DATA_INIT(CRedirPref)
  45. m_szFolderName.Empty();
  46. m_fInitialized = FALSE;
  47. m_fMyPicsValid = FALSE;
  48. m_fMyPicsFollows = TRUE;
  49. m_fSettingsChanged = FALSE;
  50. //}}AFX_DATA_INIT
  51. //m_ppThis and m_pFileInfo are set immediately after creation in CScopePane routines
  52. }
  53. CRedirPref::~CRedirPref()
  54. {
  55. //reset the pointer to this property page from its corresponding
  56. //CFileInfo object so that it know that it is gone.
  57. *m_ppThis = NULL;
  58. //reset the settings initialized member since this page is being destroyed
  59. m_fInitialized = m_pFileInfo->m_bSettingsInitialized = FALSE;
  60. }
  61. void CRedirPref::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CPropertyPage::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CRedirPref)
  65. // NOTE: the ClassWizard will add DDX and DDV calls here
  66. DDX_Control (pDX, IDC_PREF_TITLE, m_csTitle);
  67. DDX_Control (pDX, IDC_PREF_MOVE, m_cbMoveContents);
  68. DDX_Control (pDX, IDC_PREF_APPLYSECURITY, m_cbApplySecurity);
  69. DDX_Control (pDX, IDC_GROUP_ORPHAN, m_grOrphan);
  70. DDX_Control (pDX, IDC_PREF_ORPHAN, m_rbOrphan);
  71. DDX_Control (pDX, IDC_PREF_RELOCATE, m_rbRelocate);
  72. DDX_Control (pDX, IDC_PREF_MYPICS_GROUP, m_grMyPics);
  73. DDX_Control (pDX, IDC_PREF_CHANGEMYPICS, m_rbFollowMyDocs);
  74. DDX_Control (pDX, IDC_PREF_LEAVEMYPICS, m_rbNoModify);
  75. //}}AFX_DATA_MAP
  76. }
  77. BEGIN_MESSAGE_MAP(CRedirPref, CPropertyPage)
  78. //{{AFX_MSG_MAP(CRedirPref)
  79. ON_BN_CLICKED (IDC_PREF_MOVE, OnModify)
  80. ON_BN_CLICKED (IDC_PREF_APPLYSECURITY, OnModify)
  81. ON_BN_CLICKED (IDC_PREF_ORPHAN, OnModify)
  82. ON_BN_CLICKED (IDC_PREF_RELOCATE, OnModify)
  83. ON_BN_CLICKED (IDC_PREF_CHANGEMYPICS, OnMyPicsChange)
  84. ON_BN_CLICKED (IDC_PREF_LEAVEMYPICS, OnMyPicsChange)
  85. ON_MESSAGE (WM_HELP, OnHelp)
  86. ON_MESSAGE (WM_CONTEXTMENU, OnContextMenu)
  87. //}}AFX_MSG_MAP
  88. END_MESSAGE_MAP()
  89. /////////////////////////////////////////////////////////////////////////////
  90. // CRedirPref message handlers
  91. BOOL CRedirPref::OnInitDialog()
  92. {
  93. AFX_MANAGE_STATE (AfxGetStaticModuleState());
  94. RECT rc;
  95. RECT rcDlg;
  96. int top, height;
  97. CString szFormat;
  98. CString szText;
  99. CPropertyPage::OnInitDialog();
  100. //tell the other property pages that InitDialog has been received.
  101. m_fInitialized = m_pFileInfo->m_bSettingsInitialized = TRUE;
  102. //get the display name
  103. m_szFolderName = m_pFileInfo->m_szDisplayname;
  104. //set the right text in the check boxes etc.
  105. szFormat.LoadString (IDS_PREF_TITLE);
  106. szText.Format ((LPCTSTR) szFormat, (LPCTSTR) m_szFolderName);
  107. m_csTitle.SetWindowText (szText);
  108. szFormat.LoadString (IDS_PREF_APPLYSECURITY);
  109. szText.Format ((LPCTSTR) szFormat, (LPCTSTR) m_szFolderName);
  110. m_cbApplySecurity.SetWindowText (szText);
  111. szFormat.LoadString (IDS_PREF_MOVE);
  112. szText.Format ((LPCTSTR) szFormat, (LPCTSTR) m_szFolderName);
  113. m_cbMoveContents.SetWindowText (szText);
  114. return TRUE; //return TRUE unless you set focus to a control.
  115. }
  116. BOOL CRedirPref::OnSetActive ()
  117. {
  118. BOOL bRet;
  119. CRedirect * pPage = NULL;
  120. bRet = CPropertyPage::OnSetActive();
  121. pPage = m_pFileInfo->m_pRedirPage;
  122. switch (pPage->m_iCurrChoice + pPage->m_iChoiceStart)
  123. {
  124. case IDS_DONT_CARE:
  125. case IDS_FOLLOW_PARENT:
  126. DisableSettings();
  127. break;
  128. case IDS_SCALEABLE:
  129. if (pPage->m_lstSecGroups.GetItemCount())
  130. EnableSettings();
  131. else
  132. DisableSettings();
  133. break;
  134. default:
  135. EnableSettings();
  136. break;
  137. }
  138. return bRet;
  139. }
  140. void CRedirPref::EnablePage (BOOL bEnable /* = TRUE*/)
  141. {
  142. //enable or disable the contents of a page depending on whether
  143. if (!m_fInitialized)
  144. return;
  145. if (bEnable)
  146. EnableSettings();
  147. else
  148. DisableSettings();
  149. }
  150. void CRedirPref::DisableSettings(void)
  151. {
  152. //since the settings are being disabled, the modifications in the
  153. //settings (if any) obviously have no significance.
  154. SetModified (FALSE);
  155. //disable all the options on this page... also uncheck all of them.
  156. m_csTitle.EnableWindow (FALSE);
  157. m_cbMoveContents.SetCheck(0);
  158. m_cbMoveContents.EnableWindow(FALSE);
  159. m_cbApplySecurity.SetCheck (0);
  160. m_cbApplySecurity.EnableWindow (FALSE);
  161. m_grOrphan.EnableWindow (FALSE);
  162. m_rbOrphan.SetCheck(0);
  163. m_rbOrphan.EnableWindow (FALSE);
  164. m_rbRelocate.SetCheck (0);
  165. m_rbRelocate.EnableWindow (FALSE);
  166. EnableMyPicsSettings (FALSE);
  167. return;
  168. }
  169. void CRedirPref::EnableMyPicsSettings (BOOL bEnable /* = TRUE*/)
  170. {
  171. CRedirect * pPage = m_pFileInfo->m_pRedirPage;
  172. //my pics preferences are shown only in the tab for my documents
  173. if (IDS_MYDOCS != m_pFileInfo->m_cookie)
  174. {
  175. m_grMyPics.ShowWindow (SW_HIDE);
  176. m_rbFollowMyDocs.ShowWindow (SW_HIDE);
  177. m_rbNoModify.ShowWindow (SW_HIDE);
  178. return;
  179. }
  180. //this is the my docs folder
  181. m_grMyPics.ShowWindow (SW_SHOW);
  182. m_rbNoModify.ShowWindow (SW_SHOW);
  183. m_rbFollowMyDocs.ShowWindow (SW_SHOW);
  184. LONG index = pPage->m_iCurrChoice + pPage->m_iChoiceStart - IDS_CHILD_REDIR_START;
  185. if (bEnable &&
  186. pPage->m_fEnableMyPics &&
  187. pPage->m_fSettingModified [index])
  188. {
  189. m_grMyPics.EnableWindow ();
  190. m_rbFollowMyDocs.EnableWindow ();
  191. m_rbNoModify.EnableWindow ();
  192. if (m_fMyPicsValid)
  193. {
  194. m_rbFollowMyDocs.SetCheck (m_fMyPicsFollows ? 1 : 0);
  195. m_rbNoModify.SetCheck (m_fMyPicsFollows ? 0 : 1);
  196. }
  197. else //set defaults as the setting
  198. {
  199. m_rbFollowMyDocs.SetCheck (1);
  200. m_rbNoModify.SetCheck (0);
  201. m_fMyPicsFollows = TRUE;
  202. m_fMyPicsValid = TRUE;
  203. }
  204. }
  205. else
  206. {
  207. m_grMyPics.EnableWindow (FALSE);
  208. //even when disabled, show the current status of My Pictures as far
  209. //as possible. The only situation when both the radio buttons should
  210. //be unchecked is when My Pics is getting redirected independently.
  211. m_rbFollowMyDocs.EnableWindow (FALSE);
  212. m_rbFollowMyDocs.SetCheck ((REDIR_FOLLOW_PARENT == pPage->m_dwMyPicsCurr) ? 1 : 0);
  213. m_rbNoModify.EnableWindow (FALSE);
  214. m_rbNoModify.SetCheck ((REDIR_DONT_CARE == pPage->m_dwMyPicsCurr) ? 1 : 0);
  215. }
  216. }
  217. void CRedirPref::EnableSettings (void)
  218. {
  219. CRedirect * pPage = m_pFileInfo->m_pRedirPage;
  220. //the page is being enabled. If the settings had been modified earlier,
  221. //we need to make sure that the modified state indicates that.
  222. SetModified (m_fSettingsChanged);
  223. //enables applicable settings
  224. m_csTitle.EnableWindow (TRUE);
  225. if (IDS_STARTMENU == pPage->m_cookie)
  226. {
  227. m_cbMoveContents.EnableWindow (FALSE);
  228. m_cbMoveContents.SetCheck (0);
  229. m_cbApplySecurity.EnableWindow (FALSE);
  230. m_cbApplySecurity.SetCheck (0);
  231. }
  232. else
  233. {
  234. m_cbApplySecurity.EnableWindow ();
  235. m_cbMoveContents.EnableWindow ();
  236. if (pPage->m_fValidFlags)
  237. {
  238. m_cbApplySecurity.SetCheck ((pPage->m_dwFlags & REDIR_SETACLS)?1:0);
  239. m_cbMoveContents.SetCheck ((pPage->m_dwFlags & REDIR_MOVE_CONTENTS)? 1 : 0);
  240. }
  241. else
  242. {
  243. m_cbApplySecurity.SetCheck (1);
  244. m_cbMoveContents.SetCheck (1);
  245. }
  246. }
  247. m_grOrphan.EnableWindow ();
  248. m_rbOrphan.EnableWindow();
  249. m_rbRelocate.EnableWindow ();
  250. if (pPage->m_fValidFlags)
  251. {
  252. m_rbRelocate.SetCheck ((pPage->m_dwFlags & REDIR_RELOCATEONREMOVE)?1:0);
  253. m_rbOrphan.SetCheck ((pPage->m_dwFlags & REDIR_RELOCATEONREMOVE)?0:1);
  254. }
  255. else
  256. {
  257. m_rbOrphan.SetCheck (1);
  258. m_rbRelocate.SetCheck (0);
  259. }
  260. //enable my pics preferences for the My Docs folder
  261. EnableMyPicsSettings ();
  262. return;
  263. }
  264. void CRedirPref::OnModify()
  265. {
  266. CRedirect * pPage = m_pFileInfo->m_pRedirPage;
  267. //modify the flags
  268. if (m_cbMoveContents.GetCheck())
  269. pPage->m_dwFlags |= REDIR_MOVE_CONTENTS;
  270. else
  271. pPage->m_dwFlags &= ~REDIR_MOVE_CONTENTS;
  272. if (m_cbApplySecurity.GetCheck())
  273. pPage->m_dwFlags |= REDIR_SETACLS;
  274. else
  275. pPage->m_dwFlags &= ~REDIR_SETACLS;
  276. if (m_rbRelocate.GetCheck())
  277. pPage->m_dwFlags |= REDIR_RELOCATEONREMOVE;
  278. else
  279. pPage->m_dwFlags &= ~REDIR_RELOCATEONREMOVE;
  280. //the flag now contains valid values
  281. pPage->m_fValidFlags = TRUE;
  282. DirtyPage (TRUE);
  283. }
  284. void CRedirPref::OnMyPicsChange()
  285. {
  286. m_fMyPicsValid = TRUE;
  287. m_fMyPicsFollows = m_rbFollowMyDocs.GetCheck();
  288. DirtyPage(TRUE);
  289. }
  290. void CRedirPref::DirtyPage (BOOL fModified)
  291. {
  292. m_fSettingsChanged = fModified;
  293. SetModified (fModified);
  294. }
  295. LONG CRedirPref::OnHelp (WPARAM wParam, LPARAM lParam)
  296. {
  297. LONG lResult = 0;
  298. CString szHelpFile;
  299. szHelpFile.LoadString(IDS_HELP_FILE);
  300. ::WinHelp((HWND)(((LPHELPINFO)lParam)->hItemHandle),
  301. (LPCTSTR) szHelpFile,
  302. HELP_WM_HELP,
  303. (ULONG_PTR)(LPTSTR)g_aHelpIDMap_IDD_REDIRMETHOD);
  304. return lResult;
  305. }
  306. LONG CRedirPref::OnContextMenu (WPARAM wParam, LPARAM lParam)
  307. {
  308. AFX_MANAGE_STATE (AfxGetStaticModuleState());
  309. LONG lResult = 0;
  310. CString szHelpFile;
  311. szHelpFile.LoadString(IDS_HELP_FILE);
  312. ::WinHelp((HWND)wParam,
  313. (LPCTSTR)szHelpFile,
  314. HELP_CONTEXTMENU,
  315. (ULONG_PTR)(LPVOID)g_aHelpIDMap_IDD_REDIRMETHOD);
  316. return lResult;
  317. }