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.

361 lines
8.8 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-1998 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // AtlLCPair.cpp
  7. //
  8. // Abstract:
  9. // Implementation of the CListCtrlPair class.
  10. //
  11. // Author:
  12. // David Potter (davidp) August 8, 1996
  13. //
  14. // Revision History:
  15. //
  16. // Notes:
  17. //
  18. /////////////////////////////////////////////////////////////////////////////
  19. #include "AtlLCPair.h"
  20. #include "AtlUtil.h" // for DDX_xxx
  21. #include "AdmCommonRes.h" // for ADMC_IDC_LCP_xxx
  22. /////////////////////////////////////////////////////////////////////////////
  23. // class CListCtrlPair
  24. /////////////////////////////////////////////////////////////////////////////
  25. /////////////////////////////////////////////////////////////////////////////
  26. //++
  27. //
  28. // CListCtrlPair::BInitDialog
  29. //
  30. // Routine Description:
  31. // Generic dialog initialization routine.
  32. //
  33. // Arguments:
  34. // None.
  35. //
  36. // Return Value:
  37. // TRUE Dialog was initialized successfully.
  38. // FALSE Error initializing the dialog.
  39. //
  40. //--
  41. /////////////////////////////////////////////////////////////////////////////
  42. template < class T, class ObjT, class BaseT>
  43. BOOL CListCtrlPair::BInitDialog( void )
  44. {
  45. //
  46. // Attach the controls to control member variables.
  47. //
  48. AttachControl( m_lvcRight, ADMC_IDC_LCP_RIGHT_LIST );
  49. AttachControl( m_lvcLeft, ADMC_IDC_LCP_LEFT_LIST );
  50. AttachControl( m_pbAdd, ADMC_IDC_LCP_ADD );
  51. AttachControl( m_pbRemove, ADMC_IDC_LCP_REMOVE );
  52. if ( BPropertiesButton() )
  53. {
  54. AttachControl( m_pbProperties, ADMC_IDC_LCP_PROPERTIES );
  55. } // if: dialog has Properties button
  56. // if ( BShowImages() )
  57. // {
  58. // CClusterAdminApp * papp = GetClusterAdminApp();
  59. //
  60. // m_lvcLeft.SetImageList( papp->PilSmallImages(), LVSIL_SMALL );
  61. // m_lvcRight.SetImageList( papp->PilSmallImages(), LVSIL_SMALL );
  62. // } // if: showing images
  63. //
  64. // Disable buttons by default.
  65. //
  66. m_pbAdd.EnableWindow( FALSE );
  67. m_pbRemove.EnableWindow( FALSE );
  68. if ( BPropertiesButton() )
  69. {
  70. m_pbProperties.EnableWindow( FALSE );
  71. } // if: dialog has Properties button
  72. //
  73. // Set the right list to sort. Set both to show selection always.
  74. //
  75. m_lvcRight.ModifyStyle( 0, LVS_SHOWSELALWAYS | LVS_SORTASCENDING, 0 );
  76. m_lvcLeft.ModifyStyle( 0, LVS_SHOWSELALWAYS, 0 );
  77. //
  78. // Change left list view control extended styles.
  79. //
  80. m_lvcLeft.SetExtendedListViewStyle(
  81. LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP,
  82. LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP
  83. );
  84. //
  85. // Change right list view control extended styles.
  86. //
  87. m_lvcRight.SetExtendedListViewStyle(
  88. LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP,
  89. LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP
  90. );
  91. // Duplicate lists.
  92. DuplicateLists();
  93. //
  94. // Insert all the columns.
  95. //
  96. {
  97. int icol;
  98. int ncol;
  99. int nUpperBound = m_aColumns.size();
  100. CString strColText;
  101. ATLASSERT( nUpperBound >= 0 );
  102. for ( icol = 0 ; icol <= nUpperBound ; icol++ )
  103. {
  104. strColText.LoadString( m_aColumns[icol].m_idsText );
  105. ncol = m_lvcLeft.InsertColumn( icol, strColText, LVCFMT_LEFT, m_aColumns[icol].m_nWidth, 0 );
  106. ATLASSERT( ncol == icol );
  107. ncol = m_lvcRight.InsertColumn( icol, strColText, LVCFMT_LEFT, m_aColumns[icol].m_nWidth, 0 );
  108. ATLASSERT( ncol == icol );
  109. } // for: each column
  110. } // Insert all the columns
  111. //
  112. // Fill the list controls.
  113. //
  114. FillList( m_lvcRight, LpobjRight() );
  115. FillList( m_lvcLeft, LpobjLeft() );
  116. //
  117. // If read-only, set all controls to be either disabled or read-only.
  118. //
  119. if ( BReadOnly() )
  120. {
  121. m_lvcRight.EnableWindow( FALSE );
  122. m_lvcLeft.EnableWindow( FALSE );
  123. } // if: sheet is read-only
  124. return TRUE;
  125. } //*** CListCtrlPair::BInitDialog()
  126. /////////////////////////////////////////////////////////////////////////////
  127. //++
  128. //
  129. // CListCtrlPair::OnSetActive
  130. //
  131. // Routine Description:
  132. // Handler for the PSN_SETACTIVE message.
  133. //
  134. // Arguments:
  135. // None.
  136. //
  137. // Return Value:
  138. // TRUE Page successfully initialized.
  139. // FALSE Page not initialized.
  140. //
  141. //--
  142. /////////////////////////////////////////////////////////////////////////////
  143. template < class T, class ObjT, class BaseT>
  144. BOOL CListCtrlPair::OnSetActive( void )
  145. {
  146. UINT nSelCount;
  147. // Set the focus to the left list.
  148. m_lvcLeft.SetFocus();
  149. m_plvcFocusList = &m_lvcLeft;
  150. // Enable/disable the Properties button.
  151. nSelCount = m_lvcLeft.GetSelectedCount();
  152. if ( BPropertiesButton() )
  153. {
  154. m_pbProperties.EnableWindow( nSelCount == 1 );
  155. } // if: dialog has Properties button
  156. // Enable or disable the other buttons.
  157. if ( ! BReadOnly() )
  158. {
  159. m_pbAdd.EnableWindow( nSelCount > 0 );
  160. nSelCount = m_lvcRight.GetSelectedCount();
  161. m_pbRemove.EnableWindow( nSelCount > 0 );
  162. } // if: not read-only page
  163. return TRUE;
  164. } //*** CListCtrlPair::OnSetActive()
  165. /////////////////////////////////////////////////////////////////////////////
  166. //++
  167. //
  168. // CListCtrlPair::OnContextMenu
  169. //
  170. // Routine Description:
  171. // Handler for the WM_CONTEXTMENU method.
  172. //
  173. // Arguments:
  174. // pWnd Window in which the user right clicked the mouse.
  175. // point Position of the cursor, in screen coordinates.
  176. //
  177. // Return Value:
  178. // None.
  179. //
  180. //--
  181. /////////////////////////////////////////////////////////////////////////////
  182. template < class T, class ObjT, class BaseT>
  183. LRESULT CListCtrlPair::OnContextMenu(
  184. IN UINT uMsg,
  185. IN WPARAM wParam,
  186. IN LPARAM lParam,
  187. IN OUT BOOL & bHandled
  188. )
  189. {
  190. BOOL bDisplayed = FALSE;
  191. CMenu * pmenu = NULL;
  192. HWND hWnd = (HWND) wParam;
  193. WORD xPos = LOWORD( lParam );
  194. WORD yPos = HIWORD( lParam );
  195. CListViewCtrl * plvc;
  196. CString strMenuName;
  197. CWaitCursor wc;
  198. //
  199. // If focus is not in a list control, don't handle the message.
  200. //
  201. if ( hWnd == m_lvcLeft.m_hWnd )
  202. {
  203. plvc = &m_lvcLeft;
  204. } // if: context menu on left list
  205. else if ( hWnd == m_lvcRight.m_hWnd )
  206. {
  207. plvc = &m_lvcRight;
  208. } // else if: context menu on right list
  209. else
  210. {
  211. bHandled = FALSE;
  212. return 0;
  213. } // else: focus not in a list control
  214. ATLASSERT( plvc != NULL );
  215. //
  216. // If the properties button is not enabled, don't display a menu.
  217. //
  218. if ( ! BPropertiesButton() )
  219. {
  220. bHandled = FALSE;
  221. return 0;
  222. } // if: no properties button
  223. //
  224. // Create the menu to display.
  225. //
  226. pmenu = new CMenu;
  227. if ( pmenu->CreatePopupMenu() )
  228. {
  229. UINT nFlags = MF_STRING;
  230. //
  231. // If there are no items in the list, disable the menu item.
  232. //
  233. if ( plvc->GetItemCount() == 0 )
  234. {
  235. nFlags |= MF_GRAYED;
  236. } // if: no items in the list
  237. //
  238. // Add the Properties item to the menu.
  239. //
  240. strMenuName.LoadString( ADMC_ID_MENU_PROPERTIES );
  241. if ( pmenu->AppendMenu( nFlags, ADMC_ID_MENU_PROPERTIES, strMenuName ) )
  242. {
  243. m_plvcFocusList = plvc;
  244. bDisplayed = TRUE;
  245. } // if: successfully added menu item
  246. } // if: menu created successfully
  247. if ( bDisplayed )
  248. {
  249. //
  250. // Display the menu.
  251. //
  252. if ( ! pmenu->TrackPopupMenu(
  253. TPM_LEFTALIGN | TPM_RIGHTBUTTON,
  254. xPos,
  255. yPos,
  256. m_hWnd
  257. ) )
  258. {
  259. } // if: unsuccessfully displayed the menu
  260. } // if: there is a menu to display
  261. delete pmenu;
  262. return 0;
  263. } //*** CListCtrlPair::OnContextMenu()
  264. /////////////////////////////////////////////////////////////////////////////
  265. //++
  266. //
  267. // CListCtrlPair::OnColumnClickList
  268. //
  269. // Routine Description:
  270. // Handler method for the LVN_COLUMNCLICK message on the left or
  271. // right list.
  272. //
  273. // Arguments:
  274. // idCtrl [IN] ID of control sending the message.
  275. // pnmh [IN] Notify header.
  276. // bHandled [IN OUT] Indicates if we handled or not. Defaults to TRUE.
  277. //
  278. // Return Value:
  279. // None.
  280. //
  281. //--
  282. /////////////////////////////////////////////////////////////////////////////
  283. template < class T, class ObjT, class BaseT>
  284. void CListCtrlPair::OnColumnClickList(
  285. IN int idCtrl,
  286. IN LPNMHDR pnmh,
  287. IN OUT BOOL & bHandled
  288. )
  289. {
  290. NM_LISTVIEW * pNMListView = (NM_LISTVIEW *) pnmh;
  291. SortInfo * psi;
  292. if ( idCtrl == ADMC_IDC_LCP_LEFT_LIST )
  293. {
  294. m_plvcFocusList = &m_lvcLeft;
  295. m_psiCur = &SiLeft();
  296. } // if: column clicked in left list
  297. else if ( idCtrl == ADMC_IDC_LCP_RIGHT_LIST )
  298. {
  299. m_plvcFocusList = &m_lvcRight;
  300. m_psiCur = &SiRight();
  301. } // else if: column clicked in right list
  302. else
  303. {
  304. ATLASSERT( 0 );
  305. bHandled = FALSE;
  306. return 0;
  307. } // else: column clicked in unknown list
  308. // Save the current sort column and direction.
  309. if ( pNMListView->iSubItem == psi->m_nColumn )
  310. {
  311. m_psiCur->m_nDirection ^= -1;
  312. } // if: sorting same column again
  313. else
  314. {
  315. m_psiCur->m_nColumn = pNMListView->iSubItem;
  316. m_psiCur->m_nDirection = 0;
  317. } // else: different column
  318. // Sort the list.
  319. if ( ! m_plvcFocusList->SortItems( CompareItems, (LPARAM) this ) )
  320. {
  321. ATLASSERT( 0 );
  322. } // if: error sorting items
  323. *pResult = 0;
  324. } //*** CListCtrlPair::OnColumnClickList()