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.

402 lines
12 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DelRes.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CDeleteResourcesDlg class.
  10. //
  11. // Author:
  12. // David Potter (davidp) August 7, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "CluAdmin.h"
  21. #include "DelRes.h"
  22. #include "Res.h"
  23. #include "HelpData.h" // for g_rghelpmapDeleteResource
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CDeleteResourcesDlg class
  31. /////////////////////////////////////////////////////////////////////////////
  32. /////////////////////////////////////////////////////////////////////////////
  33. // Message Maps
  34. BEGIN_MESSAGE_MAP(CDeleteResourcesDlg, CBaseDialog)
  35. //{{AFX_MSG_MAP(CDeleteResourcesDlg)
  36. ON_NOTIFY(NM_DBLCLK, IDC_DR_RESOURCES_LIST, OnDblClkResourcesList)
  37. ON_NOTIFY(LVN_COLUMNCLICK, IDC_DR_RESOURCES_LIST, OnColumnClick)
  38. ON_WM_DESTROY()
  39. //}}AFX_MSG_MAP
  40. ON_BN_CLICKED(IDYES, CBaseDialog::OnOK)
  41. ON_BN_CLICKED(IDNO, CBaseDialog::OnCancel)
  42. END_MESSAGE_MAP()
  43. /////////////////////////////////////////////////////////////////////////////
  44. //++
  45. //
  46. // CDeleteResourcesDlg::CDeleteResourcesDlg
  47. //
  48. // Routine Description:
  49. // Constructor.
  50. //
  51. // Arguments:
  52. // pciRes [IN] Resource being deleted.
  53. // plpci [IN] List of resources which are dependent on pciRes.
  54. // pParent [IN OUT] Parent window for the dialog.
  55. //
  56. // Return Value:
  57. // None.
  58. //
  59. //--
  60. /////////////////////////////////////////////////////////////////////////////
  61. CDeleteResourcesDlg::CDeleteResourcesDlg(
  62. IN CResource * pciRes,
  63. IN const CResourceList * plpci,
  64. IN OUT CWnd * pParent /*=NULL*/
  65. )
  66. : CBaseDialog(IDD, g_aHelpIDs_IDD_DELETE_RESOURCES, pParent)
  67. {
  68. //{{AFX_DATA_INIT(CDeleteResourcesDlg)
  69. //}}AFX_DATA_INIT
  70. ASSERT_VALID(pciRes);
  71. ASSERT(plpci != NULL);
  72. m_pciRes = pciRes;
  73. m_plpci = plpci;
  74. } //*** CDeleteResourcesDlg::CDeleteResourcesDlg()
  75. /////////////////////////////////////////////////////////////////////////////
  76. //++
  77. //
  78. // CDeleteResourcesDlg::DoDataExchange
  79. //
  80. // Routine Description:
  81. // Do data exchange between the dialog and the class.
  82. //
  83. // Arguments:
  84. // pDX [IN OUT] Data exchange object
  85. //
  86. // Return Value:
  87. // None.
  88. //
  89. //--
  90. /////////////////////////////////////////////////////////////////////////////
  91. void CDeleteResourcesDlg::DoDataExchange(CDataExchange * pDX)
  92. {
  93. CBaseDialog::DoDataExchange(pDX);
  94. //{{AFX_DATA_MAP(CDeleteResourcesDlg)
  95. DDX_Control(pDX, IDC_DR_RESOURCES_LIST, m_lcResources);
  96. //}}AFX_DATA_MAP
  97. } //*** CDeleteResourcesDlg::DoDataExchange()
  98. /////////////////////////////////////////////////////////////////////////////
  99. //++
  100. //
  101. // CDeleteResourcesDlg::OnInitDialog
  102. //
  103. // Routine Description:
  104. // Handler for the WM_INITDIALOG message.
  105. //
  106. // Arguments:
  107. // None.
  108. //
  109. // Return Value:
  110. // TRUE Focus needs to be set.
  111. // FALSE Focus already set.
  112. //
  113. //--
  114. /////////////////////////////////////////////////////////////////////////////
  115. BOOL CDeleteResourcesDlg::OnInitDialog(void)
  116. {
  117. int nitem;
  118. CBaseDialog::OnInitDialog();
  119. // Change list view control extended styles.
  120. {
  121. DWORD dwExtendedStyle;
  122. dwExtendedStyle = (DWORD)m_lcResources.SendMessage(LVM_GETEXTENDEDLISTVIEWSTYLE);
  123. m_lcResources.SendMessage(
  124. LVM_SETEXTENDEDLISTVIEWSTYLE,
  125. 0,
  126. dwExtendedStyle
  127. | LVS_EX_FULLROWSELECT
  128. | LVS_EX_HEADERDRAGDROP
  129. );
  130. } // Change list view control extended styles
  131. // Set the image list for the list control to use.
  132. m_lcResources.SetImageList(GetClusterAdminApp()->PilSmallImages(), LVSIL_SMALL);
  133. // Add the columns.
  134. {
  135. CString strColumn;
  136. try
  137. {
  138. strColumn.LoadString(IDS_COLTEXT_NAME);
  139. m_lcResources.InsertColumn(0, strColumn, LVCFMT_LEFT, COLI_WIDTH_NAME * 3 / 2);
  140. strColumn.LoadString(IDS_COLTEXT_RESTYPE);
  141. m_lcResources.InsertColumn(1, strColumn, LVCFMT_LEFT, COLI_WIDTH_RESTYPE * 3 / 2);
  142. } // try
  143. catch (CException * pe)
  144. {
  145. pe->Delete();
  146. } // catch: CException
  147. } // Add the columns
  148. // Add the resource being deleted to the list.
  149. nitem = m_lcResources.InsertItem(0, PciRes()->StrName(), PciRes()->IimgObjectType());
  150. m_lcResources.SetItemText(nitem, 1, PciRes()->StrRealResourceTypeDisplayName());
  151. m_lcResources.SetItemData(nitem, (DWORD_PTR) PciRes());
  152. m_pciRes->AddRef();
  153. // Add the items.
  154. {
  155. POSITION pos;
  156. int iitem;
  157. CResource * pciRes;
  158. pos = Plpci()->GetHeadPosition();
  159. for (iitem = 1 ; pos != NULL ; iitem++)
  160. {
  161. pciRes = (CResource *) Plpci()->GetNext(pos);
  162. ASSERT_VALID(pciRes);
  163. if (pciRes != PciRes())
  164. {
  165. nitem = m_lcResources.InsertItem(iitem, pciRes->StrName(), pciRes->IimgObjectType());
  166. m_lcResources.SetItemText(nitem, 1, pciRes->StrRealResourceTypeDisplayName());
  167. m_lcResources.SetItemData(nitem, (DWORD_PTR) pciRes);
  168. pciRes->AddRef();
  169. } // if: not resource being deleted
  170. } // while: more items in the list
  171. } // Add the items
  172. // Sort the items.
  173. m_nSortColumn = 0;
  174. m_nSortDirection = 0;
  175. m_lcResources.SortItems(CompareItems, (LPARAM) this);
  176. return TRUE; // return TRUE unless you set the focus to a control
  177. // EXCEPTION: OCX Property Pages should return FALSE
  178. } //*** CDeleteResourcesDlg::OnInitDialog()
  179. /////////////////////////////////////////////////////////////////////////////
  180. //++
  181. //
  182. // CDeleteResourcesDlg::OnDestroy
  183. //
  184. // Routine Description:
  185. // Handler method for the WM_DESTROY message.
  186. //
  187. // Arguments:
  188. // None.
  189. //
  190. // Return Value:
  191. // None.
  192. //
  193. //--
  194. /////////////////////////////////////////////////////////////////////////////
  195. void CDeleteResourcesDlg::OnDestroy(void)
  196. {
  197. // Dereference all the cluster item pointers.
  198. if (m_lcResources.m_hWnd != NULL)
  199. {
  200. int ili = -1;
  201. CClusterItem * pci;
  202. while ((ili = m_lcResources.GetNextItem(ili, LVNI_ALL)) != -1)
  203. {
  204. pci = (CClusterItem *) m_lcResources.GetItemData(ili);
  205. ASSERT_VALID(pci);
  206. ASSERT_KINDOF(CClusterItem, pci);
  207. pci->Release();
  208. } // while: more items in the list control
  209. } // if: list control has been instantiated
  210. CBaseDialog::OnDestroy();
  211. } //*** CDeleteResourcesDlg::OnDestroy()
  212. /////////////////////////////////////////////////////////////////////////////
  213. //++
  214. //
  215. // CDeleteResourcesDlg::OnDblClkDependsList
  216. //
  217. // Routine Description:
  218. // Handler method for the NM_DBLCLK message.
  219. //
  220. // Arguments:
  221. // None.
  222. //
  223. // Return Value:
  224. // None.
  225. //
  226. //--
  227. /////////////////////////////////////////////////////////////////////////////
  228. void CDeleteResourcesDlg::OnDblClkResourcesList(NMHDR * pNMHDR, LRESULT * pResult)
  229. {
  230. int iitem;
  231. CResource * pciRes;
  232. // Get the item with the focus.
  233. iitem = m_lcResources.GetNextItem(-1, LVNI_FOCUSED);
  234. ASSERT(iitem != -1);
  235. if (iitem != -1)
  236. {
  237. // Get the resource pointer.
  238. pciRes = (CResource *) m_lcResources.GetItemData(iitem);
  239. ASSERT_VALID(pciRes);
  240. // Get properties of that item.
  241. pciRes->BDisplayProperties(FALSE /*bReadOnly*/);
  242. } // if: found an item with focus
  243. *pResult = 0;
  244. } //*** CDeleteResourcesDlg::OnDblClkResourcesList()
  245. /////////////////////////////////////////////////////////////////////////////
  246. //++
  247. //
  248. // CDeleteResourcesDlg::OnColumnClick
  249. //
  250. // Routine Description:
  251. // Handler method for the LVN_COLUMNCLICK message.
  252. //
  253. // Arguments:
  254. // None.
  255. //
  256. // Return Value:
  257. // None.
  258. //
  259. //--
  260. /////////////////////////////////////////////////////////////////////////////
  261. void CDeleteResourcesDlg::OnColumnClick(NMHDR * pNMHDR, LRESULT * pResult)
  262. {
  263. NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR;
  264. if (m_lcResources.GetItemCount() != 0)
  265. {
  266. // Save the current sort column and direction.
  267. if (pNMListView->iSubItem == m_nSortColumn)
  268. m_nSortDirection ^= -1;
  269. else
  270. {
  271. m_nSortColumn = pNMListView->iSubItem;
  272. m_nSortDirection = 0;
  273. } // else: different column
  274. // Sort the list.
  275. m_lcResources.SortItems(CompareItems, (LPARAM) this);
  276. } // if: there are items in the list
  277. *pResult = 0;
  278. } //*** CDeleteResourcesDlg::OnColumnClick()
  279. /////////////////////////////////////////////////////////////////////////////
  280. //++
  281. //
  282. // CDeleteResourcesDlg::CompareItems [static]
  283. //
  284. // Routine Description:
  285. // Callback function for the CListCtrl::SortItems method.
  286. //
  287. // Arguments:
  288. // lparam1 First item to compare.
  289. // lparam2 Second item to compare.
  290. // lparamSort Sort parameter.
  291. //
  292. // Return Value:
  293. // -1 First parameter comes before second.
  294. // 0 First and second parameters are the same.
  295. // 1 First parameter comes after second.
  296. //
  297. //--
  298. /////////////////////////////////////////////////////////////////////////////
  299. int CALLBACK CDeleteResourcesDlg::CompareItems(
  300. LPARAM lparam1,
  301. LPARAM lparam2,
  302. LPARAM lparamSort
  303. )
  304. {
  305. CResource * pciRes1 = (CResource *) lparam1;
  306. CResource * pciRes2 = (CResource *) lparam2;
  307. CDeleteResourcesDlg * pdlg = (CDeleteResourcesDlg *) lparamSort;
  308. const CString * pstr1;
  309. const CString * pstr2;
  310. int nResult;
  311. ASSERT_VALID(pciRes1);
  312. ASSERT_VALID(pciRes2);
  313. ASSERT_VALID(pdlg);
  314. // Get the strings from the list items.
  315. if (pdlg->m_nSortColumn == 1)
  316. {
  317. pstr1 = &pciRes1->StrRealResourceTypeDisplayName();
  318. pstr2 = &pciRes2->StrRealResourceTypeDisplayName();
  319. } // if: sorting on name column
  320. else
  321. {
  322. pstr1 = &pciRes1->StrName();
  323. pstr2 = &pciRes2->StrName();
  324. } // else: sorting on resource type column
  325. // Compare the two strings.
  326. // Use CompareString() so that it will sort properly on localized builds.
  327. nResult = CompareString(
  328. LOCALE_USER_DEFAULT,
  329. 0,
  330. *pstr1,
  331. pstr1->GetLength(),
  332. *pstr2,
  333. pstr2->GetLength()
  334. );
  335. if ( nResult == CSTR_LESS_THAN )
  336. {
  337. nResult = -1;
  338. }
  339. else if ( nResult == CSTR_EQUAL )
  340. {
  341. nResult = 0;
  342. }
  343. else if ( nResult == CSTR_GREATER_THAN )
  344. {
  345. nResult = 1;
  346. }
  347. else
  348. {
  349. // An error occurred. Ignore it.
  350. nResult = 0;
  351. }
  352. // Return the result based on the direction we are sorting.
  353. if (pdlg->m_nSortDirection != 0)
  354. nResult = -nResult;
  355. return nResult;
  356. } //*** CDeleteResourcesDlg::CompareItems()