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.

455 lines
12 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: Snppage.cpp
  7. //
  8. // Contents: WiF Policy Snapin
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "stdafx.h"
  16. #ifdef _DEBUG
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CSnapPage property page base class
  23. IMPLEMENT_DYNCREATE(CSnapPage, CPropertyPage)
  24. BEGIN_MESSAGE_MAP(CSnapPage, CPropertyPage)
  25. //{{AFX_MSG_MAP(CSnapPage)
  26. ON_WM_DESTROY()
  27. //}}AFX_MSG_MAP
  28. END_MESSAGE_MAP()
  29. CSnapPage::CSnapPage (UINT nIDTemplate, BOOL bWiz97, UINT nNextIDD) : CPropertyPage(nIDTemplate)
  30. {
  31. m_pspiResultItem = NULL;
  32. m_pDefaultCallback = NULL;
  33. m_bDoRefresh = TRUE;
  34. m_bModified = FALSE;
  35. m_bInitializing = FALSE;
  36. #ifdef _DEBUG
  37. m_bDebugNewState = false;
  38. #endif
  39. // if they set this to begin with, but note that calling InitWiz97 turns this on anyway
  40. m_bWiz97 = bWiz97;
  41. m_nIDD = nIDTemplate;
  42. m_nNextIDD = nNextIDD;
  43. #ifdef WIZ97WIZARDS
  44. // copy the base class m_psp to ours
  45. m_psp.dwSize = sizeof (CPropertyPage::m_psp);
  46. memcpy (&m_psp, &(CPropertyPage::m_psp), CPropertyPage::m_psp.dwSize);
  47. m_psp.dwSize = sizeof (PROPSHEETPAGE);
  48. m_pWiz97Sheet = NULL;
  49. m_pHeaderTitle = NULL;
  50. m_pHeaderSubTitle = NULL;
  51. m_pstackWiz97Pages = NULL;
  52. #endif
  53. }
  54. CSnapPage::~CSnapPage ()
  55. {
  56. // guess we are done with the m_pspiResultItem, decrement its reference count
  57. if (m_pspiResultItem)
  58. {
  59. m_pspiResultItem->Release();
  60. m_pspiResultItem = NULL;
  61. }
  62. // Page's parent or caller will delete these objs
  63. m_pstackWiz97Pages = NULL;
  64. #ifdef WIZ97WIZARDS
  65. DELETE_OBJECT(m_pHeaderTitle);
  66. DELETE_OBJECT(m_pHeaderSubTitle);
  67. #endif
  68. }
  69. UINT CALLBACK CSnapPage::PropertyPageCallback (HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp)
  70. {
  71. // get our psuedo this pointer
  72. CSnapPage* pThis = (CSnapPage*) ppsp->lParam;
  73. // get the default callback pointer
  74. UINT (CALLBACK* pDefaultCallback) (HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp) = pThis->m_pDefaultCallback;
  75. switch (uMsg)
  76. {
  77. case PSPCB_RELEASE:
  78. {
  79. // Delete ourself
  80. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  81. delete pThis;
  82. break;
  83. }
  84. }
  85. // call the default cleanup function if there was one (because we are using
  86. // mfc and it always puts in a callback for itself there should be one... or
  87. // we block the page from coming up)
  88. if (pDefaultCallback)
  89. {
  90. return pDefaultCallback (hwnd, uMsg, ppsp);
  91. }
  92. // There should be a default callback to handle creation, otherwise page will not
  93. // be created because we return 0.
  94. ASSERT( PSPCB_CREATE != uMsg );
  95. // to create the page 1 allows it and 0 says 'no way'
  96. return 0;
  97. }
  98. #ifdef WIZ97WIZARDS
  99. BOOL CSnapPage::OnSetActive()
  100. {
  101. // NOTE: we only ever want to do this if it is a wizard, otherwise the
  102. // cancel button gets the default focus!
  103. if (m_bWiz97)
  104. {
  105. // now we can set our buttons correctly
  106. GetParent()->SendMessage(PSM_SETWIZBUTTONS, 0, m_dwWizButtonFlags);
  107. }
  108. return CPropertyPage::OnSetActive();
  109. }
  110. LRESULT CSnapPage::OnWizardBack()
  111. {
  112. // use the snapitem to help us keep track of wizard state
  113. if (m_pspiResultItem)
  114. {
  115. // pop to the last page
  116. return m_pspiResultItem->PopWiz97Page ();
  117. }
  118. else if (NULL != m_pstackWiz97Pages)
  119. {
  120. // Or, use our own stack, if we have one
  121. return PopWiz97Page();
  122. }
  123. return CPropertyPage::OnWizardBack();
  124. }
  125. LRESULT CSnapPage::OnWizardNext()
  126. {
  127. // use the snapitem to help us keep track of wizard state
  128. if (m_pspiResultItem)
  129. {
  130. // push our id, in case they need to use the 'back' button
  131. m_pspiResultItem->PushWiz97Page (m_nIDD);
  132. }
  133. else if (NULL != m_pstackWiz97Pages)
  134. {
  135. // Or, use our own stack, if we have one
  136. PushWiz97Page( m_nIDD );
  137. }
  138. // If we have the ID of the next page, return it, otherwise return default
  139. return ((m_nNextIDD != -1) ? m_nNextIDD : CPropertyPage::OnWizardNext());
  140. }
  141. int CSnapPage::PopWiz97Page ()
  142. {
  143. ASSERT( NULL != m_pstackWiz97Pages );
  144. // There better be something on the stack if we're popping it
  145. ASSERT( m_pstackWiz97Pages->size() );
  146. int i;
  147. i = m_pstackWiz97Pages->top();
  148. m_pstackWiz97Pages->pop();
  149. return i;
  150. }
  151. void CSnapPage::PushWiz97Page (int nIDD)
  152. {
  153. ASSERT( NULL != m_pstackWiz97Pages );
  154. m_pstackWiz97Pages->push(nIDD);
  155. }
  156. BOOL CSnapPage::InitWiz97( CComObject<CSecPolItem> *pSecPolItem, DWORD dwFlags, DWORD dwWizButtonFlags, UINT nHeaderTitle, UINT nSubTitle )
  157. {
  158. CommonInitWiz97( pSecPolItem, dwFlags, dwWizButtonFlags, nHeaderTitle, nSubTitle );
  159. // Use our own callback.
  160. SetCallback( CSnapPage::PropertyPageCallback );
  161. return S_OK;
  162. }
  163. BOOL CSnapPage::InitWiz97( LPFNPSPCALLBACK pfnCallback, CComObject<CSecPolItem> *pSecPolItem, DWORD dwFlags, DWORD dwWizButtonFlags /*= 0*/, UINT nHeaderTitle /*= 0*/, UINT nSubTitle /*= 0*/, STACK_INT *pstackPages /*=NULL*/)
  164. {
  165. CommonInitWiz97( pSecPolItem, dwFlags, dwWizButtonFlags, nHeaderTitle, nSubTitle );
  166. // Use the caller's callback which should call ours after it does whatever it does.
  167. SetCallback( pfnCallback );
  168. // Use the stack owned by our parent sheet
  169. m_pstackWiz97Pages = pstackPages;
  170. return S_OK;
  171. }
  172. void CSnapPage::CommonInitWiz97( CComObject<CSecPolItem> *pSecPolItem, DWORD dwFlags, DWORD dwWizButtonFlags, UINT nHeaderTitle, UINT nSubTitle )
  173. {
  174. m_psp.dwFlags |= dwFlags;
  175. // they called us this way, so ... they must expect ...
  176. m_bWiz97 = TRUE;
  177. // get strings
  178. CString str;
  179. str.LoadString (nHeaderTitle);
  180. m_pHeaderTitle = (TCHAR*) malloc ((str.GetLength()+1)*sizeof(TCHAR));
  181. if (m_pHeaderTitle)
  182. {
  183. lstrcpy (m_pHeaderTitle, str.GetBuffer(20));
  184. } else
  185. {
  186. m_pHeaderTitle = _T("\0");
  187. }
  188. str.ReleaseBuffer(-1);
  189. str.LoadString (nSubTitle);
  190. m_pHeaderSubTitle = (TCHAR*) malloc ((str.GetLength()+1)*sizeof(TCHAR));
  191. if (m_pHeaderSubTitle)
  192. {
  193. lstrcpy (m_pHeaderSubTitle, str.GetBuffer(20));
  194. } else
  195. {
  196. m_pHeaderSubTitle = _T("\0");
  197. }
  198. m_psp.pszHeaderTitle = m_pHeaderTitle;
  199. m_psp.pszHeaderSubTitle = m_pHeaderSubTitle;
  200. // save off the button flags
  201. m_dwWizButtonFlags = dwWizButtonFlags;
  202. // save the snapitem
  203. SetResultObject(pSecPolItem);
  204. }
  205. void CSnapPage::SetCallback( LPFNPSPCALLBACK pfnCallback )
  206. {
  207. // attempt the wilder CSnapPage mmc stuff
  208. // store the existing Callback information (if any)
  209. if (m_psp.dwFlags |= PSP_USECALLBACK)
  210. {
  211. m_pDefaultCallback = m_psp.pfnCallback;
  212. }
  213. // hook up our callback function
  214. m_psp.dwFlags |= PSP_USECALLBACK;
  215. m_psp.lParam = reinterpret_cast<LONG_PTR>(this);
  216. m_psp.pfnCallback = pfnCallback;
  217. // IF WE SWITCH TO DLL VERSION OF MFC WE NEED THIS
  218. // hook up mmc (this is an mmc hack to avoid an issue with AFX_MANAGE_STATE in MFC)
  219. HRESULT hr = ::MMCPropPageCallback (&m_psp);
  220. ASSERT (hr == S_OK);
  221. }
  222. #endif
  223. void CSnapPage::SetPostRemoveFocus( int nListSel, UINT nAddId, UINT nRemoveId, CWnd *pwndPrevFocus )
  224. {
  225. ASSERT( 0 != nAddId );
  226. ASSERT( 0 != nRemoveId );
  227. // Fix up focus, if necessary
  228. SET_POST_REMOVE_FOCUS<CDialog>( this, nListSel, nAddId, nRemoveId, pwndPrevFocus );
  229. }
  230. BOOL CSnapPage::OnWizardFinish()
  231. {
  232. return CPropertyPage::OnWizardFinish();
  233. }
  234. HRESULT CSnapPage::Initialize( CComObject<CSecPolItem> *pSecPolItem)
  235. {
  236. HRESULT hr = S_OK;
  237. // turn on an hourglass
  238. CWaitCursor waitCursor;
  239. // store the snap object
  240. ASSERT( NULL == m_pspiResultItem );
  241. SetResultObject(pSecPolItem);
  242. ASSERT( NULL != m_pspiResultItem );
  243. // store the existing Callback information (if any)
  244. if (m_psp.dwFlags |= PSP_USECALLBACK)
  245. {
  246. m_pDefaultCallback = m_psp.pfnCallback;
  247. }
  248. // hook up our callback function
  249. m_psp.dwFlags |= PSP_USECALLBACK;
  250. m_psp.lParam = reinterpret_cast<LONG_PTR>(this);
  251. m_psp.pfnCallback = CSnapPage::PropertyPageCallback;
  252. // IF WE SWITCH TO DLL VERSION OF MFC WE NEED THIS
  253. // hook up mmc (this is an mmc hack to avoid an issue with AFX_MANAGE_STATE in MFC)
  254. hr = ::MMCPropPageCallback (&m_psp);
  255. ASSERT (hr == S_OK);
  256. return hr;
  257. };
  258. void CSnapPage::SetModified( BOOL bChanged /*= TRUE*/ )
  259. {
  260. // Ignore modifications made during dialog initialization, its not
  261. // the user doing anything.
  262. if (!HandlingInitDialog())
  263. {
  264. m_bModified = bChanged;
  265. if (bChanged && m_spManager.p)
  266. m_spManager->SetModified(TRUE);
  267. }
  268. CPropertyPage::SetModified( bChanged );
  269. }
  270. /////////////////////////////////////////////////////////////////////////////
  271. // CSnapPage message handlers
  272. BOOL CSnapPage::OnInitDialog()
  273. {
  274. m_bInitializing = TRUE;
  275. #ifdef _DEBUG
  276. if (m_bDebugNewState)
  277. {
  278. // Page should be unmodified, unless its explicitly set new.
  279. ASSERT( m_bModified );
  280. }
  281. else
  282. {
  283. ASSERT( !m_bModified );
  284. }
  285. #endif
  286. // add context help to the style bits
  287. if (GetParent())
  288. {
  289. //GetParent()->ModifyStyleEx (0, WS_EX_CONTEXTHELP, 0);
  290. }
  291. // call base class and dis-regard return value as per the docs
  292. CPropertyPage::OnInitDialog();
  293. return TRUE;
  294. }
  295. BOOL CSnapPage::OnApply()
  296. {
  297. BOOL fRet = TRUE;
  298. if (!m_bWiz97) //$review do we need this bool check here?
  299. {
  300. m_bModified = FALSE;
  301. if (m_spManager.p && m_spManager->IsModified()) //to avoid call mutliple times
  302. {
  303. //the manager will force other pages in the sheet to apply
  304. fRet = m_spManager->OnApply();
  305. }
  306. }
  307. if (fRet)
  308. {
  309. return CPropertyPage::OnApply();
  310. }
  311. else
  312. {
  313. //Some page refuse to apply, we set this page back to dirty (will also
  314. // in turn set the property sheet manager to dirty)
  315. SetModified();
  316. }
  317. return fRet;
  318. }
  319. void CSnapPage::OnCancel()
  320. {
  321. if (m_spManager.p)
  322. {
  323. m_spManager->OnCancel();
  324. }
  325. // pass to base class
  326. CPropertyPage::OnCancel();
  327. }
  328. void CSnapPage::OnDestroy()
  329. {
  330. CPropertyPage::OnDestroy();
  331. }
  332. BOOL CSnapPage::ActivateThisPage()
  333. {
  334. BOOL bRet = FALSE;
  335. // Activate this page so it is visible. Return TRUE if successful.
  336. // if the page is in a wizard, it wont have a property sheet manager
  337. if (m_spManager.p)
  338. {
  339. CPropertySheet * pSheet = m_spManager->PropertySheet();
  340. if (pSheet)
  341. {
  342. pSheet->SetActivePage(this);
  343. bRet = TRUE;
  344. }
  345. }
  346. return bRet;
  347. }
  348. BOOL CSnapPage::CancelApply()
  349. {
  350. // This function should be called from OnApply when changes made
  351. // to the page are being rejected.
  352. // Return FALSE to abort the OnApply
  353. return FALSE;
  354. }
  355. IMPLEMENT_DYNCREATE(CSnapinPropPage, CSnapPage)
  356. //Check whether the Cancel button of the property sheet is disabled by CancelToClose
  357. BOOL CSnapPage::IsCancelEnabled()
  358. {
  359. BOOL fRet = TRUE;
  360. CWnd * pWnd = GetParent()->GetDlgItem(IDCANCEL);
  361. ASSERT(pWnd);
  362. if (pWnd)
  363. {
  364. fRet = pWnd->IsWindowEnabled();
  365. }
  366. return fRet;
  367. }
  368.