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.

553 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000 - 2001.
  5. //
  6. // File: AddDlg.cpp
  7. //
  8. // Contents: Add Dialogs are presented when user clicks add button. For
  9. // Add Task, Add Group etc. This file has implementation of add dlgs.
  10. //
  11. //----------------------------------------------------------------------------
  12. #include "headers.h"
  13. /******************************************************************************
  14. Class: CBaseAddDialog
  15. Purpose: This is the base class for all Add Dialog classes.
  16. ******************************************************************************/
  17. BOOL
  18. CBaseAddDialog::
  19. OnInitDialog()
  20. {
  21. TRACE_METHOD_EX(DEB_SNAPIN,CBaseAddDialog,OnInitDialog)
  22. VERIFY(m_listCtrl.SubclassDlgItem(m_nIDListCtrl,this));
  23. m_listCtrl.Initialize();
  24. //Add AzObjects from list to ListControl
  25. POSITION pos = m_listAzObjectsToDisplay.GetHeadPosition();
  26. for (int i=0;i < m_listAzObjectsToDisplay.GetCount();i++)
  27. {
  28. CBaseAz* pBaseAz = m_listAzObjectsToDisplay.GetNext(pos);
  29. //Add Item to ListControl
  30. VERIFY( AddBaseAzToListCtrl(&m_listCtrl,
  31. m_listCtrl.GetItemCount(),
  32. pBaseAz,
  33. m_uiListCtrlFlags) != -1);
  34. }
  35. //Sort the listctrl entries
  36. m_listCtrl.Sort();
  37. return TRUE;
  38. }
  39. void
  40. CBaseAddDialog
  41. ::OnOK()
  42. {
  43. OnOkCancel(FALSE);
  44. }
  45. void
  46. CBaseAddDialog::
  47. OnCancel()
  48. {
  49. OnOkCancel(TRUE);
  50. }
  51. void
  52. CBaseAddDialog::
  53. OnOkCancel(BOOL bCancel)
  54. {
  55. //Get ListCotrol
  56. int iRowCount = m_listCtrl.GetItemCount();
  57. for( int iRow = 0; iRow < iRowCount; iRow++)
  58. {
  59. CBaseAz* pBaseAz = (CBaseAz*)(m_listCtrl.GetItemData(iRow));
  60. ASSERT(pBaseAz);
  61. //user Pressed Cancel, delete all items
  62. if(bCancel)
  63. delete pBaseAz;
  64. else
  65. {
  66. //if checkbox for an item is checked, add it to the list
  67. //else delete it
  68. if(m_listCtrl.GetCheck(iRow))
  69. m_listAzObjectsSelected.AddTail(pBaseAz);
  70. else
  71. delete pBaseAz;
  72. }
  73. }
  74. if(bCancel)
  75. CDialog::OnCancel();
  76. else
  77. CDialog::OnOK();
  78. }
  79. /******************************************************************************
  80. Class: CAddOperationDlg
  81. Purpose: Add Operation Dlg box
  82. ******************************************************************************/
  83. BEGIN_MESSAGE_MAP(CAddOperationDlg, CBaseAddDialog)
  84. //}}AFX_MSG_MAP
  85. END_MESSAGE_MAP()
  86. CAddOperationDlg
  87. ::CAddOperationDlg(CList<CBaseAz*,CBaseAz*>& listAzObjectsToDisplay,
  88. CList<CBaseAz*,CBaseAz*>& listAzObjectsSelected)
  89. :CBaseAddDialog(listAzObjectsToDisplay,
  90. listAzObjectsSelected,
  91. CAddOperationDlg::IDD,
  92. IDC_LIST,
  93. Col_For_Add_Object,
  94. COL_NAME |COL_PARENT_TYPE|COL_DESCRIPTION)
  95. {
  96. }
  97. CAddOperationDlg
  98. ::~CAddOperationDlg()
  99. {
  100. }
  101. /******************************************************************************
  102. Class: CAddTaskDlg
  103. Purpose: Add Task Dlg box
  104. ******************************************************************************/
  105. BEGIN_MESSAGE_MAP(CAddTaskDlg, CBaseAddDialog)
  106. //}}AFX_MSG_MAP
  107. END_MESSAGE_MAP()
  108. CAddTaskDlg::
  109. CAddTaskDlg(CList<CBaseAz*,CBaseAz*>& listAzObjectsToDisplay,
  110. CList<CBaseAz*,CBaseAz*>& listAzObjectsSelected,
  111. ULONG IDD_DIALOG)
  112. :CBaseAddDialog(listAzObjectsToDisplay,
  113. listAzObjectsSelected,
  114. IDD_DIALOG,
  115. IDC_LIST,
  116. Col_For_Add_Object,
  117. COL_NAME |COL_PARENT_TYPE|COL_DESCRIPTION)
  118. {
  119. }
  120. CAddTaskDlg
  121. ::~CAddTaskDlg()
  122. {
  123. }
  124. /******************************************************************************
  125. Class: CAddGroupDlg
  126. Purpose: Add Group Dlg box
  127. ******************************************************************************/
  128. BEGIN_MESSAGE_MAP(CAddGroupDlg, CBaseAddDialog)
  129. //}}AFX_MSG_MAP
  130. END_MESSAGE_MAP()
  131. CAddGroupDlg
  132. ::CAddGroupDlg(CList<CBaseAz*,CBaseAz*>& listAzObjectsToDisplay,
  133. CList<CBaseAz*,CBaseAz*>& listAzObjectsSelected)
  134. :CBaseAddDialog(listAzObjectsToDisplay,
  135. listAzObjectsSelected,
  136. CAddGroupDlg::IDD,
  137. IDC_LIST,
  138. Col_For_Add_Object,
  139. COL_NAME |COL_PARENT_TYPE|COL_DESCRIPTION)
  140. {
  141. }
  142. CAddGroupDlg
  143. ::~CAddGroupDlg()
  144. {
  145. }
  146. //+----------------------------------------------------------------------------
  147. // Function:GetSelectedAzObjects
  148. // Synopsis:Display the add dlg box for eObjecType and return the objects
  149. // selected by user
  150. // Arguments:hwnd
  151. // eObjectType: Shows Add Dlg for this objecttype
  152. // pContainerAz:ContainerAz object from whose child objects are
  153. // shown
  154. // listObjectsSelected: Gets list of selected object types
  155. // Returns:
  156. //-----------------------------------------------------------------------------
  157. BOOL GetSelectedAzObjects(IN HWND hWnd,
  158. IN OBJECT_TYPE_AZ eObjectType,
  159. IN CContainerAz* pContainerAz,
  160. OUT CList<CBaseAz*,CBaseAz*>& listObjectsSelected)
  161. {
  162. TRACE_FUNCTION_EX(DEB_SNAPIN,GetSelectedAzObjects)
  163. if(!pContainerAz)
  164. {
  165. ASSERT(pContainerAz);
  166. return FALSE;
  167. }
  168. //Get All the object of type eObjectType at pRoleTaskContainerAz
  169. CList<CBaseAz*,CBaseAz*> listChildObjectsToDisplay;
  170. HRESULT hr = GetAllAzChildObjects(pContainerAz,
  171. eObjectType,
  172. listChildObjectsToDisplay);
  173. if(FAILED(hr))
  174. {
  175. CString strError;
  176. GetSystemError(strError, hr);
  177. //Display Generic Error Message
  178. DisplayError(hWnd,
  179. IDS_ERROR_OPERATION_FAILED,
  180. (LPWSTR)(LPCWSTR)strError);
  181. return FALSE;
  182. }
  183. //if there are no objects to add, show the error message and quit
  184. if(!listChildObjectsToDisplay.GetCount())
  185. {
  186. switch(eObjectType)
  187. {
  188. case OPERATION_AZ:
  189. DisplayInformation(hWnd,IDS_NO_OPERATIONS_TO_ADD);
  190. break;
  191. case GROUP_AZ:
  192. DisplayInformation(hWnd,IDS_NO_GROUP_TO_ADD);
  193. break;
  194. default:
  195. ASSERT(FALSE);
  196. break;
  197. }
  198. return TRUE;
  199. }
  200. //Display Appropriate Dialog box
  201. if(eObjectType == OPERATION_AZ)
  202. {
  203. CAddOperationDlg dlgAddOperation(listChildObjectsToDisplay,
  204. listObjectsSelected);
  205. dlgAddOperation.DoModal();
  206. }
  207. else if(eObjectType == GROUP_AZ)
  208. {
  209. CAddGroupDlg dlgAddGroup(listChildObjectsToDisplay,
  210. listObjectsSelected);
  211. dlgAddGroup.DoModal();
  212. }
  213. return TRUE;
  214. }
  215. //+----------------------------------------------------------------------------
  216. // Function:GetSelectedTasks
  217. // Synopsis:Display the add dlg box for Tasks/RoleDefintions
  218. // and return the objects selected by user
  219. // Arguments:hwnd
  220. // bTaskIsRoleDefintion if True Display AddTask else Add Role Def.
  221. // pContainerAz:ContainerAz object from whose child objects are
  222. // shown
  223. // listObjectsSelected: Gets list of selected object types
  224. // Returns:
  225. //-----------------------------------------------------------------------------
  226. BOOL GetSelectedTasks(IN HWND hWnd,
  227. IN BOOL bTaskIsRoleDefintion,
  228. IN CContainerAz* pContainerAz,
  229. OUT CList<CBaseAz*,CBaseAz*>& listObjectsSelected)
  230. {
  231. if(!pContainerAz)
  232. {
  233. ASSERT(pContainerAz);
  234. return FALSE;
  235. }
  236. //Get All the object of type eObjectType at pRoleTaskContainerAz
  237. CList<CBaseAz*,CBaseAz*> listListOfAllTasks;
  238. HRESULT hr = GetAllAzChildObjects(pContainerAz,
  239. TASK_AZ,
  240. listListOfAllTasks);
  241. if(FAILED(hr))
  242. {
  243. CString strError;
  244. GetSystemError(strError, hr);
  245. //Display Generic Error Message
  246. DisplayError(hWnd,
  247. IDS_ERROR_OPERATION_FAILED,
  248. (LPWSTR)(LPCWSTR)strError);
  249. return FALSE;
  250. }
  251. CList<CBaseAz*,CBaseAz*> listChildObjectsToDisplay;
  252. POSITION pos = listListOfAllTasks.GetHeadPosition();
  253. for( int i = 0; i < listListOfAllTasks.GetCount(); ++i)
  254. {
  255. CTaskAz* pTaskAz = dynamic_cast<CTaskAz*>(listListOfAllTasks.GetNext(pos));
  256. ASSERT(pTaskAz);
  257. if((bTaskIsRoleDefintion && pTaskAz->IsRoleDefinition())
  258. ||(!bTaskIsRoleDefintion) && !pTaskAz->IsRoleDefinition())
  259. listChildObjectsToDisplay.AddTail(pTaskAz);
  260. else
  261. delete pTaskAz;
  262. }
  263. //if there are no objects to add, show the error message and quit
  264. if(!listChildObjectsToDisplay.GetCount())
  265. {
  266. if(bTaskIsRoleDefintion)
  267. DisplayInformation(hWnd,IDS_NO_ROLE_DEFINITION_TO_ADD);
  268. else
  269. DisplayInformation(hWnd,IDS_NO_TASKS_TO_ADD);
  270. return TRUE ;
  271. }
  272. CAddTaskDlg dlgAddTask(listChildObjectsToDisplay,
  273. listObjectsSelected,
  274. bTaskIsRoleDefintion? IDD_ADD_ROLE_DEFINITION_1 :IDD_ADD_TASK);
  275. //Get List of Tasks to be Added
  276. dlgAddTask.DoModal();
  277. return TRUE;
  278. }
  279. /******************************************************************************
  280. Class: CAddDefinition
  281. Purpose:Property Page for Add Definition Tab. Allows to add Role, Task or
  282. Operation
  283. ******************************************************************************/
  284. BEGIN_MESSAGE_MAP(CAddDefinition, CPropertyPage)
  285. //}}AFX_MSG_MAP
  286. END_MESSAGE_MAP()
  287. BOOL
  288. CAddDefinition::
  289. OnInitDialog()
  290. {
  291. TRACE_METHOD_EX(DEB_SNAPIN,CAddDefinition,OnInitDialog)
  292. VERIFY(m_listCtrl.SubclassDlgItem(IDC_LIST,this));
  293. m_listCtrl.Initialize();
  294. //
  295. //Get List of Objects to Display
  296. //
  297. CList<CBaseAz*,CBaseAz*> listAzObjectsToDisplay;
  298. HRESULT hr = S_OK;
  299. if(m_eObjectType == TASK_AZ)
  300. {
  301. CList<CBaseAz*,CBaseAz*> listTasks;
  302. hr = GetAllAzChildObjects(m_pContainerAz,
  303. TASK_AZ,
  304. listTasks);
  305. if(SUCCEEDED(hr))
  306. {
  307. POSITION pos = listTasks.GetHeadPosition();
  308. for( int i = 0; i < listTasks.GetCount(); ++i)
  309. {
  310. CTaskAz* pTaskAz = dynamic_cast<CTaskAz*>(listTasks.GetNext(pos));
  311. ASSERT(pTaskAz);
  312. if((m_bTaskIsRoleDefintion && pTaskAz->IsRoleDefinition())
  313. ||(!m_bTaskIsRoleDefintion && !pTaskAz->IsRoleDefinition()))
  314. {
  315. listAzObjectsToDisplay.AddTail(pTaskAz);
  316. }
  317. else
  318. delete pTaskAz;
  319. }
  320. }
  321. }
  322. else
  323. {
  324. hr = GetAllAzChildObjects(m_pContainerAz,
  325. m_eObjectType,
  326. listAzObjectsToDisplay);
  327. }
  328. if(FAILED(hr))
  329. {
  330. CString strError;
  331. GetSystemError(strError, hr);
  332. //Display Generic Error Message
  333. DisplayError(m_hWnd,
  334. IDS_ERROR_OPERATION_FAILED,
  335. (LPWSTR)(LPCWSTR)strError);
  336. return FALSE;
  337. }
  338. //if there are no objects to add, show the error message and quit
  339. if(!listAzObjectsToDisplay.GetCount())
  340. {
  341. if(m_eObjectType == TASK_AZ)
  342. {
  343. if(m_bTaskIsRoleDefintion)
  344. DisplayInformation(m_hWnd,IDS_NO_ROLE_DEFINITION_TO_ADD);
  345. else
  346. DisplayInformation(m_hWnd,IDS_NO_TASKS_TO_ADD);
  347. }
  348. else
  349. {
  350. DisplayInformation(m_hWnd,IDS_NO_OPERATIONS_TO_ADD);
  351. }
  352. return TRUE ;
  353. }
  354. //Add AzObjects from list to ListControl
  355. POSITION pos = listAzObjectsToDisplay.GetHeadPosition();
  356. for (int i=0;i < listAzObjectsToDisplay.GetCount();i++)
  357. {
  358. CBaseAz* pBaseAz = listAzObjectsToDisplay.GetNext(pos);
  359. //Add Item to ListControl
  360. VERIFY( AddBaseAzToListCtrl(&m_listCtrl,
  361. m_listCtrl.GetItemCount(),
  362. pBaseAz,
  363. COL_NAME |COL_PARENT_TYPE|COL_DESCRIPTION) != -1);
  364. }
  365. m_listCtrl.Sort();
  366. return TRUE;
  367. }
  368. void
  369. CAddDefinition
  370. ::OnOK()
  371. {
  372. OnOkCancel(FALSE);
  373. }
  374. void
  375. CAddDefinition::
  376. OnCancel()
  377. {
  378. OnOkCancel(TRUE);
  379. }
  380. void
  381. CAddDefinition::
  382. OnOkCancel(BOOL bCancel)
  383. {
  384. int iRowCount = m_listCtrl.GetItemCount();
  385. for( int iRow = 0; iRow < iRowCount; iRow++)
  386. {
  387. CBaseAz* pBaseAz = (CBaseAz*)m_listCtrl.GetItemData(iRow);
  388. ASSERT(pBaseAz);
  389. //user Pressed Cancel, delete all items
  390. if(bCancel)
  391. delete pBaseAz;
  392. else
  393. {
  394. //if checkbox for an item is checked, add it to the list
  395. //else delete it
  396. if(m_listCtrl.GetCheck(iRow))
  397. m_listAzObjectsSelected.AddTail(pBaseAz);
  398. else
  399. delete pBaseAz;
  400. }
  401. }
  402. if(bCancel)
  403. CDialog::OnCancel();
  404. else
  405. CDialog::OnOK();
  406. }
  407. //+----------------------------------------------------------------------------
  408. // Function:GetSelectedDefinitions
  409. // Synopsis:Display the dlg boxes for Tasks/RoleDefintions/Operations
  410. // and return the objects selected by user
  411. // Arguments:hwnd
  412. // bRoleDefintion if True Display Add Role dialog also.
  413. // pContainerAz:ContainerAz object from whose child objects are
  414. // shown
  415. // listObjectsSelected: Gets list of selected object types
  416. // Returns:
  417. //-----------------------------------------------------------------------------
  418. BOOL GetSelectedDefinitions(IN BOOL bAllowRoleDefinition,
  419. IN CContainerAz* pContainerAz,
  420. OUT CList<CBaseAz*,CBaseAz*>& listObjectsSelected)
  421. {
  422. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  423. if(!pContainerAz)
  424. {
  425. ASSERT(pContainerAz);
  426. return FALSE;
  427. }
  428. CPropertySheet sheet(IDS_ADD_DEFINITION);
  429. CAddDefinition *ppageRole = NULL;
  430. //Add Role Definition Page
  431. if(bAllowRoleDefinition)
  432. {
  433. ppageRole= new CAddDefinition(listObjectsSelected,
  434. IDD_ADD_ROLE_DEFINITION,
  435. pContainerAz,
  436. TASK_AZ,
  437. TRUE);
  438. if(!ppageRole)
  439. {
  440. return FALSE;
  441. }
  442. sheet.AddPage(ppageRole);
  443. }
  444. //Add Task Page
  445. CAddDefinition pageTask(listObjectsSelected,
  446. IDD_ADD_TASK,
  447. pContainerAz,
  448. TASK_AZ,
  449. FALSE);
  450. sheet.AddPage(&pageTask);
  451. CContainerAz * pOperationContainer
  452. = (pContainerAz->GetObjectType() == SCOPE_AZ) ? pContainerAz->GetParentAz():pContainerAz;
  453. //Add Operation Page
  454. CAddDefinition pageOperation(listObjectsSelected,
  455. IDD_ADD_OPERATION,
  456. pOperationContainer,
  457. OPERATION_AZ,
  458. FALSE);
  459. sheet.AddPage(&pageOperation);
  460. //Remove the apply button
  461. sheet.m_psh.dwFlags |= PSH_NOAPPLYNOW;
  462. //Display the sheet
  463. sheet.DoModal();
  464. if(ppageRole)
  465. delete ppageRole;
  466. return TRUE;
  467. }