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.

446 lines
12 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. afx_msg BOOL OnHelp(WPARAM wParam, LPARAM lParam);
  283. DECLARE_MESSAGE_MAP()
  284. // attributes
  285. public:
  286. // common
  287. PROPSHEETPAGE m_psp97;
  288. HPROPSHEETPAGE m_hPage;
  289. void SetHolder(CPropertyPageHolderBase* pPageHolder)
  290. { ASSERT((pPageHolder != NULL) && (m_pPageHolder == NULL)); m_pPageHolder = pPageHolder;}
  291. CPropertyPageHolderBase* GetHolder() { return m_pPageHolder;};
  292. // property seet only
  293. virtual BOOL OnPropertyChange(BOOL, long*) // execute from main thread
  294. { return FALSE; /* do not repaint UI */ }
  295. // wizard only
  296. UINT m_nPrevPageID; // to be used by OnWizardBack()
  297. void InitWiz97(BOOL bHideHeader, UINT nIDHeaderTitle, UINT nIDHeaderSubTitle);
  298. private:
  299. CString m_szHeaderTitle;
  300. CString m_szHeaderSubTitle;
  301. protected:
  302. virtual void SetUIData(){}
  303. virtual void GetUIData(){}
  304. virtual LONG GetUIDataEx() { return 0;}
  305. virtual void SetDirty(BOOL bDirty);
  306. BOOL IsDirty() { return m_bIsDirty; }
  307. private:
  308. CPropertyPageHolderBase* m_pPageHolder; // backpointer to holder
  309. BOOL m_bIsDirty; // dirty flag
  310. HWND m_hWndWhatsThis; // hwnd of right click "What's this" help
  311. };
  312. /////////////////////////////////////////////////////////////////////////////
  313. // CPropertyPageHolderTable
  314. class CPropertyPageHolderTable
  315. {
  316. public:
  317. CPropertyPageHolderTable(CComponentDataObject* pComponentData);
  318. ~CPropertyPageHolderTable();
  319. void Add(CPropertyPageHolderBase* pPPHolder);
  320. void AddWindow(CPropertyPageHolderBase* pPPHolder, HWND hWnd);
  321. void Remove(CPropertyPageHolderBase* pPPHolder);
  322. void DeleteSheetsOfNode(CTreeNode* pNode);
  323. void WaitForAllToShutDown();
  324. // sheet notification mechanism
  325. void BroadcastMessageToSheets(CTreeNode* pNode, WPARAM wParam, LPARAM lParam);
  326. void BroadcastSelectPage(CTreeNode* pNode, long nPageCode);
  327. int BroadcastCloseMessageToSheets(CTreeNode* pNode);
  328. private:
  329. CComponentDataObject* m_pComponentData; // back pointer
  330. void WaitForSheetShutdown(int nCount, HWND* hWndArr = NULL);
  331. struct PPAGE_HOLDER_TABLE_ENTRY
  332. {
  333. CPropertyPageHolderBase* pPPHolder;
  334. CTreeNode* pNode;
  335. HWND hWnd;
  336. };
  337. PPAGE_HOLDER_TABLE_ENTRY* m_pEntries;
  338. int m_nSize;
  339. };
  340. ////////////////////////////////////////////////////////////
  341. // CHelpDialog
  342. class CHelpDialog : public CDialog
  343. {
  344. // Construction
  345. private:
  346. CHelpDialog(){}
  347. public:
  348. CHelpDialog(UINT nIDTemplate, CComponentDataObject* pComponentData);
  349. CHelpDialog(UINT nIDTemplate, CWnd* pParentWnd, CComponentDataObject* pComponentData);
  350. virtual ~CHelpDialog() {};
  351. virtual void OnOK() { CDialog::OnOK(); }
  352. protected:
  353. afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  354. afx_msg void OnWhatsThis();
  355. afx_msg BOOL OnHelp(WPARAM wParam, LPARAM lParam);
  356. DECLARE_MESSAGE_MAP()
  357. private:
  358. HWND m_hWndWhatsThis; // hwnd of right click "What's this" help
  359. CComponentDataObject* m_pComponentData;
  360. };
  361. #endif // _PROPPAGE_H