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.

370 lines
9.5 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2001.
  5. //
  6. // File: Snppage.h
  7. //
  8. // Contents: WiF Policy Snapin
  9. //
  10. //
  11. // History: TaroonM
  12. // 10/30/01
  13. //
  14. //----------------------------------------------------------------------------
  15. #ifndef _SNPPAGE_H
  16. #define _SNPPAGE_H
  17. // CSnapPage.h : header file
  18. //
  19. // PSM_QUERYSIBLING helpers
  20. //
  21. // User defined message IDs, passed in wparam of message PSM_QUERYSIBLING
  22. #define PSM_QUERYSIBLING_ACTIVATED (WM_USER + 1)
  23. #ifdef WIZ97WIZARDS
  24. class CWiz97Sheet;
  25. #endif
  26. class CPropertySheetManager;
  27. class CSnapPage : public CPropertyPage
  28. {
  29. DECLARE_DYNCREATE(CSnapPage)
  30. CSnapPage(UINT nIDTemplate, BOOL bWiz97=FALSE, UINT nNextIDD=-1);
  31. CSnapPage() {ASSERT(0);};
  32. virtual ~CSnapPage();
  33. virtual HRESULT Initialize( CComObject<CSecPolItem>* pSecPolItem);
  34. void SetManager(CPropertySheetManager * pManager)
  35. {
  36. m_spManager = pManager;
  37. }
  38. UINT m_nIDD;
  39. UINT m_nNextIDD;
  40. BOOL m_bWiz97;
  41. #ifdef WIZ97WIZARDS
  42. public:
  43. virtual BOOL InitWiz97( CComObject<CSecPolItem> *pSecPolItem, DWORD dwFlags,
  44. DWORD dwWizButtonFlags = 0, UINT nHeaderTitle = 0, UINT nSubTitle = 0);
  45. virtual BOOL InitWiz97( LPFNPSPCALLBACK pfnCallback, CComObject<CSecPolItem> *pSecPolItem,
  46. DWORD dwFlags, DWORD dwWizButtonFlags = 0, UINT nHeaderTitle = 0, UINT nSubTitle = 0,
  47. STACK_INT *pstackPages=NULL);
  48. // our m_psp
  49. PROPSHEETPAGE m_psp;
  50. void Wiz97Sheet (CWiz97Sheet* pWiz97Sheet) {m_pWiz97Sheet = pWiz97Sheet;};
  51. CWiz97Sheet* Wiz97Sheet () {return m_pWiz97Sheet;};
  52. protected:
  53. void CommonInitWiz97( CComObject<CSecPolItem> *pSecPolItem, DWORD dwFlags,
  54. DWORD dwWizButtonFlags, UINT nHeaderTitle, UINT nSubTitle );
  55. void SetCallback( LPFNPSPCALLBACK pfnCallback );
  56. void SetPostRemoveFocus( int nListSel, UINT nAddId, UINT nRemoveId, CWnd *pwndPrevFocus );
  57. CWiz97Sheet* m_pWiz97Sheet;
  58. DWORD m_dwWizButtonFlags;
  59. TCHAR* m_pHeaderTitle;
  60. TCHAR* m_pHeaderSubTitle;
  61. #endif
  62. // Overrides
  63. public:
  64. // ClassWizard generate virtual function overrides
  65. //{{AFX_VIRTUAL(CSnapPage)
  66. public:
  67. virtual BOOL OnApply();
  68. virtual void OnCancel();
  69. virtual BOOL OnWizardFinish();
  70. #ifdef WIZ97WIZARDS
  71. virtual BOOL OnSetActive();
  72. virtual LRESULT OnWizardBack();
  73. virtual LRESULT OnWizardNext();
  74. #endif
  75. //}}AFX_VIRTUAL
  76. static UINT CALLBACK PropertyPageCallback (HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp);
  77. UINT (CALLBACK* m_pDefaultCallback) (HWND hwnd, UINT uMsg, LPPROPSHEETPAGE ppsp);
  78. // Don't need to save original LPARAM for m_pDefaultCallback. For some reason it works just
  79. // fine as is.
  80. //LPARAM m_paramDefaultCallback;
  81. void ProtectFromStaleData (BOOL bRefresh = TRUE) {m_bDoRefresh = bRefresh;};
  82. // Implementation
  83. public:
  84. BOOL IsModified() { return m_bModified; }
  85. //This is get called when the CPropertySheetManager notify the page
  86. //that the apply in the manager is done
  87. //See also CPropertySheetManager::NotifyManagerApplied
  88. virtual void OnManagerApplied() {};
  89. protected:
  90. //{{AFX_MSG(CSnapPage)
  91. virtual BOOL OnInitDialog();
  92. afx_msg void OnDestroy();
  93. //}}AFX_MSG
  94. DECLARE_MESSAGE_MAP()
  95. void SetResultObject( CComObject<CSecPolItem>* pSecPolItem )
  96. {
  97. CComObject<CSecPolItem> * pOldItem = m_pspiResultItem;
  98. m_pspiResultItem = pSecPolItem;
  99. if (m_pspiResultItem)
  100. {
  101. m_pspiResultItem->AddRef();
  102. }
  103. if (pOldItem)
  104. {
  105. pOldItem->Release();
  106. }
  107. }
  108. CComObject<CSecPolItem>* GetResultObject() { ASSERT( NULL != m_pspiResultItem ); return m_pspiResultItem; }
  109. // Want to test validity of m_pspiResultItem without actually getting the ptr.
  110. // We can keep the ASSERT in the accessor function this way.
  111. BOOL IsNullResultObject() { return NULL == m_pspiResultItem ? TRUE : FALSE; }
  112. void SetModified( BOOL bChanged = TRUE );
  113. BOOL IsCancelEnabled();
  114. BOOL ActivateThisPage();
  115. int PopWiz97Page ();
  116. void PushWiz97Page (int nIDD);
  117. virtual void OnFinishInitDialog()
  118. {
  119. m_bInitializing = FALSE;
  120. }
  121. BOOL HandlingInitDialog() { return m_bInitializing; }
  122. virtual BOOL CancelApply();
  123. CComObject <CSecPolItem>* m_pspiResultItem;
  124. CComPtr<CPropertySheetManager> m_spManager;
  125. private:
  126. BOOL m_bDoRefresh;
  127. BOOL m_bModified;
  128. BOOL m_bInitializing; // TRUE during OnInitDialog
  129. STACK_INT *m_pstackWiz97Pages;
  130. };
  131. //the class to handle MMC property pages
  132. class CSnapinPropPage : public CSnapPage
  133. {
  134. DECLARE_DYNCREATE(CSnapinPropPage)
  135. public:
  136. CSnapinPropPage (UINT nIDTemplate, BOOL fNotifyConsole = TRUE) :
  137. CSnapPage(nIDTemplate),
  138. m_fNotifyConsole (fNotifyConsole)
  139. {}
  140. CSnapinPropPage() :CSnapPage() {}
  141. virtual ~CSnapinPropPage() {}
  142. virtual BOOL OnApply()
  143. {
  144. if (IsModified() && m_pspiResultItem && m_fNotifyConsole)
  145. {
  146. LONG_PTR handleNotify = m_pspiResultItem->GetNotifyHandle();
  147. //We dont use CPropertySheetManager to control the prop sheet if this is
  148. //a MMC prop sheet. So we should call OnManagerApplied to let the page to
  149. //apply the data here
  150. if (!m_spManager.p)
  151. {
  152. OnManagerApplied();
  153. }
  154. if (handleNotify)
  155. MMCPropertyChangeNotify(handleNotify, (LPARAM) m_pspiResultItem);
  156. }
  157. return CSnapPage::OnApply();
  158. }
  159. protected:
  160. BOOL m_fNotifyConsole;
  161. };
  162. typedef CList<CSnapPage *, CSnapPage *> CListSnapPages;
  163. class ATL_NO_VTABLE CPropertySheetManager :
  164. public CComObjectRootEx<CComSingleThreadModel>,
  165. public IUnknown
  166. {
  167. BEGIN_COM_MAP(CPropertySheetManager)
  168. COM_INTERFACE_ENTRY(IUnknown)
  169. END_COM_MAP()
  170. public:
  171. CPropertySheetManager() :
  172. m_fModified (FALSE),
  173. m_fCanceled (FALSE),
  174. m_fDataChangeOnApply (FALSE)
  175. {}
  176. virtual ~CPropertySheetManager() {};
  177. BOOL IsModified() {
  178. return m_fModified;
  179. }
  180. void SetModified(BOOL fModified) {
  181. m_fModified = fModified;
  182. }
  183. BOOL IsCanceled() {
  184. return m_fCanceled;
  185. }
  186. BOOL HasEverApplied() {
  187. return m_fDataChangeOnApply;
  188. }
  189. CPropertySheet * PropertySheet()
  190. {
  191. return &m_Sheet;
  192. }
  193. virtual void AddPage(CSnapPage * pPage)
  194. {
  195. ASSERT(pPage);
  196. m_listPages.AddTail(pPage);
  197. pPage->SetManager(this);
  198. m_Sheet.AddPage(pPage);
  199. }
  200. virtual void OnCancel()
  201. {
  202. m_fCanceled = TRUE;
  203. }
  204. virtual BOOL OnApply()
  205. {
  206. if (!IsModified())
  207. return TRUE;
  208. BOOL fRet = TRUE;
  209. SetModified(FALSE); // prevent from doing this more than once
  210. CSnapPage * pPage;
  211. POSITION pos = m_listPages.GetHeadPosition();
  212. while(pos)
  213. {
  214. pPage = m_listPages.GetNext(pos);
  215. if (pPage->IsModified())
  216. {
  217. fRet = pPage->OnApply();
  218. //exit if any page says no
  219. if (!fRet)
  220. break;
  221. }
  222. }
  223. //OK we update data at least once now
  224. if (fRet)
  225. m_fDataChangeOnApply = TRUE;
  226. return fRet;
  227. }
  228. //the manager should call this method to notify the pages that
  229. //the apply in the manager is done, so that the page can do their
  230. //specific data operation
  231. virtual void NotifyManagerApplied()
  232. {
  233. CSnapPage * pPage;
  234. POSITION pos = m_listPages.GetHeadPosition();
  235. while(pos)
  236. {
  237. pPage = m_listPages.GetNext(pos);
  238. pPage->OnManagerApplied();
  239. }
  240. }
  241. virtual CPropertySheet * GetSheet()
  242. {
  243. return &m_Sheet;
  244. }
  245. virtual int DoModalPropertySheet()
  246. {
  247. return m_Sheet.DoModal();
  248. }
  249. protected:
  250. CPropertySheet m_Sheet;
  251. CListSnapPages m_listPages;
  252. BOOL m_fModified;
  253. BOOL m_fCanceled;
  254. BOOL m_fDataChangeOnApply;
  255. };
  256. class CMMCPropSheetManager : public CPropertySheetManager
  257. {
  258. public:
  259. CMMCPropSheetManager() :
  260. CPropertySheetManager(),
  261. m_fNotifyConsole(FALSE)
  262. {}
  263. void EnableConsoleNotify(
  264. LONG_PTR lpNotifyHandle,
  265. LPARAM lParam = 0
  266. )
  267. {
  268. m_fNotifyConsole = TRUE;
  269. m_lpNotifyHandle = lpNotifyHandle;
  270. m_lpNotifyParam = lParam;
  271. }
  272. void NotifyConsole()
  273. {
  274. if (m_fNotifyConsole && m_lpNotifyHandle)
  275. {
  276. ::MMCPropertyChangeNotify(
  277. m_lpNotifyHandle,
  278. m_lpNotifyParam
  279. );
  280. }
  281. }
  282. protected:
  283. LONG_PTR m_lpNotifyHandle;
  284. LPARAM m_lpNotifyParam;
  285. BOOL m_fNotifyConsole;
  286. };
  287. //Max number of chars in a name or description
  288. const UINT c_nMaxName = 255;
  289. #endif