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.

403 lines
11 KiB

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