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.

472 lines
14 KiB

  1. //============================================================================
  2. // Copyright (C) Microsoft Corporation, 1996 - 1999
  3. //
  4. // File: sheet.h
  5. //
  6. // History:
  7. // Abolade Gbadegesin April-17-1996 Created.
  8. //
  9. // This file contains declarations for the CPropertySheetEx_Mine class,
  10. // which is based on CPropertySheet and supports modal or modeless display.
  11. //============================================================================
  12. #ifndef _SHEET_H_
  13. #define _SHEET_H_
  14. //----------------------------------------------------------------------------
  15. // Class: CPropertySheetEx_Mine
  16. //----------------------------------------------------------------------------
  17. class CPropertySheetEx_Mine : public CPropertySheet {
  18. DECLARE_DYNAMIC(CPropertySheetEx_Mine)
  19. public:
  20. //-------------------------------------------------------------------
  21. // Constructors
  22. //
  23. //-------------------------------------------------------------------
  24. CPropertySheetEx_Mine(
  25. UINT nIDCaption,
  26. CWnd* pParent = NULL,
  27. UINT iPage = 0
  28. ) : CPropertySheet(nIDCaption, pParent, iPage),
  29. m_bSheetModal(FALSE),
  30. m_bDllInvoked(FALSE)
  31. {
  32. m_psh.dwFlags &= ~(PSH_HASHELP);
  33. }
  34. CPropertySheetEx_Mine(
  35. LPCTSTR pszCaption,
  36. CWnd* pParent = NULL,
  37. UINT iPage = 0
  38. ) : CPropertySheet(pszCaption, pParent, iPage),
  39. m_bSheetModal(FALSE),
  40. m_bDllInvoked(FALSE)
  41. {
  42. m_psh.dwFlags &= ~(PSH_HASHELP);
  43. }
  44. CPropertySheetEx_Mine(
  45. ) : m_bDllInvoked(FALSE),
  46. m_bSheetModal(FALSE)
  47. {
  48. m_psh.dwFlags &= ~(PSH_HASHELP);
  49. }
  50. //-------------------------------------------------------------------
  51. // Function: DestroyWindow
  52. //
  53. // Checks whether the sheet was invoked modeless from a DLL,
  54. // and if so tells the admin-thread to destroy the sheet.
  55. // This is necessary since DestroyWindow can only be invoked
  56. // from the context of the thread which created the window.
  57. //-------------------------------------------------------------------
  58. virtual BOOL
  59. DestroyWindow( );
  60. //-------------------------------------------------------------------
  61. // Function: OnHelpInfo
  62. //
  63. // This is called by MFC in response to WM_HELP message
  64. //
  65. //
  66. //-------------------------------------------------------------------
  67. afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
  68. //-------------------------------------------------------------------
  69. // Function: DoModeless
  70. //
  71. // Invoked to show the modeless property sheet
  72. //-------------------------------------------------------------------
  73. BOOL
  74. DoModeless(
  75. CWnd* pParent = NULL,
  76. BOOL bDllInvoked = FALSE );
  77. //-------------------------------------------------------------------
  78. // Function: OnInitDialog
  79. //
  80. // Invokes the base OnInitDialog and then if DoModeless was called,
  81. // shows the buttons OK, Cancel, Apply, and Help which are hidden
  82. // in the default CPropertySheet::OnInitDialog
  83. //-------------------------------------------------------------------
  84. virtual BOOL
  85. OnInitDialog( );
  86. //-------------------------------------------------------------------
  87. // Function: PostNcDestroy
  88. //
  89. // Destroys the sheet's object if modeless
  90. //-------------------------------------------------------------------
  91. virtual void
  92. PostNcDestroy( ) {
  93. CPropertySheet::PostNcDestroy();
  94. if (!m_bSheetModal) { delete this; }
  95. }
  96. //-------------------------------------------------------------------
  97. // Function: PreTranslateMessage
  98. //
  99. // Replacement for CPropertySheet::PreTranslateMessage;
  100. // handles destruction of the sheet when it is modeless.
  101. //-------------------------------------------------------------------
  102. virtual BOOL
  103. PreTranslateMessage(
  104. MSG* pmsg );
  105. protected:
  106. // This is set to TRUE if we are calling this through DoModal().
  107. // We can't use the m_bModeless variable due to the Wiz97 changes.
  108. BOOL m_bSheetModal;
  109. BOOL m_bDllInvoked;
  110. DECLARE_MESSAGE_MAP()
  111. };
  112. //----------------------------------------------------------------------------
  113. // Type: PFNROUTERUICALLBACK
  114. //
  115. // Defines the callback function used by the CRtrPropertySheet class.
  116. //----------------------------------------------------------------------------
  117. typedef VOID
  118. (CALLBACK* PFNROUTERUICALLBACK)(
  119. IN HWND hwndSheet,
  120. IN VOID* pCallbackData,
  121. IN UINT uiCode
  122. );
  123. //----------------------------------------------------------------------------
  124. // Definitions of the callback codes passed by the CRtrPropertySheet class.
  125. //----------------------------------------------------------------------------
  126. #define RTRUI_Close 1
  127. #define RTRUI_Apply 2
  128. #define RTRUI_Changed 3
  129. #define RTRUI_Unchanged 4
  130. //----------------------------------------------------------------------------
  131. // Class: CRtrSheet
  132. //
  133. // This class is used by property sheets in the router administration tool.
  134. // It is intended to host pages derived from CRtrPropertyPage (below).
  135. //
  136. // It is an enhanced version of CPropertySheetEx_Mine; sheets derived
  137. // from this class allow their creators to specify a callback
  138. // to be invoked when certain events occur, such as closing the sheet or
  139. // applying changes.
  140. //
  141. // It also allows its contained pages to accumulate their changes in memory
  142. // when the user selects "Apply"; the changes are then saved together,
  143. // rather than having each page save its own changes.
  144. // Note that this increases the performance of the router UI, which uses RPC
  145. // to save its information; using this class results in a single RPC call
  146. // to save changes, rather than separate calls from each of the pages.
  147. //----------------------------------------------------------------------------
  148. class CRtrSheet : public CPropertySheetEx_Mine {
  149. DECLARE_DYNAMIC(CRtrSheet)
  150. public:
  151. //-------------------------------------------------------------------
  152. // Constructors
  153. //
  154. //-------------------------------------------------------------------
  155. CRtrSheet(
  156. PFNROUTERUICALLBACK pfnCallback,
  157. VOID* pCallbackData,
  158. UINT nIDCaption,
  159. CWnd* pParent = NULL,
  160. UINT iPage = 0
  161. ) : CPropertySheetEx_Mine(nIDCaption, pParent, iPage),
  162. m_pfnCallback(pfnCallback),
  163. m_pCallbackData(pCallbackData) { }
  164. CRtrSheet(
  165. PFNROUTERUICALLBACK pfnCallback,
  166. VOID* pCallbackData,
  167. LPCTSTR pszCaption,
  168. CWnd* pParent = NULL,
  169. UINT iPage = 0
  170. ) : CPropertySheetEx_Mine(pszCaption, pParent, iPage),
  171. m_pfnCallback(pfnCallback),
  172. m_pCallbackData(pCallbackData) { }
  173. CRtrSheet(
  174. ) : m_pfnCallback(NULL),
  175. m_pCallbackData(NULL) { }
  176. //-------------------------------------------------------------------
  177. // Function: Cancel
  178. //
  179. // Called to cancel the sheet.
  180. //-------------------------------------------------------------------
  181. virtual VOID
  182. Cancel(
  183. ) {
  184. if (!m_bSheetModal) { PressButton(PSBTN_CANCEL); }
  185. else { EndDialog(IDCANCEL); }
  186. }
  187. //-------------------------------------------------------------------
  188. // Function: Callback
  189. //
  190. // Called by contained pages to notify the sheet-owner of events
  191. //-------------------------------------------------------------------
  192. virtual VOID
  193. Callback(
  194. UINT uiMsg
  195. ) {
  196. if (m_pfnCallback) {
  197. m_pfnCallback(m_hWnd, m_pCallbackData, uiMsg);
  198. }
  199. }
  200. //-------------------------------------------------------------------
  201. // Function: DoModal
  202. //
  203. // Invoked to show a modal property sheet.
  204. //
  205. // We remove the 'Apply' button so that the page only gets applied
  206. // when the user hits OK.
  207. //
  208. // In addition, in order to avoid an MFC bug, lock the handle-map
  209. // for the caller's module. The bug surfaces when idle-processing
  210. // in MFC deletes the dialog's top-level parent from the temporary
  211. // handle-map, causing an assertion to fail as soon as the dialog
  212. // is dismissed.
  213. //-------------------------------------------------------------------
  214. virtual INT_PTR
  215. DoModal(
  216. ) {
  217. m_bSheetModal = TRUE;
  218. m_psh.dwFlags |= PSH_NOAPPLYNOW;
  219. m_psh.dwFlags &= ~(PSH_HASHELP);
  220. AfxLockTempMaps();
  221. INT_PTR ret = CPropertySheet::DoModal();
  222. AfxUnlockTempMaps();
  223. m_bSheetModal = FALSE;
  224. return ret;
  225. }
  226. //-------------------------------------------------------------------
  227. // Function: ApplyAll
  228. //
  229. // This should be overridden to call the "Apply" method of each of
  230. // the sheet's pages, collecting information, and then saving all
  231. // changes at once.
  232. //-------------------------------------------------------------------
  233. virtual BOOL
  234. ApplyAll( ) { return TRUE; }
  235. //-------------------------------------------------------------------
  236. // Function: PostNcDestroy
  237. //
  238. // notifies the UI framework that the sheet is being destroyed
  239. //-------------------------------------------------------------------
  240. virtual void
  241. PostNcDestroy( ) {
  242. Callback(RTRUI_Close);
  243. CPropertySheetEx_Mine::PostNcDestroy();
  244. }
  245. protected:
  246. PFNROUTERUICALLBACK m_pfnCallback;
  247. VOID* m_pCallbackData;
  248. };
  249. //----------------------------------------------------------------------------
  250. // Class: CRtrPage
  251. //
  252. // This class is used for property-pages in the router administration tool.
  253. // It is intended to be contained by a CRtrSheet-derived object.
  254. //
  255. // In addition to the behavior defined by CPropertyPage, this class
  256. // adds the ability to have a page accumulate its changes with those of
  257. // other pages in a sheet, and have the sheet save the collected changes.
  258. //
  259. // This is accomplished below by overriding "CPropertyPage::OnApply"
  260. // to call the parent-sheet's "CRtrSheet::ApplyAll" if the page
  261. // is the first page (i.e. the page with index 0).
  262. //
  263. // The parent's "ApplyAll" should then call the "CRtrSheet::Apply"
  264. // methods for each of the pages in the sheet, passing them a sheet-specific
  265. // pointer into which changes are to be collected. The parent then saves
  266. // the information for all of the pages.
  267. //
  268. // CRtrPage-derived objects can also notify the creator of the sheet
  269. // of events, by calling the "CRtrSheet::Callback" method.
  270. //----------------------------------------------------------------------------
  271. class CRtrPage : public CPropertyPage
  272. {
  273. DECLARE_DYNAMIC(CRtrPage)
  274. public:
  275. //-------------------------------------------------------------------
  276. // Constructors
  277. //
  278. //-------------------------------------------------------------------
  279. CRtrPage(
  280. LPCTSTR lpszTemplate,
  281. UINT nIDCaption = 0
  282. ) : CPropertyPage(lpszTemplate, nIDCaption)
  283. {
  284. m_psp.dwFlags &= ~(PSP_HASHELP);
  285. }
  286. CRtrPage(
  287. UINT nIDTemplate,
  288. UINT nIDCaption = 0
  289. ) : CPropertyPage(nIDTemplate, nIDCaption)
  290. {
  291. m_psp.dwFlags &= ~(PSP_HASHELP);
  292. }
  293. //-------------------------------------------------------------------
  294. // Function: Cancel
  295. //
  296. // Called to cancel the sheet.
  297. //-------------------------------------------------------------------
  298. virtual VOID
  299. Cancel(
  300. ) {
  301. ((CRtrSheet*)GetParent())->Cancel();
  302. }
  303. //-------------------------------------------------------------------
  304. // Function: OnApply
  305. //
  306. // Called by the MFC propsheet-proc when user clicks Apply;
  307. // the active page calls the pages' parent (CPropertySheet)
  308. // and the parent invokes the Apply method for each of its pages.
  309. //-------------------------------------------------------------------
  310. virtual BOOL
  311. OnApply( )
  312. {
  313. if (((CRtrSheet *)GetParent())->GetActiveIndex() !=
  314. ((CRtrSheet *)GetParent())->GetPageIndex(this))
  315. {
  316. return TRUE;
  317. }
  318. else
  319. {
  320. return ((CRtrSheet *)GetParent())->ApplyAll();
  321. }
  322. }
  323. //-------------------------------------------------------------------
  324. // Function: Apply
  325. //
  326. // called by the page's parent (CRtrSheet) to apply changes
  327. //-------------------------------------------------------------------
  328. virtual BOOL
  329. Apply(
  330. VOID* pArg
  331. ) {
  332. return TRUE;
  333. }
  334. //-------------------------------------------------------------------
  335. // Function: Callback
  336. //
  337. // notifies the UI framework of an event
  338. //-------------------------------------------------------------------
  339. virtual void
  340. Callback(
  341. UINT uiMsg ) {
  342. ((CRtrSheet *)GetParent())->Callback(uiMsg);
  343. }
  344. // help messages
  345. afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
  346. afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
  347. protected:
  348. // Use this call to get the actual help map
  349. // this version will check the global help map first.
  350. DWORD * GetHelpMapInternal();
  351. // override this to return the pointer to the help map
  352. virtual LPDWORD GetHelpMap() { return NULL; }
  353. DECLARE_MESSAGE_MAP()
  354. };
  355. #endif // _SHEET_H_