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.

458 lines
13 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1998 - 1998
  6. //
  7. // File: proppage.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _PROPPAGE_H
  11. #define _PROPPAGE_H
  12. // proppage.h : header file
  13. //
  14. ///////////////////////////////////////////////////////////////////////////////
  15. // FORWARD DECLARATIONS
  16. class CTreeNode;
  17. class CContainerNode;
  18. class CComponentDataObject;
  19. class CPropertyPageHolderBase;
  20. class CPropertyPageBase;
  21. class CPropertyPageHolderTable;
  22. class CWatermarkInfo;
  23. typedef CList< CPropertyPageBase*, CPropertyPageBase* > CPropertyPageBaseList;
  24. ////////////////////////////////////////////////////////////////////
  25. // CHiddenWndBase : Utility Hidden Window
  26. class CHiddenWndBase : public CWindowImpl<CHiddenWndBase>
  27. {
  28. public:
  29. DECLARE_WND_CLASS(L"DNSMgrHiddenWindow")
  30. BOOL Create(HWND hWndParent = NULL);
  31. BEGIN_MSG_MAP(CHiddenWndBase)
  32. END_MSG_MAP()
  33. };
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CSheetWnd
  36. class CSheetWnd : public CHiddenWndBase
  37. {
  38. public:
  39. static const UINT s_SheetMessage;
  40. static const UINT s_SelectPageMessage;
  41. CSheetWnd(CPropertyPageHolderBase* pHolder) { m_pHolder = pHolder;}
  42. BEGIN_MSG_MAP(CSheetWnd)
  43. MESSAGE_HANDLER( WM_CLOSE, OnClose )
  44. MESSAGE_HANDLER( CSheetWnd::s_SheetMessage, OnSheetMessage )
  45. MESSAGE_HANDLER( CSheetWnd::s_SelectPageMessage, OnSelectPageMessage )
  46. CHAIN_MSG_MAP(CHiddenWndBase)
  47. END_MSG_MAP()
  48. LRESULT OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  49. LRESULT OnSheetMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  50. LRESULT OnSelectPageMessage(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  51. private:
  52. CPropertyPageHolderBase* m_pHolder;
  53. };
  54. /////////////////////////////////////////////////////////////////////////////
  55. // CCloseDialogInfo
  56. class CCloseDialogInfo
  57. {
  58. public:
  59. CCloseDialogInfo()
  60. { m_hWnd = NULL; m_dwFlags = 0x0; }
  61. BOOL CloseDialog(BOOL bCheckForMsgBox);
  62. static BOOL CCloseDialogInfo::CloseMessageBox(HWND hWndParent);
  63. HWND m_hWnd;
  64. DWORD m_dwFlags;
  65. };
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CCloseDialogInfoStack
  68. template <UINT nSize> class CCloseDialogInfoStack
  69. {
  70. public:
  71. CCloseDialogInfoStack()
  72. {
  73. m_nTop = 0; // first empty
  74. m_bForcedClose = FALSE;
  75. }
  76. BOOL IsEmpty()
  77. {
  78. return m_nTop <= 0;
  79. }
  80. BOOL Push(HWND hWnd, DWORD dwFlags)
  81. {
  82. ASSERT(hWnd != NULL);
  83. ASSERT(::IsWindow(hWnd));
  84. if (m_nTop >= nSize)
  85. return FALSE;
  86. m_arr[m_nTop].m_hWnd = hWnd;
  87. m_arr[m_nTop].m_dwFlags = dwFlags;
  88. m_nTop++;
  89. return TRUE;
  90. }
  91. BOOL Pop()
  92. {
  93. if (m_bForcedClose)
  94. return TRUE; // going away
  95. if (m_nTop <= 0)
  96. return FALSE;
  97. m_nTop--;
  98. return TRUE;
  99. }
  100. void ForceClose(HWND hWndPage)
  101. {
  102. if (m_bForcedClose)
  103. {
  104. return; // avoid reentrancy
  105. }
  106. m_bForcedClose = TRUE;
  107. if (m_nTop > 0)
  108. {
  109. // have a stack to unwind
  110. BOOL bOutermost = TRUE;
  111. while (m_nTop > 0)
  112. {
  113. VERIFY(m_arr[m_nTop-1].CloseDialog(bOutermost));
  114. bOutermost = FALSE;
  115. m_nTop--;
  116. }
  117. }
  118. else
  119. {
  120. // empty stack, but might have a message box
  121. HWND hWndSheet = ::GetParent(hWndPage);
  122. ASSERT(hWndSheet != NULL);
  123. if (CCloseDialogInfo::CloseMessageBox(hWndSheet))
  124. VERIFY(::PostMessage(hWndSheet, WM_COMMAND, IDCANCEL, 0));
  125. }
  126. }
  127. private:
  128. UINT m_nTop;
  129. CCloseDialogInfo m_arr[nSize];
  130. BOOL m_bForcedClose;
  131. };
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CPropertyPageHolderBase
  134. class CPropertyPageHolderBase
  135. {
  136. public:
  137. // construction
  138. CPropertyPageHolderBase(CContainerNode* pContNode, CTreeNode* pNode,
  139. CComponentDataObject* pComponentData);
  140. virtual ~CPropertyPageHolderBase();
  141. // initialization
  142. // common
  143. void Attach(CPropertyPageHolderBase* pContHolder);
  144. BOOL EnableSheetControl(UINT nCtrlID, BOOL bEnable);
  145. // property sheet only
  146. static HRESULT CreateModelessSheet(CTreeNode* pNode, CComponentDataObject* pComponentData);
  147. HRESULT CreateModelessSheet(CTreeNode* pCookieNode);
  148. HRESULT CreateModelessSheet(LPPROPERTYSHEETCALLBACK pSheetCallback, LONG_PTR hConsoleHandle);
  149. void SetStartPageCode(int nStartPageCode)
  150. { m_nStartPageCode = nStartPageCode;}
  151. // wizard only
  152. HRESULT DoModalWizard();
  153. INT_PTR DoModalDialog(LPCTSTR pszCaption);
  154. // helpers
  155. // common
  156. void SetSheetWindow(HWND hSheetWindow);
  157. void SetSheetTitle(LPCWSTR lpszSheetTitle);
  158. void SetSheetTitle(UINT nStringFmtID, CTreeNode* pNode);
  159. void AddRef();
  160. void Release();
  161. DWORD GetRefCount() { return m_nCreatedCount;}
  162. CComponentDataObject* GetComponentData() { ASSERT(m_pComponentData != NULL); return m_pComponentData;}
  163. HWND GetMainWindow() { return m_hMainWnd;}
  164. // get/set for the node we are working on
  165. CTreeNode* GetTreeNode() { return m_pNode;}
  166. void SetTreeNode(CTreeNode* pNode) { m_pNode = pNode; }
  167. // get/set for the container we refer to
  168. CContainerNode* GetContainerNode()
  169. {
  170. return m_pContNode;
  171. }
  172. void SetContainerNode(CContainerNode* pContNode) { ASSERT(pContNode != NULL); m_pContNode = pContNode; }
  173. BOOL IsWizardMode();
  174. BOOL IsModalSheet();
  175. void ForceDestroy(); // forcefull shut down running sheet
  176. void AddPageToList(CPropertyPageBase* pPage);
  177. BOOL RemovePageFromList(CPropertyPageBase* pPage, BOOL bDeleteObject);
  178. // property sheet only
  179. BOOL PushDialogHWnd(HWND hWndModalDlg);
  180. BOOL PopDialogHWnd();
  181. void CloseModalDialogs(HWND hWndPage);
  182. DWORD NotifyConsole(CPropertyPageBase* pPage); // notify console of property changes
  183. void AcknowledgeNotify(); // acknowledge from the console
  184. virtual BOOL OnPropertyChange(BOOL bScopePane, long* pChangeMask); // execute from main thread
  185. // wizard only
  186. BOOL SetWizardButtons(DWORD dwFlags);
  187. BOOL SetWizardButtonsFirst(BOOL bValid)
  188. {
  189. return SetWizardButtons(bValid ? PSWIZB_NEXT : 0);
  190. }
  191. BOOL SetWizardButtonsMiddle(BOOL bValid)
  192. {
  193. return SetWizardButtons(bValid ? (PSWIZB_BACK|PSWIZB_NEXT) : PSWIZB_BACK);
  194. }
  195. BOOL SetWizardButtonsLast(BOOL bValid)
  196. {
  197. return SetWizardButtons(bValid ? (PSWIZB_BACK|PSWIZB_FINISH) : (PSWIZB_BACK|PSWIZB_DISABLEDFINISH));
  198. }
  199. HRESULT AddPageToSheet(CPropertyPageBase* pPage);
  200. HRESULT AddPageToSheetRaw(HPROPSHEETPAGE hPage);
  201. HRESULT RemovePageFromSheet(CPropertyPageBase* pPage);
  202. HRESULT AddAllPagesToSheet();
  203. protected:
  204. // common
  205. virtual HRESULT OnAddPage(int, CPropertyPageBase*) { return S_OK; }
  206. // property sheet only
  207. virtual void OnSheetMessage(WPARAM, LPARAM) {}
  208. virtual int OnSelectPageMessage(long) { return -1;}
  209. // wizard only
  210. void SetWatermarkInfo(CWatermarkInfo* pWatermarkInfo);
  211. private:
  212. void DeleteAllPages();
  213. void FinalDestruct();
  214. // attributes
  215. private:
  216. // common
  217. CString m_szSheetTitle; // title for the sheet/wizard window
  218. CPropertyPageBaseList m_pageList; // list of property page objects
  219. CPropertyPageHolderBase* m_pContHolder; // prop page holder that migh contain this
  220. CComponentDataObject* m_pComponentData; // cached pointer to CComponentDataImplementation
  221. HWND m_hMainWnd; // cached MMC frame window, if present
  222. protected:
  223. BOOL m_bWizardMode; // Wizard Mode (i.e. not modeless property sheet)
  224. BOOL m_bAutoDelete; // delete itself when refcount goes to zero
  225. BOOL m_bAutoDeletePages; // explicitely delete the property page C++ objects
  226. enum { useDefault, forceOn, forceOff } m_forceContextHelpButton; // setting for the [?] button
  227. private:
  228. DWORD m_nCreatedCount; // count of how many pages got actually created
  229. CTreeNode* m_pNode; // node the pages (or the wizard) refer to
  230. CContainerNode* m_pContNode; // container node the pages (or the wizard) refer to
  231. HWND m_hSheetWindow; // window handle to the sheet (thread safe)
  232. // property sheet only
  233. LONG_PTR m_hConsoleHandle; // handle for notifications to console
  234. HANDLE m_hEventHandle; // syncronization handle for property notifications
  235. CSheetWnd* m_pSheetWnd; // hidden window CWnd object for messages
  236. int m_nStartPageCode; // starting page code (not necessarily the page #)
  237. CCloseDialogInfoStack<5> m_dlgInfoStack; // modal dialogs stack (to close them down)
  238. // wizard only
  239. IPropertySheetCallback* m_pSheetCallback; // cached pointer to add/remove pages
  240. CPropertySheet* m_pDummySheet; // MFC surrogate property sheet for modal operations
  241. CWatermarkInfo* m_pWatermarkInfo; // watermark info for Wiz 97 sheets
  242. private:
  243. // property sheet only
  244. // variables to use across thread boundaries
  245. DWORD m_dwLastErr; // generic error code
  246. CPropertyPageBase* m_pPropChangePage; // page for which notification is valid
  247. public:
  248. void SetError(DWORD dwErr) { m_dwLastErr = dwErr;}
  249. CPropertyPageBase* GetPropChangePage()
  250. { ASSERT(m_pPropChangePage != NULL); return m_pPropChangePage; }
  251. friend class CSheetWnd;
  252. };
  253. /////////////////////////////////////////////////////////////////////////////
  254. // CPropertyPageBase
  255. class CPropertyPageBase : public CPropertyPage
  256. {
  257. // Construction
  258. private:
  259. CPropertyPageBase(){} // cannot use this constructor
  260. public:
  261. CPropertyPageBase(UINT nIDTemplate,
  262. UINT nIDCaption = 0);
  263. virtual ~CPropertyPageBase();
  264. // Overrides
  265. public:
  266. virtual BOOL OnInitDialog()
  267. {
  268. CWinApp* pApp = AfxGetApp();
  269. ASSERT(pApp);
  270. return CPropertyPage::OnInitDialog();
  271. }
  272. virtual void OnCancel();
  273. virtual BOOL OnApply();
  274. protected:
  275. // Generated message map functions
  276. //{{AFX_MSG(CGeneralPage)
  277. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  278. afx_msg void OnDestroy();
  279. //}}AFX_MSG
  280. afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  281. afx_msg void OnWhatsThis();
  282. virtual BOOL OnHelp(WPARAM wParam, LPARAM lParam);
  283. virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
  284. virtual void OnWizardHelp() {}
  285. DECLARE_MESSAGE_MAP()
  286. // attributes
  287. public:
  288. // common
  289. PROPSHEETPAGE m_psp97;
  290. HPROPSHEETPAGE m_hPage;
  291. void SetHolder(CPropertyPageHolderBase* pPageHolder)
  292. { ASSERT((pPageHolder != NULL) && (m_pPageHolder == NULL)); m_pPageHolder = pPageHolder;}
  293. CPropertyPageHolderBase* GetHolder() { return m_pPageHolder;};
  294. // property seet only
  295. virtual BOOL OnPropertyChange(BOOL, long*) // execute from main thread
  296. { return FALSE; /* do not repaint UI */ }
  297. // wizard only
  298. UINT m_nPrevPageID; // to be used by OnWizardBack()
  299. void InitWiz97(
  300. BOOL bHideHeader,
  301. UINT nIDHeaderTitle,
  302. UINT nIDHeaderSubTitle,
  303. bool hasHelp = false);
  304. private:
  305. CString m_szHeaderTitle;
  306. CString m_szHeaderSubTitle;
  307. protected:
  308. virtual void SetUIData(){}
  309. virtual void GetUIData(){}
  310. virtual LONG GetUIDataEx() { return 0;}
  311. virtual void SetDirty(BOOL bDirty);
  312. BOOL IsDirty() { return m_bIsDirty; }
  313. private:
  314. CPropertyPageHolderBase* m_pPageHolder; // backpointer to holder
  315. BOOL m_bIsDirty; // dirty flag
  316. HWND m_hWndWhatsThis; // hwnd of right click "What's this" help
  317. };
  318. /////////////////////////////////////////////////////////////////////////////
  319. // CPropertyPageHolderTable
  320. class CPropertyPageHolderTable
  321. {
  322. public:
  323. CPropertyPageHolderTable(CComponentDataObject* pComponentData);
  324. ~CPropertyPageHolderTable();
  325. void Add(CPropertyPageHolderBase* pPPHolder);
  326. void AddWindow(CPropertyPageHolderBase* pPPHolder, HWND hWnd);
  327. void Remove(CPropertyPageHolderBase* pPPHolder);
  328. void DeleteSheetsOfNode(CTreeNode* pNode);
  329. void WaitForAllToShutDown();
  330. // sheet notification mechanism
  331. void BroadcastMessageToSheets(CTreeNode* pNode, WPARAM wParam, LPARAM lParam);
  332. void BroadcastSelectPage(CTreeNode* pNode, long nPageCode);
  333. int BroadcastCloseMessageToSheets(CTreeNode* pNode);
  334. struct PPAGE_HOLDER_TABLE_ENTRY
  335. {
  336. CPropertyPageHolderBase* pPPHolder;
  337. CTreeNode* pNode;
  338. HWND hWnd;
  339. };
  340. PPAGE_HOLDER_TABLE_ENTRY* GetPageHolderTableEntry(){return m_pEntries;}
  341. int GetPageHolderTableEntrySize(){return m_nSize;}
  342. private:
  343. CComponentDataObject* m_pComponentData; // back pointer
  344. void WaitForSheetShutdown(int nCount, HWND* hWndArr = NULL);
  345. PPAGE_HOLDER_TABLE_ENTRY* m_pEntries;
  346. int m_nSize;
  347. };
  348. ////////////////////////////////////////////////////////////
  349. // CHelpDialog
  350. class CHelpDialog : public CDialog
  351. {
  352. // Construction
  353. private:
  354. CHelpDialog(){}
  355. public:
  356. CHelpDialog(UINT nIDTemplate, CComponentDataObject* pComponentData);
  357. CHelpDialog(UINT nIDTemplate, CWnd* pParentWnd, CComponentDataObject* pComponentData);
  358. virtual ~CHelpDialog() {};
  359. virtual void OnOK() { CDialog::OnOK(); }
  360. protected:
  361. afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  362. afx_msg void OnWhatsThis();
  363. afx_msg BOOL OnHelp(WPARAM wParam, LPARAM lParam);
  364. DECLARE_MESSAGE_MAP()
  365. private:
  366. HWND m_hWndWhatsThis; // hwnd of right click "What's this" help
  367. CComponentDataObject* m_pComponentData;
  368. };
  369. #endif // _PROPPAGE_H