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.

398 lines
10 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ARName.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CWizPageARNameDesc class.
  10. //
  11. // Author:
  12. // David Potter (davidp) December 10, 1997
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "ARName.h"
  21. #include "ClusAppWiz.h"
  22. #include "ResAdv.h" // for CGeneralResourceAdvancedSheet
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // class CWizPageARNameDesc
  30. /////////////////////////////////////////////////////////////////////////////
  31. /////////////////////////////////////////////////////////////////////////////
  32. // Control name map
  33. BEGIN_CTRL_NAME_MAP( CWizPageARNameDesc )
  34. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_RES_NAME_TITLE )
  35. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_RES_NAME_LABEL )
  36. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_RES_NAME )
  37. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_RES_DESC_TITLE )
  38. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_RES_DESC_LABEL )
  39. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_RES_DESC )
  40. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_ADVANCED_PROPS_LABEL )
  41. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_ARND_ADVANCED_PROPS )
  42. DEFINE_CTRL_NAME_MAP_ENTRY( IDC_WIZARD_CLICK_NEXT )
  43. END_CTRL_NAME_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. //++
  46. //
  47. // CWizPageARNameDesc::BInit
  48. //
  49. // Routine Description:
  50. // Initialize the page.
  51. //
  52. // Arguments:
  53. // psht [IN] Property sheet object to which this page belongs.
  54. //
  55. // Return Value:
  56. // TRUE Page initialized successfully.
  57. // FALSE Error initializing the page.
  58. //
  59. //--
  60. /////////////////////////////////////////////////////////////////////////////
  61. BOOL CWizPageARNameDesc::BInit( IN CBaseSheetWindow * psht )
  62. {
  63. //
  64. // Call the base class method.
  65. //
  66. return baseClass::BInit( psht );
  67. } //*** CWizPageARNameDesc::BInit()
  68. /////////////////////////////////////////////////////////////////////////////
  69. //++
  70. //
  71. // CWizPageARNameDesc::OnInitDialog
  72. //
  73. // Routine Description:
  74. // Handler for the WM_INITDIALOG message.
  75. //
  76. // Arguments:
  77. // None.
  78. //
  79. // Return Value:
  80. // TRUE Focus still needs to be set.
  81. // FALSE Focus does not need to be set.
  82. //
  83. //--
  84. /////////////////////////////////////////////////////////////////////////////
  85. BOOL CWizPageARNameDesc::OnInitDialog( void )
  86. {
  87. //
  88. // Make a local copy of the dependency list and the possible owners
  89. // list. This is needed to find out the changes made to these lists.
  90. //
  91. CClusResInfo * _priAppResInfoPtr = PwizThis()->PriApplication();
  92. m_lpriOldDependencies = *(_priAppResInfoPtr->PlpriDependencies());
  93. m_lpniOldPossibleOwners = *(_priAppResInfoPtr->PlpniPossibleOwners());
  94. //
  95. // Attach the controls to control member variables.
  96. //
  97. AttachControl( m_editResName, IDC_ARND_RES_NAME );
  98. AttachControl( m_editResDesc, IDC_ARND_RES_DESC );
  99. return TRUE;
  100. } //*** CWizPageARNameDesc::OnInitDialog()
  101. /////////////////////////////////////////////////////////////////////////////
  102. //++
  103. //
  104. // CWizPageARNameDesc::UpdateData
  105. //
  106. // Routine Description:
  107. // Update data on or from the page.
  108. //
  109. // Arguments:
  110. // bSaveAndValidate [IN] TRUE if need to read data from the page.
  111. // FALSE if need to set data to the page.
  112. //
  113. // Return Value:
  114. // TRUE The data was updated successfully.
  115. // FALSE An error occurred updating the data.
  116. //
  117. //--
  118. /////////////////////////////////////////////////////////////////////////////
  119. BOOL CWizPageARNameDesc::UpdateData( BOOL bSaveAndValidate )
  120. {
  121. BOOL _bSuccess = TRUE;
  122. CClusResInfo * _priAppResInfoPtr = PwizThis()->PriApplication();
  123. if ( bSaveAndValidate )
  124. {
  125. DDX_GetText( m_hWnd, IDC_ARND_RES_NAME, m_strResName );
  126. DDX_GetText( m_hWnd, IDC_ARND_RES_DESC, m_strResDesc );
  127. if ( ! BBackPressed() && ( m_bAdvancedButtonPressed == FALSE ) )
  128. {
  129. if ( ! DDV_RequiredText( m_hWnd, IDC_ARND_RES_NAME, IDC_ARND_RES_NAME_LABEL, m_strResName ) )
  130. {
  131. return FALSE;
  132. } // if: required text not specified
  133. } // if: Back button not presssed
  134. //
  135. // Check if the resource name has changed. If so update the data in
  136. // the wizard and set a flag.
  137. //
  138. if ( _priAppResInfoPtr->RstrName().CompareNoCase( m_strResName ) != 0 )
  139. {
  140. _priAppResInfoPtr->SetName( m_strResName );
  141. m_bNameChanged = TRUE;
  142. } // if: resource name changed
  143. //
  144. // Check if the resource description has changed. If so update the data in
  145. // the wizard and set a flag.
  146. //
  147. if ( _priAppResInfoPtr->RstrDescription().CompareNoCase( m_strResDesc ) != 0 )
  148. {
  149. _priAppResInfoPtr->SetDescription( m_strResDesc );
  150. PwizThis()->SetAppDataChanged();
  151. } // if: description changed
  152. } // if: saving data from the page
  153. else
  154. {
  155. m_strResName = _priAppResInfoPtr->RstrName();
  156. m_strResDesc = _priAppResInfoPtr->RstrDescription();
  157. m_editResName.SetWindowText( m_strResName );
  158. m_editResDesc.SetWindowText( m_strResDesc );
  159. } // else: setting data to the page
  160. return _bSuccess;
  161. } //*** CWizPageARNameDesc::UpdateData()
  162. /////////////////////////////////////////////////////////////////////////////
  163. //++
  164. //
  165. // CWizPageARNameDesc::OnWizardBack
  166. //
  167. // Routine Description:
  168. // Handler for PSN_WIZBACK.
  169. //
  170. // Arguments:
  171. // None.
  172. //
  173. // Return Value:
  174. // 0 Move to previous page.
  175. // -1 Don't move to previous page.
  176. // anything else Move to specified page.
  177. //
  178. //--
  179. /////////////////////////////////////////////////////////////////////////////
  180. int CWizPageARNameDesc::OnWizardBack( void )
  181. {
  182. int _nResult;
  183. //
  184. // Call the base class. This causes our UpdateData() method to get
  185. // called. If it succeeds, save our values.
  186. //
  187. _nResult = baseClass::OnWizardBack();
  188. return _nResult;
  189. } //*** CWizPageARNameDesc::OnWizardBack()
  190. /////////////////////////////////////////////////////////////////////////////
  191. //++
  192. //
  193. // CWizPageARNameDesc::BApplyChanges
  194. //
  195. // Routine Description:
  196. // Apply changes made on this page to the sheet.
  197. //
  198. // Arguments:
  199. // None.
  200. //
  201. // Return Value:
  202. // TRUE The data was applied successfully.
  203. // FALSE An error occurred applying the data.
  204. //
  205. //--
  206. /////////////////////////////////////////////////////////////////////////////
  207. BOOL CWizPageARNameDesc::BApplyChanges( void )
  208. {
  209. BOOL _bSuccess = FALSE;
  210. // Loop to avoid goto's.
  211. do
  212. {
  213. CClusResInfo * priAppResInfoPtr = &PwizThis()->RriApplication();
  214. if ( BResourceNameInUse() )
  215. {
  216. CString _strMsg;
  217. _strMsg.FormatMessage( IDS_ERROR_RESOURCE_NAME_IN_USE, m_strResName );
  218. AppMessageBox( m_hWnd, _strMsg, MB_OK | MB_ICONEXCLAMATION );
  219. break;
  220. } // if: resource name is already in use
  221. //
  222. // Create the resource if the if the resource does not exist.
  223. //
  224. if ( PwizThis()->PriApplication()->BCreated() == FALSE )
  225. {
  226. //
  227. // Delete the resource if it already exists.
  228. //
  229. _bSuccess = PwizThis()->BDeleteAppResource();
  230. if ( _bSuccess == FALSE )
  231. {
  232. break;
  233. } // if: resource deletion failed.
  234. //
  235. //
  236. // Ensure all required dependencies are present.
  237. //
  238. _bSuccess = PwizThis()->BRequiredDependenciesPresent( &PwizThis()->RriApplication() );
  239. if ( _bSuccess == FALSE )
  240. {
  241. break;
  242. } // if: all required dependencies not present
  243. //
  244. // Create the resource.
  245. //
  246. _bSuccess = PwizThis()->BCreateAppResource();
  247. if ( _bSuccess == FALSE )
  248. {
  249. break;
  250. } // if: resource creation failed.
  251. //
  252. // Copy the list of dependencies and possible owners.
  253. // This is required to update only the changes to these lists.
  254. //
  255. m_lpriOldDependencies = *(priAppResInfoPtr->PlpriDependencies());
  256. m_lpniOldPossibleOwners = *(priAppResInfoPtr->PlpniPossibleOwners());
  257. m_bNameChanged = FALSE;
  258. //
  259. // Add extension pages.
  260. //
  261. Pwiz()->AddExtensionPages( NULL /*hfont*/, PwizThis()->HiconRes() );
  262. } // if: the application has not been created
  263. else
  264. {
  265. CClusResInfo * _priAppResInfoPtr = &PwizThis()->RriApplication();
  266. //
  267. // The name of the resource has changed. We cannot set it with the
  268. // rest of the properties since it is a read only property. So, use
  269. // the SetClusterResourceName API.
  270. //
  271. if ( m_bNameChanged != FALSE )
  272. {
  273. if ( SetClusterResourceName(
  274. _priAppResInfoPtr->Hresource(),
  275. _priAppResInfoPtr->RstrName()
  276. )
  277. != ERROR_SUCCESS
  278. )
  279. {
  280. _bSuccess = FALSE;
  281. break;
  282. } // if: the name of the resource could not be set
  283. m_bNameChanged = FALSE;
  284. } // if: the name of the resource has changed
  285. //
  286. // If the app data has changed, update the data.
  287. //
  288. if ( PwizThis()->BAppDataChanged() )
  289. {
  290. _bSuccess = PwizThis()->BSetAppResAttributes( &m_lpriOldDependencies, &m_lpniOldPossibleOwners );
  291. if ( _bSuccess )
  292. {
  293. //
  294. // Copy the list of dependencies and possible owners.
  295. // This is required to update only the changes to these lists.
  296. //
  297. m_lpriOldDependencies = *(_priAppResInfoPtr->PlpriDependencies());
  298. m_lpniOldPossibleOwners = *(_priAppResInfoPtr->PlpniPossibleOwners());
  299. } // if: set attributes successfully
  300. } // if: application data changed
  301. else
  302. {
  303. _bSuccess = TRUE;
  304. } // else: application data has not changed.
  305. } // else: the application has been created
  306. } while ( 0 );
  307. return _bSuccess;
  308. } //*** CWizPageARNameDesc::BApplyChanges()
  309. /////////////////////////////////////////////////////////////////////////////
  310. //++
  311. //
  312. // CWizPageARNameDesc::OnAdvancedProps
  313. //
  314. // Routine Description:
  315. // Handler for the BN_CLICKED command notification on IDC_ARA_ADVANCED_PROPS.
  316. //
  317. // Arguments:
  318. // None.
  319. //
  320. // Return Value:
  321. // Ignored.
  322. //
  323. //--
  324. /////////////////////////////////////////////////////////////////////////////
  325. LRESULT CWizPageARNameDesc::OnAdvancedProps(
  326. WORD /*wNotifyCode*/,
  327. WORD /*idCtrl*/,
  328. HWND /*hwndCtrl*/,
  329. BOOL & /*bHandled*/
  330. )
  331. {
  332. CWaitCursor _wc;
  333. CClusResInfo * _priAppResInfoPtr = PwizThis()->PriApplication();
  334. BOOL _bAppDataChanged = PwizThis()->BAppDataChanged();
  335. m_bAdvancedButtonPressed = TRUE;
  336. UpdateData( TRUE );
  337. CGeneralResourceAdvancedSheet _sht( IDS_ADV_RESOURCE_PROP_TITLE, PwizThis() );
  338. if ( _sht.BInit( *_priAppResInfoPtr, _bAppDataChanged ) )
  339. {
  340. //
  341. // Display the property sheet. If any properties were changed,
  342. // update the display of the resource name and description.
  343. //
  344. _sht.DoModal();
  345. PwizThis()->SetAppDataChanged( _bAppDataChanged );
  346. UpdateData( FALSE );
  347. } // if: sheet successfully initialized
  348. m_bAdvancedButtonPressed = FALSE;
  349. return 0;
  350. } //*** CWizPageARNameDesc::OnAdvancedProps()