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.

414 lines
11 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // OLCPair.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the COrderedListCtrlPair class.
  10. //
  11. // Author:
  12. // David Potter (davidp) August 8, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "stdafx.h"
  20. #include "OLCPair.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // COrderedListCtrlPair
  28. /////////////////////////////////////////////////////////////////////////////
  29. IMPLEMENT_DYNCREATE(COrderedListCtrlPair, CListCtrlPair)
  30. /////////////////////////////////////////////////////////////////////////////
  31. // Message Maps
  32. BEGIN_MESSAGE_MAP(COrderedListCtrlPair, CListCtrlPair)
  33. //{{AFX_MSG_MAP(COrderedListCtrlPair)
  34. //}}AFX_MSG_MAP
  35. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LCP_RIGHT_LIST, OnItemChangedRightList)
  36. ON_BN_CLICKED(IDC_LCP_MOVE_UP, OnClickedMoveUp)
  37. ON_BN_CLICKED(IDC_LCP_MOVE_DOWN, OnClickedMoveDown)
  38. END_MESSAGE_MAP()
  39. /////////////////////////////////////////////////////////////////////////////
  40. //++
  41. //
  42. // COrderedListCtrlPair::COrderedListCtrlPair
  43. //
  44. // Routine Description:
  45. // Default constructor.
  46. //
  47. // Arguments:
  48. // None.
  49. //
  50. // Return Value:
  51. // None.
  52. //
  53. //--
  54. /////////////////////////////////////////////////////////////////////////////
  55. COrderedListCtrlPair::COrderedListCtrlPair(void)
  56. {
  57. ModifyStyle(0, LCPS_ORDERED);
  58. } //*** COrderedListCtrlPair::COrderedListCtrlPair()
  59. /////////////////////////////////////////////////////////////////////////////
  60. //++
  61. //
  62. // COrderedListCtrlPair::COrderedListCtrlPair
  63. //
  64. // Routine Description:
  65. // Cconstructor.
  66. //
  67. // Arguments:
  68. // pdlg [IN OUT] Dialog to which controls belong.
  69. // plpobjRight [IN OUT] List for the right list control.
  70. // plpobjLeft [IN] List for the left list control.
  71. // dwStyle [IN] Style:
  72. // LCPS_SHOW_IMAGES Show images to left of items.
  73. // LCPS_ALLOW_EMPTY Allow right list to be empty.
  74. // LCPS_ORDERED Ordered right list.
  75. // pfnGetColumn [IN] Function pointer for retrieving columns.
  76. // pfnDisplayProps [IN] Function pointer for displaying properties.
  77. //
  78. // Return Value:
  79. // None.
  80. //
  81. //--
  82. /////////////////////////////////////////////////////////////////////////////
  83. COrderedListCtrlPair::COrderedListCtrlPair(
  84. IN OUT CDialog * pdlg,
  85. IN OUT CClusterItemList * plpobjRight,
  86. IN const CClusterItemList * plpobjLeft,
  87. IN DWORD dwStyle,
  88. IN PFNLCPGETCOLUMN pfnGetColumn,
  89. IN PFNLCPDISPPROPS pfnDisplayProps
  90. )
  91. : CListCtrlPair(
  92. pdlg,
  93. plpobjRight,
  94. plpobjLeft,
  95. dwStyle,
  96. pfnGetColumn,
  97. pfnDisplayProps
  98. )
  99. {
  100. } //*** COrderedListCtrlPair::COrderedListCtrlPair()
  101. /////////////////////////////////////////////////////////////////////////////
  102. //++
  103. //
  104. // COrderedListCtrlPair::DoDataExchange
  105. //
  106. // Routine Description:
  107. // Do data exchange between the dialog and the class.
  108. //
  109. // Arguments:
  110. // pDX [IN OUT] Data exchange object
  111. //
  112. // Return Value:
  113. // None.
  114. //
  115. //--
  116. /////////////////////////////////////////////////////////////////////////////
  117. void COrderedListCtrlPair::DoDataExchange(CDataExchange * pDX)
  118. {
  119. CListCtrlPair::DoDataExchange(pDX);
  120. DDX_Control(pDX, IDC_LCP_MOVE_UP, m_pbMoveUp);
  121. DDX_Control(pDX, IDC_LCP_MOVE_DOWN, m_pbMoveDown);
  122. } //*** COrderedListCtrlPair::DoDataExchange()
  123. /////////////////////////////////////////////////////////////////////////////
  124. //++
  125. //
  126. // COrderedListCtrlPair::OnInitDialog
  127. //
  128. // Routine Description:
  129. // Handler for the WM_INITDIALOG message.
  130. //
  131. // Arguments:
  132. // None.
  133. //
  134. // Return Value:
  135. // TRUE Focus needs to be set.
  136. // FALSE Focus already set.
  137. //
  138. //--
  139. /////////////////////////////////////////////////////////////////////////////
  140. BOOL COrderedListCtrlPair::OnInitDialog(void)
  141. {
  142. // Call the base class method.
  143. CListCtrlPair::OnInitDialog();
  144. // If this is an ordered list, show the Move buttons.
  145. // Otherwise, hide them.
  146. SetUpDownState();
  147. // If this is an ordered list, don't sort items in the right list.
  148. if (BOrdered())
  149. m_lcRight.ModifyStyle(LVS_SORTASCENDING, 0, 0);
  150. else
  151. m_lcRight.ModifyStyle(0, LVS_SORTASCENDING, 0);
  152. // Reload the list control.
  153. Pdlg()->UpdateData(FALSE /*bSaveAndValidate*/);
  154. return TRUE; // return TRUE unless you set the focus to a control
  155. // EXCEPTION: OCX Property Pages should return FALSE
  156. } //*** COrderedListCtrlPair::OnInitDialog()
  157. /////////////////////////////////////////////////////////////////////////////
  158. //++
  159. //
  160. // COrderedListCtrlPair::OnSetActive
  161. //
  162. // Routine Description:
  163. // Handler for the PSN_SETACTIVE message.
  164. //
  165. // Arguments:
  166. // None.
  167. //
  168. // Return Value:
  169. // TRUE Page successfully initialized.
  170. // FALSE Page not initialized.
  171. //
  172. //--
  173. /////////////////////////////////////////////////////////////////////////////
  174. BOOL COrderedListCtrlPair::OnSetActive(void)
  175. {
  176. UINT nSelCount;
  177. nSelCount = m_lcRight.GetSelectedCount();
  178. if (BPropertiesButton())
  179. m_pbProperties.EnableWindow(nSelCount == 1);
  180. // Enable or disable the other buttons.
  181. if (!BReadOnly())
  182. SetUpDownState();
  183. return CListCtrlPair::OnSetActive();
  184. } //*** COrderedListCtrlPair::OnSetActive()
  185. /////////////////////////////////////////////////////////////////////////////
  186. //++
  187. //
  188. // COrderedListCtrlPair::OnItemChangedRightList
  189. //
  190. // Routine Description:
  191. // Handler method for the LVN_ITEMCHANGED message in the right list.
  192. //
  193. // Arguments:
  194. // pNMHDR [IN OUT] WM_NOTIFY structure.
  195. // pResult [OUT] LRESULT in which to return the result of this operation.
  196. //
  197. // Return Value:
  198. // None.
  199. //
  200. //--
  201. /////////////////////////////////////////////////////////////////////////////
  202. void COrderedListCtrlPair::OnItemChangedRightList(NMHDR * pNMHDR, LRESULT * pResult)
  203. {
  204. NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pNMHDR;
  205. // Call the base class method.
  206. CListCtrlPair::OnItemChangedRightList(pNMHDR, pResult);
  207. if (BOrdered())
  208. {
  209. // If the selection changed, enable/disable the Remove button.
  210. if ((pNMListView->uChanged & LVIF_STATE)
  211. && ((pNMListView->uOldState & LVIS_SELECTED)
  212. || (pNMListView->uNewState & LVIS_SELECTED)))
  213. {
  214. SetUpDownState();
  215. } // if: selection changed
  216. } // if: list is ordered
  217. *pResult = 0;
  218. } //*** COrderedListCtrlPair::OnItemChangedRightList()
  219. /////////////////////////////////////////////////////////////////////////////
  220. //++
  221. //
  222. // COrderedListCtrlPair::OnClickedMoveUp
  223. //
  224. // Routine Description:
  225. // Handler for the BN_CLICKED message on the Move Up button.
  226. //
  227. // Arguments:
  228. // None.
  229. //
  230. // Return Value:
  231. // None.
  232. //
  233. //--
  234. /////////////////////////////////////////////////////////////////////////////
  235. void COrderedListCtrlPair::OnClickedMoveUp(void)
  236. {
  237. int nItem;
  238. CClusterItem * pci;
  239. // Find the index of the selected item.
  240. nItem = m_lcRight.GetNextItem(-1, LVNI_SELECTED);
  241. ASSERT(nItem != -1);
  242. // Get the item pointer.
  243. pci = (CClusterItem *) m_lcRight.GetItemData(nItem);
  244. ASSERT_VALID(pci);
  245. // Remove the selected item from the list and add it back in.
  246. {
  247. POSITION posRemove;
  248. POSITION posAdd;
  249. // Find the position of the item to be removed and the item before
  250. // which the item is to be inserted.
  251. posRemove = LpobjRight().FindIndex(nItem);
  252. ASSERT(posRemove != NULL);
  253. ASSERT(posRemove == LpobjRight().Find(pci));
  254. posAdd = LpobjRight().FindIndex(nItem - 1);
  255. ASSERT(posAdd != NULL);
  256. VERIFY(LpobjRight().InsertBefore(posAdd, pci) != NULL);
  257. LpobjRight().RemoveAt(posRemove);
  258. } // Remove the selected item from the list and add it back in
  259. // Remove the selected item from the list control and add it back in.
  260. VERIFY(m_lcRight.DeleteItem(nItem));
  261. NInsertItemInListCtrl(nItem - 1, pci, m_lcRight);
  262. m_lcRight.SetItemState(
  263. nItem - 1,
  264. LVIS_SELECTED | LVIS_FOCUSED,
  265. LVIS_SELECTED | LVIS_FOCUSED
  266. );
  267. m_lcRight.EnsureVisible(nItem - 1, FALSE /*bPartialOK*/);
  268. m_lcRight.SetFocus();
  269. } //*** COrderedListCtrlPair::OnClickedMoveUp()
  270. /////////////////////////////////////////////////////////////////////////////
  271. //++
  272. //
  273. // COrderedListCtrlPair::OnClickedMoveDown
  274. //
  275. // Routine Description:
  276. // Handler for the BN_CLICKED message on the Move Down button.
  277. //
  278. // Arguments:
  279. // None.
  280. //
  281. // Return Value:
  282. // None.
  283. //
  284. //--
  285. /////////////////////////////////////////////////////////////////////////////
  286. void COrderedListCtrlPair::OnClickedMoveDown(void)
  287. {
  288. int nItem;
  289. CClusterItem * pci;
  290. // Find the index of the selected item.
  291. nItem = m_lcRight.GetNextItem(-1, LVNI_SELECTED);
  292. ASSERT(nItem != -1);
  293. // Get the item pointer.
  294. pci = (CClusterItem *) m_lcRight.GetItemData(nItem);
  295. ASSERT_VALID(pci);
  296. // Remove the selected item from the list and add it back in.
  297. {
  298. POSITION posRemove;
  299. POSITION posAdd;
  300. // Find the position of the item to be removed and the item after
  301. // which the item is to be inserted.
  302. posRemove = LpobjRight().FindIndex(nItem);
  303. ASSERT(posRemove != NULL);
  304. ASSERT(posRemove == LpobjRight().Find(pci));
  305. posAdd = LpobjRight().FindIndex(nItem + 1);
  306. ASSERT(posAdd != NULL);
  307. VERIFY(LpobjRight().InsertAfter(posAdd, pci) != NULL);
  308. LpobjRight().RemoveAt(posRemove);
  309. } // Remove the selected item from the list and add it back in
  310. // Remove the selected item from the list control and add it back in.
  311. VERIFY(m_lcRight.DeleteItem(nItem));
  312. NInsertItemInListCtrl(nItem + 1, pci, m_lcRight);
  313. m_lcRight.SetItemState(
  314. nItem + 1,
  315. LVIS_SELECTED | LVIS_FOCUSED,
  316. LVIS_SELECTED | LVIS_FOCUSED
  317. );
  318. m_lcRight.EnsureVisible(nItem + 1, FALSE /*bPartialOK*/);
  319. m_lcRight.SetFocus();
  320. } //*** COrderedListCtrlPair::OnClickedMoveDown()
  321. /////////////////////////////////////////////////////////////////////////////
  322. //++
  323. //
  324. // COrderedListCtrlPair::SetUpDownState
  325. //
  326. // Routine Description:
  327. // Set the state of the Up/Down buttons based on the selection.
  328. //
  329. // Arguments:
  330. // None.
  331. //
  332. // Return Value:
  333. // None.
  334. //
  335. //--
  336. /////////////////////////////////////////////////////////////////////////////
  337. void COrderedListCtrlPair::SetUpDownState(void)
  338. {
  339. BOOL bEnableUp;
  340. BOOL bEnableDown;
  341. if ( BOrdered()
  342. && !BReadOnly()
  343. && (m_lcRight.GetSelectedCount() == 1))
  344. {
  345. int nItem;
  346. bEnableUp = TRUE;
  347. bEnableDown = TRUE;
  348. // Find the index of the selected item.
  349. nItem = m_lcRight.GetNextItem(-1, LVNI_SELECTED);
  350. ASSERT(nItem != -1);
  351. // If the first item is selected, can't move up.
  352. if (nItem == 0)
  353. bEnableUp = FALSE;
  354. // If the last item is selected, can't move down.
  355. if (nItem == m_lcRight.GetItemCount() - 1)
  356. bEnableDown = FALSE;
  357. } // if: only one item selected
  358. else
  359. {
  360. bEnableUp = FALSE;
  361. bEnableDown = FALSE;
  362. } // else: zero or more than one item selected
  363. m_pbMoveUp.EnableWindow(bEnableUp);
  364. m_pbMoveDown.EnableWindow(bEnableDown);
  365. } //*** COrderedListCtrlPair::SetUpDownState()