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.

552 lines
15 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AtlBasePropSheet.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CBasePropertySheetWindow class.
  10. //
  11. // Author:
  12. // David Potter (davidp) February 26, 1998
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "AtlBasePropSheet.h"
  20. #include "AtlBasePropPage.h"
  21. #include "AtlExtDll.h"
  22. #include "StlUtils.h"
  23. #include "ExcOper.h"
  24. #include "AdmCommonRes.h"
  25. /////////////////////////////////////////////////////////////////////////////
  26. // class CBasePropertySheetWindow
  27. /////////////////////////////////////////////////////////////////////////////
  28. /////////////////////////////////////////////////////////////////////////////
  29. //++
  30. //
  31. // CBasePropertySheetWindow::~CBasePropertySheetWindow
  32. //
  33. // Routine Description:
  34. // Destructor.
  35. //
  36. // Arguments:
  37. // None.
  38. //
  39. // Return Value:
  40. // None.
  41. //
  42. // Exceptions Thrown:
  43. // None.
  44. //
  45. //--
  46. /////////////////////////////////////////////////////////////////////////////
  47. CBasePropertySheetWindow::~CBasePropertySheetWindow( void )
  48. {
  49. //
  50. // Delete pages from the page list.
  51. //
  52. if ( m_plppPages != NULL )
  53. {
  54. DeleteAllPtrListItems( m_plppPages );
  55. delete m_plppPages;
  56. } // if: page array has been allocated
  57. } //*** CBasePropertySheetWindow::~CBasePropertySheetWindow()
  58. /////////////////////////////////////////////////////////////////////////////
  59. //++
  60. //
  61. // CBasePropertySheetWindow::BInit
  62. //
  63. // Routine Description:
  64. // Initialize the sheet.
  65. //
  66. // Arguments:
  67. // None.
  68. //
  69. // Return Value:
  70. // TRUE Property sheet initialized successfully.
  71. // FALSE Error initializing the property sheet.
  72. //
  73. // Exceptions Thrown:
  74. // None.
  75. //
  76. //--
  77. /////////////////////////////////////////////////////////////////////////////
  78. BOOL CBasePropertySheetWindow::BInit( void )
  79. {
  80. ATLASSERT( PlppPages()->size() > 0 );
  81. ATLASSERT( m_hWnd == NULL );
  82. BOOL bSuccess = TRUE;
  83. CPropertyPageList::iterator itCurrent = PlppPages()->begin();
  84. CPropertyPageList::iterator itLast = PlppPages()->end();
  85. CStaticPropertyPageWindow * pspp;
  86. //
  87. // Add static pages.
  88. //
  89. for ( ; itCurrent != itLast ; itCurrent++ )
  90. {
  91. //
  92. // If this is a static page, add it to the list.
  93. //
  94. pspp = dynamic_cast< CStaticPropertyPageWindow * >( *itCurrent );
  95. if ( pspp != NULL )
  96. {
  97. //
  98. // Initialize the page.
  99. //
  100. bSuccess = pspp->BInit( this );
  101. if ( ! bSuccess )
  102. {
  103. break;
  104. } // if: error initializing the page
  105. //
  106. // Add the page.
  107. //
  108. bSuccess = AddPage( pspp->Ppsp() );
  109. if ( ! bSuccess )
  110. {
  111. CNTException nte(
  112. GetLastError(),
  113. ADMC_IDS_ADD_PAGE_TO_PROP_SHEET_ERROR,
  114. NULL,
  115. NULL,
  116. FALSE
  117. );
  118. nte.ReportError();
  119. break;
  120. } // if: error adding the page
  121. } // if: static page
  122. } // for: each page
  123. return bSuccess;
  124. } //*** CBasePropertySheetWindow::BInit()
  125. /////////////////////////////////////////////////////////////////////////////
  126. //++
  127. //
  128. // CBasePropertySheetWindow::BAddPage
  129. //
  130. // Routine Description:
  131. // Add a page to the page list.
  132. //
  133. // Arguments:
  134. // ppp [IN] Property page to add.
  135. //
  136. // Return Value:
  137. // TRUE Page added successfully.
  138. // FALSE Error adding page.
  139. //
  140. //--
  141. /////////////////////////////////////////////////////////////////////////////
  142. BOOL CBasePropertySheetWindow::BAddPage( IN CBasePropertyPageWindow * ppp )
  143. {
  144. ATLASSERT( ppp != NULL );
  145. BOOL bSuccess = FALSE;
  146. // Loop to avoid goto's.
  147. do
  148. {
  149. //
  150. // Allocate the page array if it doesn't exist yet.
  151. //
  152. if ( m_plppPages == NULL )
  153. {
  154. m_plppPages = new CPropertyPageList;
  155. ATLASSERT( m_plppPages != NULL );
  156. if ( m_plppPages == NULL )
  157. {
  158. CNTException nte(
  159. GetLastError(),
  160. ADMC_IDS_ADD_FIRST_PAGE_TO_PROP_SHEET_ERROR,
  161. NULL,
  162. NULL,
  163. FALSE
  164. );
  165. nte.ReportError();
  166. break;
  167. } // if: error allocating page list
  168. } // if: no page array yet
  169. //
  170. // Insert the page at the end of the list.
  171. //
  172. PlppPages()->insert( PlppPages()->end(), ppp );
  173. bSuccess = TRUE;
  174. } while ( 0 );
  175. return bSuccess;
  176. } //*** CBasePropertySheetWindow::BAddPage()
  177. /////////////////////////////////////////////////////////////////////////////
  178. //++
  179. //
  180. // CBasePropertySheetWindow::OnSheetInitialized
  181. //
  182. // Routine Description:
  183. // Handler for PSCB_INITIALIZED.
  184. //
  185. // Arguments:
  186. // None.
  187. //
  188. // Return Value:
  189. // None.
  190. //
  191. // Exceptions Thrown:
  192. // None.
  193. //
  194. //--
  195. /////////////////////////////////////////////////////////////////////////////
  196. void CBasePropertySheetWindow::OnSheetInitialized( void )
  197. {
  198. //
  199. // Add dynamic pages, including extension pages.
  200. //
  201. {
  202. //
  203. // Get pointers to beginning and end of list.
  204. //
  205. CPropertyPageList::iterator itCurrent = PlppPages()->begin();
  206. CPropertyPageList::iterator itLast = PlppPages()->end();
  207. //
  208. // Loop through the list and add each dynamic page.
  209. //
  210. for ( ; itCurrent != itLast ; itCurrent++ )
  211. {
  212. CDynamicPropertyPageWindow * pdpp = dynamic_cast< CDynamicPropertyPageWindow * >( *itCurrent );
  213. if ( pdpp != NULL )
  214. {
  215. if ( pdpp->Hpage() != NULL )
  216. {
  217. AddPage( pdpp->Hpage() );
  218. pdpp->SetPageAdded( TRUE );
  219. } // if: page has already been created
  220. } // if: dynamic page found
  221. } // for: each item in the list
  222. } // Add dynamic pages, including extension pages
  223. //
  224. // Call the base class method.
  225. //
  226. CBaseSheetWindow::OnSheetInitialized();
  227. } //*** CBasePropertySheetWindow::OnSheetInitialized()
  228. /////////////////////////////////////////////////////////////////////////////
  229. //++
  230. //
  231. // CBasePropertySheetWindow::AddExtensionPages
  232. //
  233. // Routine Description:
  234. // Add extension pages to the sheet.
  235. //
  236. // Arguments:
  237. // hfont [IN] Font to use for the extension pages.
  238. // hicon [IN] Icon to use for the extension pages.
  239. //
  240. // Return Value:
  241. // None.
  242. //
  243. //--
  244. /////////////////////////////////////////////////////////////////////////////
  245. void CBasePropertySheetWindow::AddExtensionPages(
  246. IN HFONT hfont,
  247. IN HICON hicon
  248. )
  249. {
  250. ATLASSERT( PcoObjectToExtend() != NULL );
  251. //
  252. // Add extension pages if there any extensions.
  253. //
  254. if ( (PcoObjectToExtend()->PlstrAdminExtensions() != NULL)
  255. && (PcoObjectToExtend()->PlstrAdminExtensions()->size() > 0) )
  256. {
  257. //
  258. // Get the currently selected page so we can reset it when we're done.
  259. //
  260. CTabCtrl tabc( GetTabControl() );
  261. int nCurPage = tabc.GetCurSel();
  262. //
  263. // Prepare to add extension pages.
  264. //
  265. CDynamicPropertyPageList ldpp;
  266. PrepareToAddExtensionPages( ldpp );
  267. //
  268. // If no extensions object has been created yet, create it now.
  269. //
  270. if ( Pext() == NULL )
  271. {
  272. m_pext = new CCluAdmExtensions;
  273. ATLASSERT( m_pext != NULL );
  274. } // if: no extensions list yet
  275. //
  276. // Enclose the loading of the extension in a try/catch block so
  277. // that the loading of the extension won't prevent all pages
  278. // from being displayed.
  279. //
  280. try
  281. {
  282. Pext()->CreatePropertySheetPages(
  283. this,
  284. *PcoObjectToExtend()->PlstrAdminExtensions(),
  285. PcoObjectToExtend(),
  286. hfont,
  287. hicon
  288. );
  289. } // try
  290. catch (...)
  291. {
  292. } // catch: anything
  293. //
  294. // Complete the process of adding extension pages.
  295. //
  296. CompleteAddingExtensionPages( ldpp );
  297. //
  298. // Restore the current selection.
  299. // This has to be done because sometimes the above process causes
  300. // the current page to be set to the last page added, which prevents
  301. // the next page from being displayed.
  302. //
  303. SetActivePage( nCurPage );
  304. } // if: object has extensions
  305. else
  306. {
  307. //
  308. // Remove extension pages.
  309. //
  310. RemoveAllExtensionPages();
  311. } // else: object doesn't have extensions
  312. } //*** CBasePropertySheetWindow::AddExtensionPages()
  313. /////////////////////////////////////////////////////////////////////////////
  314. //++
  315. //
  316. // CBasePropertySheetWindow::PrepareToAddExtensionPages
  317. //
  318. // Routine Description:
  319. // Prepare to add extension pages by deleting existing extension
  320. // pages and removing dynamic pages.
  321. //
  322. // Arguments:
  323. // None.
  324. //
  325. // Return Value:
  326. // None.
  327. //
  328. //--
  329. /////////////////////////////////////////////////////////////////////////////
  330. void CBasePropertySheetWindow::PrepareToAddExtensionPages(
  331. CDynamicPropertyPageList & rldpp
  332. )
  333. {
  334. //
  335. // Delete all extension pages.
  336. //
  337. RemoveAllExtensionPages();
  338. //
  339. // Move all dynamic pages to the temporary list.
  340. //
  341. ATLASSERT( rldpp.size() == 0);
  342. MovePtrListItems< CBasePropertyPageWindow *, CDynamicPropertyPageWindow * >( PlppPages(), &rldpp );
  343. //
  344. // Remove all pages in the temporary list from the property sheet.
  345. // The page must have already been created because we don't have
  346. // any access to the PROPSHEETPAGE structure to create it
  347. // during the completion phase.
  348. //
  349. {
  350. CDynamicPropertyPageList::iterator itCurrent;
  351. CDynamicPropertyPageList::iterator itLast;
  352. itCurrent = rldpp.begin();
  353. itLast = rldpp.end();
  354. for ( ; itCurrent != itLast ; itCurrent++ )
  355. {
  356. CDynamicPropertyPageWindow * pdpp = *itCurrent;
  357. ATLASSERT( pdpp != NULL );
  358. if ( pdpp->Hpage() != NULL )
  359. {
  360. RemovePage( pdpp->Hpage() );
  361. pdpp->SetPageAdded( FALSE );
  362. } // if: page already created
  363. } // for: each page in the list
  364. } // Remove dynamic pages
  365. } //*** CBasePropertySheetWindow::PrepareToAddExtensionPages()
  366. /////////////////////////////////////////////////////////////////////////////
  367. //++
  368. //
  369. // CBasePropertySheetWindow::HrAddExtensionPage
  370. //
  371. // Routine Description:
  372. // Add an extension page.
  373. //
  374. // Arguments:
  375. // ppage [IN OUT] Page to be added.
  376. //
  377. // Return Value:
  378. // S_OK Page added successfully.
  379. // S_FALSE Page not added.
  380. //
  381. //--
  382. /////////////////////////////////////////////////////////////////////////////
  383. HRESULT CBasePropertySheetWindow::HrAddExtensionPage( IN CBasePageWindow * ppage )
  384. {
  385. ATLASSERT( ppage != NULL );
  386. HRESULT hr = S_OK;
  387. CExtensionPropertyPageWindow * pepp = dynamic_cast< CExtensionPropertyPageWindow * >( ppage );
  388. ATLASSERT( pepp != NULL );
  389. if ( (ppage == NULL)
  390. || (pepp == NULL ) )
  391. {
  392. return S_FALSE;
  393. } // if: invalid arguments
  394. //
  395. // Add the page to the sheet.
  396. //
  397. if ( m_hWnd != NULL )
  398. {
  399. AddPage( pepp->Hpage() );
  400. pepp->SetPageAdded( TRUE );
  401. } // if: sheet is being displayed
  402. //
  403. // Add the page to the end of the list.
  404. //
  405. PlppPages()->insert( PlppPages()->end(), reinterpret_cast< CBasePropertyPageWindow * >( ppage ) );
  406. return hr;
  407. } //*** CBasePropertySheetWindow::HrAddExtensionPage()
  408. /////////////////////////////////////////////////////////////////////////////
  409. //++
  410. //
  411. // CBasePropertySheetWindow::CompleteAddingExtensionPages
  412. //
  413. // Routine Description:
  414. // Complete the process of adding extension pages to the sheet by
  415. // re-adding dynamic pages.
  416. //
  417. // Arguments:
  418. // None.
  419. //
  420. // Return Value:
  421. // None.
  422. //
  423. //--
  424. /////////////////////////////////////////////////////////////////////////////
  425. void CBasePropertySheetWindow::CompleteAddingExtensionPages(
  426. CDynamicPropertyPageList & rldpp
  427. )
  428. {
  429. DWORD sc;
  430. CDynamicPropertyPageWindow * pdpp;
  431. //
  432. // Move all pages from the temporary list to the real list and
  433. // add them to the end of the sheet.
  434. //
  435. CDynamicPropertyPageList::iterator itCurrent = rldpp.begin();
  436. CDynamicPropertyPageList::iterator itLast = rldpp.end();
  437. while ( itCurrent != itLast )
  438. {
  439. pdpp = *itCurrent;
  440. ATLASSERT( pdpp != NULL );
  441. //
  442. // Create the page.
  443. //
  444. sc = pdpp->ScCreatePage();
  445. if ( sc != ERROR_SUCCESS )
  446. {
  447. CNTException nte( sc, ADMC_IDS_CREATE_EXT_PAGE_ERROR, NULL, NULL, FALSE );
  448. delete pdpp;
  449. itCurrent = rldpp.erase( itCurrent );
  450. continue;
  451. } // if: error creating the page
  452. //
  453. // Add the page to the sheet.
  454. //
  455. ATLASSERT( pdpp->Hpage() != NULL );
  456. AddPage( pdpp->Hpage() );
  457. pdpp->SetPageAdded( TRUE );
  458. //
  459. // Move the page to real list.
  460. //
  461. PlppPages()->insert( PlppPages()->end(), pdpp );
  462. itCurrent = rldpp.erase( itCurrent );
  463. } // while: not at last page
  464. } //*** CBasePropertySheetWindow::CompleteAddingExtensionPages()
  465. /////////////////////////////////////////////////////////////////////////////
  466. //++
  467. //
  468. // CBasePropertySheetWindow::RemoveAllExtensionPages
  469. //
  470. // Routine Description:
  471. // Remove all extension pages from the property sheet.
  472. //
  473. // Arguments:
  474. // None.
  475. //
  476. // Return Value:
  477. // None.
  478. //
  479. //--
  480. /////////////////////////////////////////////////////////////////////////////
  481. void CBasePropertySheetWindow::RemoveAllExtensionPages( void )
  482. {
  483. //
  484. // Remove the extension pages.
  485. //
  486. CExtensionPropertyPageList lepp;
  487. MovePtrListItems< CBasePropertyPageWindow *, CExtensionPropertyPageWindow * >( PlppPages(), &lepp );
  488. CExtensionPropertyPageList::iterator itCurrent = lepp.begin();
  489. CExtensionPropertyPageList::iterator itLast = lepp.end();
  490. for ( ; itCurrent != itLast ; itCurrent++ )
  491. {
  492. CExtensionPropertyPageWindow * pepp = *itCurrent;
  493. ATLASSERT( pepp != NULL );
  494. if ( pepp->Hpage() != NULL )
  495. {
  496. RemovePage( pepp->Hpage() );
  497. pepp->SetPageAdded( FALSE );
  498. } // if: page already created
  499. } // for: each page in the list
  500. DeleteAllPtrListItems( &lepp );
  501. } //*** CBasePropertySheetWindow::RemoveAllExtensionPages()