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.

233 lines
7.0 KiB

  1. //+---------------------------------------------------------------------------
  2. /////////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 2000-2001.
  6. //
  7. // File: SaferLevelGeneral.cpp
  8. //
  9. // Contents: Implementation of CSaferLevelGeneral
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "stdafx.h"
  13. #include <gpedit.h>
  14. #include <winsafer.h>
  15. #include "SaferLevelGeneral.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSaferLevelGeneral property page
  23. CSaferLevelGeneral::CSaferLevelGeneral(
  24. CSaferLevel& rSaferLevel,
  25. bool bReadOnly,
  26. LONG_PTR lNotifyHandle,
  27. LPDATAOBJECT pDataObject,
  28. DWORD dwDefaultSaferLevel)
  29. : CHelpPropertyPage(CSaferLevelGeneral::IDD),
  30. m_rSaferLevel (rSaferLevel),
  31. m_bReadOnly (bReadOnly),
  32. m_bSetAsDefault (false),
  33. m_lNotifyHandle (lNotifyHandle),
  34. m_bDirty (false),
  35. m_pDataObject (pDataObject),
  36. m_dwDefaultSaferLevel (dwDefaultSaferLevel),
  37. m_bFirst (true),
  38. m_bLevelChanged (false)
  39. {
  40. //{{AFX_DATA_INIT(CSaferLevelGeneral)
  41. // NOTE: the ClassWizard will add member initialization here
  42. //}}AFX_DATA_INIT
  43. m_rSaferLevel.IncrementOpenPageCount ();
  44. }
  45. CSaferLevelGeneral::~CSaferLevelGeneral()
  46. {
  47. if ( m_lNotifyHandle )
  48. {
  49. if ( m_bLevelChanged )
  50. {
  51. MMCPropertyChangeNotify (
  52. m_lNotifyHandle, // handle to a notification
  53. (LPARAM) m_pDataObject); // unique identifier
  54. }
  55. MMCFreeNotifyHandle (m_lNotifyHandle);
  56. }
  57. m_rSaferLevel.DecrementOpenPageCount ();
  58. }
  59. void CSaferLevelGeneral::DoDataExchange(CDataExchange* pDX)
  60. {
  61. CHelpPropertyPage::DoDataExchange(pDX);
  62. //{{AFX_DATA_MAP(CSaferLevelGeneral)
  63. // NOTE: the ClassWizard will add DDX and DDV calls here
  64. //}}AFX_DATA_MAP
  65. }
  66. BEGIN_MESSAGE_MAP(CSaferLevelGeneral, CHelpPropertyPage)
  67. //{{AFX_MSG_MAP(CSaferLevelGeneral)
  68. ON_BN_CLICKED(IDC_SAFER_LEVEL_SET_AS_DEFAULT, OnSaferLevelSetAsDefault)
  69. ON_EN_SETFOCUS(IDC_SAFER_LEVEL_DESCRIPTION, OnSetfocusSaferLevelDescription)
  70. //}}AFX_MSG_MAP
  71. END_MESSAGE_MAP()
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CSaferLevelGeneral message handlers
  74. void CSaferLevelGeneral::DoContextHelp (HWND hWndControl)
  75. {
  76. _TRACE (1, L"Entering CSaferLevelGeneral::DoContextHelp\n");
  77. static const DWORD help_map[] =
  78. {
  79. IDC_SAFER_LEVEL_NAME, IDH_SAFER_LEVEL_NAME,
  80. IDC_SAFER_LEVEL_DESCRIPTION, IDH_SAFER_LEVEL_DESCRIPTION,
  81. IDC_SAFER_LEVEL_SET_AS_DEFAULT, IDH_SAFER_LEVEL_SET_AS_DEFAULT,
  82. IDC_SAFER_LEVEL_STATUS, IDH_SAFER_LEVEL_STATUS,
  83. 0, 0
  84. };
  85. if ( !::WinHelp (
  86. hWndControl,
  87. GetF1HelpFilename(),
  88. HELP_WM_HELP,
  89. (DWORD_PTR) help_map) )
  90. {
  91. _TRACE (0, L"WinHelp () failed: 0x%x\n", GetLastError ());
  92. }
  93. _TRACE (-1, L"Leaving CSaferLevelGeneral::DoContextHelp\n");
  94. }
  95. BOOL CSaferLevelGeneral::OnInitDialog()
  96. {
  97. CHelpPropertyPage::OnInitDialog();
  98. SetDlgItemText (IDC_SAFER_LEVEL_NAME, m_rSaferLevel.GetObjectName ());
  99. SetDlgItemText (IDC_SAFER_LEVEL_DESCRIPTION, m_rSaferLevel.GetDescription ());
  100. if ( m_rSaferLevel.IsDefault () )
  101. {
  102. m_bSetAsDefault = true;
  103. CString text;
  104. VERIFY (text.LoadString (IDS_IS_DEFAULT_LEVEL));
  105. SetDlgItemText (IDC_SAFER_LEVEL_STATUS, text);
  106. GetDlgItem (IDC_SAFER_LEVEL_SET_AS_DEFAULT)->EnableWindow (FALSE);
  107. GetDlgItem (IDC_LEVEL_INSTRUCTIONS)->EnableWindow (FALSE);
  108. }
  109. if ( m_bReadOnly || ( SAFER_LEVELID_DISALLOWED != m_rSaferLevel.GetLevel () &&
  110. SAFER_LEVELID_FULLYTRUSTED != m_rSaferLevel.GetLevel () ) )
  111. {
  112. CString text;
  113. if ( SAFER_LEVELID_CONSTRAINED == m_rSaferLevel.GetLevel () )
  114. {
  115. VERIFY (text.LoadString (IDS_CANT_SET_CONSTRAINED_AS_DEFAULT));
  116. SetDlgItemText (IDC_LEVEL_INSTRUCTIONS, text);
  117. }
  118. GetDlgItem (IDC_SAFER_LEVEL_SET_AS_DEFAULT)->EnableWindow (FALSE);
  119. GetDlgItem (IDC_LEVEL_INSTRUCTIONS)->EnableWindow (FALSE);
  120. }
  121. return TRUE; // return TRUE unless you set the focus to a control
  122. // EXCEPTION: OCX Property Pages should return FALSE
  123. }
  124. BOOL CSaferLevelGeneral::OnApply ()
  125. {
  126. if ( !m_bReadOnly && m_bDirty )
  127. {
  128. HRESULT hr = S_OK;
  129. BOOL bResult = FALSE;
  130. if ( m_bSetAsDefault )
  131. hr = m_rSaferLevel.SetAsDefault ();
  132. if ( SUCCEEDED (hr) )
  133. {
  134. m_bLevelChanged = true;
  135. bResult = CHelpPropertyPage::OnApply ();
  136. }
  137. else
  138. {
  139. CString text;
  140. CString caption;
  141. CThemeContextActivator activator;
  142. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_EXTENSION_REGISTRY));
  143. text.FormatMessage (IDS_CANT_SET_AS_DEFAULT, m_rSaferLevel.GetObjectName (),
  144. GetSystemMessage (hr));
  145. MessageBox (text, caption, MB_ICONWARNING | MB_OK);
  146. }
  147. return bResult;
  148. }
  149. else
  150. return CHelpPropertyPage::OnApply ();
  151. }
  152. void CSaferLevelGeneral::OnSaferLevelSetAsDefault()
  153. {
  154. if ( !m_bSetAsDefault )
  155. {
  156. int iRet = IDYES;
  157. if ( m_rSaferLevel.GetLevel () < m_dwDefaultSaferLevel )
  158. {
  159. CString text;
  160. CString caption;
  161. CThemeContextActivator activator;
  162. VERIFY (caption.LoadString (IDS_SAFER_WINDOWS_EXTENSION_REGISTRY));
  163. VERIFY (text.LoadString (IDS_DEFAULT_LEVEL_CHANGE_WARNING));
  164. iRet = MessageBox (text, caption, MB_ICONWARNING | MB_YESNO);
  165. }
  166. if ( IDYES == iRet )
  167. {
  168. m_dwDefaultSaferLevel = m_rSaferLevel.GetLevel ();
  169. m_bDirty = true;
  170. m_bSetAsDefault = true;
  171. CString text;
  172. VERIFY (text.LoadString (IDS_IS_DEFAULT_LEVEL));
  173. SetDlgItemText (IDC_SAFER_LEVEL_STATUS, text);
  174. SetModified (TRUE);
  175. GetDlgItem (IDC_SAFER_LEVEL_SET_AS_DEFAULT)->EnableWindow (FALSE);
  176. }
  177. }
  178. }
  179. ///////////////////////////////////////////////////////////////////////////////
  180. // This method traps keyboard commands from the dialog, which has only
  181. // disabled controls, usually. That prevented the closing of the dialog
  182. // when the user pressed ESC.
  183. // 222693 SAFER: Pressing ESC doesn't dismiss SAFER Level dialogs
  184. ///////////////////////////////////////////////////////////////////////////////
  185. BOOL CSaferLevelGeneral::OnCommand(WPARAM wParam, LPARAM lParam)
  186. {
  187. WORD id = LOWORD (wParam);
  188. if ( IDCANCEL == id )
  189. {
  190. GetParent ()->SendMessage (WM_COMMAND, wParam, lParam);
  191. }
  192. return CHelpPropertyPage::OnCommand(wParam, lParam);
  193. }
  194. void CSaferLevelGeneral::OnSetfocusSaferLevelDescription()
  195. {
  196. if ( m_bFirst )
  197. {
  198. SendDlgItemMessage (IDC_SAFER_LEVEL_DESCRIPTION, EM_SETSEL, (WPARAM) 0, 0);
  199. m_bFirst = false;
  200. }
  201. }