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.

476 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AtlBaseWiz.h
  7. //
  8. // Implementation File:
  9. // AtlBaseWiz.cpp
  10. //
  11. // Description:
  12. // Definition of the CWizardWindow and CWizardImpl classes.
  13. //
  14. // Author:
  15. // David Potter (davidp) December 2, 1997
  16. //
  17. // Revision History:
  18. //
  19. // Notes:
  20. //
  21. /////////////////////////////////////////////////////////////////////////////
  22. #ifndef __ATLBASEWIZ_H_
  23. #define __ATLBASEWIZ_H_
  24. // Required because of class names longer than 16 characters in lists.
  25. #pragma warning( disable : 4786 ) // identifier was truncated to '255' characters in the browser information
  26. /////////////////////////////////////////////////////////////////////////////
  27. // Forward Class Declarations
  28. /////////////////////////////////////////////////////////////////////////////
  29. class CWizardWindow;
  30. template < class T, class TBase > class CWizardImpl;
  31. /////////////////////////////////////////////////////////////////////////////
  32. // External Class Declarations
  33. /////////////////////////////////////////////////////////////////////////////
  34. class CWizardPageWindow;
  35. class CWizardPageList;
  36. class CDynamicWizardPageList;
  37. class CExtensionWizardPageList;
  38. class CClusterObject;
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Include Files
  41. /////////////////////////////////////////////////////////////////////////////
  42. #ifndef __ADMCOMMONRES_H_
  43. #include "AdmCommonRes.h" // for ID_WIZNEXT, etc.
  44. #endif
  45. #ifndef __ATLBASESHEET_H_
  46. #include "AtlBaseSheet.h" // for CBaseSheetWindow
  47. #endif
  48. /////////////////////////////////////////////////////////////////////////////
  49. // Type Definitions
  50. /////////////////////////////////////////////////////////////////////////////
  51. /////////////////////////////////////////////////////////////////////////////
  52. //++
  53. //
  54. // class CWizardWindow
  55. //
  56. // Description:
  57. // Base wizard property sheet window.
  58. //
  59. // Inheritance:
  60. // CWizardWindow
  61. // CBaseSheetWindow
  62. // CPropertySheetWindow
  63. //
  64. //--
  65. /////////////////////////////////////////////////////////////////////////////
  66. class CWizardWindow : public CBaseSheetWindow
  67. {
  68. typedef CBaseSheetWindow baseClass;
  69. friend class CWizardPageWindow;
  70. public:
  71. //
  72. // Construction
  73. //
  74. // Standard constructor
  75. CWizardWindow( HWND hWnd = NULL )
  76. : baseClass( hWnd )
  77. , m_plwpPages( NULL )
  78. , m_plewpNormal( NULL )
  79. , m_plewpAlternate( NULL )
  80. , m_pwizAlternate( NULL )
  81. , m_pcoObjectToExtend( NULL )
  82. , m_nLastWizardButton( 0 )
  83. {
  84. m_pwizCurrent = this;
  85. } //*** CWizardWindow()
  86. // Destructor
  87. ~CWizardWindow( void );
  88. protected:
  89. CWizardPageList * m_plwpPages; // List of pages in the wizard.
  90. CExtensionWizardPageList * m_plewpNormal; // List of normal extension pages.
  91. CExtensionWizardPageList * m_plewpAlternate; // List of alternate extension pages.
  92. CWizardWindow * m_pwizAlternate; // Alternate extension wizard.
  93. CWizardWindow * m_pwizCurrent; // Currently visible wizard.
  94. CClusterObject * m_pcoObjectToExtend; // Cluster object to extend.
  95. int m_nLastWizardButton; // Indicates the last wizard button pressed.
  96. public:
  97. //
  98. // Access methods.
  99. //
  100. // Access list of pages in the wizard
  101. CWizardPageList * PlwpPages( void )
  102. {
  103. ATLASSERT( m_plwpPages != NULL );
  104. return m_plwpPages;
  105. } //*** PlwpPages()
  106. // Access list of normal extension pages
  107. CExtensionWizardPageList * PlewpNormal( void ) { return m_plewpNormal; }
  108. // Access list of alternate extension pages
  109. CExtensionWizardPageList * PlewpAlternate( void ) { return m_plewpAlternate; }
  110. // Access alternate extension wizard
  111. CWizardWindow * PwizAlternate( void ) { return m_pwizAlternate; }
  112. // Access currently visible wizard
  113. CWizardWindow * PwizCurrent( void ) { return m_pwizCurrent; }
  114. // Set the current wizard
  115. void SetCurrentWizard( CWizardWindow * pwizCurrent )
  116. {
  117. ATLASSERT( pwizCurrent != NULL );
  118. ATLASSERT( ( pwizCurrent == this ) || ( pwizCurrent == m_pwizAlternate ) );
  119. m_pwizCurrent = pwizCurrent;
  120. } //*** SetCurrentWizard()
  121. // Set the alternate extension wizard
  122. void SetAlternateWizard( IN CWizardWindow * pwiz )
  123. {
  124. ATLASSERT( pwiz != NULL );
  125. m_pwizAlternate = pwiz;
  126. } //*** SetAlternateWizard()
  127. // Delete the alternate extension wizard
  128. void DeleteAlternateWizard( void )
  129. {
  130. ATLASSERT( m_pwizAlternate != NULL );
  131. ATLASSERT( m_pwizCurrent != m_pwizAlternate );
  132. delete m_pwizAlternate;
  133. m_pwizAlternate = NULL;
  134. } //*** ClearAlternateWizard()
  135. // Access the cluster object to extend
  136. CClusterObject * PcoObjectToExtend( void ) { return m_pcoObjectToExtend; }
  137. // Set the object to extend
  138. void SetObjectToExtend( IN CClusterObject * pco )
  139. {
  140. ATLASSERT( pco != NULL );
  141. m_pcoObjectToExtend = pco;
  142. } //*** SetObjectToExtend()
  143. // Returns the last wizard button pressed
  144. int NLastWizardButton( void ) const { return m_nLastWizardButton; }
  145. // Set the last wizard button pressed
  146. void SetLastWizardButton( IN int idCtrl )
  147. {
  148. ATLASSERT( (idCtrl == ID_WIZBACK) || (idCtrl == ID_WIZNEXT) || (idCtrl == IDCANCEL) );
  149. m_nLastWizardButton = idCtrl;
  150. } //*** SetLastWizardButton()
  151. // Returns whether the Back button was pressed
  152. BOOL BBackPressed( void ) const { return (m_nLastWizardButton == ID_WIZBACK); }
  153. // Returns whether the Next button was pressed
  154. BOOL BNextPressed( void ) const { return (m_nLastWizardButton == ID_WIZNEXT); }
  155. // Returns whether the Cancel button was pressed
  156. BOOL BCancelPressed( void ) const { return (m_nLastWizardButton == IDCANCEL); }
  157. // Returns whether the wizard is Wizard97 compliant or not
  158. BOOL BWizard97( void ) const { return (Ppsh()->dwFlags & PSH_WIZARD97) == PSH_WIZARD97; }
  159. public:
  160. // Add a page (required to get to base class method)
  161. void AddPage( HPROPSHEETPAGE hPage )
  162. {
  163. CBaseSheetWindow::AddPage( hPage );
  164. } //*** AddPage( hPage )
  165. // Add a page (required to get to base class method)
  166. BOOL AddPage( LPCPROPSHEETPAGE pPage )
  167. {
  168. return CBaseSheetWindow::AddPage( pPage );
  169. } //*** AddPage( pPage )
  170. // Add a page to wizard
  171. BOOL BAddPage( IN CWizardPageWindow * pwp );
  172. // Set the next page to be displayed
  173. void SetNextPage( IN CWizardPageWindow * pwCurrentPage, IN LPCTSTR pszNextPage );
  174. // Set the next page to be displayed from a dialog ID
  175. void SetNextPage( IN CWizardPageWindow * pwCurrentPage, IN UINT idNextPage )
  176. {
  177. SetNextPage( pwCurrentPage, MAKEINTRESOURCE( idNextPage ) );
  178. } //*** SetNextPage( idNextPage )
  179. // Handler for BN_CLICKED for ID_WIZFINISH
  180. LRESULT OnWizFinish(
  181. WORD wNotifyCode,
  182. WORD idCtrl,
  183. HWND hwndCtrl,
  184. BOOL & bHandled
  185. )
  186. {
  187. EnumChildWindows( m_hWnd, &ECWCallback, (LPARAM) this );
  188. if ( m_pwizAlternate != NULL )
  189. {
  190. return m_pwizAlternate->OnWizFinish( wNotifyCode, idCtrl, hwndCtrl, bHandled );
  191. } // if: alternate wizard exists
  192. bHandled = FALSE;
  193. return FALSE;
  194. } //*** OnWizFinish()
  195. static BOOL CALLBACK ECWCallback( HWND hWnd, LPARAM lParam )
  196. {
  197. CWizardWindow *pww = (CWizardWindow *) lParam;
  198. NMHDR nmhdr;
  199. // If we enumerated ourself, skip
  200. if ( pww->m_hWnd == hWnd )
  201. {
  202. return TRUE;
  203. } // if: enumerating ourself
  204. nmhdr.hwndFrom = pww->m_hWnd;
  205. nmhdr.idFrom = 0;
  206. nmhdr.code = PSN_WIZFINISH;
  207. SendMessage( hWnd, WM_NOTIFY, 0, (LPARAM) &nmhdr );
  208. return TRUE;
  209. } //*** ECWCallback()
  210. public:
  211. //
  212. // CWizardWindow methods.
  213. //
  214. // Enable or disable the Next button
  215. void EnableNext( IN BOOL bEnable, IN DWORD fDefaultWizardButtons )
  216. {
  217. ATLASSERT( fDefaultWizardButtons != 0 );
  218. //
  219. // If there is an alternate wizard, send this message to it.
  220. //
  221. if ( PwizCurrent() == PwizAlternate() )
  222. {
  223. PwizAlternate()->EnableNext( bEnable, fDefaultWizardButtons );
  224. } // if: there is an alternate wizard
  225. else
  226. {
  227. //
  228. // Get the buttons for the wizard.
  229. //
  230. DWORD fWizardButtons = fDefaultWizardButtons;
  231. //
  232. // If the Next button is to be disabled, make sure we show a
  233. // disabled Finish button if the Finish button is supposed to be
  234. // displayed. Otherwise a disabled Next button will be displayed.
  235. //
  236. if ( ! bEnable )
  237. {
  238. fWizardButtons &= ~(PSWIZB_NEXT | PSWIZB_FINISH);
  239. if ( fDefaultWizardButtons & PSWIZB_FINISH )
  240. {
  241. fWizardButtons |= PSWIZB_DISABLEDFINISH;
  242. } // if: finish button displayed
  243. } // if: disabling the button
  244. //
  245. // Set the new button states.
  246. //
  247. SetWizardButtons( fWizardButtons );
  248. } // else: no alternate wizard
  249. } //*** EnableNext()
  250. public:
  251. //
  252. // Overrides of abstract methods.
  253. //
  254. // Add extension pages to the sheet
  255. virtual void AddExtensionPages( IN HFONT hfont, IN HICON hicon );
  256. // Add a page (called by extension)
  257. virtual HRESULT HrAddExtensionPage( IN CBasePageWindow * ppage );
  258. // Handle a reset from one of the pages
  259. virtual void OnReset( void )
  260. {
  261. } //*** OnReset()
  262. public:
  263. //
  264. // Message handler functions.
  265. //
  266. // Handler for PSCB_INITIALIZED
  267. void OnSheetInitialized( void );
  268. // Implementation
  269. protected:
  270. // Prepare to add exension pages to the wizard
  271. void PrepareToAddExtensionPages( IN OUT CDynamicWizardPageList & rldwp );
  272. // Complete the process of adding extension pages
  273. void CompleteAddingExtensionPages( IN OUT CDynamicWizardPageList & rldwp );
  274. // Remove all extension pages from the wizard
  275. void RemoveAllExtensionPages( void );
  276. }; //*** class CWizardWindow
  277. /////////////////////////////////////////////////////////////////////////////
  278. //++
  279. //
  280. // class CWizardImpl
  281. //
  282. // Description:
  283. // Base wizard property sheet implementation.
  284. //
  285. // Inheritance:
  286. // CWizardImpl< T, TBase >
  287. // CBaseSheetImpl< T, TBase >
  288. // CPropertySheetImpl< T, TBase >
  289. // <TBase>
  290. // ...
  291. // CWizardWindow
  292. // CBaseSheetWindow
  293. // CPropertySheetWindow
  294. //
  295. //--
  296. /////////////////////////////////////////////////////////////////////////////
  297. template < class T, class TBase = CWizardWindow >
  298. class CWizardImpl : public CBaseSheetImpl< T, TBase >
  299. {
  300. typedef CWizardImpl< T, TBase > thisClass;
  301. typedef CBaseSheetImpl< T, TBase > baseClass;
  302. public:
  303. //
  304. // Construction
  305. //
  306. // Standard constructor
  307. CWizardImpl(
  308. IN LPCTSTR lpszTitle = NULL,
  309. IN UINT uStartPage = 0
  310. )
  311. : CBaseSheetImpl< T, TBase >( lpszTitle, uStartPage )
  312. {
  313. // Make this sheet a wizard.
  314. SetWizardMode();
  315. // Set the pointer in the base window class to our prop sheet header.
  316. m_ppsh = &m_psh;
  317. } //*** CWizardImpl( lpszTitle )
  318. // Constructor taking a resource ID for the title
  319. CWizardImpl(
  320. IN UINT nIDTitle,
  321. IN UINT uStartPage = 0
  322. )
  323. : CBaseSheetImpl< T, TBase >( NULL, uStartPage )
  324. {
  325. m_strTitle.LoadString( nIDTitle );
  326. m_psh.pszCaption = m_strTitle;
  327. // Make this sheet a wizard.
  328. SetWizardMode();
  329. // Set the pointer in the base window class to our prop sheet header.
  330. m_ppsh = &m_psh;
  331. } //*** CWizardImpl( nIDTitle )
  332. public:
  333. //
  334. // Message map.
  335. //
  336. BEGIN_MSG_MAP( thisClass )
  337. COMMAND_HANDLER( ID_WIZBACK, BN_CLICKED, OnButtonPressed )
  338. COMMAND_HANDLER( ID_WIZNEXT, BN_CLICKED, OnButtonPressed )
  339. COMMAND_HANDLER( ID_WIZFINISH, BN_CLICKED, OnWizFinish )
  340. COMMAND_HANDLER( IDCANCEL, BN_CLICKED, OnButtonPressed )
  341. CHAIN_MSG_MAP( baseClass )
  342. END_MSG_MAP()
  343. //
  344. // Message handler functions.
  345. //
  346. // Handler for BN_CLICKED on wizard buttons
  347. LRESULT OnButtonPressed(
  348. WORD wNotifyCode,
  349. WORD idCtrl,
  350. HWND hwndCtrl,
  351. BOOL & bHandled
  352. )
  353. {
  354. m_nLastWizardButton = idCtrl;
  355. bHandled = FALSE;
  356. return 0;
  357. } //*** OnButtonPressed()
  358. // Implementation
  359. protected:
  360. CString m_strTitle; // Used to support resource IDs for the title.
  361. public:
  362. const CString & StrTitle( void ) const { return m_strTitle; }
  363. // Set the title of the sheet
  364. void SetTitle( LPCTSTR lpszText, UINT nStyle = 0 )
  365. {
  366. baseClass::SetTitle( lpszText, nStyle );
  367. m_strTitle = lpszText;
  368. } //*** SetTitle()
  369. }; //*** class CWizardImpl
  370. /////////////////////////////////////////////////////////////////////////////
  371. // Global Function Prototypes
  372. /////////////////////////////////////////////////////////////////////////////
  373. // Create a dialog template for use with a dummy page
  374. DLGTEMPLATE * PdtCreateDummyPageDialogTemplate( IN WORD cx, IN WORD cy );
  375. /////////////////////////////////////////////////////////////////////////////
  376. #endif // __ATLBASEWIZ_H_